mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hideki EIRAKU <hdk@igel.co.jp>
To: nobuhiro.iwamatsu.yj@renesas.com
Cc: lethal@linux-sh.org, magnus.damm@gmail.com,
	linux@arm.linux.org.uk, horms@verge.net.au,
	linux-sh@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, m.szyprowski@samsung.com,
	matsu@igel.co.jp, dhobsong@igel.co.jp
Subject: Re: [PATCH v3 1/2] iommu/shmobile: Add iommu driver for Renesas IPMMU modules
Date: Fri, 28 Sep 2012 13:29:11 +0900 (JST)	[thread overview]
Message-ID: <20120928.132911.321770401.hdk@igel.co.jp> (raw)
In-Reply-To: <CABMQnVKiZyKMy_T7iAArc48zKnwzHpEUZY9+iqTRzCf9v9tJ0g@mail.gmail.com>

Hi,

From: Nobuhiro Iwamatsu <nobuhiro.iwamatsu.yj@renesas.com>
Subject: Re: [PATCH v3 1/2] iommu/shmobile: Add iommu driver for Renesas IPMMU modules
Date: Wed, 12 Sep 2012 17:07:00 +0900

>> +static inline void ipmmu_add_device(struct device *dev)
>> +{
>> +}
> 
> Please use 'do { } while (0)'.

Do you mean using #define macro is better than this inline function?
I chose the inline function because:

- The function's argument type is checked by a compiler.
- Its output code should be exactly the same as a macro in this case.
- The Linux kernel coding style says "Generally, inline functions are
  preferable to macros resembling functions."

>> +       switch (size) {
>> +       default:
>> +               priv->tlb_enabled = 0;
>> +               break;
>> +       case 0x2000:
>> +               ipmmu_reg_write(priv, IMTTBCR, 1);
>> +               priv->tlb_enabled = 1;
>> +               break;
>> +       case 0x1000:
>> +               ipmmu_reg_write(priv, IMTTBCR, 2);
>> +               priv->tlb_enabled = 1;
>> +               break;
>> +       case 0x800:
>> +               ipmmu_reg_write(priv, IMTTBCR, 3);
>> +               priv->tlb_enabled = 1;
>> +               break;
>> +       case 0x400:
>> +               ipmmu_reg_write(priv, IMTTBCR, 4);
>> +               priv->tlb_enabled = 1;
>> +               break;
>> +       case 0x200:
>> +               ipmmu_reg_write(priv, IMTTBCR, 5);
>> +               priv->tlb_enabled = 1;
>> +               break;
>> +       case 0x100:
>> +               ipmmu_reg_write(priv, IMTTBCR, 6);
>> +               priv->tlb_enabled = 1;
>> +               break;
>> +       case 0x80:
>> +               ipmmu_reg_write(priv, IMTTBCR, 7);
>> +               priv->tlb_enabled = 1;
>> +               break;
>> +       }
> 
> I thought that you could describe more briefly if ffs() is used.

This is simply converted from a hardware manual.  ffs() can be used
like below:

	bit = ffs(size);
	if (bit >= 7 && bit <= 13 && (1 << bit) == size) {
		ipmmu_reg_write(priv, IMTTBCR, 14 - bit);
		priv->tlb_enabled = 1;
	} else {
		priv->tlb_enabled = 0;
	}

Checking size is still needed because only 7 sizes are allowed here.
I think using switch() is easier to understand.

>> +#ifdef CONFIG_SHMOBILE_IOMMU_L1SIZE_8192
>> +#define L1_SIZE 8192
>> +#endif
>> +#ifdef CONFIG_SHMOBILE_IOMMU_L1SIZE_4096
>> +#define L1_SIZE 4096
>> +#endif
>> +#ifdef CONFIG_SHMOBILE_IOMMU_L1SIZE_2048
>> +#define L1_SIZE 2048
>> +#endif
>> +#ifdef CONFIG_SHMOBILE_IOMMU_L1SIZE_1024
>> +#define L1_SIZE 1024
>> +#endif
>> +#ifdef CONFIG_SHMOBILE_IOMMU_L1SIZE_512
>> +#define L1_SIZE 512
>> +#endif
>> +#ifdef CONFIG_SHMOBILE_IOMMU_L1SIZE_256
>> +#define L1_SIZE 256
>> +#endif
>> +#ifdef CONFIG_SHMOBILE_IOMMU_L1SIZE_128
>> +#define L1_SIZE 128
>> +#endif
> 
> I think that it was better to define by kconfig.
> For example, following codes.
> 
> +config SHMOBILE_IOMMU_L1SIZE
> +       hex
> +       default "0x00002000" if SHMOBILE_IOMMU_L1SIZE_8192
> +       default "0x00001000" if SHMOBILE_IOMMU_L1SIZE_4096
> +       default "0x00000800" if SHMOBILE_IOMMU_L1SIZE_2048
> +       default "0x00000400" if SHMOBILE_IOMMU_L1SIZE_1024
> +       default "0x00000200" if SHMOBILE_IOMMU_L1SIZE_512
> +       default "0x00000100" if SHMOBILE_IOMMU_L1SIZE_256
> +       default "0x00000080" if SHMOBILE_IOMMU_L1SIZE_128

I did not know that way.  It looks good for me too.
Thank you.

-- 
Hideki EIRAKU <hdk@igel.co.jp>

  reply	other threads:[~2012-09-28  4:29 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-11  6:10 [PATCH v3 0/2] Renesas IPMMU driver for sh7372 Hideki EIRAKU
2012-09-11  6:10 ` [PATCH v3 1/2] iommu/shmobile: Add iommu driver for Renesas IPMMU modules Hideki EIRAKU
2012-09-12  8:07   ` Nobuhiro Iwamatsu
2012-09-28  4:29     ` Hideki EIRAKU [this message]
2012-09-11  6:10 ` [PATCH v3 2/2] ARM: mach-shmobile: sh7372: Add IPMMU device Hideki EIRAKU

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=20120928.132911.321770401.hdk@igel.co.jp \
    --to=hdk@igel.co.jp \
    --cc=dhobsong@igel.co.jp \
    --cc=horms@verge.net.au \
    --cc=lethal@linux-sh.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sh@vger.kernel.org \
    --cc=linux@arm.linux.org.uk \
    --cc=m.szyprowski@samsung.com \
    --cc=magnus.damm@gmail.com \
    --cc=matsu@igel.co.jp \
    --cc=nobuhiro.iwamatsu.yj@renesas.com \
    /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®