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 | |
| 8 | #include <common.h> |
| 9 | #include <cpu.h> |
| 10 | #include <dm.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> |
| 13 | #include <asm/mpspec.h> |
| 14 | #include <asm/tables.h> |
| 15 | #include <asm/arch/global_nvs.h> |
Andy Shevchenko | b04ef3b | 2019-08-29 17:04:19 +0300 | [diff] [blame] | 16 | #include <asm/arch/iomap.h> |
Simon Glass | 858fed1 | 2020-04-08 16:57:36 -0600 | [diff] [blame] | 17 | #include <dm/uclass-internal.h> |
Andy Shevchenko | 286e77f | 2017-10-03 14:55:07 +0300 | [diff] [blame] | 18 | |
Simon Glass | 9bd6b62 | 2023-09-01 11:27:09 -0600 | [diff] [blame^] | 19 | static int tangier_write_fadt(struct acpi_ctx *ctx, |
| 20 | const struct acpi_writer *entry) |
Andy Shevchenko | 286e77f | 2017-10-03 14:55:07 +0300 | [diff] [blame] | 21 | { |
Simon Glass | 9bd6b62 | 2023-09-01 11:27:09 -0600 | [diff] [blame^] | 22 | struct acpi_table_header *header; |
| 23 | struct acpi_fadt *fadt; |
Andy Shevchenko | 286e77f | 2017-10-03 14:55:07 +0300 | [diff] [blame] | 24 | |
Simon Glass | 9bd6b62 | 2023-09-01 11:27:09 -0600 | [diff] [blame^] | 25 | fadt = ctx->current; |
| 26 | header = &fadt->header; |
| 27 | |
| 28 | memset(fadt, '\0', sizeof(struct acpi_fadt)); |
Andy Shevchenko | 286e77f | 2017-10-03 14:55:07 +0300 | [diff] [blame] | 29 | |
| 30 | acpi_fill_header(header, "FACP"); |
| 31 | header->length = sizeof(struct acpi_fadt); |
| 32 | header->revision = 6; |
| 33 | |
Simon Glass | 9bd6b62 | 2023-09-01 11:27:09 -0600 | [diff] [blame^] | 34 | fadt->firmware_ctrl = (u32)ctx->facs; |
| 35 | fadt->dsdt = (u32)ctx->dsdt; |
Andy Shevchenko | 286e77f | 2017-10-03 14:55:07 +0300 | [diff] [blame] | 36 | 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 Glass | 9bd6b62 | 2023-09-01 11:27:09 -0600 | [diff] [blame^] | 48 | fadt->x_firmware_ctl_l = (u32)ctx->facs; |
Andy Shevchenko | 286e77f | 2017-10-03 14:55:07 +0300 | [diff] [blame] | 49 | fadt->x_firmware_ctl_h = 0; |
Simon Glass | 9bd6b62 | 2023-09-01 11:27:09 -0600 | [diff] [blame^] | 50 | fadt->x_dsdt_l = (u32)ctx->dsdt; |
Andy Shevchenko | 286e77f | 2017-10-03 14:55:07 +0300 | [diff] [blame] | 51 | fadt->x_dsdt_h = 0; |
| 52 | |
| 53 | header->checksum = table_compute_checksum(fadt, header->length); |
Simon Glass | 9bd6b62 | 2023-09-01 11:27:09 -0600 | [diff] [blame^] | 54 | |
| 55 | acpi_add_table(ctx, fadt); |
| 56 | |
| 57 | acpi_inc(ctx, sizeof(struct acpi_fadt)); |
| 58 | |
| 59 | return 0; |
Andy Shevchenko | 286e77f | 2017-10-03 14:55:07 +0300 | [diff] [blame] | 60 | } |
Simon Glass | 9bd6b62 | 2023-09-01 11:27:09 -0600 | [diff] [blame^] | 61 | ACPI_WRITER(5fadt, "FADT", tangier_write_fadt, 0); |
Andy Shevchenko | 286e77f | 2017-10-03 14:55:07 +0300 | [diff] [blame] | 62 | |
| 63 | u32 acpi_fill_madt(u32 current) |
| 64 | { |
| 65 | current += acpi_create_madt_lapics(current); |
| 66 | |
| 67 | current += acpi_create_madt_ioapic((struct acpi_madt_ioapic *)current, |
| 68 | io_apic_read(IO_APIC_ID) >> 24, IO_APIC_ADDR, 0); |
| 69 | |
| 70 | return current; |
| 71 | } |
| 72 | |
Moritz Fischer | c656172 | 2022-02-05 12:17:45 -0800 | [diff] [blame] | 73 | int acpi_fill_mcfg(struct acpi_ctx *ctx) |
Andy Shevchenko | 286e77f | 2017-10-03 14:55:07 +0300 | [diff] [blame] | 74 | { |
Moritz Fischer | c656172 | 2022-02-05 12:17:45 -0800 | [diff] [blame] | 75 | size_t size; |
| 76 | |
Andy Shevchenko | 286e77f | 2017-10-03 14:55:07 +0300 | [diff] [blame] | 77 | /* TODO: Derive parameters from SFI MCFG table */ |
Moritz Fischer | c656172 | 2022-02-05 12:17:45 -0800 | [diff] [blame] | 78 | size = acpi_create_mcfg_mmconfig |
| 79 | ((struct acpi_mcfg_mmconfig *)ctx->current, |
Andy Shevchenko | b04ef3b | 2019-08-29 17:04:19 +0300 | [diff] [blame] | 80 | MCFG_BASE_ADDRESS, 0x0, 0x0, 0x0); |
Moritz Fischer | c656172 | 2022-02-05 12:17:45 -0800 | [diff] [blame] | 81 | acpi_inc(ctx, size); |
Andy Shevchenko | 286e77f | 2017-10-03 14:55:07 +0300 | [diff] [blame] | 82 | |
Moritz Fischer | c656172 | 2022-02-05 12:17:45 -0800 | [diff] [blame] | 83 | return 0; |
Andy Shevchenko | 286e77f | 2017-10-03 14:55:07 +0300 | [diff] [blame] | 84 | } |
| 85 | |
Andy Shevchenko | 70c6298 | 2019-07-14 19:23:59 +0300 | [diff] [blame] | 86 | static u32 acpi_fill_csrt_dma(struct acpi_csrt_group *grp) |
| 87 | { |
| 88 | struct acpi_csrt_shared_info *si = (struct acpi_csrt_shared_info *)&grp[1]; |
| 89 | |
| 90 | /* Fill the Resource Group with Shared Information attached */ |
| 91 | memset(grp, 0, sizeof(*grp)); |
| 92 | grp->shared_info_length = sizeof(struct acpi_csrt_shared_info); |
| 93 | grp->length = sizeof(struct acpi_csrt_group) + grp->shared_info_length; |
| 94 | /* TODO: All values below should come from U-Boot DT somehow */ |
| 95 | sprintf((char *)&grp->vendor_id, "%04X", 0x8086); |
| 96 | grp->device_id = 0x11a2; |
| 97 | |
| 98 | /* Fill the Resource Group Shared Information */ |
| 99 | memset(si, 0, sizeof(*si)); |
| 100 | si->major_version = 1; |
| 101 | si->minor_version = 0; |
| 102 | /* TODO: All values below should come from U-Boot DT somehow */ |
| 103 | si->mmio_base_low = 0xff192000; |
| 104 | si->mmio_base_high = 0; |
| 105 | si->gsi_interrupt = 32; |
Andy Shevchenko | da28b58 | 2021-07-30 23:15:44 +0300 | [diff] [blame] | 106 | si->interrupt_polarity = 0; /* Active High */ |
| 107 | si->interrupt_mode = 0; /* Level triggered */ |
Andy Shevchenko | 70c6298 | 2019-07-14 19:23:59 +0300 | [diff] [blame] | 108 | si->num_channels = 8; |
| 109 | si->dma_address_width = 32; |
| 110 | si->base_request_line = 0; |
| 111 | si->num_handshake_signals = 16; |
Andy Shevchenko | 613092b | 2019-08-29 17:04:20 +0300 | [diff] [blame] | 112 | si->max_block_size = 0x1ffff; |
Andy Shevchenko | 70c6298 | 2019-07-14 19:23:59 +0300 | [diff] [blame] | 113 | |
| 114 | return grp->length; |
| 115 | } |
| 116 | |
Simon Glass | 89ce519 | 2021-12-01 09:03:01 -0700 | [diff] [blame] | 117 | int acpi_fill_csrt(struct acpi_ctx *ctx) |
Andy Shevchenko | 70c6298 | 2019-07-14 19:23:59 +0300 | [diff] [blame] | 118 | { |
Simon Glass | 89ce519 | 2021-12-01 09:03:01 -0700 | [diff] [blame] | 119 | int size; |
| 120 | |
| 121 | size = acpi_fill_csrt_dma(ctx->current); |
| 122 | acpi_inc(ctx, size); |
Andy Shevchenko | 70c6298 | 2019-07-14 19:23:59 +0300 | [diff] [blame] | 123 | |
Simon Glass | 89ce519 | 2021-12-01 09:03:01 -0700 | [diff] [blame] | 124 | return 0; |
Andy Shevchenko | 70c6298 | 2019-07-14 19:23:59 +0300 | [diff] [blame] | 125 | } |
| 126 | |
Simon Glass | 9ed41e7 | 2020-07-07 21:32:05 -0600 | [diff] [blame] | 127 | int acpi_create_gnvs(struct acpi_global_nvs *gnvs) |
Andy Shevchenko | 286e77f | 2017-10-03 14:55:07 +0300 | [diff] [blame] | 128 | { |
| 129 | struct udevice *dev; |
| 130 | int ret; |
| 131 | |
| 132 | /* at least we have one processor */ |
| 133 | gnvs->pcnt = 1; |
| 134 | |
| 135 | /* override the processor count with actual number */ |
| 136 | ret = uclass_find_first_device(UCLASS_CPU, &dev); |
| 137 | if (ret == 0 && dev != NULL) { |
| 138 | ret = cpu_get_count(dev); |
| 139 | if (ret > 0) |
| 140 | gnvs->pcnt = ret; |
| 141 | } |
Simon Glass | 9ed41e7 | 2020-07-07 21:32:05 -0600 | [diff] [blame] | 142 | |
| 143 | return 0; |
Andy Shevchenko | 286e77f | 2017-10-03 14:55:07 +0300 | [diff] [blame] | 144 | } |