diff options
-rw-r--r-- | drivers/iommu/dmar.c | 7 | ||||
-rw-r--r-- | drivers/iommu/intel-iommu.c | 55 | ||||
-rw-r--r-- | drivers/iommu/intel_irq_remapping.c | 31 | ||||
-rw-r--r-- | include/linux/dmar.h | 4 |
4 files changed, 29 insertions, 68 deletions
diff --git a/drivers/iommu/dmar.c b/drivers/iommu/dmar.c index e3c03bb7c374..ee4cb1906e45 100644 --- a/drivers/iommu/dmar.c +++ b/drivers/iommu/dmar.c | |||
@@ -1305,15 +1305,14 @@ int dmar_set_interrupt(struct intel_iommu *iommu) | |||
1305 | int __init enable_drhd_fault_handling(void) | 1305 | int __init enable_drhd_fault_handling(void) |
1306 | { | 1306 | { |
1307 | struct dmar_drhd_unit *drhd; | 1307 | struct dmar_drhd_unit *drhd; |
1308 | struct intel_iommu *iommu; | ||
1308 | 1309 | ||
1309 | /* | 1310 | /* |
1310 | * Enable fault control interrupt. | 1311 | * Enable fault control interrupt. |
1311 | */ | 1312 | */ |
1312 | for_each_drhd_unit(drhd) { | 1313 | for_each_iommu(iommu, drhd) { |
1313 | int ret; | ||
1314 | struct intel_iommu *iommu = drhd->iommu; | ||
1315 | u32 fault_status; | 1314 | u32 fault_status; |
1316 | ret = dmar_set_interrupt(iommu); | 1315 | int ret = dmar_set_interrupt(iommu); |
1317 | 1316 | ||
1318 | if (ret) { | 1317 | if (ret) { |
1319 | pr_err("DRHD %Lx: failed to enable fault, interrupt, ret %d\n", | 1318 | pr_err("DRHD %Lx: failed to enable fault, interrupt, ret %d\n", |
diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c index 7a29a5e6e5a4..3731bf68ddce 100644 --- a/drivers/iommu/intel-iommu.c +++ b/drivers/iommu/intel-iommu.c | |||
@@ -628,9 +628,7 @@ static struct intel_iommu *device_to_iommu(int segment, u8 bus, u8 devfn) | |||
628 | struct dmar_drhd_unit *drhd = NULL; | 628 | struct dmar_drhd_unit *drhd = NULL; |
629 | int i; | 629 | int i; |
630 | 630 | ||
631 | for_each_drhd_unit(drhd) { | 631 | for_each_active_drhd_unit(drhd) { |
632 | if (drhd->ignored) | ||
633 | continue; | ||
634 | if (segment != drhd->segment) | 632 | if (segment != drhd->segment) |
635 | continue; | 633 | continue; |
636 | 634 | ||
@@ -2470,11 +2468,7 @@ static int __init init_dmars(void) | |||
2470 | goto error; | 2468 | goto error; |
2471 | } | 2469 | } |
2472 | 2470 | ||
2473 | for_each_drhd_unit(drhd) { | 2471 | for_each_active_iommu(iommu, drhd) { |
2474 | if (drhd->ignored) | ||
2475 | continue; | ||
2476 | |||
2477 | iommu = drhd->iommu; | ||
2478 | g_iommus[iommu->seq_id] = iommu; | 2472 | g_iommus[iommu->seq_id] = iommu; |
2479 | 2473 | ||
2480 | ret = iommu_init_domains(iommu); | 2474 | ret = iommu_init_domains(iommu); |
@@ -2498,12 +2492,7 @@ static int __init init_dmars(void) | |||
2498 | /* | 2492 | /* |
2499 | * Start from the sane iommu hardware state. | 2493 | * Start from the sane iommu hardware state. |
2500 | */ | 2494 | */ |
2501 | for_each_drhd_unit(drhd) { | 2495 | for_each_active_iommu(iommu, drhd) { |
2502 | if (drhd->ignored) | ||
2503 | continue; | ||
2504 | |||
2505 | iommu = drhd->iommu; | ||
2506 | |||
2507 | /* | 2496 | /* |
2508 | * If the queued invalidation is already initialized by us | 2497 | * If the queued invalidation is already initialized by us |
2509 | * (for example, while enabling interrupt-remapping) then | 2498 | * (for example, while enabling interrupt-remapping) then |
@@ -2523,12 +2512,7 @@ static int __init init_dmars(void) | |||
2523 | dmar_disable_qi(iommu); | 2512 | dmar_disable_qi(iommu); |
2524 | } | 2513 | } |
2525 | 2514 | ||
2526 | for_each_drhd_unit(drhd) { | 2515 | for_each_active_iommu(iommu, drhd) { |
2527 | if (drhd->ignored) | ||
2528 | continue; | ||
2529 | |||
2530 | iommu = drhd->iommu; | ||
2531 | |||
2532 | if (dmar_enable_qi(iommu)) { | 2516 | if (dmar_enable_qi(iommu)) { |
2533 | /* | 2517 | /* |
2534 | * Queued Invalidate not enabled, use Register Based | 2518 | * Queued Invalidate not enabled, use Register Based |
@@ -2611,17 +2595,16 @@ static int __init init_dmars(void) | |||
2611 | * global invalidate iotlb | 2595 | * global invalidate iotlb |
2612 | * enable translation | 2596 | * enable translation |
2613 | */ | 2597 | */ |
2614 | for_each_drhd_unit(drhd) { | 2598 | for_each_iommu(iommu, drhd) { |
2615 | if (drhd->ignored) { | 2599 | if (drhd->ignored) { |
2616 | /* | 2600 | /* |
2617 | * we always have to disable PMRs or DMA may fail on | 2601 | * we always have to disable PMRs or DMA may fail on |
2618 | * this device | 2602 | * this device |
2619 | */ | 2603 | */ |
2620 | if (force_on) | 2604 | if (force_on) |
2621 | iommu_disable_protect_mem_regions(drhd->iommu); | 2605 | iommu_disable_protect_mem_regions(iommu); |
2622 | continue; | 2606 | continue; |
2623 | } | 2607 | } |
2624 | iommu = drhd->iommu; | ||
2625 | 2608 | ||
2626 | iommu_flush_write_buffer(iommu); | 2609 | iommu_flush_write_buffer(iommu); |
2627 | 2610 | ||
@@ -2643,12 +2626,8 @@ static int __init init_dmars(void) | |||
2643 | 2626 | ||
2644 | return 0; | 2627 | return 0; |
2645 | error: | 2628 | error: |
2646 | for_each_drhd_unit(drhd) { | 2629 | for_each_active_iommu(iommu, drhd) |
2647 | if (drhd->ignored) | ||
2648 | continue; | ||
2649 | iommu = drhd->iommu; | ||
2650 | free_iommu(iommu); | 2630 | free_iommu(iommu); |
2651 | } | ||
2652 | kfree(g_iommus); | 2631 | kfree(g_iommus); |
2653 | return ret; | 2632 | return ret; |
2654 | } | 2633 | } |
@@ -3296,9 +3275,9 @@ static void __init init_no_remapping_devices(void) | |||
3296 | } | 3275 | } |
3297 | } | 3276 | } |
3298 | 3277 | ||
3299 | for_each_drhd_unit(drhd) { | 3278 | for_each_active_drhd_unit(drhd) { |
3300 | int i; | 3279 | int i; |
3301 | if (drhd->ignored || drhd->include_all) | 3280 | if (drhd->include_all) |
3302 | continue; | 3281 | continue; |
3303 | 3282 | ||
3304 | for (i = 0; i < drhd->devices_cnt; i++) | 3283 | for (i = 0; i < drhd->devices_cnt; i++) |
@@ -3647,6 +3626,7 @@ int __init intel_iommu_init(void) | |||
3647 | { | 3626 | { |
3648 | int ret = 0; | 3627 | int ret = 0; |
3649 | struct dmar_drhd_unit *drhd; | 3628 | struct dmar_drhd_unit *drhd; |
3629 | struct intel_iommu *iommu; | ||
3650 | 3630 | ||
3651 | /* VT-d is required for a TXT/tboot launch, so enforce that */ | 3631 | /* VT-d is required for a TXT/tboot launch, so enforce that */ |
3652 | force_on = tboot_force_iommu(); | 3632 | force_on = tboot_force_iommu(); |
@@ -3660,16 +3640,9 @@ int __init intel_iommu_init(void) | |||
3660 | /* | 3640 | /* |
3661 | * Disable translation if already enabled prior to OS handover. | 3641 | * Disable translation if already enabled prior to OS handover. |
3662 | */ | 3642 | */ |
3663 | for_each_drhd_unit(drhd) { | 3643 | for_each_active_iommu(iommu, drhd) |
3664 | struct intel_iommu *iommu; | ||
3665 | |||
3666 | if (drhd->ignored) | ||
3667 | continue; | ||
3668 | |||
3669 | iommu = drhd->iommu; | ||
3670 | if (iommu->gcmd & DMA_GCMD_TE) | 3644 | if (iommu->gcmd & DMA_GCMD_TE) |
3671 | iommu_disable_translation(iommu); | 3645 | iommu_disable_translation(iommu); |
3672 | } | ||
3673 | 3646 | ||
3674 | if (dmar_dev_scope_init() < 0) { | 3647 | if (dmar_dev_scope_init() < 0) { |
3675 | if (force_on) | 3648 | if (force_on) |
@@ -3912,11 +3885,7 @@ static void iommu_free_vm_domain(struct dmar_domain *domain) | |||
3912 | unsigned long i; | 3885 | unsigned long i; |
3913 | unsigned long ndomains; | 3886 | unsigned long ndomains; |
3914 | 3887 | ||
3915 | for_each_drhd_unit(drhd) { | 3888 | for_each_active_iommu(iommu, drhd) { |
3916 | if (drhd->ignored) | ||
3917 | continue; | ||
3918 | iommu = drhd->iommu; | ||
3919 | |||
3920 | ndomains = cap_ndoms(iommu->cap); | 3889 | ndomains = cap_ndoms(iommu->cap); |
3921 | for_each_set_bit(i, iommu->domain_ids, ndomains) { | 3890 | for_each_set_bit(i, iommu->domain_ids, ndomains) { |
3922 | if (iommu->domains[i] == domain) { | 3891 | if (iommu->domains[i] == domain) { |
diff --git a/drivers/iommu/intel_irq_remapping.c b/drivers/iommu/intel_irq_remapping.c index fdf57534b76c..f307a3fb93ce 100644 --- a/drivers/iommu/intel_irq_remapping.c +++ b/drivers/iommu/intel_irq_remapping.c | |||
@@ -520,6 +520,7 @@ static int __init dmar_x2apic_optout(void) | |||
520 | static int __init intel_irq_remapping_supported(void) | 520 | static int __init intel_irq_remapping_supported(void) |
521 | { | 521 | { |
522 | struct dmar_drhd_unit *drhd; | 522 | struct dmar_drhd_unit *drhd; |
523 | struct intel_iommu *iommu; | ||
523 | 524 | ||
524 | if (disable_irq_remap) | 525 | if (disable_irq_remap) |
525 | return 0; | 526 | return 0; |
@@ -538,12 +539,9 @@ static int __init intel_irq_remapping_supported(void) | |||
538 | if (!dmar_ir_support()) | 539 | if (!dmar_ir_support()) |
539 | return 0; | 540 | return 0; |
540 | 541 | ||
541 | for_each_drhd_unit(drhd) { | 542 | for_each_iommu(iommu, drhd) |
542 | struct intel_iommu *iommu = drhd->iommu; | ||
543 | |||
544 | if (!ecap_ir_support(iommu->ecap)) | 543 | if (!ecap_ir_support(iommu->ecap)) |
545 | return 0; | 544 | return 0; |
546 | } | ||
547 | 545 | ||
548 | return 1; | 546 | return 1; |
549 | } | 547 | } |
@@ -551,6 +549,7 @@ static int __init intel_irq_remapping_supported(void) | |||
551 | static int __init intel_enable_irq_remapping(void) | 549 | static int __init intel_enable_irq_remapping(void) |
552 | { | 550 | { |
553 | struct dmar_drhd_unit *drhd; | 551 | struct dmar_drhd_unit *drhd; |
552 | struct intel_iommu *iommu; | ||
554 | bool x2apic_present; | 553 | bool x2apic_present; |
555 | int setup = 0; | 554 | int setup = 0; |
556 | int eim = 0; | 555 | int eim = 0; |
@@ -573,9 +572,7 @@ static int __init intel_enable_irq_remapping(void) | |||
573 | "Use 'intremap=no_x2apic_optout' to override BIOS request.\n"); | 572 | "Use 'intremap=no_x2apic_optout' to override BIOS request.\n"); |
574 | } | 573 | } |
575 | 574 | ||
576 | for_each_drhd_unit(drhd) { | 575 | for_each_iommu(iommu, drhd) { |
577 | struct intel_iommu *iommu = drhd->iommu; | ||
578 | |||
579 | /* | 576 | /* |
580 | * If the queued invalidation is already initialized, | 577 | * If the queued invalidation is already initialized, |
581 | * shouldn't disable it. | 578 | * shouldn't disable it. |
@@ -600,9 +597,7 @@ static int __init intel_enable_irq_remapping(void) | |||
600 | /* | 597 | /* |
601 | * check for the Interrupt-remapping support | 598 | * check for the Interrupt-remapping support |
602 | */ | 599 | */ |
603 | for_each_drhd_unit(drhd) { | 600 | for_each_iommu(iommu, drhd) { |
604 | struct intel_iommu *iommu = drhd->iommu; | ||
605 | |||
606 | if (!ecap_ir_support(iommu->ecap)) | 601 | if (!ecap_ir_support(iommu->ecap)) |
607 | continue; | 602 | continue; |
608 | 603 | ||
@@ -616,10 +611,8 @@ static int __init intel_enable_irq_remapping(void) | |||
616 | /* | 611 | /* |
617 | * Enable queued invalidation for all the DRHD's. | 612 | * Enable queued invalidation for all the DRHD's. |
618 | */ | 613 | */ |
619 | for_each_drhd_unit(drhd) { | 614 | for_each_iommu(iommu, drhd) { |
620 | int ret; | 615 | int ret = dmar_enable_qi(iommu); |
621 | struct intel_iommu *iommu = drhd->iommu; | ||
622 | ret = dmar_enable_qi(iommu); | ||
623 | 616 | ||
624 | if (ret) { | 617 | if (ret) { |
625 | printk(KERN_ERR "DRHD %Lx: failed to enable queued, " | 618 | printk(KERN_ERR "DRHD %Lx: failed to enable queued, " |
@@ -632,9 +625,7 @@ static int __init intel_enable_irq_remapping(void) | |||
632 | /* | 625 | /* |
633 | * Setup Interrupt-remapping for all the DRHD's now. | 626 | * Setup Interrupt-remapping for all the DRHD's now. |
634 | */ | 627 | */ |
635 | for_each_drhd_unit(drhd) { | 628 | for_each_iommu(iommu, drhd) { |
636 | struct intel_iommu *iommu = drhd->iommu; | ||
637 | |||
638 | if (!ecap_ir_support(iommu->ecap)) | 629 | if (!ecap_ir_support(iommu->ecap)) |
639 | continue; | 630 | continue; |
640 | 631 | ||
@@ -778,19 +769,17 @@ static int ir_parse_ioapic_hpet_scope(struct acpi_dmar_header *header, | |||
778 | static int __init parse_ioapics_under_ir(void) | 769 | static int __init parse_ioapics_under_ir(void) |
779 | { | 770 | { |
780 | struct dmar_drhd_unit *drhd; | 771 | struct dmar_drhd_unit *drhd; |
772 | struct intel_iommu *iommu; | ||
781 | int ir_supported = 0; | 773 | int ir_supported = 0; |
782 | int ioapic_idx; | 774 | int ioapic_idx; |
783 | 775 | ||
784 | for_each_drhd_unit(drhd) { | 776 | for_each_iommu(iommu, drhd) |
785 | struct intel_iommu *iommu = drhd->iommu; | ||
786 | |||
787 | if (ecap_ir_support(iommu->ecap)) { | 777 | if (ecap_ir_support(iommu->ecap)) { |
788 | if (ir_parse_ioapic_hpet_scope(drhd->hdr, iommu)) | 778 | if (ir_parse_ioapic_hpet_scope(drhd->hdr, iommu)) |
789 | return -1; | 779 | return -1; |
790 | 780 | ||
791 | ir_supported = 1; | 781 | ir_supported = 1; |
792 | } | 782 | } |
793 | } | ||
794 | 783 | ||
795 | if (!ir_supported) | 784 | if (!ir_supported) |
796 | return 0; | 785 | return 0; |
diff --git a/include/linux/dmar.h b/include/linux/dmar.h index 1a60dd630bb4..eccb0c0c6cf6 100644 --- a/include/linux/dmar.h +++ b/include/linux/dmar.h | |||
@@ -53,6 +53,10 @@ extern struct list_head dmar_drhd_units; | |||
53 | #define for_each_drhd_unit(drhd) \ | 53 | #define for_each_drhd_unit(drhd) \ |
54 | list_for_each_entry(drhd, &dmar_drhd_units, list) | 54 | list_for_each_entry(drhd, &dmar_drhd_units, list) |
55 | 55 | ||
56 | #define for_each_active_drhd_unit(drhd) \ | ||
57 | list_for_each_entry(drhd, &dmar_drhd_units, list) \ | ||
58 | if (drhd->ignored) {} else | ||
59 | |||
56 | #define for_each_active_iommu(i, drhd) \ | 60 | #define for_each_active_iommu(i, drhd) \ |
57 | list_for_each_entry(drhd, &dmar_drhd_units, list) \ | 61 | list_for_each_entry(drhd, &dmar_drhd_units, list) \ |
58 | if (i=drhd->iommu, drhd->ignored) {} else | 62 | if (i=drhd->iommu, drhd->ignored) {} else |