Skip to content

Commit 7993085

Browse files
jgunthorpejoergroedel
authored andcommitted
iommu/dart: Use static global identity domains
Move to the new static global for identity domains. Move the identity specific code to apple_dart_attach_dev_identity(). Reviewed-by: Janne Grunau <j@jannau.net> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Acked-by: Sven Peter <sven@svenpeter.dev> Link: https://lore.kernel.org/r/5-v2-bff223cf6409+282-dart_paging_jgg@nvidia.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent 13fbceb commit 7993085

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

drivers/iommu/apple-dart.c

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -659,11 +659,7 @@ static int apple_dart_attach_dev(struct iommu_domain *domain,
659659
struct apple_dart_master_cfg *cfg = dev_iommu_priv_get(dev);
660660
struct apple_dart_domain *dart_domain = to_dart_domain(domain);
661661

662-
if (cfg->stream_maps[0].dart->force_bypass &&
663-
domain->type != IOMMU_DOMAIN_IDENTITY)
664-
return -EINVAL;
665-
if (!cfg->stream_maps[0].dart->supports_bypass &&
666-
domain->type == IOMMU_DOMAIN_IDENTITY)
662+
if (cfg->stream_maps[0].dart->force_bypass)
667663
return -EINVAL;
668664

669665
ret = apple_dart_finalize_domain(domain, cfg);
@@ -684,15 +680,35 @@ static int apple_dart_attach_dev(struct iommu_domain *domain,
684680
for_each_stream_map(i, cfg, stream_map)
685681
apple_dart_hw_disable_dma(stream_map);
686682
break;
687-
case IOMMU_DOMAIN_IDENTITY:
688-
for_each_stream_map(i, cfg, stream_map)
689-
apple_dart_hw_enable_bypass(stream_map);
690-
break;
691683
}
692684

693685
return ret;
694686
}
695687

688+
static int apple_dart_attach_dev_identity(struct iommu_domain *domain,
689+
struct device *dev)
690+
{
691+
struct apple_dart_master_cfg *cfg = dev_iommu_priv_get(dev);
692+
struct apple_dart_stream_map *stream_map;
693+
int i;
694+
695+
if (!cfg->stream_maps[0].dart->supports_bypass)
696+
return -EINVAL;
697+
698+
for_each_stream_map(i, cfg, stream_map)
699+
apple_dart_hw_enable_bypass(stream_map);
700+
return 0;
701+
}
702+
703+
static const struct iommu_domain_ops apple_dart_identity_ops = {
704+
.attach_dev = apple_dart_attach_dev_identity,
705+
};
706+
707+
static struct iommu_domain apple_dart_identity_domain = {
708+
.type = IOMMU_DOMAIN_IDENTITY,
709+
.ops = &apple_dart_identity_ops,
710+
};
711+
696712
static struct iommu_device *apple_dart_probe_device(struct device *dev)
697713
{
698714
struct apple_dart_master_cfg *cfg = dev_iommu_priv_get(dev);
@@ -723,7 +739,7 @@ static struct iommu_domain *apple_dart_domain_alloc(unsigned int type)
723739
struct apple_dart_domain *dart_domain;
724740

725741
if (type != IOMMU_DOMAIN_DMA && type != IOMMU_DOMAIN_UNMANAGED &&
726-
type != IOMMU_DOMAIN_IDENTITY && type != IOMMU_DOMAIN_BLOCKED)
742+
type != IOMMU_DOMAIN_BLOCKED)
727743
return NULL;
728744

729745
dart_domain = kzalloc(sizeof(*dart_domain), GFP_KERNEL);
@@ -733,7 +749,7 @@ static struct iommu_domain *apple_dart_domain_alloc(unsigned int type)
733749
mutex_init(&dart_domain->init_lock);
734750

735751
/* no need to allocate pgtbl_ops or do any other finalization steps */
736-
if (type == IOMMU_DOMAIN_IDENTITY || type == IOMMU_DOMAIN_BLOCKED)
752+
if (type == IOMMU_DOMAIN_BLOCKED)
737753
dart_domain->finalized = true;
738754

739755
return &dart_domain->domain;
@@ -948,6 +964,7 @@ static void apple_dart_get_resv_regions(struct device *dev,
948964
}
949965

950966
static const struct iommu_ops apple_dart_iommu_ops = {
967+
.identity_domain = &apple_dart_identity_domain,
951968
.domain_alloc = apple_dart_domain_alloc,
952969
.probe_device = apple_dart_probe_device,
953970
.release_device = apple_dart_release_device,

0 commit comments

Comments
 (0)