blob: 1c73a9dbfece1c0562eaf02cf3abfc2ef7ca08fe [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>
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
Maximilian Brune8dc45122024-10-23 15:19:45 +020019void acpi_fill_fadt(struct acpi_fadt *fadt)
Andy Shevchenko286e77f2017-10-03 14:55:07 +030020{
Andy Shevchenko286e77f2017-10-03 14:55:07 +030021 fadt->preferred_pm_profile = ACPI_PM_UNSPECIFIED;
22
23 fadt->iapc_boot_arch = ACPI_FADT_VGA_NOT_PRESENT |
24 ACPI_FADT_NO_PCIE_ASPM_CONTROL;
25 fadt->flags =
26 ACPI_FADT_WBINVD |
27 ACPI_FADT_POWER_BUTTON | ACPI_FADT_SLEEP_BUTTON |
28 ACPI_FADT_SEALED_CASE | ACPI_FADT_HEADLESS |
29 ACPI_FADT_HW_REDUCED_ACPI;
Maximilian Brune8dc45122024-10-23 15:19:45 +020030 fadt->header.revision = 6;
Andy Shevchenko286e77f2017-10-03 14:55:07 +030031 fadt->minor_revision = 2;
Andy Shevchenko286e77f2017-10-03 14:55:07 +030032}
33
34u32 acpi_fill_madt(u32 current)
35{
36 current += acpi_create_madt_lapics(current);
37
38 current += acpi_create_madt_ioapic((struct acpi_madt_ioapic *)current,
39 io_apic_read(IO_APIC_ID) >> 24, IO_APIC_ADDR, 0);
40
41 return current;
42}
43
Moritz Fischerc6561722022-02-05 12:17:45 -080044int acpi_fill_mcfg(struct acpi_ctx *ctx)
Andy Shevchenko286e77f2017-10-03 14:55:07 +030045{
Moritz Fischerc6561722022-02-05 12:17:45 -080046 size_t size;
47
Andy Shevchenko286e77f2017-10-03 14:55:07 +030048 /* TODO: Derive parameters from SFI MCFG table */
Moritz Fischerc6561722022-02-05 12:17:45 -080049 size = acpi_create_mcfg_mmconfig
50 ((struct acpi_mcfg_mmconfig *)ctx->current,
Andy Shevchenkob04ef3b2019-08-29 17:04:19 +030051 MCFG_BASE_ADDRESS, 0x0, 0x0, 0x0);
Moritz Fischerc6561722022-02-05 12:17:45 -080052 acpi_inc(ctx, size);
Andy Shevchenko286e77f2017-10-03 14:55:07 +030053
Moritz Fischerc6561722022-02-05 12:17:45 -080054 return 0;
Andy Shevchenko286e77f2017-10-03 14:55:07 +030055}
56
Andy Shevchenko70c62982019-07-14 19:23:59 +030057static u32 acpi_fill_csrt_dma(struct acpi_csrt_group *grp)
58{
59 struct acpi_csrt_shared_info *si = (struct acpi_csrt_shared_info *)&grp[1];
60
61 /* Fill the Resource Group with Shared Information attached */
62 memset(grp, 0, sizeof(*grp));
63 grp->shared_info_length = sizeof(struct acpi_csrt_shared_info);
64 grp->length = sizeof(struct acpi_csrt_group) + grp->shared_info_length;
65 /* TODO: All values below should come from U-Boot DT somehow */
66 sprintf((char *)&grp->vendor_id, "%04X", 0x8086);
67 grp->device_id = 0x11a2;
68
69 /* Fill the Resource Group Shared Information */
70 memset(si, 0, sizeof(*si));
71 si->major_version = 1;
72 si->minor_version = 0;
73 /* TODO: All values below should come from U-Boot DT somehow */
74 si->mmio_base_low = 0xff192000;
75 si->mmio_base_high = 0;
76 si->gsi_interrupt = 32;
Andy Shevchenkoda28b582021-07-30 23:15:44 +030077 si->interrupt_polarity = 0; /* Active High */
78 si->interrupt_mode = 0; /* Level triggered */
Andy Shevchenko70c62982019-07-14 19:23:59 +030079 si->num_channels = 8;
80 si->dma_address_width = 32;
81 si->base_request_line = 0;
82 si->num_handshake_signals = 16;
Andy Shevchenko613092b2019-08-29 17:04:20 +030083 si->max_block_size = 0x1ffff;
Andy Shevchenko70c62982019-07-14 19:23:59 +030084
85 return grp->length;
86}
87
Simon Glass89ce5192021-12-01 09:03:01 -070088int acpi_fill_csrt(struct acpi_ctx *ctx)
Andy Shevchenko70c62982019-07-14 19:23:59 +030089{
Simon Glass89ce5192021-12-01 09:03:01 -070090 int size;
91
92 size = acpi_fill_csrt_dma(ctx->current);
93 acpi_inc(ctx, size);
Andy Shevchenko70c62982019-07-14 19:23:59 +030094
Simon Glass89ce5192021-12-01 09:03:01 -070095 return 0;
Andy Shevchenko70c62982019-07-14 19:23:59 +030096}
97
Simon Glass9ed41e72020-07-07 21:32:05 -060098int acpi_create_gnvs(struct acpi_global_nvs *gnvs)
Andy Shevchenko286e77f2017-10-03 14:55:07 +030099{
100 struct udevice *dev;
101 int ret;
102
103 /* at least we have one processor */
104 gnvs->pcnt = 1;
105
106 /* override the processor count with actual number */
107 ret = uclass_find_first_device(UCLASS_CPU, &dev);
108 if (ret == 0 && dev != NULL) {
109 ret = cpu_get_count(dev);
110 if (ret > 0)
111 gnvs->pcnt = ret;
112 }
Simon Glass9ed41e72020-07-07 21:32:05 -0600113
114 return 0;
Andy Shevchenko286e77f2017-10-03 14:55:07 +0300115}