pgd_t *pgd;
};
+struct ipmmu_vmsa_archdata {
+ struct ipmmu_vmsa_device *mmu;
+ unsigned int utlb;
+};
+
static DEFINE_SPINLOCK(ipmmu_devices_lock);
static LIST_HEAD(ipmmu_devices);
* Enable MMU translation for the microTLB.
*/
static void ipmmu_utlb_enable(struct ipmmu_vmsa_domain *domain,
- const struct ipmmu_vmsa_master *master)
+ unsigned int utlb)
{
struct ipmmu_vmsa_device *mmu = domain->mmu;
+ /*
+ * TODO: Reference-count the microTLB as several bus masters can be
+ * connected to the same microTLB.
+ */
+
/* TODO: What should we set the ASID to ? */
- ipmmu_write(mmu, IMUASID(master->utlb), 0);
+ ipmmu_write(mmu, IMUASID(utlb), 0);
/* TODO: Do we need to flush the microTLB ? */
- ipmmu_write(mmu, IMUCTR(master->utlb),
+ ipmmu_write(mmu, IMUCTR(utlb),
IMUCTR_TTSEL_MMU(domain->context_id) | IMUCTR_FLUSH |
IMUCTR_MMUEN);
}
* Disable MMU translation for the microTLB.
*/
static void ipmmu_utlb_disable(struct ipmmu_vmsa_domain *domain,
- const struct ipmmu_vmsa_master *master)
+ unsigned int utlb)
{
struct ipmmu_vmsa_device *mmu = domain->mmu;
- ipmmu_write(mmu, IMUCTR(master->utlb), 0);
+ ipmmu_write(mmu, IMUCTR(utlb), 0);
}
static void ipmmu_flush_pgtable(struct ipmmu_vmsa_device *mmu, void *addr,
* IOMMU Operations
*/
-static const struct ipmmu_vmsa_master *
-ipmmu_find_master(struct ipmmu_vmsa_device *ipmmu, struct device *dev)
-{
- const struct ipmmu_vmsa_master *master = ipmmu->pdata->masters;
- const char *devname = dev_name(dev);
- unsigned int i;
-
- for (i = 0; i < ipmmu->pdata->num_masters; ++i, ++master) {
- if (strcmp(master->name, devname) == 0)
- return master;
- }
-
- return NULL;
-}
-
static int ipmmu_domain_init(struct iommu_domain *io_domain)
{
struct ipmmu_vmsa_domain *domain;
static int ipmmu_attach_device(struct iommu_domain *io_domain,
struct device *dev)
{
- struct ipmmu_vmsa_device *mmu = dev->archdata.iommu;
+ struct ipmmu_vmsa_archdata *archdata = dev->archdata.iommu;
+ struct ipmmu_vmsa_device *mmu = archdata->mmu;
struct ipmmu_vmsa_domain *domain = io_domain->priv;
- const struct ipmmu_vmsa_master *master;
unsigned long flags;
int ret = 0;
if (ret < 0)
return ret;
- master = ipmmu_find_master(mmu, dev);
- if (!master)
- return -EINVAL;
-
- ipmmu_utlb_enable(domain, master);
+ ipmmu_utlb_enable(domain, archdata->utlb);
return 0;
}
static void ipmmu_detach_device(struct iommu_domain *io_domain,
struct device *dev)
{
+ struct ipmmu_vmsa_archdata *archdata = dev->archdata.iommu;
struct ipmmu_vmsa_domain *domain = io_domain->priv;
- const struct ipmmu_vmsa_master *master;
- master = ipmmu_find_master(domain->mmu, dev);
- if (!master)
- return;
-
- ipmmu_utlb_disable(domain, master);
+ ipmmu_utlb_disable(domain, archdata->utlb);
/*
* TODO: Optimize by disabling the context when no device is attached.
return __pfn_to_phys(pte_pfn(pte)) | (iova & ~PAGE_MASK);
}
+static int ipmmu_find_utlb(struct ipmmu_vmsa_device *mmu, struct device *dev)
+{
+ const struct ipmmu_vmsa_master *master = mmu->pdata->masters;
+ const char *devname = dev_name(dev);
+ unsigned int i;
+
+ for (i = 0; i < mmu->pdata->num_masters; ++i, ++master) {
+ if (strcmp(master->name, devname) == 0)
+ return master->utlb;
+ }
+
+ return -1;
+}
+
static int ipmmu_add_device(struct device *dev)
{
- const struct ipmmu_vmsa_master *master = NULL;
+ struct ipmmu_vmsa_archdata *archdata;
struct ipmmu_vmsa_device *mmu;
struct iommu_group *group;
+ int utlb = -1;
int ret;
if (dev->archdata.iommu) {
spin_lock(&ipmmu_devices_lock);
list_for_each_entry(mmu, &ipmmu_devices, list) {
- master = ipmmu_find_master(mmu, dev);
- if (master) {
+ utlb = ipmmu_find_utlb(mmu, dev);
+ if (utlb >= 0) {
/*
- * TODO Take a reference to the master to protect
+ * TODO Take a reference to the MMU to protect
* against device removal.
*/
break;
spin_unlock(&ipmmu_devices_lock);
- if (!master)
+ if (utlb < 0)
return -ENODEV;
- if (!master->utlb >= mmu->num_utlbs)
+ if (utlb >= mmu->num_utlbs)
return -EINVAL;
/* Create a device group and add the device to it. */
return ret;
}
- dev->archdata.iommu = mmu;
+ archdata = kzalloc(sizeof(*archdata), GFP_KERNEL);
+ if (!archdata) {
+ ret = -ENOMEM;
+ goto error;
+ }
+
+ archdata->mmu = mmu;
+ archdata->utlb = utlb;
+ dev->archdata.iommu = archdata;
/*
* Create the ARM mapping, used by the ARM DMA mapping core to allocate
return 0;
error:
+ kfree(dev->archdata.iommu);
dev->archdata.iommu = NULL;
iommu_group_remove_device(dev);
return ret;
{
arm_iommu_detach_device(dev);
iommu_group_remove_device(dev);
+ kfree(dev->archdata.iommu);
dev->archdata.iommu = NULL;
}