[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH v3 07/19] acpi/hvmloader: Translate all addresses when assigning addresses in ACPI tables



Non-hvmloader users may be building tables in virtual address space
and therefore we need to make sure that values that end up in tables
are physical addresses.

Signed-off-by: Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx>
Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
---
 tools/firmware/hvmloader/acpi/build.c | 47 ++++++++++++++++++-----------------
 1 file changed, 24 insertions(+), 23 deletions(-)

diff --git a/tools/firmware/hvmloader/acpi/build.c 
b/tools/firmware/hvmloader/acpi/build.c
index 9c4a0a0..2098920 100644
--- a/tools/firmware/hvmloader/acpi/build.c
+++ b/tools/firmware/hvmloader/acpi/build.c
@@ -144,7 +144,7 @@ static struct acpi_20_madt *construct_madt(struct acpi_ctxt 
*ctxt,
         lapic = (struct acpi_20_madt_lapic *)(madt + 1);
 
     info->nr_cpus = hvminfo->nr_vcpus;
-    info->madt_lapic0_addr = (uint32_t)lapic;
+    info->madt_lapic0_addr = ctxt->mem_ops.v2p(ctxt, lapic);
     for ( i = 0; i < hvminfo->nr_vcpus; i++ )
     {
         memset(lapic, 0, sizeof(*lapic));
@@ -161,7 +161,8 @@ static struct acpi_20_madt *construct_madt(struct acpi_ctxt 
*ctxt,
     madt->header.length = (unsigned char *)lapic - (unsigned char *)madt;
     set_checksum(madt, offsetof(struct acpi_header, checksum),
                  madt->header.length);
-    info->madt_csum_addr = (uint32_t)&madt->header.checksum;
+    info->madt_csum_addr =
+        ctxt->mem_ops.v2p(ctxt, &madt->header.checksum);
 
     return madt;
 }
@@ -327,7 +328,7 @@ static int construct_passthrough_tables(struct acpi_ctxt 
*ctxt,
             break;
         memcpy(buffer, header, header->length);
 
-        table_ptrs[nr_tables++] = (unsigned long)buffer;
+        table_ptrs[nr_tables++] = ctxt->mem_ops.v2p(ctxt, buffer);
         total += header->length;
         pt_addr += header->length;
     }
@@ -354,7 +355,7 @@ static int construct_secondary_tables(struct acpi_ctxt 
*ctxt,
     {
         madt = construct_madt(ctxt, config, info);
         if (!madt) return -1;
-        table_ptrs[nr_tables++] = (unsigned long)madt;
+        table_ptrs[nr_tables++] = ctxt->mem_ops.v2p(ctxt, madt);
     }
 
     /* HPET. */
@@ -362,7 +363,7 @@ static int construct_secondary_tables(struct acpi_ctxt 
*ctxt,
     {
         hpet = construct_hpet(ctxt, config);
         if (!hpet) return -1;
-        table_ptrs[nr_tables++] = (unsigned long)hpet;
+        table_ptrs[nr_tables++] = ctxt->mem_ops.v2p(ctxt, hpet);
     }
 
     /* WAET. */
@@ -371,7 +372,7 @@ static int construct_secondary_tables(struct acpi_ctxt 
*ctxt,
         waet = construct_waet(ctxt, config);
         if ( !waet )
             return -1;
-        table_ptrs[nr_tables++] = (unsigned long)waet;
+        table_ptrs[nr_tables++] = ctxt->mem_ops.v2p(ctxt, waet);
     }
 
     if ( config->table_flags & ACPI_HAS_SSDT_PM )
@@ -379,7 +380,7 @@ static int construct_secondary_tables(struct acpi_ctxt 
*ctxt,
         ssdt = ctxt->mem_ops.alloc(ctxt, sizeof(ssdt_pm), 16);
         if (!ssdt) return -1;
         memcpy(ssdt, ssdt_pm, sizeof(ssdt_pm));
-        table_ptrs[nr_tables++] = (unsigned long)ssdt;
+        table_ptrs[nr_tables++] = ctxt->mem_ops.v2p(ctxt, ssdt);
     }
 
     if ( config->table_flags & ACPI_HAS_SSDT_S3 )
@@ -387,7 +388,7 @@ static int construct_secondary_tables(struct acpi_ctxt 
*ctxt,
         ssdt = ctxt->mem_ops.alloc(ctxt, sizeof(ssdt_s3), 16);
         if (!ssdt) return -1;
         memcpy(ssdt, ssdt_s3, sizeof(ssdt_s3));
-        table_ptrs[nr_tables++] = (unsigned long)ssdt;
+        table_ptrs[nr_tables++] = ctxt->mem_ops.v2p(ctxt, ssdt);
     } else {
         printf("S3 disabled\n");
     }
@@ -397,7 +398,7 @@ static int construct_secondary_tables(struct acpi_ctxt 
*ctxt,
         ssdt = ctxt->mem_ops.alloc(ctxt, sizeof(ssdt_s4), 16);
         if (!ssdt) return -1;
         memcpy(ssdt, ssdt_s4, sizeof(ssdt_s4));
-        table_ptrs[nr_tables++] = (unsigned long)ssdt;
+        table_ptrs[nr_tables++] = ctxt->mem_ops.v2p(ctxt, ssdt);
     } else {
         printf("S4 disabled\n");
     }
@@ -411,12 +412,12 @@ static int construct_secondary_tables(struct acpi_ctxt 
*ctxt,
         ssdt = ctxt->mem_ops.alloc(ctxt, sizeof(ssdt_tpm), 16);
         if (!ssdt) return -1;
         memcpy(ssdt, ssdt_tpm, sizeof(ssdt_tpm));
-        table_ptrs[nr_tables++] = (unsigned long)ssdt;
+        table_ptrs[nr_tables++] = ctxt->mem_ops.v2p(ctxt, ssdt);
 
         tcpa = ctxt->mem_ops.alloc(ctxt, sizeof(struct acpi_20_tcpa), 16);
         if (!tcpa) return -1;
         memset(tcpa, 0, sizeof(*tcpa));
-        table_ptrs[nr_tables++] = (unsigned long)tcpa;
+        table_ptrs[nr_tables++] = ctxt->mem_ops.v2p(ctxt, tcpa);
 
         tcpa->header.signature = ACPI_2_0_TCPA_SIGNATURE;
         tcpa->header.length    = sizeof(*tcpa);
@@ -444,11 +445,11 @@ static int construct_secondary_tables(struct acpi_ctxt 
*ctxt,
         struct acpi_20_slit *slit = construct_slit(ctxt, config);
 
         if ( srat )
-            table_ptrs[nr_tables++] = (unsigned long)srat;
+            table_ptrs[nr_tables++] = ctxt->mem_ops.v2p(ctxt, srat);
         else
             printf("Failed to build SRAT, skipping...\n");
         if ( slit )
-            table_ptrs[nr_tables++] = (unsigned long)slit;
+            table_ptrs[nr_tables++] = ctxt->mem_ops.v2p(ctxt, slit);
         else
             printf("Failed to build SLIT, skipping...\n");
     }
@@ -562,8 +563,8 @@ void acpi_build_tables(struct acpi_ctxt *ctxt, struct 
acpi_config *config)
     memcpy(fadt_10, &Fadt, sizeof(struct acpi_10_fadt));
     fadt_10->header.length = sizeof(struct acpi_10_fadt);
     fadt_10->header.revision = ACPI_1_0_FADT_REVISION;
-    fadt_10->dsdt          = (unsigned long)dsdt;
-    fadt_10->firmware_ctrl = (unsigned long)facs;
+    fadt_10->dsdt          = ctxt->mem_ops.v2p(ctxt, dsdt);
+    fadt_10->firmware_ctrl = ctxt->mem_ops.v2p(ctxt, facs);
     set_checksum(fadt_10,
                  offsetof(struct acpi_header, checksum),
                  sizeof(struct acpi_10_fadt));
@@ -571,10 +572,10 @@ void acpi_build_tables(struct acpi_ctxt *ctxt, struct 
acpi_config *config)
     fadt = ctxt->mem_ops.alloc(ctxt, sizeof(struct acpi_20_fadt), 16);
     if (!fadt) goto oom;
     memcpy(fadt, &Fadt, sizeof(struct acpi_20_fadt));
-    fadt->dsdt   = (unsigned long)dsdt;
-    fadt->x_dsdt = (unsigned long)dsdt;
-    fadt->firmware_ctrl   = (unsigned long)facs;
-    fadt->x_firmware_ctrl = (unsigned long)facs;
+    fadt->dsdt   = ctxt->mem_ops.v2p(ctxt, dsdt);
+    fadt->x_dsdt = ctxt->mem_ops.v2p(ctxt, dsdt);
+    fadt->firmware_ctrl   = ctxt->mem_ops.v2p(ctxt, facs);
+    fadt->x_firmware_ctrl = ctxt->mem_ops.v2p(ctxt, facs);
     set_checksum(fadt,
                  offsetof(struct acpi_header, checksum),
                  sizeof(struct acpi_20_fadt));
@@ -589,7 +590,7 @@ void acpi_build_tables(struct acpi_ctxt *ctxt, struct 
acpi_config *config)
                                16);
     if (!xsdt) goto oom;
     memcpy(xsdt, &Xsdt, sizeof(struct acpi_header));
-    xsdt->entry[0] = (unsigned long)fadt;
+    xsdt->entry[0] = ctxt->mem_ops.v2p(ctxt, fadt);
     for ( i = 0; secondary_tables[i]; i++ )
         xsdt->entry[i+1] = secondary_tables[i];
     xsdt->header.length = sizeof(struct acpi_header) + (i+1)*sizeof(uint64_t);
@@ -602,7 +603,7 @@ void acpi_build_tables(struct acpi_ctxt *ctxt, struct 
acpi_config *config)
                                16);
     if (!rsdt) goto oom;
     memcpy(rsdt, &Rsdt, sizeof(struct acpi_header));
-    rsdt->entry[0] = (unsigned long)fadt_10;
+    rsdt->entry[0] = ctxt->mem_ops.v2p(ctxt, fadt_10);
     for ( i = 0; secondary_tables[i]; i++ )
         rsdt->entry[i+1] = secondary_tables[i];
     rsdt->header.length = sizeof(struct acpi_header) + (i+1)*sizeof(uint32_t);
@@ -616,8 +617,8 @@ void acpi_build_tables(struct acpi_ctxt *ctxt, struct 
acpi_config *config)
     rsdp = (struct acpi_20_rsdp *)config->rsdp;
 
     memcpy(rsdp, &Rsdp, sizeof(struct acpi_20_rsdp));
-    rsdp->rsdt_address = (unsigned long)rsdt;
-    rsdp->xsdt_address = (unsigned long)xsdt;
+    rsdp->rsdt_address = ctxt->mem_ops.v2p(ctxt, rsdt);
+    rsdp->xsdt_address = ctxt->mem_ops.v2p(ctxt, xsdt);
     set_checksum(rsdp,
                  offsetof(struct acpi_10_rsdp, checksum),
                  sizeof(struct acpi_10_rsdp));
-- 
1.8.3.1


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
https://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.