Commit 693567125bde1966a095267a9d8ca1b8d40f59ee

Authored by Joerg Roedel
1 parent d7787d579c

iommu: Add DOMAIN_ATTR_WINDOWS domain attribute

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>

Showing 2 changed files with 35 additions and 3 deletions Side-by-side Diff

drivers/iommu/iommu.c
... ... @@ -891,6 +891,7 @@
891 891 struct iommu_domain_geometry *geometry;
892 892 bool *paging;
893 893 int ret = 0;
  894 + u32 *count;
894 895  
895 896 switch (attr) {
896 897 case DOMAIN_ATTR_GEOMETRY:
... ... @@ -902,6 +903,15 @@
902 903 paging = data;
903 904 *paging = (domain->ops->pgsize_bitmap != 0UL);
904 905 break;
  906 + case DOMAIN_ATTR_WINDOWS:
  907 + count = data;
  908 +
  909 + if (domain->ops->domain_get_windows != NULL)
  910 + *count = domain->ops->domain_get_windows(domain);
  911 + else
  912 + ret = -ENODEV;
  913 +
  914 + break;
905 915 default:
906 916 if (!domain->ops->domain_get_attr)
907 917 return -EINVAL;
908 918  
... ... @@ -916,10 +926,27 @@
916 926 int iommu_domain_set_attr(struct iommu_domain *domain,
917 927 enum iommu_attr attr, void *data)
918 928 {
919   - if (!domain->ops->domain_set_attr)
920   - return -EINVAL;
  929 + int ret = 0;
  930 + u32 *count;
921 931  
922   - return domain->ops->domain_set_attr(domain, attr, data);
  932 + switch (attr) {
  933 + case DOMAIN_ATTR_WINDOWS:
  934 + count = data;
  935 +
  936 + if (domain->ops->domain_set_windows != NULL)
  937 + ret = domain->ops->domain_set_windows(domain, *count);
  938 + else
  939 + ret = -ENODEV;
  940 +
  941 + break;
  942 + default:
  943 + if (domain->ops->domain_set_attr == NULL)
  944 + return -EINVAL;
  945 +
  946 + ret = domain->ops->domain_set_attr(domain, attr, data);
  947 + }
  948 +
  949 + return ret;
923 950 }
924 951 EXPORT_SYMBOL_GPL(iommu_domain_set_attr);
include/linux/iommu.h
... ... @@ -60,6 +60,7 @@
60 60 enum iommu_attr {
61 61 DOMAIN_ATTR_GEOMETRY,
62 62 DOMAIN_ATTR_PAGING,
  63 + DOMAIN_ATTR_WINDOWS,
63 64 DOMAIN_ATTR_MAX,
64 65 };
65 66  
... ... @@ -106,6 +107,10 @@
106 107 int (*domain_window_enable)(struct iommu_domain *domain, u32 wnd_nr,
107 108 phys_addr_t paddr, u64 size);
108 109 void (*domain_window_disable)(struct iommu_domain *domain, u32 wnd_nr);
  110 + /* Set the numer of window per domain */
  111 + int (*domain_set_windows)(struct iommu_domain *domain, u32 w_count);
  112 + /* Get the numer of window per domain */
  113 + u32 (*domain_get_windows)(struct iommu_domain *domain);
109 114  
110 115 unsigned long pgsize_bitmap;
111 116 };