1/*
2 * Copyright 2008, Dustin Howett, dustin.howett@gmail.com. All rights reserved.
3 * Copyright 2007, Michael Lotz, mmlr@mlotz.ch. All rights reserved.
4 * Distributed under the terms of the MIT License.
5 */
6#ifndef _KERNEL_ARCH_x86_ARCH_ACPI_H
7#define _KERNEL_ARCH_x86_ARCH_ACPI_H
8
9#define ACPI_RSDP_SIGNATURE		"RSD PTR "
10#define ACPI_RSDT_SIGNATURE		"RSDT"
11#define ACPI_XSDT_SIGNATURE		"XSDT"
12#define ACPI_MADT_SIGNATURE		"APIC"
13
14#define ACPI_LOCAL_APIC_ENABLED	0x01
15
16typedef struct acpi_rsdp_legacy {
17	char	signature[8];			/* "RSD PTR " including blank */
18	uint8	checksum;				/* checksum of bytes 0-19 (per ACPI 1.0) */
19	char	oem_id[6];				/* not null terminated */
20	uint8	revision;				/* 0 = ACPI 1.0, 2 = ACPI 3.0 */
21	uint32	rsdt_address;			/* physical memory address of RSDT */
22} _PACKED acpi_rsdp_legacy;
23
24typedef struct acpi_rsdp_extended {
25	char	signature[8];			/* "RSD PTR " including blank */
26	uint8	checksum;				/* checksum of bytes 0-19 (per ACPI 1.0) */
27	char	oem_id[6];				/* not null terminated */
28	uint8	revision;				/* 0 = ACPI 1.0, 2 = ACPI 3.0 */
29	uint32	rsdt_address;			/* physical memory address of RSDT */
30	uint32	xsdt_length;			/* length in bytes including header */
31	uint64	xsdt_address;			/* 64bit physical memory address of XSDT */
32	uint8	extended_checksum;		/* including entire table */
33	uint8	reserved[3];
34} _PACKED acpi_rsdp_extended;
35
36typedef acpi_rsdp_extended acpi_rsdp;
37
38typedef struct acpi_descriptor_header {
39	char	signature[4];			/* table identifier as ASCII string */
40	uint32	length;					/* length in bytes of the entire table */
41	uint8	revision;
42	uint8	checksum;				/* checksum of entire table */
43	char	oem_id[6];				/* not null terminated */
44	char	oem_table_id[8];		/* oem supplied table identifier */
45	uint32	oem_revision;			/* oem supplied revision number */
46	char	creator_id[4];			/* creator / asl compiler id */
47	uint32	creator_revision;		/* compiler revision */
48} _PACKED acpi_descriptor_header;
49
50typedef struct acpi_madt {
51	acpi_descriptor_header	header;		/* "APIC" signature */
52	uint32	local_apic_address;		/* physical address for local CPUs APICs */
53	uint32	flags;
54} _PACKED acpi_madt;
55
56enum {
57	ACPI_MADT_LOCAL_APIC = 0,
58	ACPI_MADT_IO_APIC = 1,
59	ACPI_MADT_INTERRUPT_SOURCE_OVERRIDE = 2,
60	ACPI_MADT_NMI_SOURCE = 3,
61	ACPI_MADT_LOCAL_APIC_NMI = 4,
62	ACPI_MADT_LOCAL_APIC_ADDRESS_OVERRIDE = 5,
63	ACPI_MADT_IO_SAPIC = 6,
64	ACPI_MADT_LOCAL_SAPIC = 7,
65	ACPI_MADT_PLATFORM_INTERRUPT_SOURCE = 8,
66	ACPI_MADT_PROCESSOR_LOCAL_X2_APIC_NMI = 9,
67	ACPI_MADT_LOCAL_X2_APIC_NMI = 0XA
68};
69
70typedef struct acpi_apic {
71	uint8	type;
72	uint8	length;
73} _PACKED acpi_apic;
74
75typedef struct acpi_local_apic {
76	uint8	type;					/* 0 = processor local APIC */
77	uint8	length;					/* 8 bytes */
78	uint8	acpi_processor_id;
79	uint8	apic_id;				/* the id of this APIC */
80	uint32	flags;					/* 1 = enabled */
81} _PACKED acpi_local_apic;
82
83typedef struct acpi_io_apic {
84	uint8	type;					/* 1 = I/O APIC */
85	uint8	length;					/* 12 bytes */
86	uint8	io_apic_id;				/* the id of this APIC */
87	uint8	reserved;
88	uint32	io_apic_address;		/* physical address of I/O APIC */
89	uint32	interrupt_base;			/* global system interrupt base */
90} _PACKED acpi_io_apic;
91
92typedef struct acpi_int_source_override {
93	uint8	type;					/* 2 = Interrupt source override */
94	uint8	length;					/* 10 bytes */
95	uint8	bus;					/* 0 = ISA  */
96	uint8	source;					/* Bus-relative interrupt source (IRQ) */
97	uint32	interrupt;				/* global system interrupt this
98									   bus-relative source int will signal */
99	uint16	flags;					/* MPS INTI flags. See Table 5-25 in
100									   ACPI Spec 4.0a or similar */
101} _PACKED acpi_int_source_override;
102
103typedef struct acpi_nmi_source {
104	uint8	type;					/* 3 = NMI */
105	uint8	length;					/* 8 bytes */
106	uint16	flags;					/* Same as MPS INTI flags. See Table 5-25 in
107									   ACPI Spec 4.0a or similar */
108	uint32  interrupt;				/* global system interrupt this
109									   non-maskable interrupt will trigger */
110} _PACKED acpi_nmi_source;
111
112typedef struct acpi_local_apic_nmi {
113	uint8	type;					/* 4 = local APIC NMI */
114	uint8	length;					/* 6 bytes */
115	uint8	acpi_processor_id;		/* Processor ID corresponding to processor
116									   ID in acpi_local_apic. 0xFF means
117									   it applies to all processors */
118	uint16	flags;					/* Same as MPS INTI flags. See Table 5-25 in
119									   ACPI Spec 4.0a or similar */
120	uint8   local_interrupt;		/* Local APIC interrupt input LINTn to which
121									   NMI is connected */
122} _PACKED acpi_local_apic_nmi;
123
124typedef struct acpi_local_apic_address_override {
125	uint8	type;					/* 5 = local APIC address override */
126	uint8	length;					/* 12 bytes */
127	uint16	reserved;				/* reserved (must be set to zero) */
128	uint64	local_apic_address;		/* Physical address of local APIC. See table
129										5-28 in ACPI Spec 4.0a for more */
130} _PACKED acpi_local_apic_address_override;
131
132typedef struct acpi_io_sapic {
133	uint8	type;					/* 6 = I/0 SAPIC (should be used if it
134									   exists instead of I/O APIC if both exists
135									   for a APIC ID.*/
136	uint8	length;					/* 16 bytes */
137	uint8	io_apic_id;				/* the id of this SAPIC */
138	uint8	reserved;				/* reserved (must be set to zero) */
139	uint32	interrupt_base;			/* global system interrupt base */
140	uint64	sapic_address;			/* The physical address to access this I/0
141									   SAPIC. Each SAPIC resides at a unique
142									   address */
143} _PACKED acpi_io_sapic;
144
145typedef struct acpi_local_sapic {
146	uint8	type;					/* 7 = processor local SAPIC */
147	uint8	length;					/* n bytes */
148	uint8	acpi_processor_id;
149	uint8	local_sapic_id;
150	uint8	local_sapic_eid;
151	uint8	reserved1;				/* reserved (must be set to zero) */
152	uint8	reserved2;				/* reserved (must be set to zero) */
153	uint8	reserved3;				/* reserved (must be set to zero) */
154	uint32	flags;					/* Local SAPIC flags, see table 5-22 in
155									   ACPI Spec 4.0a */
156	uint32	processor_uid_nr;		/* Matches _UID of a processor when it is a
157									   number */
158	char	processor_uid_str[];	/* Matches _UID of a processor when it is a
159									   string. Null-terminated */
160} _PACKED acpi_local_sapic;
161
162typedef struct acpi_platform_interrupt_source {
163	uint8	type;					/* 8 = platform interrupt source */
164	uint8	length;					/* 16 bytes */
165	uint16	flags;					/* Same as MPS INTI flags. See Table 5-25 in
166									   ACPI Spec 4.0a or similar */
167	uint8	interrupt_type;			/* 1 PMI, 2 INIT, 3 Corrected Platform
168									   Error Interrupt */
169	uint8	processor_id;			/* processor ID of destination */
170	uint8	processor_eid;			/* processor EID of destination */
171	uint8	io_sapic_vector;		/* value that must be used to program the
172									   vector field of the I/O SAPIC redirection
173									   entry for entries with PMI type. */
174	uint32	interrupt;				/* global system interrupt this
175									   platform interrupt will trigger */
176	uint32	platform_int_flags;		/* Platform Interrupt Source Flags. See
177									   Table 5-32 of ACPI Spec 4.0a for desc */
178} _PACKED acpi_platform_interrupt_source;
179
180typedef struct acpi_local_x2_apic {
181	uint8	type;					/* 9 = processor local x2APIC */
182	uint8	length;					/* 16 bytes */
183	uint16	reserved;				/* reserved (must be zero) */
184	uint32	x2apic_id;				/* processor's local x2APIC ID */
185	uint32	flags;					/* 1 = enabled. */
186	uint32	processor_uid_nr;		/* Matches _UID of a processor when it is a
187									   number */
188} _PACKED acpi_local_x2_apic;
189
190typedef struct acpi_local_x2_apic_nmi {
191	uint8	type;					/* 0xA = local x2APIC NMI */
192	uint8	length;					/* 12 bytes */
193	uint16	flags;					/* Same as MPS INTI flags. See Table 5-25 in
194									   ACPI Spec 4.0a or similar */
195	uint32	acpi_processor_uid;		/* UID corresponding to ID in processor
196									   device object. 0xFFFFFFFF means
197									   it applies to all processors */
198	uint8   local_interrupt;		/* Local x2APIC interrupt input LINTn to
199									   which NMI is connected */
200	uint8	reserved1;				/* reserved (must be set to zero) */
201	uint8	reserved2;				/* reserved (must be set to zero) */
202	uint8	reserved3;				/* reserved (must be set to zero) */
203} _PACKED acpi_local_x2_apic_nmi;
204
205
206#endif	/* _KERNEL_ARCH_x86_ARCH_ACPI_H */
207