drivers/char/random.c
changeset 2 d1f6d8b6f81c
parent 0 aa628870c1d3
equal deleted inserted replaced
1:0056487c491e 2:d1f6d8b6f81c
   405 	struct entropy_store *pull;
   405 	struct entropy_store *pull;
   406 
   406 
   407 	/* read-write data: */
   407 	/* read-write data: */
   408 	spinlock_t lock;
   408 	spinlock_t lock;
   409 	unsigned add_ptr;
   409 	unsigned add_ptr;
   410 	int entropy_count;	/* Must at no time exceed ->POOLBITS! */
   410 	int entropy_count;
   411 	int input_rotate;
   411 	int input_rotate;
   412 };
   412 };
   413 
   413 
   414 static __u32 input_pool_data[INPUT_POOL_WORDS];
   414 static __u32 input_pool_data[INPUT_POOL_WORDS];
   415 static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
   415 static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
   556 	cycles_t last_time;
   556 	cycles_t last_time;
   557 	long last_delta, last_delta2;
   557 	long last_delta, last_delta2;
   558 	unsigned dont_count_entropy:1;
   558 	unsigned dont_count_entropy:1;
   559 };
   559 };
   560 
   560 
       
   561 #ifndef CONFIG_SPARSE_IRQ
       
   562 
   561 static struct timer_rand_state *irq_timer_state[NR_IRQS];
   563 static struct timer_rand_state *irq_timer_state[NR_IRQS];
   562 
   564 
   563 static struct timer_rand_state *get_timer_rand_state(unsigned int irq)
   565 static struct timer_rand_state *get_timer_rand_state(unsigned int irq)
   564 {
   566 {
   565 	if (irq >= nr_irqs)
       
   566 		return NULL;
       
   567 
       
   568 	return irq_timer_state[irq];
   567 	return irq_timer_state[irq];
   569 }
   568 }
   570 
   569 
   571 static void set_timer_rand_state(unsigned int irq, struct timer_rand_state *state)
   570 static void set_timer_rand_state(unsigned int irq,
   572 {
   571 				 struct timer_rand_state *state)
   573 	if (irq >= nr_irqs)
   572 {
   574 		return;
       
   575 
       
   576 	irq_timer_state[irq] = state;
   573 	irq_timer_state[irq] = state;
   577 }
   574 }
       
   575 
       
   576 #else
       
   577 
       
   578 static struct timer_rand_state *get_timer_rand_state(unsigned int irq)
       
   579 {
       
   580 	struct irq_desc *desc;
       
   581 
       
   582 	desc = irq_to_desc(irq);
       
   583 
       
   584 	return desc->timer_rand_state;
       
   585 }
       
   586 
       
   587 static void set_timer_rand_state(unsigned int irq,
       
   588 				 struct timer_rand_state *state)
       
   589 {
       
   590 	struct irq_desc *desc;
       
   591 
       
   592 	desc = irq_to_desc(irq);
       
   593 
       
   594 	desc->timer_rand_state = state;
       
   595 }
       
   596 #endif
   578 
   597 
   579 static struct timer_rand_state input_timer_state;
   598 static struct timer_rand_state input_timer_state;
   580 
   599 
   581 /*
   600 /*
   582  * This function adds entropy to the entropy "pool" by using timing
   601  * This function adds entropy to the entropy "pool" by using timing
   745 
   764 
   746 static size_t account(struct entropy_store *r, size_t nbytes, int min,
   765 static size_t account(struct entropy_store *r, size_t nbytes, int min,
   747 		      int reserved)
   766 		      int reserved)
   748 {
   767 {
   749 	unsigned long flags;
   768 	unsigned long flags;
   750 
       
   751 	BUG_ON(r->entropy_count > r->poolinfo->POOLBITS);
       
   752 #ifdef CONFIG_NSC
   769 #ifdef CONFIG_NSC
   753 	/*
   770 	/*
   754 	 * prevent infinite loop: if a code path calls get_random_bytes
   771 	 * prevent infinite loop: if a code path calls get_random_bytes
   755 	 * and we've run out of entropy, this calls wake_up_interruptible(),
   772 	 * and we've run out of entropy, this calls wake_up_interruptible(),
   756 	 * which calls the code path again, which calls get_random_bytes,
   773 	 * which calls the code path again, which calls get_random_bytes,
   759 	return nbytes;
   776 	return nbytes;
   760 #endif
   777 #endif
   761 	/* Hold lock while accounting */
   778 	/* Hold lock while accounting */
   762 	spin_lock_irqsave(&r->lock, flags);
   779 	spin_lock_irqsave(&r->lock, flags);
   763 
   780 
       
   781 	BUG_ON(r->entropy_count > r->poolinfo->POOLBITS);
   764 	DEBUG_ENT("trying to extract %d bits from %s\n",
   782 	DEBUG_ENT("trying to extract %d bits from %s\n",
   765 		  nbytes * 8, r->name);
   783 		  nbytes * 8, r->name);
   766 
   784 
   767 	/* Can we pull enough? */
   785 	/* Can we pull enough? */
   768 	if (r->entropy_count / 8 < min + reserved) {
   786 	if (r->entropy_count / 8 < min + reserved) {
   938 module_init(rand_initialize);
   956 module_init(rand_initialize);
   939 
   957 
   940 void rand_initialize_irq(int irq)
   958 void rand_initialize_irq(int irq)
   941 {
   959 {
   942 	struct timer_rand_state *state;
   960 	struct timer_rand_state *state;
   943 
       
   944 	if (irq >= nr_irqs)
       
   945 		return;
       
   946 
   961 
   947 	state = get_timer_rand_state(irq);
   962 	state = get_timer_rand_state(irq);
   948 
   963 
   949 	if (state)
   964 	if (state)
   950 		return;
   965 		return;