blob: 3d117878615234dec7a8e0c2c51a7ec145a739d3 [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
Andy Shevchenko286e77f2017-10-03 14:55:07 +03008#include <cpu.h>
9#include <dm.h>
Heinrich Schuchardtec958062023-12-16 09:11:57 +010010#include <mapmem.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>
Patrick Rudolph97b4c8a2024-10-23 15:19:46 +020013#include <asm/lapic.h>
Andy Shevchenko286e77f2017-10-03 14:55:07 +030014#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
Maximilian Brune8dc45122024-10-23 15:19:45 +020020void acpi_fill_fadt(struct acpi_fadt *fadt)
Andy Shevchenko286e77f2017-10-03 14:55:07 +030021{
Andy Shevchenko286e77f2017-10-03 14:55:07 +030022 fadt->preferred_pm_profile = ACPI_PM_UNSPECIFIED;
23
24 fadt->iapc_boot_arch = ACPI_FADT_VGA_NOT_PRESENT |
25 ACPI_FADT_NO_PCIE_ASPM_CONTROL;
26 fadt->flags =
27 ACPI_FADT_WBINVD |
28 ACPI_FADT_POWER_BUTTON | ACPI_FADT_SLEEP_BUTTON |
29 ACPI_FADT_SEALED_CASE | ACPI_FADT_HEADLESS |
30 ACPI_FADT_HW_REDUCED_ACPI;
Maximilian Brune8dc45122024-10-23 15:19:45 +020031 fadt->header.revision = 6;
Andy Shevchenko286e77f2017-10-03 14:55:07 +030032 fadt->minor_revision = 2;
Andy Shevchenko286e77f2017-10-03 14:55:07 +030033}
34
Patrick Rudolph97b4c8a2024-10-23 15:19:46 +020035void *acpi_fill_madt(struct acpi_madt *madt, struct acpi_ctx *ctx)
Andy Shevchenko286e77f2017-10-03 14:55:07 +030036{
Patrick Rudolph97b4c8a2024-10-23 15:19:46 +020037 void *current = ctx->current;
38
39 madt->lapic_addr = LAPIC_DEFAULT_BASE;
40 madt->flags = ACPI_MADT_PCAT_COMPAT;
41
Andy Shevchenko286e77f2017-10-03 14:55:07 +030042 current += acpi_create_madt_lapics(current);
43
44 current += acpi_create_madt_ioapic((struct acpi_madt_ioapic *)current,
45 io_apic_read(IO_APIC_ID) >> 24, IO_APIC_ADDR, 0);
46
47 return current;
48}
49
Moritz Fischerc6561722022-02-05 12:17:45 -080050int acpi_fill_mcfg(struct acpi_ctx *ctx)
Andy Shevchenko286e77f2017-10-03 14:55:07 +030051{
Moritz Fischerc6561722022-02-05 12:17:45 -080052 size_t size;
53
Andy Shevchenko286e77f2017-10-03 14:55:07 +030054 /* TODO: Derive parameters from SFI MCFG table */
Moritz Fischerc6561722022-02-05 12:17:45 -080055 size = acpi_create_mcfg_mmconfig
56 ((struct acpi_mcfg_mmconfig *)ctx->current,
Andy Shevchenkob04ef3b2019-08-29 17:04:19 +030057 MCFG_BASE_ADDRESS, 0x0, 0x0, 0x0);
Moritz Fischerc6561722022-02-05 12:17:45 -080058 acpi_inc(ctx, size);
Andy Shevchenko286e77f2017-10-03 14:55:07 +030059
Moritz Fischerc6561722022-02-05 12:17:45 -080060 return 0;
Andy Shevchenko286e77f2017-10-03 14:55:07 +030061}
62
Andy Shevchenko70c62982019-07-14 19:23:59 +030063static u32 acpi_fill_csrt_dma(struct acpi_csrt_group *grp)
64{
65 struct acpi_csrt_shared_info *si = (struct acpi_csrt_shared_info *)&grp[1];
66
67 /* Fill the Resource Group with Shared Information attached */
68 memset(grp, 0, sizeof(*grp));
69 grp->shared_info_length = sizeof(struct acpi_csrt_shared_info);
70 grp->length = sizeof(struct acpi_csrt_group) + grp->shared_info_length;
71 /* TODO: All values below should come from U-Boot DT somehow */
72 sprintf((char *)&grp->vendor_id, "%04X", 0x8086);
73 grp->device_id = 0x11a2;
74
75 /* Fill the Resource Group Shared Information */
76 memset(si, 0, sizeof(*si));
77 si->major_version = 1;
78 si->minor_version = 0;
79 /* TODO: All values below should come from U-Boot DT somehow */
80 si->mmio_base_low = 0xff192000;
81 si->mmio_base_high = 0;
82 si->gsi_interrupt = 32;
Andy Shevchenkoda28b582021-07-30 23:15:44 +030083 si->interrupt_polarity = 0; /* Active High */
84 si->interrupt_mode = 0; /* Level triggered */
Andy Shevchenko70c62982019-07-14 19:23:59 +030085 si->num_channels = 8;
86 si->dma_address_width = 32;
87 si->base_request_line = 0;
88 si->num_handshake_signals = 16;
Andy Shevchenko613092b2019-08-29 17:04:20 +030089 si->max_block_size = 0x1ffff;
Andy Shevchenko70c62982019-07-14 19:23:59 +030090
91 return grp->length;
92}
93
Simon Glass89ce5192021-12-01 09:03:01 -070094int acpi_fill_csrt(struct acpi_ctx *ctx)
Andy Shevchenko70c62982019-07-14 19:23:59 +030095{
Simon Glass89ce5192021-12-01 09:03:01 -070096 int size;
97
98 size = acpi_fill_csrt_dma(ctx->current);
99 acpi_inc(ctx, size);
Andy Shevchenko70c62982019-07-14 19:23:59 +0300100
Simon Glass89ce5192021-12-01 09:03:01 -0700101 return 0;
Andy Shevchenko70c62982019-07-14 19:23:59 +0300102}
103
Simon Glass9ed41e72020-07-07 21:32:05 -0600104int acpi_create_gnvs(struct acpi_global_nvs *gnvs)
Andy Shevchenko286e77f2017-10-03 14:55:07 +0300105{
106 struct udevice *dev;
107 int ret;
108
109 /* at least we have one processor */
110 gnvs->pcnt = 1;
111
112 /* override the processor count with actual number */
113 ret = uclass_find_first_device(UCLASS_CPU, &dev);
114 if (ret == 0 && dev != NULL) {
115 ret = cpu_get_count(dev);
116 if (ret > 0)
117 gnvs->pcnt = ret;
118 }
Simon Glass9ed41e72020-07-07 21:32:05 -0600119
120 return 0;
Andy Shevchenko286e77f2017-10-03 14:55:07 +0300121}