2 * Copyright (c) 2006, Intel Corporation.
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.
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
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.
17 <<<<<<< HEAD:drivers/pci/dmar.c
18 * Copyright (C) Ashok Raj <ashok.raj@intel.com>
19 * Copyright (C) Shaohua Li <shaohua.li@intel.com>
20 * Copyright (C) Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
22 * Copyright (C) 2006-2008 Intel Corporation
23 * Author: Ashok Raj <ashok.raj@intel.com>
24 * Author: Shaohua Li <shaohua.li@intel.com>
25 * Author: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
26 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/pci/dmar.c
28 <<<<<<< HEAD:drivers/pci/dmar.c
29 * This file implements early detection/parsing of DMA Remapping Devices
31 * This file implements early detection/parsing of DMA Remapping Devices
32 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/pci/dmar.c
33 * reported to OS through BIOS via DMA remapping reporting (DMAR) ACPI
37 #include <linux/pci.h>
38 #include <linux/dmar.h>
40 #include "intel-iommu.h"
43 #define PREFIX "DMAR:"
45 /* No locks are needed as DMA remapping hardware unit
46 * list is constructed at boot time and hotplug of
47 * these units are not supported by the architecture.
49 LIST_HEAD(dmar_drhd_units
);
50 LIST_HEAD(dmar_rmrr_units
);
52 static struct acpi_table_header
* __initdata dmar_tbl
;
54 static void __init
dmar_register_drhd_unit(struct dmar_drhd_unit
*drhd
)
57 * add INCLUDE_ALL at the tail, so scan the list will find it at
60 if (drhd
->include_all
)
61 list_add_tail(&drhd
->list
, &dmar_drhd_units
);
63 list_add(&drhd
->list
, &dmar_drhd_units
);
66 static void __init
dmar_register_rmrr_unit(struct dmar_rmrr_unit
*rmrr
)
68 list_add(&rmrr
->list
, &dmar_rmrr_units
);
71 static int __init
dmar_parse_one_dev_scope(struct acpi_dmar_device_scope
*scope
,
72 struct pci_dev
**dev
, u16 segment
)
75 struct pci_dev
*pdev
= NULL
;
76 struct acpi_dmar_pci_path
*path
;
79 bus
= pci_find_bus(segment
, scope
->bus
);
80 path
= (struct acpi_dmar_pci_path
*)(scope
+ 1);
81 count
= (scope
->length
- sizeof(struct acpi_dmar_device_scope
))
82 / sizeof(struct acpi_dmar_pci_path
);
88 * Some BIOSes list non-exist devices in DMAR table, just
93 PREFIX
"Device scope bus [%d] not found\n",
97 pdev
= pci_get_slot(bus
, PCI_DEVFN(path
->dev
, path
->fn
));
99 printk(KERN_WARNING PREFIX
100 "Device scope device [%04x:%02x:%02x.%02x] not found\n",
101 segment
, bus
->number
, path
->dev
, path
->fn
);
106 bus
= pdev
->subordinate
;
109 printk(KERN_WARNING PREFIX
110 "Device scope device [%04x:%02x:%02x.%02x] not found\n",
111 segment
, scope
->bus
, path
->dev
, path
->fn
);
115 if ((scope
->entry_type
== ACPI_DMAR_SCOPE_TYPE_ENDPOINT
&& \
116 pdev
->subordinate
) || (scope
->entry_type
== \
117 ACPI_DMAR_SCOPE_TYPE_BRIDGE
&& !pdev
->subordinate
)) {
119 printk(KERN_WARNING PREFIX
120 "Device scope type does not match for %s\n",
128 static int __init
dmar_parse_dev_scope(void *start
, void *end
, int *cnt
,
129 struct pci_dev
***devices
, u16 segment
)
131 struct acpi_dmar_device_scope
*scope
;
137 while (start
< end
) {
139 if (scope
->entry_type
== ACPI_DMAR_SCOPE_TYPE_ENDPOINT
||
140 scope
->entry_type
== ACPI_DMAR_SCOPE_TYPE_BRIDGE
)
143 printk(KERN_WARNING PREFIX
144 "Unsupported device scope\n");
145 start
+= scope
->length
;
150 *devices
= kcalloc(*cnt
, sizeof(struct pci_dev
*), GFP_KERNEL
);
156 while (start
< end
) {
158 if (scope
->entry_type
== ACPI_DMAR_SCOPE_TYPE_ENDPOINT
||
159 scope
->entry_type
== ACPI_DMAR_SCOPE_TYPE_BRIDGE
) {
160 ret
= dmar_parse_one_dev_scope(scope
,
161 &(*devices
)[index
], segment
);
168 start
+= scope
->length
;
175 * dmar_parse_one_drhd - parses exactly one DMA remapping hardware definition
176 * structure which uniquely represent one DMA remapping hardware unit
177 * present in the platform
180 dmar_parse_one_drhd(struct acpi_dmar_header
*header
)
182 struct acpi_dmar_hardware_unit
*drhd
;
183 struct dmar_drhd_unit
*dmaru
;
185 static int include_all
;
187 dmaru
= kzalloc(sizeof(*dmaru
), GFP_KERNEL
);
191 drhd
= (struct acpi_dmar_hardware_unit
*)header
;
192 dmaru
->reg_base_addr
= drhd
->address
;
193 dmaru
->include_all
= drhd
->flags
& 0x1; /* BIT0: INCLUDE_ALL */
195 if (!dmaru
->include_all
)
196 ret
= dmar_parse_dev_scope((void *)(drhd
+ 1),
197 ((void *)drhd
) + header
->length
,
198 &dmaru
->devices_cnt
, &dmaru
->devices
,
201 /* Only allow one INCLUDE_ALL */
203 printk(KERN_WARNING PREFIX
"Only one INCLUDE_ALL "
204 "device scope is allowed\n");
210 if (ret
|| (dmaru
->devices_cnt
== 0 && !dmaru
->include_all
))
213 dmar_register_drhd_unit(dmaru
);
218 dmar_parse_one_rmrr(struct acpi_dmar_header
*header
)
220 struct acpi_dmar_reserved_memory
*rmrr
;
221 struct dmar_rmrr_unit
*rmrru
;
224 rmrru
= kzalloc(sizeof(*rmrru
), GFP_KERNEL
);
228 rmrr
= (struct acpi_dmar_reserved_memory
*)header
;
229 rmrru
->base_address
= rmrr
->base_address
;
230 rmrru
->end_address
= rmrr
->end_address
;
231 ret
= dmar_parse_dev_scope((void *)(rmrr
+ 1),
232 ((void *)rmrr
) + header
->length
,
233 &rmrru
->devices_cnt
, &rmrru
->devices
, rmrr
->segment
);
235 if (ret
|| (rmrru
->devices_cnt
== 0))
238 dmar_register_rmrr_unit(rmrru
);
243 dmar_table_print_dmar_entry(struct acpi_dmar_header
*header
)
245 struct acpi_dmar_hardware_unit
*drhd
;
246 struct acpi_dmar_reserved_memory
*rmrr
;
248 switch (header
->type
) {
249 case ACPI_DMAR_TYPE_HARDWARE_UNIT
:
250 drhd
= (struct acpi_dmar_hardware_unit
*)header
;
251 printk (KERN_INFO PREFIX
252 "DRHD (flags: 0x%08x)base: 0x%016Lx\n",
253 drhd
->flags
, drhd
->address
);
255 case ACPI_DMAR_TYPE_RESERVED_MEMORY
:
256 rmrr
= (struct acpi_dmar_reserved_memory
*)header
;
258 printk (KERN_INFO PREFIX
259 "RMRR base: 0x%016Lx end: 0x%016Lx\n",
260 rmrr
->base_address
, rmrr
->end_address
);
266 * parse_dmar_table - parses the DMA reporting table
269 parse_dmar_table(void)
271 struct acpi_table_dmar
*dmar
;
272 struct acpi_dmar_header
*entry_header
;
275 dmar
= (struct acpi_table_dmar
*)dmar_tbl
;
279 if (dmar
->width
< PAGE_SHIFT_4K
- 1) {
280 printk(KERN_WARNING PREFIX
"Invalid DMAR haw\n");
284 printk (KERN_INFO PREFIX
"Host address width %d\n",
287 entry_header
= (struct acpi_dmar_header
*)(dmar
+ 1);
288 while (((unsigned long)entry_header
) <
289 (((unsigned long)dmar
) + dmar_tbl
->length
)) {
290 dmar_table_print_dmar_entry(entry_header
);
292 switch (entry_header
->type
) {
293 case ACPI_DMAR_TYPE_HARDWARE_UNIT
:
294 ret
= dmar_parse_one_drhd(entry_header
);
296 case ACPI_DMAR_TYPE_RESERVED_MEMORY
:
297 ret
= dmar_parse_one_rmrr(entry_header
);
300 printk(KERN_WARNING PREFIX
301 "Unknown DMAR structure type\n");
302 ret
= 0; /* for forward compatibility */
308 entry_header
= ((void *)entry_header
+ entry_header
->length
);
314 int __init
dmar_table_init(void)
319 ret
= parse_dmar_table();
321 printk(KERN_INFO PREFIX
"parse DMAR table failure.\n");
325 if (list_empty(&dmar_drhd_units
)) {
326 printk(KERN_INFO PREFIX
"No DMAR devices found\n");
330 if (list_empty(&dmar_rmrr_units
)) {
331 printk(KERN_INFO PREFIX
"No RMRR found\n");
339 * early_dmar_detect - checks to see if the platform supports DMAR devices
341 int __init
early_dmar_detect(void)
343 acpi_status status
= AE_OK
;
345 /* if we could find DMAR table, then there are DMAR devices */
346 status
= acpi_get_table(ACPI_SIG_DMAR
, 0,
347 (struct acpi_table_header
**)&dmar_tbl
);
349 if (ACPI_SUCCESS(status
) && !dmar_tbl
) {
350 printk (KERN_WARNING PREFIX
"Unable to map DMAR\n");
351 status
= AE_NOT_FOUND
;
354 return (ACPI_SUCCESS(status
) ? 1 : 0);