Skip to content

Commit 17ef8d6

Browse files
jgunthorpejoergroedel
authored andcommitted
iommu/dart: Move the blocked domain support to a global static
Move to the new static global for blocked domains. Move the blocked specific code to apple_dart_attach_dev_blocked(). Reviewed-by: Janne Grunau <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]> Acked-by: Sven Peter <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 7993085 commit 17ef8d6

File tree

1 file changed

+32
-22
lines changed

1 file changed

+32
-22
lines changed

drivers/iommu/apple-dart.c

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -666,23 +666,13 @@ static int apple_dart_attach_dev(struct iommu_domain *domain,
666666
if (ret)
667667
return ret;
668668

669-
switch (domain->type) {
670-
case IOMMU_DOMAIN_DMA:
671-
case IOMMU_DOMAIN_UNMANAGED:
672-
ret = apple_dart_domain_add_streams(dart_domain, cfg);
673-
if (ret)
674-
return ret;
675-
676-
for_each_stream_map(i, cfg, stream_map)
677-
apple_dart_setup_translation(dart_domain, stream_map);
678-
break;
679-
case IOMMU_DOMAIN_BLOCKED:
680-
for_each_stream_map(i, cfg, stream_map)
681-
apple_dart_hw_disable_dma(stream_map);
682-
break;
683-
}
669+
ret = apple_dart_domain_add_streams(dart_domain, cfg);
670+
if (ret)
671+
return ret;
684672

685-
return ret;
673+
for_each_stream_map(i, cfg, stream_map)
674+
apple_dart_setup_translation(dart_domain, stream_map);
675+
return 0;
686676
}
687677

688678
static int apple_dart_attach_dev_identity(struct iommu_domain *domain,
@@ -709,6 +699,30 @@ static struct iommu_domain apple_dart_identity_domain = {
709699
.ops = &apple_dart_identity_ops,
710700
};
711701

702+
static int apple_dart_attach_dev_blocked(struct iommu_domain *domain,
703+
struct device *dev)
704+
{
705+
struct apple_dart_master_cfg *cfg = dev_iommu_priv_get(dev);
706+
struct apple_dart_stream_map *stream_map;
707+
int i;
708+
709+
if (cfg->stream_maps[0].dart->force_bypass)
710+
return -EINVAL;
711+
712+
for_each_stream_map(i, cfg, stream_map)
713+
apple_dart_hw_disable_dma(stream_map);
714+
return 0;
715+
}
716+
717+
static const struct iommu_domain_ops apple_dart_blocked_ops = {
718+
.attach_dev = apple_dart_attach_dev_blocked,
719+
};
720+
721+
static struct iommu_domain apple_dart_blocked_domain = {
722+
.type = IOMMU_DOMAIN_BLOCKED,
723+
.ops = &apple_dart_blocked_ops,
724+
};
725+
712726
static struct iommu_device *apple_dart_probe_device(struct device *dev)
713727
{
714728
struct apple_dart_master_cfg *cfg = dev_iommu_priv_get(dev);
@@ -738,8 +752,7 @@ static struct iommu_domain *apple_dart_domain_alloc(unsigned int type)
738752
{
739753
struct apple_dart_domain *dart_domain;
740754

741-
if (type != IOMMU_DOMAIN_DMA && type != IOMMU_DOMAIN_UNMANAGED &&
742-
type != IOMMU_DOMAIN_BLOCKED)
755+
if (type != IOMMU_DOMAIN_DMA && type != IOMMU_DOMAIN_UNMANAGED)
743756
return NULL;
744757

745758
dart_domain = kzalloc(sizeof(*dart_domain), GFP_KERNEL);
@@ -748,10 +761,6 @@ static struct iommu_domain *apple_dart_domain_alloc(unsigned int type)
748761

749762
mutex_init(&dart_domain->init_lock);
750763

751-
/* no need to allocate pgtbl_ops or do any other finalization steps */
752-
if (type == IOMMU_DOMAIN_BLOCKED)
753-
dart_domain->finalized = true;
754-
755764
return &dart_domain->domain;
756765
}
757766

@@ -965,6 +974,7 @@ static void apple_dart_get_resv_regions(struct device *dev,
965974

966975
static const struct iommu_ops apple_dart_iommu_ops = {
967976
.identity_domain = &apple_dart_identity_domain,
977+
.blocked_domain = &apple_dart_blocked_domain,
968978
.domain_alloc = apple_dart_domain_alloc,
969979
.probe_device = apple_dart_probe_device,
970980
.release_device = apple_dart_release_device,

0 commit comments

Comments
 (0)