blob: 8bad755de1ae8c13104c258421fb8413d2e60e3b [file] [log] [blame]
Raul E Rangel0f3bc812021-02-10 16:36:33 -07001/* SPDX-License-Identifier: GPL-2.0-only */
2
3#include <acpi/acpi.h>
Raul E Rangel58a8ad12021-02-18 16:36:08 -07004#include <acpi/acpigen.h>
Raul E Rangel0f3bc812021-02-10 16:36:33 -07005#include <amdblocks/acpi.h>
Raul E Rangelffab5e62021-02-11 11:07:11 -07006#include <amdblocks/chip.h>
Raul E Rangel58a8ad12021-02-18 16:36:08 -07007#include <assert.h>
8#include <cpu/amd/msr.h>
9#include <cpu/amd/mtrr.h>
Raul E Rangel0f3bc812021-02-10 16:36:33 -070010#include <device/device.h>
11#include <types.h>
12
13unsigned long southbridge_write_acpi_tables(const struct device *device,
14 unsigned long current,
15 struct acpi_rsdp *rsdp)
16{
17 return acpi_write_hpet(device, current, rsdp);
18}
Raul E Rangel0e560e72021-02-11 10:10:57 -070019
20unsigned long acpi_fill_mcfg(unsigned long current)
21{
22
23 current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *)current,
24 CONFIG_MMCONF_BASE_ADDRESS,
25 0,
26 0,
27 CONFIG_MMCONF_BUS_NUMBER - 1);
28
29 return current;
30}
Raul E Rangelffab5e62021-02-11 11:07:11 -070031
32unsigned long acpi_fill_madt_irqoverride(unsigned long current)
33{
34 const struct soc_amd_common_config *cfg = soc_get_common_config();
35 unsigned int i;
36 uint8_t irq;
37 uint8_t flags;
38
39 for (i = 0; i < ARRAY_SIZE(cfg->irq_override); ++i) {
40 irq = cfg->irq_override[i].irq;
41 flags = cfg->irq_override[i].flags;
42
43 if (!flags)
44 continue;
45
46 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)current, 0,
47 irq, irq, flags);
48 }
49
50 return current;
51}
Raul E Rangel58a8ad12021-02-18 16:36:08 -070052
53/* Used by \_SB.PCI0._CRS */
54void acpi_fill_root_complex_tom(const struct device *device)
55{
56 msr_t msr;
57 const char *scope;
58
59 assert(device);
60
61 scope = acpi_device_scope(device);
62 assert(scope);
63 acpigen_write_scope(scope);
64
65 msr = rdmsr(TOP_MEM);
66 acpigen_write_name_dword("TOM1", msr.lo);
67 msr = rdmsr(TOP_MEM2);
68 /*
69 * Since XP only implements parts of ACPI 2.0, we can't use a qword
70 * here.
71 * See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt
72 * slide 22ff.
73 * Shift value right by 20 bit to make it fit into 32bit,
74 * giving us 1MB granularity and a limit of almost 4Exabyte of memory.
75 */
76 acpigen_write_name_dword("TOM2", (msr.hi << 12) | msr.lo >> 20);
77 acpigen_pop_len();
78}