|
21 | 21 | #include <logmsg.h>
|
22 | 22 | #include <board.h>
|
23 | 23 | #include <vm_configurations.h>
|
| 24 | +#include <pci.h> |
24 | 25 |
|
25 | 26 | #define DBG_IOMMU 0
|
26 | 27 |
|
@@ -555,30 +556,23 @@ static struct dmar_drhd_rt *ioapic_to_dmaru(uint16_t ioapic_id, union pci_bdf *s
|
555 | 556 |
|
556 | 557 | static struct dmar_drhd_rt *device_to_dmaru(uint8_t bus, uint8_t devfun)
|
557 | 558 | {
|
558 |
| - struct dmar_drhd_rt *dmar_unit = NULL; |
559 |
| - uint32_t i, j; |
560 |
| - |
561 |
| - for (j = 0U; j < platform_dmar_info->drhd_count; j++) { |
562 |
| - dmar_unit = &dmar_drhd_units[j]; |
563 |
| - |
564 |
| - for (i = 0U; i < dmar_unit->drhd->dev_cnt; i++) { |
565 |
| - if ((dmar_unit->drhd->devices[i].bus == bus) && |
566 |
| - (dmar_unit->drhd->devices[i].devfun == devfun)) { |
567 |
| - break; |
568 |
| - } |
569 |
| - } |
| 559 | + struct dmar_drhd_rt *dmaru = NULL; |
| 560 | + uint16_t bdf = ((uint16_t)bus << 8U) | devfun; |
| 561 | + uint32_t index = pci_lookup_drhd_for_pbdf(bdf); |
570 | 562 |
|
571 |
| - if ((i != dmar_unit->drhd->dev_cnt) || ((dmar_unit->drhd->flags & DRHD_FLAG_INCLUDE_PCI_ALL_MASK) != 0U)) { |
572 |
| - break; |
573 |
| - } |
574 |
| - } |
575 |
| - |
576 |
| - /* not found */ |
577 |
| - if (j == platform_dmar_info->drhd_count) { |
578 |
| - dmar_unit = NULL; |
| 563 | + if (index == INVALID_DRHD_INDEX) { |
| 564 | + pr_fatal("BDF %02x:%02x:%x has no IOMMU\n", bus, devfun >> 3U, devfun & 7U); |
| 565 | + /* |
| 566 | + * pci_lookup_drhd_for_pbdf would return -1U for any of the reasons |
| 567 | + * 1) PCI device with bus, devfun does not exist on platform |
| 568 | + * 2) ACRN had issues finding the device with bus, devfun during init |
| 569 | + * 3) DMAR tables provided by ACPI for this platform are incorrect |
| 570 | + */ |
| 571 | + } else { |
| 572 | + dmaru = &dmar_drhd_units[index]; |
579 | 573 | }
|
580 | 574 |
|
581 |
| - return dmar_unit; |
| 575 | + return dmaru; |
582 | 576 | }
|
583 | 577 |
|
584 | 578 | static void dmar_issue_qi_request(struct dmar_drhd_rt *dmar_unit, struct dmar_entry invalidate_desc)
|
|
0 commit comments