intr_remapping.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
  1. #include <linux/interrupt.h>
  2. #include <linux/dmar.h>
  3. #include <linux/spinlock.h>
  4. #include <linux/slab.h>
  5. #include <linux/jiffies.h>
  6. #include <linux/hpet.h>
  7. #include <linux/pci.h>
  8. #include <linux/irq.h>
  9. #include <asm/io_apic.h>
  10. #include <asm/smp.h>
  11. #include <asm/cpu.h>
  12. #include <linux/intel-iommu.h>
  13. #include "intr_remapping.h"
  14. #include <acpi/acpi.h>
  15. #include <asm/pci-direct.h>
  16. static struct ioapic_scope ir_ioapic[MAX_IO_APICS];
  17. static struct hpet_scope ir_hpet[MAX_HPET_TBS];
  18. static int ir_ioapic_num, ir_hpet_num;
  19. int intr_remapping_enabled;
  20. static int disable_intremap;
  21. static int disable_sourceid_checking;
  22. static __init int setup_nointremap(char *str)
  23. {
  24. disable_intremap = 1;
  25. return 0;
  26. }
  27. early_param("nointremap", setup_nointremap);
  28. static __init int setup_intremap(char *str)
  29. {
  30. if (!str)
  31. return -EINVAL;
  32. if (!strncmp(str, "on", 2))
  33. disable_intremap = 0;
  34. else if (!strncmp(str, "off", 3))
  35. disable_intremap = 1;
  36. else if (!strncmp(str, "nosid", 5))
  37. disable_sourceid_checking = 1;
  38. return 0;
  39. }
  40. early_param("intremap", setup_intremap);
  41. static DEFINE_SPINLOCK(irq_2_ir_lock);
  42. static struct irq_2_iommu *irq_2_iommu(unsigned int irq)
  43. {
  44. struct irq_cfg *cfg = irq_get_chip_data(irq);
  45. return cfg ? &cfg->irq_2_iommu : NULL;
  46. }
  47. int get_irte(int irq, struct irte *entry)
  48. {
  49. struct irq_2_iommu *irq_iommu = irq_2_iommu(irq);
  50. unsigned long flags;
  51. int index;
  52. if (!entry || !irq_iommu)
  53. return -1;
  54. spin_lock_irqsave(&irq_2_ir_lock, flags);
  55. index = irq_iommu->irte_index + irq_iommu->sub_handle;
  56. *entry = *(irq_iommu->iommu->ir_table->base + index);
  57. spin_unlock_irqrestore(&irq_2_ir_lock, flags);
  58. return 0;
  59. }
  60. int alloc_irte(struct intel_iommu *iommu, int irq, u16 count)
  61. {
  62. struct ir_table *table = iommu->ir_table;
  63. struct irq_2_iommu *irq_iommu = irq_2_iommu(irq);
  64. u16 index, start_index;
  65. unsigned int mask = 0;
  66. unsigned long flags;
  67. int i;
  68. if (!count || !irq_iommu)
  69. return -1;
  70. /*
  71. * start the IRTE search from index 0.
  72. */
  73. index = start_index = 0;
  74. if (count > 1) {
  75. count = __roundup_pow_of_two(count);
  76. mask = ilog2(count);
  77. }
  78. if (mask > ecap_max_handle_mask(iommu->ecap)) {
  79. printk(KERN_ERR
  80. "Requested mask %x exceeds the max invalidation handle"
  81. " mask value %Lx\n", mask,
  82. ecap_max_handle_mask(iommu->ecap));
  83. return -1;
  84. }
  85. spin_lock_irqsave(&irq_2_ir_lock, flags);
  86. do {
  87. for (i = index; i < index + count; i++)
  88. if (table->base[i].present)
  89. break;
  90. /* empty index found */
  91. if (i == index + count)
  92. break;
  93. index = (index + count) % INTR_REMAP_TABLE_ENTRIES;
  94. if (index == start_index) {
  95. spin_unlock_irqrestore(&irq_2_ir_lock, flags);
  96. printk(KERN_ERR "can't allocate an IRTE\n");
  97. return -1;
  98. }
  99. } while (1);
  100. for (i = index; i < index + count; i++)
  101. table->base[i].present = 1;
  102. irq_iommu->iommu = iommu;
  103. irq_iommu->irte_index = index;
  104. irq_iommu->sub_handle = 0;
  105. irq_iommu->irte_mask = mask;
  106. spin_unlock_irqrestore(&irq_2_ir_lock, flags);
  107. return index;
  108. }
  109. static int qi_flush_iec(struct intel_iommu *iommu, int index, int mask)
  110. {
  111. struct qi_desc desc;
  112. desc.low = QI_IEC_IIDEX(index) | QI_IEC_TYPE | QI_IEC_IM(mask)
  113. | QI_IEC_SELECTIVE;
  114. desc.high = 0;
  115. return qi_submit_sync(&desc, iommu);
  116. }
  117. int map_irq_to_irte_handle(int irq, u16 *sub_handle)
  118. {
  119. struct irq_2_iommu *irq_iommu = irq_2_iommu(irq);
  120. unsigned long flags;
  121. int index;
  122. if (!irq_iommu)
  123. return -1;
  124. spin_lock_irqsave(&irq_2_ir_lock, flags);
  125. *sub_handle = irq_iommu->sub_handle;
  126. index = irq_iommu->irte_index;
  127. spin_unlock_irqrestore(&irq_2_ir_lock, flags);
  128. return index;
  129. }
  130. int set_irte_irq(int irq, struct intel_iommu *iommu, u16 index, u16 subhandle)
  131. {
  132. struct irq_2_iommu *irq_iommu = irq_2_iommu(irq);
  133. unsigned long flags;
  134. if (!irq_iommu)
  135. return -1;
  136. spin_lock_irqsave(&irq_2_ir_lock, flags);
  137. irq_iommu->iommu = iommu;
  138. irq_iommu->irte_index = index;
  139. irq_iommu->sub_handle = subhandle;
  140. irq_iommu->irte_mask = 0;
  141. spin_unlock_irqrestore(&irq_2_ir_lock, flags);
  142. return 0;
  143. }
  144. int modify_irte(int irq, struct irte *irte_modified)
  145. {
  146. struct irq_2_iommu *irq_iommu = irq_2_iommu(irq);
  147. struct intel_iommu *iommu;
  148. unsigned long flags;
  149. struct irte *irte;
  150. int rc, index;
  151. if (!irq_iommu)
  152. return -1;
  153. spin_lock_irqsave(&irq_2_ir_lock, flags);
  154. iommu = irq_iommu->iommu;
  155. index = irq_iommu->irte_index + irq_iommu->sub_handle;
  156. irte = &iommu->ir_table->base[index];
  157. set_64bit(&irte->low, irte_modified->low);
  158. set_64bit(&irte->high, irte_modified->high);
  159. __iommu_flush_cache(iommu, irte, sizeof(*irte));
  160. rc = qi_flush_iec(iommu, index, 0);
  161. spin_unlock_irqrestore(&irq_2_ir_lock, flags);
  162. return rc;
  163. }
  164. struct intel_iommu *map_hpet_to_ir(u8 hpet_id)
  165. {
  166. int i;
  167. for (i = 0; i < MAX_HPET_TBS; i++)
  168. if (ir_hpet[i].id == hpet_id)
  169. return ir_hpet[i].iommu;
  170. return NULL;
  171. }
  172. struct intel_iommu *map_ioapic_to_ir(int apic)
  173. {
  174. int i;
  175. for (i = 0; i < MAX_IO_APICS; i++)
  176. if (ir_ioapic[i].id == apic)
  177. return ir_ioapic[i].iommu;
  178. return NULL;
  179. }
  180. struct intel_iommu *map_dev_to_ir(struct pci_dev *dev)
  181. {
  182. struct dmar_drhd_unit *drhd;
  183. drhd = dmar_find_matched_drhd_unit(dev);
  184. if (!drhd)
  185. return NULL;
  186. return drhd->iommu;
  187. }
  188. static int clear_entries(struct irq_2_iommu *irq_iommu)
  189. {
  190. struct irte *start, *entry, *end;
  191. struct intel_iommu *iommu;
  192. int index;
  193. if (irq_iommu->sub_handle)
  194. return 0;
  195. iommu = irq_iommu->iommu;
  196. index = irq_iommu->irte_index + irq_iommu->sub_handle;
  197. start = iommu->ir_table->base + index;
  198. end = start + (1 << irq_iommu->irte_mask);
  199. for (entry = start; entry < end; entry++) {
  200. set_64bit(&entry->low, 0);
  201. set_64bit(&entry->high, 0);
  202. }
  203. return qi_flush_iec(iommu, index, irq_iommu->irte_mask);
  204. }
  205. int free_irte(int irq)
  206. {
  207. struct irq_2_iommu *irq_iommu = irq_2_iommu(irq);
  208. unsigned long flags;
  209. int rc;
  210. if (!irq_iommu)
  211. return -1;
  212. spin_lock_irqsave(&irq_2_ir_lock, flags);
  213. rc = clear_entries(irq_iommu);
  214. irq_iommu->iommu = NULL;
  215. irq_iommu->irte_index = 0;
  216. irq_iommu->sub_handle = 0;
  217. irq_iommu->irte_mask = 0;
  218. spin_unlock_irqrestore(&irq_2_ir_lock, flags);
  219. return rc;
  220. }
  221. /*
  222. * source validation type
  223. */
  224. #define SVT_NO_VERIFY 0x0 /* no verification is required */
  225. #define SVT_VERIFY_SID_SQ 0x1 /* verify using SID and SQ fields */
  226. #define SVT_VERIFY_BUS 0x2 /* verify bus of request-id */
  227. /*
  228. * source-id qualifier
  229. */
  230. #define SQ_ALL_16 0x0 /* verify all 16 bits of request-id */
  231. #define SQ_13_IGNORE_1 0x1 /* verify most significant 13 bits, ignore
  232. * the third least significant bit
  233. */
  234. #define SQ_13_IGNORE_2 0x2 /* verify most significant 13 bits, ignore
  235. * the second and third least significant bits
  236. */
  237. #define SQ_13_IGNORE_3 0x3 /* verify most significant 13 bits, ignore
  238. * the least three significant bits
  239. */
  240. /*
  241. * set SVT, SQ and SID fields of irte to verify
  242. * source ids of interrupt requests
  243. */
  244. static void set_irte_sid(struct irte *irte, unsigned int svt,
  245. unsigned int sq, unsigned int sid)
  246. {
  247. if (disable_sourceid_checking)
  248. svt = SVT_NO_VERIFY;
  249. irte->svt = svt;
  250. irte->sq = sq;
  251. irte->sid = sid;
  252. }
  253. int set_ioapic_sid(struct irte *irte, int apic)
  254. {
  255. int i;
  256. u16 sid = 0;
  257. if (!irte)
  258. return -1;
  259. for (i = 0; i < MAX_IO_APICS; i++) {
  260. if (ir_ioapic[i].id == apic) {
  261. sid = (ir_ioapic[i].bus << 8) | ir_ioapic[i].devfn;
  262. break;
  263. }
  264. }
  265. if (sid == 0) {
  266. pr_warning("Failed to set source-id of IOAPIC (%d)\n", apic);
  267. return -1;
  268. }
  269. set_irte_sid(irte, 1, 0, sid);
  270. return 0;
  271. }
  272. int set_hpet_sid(struct irte *irte, u8 id)
  273. {
  274. int i;
  275. u16 sid = 0;
  276. if (!irte)
  277. return -1;
  278. for (i = 0; i < MAX_HPET_TBS; i++) {
  279. if (ir_hpet[i].id == id) {
  280. sid = (ir_hpet[i].bus << 8) | ir_hpet[i].devfn;
  281. break;
  282. }
  283. }
  284. if (sid == 0) {
  285. pr_warning("Failed to set source-id of HPET block (%d)\n", id);
  286. return -1;
  287. }
  288. /*
  289. * Should really use SQ_ALL_16. Some platforms are broken.
  290. * While we figure out the right quirks for these broken platforms, use
  291. * SQ_13_IGNORE_3 for now.
  292. */
  293. set_irte_sid(irte, SVT_VERIFY_SID_SQ, SQ_13_IGNORE_3, sid);
  294. return 0;
  295. }
  296. int set_msi_sid(struct irte *irte, struct pci_dev *dev)
  297. {
  298. struct pci_dev *bridge;
  299. if (!irte || !dev)
  300. return -1;
  301. /* PCIe device or Root Complex integrated PCI device */
  302. if (pci_is_pcie(dev) || !dev->bus->parent) {
  303. set_irte_sid(irte, SVT_VERIFY_SID_SQ, SQ_ALL_16,
  304. (dev->bus->number << 8) | dev->devfn);
  305. return 0;
  306. }
  307. bridge = pci_find_upstream_pcie_bridge(dev);
  308. if (bridge) {
  309. if (pci_is_pcie(bridge))/* this is a PCIe-to-PCI/PCIX bridge */
  310. set_irte_sid(irte, SVT_VERIFY_BUS, SQ_ALL_16,
  311. (bridge->bus->number << 8) | dev->bus->number);
  312. else /* this is a legacy PCI bridge */
  313. set_irte_sid(irte, SVT_VERIFY_SID_SQ, SQ_ALL_16,
  314. (bridge->bus->number << 8) | bridge->devfn);
  315. }
  316. return 0;
  317. }
  318. static void iommu_set_intr_remapping(struct intel_iommu *iommu, int mode)
  319. {
  320. u64 addr;
  321. u32 sts;
  322. unsigned long flags;
  323. addr = virt_to_phys((void *)iommu->ir_table->base);
  324. spin_lock_irqsave(&iommu->register_lock, flags);
  325. dmar_writeq(iommu->reg + DMAR_IRTA_REG,
  326. (addr) | IR_X2APIC_MODE(mode) | INTR_REMAP_TABLE_REG_SIZE);
  327. /* Set interrupt-remapping table pointer */
  328. iommu->gcmd |= DMA_GCMD_SIRTP;
  329. writel(iommu->gcmd, iommu->reg + DMAR_GCMD_REG);
  330. IOMMU_WAIT_OP(iommu, DMAR_GSTS_REG,
  331. readl, (sts & DMA_GSTS_IRTPS), sts);
  332. spin_unlock_irqrestore(&iommu->register_lock, flags);
  333. /*
  334. * global invalidation of interrupt entry cache before enabling
  335. * interrupt-remapping.
  336. */
  337. qi_global_iec(iommu);
  338. spin_lock_irqsave(&iommu->register_lock, flags);
  339. /* Enable interrupt-remapping */
  340. iommu->gcmd |= DMA_GCMD_IRE;
  341. writel(iommu->gcmd, iommu->reg + DMAR_GCMD_REG);
  342. IOMMU_WAIT_OP(iommu, DMAR_GSTS_REG,
  343. readl, (sts & DMA_GSTS_IRES), sts);
  344. spin_unlock_irqrestore(&iommu->register_lock, flags);
  345. }
  346. static int setup_intr_remapping(struct intel_iommu *iommu, int mode)
  347. {
  348. struct ir_table *ir_table;
  349. struct page *pages;
  350. ir_table = iommu->ir_table = kzalloc(sizeof(struct ir_table),
  351. GFP_ATOMIC);
  352. if (!iommu->ir_table)
  353. return -ENOMEM;
  354. pages = alloc_pages_node(iommu->node, GFP_ATOMIC | __GFP_ZERO,
  355. INTR_REMAP_PAGE_ORDER);
  356. if (!pages) {
  357. printk(KERN_ERR "failed to allocate pages of order %d\n",
  358. INTR_REMAP_PAGE_ORDER);
  359. kfree(iommu->ir_table);
  360. return -ENOMEM;
  361. }
  362. ir_table->base = page_address(pages);
  363. iommu_set_intr_remapping(iommu, mode);
  364. return 0;
  365. }
  366. /*
  367. * Disable Interrupt Remapping.
  368. */
  369. static void iommu_disable_intr_remapping(struct intel_iommu *iommu)
  370. {
  371. unsigned long flags;
  372. u32 sts;
  373. if (!ecap_ir_support(iommu->ecap))
  374. return;
  375. /*
  376. * global invalidation of interrupt entry cache before disabling
  377. * interrupt-remapping.
  378. */
  379. qi_global_iec(iommu);
  380. spin_lock_irqsave(&iommu->register_lock, flags);
  381. sts = dmar_readq(iommu->reg + DMAR_GSTS_REG);
  382. if (!(sts & DMA_GSTS_IRES))
  383. goto end;
  384. iommu->gcmd &= ~DMA_GCMD_IRE;
  385. writel(iommu->gcmd, iommu->reg + DMAR_GCMD_REG);
  386. IOMMU_WAIT_OP(iommu, DMAR_GSTS_REG,
  387. readl, !(sts & DMA_GSTS_IRES), sts);
  388. end:
  389. spin_unlock_irqrestore(&iommu->register_lock, flags);
  390. }
  391. int __init intr_remapping_supported(void)
  392. {
  393. struct dmar_drhd_unit *drhd;
  394. if (disable_intremap)
  395. return 0;
  396. if (!dmar_ir_support())
  397. return 0;
  398. for_each_drhd_unit(drhd) {
  399. struct intel_iommu *iommu = drhd->iommu;
  400. if (!ecap_ir_support(iommu->ecap))
  401. return 0;
  402. }
  403. return 1;
  404. }
  405. int __init enable_intr_remapping(int eim)
  406. {
  407. struct dmar_drhd_unit *drhd;
  408. int setup = 0;
  409. if (parse_ioapics_under_ir() != 1) {
  410. printk(KERN_INFO "Not enable interrupt remapping\n");
  411. return -1;
  412. }
  413. for_each_drhd_unit(drhd) {
  414. struct intel_iommu *iommu = drhd->iommu;
  415. /*
  416. * If the queued invalidation is already initialized,
  417. * shouldn't disable it.
  418. */
  419. if (iommu->qi)
  420. continue;
  421. /*
  422. * Clear previous faults.
  423. */
  424. dmar_fault(-1, iommu);
  425. /*
  426. * Disable intr remapping and queued invalidation, if already
  427. * enabled prior to OS handover.
  428. */
  429. iommu_disable_intr_remapping(iommu);
  430. dmar_disable_qi(iommu);
  431. }
  432. /*
  433. * check for the Interrupt-remapping support
  434. */
  435. for_each_drhd_unit(drhd) {
  436. struct intel_iommu *iommu = drhd->iommu;
  437. if (!ecap_ir_support(iommu->ecap))
  438. continue;
  439. if (eim && !ecap_eim_support(iommu->ecap)) {
  440. printk(KERN_INFO "DRHD %Lx: EIM not supported by DRHD, "
  441. " ecap %Lx\n", drhd->reg_base_addr, iommu->ecap);
  442. return -1;
  443. }
  444. }
  445. /*
  446. * Enable queued invalidation for all the DRHD's.
  447. */
  448. for_each_drhd_unit(drhd) {
  449. int ret;
  450. struct intel_iommu *iommu = drhd->iommu;
  451. ret = dmar_enable_qi(iommu);
  452. if (ret) {
  453. printk(KERN_ERR "DRHD %Lx: failed to enable queued, "
  454. " invalidation, ecap %Lx, ret %d\n",
  455. drhd->reg_base_addr, iommu->ecap, ret);
  456. return -1;
  457. }
  458. }
  459. /*
  460. * Setup Interrupt-remapping for all the DRHD's now.
  461. */
  462. for_each_drhd_unit(drhd) {
  463. struct intel_iommu *iommu = drhd->iommu;
  464. if (!ecap_ir_support(iommu->ecap))
  465. continue;
  466. if (setup_intr_remapping(iommu, eim))
  467. goto error;
  468. setup = 1;
  469. }
  470. if (!setup)
  471. goto error;
  472. intr_remapping_enabled = 1;
  473. return 0;
  474. error:
  475. /*
  476. * handle error condition gracefully here!
  477. */
  478. return -1;
  479. }
  480. static void ir_parse_one_hpet_scope(struct acpi_dmar_device_scope *scope,
  481. struct intel_iommu *iommu)
  482. {
  483. struct acpi_dmar_pci_path *path;
  484. u8 bus;
  485. int count;
  486. bus = scope->bus;
  487. path = (struct acpi_dmar_pci_path *)(scope + 1);
  488. count = (scope->length - sizeof(struct acpi_dmar_device_scope))
  489. / sizeof(struct acpi_dmar_pci_path);
  490. while (--count > 0) {
  491. /*
  492. * Access PCI directly due to the PCI
  493. * subsystem isn't initialized yet.
  494. */
  495. bus = read_pci_config_byte(bus, path->dev, path->fn,
  496. PCI_SECONDARY_BUS);
  497. path++;
  498. }
  499. ir_hpet[ir_hpet_num].bus = bus;
  500. ir_hpet[ir_hpet_num].devfn = PCI_DEVFN(path->dev, path->fn);
  501. ir_hpet[ir_hpet_num].iommu = iommu;
  502. ir_hpet[ir_hpet_num].id = scope->enumeration_id;
  503. ir_hpet_num++;
  504. }
  505. static void ir_parse_one_ioapic_scope(struct acpi_dmar_device_scope *scope,
  506. struct intel_iommu *iommu)
  507. {
  508. struct acpi_dmar_pci_path *path;
  509. u8 bus;
  510. int count;
  511. bus = scope->bus;
  512. path = (struct acpi_dmar_pci_path *)(scope + 1);
  513. count = (scope->length - sizeof(struct acpi_dmar_device_scope))
  514. / sizeof(struct acpi_dmar_pci_path);
  515. while (--count > 0) {
  516. /*
  517. * Access PCI directly due to the PCI
  518. * subsystem isn't initialized yet.
  519. */
  520. bus = read_pci_config_byte(bus, path->dev, path->fn,
  521. PCI_SECONDARY_BUS);
  522. path++;
  523. }
  524. ir_ioapic[ir_ioapic_num].bus = bus;
  525. ir_ioapic[ir_ioapic_num].devfn = PCI_DEVFN(path->dev, path->fn);
  526. ir_ioapic[ir_ioapic_num].iommu = iommu;
  527. ir_ioapic[ir_ioapic_num].id = scope->enumeration_id;
  528. ir_ioapic_num++;
  529. }
  530. static int ir_parse_ioapic_hpet_scope(struct acpi_dmar_header *header,
  531. struct intel_iommu *iommu)
  532. {
  533. struct acpi_dmar_hardware_unit *drhd;
  534. struct acpi_dmar_device_scope *scope;
  535. void *start, *end;
  536. drhd = (struct acpi_dmar_hardware_unit *)header;
  537. start = (void *)(drhd + 1);
  538. end = ((void *)drhd) + header->length;
  539. while (start < end) {
  540. scope = start;
  541. if (scope->entry_type == ACPI_DMAR_SCOPE_TYPE_IOAPIC) {
  542. if (ir_ioapic_num == MAX_IO_APICS) {
  543. printk(KERN_WARNING "Exceeded Max IO APICS\n");
  544. return -1;
  545. }
  546. printk(KERN_INFO "IOAPIC id %d under DRHD base "
  547. " 0x%Lx IOMMU %d\n", scope->enumeration_id,
  548. drhd->address, iommu->seq_id);
  549. ir_parse_one_ioapic_scope(scope, iommu);
  550. } else if (scope->entry_type == ACPI_DMAR_SCOPE_TYPE_HPET) {
  551. if (ir_hpet_num == MAX_HPET_TBS) {
  552. printk(KERN_WARNING "Exceeded Max HPET blocks\n");
  553. return -1;
  554. }
  555. printk(KERN_INFO "HPET id %d under DRHD base"
  556. " 0x%Lx\n", scope->enumeration_id,
  557. drhd->address);
  558. ir_parse_one_hpet_scope(scope, iommu);
  559. }
  560. start += scope->length;
  561. }
  562. return 0;
  563. }
  564. /*
  565. * Finds the assocaition between IOAPIC's and its Interrupt-remapping
  566. * hardware unit.
  567. */
  568. int __init parse_ioapics_under_ir(void)
  569. {
  570. struct dmar_drhd_unit *drhd;
  571. int ir_supported = 0;
  572. for_each_drhd_unit(drhd) {
  573. struct intel_iommu *iommu = drhd->iommu;
  574. if (ecap_ir_support(iommu->ecap)) {
  575. if (ir_parse_ioapic_hpet_scope(drhd->hdr, iommu))
  576. return -1;
  577. ir_supported = 1;
  578. }
  579. }
  580. if (ir_supported && ir_ioapic_num != nr_ioapics) {
  581. printk(KERN_WARNING
  582. "Not all IO-APIC's listed under remapping hardware\n");
  583. return -1;
  584. }
  585. return ir_supported;
  586. }
  587. void disable_intr_remapping(void)
  588. {
  589. struct dmar_drhd_unit *drhd;
  590. struct intel_iommu *iommu = NULL;
  591. /*
  592. * Disable Interrupt-remapping for all the DRHD's now.
  593. */
  594. for_each_iommu(iommu, drhd) {
  595. if (!ecap_ir_support(iommu->ecap))
  596. continue;
  597. iommu_disable_intr_remapping(iommu);
  598. }
  599. }
  600. int reenable_intr_remapping(int eim)
  601. {
  602. struct dmar_drhd_unit *drhd;
  603. int setup = 0;
  604. struct intel_iommu *iommu = NULL;
  605. for_each_iommu(iommu, drhd)
  606. if (iommu->qi)
  607. dmar_reenable_qi(iommu);
  608. /*
  609. * Setup Interrupt-remapping for all the DRHD's now.
  610. */
  611. for_each_iommu(iommu, drhd) {
  612. if (!ecap_ir_support(iommu->ecap))
  613. continue;
  614. /* Set up interrupt remapping for iommu.*/
  615. iommu_set_intr_remapping(iommu, eim);
  616. setup = 1;
  617. }
  618. if (!setup)
  619. goto error;
  620. return 0;
  621. error:
  622. /*
  623. * handle error condition gracefully here!
  624. */
  625. return -1;
  626. }