All of lore.kernel.org
 help / color / mirror / Atom feed
From: Heiko Stuebner <heiko-4mtYJXux2i+zQB+pC5nmwQ@public.gmane.org>
To: xxm <xxm-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
Cc: linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH V2 2/3] iommu/rockchip: add multi irqs support
Date: Fri, 21 Jul 2017 20:37:02 +0200	[thread overview]
Message-ID: <1622328.YERcK565Fd@phil> (raw)
In-Reply-To: <675fd7bf-7551-4f95-9b9c-8a2151e59ee1-TNX95d0MmH7DzftRWevZcw@public.gmane.org>

Am Freitag, 21. Juli 2017, 15:54:40 CEST schrieb xxm:
> Hi Heiko,
> 
> 
> On 07/21/2017 03:07 PM, Heiko Stuebner wrote:
> > Am Freitag, 21. Juli 2017, 14:27:09 CEST schrieb Simon Xue:
> >> From: Simon <xxm-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
> >>
> >> RK3368 vpu mmu have two irqs, this patch support multi irqs
> >>
> >> Signed-off-by: Simon <xxm-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
> >> ---
> >> changes since V1:
> >>   - use devm_kcalloc instead of devm_kzalloc when alloc irq array
> >>
> >>   drivers/iommu/rockchip-iommu.c | 34 ++++++++++++++++++++++++----------
> >>   1 file changed, 24 insertions(+), 10 deletions(-)
> >>
> >> diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c
> >> index 4ba48a2..3c462c0 100644
> >> --- a/drivers/iommu/rockchip-iommu.c
> >> +++ b/drivers/iommu/rockchip-iommu.c
> >> @@ -90,7 +90,8 @@ struct rk_iommu {
> >>   	struct device *dev;
> >>   	void __iomem **bases;
> >>   	int num_mmu;
> >> -	int irq;
> >> +	int *irq;
> >> +	int num_irq;
> >>   	struct iommu_device iommu;
> >>   	struct list_head node; /* entry in rk_iommu_domain.iommus */
> >>   	struct iommu_domain *domain; /* domain to which iommu is attached */
> >> @@ -825,10 +826,12 @@ static int rk_iommu_attach_device(struct iommu_domain *domain,
> >>   
> >>   	iommu->domain = domain;
> >>   
> >> -	ret = devm_request_irq(iommu->dev, iommu->irq, rk_iommu_irq,
> >> -			       IRQF_SHARED, dev_name(dev), iommu);
> >> -	if (ret)
> >> -		return ret;
> >> +	for (i = 0; i < iommu->num_irq; i++) {
> >> +		ret = devm_request_irq(iommu->dev, iommu->irq[i], rk_iommu_irq,
> >> +				       IRQF_SHARED, dev_name(dev), iommu);
> >> +		if (ret)
> >> +			return ret;
> >> +	}
> >>   
> >>   	for (i = 0; i < iommu->num_mmu; i++) {
> >>   		rk_iommu_write(iommu->bases[i], RK_MMU_DTE_ADDR,
> >> @@ -878,7 +881,8 @@ static void rk_iommu_detach_device(struct iommu_domain *domain,
> >>   	}
> >>   	rk_iommu_disable_stall(iommu);
> >>   
> >> -	devm_free_irq(iommu->dev, iommu->irq, iommu);
> >> +	for (i = 0; i < iommu->num_irq; i++)
> >> +		devm_free_irq(iommu->dev, iommu->irq[i], iommu);
> >>   
> >>   	iommu->domain = NULL;
> >>   
> >> @@ -1157,10 +1161,20 @@ static int rk_iommu_probe(struct platform_device *pdev)
> >>   	if (iommu->num_mmu == 0)
> >>   		return PTR_ERR(iommu->bases[0]);
> >>   
> >> -	iommu->irq = platform_get_irq(pdev, 0);
> >> -	if (iommu->irq < 0) {
> >> -		dev_err(dev, "Failed to get IRQ, %d\n", iommu->irq);
> >> -		return -ENXIO;
> >> +	while (platform_get_irq(pdev, iommu->num_irq) >= 0)
> >> +		iommu->num_irq++;
> > Hmm, this could also result in a iommu having 0 irqs if wrongly
> > configured and probe would still suceed. This sounds somehow
> > wrong to me.
> >
> > But I'm not sure if there is precedent on how to handle a variable
> > number of interrupts correctly somewhere.
> 
> How about add a judgement for iommu->num_irq ? like this:
> if (!iommu->num_irq)
> 	return -ENOXIO;

platform devices already have a function that gets you the number of irqs.
Re-using that is way better than open-coding it, so

iommu->num_irq = platform_irq_count(pdev);
if (iommu->num_irq < 0)
	return iommu->num_irq;
if (iommu->num_irq == 0)
	return -ENXIO;


Heiko

WARNING: multiple messages have this Message-ID (diff)
From: Heiko Stuebner <heiko@sntech.de>
To: xxm <xxm@rock-chips.com>
Cc: Joerg Roedel <joro@8bytes.org>,
	linux-rockchip@lists.infradead.org,
	iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH V2 2/3] iommu/rockchip: add multi irqs support
Date: Fri, 21 Jul 2017 20:37:02 +0200	[thread overview]
Message-ID: <1622328.YERcK565Fd@phil> (raw)
In-Reply-To: <675fd7bf-7551-4f95-9b9c-8a2151e59ee1@rock-chips.com>

Am Freitag, 21. Juli 2017, 15:54:40 CEST schrieb xxm:
> Hi Heiko,
> 
> 
> On 07/21/2017 03:07 PM, Heiko Stuebner wrote:
> > Am Freitag, 21. Juli 2017, 14:27:09 CEST schrieb Simon Xue:
> >> From: Simon <xxm@rock-chips.com>
> >>
> >> RK3368 vpu mmu have two irqs, this patch support multi irqs
> >>
> >> Signed-off-by: Simon <xxm@rock-chips.com>
> >> ---
> >> changes since V1:
> >>   - use devm_kcalloc instead of devm_kzalloc when alloc irq array
> >>
> >>   drivers/iommu/rockchip-iommu.c | 34 ++++++++++++++++++++++++----------
> >>   1 file changed, 24 insertions(+), 10 deletions(-)
> >>
> >> diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c
> >> index 4ba48a2..3c462c0 100644
> >> --- a/drivers/iommu/rockchip-iommu.c
> >> +++ b/drivers/iommu/rockchip-iommu.c
> >> @@ -90,7 +90,8 @@ struct rk_iommu {
> >>   	struct device *dev;
> >>   	void __iomem **bases;
> >>   	int num_mmu;
> >> -	int irq;
> >> +	int *irq;
> >> +	int num_irq;
> >>   	struct iommu_device iommu;
> >>   	struct list_head node; /* entry in rk_iommu_domain.iommus */
> >>   	struct iommu_domain *domain; /* domain to which iommu is attached */
> >> @@ -825,10 +826,12 @@ static int rk_iommu_attach_device(struct iommu_domain *domain,
> >>   
> >>   	iommu->domain = domain;
> >>   
> >> -	ret = devm_request_irq(iommu->dev, iommu->irq, rk_iommu_irq,
> >> -			       IRQF_SHARED, dev_name(dev), iommu);
> >> -	if (ret)
> >> -		return ret;
> >> +	for (i = 0; i < iommu->num_irq; i++) {
> >> +		ret = devm_request_irq(iommu->dev, iommu->irq[i], rk_iommu_irq,
> >> +				       IRQF_SHARED, dev_name(dev), iommu);
> >> +		if (ret)
> >> +			return ret;
> >> +	}
> >>   
> >>   	for (i = 0; i < iommu->num_mmu; i++) {
> >>   		rk_iommu_write(iommu->bases[i], RK_MMU_DTE_ADDR,
> >> @@ -878,7 +881,8 @@ static void rk_iommu_detach_device(struct iommu_domain *domain,
> >>   	}
> >>   	rk_iommu_disable_stall(iommu);
> >>   
> >> -	devm_free_irq(iommu->dev, iommu->irq, iommu);
> >> +	for (i = 0; i < iommu->num_irq; i++)
> >> +		devm_free_irq(iommu->dev, iommu->irq[i], iommu);
> >>   
> >>   	iommu->domain = NULL;
> >>   
> >> @@ -1157,10 +1161,20 @@ static int rk_iommu_probe(struct platform_device *pdev)
> >>   	if (iommu->num_mmu == 0)
> >>   		return PTR_ERR(iommu->bases[0]);
> >>   
> >> -	iommu->irq = platform_get_irq(pdev, 0);
> >> -	if (iommu->irq < 0) {
> >> -		dev_err(dev, "Failed to get IRQ, %d\n", iommu->irq);
> >> -		return -ENXIO;
> >> +	while (platform_get_irq(pdev, iommu->num_irq) >= 0)
> >> +		iommu->num_irq++;
> > Hmm, this could also result in a iommu having 0 irqs if wrongly
> > configured and probe would still suceed. This sounds somehow
> > wrong to me.
> >
> > But I'm not sure if there is precedent on how to handle a variable
> > number of interrupts correctly somewhere.
> 
> How about add a judgement for iommu->num_irq ? like this:
> if (!iommu->num_irq)
> 	return -ENOXIO;

platform devices already have a function that gets you the number of irqs.
Re-using that is way better than open-coding it, so

iommu->num_irq = platform_irq_count(pdev);
if (iommu->num_irq < 0)
	return iommu->num_irq;
if (iommu->num_irq == 0)
	return -ENXIO;


Heiko

  parent reply	other threads:[~2017-07-21 18:37 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-21  6:27 [PATCH V2 1/3] Docs: dt: rockchip: add rk-iommu,disable-reset-quirk property Simon Xue
2017-07-21  6:27 ` [PATCH V2 3/3] iommu/rockchip: ignore isp mmu reset operation Simon Xue
     [not found] ` <1500618430-114821-1-git-send-email-xxm-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
2017-07-21  6:27   ` [PATCH V2 2/3] iommu/rockchip: add multi irqs support Simon Xue
2017-07-21  6:27     ` Simon Xue
2017-07-21  7:07     ` Heiko Stuebner
2017-07-21  7:54       ` xxm
2017-07-21  7:54         ` xxm
     [not found]         ` <675fd7bf-7551-4f95-9b9c-8a2151e59ee1-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
2017-07-21 18:37           ` Heiko Stuebner [this message]
2017-07-21 18:37             ` Heiko Stuebner
2017-07-21  6:57   ` [PATCH V2 1/3] Docs: dt: rockchip: add rk-iommu, disable-reset-quirk property Heiko Stuebner
2017-07-21  6:57     ` [PATCH V2 1/3] Docs: dt: rockchip: add rk-iommu,disable-reset-quirk property Heiko Stuebner

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=1622328.YERcK565Fd@phil \
    --to=heiko-4mtyjxux2i+zqb+pc5nmwq@public.gmane.org \
    --cc=iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=xxm-TNX95d0MmH7DzftRWevZcw@public.gmane.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.