summaryrefslogtreecommitdiff
path: root/src/soc/amd/common/block/acpi/tables.c
blob: b7c942c27a7f209a34b35f9a478ca9d6837a9311 (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
/* SPDX-License-Identifier: GPL-2.0-only */

#include <acpi/acpi.h>
#include <acpi/acpigen.h>
#include <amdblocks/acpi.h>
#include <amdblocks/chip.h>
#include <assert.h>
#include <cpu/amd/mtrr.h>
#include <device/device.h>
#include <types.h>

unsigned long southbridge_write_acpi_tables(const struct device *device,
		unsigned long current,
		struct acpi_rsdp *rsdp)
{
	return acpi_write_hpet(device, current, rsdp);
}

unsigned long acpi_fill_madt_irqoverride(unsigned long current)
{
	const struct soc_amd_common_config *cfg = soc_get_common_config();
	unsigned int i;
	uint8_t irq;
	uint8_t flags;

	for (i = 0; i < ARRAY_SIZE(cfg->irq_override); ++i) {
		irq = cfg->irq_override[i].irq;
		flags = cfg->irq_override[i].flags;

		if (!flags)
			continue;

		current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)current, 0,
							irq, irq, flags);
	}

	return current;
}

/* Used by \_SB.PCI0._CRS */
void acpi_fill_root_complex_tom(const struct device *device)
{
	msr_t msr;
	const char *scope;

	assert(device);

	scope = acpi_device_scope(device);
	assert(scope);
	acpigen_write_scope(scope);

	msr = rdmsr(TOP_MEM);
	acpigen_write_name_dword("TOM1", msr.lo);
	msr = rdmsr(TOP_MEM2);
	/*
	 * Since XP only implements parts of ACPI 2.0, we can't use a qword
	 * here.
	 * See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt
	 * slide 22ff.
	 * Shift value right by 20 bit to make it fit into 32bit,
	 * giving us 1MB granularity and a limit of almost 4Exabyte of memory.
	 */
	acpigen_write_name_dword("TOM2", (msr.hi << 12) | msr.lo >> 20);
	acpigen_pop_len();
}