Spinlock save cpu flags
This commit is contained in:
@@ -57,19 +57,23 @@ static spin_lock_t lapic_calibration_lock = SPIN_LOCK_INIT;
|
||||
|
||||
/* Read IOAPIC */
|
||||
static uint32_t ioapic_read (struct ioapic* ioapic, uint32_t reg) {
|
||||
spin_lock (&ioapic->lock);
|
||||
uint64_t fia;
|
||||
|
||||
spin_lock (&ioapic->lock, &fia);
|
||||
*(volatile uint32_t*)ioapic->mmio_base = reg;
|
||||
uint32_t ret = *(volatile uint32_t*)(ioapic->mmio_base + 0x10);
|
||||
spin_unlock (&ioapic->lock);
|
||||
spin_unlock (&ioapic->lock, fia);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Write IOAPIC */
|
||||
static void ioapic_write (struct ioapic* ioapic, uint32_t reg, uint32_t value) {
|
||||
spin_lock (&ioapic->lock);
|
||||
uint64_t fia;
|
||||
|
||||
spin_lock (&ioapic->lock, &fia);
|
||||
*(volatile uint32_t*)ioapic->mmio_base = reg;
|
||||
*(volatile uint32_t*)(ioapic->mmio_base + 0x10) = value;
|
||||
spin_unlock (&ioapic->lock);
|
||||
spin_unlock (&ioapic->lock, fia);
|
||||
}
|
||||
|
||||
/* Find an IOAPIC corresposting to provided IRQ */
|
||||
@@ -197,7 +201,9 @@ void lapic_eoi (void) { lapic_write (LAPIC_EOI, 0); }
|
||||
* us - Period length in microseconds
|
||||
*/
|
||||
static uint32_t lapic_calibrate (uint32_t us) {
|
||||
spin_lock (&lapic_calibration_lock);
|
||||
uint64_t flc;
|
||||
|
||||
spin_lock (&lapic_calibration_lock, &flc);
|
||||
|
||||
lapic_write (LAPIC_DCR, DIVIDER_VALUE);
|
||||
|
||||
@@ -210,7 +216,7 @@ static uint32_t lapic_calibrate (uint32_t us) {
|
||||
uint32_t ticks = 0xFFFFFFFF - lapic_read (LAPIC_TIMCCT);
|
||||
DEBUG ("timer ticks = %u\n", ticks);
|
||||
|
||||
spin_unlock (&lapic_calibration_lock);
|
||||
spin_unlock (&lapic_calibration_lock, flc);
|
||||
|
||||
return ticks;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user