dmar.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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. #ifdef CONFIG_X86
  30. # define DMAR_UNITS_SUPPORTED MAX_IO_APICS
  31. #else
  32. # define DMAR_UNITS_SUPPORTED 64
  33. #endif
  34. /* DMAR Flags */
  35. #define DMAR_INTR_REMAP 0x1
  36. #define DMAR_X2APIC_OPT_OUT 0x2
  37. struct intel_iommu;
  38. struct dmar_dev_scope {
  39. struct device __rcu *dev;
  40. u8 bus;
  41. u8 devfn;
  42. };
  43. #ifdef CONFIG_DMAR_TABLE
  44. extern struct acpi_table_header *dmar_tbl;
  45. struct dmar_drhd_unit {
  46. struct list_head list; /* list of drhd units */
  47. struct acpi_dmar_header *hdr; /* ACPI header */
  48. u64 reg_base_addr; /* register base address*/
  49. struct dmar_dev_scope *devices;/* target device array */
  50. int devices_cnt; /* target device count */
  51. u16 segment; /* PCI domain */
  52. u8 ignored:1; /* ignore drhd */
  53. u8 include_all:1;
  54. struct intel_iommu *iommu;
  55. };
  56. struct dmar_pci_path {
  57. u8 bus;
  58. u8 device;
  59. u8 function;
  60. };
  61. struct dmar_pci_notify_info {
  62. struct pci_dev *dev;
  63. unsigned long event;
  64. int bus;
  65. u16 seg;
  66. u16 level;
  67. struct dmar_pci_path path[];
  68. } __attribute__((packed));
  69. extern struct rw_semaphore dmar_global_lock;
  70. extern struct list_head dmar_drhd_units;
  71. #define for_each_drhd_unit(drhd) \
  72. list_for_each_entry_rcu(drhd, &dmar_drhd_units, list)
  73. #define for_each_active_drhd_unit(drhd) \
  74. list_for_each_entry_rcu(drhd, &dmar_drhd_units, list) \
  75. if (drhd->ignored) {} else
  76. #define for_each_active_iommu(i, drhd) \
  77. list_for_each_entry_rcu(drhd, &dmar_drhd_units, list) \
  78. if (i=drhd->iommu, drhd->ignored) {} else
  79. #define for_each_iommu(i, drhd) \
  80. list_for_each_entry_rcu(drhd, &dmar_drhd_units, list) \
  81. if (i=drhd->iommu, 0) {} else
  82. static inline bool dmar_rcu_check(void)
  83. {
  84. return rwsem_is_locked(&dmar_global_lock) ||
  85. system_state == SYSTEM_BOOTING;
  86. }
  87. #define dmar_rcu_dereference(p) rcu_dereference_check((p), dmar_rcu_check())
  88. #define for_each_dev_scope(a, c, p, d) \
  89. for ((p) = 0; ((d) = (p) < (c) ? dmar_rcu_dereference((a)[(p)].dev) : \
  90. NULL, (p) < (c)); (p)++)
  91. #define for_each_active_dev_scope(a, c, p, d) \
  92. for_each_dev_scope((a), (c), (p), (d)) if (!(d)) { continue; } else
  93. extern int dmar_table_init(void);
  94. extern int dmar_dev_scope_init(void);
  95. extern int dmar_parse_dev_scope(void *start, void *end, int *cnt,
  96. struct dmar_dev_scope **devices, u16 segment);
  97. extern void *dmar_alloc_dev_scope(void *start, void *end, int *cnt);
  98. extern void dmar_free_dev_scope(struct dmar_dev_scope **devices, int *cnt);
  99. extern int dmar_insert_dev_scope(struct dmar_pci_notify_info *info,
  100. void *start, void*end, u16 segment,
  101. struct dmar_dev_scope *devices,
  102. int devices_cnt);
  103. extern int dmar_remove_dev_scope(struct dmar_pci_notify_info *info,
  104. u16 segment, struct dmar_dev_scope *devices,
  105. int count);
  106. /* Intel IOMMU detection */
  107. extern int detect_intel_iommu(void);
  108. extern int enable_drhd_fault_handling(void);
  109. extern int dmar_device_add(acpi_handle handle);
  110. extern int dmar_device_remove(acpi_handle handle);
  111. static inline int dmar_res_noop(struct acpi_dmar_header *hdr, void *arg)
  112. {
  113. return 0;
  114. }
  115. #ifdef CONFIG_INTEL_IOMMU
  116. extern int iommu_detected, no_iommu;
  117. extern int intel_iommu_init(void);
  118. extern int dmar_parse_one_rmrr(struct acpi_dmar_header *header, void *arg);
  119. extern int dmar_parse_one_atsr(struct acpi_dmar_header *header, void *arg);
  120. extern int dmar_check_one_atsr(struct acpi_dmar_header *hdr, void *arg);
  121. extern int dmar_release_one_atsr(struct acpi_dmar_header *hdr, void *arg);
  122. extern int dmar_iommu_hotplug(struct dmar_drhd_unit *dmaru, bool insert);
  123. extern int dmar_iommu_notify_scope_dev(struct dmar_pci_notify_info *info);
  124. #else /* !CONFIG_INTEL_IOMMU: */
  125. static inline int intel_iommu_init(void) { return -ENODEV; }
  126. #define dmar_parse_one_rmrr dmar_res_noop
  127. #define dmar_parse_one_atsr dmar_res_noop
  128. #define dmar_check_one_atsr dmar_res_noop
  129. #define dmar_release_one_atsr dmar_res_noop
  130. static inline int dmar_iommu_notify_scope_dev(struct dmar_pci_notify_info *info)
  131. {
  132. return 0;
  133. }
  134. static inline int dmar_iommu_hotplug(struct dmar_drhd_unit *dmaru, bool insert)
  135. {
  136. return 0;
  137. }
  138. #endif /* CONFIG_INTEL_IOMMU */
  139. #ifdef CONFIG_IRQ_REMAP
  140. extern int dmar_ir_hotplug(struct dmar_drhd_unit *dmaru, bool insert);
  141. #else /* CONFIG_IRQ_REMAP */
  142. static inline int dmar_ir_hotplug(struct dmar_drhd_unit *dmaru, bool insert)
  143. { return 0; }
  144. #endif /* CONFIG_IRQ_REMAP */
  145. #else /* CONFIG_DMAR_TABLE */
  146. static inline int dmar_device_add(void *handle)
  147. {
  148. return 0;
  149. }
  150. static inline int dmar_device_remove(void *handle)
  151. {
  152. return 0;
  153. }
  154. #endif /* CONFIG_DMAR_TABLE */
  155. struct irte {
  156. union {
  157. /* Shared between remapped and posted mode*/
  158. struct {
  159. __u64 present : 1, /* 0 */
  160. fpd : 1, /* 1 */
  161. __res0 : 6, /* 2 - 6 */
  162. avail : 4, /* 8 - 11 */
  163. __res1 : 3, /* 12 - 14 */
  164. pst : 1, /* 15 */
  165. vector : 8, /* 16 - 23 */
  166. __res2 : 40; /* 24 - 63 */
  167. };
  168. /* Remapped mode */
  169. struct {
  170. __u64 r_present : 1, /* 0 */
  171. r_fpd : 1, /* 1 */
  172. dst_mode : 1, /* 2 */
  173. redir_hint : 1, /* 3 */
  174. trigger_mode : 1, /* 4 */
  175. dlvry_mode : 3, /* 5 - 7 */
  176. r_avail : 4, /* 8 - 11 */
  177. r_res0 : 4, /* 12 - 15 */
  178. r_vector : 8, /* 16 - 23 */
  179. r_res1 : 8, /* 24 - 31 */
  180. dest_id : 32; /* 32 - 63 */
  181. };
  182. /* Posted mode */
  183. struct {
  184. __u64 p_present : 1, /* 0 */
  185. p_fpd : 1, /* 1 */
  186. p_res0 : 6, /* 2 - 7 */
  187. p_avail : 4, /* 8 - 11 */
  188. p_res1 : 2, /* 12 - 13 */
  189. p_urgent : 1, /* 14 */
  190. p_pst : 1, /* 15 */
  191. p_vector : 8, /* 16 - 23 */
  192. p_res2 : 14, /* 24 - 37 */
  193. pda_l : 26; /* 38 - 63 */
  194. };
  195. __u64 low;
  196. };
  197. union {
  198. /* Shared between remapped and posted mode*/
  199. struct {
  200. __u64 sid : 16, /* 64 - 79 */
  201. sq : 2, /* 80 - 81 */
  202. svt : 2, /* 82 - 83 */
  203. __res3 : 44; /* 84 - 127 */
  204. };
  205. /* Posted mode*/
  206. struct {
  207. __u64 p_sid : 16, /* 64 - 79 */
  208. p_sq : 2, /* 80 - 81 */
  209. p_svt : 2, /* 82 - 83 */
  210. p_res3 : 12, /* 84 - 95 */
  211. pda_h : 32; /* 96 - 127 */
  212. };
  213. __u64 high;
  214. };
  215. };
  216. static inline void dmar_copy_shared_irte(struct irte *dst, struct irte *src)
  217. {
  218. dst->present = src->present;
  219. dst->fpd = src->fpd;
  220. dst->avail = src->avail;
  221. dst->pst = src->pst;
  222. dst->vector = src->vector;
  223. dst->sid = src->sid;
  224. dst->sq = src->sq;
  225. dst->svt = src->svt;
  226. }
  227. #define PDA_LOW_BIT 26
  228. #define PDA_HIGH_BIT 32
  229. enum {
  230. IRQ_REMAP_XAPIC_MODE,
  231. IRQ_REMAP_X2APIC_MODE,
  232. };
  233. /* Can't use the common MSI interrupt functions
  234. * since DMAR is not a pci device
  235. */
  236. struct irq_data;
  237. extern void dmar_msi_unmask(struct irq_data *data);
  238. extern void dmar_msi_mask(struct irq_data *data);
  239. extern void dmar_msi_read(int irq, struct msi_msg *msg);
  240. extern void dmar_msi_write(int irq, struct msi_msg *msg);
  241. extern int dmar_set_interrupt(struct intel_iommu *iommu);
  242. extern irqreturn_t dmar_fault(int irq, void *dev_id);
  243. extern int dmar_alloc_hwirq(int id, int node, void *arg);
  244. extern void dmar_free_hwirq(int irq);
  245. #endif /* __DMAR_H__ */