ioapic.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* I/O APIC masking.
  2. *
  3. * This kernel has no IOAPIC driver: the BSP keeps the 8259 PIC and delivers
  4. * its interrupts through LAPIC LINT0 in ExtINT mode (lapic.c). Firmware may
  5. * still leave IOAPIC redirection entries programmed, and their vectors can
  6. * collide with the PIC vectors (0x20..0x2f) or the LAPIC timer vector 0x30.
  7. * Masking every normal entry makes the 8259 path deterministic.
  8. *
  9. * ExtINT-delivery entries are deliberately left unmasked: a few boards route
  10. * the 8259 output through an IOAPIC pin instead of LINT0, and that entry must
  11. * keep working. Entries that are already masked are skipped.
  12. */
  13. #include "ioapic.h"
  14. #include "acpi.h"
  15. #include "paging.h"
  16. #include "serial.h"
  17. #define IOAPIC_REGSEL 0x00
  18. #define IOAPIC_IOWIN 0x10
  19. #define IOAPIC_VER 0x01
  20. #define IOAPIC_REDTBL 0x10
  21. #define IOAPIC_MASK 0x00010000u
  22. #define IOAPIC_DELMODE_MASK 0x00000700u
  23. #define IOAPIC_DELMODE_EXTINT 0x00000700u
  24. static unsigned int ioapic_read(volatile unsigned int *base, unsigned int reg)
  25. {
  26. base[IOAPIC_REGSEL / 4] = reg;
  27. return base[IOAPIC_IOWIN / 4];
  28. }
  29. static void ioapic_write(volatile unsigned int *base, unsigned int reg,
  30. unsigned int val)
  31. {
  32. base[IOAPIC_REGSEL / 4] = reg;
  33. base[IOAPIC_IOWIN / 4] = val;
  34. }
  35. void ioapic_mask_all(void)
  36. {
  37. unsigned int n = acpi_ioapic_count();
  38. unsigned int i;
  39. for (i = 0; i < n; i++) {
  40. unsigned int addr = acpi_ioapic_base(i);
  41. volatile unsigned int *base;
  42. unsigned int ver, entries, j, masked = 0;
  43. if (!addr)
  44. continue;
  45. base = ioremap(addr, 0x1000, IOREMAP_MMIO);
  46. if (!base)
  47. continue;
  48. ver = ioapic_read(base, IOAPIC_VER);
  49. if (ver == 0xFFFFFFFFu)
  50. continue;
  51. entries = ((ver >> 16) & 0xFFu) + 1u;
  52. for (j = 0; j < entries; j++) {
  53. unsigned int lo = ioapic_read(base,
  54. IOAPIC_REDTBL + 2u * j);
  55. if (lo & IOAPIC_MASK)
  56. continue;
  57. if ((lo & IOAPIC_DELMODE_MASK) ==
  58. IOAPIC_DELMODE_EXTINT)
  59. continue;
  60. ioapic_write(base, IOAPIC_REDTBL + 2u * j,
  61. lo | IOAPIC_MASK);
  62. masked++;
  63. }
  64. serial_puts(SERIAL_COM1, "ioapic: masked ");
  65. serial_putdec(SERIAL_COM1, masked);
  66. serial_puts(SERIAL_COM1, " of ");
  67. serial_putdec(SERIAL_COM1, entries);
  68. serial_puts(SERIAL_COM1, " entries at ");
  69. serial_puthex(SERIAL_COM1, addr);
  70. serial_puts(SERIAL_COM1, "\n");
  71. }
  72. }