1 From: Suresh Siddha <suresh.b.siddha@intel.com>
2 Subject: x64, x2apic/intr-remap: code re-structuring, to be used by both DMA and Interrupt remapping
3 References: fate #303948 and fate #303984
4 Patch-Mainline: queued for .28
5 Commit-ID: 1886e8a90a580f3ad343f2065c84c1b9e1dac9ef
7 Signed-off-by: Thomas Renninger <trenn@suse.de>
9 Allocate the iommu during the parse of DMA remapping hardware
10 definition structures. And also, introduce routines for device
11 scope initialization which will be explicitly called during
12 dma-remapping initialization.
14 These will be used for enabling interrupt remapping separately from the
15 existing DMA-remapping enabling sequence.
17 Signed-off-by: Suresh Siddha <suresh.b.siddha@intel.com>
18 Cc: akpm@linux-foundation.org
19 Cc: arjan@linux.intel.com
20 Cc: andi@firstfloor.org
21 Cc: ebiederm@xmission.com
22 Cc: jbarnes@virtuousgeek.org
24 Signed-off-by: Ingo Molnar <mingo@elte.hu>
27 drivers/pci/dmar.c | 89 +++++++++++++++++++++++++++++++++++++---------
28 drivers/pci/intel-iommu.c | 10 ++---
29 drivers/pci/intel-iommu.h | 2 -
30 include/linux/dmar.h | 10 ++++-
31 4 files changed, 88 insertions(+), 23 deletions(-)
33 --- a/drivers/pci/dmar.c
34 +++ b/drivers/pci/dmar.c
35 @@ -174,19 +174,37 @@ dmar_parse_one_drhd(struct acpi_dmar_hea
36 struct acpi_dmar_hardware_unit *drhd;
37 struct dmar_drhd_unit *dmaru;
39 - static int include_all;
41 dmaru = kzalloc(sizeof(*dmaru), GFP_KERNEL);
45 + dmaru->hdr = header;
46 drhd = (struct acpi_dmar_hardware_unit *)header;
47 dmaru->reg_base_addr = drhd->address;
48 dmaru->include_all = drhd->flags & 0x1; /* BIT0: INCLUDE_ALL */
50 + ret = alloc_iommu(dmaru);
55 + dmar_register_drhd_unit(dmaru);
60 +dmar_parse_dev(struct dmar_drhd_unit *dmaru)
62 + struct acpi_dmar_hardware_unit *drhd;
63 + static int include_all;
66 + drhd = (struct acpi_dmar_hardware_unit *) dmaru->hdr;
68 if (!dmaru->include_all)
69 ret = dmar_parse_dev_scope((void *)(drhd + 1),
70 - ((void *)drhd) + header->length,
71 + ((void *)drhd) + drhd->header.length,
72 &dmaru->devices_cnt, &dmaru->devices,
75 @@ -199,10 +217,10 @@ dmar_parse_one_drhd(struct acpi_dmar_hea
79 - if (ret || (dmaru->devices_cnt == 0 && !dmaru->include_all))
80 + if (ret || (dmaru->devices_cnt == 0 && !dmaru->include_all)) {
81 + list_del(&dmaru->list);
84 - dmar_register_drhd_unit(dmaru);
89 @@ -211,23 +229,35 @@ dmar_parse_one_rmrr(struct acpi_dmar_hea
91 struct acpi_dmar_reserved_memory *rmrr;
92 struct dmar_rmrr_unit *rmrru;
95 rmrru = kzalloc(sizeof(*rmrru), GFP_KERNEL);
99 + rmrru->hdr = header;
100 rmrr = (struct acpi_dmar_reserved_memory *)header;
101 rmrru->base_address = rmrr->base_address;
102 rmrru->end_address = rmrr->end_address;
104 + dmar_register_rmrr_unit(rmrru);
109 +rmrr_parse_dev(struct dmar_rmrr_unit *rmrru)
111 + struct acpi_dmar_reserved_memory *rmrr;
114 + rmrr = (struct acpi_dmar_reserved_memory *) rmrru->hdr;
115 ret = dmar_parse_dev_scope((void *)(rmrr + 1),
116 - ((void *)rmrr) + header->length,
117 + ((void *)rmrr) + rmrr->header.length,
118 &rmrru->devices_cnt, &rmrru->devices, rmrr->segment);
120 - if (ret || (rmrru->devices_cnt == 0))
121 + if (ret || (rmrru->devices_cnt == 0)) {
122 + list_del(&rmrru->list);
125 - dmar_register_rmrr_unit(rmrru);
130 @@ -333,15 +363,42 @@ dmar_find_matched_drhd_unit(struct pci_d
134 +int __init dmar_dev_scope_init(void)
136 + struct dmar_drhd_unit *drhd;
137 + struct dmar_rmrr_unit *rmrr;
140 + for_each_drhd_unit(drhd) {
141 + ret = dmar_parse_dev(drhd);
146 + for_each_rmrr_units(rmrr) {
147 + ret = rmrr_parse_dev(rmrr);
156 int __init dmar_table_init(void)
159 + static int dmar_table_initialized;
162 + if (dmar_table_initialized)
165 + dmar_table_initialized = 1;
167 ret = parse_dmar_table();
169 - printk(KERN_INFO PREFIX "parse DMAR table failure.\n");
170 + if (ret != -ENODEV)
171 + printk(KERN_INFO PREFIX "parse DMAR table failure.\n");
175 @@ -375,7 +432,7 @@ int __init early_dmar_detect(void)
176 return (ACPI_SUCCESS(status) ? 1 : 0);
179 -struct intel_iommu *alloc_iommu(struct dmar_drhd_unit *drhd)
180 +int alloc_iommu(struct dmar_drhd_unit *drhd)
182 struct intel_iommu *iommu;
184 @@ -384,7 +441,7 @@ struct intel_iommu *alloc_iommu(struct d
186 iommu = kzalloc(sizeof(*iommu), GFP_KERNEL);
191 iommu->seq_id = iommu_allocated++;
193 @@ -417,10 +474,10 @@ struct intel_iommu *alloc_iommu(struct d
194 spin_lock_init(&iommu->register_lock);
205 void free_iommu(struct intel_iommu *iommu)
206 --- a/drivers/pci/intel-iommu.c
207 +++ b/drivers/pci/intel-iommu.c
208 @@ -1667,11 +1667,8 @@ int __init init_dmars(void)
209 for_each_drhd_unit(drhd) {
212 - iommu = alloc_iommu(drhd);
218 + iommu = drhd->iommu;
220 ret = iommu_init_domains(iommu);
222 @@ -2349,6 +2346,9 @@ int __init intel_iommu_init(void)
223 if (dmar_table_init())
226 + if (dmar_dev_scope_init())
229 iommu_init_mempool();
230 dmar_init_reserved_ranges();
232 --- a/drivers/pci/intel-iommu.h
233 +++ b/drivers/pci/intel-iommu.h
234 @@ -199,7 +199,7 @@ struct intel_iommu {
236 extern struct dmar_drhd_unit * dmar_find_matched_drhd_unit(struct pci_dev *dev);
238 -extern struct intel_iommu *alloc_iommu(struct dmar_drhd_unit *drhd);
239 +extern int alloc_iommu(struct dmar_drhd_unit *drhd);
240 extern void free_iommu(struct intel_iommu *iommu);
243 --- a/include/linux/dmar.h
244 +++ b/include/linux/dmar.h
245 @@ -46,12 +46,14 @@ extern int intel_iommu_init(void);
247 extern int dmar_table_init(void);
248 extern int early_dmar_detect(void);
249 +extern int dmar_dev_scope_init(void);
251 extern struct list_head dmar_drhd_units;
252 extern struct list_head dmar_rmrr_units;
254 struct dmar_drhd_unit {
255 struct list_head list; /* list of drhd units */
256 + struct acpi_dmar_header *hdr; /* ACPI header */
257 u64 reg_base_addr; /* register base address*/
258 struct pci_dev **devices; /* target device array */
259 int devices_cnt; /* target device count */
260 @@ -62,6 +64,7 @@ struct dmar_drhd_unit {
262 struct dmar_rmrr_unit {
263 struct list_head list; /* list of rmrr units */
264 + struct acpi_dmar_header *hdr; /* ACPI header */
265 u64 base_address; /* reserved base address*/
266 u64 end_address; /* reserved end address */
267 struct pci_dev **devices; /* target devices */
268 @@ -72,6 +75,8 @@ struct dmar_rmrr_unit {
269 list_for_each_entry(drhd, &dmar_drhd_units, list)
270 #define for_each_rmrr_units(rmrr) \
271 list_for_each_entry(rmrr, &dmar_rmrr_units, list)
273 +extern int alloc_iommu(struct dmar_drhd_unit *);
275 static inline void detect_intel_iommu(void)
277 @@ -81,6 +86,9 @@ static inline int intel_iommu_init(void)
282 +static inline int dmar_table_init(void)
286 #endif /* !CONFIG_DMAR */
287 #endif /* __DMAR_H__ */