提交 d5f1a81c 编写于 作者: J Joerg Roedel

iommu/tegra-smmu: Make use of domain_alloc and domain_free

Implement domain_alloc and domain_free iommu-ops as a
replacement for domain_init/domain_destroy.
Tested-by: NThierry Reding <treding@nvidia.com>
Acked-by: NThierry Reding <treding@nvidia.com>
Signed-off-by: NJoerg Roedel <jroedel@suse.de>
上级 e1fd1eaa
...@@ -31,7 +31,7 @@ struct tegra_smmu { ...@@ -31,7 +31,7 @@ struct tegra_smmu {
}; };
struct tegra_smmu_as { struct tegra_smmu_as {
struct iommu_domain *domain; struct iommu_domain domain;
struct tegra_smmu *smmu; struct tegra_smmu *smmu;
unsigned int use_count; unsigned int use_count;
struct page *count; struct page *count;
...@@ -40,6 +40,11 @@ struct tegra_smmu_as { ...@@ -40,6 +40,11 @@ struct tegra_smmu_as {
u32 attr; u32 attr;
}; };
static struct tegra_smmu_as *to_smmu_as(struct iommu_domain *dom)
{
return container_of(dom, struct tegra_smmu_as, domain);
}
static inline void smmu_writel(struct tegra_smmu *smmu, u32 value, static inline void smmu_writel(struct tegra_smmu *smmu, u32 value,
unsigned long offset) unsigned long offset)
{ {
...@@ -224,30 +229,32 @@ static bool tegra_smmu_capable(enum iommu_cap cap) ...@@ -224,30 +229,32 @@ static bool tegra_smmu_capable(enum iommu_cap cap)
return false; return false;
} }
static int tegra_smmu_domain_init(struct iommu_domain *domain) static struct iommu_domain *tegra_smmu_domain_alloc(unsigned type)
{ {
struct tegra_smmu_as *as; struct tegra_smmu_as *as;
unsigned int i; unsigned int i;
uint32_t *pd; uint32_t *pd;
if (type != IOMMU_DOMAIN_UNMANAGED)
return NULL;
as = kzalloc(sizeof(*as), GFP_KERNEL); as = kzalloc(sizeof(*as), GFP_KERNEL);
if (!as) if (!as)
return -ENOMEM; return NULL;
as->attr = SMMU_PD_READABLE | SMMU_PD_WRITABLE | SMMU_PD_NONSECURE; as->attr = SMMU_PD_READABLE | SMMU_PD_WRITABLE | SMMU_PD_NONSECURE;
as->domain = domain;
as->pd = alloc_page(GFP_KERNEL | __GFP_DMA); as->pd = alloc_page(GFP_KERNEL | __GFP_DMA);
if (!as->pd) { if (!as->pd) {
kfree(as); kfree(as);
return -ENOMEM; return NULL;
} }
as->count = alloc_page(GFP_KERNEL); as->count = alloc_page(GFP_KERNEL);
if (!as->count) { if (!as->count) {
__free_page(as->pd); __free_page(as->pd);
kfree(as); kfree(as);
return -ENOMEM; return NULL;
} }
/* clear PDEs */ /* clear PDEs */
...@@ -264,14 +271,12 @@ static int tegra_smmu_domain_init(struct iommu_domain *domain) ...@@ -264,14 +271,12 @@ static int tegra_smmu_domain_init(struct iommu_domain *domain)
for (i = 0; i < SMMU_NUM_PDE; i++) for (i = 0; i < SMMU_NUM_PDE; i++)
pd[i] = 0; pd[i] = 0;
domain->priv = as; return &as->domain;
return 0;
} }
static void tegra_smmu_domain_destroy(struct iommu_domain *domain) static void tegra_smmu_domain_free(struct iommu_domain *domain)
{ {
struct tegra_smmu_as *as = domain->priv; struct tegra_smmu_as *as = to_smmu_as(domain);
/* TODO: free page directory and page tables */ /* TODO: free page directory and page tables */
ClearPageReserved(as->pd); ClearPageReserved(as->pd);
...@@ -395,7 +400,7 @@ static int tegra_smmu_attach_dev(struct iommu_domain *domain, ...@@ -395,7 +400,7 @@ static int tegra_smmu_attach_dev(struct iommu_domain *domain,
struct device *dev) struct device *dev)
{ {
struct tegra_smmu *smmu = dev->archdata.iommu; struct tegra_smmu *smmu = dev->archdata.iommu;
struct tegra_smmu_as *as = domain->priv; struct tegra_smmu_as *as = to_smmu_as(domain);
struct device_node *np = dev->of_node; struct device_node *np = dev->of_node;
struct of_phandle_args args; struct of_phandle_args args;
unsigned int index = 0; unsigned int index = 0;
...@@ -428,7 +433,7 @@ static int tegra_smmu_attach_dev(struct iommu_domain *domain, ...@@ -428,7 +433,7 @@ static int tegra_smmu_attach_dev(struct iommu_domain *domain,
static void tegra_smmu_detach_dev(struct iommu_domain *domain, struct device *dev) static void tegra_smmu_detach_dev(struct iommu_domain *domain, struct device *dev)
{ {
struct tegra_smmu_as *as = domain->priv; struct tegra_smmu_as *as = to_smmu_as(domain);
struct device_node *np = dev->of_node; struct device_node *np = dev->of_node;
struct tegra_smmu *smmu = as->smmu; struct tegra_smmu *smmu = as->smmu;
struct of_phandle_args args; struct of_phandle_args args;
...@@ -524,7 +529,7 @@ static void as_put_pte(struct tegra_smmu_as *as, dma_addr_t iova) ...@@ -524,7 +529,7 @@ static void as_put_pte(struct tegra_smmu_as *as, dma_addr_t iova)
static int tegra_smmu_map(struct iommu_domain *domain, unsigned long iova, static int tegra_smmu_map(struct iommu_domain *domain, unsigned long iova,
phys_addr_t paddr, size_t size, int prot) phys_addr_t paddr, size_t size, int prot)
{ {
struct tegra_smmu_as *as = domain->priv; struct tegra_smmu_as *as = to_smmu_as(domain);
struct tegra_smmu *smmu = as->smmu; struct tegra_smmu *smmu = as->smmu;
unsigned long offset; unsigned long offset;
struct page *page; struct page *page;
...@@ -548,7 +553,7 @@ static int tegra_smmu_map(struct iommu_domain *domain, unsigned long iova, ...@@ -548,7 +553,7 @@ static int tegra_smmu_map(struct iommu_domain *domain, unsigned long iova,
static size_t tegra_smmu_unmap(struct iommu_domain *domain, unsigned long iova, static size_t tegra_smmu_unmap(struct iommu_domain *domain, unsigned long iova,
size_t size) size_t size)
{ {
struct tegra_smmu_as *as = domain->priv; struct tegra_smmu_as *as = to_smmu_as(domain);
struct tegra_smmu *smmu = as->smmu; struct tegra_smmu *smmu = as->smmu;
unsigned long offset; unsigned long offset;
struct page *page; struct page *page;
...@@ -572,7 +577,7 @@ static size_t tegra_smmu_unmap(struct iommu_domain *domain, unsigned long iova, ...@@ -572,7 +577,7 @@ static size_t tegra_smmu_unmap(struct iommu_domain *domain, unsigned long iova,
static phys_addr_t tegra_smmu_iova_to_phys(struct iommu_domain *domain, static phys_addr_t tegra_smmu_iova_to_phys(struct iommu_domain *domain,
dma_addr_t iova) dma_addr_t iova)
{ {
struct tegra_smmu_as *as = domain->priv; struct tegra_smmu_as *as = to_smmu_as(domain);
struct page *page; struct page *page;
unsigned long pfn; unsigned long pfn;
u32 *pte; u32 *pte;
...@@ -633,8 +638,8 @@ static void tegra_smmu_remove_device(struct device *dev) ...@@ -633,8 +638,8 @@ static void tegra_smmu_remove_device(struct device *dev)
static const struct iommu_ops tegra_smmu_ops = { static const struct iommu_ops tegra_smmu_ops = {
.capable = tegra_smmu_capable, .capable = tegra_smmu_capable,
.domain_init = tegra_smmu_domain_init, .domain_alloc = tegra_smmu_domain_alloc,
.domain_destroy = tegra_smmu_domain_destroy, .domain_free = tegra_smmu_domain_free,
.attach_dev = tegra_smmu_attach_dev, .attach_dev = tegra_smmu_attach_dev,
.detach_dev = tegra_smmu_detach_dev, .detach_dev = tegra_smmu_detach_dev,
.add_device = tegra_smmu_add_device, .add_device = tegra_smmu_add_device,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册