xref: /openbmc/u-boot/arch/x86/cpu/tangier/acpi.c (revision c68c03f5)
1 /*
2  * Copyright (c) 2017 Intel Corporation
3  *
4  * Partially based on acpi.c for other x86 platforms
5  *
6  * SPDX-License-Identifier:	GPL-2.0+
7  */
8 
9 #include <common.h>
10 #include <cpu.h>
11 #include <dm.h>
12 #include <dm/uclass-internal.h>
13 #include <asm/acpi_table.h>
14 #include <asm/ioapic.h>
15 #include <asm/mpspec.h>
16 #include <asm/tables.h>
17 #include <asm/arch/global_nvs.h>
18 
19 void acpi_create_fadt(struct acpi_fadt *fadt, struct acpi_facs *facs,
20 		      void *dsdt)
21 {
22 	struct acpi_table_header *header = &(fadt->header);
23 
24 	memset((void *)fadt, 0, sizeof(struct acpi_fadt));
25 
26 	acpi_fill_header(header, "FACP");
27 	header->length = sizeof(struct acpi_fadt);
28 	header->revision = 6;
29 
30 	fadt->firmware_ctrl = (u32)facs;
31 	fadt->dsdt = (u32)dsdt;
32 	fadt->preferred_pm_profile = ACPI_PM_UNSPECIFIED;
33 
34 	fadt->iapc_boot_arch = ACPI_FADT_VGA_NOT_PRESENT |
35 			       ACPI_FADT_NO_PCIE_ASPM_CONTROL;
36 	fadt->flags =
37 		ACPI_FADT_WBINVD |
38 		ACPI_FADT_POWER_BUTTON | ACPI_FADT_SLEEP_BUTTON |
39 		ACPI_FADT_SEALED_CASE | ACPI_FADT_HEADLESS |
40 		ACPI_FADT_HW_REDUCED_ACPI;
41 
42 	fadt->minor_revision = 2;
43 
44 	fadt->x_firmware_ctl_l = (u32)facs;
45 	fadt->x_firmware_ctl_h = 0;
46 	fadt->x_dsdt_l = (u32)dsdt;
47 	fadt->x_dsdt_h = 0;
48 
49 	header->checksum = table_compute_checksum(fadt, header->length);
50 }
51 
52 u32 acpi_fill_madt(u32 current)
53 {
54 	current += acpi_create_madt_lapics(current);
55 
56 	current += acpi_create_madt_ioapic((struct acpi_madt_ioapic *)current,
57 			io_apic_read(IO_APIC_ID) >> 24, IO_APIC_ADDR, 0);
58 
59 	return current;
60 }
61 
62 u32 acpi_fill_mcfg(u32 current)
63 {
64 	/* TODO: Derive parameters from SFI MCFG table */
65 	current += acpi_create_mcfg_mmconfig
66 		((struct acpi_mcfg_mmconfig *)current,
67 		0x3f500000, 0x0, 0x0, 0x0);
68 
69 	return current;
70 }
71 
72 void acpi_create_gnvs(struct acpi_global_nvs *gnvs)
73 {
74 	struct udevice *dev;
75 	int ret;
76 
77 	/* at least we have one processor */
78 	gnvs->pcnt = 1;
79 
80 	/* override the processor count with actual number */
81 	ret = uclass_find_first_device(UCLASS_CPU, &dev);
82 	if (ret == 0 && dev != NULL) {
83 		ret = cpu_get_count(dev);
84 		if (ret > 0)
85 			gnvs->pcnt = ret;
86 	}
87 }
88