@@ -223,8 +223,16 @@ static int mock_domain_nop_attach(struct iommu_domain *domain,
223
223
return 0 ;
224
224
}
225
225
226
+ static int mock_domain_set_dev_pasid_nop (struct iommu_domain * domain ,
227
+ struct device * dev , ioasid_t pasid ,
228
+ struct iommu_domain * old )
229
+ {
230
+ return 0 ;
231
+ }
232
+
226
233
static const struct iommu_domain_ops mock_blocking_ops = {
227
234
.attach_dev = mock_domain_nop_attach ,
235
+ .set_dev_pasid = mock_domain_set_dev_pasid_nop
228
236
};
229
237
230
238
static struct iommu_domain mock_blocking_domain = {
@@ -366,7 +374,7 @@ mock_domain_alloc_nested(struct device *dev, struct iommu_domain *parent,
366
374
struct mock_iommu_domain_nested * mock_nested ;
367
375
struct mock_iommu_domain * mock_parent ;
368
376
369
- if (flags )
377
+ if (flags & ~ IOMMU_HWPT_ALLOC_PASID )
370
378
return ERR_PTR (- EOPNOTSUPP );
371
379
if (!parent || parent -> ops != mock_ops .default_domain_ops )
372
380
return ERR_PTR (- EINVAL );
@@ -388,7 +396,8 @@ mock_domain_alloc_paging_flags(struct device *dev, u32 flags,
388
396
{
389
397
bool has_dirty_flag = flags & IOMMU_HWPT_ALLOC_DIRTY_TRACKING ;
390
398
const u32 PAGING_FLAGS = IOMMU_HWPT_ALLOC_DIRTY_TRACKING |
391
- IOMMU_HWPT_ALLOC_NEST_PARENT ;
399
+ IOMMU_HWPT_ALLOC_NEST_PARENT |
400
+ IOMMU_HWPT_ALLOC_PASID ;
392
401
struct mock_dev * mdev = to_mock_dev (dev );
393
402
bool no_dirty_ops = mdev -> flags & MOCK_FLAGS_DEVICE_NO_DIRTY ;
394
403
struct mock_iommu_domain * mock ;
@@ -608,7 +617,7 @@ mock_viommu_alloc_domain_nested(struct iommufd_viommu *viommu, u32 flags,
608
617
struct mock_viommu * mock_viommu = to_mock_viommu (viommu );
609
618
struct mock_iommu_domain_nested * mock_nested ;
610
619
611
- if (flags )
620
+ if (flags & ~ IOMMU_HWPT_ALLOC_PASID )
612
621
return ERR_PTR (- EOPNOTSUPP );
613
622
614
623
mock_nested = __mock_domain_alloc_nested (user_data );
@@ -743,6 +752,7 @@ static const struct iommu_ops mock_ops = {
743
752
.map_pages = mock_domain_map_pages ,
744
753
.unmap_pages = mock_domain_unmap_pages ,
745
754
.iova_to_phys = mock_domain_iova_to_phys ,
755
+ .set_dev_pasid = mock_domain_set_dev_pasid_nop ,
746
756
},
747
757
};
748
758
@@ -803,6 +813,7 @@ static struct iommu_domain_ops domain_nested_ops = {
803
813
.free = mock_domain_free_nested ,
804
814
.attach_dev = mock_domain_nop_attach ,
805
815
.cache_invalidate_user = mock_domain_cache_invalidate_user ,
816
+ .set_dev_pasid = mock_domain_set_dev_pasid_nop ,
806
817
};
807
818
808
819
static inline struct iommufd_hw_pagetable *
@@ -862,11 +873,17 @@ static void mock_dev_release(struct device *dev)
862
873
863
874
static struct mock_dev * mock_dev_create (unsigned long dev_flags )
864
875
{
876
+ struct property_entry prop [] = {
877
+ PROPERTY_ENTRY_U32 ("pasid-num-bits" , 0 ),
878
+ {},
879
+ };
880
+ const u32 valid_flags = MOCK_FLAGS_DEVICE_NO_DIRTY |
881
+ MOCK_FLAGS_DEVICE_HUGE_IOVA |
882
+ MOCK_FLAGS_DEVICE_PASID ;
865
883
struct mock_dev * mdev ;
866
884
int rc , i ;
867
885
868
- if (dev_flags &
869
- ~(MOCK_FLAGS_DEVICE_NO_DIRTY | MOCK_FLAGS_DEVICE_HUGE_IOVA ))
886
+ if (dev_flags & ~valid_flags )
870
887
return ERR_PTR (- EINVAL );
871
888
872
889
mdev = kzalloc (sizeof (* mdev ), GFP_KERNEL );
@@ -890,6 +907,15 @@ static struct mock_dev *mock_dev_create(unsigned long dev_flags)
890
907
if (rc )
891
908
goto err_put ;
892
909
910
+ if (dev_flags & MOCK_FLAGS_DEVICE_PASID )
911
+ prop [0 ] = PROPERTY_ENTRY_U32 ("pasid-num-bits" , MOCK_PASID_WIDTH );
912
+
913
+ rc = device_create_managed_software_node (& mdev -> dev , prop , NULL );
914
+ if (rc ) {
915
+ dev_err (& mdev -> dev , "add pasid-num-bits property failed, rc: %d" , rc );
916
+ goto err_put ;
917
+ }
918
+
893
919
rc = device_add (& mdev -> dev );
894
920
if (rc )
895
921
goto err_put ;
@@ -1778,6 +1804,7 @@ int __init iommufd_test_init(void)
1778
1804
init_completion (& mock_iommu .complete );
1779
1805
1780
1806
mock_iommu_iopf_queue = iopf_queue_alloc ("mock-iopfq" );
1807
+ mock_iommu .iommu_dev .max_pasids = (1 << MOCK_PASID_WIDTH );
1781
1808
1782
1809
return 0 ;
1783
1810
0 commit comments