@@ -94,8 +94,6 @@ static const char * const iommu_group_resv_type_string[] = {
94
94
static int iommu_bus_notifier (struct notifier_block * nb ,
95
95
unsigned long action , void * data );
96
96
static void iommu_release_device (struct device * dev );
97
- static struct iommu_domain *
98
- __iommu_group_domain_alloc (struct iommu_group * group , unsigned int type );
99
97
static int __iommu_attach_device (struct iommu_domain * domain ,
100
98
struct device * dev );
101
99
static int __iommu_attach_group (struct iommu_domain * domain ,
@@ -137,6 +135,8 @@ static struct group_device *iommu_group_alloc_device(struct iommu_group *group,
137
135
struct device * dev );
138
136
static void __iommu_group_free_device (struct iommu_group * group ,
139
137
struct group_device * grp_dev );
138
+ static void iommu_domain_init (struct iommu_domain * domain , unsigned int type ,
139
+ const struct iommu_ops * ops );
140
140
141
141
#define IOMMU_GROUP_ATTR (_name , _mode , _show , _store ) \
142
142
struct iommu_group_attribute iommu_group_attr_##_name = \
@@ -1586,6 +1586,28 @@ struct iommu_group *fsl_mc_device_group(struct device *dev)
1586
1586
}
1587
1587
EXPORT_SYMBOL_GPL (fsl_mc_device_group );
1588
1588
1589
+ static struct iommu_domain * __iommu_alloc_identity_domain (struct device * dev )
1590
+ {
1591
+ const struct iommu_ops * ops = dev_iommu_ops (dev );
1592
+ struct iommu_domain * domain ;
1593
+
1594
+ if (ops -> identity_domain )
1595
+ return ops -> identity_domain ;
1596
+
1597
+ /* Older drivers create the identity domain via ops->domain_alloc() */
1598
+ if (!ops -> domain_alloc )
1599
+ return ERR_PTR (- EOPNOTSUPP );
1600
+
1601
+ domain = ops -> domain_alloc (IOMMU_DOMAIN_IDENTITY );
1602
+ if (IS_ERR (domain ))
1603
+ return domain ;
1604
+ if (!domain )
1605
+ return ERR_PTR (- ENOMEM );
1606
+
1607
+ iommu_domain_init (domain , IOMMU_DOMAIN_IDENTITY , ops );
1608
+ return domain ;
1609
+ }
1610
+
1589
1611
static struct iommu_domain *
1590
1612
__iommu_group_alloc_default_domain (struct iommu_group * group , int req_type )
1591
1613
{
@@ -1613,7 +1635,10 @@ __iommu_group_alloc_default_domain(struct iommu_group *group, int req_type)
1613
1635
return dom ;
1614
1636
}
1615
1637
1616
- return __iommu_group_domain_alloc (group , req_type );
1638
+ if (req_type == IOMMU_DOMAIN_IDENTITY )
1639
+ return __iommu_alloc_identity_domain (dev );
1640
+
1641
+ return ERR_PTR (- EINVAL );
1617
1642
}
1618
1643
1619
1644
/*
@@ -1947,44 +1972,6 @@ static void iommu_domain_init(struct iommu_domain *domain, unsigned int type,
1947
1972
domain -> pgsize_bitmap = ops -> pgsize_bitmap ;
1948
1973
}
1949
1974
1950
- static struct iommu_domain * __iommu_domain_alloc (const struct iommu_ops * ops ,
1951
- struct device * dev ,
1952
- unsigned int type )
1953
- {
1954
- struct iommu_domain * domain ;
1955
- unsigned int alloc_type = type & IOMMU_DOMAIN_ALLOC_FLAGS ;
1956
-
1957
- if (alloc_type == IOMMU_DOMAIN_IDENTITY && ops -> identity_domain )
1958
- return ops -> identity_domain ;
1959
- else if (type & __IOMMU_DOMAIN_PAGING && ops -> domain_alloc_paging )
1960
- domain = ops -> domain_alloc_paging (dev );
1961
- else if (ops -> domain_alloc )
1962
- domain = ops -> domain_alloc (alloc_type );
1963
- else
1964
- return ERR_PTR (- EOPNOTSUPP );
1965
-
1966
- /*
1967
- * Many domain_alloc ops now return ERR_PTR, make things easier for the
1968
- * driver by accepting ERR_PTR from all domain_alloc ops instead of
1969
- * having two rules.
1970
- */
1971
- if (IS_ERR (domain ))
1972
- return domain ;
1973
- if (!domain )
1974
- return ERR_PTR (- ENOMEM );
1975
-
1976
- iommu_domain_init (domain , type , ops );
1977
- return domain ;
1978
- }
1979
-
1980
- static struct iommu_domain *
1981
- __iommu_group_domain_alloc (struct iommu_group * group , unsigned int type )
1982
- {
1983
- struct device * dev = iommu_group_first_dev (group );
1984
-
1985
- return __iommu_domain_alloc (dev_iommu_ops (dev ), dev , type );
1986
- }
1987
-
1988
1975
static struct iommu_domain *
1989
1976
__iommu_paging_domain_alloc_flags (struct device * dev , unsigned int type ,
1990
1977
unsigned int flags )
0 commit comments