From 4492f5358da5a933af270dac7109f689bebe2a37 Mon Sep 17 00:00:00 2001 From: Damien Zammit Date: Sat, 30 Sep 2023 06:30:58 +0000 Subject: ioapic: Add simple locking for non-atomic accesses Message-Id: <20230930063032.75232-3-damien@zamaudio.com> --- i386/i386at/ioapic.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'i386/i386at/ioapic.c') diff --git a/i386/i386at/ioapic.c b/i386/i386at/ioapic.c index 57d18789..dcc91eff 100644 --- a/i386/i386at/ioapic.c +++ b/i386/i386at/ioapic.c @@ -32,6 +32,7 @@ #include #include #include +#include static int has_irq_specific_eoi = 0; int timer_pin; @@ -42,6 +43,8 @@ uint32_t calibrated_ticks = 0; spl_t curr_ipl[NCPUS] = {0}; int spl_init = 0; +def_simple_lock_irq_data(static, ioapic_lock) /* Lock for non-atomic window accesses to ioapic */ + int iunit[NINTR] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23}; @@ -148,9 +151,11 @@ ioapic_toggle_entry(int apic, int pin, int mask) { union ioapic_route_entry_union entry; + spl_t s = simple_lock_irq(&ioapic_lock); ioapic_read_entry(apic, pin, &entry.both); entry.both.mask = mask & 0x1; ioapic_write(apic, APIC_IO_REDIR_LOW(pin), entry.lo); + simple_unlock_irq(s, &ioapic_lock); } static int @@ -245,6 +250,8 @@ ioapic_irq_eoi(int pin) if (pin == 0) goto skip_specific_eoi; + spl_t s = simple_lock_irq(&ioapic_lock); + if (!has_irq_specific_eoi) { /* Workaround for old IOAPICs with no specific EOI */ @@ -264,6 +271,8 @@ ioapic_irq_eoi(int pin) ioapic->eoi.r = entry.both.vector; } + simple_unlock_irq(s, &ioapic_lock); + skip_specific_eoi: lapic_eoi (); } -- cgit v1.2.3