Skip to content

Commit e3f37a5

Browse files
balajirraoIngo Molnar
authored andcommitted
x86: assign IRQs to HPET timers
The userspace API for the HPET (see Documentation/hpet.txt) did not work. The HPET_IE_ON ioctl was failing as there was no IRQ assigned to the timer device. This patch fixes it by allocating IRQs to timer blocks in the HPET. arch/x86/kernel/hpet.c | 13 +++++-------- drivers/char/hpet.c | 45 ++++++++++++++++++++++++++++++++++++++------- include/linux/hpet.h | 2 +- 3 files changed, 44 insertions(+), 16 deletions(-) Signed-off-by: Balaji Rao <balajirrao@gmail.com> Signed-off-by: Ingo Molnar <mingo@elte.hu> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
1 parent 45fe4fe commit e3f37a5

3 files changed

Lines changed: 44 additions & 16 deletions

File tree

‎arch/x86/kernel/hpet.c‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ int is_hpet_enabled(void)
117117
static void hpet_reserve_platform_timers(unsigned long id)
118118
{
119119
struct hpet __iomem *hpet = hpet_virt_address;
120-
struct hpet_timer __iomem *timer = &hpet->hpet_timers[2];
121-
unsigned int nrtimers, i;
120+
unsigned int nrtimers;
122121
struct hpet_data hd;
123122

124123
nrtimers = ((id & HPET_ID_NUMBER) >> HPET_ID_NUMBER_SHIFT) + 1;
@@ -133,16 +132,14 @@ static void hpet_reserve_platform_timers(unsigned long id)
133132
#ifdef CONFIG_HPET_EMULATE_RTC
134133
hpet_reserve_timer(&hd, 1);
135134
#endif
136-
137135
hd.hd_irq[0] = HPET_LEGACY_8254;
138136
hd.hd_irq[1] = HPET_LEGACY_RTC;
139137

140-
for (i = 2; i < nrtimers; timer++, i++)
141-
hd.hd_irq[i] = (timer->hpet_config & Tn_INT_ROUTE_CNF_MASK) >>
142-
Tn_INT_ROUTE_CNF_SHIFT;
143-
138+
/*
139+
* IRQs for the other timers are assigned dynamically
140+
* in hpet_alloc
141+
*/
144142
hpet_alloc(&hd);
145-
146143
}
147144
#else
148145
static void hpet_reserve_platform_timers(unsigned long id) { }

‎drivers/char/hpet.c‎

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -806,14 +806,14 @@ static unsigned long hpet_calibrate(struct hpets *hpetp)
806806

807807
int hpet_alloc(struct hpet_data *hdp)
808808
{
809-
u64 cap, mcfg;
809+
u64 cap, mcfg, hpet_config;
810810
struct hpet_dev *devp;
811-
u32 i, ntimer;
811+
u32 i, ntimer, irq;
812812
struct hpets *hpetp;
813813
size_t siz;
814814
struct hpet __iomem *hpet;
815815
static struct hpets *last = NULL;
816-
unsigned long period;
816+
unsigned long period, irq_bitmap;
817817
unsigned long long temp;
818818

819819
/*
@@ -840,11 +840,41 @@ int hpet_alloc(struct hpet_data *hdp)
840840
hpetp->hp_hpet_phys = hdp->hd_phys_address;
841841

842842
hpetp->hp_ntimer = hdp->hd_nirqs;
843+
hpet = hpetp->hp_hpet;
843844

844-
for (i = 0; i < hdp->hd_nirqs; i++)
845-
hpetp->hp_dev[i].hd_hdwirq = hdp->hd_irq[i];
845+
/* Assign IRQs statically for legacy devices */
846+
hpetp->hp_dev[0].hd_hdwirq = hdp->hd_irq[0];
847+
hpetp->hp_dev[1].hd_hdwirq = hdp->hd_irq[1];
846848

847-
hpet = hpetp->hp_hpet;
849+
/* Assign IRQs dynamically for the others */
850+
for (i = 2, devp = &hpetp->hp_dev[2]; i < hdp->hd_nirqs; i++, devp++) {
851+
struct hpet_timer __iomem *timer;
852+
853+
timer = &hpet->hpet_timers[devp - hpetp->hp_dev];
854+
855+
hpet_config = readq(&timer->hpet_config);
856+
irq_bitmap = (hpet_config & Tn_INT_ROUTE_CAP_MASK)
857+
>> Tn_INT_ROUTE_CAP_SHIFT;
858+
if (!irq_bitmap)
859+
irq = 0; /* No valid IRQ Assignable */
860+
else {
861+
irq = find_first_bit(&irq_bitmap, 32);
862+
do {
863+
hpet_config |= irq << Tn_INT_ROUTE_CNF_SHIFT;
864+
writeq(hpet_config, &timer->hpet_config);
865+
866+
/*
867+
* Verify whether we have written a valid
868+
* IRQ number by reading it back again
869+
*/
870+
hpet_config = readq(&timer->hpet_config);
871+
if (irq == (hpet_config & Tn_INT_ROUTE_CNF_MASK)
872+
>> Tn_INT_ROUTE_CNF_SHIFT)
873+
break; /* Success */
874+
} while ((irq = (find_next_bit(&irq_bitmap, 32, irq))));
875+
}
876+
hpetp->hp_dev[i].hd_hdwirq = irq;
877+
}
848878

849879
cap = readq(&hpet->hpet_cap);
850880

@@ -875,7 +905,8 @@ int hpet_alloc(struct hpet_data *hdp)
875905
hpetp->hp_which, hdp->hd_phys_address,
876906
hpetp->hp_ntimer > 1 ? "s" : "");
877907
for (i = 0; i < hpetp->hp_ntimer; i++)
878-
printk("%s %d", i > 0 ? "," : "", hdp->hd_irq[i]);
908+
printk("%s %d", i > 0 ? "," : "",
909+
hpetp->hp_dev[i].hd_hdwirq);
879910
printk("\n");
880911

881912
printk(KERN_INFO "hpet%u: %u %d-bit timers, %Lu Hz\n",

‎include/linux/hpet.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ struct hpet {
6464
*/
6565

6666
#define Tn_INT_ROUTE_CAP_MASK (0xffffffff00000000ULL)
67-
#define Tn_INI_ROUTE_CAP_SHIFT (32UL)
67+
#define Tn_INT_ROUTE_CAP_SHIFT (32UL)
6868
#define Tn_FSB_INT_DELCAP_MASK (0x8000UL)
6969
#define Tn_FSB_INT_DELCAP_SHIFT (15)
7070
#define Tn_FSB_EN_CNF_MASK (0x4000UL)

0 commit comments

Comments
 (0)