for (hpetp = hpets; hpetp; hpetp = hpetp->hp_next) if (hpetp->hp_hpet_phys == hdp->hd_phys_address) { printk(KERN_DEBUG "%s: duplicate HPET ignored\n", __FUNCTION__); return 0; } 
if (hpet_is_known(hdp)) { printk(KERN_DEBUG "%s: duplicate HPET ignored\n", __FUNCTION__); return 0; } 
int hpet_alloc(struct hpet_data *hdp){	u64 cap, mcfg;	struct hpet_dev *devp;	u32 i, ntimer;	struct hpets *hpetp;	size_t siz;	struct hpet __iomem *hpet;	static struct hpets *last = (struct hpets *)0;	unsigned long period;	unsigned long long temp;	/*	 * hpet_alloc can be called by platform dependent code.	 * if platform dependent code has allocated the hpet	 * ACPI also reports hpet, then we catch it here.	 */	for (hpetp = hpets; hpetp; hpetp = hpetp->hp_next)		if (hpetp->hp_hpet_phys == hdp->hd_phys_address) {			printk(KERN_DEBUG "%s: duplicate HPET ignored\n",				__FUNCTION__);			return 0;		}	siz = sizeof(struct hpets) + ((hdp->hd_nirqs - 1) *				      sizeof(struct hpet_dev));	hpetp = kmalloc(siz, GFP_KERNEL);	if (!hpetp)		return -ENOMEM;	memset(hpetp, 0, siz);	hpetp->hp_which = hpet_nhpet++;	hpetp->hp_hpet = hdp->hd_address;	hpetp->hp_hpet_phys = hdp->hd_phys_address;	hpetp->hp_ntimer = hdp->hd_nirqs;	for (i = 0; i < hdp->hd_nirqs; i++)		hpetp->hp_dev[i].hd_hdwirq = hdp->hd_irq[i];	hpet = hpetp->hp_hpet;	cap = readq(&hpet->hpet_cap);	ntimer = ((cap & HPET_NUM_TIM_CAP_MASK) >> HPET_NUM_TIM_CAP_SHIFT) + 1;	if (hpetp->hp_ntimer != ntimer) {		printk(KERN_WARNING "hpet: number irqs doesn't agree"		       " with number of timers\n");		kfree(hpetp);		return -ENODEV;	}	if (last)		last->hp_next = hpetp;	else		hpets = hpetp;	last = hpetp;	period = (cap & HPET_COUNTER_CLK_PERIOD_MASK) >>		HPET_COUNTER_CLK_PERIOD_SHIFT; /* fs, 10^-15 */	temp = 1000000000000000uLL; /* 10^15 femtoseconds per second */	temp += period >> 1; /* round */	do_div(temp, period);	hpetp->hp_tick_freq = temp; /* ticks per second */	printk(KERN_INFO "hpet%d: at MMIO 0x%lx (virtual 0x%p), IRQ%s",		hpetp->hp_which, hdp->hd_phys_address, hdp->hd_address,		hpetp->hp_ntimer > 1 ? "s" : "");	for (i = 0; i < hpetp->hp_ntimer; i++)		printk("%s %d", i > 0 ? "," : "", hdp->hd_irq[i]);	printk("\n");	printk(KERN_INFO "hpet%u: %u %d-bit timers, %Lu Hz\n",	       hpetp->hp_which, hpetp->hp_ntimer,	       cap & HPET_COUNTER_SIZE_MASK ? 64 : 32, hpetp->hp_tick_freq);	mcfg = readq(&hpet->hpet_config);	if ((mcfg & HPET_ENABLE_CNF_MASK) == 0) {		write_counter(0L, &hpet->hpet_mc);		mcfg |= HPET_ENABLE_CNF_MASK;		writeq(mcfg, &hpet->hpet_config);	}	for (i = 0, devp = hpetp->hp_dev; i < hpetp->hp_ntimer; i++, devp++) {		struct hpet_timer __iomem *timer;		timer = &hpet->hpet_timers[devp - hpetp->hp_dev];		devp->hd_hpets = hpetp;		devp->hd_hpet = hpet;		devp->hd_timer = timer;		/*		 * If the timer was reserved by platform code,		 * then make timer unavailable for opens.		 */		if (hdp->hd_state & (1 << i)) {			devp->hd_flags = HPET_OPEN;			continue;		}		init_waitqueue_head(&devp->hd_waitqueue);	}	hpetp->hp_delta = hpet_calibrate(hpetp);	hpet_register_interpolator(hpetp);	return 0;}
10457	/local/tlutelli/issta_data/temp/c/2005_temp/2005/10457/3e6716e748609a3a899e8d670e42832921bd45bc/hpet.c/buggy/drivers/char/hpet.c