Skip to content

Commit a9bf2ee

Browse files
committed
iommu/mediatek: Use helper functions to access dev->iommu_fwspec
Use the new helpers dev_iommu_fwspec_get()/set() to access the dev->iommu_fwspec pointer. This makes it easier to move that pointer later into another struct. Cc: Matthias Brugger <matthias.bgg@gmail.com> Tested-by: Yong Wu <yong.wu@mediatek.com> Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent df90365 commit a9bf2ee

File tree

2 files changed

+28
-21
lines changed

2 files changed

+28
-21
lines changed

drivers/iommu/mtk_iommu.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ static void mtk_iommu_config(struct mtk_iommu_data *data,
244244
{
245245
struct mtk_smi_larb_iommu *larb_mmu;
246246
unsigned int larbid, portid;
247-
struct iommu_fwspec *fwspec = dev->iommu_fwspec;
247+
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
248248
int i;
249249

250250
for (i = 0; i < fwspec->num_ids; ++i) {
@@ -336,7 +336,7 @@ static int mtk_iommu_attach_device(struct iommu_domain *domain,
336336
struct device *dev)
337337
{
338338
struct mtk_iommu_domain *dom = to_mtk_domain(domain);
339-
struct mtk_iommu_data *data = dev->iommu_fwspec->iommu_priv;
339+
struct mtk_iommu_data *data = dev_iommu_fwspec_get(dev)->iommu_priv;
340340

341341
if (!data)
342342
return -ENODEV;
@@ -355,7 +355,7 @@ static int mtk_iommu_attach_device(struct iommu_domain *domain,
355355
static void mtk_iommu_detach_device(struct iommu_domain *domain,
356356
struct device *dev)
357357
{
358-
struct mtk_iommu_data *data = dev->iommu_fwspec->iommu_priv;
358+
struct mtk_iommu_data *data = dev_iommu_fwspec_get(dev)->iommu_priv;
359359

360360
if (!data)
361361
return;
@@ -417,13 +417,14 @@ static phys_addr_t mtk_iommu_iova_to_phys(struct iommu_domain *domain,
417417

418418
static int mtk_iommu_add_device(struct device *dev)
419419
{
420+
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
420421
struct mtk_iommu_data *data;
421422
struct iommu_group *group;
422423

423-
if (!dev->iommu_fwspec || dev->iommu_fwspec->ops != &mtk_iommu_ops)
424+
if (!fwspec || fwspec->ops != &mtk_iommu_ops)
424425
return -ENODEV; /* Not a iommu client device */
425426

426-
data = dev->iommu_fwspec->iommu_priv;
427+
data = fwspec->iommu_priv;
427428
iommu_device_link(&data->iommu, dev);
428429

429430
group = iommu_group_get_for_dev(dev);
@@ -436,12 +437,13 @@ static int mtk_iommu_add_device(struct device *dev)
436437

437438
static void mtk_iommu_remove_device(struct device *dev)
438439
{
440+
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
439441
struct mtk_iommu_data *data;
440442

441-
if (!dev->iommu_fwspec || dev->iommu_fwspec->ops != &mtk_iommu_ops)
443+
if (!fwspec || fwspec->ops != &mtk_iommu_ops)
442444
return;
443445

444-
data = dev->iommu_fwspec->iommu_priv;
446+
data = fwspec->iommu_priv;
445447
iommu_device_unlink(&data->iommu, dev);
446448

447449
iommu_group_remove_device(dev);
@@ -468,6 +470,7 @@ static struct iommu_group *mtk_iommu_device_group(struct device *dev)
468470

469471
static int mtk_iommu_of_xlate(struct device *dev, struct of_phandle_args *args)
470472
{
473+
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
471474
struct platform_device *m4updev;
472475

473476
if (args->args_count != 1) {
@@ -476,13 +479,13 @@ static int mtk_iommu_of_xlate(struct device *dev, struct of_phandle_args *args)
476479
return -EINVAL;
477480
}
478481

479-
if (!dev->iommu_fwspec->iommu_priv) {
482+
if (!fwspec->iommu_priv) {
480483
/* Get the m4u device */
481484
m4updev = of_find_device_by_node(args->np);
482485
if (WARN_ON(!m4updev))
483486
return -EINVAL;
484487

485-
dev->iommu_fwspec->iommu_priv = platform_get_drvdata(m4updev);
488+
fwspec->iommu_priv = platform_get_drvdata(m4updev);
486489
}
487490

488491
return iommu_fwspec_add_ids(dev, args->args, 1);

drivers/iommu/mtk_iommu_v1.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ static void mtk_iommu_config(struct mtk_iommu_data *data,
208208
{
209209
struct mtk_smi_larb_iommu *larb_mmu;
210210
unsigned int larbid, portid;
211-
struct iommu_fwspec *fwspec = dev->iommu_fwspec;
211+
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
212212
int i;
213213

214214
for (i = 0; i < fwspec->num_ids; ++i) {
@@ -273,7 +273,7 @@ static int mtk_iommu_attach_device(struct iommu_domain *domain,
273273
struct device *dev)
274274
{
275275
struct mtk_iommu_domain *dom = to_mtk_domain(domain);
276-
struct mtk_iommu_data *data = dev->iommu_fwspec->iommu_priv;
276+
struct mtk_iommu_data *data = dev_iommu_fwspec_get(dev)->iommu_priv;
277277
int ret;
278278

279279
if (!data)
@@ -295,7 +295,7 @@ static int mtk_iommu_attach_device(struct iommu_domain *domain,
295295
static void mtk_iommu_detach_device(struct iommu_domain *domain,
296296
struct device *dev)
297297
{
298-
struct mtk_iommu_data *data = dev->iommu_fwspec->iommu_priv;
298+
struct mtk_iommu_data *data = dev_iommu_fwspec_get(dev)->iommu_priv;
299299

300300
if (!data)
301301
return;
@@ -373,6 +373,7 @@ static struct iommu_ops mtk_iommu_ops;
373373
static int mtk_iommu_create_mapping(struct device *dev,
374374
struct of_phandle_args *args)
375375
{
376+
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
376377
struct mtk_iommu_data *data;
377378
struct platform_device *m4updev;
378379
struct dma_iommu_mapping *mtk_mapping;
@@ -385,28 +386,29 @@ static int mtk_iommu_create_mapping(struct device *dev,
385386
return -EINVAL;
386387
}
387388

388-
if (!dev->iommu_fwspec) {
389+
if (!fwspec) {
389390
ret = iommu_fwspec_init(dev, &args->np->fwnode, &mtk_iommu_ops);
390391
if (ret)
391392
return ret;
392-
} else if (dev->iommu_fwspec->ops != &mtk_iommu_ops) {
393+
fwspec = dev_iommu_fwspec_get(dev);
394+
} else if (dev_iommu_fwspec_get(dev)->ops != &mtk_iommu_ops) {
393395
return -EINVAL;
394396
}
395397

396-
if (!dev->iommu_fwspec->iommu_priv) {
398+
if (!fwspec->iommu_priv) {
397399
/* Get the m4u device */
398400
m4updev = of_find_device_by_node(args->np);
399401
if (WARN_ON(!m4updev))
400402
return -EINVAL;
401403

402-
dev->iommu_fwspec->iommu_priv = platform_get_drvdata(m4updev);
404+
fwspec->iommu_priv = platform_get_drvdata(m4updev);
403405
}
404406

405407
ret = iommu_fwspec_add_ids(dev, args->args, 1);
406408
if (ret)
407409
return ret;
408410

409-
data = dev->iommu_fwspec->iommu_priv;
411+
data = fwspec->iommu_priv;
410412
m4udev = data->dev;
411413
mtk_mapping = m4udev->archdata.iommu;
412414
if (!mtk_mapping) {
@@ -424,6 +426,7 @@ static int mtk_iommu_create_mapping(struct device *dev,
424426

425427
static int mtk_iommu_add_device(struct device *dev)
426428
{
429+
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
427430
struct dma_iommu_mapping *mtk_mapping;
428431
struct of_phandle_args iommu_spec;
429432
struct of_phandle_iterator it;
@@ -442,7 +445,7 @@ static int mtk_iommu_add_device(struct device *dev)
442445
of_node_put(iommu_spec.np);
443446
}
444447

445-
if (!dev->iommu_fwspec || dev->iommu_fwspec->ops != &mtk_iommu_ops)
448+
if (!fwspec || fwspec->ops != &mtk_iommu_ops)
446449
return -ENODEV; /* Not a iommu client device */
447450

448451
/*
@@ -460,7 +463,7 @@ static int mtk_iommu_add_device(struct device *dev)
460463
if (err)
461464
return err;
462465

463-
data = dev->iommu_fwspec->iommu_priv;
466+
data = fwspec->iommu_priv;
464467
mtk_mapping = data->dev->archdata.iommu;
465468
err = arm_iommu_attach_device(dev, mtk_mapping);
466469
if (err) {
@@ -473,12 +476,13 @@ static int mtk_iommu_add_device(struct device *dev)
473476

474477
static void mtk_iommu_remove_device(struct device *dev)
475478
{
479+
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
476480
struct mtk_iommu_data *data;
477481

478-
if (!dev->iommu_fwspec || dev->iommu_fwspec->ops != &mtk_iommu_ops)
482+
if (!fwspec || fwspec->ops != &mtk_iommu_ops)
479483
return;
480484

481-
data = dev->iommu_fwspec->iommu_priv;
485+
data = fwspec->iommu_priv;
482486
iommu_device_unlink(&data->iommu, dev);
483487

484488
iommu_group_remove_device(dev);

0 commit comments

Comments
 (0)