mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Marek Szyprowski <m.szyprowski@samsung.com>
To: "myunggeun.ji" <myunggeun.ji@samsung.com>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Alim Akhtar <alim.akhtar@samsung.com>,
	Joerg Roedel <joro@8bytes.org>, Will Deacon <will@kernel.org>,
	Robin Murphy <robin.murphy@arm.com>,
	devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-samsung-soc@vger.kernel.org, linux-kernel@vger.kernel.org,
	iommu@lists.linux.dev
Cc: Jongho Park <jongho0910.park@samsung.com>,
	kiisung lee <kiisung.lee@samsung.com>
Subject: Re: [PATCH 1/2] iommu/exynos: Implement register set and fault handling on SysMMU v9
Date: Tue, 16 Sep 2025 08:36:29 +0200	[thread overview]
Message-ID: <65e3d97e-4a24-4696-9bca-c3f7833144d2@samsung.com> (raw)
In-Reply-To: <20250915051320.3378957-2-myunggeun.ji@samsung.com>

On 15.09.2025 07:13, myunggeun.ji wrote:
> SysMMU v9 has a bit different registers.
> - Major and Minor version BIT are changed to BIT[31:28] and BIT[27:24]
> - FLPT(First Level Page Table) offset is changed.
> - interrupt status register has different bits w.r.t. previous SysMMU
>    versions
>
> Add correct register set and fault handling  for SysMMU v9,
> according to all mentioned differences.
>
> Signed-off-by: myunggeun.ji <myunggeun.ji@samsung.com>
> ---
>   drivers/iommu/exynos-iommu.c | 73 +++++++++++++++++++++++++++++++-----
>   1 file changed, 64 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/iommu/exynos-iommu.c b/drivers/iommu/exynos-iommu.c
> index b6edd178fe25..00f4129a7bf2 100644
> --- a/drivers/iommu/exynos-iommu.c
> +++ b/drivers/iommu/exynos-iommu.c
> @@ -152,7 +152,9 @@ static u32 lv2ent_offset(sysmmu_iova_t iova)
>   
>   #define MMU_MAJ_VER(val)	((val) >> 7)
>   #define MMU_MIN_VER(val)	((val) & 0x7F)
> -#define MMU_RAW_VER(reg)	(((reg) >> 21) & ((1 << 11) - 1)) /* 11 bits */
> +#define MMU_RAW_VER(reg)	(((reg) >> 28 < 7) ? \
> +				(((reg) >> 21) & ((1 << 11) - 1)) : \
> +				(((reg) >> 24) & ((1 << 8) - 1)))
>   
>   #define MAKE_MMU_VER(maj, min)	((((maj) & 0xF) << 7) | ((min) & 0x7F))
>   
> @@ -171,6 +173,17 @@ static u32 lv2ent_offset(sysmmu_iova_t iova)
>   #define REG_V7_CAPA1		0x874
>   #define REG_V7_CTRL_VM		0x8000
>   
> +/* v9.x registers */
> +#define REG_V9_CTRL_VM				0x8000
> +#define REG_MMU_CONTEXT0_CFG_ATTRIBUTE_VM       0x8408
> +
> +#define MMU_MAJ_VER_V9(val)		((val) >> 4)
> +#define MMU_MIN_VER_V9(val)		((val) & 0xF)
> +#define MMU_RAW_VER_V9(reg)		(((reg) >> 24) & ((1 << 8) - 1)) /* 8 bits */
> +
> +#define MAKE_MMU_VER_V9(maj, min)	((((maj) & 0xF) << 7) | ((min) & 0xF))
> +#define MAKE_MMU_VM_OFFSET(vid)		((vid) * 0x1000)
> +
>   #define has_sysmmu(dev)		(dev_iommu_priv_get(dev) != NULL)
>   
>   static struct device *dma_dev;
> @@ -228,6 +241,14 @@ static const char * const sysmmu_v7_fault_names[] = {
>   	"RESERVED"
>   };
>   
> +static const char * const sysmmu_v9_fault_names[] = {
> +	"PTW",
> +	"PAGE",
> +	"ACCESS PROTECTION",
> +	"CONTEXT_FAULT",
> +	"RESERVED"
> +};
> +
>   /*
>    * This structure is attached to dev->iommu->priv of the master device
>    * on device add, contains a list of SYSMMU controllers defined by device tree,
> @@ -363,6 +384,19 @@ static int exynos_sysmmu_v7_get_fault_info(struct sysmmu_drvdata *data,
>   	return 0;
>   }
>   
> +static int exynos_sysmmu_v9_get_fault_info(struct sysmmu_drvdata *data,
> +					   unsigned int itype,
> +					   struct sysmmu_fault *fault)
> +{
> +	u32 info = readl(SYSMMU_REG(data, fault_info));
> +
> +	fault->addr = readl(SYSMMU_REG(data, fault_va));
> +	fault->name = sysmmu_v9_fault_names[itype % 5];
> +	fault->type = (info & BIT(20)) ? IOMMU_FAULT_WRITE : IOMMU_FAULT_READ;
> +
> +	return 0;
> +}
> +
>   /* SysMMU v1..v3 */
>   static const struct sysmmu_variant sysmmu_v1_variant = {
>   	.flush_all	= 0x0c,
> @@ -420,6 +454,21 @@ static const struct sysmmu_variant sysmmu_v7_vm_variant = {
>   	.get_fault_info	= exynos_sysmmu_v7_get_fault_info,
>   };
>   
> +/* SysMMU v9: VM capable register layout */
> +static const struct sysmmu_variant sysmmu_v9_vm_variant = {
> +	.pt_base        = 0x8404,
> +	.flush_all      = 0x8010,
> +	.flush_entry    = 0x8014,
> +	.flush_start    = 0x8020,
> +	.flush_end      = 0x8024,
> +	.int_status     = 0x8060,
> +	.int_clear      = 0x8064,
> +	.fault_va       = 0x8070,
> +	.fault_info     = 0x8074,
> +
> +	.get_fault_info = exynos_sysmmu_v9_get_fault_info,
> +};
> +
>   static struct exynos_iommu_domain *to_exynos_domain(struct iommu_domain *dom)
>   {
>   	return container_of(dom, struct exynos_iommu_domain, domain);
> @@ -522,19 +571,26 @@ static void __sysmmu_get_version(struct sysmmu_drvdata *data)
>   	ver = readl(data->sfrbase + REG_MMU_VERSION);
>   
>   	/* controllers on some SoCs don't report proper version */
> +
>   	if (ver == 0x80000001u)
>   		data->version = MAKE_MMU_VER(1, 0);
>   	else
>   		data->version = MMU_RAW_VER(ver);
>   
> -	dev_dbg(data->sysmmu, "hardware version: %d.%d\n",
> -		MMU_MAJ_VER(data->version), MMU_MIN_VER(data->version));
> +	if (data->version != 0x91)
> +		dev_err(data->sysmmu, "hardware version: %d.%d\n",
> +			MMU_MAJ_VER(data->version), MMU_MIN_VER(data->version));
> +	else if (data->version == 0x91)
> +		dev_err(data->sysmmu, "hardware version: %d.%d\n",
> +			MMU_MAJ_VER_V9(data->version), MMU_MIN_VER_V9(data->version));

Sorry, this starts looking over-engineered. Simply split data->version 
into data->major_version and data->minor_version and fill them with 
proper values. There is no point storing them together differently for 
each hw version and then decoding in each use.


>   
> -	if (MMU_MAJ_VER(data->version) < 5) {
> +	if (data->version == 0x91) {
> +		data->variant = &sysmmu_v9_vm_variant;
> +	} else if (MMU_MAJ_VER(data->version) < 5) {
>   		data->variant = &sysmmu_v1_variant;
>   	} else if (MMU_MAJ_VER(data->version) < 7) {
>   		data->variant = &sysmmu_v5_variant;
> -	} else {
> +	} else if (MMU_MAJ_VER(data->version) < 9) {
>   		if (__sysmmu_has_capa1(data))
>   			__sysmmu_get_vcr(data);
>   		if (data->has_vcr)
> @@ -763,10 +819,9 @@ static int exynos_sysmmu_probe(struct platform_device *pdev)
>   	if (IS_ERR(data->pclk))
>   		return PTR_ERR(data->pclk);
>   
> -	if (!data->clk && (!data->aclk || !data->pclk)) {
> -		dev_err(dev, "Failed to get device clock(s)!\n");
> -		return -ENOSYS;
> -	}
> +	/* There is no clock information after v9 */
> +	if (!data->clk && (!data->aclk || !data->pclk))
> +		dev_warn(dev, "Failed to get device clock(s)!\n");

If there is really no separate clock to control, then check that 
explicitly instead of printing a misleading warning.

>   	data->clk_master = devm_clk_get_optional(dev, "master");
>   	if (IS_ERR(data->clk_master))

Best regards
-- 
Marek Szyprowski, PhD
Samsung R&D Institute Poland


  parent reply	other threads:[~2025-09-16  6:36 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20250915051106epcas2p19c54f69c993621430aac622c6865919b@epcas2p1.samsung.com>
2025-09-15  5:13 ` [PATCH 0/2] update exynos-iommu code and device tree for v9 myunggeun.ji
     [not found]   ` <CGME20250915051106epcas2p1c1bdb06ec2ec65aad8a96ffe155ed8b6@epcas2p1.samsung.com>
2025-09-15  5:13     ` [PATCH 1/2] iommu/exynos: Implement register set and fault handling on SysMMU v9 myunggeun.ji
2025-09-15  7:13       ` Krzysztof Kozlowski
2025-09-16  6:36       ` Marek Szyprowski [this message]
     [not found]   ` <CGME20250915051106epcas2p37bc7519afa767689f6ea23b2dde9fb61@epcas2p3.samsung.com>
2025-09-15  5:13     ` [PATCH 2/2] arm64: dts: exynosautov920: Add DT node for sysMMU myunggeun.ji

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=65e3d97e-4a24-4696-9bca-c3f7833144d2@samsung.com \
    --to=m.szyprowski@samsung.com \
    --cc=alim.akhtar@samsung.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=iommu@lists.linux.dev \
    --cc=jongho0910.park@samsung.com \
    --cc=joro@8bytes.org \
    --cc=kiisung.lee@samsung.com \
    --cc=krzk+dt@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-samsung-soc@vger.kernel.org \
    --cc=myunggeun.ji@samsung.com \
    --cc=robh@kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®