@@ -74,16 +74,19 @@ static struct qcom_iommu_domain *to_qcom_iommu_domain(struct iommu_domain *dom)
74
74
75
75
static const struct iommu_ops qcom_iommu_ops ;
76
76
77
- static struct qcom_iommu_dev * to_iommu (struct iommu_fwspec * fwspec )
77
+ static struct qcom_iommu_dev * to_iommu (struct device * dev )
78
78
{
79
+ struct iommu_fwspec * fwspec = dev_iommu_fwspec_get (dev );
80
+
79
81
if (!fwspec || fwspec -> ops != & qcom_iommu_ops )
80
82
return NULL ;
81
- return fwspec -> iommu_priv ;
83
+
84
+ return dev_iommu_priv_get (dev );
82
85
}
83
86
84
- static struct qcom_iommu_ctx * to_ctx (struct iommu_fwspec * fwspec , unsigned asid )
87
+ static struct qcom_iommu_ctx * to_ctx (struct device * dev , unsigned asid )
85
88
{
86
- struct qcom_iommu_dev * qcom_iommu = to_iommu (fwspec );
89
+ struct qcom_iommu_dev * qcom_iommu = to_iommu (dev );
87
90
if (!qcom_iommu )
88
91
return NULL ;
89
92
return qcom_iommu -> ctxs [asid - 1 ];
@@ -115,11 +118,14 @@ iommu_readq(struct qcom_iommu_ctx *ctx, unsigned reg)
115
118
116
119
static void qcom_iommu_tlb_sync (void * cookie )
117
120
{
118
- struct iommu_fwspec * fwspec = cookie ;
121
+ struct iommu_fwspec * fwspec ;
122
+ struct device * dev = cookie ;
119
123
unsigned i ;
120
124
125
+ fwspec = dev_iommu_fwspec_get (dev );
126
+
121
127
for (i = 0 ; i < fwspec -> num_ids ; i ++ ) {
122
- struct qcom_iommu_ctx * ctx = to_ctx (fwspec , fwspec -> ids [i ]);
128
+ struct qcom_iommu_ctx * ctx = to_ctx (dev , fwspec -> ids [i ]);
123
129
unsigned int val , ret ;
124
130
125
131
iommu_writel (ctx , ARM_SMMU_CB_TLBSYNC , 0 );
@@ -133,11 +139,14 @@ static void qcom_iommu_tlb_sync(void *cookie)
133
139
134
140
static void qcom_iommu_tlb_inv_context (void * cookie )
135
141
{
136
- struct iommu_fwspec * fwspec = cookie ;
142
+ struct device * dev = cookie ;
143
+ struct iommu_fwspec * fwspec ;
137
144
unsigned i ;
138
145
146
+ fwspec = dev_iommu_fwspec_get (dev );
147
+
139
148
for (i = 0 ; i < fwspec -> num_ids ; i ++ ) {
140
- struct qcom_iommu_ctx * ctx = to_ctx (fwspec , fwspec -> ids [i ]);
149
+ struct qcom_iommu_ctx * ctx = to_ctx (dev , fwspec -> ids [i ]);
141
150
iommu_writel (ctx , ARM_SMMU_CB_S1_TLBIASID , ctx -> asid );
142
151
}
143
152
@@ -147,13 +156,16 @@ static void qcom_iommu_tlb_inv_context(void *cookie)
147
156
static void qcom_iommu_tlb_inv_range_nosync (unsigned long iova , size_t size ,
148
157
size_t granule , bool leaf , void * cookie )
149
158
{
150
- struct iommu_fwspec * fwspec = cookie ;
159
+ struct device * dev = cookie ;
160
+ struct iommu_fwspec * fwspec ;
151
161
unsigned i , reg ;
152
162
153
163
reg = leaf ? ARM_SMMU_CB_S1_TLBIVAL : ARM_SMMU_CB_S1_TLBIVA ;
154
164
165
+ fwspec = dev_iommu_fwspec_get (dev );
166
+
155
167
for (i = 0 ; i < fwspec -> num_ids ; i ++ ) {
156
- struct qcom_iommu_ctx * ctx = to_ctx (fwspec , fwspec -> ids [i ]);
168
+ struct qcom_iommu_ctx * ctx = to_ctx (dev , fwspec -> ids [i ]);
157
169
size_t s = size ;
158
170
159
171
iova = (iova >> 12 ) << 12 ;
@@ -222,9 +234,10 @@ static irqreturn_t qcom_iommu_fault(int irq, void *dev)
222
234
223
235
static int qcom_iommu_init_domain (struct iommu_domain * domain ,
224
236
struct qcom_iommu_dev * qcom_iommu ,
225
- struct iommu_fwspec * fwspec )
237
+ struct device * dev )
226
238
{
227
239
struct qcom_iommu_domain * qcom_domain = to_qcom_iommu_domain (domain );
240
+ struct iommu_fwspec * fwspec = dev_iommu_fwspec_get (dev );
228
241
struct io_pgtable_ops * pgtbl_ops ;
229
242
struct io_pgtable_cfg pgtbl_cfg ;
230
243
int i , ret = 0 ;
@@ -243,7 +256,7 @@ static int qcom_iommu_init_domain(struct iommu_domain *domain,
243
256
};
244
257
245
258
qcom_domain -> iommu = qcom_iommu ;
246
- pgtbl_ops = alloc_io_pgtable_ops (ARM_32_LPAE_S1 , & pgtbl_cfg , fwspec );
259
+ pgtbl_ops = alloc_io_pgtable_ops (ARM_32_LPAE_S1 , & pgtbl_cfg , dev );
247
260
if (!pgtbl_ops ) {
248
261
dev_err (qcom_iommu -> dev , "failed to allocate pagetable ops\n" );
249
262
ret = - ENOMEM ;
@@ -256,7 +269,7 @@ static int qcom_iommu_init_domain(struct iommu_domain *domain,
256
269
domain -> geometry .force_aperture = true;
257
270
258
271
for (i = 0 ; i < fwspec -> num_ids ; i ++ ) {
259
- struct qcom_iommu_ctx * ctx = to_ctx (fwspec , fwspec -> ids [i ]);
272
+ struct qcom_iommu_ctx * ctx = to_ctx (dev , fwspec -> ids [i ]);
260
273
261
274
if (!ctx -> secure_init ) {
262
275
ret = qcom_scm_restore_sec_cfg (qcom_iommu -> sec_id , ctx -> asid );
@@ -363,8 +376,7 @@ static void qcom_iommu_domain_free(struct iommu_domain *domain)
363
376
364
377
static int qcom_iommu_attach_dev (struct iommu_domain * domain , struct device * dev )
365
378
{
366
- struct iommu_fwspec * fwspec = dev_iommu_fwspec_get (dev );
367
- struct qcom_iommu_dev * qcom_iommu = to_iommu (fwspec );
379
+ struct qcom_iommu_dev * qcom_iommu = to_iommu (dev );
368
380
struct qcom_iommu_domain * qcom_domain = to_qcom_iommu_domain (domain );
369
381
int ret ;
370
382
@@ -375,7 +387,7 @@ static int qcom_iommu_attach_dev(struct iommu_domain *domain, struct device *dev
375
387
376
388
/* Ensure that the domain is finalized */
377
389
pm_runtime_get_sync (qcom_iommu -> dev );
378
- ret = qcom_iommu_init_domain (domain , qcom_iommu , fwspec );
390
+ ret = qcom_iommu_init_domain (domain , qcom_iommu , dev );
379
391
pm_runtime_put_sync (qcom_iommu -> dev );
380
392
if (ret < 0 )
381
393
return ret ;
@@ -397,17 +409,17 @@ static int qcom_iommu_attach_dev(struct iommu_domain *domain, struct device *dev
397
409
398
410
static void qcom_iommu_detach_dev (struct iommu_domain * domain , struct device * dev )
399
411
{
400
- struct iommu_fwspec * fwspec = dev_iommu_fwspec_get (dev );
401
- struct qcom_iommu_dev * qcom_iommu = to_iommu (fwspec );
402
412
struct qcom_iommu_domain * qcom_domain = to_qcom_iommu_domain (domain );
413
+ struct iommu_fwspec * fwspec = dev_iommu_fwspec_get (dev );
414
+ struct qcom_iommu_dev * qcom_iommu = to_iommu (dev );
403
415
unsigned i ;
404
416
405
417
if (WARN_ON (!qcom_domain -> iommu ))
406
418
return ;
407
419
408
420
pm_runtime_get_sync (qcom_iommu -> dev );
409
421
for (i = 0 ; i < fwspec -> num_ids ; i ++ ) {
410
- struct qcom_iommu_ctx * ctx = to_ctx (fwspec , fwspec -> ids [i ]);
422
+ struct qcom_iommu_ctx * ctx = to_ctx (dev , fwspec -> ids [i ]);
411
423
412
424
/* Disable the context bank: */
413
425
iommu_writel (ctx , ARM_SMMU_CB_SCTLR , 0 );
@@ -514,7 +526,7 @@ static bool qcom_iommu_capable(enum iommu_cap cap)
514
526
515
527
static int qcom_iommu_add_device (struct device * dev )
516
528
{
517
- struct qcom_iommu_dev * qcom_iommu = to_iommu (dev_iommu_fwspec_get ( dev ) );
529
+ struct qcom_iommu_dev * qcom_iommu = to_iommu (dev );
518
530
struct iommu_group * group ;
519
531
struct device_link * link ;
520
532
@@ -545,7 +557,7 @@ static int qcom_iommu_add_device(struct device *dev)
545
557
546
558
static void qcom_iommu_remove_device (struct device * dev )
547
559
{
548
- struct qcom_iommu_dev * qcom_iommu = to_iommu (dev_iommu_fwspec_get ( dev ) );
560
+ struct qcom_iommu_dev * qcom_iommu = to_iommu (dev );
549
561
550
562
if (!qcom_iommu )
551
563
return ;
@@ -557,7 +569,6 @@ static void qcom_iommu_remove_device(struct device *dev)
557
569
558
570
static int qcom_iommu_of_xlate (struct device * dev , struct of_phandle_args * args )
559
571
{
560
- struct iommu_fwspec * fwspec = dev_iommu_fwspec_get (dev );
561
572
struct qcom_iommu_dev * qcom_iommu ;
562
573
struct platform_device * iommu_pdev ;
563
574
unsigned asid = args -> args [0 ];
@@ -583,14 +594,14 @@ static int qcom_iommu_of_xlate(struct device *dev, struct of_phandle_args *args)
583
594
WARN_ON (asid > qcom_iommu -> num_ctxs ))
584
595
return - EINVAL ;
585
596
586
- if (!fwspec -> iommu_priv ) {
587
- fwspec -> iommu_priv = qcom_iommu ;
597
+ if (!dev_iommu_priv_get ( dev ) ) {
598
+ dev_iommu_priv_set ( dev , qcom_iommu ) ;
588
599
} else {
589
600
/* make sure devices iommus dt node isn't referring to
590
601
* multiple different iommu devices. Multiple context
591
602
* banks are ok, but multiple devices are not:
592
603
*/
593
- if (WARN_ON (qcom_iommu != fwspec -> iommu_priv ))
604
+ if (WARN_ON (qcom_iommu != dev_iommu_priv_get ( dev ) ))
594
605
return - EINVAL ;
595
606
}
596
607
0 commit comments