blob: 61b2642aa95d600d2e8d7d84a56c443ace7c5002 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Andy Shevchenko286e77f2017-10-03 14:55:07 +03002/*
3 * Copyright (c) 2017 Intel Corporation
4 *
5 * Partially based on acpi.c for other x86 platforms
Andy Shevchenko286e77f2017-10-03 14:55:07 +03006 */
7
8#include <common.h>
9#include <cpu.h>
10#include <dm.h>
11#include <dm/uclass-internal.h>
12#include <asm/acpi_table.h>
13#include <asm/ioapic.h>
14#include <asm/mpspec.h>
15#include <asm/tables.h>
16#include <asm/arch/global_nvs.h>
17
18void acpi_create_fadt(struct acpi_fadt *fadt, struct acpi_facs *facs,
19 void *dsdt)
20{
21 struct acpi_table_header *header = &(fadt->header);
22
23 memset((void *)fadt, 0, sizeof(struct acpi_fadt));
24
25 acpi_fill_header(header, "FACP");
26 header->length = sizeof(struct acpi_fadt);
27 header->revision = 6;
28
29 fadt->firmware_ctrl = (u32)facs;
30 fadt->dsdt = (u32)dsdt;
31 fadt->preferred_pm_profile = ACPI_PM_UNSPECIFIED;
32
33 fadt->iapc_boot_arch = ACPI_FADT_VGA_NOT_PRESENT |
34 ACPI_FADT_NO_PCIE_ASPM_CONTROL;
35 fadt->flags =
36 ACPI_FADT_WBINVD |
37 ACPI_FADT_POWER_BUTTON | ACPI_FADT_SLEEP_BUTTON |
38 ACPI_FADT_SEALED_CASE | ACPI_FADT_HEADLESS |
39 ACPI_FADT_HW_REDUCED_ACPI;
40
41 fadt->minor_revision = 2;
42
43 fadt->x_firmware_ctl_l = (u32)facs;
44 fadt->x_firmware_ctl_h = 0;
45 fadt->x_dsdt_l = (u32)dsdt;
46 fadt->x_dsdt_h = 0;
47
48 header->checksum = table_compute_checksum(fadt, header->length);
49}
50
51u32 acpi_fill_madt(u32 current)
52{
53 current += acpi_create_madt_lapics(current);
54
55 current += acpi_create_madt_ioapic((struct acpi_madt_ioapic *)current,
56 io_apic_read(IO_APIC_ID) >> 24, IO_APIC_ADDR, 0);
57
58 return current;
59}
60
61u32 acpi_fill_mcfg(u32 current)
62{
63 /* TODO: Derive parameters from SFI MCFG table */
64 current += acpi_create_mcfg_mmconfig
65 ((struct acpi_mcfg_mmconfig *)current,
66 0x3f500000, 0x0, 0x0, 0x0);
67
68 return current;
69}
70
Andy Shevchenko70c62982019-07-14 19:23:59 +030071static u32 acpi_fill_csrt_dma(struct acpi_csrt_group *grp)
72{
73 struct acpi_csrt_shared_info *si = (struct acpi_csrt_shared_info *)&grp[1];
74
75 /* Fill the Resource Group with Shared Information attached */
76 memset(grp, 0, sizeof(*grp));
77 grp->shared_info_length = sizeof(struct acpi_csrt_shared_info);
78 grp->length = sizeof(struct acpi_csrt_group) + grp->shared_info_length;
79 /* TODO: All values below should come from U-Boot DT somehow */
80 sprintf((char *)&grp->vendor_id, "%04X", 0x8086);
81 grp->device_id = 0x11a2;
82
83 /* Fill the Resource Group Shared Information */
84 memset(si, 0, sizeof(*si));
85 si->major_version = 1;
86 si->minor_version = 0;
87 /* TODO: All values below should come from U-Boot DT somehow */
88 si->mmio_base_low = 0xff192000;
89 si->mmio_base_high = 0;
90 si->gsi_interrupt = 32;
91 si->interrupt_polarity = 1;
92 si->interrupt_mode = 0;
93 si->num_channels = 8;
94 si->dma_address_width = 32;
95 si->base_request_line = 0;
96 si->num_handshake_signals = 16;
97 si->max_block_size = 0x20000;
98
99 return grp->length;
100}
101
102u32 acpi_fill_csrt(u32 current)
103{
104 current += acpi_fill_csrt_dma((struct acpi_csrt_group *)current);
105
106 return current;
107}
108
Andy Shevchenko286e77f2017-10-03 14:55:07 +0300109void acpi_create_gnvs(struct acpi_global_nvs *gnvs)
110{
111 struct udevice *dev;
112 int ret;
113
114 /* at least we have one processor */
115 gnvs->pcnt = 1;
116
117 /* override the processor count with actual number */
118 ret = uclass_find_first_device(UCLASS_CPU, &dev);
119 if (ret == 0 && dev != NULL) {
120 ret = cpu_get_count(dev);
121 if (ret > 0)
122 gnvs->pcnt = ret;
123 }
124}