blob: b3774ef3f25576ffa3083da12bed42ea97bbdffa [file] [log] [blame]
Keshavamurthy, Anil S10e52472007-10-21 16:41:41 -07001/*
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 *
mark gross98bcef52008-02-23 15:23:35 -080017 * Copyright (C) 2006-2008 Intel Corporation
18 * Author: Ashok Raj <ashok.raj@intel.com>
19 * Author: Shaohua Li <shaohua.li@intel.com>
20 * Author: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
Keshavamurthy, Anil S10e52472007-10-21 16:41:41 -070021 *
Suresh Siddhae61d98d2008-07-10 11:16:35 -070022 * This file implements early detection/parsing of Remapping Devices
Keshavamurthy, Anil S10e52472007-10-21 16:41:41 -070023 * reported to OS through BIOS via DMA remapping reporting (DMAR) ACPI
24 * tables.
Suresh Siddhae61d98d2008-07-10 11:16:35 -070025 *
26 * These routines are used by both DMA-remapping and Interrupt-remapping
Keshavamurthy, Anil S10e52472007-10-21 16:41:41 -070027 */
28
Donald Dutilee9071b02012-06-08 17:13:11 -040029#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt /* has to precede printk.h */
30
Keshavamurthy, Anil S10e52472007-10-21 16:41:41 -070031#include <linux/pci.h>
32#include <linux/dmar.h>
Kay, Allen M38717942008-09-09 18:37:29 +030033#include <linux/iova.h>
34#include <linux/intel-iommu.h>
Suresh Siddhafe962e92008-07-10 11:16:42 -070035#include <linux/timer.h>
Suresh Siddha0ac24912009-03-16 17:04:54 -070036#include <linux/irq.h>
37#include <linux/interrupt.h>
Shane Wang69575d32009-09-01 18:25:07 -070038#include <linux/tboot.h>
Len Browneb27cae2009-07-06 23:40:19 -040039#include <linux/dmi.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090040#include <linux/slab.h>
Alex Williamsona5459cf2014-06-12 16:12:31 -060041#include <linux/iommu.h>
Suresh Siddha8a8f4222012-03-30 11:47:08 -070042#include <asm/irq_remapping.h>
Konrad Rzeszutek Wilk4db77ff2010-08-26 13:58:04 -040043#include <asm/iommu_table.h>
Keshavamurthy, Anil S10e52472007-10-21 16:41:41 -070044
Joerg Roedel078e1ee2012-09-26 12:44:43 +020045#include "irq_remapping.h"
46
Jiang Liu3a5670e2014-02-19 14:07:33 +080047/*
48 * Assumptions:
49 * 1) The hotplug framework guarentees that DMAR unit will be hot-added
50 * before IO devices managed by that unit.
51 * 2) The hotplug framework guarantees that DMAR unit will be hot-removed
52 * after IO devices managed by that unit.
53 * 3) Hotplug events are rare.
54 *
55 * Locking rules for DMA and interrupt remapping related global data structures:
56 * 1) Use dmar_global_lock in process context
57 * 2) Use RCU in interrupt context
Keshavamurthy, Anil S10e52472007-10-21 16:41:41 -070058 */
Jiang Liu3a5670e2014-02-19 14:07:33 +080059DECLARE_RWSEM(dmar_global_lock);
Keshavamurthy, Anil S10e52472007-10-21 16:41:41 -070060LIST_HEAD(dmar_drhd_units);
Keshavamurthy, Anil S10e52472007-10-21 16:41:41 -070061
Suresh Siddha41750d32011-08-23 17:05:18 -070062struct acpi_table_header * __initdata dmar_tbl;
Yinghai Lu8e1568f2009-02-11 01:06:59 -080063static acpi_size dmar_tbl_size;
Jiang Liu2e455282014-02-19 14:07:36 +080064static int dmar_dev_scope_status = 1;
Keshavamurthy, Anil S10e52472007-10-21 16:41:41 -070065
Jiang Liu694835d2014-01-06 14:18:16 +080066static int alloc_iommu(struct dmar_drhd_unit *drhd);
Jiang Liua868e6b2014-01-06 14:18:20 +080067static void free_iommu(struct intel_iommu *iommu);
Jiang Liu694835d2014-01-06 14:18:16 +080068
Keshavamurthy, Anil S10e52472007-10-21 16:41:41 -070069static void __init dmar_register_drhd_unit(struct dmar_drhd_unit *drhd)
70{
71 /*
72 * add INCLUDE_ALL at the tail, so scan the list will find it at
73 * the very end.
74 */
75 if (drhd->include_all)
Jiang Liu0e242612014-02-19 14:07:34 +080076 list_add_tail_rcu(&drhd->list, &dmar_drhd_units);
Keshavamurthy, Anil S10e52472007-10-21 16:41:41 -070077 else
Jiang Liu0e242612014-02-19 14:07:34 +080078 list_add_rcu(&drhd->list, &dmar_drhd_units);
Keshavamurthy, Anil S10e52472007-10-21 16:41:41 -070079}
80
Jiang Liubb3a6b72014-02-19 14:07:24 +080081void *dmar_alloc_dev_scope(void *start, void *end, int *cnt)
Keshavamurthy, Anil S10e52472007-10-21 16:41:41 -070082{
83 struct acpi_dmar_device_scope *scope;
Keshavamurthy, Anil S10e52472007-10-21 16:41:41 -070084
85 *cnt = 0;
86 while (start < end) {
87 scope = start;
Bob Moore83118b02014-07-30 12:21:00 +080088 if (scope->entry_type == ACPI_DMAR_SCOPE_TYPE_NAMESPACE ||
David Woodhouse07cb52f2014-03-07 14:39:27 +000089 scope->entry_type == ACPI_DMAR_SCOPE_TYPE_ENDPOINT ||
Keshavamurthy, Anil S10e52472007-10-21 16:41:41 -070090 scope->entry_type == ACPI_DMAR_SCOPE_TYPE_BRIDGE)
91 (*cnt)++;
Linn Crosettoae3e7f32013-04-23 12:26:45 -060092 else if (scope->entry_type != ACPI_DMAR_SCOPE_TYPE_IOAPIC &&
93 scope->entry_type != ACPI_DMAR_SCOPE_TYPE_HPET) {
Donald Dutilee9071b02012-06-08 17:13:11 -040094 pr_warn("Unsupported device scope\n");
Yinghai Lu5715f0f2010-04-08 19:58:22 +010095 }
Keshavamurthy, Anil S10e52472007-10-21 16:41:41 -070096 start += scope->length;
97 }
98 if (*cnt == 0)
Jiang Liubb3a6b72014-02-19 14:07:24 +080099 return NULL;
Keshavamurthy, Anil S10e52472007-10-21 16:41:41 -0700100
David Woodhouse832bd852014-03-07 15:08:36 +0000101 return kcalloc(*cnt, sizeof(struct dmar_dev_scope), GFP_KERNEL);
Jiang Liubb3a6b72014-02-19 14:07:24 +0800102}
103
David Woodhouse832bd852014-03-07 15:08:36 +0000104void dmar_free_dev_scope(struct dmar_dev_scope **devices, int *cnt)
Jiang Liuada4d4b2014-01-06 14:18:09 +0800105{
Jiang Liub683b232014-02-19 14:07:32 +0800106 int i;
David Woodhouse832bd852014-03-07 15:08:36 +0000107 struct device *tmp_dev;
Jiang Liub683b232014-02-19 14:07:32 +0800108
Jiang Liuada4d4b2014-01-06 14:18:09 +0800109 if (*devices && *cnt) {
Jiang Liub683b232014-02-19 14:07:32 +0800110 for_each_active_dev_scope(*devices, *cnt, i, tmp_dev)
David Woodhouse832bd852014-03-07 15:08:36 +0000111 put_device(tmp_dev);
Jiang Liuada4d4b2014-01-06 14:18:09 +0800112 kfree(*devices);
Jiang Liuada4d4b2014-01-06 14:18:09 +0800113 }
Jiang Liu0e242612014-02-19 14:07:34 +0800114
115 *devices = NULL;
116 *cnt = 0;
Jiang Liuada4d4b2014-01-06 14:18:09 +0800117}
118
Jiang Liu59ce0512014-02-19 14:07:35 +0800119/* Optimize out kzalloc()/kfree() for normal cases */
120static char dmar_pci_notify_info_buf[64];
121
122static struct dmar_pci_notify_info *
123dmar_alloc_pci_notify_info(struct pci_dev *dev, unsigned long event)
124{
125 int level = 0;
126 size_t size;
127 struct pci_dev *tmp;
128 struct dmar_pci_notify_info *info;
129
130 BUG_ON(dev->is_virtfn);
131
132 /* Only generate path[] for device addition event */
133 if (event == BUS_NOTIFY_ADD_DEVICE)
134 for (tmp = dev; tmp; tmp = tmp->bus->self)
135 level++;
136
137 size = sizeof(*info) + level * sizeof(struct acpi_dmar_pci_path);
138 if (size <= sizeof(dmar_pci_notify_info_buf)) {
139 info = (struct dmar_pci_notify_info *)dmar_pci_notify_info_buf;
140 } else {
141 info = kzalloc(size, GFP_KERNEL);
142 if (!info) {
143 pr_warn("Out of memory when allocating notify_info "
144 "for %s.\n", pci_name(dev));
Jiang Liu2e455282014-02-19 14:07:36 +0800145 if (dmar_dev_scope_status == 0)
146 dmar_dev_scope_status = -ENOMEM;
Jiang Liu59ce0512014-02-19 14:07:35 +0800147 return NULL;
148 }
149 }
150
151 info->event = event;
152 info->dev = dev;
153 info->seg = pci_domain_nr(dev->bus);
154 info->level = level;
155 if (event == BUS_NOTIFY_ADD_DEVICE) {
Jiang Liu5ae05662014-04-15 10:35:35 +0800156 for (tmp = dev; tmp; tmp = tmp->bus->self) {
157 level--;
Joerg Roedel57384592014-10-02 11:50:25 +0200158 info->path[level].bus = tmp->bus->number;
Jiang Liu59ce0512014-02-19 14:07:35 +0800159 info->path[level].device = PCI_SLOT(tmp->devfn);
160 info->path[level].function = PCI_FUNC(tmp->devfn);
161 if (pci_is_root_bus(tmp->bus))
162 info->bus = tmp->bus->number;
163 }
164 }
165
166 return info;
167}
168
169static inline void dmar_free_pci_notify_info(struct dmar_pci_notify_info *info)
170{
171 if ((void *)info != dmar_pci_notify_info_buf)
172 kfree(info);
173}
174
175static bool dmar_match_pci_path(struct dmar_pci_notify_info *info, int bus,
176 struct acpi_dmar_pci_path *path, int count)
177{
178 int i;
179
180 if (info->bus != bus)
Joerg Roedel80f7b3d2014-09-22 16:30:22 +0200181 goto fallback;
Jiang Liu59ce0512014-02-19 14:07:35 +0800182 if (info->level != count)
Joerg Roedel80f7b3d2014-09-22 16:30:22 +0200183 goto fallback;
Jiang Liu59ce0512014-02-19 14:07:35 +0800184
185 for (i = 0; i < count; i++) {
186 if (path[i].device != info->path[i].device ||
187 path[i].function != info->path[i].function)
Joerg Roedel80f7b3d2014-09-22 16:30:22 +0200188 goto fallback;
Jiang Liu59ce0512014-02-19 14:07:35 +0800189 }
190
191 return true;
Joerg Roedel80f7b3d2014-09-22 16:30:22 +0200192
193fallback:
194
195 if (count != 1)
196 return false;
197
198 i = info->level - 1;
199 if (bus == info->path[i].bus &&
200 path[0].device == info->path[i].device &&
201 path[0].function == info->path[i].function) {
202 pr_info(FW_BUG "RMRR entry for device %02x:%02x.%x is broken - applying workaround\n",
203 bus, path[0].device, path[0].function);
204 return true;
205 }
206
207 return false;
Jiang Liu59ce0512014-02-19 14:07:35 +0800208}
209
210/* Return: > 0 if match found, 0 if no match found, < 0 if error happens */
211int dmar_insert_dev_scope(struct dmar_pci_notify_info *info,
212 void *start, void*end, u16 segment,
David Woodhouse832bd852014-03-07 15:08:36 +0000213 struct dmar_dev_scope *devices,
214 int devices_cnt)
Jiang Liu59ce0512014-02-19 14:07:35 +0800215{
216 int i, level;
David Woodhouse832bd852014-03-07 15:08:36 +0000217 struct device *tmp, *dev = &info->dev->dev;
Jiang Liu59ce0512014-02-19 14:07:35 +0800218 struct acpi_dmar_device_scope *scope;
219 struct acpi_dmar_pci_path *path;
220
221 if (segment != info->seg)
222 return 0;
223
224 for (; start < end; start += scope->length) {
225 scope = start;
226 if (scope->entry_type != ACPI_DMAR_SCOPE_TYPE_ENDPOINT &&
227 scope->entry_type != ACPI_DMAR_SCOPE_TYPE_BRIDGE)
228 continue;
229
230 path = (struct acpi_dmar_pci_path *)(scope + 1);
231 level = (scope->length - sizeof(*scope)) / sizeof(*path);
232 if (!dmar_match_pci_path(info, scope->bus, path, level))
233 continue;
234
235 if ((scope->entry_type == ACPI_DMAR_SCOPE_TYPE_ENDPOINT) ^
David Woodhouse832bd852014-03-07 15:08:36 +0000236 (info->dev->hdr_type == PCI_HEADER_TYPE_NORMAL)) {
Jiang Liu59ce0512014-02-19 14:07:35 +0800237 pr_warn("Device scope type does not match for %s\n",
David Woodhouse832bd852014-03-07 15:08:36 +0000238 pci_name(info->dev));
Jiang Liu59ce0512014-02-19 14:07:35 +0800239 return -EINVAL;
240 }
241
242 for_each_dev_scope(devices, devices_cnt, i, tmp)
243 if (tmp == NULL) {
David Woodhouse832bd852014-03-07 15:08:36 +0000244 devices[i].bus = info->dev->bus->number;
245 devices[i].devfn = info->dev->devfn;
246 rcu_assign_pointer(devices[i].dev,
247 get_device(dev));
Jiang Liu59ce0512014-02-19 14:07:35 +0800248 return 1;
249 }
250 BUG_ON(i >= devices_cnt);
251 }
252
253 return 0;
254}
255
256int dmar_remove_dev_scope(struct dmar_pci_notify_info *info, u16 segment,
David Woodhouse832bd852014-03-07 15:08:36 +0000257 struct dmar_dev_scope *devices, int count)
Jiang Liu59ce0512014-02-19 14:07:35 +0800258{
259 int index;
David Woodhouse832bd852014-03-07 15:08:36 +0000260 struct device *tmp;
Jiang Liu59ce0512014-02-19 14:07:35 +0800261
262 if (info->seg != segment)
263 return 0;
264
265 for_each_active_dev_scope(devices, count, index, tmp)
David Woodhouse832bd852014-03-07 15:08:36 +0000266 if (tmp == &info->dev->dev) {
Andreea-Cristina Bernateecbad72014-08-18 15:20:56 +0300267 RCU_INIT_POINTER(devices[index].dev, NULL);
Jiang Liu59ce0512014-02-19 14:07:35 +0800268 synchronize_rcu();
David Woodhouse832bd852014-03-07 15:08:36 +0000269 put_device(tmp);
Jiang Liu59ce0512014-02-19 14:07:35 +0800270 return 1;
271 }
272
273 return 0;
274}
275
276static int dmar_pci_bus_add_dev(struct dmar_pci_notify_info *info)
277{
278 int ret = 0;
279 struct dmar_drhd_unit *dmaru;
280 struct acpi_dmar_hardware_unit *drhd;
281
282 for_each_drhd_unit(dmaru) {
283 if (dmaru->include_all)
284 continue;
285
286 drhd = container_of(dmaru->hdr,
287 struct acpi_dmar_hardware_unit, header);
288 ret = dmar_insert_dev_scope(info, (void *)(drhd + 1),
289 ((void *)drhd) + drhd->header.length,
290 dmaru->segment,
291 dmaru->devices, dmaru->devices_cnt);
292 if (ret != 0)
293 break;
294 }
295 if (ret >= 0)
296 ret = dmar_iommu_notify_scope_dev(info);
Jiang Liu2e455282014-02-19 14:07:36 +0800297 if (ret < 0 && dmar_dev_scope_status == 0)
298 dmar_dev_scope_status = ret;
Jiang Liu59ce0512014-02-19 14:07:35 +0800299
300 return ret;
301}
302
303static void dmar_pci_bus_del_dev(struct dmar_pci_notify_info *info)
304{
305 struct dmar_drhd_unit *dmaru;
306
307 for_each_drhd_unit(dmaru)
308 if (dmar_remove_dev_scope(info, dmaru->segment,
309 dmaru->devices, dmaru->devices_cnt))
310 break;
311 dmar_iommu_notify_scope_dev(info);
312}
313
314static int dmar_pci_bus_notifier(struct notifier_block *nb,
315 unsigned long action, void *data)
316{
317 struct pci_dev *pdev = to_pci_dev(data);
318 struct dmar_pci_notify_info *info;
319
320 /* Only care about add/remove events for physical functions */
321 if (pdev->is_virtfn)
322 return NOTIFY_DONE;
323 if (action != BUS_NOTIFY_ADD_DEVICE && action != BUS_NOTIFY_DEL_DEVICE)
324 return NOTIFY_DONE;
325
326 info = dmar_alloc_pci_notify_info(pdev, action);
327 if (!info)
328 return NOTIFY_DONE;
329
330 down_write(&dmar_global_lock);
331 if (action == BUS_NOTIFY_ADD_DEVICE)
332 dmar_pci_bus_add_dev(info);
333 else if (action == BUS_NOTIFY_DEL_DEVICE)
334 dmar_pci_bus_del_dev(info);
335 up_write(&dmar_global_lock);
336
337 dmar_free_pci_notify_info(info);
338
339 return NOTIFY_OK;
340}
341
342static struct notifier_block dmar_pci_bus_nb = {
343 .notifier_call = dmar_pci_bus_notifier,
344 .priority = INT_MIN,
345};
346
Keshavamurthy, Anil S10e52472007-10-21 16:41:41 -0700347/**
348 * dmar_parse_one_drhd - parses exactly one DMA remapping hardware definition
349 * structure which uniquely represent one DMA remapping hardware unit
350 * present in the platform
351 */
352static int __init
353dmar_parse_one_drhd(struct acpi_dmar_header *header)
354{
355 struct acpi_dmar_hardware_unit *drhd;
356 struct dmar_drhd_unit *dmaru;
357 int ret = 0;
Keshavamurthy, Anil S10e52472007-10-21 16:41:41 -0700358
David Woodhousee523b382009-04-10 22:27:48 -0700359 drhd = (struct acpi_dmar_hardware_unit *)header;
Keshavamurthy, Anil S10e52472007-10-21 16:41:41 -0700360 dmaru = kzalloc(sizeof(*dmaru), GFP_KERNEL);
361 if (!dmaru)
362 return -ENOMEM;
363
Suresh Siddha1886e8a2008-07-10 11:16:37 -0700364 dmaru->hdr = header;
Keshavamurthy, Anil S10e52472007-10-21 16:41:41 -0700365 dmaru->reg_base_addr = drhd->address;
David Woodhouse276dbf92009-04-04 01:45:37 +0100366 dmaru->segment = drhd->segment;
Keshavamurthy, Anil S10e52472007-10-21 16:41:41 -0700367 dmaru->include_all = drhd->flags & 0x1; /* BIT0: INCLUDE_ALL */
David Woodhouse07cb52f2014-03-07 14:39:27 +0000368 dmaru->devices = dmar_alloc_dev_scope((void *)(drhd + 1),
369 ((void *)drhd) + drhd->header.length,
370 &dmaru->devices_cnt);
371 if (dmaru->devices_cnt && dmaru->devices == NULL) {
372 kfree(dmaru);
373 return -ENOMEM;
Jiang Liu2e455282014-02-19 14:07:36 +0800374 }
Keshavamurthy, Anil S10e52472007-10-21 16:41:41 -0700375
Suresh Siddha1886e8a2008-07-10 11:16:37 -0700376 ret = alloc_iommu(dmaru);
377 if (ret) {
David Woodhouse07cb52f2014-03-07 14:39:27 +0000378 dmar_free_dev_scope(&dmaru->devices,
379 &dmaru->devices_cnt);
Suresh Siddha1886e8a2008-07-10 11:16:37 -0700380 kfree(dmaru);
381 return ret;
382 }
383 dmar_register_drhd_unit(dmaru);
384 return 0;
385}
386
Jiang Liua868e6b2014-01-06 14:18:20 +0800387static void dmar_free_drhd(struct dmar_drhd_unit *dmaru)
388{
389 if (dmaru->devices && dmaru->devices_cnt)
390 dmar_free_dev_scope(&dmaru->devices, &dmaru->devices_cnt);
391 if (dmaru->iommu)
392 free_iommu(dmaru->iommu);
393 kfree(dmaru);
394}
395
David Woodhousee625b4a2014-03-07 14:34:38 +0000396static int __init dmar_parse_one_andd(struct acpi_dmar_header *header)
397{
398 struct acpi_dmar_andd *andd = (void *)header;
399
400 /* Check for NUL termination within the designated length */
Bob Moore83118b02014-07-30 12:21:00 +0800401 if (strnlen(andd->device_name, header->length - 8) == header->length - 8) {
David Woodhousee625b4a2014-03-07 14:34:38 +0000402 WARN_TAINT(1, TAINT_FIRMWARE_WORKAROUND,
403 "Your BIOS is broken; ANDD object name is not NUL-terminated\n"
404 "BIOS vendor: %s; Ver: %s; Product Version: %s\n",
405 dmi_get_system_info(DMI_BIOS_VENDOR),
406 dmi_get_system_info(DMI_BIOS_VERSION),
407 dmi_get_system_info(DMI_PRODUCT_VERSION));
408 return -EINVAL;
409 }
410 pr_info("ANDD device: %x name: %s\n", andd->device_number,
Bob Moore83118b02014-07-30 12:21:00 +0800411 andd->device_name);
David Woodhousee625b4a2014-03-07 14:34:38 +0000412
413 return 0;
414}
415
David Woodhouseaa697072009-10-07 12:18:00 +0100416#ifdef CONFIG_ACPI_NUMA
Suresh Siddhaee34b322009-10-02 11:01:21 -0700417static int __init
418dmar_parse_one_rhsa(struct acpi_dmar_header *header)
419{
420 struct acpi_dmar_rhsa *rhsa;
421 struct dmar_drhd_unit *drhd;
422
423 rhsa = (struct acpi_dmar_rhsa *)header;
David Woodhouseaa697072009-10-07 12:18:00 +0100424 for_each_drhd_unit(drhd) {
Suresh Siddhaee34b322009-10-02 11:01:21 -0700425 if (drhd->reg_base_addr == rhsa->base_address) {
426 int node = acpi_map_pxm_to_node(rhsa->proximity_domain);
427
428 if (!node_online(node))
429 node = -1;
430 drhd->iommu->node = node;
David Woodhouseaa697072009-10-07 12:18:00 +0100431 return 0;
432 }
Suresh Siddhaee34b322009-10-02 11:01:21 -0700433 }
Ben Hutchingsfd0c8892010-04-03 19:38:43 +0100434 WARN_TAINT(
435 1, TAINT_FIRMWARE_WORKAROUND,
436 "Your BIOS is broken; RHSA refers to non-existent DMAR unit at %llx\n"
437 "BIOS vendor: %s; Ver: %s; Product Version: %s\n",
438 drhd->reg_base_addr,
439 dmi_get_system_info(DMI_BIOS_VENDOR),
440 dmi_get_system_info(DMI_BIOS_VERSION),
441 dmi_get_system_info(DMI_PRODUCT_VERSION));
Suresh Siddhaee34b322009-10-02 11:01:21 -0700442
David Woodhouseaa697072009-10-07 12:18:00 +0100443 return 0;
Suresh Siddhaee34b322009-10-02 11:01:21 -0700444}
David Woodhouseaa697072009-10-07 12:18:00 +0100445#endif
Suresh Siddhaee34b322009-10-02 11:01:21 -0700446
Keshavamurthy, Anil S10e52472007-10-21 16:41:41 -0700447static void __init
448dmar_table_print_dmar_entry(struct acpi_dmar_header *header)
449{
450 struct acpi_dmar_hardware_unit *drhd;
451 struct acpi_dmar_reserved_memory *rmrr;
Yu Zhaoaa5d2b52009-05-18 13:51:34 +0800452 struct acpi_dmar_atsr *atsr;
Roland Dreier17b60972009-09-24 12:14:00 -0700453 struct acpi_dmar_rhsa *rhsa;
Keshavamurthy, Anil S10e52472007-10-21 16:41:41 -0700454
455 switch (header->type) {
456 case ACPI_DMAR_TYPE_HARDWARE_UNIT:
Yu Zhaoaa5d2b52009-05-18 13:51:34 +0800457 drhd = container_of(header, struct acpi_dmar_hardware_unit,
458 header);
Donald Dutilee9071b02012-06-08 17:13:11 -0400459 pr_info("DRHD base: %#016Lx flags: %#x\n",
Yu Zhaoaa5d2b52009-05-18 13:51:34 +0800460 (unsigned long long)drhd->address, drhd->flags);
Keshavamurthy, Anil S10e52472007-10-21 16:41:41 -0700461 break;
462 case ACPI_DMAR_TYPE_RESERVED_MEMORY:
Yu Zhaoaa5d2b52009-05-18 13:51:34 +0800463 rmrr = container_of(header, struct acpi_dmar_reserved_memory,
464 header);
Donald Dutilee9071b02012-06-08 17:13:11 -0400465 pr_info("RMRR base: %#016Lx end: %#016Lx\n",
Fenghua Yu5b6985c2008-10-16 18:02:32 -0700466 (unsigned long long)rmrr->base_address,
467 (unsigned long long)rmrr->end_address);
Keshavamurthy, Anil S10e52472007-10-21 16:41:41 -0700468 break;
Bob Moore83118b02014-07-30 12:21:00 +0800469 case ACPI_DMAR_TYPE_ROOT_ATS:
Yu Zhaoaa5d2b52009-05-18 13:51:34 +0800470 atsr = container_of(header, struct acpi_dmar_atsr, header);
Donald Dutilee9071b02012-06-08 17:13:11 -0400471 pr_info("ATSR flags: %#x\n", atsr->flags);
Yu Zhaoaa5d2b52009-05-18 13:51:34 +0800472 break;
Bob Moore83118b02014-07-30 12:21:00 +0800473 case ACPI_DMAR_TYPE_HARDWARE_AFFINITY:
Roland Dreier17b60972009-09-24 12:14:00 -0700474 rhsa = container_of(header, struct acpi_dmar_rhsa, header);
Donald Dutilee9071b02012-06-08 17:13:11 -0400475 pr_info("RHSA base: %#016Lx proximity domain: %#x\n",
Roland Dreier17b60972009-09-24 12:14:00 -0700476 (unsigned long long)rhsa->base_address,
477 rhsa->proximity_domain);
478 break;
Bob Moore83118b02014-07-30 12:21:00 +0800479 case ACPI_DMAR_TYPE_NAMESPACE:
David Woodhousee625b4a2014-03-07 14:34:38 +0000480 /* We don't print this here because we need to sanity-check
481 it first. So print it in dmar_parse_one_andd() instead. */
482 break;
Keshavamurthy, Anil S10e52472007-10-21 16:41:41 -0700483 }
484}
485
Yinghai Luf6dd5c32008-09-03 16:58:32 -0700486/**
487 * dmar_table_detect - checks to see if the platform supports DMAR devices
488 */
489static int __init dmar_table_detect(void)
490{
491 acpi_status status = AE_OK;
492
493 /* if we could find DMAR table, then there are DMAR devices */
Yinghai Lu8e1568f2009-02-11 01:06:59 -0800494 status = acpi_get_table_with_size(ACPI_SIG_DMAR, 0,
495 (struct acpi_table_header **)&dmar_tbl,
496 &dmar_tbl_size);
Yinghai Luf6dd5c32008-09-03 16:58:32 -0700497
498 if (ACPI_SUCCESS(status) && !dmar_tbl) {
Donald Dutilee9071b02012-06-08 17:13:11 -0400499 pr_warn("Unable to map DMAR\n");
Yinghai Luf6dd5c32008-09-03 16:58:32 -0700500 status = AE_NOT_FOUND;
501 }
502
503 return (ACPI_SUCCESS(status) ? 1 : 0);
504}
Suresh Siddhaaaa9d1d2008-07-10 11:16:38 -0700505
Keshavamurthy, Anil S10e52472007-10-21 16:41:41 -0700506/**
507 * parse_dmar_table - parses the DMA reporting table
508 */
509static int __init
510parse_dmar_table(void)
511{
512 struct acpi_table_dmar *dmar;
513 struct acpi_dmar_header *entry_header;
514 int ret = 0;
Li, Zhen-Hua7cef3342013-05-20 15:57:32 +0800515 int drhd_count = 0;
Keshavamurthy, Anil S10e52472007-10-21 16:41:41 -0700516
Yinghai Luf6dd5c32008-09-03 16:58:32 -0700517 /*
518 * Do it again, earlier dmar_tbl mapping could be mapped with
519 * fixed map.
520 */
521 dmar_table_detect();
522
Joseph Cihulaa59b50e2009-06-30 19:31:10 -0700523 /*
524 * ACPI tables may not be DMA protected by tboot, so use DMAR copy
525 * SINIT saved in SinitMleData in TXT heap (which is DMA protected)
526 */
527 dmar_tbl = tboot_get_dmar_table(dmar_tbl);
528
Keshavamurthy, Anil S10e52472007-10-21 16:41:41 -0700529 dmar = (struct acpi_table_dmar *)dmar_tbl;
530 if (!dmar)
531 return -ENODEV;
532
Fenghua Yu5b6985c2008-10-16 18:02:32 -0700533 if (dmar->width < PAGE_SHIFT - 1) {
Donald Dutilee9071b02012-06-08 17:13:11 -0400534 pr_warn("Invalid DMAR haw\n");
Keshavamurthy, Anil S10e52472007-10-21 16:41:41 -0700535 return -EINVAL;
536 }
537
Donald Dutilee9071b02012-06-08 17:13:11 -0400538 pr_info("Host address width %d\n", dmar->width + 1);
Keshavamurthy, Anil S10e52472007-10-21 16:41:41 -0700539
540 entry_header = (struct acpi_dmar_header *)(dmar + 1);
541 while (((unsigned long)entry_header) <
542 (((unsigned long)dmar) + dmar_tbl->length)) {
Tony Battersby084eb962009-02-11 13:24:19 -0800543 /* Avoid looping forever on bad ACPI tables */
544 if (entry_header->length == 0) {
Donald Dutilee9071b02012-06-08 17:13:11 -0400545 pr_warn("Invalid 0-length structure\n");
Tony Battersby084eb962009-02-11 13:24:19 -0800546 ret = -EINVAL;
547 break;
548 }
549
Keshavamurthy, Anil S10e52472007-10-21 16:41:41 -0700550 dmar_table_print_dmar_entry(entry_header);
551
552 switch (entry_header->type) {
553 case ACPI_DMAR_TYPE_HARDWARE_UNIT:
Li, Zhen-Hua7cef3342013-05-20 15:57:32 +0800554 drhd_count++;
Keshavamurthy, Anil S10e52472007-10-21 16:41:41 -0700555 ret = dmar_parse_one_drhd(entry_header);
556 break;
557 case ACPI_DMAR_TYPE_RESERVED_MEMORY:
558 ret = dmar_parse_one_rmrr(entry_header);
559 break;
Bob Moore83118b02014-07-30 12:21:00 +0800560 case ACPI_DMAR_TYPE_ROOT_ATS:
Yu Zhaoaa5d2b52009-05-18 13:51:34 +0800561 ret = dmar_parse_one_atsr(entry_header);
Yu Zhaoaa5d2b52009-05-18 13:51:34 +0800562 break;
Bob Moore83118b02014-07-30 12:21:00 +0800563 case ACPI_DMAR_TYPE_HARDWARE_AFFINITY:
David Woodhouseaa697072009-10-07 12:18:00 +0100564#ifdef CONFIG_ACPI_NUMA
Suresh Siddhaee34b322009-10-02 11:01:21 -0700565 ret = dmar_parse_one_rhsa(entry_header);
David Woodhouseaa697072009-10-07 12:18:00 +0100566#endif
Roland Dreier17b60972009-09-24 12:14:00 -0700567 break;
Bob Moore83118b02014-07-30 12:21:00 +0800568 case ACPI_DMAR_TYPE_NAMESPACE:
David Woodhousee625b4a2014-03-07 14:34:38 +0000569 ret = dmar_parse_one_andd(entry_header);
570 break;
Keshavamurthy, Anil S10e52472007-10-21 16:41:41 -0700571 default:
Donald Dutilee9071b02012-06-08 17:13:11 -0400572 pr_warn("Unknown DMAR structure type %d\n",
Roland Dreier4de75cf2009-09-24 01:01:29 +0100573 entry_header->type);
Keshavamurthy, Anil S10e52472007-10-21 16:41:41 -0700574 ret = 0; /* for forward compatibility */
575 break;
576 }
577 if (ret)
578 break;
579
580 entry_header = ((void *)entry_header + entry_header->length);
581 }
Li, Zhen-Hua7cef3342013-05-20 15:57:32 +0800582 if (drhd_count == 0)
583 pr_warn(FW_BUG "No DRHD structure found in DMAR table\n");
Keshavamurthy, Anil S10e52472007-10-21 16:41:41 -0700584 return ret;
585}
586
David Woodhouse832bd852014-03-07 15:08:36 +0000587static int dmar_pci_device_match(struct dmar_dev_scope devices[],
588 int cnt, struct pci_dev *dev)
Suresh Siddhae61d98d2008-07-10 11:16:35 -0700589{
590 int index;
David Woodhouse832bd852014-03-07 15:08:36 +0000591 struct device *tmp;
Suresh Siddhae61d98d2008-07-10 11:16:35 -0700592
593 while (dev) {
Jiang Liub683b232014-02-19 14:07:32 +0800594 for_each_active_dev_scope(devices, cnt, index, tmp)
David Woodhouse832bd852014-03-07 15:08:36 +0000595 if (dev_is_pci(tmp) && dev == to_pci_dev(tmp))
Suresh Siddhae61d98d2008-07-10 11:16:35 -0700596 return 1;
597
598 /* Check our parent */
599 dev = dev->bus->self;
600 }
601
602 return 0;
603}
604
605struct dmar_drhd_unit *
606dmar_find_matched_drhd_unit(struct pci_dev *dev)
607{
Jiang Liu0e242612014-02-19 14:07:34 +0800608 struct dmar_drhd_unit *dmaru;
Yu Zhao2e824f72008-12-22 16:54:58 +0800609 struct acpi_dmar_hardware_unit *drhd;
Suresh Siddhae61d98d2008-07-10 11:16:35 -0700610
Yinghaidda56542010-04-09 01:07:55 +0100611 dev = pci_physfn(dev);
612
Jiang Liu0e242612014-02-19 14:07:34 +0800613 rcu_read_lock();
Yijing Wang8b161f02013-10-31 17:25:16 +0800614 for_each_drhd_unit(dmaru) {
Yu Zhao2e824f72008-12-22 16:54:58 +0800615 drhd = container_of(dmaru->hdr,
616 struct acpi_dmar_hardware_unit,
617 header);
618
619 if (dmaru->include_all &&
620 drhd->segment == pci_domain_nr(dev->bus))
Jiang Liu0e242612014-02-19 14:07:34 +0800621 goto out;
Yu Zhao2e824f72008-12-22 16:54:58 +0800622
623 if (dmar_pci_device_match(dmaru->devices,
624 dmaru->devices_cnt, dev))
Jiang Liu0e242612014-02-19 14:07:34 +0800625 goto out;
Suresh Siddhae61d98d2008-07-10 11:16:35 -0700626 }
Jiang Liu0e242612014-02-19 14:07:34 +0800627 dmaru = NULL;
628out:
629 rcu_read_unlock();
Suresh Siddhae61d98d2008-07-10 11:16:35 -0700630
Jiang Liu0e242612014-02-19 14:07:34 +0800631 return dmaru;
Suresh Siddhae61d98d2008-07-10 11:16:35 -0700632}
633
David Woodhouseed403562014-03-07 23:15:42 +0000634static void __init dmar_acpi_insert_dev_scope(u8 device_number,
635 struct acpi_device *adev)
636{
637 struct dmar_drhd_unit *dmaru;
638 struct acpi_dmar_hardware_unit *drhd;
639 struct acpi_dmar_device_scope *scope;
640 struct device *tmp;
641 int i;
642 struct acpi_dmar_pci_path *path;
643
644 for_each_drhd_unit(dmaru) {
645 drhd = container_of(dmaru->hdr,
646 struct acpi_dmar_hardware_unit,
647 header);
648
649 for (scope = (void *)(drhd + 1);
650 (unsigned long)scope < ((unsigned long)drhd) + drhd->header.length;
651 scope = ((void *)scope) + scope->length) {
Bob Moore83118b02014-07-30 12:21:00 +0800652 if (scope->entry_type != ACPI_DMAR_SCOPE_TYPE_NAMESPACE)
David Woodhouseed403562014-03-07 23:15:42 +0000653 continue;
654 if (scope->enumeration_id != device_number)
655 continue;
656
657 path = (void *)(scope + 1);
658 pr_info("ACPI device \"%s\" under DMAR at %llx as %02x:%02x.%d\n",
659 dev_name(&adev->dev), dmaru->reg_base_addr,
660 scope->bus, path->device, path->function);
661 for_each_dev_scope(dmaru->devices, dmaru->devices_cnt, i, tmp)
662 if (tmp == NULL) {
663 dmaru->devices[i].bus = scope->bus;
664 dmaru->devices[i].devfn = PCI_DEVFN(path->device,
665 path->function);
666 rcu_assign_pointer(dmaru->devices[i].dev,
667 get_device(&adev->dev));
668 return;
669 }
670 BUG_ON(i >= dmaru->devices_cnt);
671 }
672 }
673 pr_warn("No IOMMU scope found for ANDD enumeration ID %d (%s)\n",
674 device_number, dev_name(&adev->dev));
675}
676
677static int __init dmar_acpi_dev_scope_init(void)
678{
Joerg Roedel11f1a772014-03-25 20:16:40 +0100679 struct acpi_dmar_andd *andd;
680
681 if (dmar_tbl == NULL)
682 return -ENODEV;
683
David Woodhouse7713ec02014-04-01 14:58:36 +0100684 for (andd = (void *)dmar_tbl + sizeof(struct acpi_table_dmar);
685 ((unsigned long)andd) < ((unsigned long)dmar_tbl) + dmar_tbl->length;
686 andd = ((void *)andd) + andd->header.length) {
Bob Moore83118b02014-07-30 12:21:00 +0800687 if (andd->header.type == ACPI_DMAR_TYPE_NAMESPACE) {
David Woodhouseed403562014-03-07 23:15:42 +0000688 acpi_handle h;
689 struct acpi_device *adev;
690
691 if (!ACPI_SUCCESS(acpi_get_handle(ACPI_ROOT_OBJECT,
Bob Moore83118b02014-07-30 12:21:00 +0800692 andd->device_name,
David Woodhouseed403562014-03-07 23:15:42 +0000693 &h))) {
694 pr_err("Failed to find handle for ACPI object %s\n",
Bob Moore83118b02014-07-30 12:21:00 +0800695 andd->device_name);
David Woodhouseed403562014-03-07 23:15:42 +0000696 continue;
697 }
698 acpi_bus_get_device(h, &adev);
699 if (!adev) {
700 pr_err("Failed to get device for ACPI object %s\n",
Bob Moore83118b02014-07-30 12:21:00 +0800701 andd->device_name);
David Woodhouseed403562014-03-07 23:15:42 +0000702 continue;
703 }
704 dmar_acpi_insert_dev_scope(andd->device_number, adev);
705 }
David Woodhouseed403562014-03-07 23:15:42 +0000706 }
707 return 0;
708}
709
Suresh Siddha1886e8a2008-07-10 11:16:37 -0700710int __init dmar_dev_scope_init(void)
711{
Jiang Liu2e455282014-02-19 14:07:36 +0800712 struct pci_dev *dev = NULL;
713 struct dmar_pci_notify_info *info;
Suresh Siddha1886e8a2008-07-10 11:16:37 -0700714
Jiang Liu2e455282014-02-19 14:07:36 +0800715 if (dmar_dev_scope_status != 1)
716 return dmar_dev_scope_status;
Suresh Siddhac2c72862011-08-23 17:05:19 -0700717
Jiang Liu2e455282014-02-19 14:07:36 +0800718 if (list_empty(&dmar_drhd_units)) {
719 dmar_dev_scope_status = -ENODEV;
720 } else {
721 dmar_dev_scope_status = 0;
Suresh Siddha318fe7d2011-08-23 17:05:20 -0700722
David Woodhouse63b42622014-03-28 11:28:40 +0000723 dmar_acpi_dev_scope_init();
724
Jiang Liu2e455282014-02-19 14:07:36 +0800725 for_each_pci_dev(dev) {
726 if (dev->is_virtfn)
727 continue;
728
729 info = dmar_alloc_pci_notify_info(dev,
730 BUS_NOTIFY_ADD_DEVICE);
731 if (!info) {
732 return dmar_dev_scope_status;
733 } else {
734 dmar_pci_bus_add_dev(info);
735 dmar_free_pci_notify_info(info);
736 }
737 }
738
739 bus_register_notifier(&pci_bus_type, &dmar_pci_bus_nb);
Suresh Siddha1886e8a2008-07-10 11:16:37 -0700740 }
741
Jiang Liu2e455282014-02-19 14:07:36 +0800742 return dmar_dev_scope_status;
Suresh Siddha1886e8a2008-07-10 11:16:37 -0700743}
744
Keshavamurthy, Anil S10e52472007-10-21 16:41:41 -0700745
746int __init dmar_table_init(void)
747{
Suresh Siddha1886e8a2008-07-10 11:16:37 -0700748 static int dmar_table_initialized;
Fenghua Yu093f87d2007-11-21 15:07:14 -0800749 int ret;
750
Jiang Liucc053012014-01-06 14:18:24 +0800751 if (dmar_table_initialized == 0) {
752 ret = parse_dmar_table();
753 if (ret < 0) {
754 if (ret != -ENODEV)
755 pr_info("parse DMAR table failure.\n");
756 } else if (list_empty(&dmar_drhd_units)) {
757 pr_info("No DMAR devices found\n");
758 ret = -ENODEV;
759 }
Suresh Siddha1886e8a2008-07-10 11:16:37 -0700760
Jiang Liucc053012014-01-06 14:18:24 +0800761 if (ret < 0)
762 dmar_table_initialized = ret;
763 else
764 dmar_table_initialized = 1;
Fenghua Yu093f87d2007-11-21 15:07:14 -0800765 }
766
Jiang Liucc053012014-01-06 14:18:24 +0800767 return dmar_table_initialized < 0 ? dmar_table_initialized : 0;
Keshavamurthy, Anil S10e52472007-10-21 16:41:41 -0700768}
769
Ben Hutchings3a8663e2010-04-03 19:37:23 +0100770static void warn_invalid_dmar(u64 addr, const char *message)
771{
Ben Hutchingsfd0c8892010-04-03 19:38:43 +0100772 WARN_TAINT_ONCE(
773 1, TAINT_FIRMWARE_WORKAROUND,
774 "Your BIOS is broken; DMAR reported at address %llx%s!\n"
775 "BIOS vendor: %s; Ver: %s; Product Version: %s\n",
776 addr, message,
777 dmi_get_system_info(DMI_BIOS_VENDOR),
778 dmi_get_system_info(DMI_BIOS_VERSION),
779 dmi_get_system_info(DMI_PRODUCT_VERSION));
Ben Hutchings3a8663e2010-04-03 19:37:23 +0100780}
David Woodhouse6ecbf012009-12-02 09:20:27 +0000781
Rashika Kheria21004dc2013-12-18 12:01:46 +0530782static int __init check_zero_address(void)
David Woodhouse86cf8982009-11-09 22:15:15 +0000783{
784 struct acpi_table_dmar *dmar;
785 struct acpi_dmar_header *entry_header;
786 struct acpi_dmar_hardware_unit *drhd;
787
788 dmar = (struct acpi_table_dmar *)dmar_tbl;
789 entry_header = (struct acpi_dmar_header *)(dmar + 1);
790
791 while (((unsigned long)entry_header) <
792 (((unsigned long)dmar) + dmar_tbl->length)) {
793 /* Avoid looping forever on bad ACPI tables */
794 if (entry_header->length == 0) {
Donald Dutilee9071b02012-06-08 17:13:11 -0400795 pr_warn("Invalid 0-length structure\n");
David Woodhouse86cf8982009-11-09 22:15:15 +0000796 return 0;
797 }
798
799 if (entry_header->type == ACPI_DMAR_TYPE_HARDWARE_UNIT) {
Chris Wright2c992202009-12-02 09:17:13 +0000800 void __iomem *addr;
801 u64 cap, ecap;
802
David Woodhouse86cf8982009-11-09 22:15:15 +0000803 drhd = (void *)entry_header;
804 if (!drhd->address) {
Ben Hutchings3a8663e2010-04-03 19:37:23 +0100805 warn_invalid_dmar(0, "");
Chris Wright2c992202009-12-02 09:17:13 +0000806 goto failed;
David Woodhouse86cf8982009-11-09 22:15:15 +0000807 }
Chris Wright2c992202009-12-02 09:17:13 +0000808
809 addr = early_ioremap(drhd->address, VTD_PAGE_SIZE);
810 if (!addr ) {
811 printk("IOMMU: can't validate: %llx\n", drhd->address);
812 goto failed;
813 }
814 cap = dmar_readq(addr + DMAR_CAP_REG);
815 ecap = dmar_readq(addr + DMAR_ECAP_REG);
816 early_iounmap(addr, VTD_PAGE_SIZE);
817 if (cap == (uint64_t)-1 && ecap == (uint64_t)-1) {
Ben Hutchings3a8663e2010-04-03 19:37:23 +0100818 warn_invalid_dmar(drhd->address,
819 " returns all ones");
Chris Wright2c992202009-12-02 09:17:13 +0000820 goto failed;
821 }
David Woodhouse86cf8982009-11-09 22:15:15 +0000822 }
823
824 entry_header = ((void *)entry_header + entry_header->length);
825 }
826 return 1;
Chris Wright2c992202009-12-02 09:17:13 +0000827
828failed:
Chris Wright2c992202009-12-02 09:17:13 +0000829 return 0;
David Woodhouse86cf8982009-11-09 22:15:15 +0000830}
831
Konrad Rzeszutek Wilk480125b2010-08-26 13:57:57 -0400832int __init detect_intel_iommu(void)
Suresh Siddha2ae21012008-07-10 11:16:43 -0700833{
834 int ret;
835
Jiang Liu3a5670e2014-02-19 14:07:33 +0800836 down_write(&dmar_global_lock);
Yinghai Luf6dd5c32008-09-03 16:58:32 -0700837 ret = dmar_table_detect();
David Woodhouse86cf8982009-11-09 22:15:15 +0000838 if (ret)
839 ret = check_zero_address();
Suresh Siddha2ae21012008-07-10 11:16:43 -0700840 {
Linus Torvalds11bd04f2009-12-11 12:18:16 -0800841 if (ret && !no_iommu && !iommu_detected && !dmar_disabled) {
Suresh Siddha2ae21012008-07-10 11:16:43 -0700842 iommu_detected = 1;
Chris Wright5d990b62009-12-04 12:15:21 -0800843 /* Make sure ACS will be enabled */
844 pci_request_acs();
845 }
Suresh Siddhaf5d1b972011-08-23 17:05:22 -0700846
FUJITA Tomonori9d5ce732009-11-10 19:46:16 +0900847#ifdef CONFIG_X86
848 if (ret)
849 x86_init.iommu.iommu_init = intel_iommu_init;
850#endif
Youquan Songcacd4212008-10-16 16:31:57 -0700851 }
Jiang Liub707cb02014-01-06 14:18:26 +0800852 early_acpi_os_unmap_memory((void __iomem *)dmar_tbl, dmar_tbl_size);
Yinghai Luf6dd5c32008-09-03 16:58:32 -0700853 dmar_tbl = NULL;
Jiang Liu3a5670e2014-02-19 14:07:33 +0800854 up_write(&dmar_global_lock);
Konrad Rzeszutek Wilk480125b2010-08-26 13:57:57 -0400855
Konrad Rzeszutek Wilk4db77ff2010-08-26 13:58:04 -0400856 return ret ? 1 : -ENODEV;
Suresh Siddha2ae21012008-07-10 11:16:43 -0700857}
858
859
Donald Dutile6f5cf522012-06-04 17:29:02 -0400860static void unmap_iommu(struct intel_iommu *iommu)
861{
862 iounmap(iommu->reg);
863 release_mem_region(iommu->reg_phys, iommu->reg_size);
864}
865
866/**
867 * map_iommu: map the iommu's registers
868 * @iommu: the iommu to map
869 * @phys_addr: the physical address of the base resgister
Donald Dutilee9071b02012-06-08 17:13:11 -0400870 *
Donald Dutile6f5cf522012-06-04 17:29:02 -0400871 * Memory map the iommu's registers. Start w/ a single page, and
Donald Dutilee9071b02012-06-08 17:13:11 -0400872 * possibly expand if that turns out to be insufficent.
Donald Dutile6f5cf522012-06-04 17:29:02 -0400873 */
874static int map_iommu(struct intel_iommu *iommu, u64 phys_addr)
875{
876 int map_size, err=0;
877
878 iommu->reg_phys = phys_addr;
879 iommu->reg_size = VTD_PAGE_SIZE;
880
881 if (!request_mem_region(iommu->reg_phys, iommu->reg_size, iommu->name)) {
882 pr_err("IOMMU: can't reserve memory\n");
883 err = -EBUSY;
884 goto out;
885 }
886
887 iommu->reg = ioremap(iommu->reg_phys, iommu->reg_size);
888 if (!iommu->reg) {
889 pr_err("IOMMU: can't map the region\n");
890 err = -ENOMEM;
891 goto release;
892 }
893
894 iommu->cap = dmar_readq(iommu->reg + DMAR_CAP_REG);
895 iommu->ecap = dmar_readq(iommu->reg + DMAR_ECAP_REG);
896
897 if (iommu->cap == (uint64_t)-1 && iommu->ecap == (uint64_t)-1) {
898 err = -EINVAL;
899 warn_invalid_dmar(phys_addr, " returns all ones");
900 goto unmap;
901 }
902
903 /* the registers might be more than one page */
904 map_size = max_t(int, ecap_max_iotlb_offset(iommu->ecap),
905 cap_max_fault_reg_offset(iommu->cap));
906 map_size = VTD_PAGE_ALIGN(map_size);
907 if (map_size > iommu->reg_size) {
908 iounmap(iommu->reg);
909 release_mem_region(iommu->reg_phys, iommu->reg_size);
910 iommu->reg_size = map_size;
911 if (!request_mem_region(iommu->reg_phys, iommu->reg_size,
912 iommu->name)) {
913 pr_err("IOMMU: can't reserve memory\n");
914 err = -EBUSY;
915 goto out;
916 }
917 iommu->reg = ioremap(iommu->reg_phys, iommu->reg_size);
918 if (!iommu->reg) {
919 pr_err("IOMMU: can't map the region\n");
920 err = -ENOMEM;
921 goto release;
922 }
923 }
924 err = 0;
925 goto out;
926
927unmap:
928 iounmap(iommu->reg);
929release:
930 release_mem_region(iommu->reg_phys, iommu->reg_size);
931out:
932 return err;
933}
934
Jiang Liu694835d2014-01-06 14:18:16 +0800935static int alloc_iommu(struct dmar_drhd_unit *drhd)
Suresh Siddhae61d98d2008-07-10 11:16:35 -0700936{
Suresh Siddhac42d9f32008-07-10 11:16:36 -0700937 struct intel_iommu *iommu;
Takao Indoh3a93c842013-04-23 17:35:03 +0900938 u32 ver, sts;
Suresh Siddhac42d9f32008-07-10 11:16:36 -0700939 static int iommu_allocated = 0;
Joerg Roedel43f73922009-01-03 23:56:27 +0100940 int agaw = 0;
Fenghua Yu4ed0d3e2009-04-24 17:30:20 -0700941 int msagaw = 0;
Donald Dutile6f5cf522012-06-04 17:29:02 -0400942 int err;
Suresh Siddhac42d9f32008-07-10 11:16:36 -0700943
David Woodhouse6ecbf012009-12-02 09:20:27 +0000944 if (!drhd->reg_base_addr) {
Ben Hutchings3a8663e2010-04-03 19:37:23 +0100945 warn_invalid_dmar(0, "");
David Woodhouse6ecbf012009-12-02 09:20:27 +0000946 return -EINVAL;
947 }
948
Suresh Siddhac42d9f32008-07-10 11:16:36 -0700949 iommu = kzalloc(sizeof(*iommu), GFP_KERNEL);
950 if (!iommu)
Suresh Siddha1886e8a2008-07-10 11:16:37 -0700951 return -ENOMEM;
Suresh Siddhac42d9f32008-07-10 11:16:36 -0700952
953 iommu->seq_id = iommu_allocated++;
Suresh Siddha9d783ba2009-03-16 17:04:55 -0700954 sprintf (iommu->name, "dmar%d", iommu->seq_id);
Suresh Siddhae61d98d2008-07-10 11:16:35 -0700955
Donald Dutile6f5cf522012-06-04 17:29:02 -0400956 err = map_iommu(iommu, drhd->reg_base_addr);
957 if (err) {
958 pr_err("IOMMU: failed to map %s\n", iommu->name);
Suresh Siddhae61d98d2008-07-10 11:16:35 -0700959 goto error;
960 }
Suresh Siddhae61d98d2008-07-10 11:16:35 -0700961
Donald Dutile6f5cf522012-06-04 17:29:02 -0400962 err = -EINVAL;
Weidong Han1b573682008-12-08 15:34:06 +0800963 agaw = iommu_calculate_agaw(iommu);
964 if (agaw < 0) {
Donald Dutilebf947fcb2012-06-04 17:29:01 -0400965 pr_err("Cannot get a valid agaw for iommu (seq_id = %d)\n",
966 iommu->seq_id);
David Woodhouse08155652009-08-04 09:17:20 +0100967 goto err_unmap;
Fenghua Yu4ed0d3e2009-04-24 17:30:20 -0700968 }
969 msagaw = iommu_calculate_max_sagaw(iommu);
970 if (msagaw < 0) {
Donald Dutilebf947fcb2012-06-04 17:29:01 -0400971 pr_err("Cannot get a valid max agaw for iommu (seq_id = %d)\n",
Weidong Han1b573682008-12-08 15:34:06 +0800972 iommu->seq_id);
David Woodhouse08155652009-08-04 09:17:20 +0100973 goto err_unmap;
Weidong Han1b573682008-12-08 15:34:06 +0800974 }
975 iommu->agaw = agaw;
Fenghua Yu4ed0d3e2009-04-24 17:30:20 -0700976 iommu->msagaw = msagaw;
David Woodhouse67ccac42014-03-09 13:49:45 -0700977 iommu->segment = drhd->segment;
Weidong Han1b573682008-12-08 15:34:06 +0800978
Suresh Siddhaee34b322009-10-02 11:01:21 -0700979 iommu->node = -1;
980
Suresh Siddhae61d98d2008-07-10 11:16:35 -0700981 ver = readl(iommu->reg + DMAR_VER_REG);
Yinghai Lu680a7522010-04-08 19:58:23 +0100982 pr_info("IOMMU %d: reg_base_addr %llx ver %d:%d cap %llx ecap %llx\n",
983 iommu->seq_id,
Fenghua Yu5b6985c2008-10-16 18:02:32 -0700984 (unsigned long long)drhd->reg_base_addr,
985 DMAR_VER_MAJOR(ver), DMAR_VER_MINOR(ver),
986 (unsigned long long)iommu->cap,
987 (unsigned long long)iommu->ecap);
Suresh Siddhae61d98d2008-07-10 11:16:35 -0700988
Takao Indoh3a93c842013-04-23 17:35:03 +0900989 /* Reflect status in gcmd */
990 sts = readl(iommu->reg + DMAR_GSTS_REG);
991 if (sts & DMA_GSTS_IRES)
992 iommu->gcmd |= DMA_GCMD_IRE;
993 if (sts & DMA_GSTS_TES)
994 iommu->gcmd |= DMA_GCMD_TE;
995 if (sts & DMA_GSTS_QIES)
996 iommu->gcmd |= DMA_GCMD_QIE;
997
Thomas Gleixner1f5b3c32011-07-19 16:19:51 +0200998 raw_spin_lock_init(&iommu->register_lock);
Suresh Siddhae61d98d2008-07-10 11:16:35 -0700999
1000 drhd->iommu = iommu;
Alex Williamsona5459cf2014-06-12 16:12:31 -06001001
1002 if (intel_iommu_enabled)
1003 iommu->iommu_dev = iommu_device_create(NULL, iommu,
1004 intel_iommu_groups,
1005 iommu->name);
1006
Suresh Siddha1886e8a2008-07-10 11:16:37 -07001007 return 0;
David Woodhouse08155652009-08-04 09:17:20 +01001008
1009 err_unmap:
Donald Dutile6f5cf522012-06-04 17:29:02 -04001010 unmap_iommu(iommu);
David Woodhouse08155652009-08-04 09:17:20 +01001011 error:
Suresh Siddhae61d98d2008-07-10 11:16:35 -07001012 kfree(iommu);
Donald Dutile6f5cf522012-06-04 17:29:02 -04001013 return err;
Suresh Siddhae61d98d2008-07-10 11:16:35 -07001014}
1015
Jiang Liua868e6b2014-01-06 14:18:20 +08001016static void free_iommu(struct intel_iommu *iommu)
Suresh Siddhae61d98d2008-07-10 11:16:35 -07001017{
Alex Williamsona5459cf2014-06-12 16:12:31 -06001018 iommu_device_destroy(iommu->iommu_dev);
1019
Jiang Liua868e6b2014-01-06 14:18:20 +08001020 if (iommu->irq) {
1021 free_irq(iommu->irq, iommu);
1022 irq_set_handler_data(iommu->irq, NULL);
Thomas Gleixnera553b142014-05-07 15:44:11 +00001023 dmar_free_hwirq(iommu->irq);
Jiang Liua868e6b2014-01-06 14:18:20 +08001024 }
Suresh Siddhae61d98d2008-07-10 11:16:35 -07001025
Jiang Liua84da702014-01-06 14:18:23 +08001026 if (iommu->qi) {
1027 free_page((unsigned long)iommu->qi->desc);
1028 kfree(iommu->qi->desc_status);
1029 kfree(iommu->qi);
1030 }
1031
Suresh Siddhae61d98d2008-07-10 11:16:35 -07001032 if (iommu->reg)
Donald Dutile6f5cf522012-06-04 17:29:02 -04001033 unmap_iommu(iommu);
1034
Suresh Siddhae61d98d2008-07-10 11:16:35 -07001035 kfree(iommu);
1036}
Suresh Siddhafe962e92008-07-10 11:16:42 -07001037
1038/*
1039 * Reclaim all the submitted descriptors which have completed its work.
1040 */
1041static inline void reclaim_free_desc(struct q_inval *qi)
1042{
Yu Zhao6ba6c3a2009-05-18 13:51:35 +08001043 while (qi->desc_status[qi->free_tail] == QI_DONE ||
1044 qi->desc_status[qi->free_tail] == QI_ABORT) {
Suresh Siddhafe962e92008-07-10 11:16:42 -07001045 qi->desc_status[qi->free_tail] = QI_FREE;
1046 qi->free_tail = (qi->free_tail + 1) % QI_LENGTH;
1047 qi->free_cnt++;
1048 }
1049}
1050
Yu Zhao704126a2009-01-04 16:28:52 +08001051static int qi_check_fault(struct intel_iommu *iommu, int index)
1052{
1053 u32 fault;
Yu Zhao6ba6c3a2009-05-18 13:51:35 +08001054 int head, tail;
Yu Zhao704126a2009-01-04 16:28:52 +08001055 struct q_inval *qi = iommu->qi;
1056 int wait_index = (index + 1) % QI_LENGTH;
1057
Yu Zhao6ba6c3a2009-05-18 13:51:35 +08001058 if (qi->desc_status[wait_index] == QI_ABORT)
1059 return -EAGAIN;
1060
Yu Zhao704126a2009-01-04 16:28:52 +08001061 fault = readl(iommu->reg + DMAR_FSTS_REG);
1062
1063 /*
1064 * If IQE happens, the head points to the descriptor associated
1065 * with the error. No new descriptors are fetched until the IQE
1066 * is cleared.
1067 */
1068 if (fault & DMA_FSTS_IQE) {
1069 head = readl(iommu->reg + DMAR_IQH_REG);
Yu Zhao6ba6c3a2009-05-18 13:51:35 +08001070 if ((head >> DMAR_IQ_SHIFT) == index) {
Donald Dutilebf947fcb2012-06-04 17:29:01 -04001071 pr_err("VT-d detected invalid descriptor: "
Yu Zhao6ba6c3a2009-05-18 13:51:35 +08001072 "low=%llx, high=%llx\n",
1073 (unsigned long long)qi->desc[index].low,
1074 (unsigned long long)qi->desc[index].high);
Yu Zhao704126a2009-01-04 16:28:52 +08001075 memcpy(&qi->desc[index], &qi->desc[wait_index],
1076 sizeof(struct qi_desc));
1077 __iommu_flush_cache(iommu, &qi->desc[index],
1078 sizeof(struct qi_desc));
1079 writel(DMA_FSTS_IQE, iommu->reg + DMAR_FSTS_REG);
1080 return -EINVAL;
1081 }
1082 }
1083
Yu Zhao6ba6c3a2009-05-18 13:51:35 +08001084 /*
1085 * If ITE happens, all pending wait_desc commands are aborted.
1086 * No new descriptors are fetched until the ITE is cleared.
1087 */
1088 if (fault & DMA_FSTS_ITE) {
1089 head = readl(iommu->reg + DMAR_IQH_REG);
1090 head = ((head >> DMAR_IQ_SHIFT) - 1 + QI_LENGTH) % QI_LENGTH;
1091 head |= 1;
1092 tail = readl(iommu->reg + DMAR_IQT_REG);
1093 tail = ((tail >> DMAR_IQ_SHIFT) - 1 + QI_LENGTH) % QI_LENGTH;
1094
1095 writel(DMA_FSTS_ITE, iommu->reg + DMAR_FSTS_REG);
1096
1097 do {
1098 if (qi->desc_status[head] == QI_IN_USE)
1099 qi->desc_status[head] = QI_ABORT;
1100 head = (head - 2 + QI_LENGTH) % QI_LENGTH;
1101 } while (head != tail);
1102
1103 if (qi->desc_status[wait_index] == QI_ABORT)
1104 return -EAGAIN;
1105 }
1106
1107 if (fault & DMA_FSTS_ICE)
1108 writel(DMA_FSTS_ICE, iommu->reg + DMAR_FSTS_REG);
1109
Yu Zhao704126a2009-01-04 16:28:52 +08001110 return 0;
1111}
1112
Suresh Siddhafe962e92008-07-10 11:16:42 -07001113/*
1114 * Submit the queued invalidation descriptor to the remapping
1115 * hardware unit and wait for its completion.
1116 */
Yu Zhao704126a2009-01-04 16:28:52 +08001117int qi_submit_sync(struct qi_desc *desc, struct intel_iommu *iommu)
Suresh Siddhafe962e92008-07-10 11:16:42 -07001118{
Yu Zhao6ba6c3a2009-05-18 13:51:35 +08001119 int rc;
Suresh Siddhafe962e92008-07-10 11:16:42 -07001120 struct q_inval *qi = iommu->qi;
1121 struct qi_desc *hw, wait_desc;
1122 int wait_index, index;
1123 unsigned long flags;
1124
1125 if (!qi)
Yu Zhao704126a2009-01-04 16:28:52 +08001126 return 0;
Suresh Siddhafe962e92008-07-10 11:16:42 -07001127
1128 hw = qi->desc;
1129
Yu Zhao6ba6c3a2009-05-18 13:51:35 +08001130restart:
1131 rc = 0;
1132
Thomas Gleixner3b8f4042011-07-19 17:02:07 +02001133 raw_spin_lock_irqsave(&qi->q_lock, flags);
Suresh Siddhafe962e92008-07-10 11:16:42 -07001134 while (qi->free_cnt < 3) {
Thomas Gleixner3b8f4042011-07-19 17:02:07 +02001135 raw_spin_unlock_irqrestore(&qi->q_lock, flags);
Suresh Siddhafe962e92008-07-10 11:16:42 -07001136 cpu_relax();
Thomas Gleixner3b8f4042011-07-19 17:02:07 +02001137 raw_spin_lock_irqsave(&qi->q_lock, flags);
Suresh Siddhafe962e92008-07-10 11:16:42 -07001138 }
1139
1140 index = qi->free_head;
1141 wait_index = (index + 1) % QI_LENGTH;
1142
1143 qi->desc_status[index] = qi->desc_status[wait_index] = QI_IN_USE;
1144
1145 hw[index] = *desc;
1146
Yu Zhao704126a2009-01-04 16:28:52 +08001147 wait_desc.low = QI_IWD_STATUS_DATA(QI_DONE) |
1148 QI_IWD_STATUS_WRITE | QI_IWD_TYPE;
Suresh Siddhafe962e92008-07-10 11:16:42 -07001149 wait_desc.high = virt_to_phys(&qi->desc_status[wait_index]);
1150
1151 hw[wait_index] = wait_desc;
1152
1153 __iommu_flush_cache(iommu, &hw[index], sizeof(struct qi_desc));
1154 __iommu_flush_cache(iommu, &hw[wait_index], sizeof(struct qi_desc));
1155
1156 qi->free_head = (qi->free_head + 2) % QI_LENGTH;
1157 qi->free_cnt -= 2;
1158
Suresh Siddhafe962e92008-07-10 11:16:42 -07001159 /*
1160 * update the HW tail register indicating the presence of
1161 * new descriptors.
1162 */
Yu Zhao6ba6c3a2009-05-18 13:51:35 +08001163 writel(qi->free_head << DMAR_IQ_SHIFT, iommu->reg + DMAR_IQT_REG);
Suresh Siddhafe962e92008-07-10 11:16:42 -07001164
1165 while (qi->desc_status[wait_index] != QI_DONE) {
Suresh Siddhaf05810c2008-10-16 16:31:54 -07001166 /*
1167 * We will leave the interrupts disabled, to prevent interrupt
1168 * context to queue another cmd while a cmd is already submitted
1169 * and waiting for completion on this cpu. This is to avoid
1170 * a deadlock where the interrupt context can wait indefinitely
1171 * for free slots in the queue.
1172 */
Yu Zhao704126a2009-01-04 16:28:52 +08001173 rc = qi_check_fault(iommu, index);
1174 if (rc)
Yu Zhao6ba6c3a2009-05-18 13:51:35 +08001175 break;
Yu Zhao704126a2009-01-04 16:28:52 +08001176
Thomas Gleixner3b8f4042011-07-19 17:02:07 +02001177 raw_spin_unlock(&qi->q_lock);
Suresh Siddhafe962e92008-07-10 11:16:42 -07001178 cpu_relax();
Thomas Gleixner3b8f4042011-07-19 17:02:07 +02001179 raw_spin_lock(&qi->q_lock);
Suresh Siddhafe962e92008-07-10 11:16:42 -07001180 }
Yu Zhao6ba6c3a2009-05-18 13:51:35 +08001181
1182 qi->desc_status[index] = QI_DONE;
Suresh Siddhafe962e92008-07-10 11:16:42 -07001183
1184 reclaim_free_desc(qi);
Thomas Gleixner3b8f4042011-07-19 17:02:07 +02001185 raw_spin_unlock_irqrestore(&qi->q_lock, flags);
Yu Zhao704126a2009-01-04 16:28:52 +08001186
Yu Zhao6ba6c3a2009-05-18 13:51:35 +08001187 if (rc == -EAGAIN)
1188 goto restart;
1189
Yu Zhao704126a2009-01-04 16:28:52 +08001190 return rc;
Suresh Siddhafe962e92008-07-10 11:16:42 -07001191}
1192
1193/*
1194 * Flush the global interrupt entry cache.
1195 */
1196void qi_global_iec(struct intel_iommu *iommu)
1197{
1198 struct qi_desc desc;
1199
1200 desc.low = QI_IEC_TYPE;
1201 desc.high = 0;
1202
Yu Zhao704126a2009-01-04 16:28:52 +08001203 /* should never fail */
Suresh Siddhafe962e92008-07-10 11:16:42 -07001204 qi_submit_sync(&desc, iommu);
1205}
1206
David Woodhouse4c25a2c2009-05-10 17:16:06 +01001207void qi_flush_context(struct intel_iommu *iommu, u16 did, u16 sid, u8 fm,
1208 u64 type)
Youquan Song3481f212008-10-16 16:31:55 -07001209{
Youquan Song3481f212008-10-16 16:31:55 -07001210 struct qi_desc desc;
1211
Youquan Song3481f212008-10-16 16:31:55 -07001212 desc.low = QI_CC_FM(fm) | QI_CC_SID(sid) | QI_CC_DID(did)
1213 | QI_CC_GRAN(type) | QI_CC_TYPE;
1214 desc.high = 0;
1215
David Woodhouse4c25a2c2009-05-10 17:16:06 +01001216 qi_submit_sync(&desc, iommu);
Youquan Song3481f212008-10-16 16:31:55 -07001217}
1218
David Woodhouse1f0ef2a2009-05-10 19:58:49 +01001219void qi_flush_iotlb(struct intel_iommu *iommu, u16 did, u64 addr,
1220 unsigned int size_order, u64 type)
Youquan Song3481f212008-10-16 16:31:55 -07001221{
1222 u8 dw = 0, dr = 0;
1223
1224 struct qi_desc desc;
1225 int ih = 0;
1226
Youquan Song3481f212008-10-16 16:31:55 -07001227 if (cap_write_drain(iommu->cap))
1228 dw = 1;
1229
1230 if (cap_read_drain(iommu->cap))
1231 dr = 1;
1232
1233 desc.low = QI_IOTLB_DID(did) | QI_IOTLB_DR(dr) | QI_IOTLB_DW(dw)
1234 | QI_IOTLB_GRAN(type) | QI_IOTLB_TYPE;
1235 desc.high = QI_IOTLB_ADDR(addr) | QI_IOTLB_IH(ih)
1236 | QI_IOTLB_AM(size_order);
1237
David Woodhouse1f0ef2a2009-05-10 19:58:49 +01001238 qi_submit_sync(&desc, iommu);
Youquan Song3481f212008-10-16 16:31:55 -07001239}
1240
Yu Zhao6ba6c3a2009-05-18 13:51:35 +08001241void qi_flush_dev_iotlb(struct intel_iommu *iommu, u16 sid, u16 qdep,
1242 u64 addr, unsigned mask)
1243{
1244 struct qi_desc desc;
1245
1246 if (mask) {
1247 BUG_ON(addr & ((1 << (VTD_PAGE_SHIFT + mask)) - 1));
1248 addr |= (1 << (VTD_PAGE_SHIFT + mask - 1)) - 1;
1249 desc.high = QI_DEV_IOTLB_ADDR(addr) | QI_DEV_IOTLB_SIZE;
1250 } else
1251 desc.high = QI_DEV_IOTLB_ADDR(addr);
1252
1253 if (qdep >= QI_DEV_IOTLB_MAX_INVS)
1254 qdep = 0;
1255
1256 desc.low = QI_DEV_IOTLB_SID(sid) | QI_DEV_IOTLB_QDEP(qdep) |
1257 QI_DIOTLB_TYPE;
1258
1259 qi_submit_sync(&desc, iommu);
1260}
1261
Suresh Siddhafe962e92008-07-10 11:16:42 -07001262/*
Suresh Siddhaeba67e52009-03-16 17:04:56 -07001263 * Disable Queued Invalidation interface.
1264 */
1265void dmar_disable_qi(struct intel_iommu *iommu)
1266{
1267 unsigned long flags;
1268 u32 sts;
1269 cycles_t start_time = get_cycles();
1270
1271 if (!ecap_qis(iommu->ecap))
1272 return;
1273
Thomas Gleixner1f5b3c32011-07-19 16:19:51 +02001274 raw_spin_lock_irqsave(&iommu->register_lock, flags);
Suresh Siddhaeba67e52009-03-16 17:04:56 -07001275
1276 sts = dmar_readq(iommu->reg + DMAR_GSTS_REG);
1277 if (!(sts & DMA_GSTS_QIES))
1278 goto end;
1279
1280 /*
1281 * Give a chance to HW to complete the pending invalidation requests.
1282 */
1283 while ((readl(iommu->reg + DMAR_IQT_REG) !=
1284 readl(iommu->reg + DMAR_IQH_REG)) &&
1285 (DMAR_OPERATION_TIMEOUT > (get_cycles() - start_time)))
1286 cpu_relax();
1287
1288 iommu->gcmd &= ~DMA_GCMD_QIE;
Suresh Siddhaeba67e52009-03-16 17:04:56 -07001289 writel(iommu->gcmd, iommu->reg + DMAR_GCMD_REG);
1290
1291 IOMMU_WAIT_OP(iommu, DMAR_GSTS_REG, readl,
1292 !(sts & DMA_GSTS_QIES), sts);
1293end:
Thomas Gleixner1f5b3c32011-07-19 16:19:51 +02001294 raw_spin_unlock_irqrestore(&iommu->register_lock, flags);
Suresh Siddhaeba67e52009-03-16 17:04:56 -07001295}
1296
1297/*
Fenghua Yueb4a52b2009-03-27 14:22:43 -07001298 * Enable queued invalidation.
1299 */
1300static void __dmar_enable_qi(struct intel_iommu *iommu)
1301{
David Woodhousec416daa2009-05-10 20:30:58 +01001302 u32 sts;
Fenghua Yueb4a52b2009-03-27 14:22:43 -07001303 unsigned long flags;
1304 struct q_inval *qi = iommu->qi;
1305
1306 qi->free_head = qi->free_tail = 0;
1307 qi->free_cnt = QI_LENGTH;
1308
Thomas Gleixner1f5b3c32011-07-19 16:19:51 +02001309 raw_spin_lock_irqsave(&iommu->register_lock, flags);
Fenghua Yueb4a52b2009-03-27 14:22:43 -07001310
1311 /* write zero to the tail reg */
1312 writel(0, iommu->reg + DMAR_IQT_REG);
1313
1314 dmar_writeq(iommu->reg + DMAR_IQA_REG, virt_to_phys(qi->desc));
1315
Fenghua Yueb4a52b2009-03-27 14:22:43 -07001316 iommu->gcmd |= DMA_GCMD_QIE;
David Woodhousec416daa2009-05-10 20:30:58 +01001317 writel(iommu->gcmd, iommu->reg + DMAR_GCMD_REG);
Fenghua Yueb4a52b2009-03-27 14:22:43 -07001318
1319 /* Make sure hardware complete it */
1320 IOMMU_WAIT_OP(iommu, DMAR_GSTS_REG, readl, (sts & DMA_GSTS_QIES), sts);
1321
Thomas Gleixner1f5b3c32011-07-19 16:19:51 +02001322 raw_spin_unlock_irqrestore(&iommu->register_lock, flags);
Fenghua Yueb4a52b2009-03-27 14:22:43 -07001323}
1324
1325/*
Suresh Siddhafe962e92008-07-10 11:16:42 -07001326 * Enable Queued Invalidation interface. This is a must to support
1327 * interrupt-remapping. Also used by DMA-remapping, which replaces
1328 * register based IOTLB invalidation.
1329 */
1330int dmar_enable_qi(struct intel_iommu *iommu)
1331{
Suresh Siddhafe962e92008-07-10 11:16:42 -07001332 struct q_inval *qi;
Suresh Siddha751cafe2009-10-02 11:01:22 -07001333 struct page *desc_page;
Suresh Siddhafe962e92008-07-10 11:16:42 -07001334
1335 if (!ecap_qis(iommu->ecap))
1336 return -ENOENT;
1337
1338 /*
1339 * queued invalidation is already setup and enabled.
1340 */
1341 if (iommu->qi)
1342 return 0;
1343
Suresh Siddhafa4b57c2009-03-16 17:05:05 -07001344 iommu->qi = kmalloc(sizeof(*qi), GFP_ATOMIC);
Suresh Siddhafe962e92008-07-10 11:16:42 -07001345 if (!iommu->qi)
1346 return -ENOMEM;
1347
1348 qi = iommu->qi;
1349
Suresh Siddha751cafe2009-10-02 11:01:22 -07001350
1351 desc_page = alloc_pages_node(iommu->node, GFP_ATOMIC | __GFP_ZERO, 0);
1352 if (!desc_page) {
Suresh Siddhafe962e92008-07-10 11:16:42 -07001353 kfree(qi);
Jiang Liub707cb02014-01-06 14:18:26 +08001354 iommu->qi = NULL;
Suresh Siddhafe962e92008-07-10 11:16:42 -07001355 return -ENOMEM;
1356 }
1357
Suresh Siddha751cafe2009-10-02 11:01:22 -07001358 qi->desc = page_address(desc_page);
1359
Hannes Reinecke37a40712013-02-06 09:50:10 +01001360 qi->desc_status = kzalloc(QI_LENGTH * sizeof(int), GFP_ATOMIC);
Suresh Siddhafe962e92008-07-10 11:16:42 -07001361 if (!qi->desc_status) {
1362 free_page((unsigned long) qi->desc);
1363 kfree(qi);
Jiang Liub707cb02014-01-06 14:18:26 +08001364 iommu->qi = NULL;
Suresh Siddhafe962e92008-07-10 11:16:42 -07001365 return -ENOMEM;
1366 }
1367
Thomas Gleixner3b8f4042011-07-19 17:02:07 +02001368 raw_spin_lock_init(&qi->q_lock);
Suresh Siddhafe962e92008-07-10 11:16:42 -07001369
Fenghua Yueb4a52b2009-03-27 14:22:43 -07001370 __dmar_enable_qi(iommu);
Suresh Siddhafe962e92008-07-10 11:16:42 -07001371
1372 return 0;
1373}
Suresh Siddha0ac24912009-03-16 17:04:54 -07001374
1375/* iommu interrupt handling. Most stuff are MSI-like. */
1376
Suresh Siddha9d783ba2009-03-16 17:04:55 -07001377enum faulttype {
1378 DMA_REMAP,
1379 INTR_REMAP,
1380 UNKNOWN,
1381};
1382
1383static const char *dma_remap_fault_reasons[] =
Suresh Siddha0ac24912009-03-16 17:04:54 -07001384{
1385 "Software",
1386 "Present bit in root entry is clear",
1387 "Present bit in context entry is clear",
1388 "Invalid context entry",
1389 "Access beyond MGAW",
1390 "PTE Write access is not set",
1391 "PTE Read access is not set",
1392 "Next page table ptr is invalid",
1393 "Root table address invalid",
1394 "Context table ptr is invalid",
1395 "non-zero reserved fields in RTP",
1396 "non-zero reserved fields in CTP",
1397 "non-zero reserved fields in PTE",
Li, Zhen-Hua4ecccd92013-03-06 10:43:17 +08001398 "PCE for translation request specifies blocking",
Suresh Siddha0ac24912009-03-16 17:04:54 -07001399};
Suresh Siddha9d783ba2009-03-16 17:04:55 -07001400
Suresh Siddha95a02e92012-03-30 11:47:07 -07001401static const char *irq_remap_fault_reasons[] =
Suresh Siddha9d783ba2009-03-16 17:04:55 -07001402{
1403 "Detected reserved fields in the decoded interrupt-remapped request",
1404 "Interrupt index exceeded the interrupt-remapping table size",
1405 "Present field in the IRTE entry is clear",
1406 "Error accessing interrupt-remapping table pointed by IRTA_REG",
1407 "Detected reserved fields in the IRTE entry",
1408 "Blocked a compatibility format interrupt request",
1409 "Blocked an interrupt request due to source-id verification failure",
1410};
1411
Rashika Kheria21004dc2013-12-18 12:01:46 +05301412static const char *dmar_get_fault_reason(u8 fault_reason, int *fault_type)
Suresh Siddha0ac24912009-03-16 17:04:54 -07001413{
Dan Carpenterfefe1ed2012-05-13 20:09:38 +03001414 if (fault_reason >= 0x20 && (fault_reason - 0x20 <
1415 ARRAY_SIZE(irq_remap_fault_reasons))) {
Suresh Siddha9d783ba2009-03-16 17:04:55 -07001416 *fault_type = INTR_REMAP;
Suresh Siddha95a02e92012-03-30 11:47:07 -07001417 return irq_remap_fault_reasons[fault_reason - 0x20];
Suresh Siddha9d783ba2009-03-16 17:04:55 -07001418 } else if (fault_reason < ARRAY_SIZE(dma_remap_fault_reasons)) {
1419 *fault_type = DMA_REMAP;
1420 return dma_remap_fault_reasons[fault_reason];
1421 } else {
1422 *fault_type = UNKNOWN;
Suresh Siddha0ac24912009-03-16 17:04:54 -07001423 return "Unknown";
Suresh Siddha9d783ba2009-03-16 17:04:55 -07001424 }
Suresh Siddha0ac24912009-03-16 17:04:54 -07001425}
1426
Thomas Gleixner5c2837f2010-09-28 17:15:11 +02001427void dmar_msi_unmask(struct irq_data *data)
Suresh Siddha0ac24912009-03-16 17:04:54 -07001428{
Thomas Gleixnerdced35a2011-03-28 17:49:12 +02001429 struct intel_iommu *iommu = irq_data_get_irq_handler_data(data);
Suresh Siddha0ac24912009-03-16 17:04:54 -07001430 unsigned long flag;
1431
1432 /* unmask it */
Thomas Gleixner1f5b3c32011-07-19 16:19:51 +02001433 raw_spin_lock_irqsave(&iommu->register_lock, flag);
Suresh Siddha0ac24912009-03-16 17:04:54 -07001434 writel(0, iommu->reg + DMAR_FECTL_REG);
1435 /* Read a reg to force flush the post write */
1436 readl(iommu->reg + DMAR_FECTL_REG);
Thomas Gleixner1f5b3c32011-07-19 16:19:51 +02001437 raw_spin_unlock_irqrestore(&iommu->register_lock, flag);
Suresh Siddha0ac24912009-03-16 17:04:54 -07001438}
1439
Thomas Gleixner5c2837f2010-09-28 17:15:11 +02001440void dmar_msi_mask(struct irq_data *data)
Suresh Siddha0ac24912009-03-16 17:04:54 -07001441{
1442 unsigned long flag;
Thomas Gleixnerdced35a2011-03-28 17:49:12 +02001443 struct intel_iommu *iommu = irq_data_get_irq_handler_data(data);
Suresh Siddha0ac24912009-03-16 17:04:54 -07001444
1445 /* mask it */
Thomas Gleixner1f5b3c32011-07-19 16:19:51 +02001446 raw_spin_lock_irqsave(&iommu->register_lock, flag);
Suresh Siddha0ac24912009-03-16 17:04:54 -07001447 writel(DMA_FECTL_IM, iommu->reg + DMAR_FECTL_REG);
1448 /* Read a reg to force flush the post write */
1449 readl(iommu->reg + DMAR_FECTL_REG);
Thomas Gleixner1f5b3c32011-07-19 16:19:51 +02001450 raw_spin_unlock_irqrestore(&iommu->register_lock, flag);
Suresh Siddha0ac24912009-03-16 17:04:54 -07001451}
1452
1453void dmar_msi_write(int irq, struct msi_msg *msg)
1454{
Thomas Gleixnerdced35a2011-03-28 17:49:12 +02001455 struct intel_iommu *iommu = irq_get_handler_data(irq);
Suresh Siddha0ac24912009-03-16 17:04:54 -07001456 unsigned long flag;
1457
Thomas Gleixner1f5b3c32011-07-19 16:19:51 +02001458 raw_spin_lock_irqsave(&iommu->register_lock, flag);
Suresh Siddha0ac24912009-03-16 17:04:54 -07001459 writel(msg->data, iommu->reg + DMAR_FEDATA_REG);
1460 writel(msg->address_lo, iommu->reg + DMAR_FEADDR_REG);
1461 writel(msg->address_hi, iommu->reg + DMAR_FEUADDR_REG);
Thomas Gleixner1f5b3c32011-07-19 16:19:51 +02001462 raw_spin_unlock_irqrestore(&iommu->register_lock, flag);
Suresh Siddha0ac24912009-03-16 17:04:54 -07001463}
1464
1465void dmar_msi_read(int irq, struct msi_msg *msg)
1466{
Thomas Gleixnerdced35a2011-03-28 17:49:12 +02001467 struct intel_iommu *iommu = irq_get_handler_data(irq);
Suresh Siddha0ac24912009-03-16 17:04:54 -07001468 unsigned long flag;
1469
Thomas Gleixner1f5b3c32011-07-19 16:19:51 +02001470 raw_spin_lock_irqsave(&iommu->register_lock, flag);
Suresh Siddha0ac24912009-03-16 17:04:54 -07001471 msg->data = readl(iommu->reg + DMAR_FEDATA_REG);
1472 msg->address_lo = readl(iommu->reg + DMAR_FEADDR_REG);
1473 msg->address_hi = readl(iommu->reg + DMAR_FEUADDR_REG);
Thomas Gleixner1f5b3c32011-07-19 16:19:51 +02001474 raw_spin_unlock_irqrestore(&iommu->register_lock, flag);
Suresh Siddha0ac24912009-03-16 17:04:54 -07001475}
1476
1477static int dmar_fault_do_one(struct intel_iommu *iommu, int type,
1478 u8 fault_reason, u16 source_id, unsigned long long addr)
1479{
1480 const char *reason;
Suresh Siddha9d783ba2009-03-16 17:04:55 -07001481 int fault_type;
Suresh Siddha0ac24912009-03-16 17:04:54 -07001482
Suresh Siddha9d783ba2009-03-16 17:04:55 -07001483 reason = dmar_get_fault_reason(fault_reason, &fault_type);
Suresh Siddha0ac24912009-03-16 17:04:54 -07001484
Suresh Siddha9d783ba2009-03-16 17:04:55 -07001485 if (fault_type == INTR_REMAP)
Donald Dutilebf947fcb2012-06-04 17:29:01 -04001486 pr_err("INTR-REMAP: Request device [[%02x:%02x.%d] "
Suresh Siddha9d783ba2009-03-16 17:04:55 -07001487 "fault index %llx\n"
1488 "INTR-REMAP:[fault reason %02d] %s\n",
1489 (source_id >> 8), PCI_SLOT(source_id & 0xFF),
1490 PCI_FUNC(source_id & 0xFF), addr >> 48,
1491 fault_reason, reason);
1492 else
Donald Dutilebf947fcb2012-06-04 17:29:01 -04001493 pr_err("DMAR:[%s] Request device [%02x:%02x.%d] "
Suresh Siddha9d783ba2009-03-16 17:04:55 -07001494 "fault addr %llx \n"
1495 "DMAR:[fault reason %02d] %s\n",
1496 (type ? "DMA Read" : "DMA Write"),
1497 (source_id >> 8), PCI_SLOT(source_id & 0xFF),
1498 PCI_FUNC(source_id & 0xFF), addr, fault_reason, reason);
Suresh Siddha0ac24912009-03-16 17:04:54 -07001499 return 0;
1500}
1501
1502#define PRIMARY_FAULT_REG_LEN (16)
Suresh Siddha1531a6a2009-03-16 17:04:57 -07001503irqreturn_t dmar_fault(int irq, void *dev_id)
Suresh Siddha0ac24912009-03-16 17:04:54 -07001504{
1505 struct intel_iommu *iommu = dev_id;
1506 int reg, fault_index;
1507 u32 fault_status;
1508 unsigned long flag;
1509
Thomas Gleixner1f5b3c32011-07-19 16:19:51 +02001510 raw_spin_lock_irqsave(&iommu->register_lock, flag);
Suresh Siddha0ac24912009-03-16 17:04:54 -07001511 fault_status = readl(iommu->reg + DMAR_FSTS_REG);
Suresh Siddha9d783ba2009-03-16 17:04:55 -07001512 if (fault_status)
Donald Dutilebf947fcb2012-06-04 17:29:01 -04001513 pr_err("DRHD: handling fault status reg %x\n", fault_status);
Suresh Siddha0ac24912009-03-16 17:04:54 -07001514
1515 /* TBD: ignore advanced fault log currently */
1516 if (!(fault_status & DMA_FSTS_PPF))
Li, Zhen-Huabd5cdad2013-03-25 16:20:52 +08001517 goto unlock_exit;
Suresh Siddha0ac24912009-03-16 17:04:54 -07001518
1519 fault_index = dma_fsts_fault_record_index(fault_status);
1520 reg = cap_fault_reg_offset(iommu->cap);
1521 while (1) {
1522 u8 fault_reason;
1523 u16 source_id;
1524 u64 guest_addr;
1525 int type;
1526 u32 data;
1527
1528 /* highest 32 bits */
1529 data = readl(iommu->reg + reg +
1530 fault_index * PRIMARY_FAULT_REG_LEN + 12);
1531 if (!(data & DMA_FRCD_F))
1532 break;
1533
1534 fault_reason = dma_frcd_fault_reason(data);
1535 type = dma_frcd_type(data);
1536
1537 data = readl(iommu->reg + reg +
1538 fault_index * PRIMARY_FAULT_REG_LEN + 8);
1539 source_id = dma_frcd_source_id(data);
1540
1541 guest_addr = dmar_readq(iommu->reg + reg +
1542 fault_index * PRIMARY_FAULT_REG_LEN);
1543 guest_addr = dma_frcd_page_addr(guest_addr);
1544 /* clear the fault */
1545 writel(DMA_FRCD_F, iommu->reg + reg +
1546 fault_index * PRIMARY_FAULT_REG_LEN + 12);
1547
Thomas Gleixner1f5b3c32011-07-19 16:19:51 +02001548 raw_spin_unlock_irqrestore(&iommu->register_lock, flag);
Suresh Siddha0ac24912009-03-16 17:04:54 -07001549
1550 dmar_fault_do_one(iommu, type, fault_reason,
1551 source_id, guest_addr);
1552
1553 fault_index++;
Troy Heber8211a7b2009-08-19 15:26:11 -06001554 if (fault_index >= cap_num_fault_regs(iommu->cap))
Suresh Siddha0ac24912009-03-16 17:04:54 -07001555 fault_index = 0;
Thomas Gleixner1f5b3c32011-07-19 16:19:51 +02001556 raw_spin_lock_irqsave(&iommu->register_lock, flag);
Suresh Siddha0ac24912009-03-16 17:04:54 -07001557 }
Suresh Siddha0ac24912009-03-16 17:04:54 -07001558
Li, Zhen-Huabd5cdad2013-03-25 16:20:52 +08001559 writel(DMA_FSTS_PFO | DMA_FSTS_PPF, iommu->reg + DMAR_FSTS_REG);
1560
1561unlock_exit:
Thomas Gleixner1f5b3c32011-07-19 16:19:51 +02001562 raw_spin_unlock_irqrestore(&iommu->register_lock, flag);
Suresh Siddha0ac24912009-03-16 17:04:54 -07001563 return IRQ_HANDLED;
1564}
1565
1566int dmar_set_interrupt(struct intel_iommu *iommu)
1567{
1568 int irq, ret;
1569
Suresh Siddha9d783ba2009-03-16 17:04:55 -07001570 /*
1571 * Check if the fault interrupt is already initialized.
1572 */
1573 if (iommu->irq)
1574 return 0;
1575
Thomas Gleixnera553b142014-05-07 15:44:11 +00001576 irq = dmar_alloc_hwirq();
Thomas Gleixneraa5125a2014-05-07 15:44:10 +00001577 if (irq <= 0) {
Donald Dutilebf947fcb2012-06-04 17:29:01 -04001578 pr_err("IOMMU: no free vectors\n");
Suresh Siddha0ac24912009-03-16 17:04:54 -07001579 return -EINVAL;
1580 }
1581
Thomas Gleixnerdced35a2011-03-28 17:49:12 +02001582 irq_set_handler_data(irq, iommu);
Suresh Siddha0ac24912009-03-16 17:04:54 -07001583 iommu->irq = irq;
1584
1585 ret = arch_setup_dmar_msi(irq);
1586 if (ret) {
Thomas Gleixnerdced35a2011-03-28 17:49:12 +02001587 irq_set_handler_data(irq, NULL);
Suresh Siddha0ac24912009-03-16 17:04:54 -07001588 iommu->irq = 0;
Thomas Gleixnera553b142014-05-07 15:44:11 +00001589 dmar_free_hwirq(irq);
Chris Wrightdd726432009-05-13 15:55:52 -07001590 return ret;
Suresh Siddha0ac24912009-03-16 17:04:54 -07001591 }
1592
Thomas Gleixner477694e2011-07-19 16:25:42 +02001593 ret = request_irq(irq, dmar_fault, IRQF_NO_THREAD, iommu->name, iommu);
Suresh Siddha0ac24912009-03-16 17:04:54 -07001594 if (ret)
Donald Dutilebf947fcb2012-06-04 17:29:01 -04001595 pr_err("IOMMU: can't request irq\n");
Suresh Siddha0ac24912009-03-16 17:04:54 -07001596 return ret;
1597}
Suresh Siddha9d783ba2009-03-16 17:04:55 -07001598
1599int __init enable_drhd_fault_handling(void)
1600{
1601 struct dmar_drhd_unit *drhd;
Jiang Liu7c919772014-01-06 14:18:18 +08001602 struct intel_iommu *iommu;
Suresh Siddha9d783ba2009-03-16 17:04:55 -07001603
1604 /*
1605 * Enable fault control interrupt.
1606 */
Jiang Liu7c919772014-01-06 14:18:18 +08001607 for_each_iommu(iommu, drhd) {
Li, Zhen-Huabd5cdad2013-03-25 16:20:52 +08001608 u32 fault_status;
Jiang Liu7c919772014-01-06 14:18:18 +08001609 int ret = dmar_set_interrupt(iommu);
Suresh Siddha9d783ba2009-03-16 17:04:55 -07001610
1611 if (ret) {
Donald Dutilee9071b02012-06-08 17:13:11 -04001612 pr_err("DRHD %Lx: failed to enable fault, interrupt, ret %d\n",
Suresh Siddha9d783ba2009-03-16 17:04:55 -07001613 (unsigned long long)drhd->reg_base_addr, ret);
1614 return -1;
1615 }
Suresh Siddha7f99d942010-11-30 22:22:29 -08001616
1617 /*
1618 * Clear any previous faults.
1619 */
1620 dmar_fault(iommu->irq, iommu);
Li, Zhen-Huabd5cdad2013-03-25 16:20:52 +08001621 fault_status = readl(iommu->reg + DMAR_FSTS_REG);
1622 writel(fault_status, iommu->reg + DMAR_FSTS_REG);
Suresh Siddha9d783ba2009-03-16 17:04:55 -07001623 }
1624
1625 return 0;
1626}
Fenghua Yueb4a52b2009-03-27 14:22:43 -07001627
1628/*
1629 * Re-enable Queued Invalidation interface.
1630 */
1631int dmar_reenable_qi(struct intel_iommu *iommu)
1632{
1633 if (!ecap_qis(iommu->ecap))
1634 return -ENOENT;
1635
1636 if (!iommu->qi)
1637 return -ENOENT;
1638
1639 /*
1640 * First disable queued invalidation.
1641 */
1642 dmar_disable_qi(iommu);
1643 /*
1644 * Then enable queued invalidation again. Since there is no pending
1645 * invalidation requests now, it's safe to re-enable queued
1646 * invalidation.
1647 */
1648 __dmar_enable_qi(iommu);
1649
1650 return 0;
1651}
Youquan Song074835f2009-09-09 12:05:39 -04001652
1653/*
1654 * Check interrupt remapping support in DMAR table description.
1655 */
Luck, Tony0b8973a2009-12-16 22:59:29 +00001656int __init dmar_ir_support(void)
Youquan Song074835f2009-09-09 12:05:39 -04001657{
1658 struct acpi_table_dmar *dmar;
1659 dmar = (struct acpi_table_dmar *)dmar_tbl;
Arnaud Patard4f506e02010-03-25 18:02:58 +00001660 if (!dmar)
1661 return 0;
Youquan Song074835f2009-09-09 12:05:39 -04001662 return dmar->flags & 0x1;
1663}
Jiang Liu694835d2014-01-06 14:18:16 +08001664
Jiang Liua868e6b2014-01-06 14:18:20 +08001665static int __init dmar_free_unused_resources(void)
1666{
1667 struct dmar_drhd_unit *dmaru, *dmaru_n;
1668
1669 /* DMAR units are in use */
1670 if (irq_remapping_enabled || intel_iommu_enabled)
1671 return 0;
1672
Jiang Liu2e455282014-02-19 14:07:36 +08001673 if (dmar_dev_scope_status != 1 && !list_empty(&dmar_drhd_units))
1674 bus_unregister_notifier(&pci_bus_type, &dmar_pci_bus_nb);
Jiang Liu59ce0512014-02-19 14:07:35 +08001675
Jiang Liu3a5670e2014-02-19 14:07:33 +08001676 down_write(&dmar_global_lock);
Jiang Liua868e6b2014-01-06 14:18:20 +08001677 list_for_each_entry_safe(dmaru, dmaru_n, &dmar_drhd_units, list) {
1678 list_del(&dmaru->list);
1679 dmar_free_drhd(dmaru);
1680 }
Jiang Liu3a5670e2014-02-19 14:07:33 +08001681 up_write(&dmar_global_lock);
Jiang Liua868e6b2014-01-06 14:18:20 +08001682
1683 return 0;
1684}
1685
1686late_initcall(dmar_free_unused_resources);
Konrad Rzeszutek Wilk4db77ff2010-08-26 13:58:04 -04001687IOMMU_INIT_POST(detect_intel_iommu);