1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23#include <string.h>
24#include <console/console.h>
25#include <arch/acpi.h>
26#include <arch/ioapic.h>
27#include <device/device.h>
28#include <device/pci.h>
29#include <device/pci_ids.h>
30#include "ioapic.h"
31
32extern const unsigned char AmlCode[];
33
34unsigned long acpi_fill_mcfg(unsigned long current)
35{
36 device_t dev;
37 u64 mmcfg;
38
39 dev = dev_find_device(0x8086, 0x35B0, 0);
40 if (!dev)
41 return current;
42
43
44 mmcfg = ((u64) pci_read_config16(dev, 0xce)) << 16;
45 if (!mmcfg)
46 return current;
47
48 current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *) current,
49 mmcfg, 0x0, 0x0, 0xff);
50
51 return current;
52}
53
54static void acpi_create_intel_hpet(acpi_hpet_t * hpet)
55{
56#define HPET_ADDR 0xfed00000ULL
57 acpi_header_t *header = &(hpet->header);
58 acpi_addr_t *addr = &(hpet->addr);
59
60 memset((void *) hpet, 0, sizeof(acpi_hpet_t));
61
62
63 memcpy(header->signature, "HPET", 4);
64 memcpy(header->oem_id, OEM_ID, 6);
65 memcpy(header->oem_table_id, "IC ", 8);
66 memcpy(header->asl_compiler_id, ASLC, 4);
67
68 header->length = sizeof(acpi_hpet_t);
69 header->revision = 1;
70
71
72
73 addr->space_id = 0;
74 addr->bit_width = 64;
75 addr->bit_offset = 0;
76 addr->addrl = HPET_ADDR & 0xffffffff;
77 addr->addrh = HPET_ADDR >> 32;
78
79 hpet->id = 0x80861234;
80 hpet->number = 0x00;
81 hpet->min_tick = 0x0090;
82
83 header->checksum = acpi_checksum((void *) hpet, sizeof(acpi_hpet_t));
84}
85
86#define IO_APIC0 2
87#define IO_APIC1 3
88
89unsigned long acpi_fill_madt(unsigned long current)
90{
91 unsigned int irq_start = 0;
92 device_t dev = 0;
93 unsigned char bus_isa;
94
95
96 current += acpi_create_madt_lapic((acpi_madt_lapic_t *) current, 1, 0);
97
98 current += acpi_create_madt_lapic((acpi_madt_lapic_t *) current, 2, 1);
99
100
101 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current, IO_APIC0, IO_APIC_ADDR, irq_start);
102 irq_start += INTEL_IOAPIC_NUM_INTERRUPTS;
103 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current, IO_APIC1, IO_APIC_ADDR + 0x10000, irq_start);
104 irq_start += INTEL_IOAPIC_NUM_INTERRUPTS;
105
106 dev = dev_find_slot(0, PCI_DEVFN(0x1e,0));
107
108 if (dev) {
109 bus_isa = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
110 bus_isa++;
111 } else {
112 printk(BIOS_DEBUG, "ERROR - could not find PCI 0:1e.0, using defaults\n");
113 bus_isa = 7;
114 }
115
116
117 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *) current, bus_isa, 0, 2, 0);
118
119
120 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *) current, 0, 9, 9, 0x000d);
121
122 return current;
123}
124
125unsigned long acpi_fill_slit(unsigned long current)
126{
127
128 return current;
129}
130
131unsigned long acpi_fill_srat(unsigned long current)
132{
133
134 return current;
135}
136
137
138#define ALIGN_CURRENT current = ((current + 0x0f) & -0x10)
139unsigned long write_acpi_tables(unsigned long start)
140{
141 unsigned long current;
142 acpi_rsdp_t *rsdp;
143 acpi_rsdt_t *rsdt;
144 acpi_hpet_t *hpet;
145 acpi_madt_t *madt;
146 acpi_mcfg_t *mcfg;
147 acpi_fadt_t *fadt;
148 acpi_facs_t *facs;
149 acpi_header_t *dsdt;
150
151 current = start;
152
153
154 ALIGN_CURRENT;
155
156 printk(BIOS_INFO, "ACPI: Writing ACPI tables at %lx.\n", current);
157
158
159 rsdp = (acpi_rsdp_t *) current;
160 current += sizeof(acpi_rsdp_t);
161 ALIGN_CURRENT;
162 rsdt = (acpi_rsdt_t *) current;
163 current += sizeof(acpi_rsdt_t);
164 ALIGN_CURRENT;
165
166
167 memset((void *) start, 0, current - start);
168
169 acpi_write_rsdp(rsdp, rsdt, NULL);
170 acpi_write_rsdt(rsdt);
171
172
173
174
175 printk(BIOS_DEBUG, "ACPI: * HPET\n");
176
177 hpet = (acpi_hpet_t *) current;
178 current += sizeof(acpi_hpet_t);
179 ALIGN_CURRENT;
180 acpi_create_intel_hpet(hpet);
181 acpi_add_table(rsdp, hpet);
182
183
184 printk(BIOS_DEBUG, "ACPI: * MADT\n");
185
186 madt = (acpi_madt_t *) current;
187 acpi_create_madt(madt);
188 current += madt->header.length;
189 ALIGN_CURRENT;
190 acpi_add_table(rsdp, madt);
191
192 printk(BIOS_DEBUG, "ACPI: * MCFG\n");
193 mcfg = (acpi_mcfg_t *) current;
194 acpi_create_mcfg(mcfg);
195 current += mcfg->header.length;
196 ALIGN_CURRENT;
197 acpi_add_table(rsdp, mcfg);
198
199 printk(BIOS_DEBUG, "ACPI: * FACS\n");
200 facs = (acpi_facs_t *) current;
201 current += sizeof(acpi_facs_t);
202 ALIGN_CURRENT;
203 acpi_create_facs(facs);
204
205 dsdt = (acpi_header_t *) current;
206 memcpy(dsdt, &AmlCode, sizeof(acpi_header_t));
207 current += dsdt->length;
208 memcpy(dsdt, &AmlCode, dsdt->length);
209 ALIGN_CURRENT;
210
211 printk(BIOS_DEBUG, "ACPI: * DSDT @ %p Length %x\n", dsdt,
212 dsdt->length);
213
214 printk(BIOS_DEBUG, "ACPI: * FADT\n");
215 fadt = (acpi_fadt_t *) current;
216 current += sizeof(acpi_fadt_t);
217 ALIGN_CURRENT;
218
219 acpi_create_fadt(fadt, facs, dsdt);
220 acpi_add_table(rsdp, fadt);
221
222 printk(BIOS_INFO, "ACPI: done.\n");
223 return current;
224}
225