Message ID | 1428055432-12120-13-git-send-email-zhaoshenglong@huawei.com |
---|---|
State | New |
Headers | show |
Shannon Zhao <zhaoshenglong@huawei.com> writes: > From: Shannon Zhao <shannon.zhao@linaro.org> > > Add PCIe info struct, prepare for building PCIe table. > And generate MCFG table. > > Signed-off-by: Shannon Zhao <zhaoshenglong@huawei.com> > Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org> > --- > hw/arm/virt-acpi-build.c | 21 +++++++++++++++++++++ > include/hw/arm/virt-acpi-build.h | 12 ++++++++++++ > 2 files changed, 33 insertions(+) > > diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c > index dd5538b..a979582 100644 > --- a/hw/arm/virt-acpi-build.c > +++ b/hw/arm/virt-acpi-build.c > @@ -229,6 +229,24 @@ build_rsdt(GArray *table_data, GArray *linker, GArray *table_offsets) > (void *)rsdt, "RSDT", rsdt_len, 1); > } > > +static void > +build_mcfg(GArray *table_data, GArray *linker, VirtGuestInfo *guest_info) > +{ > + AcpiTableMcfg *mcfg; > + acpi_pcie_info *info = guest_info->pcie_info; > + int len = sizeof(*mcfg) + 1 * sizeof(mcfg->allocation[0]); Explicit bracketing around the maths please. > + > + mcfg = acpi_data_push(table_data, len); > + mcfg->allocation[0].address = cpu_to_le64(info->pcie_ecam_base); > + > + /* Only a single allocation so no need to play with segments */ > + mcfg->allocation[0].pci_segment = cpu_to_le16(0); > + mcfg->allocation[0].start_bus_number = 0; > + mcfg->allocation[0].end_bus_number = info->nr_pcie_buses - 1; > + > + build_header(linker, table_data, (void *)mcfg, "MCFG", len, 1); > +} > + > /* GTDT */ > static void > build_gtdt(GArray *table_data, GArray *linker, VirtGuestInfo *guest_info) > @@ -401,6 +419,9 @@ void virt_acpi_build(VirtGuestInfo *guest_info, AcpiBuildTables *tables) > acpi_add_table(table_offsets, tables_blob); > build_gtdt(tables_blob, tables->linker, guest_info); > > + acpi_add_table(table_offsets, tables_blob); > + build_mcfg(tables_blob, tables->linker, guest_info); > + > /* RSDT is pointed to by RSDP */ > rsdt = tables_blob->len; > build_rsdt(tables_blob, tables->linker, table_offsets); > diff --git a/include/hw/arm/virt-acpi-build.h b/include/hw/arm/virt-acpi-build.h > index 2780856..d534489 100644 > --- a/include/hw/arm/virt-acpi-build.h > +++ b/include/hw/arm/virt-acpi-build.h > @@ -47,6 +47,17 @@ typedef struct acpi_dsdt_info { > const hwaddr *flash_addr; > } acpi_dsdt_info; > > +typedef struct acpi_pcie_info { > + const int *pcie_irq; > + hwaddr pcie_mmio_base; > + hwaddr pcie_mmio_size; > + hwaddr pcie_ioport_base; > + hwaddr pcie_ioport_size; > + hwaddr pcie_ecam_base; > + hwaddr pcie_ecam_size; > + int nr_pcie_buses; > +} acpi_pcie_info; > + > typedef struct VirtGuestInfo { > int smp_cpus; > int max_cpus; > @@ -54,6 +65,7 @@ typedef struct VirtGuestInfo { > acpi_madt_info *madt_info; > acpi_dsdt_info *dsdt_info; > acpi_gtdt_info *gtdt_info; > + acpi_pcie_info *pcie_info; > } VirtGuestInfo;
On 9 April 2015 at 16:54, Alex Bennée <alex.bennee@linaro.org> wrote: > > Shannon Zhao <zhaoshenglong@huawei.com> writes: > >> From: Shannon Zhao <shannon.zhao@linaro.org> >> +build_mcfg(GArray *table_data, GArray *linker, VirtGuestInfo *guest_info) >> +{ >> + AcpiTableMcfg *mcfg; >> + acpi_pcie_info *info = guest_info->pcie_info; >> + int len = sizeof(*mcfg) + 1 * sizeof(mcfg->allocation[0]); > > Explicit bracketing around the maths please. This doesn't seem to make much sense anyway: if the addition was intended to take precedence then we're adding 1 to a size-of-a-struct, which is a bit weird. And if the multiplication was intended to take precedence then it's doing a pointless multiply by one. Please can you check that this is actually calculating the right value? thanks -- PMM
diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c index dd5538b..a979582 100644 --- a/hw/arm/virt-acpi-build.c +++ b/hw/arm/virt-acpi-build.c @@ -229,6 +229,24 @@ build_rsdt(GArray *table_data, GArray *linker, GArray *table_offsets) (void *)rsdt, "RSDT", rsdt_len, 1); } +static void +build_mcfg(GArray *table_data, GArray *linker, VirtGuestInfo *guest_info) +{ + AcpiTableMcfg *mcfg; + acpi_pcie_info *info = guest_info->pcie_info; + int len = sizeof(*mcfg) + 1 * sizeof(mcfg->allocation[0]); + + mcfg = acpi_data_push(table_data, len); + mcfg->allocation[0].address = cpu_to_le64(info->pcie_ecam_base); + + /* Only a single allocation so no need to play with segments */ + mcfg->allocation[0].pci_segment = cpu_to_le16(0); + mcfg->allocation[0].start_bus_number = 0; + mcfg->allocation[0].end_bus_number = info->nr_pcie_buses - 1; + + build_header(linker, table_data, (void *)mcfg, "MCFG", len, 1); +} + /* GTDT */ static void build_gtdt(GArray *table_data, GArray *linker, VirtGuestInfo *guest_info) @@ -401,6 +419,9 @@ void virt_acpi_build(VirtGuestInfo *guest_info, AcpiBuildTables *tables) acpi_add_table(table_offsets, tables_blob); build_gtdt(tables_blob, tables->linker, guest_info); + acpi_add_table(table_offsets, tables_blob); + build_mcfg(tables_blob, tables->linker, guest_info); + /* RSDT is pointed to by RSDP */ rsdt = tables_blob->len; build_rsdt(tables_blob, tables->linker, table_offsets); diff --git a/include/hw/arm/virt-acpi-build.h b/include/hw/arm/virt-acpi-build.h index 2780856..d534489 100644 --- a/include/hw/arm/virt-acpi-build.h +++ b/include/hw/arm/virt-acpi-build.h @@ -47,6 +47,17 @@ typedef struct acpi_dsdt_info { const hwaddr *flash_addr; } acpi_dsdt_info; +typedef struct acpi_pcie_info { + const int *pcie_irq; + hwaddr pcie_mmio_base; + hwaddr pcie_mmio_size; + hwaddr pcie_ioport_base; + hwaddr pcie_ioport_size; + hwaddr pcie_ecam_base; + hwaddr pcie_ecam_size; + int nr_pcie_buses; +} acpi_pcie_info; + typedef struct VirtGuestInfo { int smp_cpus; int max_cpus; @@ -54,6 +65,7 @@ typedef struct VirtGuestInfo { acpi_madt_info *madt_info; acpi_dsdt_info *dsdt_info; acpi_gtdt_info *gtdt_info; + acpi_pcie_info *pcie_info; } VirtGuestInfo;