Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Andy Shevchenko | 286e77f | 2017-10-03 14:55:07 +0300 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2017 Intel Corporation |
| 4 | * |
| 5 | * Partially based on acpi.c for other x86 platforms |
Andy Shevchenko | 286e77f | 2017-10-03 14:55:07 +0300 | [diff] [blame] | 6 | */ |
| 7 | |
Andy Shevchenko | 286e77f | 2017-10-03 14:55:07 +0300 | [diff] [blame] | 8 | #include <cpu.h> |
| 9 | #include <dm.h> |
Heinrich Schuchardt | ec95806 | 2023-12-16 09:11:57 +0100 | [diff] [blame] | 10 | #include <mapmem.h> |
Simon Glass | 858fed1 | 2020-04-08 16:57:36 -0600 | [diff] [blame] | 11 | #include <acpi/acpi_table.h> |
Andy Shevchenko | 286e77f | 2017-10-03 14:55:07 +0300 | [diff] [blame] | 12 | #include <asm/ioapic.h> |
Patrick Rudolph | 97b4c8a | 2024-10-23 15:19:46 +0200 | [diff] [blame] | 13 | #include <asm/lapic.h> |
Andy Shevchenko | 286e77f | 2017-10-03 14:55:07 +0300 | [diff] [blame] | 14 | #include <asm/mpspec.h> |
| 15 | #include <asm/tables.h> |
| 16 | #include <asm/arch/global_nvs.h> |
Andy Shevchenko | b04ef3b | 2019-08-29 17:04:19 +0300 | [diff] [blame] | 17 | #include <asm/arch/iomap.h> |
Simon Glass | 858fed1 | 2020-04-08 16:57:36 -0600 | [diff] [blame] | 18 | #include <dm/uclass-internal.h> |
Andy Shevchenko | 286e77f | 2017-10-03 14:55:07 +0300 | [diff] [blame] | 19 | |
Maximilian Brune | 8dc4512 | 2024-10-23 15:19:45 +0200 | [diff] [blame] | 20 | void acpi_fill_fadt(struct acpi_fadt *fadt) |
Andy Shevchenko | 286e77f | 2017-10-03 14:55:07 +0300 | [diff] [blame] | 21 | { |
Andy Shevchenko | 286e77f | 2017-10-03 14:55:07 +0300 | [diff] [blame] | 22 | 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; |
Andy Shevchenko | 286e77f | 2017-10-03 14:55:07 +0300 | [diff] [blame] | 31 | } |
| 32 | |
Patrick Rudolph | 97b4c8a | 2024-10-23 15:19:46 +0200 | [diff] [blame] | 33 | void *acpi_fill_madt(struct acpi_madt *madt, struct acpi_ctx *ctx) |
Andy Shevchenko | 286e77f | 2017-10-03 14:55:07 +0300 | [diff] [blame] | 34 | { |
Patrick Rudolph | 97b4c8a | 2024-10-23 15:19:46 +0200 | [diff] [blame] | 35 | void *current = ctx->current; |
| 36 | |
| 37 | madt->lapic_addr = LAPIC_DEFAULT_BASE; |
| 38 | madt->flags = ACPI_MADT_PCAT_COMPAT; |
| 39 | |
Andy Shevchenko | 286e77f | 2017-10-03 14:55:07 +0300 | [diff] [blame] | 40 | current += acpi_create_madt_lapics(current); |
| 41 | |
| 42 | current += acpi_create_madt_ioapic((struct acpi_madt_ioapic *)current, |
| 43 | io_apic_read(IO_APIC_ID) >> 24, IO_APIC_ADDR, 0); |
| 44 | |
| 45 | return current; |
| 46 | } |
| 47 | |
Moritz Fischer | c656172 | 2022-02-05 12:17:45 -0800 | [diff] [blame] | 48 | int acpi_fill_mcfg(struct acpi_ctx *ctx) |
Andy Shevchenko | 286e77f | 2017-10-03 14:55:07 +0300 | [diff] [blame] | 49 | { |
Moritz Fischer | c656172 | 2022-02-05 12:17:45 -0800 | [diff] [blame] | 50 | size_t size; |
| 51 | |
Andy Shevchenko | 286e77f | 2017-10-03 14:55:07 +0300 | [diff] [blame] | 52 | /* TODO: Derive parameters from SFI MCFG table */ |
Moritz Fischer | c656172 | 2022-02-05 12:17:45 -0800 | [diff] [blame] | 53 | size = acpi_create_mcfg_mmconfig |
| 54 | ((struct acpi_mcfg_mmconfig *)ctx->current, |
Andy Shevchenko | b04ef3b | 2019-08-29 17:04:19 +0300 | [diff] [blame] | 55 | MCFG_BASE_ADDRESS, 0x0, 0x0, 0x0); |
Moritz Fischer | c656172 | 2022-02-05 12:17:45 -0800 | [diff] [blame] | 56 | acpi_inc(ctx, size); |
Andy Shevchenko | 286e77f | 2017-10-03 14:55:07 +0300 | [diff] [blame] | 57 | |
Moritz Fischer | c656172 | 2022-02-05 12:17:45 -0800 | [diff] [blame] | 58 | return 0; |
Andy Shevchenko | 286e77f | 2017-10-03 14:55:07 +0300 | [diff] [blame] | 59 | } |
| 60 | |
Andy Shevchenko | 70c6298 | 2019-07-14 19:23:59 +0300 | [diff] [blame] | 61 | static u32 acpi_fill_csrt_dma(struct acpi_csrt_group *grp) |
| 62 | { |
| 63 | struct acpi_csrt_shared_info *si = (struct acpi_csrt_shared_info *)&grp[1]; |
| 64 | |
| 65 | /* Fill the Resource Group with Shared Information attached */ |
| 66 | memset(grp, 0, sizeof(*grp)); |
| 67 | grp->shared_info_length = sizeof(struct acpi_csrt_shared_info); |
| 68 | grp->length = sizeof(struct acpi_csrt_group) + grp->shared_info_length; |
| 69 | /* TODO: All values below should come from U-Boot DT somehow */ |
| 70 | sprintf((char *)&grp->vendor_id, "%04X", 0x8086); |
| 71 | grp->device_id = 0x11a2; |
| 72 | |
| 73 | /* Fill the Resource Group Shared Information */ |
| 74 | memset(si, 0, sizeof(*si)); |
| 75 | si->major_version = 1; |
| 76 | si->minor_version = 0; |
| 77 | /* TODO: All values below should come from U-Boot DT somehow */ |
| 78 | si->mmio_base_low = 0xff192000; |
| 79 | si->mmio_base_high = 0; |
| 80 | si->gsi_interrupt = 32; |
Andy Shevchenko | da28b58 | 2021-07-30 23:15:44 +0300 | [diff] [blame] | 81 | si->interrupt_polarity = 0; /* Active High */ |
| 82 | si->interrupt_mode = 0; /* Level triggered */ |
Andy Shevchenko | 70c6298 | 2019-07-14 19:23:59 +0300 | [diff] [blame] | 83 | si->num_channels = 8; |
| 84 | si->dma_address_width = 32; |
| 85 | si->base_request_line = 0; |
| 86 | si->num_handshake_signals = 16; |
Andy Shevchenko | 613092b | 2019-08-29 17:04:20 +0300 | [diff] [blame] | 87 | si->max_block_size = 0x1ffff; |
Andy Shevchenko | 70c6298 | 2019-07-14 19:23:59 +0300 | [diff] [blame] | 88 | |
| 89 | return grp->length; |
| 90 | } |
| 91 | |
Simon Glass | 89ce519 | 2021-12-01 09:03:01 -0700 | [diff] [blame] | 92 | int acpi_fill_csrt(struct acpi_ctx *ctx) |
Andy Shevchenko | 70c6298 | 2019-07-14 19:23:59 +0300 | [diff] [blame] | 93 | { |
Simon Glass | 89ce519 | 2021-12-01 09:03:01 -0700 | [diff] [blame] | 94 | int size; |
| 95 | |
| 96 | size = acpi_fill_csrt_dma(ctx->current); |
| 97 | acpi_inc(ctx, size); |
Andy Shevchenko | 70c6298 | 2019-07-14 19:23:59 +0300 | [diff] [blame] | 98 | |
Simon Glass | 89ce519 | 2021-12-01 09:03:01 -0700 | [diff] [blame] | 99 | return 0; |
Andy Shevchenko | 70c6298 | 2019-07-14 19:23:59 +0300 | [diff] [blame] | 100 | } |
| 101 | |
Simon Glass | 9ed41e7 | 2020-07-07 21:32:05 -0600 | [diff] [blame] | 102 | int acpi_create_gnvs(struct acpi_global_nvs *gnvs) |
Andy Shevchenko | 286e77f | 2017-10-03 14:55:07 +0300 | [diff] [blame] | 103 | { |
| 104 | struct udevice *dev; |
| 105 | int ret; |
| 106 | |
| 107 | /* at least we have one processor */ |
| 108 | gnvs->pcnt = 1; |
| 109 | |
| 110 | /* override the processor count with actual number */ |
| 111 | ret = uclass_find_first_device(UCLASS_CPU, &dev); |
| 112 | if (ret == 0 && dev != NULL) { |
| 113 | ret = cpu_get_count(dev); |
| 114 | if (ret > 0) |
| 115 | gnvs->pcnt = ret; |
| 116 | } |
Simon Glass | 9ed41e7 | 2020-07-07 21:32:05 -0600 | [diff] [blame] | 117 | |
| 118 | return 0; |
Andy Shevchenko | 286e77f | 2017-10-03 14:55:07 +0300 | [diff] [blame] | 119 | } |