Moritz Fischer | c656172 | 2022-02-05 12:17:45 -0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Write an ACPI MCFG table |
| 4 | * |
| 5 | * Copyright 2022 Google LLC |
| 6 | */ |
| 7 | |
| 8 | #define LOG_CATEGORY LOGC_ACPI |
| 9 | |
Moritz Fischer | c656172 | 2022-02-05 12:17:45 -0800 | [diff] [blame] | 10 | #include <mapmem.h> |
| 11 | #include <tables_csum.h> |
| 12 | #include <acpi/acpi_table.h> |
| 13 | #include <dm/acpi.h> |
Tom Rini | a877ce1 | 2023-12-14 13:16:58 -0500 | [diff] [blame] | 14 | #include <linux/errno.h> |
| 15 | #include <linux/string.h> |
| 16 | #include <linux/types.h> |
Moritz Fischer | c656172 | 2022-02-05 12:17:45 -0800 | [diff] [blame] | 17 | |
| 18 | int acpi_create_mcfg_mmconfig(struct acpi_mcfg_mmconfig *mmconfig, u32 base, |
| 19 | u16 seg_nr, u8 start, u8 end) |
| 20 | { |
| 21 | memset(mmconfig, 0, sizeof(*mmconfig)); |
| 22 | mmconfig->base_address_l = base; |
| 23 | mmconfig->base_address_h = 0; |
| 24 | mmconfig->pci_segment_group_number = seg_nr; |
| 25 | mmconfig->start_bus_number = start; |
| 26 | mmconfig->end_bus_number = end; |
| 27 | |
| 28 | return sizeof(struct acpi_mcfg_mmconfig); |
| 29 | } |
| 30 | |
| 31 | __weak int acpi_fill_mcfg(struct acpi_ctx *ctx) |
| 32 | { |
| 33 | return -ENOENT; |
| 34 | } |
| 35 | |
| 36 | /* MCFG is defined in the PCI Firmware Specification 3.0 */ |
| 37 | int acpi_write_mcfg(struct acpi_ctx *ctx, const struct acpi_writer *entry) |
| 38 | { |
| 39 | struct acpi_table_header *header; |
| 40 | struct acpi_mcfg *mcfg; |
| 41 | int ret; |
| 42 | |
| 43 | mcfg = ctx->current; |
| 44 | header = &mcfg->header; |
| 45 | |
| 46 | memset(mcfg, '\0', sizeof(struct acpi_mcfg)); |
| 47 | |
| 48 | /* Fill out header fields */ |
| 49 | acpi_fill_header(header, "MCFG"); |
| 50 | header->length = sizeof(struct acpi_mcfg); |
| 51 | header->revision = 1; |
| 52 | acpi_inc(ctx, sizeof(*mcfg)); |
| 53 | |
| 54 | ret = acpi_fill_mcfg(ctx); |
| 55 | if (ret) |
| 56 | return log_msg_ret("fill", ret); |
| 57 | |
| 58 | /* (Re)calculate length and checksum */ |
| 59 | header->length = (ulong)ctx->current - (ulong)mcfg; |
| 60 | header->checksum = table_compute_checksum(mcfg, header->length); |
| 61 | |
| 62 | acpi_add_table(ctx, mcfg); |
| 63 | |
| 64 | return 0; |
| 65 | } |
| 66 | ACPI_WRITER(5mcfg, "MCFG", acpi_write_mcfg, 0); |