blob: 1d37cc9e2b0db384cfe951980fa8a8b71fd4886b [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
Tom Riniabb9a042024-05-18 20:20:43 -06008#include <common.h>
Andy Shevchenko286e77f2017-10-03 14:55:07 +03009#include <cpu.h>
10#include <dm.h>
Heinrich Schuchardtec958062023-12-16 09:11:57 +010011#include <mapmem.h>
Simon Glass858fed12020-04-08 16:57:36 -060012#include <acpi/acpi_table.h>
Andy Shevchenko286e77f2017-10-03 14:55:07 +030013#include <asm/ioapic.h>
14#include <asm/mpspec.h>
15#include <asm/tables.h>
16#include <asm/arch/global_nvs.h>
Andy Shevchenkob04ef3b2019-08-29 17:04:19 +030017#include <asm/arch/iomap.h>
Simon Glass858fed12020-04-08 16:57:36 -060018#include <dm/uclass-internal.h>
Andy Shevchenko286e77f2017-10-03 14:55:07 +030019
Simon Glass9bd6b622023-09-01 11:27:09 -060020static int tangier_write_fadt(struct acpi_ctx *ctx,
21 const struct acpi_writer *entry)
Andy Shevchenko286e77f2017-10-03 14:55:07 +030022{
Simon Glass9bd6b622023-09-01 11:27:09 -060023 struct acpi_table_header *header;
24 struct acpi_fadt *fadt;
Andy Shevchenko286e77f2017-10-03 14:55:07 +030025
Simon Glass9bd6b622023-09-01 11:27:09 -060026 fadt = ctx->current;
27 header = &fadt->header;
28
29 memset(fadt, '\0', sizeof(struct acpi_fadt));
Andy Shevchenko286e77f2017-10-03 14:55:07 +030030
31 acpi_fill_header(header, "FACP");
32 header->length = sizeof(struct acpi_fadt);
33 header->revision = 6;
34
Andy Shevchenko286e77f2017-10-03 14:55:07 +030035 fadt->preferred_pm_profile = ACPI_PM_UNSPECIFIED;
36
37 fadt->iapc_boot_arch = ACPI_FADT_VGA_NOT_PRESENT |
38 ACPI_FADT_NO_PCIE_ASPM_CONTROL;
39 fadt->flags =
40 ACPI_FADT_WBINVD |
41 ACPI_FADT_POWER_BUTTON | ACPI_FADT_SLEEP_BUTTON |
42 ACPI_FADT_SEALED_CASE | ACPI_FADT_HEADLESS |
43 ACPI_FADT_HW_REDUCED_ACPI;
44
45 fadt->minor_revision = 2;
46
Heinrich Schuchardtec958062023-12-16 09:11:57 +010047 fadt->x_firmware_ctrl = map_to_sysmem(ctx->facs);
48 fadt->x_dsdt = map_to_sysmem(ctx->dsdt);
Andy Shevchenko286e77f2017-10-03 14:55:07 +030049
50 header->checksum = table_compute_checksum(fadt, header->length);
Simon Glass9bd6b622023-09-01 11:27:09 -060051
Andy Shevchenko6f15ab72023-09-01 11:27:10 -060052 return acpi_add_fadt(ctx, fadt);
Andy Shevchenko286e77f2017-10-03 14:55:07 +030053}
Simon Glass9bd6b622023-09-01 11:27:09 -060054ACPI_WRITER(5fadt, "FADT", tangier_write_fadt, 0);
Andy Shevchenko286e77f2017-10-03 14:55:07 +030055
56u32 acpi_fill_madt(u32 current)
57{
58 current += acpi_create_madt_lapics(current);
59
60 current += acpi_create_madt_ioapic((struct acpi_madt_ioapic *)current,
61 io_apic_read(IO_APIC_ID) >> 24, IO_APIC_ADDR, 0);
62
63 return current;
64}
65
Moritz Fischerc6561722022-02-05 12:17:45 -080066int acpi_fill_mcfg(struct acpi_ctx *ctx)
Andy Shevchenko286e77f2017-10-03 14:55:07 +030067{
Moritz Fischerc6561722022-02-05 12:17:45 -080068 size_t size;
69
Andy Shevchenko286e77f2017-10-03 14:55:07 +030070 /* TODO: Derive parameters from SFI MCFG table */
Moritz Fischerc6561722022-02-05 12:17:45 -080071 size = acpi_create_mcfg_mmconfig
72 ((struct acpi_mcfg_mmconfig *)ctx->current,
Andy Shevchenkob04ef3b2019-08-29 17:04:19 +030073 MCFG_BASE_ADDRESS, 0x0, 0x0, 0x0);
Moritz Fischerc6561722022-02-05 12:17:45 -080074 acpi_inc(ctx, size);
Andy Shevchenko286e77f2017-10-03 14:55:07 +030075
Moritz Fischerc6561722022-02-05 12:17:45 -080076 return 0;
Andy Shevchenko286e77f2017-10-03 14:55:07 +030077}
78
Andy Shevchenko70c62982019-07-14 19:23:59 +030079static u32 acpi_fill_csrt_dma(struct acpi_csrt_group *grp)
80{
81 struct acpi_csrt_shared_info *si = (struct acpi_csrt_shared_info *)&grp[1];
82
83 /* Fill the Resource Group with Shared Information attached */
84 memset(grp, 0, sizeof(*grp));
85 grp->shared_info_length = sizeof(struct acpi_csrt_shared_info);
86 grp->length = sizeof(struct acpi_csrt_group) + grp->shared_info_length;
87 /* TODO: All values below should come from U-Boot DT somehow */
88 sprintf((char *)&grp->vendor_id, "%04X", 0x8086);
89 grp->device_id = 0x11a2;
90
91 /* Fill the Resource Group Shared Information */
92 memset(si, 0, sizeof(*si));
93 si->major_version = 1;
94 si->minor_version = 0;
95 /* TODO: All values below should come from U-Boot DT somehow */
96 si->mmio_base_low = 0xff192000;
97 si->mmio_base_high = 0;
98 si->gsi_interrupt = 32;
Andy Shevchenkoda28b582021-07-30 23:15:44 +030099 si->interrupt_polarity = 0; /* Active High */
100 si->interrupt_mode = 0; /* Level triggered */
Andy Shevchenko70c62982019-07-14 19:23:59 +0300101 si->num_channels = 8;
102 si->dma_address_width = 32;
103 si->base_request_line = 0;
104 si->num_handshake_signals = 16;
Andy Shevchenko613092b2019-08-29 17:04:20 +0300105 si->max_block_size = 0x1ffff;
Andy Shevchenko70c62982019-07-14 19:23:59 +0300106
107 return grp->length;
108}
109
Simon Glass89ce5192021-12-01 09:03:01 -0700110int acpi_fill_csrt(struct acpi_ctx *ctx)
Andy Shevchenko70c62982019-07-14 19:23:59 +0300111{
Simon Glass89ce5192021-12-01 09:03:01 -0700112 int size;
113
114 size = acpi_fill_csrt_dma(ctx->current);
115 acpi_inc(ctx, size);
Andy Shevchenko70c62982019-07-14 19:23:59 +0300116
Simon Glass89ce5192021-12-01 09:03:01 -0700117 return 0;
Andy Shevchenko70c62982019-07-14 19:23:59 +0300118}
119
Simon Glass9ed41e72020-07-07 21:32:05 -0600120int acpi_create_gnvs(struct acpi_global_nvs *gnvs)
Andy Shevchenko286e77f2017-10-03 14:55:07 +0300121{
122 struct udevice *dev;
123 int ret;
124
125 /* at least we have one processor */
126 gnvs->pcnt = 1;
127
128 /* override the processor count with actual number */
129 ret = uclass_find_first_device(UCLASS_CPU, &dev);
130 if (ret == 0 && dev != NULL) {
131 ret = cpu_get_count(dev);
132 if (ret > 0)
133 gnvs->pcnt = ret;
134 }
Simon Glass9ed41e72020-07-07 21:32:05 -0600135
136 return 0;
Andy Shevchenko286e77f2017-10-03 14:55:07 +0300137}