blob: 3ffba3897aad880dafb86a4082088b84c0baba78 [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>
Simon Glass858fed12020-04-08 16:57:36 -060011#include <acpi/acpi_table.h>
Andy Shevchenko286e77f2017-10-03 14:55:07 +030012#include <asm/ioapic.h>
13#include <asm/mpspec.h>
14#include <asm/tables.h>
15#include <asm/arch/global_nvs.h>
Andy Shevchenkob04ef3b2019-08-29 17:04:19 +030016#include <asm/arch/iomap.h>
Simon Glass858fed12020-04-08 16:57:36 -060017#include <dm/uclass-internal.h>
Andy Shevchenko286e77f2017-10-03 14:55:07 +030018
Andy Shevchenko33e030b2022-03-30 18:49:18 +030019void acpi_create_fadt(struct acpi_fadt *fadt, struct acpi_facs *facs,
20 void *dsdt)
Andy Shevchenko286e77f2017-10-03 14:55:07 +030021{
Andy Shevchenko33e030b2022-03-30 18:49:18 +030022 struct acpi_table_header *header = &(fadt->header);
Andy Shevchenko286e77f2017-10-03 14:55:07 +030023
Andy Shevchenko33e030b2022-03-30 18:49:18 +030024 memset((void *)fadt, 0, sizeof(struct acpi_fadt));
Andy Shevchenko286e77f2017-10-03 14:55:07 +030025
26 acpi_fill_header(header, "FACP");
27 header->length = sizeof(struct acpi_fadt);
28 header->revision = 6;
29
Andy Shevchenko33e030b2022-03-30 18:49:18 +030030 fadt->firmware_ctrl = (u32)facs;
31 fadt->dsdt = (u32)dsdt;
Andy Shevchenko286e77f2017-10-03 14:55:07 +030032 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
Andy Shevchenko33e030b2022-03-30 18:49:18 +030044 fadt->x_firmware_ctl_l = (u32)facs;
Andy Shevchenko286e77f2017-10-03 14:55:07 +030045 fadt->x_firmware_ctl_h = 0;
Andy Shevchenko33e030b2022-03-30 18:49:18 +030046 fadt->x_dsdt_l = (u32)dsdt;
Andy Shevchenko286e77f2017-10-03 14:55:07 +030047 fadt->x_dsdt_h = 0;
48
49 header->checksum = table_compute_checksum(fadt, header->length);
50}
51
52u32 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
Moritz Fischerc6561722022-02-05 12:17:45 -080062int acpi_fill_mcfg(struct acpi_ctx *ctx)
Andy Shevchenko286e77f2017-10-03 14:55:07 +030063{
Moritz Fischerc6561722022-02-05 12:17:45 -080064 size_t size;
65
Andy Shevchenko286e77f2017-10-03 14:55:07 +030066 /* TODO: Derive parameters from SFI MCFG table */
Moritz Fischerc6561722022-02-05 12:17:45 -080067 size = acpi_create_mcfg_mmconfig
68 ((struct acpi_mcfg_mmconfig *)ctx->current,
Andy Shevchenkob04ef3b2019-08-29 17:04:19 +030069 MCFG_BASE_ADDRESS, 0x0, 0x0, 0x0);
Moritz Fischerc6561722022-02-05 12:17:45 -080070 acpi_inc(ctx, size);
Andy Shevchenko286e77f2017-10-03 14:55:07 +030071
Moritz Fischerc6561722022-02-05 12:17:45 -080072 return 0;
Andy Shevchenko286e77f2017-10-03 14:55:07 +030073}
74
Andy Shevchenko70c62982019-07-14 19:23:59 +030075static u32 acpi_fill_csrt_dma(struct acpi_csrt_group *grp)
76{
77 struct acpi_csrt_shared_info *si = (struct acpi_csrt_shared_info *)&grp[1];
78
79 /* Fill the Resource Group with Shared Information attached */
80 memset(grp, 0, sizeof(*grp));
81 grp->shared_info_length = sizeof(struct acpi_csrt_shared_info);
82 grp->length = sizeof(struct acpi_csrt_group) + grp->shared_info_length;
83 /* TODO: All values below should come from U-Boot DT somehow */
84 sprintf((char *)&grp->vendor_id, "%04X", 0x8086);
85 grp->device_id = 0x11a2;
86
87 /* Fill the Resource Group Shared Information */
88 memset(si, 0, sizeof(*si));
89 si->major_version = 1;
90 si->minor_version = 0;
91 /* TODO: All values below should come from U-Boot DT somehow */
92 si->mmio_base_low = 0xff192000;
93 si->mmio_base_high = 0;
94 si->gsi_interrupt = 32;
Andy Shevchenkoda28b582021-07-30 23:15:44 +030095 si->interrupt_polarity = 0; /* Active High */
96 si->interrupt_mode = 0; /* Level triggered */
Andy Shevchenko70c62982019-07-14 19:23:59 +030097 si->num_channels = 8;
98 si->dma_address_width = 32;
99 si->base_request_line = 0;
100 si->num_handshake_signals = 16;
Andy Shevchenko613092b2019-08-29 17:04:20 +0300101 si->max_block_size = 0x1ffff;
Andy Shevchenko70c62982019-07-14 19:23:59 +0300102
103 return grp->length;
104}
105
Simon Glass89ce5192021-12-01 09:03:01 -0700106int acpi_fill_csrt(struct acpi_ctx *ctx)
Andy Shevchenko70c62982019-07-14 19:23:59 +0300107{
Simon Glass89ce5192021-12-01 09:03:01 -0700108 int size;
109
110 size = acpi_fill_csrt_dma(ctx->current);
111 acpi_inc(ctx, size);
Andy Shevchenko70c62982019-07-14 19:23:59 +0300112
Simon Glass89ce5192021-12-01 09:03:01 -0700113 return 0;
Andy Shevchenko70c62982019-07-14 19:23:59 +0300114}
115
Simon Glass9ed41e72020-07-07 21:32:05 -0600116int acpi_create_gnvs(struct acpi_global_nvs *gnvs)
Andy Shevchenko286e77f2017-10-03 14:55:07 +0300117{
118 struct udevice *dev;
119 int ret;
120
121 /* at least we have one processor */
122 gnvs->pcnt = 1;
123
124 /* override the processor count with actual number */
125 ret = uclass_find_first_device(UCLASS_CPU, &dev);
126 if (ret == 0 && dev != NULL) {
127 ret = cpu_get_count(dev);
128 if (ret > 0)
129 gnvs->pcnt = ret;
130 }
Simon Glass9ed41e72020-07-07 21:32:05 -0600131
132 return 0;
Andy Shevchenko286e77f2017-10-03 14:55:07 +0300133}