intr_remapping.c 17 KB

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