Keshavamurthy, Anil S | 10e5247 | 2007-10-21 16:41:41 -0700 | [diff] [blame] | 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 | * |
mark gross | 98bcef5 | 2008-02-23 15:23:35 -0800 | [diff] [blame] | 17 | * 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 S | 10e5247 | 2007-10-21 16:41:41 -0700 | [diff] [blame] | 21 | * |
Suresh Siddha | e61d98d | 2008-07-10 11:16:35 -0700 | [diff] [blame] | 22 | * This file implements early detection/parsing of Remapping Devices |
Keshavamurthy, Anil S | 10e5247 | 2007-10-21 16:41:41 -0700 | [diff] [blame] | 23 | * reported to OS through BIOS via DMA remapping reporting (DMAR) ACPI |
| 24 | * tables. |
Suresh Siddha | e61d98d | 2008-07-10 11:16:35 -0700 | [diff] [blame] | 25 | * |
| 26 | * These routines are used by both DMA-remapping and Interrupt-remapping |
Keshavamurthy, Anil S | 10e5247 | 2007-10-21 16:41:41 -0700 | [diff] [blame] | 27 | */ |
| 28 | |
| 29 | #include <linux/pci.h> |
| 30 | #include <linux/dmar.h> |
Fenghua Yu | 093f87d | 2007-11-21 15:07:14 -0800 | [diff] [blame] | 31 | #include "iova.h" |
David Miller | f661197 | 2008-02-06 01:36:23 -0800 | [diff] [blame] | 32 | #include "intel-iommu.h" |
Keshavamurthy, Anil S | 10e5247 | 2007-10-21 16:41:41 -0700 | [diff] [blame] | 33 | |
| 34 | #undef PREFIX |
| 35 | #define PREFIX "DMAR:" |
| 36 | |
| 37 | /* No locks are needed as DMA remapping hardware unit |
| 38 | * list is constructed at boot time and hotplug of |
| 39 | * these units are not supported by the architecture. |
| 40 | */ |
| 41 | LIST_HEAD(dmar_drhd_units); |
Keshavamurthy, Anil S | 10e5247 | 2007-10-21 16:41:41 -0700 | [diff] [blame] | 42 | |
| 43 | static struct acpi_table_header * __initdata dmar_tbl; |
| 44 | |
| 45 | static void __init dmar_register_drhd_unit(struct dmar_drhd_unit *drhd) |
| 46 | { |
| 47 | /* |
| 48 | * add INCLUDE_ALL at the tail, so scan the list will find it at |
| 49 | * the very end. |
| 50 | */ |
| 51 | if (drhd->include_all) |
| 52 | list_add_tail(&drhd->list, &dmar_drhd_units); |
| 53 | else |
| 54 | list_add(&drhd->list, &dmar_drhd_units); |
| 55 | } |
| 56 | |
Keshavamurthy, Anil S | 10e5247 | 2007-10-21 16:41:41 -0700 | [diff] [blame] | 57 | static int __init dmar_parse_one_dev_scope(struct acpi_dmar_device_scope *scope, |
| 58 | struct pci_dev **dev, u16 segment) |
| 59 | { |
| 60 | struct pci_bus *bus; |
| 61 | struct pci_dev *pdev = NULL; |
| 62 | struct acpi_dmar_pci_path *path; |
| 63 | int count; |
| 64 | |
| 65 | bus = pci_find_bus(segment, scope->bus); |
| 66 | path = (struct acpi_dmar_pci_path *)(scope + 1); |
| 67 | count = (scope->length - sizeof(struct acpi_dmar_device_scope)) |
| 68 | / sizeof(struct acpi_dmar_pci_path); |
| 69 | |
| 70 | while (count) { |
| 71 | if (pdev) |
| 72 | pci_dev_put(pdev); |
| 73 | /* |
| 74 | * Some BIOSes list non-exist devices in DMAR table, just |
| 75 | * ignore it |
| 76 | */ |
| 77 | if (!bus) { |
| 78 | printk(KERN_WARNING |
| 79 | PREFIX "Device scope bus [%d] not found\n", |
| 80 | scope->bus); |
| 81 | break; |
| 82 | } |
| 83 | pdev = pci_get_slot(bus, PCI_DEVFN(path->dev, path->fn)); |
| 84 | if (!pdev) { |
| 85 | printk(KERN_WARNING PREFIX |
| 86 | "Device scope device [%04x:%02x:%02x.%02x] not found\n", |
| 87 | segment, bus->number, path->dev, path->fn); |
| 88 | break; |
| 89 | } |
| 90 | path ++; |
| 91 | count --; |
| 92 | bus = pdev->subordinate; |
| 93 | } |
| 94 | if (!pdev) { |
| 95 | printk(KERN_WARNING PREFIX |
| 96 | "Device scope device [%04x:%02x:%02x.%02x] not found\n", |
| 97 | segment, scope->bus, path->dev, path->fn); |
| 98 | *dev = NULL; |
| 99 | return 0; |
| 100 | } |
| 101 | if ((scope->entry_type == ACPI_DMAR_SCOPE_TYPE_ENDPOINT && \ |
| 102 | pdev->subordinate) || (scope->entry_type == \ |
| 103 | ACPI_DMAR_SCOPE_TYPE_BRIDGE && !pdev->subordinate)) { |
| 104 | pci_dev_put(pdev); |
| 105 | printk(KERN_WARNING PREFIX |
| 106 | "Device scope type does not match for %s\n", |
| 107 | pci_name(pdev)); |
| 108 | return -EINVAL; |
| 109 | } |
| 110 | *dev = pdev; |
| 111 | return 0; |
| 112 | } |
| 113 | |
| 114 | static int __init dmar_parse_dev_scope(void *start, void *end, int *cnt, |
| 115 | struct pci_dev ***devices, u16 segment) |
| 116 | { |
| 117 | struct acpi_dmar_device_scope *scope; |
| 118 | void * tmp = start; |
| 119 | int index; |
| 120 | int ret; |
| 121 | |
| 122 | *cnt = 0; |
| 123 | while (start < end) { |
| 124 | scope = start; |
| 125 | if (scope->entry_type == ACPI_DMAR_SCOPE_TYPE_ENDPOINT || |
| 126 | scope->entry_type == ACPI_DMAR_SCOPE_TYPE_BRIDGE) |
| 127 | (*cnt)++; |
| 128 | else |
| 129 | printk(KERN_WARNING PREFIX |
| 130 | "Unsupported device scope\n"); |
| 131 | start += scope->length; |
| 132 | } |
| 133 | if (*cnt == 0) |
| 134 | return 0; |
| 135 | |
| 136 | *devices = kcalloc(*cnt, sizeof(struct pci_dev *), GFP_KERNEL); |
| 137 | if (!*devices) |
| 138 | return -ENOMEM; |
| 139 | |
| 140 | start = tmp; |
| 141 | index = 0; |
| 142 | while (start < end) { |
| 143 | scope = start; |
| 144 | if (scope->entry_type == ACPI_DMAR_SCOPE_TYPE_ENDPOINT || |
| 145 | scope->entry_type == ACPI_DMAR_SCOPE_TYPE_BRIDGE) { |
| 146 | ret = dmar_parse_one_dev_scope(scope, |
| 147 | &(*devices)[index], segment); |
| 148 | if (ret) { |
| 149 | kfree(*devices); |
| 150 | return ret; |
| 151 | } |
| 152 | index ++; |
| 153 | } |
| 154 | start += scope->length; |
| 155 | } |
| 156 | |
| 157 | return 0; |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * dmar_parse_one_drhd - parses exactly one DMA remapping hardware definition |
| 162 | * structure which uniquely represent one DMA remapping hardware unit |
| 163 | * present in the platform |
| 164 | */ |
| 165 | static int __init |
| 166 | dmar_parse_one_drhd(struct acpi_dmar_header *header) |
| 167 | { |
| 168 | struct acpi_dmar_hardware_unit *drhd; |
| 169 | struct dmar_drhd_unit *dmaru; |
| 170 | int ret = 0; |
Keshavamurthy, Anil S | 10e5247 | 2007-10-21 16:41:41 -0700 | [diff] [blame] | 171 | |
| 172 | dmaru = kzalloc(sizeof(*dmaru), GFP_KERNEL); |
| 173 | if (!dmaru) |
| 174 | return -ENOMEM; |
| 175 | |
Suresh Siddha | 1886e8a | 2008-07-10 11:16:37 -0700 | [diff] [blame] | 176 | dmaru->hdr = header; |
Keshavamurthy, Anil S | 10e5247 | 2007-10-21 16:41:41 -0700 | [diff] [blame] | 177 | drhd = (struct acpi_dmar_hardware_unit *)header; |
| 178 | dmaru->reg_base_addr = drhd->address; |
| 179 | dmaru->include_all = drhd->flags & 0x1; /* BIT0: INCLUDE_ALL */ |
| 180 | |
Suresh Siddha | 1886e8a | 2008-07-10 11:16:37 -0700 | [diff] [blame] | 181 | ret = alloc_iommu(dmaru); |
| 182 | if (ret) { |
| 183 | kfree(dmaru); |
| 184 | return ret; |
| 185 | } |
| 186 | dmar_register_drhd_unit(dmaru); |
| 187 | return 0; |
| 188 | } |
| 189 | |
| 190 | static int __init |
| 191 | dmar_parse_dev(struct dmar_drhd_unit *dmaru) |
| 192 | { |
| 193 | struct acpi_dmar_hardware_unit *drhd; |
| 194 | static int include_all; |
| 195 | int ret; |
| 196 | |
| 197 | drhd = (struct acpi_dmar_hardware_unit *) dmaru->hdr; |
| 198 | |
Keshavamurthy, Anil S | 10e5247 | 2007-10-21 16:41:41 -0700 | [diff] [blame] | 199 | if (!dmaru->include_all) |
| 200 | ret = dmar_parse_dev_scope((void *)(drhd + 1), |
Suresh Siddha | 1886e8a | 2008-07-10 11:16:37 -0700 | [diff] [blame] | 201 | ((void *)drhd) + drhd->header.length, |
Keshavamurthy, Anil S | 10e5247 | 2007-10-21 16:41:41 -0700 | [diff] [blame] | 202 | &dmaru->devices_cnt, &dmaru->devices, |
| 203 | drhd->segment); |
| 204 | else { |
| 205 | /* Only allow one INCLUDE_ALL */ |
| 206 | if (include_all) { |
| 207 | printk(KERN_WARNING PREFIX "Only one INCLUDE_ALL " |
| 208 | "device scope is allowed\n"); |
| 209 | ret = -EINVAL; |
| 210 | } |
| 211 | include_all = 1; |
| 212 | } |
| 213 | |
Suresh Siddha | 1886e8a | 2008-07-10 11:16:37 -0700 | [diff] [blame] | 214 | if (ret || (dmaru->devices_cnt == 0 && !dmaru->include_all)) { |
| 215 | list_del(&dmaru->list); |
Keshavamurthy, Anil S | 10e5247 | 2007-10-21 16:41:41 -0700 | [diff] [blame] | 216 | kfree(dmaru); |
Suresh Siddha | 1886e8a | 2008-07-10 11:16:37 -0700 | [diff] [blame] | 217 | } |
Keshavamurthy, Anil S | 10e5247 | 2007-10-21 16:41:41 -0700 | [diff] [blame] | 218 | return ret; |
| 219 | } |
| 220 | |
Suresh Siddha | aaa9d1d | 2008-07-10 11:16:38 -0700 | [diff] [blame] | 221 | #ifdef CONFIG_DMAR |
| 222 | LIST_HEAD(dmar_rmrr_units); |
| 223 | |
| 224 | static void __init dmar_register_rmrr_unit(struct dmar_rmrr_unit *rmrr) |
| 225 | { |
| 226 | list_add(&rmrr->list, &dmar_rmrr_units); |
| 227 | } |
| 228 | |
| 229 | |
Keshavamurthy, Anil S | 10e5247 | 2007-10-21 16:41:41 -0700 | [diff] [blame] | 230 | static int __init |
| 231 | dmar_parse_one_rmrr(struct acpi_dmar_header *header) |
| 232 | { |
| 233 | struct acpi_dmar_reserved_memory *rmrr; |
| 234 | struct dmar_rmrr_unit *rmrru; |
Keshavamurthy, Anil S | 10e5247 | 2007-10-21 16:41:41 -0700 | [diff] [blame] | 235 | |
| 236 | rmrru = kzalloc(sizeof(*rmrru), GFP_KERNEL); |
| 237 | if (!rmrru) |
| 238 | return -ENOMEM; |
| 239 | |
Suresh Siddha | 1886e8a | 2008-07-10 11:16:37 -0700 | [diff] [blame] | 240 | rmrru->hdr = header; |
Keshavamurthy, Anil S | 10e5247 | 2007-10-21 16:41:41 -0700 | [diff] [blame] | 241 | rmrr = (struct acpi_dmar_reserved_memory *)header; |
| 242 | rmrru->base_address = rmrr->base_address; |
| 243 | rmrru->end_address = rmrr->end_address; |
Suresh Siddha | 1886e8a | 2008-07-10 11:16:37 -0700 | [diff] [blame] | 244 | |
| 245 | dmar_register_rmrr_unit(rmrru); |
| 246 | return 0; |
| 247 | } |
| 248 | |
| 249 | static int __init |
| 250 | rmrr_parse_dev(struct dmar_rmrr_unit *rmrru) |
| 251 | { |
| 252 | struct acpi_dmar_reserved_memory *rmrr; |
| 253 | int ret; |
| 254 | |
| 255 | rmrr = (struct acpi_dmar_reserved_memory *) rmrru->hdr; |
Keshavamurthy, Anil S | 10e5247 | 2007-10-21 16:41:41 -0700 | [diff] [blame] | 256 | ret = dmar_parse_dev_scope((void *)(rmrr + 1), |
Suresh Siddha | 1886e8a | 2008-07-10 11:16:37 -0700 | [diff] [blame] | 257 | ((void *)rmrr) + rmrr->header.length, |
Keshavamurthy, Anil S | 10e5247 | 2007-10-21 16:41:41 -0700 | [diff] [blame] | 258 | &rmrru->devices_cnt, &rmrru->devices, rmrr->segment); |
| 259 | |
Suresh Siddha | 1886e8a | 2008-07-10 11:16:37 -0700 | [diff] [blame] | 260 | if (ret || (rmrru->devices_cnt == 0)) { |
| 261 | list_del(&rmrru->list); |
Keshavamurthy, Anil S | 10e5247 | 2007-10-21 16:41:41 -0700 | [diff] [blame] | 262 | kfree(rmrru); |
Suresh Siddha | 1886e8a | 2008-07-10 11:16:37 -0700 | [diff] [blame] | 263 | } |
Keshavamurthy, Anil S | 10e5247 | 2007-10-21 16:41:41 -0700 | [diff] [blame] | 264 | return ret; |
| 265 | } |
Suresh Siddha | aaa9d1d | 2008-07-10 11:16:38 -0700 | [diff] [blame] | 266 | #endif |
Keshavamurthy, Anil S | 10e5247 | 2007-10-21 16:41:41 -0700 | [diff] [blame] | 267 | |
| 268 | static void __init |
| 269 | dmar_table_print_dmar_entry(struct acpi_dmar_header *header) |
| 270 | { |
| 271 | struct acpi_dmar_hardware_unit *drhd; |
| 272 | struct acpi_dmar_reserved_memory *rmrr; |
| 273 | |
| 274 | switch (header->type) { |
| 275 | case ACPI_DMAR_TYPE_HARDWARE_UNIT: |
| 276 | drhd = (struct acpi_dmar_hardware_unit *)header; |
| 277 | printk (KERN_INFO PREFIX |
| 278 | "DRHD (flags: 0x%08x)base: 0x%016Lx\n", |
| 279 | drhd->flags, drhd->address); |
| 280 | break; |
| 281 | case ACPI_DMAR_TYPE_RESERVED_MEMORY: |
| 282 | rmrr = (struct acpi_dmar_reserved_memory *)header; |
| 283 | |
| 284 | printk (KERN_INFO PREFIX |
| 285 | "RMRR base: 0x%016Lx end: 0x%016Lx\n", |
| 286 | rmrr->base_address, rmrr->end_address); |
| 287 | break; |
| 288 | } |
| 289 | } |
| 290 | |
Suresh Siddha | aaa9d1d | 2008-07-10 11:16:38 -0700 | [diff] [blame] | 291 | |
Keshavamurthy, Anil S | 10e5247 | 2007-10-21 16:41:41 -0700 | [diff] [blame] | 292 | /** |
| 293 | * parse_dmar_table - parses the DMA reporting table |
| 294 | */ |
| 295 | static int __init |
| 296 | parse_dmar_table(void) |
| 297 | { |
| 298 | struct acpi_table_dmar *dmar; |
| 299 | struct acpi_dmar_header *entry_header; |
| 300 | int ret = 0; |
| 301 | |
| 302 | dmar = (struct acpi_table_dmar *)dmar_tbl; |
| 303 | if (!dmar) |
| 304 | return -ENODEV; |
| 305 | |
Fenghua Yu | 093f87d | 2007-11-21 15:07:14 -0800 | [diff] [blame] | 306 | if (dmar->width < PAGE_SHIFT_4K - 1) { |
| 307 | printk(KERN_WARNING PREFIX "Invalid DMAR haw\n"); |
Keshavamurthy, Anil S | 10e5247 | 2007-10-21 16:41:41 -0700 | [diff] [blame] | 308 | return -EINVAL; |
| 309 | } |
| 310 | |
| 311 | printk (KERN_INFO PREFIX "Host address width %d\n", |
| 312 | dmar->width + 1); |
| 313 | |
| 314 | entry_header = (struct acpi_dmar_header *)(dmar + 1); |
| 315 | while (((unsigned long)entry_header) < |
| 316 | (((unsigned long)dmar) + dmar_tbl->length)) { |
| 317 | dmar_table_print_dmar_entry(entry_header); |
| 318 | |
| 319 | switch (entry_header->type) { |
| 320 | case ACPI_DMAR_TYPE_HARDWARE_UNIT: |
| 321 | ret = dmar_parse_one_drhd(entry_header); |
| 322 | break; |
| 323 | case ACPI_DMAR_TYPE_RESERVED_MEMORY: |
Suresh Siddha | aaa9d1d | 2008-07-10 11:16:38 -0700 | [diff] [blame] | 324 | #ifdef CONFIG_DMAR |
Keshavamurthy, Anil S | 10e5247 | 2007-10-21 16:41:41 -0700 | [diff] [blame] | 325 | ret = dmar_parse_one_rmrr(entry_header); |
Suresh Siddha | aaa9d1d | 2008-07-10 11:16:38 -0700 | [diff] [blame] | 326 | #endif |
Keshavamurthy, Anil S | 10e5247 | 2007-10-21 16:41:41 -0700 | [diff] [blame] | 327 | break; |
| 328 | default: |
| 329 | printk(KERN_WARNING PREFIX |
| 330 | "Unknown DMAR structure type\n"); |
| 331 | ret = 0; /* for forward compatibility */ |
| 332 | break; |
| 333 | } |
| 334 | if (ret) |
| 335 | break; |
| 336 | |
| 337 | entry_header = ((void *)entry_header + entry_header->length); |
| 338 | } |
| 339 | return ret; |
| 340 | } |
| 341 | |
Suresh Siddha | e61d98d | 2008-07-10 11:16:35 -0700 | [diff] [blame] | 342 | int dmar_pci_device_match(struct pci_dev *devices[], int cnt, |
| 343 | struct pci_dev *dev) |
| 344 | { |
| 345 | int index; |
| 346 | |
| 347 | while (dev) { |
| 348 | for (index = 0; index < cnt; index++) |
| 349 | if (dev == devices[index]) |
| 350 | return 1; |
| 351 | |
| 352 | /* Check our parent */ |
| 353 | dev = dev->bus->self; |
| 354 | } |
| 355 | |
| 356 | return 0; |
| 357 | } |
| 358 | |
| 359 | struct dmar_drhd_unit * |
| 360 | dmar_find_matched_drhd_unit(struct pci_dev *dev) |
| 361 | { |
| 362 | struct dmar_drhd_unit *drhd = NULL; |
| 363 | |
| 364 | list_for_each_entry(drhd, &dmar_drhd_units, list) { |
| 365 | if (drhd->include_all || dmar_pci_device_match(drhd->devices, |
| 366 | drhd->devices_cnt, dev)) |
| 367 | return drhd; |
| 368 | } |
| 369 | |
| 370 | return NULL; |
| 371 | } |
| 372 | |
Suresh Siddha | 1886e8a | 2008-07-10 11:16:37 -0700 | [diff] [blame] | 373 | int __init dmar_dev_scope_init(void) |
| 374 | { |
| 375 | struct dmar_drhd_unit *drhd; |
Suresh Siddha | 1886e8a | 2008-07-10 11:16:37 -0700 | [diff] [blame] | 376 | int ret = -ENODEV; |
| 377 | |
| 378 | for_each_drhd_unit(drhd) { |
| 379 | ret = dmar_parse_dev(drhd); |
| 380 | if (ret) |
| 381 | return ret; |
| 382 | } |
| 383 | |
Suresh Siddha | aaa9d1d | 2008-07-10 11:16:38 -0700 | [diff] [blame] | 384 | #ifdef CONFIG_DMAR |
| 385 | { |
| 386 | struct dmar_rmrr_unit *rmrr; |
| 387 | for_each_rmrr_units(rmrr) { |
| 388 | ret = rmrr_parse_dev(rmrr); |
| 389 | if (ret) |
| 390 | return ret; |
| 391 | } |
Suresh Siddha | 1886e8a | 2008-07-10 11:16:37 -0700 | [diff] [blame] | 392 | } |
Suresh Siddha | aaa9d1d | 2008-07-10 11:16:38 -0700 | [diff] [blame] | 393 | #endif |
Suresh Siddha | 1886e8a | 2008-07-10 11:16:37 -0700 | [diff] [blame] | 394 | |
| 395 | return ret; |
| 396 | } |
| 397 | |
Keshavamurthy, Anil S | 10e5247 | 2007-10-21 16:41:41 -0700 | [diff] [blame] | 398 | |
| 399 | int __init dmar_table_init(void) |
| 400 | { |
Suresh Siddha | 1886e8a | 2008-07-10 11:16:37 -0700 | [diff] [blame] | 401 | static int dmar_table_initialized; |
Fenghua Yu | 093f87d | 2007-11-21 15:07:14 -0800 | [diff] [blame] | 402 | int ret; |
| 403 | |
Suresh Siddha | 1886e8a | 2008-07-10 11:16:37 -0700 | [diff] [blame] | 404 | if (dmar_table_initialized) |
| 405 | return 0; |
| 406 | |
| 407 | dmar_table_initialized = 1; |
| 408 | |
Fenghua Yu | 093f87d | 2007-11-21 15:07:14 -0800 | [diff] [blame] | 409 | ret = parse_dmar_table(); |
| 410 | if (ret) { |
Suresh Siddha | 1886e8a | 2008-07-10 11:16:37 -0700 | [diff] [blame] | 411 | if (ret != -ENODEV) |
| 412 | printk(KERN_INFO PREFIX "parse DMAR table failure.\n"); |
Fenghua Yu | 093f87d | 2007-11-21 15:07:14 -0800 | [diff] [blame] | 413 | return ret; |
| 414 | } |
| 415 | |
Keshavamurthy, Anil S | 10e5247 | 2007-10-21 16:41:41 -0700 | [diff] [blame] | 416 | if (list_empty(&dmar_drhd_units)) { |
| 417 | printk(KERN_INFO PREFIX "No DMAR devices found\n"); |
| 418 | return -ENODEV; |
| 419 | } |
Fenghua Yu | 093f87d | 2007-11-21 15:07:14 -0800 | [diff] [blame] | 420 | |
Suresh Siddha | aaa9d1d | 2008-07-10 11:16:38 -0700 | [diff] [blame] | 421 | #ifdef CONFIG_DMAR |
Suresh Siddha | 2d6b5f8 | 2008-07-10 11:16:39 -0700 | [diff] [blame^] | 422 | if (list_empty(&dmar_rmrr_units)) |
Fenghua Yu | 093f87d | 2007-11-21 15:07:14 -0800 | [diff] [blame] | 423 | printk(KERN_INFO PREFIX "No RMRR found\n"); |
Suresh Siddha | aaa9d1d | 2008-07-10 11:16:38 -0700 | [diff] [blame] | 424 | #endif |
Fenghua Yu | 093f87d | 2007-11-21 15:07:14 -0800 | [diff] [blame] | 425 | |
Keshavamurthy, Anil S | 10e5247 | 2007-10-21 16:41:41 -0700 | [diff] [blame] | 426 | return 0; |
| 427 | } |
| 428 | |
| 429 | /** |
| 430 | * early_dmar_detect - checks to see if the platform supports DMAR devices |
| 431 | */ |
| 432 | int __init early_dmar_detect(void) |
| 433 | { |
| 434 | acpi_status status = AE_OK; |
| 435 | |
| 436 | /* if we could find DMAR table, then there are DMAR devices */ |
| 437 | status = acpi_get_table(ACPI_SIG_DMAR, 0, |
| 438 | (struct acpi_table_header **)&dmar_tbl); |
| 439 | |
| 440 | if (ACPI_SUCCESS(status) && !dmar_tbl) { |
| 441 | printk (KERN_WARNING PREFIX "Unable to map DMAR\n"); |
| 442 | status = AE_NOT_FOUND; |
| 443 | } |
| 444 | |
| 445 | return (ACPI_SUCCESS(status) ? 1 : 0); |
| 446 | } |
Suresh Siddha | e61d98d | 2008-07-10 11:16:35 -0700 | [diff] [blame] | 447 | |
Suresh Siddha | 1886e8a | 2008-07-10 11:16:37 -0700 | [diff] [blame] | 448 | int alloc_iommu(struct dmar_drhd_unit *drhd) |
Suresh Siddha | e61d98d | 2008-07-10 11:16:35 -0700 | [diff] [blame] | 449 | { |
Suresh Siddha | c42d9f3 | 2008-07-10 11:16:36 -0700 | [diff] [blame] | 450 | struct intel_iommu *iommu; |
Suresh Siddha | e61d98d | 2008-07-10 11:16:35 -0700 | [diff] [blame] | 451 | int map_size; |
| 452 | u32 ver; |
Suresh Siddha | c42d9f3 | 2008-07-10 11:16:36 -0700 | [diff] [blame] | 453 | static int iommu_allocated = 0; |
| 454 | |
| 455 | iommu = kzalloc(sizeof(*iommu), GFP_KERNEL); |
| 456 | if (!iommu) |
Suresh Siddha | 1886e8a | 2008-07-10 11:16:37 -0700 | [diff] [blame] | 457 | return -ENOMEM; |
Suresh Siddha | c42d9f3 | 2008-07-10 11:16:36 -0700 | [diff] [blame] | 458 | |
| 459 | iommu->seq_id = iommu_allocated++; |
Suresh Siddha | e61d98d | 2008-07-10 11:16:35 -0700 | [diff] [blame] | 460 | |
| 461 | iommu->reg = ioremap(drhd->reg_base_addr, PAGE_SIZE_4K); |
| 462 | if (!iommu->reg) { |
| 463 | printk(KERN_ERR "IOMMU: can't map the region\n"); |
| 464 | goto error; |
| 465 | } |
| 466 | iommu->cap = dmar_readq(iommu->reg + DMAR_CAP_REG); |
| 467 | iommu->ecap = dmar_readq(iommu->reg + DMAR_ECAP_REG); |
| 468 | |
| 469 | /* the registers might be more than one page */ |
| 470 | map_size = max_t(int, ecap_max_iotlb_offset(iommu->ecap), |
| 471 | cap_max_fault_reg_offset(iommu->cap)); |
| 472 | map_size = PAGE_ALIGN_4K(map_size); |
| 473 | if (map_size > PAGE_SIZE_4K) { |
| 474 | iounmap(iommu->reg); |
| 475 | iommu->reg = ioremap(drhd->reg_base_addr, map_size); |
| 476 | if (!iommu->reg) { |
| 477 | printk(KERN_ERR "IOMMU: can't map the region\n"); |
| 478 | goto error; |
| 479 | } |
| 480 | } |
| 481 | |
| 482 | ver = readl(iommu->reg + DMAR_VER_REG); |
| 483 | pr_debug("IOMMU %llx: ver %d:%d cap %llx ecap %llx\n", |
| 484 | drhd->reg_base_addr, DMAR_VER_MAJOR(ver), DMAR_VER_MINOR(ver), |
| 485 | iommu->cap, iommu->ecap); |
| 486 | |
| 487 | spin_lock_init(&iommu->register_lock); |
| 488 | |
| 489 | drhd->iommu = iommu; |
Suresh Siddha | 1886e8a | 2008-07-10 11:16:37 -0700 | [diff] [blame] | 490 | return 0; |
Suresh Siddha | e61d98d | 2008-07-10 11:16:35 -0700 | [diff] [blame] | 491 | error: |
| 492 | kfree(iommu); |
Suresh Siddha | 1886e8a | 2008-07-10 11:16:37 -0700 | [diff] [blame] | 493 | return -1; |
Suresh Siddha | e61d98d | 2008-07-10 11:16:35 -0700 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | void free_iommu(struct intel_iommu *iommu) |
| 497 | { |
| 498 | if (!iommu) |
| 499 | return; |
| 500 | |
| 501 | #ifdef CONFIG_DMAR |
| 502 | free_dmar_iommu(iommu); |
| 503 | #endif |
| 504 | |
| 505 | if (iommu->reg) |
| 506 | iounmap(iommu->reg); |
| 507 | kfree(iommu); |
| 508 | } |