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
10 /* -----------------------------------------------------------------------------
11 * ACPI is a table of tables. The tables define a hierarchy.
13 * From the hardware's perspective:
14 * Each table that we care about has a header, and the header has a
15 * length that includes the the length of all its subtables. So, even
16 * if you can't completely parse a table, you can find the next table.
18 * The process of parsing is to find the RSDP, and then for each subtable
19 * see what type it is and parse it. The process is recursive except for
20 * a few issues: The RSDP signature and header differs from the header of
21 * its subtables; their headers differ from the signatures of the tables
22 * they contain. As you walk down the tree, you need different parsers.
24 * The parser is recursive descent. Each parsing function takes a pointer
25 * to the parent of the node it is parsing and will attach itself to the parent
26 * via that pointer. Parsing functions are responsible for building the data
27 * structures that represent their node and recursive invocations of the parser
30 * So, in this case, it's something like this:
32 * RSDP is the root. It has a standard header and size. You map that
33 * memory. You find the first header, get its type and size, and
34 * parse as much of it as you can. Parsing will involve either a
35 * function or case statement for each element type. DMARs are complex
36 * and need functions; APICs are simple and we can get by with case
39 * Each node in the tree is represented as a 'struct Atable'. This has a
40 * pointer to the actual node data, a type tag, a name, pointers to this
41 * node's children (if any) and a parent pointer. It also has a QID so that
42 * the entire structure can be exposed as a filesystem. The Atable doesn't
43 * contain any table data per se; it's metadata. The table pointer contains
44 * the table data as well as a pointer back to it's corresponding Atable.
46 * In the end we present a directory tree for #apic that looks, in this example:
47 * #acpi/DMAR/DRHD/0/{pretty,raw}
49 * 'cat pretty' will return JSON-encoded data described the element.
50 * 'cat raw' gets you the raw bytes.
60 Sdthdrsz = 36, /* size of SDT header */
62 /* ACPI regions. Gas ids */
73 /* ACPI PM1 control */
74 Pm1SciEn = 0x1, /* Generate SCI and not SMI */
76 /* ACPI tbdf as encoded in acpi region base addresses */
86 /* Apic structure types */
87 ASlapic = 0, /* processor local apic */
88 ASioapic, /* I/O apic */
89 ASintovr, /* Interrupt source override */
90 ASnmi, /* NMI source */
91 ASlnmi, /* local apic nmi */
92 ASladdr, /* local apic address override */
93 ASiosapic, /* I/O sapic */
94 ASlsapic, /* local sapic */
95 ASintsrc, /* platform interrupt sources */
96 ASlx2apic, /* local x2 apic */
97 ASlx2nmi, /* local x2 apic NMI */
100 AFbus = 0, /* polarity/trigger like in ISA */
101 AFhigh = 1, /* active high */
102 AFlow = 3, /* active low */
103 AFpmask = 3, /* polarity bits */
104 AFedge = 1 << 2, /* edge triggered */
105 AFlevel = 3 << 2, /* level triggered */
106 AFtmask = 3 << 2, /* trigger bits */
139 NACPITBLS, /* Number of ACPI tables */
142 SRlapic = 0, /* Local apic/sapic affinity */
143 SRmem, /* Memory affinity */
144 SRlx2apic, /* x2 apic affinity */
146 /* Atable constants */
147 SIGSZ = 4+1, /* Size of the signature (including NUL) */
148 OEMIDSZ = 6+1, /* Size of the OEM ID (including NUL) */
149 OEMTBLIDSZ = 8+1, /* Size of the OEM Table ID (including NUL) */
152 Ppic = 0, /* PIC interrupt model */
153 Papic, /* APIC interrupt model */
154 Psapic, /* SAPIC interrupt model */
156 CMregion = 0, /* regio name spc base len accsz */
157 CMgpe, /* gpe name id */
163 * This Atable struct corresponds to an interpretation of the standard header
164 * for all table types we support. It has a pointer to the converted data, i.e.
165 * the structs created by functions like acpimadt and so on. Note: althouh the
166 * various things in this are a superset of many ACPI table names (DRHD, DRHD
167 * scopes, etc). The raw data follows this header.
169 * Child entries in the table are kept in an array of pointers. Each entry has
170 * a pointer to it's logically "next" sibling, thus forming a linked list. But
171 * these lists are purely for convenience and all point to nodes within the
175 struct qid qid; /* QID corresponding to this table. */
176 struct qid rqid; /* This table's 'raw' QID. */
177 struct qid pqid; /* This table's 'pretty' QID. */
178 struct qid tqid; /* This table's 'table' QID. */
179 int type; /* This table's type */
180 void *tbl; /* pointer to the converted table, e.g. madt. */
181 char name[16]; /* name of this table */
183 struct Atable *parent; /* Parent pointer */
184 struct Atable **children; /* children of this node (an array). */
185 struct dirtab *cdirs; /* child directory entries of this node. */
186 size_t nchildren; /* count of this node's children */
187 struct Atable *next; /* Pointer to the next sibling. */
189 size_t rawsize; /* Total size of raw table */
190 uint8_t *raw; /* Raw data. */
194 uintptr_t stsio; /* port used for status */
195 int stsbit; /* bit number */
196 uintptr_t enio; /* port used for enable */
197 int enbit; /* bit number */
198 int nb; /* event number */
199 char *obj; /* handler object */
200 int id; /* id as supplied by user */
205 uint8_t (*get8)(uintptr_t, void *);
206 void (*set8)(uintptr_t, uint8_t unused_int, void *);
207 uint16_t (*get16)(uintptr_t, void *);
208 void (*set16)(uintptr_t, uint16_t unused_int, void *);
209 uint32_t (*get32)(uintptr_t, void *);
210 void (*set32)(uintptr_t, uint32_t, void *);
211 uint64_t (*get64)(uintptr_t, void *);
212 void (*set64)(uintptr_t, uint64_t unused_int, void *);
217 int spc; /* io space */
218 uint64_t base; /* address, physical */
219 uint8_t *p; /* address, kmapped */
222 int accsz; /* access size */
225 /* Generic address structure.
228 uint8_t spc; /* address space id */
229 uint8_t len; /* register size in bits */
230 uint8_t off; /* bit offset */
231 uint8_t accsz; /* 1: byte; 2: word; 3: dword; 4: qword */
232 uint64_t addr; /* address (or acpi encoded tbdf + reg) */
235 /* Root system description table pointer.
236 * Used to locate the root system description table RSDT
237 * (or the extended system description table from version 2) XSDT.
238 * The XDST contains (after the DST header) a list of pointers to tables:
239 * - FADT fixed acpi description table.
240 * It points to the DSDT, AML code making the acpi namespace.
241 * - SSDTs tables with AML code to add to the acpi namespace.
242 * - pointers to other tables for apics, etc.
245 uint8_t signature[8]; /* "RSD PTR " */
249 uint8_t raddr[4]; /* RSDT */
251 uint8_t xaddr[8]; /* XSDT */
252 uint8_t xchecksum; /* XSDT */
253 uint8_t _reserved[3]; /* reserved */
256 /* Header for ACPI description tables
259 uint8_t sig[4]; /* "FACP" or whatever */
266 uint8_t creatorid[4];
267 uint8_t creatorrev[4];
270 /* Firmware control structure
284 /* Maximum System Characteristics table
287 int ndoms; /* number of domains */
288 int nclkdoms; /* number of clock domains */
289 uint64_t maxpa; /* max physical address */
290 size_t nmdom; /* number of discovered domains */
291 struct Mdom *dom; /* array of domains */
295 int start; /* start dom id */
296 int end; /* end dom id */
297 int maxproc; /* max processor capacity */
298 uint64_t maxmem; /* max memory capacity */
301 /* Multiple APIC description table
302 * Interrupts are virtualized by ACPI and each APIC has
303 * a `virtual interrupt base' where its interrupts start.
304 * Addresses are processor-relative physical addresses.
305 * Only enabled devices are linked, others are filtered out.
308 uint64_t lapicpa; /* local APIC addr */
309 int pcat; /* the machine has PC/AT 8259s */
316 int pid; /* processor id */
317 int id; /* apic no */
320 int id; /* io apic id */
321 uint32_t ibase; /* interrupt base addr. */
322 uint64_t addr; /* base address */
325 int irq; /* bus intr. source (ISA only) */
326 int intr; /* system interrupt */
327 int flags; /* apic flags */
330 int intr; /* system interrupt */
331 int flags; /* apic flags */
334 int pid; /* processor id */
335 int flags; /* lapic flags */
336 int lint; /* lapic LINTn for nmi */
339 int pid; /* processor id */
340 int id; /* apic id */
341 int eid; /* apic eid */
342 int puid; /* processor uid */
343 char *puids; /* same thing */
346 int pid; /* processor id */
347 int peid; /* processor eid */
348 int iosv; /* io sapic vector */
349 int intr; /* global sys intr. */
350 int type; /* intr type */
351 int flags; /* apic flags */
352 int any; /* err sts at any proc */
355 int id; /* x2 apic id */
356 int puid; /* processor uid */
366 /* System resource affinity table
372 int dom; /* proximity domain */
373 int apic; /* apic id */
374 int sapic; /* sapic id */
375 int clkdom; /* clock domain */
378 int dom; /* proximity domain */
379 uint64_t addr; /* base address */
381 int hplug; /* hot pluggable */
382 int nvram; /* non volatile */
385 int dom; /* proximity domain */
386 int apic; /* x2 apic id */
387 int clkdom; /* clock domain */
392 /* System locality information table
400 int dom; /* proximity domain */
401 unsigned int dist; /* distance to proximity domain */
404 /* Fixed ACPI description table.
405 * Describes implementation and hardware registers.
406 * PM* blocks are low level functions.
407 * GPE* blocks refer to general purpose events.
408 * P_* blocks are for processor features.
409 * Has address for the DSDT.
441 uint16_t flushstride;
447 uint16_t iapcbootarch;
455 struct Gas xpm1aevtblk;
456 struct Gas xpm1bevtblk;
457 struct Gas xpm1acntblk;
458 struct Gas xpm1bcntblk;
459 struct Gas xpm2cntblk;
460 struct Gas xpmtmrblk;
465 /* XSDT/RSDT. 4/8 byte addresses starting at p.
480 int start_bus_number;
485 * The device scope is basic tbdf as uint32_t. There is a special value
486 * that means "everything" and if we see that we set "all" in the Drhd.
492 uintptr_t all; // This drhd scope is for everything.
494 struct DevScope *scopes;
500 * If your firmware disables x2apic mode, you should not be here.
501 * We ignore that bit.
507 struct Atable *mkatable(struct Atable *parent,
508 int type, char *name, uint8_t *raw,
509 size_t rawsize, size_t addsize);
510 struct Atable *finatable(struct Atable *t, struct slice *slice);
511 struct Atable *finatable_nochildren(struct Atable *t);
512 int get_early_num_cores(void);
514 extern struct Atable *apics;
515 extern struct Atable *dmar;
516 extern struct Atable *srat;