blob: 4d44a49564d5291a0a2ea621d3a2c7a367772151 [file] [log] [blame]
Marc Jones1587dc82017-05-15 18:55:11 -06001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2015-2016 Advanced Micro Devices, Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16
17#include <arch/io.h>
18#include <arch/acpi.h>
19#include <arch/acpigen.h>
20#include <cbmem.h>
21#include <chip.h>
22#include <console/console.h>
Marc Jones1587dc82017-05-15 18:55:11 -060023#include <cpu/amd/mtrr.h>
24#include <cpu/cpu.h>
Marshall Dawsonf82aa102017-09-20 18:01:41 -060025#include <cpu/x86/msr.h>
Marc Jones1587dc82017-05-15 18:55:11 -060026#include <device/device.h>
27#include <device/pci.h>
28#include <device/pci_ids.h>
Marc Jones1587dc82017-05-15 18:55:11 -060029#include <agesawrapper.h>
30#include <agesawrapper_call.h>
31#include <soc/northbridge.h>
Marshall Dawson38bded02017-09-01 09:54:48 -060032#include <soc/pci_devs.h>
Marc Jones1587dc82017-05-15 18:55:11 -060033#include <stdint.h>
34#include <stdlib.h>
35#include <string.h>
36
Marc Jones1587dc82017-05-15 18:55:11 -060037typedef struct dram_base_mask {
Marshall Dawson4e101ad2017-06-15 12:17:38 -060038 u32 base; /* [47:27] at [28:8] */
39 u32 mask; /* [47:27] at [28:8] and enable at bit 0 */
Marc Jones1587dc82017-05-15 18:55:11 -060040} dram_base_mask_t;
41
Marshall Dawson38bded02017-09-01 09:54:48 -060042static dram_base_mask_t get_dram_base_mask(void)
Marc Jones1587dc82017-05-15 18:55:11 -060043{
Marshall Dawson38bded02017-09-01 09:54:48 -060044 device_t dev = dev_find_slot(0, ADDR_DEVFN);
Marc Jones1587dc82017-05-15 18:55:11 -060045 dram_base_mask_t d;
46 u32 temp;
Marshall Dawson4e101ad2017-06-15 12:17:38 -060047
48 /* [39:24] at [31:16] */
Marshall Dawson38bded02017-09-01 09:54:48 -060049 temp = pci_read_config32(dev, 0x44);
Marshall Dawson4e101ad2017-06-15 12:17:38 -060050
51 /* mask out DramMask [26:24] too */
52 d.mask = ((temp & 0xfff80000) >> (8 + 3));
53
54 /* [47:40] at [7:0] */
Marshall Dawson38bded02017-09-01 09:54:48 -060055 temp = pci_read_config32(dev, 0x144) & 0xff;
Marc Jones1587dc82017-05-15 18:55:11 -060056 d.mask |= temp << 21;
Marshall Dawson4e101ad2017-06-15 12:17:38 -060057
Marshall Dawson38bded02017-09-01 09:54:48 -060058 temp = pci_read_config32(dev, 0x40);
Marshall Dawson4e101ad2017-06-15 12:17:38 -060059 d.mask |= (temp & 1); /* enable bit */
60 d.base = ((temp & 0xfff80000) >> (8 + 3));
Marshall Dawson38bded02017-09-01 09:54:48 -060061 temp = pci_read_config32(dev, 0x140) & 0xff;
Marc Jones1587dc82017-05-15 18:55:11 -060062 d.base |= temp << 21;
63 return d;
64}
65
66static void set_io_addr_reg(device_t dev, u32 nodeid, u32 linkn, u32 reg,
67 u32 io_min, u32 io_max)
68{
69 u32 tempreg;
Marshall Dawson38bded02017-09-01 09:54:48 -060070 device_t addr_map = dev_find_slot(0, ADDR_DEVFN);
71
Marshall Dawson4e101ad2017-06-15 12:17:38 -060072 /* io range allocation. Limit */
73 tempreg = (nodeid & 0xf) | ((nodeid & 0x30) << (8 - 4)) | (linkn << 4)
74 | ((io_max & 0xf0) << (12 - 4));
Marshall Dawson38bded02017-09-01 09:54:48 -060075 pci_write_config32(addr_map, reg + 4, tempreg);
Marshall Dawson4e101ad2017-06-15 12:17:38 -060076 tempreg = 3 | ((io_min & 0xf0) << (12 - 4)); /* base: ISA and VGA ? */
Marshall Dawson38bded02017-09-01 09:54:48 -060077 pci_write_config32(addr_map, reg, tempreg);
Marc Jones1587dc82017-05-15 18:55:11 -060078}
79
Marshall Dawson4e101ad2017-06-15 12:17:38 -060080static void set_mmio_addr_reg(u32 nodeid, u32 linkn, u32 reg, u32 index,
81 u32 mmio_min, u32 mmio_max)
Marc Jones1587dc82017-05-15 18:55:11 -060082{
83 u32 tempreg;
Marshall Dawson38bded02017-09-01 09:54:48 -060084 device_t addr_map = dev_find_slot(0, ADDR_DEVFN);
85
Marshall Dawson4e101ad2017-06-15 12:17:38 -060086 /* io range allocation. Limit */
87 tempreg = (nodeid & 0xf) | (linkn << 4) | (mmio_max & 0xffffff00);
Marshall Dawson38bded02017-09-01 09:54:48 -060088 pci_write_config32(addr_map, reg + 4, tempreg);
Marc Jones1587dc82017-05-15 18:55:11 -060089 tempreg = 3 | (nodeid & 0x30) | (mmio_min & 0xffffff00);
Marshall Dawson38bded02017-09-01 09:54:48 -060090 pci_write_config32(addr_map, reg, tempreg);
Marc Jones1587dc82017-05-15 18:55:11 -060091}
92
Marc Jones1587dc82017-05-15 18:55:11 -060093static void read_resources(device_t dev)
94{
Marc Jones1587dc82017-05-15 18:55:11 -060095 /*
96 * This MMCONF resource must be reserved in the PCI domain.
97 * It is not honored by the coreboot resource allocator if it is in
98 * the CPU_CLUSTER.
99 */
100 mmconf_resource(dev, 0xc0010058);
101}
102
103static void set_resource(device_t dev, struct resource *resource, u32 nodeid)
104{
105 resource_t rbase, rend;
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600106 unsigned int reg, link_num;
Marc Jones1587dc82017-05-15 18:55:11 -0600107 char buf[50];
108
109 /* Make certain the resource has actually been set */
110 if (!(resource->flags & IORESOURCE_ASSIGNED))
111 return;
112
113 /* If I have already stored this resource don't worry about it */
114 if (resource->flags & IORESOURCE_STORED)
115 return;
116
117 /* Only handle PCI memory and IO resources */
118 if (!(resource->flags & (IORESOURCE_MEM | IORESOURCE_IO)))
119 return;
120
121 /* Ensure I am actually looking at a resource of function 1 */
122 if ((resource->index & 0xffff) < 0x1000)
123 return;
124
125 /* Get the base address */
126 rbase = resource->base;
127
128 /* Get the limit (rounded up) */
129 rend = resource_end(resource);
130
131 /* Get the register and link */
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600132 reg = resource->index & 0xfff; /* 4k */
Marc Jones1587dc82017-05-15 18:55:11 -0600133 link_num = IOINDEX_LINK(resource->index);
134
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600135 if (resource->flags & IORESOURCE_IO)
Marc Jones1587dc82017-05-15 18:55:11 -0600136 set_io_addr_reg(dev, nodeid, link_num, reg, rbase>>8, rend>>8);
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600137 else if (resource->flags & IORESOURCE_MEM)
138 set_mmio_addr_reg(nodeid, link_num, reg,
139 (resource->index >> 24), rbase >> 8, rend >> 8);
140
Marc Jones1587dc82017-05-15 18:55:11 -0600141 resource->flags |= IORESOURCE_STORED;
142 snprintf(buf, sizeof(buf), " <node %x link %x>",
143 nodeid, link_num);
144 report_resource_stored(dev, resource, buf);
145}
146
147/**
148 * I tried to reuse the resource allocation code in set_resource()
149 * but it is too difficult to deal with the resource allocation magic.
150 */
151
152static void create_vga_resource(device_t dev)
153{
154 struct bus *link;
155
156 /* find out which link the VGA card is connected,
157 * we only deal with the 'first' vga card */
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600158 for (link = dev->link_list ; link ; link = link->next)
Marc Jones1587dc82017-05-15 18:55:11 -0600159 if (link->bridge_ctrl & PCI_BRIDGE_CTL_VGA)
160 break;
Marc Jones1587dc82017-05-15 18:55:11 -0600161
162 /* no VGA card installed */
163 if (link == NULL)
164 return;
165
Marshall Dawsone2697de2017-09-06 10:46:36 -0600166 printk(BIOS_DEBUG, "VGA: %s has VGA device\n", dev_path(dev));
Marshall Dawson38bded02017-09-01 09:54:48 -0600167 /* Route A0000-BFFFF, IO 3B0-3BB 3C0-3DF */
168 pci_write_config32(dev_find_slot(0, ADDR_DEVFN), 0xf4, 1);
Marc Jones1587dc82017-05-15 18:55:11 -0600169}
170
171static void set_resources(device_t dev)
172{
173 struct bus *bus;
174 struct resource *res;
175
176
177 /* do we need this? */
178 create_vga_resource(dev);
179
180 /* Set each resource we have found */
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600181 for (res = dev->resource_list ; res ; res = res->next)
Marc Jones1587dc82017-05-15 18:55:11 -0600182 set_resource(dev, res, 0);
Marc Jones1587dc82017-05-15 18:55:11 -0600183
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600184 for (bus = dev->link_list ; bus ; bus = bus->next)
185 if (bus->children)
Marc Jones1587dc82017-05-15 18:55:11 -0600186 assign_resources(bus);
Marc Jones1587dc82017-05-15 18:55:11 -0600187}
188
189static void northbridge_init(struct device *dev)
190{
191}
192
193static unsigned long acpi_fill_hest(acpi_hest_t *hest)
194{
195 void *addr, *current;
196
197 /* Skip the HEST header. */
198 current = (void *)(hest + 1);
199
200 addr = agesawrapper_getlateinitptr(PICK_WHEA_MCE);
201 if (addr != NULL)
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600202 current += acpi_create_hest_error_source(hest, current, 0,
203 (void *)((u32)addr + 2), *(UINT16 *)addr - 2);
Marc Jones1587dc82017-05-15 18:55:11 -0600204
205 addr = agesawrapper_getlateinitptr(PICK_WHEA_CMC);
206 if (addr != NULL)
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600207 current += acpi_create_hest_error_source(hest, current, 1,
208 (void *)((u32)addr + 2), *(UINT16 *)addr - 2);
Marc Jones1587dc82017-05-15 18:55:11 -0600209
210 return (unsigned long)current;
211}
212
213static void northbridge_fill_ssdt_generator(device_t device)
214{
215 msr_t msr;
216 char pscope[] = "\\_SB.PCI0";
217
218 acpigen_write_scope(pscope);
219 msr = rdmsr(TOP_MEM);
220 acpigen_write_name_dword("TOM1", msr.lo);
221 msr = rdmsr(TOP_MEM2);
222 /*
223 * Since XP only implements parts of ACPI 2.0, we can't use a qword
224 * here.
225 * See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt
226 * slide 22ff.
227 * Shift value right by 20 bit to make it fit into 32bit,
228 * giving us 1MB granularity and a limit of almost 4Exabyte of memory.
229 */
230 acpigen_write_name_dword("TOM2", (msr.hi << 12) | msr.lo >> 20);
231 acpigen_pop_len();
232}
233
234static unsigned long agesa_write_acpi_tables(device_t device,
235 unsigned long current,
236 acpi_rsdp_t *rsdp)
237{
238 acpi_srat_t *srat;
239 acpi_slit_t *slit;
240 acpi_header_t *ssdt;
241 acpi_header_t *alib;
242 acpi_header_t *ivrs;
243 acpi_hest_t *hest;
244
245 /* HEST */
246 current = ALIGN(current, 8);
247 hest = (acpi_hest_t *)current;
248 acpi_write_hest((void *)current, acpi_fill_hest);
249 acpi_add_table(rsdp, (void *)current);
250 current += ((acpi_header_t *)current)->length;
251
252 current = ALIGN(current, 8);
253 printk(BIOS_DEBUG, "ACPI: * IVRS at %lx\n", current);
254 ivrs = agesawrapper_getlateinitptr(PICK_IVRS);
255 if (ivrs != NULL) {
256 memcpy((void *)current, ivrs, ivrs->length);
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600257 ivrs = (acpi_header_t *)current;
Marc Jones1587dc82017-05-15 18:55:11 -0600258 current += ivrs->length;
259 acpi_add_table(rsdp, ivrs);
260 } else {
261 printk(BIOS_DEBUG, " AGESA IVRS table NULL. Skipping.\n");
262 }
263
264 /* SRAT */
265 current = ALIGN(current, 8);
266 printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current);
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600267 srat = (acpi_srat_t *)agesawrapper_getlateinitptr(PICK_SRAT);
Marc Jones1587dc82017-05-15 18:55:11 -0600268 if (srat != NULL) {
269 memcpy((void *)current, srat, srat->header.length);
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600270 srat = (acpi_srat_t *)current;
Marc Jones1587dc82017-05-15 18:55:11 -0600271 current += srat->header.length;
272 acpi_add_table(rsdp, srat);
273 } else {
274 printk(BIOS_DEBUG, " AGESA SRAT table NULL. Skipping.\n");
275 }
276
277 /* SLIT */
278 current = ALIGN(current, 8);
279 printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current);
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600280 slit = (acpi_slit_t *)agesawrapper_getlateinitptr(PICK_SLIT);
Marc Jones1587dc82017-05-15 18:55:11 -0600281 if (slit != NULL) {
282 memcpy((void *)current, slit, slit->header.length);
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600283 slit = (acpi_slit_t *)current;
Marc Jones1587dc82017-05-15 18:55:11 -0600284 current += slit->header.length;
285 acpi_add_table(rsdp, slit);
286 } else {
287 printk(BIOS_DEBUG, " AGESA SLIT table NULL. Skipping.\n");
288 }
289
290 /* ALIB */
291 current = ALIGN(current, 16);
292 printk(BIOS_DEBUG, "ACPI: * AGESA ALIB SSDT at %lx\n", current);
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600293 alib = (acpi_header_t *)agesawrapper_getlateinitptr(PICK_ALIB);
Marc Jones1587dc82017-05-15 18:55:11 -0600294 if (alib != NULL) {
295 memcpy((void *)current, alib, alib->length);
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600296 alib = (acpi_header_t *)current;
Marc Jones1587dc82017-05-15 18:55:11 -0600297 current += alib->length;
298 acpi_add_table(rsdp, (void *)alib);
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600299 } else {
300 printk(BIOS_DEBUG, " AGESA ALIB SSDT table NULL."
301 " Skipping.\n");
Marc Jones1587dc82017-05-15 18:55:11 -0600302 }
303
Marc Jones1587dc82017-05-15 18:55:11 -0600304 current = ALIGN(current, 16);
305 printk(BIOS_DEBUG, "ACPI: * SSDT at %lx\n", current);
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600306 ssdt = (acpi_header_t *)agesawrapper_getlateinitptr(PICK_PSTATE);
Marc Jones1587dc82017-05-15 18:55:11 -0600307 if (ssdt != NULL) {
308 memcpy((void *)current, ssdt, ssdt->length);
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600309 ssdt = (acpi_header_t *)current;
Marc Jones1587dc82017-05-15 18:55:11 -0600310 current += ssdt->length;
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600311 } else {
Marc Jones1587dc82017-05-15 18:55:11 -0600312 printk(BIOS_DEBUG, " AGESA PState table NULL. Skipping.\n");
313 }
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600314 acpi_add_table(rsdp, ssdt);
Marc Jones1587dc82017-05-15 18:55:11 -0600315
316 printk(BIOS_DEBUG, "ACPI: * SSDT for PState at %lx\n", current);
317 return current;
318}
319
320static struct device_operations northbridge_operations = {
321 .read_resources = read_resources,
322 .set_resources = set_resources,
323 .enable_resources = pci_dev_enable_resources,
324 .init = northbridge_init,
325 .acpi_fill_ssdt_generator = northbridge_fill_ssdt_generator,
326 .write_acpi_tables = agesa_write_acpi_tables,
327 .enable = 0,
328 .ops_pci = 0,
329};
330
331static const struct pci_driver family15_northbridge __pci_driver = {
332 .ops = &northbridge_operations,
333 .vendor = PCI_VENDOR_ID_AMD,
334 .device = PCI_DEVICE_ID_AMD_15H_MODEL_707F_NB_HT,
335};
336
337void fam15_finalize(void *chip_info)
338{
339 device_t dev;
340 u32 value;
341 dev = dev_find_slot(0, PCI_DEVFN(0, 0)); /* clear IoapicSbFeatureEn */
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600342 pci_write_config32(dev, 0xf8, 0);
343 pci_write_config32(dev, 0xfc, 5); /* TODO: move it to dsdt.asl */
Marc Jones1587dc82017-05-15 18:55:11 -0600344
345 /* disable No Snoop */
346 dev = dev_find_slot(0, PCI_DEVFN(1, 1));
347 value = pci_read_config32(dev, 0x60);
348 value &= ~(1 << 11);
349 pci_write_config32(dev, 0x60, value);
350}
351
352void domain_read_resources(device_t dev)
353{
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600354 unsigned int reg;
Marshall Dawson38bded02017-09-01 09:54:48 -0600355 device_t addr_map = dev_find_slot(0, ADDR_DEVFN);
Marc Jones1587dc82017-05-15 18:55:11 -0600356
357 /* Find the already assigned resource pairs */
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600358 for (reg = 0x80 ; reg <= 0xd8 ; reg += 0x08) {
Marc Jones1587dc82017-05-15 18:55:11 -0600359 u32 base, limit;
Marshall Dawson38bded02017-09-01 09:54:48 -0600360 base = pci_read_config32(addr_map, reg);
361 limit = pci_read_config32(addr_map, reg + 4);
Marc Jones1587dc82017-05-15 18:55:11 -0600362 /* Is this register allocated? */
363 if ((base & 3) != 0) {
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600364 unsigned int nodeid, reg_link;
Marshall Dawson38bded02017-09-01 09:54:48 -0600365 device_t reg_dev = dev_find_slot(0, HT_DEVFN);
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600366 if (reg < 0xc0) /* mmio */
Marc Jones1587dc82017-05-15 18:55:11 -0600367 nodeid = (limit & 0xf) + (base & 0x30);
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600368 else /* io */
Marc Jones1587dc82017-05-15 18:55:11 -0600369 nodeid = (limit & 0xf) + ((base >> 4) & 0x30);
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600370
Marc Jones1587dc82017-05-15 18:55:11 -0600371 reg_link = (limit >> 4) & 7;
Marc Jones1587dc82017-05-15 18:55:11 -0600372 if (reg_dev) {
373 /* Reserve the resource */
374 struct resource *res;
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600375 res = new_resource(reg_dev,
376 IOINDEX(0x1000 + reg,
377 reg_link));
378 if (res)
Marc Jones1587dc82017-05-15 18:55:11 -0600379 res->flags = 1;
Marc Jones1587dc82017-05-15 18:55:11 -0600380 }
381 }
382 }
383 /* FIXME: do we need to check extend conf space?
384 I don't believe that much preset value */
385
386 pci_domain_read_resources(dev);
387}
388
389void domain_enable_resources(device_t dev)
390{
391 if (acpi_is_wakeup_s3())
392 AGESAWRAPPER(fchs3laterestore);
393
394 /* Must be called after PCI enumeration and resource allocation */
395 if (!acpi_is_wakeup_s3())
396 AGESAWRAPPER(amdinitmid);
397
398 printk(BIOS_DEBUG, " ader - leaving domain_enable_resources.\n");
399}
400
Marc Jones1587dc82017-05-15 18:55:11 -0600401void domain_set_resources(device_t dev)
402{
403 unsigned long mmio_basek;
404 u32 pci_tolm;
Marshall Dawson29f1b742017-09-06 14:59:45 -0600405 u32 hole;
Marshall Dawson38bded02017-09-01 09:54:48 -0600406 int idx;
Marc Jones1587dc82017-05-15 18:55:11 -0600407 struct bus *link;
Marshall Dawsonb6172112017-09-13 17:47:31 -0600408 void *tseg_base;
409 size_t tseg_size;
Marc Jones1587dc82017-05-15 18:55:11 -0600410
411 pci_tolm = 0xffffffffUL;
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600412 for (link = dev->link_list ; link ; link = link->next)
Marc Jones1587dc82017-05-15 18:55:11 -0600413 pci_tolm = find_pci_tolm(link);
Marc Jones1587dc82017-05-15 18:55:11 -0600414
Marshall Dawson29f1b742017-09-06 14:59:45 -0600415 /* Start with alignment supportable in variable MTRR */
416 mmio_basek = ALIGN_DOWN(pci_tolm, 4 * KiB) / KiB;
Marc Jones1587dc82017-05-15 18:55:11 -0600417
Marshall Dawson29f1b742017-09-06 14:59:45 -0600418 /*
419 * AGESA may have programmed the memory hole and rounded down to a
420 * 128MB boundary. If we find it's valid, adjust mmio_basek downward
421 * to the hole bottom. D18F1xF0[DramHoleBase] is granular to 16MB.
Marc Jones1587dc82017-05-15 18:55:11 -0600422 */
Marshall Dawson29f1b742017-09-06 14:59:45 -0600423 hole = pci_read_config32(dev_find_slot(0, ADDR_DEVFN), D18F1_DRAM_HOLE);
424 if (hole & DRAM_HOLE_VALID)
425 mmio_basek = min(mmio_basek, ALIGN_DOWN(hole, 16 * MiB) / KiB);
Marc Jones1587dc82017-05-15 18:55:11 -0600426
427 idx = 0x10;
Marshall Dawson38bded02017-09-01 09:54:48 -0600428 dram_base_mask_t d;
429 resource_t basek, limitk, sizek; /* 4 1T */
Marc Jones1587dc82017-05-15 18:55:11 -0600430
Marshall Dawson38bded02017-09-01 09:54:48 -0600431 d = get_dram_base_mask();
Marc Jones1587dc82017-05-15 18:55:11 -0600432
Marshall Dawson38bded02017-09-01 09:54:48 -0600433 if ((d.mask & 1)) { /* if enabled... */
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600434 /* could overflow, we may lose 6 bit here */
435 basek = ((resource_t)(d.base & 0x1fffff00)) << 9;
436 limitk = ((resource_t)(((d.mask & ~1) + 0x000ff)
437 & 0x1fffff00)) << 9;
Marc Jones1587dc82017-05-15 18:55:11 -0600438
439 sizek = limitk - basek;
440
441 /* see if we need a hole from 0xa0000 to 0xbffff */
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600442 if ((basek < ((8 * 64) + (8 * 16))) && (sizek > ((8 * 64) +
443 (16 * 16)))) {
Marshall Dawson38bded02017-09-01 09:54:48 -0600444 ram_resource(dev, idx, basek,
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600445 ((8 * 64) + (8 * 16)) - basek);
Marc Jones1587dc82017-05-15 18:55:11 -0600446 idx += 0x10;
447 basek = (8 * 64) + (16 * 16);
448 sizek = limitk - ((8 * 64) + (16 * 16));
449
450 }
451
452 /* split the region to accommodate pci memory space */
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600453 if ((basek < 4 * 1024 * 1024) && (limitk > mmio_basek)) {
Marc Jones1587dc82017-05-15 18:55:11 -0600454 if (basek <= mmio_basek) {
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600455 unsigned int pre_sizek;
Marc Jones1587dc82017-05-15 18:55:11 -0600456 pre_sizek = mmio_basek - basek;
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600457 if (pre_sizek > 0) {
Marshall Dawson38bded02017-09-01 09:54:48 -0600458 ram_resource(dev, idx, basek,
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600459 pre_sizek);
Marc Jones1587dc82017-05-15 18:55:11 -0600460 idx += 0x10;
461 sizek -= pre_sizek;
462 }
463 basek = mmio_basek;
464 }
465 if ((basek + sizek) <= 4 * 1024 * 1024) {
466 sizek = 0;
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600467 } else {
Marc Jones1587dc82017-05-15 18:55:11 -0600468 uint64_t topmem2 = bsp_topmem2();
469 basek = 4 * 1024 * 1024;
470 sizek = topmem2 / 1024 - basek;
471 }
472 }
473
Marshall Dawson38bded02017-09-01 09:54:48 -0600474 ram_resource(dev, idx, basek, sizek);
475 printk(BIOS_DEBUG, "node 0: mmio_basek=%08lx, basek=%08llx,"
476 " limitk=%08llx\n", mmio_basek, basek, limitk);
Marc Jones1587dc82017-05-15 18:55:11 -0600477 }
478
Marshall Dawson7ac2af32017-09-19 16:26:34 -0600479 /* UMA is not set up yet, but infer the base & size to make cacheable */
480 uint32_t uma_base = restore_top_of_low_cacheable();
481 if (uma_base != bsp_topmem()) {
482 uint32_t uma_size = bsp_topmem() - uma_base;
483 printk(BIOS_INFO, "%s: uma size 0x%08x, memory start 0x%08x\n",
484 __func__, uma_size, uma_base);
485 reserved_ram_resource(dev, 7, uma_base / KiB, uma_size / KiB);
486 }
Marc Jones1587dc82017-05-15 18:55:11 -0600487
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600488 for (link = dev->link_list ; link ; link = link->next)
489 if (link->children)
Marc Jones1587dc82017-05-15 18:55:11 -0600490 assign_resources(link);
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600491
Marc Jones1587dc82017-05-15 18:55:11 -0600492 /*
493 * Reserve everything between A segment and 1MB:
494 *
495 * 0xa0000 - 0xbffff: legacy VGA
496 * 0xc0000 - 0xfffff: RAM
497 */
498 mmio_resource(dev, 0xa0000, 0xa0000 / KiB, 0x20000 / KiB);
499 reserved_ram_resource(dev, 0xc0000, 0xc0000 / KiB, 0x40000 / KiB);
Marshall Dawsonb6172112017-09-13 17:47:31 -0600500
501 /* Reserve TSEG */
502 smm_region_info(&tseg_base, &tseg_size);
503 idx += 0x10;
504 reserved_ram_resource(dev, idx, (unsigned long)tseg_base/KiB,
505 tseg_size/KiB);
Marc Jones1587dc82017-05-15 18:55:11 -0600506}
507
Marc Jones1587dc82017-05-15 18:55:11 -0600508/*********************************************************************
509 * Change the vendor / device IDs to match the generic VBIOS header. *
510 *********************************************************************/
511u32 map_oprom_vendev(u32 vendev)
512{
513 u32 new_vendev;
514 new_vendev =
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600515 ((vendev >= 0x100298e0) && (vendev <= 0x100298ef)) ?
516 0x100298e0 : vendev;
Marc Jones1587dc82017-05-15 18:55:11 -0600517
518 if (vendev != new_vendev)
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600519 printk(BIOS_NOTICE, "Mapping PCI device %8x to %8x\n",
520 vendev, new_vendev);
Marc Jones1587dc82017-05-15 18:55:11 -0600521
522 return new_vendev;
523}