blob: d4d0ef6f855269e2c3f24bc0bdc59f9e77d71d65 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Andy Shevchenko39665be2017-10-03 14:55:07 +03002/*
3 * Copyright (c) 2017 Intel Corporation
4 *
5 * Partially based on acpi.c for other x86 platforms
Andy Shevchenko39665be2017-10-03 14:55:07 +03006 */
7
Andy Shevchenko39665be2017-10-03 14:55:07 +03008#include <cpu.h>
9#include <dm.h>
Heinrich Schuchardta083ae72023-12-16 09:11:57 +010010#include <mapmem.h>
Simon Glass776cc202020-04-08 16:57:36 -060011#include <acpi/acpi_table.h>
Andy Shevchenko39665be2017-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 Shevchenko0c6352e2019-08-29 17:04:19 +030016#include <asm/arch/iomap.h>
Simon Glass776cc202020-04-08 16:57:36 -060017#include <dm/uclass-internal.h>
Andy Shevchenko39665be2017-10-03 14:55:07 +030018
Simon Glass2e977b22023-09-01 11:27:09 -060019static int tangier_write_fadt(struct acpi_ctx *ctx,
20 const struct acpi_writer *entry)
Andy Shevchenko39665be2017-10-03 14:55:07 +030021{
Simon Glass2e977b22023-09-01 11:27:09 -060022 struct acpi_table_header *header;
23 struct acpi_fadt *fadt;
Andy Shevchenko39665be2017-10-03 14:55:07 +030024
Simon Glass2e977b22023-09-01 11:27:09 -060025 fadt = ctx->current;
26 header = &fadt->header;
27
28 memset(fadt, '\0', sizeof(struct acpi_fadt));
Andy Shevchenko39665be2017-10-03 14:55:07 +030029
30 acpi_fill_header(header, "FACP");
31 header->length = sizeof(struct acpi_fadt);
32 header->revision = 6;
33
Andy Shevchenko39665be2017-10-03 14:55:07 +030034 fadt->preferred_pm_profile = ACPI_PM_UNSPECIFIED;
35
36 fadt->iapc_boot_arch = ACPI_FADT_VGA_NOT_PRESENT |
37 ACPI_FADT_NO_PCIE_ASPM_CONTROL;
38 fadt->flags =
39 ACPI_FADT_WBINVD |
40 ACPI_FADT_POWER_BUTTON | ACPI_FADT_SLEEP_BUTTON |
41 ACPI_FADT_SEALED_CASE | ACPI_FADT_HEADLESS |
42 ACPI_FADT_HW_REDUCED_ACPI;
43
44 fadt->minor_revision = 2;
45
Heinrich Schuchardta083ae72023-12-16 09:11:57 +010046 fadt->x_firmware_ctrl = map_to_sysmem(ctx->facs);
47 fadt->x_dsdt = map_to_sysmem(ctx->dsdt);
Andy Shevchenko39665be2017-10-03 14:55:07 +030048
49 header->checksum = table_compute_checksum(fadt, header->length);
Simon Glass2e977b22023-09-01 11:27:09 -060050
Andy Shevchenkob95bc642023-09-01 11:27:10 -060051 return acpi_add_fadt(ctx, fadt);
Andy Shevchenko39665be2017-10-03 14:55:07 +030052}
Simon Glass2e977b22023-09-01 11:27:09 -060053ACPI_WRITER(5fadt, "FADT", tangier_write_fadt, 0);
Andy Shevchenko39665be2017-10-03 14:55:07 +030054
55u32 acpi_fill_madt(u32 current)
56{
57 current += acpi_create_madt_lapics(current);
58
59 current += acpi_create_madt_ioapic((struct acpi_madt_ioapic *)current,
60 io_apic_read(IO_APIC_ID) >> 24, IO_APIC_ADDR, 0);
61
62 return current;
63}
64
Moritz Fischer058fb9f2022-02-05 12:17:45 -080065int acpi_fill_mcfg(struct acpi_ctx *ctx)
Andy Shevchenko39665be2017-10-03 14:55:07 +030066{
Moritz Fischer058fb9f2022-02-05 12:17:45 -080067 size_t size;
Andy Shevchenko39665be2017-10-03 14:55:07 +030068
Moritz Fischer058fb9f2022-02-05 12:17:45 -080069 /* TODO: Derive parameters from SFI MCFG table */
70 size = acpi_create_mcfg_mmconfig
71 ((struct acpi_mcfg_mmconfig *)ctx->current,
72 MCFG_BASE_ADDRESS, 0x0, 0x0, 0x0);
73 acpi_inc(ctx, size);
74
75 return 0;
Andy Shevchenko39665be2017-10-03 14:55:07 +030076}
77
Andy Shevchenko5e99fde2019-07-14 19:23:59 +030078static u32 acpi_fill_csrt_dma(struct acpi_csrt_group *grp)
79{
80 struct acpi_csrt_shared_info *si = (struct acpi_csrt_shared_info *)&grp[1];
81
82 /* Fill the Resource Group with Shared Information attached */
83 memset(grp, 0, sizeof(*grp));
84 grp->shared_info_length = sizeof(struct acpi_csrt_shared_info);
85 grp->length = sizeof(struct acpi_csrt_group) + grp->shared_info_length;
86 /* TODO: All values below should come from U-Boot DT somehow */
87 sprintf((char *)&grp->vendor_id, "%04X", 0x8086);
88 grp->device_id = 0x11a2;
89
90 /* Fill the Resource Group Shared Information */
91 memset(si, 0, sizeof(*si));
92 si->major_version = 1;
93 si->minor_version = 0;
94 /* TODO: All values below should come from U-Boot DT somehow */
95 si->mmio_base_low = 0xff192000;
96 si->mmio_base_high = 0;
97 si->gsi_interrupt = 32;
Andy Shevchenko46db4bb2021-07-30 23:15:44 +030098 si->interrupt_polarity = 0; /* Active High */
99 si->interrupt_mode = 0; /* Level triggered */
Andy Shevchenko5e99fde2019-07-14 19:23:59 +0300100 si->num_channels = 8;
101 si->dma_address_width = 32;
102 si->base_request_line = 0;
103 si->num_handshake_signals = 16;
Andy Shevchenko980fe1a2019-08-29 17:04:20 +0300104 si->max_block_size = 0x1ffff;
Andy Shevchenko5e99fde2019-07-14 19:23:59 +0300105
106 return grp->length;
107}
108
Simon Glass78031ad2021-12-01 09:03:01 -0700109int acpi_fill_csrt(struct acpi_ctx *ctx)
Andy Shevchenko5e99fde2019-07-14 19:23:59 +0300110{
Simon Glass78031ad2021-12-01 09:03:01 -0700111 int size;
Andy Shevchenko5e99fde2019-07-14 19:23:59 +0300112
Simon Glass78031ad2021-12-01 09:03:01 -0700113 size = acpi_fill_csrt_dma(ctx->current);
114 acpi_inc(ctx, size);
115
116 return 0;
Andy Shevchenko5e99fde2019-07-14 19:23:59 +0300117}
118
Simon Glass8d7ff122020-07-07 21:32:05 -0600119int acpi_create_gnvs(struct acpi_global_nvs *gnvs)
Andy Shevchenko39665be2017-10-03 14:55:07 +0300120{
121 struct udevice *dev;
122 int ret;
123
124 /* at least we have one processor */
125 gnvs->pcnt = 1;
126
127 /* override the processor count with actual number */
128 ret = uclass_find_first_device(UCLASS_CPU, &dev);
129 if (ret == 0 && dev != NULL) {
130 ret = cpu_get_count(dev);
131 if (ret > 0)
132 gnvs->pcnt = ret;
133 }
Simon Glass8d7ff122020-07-07 21:32:05 -0600134
135 return 0;
Andy Shevchenko39665be2017-10-03 14:55:07 +0300136}