29 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
31 #include <linux/pci.h>
40 #include <linux/slab.h>
41 #include <asm/irq_remapping.h>
42 #include <asm/iommu_table.h>
51 static acpi_size dmar_tbl_size;
53 static void __init dmar_register_drhd_unit(
struct dmar_drhd_unit *drhd)
59 if (drhd->include_all)
62 list_add(&drhd->list, &dmar_drhd_units);
86 pr_warn(
"Device scope bus [%d] not found\n", scope->
bus);
99 pr_warn(
"Device scope device [%04x:%02x:%02x.%02x] not found\n",
100 segment, scope->
bus, path->
dev, path->
fn);
108 pr_warn(
"Device scope type does not match for %s\n",
125 while (start < end) {
131 pr_warn(
"Unsupported device scope\n");
144 while (start < end) {
148 ret = dmar_parse_one_dev_scope(scope,
149 &(*devices)[index], segment);
171 struct dmar_drhd_unit *dmaru;
180 dmaru->reg_base_addr = drhd->
address;
181 dmaru->segment = drhd->
segment;
182 dmaru->include_all = drhd->
flags & 0x1;
189 dmar_register_drhd_unit(dmaru);
193 static int __init dmar_parse_dev(
struct dmar_drhd_unit *dmaru)
200 if (dmaru->include_all)
204 ((
void *)drhd) + drhd->
header.length,
205 &dmaru->devices_cnt, &dmaru->devices,
214 #ifdef CONFIG_ACPI_NUMA
219 struct dmar_drhd_unit *drhd;
222 for_each_drhd_unit(drhd) {
228 drhd->iommu->node =
node;
234 "Your BIOS is broken; RHSA refers to non-existent DMAR unit at %llx\n"
235 "BIOS vendor: %s; Ver: %s; Product Version: %s\n",
253 switch (header->
type) {
257 pr_info(
"DRHD base: %#016Lx flags: %#x\n",
263 pr_info(
"RMRR base: %#016Lx end: %#016Lx\n",
273 pr_info(
"RHSA base: %#016Lx proximity domain: %#x\n",
283 static int __init dmar_table_detect(
void)
293 pr_warn(
"Unable to map DMAR\n");
304 parse_dmar_table(
void)
334 while (((
unsigned long)entry_header) <
337 if (entry_header->length == 0) {
338 pr_warn(
"Invalid 0-length structure\n");
343 dmar_table_print_dmar_entry(entry_header);
345 switch (entry_header->type) {
347 ret = dmar_parse_one_drhd(entry_header);
356 #ifdef CONFIG_ACPI_NUMA
357 ret = dmar_parse_one_rhsa(entry_header);
361 pr_warn(
"Unknown DMAR structure type %d\n",
369 entry_header = ((
void *)entry_header + entry_header->length);
374 static int dmar_pci_device_match(
struct pci_dev *devices[],
int cnt,
380 for (index = 0; index <
cnt; index++)
381 if (dev == devices[index])
385 dev = dev->
bus->self;
391 struct dmar_drhd_unit *
394 struct dmar_drhd_unit *dmaru =
NULL;
397 dev = pci_physfn(dev);
404 if (dmaru->include_all &&
408 if (dmar_pci_device_match(dmaru->devices,
409 dmaru->devices_cnt, dev))
418 static int dmar_dev_scope_initialized;
419 struct dmar_drhd_unit *drhd, *drhd_n;
422 if (dmar_dev_scope_initialized)
423 return dmar_dev_scope_initialized;
425 if (list_empty(&dmar_drhd_units))
429 ret = dmar_parse_dev(drhd);
438 dmar_dev_scope_initialized = 1;
442 dmar_dev_scope_initialized =
ret;
449 static int dmar_table_initialized;
452 if (dmar_table_initialized)
455 dmar_table_initialized = 1;
457 ret = parse_dmar_table();
460 pr_info(
"parse DMAR table failure.\n");
464 if (list_empty(&dmar_drhd_units)) {
465 pr_info(
"No DMAR devices found\n");
476 "Your BIOS is broken; DMAR reported at address %llx%s!\n"
477 "BIOS vendor: %s; Ver: %s; Product Version: %s\n",
493 while (((
unsigned long)entry_header) <
494 (((
unsigned long)dmar) +
dmar_tbl->length)) {
496 if (entry_header->
length == 0) {
497 pr_warn(
"Invalid 0-length structure\n");
505 drhd = (
void *)entry_header;
507 warn_invalid_dmar(0,
"");
520 warn_invalid_dmar(drhd->
address,
521 " returns all ones");
526 entry_header = ((
void *)entry_header + entry_header->
length);
538 ret = dmar_table_detect();
548 pr_info(
"Queued invalidation will be enabled to support x2apic and Intr-remapping.\n");
590 pr_err(
"IOMMU: can't reserve memory\n");
597 pr_err(
"IOMMU: can't map the region\n");
607 warn_invalid_dmar(phys_addr,
" returns all ones");
621 pr_err(
"IOMMU: can't reserve memory\n");
627 pr_err(
"IOMMU: can't map the region\n");
647 static int iommu_allocated = 0;
652 if (!drhd->reg_base_addr) {
653 warn_invalid_dmar(0,
"");
661 iommu->
seq_id = iommu_allocated++;
664 err = map_iommu(iommu, drhd->reg_base_addr);
666 pr_err(
"IOMMU: failed to map %s\n", iommu->
name);
673 pr_err(
"Cannot get a valid agaw for iommu (seq_id = %d)\n",
679 pr_err(
"Cannot get a valid max agaw for iommu (seq_id = %d)\n",
689 pr_info(
"IOMMU %d: reg_base_addr %llx ver %d:%d cap %llx ecap %llx\n",
691 (
unsigned long long)drhd->reg_base_addr,
693 (
unsigned long long)iommu->
cap,
694 (
unsigned long long)iommu->
ecap);
724 static inline void reclaim_free_desc(
struct q_inval *
qi)
734 static int qi_check_fault(
struct intel_iommu *iommu,
int index)
739 int wait_index = (index + 1) %
QI_LENGTH;
754 pr_err(
"VT-d detected invalid descriptor: "
755 "low=%llx, high=%llx\n",
756 (
unsigned long long)qi->
desc[index].low,
757 (
unsigned long long)qi->
desc[index].high);
760 __iommu_flush_cache(iommu, &qi->
desc[index],
784 }
while (head != tail);
805 int wait_index,
index;
834 hw[wait_index] = wait_desc;
836 __iommu_flush_cache(iommu, &hw[index],
sizeof(
struct qi_desc));
837 __iommu_flush_cache(iommu, &hw[wait_index],
sizeof(
struct qi_desc));
856 rc = qi_check_fault(iommu, index);
867 reclaim_free_desc(qi);
903 unsigned int size_order,
u64 type)
975 !(sts & DMA_GSTS_QIES), sts);
983 static void __dmar_enable_qi(
struct intel_iommu *iommu)
1016 struct page *desc_page;
1056 __dmar_enable_qi(iommu);
1069 static const char *dma_remap_fault_reasons[] =
1072 "Present bit in root entry is clear",
1073 "Present bit in context entry is clear",
1074 "Invalid context entry",
1075 "Access beyond MGAW",
1076 "PTE Write access is not set",
1077 "PTE Read access is not set",
1078 "Next page table ptr is invalid",
1079 "Root table address invalid",
1080 "Context table ptr is invalid",
1081 "non-zero reserved fields in RTP",
1082 "non-zero reserved fields in CTP",
1083 "non-zero reserved fields in PTE",
1086 static const char *irq_remap_fault_reasons[] =
1088 "Detected reserved fields in the decoded interrupt-remapped request",
1089 "Interrupt index exceeded the interrupt-remapping table size",
1090 "Present field in the IRTE entry is clear",
1091 "Error accessing interrupt-remapping table pointed by IRTA_REG",
1092 "Detected reserved fields in the IRTE entry",
1093 "Blocked a compatibility format interrupt request",
1094 "Blocked an interrupt request due to source-id verification failure",
1097 #define MAX_FAULT_REASON_IDX (ARRAY_SIZE(fault_reason_strings) - 1)
1101 if (fault_reason >= 0x20 && (fault_reason - 0x20 <
1104 return irq_remap_fault_reasons[fault_reason - 0x20];
1105 }
else if (fault_reason <
ARRAY_SIZE(dma_remap_fault_reasons)) {
1107 return dma_remap_fault_reasons[fault_reason];
1116 struct intel_iommu *iommu = irq_data_get_irq_handler_data(data);
1130 struct intel_iommu *iommu = irq_data_get_irq_handler_data(data);
1142 struct intel_iommu *iommu = irq_get_handler_data(irq);
1154 struct intel_iommu *iommu = irq_get_handler_data(irq);
1165 u8 fault_reason,
u16 source_id,
unsigned long long addr)
1173 pr_err(
"INTR-REMAP: Request device [[%02x:%02x.%d] "
1174 "fault index %llx\n"
1175 "INTR-REMAP:[fault reason %02d] %s\n",
1176 (source_id >> 8),
PCI_SLOT(source_id & 0xFF),
1177 PCI_FUNC(source_id & 0xFF), addr >> 48,
1178 fault_reason, reason);
1180 pr_err(
"DMAR:[%s] Request device [%02x:%02x.%d] "
1181 "fault addr %llx \n"
1182 "DMAR:[fault reason %02d] %s\n",
1183 (type ?
"DMA Read" :
"DMA Write"),
1184 (source_id >> 8),
PCI_SLOT(source_id & 0xFF),
1185 PCI_FUNC(source_id & 0xFF), addr, fault_reason, reason);
1189 #define PRIMARY_FAULT_REG_LEN (16)
1193 int reg, fault_index;
1200 pr_err(
"DRHD: handling fault status reg %x\n", fault_status);
1228 guest_addr = dmar_readq(iommu->
reg + reg +
1233 fault_index * PRIMARY_FAULT_REG_LEN + 12);
1237 dmar_fault_do_one(iommu, type, fault_reason,
1238 source_id, guest_addr);
1266 pr_err(
"IOMMU: no free vectors\n");
1283 pr_err(
"IOMMU: can't request irq\n");
1289 struct dmar_drhd_unit *drhd;
1294 for_each_drhd_unit(drhd) {
1300 pr_err(
"DRHD %Lx: failed to enable fault, interrupt, ret %d\n",
1301 (
unsigned long long)drhd->reg_base_addr, ret);
1334 __dmar_enable_qi(iommu);
1348 return dmar->
flags & 0x1;