1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright (c) 2017 Intel Corporation
4 *
5 * Partially based on acpi.c for other x86 platforms
6 */
7
8 #include <common.h>
9 #include <cpu.h>
10 #include <dm.h>
11 #include <acpi/acpi_table.h>
12 #include <asm/ioapic.h>
13 #include <asm/mpspec.h>
14 #include <asm/tables.h>
15 #include <asm/arch/global_nvs.h>
16 #include <asm/arch/iomap.h>
17 #include <dm/uclass-internal.h>
18
acpi_create_fadt(struct acpi_fadt * fadt,struct acpi_facs * facs,void * dsdt)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
acpi_fill_madt(u32 current)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
acpi_fill_mcfg(u32 current)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 MCFG_BASE_ADDRESS, 0x0, 0x0, 0x0);
68
69 return current;
70 }
71
acpi_fill_csrt_dma(struct acpi_csrt_group * grp)72 static u32 acpi_fill_csrt_dma(struct acpi_csrt_group *grp)
73 {
74 struct acpi_csrt_shared_info *si = (struct acpi_csrt_shared_info *)&grp[1];
75
76 /* Fill the Resource Group with Shared Information attached */
77 memset(grp, 0, sizeof(*grp));
78 grp->shared_info_length = sizeof(struct acpi_csrt_shared_info);
79 grp->length = sizeof(struct acpi_csrt_group) + grp->shared_info_length;
80 /* TODO: All values below should come from U-Boot DT somehow */
81 sprintf((char *)&grp->vendor_id, "%04X", 0x8086);
82 grp->device_id = 0x11a2;
83
84 /* Fill the Resource Group Shared Information */
85 memset(si, 0, sizeof(*si));
86 si->major_version = 1;
87 si->minor_version = 0;
88 /* TODO: All values below should come from U-Boot DT somehow */
89 si->mmio_base_low = 0xff192000;
90 si->mmio_base_high = 0;
91 si->gsi_interrupt = 32;
92 si->interrupt_polarity = 1;
93 si->interrupt_mode = 0;
94 si->num_channels = 8;
95 si->dma_address_width = 32;
96 si->base_request_line = 0;
97 si->num_handshake_signals = 16;
98 si->max_block_size = 0x1ffff;
99
100 return grp->length;
101 }
102
acpi_fill_csrt(u32 current)103 u32 acpi_fill_csrt(u32 current)
104 {
105 current += acpi_fill_csrt_dma((struct acpi_csrt_group *)current);
106
107 return current;
108 }
109
acpi_create_gnvs(struct acpi_global_nvs * gnvs)110 int acpi_create_gnvs(struct acpi_global_nvs *gnvs)
111 {
112 struct udevice *dev;
113 int ret;
114
115 /* at least we have one processor */
116 gnvs->pcnt = 1;
117
118 /* override the processor count with actual number */
119 ret = uclass_find_first_device(UCLASS_CPU, &dev);
120 if (ret == 0 && dev != NULL) {
121 ret = cpu_get_count(dev);
122 if (ret > 0)
123 gnvs->pcnt = ret;
124 }
125
126 return 0;
127 }
128