iommu: Add DOMAIN_ATTR_WINDOWS domain attribute
authorJoerg Roedel <joro@8bytes.org>
Mon, 4 Feb 2013 13:00:01 +0000 (14:00 +0100)
committerJoerg Roedel <joro@8bytes.org>
Wed, 6 Feb 2013 09:47:28 +0000 (10:47 +0100)
This attribute can be used to set and get the number of
subwindows on IOMMUs that are window-based.

Signed-off-by: Joerg Roedel <joro@8bytes.org>
drivers/iommu/iommu.c
include/linux/iommu.h

index b3aced7356cc13a91423fe695cf2974c59b11611..b972d430d92b946eb16e98a41a2e23441b17f93e 100644 (file)
@@ -891,6 +891,7 @@ int iommu_domain_get_attr(struct iommu_domain *domain,
        struct iommu_domain_geometry *geometry;
        bool *paging;
        int ret = 0;
+       u32 *count;
 
        switch (attr) {
        case DOMAIN_ATTR_GEOMETRY:
@@ -901,6 +902,15 @@ int iommu_domain_get_attr(struct iommu_domain *domain,
        case DOMAIN_ATTR_PAGING:
                paging  = data;
                *paging = (domain->ops->pgsize_bitmap != 0UL);
+               break;
+       case DOMAIN_ATTR_WINDOWS:
+               count = data;
+
+               if (domain->ops->domain_get_windows != NULL)
+                       *count = domain->ops->domain_get_windows(domain);
+               else
+                       ret = -ENODEV;
+
                break;
        default:
                if (!domain->ops->domain_get_attr)
@@ -916,9 +926,26 @@ EXPORT_SYMBOL_GPL(iommu_domain_get_attr);
 int iommu_domain_set_attr(struct iommu_domain *domain,
                          enum iommu_attr attr, void *data)
 {
-       if (!domain->ops->domain_set_attr)
-               return -EINVAL;
+       int ret = 0;
+       u32 *count;
+
+       switch (attr) {
+       case DOMAIN_ATTR_WINDOWS:
+               count = data;
+
+               if (domain->ops->domain_set_windows != NULL)
+                       ret = domain->ops->domain_set_windows(domain, *count);
+               else
+                       ret = -ENODEV;
 
-       return domain->ops->domain_set_attr(domain, attr, data);
+               break;
+       default:
+               if (domain->ops->domain_set_attr == NULL)
+                       return -EINVAL;
+
+               ret = domain->ops->domain_set_attr(domain, attr, data);
+       }
+
+       return ret;
 }
 EXPORT_SYMBOL_GPL(iommu_domain_set_attr);
index 5ea3d725091746374c6d4dc5d29616700c8f5fe7..ba3b8a98a0499abcb4b24eff5d8e1201c2215d4e 100644 (file)
@@ -60,6 +60,7 @@ struct iommu_domain {
 enum iommu_attr {
        DOMAIN_ATTR_GEOMETRY,
        DOMAIN_ATTR_PAGING,
+       DOMAIN_ATTR_WINDOWS,
        DOMAIN_ATTR_MAX,
 };
 
@@ -106,6 +107,10 @@ struct iommu_ops {
        int (*domain_window_enable)(struct iommu_domain *domain, u32 wnd_nr,
                                    phys_addr_t paddr, u64 size);
        void (*domain_window_disable)(struct iommu_domain *domain, u32 wnd_nr);
+       /* Set the numer of window per domain */
+       int (*domain_set_windows)(struct iommu_domain *domain, u32 w_count);
+       /* Get the numer of window per domain */
+       u32 (*domain_get_windows)(struct iommu_domain *domain);
 
        unsigned long pgsize_bitmap;
 };