Kevin O'Connor | 84ad59a | 2008-07-04 05:47:26 -0400 | [diff] [blame] | 1 | // Support for generating ACPI tables (on emulators) |
Kevin O'Connor | 276d4a9 | 2008-06-11 22:47:01 -0400 | [diff] [blame] | 2 | // |
Kevin O'Connor | e2074bf | 2010-08-03 21:30:03 -0400 | [diff] [blame] | 3 | // Copyright (C) 2008-2010 Kevin O'Connor <kevin@koconnor.net> |
Kevin O'Connor | 276d4a9 | 2008-06-11 22:47:01 -0400 | [diff] [blame] | 4 | // Copyright (C) 2006 Fabrice Bellard |
| 5 | // |
Kevin O'Connor | b1b7c2a | 2009-01-15 20:52:58 -0500 | [diff] [blame] | 6 | // This file may be distributed under the terms of the GNU LGPLv3 license. |
Kevin O'Connor | 276d4a9 | 2008-06-11 22:47:01 -0400 | [diff] [blame] | 7 | |
| 8 | #include "acpi.h" // struct rsdp_descriptor |
| 9 | #include "util.h" // memcpy |
Kevin O'Connor | 0cd7005 | 2011-07-02 14:04:19 -0400 | [diff] [blame] | 10 | #include "pci.h" // pci_find_init_device |
Kevin O'Connor | 9521e26 | 2008-07-04 13:04:29 -0400 | [diff] [blame] | 11 | #include "biosvar.h" // GET_EBDA |
Kevin O'Connor | 2ed2f58 | 2008-11-08 15:53:36 -0500 | [diff] [blame] | 12 | #include "pci_ids.h" // PCI_VENDOR_ID_INTEL |
| 13 | #include "pci_regs.h" // PCI_INTERRUPT_LINE |
Kevin O'Connor | cc6dc46 | 2009-10-08 21:18:41 -0400 | [diff] [blame] | 14 | #include "paravirt.h" |
Kevin O'Connor | 276d4a9 | 2008-06-11 22:47:01 -0400 | [diff] [blame] | 15 | |
| 16 | /****************************************************/ |
| 17 | /* ACPI tables init */ |
| 18 | |
| 19 | /* Table structure from Linux kernel (the ACPI tables are under the |
| 20 | BSD license) */ |
| 21 | |
Kevin O'Connor | 276d4a9 | 2008-06-11 22:47:01 -0400 | [diff] [blame] | 22 | struct acpi_table_header /* ACPI common table header */ |
| 23 | { |
Kevin O'Connor | d10e444 | 2009-03-01 12:41:20 -0500 | [diff] [blame] | 24 | ACPI_TABLE_HEADER_DEF |
Kevin O'Connor | e97ca7b | 2009-06-21 09:10:28 -0400 | [diff] [blame] | 25 | } PACKED; |
Kevin O'Connor | 276d4a9 | 2008-06-11 22:47:01 -0400 | [diff] [blame] | 26 | |
| 27 | /* |
| 28 | * ACPI 1.0 Root System Description Table (RSDT) |
| 29 | */ |
Kevin O'Connor | 9967ab7 | 2008-12-18 21:57:33 -0500 | [diff] [blame] | 30 | #define RSDT_SIGNATURE 0x54445352 // RSDT |
Kevin O'Connor | 276d4a9 | 2008-06-11 22:47:01 -0400 | [diff] [blame] | 31 | struct rsdt_descriptor_rev1 |
| 32 | { |
Kevin O'Connor | d10e444 | 2009-03-01 12:41:20 -0500 | [diff] [blame] | 33 | ACPI_TABLE_HEADER_DEF /* ACPI common table header */ |
Kevin O'Connor | a9242a2 | 2009-10-07 19:42:07 -0400 | [diff] [blame] | 34 | u32 table_offset_entry[0]; /* Array of pointers to other */ |
Kevin O'Connor | d10e444 | 2009-03-01 12:41:20 -0500 | [diff] [blame] | 35 | /* ACPI tables */ |
Kevin O'Connor | e97ca7b | 2009-06-21 09:10:28 -0400 | [diff] [blame] | 36 | } PACKED; |
Kevin O'Connor | 276d4a9 | 2008-06-11 22:47:01 -0400 | [diff] [blame] | 37 | |
| 38 | /* |
| 39 | * ACPI 1.0 Firmware ACPI Control Structure (FACS) |
| 40 | */ |
Kevin O'Connor | 9967ab7 | 2008-12-18 21:57:33 -0500 | [diff] [blame] | 41 | #define FACS_SIGNATURE 0x53434146 // FACS |
Kevin O'Connor | 276d4a9 | 2008-06-11 22:47:01 -0400 | [diff] [blame] | 42 | struct facs_descriptor_rev1 |
| 43 | { |
Kevin O'Connor | d10e444 | 2009-03-01 12:41:20 -0500 | [diff] [blame] | 44 | u32 signature; /* ACPI Signature */ |
| 45 | u32 length; /* Length of structure, in bytes */ |
| 46 | u32 hardware_signature; /* Hardware configuration signature */ |
| 47 | u32 firmware_waking_vector; /* ACPI OS waking vector */ |
| 48 | u32 global_lock; /* Global Lock */ |
| 49 | u32 S4bios_f : 1; /* Indicates if S4BIOS support is present */ |
| 50 | u32 reserved1 : 31; /* Must be 0 */ |
| 51 | u8 resverved3 [40]; /* Reserved - must be zero */ |
Kevin O'Connor | e97ca7b | 2009-06-21 09:10:28 -0400 | [diff] [blame] | 52 | } PACKED; |
Kevin O'Connor | 276d4a9 | 2008-06-11 22:47:01 -0400 | [diff] [blame] | 53 | |
| 54 | |
| 55 | /* |
Kevin O'Connor | 276d4a9 | 2008-06-11 22:47:01 -0400 | [diff] [blame] | 56 | * MADT values and structures |
| 57 | */ |
| 58 | |
| 59 | /* Values for MADT PCATCompat */ |
| 60 | |
| 61 | #define DUAL_PIC 0 |
| 62 | #define MULTIPLE_APIC 1 |
| 63 | |
| 64 | |
| 65 | /* Master MADT */ |
| 66 | |
Kevin O'Connor | 9967ab7 | 2008-12-18 21:57:33 -0500 | [diff] [blame] | 67 | #define APIC_SIGNATURE 0x43495041 // APIC |
Kevin O'Connor | 276d4a9 | 2008-06-11 22:47:01 -0400 | [diff] [blame] | 68 | struct multiple_apic_table |
| 69 | { |
Kevin O'Connor | d10e444 | 2009-03-01 12:41:20 -0500 | [diff] [blame] | 70 | ACPI_TABLE_HEADER_DEF /* ACPI common table header */ |
| 71 | u32 local_apic_address; /* Physical address of local APIC */ |
Kevin O'Connor | 276d4a9 | 2008-06-11 22:47:01 -0400 | [diff] [blame] | 72 | #if 0 |
Kevin O'Connor | d10e444 | 2009-03-01 12:41:20 -0500 | [diff] [blame] | 73 | u32 PCATcompat : 1; /* A one indicates system also has dual 8259s */ |
| 74 | u32 reserved1 : 31; |
Kevin O'Connor | 276d4a9 | 2008-06-11 22:47:01 -0400 | [diff] [blame] | 75 | #else |
Kevin O'Connor | d10e444 | 2009-03-01 12:41:20 -0500 | [diff] [blame] | 76 | u32 flags; |
Kevin O'Connor | 276d4a9 | 2008-06-11 22:47:01 -0400 | [diff] [blame] | 77 | #endif |
Kevin O'Connor | e97ca7b | 2009-06-21 09:10:28 -0400 | [diff] [blame] | 78 | } PACKED; |
Kevin O'Connor | 276d4a9 | 2008-06-11 22:47:01 -0400 | [diff] [blame] | 79 | |
| 80 | |
Kevin O'Connor | 590e554 | 2009-10-08 22:09:02 -0400 | [diff] [blame] | 81 | /* Values for Type in APIC sub-headers */ |
Kevin O'Connor | 276d4a9 | 2008-06-11 22:47:01 -0400 | [diff] [blame] | 82 | |
| 83 | #define APIC_PROCESSOR 0 |
| 84 | #define APIC_IO 1 |
| 85 | #define APIC_XRUPT_OVERRIDE 2 |
| 86 | #define APIC_NMI 3 |
| 87 | #define APIC_LOCAL_NMI 4 |
| 88 | #define APIC_ADDRESS_OVERRIDE 5 |
| 89 | #define APIC_IO_SAPIC 6 |
| 90 | #define APIC_LOCAL_SAPIC 7 |
| 91 | #define APIC_XRUPT_SOURCE 8 |
| 92 | #define APIC_RESERVED 9 /* 9 and greater are reserved */ |
| 93 | |
| 94 | /* |
| 95 | * MADT sub-structures (Follow MULTIPLE_APIC_DESCRIPTION_TABLE) |
| 96 | */ |
Kevin O'Connor | 590e554 | 2009-10-08 22:09:02 -0400 | [diff] [blame] | 97 | #define ACPI_SUB_HEADER_DEF /* Common ACPI sub-structure header */\ |
Kevin O'Connor | d10e444 | 2009-03-01 12:41:20 -0500 | [diff] [blame] | 98 | u8 type; \ |
| 99 | u8 length; |
Kevin O'Connor | 276d4a9 | 2008-06-11 22:47:01 -0400 | [diff] [blame] | 100 | |
| 101 | /* Sub-structures for MADT */ |
| 102 | |
| 103 | struct madt_processor_apic |
| 104 | { |
Kevin O'Connor | 590e554 | 2009-10-08 22:09:02 -0400 | [diff] [blame] | 105 | ACPI_SUB_HEADER_DEF |
Kevin O'Connor | d10e444 | 2009-03-01 12:41:20 -0500 | [diff] [blame] | 106 | u8 processor_id; /* ACPI processor id */ |
| 107 | u8 local_apic_id; /* Processor's local APIC id */ |
Kevin O'Connor | 276d4a9 | 2008-06-11 22:47:01 -0400 | [diff] [blame] | 108 | #if 0 |
Kevin O'Connor | d10e444 | 2009-03-01 12:41:20 -0500 | [diff] [blame] | 109 | u32 processor_enabled: 1; /* Processor is usable if set */ |
| 110 | u32 reserved2 : 31; /* Reserved, must be zero */ |
Kevin O'Connor | 276d4a9 | 2008-06-11 22:47:01 -0400 | [diff] [blame] | 111 | #else |
Kevin O'Connor | d10e444 | 2009-03-01 12:41:20 -0500 | [diff] [blame] | 112 | u32 flags; |
Kevin O'Connor | 276d4a9 | 2008-06-11 22:47:01 -0400 | [diff] [blame] | 113 | #endif |
Kevin O'Connor | e97ca7b | 2009-06-21 09:10:28 -0400 | [diff] [blame] | 114 | } PACKED; |
Kevin O'Connor | 276d4a9 | 2008-06-11 22:47:01 -0400 | [diff] [blame] | 115 | |
| 116 | struct madt_io_apic |
| 117 | { |
Kevin O'Connor | 590e554 | 2009-10-08 22:09:02 -0400 | [diff] [blame] | 118 | ACPI_SUB_HEADER_DEF |
Kevin O'Connor | d10e444 | 2009-03-01 12:41:20 -0500 | [diff] [blame] | 119 | u8 io_apic_id; /* I/O APIC ID */ |
| 120 | u8 reserved; /* Reserved - must be zero */ |
| 121 | u32 address; /* APIC physical address */ |
| 122 | u32 interrupt; /* Global system interrupt where INTI |
| 123 | * lines start */ |
Kevin O'Connor | e97ca7b | 2009-06-21 09:10:28 -0400 | [diff] [blame] | 124 | } PACKED; |
Kevin O'Connor | 276d4a9 | 2008-06-11 22:47:01 -0400 | [diff] [blame] | 125 | |
Kevin O'Connor | 7061eb6 | 2009-01-04 21:48:22 -0500 | [diff] [blame] | 126 | /* IRQs 5,9,10,11 */ |
| 127 | #define PCI_ISA_IRQ_MASK 0x0e20 |
Kevin O'Connor | 7061eb6 | 2009-01-04 21:48:22 -0500 | [diff] [blame] | 128 | |
| 129 | struct madt_intsrcovr { |
Kevin O'Connor | 590e554 | 2009-10-08 22:09:02 -0400 | [diff] [blame] | 130 | ACPI_SUB_HEADER_DEF |
Kevin O'Connor | 7061eb6 | 2009-01-04 21:48:22 -0500 | [diff] [blame] | 131 | u8 bus; |
| 132 | u8 source; |
| 133 | u32 gsi; |
| 134 | u16 flags; |
| 135 | } PACKED; |
| 136 | |
Kevin O'Connor | f434377 | 2009-10-08 22:05:21 -0400 | [diff] [blame] | 137 | /* |
| 138 | * ACPI 2.0 Generic Address Space definition. |
| 139 | */ |
| 140 | struct acpi_20_generic_address { |
| 141 | u8 address_space_id; |
| 142 | u8 register_bit_width; |
| 143 | u8 register_bit_offset; |
| 144 | u8 reserved; |
| 145 | u64 address; |
| 146 | } PACKED; |
| 147 | |
| 148 | /* |
| 149 | * HPET Description Table |
| 150 | */ |
| 151 | struct acpi_20_hpet { |
| 152 | ACPI_TABLE_HEADER_DEF /* ACPI common table header */ |
| 153 | u32 timer_block_id; |
| 154 | struct acpi_20_generic_address addr; |
| 155 | u8 hpet_number; |
| 156 | u16 min_tick; |
| 157 | u8 page_protect; |
| 158 | } PACKED; |
| 159 | #define ACPI_HPET_ADDRESS 0xFED00000UL |
| 160 | |
Jan Kiszka | b8a90f5 | 2011-08-29 17:50:10 +0200 | [diff] [blame] | 161 | #define HPET_ID 0x000 |
| 162 | #define HPET_PERIOD 0x004 |
| 163 | |
Kevin O'Connor | 590e554 | 2009-10-08 22:09:02 -0400 | [diff] [blame] | 164 | /* |
| 165 | * SRAT (NUMA topology description) table |
| 166 | */ |
| 167 | |
| 168 | #define SRAT_PROCESSOR 0 |
| 169 | #define SRAT_MEMORY 1 |
| 170 | |
| 171 | struct system_resource_affinity_table |
| 172 | { |
| 173 | ACPI_TABLE_HEADER_DEF |
| 174 | u32 reserved1; |
| 175 | u32 reserved2[2]; |
| 176 | } PACKED; |
| 177 | |
| 178 | struct srat_processor_affinity |
| 179 | { |
| 180 | ACPI_SUB_HEADER_DEF |
| 181 | u8 proximity_lo; |
| 182 | u8 local_apic_id; |
| 183 | u32 flags; |
| 184 | u8 local_sapic_eid; |
| 185 | u8 proximity_hi[3]; |
| 186 | u32 reserved; |
| 187 | } PACKED; |
| 188 | |
| 189 | struct srat_memory_affinity |
| 190 | { |
| 191 | ACPI_SUB_HEADER_DEF |
| 192 | u8 proximity[4]; |
| 193 | u16 reserved1; |
| 194 | u32 base_addr_low,base_addr_high; |
| 195 | u32 length_low,length_high; |
| 196 | u32 reserved2; |
| 197 | u32 flags; |
| 198 | u32 reserved3[2]; |
| 199 | } PACKED; |
| 200 | |
Kevin O'Connor | 276d4a9 | 2008-06-11 22:47:01 -0400 | [diff] [blame] | 201 | #include "acpi-dsdt.hex" |
| 202 | |
Kevin O'Connor | 2929c35 | 2009-07-25 13:48:27 -0400 | [diff] [blame] | 203 | static void |
Kevin O'Connor | a9242a2 | 2009-10-07 19:42:07 -0400 | [diff] [blame] | 204 | build_header(struct acpi_table_header *h, u32 sig, int len, u8 rev) |
Kevin O'Connor | 276d4a9 | 2008-06-11 22:47:01 -0400 | [diff] [blame] | 205 | { |
Kevin O'Connor | 9967ab7 | 2008-12-18 21:57:33 -0500 | [diff] [blame] | 206 | h->signature = sig; |
Kevin O'Connor | 276d4a9 | 2008-06-11 22:47:01 -0400 | [diff] [blame] | 207 | h->length = cpu_to_le32(len); |
| 208 | h->revision = rev; |
Kevin O'Connor | 6cb8ba9 | 2008-08-17 11:03:24 -0400 | [diff] [blame] | 209 | memcpy(h->oem_id, CONFIG_APPNAME6, 6); |
| 210 | memcpy(h->oem_table_id, CONFIG_APPNAME4, 4); |
Kevin O'Connor | 9967ab7 | 2008-12-18 21:57:33 -0500 | [diff] [blame] | 211 | memcpy(h->oem_table_id + 4, (void*)&sig, 4); |
Kevin O'Connor | 276d4a9 | 2008-06-11 22:47:01 -0400 | [diff] [blame] | 212 | h->oem_revision = cpu_to_le32(1); |
Kevin O'Connor | 8a161c9 | 2011-09-02 18:11:58 -0400 | [diff] [blame^] | 213 | memcpy(h->asl_compiler_id, CONFIG_APPNAME4, 4); |
Kevin O'Connor | 276d4a9 | 2008-06-11 22:47:01 -0400 | [diff] [blame] | 214 | h->asl_compiler_revision = cpu_to_le32(1); |
Kevin O'Connor | 523e5a9 | 2009-07-04 13:46:33 -0400 | [diff] [blame] | 215 | h->checksum -= checksum(h, len); |
Kevin O'Connor | 276d4a9 | 2008-06-11 22:47:01 -0400 | [diff] [blame] | 216 | } |
| 217 | |
Kevin O'Connor | 6e4583c | 2011-06-19 10:09:26 -0400 | [diff] [blame] | 218 | #define PIIX4_ACPI_ENABLE 0xf1 |
| 219 | #define PIIX4_ACPI_DISABLE 0xf0 |
| 220 | #define PIIX4_GPE0_BLK 0xafe0 |
| 221 | #define PIIX4_GPE0_BLK_LEN 4 |
| 222 | |
Kevin O'Connor | 278b19f | 2011-06-21 22:41:15 -0400 | [diff] [blame] | 223 | static void piix4_fadt_init(struct pci_device *pci, void *arg) |
Kevin O'Connor | 6e4583c | 2011-06-19 10:09:26 -0400 | [diff] [blame] | 224 | { |
| 225 | struct fadt_descriptor_rev1 *fadt = arg; |
| 226 | fadt->acpi_enable = PIIX4_ACPI_ENABLE; |
| 227 | fadt->acpi_disable = PIIX4_ACPI_DISABLE; |
| 228 | fadt->gpe0_blk = cpu_to_le32(PIIX4_GPE0_BLK); |
| 229 | fadt->gpe0_blk_len = PIIX4_GPE0_BLK_LEN; |
| 230 | } |
| 231 | |
Isaku Yamahata | fe54a53 | 2010-07-20 16:37:18 +0900 | [diff] [blame] | 232 | static const struct pci_device_id fadt_init_tbl[] = { |
| 233 | /* PIIX4 Power Management device (for ACPI) */ |
| 234 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_3, |
| 235 | piix4_fadt_init), |
| 236 | |
| 237 | PCI_DEVICE_END |
| 238 | }; |
| 239 | |
Kevin O'Connor | 278b19f | 2011-06-21 22:41:15 -0400 | [diff] [blame] | 240 | static void * |
| 241 | build_fadt(struct pci_device *pci) |
Kevin O'Connor | 276d4a9 | 2008-06-11 22:47:01 -0400 | [diff] [blame] | 242 | { |
Kevin O'Connor | 2929c35 | 2009-07-25 13:48:27 -0400 | [diff] [blame] | 243 | struct fadt_descriptor_rev1 *fadt = malloc_high(sizeof(*fadt)); |
Kevin O'Connor | 415d429 | 2009-08-30 19:19:31 -0400 | [diff] [blame] | 244 | struct facs_descriptor_rev1 *facs = memalign_high(64, sizeof(*facs)); |
Kevin O'Connor | 2929c35 | 2009-07-25 13:48:27 -0400 | [diff] [blame] | 245 | void *dsdt = malloc_high(sizeof(AmlCode)); |
Kevin O'Connor | 276d4a9 | 2008-06-11 22:47:01 -0400 | [diff] [blame] | 246 | |
Kevin O'Connor | 2929c35 | 2009-07-25 13:48:27 -0400 | [diff] [blame] | 247 | if (!fadt || !facs || !dsdt) { |
Kevin O'Connor | cfdc13f | 2010-02-14 13:07:54 -0500 | [diff] [blame] | 248 | warn_noalloc(); |
Kevin O'Connor | a9242a2 | 2009-10-07 19:42:07 -0400 | [diff] [blame] | 249 | return NULL; |
Kevin O'Connor | 276d4a9 | 2008-06-11 22:47:01 -0400 | [diff] [blame] | 250 | } |
| 251 | |
Kevin O'Connor | 2929c35 | 2009-07-25 13:48:27 -0400 | [diff] [blame] | 252 | /* FACS */ |
Kevin O'Connor | 2929c35 | 2009-07-25 13:48:27 -0400 | [diff] [blame] | 253 | memset(facs, 0, sizeof(*facs)); |
| 254 | facs->signature = FACS_SIGNATURE; |
| 255 | facs->length = cpu_to_le32(sizeof(*facs)); |
Kevin O'Connor | 276d4a9 | 2008-06-11 22:47:01 -0400 | [diff] [blame] | 256 | |
Kevin O'Connor | 2929c35 | 2009-07-25 13:48:27 -0400 | [diff] [blame] | 257 | /* DSDT */ |
| 258 | memcpy(dsdt, AmlCode, sizeof(AmlCode)); |
Kevin O'Connor | 276d4a9 | 2008-06-11 22:47:01 -0400 | [diff] [blame] | 259 | |
| 260 | /* FADT */ |
| 261 | memset(fadt, 0, sizeof(*fadt)); |
Kevin O'Connor | 2929c35 | 2009-07-25 13:48:27 -0400 | [diff] [blame] | 262 | fadt->firmware_ctrl = cpu_to_le32((u32)facs); |
| 263 | fadt->dsdt = cpu_to_le32((u32)dsdt); |
Kevin O'Connor | 276d4a9 | 2008-06-11 22:47:01 -0400 | [diff] [blame] | 264 | fadt->model = 1; |
| 265 | fadt->reserved1 = 0; |
Kevin O'Connor | 278b19f | 2011-06-21 22:41:15 -0400 | [diff] [blame] | 266 | int pm_sci_int = pci_config_readb(pci->bdf, PCI_INTERRUPT_LINE); |
Kevin O'Connor | 276d4a9 | 2008-06-11 22:47:01 -0400 | [diff] [blame] | 267 | fadt->sci_int = cpu_to_le16(pm_sci_int); |
Kevin O'Connor | e682cbc | 2008-12-06 23:11:56 -0500 | [diff] [blame] | 268 | fadt->smi_cmd = cpu_to_le32(PORT_SMI_CMD); |
Kevin O'Connor | e682cbc | 2008-12-06 23:11:56 -0500 | [diff] [blame] | 269 | fadt->pm1a_evt_blk = cpu_to_le32(PORT_ACPI_PM_BASE); |
| 270 | fadt->pm1a_cnt_blk = cpu_to_le32(PORT_ACPI_PM_BASE + 0x04); |
| 271 | fadt->pm_tmr_blk = cpu_to_le32(PORT_ACPI_PM_BASE + 0x08); |
Kevin O'Connor | 276d4a9 | 2008-06-11 22:47:01 -0400 | [diff] [blame] | 272 | fadt->pm1_evt_len = 4; |
| 273 | fadt->pm1_cnt_len = 2; |
| 274 | fadt->pm_tmr_len = 4; |
| 275 | fadt->plvl2_lat = cpu_to_le16(0xfff); // C2 state not supported |
| 276 | fadt->plvl3_lat = cpu_to_le16(0xfff); // C3 state not supported |
Kevin O'Connor | 278b19f | 2011-06-21 22:41:15 -0400 | [diff] [blame] | 277 | pci_init_device(fadt_init_tbl, pci, fadt); |
Gleb Natapov | 20fcf9b | 2011-01-30 14:17:11 +0200 | [diff] [blame] | 278 | /* WBINVD + PROC_C1 + SLP_BUTTON + FIX_RTC + RTC_S4 */ |
| 279 | fadt->flags = cpu_to_le32((1 << 0) | (1 << 2) | (1 << 5) | (1 << 6) | (1 << 7)); |
Kevin O'Connor | 276d4a9 | 2008-06-11 22:47:01 -0400 | [diff] [blame] | 280 | |
Kevin O'Connor | a9242a2 | 2009-10-07 19:42:07 -0400 | [diff] [blame] | 281 | build_header((void*)fadt, FACP_SIGNATURE, sizeof(*fadt), 1); |
| 282 | |
| 283 | return fadt; |
Kevin O'Connor | 2929c35 | 2009-07-25 13:48:27 -0400 | [diff] [blame] | 284 | } |
Kevin O'Connor | 276d4a9 | 2008-06-11 22:47:01 -0400 | [diff] [blame] | 285 | |
Kevin O'Connor | a9242a2 | 2009-10-07 19:42:07 -0400 | [diff] [blame] | 286 | static void* |
| 287 | build_madt(void) |
Kevin O'Connor | 2929c35 | 2009-07-25 13:48:27 -0400 | [diff] [blame] | 288 | { |
Kevin O'Connor | 2929c35 | 2009-07-25 13:48:27 -0400 | [diff] [blame] | 289 | int madt_size = (sizeof(struct multiple_apic_table) |
Kevin O'Connor | a26df9b | 2009-10-09 09:42:11 -0400 | [diff] [blame] | 290 | + sizeof(struct madt_processor_apic) * MaxCountCPUs |
Kevin O'Connor | 2929c35 | 2009-07-25 13:48:27 -0400 | [diff] [blame] | 291 | + sizeof(struct madt_io_apic) |
| 292 | + sizeof(struct madt_intsrcovr) * 16); |
| 293 | struct multiple_apic_table *madt = malloc_high(madt_size); |
| 294 | if (!madt) { |
Kevin O'Connor | cfdc13f | 2010-02-14 13:07:54 -0500 | [diff] [blame] | 295 | warn_noalloc(); |
Kevin O'Connor | a9242a2 | 2009-10-07 19:42:07 -0400 | [diff] [blame] | 296 | return NULL; |
Kevin O'Connor | 2929c35 | 2009-07-25 13:48:27 -0400 | [diff] [blame] | 297 | } |
Kevin O'Connor | 7061eb6 | 2009-01-04 21:48:22 -0500 | [diff] [blame] | 298 | memset(madt, 0, madt_size); |
| 299 | madt->local_apic_address = cpu_to_le32(BUILD_APIC_ADDR); |
| 300 | madt->flags = cpu_to_le32(1); |
Kevin O'Connor | 2929c35 | 2009-07-25 13:48:27 -0400 | [diff] [blame] | 301 | struct madt_processor_apic *apic = (void*)&madt[1]; |
| 302 | int i; |
Kevin O'Connor | a26df9b | 2009-10-09 09:42:11 -0400 | [diff] [blame] | 303 | for (i=0; i<MaxCountCPUs; i++) { |
Kevin O'Connor | 7061eb6 | 2009-01-04 21:48:22 -0500 | [diff] [blame] | 304 | apic->type = APIC_PROCESSOR; |
| 305 | apic->length = sizeof(*apic); |
| 306 | apic->processor_id = i; |
| 307 | apic->local_apic_id = i; |
Kevin O'Connor | a26df9b | 2009-10-09 09:42:11 -0400 | [diff] [blame] | 308 | if (i < CountCPUs) |
| 309 | apic->flags = cpu_to_le32(1); |
| 310 | else |
| 311 | apic->flags = cpu_to_le32(0); |
Kevin O'Connor | 7061eb6 | 2009-01-04 21:48:22 -0500 | [diff] [blame] | 312 | apic++; |
Kevin O'Connor | 276d4a9 | 2008-06-11 22:47:01 -0400 | [diff] [blame] | 313 | } |
Kevin O'Connor | 2929c35 | 2009-07-25 13:48:27 -0400 | [diff] [blame] | 314 | struct madt_io_apic *io_apic = (void*)apic; |
Kevin O'Connor | 7061eb6 | 2009-01-04 21:48:22 -0500 | [diff] [blame] | 315 | io_apic->type = APIC_IO; |
| 316 | io_apic->length = sizeof(*io_apic); |
Kevin O'Connor | a26df9b | 2009-10-09 09:42:11 -0400 | [diff] [blame] | 317 | io_apic->io_apic_id = CountCPUs; |
Kevin O'Connor | 7061eb6 | 2009-01-04 21:48:22 -0500 | [diff] [blame] | 318 | io_apic->address = cpu_to_le32(BUILD_IOAPIC_ADDR); |
| 319 | io_apic->interrupt = cpu_to_le32(0); |
| 320 | |
Kevin O'Connor | d10e444 | 2009-03-01 12:41:20 -0500 | [diff] [blame] | 321 | struct madt_intsrcovr *intsrcovr = (void*)&io_apic[1]; |
Kevin O'Connor | 4d2b619 | 2009-10-08 21:37:21 -0400 | [diff] [blame] | 322 | if (qemu_cfg_irq0_override()) { |
Kevin O'Connor | b64db30 | 2009-07-29 19:20:03 -0400 | [diff] [blame] | 323 | memset(intsrcovr, 0, sizeof(*intsrcovr)); |
| 324 | intsrcovr->type = APIC_XRUPT_OVERRIDE; |
| 325 | intsrcovr->length = sizeof(*intsrcovr); |
| 326 | intsrcovr->source = 0; |
| 327 | intsrcovr->gsi = 2; |
| 328 | intsrcovr->flags = 0; /* conforms to bus specifications */ |
| 329 | intsrcovr++; |
| 330 | } |
| 331 | for (i = 1; i < 16; i++) { |
Kevin O'Connor | d10e444 | 2009-03-01 12:41:20 -0500 | [diff] [blame] | 332 | if (!(PCI_ISA_IRQ_MASK & (1 << i))) |
Kevin O'Connor | 7061eb6 | 2009-01-04 21:48:22 -0500 | [diff] [blame] | 333 | /* No need for a INT source override structure. */ |
| 334 | continue; |
Kevin O'Connor | d10e444 | 2009-03-01 12:41:20 -0500 | [diff] [blame] | 335 | memset(intsrcovr, 0, sizeof(*intsrcovr)); |
| 336 | intsrcovr->type = APIC_XRUPT_OVERRIDE; |
| 337 | intsrcovr->length = sizeof(*intsrcovr); |
| 338 | intsrcovr->source = i; |
| 339 | intsrcovr->gsi = i; |
| 340 | intsrcovr->flags = 0xd; /* active high, level triggered */ |
Kevin O'Connor | 7061eb6 | 2009-01-04 21:48:22 -0500 | [diff] [blame] | 341 | intsrcovr++; |
Kevin O'Connor | 7061eb6 | 2009-01-04 21:48:22 -0500 | [diff] [blame] | 342 | } |
| 343 | |
Kevin O'Connor | a9242a2 | 2009-10-07 19:42:07 -0400 | [diff] [blame] | 344 | build_header((void*)madt, APIC_SIGNATURE, (void*)intsrcovr - (void*)madt, 1); |
| 345 | return madt; |
Kevin O'Connor | 2929c35 | 2009-07-25 13:48:27 -0400 | [diff] [blame] | 346 | } |
| 347 | |
Kevin O'Connor | e2074bf | 2010-08-03 21:30:03 -0400 | [diff] [blame] | 348 | // Encode a hex value |
| 349 | static inline char getHex(u32 val) { |
| 350 | val &= 0x0f; |
| 351 | return (val <= 9) ? ('0' + val) : ('A' + val - 10); |
| 352 | } |
| 353 | |
| 354 | // Encode a length in an SSDT. |
| 355 | static u8 * |
| 356 | encodeLen(u8 *ssdt_ptr, int length, int bytes) |
| 357 | { |
| 358 | switch (bytes) { |
| 359 | default: |
| 360 | case 4: ssdt_ptr[3] = ((length >> 20) & 0xff); |
| 361 | case 3: ssdt_ptr[2] = ((length >> 12) & 0xff); |
| 362 | case 2: ssdt_ptr[1] = ((length >> 4) & 0xff); |
| 363 | ssdt_ptr[0] = (((bytes-1) & 0x3) << 6) | (length & 0x0f); |
| 364 | break; |
| 365 | case 1: ssdt_ptr[0] = length & 0x3f; |
| 366 | } |
| 367 | return ssdt_ptr + bytes; |
| 368 | } |
| 369 | |
| 370 | // AML Processor() object. See src/ssdt-proc.dsl for info. |
| 371 | static unsigned char ssdt_proc[] = { |
| 372 | 0x5b,0x83,0x42,0x05,0x43,0x50,0x41,0x41, |
| 373 | 0xaa,0x10,0xb0,0x00,0x00,0x06,0x08,0x49, |
| 374 | 0x44,0x5f,0x5f,0x0a,0xaa,0x08,0x5f,0x48, |
| 375 | 0x49,0x44,0x0d,0x41,0x43,0x50,0x49,0x30, |
| 376 | 0x30,0x30,0x37,0x00,0x14,0x0f,0x5f,0x4d, |
| 377 | 0x41,0x54,0x00,0xa4,0x43,0x50,0x4d,0x41, |
| 378 | 0x49,0x44,0x5f,0x5f,0x14,0x0f,0x5f,0x53, |
| 379 | 0x54,0x41,0x00,0xa4,0x43,0x50,0x53,0x54, |
| 380 | 0x49,0x44,0x5f,0x5f,0x14,0x0f,0x5f,0x45, |
| 381 | 0x4a,0x30,0x01,0x43,0x50,0x45,0x4a,0x49, |
| 382 | 0x44,0x5f,0x5f,0x68 |
| 383 | }; |
| 384 | #define SD_OFFSET_CPUHEX 6 |
| 385 | #define SD_OFFSET_CPUID1 8 |
| 386 | #define SD_OFFSET_CPUID2 20 |
| 387 | |
Kevin O'Connor | 2929c35 | 2009-07-25 13:48:27 -0400 | [diff] [blame] | 388 | #define SSDT_SIGNATURE 0x54445353 // SSDT |
Kevin O'Connor | a9242a2 | 2009-10-07 19:42:07 -0400 | [diff] [blame] | 389 | static void* |
| 390 | build_ssdt(void) |
Kevin O'Connor | 2929c35 | 2009-07-25 13:48:27 -0400 | [diff] [blame] | 391 | { |
Kevin O'Connor | a26df9b | 2009-10-09 09:42:11 -0400 | [diff] [blame] | 392 | int acpi_cpus = MaxCountCPUs > 0xff ? 0xff : MaxCountCPUs; |
Kevin O'Connor | e2074bf | 2010-08-03 21:30:03 -0400 | [diff] [blame] | 393 | // length = ScopeOp + procs + NTYF method + CPON package |
| 394 | int length = ((1+3+4) |
| 395 | + (acpi_cpus * sizeof(ssdt_proc)) |
| 396 | + (1+2+5+(12*acpi_cpus)) |
| 397 | + (6+2+1+(1*acpi_cpus))); |
| 398 | u8 *ssdt = malloc_high(sizeof(struct acpi_table_header) + length); |
Kevin O'Connor | 2929c35 | 2009-07-25 13:48:27 -0400 | [diff] [blame] | 399 | if (! ssdt) { |
Kevin O'Connor | cfdc13f | 2010-02-14 13:07:54 -0500 | [diff] [blame] | 400 | warn_noalloc(); |
Kevin O'Connor | a9242a2 | 2009-10-07 19:42:07 -0400 | [diff] [blame] | 401 | return NULL; |
Kevin O'Connor | 2929c35 | 2009-07-25 13:48:27 -0400 | [diff] [blame] | 402 | } |
Kevin O'Connor | e2074bf | 2010-08-03 21:30:03 -0400 | [diff] [blame] | 403 | u8 *ssdt_ptr = ssdt + sizeof(struct acpi_table_header); |
Kevin O'Connor | 2929c35 | 2009-07-25 13:48:27 -0400 | [diff] [blame] | 404 | |
Kevin O'Connor | e2074bf | 2010-08-03 21:30:03 -0400 | [diff] [blame] | 405 | // build Scope(_SB_) header |
Kevin O'Connor | 2929c35 | 2009-07-25 13:48:27 -0400 | [diff] [blame] | 406 | *(ssdt_ptr++) = 0x10; // ScopeOp |
Kevin O'Connor | e2074bf | 2010-08-03 21:30:03 -0400 | [diff] [blame] | 407 | ssdt_ptr = encodeLen(ssdt_ptr, length-1, 3); |
| 408 | *(ssdt_ptr++) = '_'; |
| 409 | *(ssdt_ptr++) = 'S'; |
| 410 | *(ssdt_ptr++) = 'B'; |
Kevin O'Connor | 2929c35 | 2009-07-25 13:48:27 -0400 | [diff] [blame] | 411 | *(ssdt_ptr++) = '_'; |
| 412 | |
Kevin O'Connor | e2074bf | 2010-08-03 21:30:03 -0400 | [diff] [blame] | 413 | // build Processor object for each processor |
Kevin O'Connor | 2929c35 | 2009-07-25 13:48:27 -0400 | [diff] [blame] | 414 | int i; |
| 415 | for (i=0; i<acpi_cpus; i++) { |
Kevin O'Connor | e2074bf | 2010-08-03 21:30:03 -0400 | [diff] [blame] | 416 | memcpy(ssdt_ptr, ssdt_proc, sizeof(ssdt_proc)); |
| 417 | ssdt_ptr[SD_OFFSET_CPUHEX] = getHex(i >> 4); |
| 418 | ssdt_ptr[SD_OFFSET_CPUHEX+1] = getHex(i); |
| 419 | ssdt_ptr[SD_OFFSET_CPUID1] = i; |
| 420 | ssdt_ptr[SD_OFFSET_CPUID2] = i; |
| 421 | ssdt_ptr += sizeof(ssdt_proc); |
Kevin O'Connor | 2929c35 | 2009-07-25 13:48:27 -0400 | [diff] [blame] | 422 | } |
| 423 | |
Kevin O'Connor | e2074bf | 2010-08-03 21:30:03 -0400 | [diff] [blame] | 424 | // build "Method(NTFY, 2) {If (LEqual(Arg0, 0x00)) {Notify(CP00, Arg1)} ...}" |
| 425 | *(ssdt_ptr++) = 0x14; // MethodOp |
| 426 | ssdt_ptr = encodeLen(ssdt_ptr, 2+5+(12*acpi_cpus), 2); |
| 427 | *(ssdt_ptr++) = 'N'; |
| 428 | *(ssdt_ptr++) = 'T'; |
| 429 | *(ssdt_ptr++) = 'F'; |
| 430 | *(ssdt_ptr++) = 'Y'; |
| 431 | *(ssdt_ptr++) = 0x02; |
| 432 | for (i=0; i<acpi_cpus; i++) { |
| 433 | *(ssdt_ptr++) = 0xA0; // IfOp |
| 434 | ssdt_ptr = encodeLen(ssdt_ptr, 11, 1); |
| 435 | *(ssdt_ptr++) = 0x93; // LEqualOp |
| 436 | *(ssdt_ptr++) = 0x68; // Arg0Op |
| 437 | *(ssdt_ptr++) = 0x0A; // BytePrefix |
| 438 | *(ssdt_ptr++) = i; |
| 439 | *(ssdt_ptr++) = 0x86; // NotifyOp |
| 440 | *(ssdt_ptr++) = 'C'; |
| 441 | *(ssdt_ptr++) = 'P'; |
| 442 | *(ssdt_ptr++) = getHex(i >> 4); |
| 443 | *(ssdt_ptr++) = getHex(i); |
| 444 | *(ssdt_ptr++) = 0x69; // Arg1Op |
| 445 | } |
| 446 | |
| 447 | // build "Name(CPON, Package() { One, One, ..., Zero, Zero, ... })" |
| 448 | *(ssdt_ptr++) = 0x08; // NameOp |
| 449 | *(ssdt_ptr++) = 'C'; |
| 450 | *(ssdt_ptr++) = 'P'; |
| 451 | *(ssdt_ptr++) = 'O'; |
| 452 | *(ssdt_ptr++) = 'N'; |
| 453 | *(ssdt_ptr++) = 0x12; // PackageOp |
| 454 | ssdt_ptr = encodeLen(ssdt_ptr, 2+1+(1*acpi_cpus), 2); |
| 455 | *(ssdt_ptr++) = acpi_cpus; |
| 456 | for (i=0; i<acpi_cpus; i++) |
| 457 | *(ssdt_ptr++) = (i < CountCPUs) ? 0x01 : 0x00; |
| 458 | |
Kevin O'Connor | a9242a2 | 2009-10-07 19:42:07 -0400 | [diff] [blame] | 459 | build_header((void*)ssdt, SSDT_SIGNATURE, ssdt_ptr - ssdt, 1); |
| 460 | |
Kevin O'Connor | e2074bf | 2010-08-03 21:30:03 -0400 | [diff] [blame] | 461 | //hexdump(ssdt, ssdt_ptr - ssdt); |
| 462 | |
Kevin O'Connor | a9242a2 | 2009-10-07 19:42:07 -0400 | [diff] [blame] | 463 | return ssdt; |
Kevin O'Connor | 2929c35 | 2009-07-25 13:48:27 -0400 | [diff] [blame] | 464 | } |
| 465 | |
Kevin O'Connor | 8a161c9 | 2011-09-02 18:11:58 -0400 | [diff] [blame^] | 466 | #define HPET_SIGNATURE 0x54455048 // HPET |
Kevin O'Connor | f434377 | 2009-10-08 22:05:21 -0400 | [diff] [blame] | 467 | static void* |
| 468 | build_hpet(void) |
| 469 | { |
Jan Kiszka | b8a90f5 | 2011-08-29 17:50:10 +0200 | [diff] [blame] | 470 | struct acpi_20_hpet *hpet; |
| 471 | const void *hpet_base = (void *)ACPI_HPET_ADDRESS; |
| 472 | u32 hpet_vendor = readl(hpet_base + HPET_ID) >> 16; |
| 473 | u32 hpet_period = readl(hpet_base + HPET_PERIOD); |
| 474 | |
| 475 | if (hpet_vendor == 0 || hpet_vendor == 0xffff || |
Kevin O'Connor | 8a161c9 | 2011-09-02 18:11:58 -0400 | [diff] [blame^] | 476 | hpet_period == 0 || hpet_period > 100000000) |
Jan Kiszka | b8a90f5 | 2011-08-29 17:50:10 +0200 | [diff] [blame] | 477 | return NULL; |
| 478 | |
| 479 | hpet = malloc_high(sizeof(*hpet)); |
Kevin O'Connor | f434377 | 2009-10-08 22:05:21 -0400 | [diff] [blame] | 480 | if (!hpet) { |
Kevin O'Connor | cfdc13f | 2010-02-14 13:07:54 -0500 | [diff] [blame] | 481 | warn_noalloc(); |
Kevin O'Connor | f434377 | 2009-10-08 22:05:21 -0400 | [diff] [blame] | 482 | return NULL; |
| 483 | } |
| 484 | |
| 485 | memset(hpet, 0, sizeof(*hpet)); |
| 486 | /* Note timer_block_id value must be kept in sync with value advertised by |
| 487 | * emulated hpet |
| 488 | */ |
| 489 | hpet->timer_block_id = cpu_to_le32(0x8086a201); |
| 490 | hpet->addr.address = cpu_to_le32(ACPI_HPET_ADDRESS); |
| 491 | build_header((void*)hpet, HPET_SIGNATURE, sizeof(*hpet), 1); |
| 492 | |
| 493 | return hpet; |
| 494 | } |
| 495 | |
Kevin O'Connor | 590e554 | 2009-10-08 22:09:02 -0400 | [diff] [blame] | 496 | static void |
| 497 | acpi_build_srat_memory(struct srat_memory_affinity *numamem, |
| 498 | u64 base, u64 len, int node, int enabled) |
| 499 | { |
| 500 | numamem->type = SRAT_MEMORY; |
| 501 | numamem->length = sizeof(*numamem); |
Kevin O'Connor | 8a161c9 | 2011-09-02 18:11:58 -0400 | [diff] [blame^] | 502 | memset(numamem->proximity, 0 ,4); |
Kevin O'Connor | 590e554 | 2009-10-08 22:09:02 -0400 | [diff] [blame] | 503 | numamem->proximity[0] = node; |
| 504 | numamem->flags = cpu_to_le32(!!enabled); |
| 505 | numamem->base_addr_low = base & 0xFFFFFFFF; |
| 506 | numamem->base_addr_high = base >> 32; |
| 507 | numamem->length_low = len & 0xFFFFFFFF; |
| 508 | numamem->length_high = len >> 32; |
| 509 | } |
| 510 | |
Kevin O'Connor | 8a161c9 | 2011-09-02 18:11:58 -0400 | [diff] [blame^] | 511 | #define SRAT_SIGNATURE 0x54415253 // SRAT |
Kevin O'Connor | 590e554 | 2009-10-08 22:09:02 -0400 | [diff] [blame] | 512 | static void * |
| 513 | build_srat(void) |
| 514 | { |
| 515 | int nb_numa_nodes = qemu_cfg_get_numa_nodes(); |
| 516 | |
| 517 | if (nb_numa_nodes == 0) |
| 518 | return NULL; |
| 519 | |
Kevin O'Connor | a26df9b | 2009-10-09 09:42:11 -0400 | [diff] [blame] | 520 | u64 *numadata = malloc_tmphigh(sizeof(u64) * (MaxCountCPUs + nb_numa_nodes)); |
Kevin O'Connor | 590e554 | 2009-10-08 22:09:02 -0400 | [diff] [blame] | 521 | if (!numadata) { |
Kevin O'Connor | cfdc13f | 2010-02-14 13:07:54 -0500 | [diff] [blame] | 522 | warn_noalloc(); |
Kevin O'Connor | 590e554 | 2009-10-08 22:09:02 -0400 | [diff] [blame] | 523 | return NULL; |
| 524 | } |
| 525 | |
Kevin O'Connor | a26df9b | 2009-10-09 09:42:11 -0400 | [diff] [blame] | 526 | qemu_cfg_get_numa_data(numadata, MaxCountCPUs + nb_numa_nodes); |
Kevin O'Connor | 590e554 | 2009-10-08 22:09:02 -0400 | [diff] [blame] | 527 | |
| 528 | struct system_resource_affinity_table *srat; |
| 529 | int srat_size = sizeof(*srat) + |
Kevin O'Connor | a26df9b | 2009-10-09 09:42:11 -0400 | [diff] [blame] | 530 | sizeof(struct srat_processor_affinity) * MaxCountCPUs + |
Kevin O'Connor | 590e554 | 2009-10-08 22:09:02 -0400 | [diff] [blame] | 531 | sizeof(struct srat_memory_affinity) * (nb_numa_nodes + 2); |
| 532 | |
| 533 | srat = malloc_high(srat_size); |
| 534 | if (!srat) { |
Kevin O'Connor | cfdc13f | 2010-02-14 13:07:54 -0500 | [diff] [blame] | 535 | warn_noalloc(); |
Isaku Yamahata | e1920be | 2010-02-12 11:36:20 +0900 | [diff] [blame] | 536 | free(numadata); |
Kevin O'Connor | 590e554 | 2009-10-08 22:09:02 -0400 | [diff] [blame] | 537 | return NULL; |
| 538 | } |
| 539 | |
| 540 | memset(srat, 0, srat_size); |
| 541 | srat->reserved1=1; |
| 542 | struct srat_processor_affinity *core = (void*)(srat + 1); |
| 543 | int i; |
| 544 | u64 curnode; |
| 545 | |
Kevin O'Connor | a26df9b | 2009-10-09 09:42:11 -0400 | [diff] [blame] | 546 | for (i = 0; i < MaxCountCPUs; ++i) { |
Kevin O'Connor | 590e554 | 2009-10-08 22:09:02 -0400 | [diff] [blame] | 547 | core->type = SRAT_PROCESSOR; |
| 548 | core->length = sizeof(*core); |
| 549 | core->local_apic_id = i; |
| 550 | curnode = *numadata++; |
| 551 | core->proximity_lo = curnode; |
| 552 | memset(core->proximity_hi, 0, 3); |
| 553 | core->local_sapic_eid = 0; |
| 554 | if (i < CountCPUs) |
| 555 | core->flags = cpu_to_le32(1); |
| 556 | else |
| 557 | core->flags = 0; |
| 558 | core++; |
| 559 | } |
| 560 | |
| 561 | |
| 562 | /* the memory map is a bit tricky, it contains at least one hole |
| 563 | * from 640k-1M and possibly another one from 3.5G-4G. |
| 564 | */ |
| 565 | struct srat_memory_affinity *numamem = (void*)core; |
| 566 | int slots = 0; |
| 567 | u64 mem_len, mem_base, next_base = 0; |
| 568 | |
| 569 | acpi_build_srat_memory(numamem, 0, 640*1024, 0, 1); |
| 570 | next_base = 1024 * 1024; |
| 571 | numamem++; |
| 572 | slots++; |
| 573 | for (i = 1; i < nb_numa_nodes + 1; ++i) { |
| 574 | mem_base = next_base; |
| 575 | mem_len = *numadata++; |
| 576 | if (i == 1) |
| 577 | mem_len -= 1024 * 1024; |
| 578 | next_base = mem_base + mem_len; |
| 579 | |
| 580 | /* Cut out the PCI hole */ |
| 581 | if (mem_base <= RamSize && next_base > RamSize) { |
| 582 | mem_len -= next_base - RamSize; |
| 583 | if (mem_len > 0) { |
| 584 | acpi_build_srat_memory(numamem, mem_base, mem_len, i-1, 1); |
| 585 | numamem++; |
| 586 | slots++; |
| 587 | } |
| 588 | mem_base = 1ULL << 32; |
| 589 | mem_len = next_base - RamSize; |
| 590 | next_base += (1ULL << 32) - RamSize; |
| 591 | } |
| 592 | acpi_build_srat_memory(numamem, mem_base, mem_len, i-1, 1); |
| 593 | numamem++; |
| 594 | slots++; |
| 595 | } |
| 596 | for (; slots < nb_numa_nodes + 2; slots++) { |
| 597 | acpi_build_srat_memory(numamem, 0, 0, 0, 0); |
| 598 | numamem++; |
| 599 | } |
| 600 | |
| 601 | build_header((void*)srat, SRAT_SIGNATURE, srat_size, 1); |
| 602 | |
Isaku Yamahata | e1920be | 2010-02-12 11:36:20 +0900 | [diff] [blame] | 603 | free(numadata); |
Kevin O'Connor | 590e554 | 2009-10-08 22:09:02 -0400 | [diff] [blame] | 604 | return srat; |
| 605 | } |
| 606 | |
Isaku Yamahata | 4c67f90 | 2010-07-20 16:37:19 +0900 | [diff] [blame] | 607 | static const struct pci_device_id acpi_find_tbl[] = { |
| 608 | /* PIIX4 Power Management device. */ |
| 609 | PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_3, NULL), |
| 610 | |
| 611 | PCI_DEVICE_END, |
| 612 | }; |
| 613 | |
Kevin O'Connor | 2929c35 | 2009-07-25 13:48:27 -0400 | [diff] [blame] | 614 | struct rsdp_descriptor *RsdpAddr; |
| 615 | |
Kevin O'Connor | a9242a2 | 2009-10-07 19:42:07 -0400 | [diff] [blame] | 616 | #define MAX_ACPI_TABLES 20 |
Kevin O'Connor | 2929c35 | 2009-07-25 13:48:27 -0400 | [diff] [blame] | 617 | void |
| 618 | acpi_bios_init(void) |
| 619 | { |
| 620 | if (! CONFIG_ACPI) |
| 621 | return; |
| 622 | |
| 623 | dprintf(3, "init ACPI tables\n"); |
| 624 | |
| 625 | // This code is hardcoded for PIIX4 Power Management device. |
Kevin O'Connor | 278b19f | 2011-06-21 22:41:15 -0400 | [diff] [blame] | 626 | struct pci_device *pci = pci_find_init_device(acpi_find_tbl, NULL); |
| 627 | if (!pci) |
Kevin O'Connor | 2929c35 | 2009-07-25 13:48:27 -0400 | [diff] [blame] | 628 | // Device not found |
| 629 | return; |
| 630 | |
Kevin O'Connor | 8a161c9 | 2011-09-02 18:11:58 -0400 | [diff] [blame^] | 631 | // Build ACPI tables |
Kevin O'Connor | a9242a2 | 2009-10-07 19:42:07 -0400 | [diff] [blame] | 632 | u32 tables[MAX_ACPI_TABLES], tbl_idx = 0; |
| 633 | |
| 634 | #define ACPI_INIT_TABLE(X) \ |
| 635 | do { \ |
| 636 | tables[tbl_idx] = (u32)(X); \ |
| 637 | if (tables[tbl_idx]) \ |
| 638 | tbl_idx++; \ |
| 639 | } while(0) |
Kevin O'Connor | 2929c35 | 2009-07-25 13:48:27 -0400 | [diff] [blame] | 640 | |
Kevin O'Connor | 278b19f | 2011-06-21 22:41:15 -0400 | [diff] [blame] | 641 | ACPI_INIT_TABLE(build_fadt(pci)); |
Kevin O'Connor | a9242a2 | 2009-10-07 19:42:07 -0400 | [diff] [blame] | 642 | ACPI_INIT_TABLE(build_ssdt()); |
| 643 | ACPI_INIT_TABLE(build_madt()); |
Kevin O'Connor | f434377 | 2009-10-08 22:05:21 -0400 | [diff] [blame] | 644 | ACPI_INIT_TABLE(build_hpet()); |
Kevin O'Connor | 590e554 | 2009-10-08 22:09:02 -0400 | [diff] [blame] | 645 | ACPI_INIT_TABLE(build_srat()); |
Kevin O'Connor | 2929c35 | 2009-07-25 13:48:27 -0400 | [diff] [blame] | 646 | |
Kevin O'Connor | cc6dc46 | 2009-10-08 21:18:41 -0400 | [diff] [blame] | 647 | u16 i, external_tables = qemu_cfg_acpi_additional_tables(); |
| 648 | |
Kevin O'Connor | 8a161c9 | 2011-09-02 18:11:58 -0400 | [diff] [blame^] | 649 | for (i = 0; i < external_tables; i++) { |
Kevin O'Connor | cc6dc46 | 2009-10-08 21:18:41 -0400 | [diff] [blame] | 650 | u16 len = qemu_cfg_next_acpi_table_len(); |
| 651 | void *addr = malloc_high(len); |
| 652 | if (!addr) { |
Kevin O'Connor | cfdc13f | 2010-02-14 13:07:54 -0500 | [diff] [blame] | 653 | warn_noalloc(); |
Kevin O'Connor | cc6dc46 | 2009-10-08 21:18:41 -0400 | [diff] [blame] | 654 | continue; |
| 655 | } |
| 656 | ACPI_INIT_TABLE(qemu_cfg_next_acpi_table_load(addr, len)); |
| 657 | if (tbl_idx == MAX_ACPI_TABLES) { |
Kevin O'Connor | cfdc13f | 2010-02-14 13:07:54 -0500 | [diff] [blame] | 658 | warn_noalloc(); |
Kevin O'Connor | cc6dc46 | 2009-10-08 21:18:41 -0400 | [diff] [blame] | 659 | break; |
| 660 | } |
| 661 | } |
| 662 | |
Kevin O'Connor | 8a161c9 | 2011-09-02 18:11:58 -0400 | [diff] [blame^] | 663 | // Build final rsdt table |
Kevin O'Connor | a9242a2 | 2009-10-07 19:42:07 -0400 | [diff] [blame] | 664 | struct rsdt_descriptor_rev1 *rsdt; |
| 665 | size_t rsdt_len = sizeof(*rsdt) + sizeof(u32) * tbl_idx; |
| 666 | rsdt = malloc_high(rsdt_len); |
Kevin O'Connor | a9242a2 | 2009-10-07 19:42:07 -0400 | [diff] [blame] | 667 | if (!rsdt) { |
Kevin O'Connor | cfdc13f | 2010-02-14 13:07:54 -0500 | [diff] [blame] | 668 | warn_noalloc(); |
Kevin O'Connor | a9242a2 | 2009-10-07 19:42:07 -0400 | [diff] [blame] | 669 | return; |
| 670 | } |
| 671 | memset(rsdt, 0, rsdt_len); |
| 672 | memcpy(rsdt->table_offset_entry, tables, sizeof(u32) * tbl_idx); |
Kevin O'Connor | a9242a2 | 2009-10-07 19:42:07 -0400 | [diff] [blame] | 673 | build_header((void*)rsdt, RSDT_SIGNATURE, rsdt_len, 1); |
Kevin O'Connor | 2929c35 | 2009-07-25 13:48:27 -0400 | [diff] [blame] | 674 | |
| 675 | // Build rsdp pointer table |
Kevin O'Connor | 8a161c9 | 2011-09-02 18:11:58 -0400 | [diff] [blame^] | 676 | struct rsdp_descriptor *rsdp = malloc_fseg(sizeof(*rsdp)); |
| 677 | if (!rsdp) { |
| 678 | warn_noalloc(); |
| 679 | return; |
| 680 | } |
Kevin O'Connor | 2929c35 | 2009-07-25 13:48:27 -0400 | [diff] [blame] | 681 | memset(rsdp, 0, sizeof(*rsdp)); |
| 682 | rsdp->signature = RSDP_SIGNATURE; |
| 683 | memcpy(rsdp->oem_id, CONFIG_APPNAME6, 6); |
| 684 | rsdp->rsdt_physical_address = cpu_to_le32((u32)rsdt); |
| 685 | rsdp->checksum -= checksum(rsdp, 20); |
| 686 | RsdpAddr = rsdp; |
| 687 | dprintf(1, "ACPI tables: RSDP=%p RSDT=%p\n", rsdp, rsdt); |
Kevin O'Connor | 276d4a9 | 2008-06-11 22:47:01 -0400 | [diff] [blame] | 688 | } |
Kevin O'Connor | 9967ab7 | 2008-12-18 21:57:33 -0500 | [diff] [blame] | 689 | |
| 690 | u32 |
Kevin O'Connor | 1ca05b0 | 2010-01-03 17:43:37 -0500 | [diff] [blame] | 691 | find_resume_vector(void) |
Kevin O'Connor | 9967ab7 | 2008-12-18 21:57:33 -0500 | [diff] [blame] | 692 | { |
| 693 | dprintf(4, "rsdp=%p\n", RsdpAddr); |
| 694 | if (!RsdpAddr || RsdpAddr->signature != RSDP_SIGNATURE) |
| 695 | return 0; |
| 696 | struct rsdt_descriptor_rev1 *rsdt = (void*)RsdpAddr->rsdt_physical_address; |
| 697 | dprintf(4, "rsdt=%p\n", rsdt); |
| 698 | if (!rsdt || rsdt->signature != RSDT_SIGNATURE) |
| 699 | return 0; |
| 700 | void *end = (void*)rsdt + rsdt->length; |
| 701 | int i; |
| 702 | for (i=0; (void*)&rsdt->table_offset_entry[i] < end; i++) { |
| 703 | struct fadt_descriptor_rev1 *fadt = (void*)rsdt->table_offset_entry[i]; |
| 704 | if (!fadt || fadt->signature != FACP_SIGNATURE) |
| 705 | continue; |
| 706 | dprintf(4, "fadt=%p\n", fadt); |
| 707 | struct facs_descriptor_rev1 *facs = (void*)fadt->firmware_ctrl; |
| 708 | dprintf(4, "facs=%p\n", facs); |
| 709 | if (! facs || facs->signature != FACS_SIGNATURE) |
| 710 | return 0; |
| 711 | // Found it. |
| 712 | dprintf(4, "resume addr=%d\n", facs->firmware_waking_vector); |
| 713 | return facs->firmware_waking_vector; |
| 714 | } |
| 715 | return 0; |
| 716 | } |