1 /*
2  * Copyright (c) 2004, Intel Corporation.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published
6  * by the Free Software Foundation; version 2.1 only. with the special
7  * exception on linking described in file LICENSE.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU Lesser General Public License for more details.
13  */
14 #ifndef _ACPI_2_0_H_
15 #define _ACPI_2_0_H_
16 
17 #include <stdint.h>
18 #include <xen/xen.h>
19 #include <xen/hvm/ioreq.h>
20 
21 #define ASCII32(a,b,c,d)         \
22     (((a) <<  0) | ((b) <<  8) | ((c) << 16) | ((d) << 24))
23 #define ASCII64(a,b,c,d,e,f,g,h) \
24     (((uint64_t)ASCII32(a,b,c,d)) | (((uint64_t)ASCII32(e,f,g,h)) << 32))
25 
26 #pragma pack (1)
27 
28 /*
29  * Common ACPI header.
30  */
31 struct acpi_header {
32     uint32_t signature;
33     uint32_t length;
34     uint8_t  revision;
35     uint8_t  checksum;
36     char     oem_id[6];
37     char     oem_table_id[8];
38     uint32_t oem_revision;
39     uint32_t creator_id;
40     uint32_t creator_revision;
41 };
42 
43 #define ACPI_OEM_ID             "Xen"
44 #define ACPI_OEM_TABLE_ID       "HVM"
45 #define ACPI_OEM_REVISION       0
46 
47 #define ACPI_CREATOR_ID         ASCII32('H','V','M','L') /* HVMLoader */
48 #define ACPI_CREATOR_REVISION   0
49 
50 /*
51  * ACPI 2.0 Generic Address Space definition.
52  */
53 struct acpi_20_generic_address {
54     uint8_t  address_space_id;
55     uint8_t  register_bit_width;
56     uint8_t  register_bit_offset;
57     uint8_t  reserved;
58     uint64_t address;
59 };
60 
61 /*
62  * Generic Address Space Address IDs.
63  */
64 #define ACPI_SYSTEM_MEMORY 0
65 #define ACPI_SYSTEM_IO 1
66 #define ACPI_PCI_CONFIGURATION_SPACE 2
67 #define ACPI_EMBEDDED_CONTROLLER 3
68 #define ACPI_SMBUS 4
69 #define ACPI_FUNCTIONAL_FIXED_HARDWARE 0x7F
70 
71 /*
72  * Root System Description Pointer Structure in ACPI 1.0.
73  */
74 struct acpi_10_rsdp {
75     uint64_t signature;
76     uint8_t  checksum;
77     char     oem_id[6];
78     uint8_t  reserved;
79     uint32_t rsdt_address;
80 };
81 
82 /*
83  * Root System Description Pointer Structure.
84  */
85 struct acpi_20_rsdp {
86     uint64_t signature;
87     uint8_t  checksum;
88     char     oem_id[6];
89     uint8_t  revision;
90     uint32_t rsdt_address;
91     uint32_t length;
92     uint64_t xsdt_address;
93     uint8_t  extended_checksum;
94     uint8_t  reserved[3];
95 };
96 
97 /*
98  * Root System Description Table (RSDT).
99  */
100 struct acpi_20_rsdt {
101     struct acpi_header header;
102     uint32_t entry[1];
103 };
104 
105 /*
106  * Extended System Description Table (XSDT).
107  */
108 struct acpi_20_xsdt {
109     struct acpi_header header;
110     uint64_t entry[1];
111 };
112 
113 /*
114  * TCG Hardware Interface Table (TCPA)
115  */
116 struct acpi_20_tcpa {
117     struct acpi_header header;
118     uint16_t platform_class;
119     uint32_t laml;
120     uint64_t lasa;
121 };
122 #define ACPI_2_0_TCPA_LAML_SIZE (64*1024)
123 
124 /*
125  * Fixed ACPI Description Table Structure (FADT) in ACPI 1.0.
126  */
127 struct acpi_10_fadt {
128     struct acpi_header header;
129     uint32_t firmware_ctrl;
130     uint32_t dsdt;
131     uint8_t  reserved0;
132     uint8_t  preferred_pm_profile;
133     uint16_t sci_int;
134     uint32_t smi_cmd;
135     uint8_t  acpi_enable;
136     uint8_t  acpi_disable;
137     uint8_t  s4bios_req;
138     uint8_t  pstate_cnt;
139     uint32_t pm1a_evt_blk;
140     uint32_t pm1b_evt_blk;
141     uint32_t pm1a_cnt_blk;
142     uint32_t pm1b_cnt_blk;
143     uint32_t pm2_cnt_blk;
144     uint32_t pm_tmr_blk;
145     uint32_t gpe0_blk;
146     uint32_t gpe1_blk;
147     uint8_t  pm1_evt_len;
148     uint8_t  pm1_cnt_len;
149     uint8_t  pm2_cnt_len;
150     uint8_t  pm_tmr_len;
151     uint8_t  gpe0_blk_len;
152     uint8_t  gpe1_blk_len;
153     uint8_t  gpe1_base;
154     uint8_t  cst_cnt;
155     uint16_t p_lvl2_lat;
156     uint16_t p_lvl3_lat;
157     uint16_t flush_size;
158     uint16_t flush_stride;
159     uint8_t  duty_offset;
160     uint8_t  duty_width;
161     uint8_t  day_alrm;
162     uint8_t  mon_alrm;
163     uint8_t  century;
164     uint16_t iapc_boot_arch;
165     uint8_t  reserved1;
166     uint32_t flags;
167 };
168 
169 /*
170  * Fixed ACPI Description Table Structure (FADT).
171  */
172 struct acpi_fadt {
173     struct acpi_header header;
174     uint32_t firmware_ctrl;
175     uint32_t dsdt;
176     uint8_t  reserved0;
177     uint8_t  preferred_pm_profile;
178     uint16_t sci_int;
179     uint32_t smi_cmd;
180     uint8_t  acpi_enable;
181     uint8_t  acpi_disable;
182     uint8_t  s4bios_req;
183     uint8_t  pstate_cnt;
184     uint32_t pm1a_evt_blk;
185     uint32_t pm1b_evt_blk;
186     uint32_t pm1a_cnt_blk;
187     uint32_t pm1b_cnt_blk;
188     uint32_t pm2_cnt_blk;
189     uint32_t pm_tmr_blk;
190     uint32_t gpe0_blk;
191     uint32_t gpe1_blk;
192     uint8_t  pm1_evt_len;
193     uint8_t  pm1_cnt_len;
194     uint8_t  pm2_cnt_len;
195     uint8_t  pm_tmr_len;
196     uint8_t  gpe0_blk_len;
197     uint8_t  gpe1_blk_len;
198     uint8_t  gpe1_base;
199     uint8_t  cst_cnt;
200     uint16_t p_lvl2_lat;
201     uint16_t p_lvl3_lat;
202     uint16_t flush_size;
203     uint16_t flush_stride;
204     uint8_t  duty_offset;
205     uint8_t  duty_width;
206     uint8_t  day_alrm;
207     uint8_t  mon_alrm;
208     uint8_t  century;
209     uint16_t iapc_boot_arch;
210     uint8_t  reserved1;
211     uint32_t flags;
212     struct acpi_20_generic_address reset_reg;
213     uint8_t  reset_value;
214     uint8_t  reserved2[3];
215     uint64_t x_firmware_ctrl;
216     uint64_t x_dsdt;
217     struct acpi_20_generic_address x_pm1a_evt_blk;
218     struct acpi_20_generic_address x_pm1b_evt_blk;
219     struct acpi_20_generic_address x_pm1a_cnt_blk;
220     struct acpi_20_generic_address x_pm1b_cnt_blk;
221     struct acpi_20_generic_address x_pm2_cnt_blk;
222     struct acpi_20_generic_address x_pm_tmr_blk;
223     struct acpi_20_generic_address x_gpe0_blk;
224     struct acpi_20_generic_address x_gpe1_blk;
225     /* Only available starting from FADT revision 5. */
226     struct acpi_20_generic_address sleep_control;
227     struct acpi_20_generic_address sleep_status;
228 };
229 
230 /*
231  * FADT Boot Architecture Flags.
232  */
233 #define ACPI_FADT_LEGACY_DEVICES    (1 << 0)
234 #define ACPI_FADT_8042              (1 << 1)
235 #define ACPI_FADT_NO_VGA            (1 << 2)
236 #define ACPI_FADT_NO_CMOS_RTC       (1 << 5)
237 
238 /*
239  * FADT Fixed Feature Flags.
240  */
241 #define ACPI_WBINVD         (1 << 0)
242 #define ACPI_WBINVD_FLUSH   (1 << 1)
243 #define ACPI_PROC_C1        (1 << 2)
244 #define ACPI_P_LVL2_UP      (1 << 3)
245 #define ACPI_PWR_BUTTON     (1 << 4)
246 #define ACPI_SLP_BUTTON     (1 << 5)
247 #define ACPI_FIX_RTC        (1 << 6)
248 #define ACPI_RTC_S4         (1 << 7)
249 #define ACPI_TMR_VAL_EXT    (1 << 8)
250 #define ACPI_DCK_CAP        (1 << 9)
251 #define ACPI_RESET_REG_SUP  (1 << 10)
252 #define ACPI_SEALED_CASE    (1 << 11)
253 #define ACPI_HEADLESS       (1 << 12)
254 #define ACPI_CPU_SW_SLP     (1 << 13)
255 #define ACPI_USE_PLATFORM_CLOCK (1 << 15)
256 
257 /* PM1 Control Register Bits */
258 #define ACPI_PM1C_SCI_EN    (1 << 0)
259 
260 /*
261  * Firmware ACPI Control Structure (FACS).
262  */
263 struct acpi_20_facs {
264     uint32_t signature;
265     uint32_t length;
266     uint32_t hardware_signature;
267     uint32_t firmware_waking_vector;
268     uint32_t global_lock;
269     uint32_t flags;
270     uint64_t x_firmware_waking_vector;
271     uint8_t  version;
272     uint8_t  reserved[31];
273 };
274 
275 #define ACPI_2_0_FACS_VERSION 0x01
276 
277 /*
278  * Multiple APIC Description Table header definition (MADT).
279  */
280 struct acpi_20_madt {
281     struct acpi_header header;
282     uint32_t lapic_addr;
283     uint32_t flags;
284 };
285 
286 
287 /*
288  * HPET Description Table
289  */
290 struct acpi_20_hpet {
291     struct acpi_header header;
292     uint32_t           timer_block_id;
293     struct acpi_20_generic_address addr;
294     uint8_t            hpet_number;
295     uint16_t           min_tick;
296     uint8_t            page_protect;
297 };
298 #define ACPI_HPET_ADDRESS 0xFED00000UL
299 
300 /*
301  * WAET Description Table
302  */
303 struct acpi_20_waet {
304     struct acpi_header header;
305     uint32_t           flags;
306 };
307 
308 /*
309  * Multiple APIC Flags.
310  */
311 #define ACPI_PCAT_COMPAT (1 << 0)
312 
313 /*
314  * Multiple APIC Description Table APIC structure types.
315  */
316 #define ACPI_PROCESSOR_LOCAL_APIC           0x00
317 #define ACPI_IO_APIC                        0x01
318 #define ACPI_INTERRUPT_SOURCE_OVERRIDE      0x02
319 #define ACPI_NON_MASKABLE_INTERRUPT_SOURCE  0x03
320 #define ACPI_LOCAL_APIC_NMI                 0x04
321 #define ACPI_LOCAL_APIC_ADDRESS_OVERRIDE    0x05
322 #define ACPI_IO_SAPIC                       0x06
323 #define ACPI_PROCESSOR_LOCAL_SAPIC          0x07
324 #define ACPI_PLATFORM_INTERRUPT_SOURCES     0x08
325 
326 /*
327  * APIC Structure Definitions.
328  */
329 
330 /*
331  * Processor Local APIC Structure Definition.
332  */
333 struct acpi_20_madt_lapic {
334     uint8_t  type;
335     uint8_t  length;
336     uint8_t  acpi_processor_id;
337     uint8_t  apic_id;
338     uint32_t flags;
339 };
340 
341 /*
342  * Local APIC Flags.  All other bits are reserved and must be 0.
343  */
344 #define ACPI_LOCAL_APIC_ENABLED (1 << 0)
345 
346 /*
347  * IO APIC Structure.
348  */
349 struct acpi_20_madt_ioapic {
350     uint8_t  type;
351     uint8_t  length;
352     uint8_t  ioapic_id;
353     uint8_t  reserved;
354     uint32_t ioapic_addr;
355     uint32_t gsi_base;
356 };
357 
358 struct acpi_20_madt_intsrcovr {
359     uint8_t  type;
360     uint8_t  length;
361     uint8_t  bus;
362     uint8_t  source;
363     uint32_t gsi;
364     uint16_t flags;
365 };
366 
367 /*
368  * System Resource Affinity Table header definition (SRAT)
369  */
370 struct acpi_20_srat {
371     struct acpi_header header;
372     uint32_t table_revision;
373     uint32_t reserved2[2];
374 };
375 
376 #define ACPI_SRAT_TABLE_REVISION 1
377 
378 /*
379  * System Resource Affinity Table structure types.
380  */
381 #define ACPI_PROCESSOR_AFFINITY 0x0
382 #define ACPI_MEMORY_AFFINITY    0x1
383 struct acpi_20_srat_processor {
384     uint8_t type;
385     uint8_t length;
386     uint8_t domain;
387     uint8_t apic_id;
388     uint32_t flags;
389     uint8_t sapic_id;
390     uint8_t domain_hi[3];
391     uint32_t reserved;
392 };
393 
394 /*
395  * Local APIC Affinity Flags.  All other bits are reserved and must be 0.
396  */
397 #define ACPI_LOCAL_APIC_AFFIN_ENABLED (1 << 0)
398 
399 struct acpi_20_srat_memory {
400     uint8_t type;
401     uint8_t length;
402     uint32_t domain;
403     uint16_t reserved;
404     uint64_t base_address;
405     uint64_t mem_length;
406     uint32_t reserved2;
407     uint32_t flags;
408     uint64_t reserved3;
409 };
410 
411 /*
412  * Memory Affinity Flags.  All other bits are reserved and must be 0.
413  */
414 #define ACPI_MEM_AFFIN_ENABLED (1 << 0)
415 #define ACPI_MEM_AFFIN_HOTPLUGGABLE (1 << 1)
416 #define ACPI_MEM_AFFIN_NONVOLATILE (1 << 2)
417 
418 struct acpi_20_slit {
419     struct acpi_header header;
420     uint64_t localities;
421     uint8_t entry[0];
422 };
423 
424 /*
425  * Table Signatures.
426  */
427 #define ACPI_2_0_RSDP_SIGNATURE ASCII64('R','S','D',' ','P','T','R',' ')
428 #define ACPI_2_0_FACS_SIGNATURE ASCII32('F','A','C','S')
429 #define ACPI_FADT_SIGNATURE     ASCII32('F','A','C','P')
430 #define ACPI_2_0_MADT_SIGNATURE ASCII32('A','P','I','C')
431 #define ACPI_2_0_RSDT_SIGNATURE ASCII32('R','S','D','T')
432 #define ACPI_2_0_XSDT_SIGNATURE ASCII32('X','S','D','T')
433 #define ACPI_2_0_TCPA_SIGNATURE ASCII32('T','C','P','A')
434 #define ACPI_2_0_HPET_SIGNATURE ASCII32('H','P','E','T')
435 #define ACPI_2_0_WAET_SIGNATURE ASCII32('W','A','E','T')
436 #define ACPI_2_0_SRAT_SIGNATURE ASCII32('S','R','A','T')
437 #define ACPI_2_0_SLIT_SIGNATURE ASCII32('S','L','I','T')
438 
439 /*
440  * Table revision numbers.
441  */
442 #define ACPI_2_0_RSDP_REVISION 0x02
443 #define ACPI_2_0_MADT_REVISION 0x02
444 #define ACPI_2_0_RSDT_REVISION 0x01
445 #define ACPI_2_0_XSDT_REVISION 0x01
446 #define ACPI_2_0_TCPA_REVISION 0x02
447 #define ACPI_2_0_HPET_REVISION 0x01
448 #define ACPI_2_0_WAET_REVISION 0x01
449 #define ACPI_1_0_FADT_REVISION 0x01
450 #define ACPI_2_0_SRAT_REVISION 0x01
451 #define ACPI_2_0_SLIT_REVISION 0x01
452 
453 #pragma pack ()
454 
455 #endif /* _ACPI_2_0_H_ */
456 
457 /*
458  * Local variables:
459  * mode: C
460  * c-file-style: "BSD"
461  * c-basic-offset: 4
462  * tab-width: 4
463  * indent-tabs-mode: nil
464  * End:
465  */
466