xref: /haiku/headers/private/kernel/acpi.h (revision c237c4ce593ee823d9867fd997e51e4c447f5623)
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_ACPI_H
7 #define _KERNEL_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 #define ACPI_MCFG_SIGNATURE		"MCFG"
14 #define ACPI_SPCR_SIGNATURE		"SPCR"
15 
16 #define ACPI_LOCAL_APIC_ENABLED	0x01
17 
18 typedef struct acpi_rsdp_legacy {
19 	char	signature[8];			/* "RSD PTR " including blank */
20 	uint8	checksum;				/* checksum of bytes 0-19 (per ACPI 1.0) */
21 	char	oem_id[6];				/* not null terminated */
22 	uint8	revision;				/* 0 = ACPI 1.0, 2 = ACPI 3.0 */
23 	uint32	rsdt_address;			/* physical memory address of RSDT */
24 } _PACKED acpi_rsdp_legacy;
25 
26 typedef struct acpi_rsdp_extended {
27 	char	signature[8];			/* "RSD PTR " including blank */
28 	uint8	checksum;				/* checksum of bytes 0-19 (per ACPI 1.0) */
29 	char	oem_id[6];				/* not null terminated */
30 	uint8	revision;				/* 0 = ACPI 1.0, 2 = ACPI 3.0 */
31 	uint32	rsdt_address;			/* physical memory address of RSDT */
32 	uint32	xsdt_length;			/* length in bytes including header */
33 	uint64	xsdt_address;			/* 64bit physical memory address of XSDT */
34 	uint8	extended_checksum;		/* including entire table */
35 	uint8	reserved[3];
36 } _PACKED acpi_rsdp_extended;
37 
38 typedef acpi_rsdp_extended acpi_rsdp;
39 
40 typedef struct acpi_descriptor_header {
41 	char	signature[4];			/* table identifier as ASCII string */
42 	uint32	length;					/* length in bytes of the entire table */
43 	uint8	revision;
44 	uint8	checksum;				/* checksum of entire table */
45 	char	oem_id[6];				/* not null terminated */
46 	char	oem_table_id[8];		/* oem supplied table identifier */
47 	uint32	oem_revision;			/* oem supplied revision number */
48 	char	creator_id[4];			/* creator / asl compiler id */
49 	uint32	creator_revision;		/* compiler revision */
50 } _PACKED acpi_descriptor_header;
51 
52 typedef struct acpi_madt {
53 	acpi_descriptor_header	header;		/* "APIC" signature */
54 	uint32	local_apic_address;		/* physical address for local CPUs APICs */
55 	uint32	flags;
56 } _PACKED acpi_madt;
57 
58 enum {
59 	ACPI_MADT_LOCAL_APIC = 0,
60 	ACPI_MADT_IO_APIC = 1,
61 	ACPI_MADT_INTERRUPT_SOURCE_OVERRIDE = 2,
62 	ACPI_MADT_NMI_SOURCE = 3,
63 	ACPI_MADT_LOCAL_APIC_NMI = 4,
64 	ACPI_MADT_LOCAL_APIC_ADDRESS_OVERRIDE = 5,
65 	ACPI_MADT_IO_SAPIC = 6,
66 	ACPI_MADT_LOCAL_SAPIC = 7,
67 	ACPI_MADT_PLATFORM_INTERRUPT_SOURCE = 8,
68 	ACPI_MADT_PROCESSOR_LOCAL_X2_APIC_NMI = 9,
69 	ACPI_MADT_LOCAL_X2_APIC_NMI = 0xA,
70 	ACPI_MADT_GIC_INTERFACE = 0xB,
71 	ACPI_MADT_GIC_DISTRIBUTOR = 0xC,
72 	ACPI_MADT_GIC_MSI_FRAME = 0xD,
73 	ACPI_MADT_GIC_REDISTRIBUTOR = 0xE,
74 	ACPI_MADT_GIC_ITS = 0xF
75 };
76 
77 typedef struct acpi_apic {
78 	uint8	type;
79 	uint8	length;
80 } _PACKED acpi_apic;
81 
82 typedef struct acpi_local_apic {
83 	uint8	type;					/* 0 = processor local APIC */
84 	uint8	length;					/* 8 bytes */
85 	uint8	acpi_processor_id;
86 	uint8	apic_id;				/* the id of this APIC */
87 	uint32	flags;					/* 1 = enabled */
88 } _PACKED acpi_local_apic;
89 
90 typedef struct acpi_io_apic {
91 	uint8	type;					/* 1 = I/O APIC */
92 	uint8	length;					/* 12 bytes */
93 	uint8	io_apic_id;				/* the id of this APIC */
94 	uint8	reserved;
95 	uint32	io_apic_address;		/* physical address of I/O APIC */
96 	uint32	interrupt_base;			/* global system interrupt base */
97 } _PACKED acpi_io_apic;
98 
99 typedef struct acpi_int_source_override {
100 	uint8	type;					/* 2 = Interrupt source override */
101 	uint8	length;					/* 10 bytes */
102 	uint8	bus;					/* 0 = ISA  */
103 	uint8	source;					/* Bus-relative interrupt source (IRQ) */
104 	uint32	interrupt;				/* global system interrupt this
105 									   bus-relative source int will signal */
106 	uint16	flags;					/* MPS INTI flags. See Table 5-25 in
107 									   ACPI Spec 4.0a or similar */
108 } _PACKED acpi_int_source_override;
109 
110 typedef struct acpi_nmi_source {
111 	uint8	type;					/* 3 = NMI */
112 	uint8	length;					/* 8 bytes */
113 	uint16	flags;					/* Same as MPS INTI flags. See Table 5-25 in
114 									   ACPI Spec 4.0a or similar */
115 	uint32  interrupt;				/* global system interrupt this
116 									   non-maskable interrupt will trigger */
117 } _PACKED acpi_nmi_source;
118 
119 typedef struct acpi_local_apic_nmi {
120 	uint8	type;					/* 4 = local APIC NMI */
121 	uint8	length;					/* 6 bytes */
122 	uint8	acpi_processor_id;		/* Processor ID corresponding to processor
123 									   ID in acpi_local_apic. 0xFF means
124 									   it applies to all processors */
125 	uint16	flags;					/* Same as MPS INTI flags. See Table 5-25 in
126 									   ACPI Spec 4.0a or similar */
127 	uint8   local_interrupt;		/* Local APIC interrupt input LINTn to which
128 									   NMI is connected */
129 } _PACKED acpi_local_apic_nmi;
130 
131 typedef struct acpi_local_apic_address_override {
132 	uint8	type;					/* 5 = local APIC address override */
133 	uint8	length;					/* 12 bytes */
134 	uint16	reserved;				/* reserved (must be set to zero) */
135 	uint64	local_apic_address;		/* Physical address of local APIC. See table
136 										5-28 in ACPI Spec 4.0a for more */
137 } _PACKED acpi_local_apic_address_override;
138 
139 typedef struct acpi_io_sapic {
140 	uint8	type;					/* 6 = I/0 SAPIC (should be used if it
141 									   exists instead of I/O APIC if both exists
142 									   for a APIC ID.*/
143 	uint8	length;					/* 16 bytes */
144 	uint8	io_apic_id;				/* the id of this SAPIC */
145 	uint8	reserved;				/* reserved (must be set to zero) */
146 	uint32	interrupt_base;			/* global system interrupt base */
147 	uint64	sapic_address;			/* The physical address to access this I/0
148 									   SAPIC. Each SAPIC resides at a unique
149 									   address */
150 } _PACKED acpi_io_sapic;
151 
152 typedef struct acpi_local_sapic {
153 	uint8	type;					/* 7 = processor local SAPIC */
154 	uint8	length;					/* n bytes */
155 	uint8	acpi_processor_id;
156 	uint8	local_sapic_id;
157 	uint8	local_sapic_eid;
158 	uint8	reserved1;				/* reserved (must be set to zero) */
159 	uint8	reserved2;				/* reserved (must be set to zero) */
160 	uint8	reserved3;				/* reserved (must be set to zero) */
161 	uint32	flags;					/* Local SAPIC flags, see table 5-22 in
162 									   ACPI Spec 4.0a */
163 	uint32	processor_uid_nr;		/* Matches _UID of a processor when it is a
164 									   number */
165 	char	processor_uid_str[];	/* Matches _UID of a processor when it is a
166 									   string. Null-terminated */
167 } _PACKED acpi_local_sapic;
168 
169 typedef struct acpi_platform_interrupt_source {
170 	uint8	type;					/* 8 = platform interrupt source */
171 	uint8	length;					/* 16 bytes */
172 	uint16	flags;					/* Same as MPS INTI flags. See Table 5-25 in
173 									   ACPI Spec 4.0a or similar */
174 	uint8	interrupt_type;			/* 1 PMI, 2 INIT, 3 Corrected Platform
175 									   Error Interrupt */
176 	uint8	processor_id;			/* processor ID of destination */
177 	uint8	processor_eid;			/* processor EID of destination */
178 	uint8	io_sapic_vector;		/* value that must be used to program the
179 									   vector field of the I/O SAPIC redirection
180 									   entry for entries with PMI type. */
181 	uint32	interrupt;				/* global system interrupt this
182 									   platform interrupt will trigger */
183 	uint32	platform_int_flags;		/* Platform Interrupt Source Flags. See
184 									   Table 5-32 of ACPI Spec 4.0a for desc */
185 } _PACKED acpi_platform_interrupt_source;
186 
187 typedef struct acpi_local_x2_apic {
188 	uint8	type;					/* 9 = processor local x2APIC */
189 	uint8	length;					/* 16 bytes */
190 	uint16	reserved;				/* reserved (must be zero) */
191 	uint32	x2apic_id;				/* processor's local x2APIC ID */
192 	uint32	flags;					/* 1 = enabled. */
193 	uint32	processor_uid_nr;		/* Matches _UID of a processor when it is a
194 									   number */
195 } _PACKED acpi_local_x2_apic;
196 
197 typedef struct acpi_local_x2_apic_nmi {
198 	uint8	type;					/* 0xA = local x2APIC NMI */
199 	uint8	length;					/* 12 bytes */
200 	uint16	flags;					/* Same as MPS INTI flags. See Table 5-25 in
201 									   ACPI Spec 4.0a or similar */
202 	uint32	acpi_processor_uid;		/* UID corresponding to ID in processor
203 									   device object. 0xFFFFFFFF means
204 									   it applies to all processors */
205 	uint8   local_interrupt;		/* Local x2APIC interrupt input LINTn to
206 									   which NMI is connected */
207 	uint8	reserved1;				/* reserved (must be set to zero) */
208 	uint8	reserved2;				/* reserved (must be set to zero) */
209 	uint8	reserved3;				/* reserved (must be set to zero) */
210 } _PACKED acpi_local_x2_apic_nmi;
211 
212 typedef struct acpi_gic_interface {
213 	uint8 type;
214 	uint8 length;
215 	uint16 reserved1;
216 	uint32 cpu_interface_num;
217 	uint32 acpi_processor_uid;
218 	uint32 flags;
219 	uint32 parking_protocol_ver;
220 	uint32 performance_gsiv;
221 	uint64 parked_address;
222 	uint64 base_address;
223 	uint64 gicv_address;
224 	uint64 gich_address;
225 	uint32 vgic_maintenance_gsiv;
226 	uint64 gicr_address;
227 	uint64 mpidr;
228 	uint8 efficiency_class;
229 	uint8 reserved2;
230 	uint16 spe_overflow_gsiv;
231 } _PACKED acpi_gic_interface;
232 
233 typedef struct acpi_gic_distributor {
234 	uint8 type;
235 	uint8 length;
236 	uint16 reserved1;
237 	uint32 gic_id;
238 	uint64 base_address;
239 	uint32 reserved2;
240 	uint8 gic_version;
241 	uint8 reserved[3];
242 } _PACKED acpi_gic_distributor;
243 
244 typedef struct acpi_gas {
245 	uint8 address_space_id;
246 	uint8 bit_width;
247 	uint8 bit_offset;
248 	uint8 access_size;
249 	uint64 address;
250 } _PACKED acpi_gas;
251 
252 typedef struct acpi_mcfg
253 {
254 	acpi_descriptor_header header;
255 	uint8 reserved[8];
256 } _PACKED acpi_mcfg;
257 
258 typedef struct acpi_mcfg_allocation
259 {
260 	uint64 address;
261 	uint16 pci_segment;
262 	uint8 start_bus_number;
263 	uint8 end_bus_number;
264 	uint32 reserved;
265 } _PACKED acpi_mcfg_allocation;
266 
267 typedef struct acpi_spcr {
268 	acpi_descriptor_header header;
269 	uint32 interface_type;
270 	acpi_gas base_address;
271 	uint8 interrupt_type;
272 	uint8 irq;
273 	uint32 gisv;
274 	uint8 baud;
275 	uint8 parity;
276 	uint8 stop_bits;
277 	uint8 flow_control;
278 	uint8 terminal_type;
279 	uint8 language;
280 	uint16 pci_device_id;
281 	uint16 pci_vendor_id;
282 	uint8 pci_bus_num;
283 	uint8 pci_vendor_num;
284 	uint8 pci_function_num;
285 	uint32 pci_flags;
286 	uint8 pci_segment;
287 	uint32 clock;
288 } _PACKED acpi_spcr;
289 
290 enum {
291 	ACPI_SPCR_INTERFACE_TYPE_16550 = 0,
292 	ACPI_SPCR_INTERFACE_TYPE_PL011 = 3,
293 };
294 
295 
296 /* The following definitions are adapted from acpica/include/acrestyp.h */
297 
298 
299 typedef struct acpi_resource_source
300 {
301 	uint8 index;
302 	uint16 string_length;
303 	char *string_ptr;
304 } _PACKED acpi_resource_source;
305 
306 typedef struct acpi_resource_fixed_memory32 {
307 	uint8 write_protect;
308 	uint32 address;
309 	uint32 address_length;
310 } _PACKED acpi_resource_fixed_memory32;
311 
312 typedef struct acpi_memory_attribute {
313 	uint8 write_protect;
314 	uint8 caching;
315 	uint8 range_type;
316 	uint8 translation;
317 } _PACKED acpi_memory_attribute;
318 
319 typedef struct acpi_io_attribute {
320 	uint8 range_type;
321 	uint8 translation;
322 	uint8 translation_type;
323 	uint8 reserved1;
324 } _PACKED acpi_io_attribute;
325 
326 typedef union acpi_resource_attribute {
327 	acpi_memory_attribute mem;
328 	acpi_io_attribute io;
329 	uint8 type_specific;
330 } acpi_resource_attribute;
331 
332 typedef struct acpi_address16_attribute {
333 	uint16 granularity;
334 	uint16 minimum;
335 	uint16 maximum;
336 	uint16 translation_offset;
337 	uint16 address_length;
338 } _PACKED acpi_address16_attribute;
339 
340 typedef struct acpi_address32_attribute {
341 	uint32 granularity;
342 	uint32 minimum;
343 	uint32 maximum;
344 	uint32 translation_offset;
345 	uint32 address_length;
346 } _PACKED acpi_address32_attribute;
347 
348 typedef struct acpi_address64_attribute {
349 	uint64 granularity;
350 	uint64 minimum;
351 	uint64 maximum;
352 	uint64 translation_offset;
353 	uint64 address_length;
354 } _PACKED acpi_address64_attribute;
355 
356 typedef struct acpi_resource_address {
357 	uint8 resource_type;
358 	uint8 producer_consumer;
359 	uint8 decode;
360 	uint8 minAddress_fixed;
361 	uint8 maxAddress_fixed;
362 	acpi_resource_attribute info;
363 } _PACKED acpi_resource_address;
364 
365 typedef struct acpi_resource_address16 {
366 	uint8 resource_type;
367 	uint8 producer_consumer;
368 	uint8 decode;
369 	uint8 minAddress_fixed;
370 	uint8 maxAddress_fixed;
371 	acpi_resource_attribute info;
372 	acpi_address16_attribute address;
373 	acpi_resource_source resource_source;
374 } _PACKED acpi_resource_address16;
375 
376 typedef struct acpi_resource_address32 {
377 	uint8 resource_type;
378 	uint8 producer_consumer;
379 	uint8 decode;
380 	uint8 minAddress_fixed;
381 	uint8 maxAddress_fixed;
382 	acpi_resource_attribute info;
383 	acpi_address32_attribute address;
384 	acpi_resource_source resource_source;
385 } _PACKED acpi_resource_address32;
386 
387 typedef struct acpi_resource_address64 {
388 	uint8 resource_type;
389 	uint8 producer_consumer;
390 	uint8 decode;
391 	uint8 minAddress_fixed;
392 	uint8 maxAddress_fixed;
393 	acpi_resource_attribute info;
394 	acpi_address64_attribute address;
395 	acpi_resource_source resource_source;
396 } _PACKED acpi_resource_address64;
397 
398 typedef struct acpi_resource_extended_irq {
399 	uint8 producer_consumer;
400 	uint8 triggering;
401 	uint8 polarity;
402 	uint8 shareable;
403 	uint8 wake_capable;
404 	uint8 interrupt_count;
405 	acpi_resource_source resource_source;
406 	uint32 interrupts[1];
407 } _PACKED acpi_resource_extended_irq;
408 
409 typedef union acpi_resource_data {
410 	acpi_resource_fixed_memory32 fixed_memory32;
411 	acpi_resource_address16 address16;
412 	acpi_resource_address32 address32;
413 	acpi_resource_address64 address64;
414 	acpi_resource_extended_irq extended_irq;
415 
416 	acpi_resource_address address;
417 } acpi_resource_data;
418 
419 typedef struct acpi_resource {
420 	uint32 type;
421 	uint32 length;
422 	acpi_resource_data data;
423 } _PACKED acpi_resource;
424 
425 enum {
426 	ACPI_RESOURCE_TYPE_FIXED_MEMORY32 = 10,
427 	ACPI_RESOURCE_TYPE_ADDRESS16 = 11,
428 	ACPI_RESOURCE_TYPE_ADDRESS32 = 12,
429 	ACPI_RESOURCE_TYPE_ADDRESS64 = 13,
430 	ACPI_RESOURCE_TYPE_EXTENDED_IRQ = 15,
431 };
432 
433 
434 #endif	/* _KERNEL_ACPI_H */
435