aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoerg Roedel <jroedel@suse.de>2015-03-26 08:43:08 -0400
committerJoerg Roedel <jroedel@suse.de>2015-03-31 09:32:02 -0400
commit00a77deb0f2f2c35cfeba183df98f92487d2e88b (patch)
tree0cd156714181aaf7a8d726853c414c2f73e37ff0
parent3f4b87b959eab362b89fce6ceb9d1badd102e5ea (diff)
iommu/vt-d: Make use of domain_alloc and domain_free
Get rid of domain_init and domain_destroy and implement domain_alloc/domain_free instead. Reviewed-by: Alex Williamson <alex.williamson@redhat.com> Signed-off-by: Joerg Roedel <jroedel@suse.de>
-rw-r--r--drivers/iommu/intel-iommu.c48
1 files changed, 28 insertions, 20 deletions
diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index ae4c1a854e57..a312e4966686 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -339,7 +339,7 @@ struct dmar_domain {
339 DECLARE_BITMAP(iommu_bmp, DMAR_UNITS_SUPPORTED); 339 DECLARE_BITMAP(iommu_bmp, DMAR_UNITS_SUPPORTED);
340 /* bitmap of iommus this domain uses*/ 340 /* bitmap of iommus this domain uses*/
341 341
342 struct list_head devices; /* all devices' list */ 342 struct list_head devices; /* all devices' list */
343 struct iova_domain iovad; /* iova's that belong to this domain */ 343 struct iova_domain iovad; /* iova's that belong to this domain */
344 344
345 struct dma_pte *pgd; /* virtual address */ 345 struct dma_pte *pgd; /* virtual address */
@@ -358,6 +358,9 @@ struct dmar_domain {
358 2 == 1GiB, 3 == 512GiB, 4 == 1TiB */ 358 2 == 1GiB, 3 == 512GiB, 4 == 1TiB */
359 spinlock_t iommu_lock; /* protect iommu set in domain */ 359 spinlock_t iommu_lock; /* protect iommu set in domain */
360 u64 max_addr; /* maximum mapped address */ 360 u64 max_addr; /* maximum mapped address */
361
362 struct iommu_domain domain; /* generic domain data structure for
363 iommu core */
361}; 364};
362 365
363/* PCI domain-device relationship */ 366/* PCI domain-device relationship */
@@ -449,6 +452,12 @@ static LIST_HEAD(device_domain_list);
449 452
450static const struct iommu_ops intel_iommu_ops; 453static const struct iommu_ops intel_iommu_ops;
451 454
455/* Convert generic 'struct iommu_domain to private struct dmar_domain */
456static struct dmar_domain *to_dmar_domain(struct iommu_domain *dom)
457{
458 return container_of(dom, struct dmar_domain, domain);
459}
460
452static int __init intel_iommu_setup(char *str) 461static int __init intel_iommu_setup(char *str)
453{ 462{
454 if (!str) 463 if (!str)
@@ -4340,44 +4349,45 @@ static int md_domain_init(struct dmar_domain *domain, int guest_width)
4340 return 0; 4349 return 0;
4341} 4350}
4342 4351
4343static int intel_iommu_domain_init(struct iommu_domain *domain) 4352static struct iommu_domain *intel_iommu_domain_alloc(unsigned type)
4344{ 4353{
4345 struct dmar_domain *dmar_domain; 4354 struct dmar_domain *dmar_domain;
4355 struct iommu_domain *domain;
4356
4357 if (type != IOMMU_DOMAIN_UNMANAGED)
4358 return NULL;
4346 4359
4347 dmar_domain = alloc_domain(DOMAIN_FLAG_VIRTUAL_MACHINE); 4360 dmar_domain = alloc_domain(DOMAIN_FLAG_VIRTUAL_MACHINE);
4348 if (!dmar_domain) { 4361 if (!dmar_domain) {
4349 printk(KERN_ERR 4362 printk(KERN_ERR
4350 "intel_iommu_domain_init: dmar_domain == NULL\n"); 4363 "intel_iommu_domain_init: dmar_domain == NULL\n");
4351 return -ENOMEM; 4364 return NULL;
4352 } 4365 }
4353 if (md_domain_init(dmar_domain, DEFAULT_DOMAIN_ADDRESS_WIDTH)) { 4366 if (md_domain_init(dmar_domain, DEFAULT_DOMAIN_ADDRESS_WIDTH)) {
4354 printk(KERN_ERR 4367 printk(KERN_ERR
4355 "intel_iommu_domain_init() failed\n"); 4368 "intel_iommu_domain_init() failed\n");
4356 domain_exit(dmar_domain); 4369 domain_exit(dmar_domain);
4357 return -ENOMEM; 4370 return NULL;
4358 } 4371 }
4359 domain_update_iommu_cap(dmar_domain); 4372 domain_update_iommu_cap(dmar_domain);
4360 domain->priv = dmar_domain;
4361 4373
4374 domain = &dmar_domain->domain;
4362 domain->geometry.aperture_start = 0; 4375 domain->geometry.aperture_start = 0;
4363 domain->geometry.aperture_end = __DOMAIN_MAX_ADDR(dmar_domain->gaw); 4376 domain->geometry.aperture_end = __DOMAIN_MAX_ADDR(dmar_domain->gaw);
4364 domain->geometry.force_aperture = true; 4377 domain->geometry.force_aperture = true;
4365 4378
4366 return 0; 4379 return domain;
4367} 4380}
4368 4381
4369static void intel_iommu_domain_destroy(struct iommu_domain *domain) 4382static void intel_iommu_domain_free(struct iommu_domain *domain)
4370{ 4383{
4371 struct dmar_domain *dmar_domain = domain->priv; 4384 domain_exit(to_dmar_domain(domain));
4372
4373 domain->priv = NULL;
4374 domain_exit(dmar_domain);
4375} 4385}
4376 4386
4377static int intel_iommu_attach_device(struct iommu_domain *domain, 4387static int intel_iommu_attach_device(struct iommu_domain *domain,
4378 struct device *dev) 4388 struct device *dev)
4379{ 4389{
4380 struct dmar_domain *dmar_domain = domain->priv; 4390 struct dmar_domain *dmar_domain = to_dmar_domain(domain);
4381 struct intel_iommu *iommu; 4391 struct intel_iommu *iommu;
4382 int addr_width; 4392 int addr_width;
4383 u8 bus, devfn; 4393 u8 bus, devfn;
@@ -4442,16 +4452,14 @@ static int intel_iommu_attach_device(struct iommu_domain *domain,
4442static void intel_iommu_detach_device(struct iommu_domain *domain, 4452static void intel_iommu_detach_device(struct iommu_domain *domain,
4443 struct device *dev) 4453 struct device *dev)
4444{ 4454{
4445 struct dmar_domain *dmar_domain = domain->priv; 4455 domain_remove_one_dev_info(to_dmar_domain(domain), dev);
4446
4447 domain_remove_one_dev_info(dmar_domain, dev);
4448} 4456}
4449 4457
4450static int intel_iommu_map(struct iommu_domain *domain, 4458static int intel_iommu_map(struct iommu_domain *domain,
4451 unsigned long iova, phys_addr_t hpa, 4459 unsigned long iova, phys_addr_t hpa,
4452 size_t size, int iommu_prot) 4460 size_t size, int iommu_prot)
4453{ 4461{
4454 struct dmar_domain *dmar_domain = domain->priv; 4462 struct dmar_domain *dmar_domain = to_dmar_domain(domain);
4455 u64 max_addr; 4463 u64 max_addr;
4456 int prot = 0; 4464 int prot = 0;
4457 int ret; 4465 int ret;
@@ -4488,7 +4496,7 @@ static int intel_iommu_map(struct iommu_domain *domain,
4488static size_t intel_iommu_unmap(struct iommu_domain *domain, 4496static size_t intel_iommu_unmap(struct iommu_domain *domain,
4489 unsigned long iova, size_t size) 4497 unsigned long iova, size_t size)
4490{ 4498{
4491 struct dmar_domain *dmar_domain = domain->priv; 4499 struct dmar_domain *dmar_domain = to_dmar_domain(domain);
4492 struct page *freelist = NULL; 4500 struct page *freelist = NULL;
4493 struct intel_iommu *iommu; 4501 struct intel_iommu *iommu;
4494 unsigned long start_pfn, last_pfn; 4502 unsigned long start_pfn, last_pfn;
@@ -4536,7 +4544,7 @@ static size_t intel_iommu_unmap(struct iommu_domain *domain,
4536static phys_addr_t intel_iommu_iova_to_phys(struct iommu_domain *domain, 4544static phys_addr_t intel_iommu_iova_to_phys(struct iommu_domain *domain,
4537 dma_addr_t iova) 4545 dma_addr_t iova)
4538{ 4546{
4539 struct dmar_domain *dmar_domain = domain->priv; 4547 struct dmar_domain *dmar_domain = to_dmar_domain(domain);
4540 struct dma_pte *pte; 4548 struct dma_pte *pte;
4541 int level = 0; 4549 int level = 0;
4542 u64 phys = 0; 4550 u64 phys = 0;
@@ -4595,8 +4603,8 @@ static void intel_iommu_remove_device(struct device *dev)
4595 4603
4596static const struct iommu_ops intel_iommu_ops = { 4604static const struct iommu_ops intel_iommu_ops = {
4597 .capable = intel_iommu_capable, 4605 .capable = intel_iommu_capable,
4598 .domain_init = intel_iommu_domain_init, 4606 .domain_alloc = intel_iommu_domain_alloc,
4599 .domain_destroy = intel_iommu_domain_destroy, 4607 .domain_free = intel_iommu_domain_free,
4600 .attach_dev = intel_iommu_attach_device, 4608 .attach_dev = intel_iommu_attach_device,
4601 .detach_dev = intel_iommu_detach_device, 4609 .detach_dev = intel_iommu_detach_device,
4602 .map = intel_iommu_map, 4610 .map = intel_iommu_map,