Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: iommu/mediatek: Add device_link between the consumer and the larb devices

MediaTek IOMMU-SMI diagram is like below. all the consumer connect with
smi-larb, then connect with smi-common.

M4U
|
smi-common
|
-------------
| | ...
| |
larb1 larb2
| |
vdec venc

When the consumer works, it should enable the smi-larb's power which
also need enable the smi-common's power firstly.

Thus, First of all, use the device link connect the consumer and the
smi-larbs. then add device link between the smi-larb and smi-common.

This patch adds device_link between the consumer and the larbs.

When device_link_add, I add the flag DL_FLAG_STATELESS to avoid calling
pm_runtime_xx to keep the original status of clocks. It can avoid two
issues:
1) Display HW show fastlogo abnormally reported in [1]. At the beggining,
all the clocks are enabled before entering kernel, but the clocks for
display HW(always in larb0) will be gated after clk_enable and clk_disable
called from device_link_add(->pm_runtime_resume) and rpm_idle. The clock
operation happened before display driver probe. At that time, the display
HW will be abnormal.

2) A deadlock issue reported in [2]. Use DL_FLAG_STATELESS to skip
pm_runtime_xx to avoid the deadlock.

Corresponding, DL_FLAG_AUTOREMOVE_CONSUMER can't be added, then
device_link_removed should be added explicitly.

Meanwhile, Currently we don't have a device connect with 2 larbs at the
same time. Disallow this case, print the error log.

[1] https://lore.kernel.org/linux-mediatek/1564213888.22908.4.camel@mhfsdcap03/
[2] https://lore.kernel.org/patchwork/patch/1086569/

Suggested-by: Tomasz Figa <tfiga@chromium.org>
Signed-off-by: Yong Wu <yong.wu@mediatek.com>
Tested-by: Frank Wunderlich <frank-w@public-files.de> # BPI-R2/MT7623
Acked-by: Joerg Roedel <jroedel@suse.de>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>

authored by

Yong Wu and committed by
Mauro Carvalho Chehab
635319a4 7d09aaf8

+58 -1
+30
drivers/iommu/mtk_iommu.c
··· 562 562 { 563 563 struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); 564 564 struct mtk_iommu_data *data; 565 + struct device_link *link; 566 + struct device *larbdev; 567 + unsigned int larbid, larbidx, i; 565 568 566 569 if (!fwspec || fwspec->ops != &mtk_iommu_ops) 567 570 return ERR_PTR(-ENODEV); /* Not a iommu client device */ 568 571 569 572 data = dev_iommu_priv_get(dev); 570 573 574 + /* 575 + * Link the consumer device with the smi-larb device(supplier). 576 + * The device that connects with each a larb is a independent HW. 577 + * All the ports in each a device should be in the same larbs. 578 + */ 579 + larbid = MTK_M4U_TO_LARB(fwspec->ids[0]); 580 + for (i = 1; i < fwspec->num_ids; i++) { 581 + larbidx = MTK_M4U_TO_LARB(fwspec->ids[i]); 582 + if (larbid != larbidx) { 583 + dev_err(dev, "Can only use one larb. Fail@larb%d-%d.\n", 584 + larbid, larbidx); 585 + return ERR_PTR(-EINVAL); 586 + } 587 + } 588 + larbdev = data->larb_imu[larbid].dev; 589 + link = device_link_add(dev, larbdev, 590 + DL_FLAG_PM_RUNTIME | DL_FLAG_STATELESS); 591 + if (!link) 592 + dev_err(dev, "Unable to link %s\n", dev_name(larbdev)); 571 593 return &data->iommu; 572 594 } 573 595 574 596 static void mtk_iommu_release_device(struct device *dev) 575 597 { 576 598 struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); 599 + struct mtk_iommu_data *data; 600 + struct device *larbdev; 601 + unsigned int larbid; 577 602 578 603 if (!fwspec || fwspec->ops != &mtk_iommu_ops) 579 604 return; 605 + 606 + data = dev_iommu_priv_get(dev); 607 + larbid = MTK_M4U_TO_LARB(fwspec->ids[0]); 608 + larbdev = data->larb_imu[larbid].dev; 609 + device_link_remove(dev, larbdev); 580 610 581 611 iommu_fwspec_free(dev); 582 612 }
+28 -1
drivers/iommu/mtk_iommu_v1.c
··· 423 423 struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); 424 424 struct of_phandle_args iommu_spec; 425 425 struct mtk_iommu_data *data; 426 - int err, idx = 0; 426 + int err, idx = 0, larbid, larbidx; 427 + struct device_link *link; 428 + struct device *larbdev; 427 429 428 430 /* 429 431 * In the deferred case, free the existed fwspec. ··· 455 453 456 454 data = dev_iommu_priv_get(dev); 457 455 456 + /* Link the consumer device with the smi-larb device(supplier) */ 457 + larbid = mt2701_m4u_to_larb(fwspec->ids[0]); 458 + for (idx = 1; idx < fwspec->num_ids; idx++) { 459 + larbidx = mt2701_m4u_to_larb(fwspec->ids[idx]); 460 + if (larbid != larbidx) { 461 + dev_err(dev, "Can only use one larb. Fail@larb%d-%d.\n", 462 + larbid, larbidx); 463 + return ERR_PTR(-EINVAL); 464 + } 465 + } 466 + 467 + larbdev = data->larb_imu[larbid].dev; 468 + link = device_link_add(dev, larbdev, 469 + DL_FLAG_PM_RUNTIME | DL_FLAG_STATELESS); 470 + if (!link) 471 + dev_err(dev, "Unable to link %s\n", dev_name(larbdev)); 472 + 458 473 return &data->iommu; 459 474 } 460 475 ··· 492 473 static void mtk_iommu_release_device(struct device *dev) 493 474 { 494 475 struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); 476 + struct mtk_iommu_data *data; 477 + struct device *larbdev; 478 + unsigned int larbid; 495 479 496 480 if (!fwspec || fwspec->ops != &mtk_iommu_ops) 497 481 return; 482 + 483 + data = dev_iommu_priv_get(dev); 484 + larbid = mt2701_m4u_to_larb(fwspec->ids[0]); 485 + larbdev = data->larb_imu[larbid].dev; 486 + device_link_remove(dev, larbdev); 498 487 499 488 iommu_fwspec_free(dev); 500 489 }