blob: e3a2fcea76d042c8bae031c5f246602665d8de5a [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
Simon Glassc4b5b022021-12-01 09:02:55 -070019static int tangier_write_fadt(struct acpi_ctx *ctx,
20 const struct acpi_writer *entry)
Andy Shevchenko286e77f2017-10-03 14:55:07 +030021{
Simon Glassc4b5b022021-12-01 09:02:55 -070022 struct acpi_table_header *header;
23 struct acpi_fadt *fadt;
Andy Shevchenko286e77f2017-10-03 14:55:07 +030024
Simon Glassc4b5b022021-12-01 09:02:55 -070025 fadt = ctx->current;
26 header = &fadt->header;
27
28 memset(fadt, '\0', sizeof(struct acpi_fadt));
Andy Shevchenko286e77f2017-10-03 14:55:07 +030029
30 acpi_fill_header(header, "FACP");
31 header->length = sizeof(struct acpi_fadt);
32 header->revision = 6;
33
Simon Glassc4b5b022021-12-01 09:02:55 -070034 fadt->firmware_ctrl = (u32)ctx->facs;
35 fadt->dsdt = (u32)ctx->dsdt;
Andy Shevchenko286e77f2017-10-03 14:55:07 +030036 fadt->preferred_pm_profile = ACPI_PM_UNSPECIFIED;
37
38 fadt->iapc_boot_arch = ACPI_FADT_VGA_NOT_PRESENT |
39 ACPI_FADT_NO_PCIE_ASPM_CONTROL;
40 fadt->flags =
41 ACPI_FADT_WBINVD |
42 ACPI_FADT_POWER_BUTTON | ACPI_FADT_SLEEP_BUTTON |
43 ACPI_FADT_SEALED_CASE | ACPI_FADT_HEADLESS |
44 ACPI_FADT_HW_REDUCED_ACPI;
45
46 fadt->minor_revision = 2;
47
Simon Glassc4b5b022021-12-01 09:02:55 -070048 fadt->x_firmware_ctl_l = (u32)ctx->facs;
Andy Shevchenko286e77f2017-10-03 14:55:07 +030049 fadt->x_firmware_ctl_h = 0;
Simon Glassc4b5b022021-12-01 09:02:55 -070050 fadt->x_dsdt_l = (u32)ctx->dsdt;
Andy Shevchenko286e77f2017-10-03 14:55:07 +030051 fadt->x_dsdt_h = 0;
52
53 header->checksum = table_compute_checksum(fadt, header->length);
Simon Glassc4b5b022021-12-01 09:02:55 -070054
55 acpi_inc(ctx, sizeof(struct acpi_fadt));
56
57 return 0;
Andy Shevchenko286e77f2017-10-03 14:55:07 +030058}
Simon Glassc4b5b022021-12-01 09:02:55 -070059ACPI_WRITER(5fadt, "FACP", tangier_write_fadt, 0);
Andy Shevchenko286e77f2017-10-03 14:55:07 +030060
61u32 acpi_fill_madt(u32 current)
62{
63 current += acpi_create_madt_lapics(current);
64
65 current += acpi_create_madt_ioapic((struct acpi_madt_ioapic *)current,
66 io_apic_read(IO_APIC_ID) >> 24, IO_APIC_ADDR, 0);
67
68 return current;
69}
70
Moritz Fischerc6561722022-02-05 12:17:45 -080071int acpi_fill_mcfg(struct acpi_ctx *ctx)
Andy Shevchenko286e77f2017-10-03 14:55:07 +030072{
Moritz Fischerc6561722022-02-05 12:17:45 -080073 size_t size;
74
Andy Shevchenko286e77f2017-10-03 14:55:07 +030075 /* TODO: Derive parameters from SFI MCFG table */
Moritz Fischerc6561722022-02-05 12:17:45 -080076 size = acpi_create_mcfg_mmconfig
77 ((struct acpi_mcfg_mmconfig *)ctx->current,
Andy Shevchenkob04ef3b2019-08-29 17:04:19 +030078 MCFG_BASE_ADDRESS, 0x0, 0x0, 0x0);
Moritz Fischerc6561722022-02-05 12:17:45 -080079 acpi_inc(ctx, size);
Andy Shevchenko286e77f2017-10-03 14:55:07 +030080
Moritz Fischerc6561722022-02-05 12:17:45 -080081 return 0;
Andy Shevchenko286e77f2017-10-03 14:55:07 +030082}
83
Andy Shevchenko70c62982019-07-14 19:23:59 +030084static u32 acpi_fill_csrt_dma(struct acpi_csrt_group *grp)
85{
86 struct acpi_csrt_shared_info *si = (struct acpi_csrt_shared_info *)&grp[1];
87
88 /* Fill the Resource Group with Shared Information attached */
89 memset(grp, 0, sizeof(*grp));
90 grp->shared_info_length = sizeof(struct acpi_csrt_shared_info);
91 grp->length = sizeof(struct acpi_csrt_group) + grp->shared_info_length;
92 /* TODO: All values below should come from U-Boot DT somehow */
93 sprintf((char *)&grp->vendor_id, "%04X", 0x8086);
94 grp->device_id = 0x11a2;
95
96 /* Fill the Resource Group Shared Information */
97 memset(si, 0, sizeof(*si));
98 si->major_version = 1;
99 si->minor_version = 0;
100 /* TODO: All values below should come from U-Boot DT somehow */
101 si->mmio_base_low = 0xff192000;
102 si->mmio_base_high = 0;
103 si->gsi_interrupt = 32;
Andy Shevchenkoda28b582021-07-30 23:15:44 +0300104 si->interrupt_polarity = 0; /* Active High */
105 si->interrupt_mode = 0; /* Level triggered */
Andy Shevchenko70c62982019-07-14 19:23:59 +0300106 si->num_channels = 8;
107 si->dma_address_width = 32;
108 si->base_request_line = 0;
109 si->num_handshake_signals = 16;
Andy Shevchenko613092b2019-08-29 17:04:20 +0300110 si->max_block_size = 0x1ffff;
Andy Shevchenko70c62982019-07-14 19:23:59 +0300111
112 return grp->length;
113}
114
Simon Glass89ce5192021-12-01 09:03:01 -0700115int acpi_fill_csrt(struct acpi_ctx *ctx)
Andy Shevchenko70c62982019-07-14 19:23:59 +0300116{
Simon Glass89ce5192021-12-01 09:03:01 -0700117 int size;
118
119 size = acpi_fill_csrt_dma(ctx->current);
120 acpi_inc(ctx, size);
Andy Shevchenko70c62982019-07-14 19:23:59 +0300121
Simon Glass89ce5192021-12-01 09:03:01 -0700122 return 0;
Andy Shevchenko70c62982019-07-14 19:23:59 +0300123}
124
Simon Glass9ed41e72020-07-07 21:32:05 -0600125int acpi_create_gnvs(struct acpi_global_nvs *gnvs)
Andy Shevchenko286e77f2017-10-03 14:55:07 +0300126{
127 struct udevice *dev;
128 int ret;
129
130 /* at least we have one processor */
131 gnvs->pcnt = 1;
132
133 /* override the processor count with actual number */
134 ret = uclass_find_first_device(UCLASS_CPU, &dev);
135 if (ret == 0 && dev != NULL) {
136 ret = cpu_get_count(dev);
137 if (ret > 0)
138 gnvs->pcnt = ret;
139 }
Simon Glass9ed41e72020-07-07 21:32:05 -0600140
141 return 0;
Andy Shevchenko286e77f2017-10-03 14:55:07 +0300142}