sysfs: use sysfs_attr_init in ASUS atk0110 driver
[safe/jmp/linux-2.6] / drivers / pci / dmar.c
index 0d064d1..33ead97 100644 (file)
@@ -35,6 +35,7 @@
 #include <linux/interrupt.h>
 #include <linux/tboot.h>
 #include <linux/dmi.h>
+#include <linux/slab.h>
 
 #define PREFIX "DMAR: "
 
@@ -175,15 +176,6 @@ dmar_parse_one_drhd(struct acpi_dmar_header *header)
        int ret = 0;
 
        drhd = (struct acpi_dmar_hardware_unit *)header;
-       if (!drhd->address) {
-               /* Promote an attitude of violence to a BIOS engineer today */
-               WARN(1, "Your BIOS is broken; DMAR reported at address zero!\n"
-                    "BIOS vendor: %s; Ver: %s; Product Version: %s\n",
-                    dmi_get_system_info(DMI_BIOS_VENDOR),
-                    dmi_get_system_info(DMI_BIOS_VERSION),
-                    dmi_get_system_info(DMI_PRODUCT_VERSION));
-               return -ENODEV;
-       }
        dmaru = kzalloc(sizeof(*dmaru), GFP_KERNEL);
        if (!dmaru)
                return -ENOMEM;
@@ -329,7 +321,7 @@ found:
        for (bus = dev->bus; bus; bus = bus->parent) {
                struct pci_dev *bridge = bus->self;
 
-               if (!bridge || !bridge->is_pcie ||
+               if (!bridge || !pci_is_pcie(bridge) ||
                    bridge->pcie_type == PCI_EXP_TYPE_PCI_BRIDGE)
                        return 0;
 
@@ -622,12 +614,81 @@ int __init dmar_table_init(void)
        return 0;
 }
 
+static int bios_warned;
+
+int __init check_zero_address(void)
+{
+       struct acpi_table_dmar *dmar;
+       struct acpi_dmar_header *entry_header;
+       struct acpi_dmar_hardware_unit *drhd;
+
+       dmar = (struct acpi_table_dmar *)dmar_tbl;
+       entry_header = (struct acpi_dmar_header *)(dmar + 1);
+
+       while (((unsigned long)entry_header) <
+                       (((unsigned long)dmar) + dmar_tbl->length)) {
+               /* Avoid looping forever on bad ACPI tables */
+               if (entry_header->length == 0) {
+                       printk(KERN_WARNING PREFIX
+                               "Invalid 0-length structure\n");
+                       return 0;
+               }
+
+               if (entry_header->type == ACPI_DMAR_TYPE_HARDWARE_UNIT) {
+                       void __iomem *addr;
+                       u64 cap, ecap;
+
+                       drhd = (void *)entry_header;
+                       if (!drhd->address) {
+                               /* Promote an attitude of violence to a BIOS engineer today */
+                               WARN(1, "Your BIOS is broken; DMAR reported at address zero!\n"
+                                    "BIOS vendor: %s; Ver: %s; Product Version: %s\n",
+                                    dmi_get_system_info(DMI_BIOS_VENDOR),
+                                    dmi_get_system_info(DMI_BIOS_VERSION),
+                                    dmi_get_system_info(DMI_PRODUCT_VERSION));
+                               bios_warned = 1;
+                               goto failed;
+                       }
+
+                       addr = early_ioremap(drhd->address, VTD_PAGE_SIZE);
+                       if (!addr ) {
+                               printk("IOMMU: can't validate: %llx\n", drhd->address);
+                               goto failed;
+                       }
+                       cap = dmar_readq(addr + DMAR_CAP_REG);
+                       ecap = dmar_readq(addr + DMAR_ECAP_REG);
+                       early_iounmap(addr, VTD_PAGE_SIZE);
+                       if (cap == (uint64_t)-1 && ecap == (uint64_t)-1) {
+                               /* Promote an attitude of violence to a BIOS engineer today */
+                               WARN(1, "Your BIOS is broken; DMAR reported at address %llx returns all ones!\n"
+                                    "BIOS vendor: %s; Ver: %s; Product Version: %s\n",
+                                     drhd->address,
+                                     dmi_get_system_info(DMI_BIOS_VENDOR),
+                                     dmi_get_system_info(DMI_BIOS_VERSION),
+                                     dmi_get_system_info(DMI_PRODUCT_VERSION));
+                               bios_warned = 1;
+                               goto failed;
+                       }
+               }
+
+               entry_header = ((void *)entry_header + entry_header->length);
+       }
+       return 1;
+
+failed:
+#ifdef CONFIG_DMAR
+       dmar_disabled = 1;
+#endif
+       return 0;
+}
+
 void __init detect_intel_iommu(void)
 {
        int ret;
 
        ret = dmar_table_detect();
-
+       if (ret)
+               ret = check_zero_address();
        {
 #ifdef CONFIG_INTR_REMAP
                struct acpi_table_dmar *dmar;
@@ -644,9 +705,15 @@ void __init detect_intel_iommu(void)
                               "x2apic and Intr-remapping.\n");
 #endif
 #ifdef CONFIG_DMAR
-               if (ret && !no_iommu && !iommu_detected && !swiotlb &&
-                   !dmar_disabled)
+               if (ret && !no_iommu && !iommu_detected && !dmar_disabled) {
                        iommu_detected = 1;
+                       /* Make sure ACS will be enabled */
+                       pci_request_acs();
+               }
+#endif
+#ifdef CONFIG_X86
+               if (ret)
+                       x86_init.iommu.iommu_init = intel_iommu_init;
 #endif
        }
        early_acpi_os_unmap_memory(dmar_tbl, dmar_tbl_size);
@@ -663,6 +730,18 @@ int alloc_iommu(struct dmar_drhd_unit *drhd)
        int agaw = 0;
        int msagaw = 0;
 
+       if (!drhd->reg_base_addr) {
+               if (!bios_warned) {
+                       WARN(1, "Your BIOS is broken; DMAR reported at address zero!\n"
+                            "BIOS vendor: %s; Ver: %s; Product Version: %s\n",
+                            dmi_get_system_info(DMI_BIOS_VENDOR),
+                            dmi_get_system_info(DMI_BIOS_VERSION),
+                            dmi_get_system_info(DMI_PRODUCT_VERSION));
+                       bios_warned = 1;
+               }
+               return -EINVAL;
+       }
+
        iommu = kzalloc(sizeof(*iommu), GFP_KERNEL);
        if (!iommu)
                return -ENOMEM;
@@ -679,13 +758,16 @@ int alloc_iommu(struct dmar_drhd_unit *drhd)
        iommu->ecap = dmar_readq(iommu->reg + DMAR_ECAP_REG);
 
        if (iommu->cap == (uint64_t)-1 && iommu->ecap == (uint64_t)-1) {
-               /* Promote an attitude of violence to a BIOS engineer today */
-               WARN(1, "Your BIOS is broken; DMAR reported at address %llx returns all ones!\n"
-                    "BIOS vendor: %s; Ver: %s; Product Version: %s\n",
-                    drhd->reg_base_addr,
-                    dmi_get_system_info(DMI_BIOS_VENDOR),
-                    dmi_get_system_info(DMI_BIOS_VERSION),
-                    dmi_get_system_info(DMI_PRODUCT_VERSION));
+               if (!bios_warned) {
+                       /* Promote an attitude of violence to a BIOS engineer today */
+                       WARN(1, "Your BIOS is broken; DMAR reported at address %llx returns all ones!\n"
+                            "BIOS vendor: %s; Ver: %s; Product Version: %s\n",
+                            drhd->reg_base_addr,
+                            dmi_get_system_info(DMI_BIOS_VENDOR),
+                            dmi_get_system_info(DMI_BIOS_VERSION),
+                            dmi_get_system_info(DMI_PRODUCT_VERSION));
+                       bios_warned = 1;
+               }
                goto err_unmap;
        }