Skip to content

Commit

Permalink
acpi: Move MCFG implementation to common lib
Browse files Browse the repository at this point in the history
MCFG tables are used on multiple arches. Move to common ACPI lib.

Cc: Simon Glass <sjg@chromium.org>
Signed-off-by: Moritz Fischer <moritzf@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Use sizeof(*mcfg) instead of sizeof(*header)
Signed-off-by: Simon Glass <sjg@chromium.org>
  • Loading branch information
mfischer authored and sjg20 committed Feb 9, 2022
1 parent ab2ffe7 commit 058fb9f
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 65 deletions.
15 changes: 9 additions & 6 deletions arch/x86/cpu/intel_common/acpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,17 @@
#include <linux/err.h>
#include <power/acpi_pmc.h>

u32 acpi_fill_mcfg(u32 current)
int acpi_fill_mcfg(struct acpi_ctx *ctx)
{
size_t size;

/* PCI Segment Group 0, Start Bus Number 0, End Bus Number is 255 */
current += acpi_create_mcfg_mmconfig((void *)current,
CONFIG_MMCONF_BASE_ADDRESS, 0, 0,
(CONFIG_SA_PCIEX_LENGTH >> 20)
- 1);
return current;
size = acpi_create_mcfg_mmconfig((void *)ctx->current,
CONFIG_MMCONF_BASE_ADDRESS, 0, 0,
(CONFIG_SA_PCIEX_LENGTH >> 20) - 1);
acpi_inc(ctx, size);

return 0;
}

static int acpi_sci_irq(void)
Expand Down
11 changes: 7 additions & 4 deletions arch/x86/cpu/tangier/acpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,17 @@ u32 acpi_fill_madt(u32 current)
return current;
}

u32 acpi_fill_mcfg(u32 current)
int acpi_fill_mcfg(struct acpi_ctx *ctx)
{
size_t size;

/* TODO: Derive parameters from SFI MCFG table */
current += acpi_create_mcfg_mmconfig
((struct acpi_mcfg_mmconfig *)current,
size = acpi_create_mcfg_mmconfig
((struct acpi_mcfg_mmconfig *)ctx->current,
MCFG_BASE_ADDRESS, 0x0, 0x0, 0x0);
acpi_inc(ctx, size);

return current;
return 0;
}

static u32 acpi_fill_csrt_dma(struct acpi_csrt_group *grp)
Expand Down
1 change: 0 additions & 1 deletion arch/x86/include/asm/acpi_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ int acpi_create_madt_lapic_nmi(struct acpi_madt_lapic_nmi *lapic_nmi,
u32 acpi_fill_madt(u32 current);
int acpi_create_mcfg_mmconfig(struct acpi_mcfg_mmconfig *mmconfig, u32 base,
u16 seg_nr, u8 start, u8 end);
u32 acpi_fill_mcfg(u32 current);

/**
* acpi_write_hpet() - Write out a HPET table
Expand Down
54 changes: 0 additions & 54 deletions arch/x86/lib/acpi_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,28 +161,6 @@ int acpi_write_madt(struct acpi_ctx *ctx, const struct acpi_writer *entry)
}
ACPI_WRITER(5x86, NULL, acpi_write_madt, 0);

int acpi_create_mcfg_mmconfig(struct acpi_mcfg_mmconfig *mmconfig, u32 base,
u16 seg_nr, u8 start, u8 end)
{
memset(mmconfig, 0, sizeof(*mmconfig));
mmconfig->base_address_l = base;
mmconfig->base_address_h = 0;
mmconfig->pci_segment_group_number = seg_nr;
mmconfig->start_bus_number = start;
mmconfig->end_bus_number = end;

return sizeof(struct acpi_mcfg_mmconfig);
}

__weak u32 acpi_fill_mcfg(u32 current)
{
current += acpi_create_mcfg_mmconfig
((struct acpi_mcfg_mmconfig *)current,
CONFIG_PCIE_ECAM_BASE, 0x0, 0x0, 255);

return current;
}

/**
* acpi_create_tcpa() - Create a TCPA table
*
Expand Down Expand Up @@ -480,38 +458,6 @@ int acpi_write_gnvs(struct acpi_ctx *ctx, const struct acpi_writer *entry)
}
ACPI_WRITER(4gnvs, "GNVS", acpi_write_gnvs, 0);

/* MCFG is defined in the PCI Firmware Specification 3.0 */
int acpi_write_mcfg(struct acpi_ctx *ctx, const struct acpi_writer *entry)
{
struct acpi_table_header *header;
struct acpi_mcfg *mcfg;
u32 current;

mcfg = ctx->current;
header = &mcfg->header;

current = (u32)mcfg + sizeof(struct acpi_mcfg);

memset(mcfg, '\0', sizeof(struct acpi_mcfg));

/* Fill out header fields */
acpi_fill_header(header, "MCFG");
header->length = sizeof(struct acpi_mcfg);
header->revision = 1;

current = acpi_fill_mcfg(current);

/* (Re)calculate length and checksum */
header->length = current - (u32)mcfg;
header->checksum = table_compute_checksum(mcfg, header->length);

acpi_inc(ctx, mcfg->header.length);
acpi_add_table(ctx, mcfg);

return 0;
}
ACPI_WRITER(5mcfg, "MCFG", acpi_write_mcfg, 0);

/**
* acpi_write_hpet() - Write out a HPET table
*
Expand Down
1 change: 1 addition & 0 deletions lib/acpi/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ obj-y += acpi_writer.o
ifndef CONFIG_QEMU
obj-y += base.o
obj-y += csrt.o
obj-y += mcfg.o

# Sandbox does not build a .asl file
ifndef CONFIG_SANDBOX
Expand Down
64 changes: 64 additions & 0 deletions lib/acpi/mcfg.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// SPDX-License-Identifier: GPL-2.0+
/*
* Write an ACPI MCFG table
*
* Copyright 2022 Google LLC
*/

#define LOG_CATEGORY LOGC_ACPI

#include <common.h>
#include <mapmem.h>
#include <tables_csum.h>
#include <acpi/acpi_table.h>
#include <dm/acpi.h>

int acpi_create_mcfg_mmconfig(struct acpi_mcfg_mmconfig *mmconfig, u32 base,
u16 seg_nr, u8 start, u8 end)
{
memset(mmconfig, 0, sizeof(*mmconfig));
mmconfig->base_address_l = base;
mmconfig->base_address_h = 0;
mmconfig->pci_segment_group_number = seg_nr;
mmconfig->start_bus_number = start;
mmconfig->end_bus_number = end;

return sizeof(struct acpi_mcfg_mmconfig);
}

__weak int acpi_fill_mcfg(struct acpi_ctx *ctx)
{
return -ENOENT;
}

/* MCFG is defined in the PCI Firmware Specification 3.0 */
int acpi_write_mcfg(struct acpi_ctx *ctx, const struct acpi_writer *entry)
{
struct acpi_table_header *header;
struct acpi_mcfg *mcfg;
int ret;

mcfg = ctx->current;
header = &mcfg->header;

memset(mcfg, '\0', sizeof(struct acpi_mcfg));

/* Fill out header fields */
acpi_fill_header(header, "MCFG");
header->length = sizeof(struct acpi_mcfg);
header->revision = 1;
acpi_inc(ctx, sizeof(*mcfg));

ret = acpi_fill_mcfg(ctx);
if (ret)
return log_msg_ret("fill", ret);

/* (Re)calculate length and checksum */
header->length = (ulong)ctx->current - (ulong)mcfg;
header->checksum = table_compute_checksum(mcfg, header->length);

acpi_add_table(ctx, mcfg);

return 0;
}
ACPI_WRITER(5mcfg, "MCFG", acpi_write_mcfg, 0);

0 comments on commit 058fb9f

Please sign in to comment.