Re: [PATCH 1/3] iommu/fsl: Fix PAMU window size check.

2014-07-04 Thread Joerg Roedel
On Tue, Jun 24, 2014 at 07:27:15PM +0530, Varun Sethi wrote:
   /* window size is 2^(WSE+1) bytes */
 - return __ffs(addrspace_size) - 1;
 + return fls64(addrspace_size) - 2;

This looks bogus, why do you replace ffs (find-first-bit) by fls
(find-last-bit)?


Joerg


___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

RE: [PATCH 1/3] iommu/fsl: Fix PAMU window size check.

2014-07-04 Thread Varun Sethi


 -Original Message-
 From: Joerg Roedel [mailto:j...@8bytes.org]
 Sent: Friday, July 04, 2014 4:15 PM
 To: Sethi Varun-B16395
 Cc: io...@lists.linux-foundation.org; linux-ker...@vger.kernel.org;
 linuxppc-dev@lists.ozlabs.org; alex.william...@redhat.com
 Subject: Re: [PATCH 1/3] iommu/fsl: Fix PAMU window size check.
 
 On Tue, Jun 24, 2014 at 07:27:15PM +0530, Varun Sethi wrote:
  /* window size is 2^(WSE+1) bytes */
  -   return __ffs(addrspace_size) - 1;
  +   return fls64(addrspace_size) - 2;
 
 This looks bogus, why do you replace ffs (find-first-bit) by fls (find-
 last-bit)?
 
Address space size is always a power of 2. This change was required to handle 
address sizes  32bit width on 32 bit architectures.

-Varun

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Re: [PATCH 1/3] iommu/fsl: Fix PAMU window size check.

2014-07-02 Thread Emil Medve
On 06/24/2014 08:57 AM, Varun Sethi wrote:
 is_power_of_2 requires an unsigned long parameter which would
 lead to truncation of 64 bit values on 32 bit architectures.
 
 __ffs also expects an unsigned long parameter thus won't work
 for 64 bit values on 32 bit architectures.
 
 Signed-off-by: Varun Sethi varun.se...@freescale.com
 ---
  drivers/iommu/fsl_pamu.c|8 
  drivers/iommu/fsl_pamu_domain.c |2 +-
  2 files changed, 5 insertions(+), 5 deletions(-)

Tested-by: Emil Medve emilian.me...@freescale.com

On a P4080 DS (i.e. 32-bit SoC)


Cheers,
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

RE: [PATCH 1/3] iommu/fsl: Fix PAMU window size check.

2014-07-02 Thread Varun Sethi
Thanks Emil.

 -Original Message-
 From: Emil Medve [mailto:emilian.me...@freescale.com]
 Sent: Wednesday, July 02, 2014 1:16 PM
 To: Sethi Varun-B16395; io...@lists.linux-foundation.org;
 j...@8bytes.org; linux-ker...@vger.kernel.org; linuxppc-
 d...@lists.ozlabs.org; alex.william...@redhat.com
 Subject: Re: [PATCH 1/3] iommu/fsl: Fix PAMU window size check.
 
 On 06/24/2014 08:57 AM, Varun Sethi wrote:
  is_power_of_2 requires an unsigned long parameter which would lead to
  truncation of 64 bit values on 32 bit architectures.
 
  __ffs also expects an unsigned long parameter thus won't work for 64
  bit values on 32 bit architectures.
 
  Signed-off-by: Varun Sethi varun.se...@freescale.com
  ---
   drivers/iommu/fsl_pamu.c|8 
   drivers/iommu/fsl_pamu_domain.c |2 +-
   2 files changed, 5 insertions(+), 5 deletions(-)
 
 Tested-by: Emil Medve emilian.me...@freescale.com
 
 On a P4080 DS (i.e. 32-bit SoC)
 
 
 Cheers,
___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

[PATCH 1/3] iommu/fsl: Fix PAMU window size check.

2014-06-24 Thread Varun Sethi
is_power_of_2 requires an unsigned long parameter which would
lead to truncation of 64 bit values on 32 bit architectures.

__ffs also expects an unsigned long parameter thus won't work
for 64 bit values on 32 bit architectures.

Signed-off-by: Varun Sethi varun.se...@freescale.com
---
 drivers/iommu/fsl_pamu.c|8 
 drivers/iommu/fsl_pamu_domain.c |2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/iommu/fsl_pamu.c b/drivers/iommu/fsl_pamu.c
index b99dd88..bb446d7 100644
--- a/drivers/iommu/fsl_pamu.c
+++ b/drivers/iommu/fsl_pamu.c
@@ -170,10 +170,10 @@ int pamu_disable_liodn(int liodn)
 static unsigned int map_addrspace_size_to_wse(phys_addr_t addrspace_size)
 {
/* Bug if not a power of 2 */
-   BUG_ON(!is_power_of_2(addrspace_size));
+   BUG_ON((addrspace_size  (addrspace_size - 1)));
 
/* window size is 2^(WSE+1) bytes */
-   return __ffs(addrspace_size) - 1;
+   return fls64(addrspace_size) - 2;
 }
 
 /* Derive the PAACE window count encoding for the subwindow count */
@@ -351,7 +351,7 @@ int pamu_config_ppaace(int liodn, phys_addr_t win_addr, 
phys_addr_t win_size,
struct paace *ppaace;
unsigned long fspi;
 
-   if (!is_power_of_2(win_size) || win_size  PAMU_PAGE_SIZE) {
+   if ((win_size  (win_size - 1)) || win_size  PAMU_PAGE_SIZE) {
pr_debug(window size too small or not a power of two %llx\n, 
win_size);
return -EINVAL;
}
@@ -464,7 +464,7 @@ int pamu_config_spaace(int liodn, u32 subwin_cnt, u32 
subwin,
return -ENOENT;
}
 
-   if (!is_power_of_2(subwin_size) || subwin_size  PAMU_PAGE_SIZE) {
+   if ((subwin_size  (subwin_size - 1)) || subwin_size  PAMU_PAGE_SIZE) {
pr_debug(subwindow size out of range, or not a power of 2\n);
return -EINVAL;
}
diff --git a/drivers/iommu/fsl_pamu_domain.c b/drivers/iommu/fsl_pamu_domain.c
index 93072ba..3dd0b8e 100644
--- a/drivers/iommu/fsl_pamu_domain.c
+++ b/drivers/iommu/fsl_pamu_domain.c
@@ -301,7 +301,7 @@ static int check_size(u64 size, dma_addr_t iova)
 * Size must be a power of two and at least be equal
 * to PAMU page size.
 */
-   if (!is_power_of_2(size) || size  PAMU_PAGE_SIZE) {
+   if ((size  (size - 1)) || size  PAMU_PAGE_SIZE) {
pr_debug(%s: size too small or not a power of two\n, 
__func__);
return -EINVAL;
}
-- 
1.7.9.5

___
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev