aboutsummaryrefslogtreecommitdiffstats
path: root/tools/firmware/hvmloader/acpi/acpi2_0.h
blob: b281ec06251d0dc57b5d306f7f90ee23f61a6814 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
/*
 * Copyright (c) 2004, Intel Corporation.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place - Suite 330, Boston, MA 02111-1307 USA.
 *
 */
#ifndef _ACPI_2_0_H_
#define _ACPI_2_0_H_

#include <stdint.h>
#include <xen/xen.h>
#include <xen/hvm/ioreq.h>

#define ASCII32(a,b,c,d)         \
    (((a) <<  0) | ((b) <<  8) | ((c) << 16) | ((d) << 24))
#define ASCII64(a,b,c,d,e,f,g,h) \
    (((uint64_t)ASCII32(a,b,c,d)) | (((uint64_t)ASCII32(e,f,g,h)) << 32))

#pragma pack (1)

/*
 * Common ACPI header.
 */
struct acpi_header {
    uint32_t signature;
    uint32_t length;
    uint8_t  revision;
    uint8_t  checksum;
    char     oem_id[6];
    char     oem_table_id[8];
    uint32_t oem_revision;
    uint32_t creator_id;
    uint32_t creator_revision;
};

#define ACPI_OEM_ID             "Xen"
#define ACPI_OEM_TABLE_ID       "HVM"
#define ACPI_OEM_REVISION       0

#define ACPI_CREATOR_ID         ASCII32('H','V','M','L') /* HVMLoader */
#define ACPI_CREATOR_REVISION   0

/*
 * ACPI 2.0 Generic Address Space definition.
 */
struct acpi_20_generic_address {
    uint8_t  address_space_id;
    uint8_t  register_bit_width;
    uint8_t  register_bit_offset;
    uint8_t  reserved;
    uint64_t address;
};

/*
 * Generic Address Space Address IDs.
 */
#define ACPI_SYSTEM_MEMORY 0
#define ACPI_SYSTEM_IO 1
#define ACPI_PCI_CONFIGURATION_SPACE 2
#define ACPI_EMBEDDED_CONTROLLER 3
#define ACPI_SMBUS 4
#define ACPI_FUNCTIONAL_FIXED_HARDWARE 0x7F

/*
 * Root System Description Pointer Structure in ACPI 1.0.
 */
struct acpi_10_rsdp {
    uint64_t signature;
    uint8_t  checksum;
    char     oem_id[6];
    uint8_t  reserved;
    uint32_t rsdt_address;
};

/*
 * Root System Description Pointer Structure.
 */
struct acpi_20_rsdp {
    uint64_t signature;
    uint8_t  checksum;
    char     oem_id[6];
    uint8_t  revision;
    uint32_t rsdt_address;
    uint32_t length;
    uint64_t xsdt_address;
    uint8_t  extended_checksum;
    uint8_t  reserved[3];
};

/*
 * Root System Description Table (RSDT).
 */
struct acpi_20_rsdt {
    struct acpi_header header;
    uint32_t entry[1];
};

/*
 * Extended System Description Table (XSDT).
 */
struct acpi_20_xsdt {
    struct acpi_header header;
    uint64_t entry[1];
};

/*
 * TCG Hardware Interface Table (TCPA)
 */
struct acpi_20_tcpa {
    struct acpi_header header;
    uint16_t platform_class;
    uint32_t laml;
    uint64_t lasa;
};
#define ACPI_2_0_TCPA_LAML_SIZE (64*1024)

/*
 * Fixed ACPI Description Table Structure (FADT) in ACPI 1.0.
 */
struct acpi_10_fadt {
    struct acpi_header header;
    uint32_t firmware_ctrl;
    uint32_t dsdt;
    uint8_t  reserved0;
    uint8_t  preferred_pm_profile;
    uint16_t sci_int;
    uint32_t smi_cmd;
    uint8_t  acpi_enable;
    uint8_t  acpi_disable;
    uint8_t  s4bios_req;
    uint8_t  pstate_cnt;
    uint32_t pm1a_evt_blk;
    uint32_t pm1b_evt_blk;
    uint32_t pm1a_cnt_blk;
    uint32_t pm1b_cnt_blk;
    uint32_t pm2_cnt_blk;
    uint32_t pm_tmr_blk;
    uint32_t gpe0_blk;
    uint32_t gpe1_blk;
    uint8_t  pm1_evt_len;
    uint8_t  pm1_cnt_len;
    uint8_t  pm2_cnt_len;
    uint8_t  pm_tmr_len;
    uint8_t  gpe0_blk_len;
    uint8_t  gpe1_blk_len;
    uint8_t  gpe1_base;
    uint8_t  cst_cnt;
    uint16_t p_lvl2_lat;
    uint16_t p_lvl3_lat;
    uint16_t flush_size;
    uint16_t flush_stride;
    uint8_t  duty_offset;
    uint8_t  duty_width;
    uint8_t  day_alrm;
    uint8_t  mon_alrm;
    uint8_t  century;
    uint16_t iapc_boot_arch;
    uint8_t  reserved1;
    uint32_t flags;
};

/*
 * Fixed ACPI Description Table Structure (FADT).
 */
struct acpi_20_fadt {
    struct acpi_header header;
    uint32_t firmware_ctrl;
    uint32_t dsdt;
    uint8_t  reserved0;
    uint8_t  preferred_pm_profile;
    uint16_t sci_int;
    uint32_t smi_cmd;
    uint8_t  acpi_enable;
    uint8_t  acpi_disable;
    uint8_t  s4bios_req;
    uint8_t  pstate_cnt;
    uint32_t pm1a_evt_blk;
    uint32_t pm1b_evt_blk;
    uint32_t pm1a_cnt_blk;
    uint32_t pm1b_cnt_blk;
    uint32_t pm2_cnt_blk;
    uint32_t pm_tmr_blk;
    uint32_t gpe0_blk;
    uint32_t gpe1_blk;
    uint8_t  pm1_evt_len;
    uint8_t  pm1_cnt_len;
    uint8_t  pm2_cnt_len;
    uint8_t  pm_tmr_len;
    uint8_t  gpe0_blk_len;
    uint8_t  gpe1_blk_len;
    uint8_t  gpe1_base;
    uint8_t  cst_cnt;
    uint16_t p_lvl2_lat;
    uint16_t p_lvl3_lat;
    uint16_t flush_size;
    uint16_t flush_stride;
    uint8_t  duty_offset;
    uint8_t  duty_width;
    uint8_t  day_alrm;
    uint8_t  mon_alrm;
    uint8_t  century;
    uint16_t iapc_boot_arch;
    uint8_t  reserved1;
    uint32_t flags;
    struct acpi_20_generic_address reset_reg;
    uint8_t  reset_value;
    uint8_t  reserved2[3];
    uint64_t x_firmware_ctrl;
    uint64_t x_dsdt;
    struct acpi_20_generic_address x_pm1a_evt_blk;
    struct acpi_20_generic_address x_pm1b_evt_blk;
    struct acpi_20_generic_address x_pm1a_cnt_blk;
    struct acpi_20_generic_address x_pm1b_cnt_blk;
    struct acpi_20_generic_address x_pm2_cnt_blk;
    struct acpi_20_generic_address x_pm_tmr_blk;
    struct acpi_20_generic_address x_gpe0_blk;
    struct acpi_20_generic_address x_gpe1_blk;
};

/*
 * FADT Boot Architecture Flags.
 */
#define ACPI_LEGACY_DEVICES (1 << 0)
#define ACPI_8042           (1 << 1)

/*
 * FADT Fixed Feature Flags.
 */
#define ACPI_WBINVD         (1 << 0)
#define ACPI_WBINVD_FLUSH   (1 << 1)
#define ACPI_PROC_C1        (1 << 2)
#define ACPI_P_LVL2_UP      (1 << 3)
#define ACPI_PWR_BUTTON     (1 << 4)
#define ACPI_SLP_BUTTON     (1 << 5)
#define ACPI_FIX_RTC        (1 << 6)
#define ACPI_RTC_S4         (1 << 7)
#define ACPI_TMR_VAL_EXT    (1 << 8)
#define ACPI_DCK_CAP        (1 << 9)
#define ACPI_RESET_REG_SUP  (1 << 10)
#define ACPI_SEALED_CASE    (1 << 11)
#define ACPI_HEADLESS       (1 << 12)
#define ACPI_CPU_SW_SLP     (1 << 13)
#define ACPI_USE_PLATFORM_CLOCK (1 << 15)

/* PM1 Control Register Bits */
#define ACPI_PM1C_SCI_EN    (1 << 0)

/*
 * Firmware ACPI Control Structure (FACS).
 */
struct acpi_20_facs {
    uint32_t signature;
    uint32_t length;
    uint32_t hardware_signature;
    uint32_t firmware_waking_vector;
    uint32_t global_lock;
    uint32_t flags;
    uint64_t x_firmware_waking_vector;
    uint8_t  version;
    uint8_t  reserved[31];
};

#define ACPI_2_0_FACS_VERSION 0x01

/*
 * Multiple APIC Description Table header definition (MADT).
 */
struct acpi_20_madt {
    struct acpi_header header;
    uint32_t lapic_addr;
    uint32_t flags;
};


/*
 * HPET Description Table
 */
struct acpi_20_hpet {
    struct acpi_header header;
    uint32_t           timer_block_id;
    struct acpi_20_generic_address addr;
    uint8_t            hpet_number;
    uint16_t           min_tick;
    uint8_t            page_protect;
};
#define ACPI_HPET_ADDRESS 0xFED00000UL

/*
 * WAET Description Table
 */
struct acpi_20_waet {
    struct acpi_header header;
    uint32_t           flags;
};

/*
 * Multiple APIC Flags.
 */
#define ACPI_PCAT_COMPAT (1 << 0)

/*
 * Multiple APIC Description Table APIC structure types.
 */
#define ACPI_PROCESSOR_LOCAL_APIC           0x00
#define ACPI_IO_APIC                        0x01
#define ACPI_INTERRUPT_SOURCE_OVERRIDE      0x02
#define ACPI_NON_MASKABLE_INTERRUPT_SOURCE  0x03
#define ACPI_LOCAL_APIC_NMI                 0x04
#define ACPI_LOCAL_APIC_ADDRESS_OVERRIDE    0x05
#define ACPI_IO_SAPIC                       0x06
#define ACPI_PROCESSOR_LOCAL_SAPIC          0x07
#define ACPI_PLATFORM_INTERRUPT_SOURCES     0x08

/*
 * APIC Structure Definitions.
 */

/*
 * Processor Local APIC Structure Definition.
 */
struct acpi_20_madt_lapic {
    uint8_t  type;
    uint8_t  length;
    uint8_t  acpi_processor_id;
    uint8_t  apic_id;
    uint32_t flags;
};

/*
 * Local APIC Flags.  All other bits are reserved and must be 0.
 */
#define ACPI_LOCAL_APIC_ENABLED (1 << 0)

/*
 * IO APIC Structure.
 */
struct acpi_20_madt_ioapic {
    uint8_t  type;
    uint8_t  length;
    uint8_t  ioapic_id;
    uint8_t  reserved;
    uint32_t ioapic_addr;
    uint32_t gsi_base;
};

struct acpi_20_madt_intsrcovr {
    uint8_t  type;
    uint8_t  length;
    uint8_t  bus;
    uint8_t  source;
    uint32_t gsi;
    uint16_t flags;
};

/*
 * Table Signatures.
 */
#define ACPI_2_0_RSDP_SIGNATURE ASCII64('R','S','D',' ','P','T','R',' ')
#define ACPI_2_0_FACS_SIGNATURE ASCII32('F','A','C','S')
#define ACPI_2_0_FADT_SIGNATURE ASCII32('F','A','C','P')
#define ACPI_2_0_MADT_SIGNATURE ASCII32('A','P','I','C')
#define ACPI_2_0_RSDT_SIGNATURE ASCII32('R','S','D','T')
#define ACPI_2_0_XSDT_SIGNATURE ASCII32('X','S','D','T')
#define ACPI_2_0_TCPA_SIGNATURE ASCII32('T','C','P','A')
#define ACPI_2_0_HPET_SIGNATURE ASCII32('H','P','E','T')
#define ACPI_2_0_WAET_SIGNATURE ASCII32('W','A','E','T')

/*
 * Table revision numbers.
 */
#define ACPI_2_0_RSDP_REVISION 0x02
#define ACPI_2_0_FADT_REVISION 0x04
#define ACPI_2_0_MADT_REVISION 0x02
#define ACPI_2_0_RSDT_REVISION 0x01
#define ACPI_2_0_XSDT_REVISION 0x01
#define ACPI_2_0_TCPA_REVISION 0x02
#define ACPI_2_0_HPET_REVISION 0x01
#define ACPI_2_0_WAET_REVISION 0x01
#define ACPI_1_0_FADT_REVISION 0x01

#pragma pack ()

struct acpi_config {
    unsigned char *dsdt_anycpu;
    int dsdt_anycpu_len;
    unsigned char *dsdt_15cpu;
    int dsdt_15cpu_len;
};

void acpi_build_tables(struct acpi_config *config, unsigned int physical);

#endif /* _ACPI_2_0_H_ */

/*
 * Local variables:
 * mode: C
 * c-set-style: "BSD"
 * c-basic-offset: 4
 * tab-width: 4
 * indent-tabs-mode: nil
 * End:
 */