@@ -94,8 +94,6 @@ static const char * const iommu_group_resv_type_string[] = {
9494static int iommu_bus_notifier (struct notifier_block * nb ,
9595 unsigned long action , void * data );
9696static void iommu_release_device (struct device * dev );
97- static struct iommu_domain *
98- __iommu_group_domain_alloc (struct iommu_group * group , unsigned int type );
9997static int __iommu_attach_device (struct iommu_domain * domain ,
10098 struct device * dev );
10199static int __iommu_attach_group (struct iommu_domain * domain ,
@@ -137,6 +135,8 @@ static struct group_device *iommu_group_alloc_device(struct iommu_group *group,
137135 struct device * dev );
138136static void __iommu_group_free_device (struct iommu_group * group ,
139137 struct group_device * grp_dev );
138+ static void iommu_domain_init (struct iommu_domain * domain , unsigned int type ,
139+ const struct iommu_ops * ops );
140140
141141#define IOMMU_GROUP_ATTR (_name , _mode , _show , _store ) \
142142struct iommu_group_attribute iommu_group_attr_##_name = \
@@ -1586,6 +1586,28 @@ struct iommu_group *fsl_mc_device_group(struct device *dev)
15861586}
15871587EXPORT_SYMBOL_GPL (fsl_mc_device_group );
15881588
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+
15891611static struct iommu_domain *
15901612__iommu_group_alloc_default_domain (struct iommu_group * group , int req_type )
15911613{
@@ -1613,7 +1635,10 @@ __iommu_group_alloc_default_domain(struct iommu_group *group, int req_type)
16131635 return dom ;
16141636 }
16151637
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 );
16171642}
16181643
16191644/*
@@ -1947,44 +1972,6 @@ static void iommu_domain_init(struct iommu_domain *domain, unsigned int type,
19471972 domain -> pgsize_bitmap = ops -> pgsize_bitmap ;
19481973}
19491974
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-
19881975static struct iommu_domain *
19891976__iommu_paging_domain_alloc_flags (struct device * dev , unsigned int type ,
19901977 unsigned int flags )
0 commit comments