acpi.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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. typedef struct Atable Atable;
  10. typedef struct Facs Facs;
  11. typedef struct Fadt Fadt;
  12. typedef struct Gas Gas;
  13. typedef struct Gpe Gpe;
  14. typedef struct Rsdp Rsdp;
  15. typedef struct Sdthdr Sdthdr;
  16. typedef struct Parse Parse;
  17. typedef struct Xsdt Xsdt;
  18. typedef struct Regio Regio;
  19. typedef struct Reg Reg;
  20. typedef struct Madt Madt;
  21. typedef struct Msct Msct;
  22. typedef struct Mdom Mdom;
  23. typedef struct Apicst Apicst;
  24. typedef struct Srat Srat;
  25. typedef struct Slit Slit;
  26. typedef struct SlEntry SlEntry;
  27. enum
  28. {
  29. Sdthdrsz = 36, /* size of SDT header */
  30. /* ACPI regions. Gas ids */
  31. Rsysmem = 0,
  32. Rsysio,
  33. Rpcicfg,
  34. Rembed,
  35. Rsmbus,
  36. Rcmos,
  37. Rpcibar,
  38. Ripmi,
  39. Rfixedhw = 0x7f,
  40. /* ACPI PM1 control */
  41. Pm1SciEn = 0x1, /* Generate SCI and not SMI */
  42. /* ACPI tbdf as encoded in acpi region base addresses */
  43. Rpciregshift = 0,
  44. Rpciregmask = 0xFFFF,
  45. Rpcifunshift = 16,
  46. Rpcifunmask = 0xFFFF,
  47. Rpcidevshift = 32,
  48. Rpcidevmask = 0xFFFF,
  49. Rpcibusshift = 48,
  50. Rpcibusmask = 0xFFFF,
  51. /* Apic structure types */
  52. ASlapic = 0, /* processor local apic */
  53. ASioapic, /* I/O apic */
  54. ASintovr, /* Interrupt source override */
  55. ASnmi, /* NMI source */
  56. ASlnmi, /* local apic nmi */
  57. ASladdr, /* local apic address override */
  58. ASiosapic, /* I/O sapic */
  59. ASlsapic, /* local sapic */
  60. ASintsrc, /* platform interrupt sources */
  61. ASlx2apic, /* local x2 apic */
  62. ASlx2nmi, /* local x2 apic NMI */
  63. /* Apic flags */
  64. AFbus = 0, /* polarity/trigger like in ISA */
  65. AFhigh = 1, /* active high */
  66. AFlow = 3, /* active low */
  67. AFpmask = 3, /* polarity bits */
  68. AFedge = 1<<2, /* edge triggered */
  69. AFlevel = 3<<2, /* level triggered */
  70. AFtmask = 3<<2, /* trigger bits */
  71. /* SRAT types */
  72. SRlapic = 0, /* Local apic/sapic affinity */
  73. SRmem, /* Memory affinity */
  74. SRlx2apic, /* x2 apic affinity */
  75. /* Arg for _PIC */
  76. Ppic = 0, /* PIC interrupt model */
  77. Papic, /* APIC interrupt model */
  78. Psapic, /* SAPIC interrupt model */
  79. CMregion = 0, /* regio name spc base len accsz*/
  80. CMgpe, /* gpe name id */
  81. Qdir = 0,
  82. Qctl,
  83. Qtbl,
  84. Qio,
  85. };
  86. /*
  87. * ACPI table (sw)
  88. */
  89. struct Atable
  90. {
  91. Atable* next; /* next table in list */
  92. int is64; /* uses 64bits */
  93. char sig[5]; /* signature */
  94. char oemid[7]; /* oem id str. */
  95. char oemtblid[9]; /* oem tbl. id str. */
  96. unsigned char* tbl; /* pointer to table in memory */
  97. int32_t dlen; /* size of data in table, after Stdhdr */
  98. };
  99. struct Gpe
  100. {
  101. uintptr_t stsio; /* port used for status */
  102. int stsbit; /* bit number */
  103. uintptr_t enio; /* port used for enable */
  104. int enbit; /* bit number */
  105. int nb; /* event number */
  106. char* obj; /* handler object */
  107. int id; /* id as supplied by user */
  108. };
  109. struct Parse
  110. {
  111. char* sig;
  112. Atable* (*f)(unsigned char*, int); /* return nil to keep vmap */
  113. };
  114. struct Regio{
  115. void *arg;
  116. uint8_t (*get8)(uintptr_t, void*);
  117. void (*set8)(uintptr_t, uint8_t, void*);
  118. uint16_t (*get16)(uintptr_t, void*);
  119. void (*set16)(uintptr_t, uint16_t, void*);
  120. uint32_t (*get32)(uintptr_t, void*);
  121. void (*set32)(uintptr_t, uint32_t, void*);
  122. uint64_t (*get64)(uintptr_t, void*);
  123. void (*set64)(uintptr_t, uint64_t, void*);
  124. };
  125. struct Reg
  126. {
  127. char* name;
  128. int spc; /* io space */
  129. uint64_t base; /* address, physical */
  130. unsigned char* p; /* address, kmapped */
  131. uint64_t len;
  132. int tbdf;
  133. int accsz; /* access size */
  134. };
  135. /* Generic address structure.
  136. */
  137. struct Gas
  138. {
  139. uint8_t spc; /* address space id */
  140. uint8_t len; /* register size in bits */
  141. uint8_t off; /* bit offset */
  142. uint8_t accsz; /* 1: byte; 2: word; 3: dword; 4: qword */
  143. uint64_t addr; /* address (or acpi encoded tbdf + reg) */
  144. } __attribute__ ((packed));
  145. /* Root system description table pointer.
  146. * Used to locate the root system description table RSDT
  147. * (or the extended system description table from version 2) XSDT.
  148. * The XDST contains (after the DST header) a list of pointers to tables:
  149. * - FADT fixed acpi description table.
  150. * It points to the DSDT, AML code making the acpi namespace.
  151. * - SSDTs tables with AML code to add to the acpi namespace.
  152. * - pointers to other tables for apics, etc.
  153. */
  154. struct Rsdp
  155. {
  156. uint8_t signature[8]; /* "RSD PTR " */
  157. uint8_t rchecksum;
  158. uint8_t oemid[6];
  159. uint8_t revision;
  160. uint8_t raddr[4]; /* RSDT */
  161. uint8_t length[4];
  162. uint8_t xaddr[8]; /* XSDT */
  163. uint8_t xchecksum; /* XSDT */
  164. uint8_t _33_[3]; /* reserved */
  165. } __attribute__ ((packed));
  166. /* Header for ACPI description tables
  167. */
  168. struct Sdthdr
  169. {
  170. uint8_t sig[4]; /* "FACP" or whatever */
  171. uint8_t length[4];
  172. uint8_t rev;
  173. uint8_t csum;
  174. uint8_t oemid[6];
  175. uint8_t oemtblid[8];
  176. uint8_t oemrev[4];
  177. uint8_t creatorid[4];
  178. uint8_t creatorrev[4];
  179. } __attribute__ ((packed));
  180. /* Firmware control structure
  181. */
  182. struct Facs
  183. {
  184. uint32_t hwsig;
  185. uint32_t wakingv;
  186. uint32_t glock;
  187. uint32_t flags;
  188. uint64_t xwakingv;
  189. uint8_t vers;
  190. uint32_t ospmflags;
  191. } __attribute__ ((packed));
  192. /* Maximum System Characteristics table
  193. */
  194. struct Msct
  195. {
  196. int ndoms; /* number of domains */
  197. int nclkdoms; /* number of clock domains */
  198. uint64_t maxpa; /* max physical address */
  199. Mdom* dom; /* domain information list */
  200. };
  201. struct Mdom
  202. {
  203. Mdom* next;
  204. int start; /* start dom id */
  205. int end; /* end dom id */
  206. int maxproc; /* max processor capacity */
  207. uint64_t maxmem; /* max memory capacity */
  208. };
  209. /* Multiple APIC description table
  210. * Interrupts are virtualized by ACPI and each APIC has
  211. * a `virtual interrupt base' where its interrupts start.
  212. * Addresses are processor-relative physical addresses.
  213. * Only enabled devices are linked, others are filtered out.
  214. */
  215. struct Madt
  216. {
  217. uint64_t lapicpa; /* local APIC addr */
  218. int pcat; /* the machine has PC/AT 8259s */
  219. Apicst* st; /* list of Apic related structures */
  220. };
  221. struct Apicst
  222. {
  223. int type;
  224. Apicst* next;
  225. union{
  226. struct{
  227. int pid; /* processor id */
  228. int id; /* apic no */
  229. } lapic;
  230. struct{
  231. int id; /* io apic id */
  232. uint32_t ibase; /* interrupt base addr. */
  233. uint64_t addr; /* base address */
  234. } ioapic, iosapic;
  235. struct{
  236. int irq; /* bus intr. source (ISA only) */
  237. int intr; /* system interrupt */
  238. int flags; /* apic flags */
  239. } intovr;
  240. struct{
  241. int intr; /* system interrupt */
  242. int flags; /* apic flags */
  243. } nmi;
  244. struct{
  245. int pid; /* processor id */
  246. int flags; /* lapic flags */
  247. int lint; /* lapic LINTn for nmi */
  248. } lnmi;
  249. struct{
  250. int pid; /* processor id */
  251. int id; /* apic id */
  252. int eid; /* apic eid */
  253. int puid; /* processor uid */
  254. char* puids; /* same thing */
  255. } lsapic;
  256. struct{
  257. int pid; /* processor id */
  258. int peid; /* processor eid */
  259. int iosv; /* io sapic vector */
  260. int intr; /* global sys intr. */
  261. int type; /* intr type */
  262. int flags; /* apic flags */
  263. int any; /* err sts at any proc */
  264. } intsrc;
  265. struct{
  266. int id; /* x2 apic id */
  267. int puid; /* processor uid */
  268. } lx2apic;
  269. struct{
  270. int puid;
  271. int flags;
  272. int intr;
  273. } lx2nmi;
  274. };
  275. };
  276. /* System resource affinity table
  277. */
  278. struct Srat
  279. {
  280. int type;
  281. Srat* next;
  282. union{
  283. struct{
  284. int dom; /* proximity domain */
  285. int apic; /* apic id */
  286. int sapic; /* sapic id */
  287. int clkdom; /* clock domain */
  288. } lapic;
  289. struct{
  290. int dom; /* proximity domain */
  291. uint64_t addr; /* base address */
  292. uint64_t len;
  293. int hplug; /* hot pluggable */
  294. int nvram; /* non volatile */
  295. } mem;
  296. struct{
  297. int dom; /* proximity domain */
  298. int apic; /* x2 apic id */
  299. int clkdom; /* clock domain */
  300. } lx2apic;
  301. };
  302. };
  303. /* System locality information table
  304. */
  305. struct Slit {
  306. int64_t rowlen;
  307. SlEntry **e;
  308. };
  309. struct SlEntry {
  310. int dom; /* proximity domain */
  311. uint dist; /* distance to proximity domain */
  312. };
  313. /* Fixed ACPI description table.
  314. * Describes implementation and hardware registers.
  315. * PM* blocks are low level functions.
  316. * GPE* blocks refer to general purpose events.
  317. * P_* blocks are for processor features.
  318. * Has address for the DSDT.
  319. */
  320. struct Fadt
  321. {
  322. uint32_t facs;
  323. uint32_t dsdt;
  324. /* 1 reserved */
  325. uint8_t pmprofile;
  326. uint16_t sciint;
  327. uint32_t smicmd;
  328. uint8_t acpienable;
  329. uint8_t acpidisable;
  330. uint8_t s4biosreq;
  331. uint8_t pstatecnt;
  332. uint32_t pm1aevtblk;
  333. uint32_t pm1bevtblk;
  334. uint32_t pm1acntblk;
  335. uint32_t pm1bcntblk;
  336. uint32_t pm2cntblk;
  337. uint32_t pmtmrblk;
  338. uint32_t gpe0blk;
  339. uint32_t gpe1blk;
  340. uint8_t pm1evtlen;
  341. uint8_t pm1cntlen;
  342. uint8_t pm2cntlen;
  343. uint8_t pmtmrlen;
  344. uint8_t gpe0blklen;
  345. uint8_t gpe1blklen;
  346. uint8_t gp1base;
  347. uint8_t cstcnt;
  348. uint16_t plvl2lat;
  349. uint16_t plvl3lat;
  350. uint16_t flushsz;
  351. uint16_t flushstride;
  352. uint8_t dutyoff;
  353. uint8_t dutywidth;
  354. uint8_t dayalrm;
  355. uint8_t monalrm;
  356. uint8_t century;
  357. uint16_t iapcbootarch;
  358. /* 1 reserved */
  359. uint32_t flags;
  360. Gas resetreg;
  361. uint8_t resetval;
  362. /* 3 reserved */
  363. uint64_t xfacs;
  364. uint64_t xdsdt;
  365. Gas xpm1aevtblk;
  366. Gas xpm1bevtblk;
  367. Gas xpm1acntblk;
  368. Gas xpm1bcntblk;
  369. Gas xpm2cntblk;
  370. Gas xpmtmrblk;
  371. Gas xgpe0blk;
  372. Gas xgpe1blk;
  373. };
  374. /* XSDT/RSDT. 4/8 byte addresses starting at p.
  375. */
  376. struct Xsdt
  377. {
  378. int len;
  379. int asize;
  380. uint8_t* p;
  381. };
  382. extern uintmem acpimblocksize(uintmem, int*);