apic.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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; /* IOAPIC: register access */
  21. uint32_t* addr; /* IOAPIC: register base */
  22. int nrdt; /* IOAPIC: size of RDT */
  23. int gsib; /* IOAPIC: global RDT index */
  24. };
  25. struct Lapic {
  26. int machno; /* APIC */
  27. uint32_t lvt[6];
  28. int nlvt;
  29. int ver;
  30. int64_t hz; /* APIC Timer frequency */
  31. int64_t max;
  32. int64_t min;
  33. int64_t div;
  34. };
  35. struct Apic {
  36. int useable; /* en */
  37. Ioapic;
  38. Lapic;
  39. };
  40. enum {
  41. Nbus = 256,
  42. Napic = 254, /* xAPIC architectural limit */
  43. Nrdt = 64,
  44. };
  45. /*
  46. * Common bits for
  47. * IOAPIC Redirection Table Entry (RDT);
  48. * APIC Local Vector Table Entry (LVT);
  49. * APIC Interrupt Command Register (ICR).
  50. * [10:8] Message Type
  51. * [11] Destination Mode (RW)
  52. * [12] Delivery Status (RO)
  53. * [13] Interrupt Input Pin Polarity (RW)
  54. * [14] Remote IRR (RO)
  55. * [15] Trigger Mode (RW)
  56. * [16] Interrupt Mask
  57. */
  58. enum {
  59. MTf = 0x00000000, /* Fixed */
  60. MTlp = 0x00000100, /* Lowest Priority */
  61. MTsmi = 0x00000200, /* SMI */
  62. MTrr = 0x00000300, /* Remote Read */
  63. MTnmi = 0x00000400, /* NMI */
  64. MTir = 0x00000500, /* INIT/RESET */
  65. MTsipi = 0x00000600, /* Startup IPI */
  66. MTei = 0x00000700, /* ExtINT */
  67. Pm = 0x00000000, /* Physical Mode */
  68. Lm = 0x00000800, /* Logical Mode */
  69. Ds = 0x00001000, /* Delivery Status */
  70. IPhigh = 0x00000000, /* IIPP High */
  71. IPlow = 0x00002000, /* IIPP Low */
  72. Rirr = 0x00004000, /* Remote IRR */
  73. TMedge = 0x00000000, /* Trigger Mode Edge */
  74. TMlevel = 0x00008000, /* Trigger Mode Level */
  75. Im = 0x00010000, /* Interrupt Mask */
  76. };
  77. extern Apic xlapic[Napic];
  78. extern Apic xioapic[Napic];
  79. extern Mach *xlapicmachptr[Napic]; /* maintained, but unused */
  80. #define l16get(p) (((p)[1]<<8)|(p)[0])
  81. #define l32get(p) (((uint32_t)l16get(p+2)<<16)|l16get(p))
  82. #define l64get(p) (((uint64_t)l32get(p+4)<<32)|l32get(p))
  83. extern void apicdump(void);
  84. extern void apictimerenab(void);
  85. extern void ioapicdump(void);
  86. extern int pcimsienable(Pcidev*, uint64_t);
  87. extern int pcimsimask(Pcidev*, int);