apic.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. /*
  10. * There are 2 flavours of APIC, Local APIC and IOAPIC,
  11. * Each I/O APIC has a unique physical address,
  12. * Local APICs are all at the same physical address as they can only be
  13. * accessed by the local CPU. APIC ids are unique to the
  14. * APIC type, so an IOAPIC and APIC both with id 0 is ok.
  15. */
  16. typedef struct Ioapic Ioapic;
  17. typedef struct Lapic Lapic;
  18. typedef struct Apic Apic;
  19. struct Ioapic {
  20. Lock l; /* IOAPIC: register access */
  21. uint32_t* addr; /* IOAPIC: register base */
  22. uintptr_t paddr; /* physical address */
  23. int nrdt; /* IOAPIC: size of RDT */
  24. int gsib; /* IOAPIC: global RDT index */
  25. };
  26. struct Lapic {
  27. int machno; /* APIC */
  28. uint32_t lvt[6];
  29. int nlvt;
  30. int ver;
  31. int64_t hz; /* APIC Timer frequency */
  32. int64_t max;
  33. int64_t min;
  34. int64_t div;
  35. };
  36. struct Apic {
  37. int useable; /* en */
  38. Ioapic Ioapic;
  39. Lapic Lapic;
  40. };
  41. enum {
  42. Nbus = 256,
  43. Napic = 254, /* xAPIC architectural limit */
  44. Nrdt = 64,
  45. };
  46. /*
  47. * Common bits for
  48. * IOAPIC Redirection Table Entry (RDT);
  49. * APIC Local Vector Table Entry (LVT);
  50. * APIC Interrupt Command Register (ICR).
  51. * [10:8] Message Type
  52. * [11] Destination Mode (RW)
  53. * [12] Delivery Status (RO)
  54. * [13] Interrupt Input Pin Polarity (RW)
  55. * [14] Remote IRR (RO)
  56. * [15] Trigger Mode (RW)
  57. * [16] Interrupt Mask
  58. */
  59. enum {
  60. MTf = 0x00000000, /* Fixed */
  61. MTlp = 0x00000100, /* Lowest Priority */
  62. MTsmi = 0x00000200, /* SMI */
  63. MTrr = 0x00000300, /* Remote Read */
  64. MTnmi = 0x00000400, /* NMI */
  65. MTir = 0x00000500, /* INIT/RESET */
  66. MTsipi = 0x00000600, /* Startup IPI */
  67. MTei = 0x00000700, /* ExtINT */
  68. Pm = 0x00000000, /* Physical Mode */
  69. Lm = 0x00000800, /* Logical Mode */
  70. Ds = 0x00001000, /* Delivery Status */
  71. IPhigh = 0x00000000, /* IIPP High */
  72. IPlow = 0x00002000, /* IIPP Low */
  73. Rirr = 0x00004000, /* Remote IRR */
  74. TMedge = 0x00000000, /* Trigger Mode Edge */
  75. TMlevel = 0x00008000, /* Trigger Mode Level */
  76. Im = 0x00010000, /* Interrupt Mask */
  77. };
  78. extern Apic xlapic[Napic];
  79. extern Apic xioapic[Napic];
  80. extern Mach *xlapicmachptr[Napic]; /* maintained, but unused */
  81. #define l16get(p) (((p)[1]<<8)|(p)[0])
  82. #define l32get(p) (((uint32_t)l16get(p+2)<<16)|l16get(p))
  83. #define l64get(p) (((uint64_t)l32get(p+4)<<32)|l32get(p))
  84. extern void apicdump(void);
  85. extern void apictimerenab(void);
  86. extern void ioapicdump(void);
  87. extern int pcimsienable(Pcidev*, uint64_t);
  88. extern int pcimsimask(Pcidev*, int);