Skip to content

Commit 5131e08

Browse files
rmurphy-armjoergroedel
authored andcommitted
iommu: Remove .domain_{get,set}_windows
Since these are trivially handled by the .domain_{get,set}_attr callbacks when relevant, we can streamline struct iommu_ops for everyone. Signed-off-by: Robin Murphy <robin.murphy@arm.com> Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent 701d8a6 commit 5131e08

2 files changed

Lines changed: 51 additions & 80 deletions

File tree

‎drivers/iommu/fsl_pamu_domain.c‎

Lines changed: 51 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -814,11 +814,59 @@ static int configure_domain_dma_state(struct fsl_dma_domain *dma_domain, bool en
814814
return 0;
815815
}
816816

817+
static int fsl_pamu_set_windows(struct iommu_domain *domain, u32 w_count)
818+
{
819+
struct fsl_dma_domain *dma_domain = to_fsl_dma_domain(domain);
820+
unsigned long flags;
821+
int ret;
822+
823+
spin_lock_irqsave(&dma_domain->domain_lock, flags);
824+
/* Ensure domain is inactive i.e. DMA should be disabled for the domain */
825+
if (dma_domain->enabled) {
826+
pr_debug("Can't set geometry attributes as domain is active\n");
827+
spin_unlock_irqrestore(&dma_domain->domain_lock, flags);
828+
return -EBUSY;
829+
}
830+
831+
/* Ensure that the geometry has been set for the domain */
832+
if (!dma_domain->geom_size) {
833+
pr_debug("Please configure geometry before setting the number of windows\n");
834+
spin_unlock_irqrestore(&dma_domain->domain_lock, flags);
835+
return -EINVAL;
836+
}
837+
838+
/*
839+
* Ensure we have valid window count i.e. it should be less than
840+
* maximum permissible limit and should be a power of two.
841+
*/
842+
if (w_count > pamu_get_max_subwin_cnt() || !is_power_of_2(w_count)) {
843+
pr_debug("Invalid window count\n");
844+
spin_unlock_irqrestore(&dma_domain->domain_lock, flags);
845+
return -EINVAL;
846+
}
847+
848+
ret = pamu_set_domain_geometry(dma_domain, &domain->geometry,
849+
w_count > 1 ? w_count : 0);
850+
if (!ret) {
851+
kfree(dma_domain->win_arr);
852+
dma_domain->win_arr = kcalloc(w_count,
853+
sizeof(*dma_domain->win_arr),
854+
GFP_ATOMIC);
855+
if (!dma_domain->win_arr) {
856+
spin_unlock_irqrestore(&dma_domain->domain_lock, flags);
857+
return -ENOMEM;
858+
}
859+
dma_domain->win_cnt = w_count;
860+
}
861+
spin_unlock_irqrestore(&dma_domain->domain_lock, flags);
862+
863+
return ret;
864+
}
865+
817866
static int fsl_pamu_set_domain_attr(struct iommu_domain *domain,
818867
enum iommu_attr attr_type, void *data)
819868
{
820869
struct fsl_dma_domain *dma_domain = to_fsl_dma_domain(domain);
821-
u32 *count;
822870
int ret = 0;
823871

824872
switch (attr_type) {
@@ -832,13 +880,7 @@ static int fsl_pamu_set_domain_attr(struct iommu_domain *domain,
832880
ret = configure_domain_dma_state(dma_domain, *(int *)data);
833881
break;
834882
case DOMAIN_ATTR_WINDOWS:
835-
count = data;
836-
837-
if (domain->ops->domain_set_windows != NULL)
838-
ret = domain->ops->domain_set_windows(domain, *count);
839-
else
840-
ret = -ENODEV;
841-
883+
ret = fsl_pamu_set_windows(domain, *(u32 *)data);
842884
break;
843885
default:
844886
pr_debug("Unsupported attribute type\n");
@@ -853,7 +895,6 @@ static int fsl_pamu_get_domain_attr(struct iommu_domain *domain,
853895
enum iommu_attr attr_type, void *data)
854896
{
855897
struct fsl_dma_domain *dma_domain = to_fsl_dma_domain(domain);
856-
u32 *count;
857898
int ret = 0;
858899

859900
switch (attr_type) {
@@ -868,13 +909,7 @@ static int fsl_pamu_get_domain_attr(struct iommu_domain *domain,
868909
*(int *)data = DOMAIN_ATTR_FSL_PAMUV1;
869910
break;
870911
case DOMAIN_ATTR_WINDOWS:
871-
count = data;
872-
873-
if (domain->ops->domain_get_windows != NULL)
874-
*count = domain->ops->domain_get_windows(domain);
875-
else
876-
ret = -ENODEV;
877-
912+
*(u32 *)data = dma_domain->win_cnt;
878913
break;
879914
default:
880915
pr_debug("Unsupported attribute type\n");
@@ -1014,62 +1049,6 @@ static void fsl_pamu_remove_device(struct device *dev)
10141049
iommu_group_remove_device(dev);
10151050
}
10161051

1017-
static int fsl_pamu_set_windows(struct iommu_domain *domain, u32 w_count)
1018-
{
1019-
struct fsl_dma_domain *dma_domain = to_fsl_dma_domain(domain);
1020-
unsigned long flags;
1021-
int ret;
1022-
1023-
spin_lock_irqsave(&dma_domain->domain_lock, flags);
1024-
/* Ensure domain is inactive i.e. DMA should be disabled for the domain */
1025-
if (dma_domain->enabled) {
1026-
pr_debug("Can't set geometry attributes as domain is active\n");
1027-
spin_unlock_irqrestore(&dma_domain->domain_lock, flags);
1028-
return -EBUSY;
1029-
}
1030-
1031-
/* Ensure that the geometry has been set for the domain */
1032-
if (!dma_domain->geom_size) {
1033-
pr_debug("Please configure geometry before setting the number of windows\n");
1034-
spin_unlock_irqrestore(&dma_domain->domain_lock, flags);
1035-
return -EINVAL;
1036-
}
1037-
1038-
/*
1039-
* Ensure we have valid window count i.e. it should be less than
1040-
* maximum permissible limit and should be a power of two.
1041-
*/
1042-
if (w_count > pamu_get_max_subwin_cnt() || !is_power_of_2(w_count)) {
1043-
pr_debug("Invalid window count\n");
1044-
spin_unlock_irqrestore(&dma_domain->domain_lock, flags);
1045-
return -EINVAL;
1046-
}
1047-
1048-
ret = pamu_set_domain_geometry(dma_domain, &domain->geometry,
1049-
w_count > 1 ? w_count : 0);
1050-
if (!ret) {
1051-
kfree(dma_domain->win_arr);
1052-
dma_domain->win_arr = kcalloc(w_count,
1053-
sizeof(*dma_domain->win_arr),
1054-
GFP_ATOMIC);
1055-
if (!dma_domain->win_arr) {
1056-
spin_unlock_irqrestore(&dma_domain->domain_lock, flags);
1057-
return -ENOMEM;
1058-
}
1059-
dma_domain->win_cnt = w_count;
1060-
}
1061-
spin_unlock_irqrestore(&dma_domain->domain_lock, flags);
1062-
1063-
return ret;
1064-
}
1065-
1066-
static u32 fsl_pamu_get_windows(struct iommu_domain *domain)
1067-
{
1068-
struct fsl_dma_domain *dma_domain = to_fsl_dma_domain(domain);
1069-
1070-
return dma_domain->win_cnt;
1071-
}
1072-
10731052
static const struct iommu_ops fsl_pamu_ops = {
10741053
.capable = fsl_pamu_capable,
10751054
.domain_alloc = fsl_pamu_domain_alloc,
@@ -1078,8 +1057,6 @@ static const struct iommu_ops fsl_pamu_ops = {
10781057
.detach_dev = fsl_pamu_detach_device,
10791058
.domain_window_enable = fsl_pamu_window_enable,
10801059
.domain_window_disable = fsl_pamu_window_disable,
1081-
.domain_get_windows = fsl_pamu_get_windows,
1082-
.domain_set_windows = fsl_pamu_set_windows,
10831060
.iova_to_phys = fsl_pamu_iova_to_phys,
10841061
.domain_set_attr = fsl_pamu_set_domain_attr,
10851062
.domain_get_attr = fsl_pamu_get_domain_attr,

‎include/linux/iommu.h‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,6 @@ struct iommu_resv_region {
181181
* @apply_resv_region: Temporary helper call-back for iova reserved ranges
182182
* @domain_window_enable: Configure and enable a particular window for a domain
183183
* @domain_window_disable: Disable a particular window for a domain
184-
* @domain_set_windows: Set the number of windows for a domain
185-
* @domain_get_windows: Return the number of windows for a domain
186184
* @of_xlate: add OF master IDs to iommu grouping
187185
* @pgsize_bitmap: bitmap of all possible supported page sizes
188186
*/
@@ -223,10 +221,6 @@ struct iommu_ops {
223221
int (*domain_window_enable)(struct iommu_domain *domain, u32 wnd_nr,
224222
phys_addr_t paddr, u64 size, int prot);
225223
void (*domain_window_disable)(struct iommu_domain *domain, u32 wnd_nr);
226-
/* Set the number of windows per domain */
227-
int (*domain_set_windows)(struct iommu_domain *domain, u32 w_count);
228-
/* Get the number of windows per domain */
229-
u32 (*domain_get_windows)(struct iommu_domain *domain);
230224

231225
int (*of_xlate)(struct device *dev, struct of_phandle_args *args);
232226
bool (*is_attach_deferred)(struct iommu_domain *domain, struct device *dev);

0 commit comments

Comments
 (0)