Commit 02f3b3f5 authored by Joerg Roedel's avatar Joerg Roedel

iommu/amd: Use acpi_get_table instead of acpi_table_parse

This makes it easier to propagate errors while parsing the
IVRS table and makes the amd_iommu_init_err hack obsolete.
Signed-off-by: default avatarJoerg Roedel <joerg.roedel@amd.com>
parent 98f1ad25
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
#include <linux/msi.h> #include <linux/msi.h>
#include <linux/amd-iommu.h> #include <linux/amd-iommu.h>
#include <linux/export.h> #include <linux/export.h>
#include <linux/acpi.h>
#include <acpi/acpi.h>
#include <asm/pci-direct.h> #include <asm/pci-direct.h>
#include <asm/iommu.h> #include <asm/iommu.h>
#include <asm/gart.h> #include <asm/gart.h>
...@@ -122,7 +124,7 @@ struct ivmd_header { ...@@ -122,7 +124,7 @@ struct ivmd_header {
bool amd_iommu_dump; bool amd_iommu_dump;
static int __initdata amd_iommu_detected; static bool amd_iommu_detected;
static bool __initdata amd_iommu_disabled; static bool __initdata amd_iommu_disabled;
u16 amd_iommu_last_bdf; /* largest PCI device id we have u16 amd_iommu_last_bdf; /* largest PCI device id we have
...@@ -148,11 +150,6 @@ bool amd_iommu_v2_present __read_mostly; ...@@ -148,11 +150,6 @@ bool amd_iommu_v2_present __read_mostly;
bool amd_iommu_force_isolation __read_mostly; bool amd_iommu_force_isolation __read_mostly;
/*
* The ACPI table parsing functions set this variable on an error
*/
static int __initdata amd_iommu_init_err;
/* /*
* List of protection domains - used during resume * List of protection domains - used during resume
*/ */
...@@ -457,11 +454,9 @@ static int __init find_last_devid_acpi(struct acpi_table_header *table) ...@@ -457,11 +454,9 @@ static int __init find_last_devid_acpi(struct acpi_table_header *table)
*/ */
for (i = 0; i < table->length; ++i) for (i = 0; i < table->length; ++i)
checksum += p[i]; checksum += p[i];
if (checksum != 0) { if (checksum != 0)
/* ACPI table corrupt */ /* ACPI table corrupt */
amd_iommu_init_err = -ENODEV; return -ENODEV;
return 0;
}
p += IVRS_HEADER_LENGTH; p += IVRS_HEADER_LENGTH;
...@@ -1087,16 +1082,12 @@ static int __init init_iommu_all(struct acpi_table_header *table) ...@@ -1087,16 +1082,12 @@ static int __init init_iommu_all(struct acpi_table_header *table)
h->mmio_phys); h->mmio_phys);
iommu = kzalloc(sizeof(struct amd_iommu), GFP_KERNEL); iommu = kzalloc(sizeof(struct amd_iommu), GFP_KERNEL);
if (iommu == NULL) { if (iommu == NULL)
amd_iommu_init_err = -ENOMEM; return -ENOMEM;
return 0;
}
ret = init_iommu_one(iommu, h); ret = init_iommu_one(iommu, h);
if (ret) { if (ret)
amd_iommu_init_err = ret; return ret;
return 0;
}
break; break;
default: default:
break; break;
...@@ -1477,9 +1468,15 @@ static void __init free_on_init_error(void) ...@@ -1477,9 +1468,15 @@ static void __init free_on_init_error(void)
*/ */
int __init amd_iommu_init_hardware(void) int __init amd_iommu_init_hardware(void)
{ {
struct acpi_table_header *ivrs_base;
acpi_size ivrs_size;
acpi_status status;
int i, ret = 0; int i, ret = 0;
if (!amd_iommu_detected) if (no_iommu || (iommu_detected && !gart_iommu_aperture))
return -ENODEV;
if (amd_iommu_disabled || !amd_iommu_detected)
return -ENODEV; return -ENODEV;
if (amd_iommu_dev_table != NULL) { if (amd_iommu_dev_table != NULL) {
...@@ -1487,16 +1484,21 @@ int __init amd_iommu_init_hardware(void) ...@@ -1487,16 +1484,21 @@ int __init amd_iommu_init_hardware(void)
return 0; return 0;
} }
status = acpi_get_table_with_size("IVRS", 0, &ivrs_base, &ivrs_size);
if (status == AE_NOT_FOUND)
return -ENODEV;
else if (ACPI_FAILURE(status)) {
const char *err = acpi_format_exception(status);
pr_err("AMD-Vi: IVRS table error: %s\n", err);
return -EINVAL;
}
/* /*
* First parse ACPI tables to find the largest Bus/Dev/Func * First parse ACPI tables to find the largest Bus/Dev/Func
* we need to handle. Upon this information the shared data * we need to handle. Upon this information the shared data
* structures for the IOMMUs in the system will be allocated * structures for the IOMMUs in the system will be allocated
*/ */
if (acpi_table_parse("IVRS", find_last_devid_acpi) != 0) if (find_last_devid_acpi(ivrs_base))
return -ENODEV;
ret = amd_iommu_init_err;
if (ret)
goto out; goto out;
dev_table_size = tbl_size(DEV_TABLE_ENTRY_SIZE); dev_table_size = tbl_size(DEV_TABLE_ENTRY_SIZE);
...@@ -1553,22 +1555,13 @@ int __init amd_iommu_init_hardware(void) ...@@ -1553,22 +1555,13 @@ int __init amd_iommu_init_hardware(void)
* now the data structures are allocated and basically initialized * now the data structures are allocated and basically initialized
* start the real acpi table scan * start the real acpi table scan
*/ */
ret = -ENODEV; ret = init_iommu_all(ivrs_base);
if (acpi_table_parse("IVRS", init_iommu_all) != 0) if (ret)
goto free;
if (amd_iommu_init_err) {
ret = amd_iommu_init_err;
goto free;
}
if (acpi_table_parse("IVRS", init_memory_definitions) != 0)
goto free; goto free;
if (amd_iommu_init_err) { ret = init_memory_definitions(ivrs_base);
ret = amd_iommu_init_err; if (ret)
goto free; goto free;
}
ret = amd_iommu_init_devices(); ret = amd_iommu_init_devices();
if (ret) if (ret)
...@@ -1581,12 +1574,16 @@ int __init amd_iommu_init_hardware(void) ...@@ -1581,12 +1574,16 @@ int __init amd_iommu_init_hardware(void)
register_syscore_ops(&amd_iommu_syscore_ops); register_syscore_ops(&amd_iommu_syscore_ops);
out: out:
/* Don't leak any ACPI memory */
early_acpi_os_unmap_memory((char __iomem *)ivrs_base, ivrs_size);
ivrs_base = NULL;
return ret; return ret;
free: free:
free_on_init_error(); free_on_init_error();
return ret; goto out;
} }
static int amd_iommu_enable_interrupts(void) static int amd_iommu_enable_interrupts(void)
...@@ -1604,6 +1601,26 @@ static int amd_iommu_enable_interrupts(void) ...@@ -1604,6 +1601,26 @@ static int amd_iommu_enable_interrupts(void)
return ret; return ret;
} }
static bool detect_ivrs(void)
{
struct acpi_table_header *ivrs_base;
acpi_size ivrs_size;
acpi_status status;
status = acpi_get_table_with_size("IVRS", 0, &ivrs_base, &ivrs_size);
if (status == AE_NOT_FOUND)
return false;
else if (ACPI_FAILURE(status)) {
const char *err = acpi_format_exception(status);
pr_err("AMD-Vi: IVRS table error: %s\n", err);
return false;
}
early_acpi_os_unmap_memory((char __iomem *)ivrs_base, ivrs_size);
return true;
}
/* /*
* This is the core init function for AMD IOMMU hardware in the system. * This is the core init function for AMD IOMMU hardware in the system.
* This function is called from the generic x86 DMA layer initialization * This function is called from the generic x86 DMA layer initialization
...@@ -1663,29 +1680,26 @@ static int __init amd_iommu_init(void) ...@@ -1663,29 +1680,26 @@ static int __init amd_iommu_init(void)
* IOMMUs * IOMMUs
* *
****************************************************************************/ ****************************************************************************/
static int __init early_amd_iommu_detect(struct acpi_table_header *table)
{
return 0;
}
int __init amd_iommu_detect(void) int __init amd_iommu_detect(void)
{ {
if (no_iommu || (iommu_detected && !gart_iommu_aperture)) if (no_iommu || (iommu_detected && !gart_iommu_aperture))
return -ENODEV; return -ENODEV;
if (amd_iommu_disabled) if (amd_iommu_disabled)
return -ENODEV; return -ENODEV;
if (acpi_table_parse("IVRS", early_amd_iommu_detect) == 0) { if (!detect_ivrs())
iommu_detected = 1; return -ENODEV;
amd_iommu_detected = 1;
x86_init.iommu.iommu_init = amd_iommu_init;
/* Make sure ACS will be enabled */ amd_iommu_detected = true;
pci_request_acs(); iommu_detected = 1;
return 1; x86_init.iommu.iommu_init = amd_iommu_init;
}
return -ENODEV; /* Make sure ACS will be enabled */
pci_request_acs();
return 0;
} }
/**************************************************************************** /****************************************************************************
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment