dmar.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. * Copyright (c) 2006, Intel Corporation.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along with
  14. * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  15. * Place - Suite 330, Boston, MA 02111-1307 USA.
  16. *
  17. * Copyright (C) Ashok Raj <ashok.raj@intel.com>
  18. * Copyright (C) Shaohua Li <shaohua.li@intel.com>
  19. */
  20. #ifndef __DMAR_H__
  21. #define __DMAR_H__
  22. #include <linux/acpi.h>
  23. #include <linux/types.h>
  24. #include <linux/msi.h>
  25. #include <linux/irqreturn.h>
  26. #include <linux/rwsem.h>
  27. #include <linux/rcupdate.h>
  28. struct acpi_dmar_header;
  29. /* DMAR Flags */
  30. #define DMAR_INTR_REMAP 0x1
  31. #define DMAR_X2APIC_OPT_OUT 0x2
  32. struct intel_iommu;
  33. struct dmar_dev_scope {
  34. struct device __rcu *dev;
  35. u8 bus;
  36. u8 devfn;
  37. };
  38. #ifdef CONFIG_DMAR_TABLE
  39. extern struct acpi_table_header *dmar_tbl;
  40. struct dmar_drhd_unit {
  41. struct list_head list; /* list of drhd units */
  42. struct acpi_dmar_header *hdr; /* ACPI header */
  43. u64 reg_base_addr; /* register base address*/
  44. struct dmar_dev_scope *devices;/* target device array */
  45. int devices_cnt; /* target device count */
  46. u16 segment; /* PCI domain */
  47. u8 ignored:1; /* ignore drhd */
  48. u8 include_all:1;
  49. struct intel_iommu *iommu;
  50. };
  51. struct dmar_pci_path {
  52. u8 bus;
  53. u8 device;
  54. u8 function;
  55. };
  56. struct dmar_pci_notify_info {
  57. struct pci_dev *dev;
  58. unsigned long event;
  59. int bus;
  60. u16 seg;
  61. u16 level;
  62. struct dmar_pci_path path[];
  63. } __attribute__((packed));
  64. extern struct rw_semaphore dmar_global_lock;
  65. extern struct list_head dmar_drhd_units;
  66. #define for_each_drhd_unit(drhd) \
  67. list_for_each_entry_rcu(drhd, &dmar_drhd_units, list)
  68. #define for_each_active_drhd_unit(drhd) \
  69. list_for_each_entry_rcu(drhd, &dmar_drhd_units, list) \
  70. if (drhd->ignored) {} else
  71. #define for_each_active_iommu(i, drhd) \
  72. list_for_each_entry_rcu(drhd, &dmar_drhd_units, list) \
  73. if (i=drhd->iommu, drhd->ignored) {} else
  74. #define for_each_iommu(i, drhd) \
  75. list_for_each_entry_rcu(drhd, &dmar_drhd_units, list) \
  76. if (i=drhd->iommu, 0) {} else
  77. static inline bool dmar_rcu_check(void)
  78. {
  79. return rwsem_is_locked(&dmar_global_lock) ||
  80. system_state == SYSTEM_BOOTING;
  81. }
  82. #define dmar_rcu_dereference(p) rcu_dereference_check((p), dmar_rcu_check())
  83. #define for_each_dev_scope(a, c, p, d) \
  84. for ((p) = 0; ((d) = (p) < (c) ? dmar_rcu_dereference((a)[(p)].dev) : \
  85. NULL, (p) < (c)); (p)++)
  86. #define for_each_active_dev_scope(a, c, p, d) \
  87. for_each_dev_scope((a), (c), (p), (d)) if (!(d)) { continue; } else
  88. extern int dmar_table_init(void);
  89. extern int dmar_dev_scope_init(void);
  90. extern int dmar_parse_dev_scope(void *start, void *end, int *cnt,
  91. struct dmar_dev_scope **devices, u16 segment);
  92. extern void *dmar_alloc_dev_scope(void *start, void *end, int *cnt);
  93. extern void dmar_free_dev_scope(struct dmar_dev_scope **devices, int *cnt);
  94. extern int dmar_insert_dev_scope(struct dmar_pci_notify_info *info,
  95. void *start, void*end, u16 segment,
  96. struct dmar_dev_scope *devices,
  97. int devices_cnt);
  98. extern int dmar_remove_dev_scope(struct dmar_pci_notify_info *info,
  99. u16 segment, struct dmar_dev_scope *devices,
  100. int count);
  101. /* Intel IOMMU detection */
  102. extern int detect_intel_iommu(void);
  103. extern int enable_drhd_fault_handling(void);
  104. #ifdef CONFIG_INTEL_IOMMU
  105. extern int iommu_detected, no_iommu;
  106. extern int intel_iommu_init(void);
  107. extern int dmar_parse_one_rmrr(struct acpi_dmar_header *header);
  108. extern int dmar_parse_one_atsr(struct acpi_dmar_header *header);
  109. extern int dmar_iommu_notify_scope_dev(struct dmar_pci_notify_info *info);
  110. #else /* !CONFIG_INTEL_IOMMU: */
  111. static inline int intel_iommu_init(void) { return -ENODEV; }
  112. static inline int dmar_parse_one_rmrr(struct acpi_dmar_header *header)
  113. {
  114. return 0;
  115. }
  116. static inline int dmar_parse_one_atsr(struct acpi_dmar_header *header)
  117. {
  118. return 0;
  119. }
  120. static inline int dmar_iommu_notify_scope_dev(struct dmar_pci_notify_info *info)
  121. {
  122. return 0;
  123. }
  124. #endif /* CONFIG_INTEL_IOMMU */
  125. #endif /* CONFIG_DMAR_TABLE */
  126. struct irte {
  127. union {
  128. struct {
  129. __u64 present : 1,
  130. fpd : 1,
  131. dst_mode : 1,
  132. redir_hint : 1,
  133. trigger_mode : 1,
  134. dlvry_mode : 3,
  135. avail : 4,
  136. __reserved_1 : 4,
  137. vector : 8,
  138. __reserved_2 : 8,
  139. dest_id : 32;
  140. };
  141. __u64 low;
  142. };
  143. union {
  144. struct {
  145. __u64 sid : 16,
  146. sq : 2,
  147. svt : 2,
  148. __reserved_3 : 44;
  149. };
  150. __u64 high;
  151. };
  152. };
  153. enum {
  154. IRQ_REMAP_XAPIC_MODE,
  155. IRQ_REMAP_X2APIC_MODE,
  156. };
  157. /* Can't use the common MSI interrupt functions
  158. * since DMAR is not a pci device
  159. */
  160. struct irq_data;
  161. extern void dmar_msi_unmask(struct irq_data *data);
  162. extern void dmar_msi_mask(struct irq_data *data);
  163. extern void dmar_msi_read(int irq, struct msi_msg *msg);
  164. extern void dmar_msi_write(int irq, struct msi_msg *msg);
  165. extern int dmar_set_interrupt(struct intel_iommu *iommu);
  166. extern irqreturn_t dmar_fault(int irq, void *dev_id);
  167. extern int arch_setup_dmar_msi(unsigned int irq);
  168. #endif /* __DMAR_H__ */