2020-04-20 18:40:08

by Christophe Leroy

[permalink] [raw]
Subject: [PATCH 1/5] drivers/powerpc: Replace _ALIGN_UP() by ALIGN()

_ALIGN_UP() is specific to powerpc
ALIGN() is generic and does the same

Replace _ALIGN_UP() by ALIGN()

Signed-off-by: Christophe Leroy <[email protected]>
---
drivers/ps3/ps3-lpm.c | 6 +++---
drivers/vfio/pci/vfio_pci_nvlink2.c | 2 +-
drivers/video/fbdev/ps3fb.c | 4 ++--
sound/ppc/snd_ps3.c | 2 +-
4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/ps3/ps3-lpm.c b/drivers/ps3/ps3-lpm.c
index 83c45659bc9d..064b5884ba13 100644
--- a/drivers/ps3/ps3-lpm.c
+++ b/drivers/ps3/ps3-lpm.c
@@ -1096,8 +1096,8 @@ int ps3_lpm_open(enum ps3_lpm_tb_type tb_type, void *tb_cache,
lpm_priv->tb_cache_internal = NULL;
lpm_priv->tb_cache = NULL;
} else if (tb_cache) {
- if (tb_cache != (void *)_ALIGN_UP((unsigned long)tb_cache, 128)
- || tb_cache_size != _ALIGN_UP(tb_cache_size, 128)) {
+ if (tb_cache != (void *)ALIGN((unsigned long)tb_cache, 128)
+ || tb_cache_size != ALIGN(tb_cache_size, 128)) {
dev_err(sbd_core(), "%s:%u: unaligned tb_cache\n",
__func__, __LINE__);
result = -EINVAL;
@@ -1116,7 +1116,7 @@ int ps3_lpm_open(enum ps3_lpm_tb_type tb_type, void *tb_cache,
result = -ENOMEM;
goto fail_malloc;
}
- lpm_priv->tb_cache = (void *)_ALIGN_UP(
+ lpm_priv->tb_cache = (void *)ALIGN(
(unsigned long)lpm_priv->tb_cache_internal, 128);
}

diff --git a/drivers/vfio/pci/vfio_pci_nvlink2.c b/drivers/vfio/pci/vfio_pci_nvlink2.c
index ed20d73cc27c..65c61710c0e9 100644
--- a/drivers/vfio/pci/vfio_pci_nvlink2.c
+++ b/drivers/vfio/pci/vfio_pci_nvlink2.c
@@ -67,7 +67,7 @@ static size_t vfio_pci_nvgpu_rw(struct vfio_pci_device *vdev,
*
* This is not fast path anyway.
*/
- sizealigned = _ALIGN_UP(posoff + count, PAGE_SIZE);
+ sizealigned = ALIGN(posoff + count, PAGE_SIZE);
ptr = ioremap_cache(data->gpu_hpa + posaligned, sizealigned);
if (!ptr)
return -EFAULT;
diff --git a/drivers/video/fbdev/ps3fb.c b/drivers/video/fbdev/ps3fb.c
index 834f63edf700..9df78fb77267 100644
--- a/drivers/video/fbdev/ps3fb.c
+++ b/drivers/video/fbdev/ps3fb.c
@@ -44,7 +44,7 @@
#define GPU_CMD_BUF_SIZE (2 * 1024 * 1024)
#define GPU_FB_START (64 * 1024)
#define GPU_IOIF (0x0d000000UL)
-#define GPU_ALIGN_UP(x) _ALIGN_UP((x), 64)
+#define GPU_ALIGN_UP(x) ALIGN((x), 64)
#define GPU_MAX_LINE_LENGTH (65536 - 64)

#define GPU_INTR_STATUS_VSYNC_0 0 /* vsync on head A */
@@ -1015,7 +1015,7 @@ static int ps3fb_probe(struct ps3_system_bus_device *dev)
}
#endif

- max_ps3fb_size = _ALIGN_UP(GPU_IOIF, 256*1024*1024) - GPU_IOIF;
+ max_ps3fb_size = ALIGN(GPU_IOIF, 256*1024*1024) - GPU_IOIF;
if (ps3fb_videomemory.size > max_ps3fb_size) {
dev_info(&dev->core, "Limiting ps3fb mem size to %lu bytes\n",
max_ps3fb_size);
diff --git a/sound/ppc/snd_ps3.c b/sound/ppc/snd_ps3.c
index 6d2a33b8faa0..b8161a08f2ca 100644
--- a/sound/ppc/snd_ps3.c
+++ b/sound/ppc/snd_ps3.c
@@ -926,7 +926,7 @@ static int snd_ps3_driver_probe(struct ps3_system_bus_device *dev)
PAGE_SHIFT, /* use system page size */
0, /* dma type; not used */
NULL,
- _ALIGN_UP(SND_PS3_DMA_REGION_SIZE, PAGE_SIZE));
+ ALIGN(SND_PS3_DMA_REGION_SIZE, PAGE_SIZE));
dev->d_region->ioid = PS3_AUDIO_IOID;

ret = ps3_dma_region_create(dev->d_region);
--
2.25.0


2020-04-20 18:40:13

by Christophe Leroy

[permalink] [raw]
Subject: [PATCH 2/5] powerpc: Replace _ALIGN_DOWN() by ALIGN_DOWN()

_ALIGN_DOWN() is specific to powerpc
ALIGN_DOWN() is generic and does the same

Replace _ALIGN_DOWN() by ALIGN_DOWN()

Signed-off-by: Christophe Leroy <[email protected]>
---
arch/powerpc/include/asm/book3s/32/pgtable.h | 2 +-
arch/powerpc/include/asm/nohash/32/pgtable.h | 2 +-
arch/powerpc/kernel/pci_64.c | 2 +-
arch/powerpc/kernel/prom.c | 6 +++---
arch/powerpc/kernel/prom_init.c | 8 ++++----
arch/powerpc/mm/book3s64/hash_tlb.c | 4 ++--
arch/powerpc/mm/init_64.c | 4 ++--
arch/powerpc/platforms/powernv/opal-fadump.c | 2 +-
arch/powerpc/platforms/powernv/pci-ioda.c | 2 +-
arch/powerpc/platforms/ps3/mm.c | 14 +++++++-------
arch/powerpc/platforms/pseries/rtas-fadump.c | 2 +-
11 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/arch/powerpc/include/asm/book3s/32/pgtable.h b/arch/powerpc/include/asm/book3s/32/pgtable.h
index 7549393c4c43..53b5c93eaf5d 100644
--- a/arch/powerpc/include/asm/book3s/32/pgtable.h
+++ b/arch/powerpc/include/asm/book3s/32/pgtable.h
@@ -195,7 +195,7 @@ int map_kernel_page(unsigned long va, phys_addr_t pa, pgprot_t prot);
#endif

#ifdef CONFIG_KASAN_VMALLOC
-#define VMALLOC_END _ALIGN_DOWN(ioremap_bot, PAGE_SIZE << KASAN_SHADOW_SCALE_SHIFT)
+#define VMALLOC_END ALIGN_DOWN(ioremap_bot, PAGE_SIZE << KASAN_SHADOW_SCALE_SHIFT)
#else
#define VMALLOC_END ioremap_bot
#endif
diff --git a/arch/powerpc/include/asm/nohash/32/pgtable.h b/arch/powerpc/include/asm/nohash/32/pgtable.h
index b04ba257fddb..5b4d4c4297e1 100644
--- a/arch/powerpc/include/asm/nohash/32/pgtable.h
+++ b/arch/powerpc/include/asm/nohash/32/pgtable.h
@@ -116,7 +116,7 @@ int map_kernel_page(unsigned long va, phys_addr_t pa, pgprot_t prot);
#endif

#ifdef CONFIG_KASAN_VMALLOC
-#define VMALLOC_END _ALIGN_DOWN(ioremap_bot, PAGE_SIZE << KASAN_SHADOW_SCALE_SHIFT)
+#define VMALLOC_END ALIGN_DOWN(ioremap_bot, PAGE_SIZE << KASAN_SHADOW_SCALE_SHIFT)
#else
#define VMALLOC_END ioremap_bot
#endif
diff --git a/arch/powerpc/kernel/pci_64.c b/arch/powerpc/kernel/pci_64.c
index f83d1f69b1dd..e5d05af5a9af 100644
--- a/arch/powerpc/kernel/pci_64.c
+++ b/arch/powerpc/kernel/pci_64.c
@@ -130,7 +130,7 @@ static int pcibios_map_phb_io_space(struct pci_controller *hose)
unsigned long size_page;
unsigned long io_virt_offset;

- phys_page = _ALIGN_DOWN(hose->io_base_phys, PAGE_SIZE);
+ phys_page = ALIGN_DOWN(hose->io_base_phys, PAGE_SIZE);
size_page = _ALIGN_UP(hose->pci_io_size, PAGE_SIZE);

/* Make sure IO area address is clear */
diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c
index 6620f37abe73..10b5d5eafd34 100644
--- a/arch/powerpc/kernel/prom.c
+++ b/arch/powerpc/kernel/prom.c
@@ -96,7 +96,7 @@ static inline int overlaps_initrd(unsigned long start, unsigned long size)
if (!initrd_start)
return 0;

- return (start + size) > _ALIGN_DOWN(initrd_start, PAGE_SIZE) &&
+ return (start + size) > ALIGN_DOWN(initrd_start, PAGE_SIZE) &&
start <= _ALIGN_UP(initrd_end, PAGE_SIZE);
#else
return 0;
@@ -623,9 +623,9 @@ static void __init early_reserve_mem(void)
#ifdef CONFIG_BLK_DEV_INITRD
/* Then reserve the initrd, if any */
if (initrd_start && (initrd_end > initrd_start)) {
- memblock_reserve(_ALIGN_DOWN(__pa(initrd_start), PAGE_SIZE),
+ memblock_reserve(ALIGN_DOWN(__pa(initrd_start), PAGE_SIZE),
_ALIGN_UP(initrd_end, PAGE_SIZE) -
- _ALIGN_DOWN(initrd_start, PAGE_SIZE));
+ ALIGN_DOWN(initrd_start, PAGE_SIZE));
}
#endif /* CONFIG_BLK_DEV_INITRD */

diff --git a/arch/powerpc/kernel/prom_init.c b/arch/powerpc/kernel/prom_init.c
index 806be751c336..4cf5958eebd4 100644
--- a/arch/powerpc/kernel/prom_init.c
+++ b/arch/powerpc/kernel/prom_init.c
@@ -1500,7 +1500,7 @@ static unsigned long __init alloc_down(unsigned long size, unsigned long align,

if (highmem) {
/* Carve out storage for the TCE table. */
- addr = _ALIGN_DOWN(alloc_top_high - size, align);
+ addr = ALIGN_DOWN(alloc_top_high - size, align);
if (addr <= alloc_bottom)
return 0;
/* Will we bump into the RMO ? If yes, check out that we
@@ -1518,9 +1518,9 @@ static unsigned long __init alloc_down(unsigned long size, unsigned long align,
goto bail;
}

- base = _ALIGN_DOWN(alloc_top - size, align);
+ base = ALIGN_DOWN(alloc_top - size, align);
for (; base > alloc_bottom;
- base = _ALIGN_DOWN(base - 0x100000, align)) {
+ base = ALIGN_DOWN(base - 0x100000, align)) {
prom_debug(" trying: 0x%lx\n\r", base);
addr = (unsigned long)prom_claim(base, size, 0);
if (addr != PROM_ERROR && addr != 0)
@@ -1586,7 +1586,7 @@ static void __init reserve_mem(u64 base, u64 size)
* have our terminator with "size" set to 0 since we are
* dumb and just copy this entire array to the boot params
*/
- base = _ALIGN_DOWN(base, PAGE_SIZE);
+ base = ALIGN_DOWN(base, PAGE_SIZE);
top = _ALIGN_UP(top, PAGE_SIZE);
size = top - base;

diff --git a/arch/powerpc/mm/book3s64/hash_tlb.c b/arch/powerpc/mm/book3s64/hash_tlb.c
index 4a70d8dd39cd..2242d022b620 100644
--- a/arch/powerpc/mm/book3s64/hash_tlb.c
+++ b/arch/powerpc/mm/book3s64/hash_tlb.c
@@ -196,7 +196,7 @@ void __flush_hash_table_range(struct mm_struct *mm, unsigned long start,
int hugepage_shift;
unsigned long flags;

- start = _ALIGN_DOWN(start, PAGE_SIZE);
+ start = ALIGN_DOWN(start, PAGE_SIZE);
end = _ALIGN_UP(end, PAGE_SIZE);

BUG_ON(!mm->pgd);
@@ -238,7 +238,7 @@ void flush_tlb_pmd_range(struct mm_struct *mm, pmd_t *pmd, unsigned long addr)
pte_t *start_pte;
unsigned long flags;

- addr = _ALIGN_DOWN(addr, PMD_SIZE);
+ addr = ALIGN_DOWN(addr, PMD_SIZE);
/*
* Note: Normally, we should only ever use a batch within a
* PTE locked section. This violates the rule, but will work
diff --git a/arch/powerpc/mm/init_64.c b/arch/powerpc/mm/init_64.c
index 4002ced3596f..c7ce4ec5060e 100644
--- a/arch/powerpc/mm/init_64.c
+++ b/arch/powerpc/mm/init_64.c
@@ -203,7 +203,7 @@ int __meminit vmemmap_populate(unsigned long start, unsigned long end, int node,
unsigned long page_size = 1 << mmu_psize_defs[mmu_vmemmap_psize].shift;

/* Align to the page size of the linear mapping. */
- start = _ALIGN_DOWN(start, page_size);
+ start = ALIGN_DOWN(start, page_size);

pr_debug("vmemmap_populate %lx..%lx, node %d\n", start, end, node);

@@ -292,7 +292,7 @@ void __ref vmemmap_free(unsigned long start, unsigned long end,
unsigned long alt_start = ~0, alt_end = ~0;
unsigned long base_pfn;

- start = _ALIGN_DOWN(start, page_size);
+ start = ALIGN_DOWN(start, page_size);
if (altmap) {
alt_start = altmap->base_pfn;
alt_end = altmap->base_pfn + altmap->reserve +
diff --git a/arch/powerpc/platforms/powernv/opal-fadump.c b/arch/powerpc/platforms/powernv/opal-fadump.c
index d361d37d975f..9a360ced663b 100644
--- a/arch/powerpc/platforms/powernv/opal-fadump.c
+++ b/arch/powerpc/platforms/powernv/opal-fadump.c
@@ -671,7 +671,7 @@ void __init opal_fadump_dt_scan(struct fw_dump *fadump_conf, u64 node)
* Firmware supports 32-bit field for size. Align it to PAGE_SIZE
* and request firmware to copy multiple kernel boot memory regions.
*/
- fadump_conf->max_copy_size = _ALIGN_DOWN(U32_MAX, PAGE_SIZE);
+ fadump_conf->max_copy_size = ALIGN_DOWN(U32_MAX, PAGE_SIZE);

/*
* Check if dump has been initiated on last reboot.
diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c b/arch/powerpc/platforms/powernv/pci-ioda.c
index 57d3a6af1d52..276b011cd45d 100644
--- a/arch/powerpc/platforms/powernv/pci-ioda.c
+++ b/arch/powerpc/platforms/powernv/pci-ioda.c
@@ -264,7 +264,7 @@ static void pnv_ioda_reserve_dev_m64_pe(struct pci_dev *pdev,
if (!r->parent || !pnv_pci_is_m64(phb, r))
continue;

- start = _ALIGN_DOWN(r->start - base, sgsz);
+ start = ALIGN_DOWN(r->start - base, sgsz);
end = _ALIGN_UP(r->end - base, sgsz);
for (segno = start / sgsz; segno < end / sgsz; segno++) {
if (pe_bitmap)
diff --git a/arch/powerpc/platforms/ps3/mm.c b/arch/powerpc/platforms/ps3/mm.c
index 423be34f0f5f..71ed37f7f475 100644
--- a/arch/powerpc/platforms/ps3/mm.c
+++ b/arch/powerpc/platforms/ps3/mm.c
@@ -263,7 +263,7 @@ static int ps3_mm_region_create(struct mem_region *r, unsigned long size)
int result;
u64 muid;

- r->size = _ALIGN_DOWN(size, 1 << PAGE_SHIFT_16M);
+ r->size = ALIGN_DOWN(size, 1 << PAGE_SHIFT_16M);

DBG("%s:%d requested %lxh\n", __func__, __LINE__, size);
DBG("%s:%d actual %llxh\n", __func__, __LINE__, r->size);
@@ -394,7 +394,7 @@ static struct dma_chunk * dma_find_chunk(struct ps3_dma_region *r,
unsigned long bus_addr, unsigned long len)
{
struct dma_chunk *c;
- unsigned long aligned_bus = _ALIGN_DOWN(bus_addr, 1 << r->page_size);
+ unsigned long aligned_bus = ALIGN_DOWN(bus_addr, 1 << r->page_size);
unsigned long aligned_len = _ALIGN_UP(len+bus_addr-aligned_bus,
1 << r->page_size);

@@ -423,7 +423,7 @@ static struct dma_chunk *dma_find_chunk_lpar(struct ps3_dma_region *r,
unsigned long lpar_addr, unsigned long len)
{
struct dma_chunk *c;
- unsigned long aligned_lpar = _ALIGN_DOWN(lpar_addr, 1 << r->page_size);
+ unsigned long aligned_lpar = ALIGN_DOWN(lpar_addr, 1 << r->page_size);
unsigned long aligned_len = _ALIGN_UP(len + lpar_addr - aligned_lpar,
1 << r->page_size);

@@ -775,7 +775,7 @@ static int dma_sb_map_area(struct ps3_dma_region *r, unsigned long virt_addr,
struct dma_chunk *c;
unsigned long phys_addr = is_kernel_addr(virt_addr) ? __pa(virt_addr)
: virt_addr;
- unsigned long aligned_phys = _ALIGN_DOWN(phys_addr, 1 << r->page_size);
+ unsigned long aligned_phys = ALIGN_DOWN(phys_addr, 1 << r->page_size);
unsigned long aligned_len = _ALIGN_UP(len + phys_addr - aligned_phys,
1 << r->page_size);
*bus_addr = dma_sb_lpar_to_bus(r, ps3_mm_phys_to_lpar(phys_addr));
@@ -830,7 +830,7 @@ static int dma_ioc0_map_area(struct ps3_dma_region *r, unsigned long virt_addr,
struct dma_chunk *c;
unsigned long phys_addr = is_kernel_addr(virt_addr) ? __pa(virt_addr)
: virt_addr;
- unsigned long aligned_phys = _ALIGN_DOWN(phys_addr, 1 << r->page_size);
+ unsigned long aligned_phys = ALIGN_DOWN(phys_addr, 1 << r->page_size);
unsigned long aligned_len = _ALIGN_UP(len + phys_addr - aligned_phys,
1 << r->page_size);

@@ -889,7 +889,7 @@ static int dma_sb_unmap_area(struct ps3_dma_region *r, dma_addr_t bus_addr,
c = dma_find_chunk(r, bus_addr, len);

if (!c) {
- unsigned long aligned_bus = _ALIGN_DOWN(bus_addr,
+ unsigned long aligned_bus = ALIGN_DOWN(bus_addr,
1 << r->page_size);
unsigned long aligned_len = _ALIGN_UP(len + bus_addr
- aligned_bus, 1 << r->page_size);
@@ -926,7 +926,7 @@ static int dma_ioc0_unmap_area(struct ps3_dma_region *r,
c = dma_find_chunk(r, bus_addr, len);

if (!c) {
- unsigned long aligned_bus = _ALIGN_DOWN(bus_addr,
+ unsigned long aligned_bus = ALIGN_DOWN(bus_addr,
1 << r->page_size);
unsigned long aligned_len = _ALIGN_UP(len + bus_addr
- aligned_bus,
diff --git a/arch/powerpc/platforms/pseries/rtas-fadump.c b/arch/powerpc/platforms/pseries/rtas-fadump.c
index 70c3013fdd07..81343908ed33 100644
--- a/arch/powerpc/platforms/pseries/rtas-fadump.c
+++ b/arch/powerpc/platforms/pseries/rtas-fadump.c
@@ -506,7 +506,7 @@ void __init rtas_fadump_dt_scan(struct fw_dump *fadump_conf, u64 node)
fadump_conf->fadump_supported = 1;

/* Firmware supports 64-bit value for size, align it to pagesize. */
- fadump_conf->max_copy_size = _ALIGN_DOWN(U64_MAX, PAGE_SIZE);
+ fadump_conf->max_copy_size = ALIGN_DOWN(U64_MAX, PAGE_SIZE);

/*
* The 'ibm,kernel-dump' rtas node is present only if there is
--
2.25.0

2020-04-21 00:51:26

by Joel Stanley

[permalink] [raw]
Subject: Re: [PATCH 1/5] drivers/powerpc: Replace _ALIGN_UP() by ALIGN()

On Mon, 20 Apr 2020 at 18:37, Christophe Leroy <[email protected]> wrote:
>
> _ALIGN_UP() is specific to powerpc
> ALIGN() is generic and does the same
>
> Replace _ALIGN_UP() by ALIGN()
>
> Signed-off-by: Christophe Leroy <[email protected]>

I was curious, so I expanded out the kernel one. Here's the diff:

- (((addr)+((size)-1))&(~((typeof(addr))(size)-1)))
+ (((addr)+((typeof(addr))(size) - 1))&~((typeof(addr))(size)-1))

So it adds a cast, but aside from that it's the same.

Reviewed-by: Joel Stanley <[email protected]>

> ---
> drivers/ps3/ps3-lpm.c | 6 +++---
> drivers/vfio/pci/vfio_pci_nvlink2.c | 2 +-
> drivers/video/fbdev/ps3fb.c | 4 ++--
> sound/ppc/snd_ps3.c | 2 +-
> 4 files changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/ps3/ps3-lpm.c b/drivers/ps3/ps3-lpm.c
> index 83c45659bc9d..064b5884ba13 100644
> --- a/drivers/ps3/ps3-lpm.c
> +++ b/drivers/ps3/ps3-lpm.c
> @@ -1096,8 +1096,8 @@ int ps3_lpm_open(enum ps3_lpm_tb_type tb_type, void *tb_cache,
> lpm_priv->tb_cache_internal = NULL;
> lpm_priv->tb_cache = NULL;
> } else if (tb_cache) {
> - if (tb_cache != (void *)_ALIGN_UP((unsigned long)tb_cache, 128)
> - || tb_cache_size != _ALIGN_UP(tb_cache_size, 128)) {
> + if (tb_cache != (void *)ALIGN((unsigned long)tb_cache, 128)
> + || tb_cache_size != ALIGN(tb_cache_size, 128)) {
> dev_err(sbd_core(), "%s:%u: unaligned tb_cache\n",
> __func__, __LINE__);
> result = -EINVAL;
> @@ -1116,7 +1116,7 @@ int ps3_lpm_open(enum ps3_lpm_tb_type tb_type, void *tb_cache,
> result = -ENOMEM;
> goto fail_malloc;
> }
> - lpm_priv->tb_cache = (void *)_ALIGN_UP(
> + lpm_priv->tb_cache = (void *)ALIGN(
> (unsigned long)lpm_priv->tb_cache_internal, 128);
> }
>
> diff --git a/drivers/vfio/pci/vfio_pci_nvlink2.c b/drivers/vfio/pci/vfio_pci_nvlink2.c
> index ed20d73cc27c..65c61710c0e9 100644
> --- a/drivers/vfio/pci/vfio_pci_nvlink2.c
> +++ b/drivers/vfio/pci/vfio_pci_nvlink2.c
> @@ -67,7 +67,7 @@ static size_t vfio_pci_nvgpu_rw(struct vfio_pci_device *vdev,
> *
> * This is not fast path anyway.
> */
> - sizealigned = _ALIGN_UP(posoff + count, PAGE_SIZE);
> + sizealigned = ALIGN(posoff + count, PAGE_SIZE);
> ptr = ioremap_cache(data->gpu_hpa + posaligned, sizealigned);
> if (!ptr)
> return -EFAULT;
> diff --git a/drivers/video/fbdev/ps3fb.c b/drivers/video/fbdev/ps3fb.c
> index 834f63edf700..9df78fb77267 100644
> --- a/drivers/video/fbdev/ps3fb.c
> +++ b/drivers/video/fbdev/ps3fb.c
> @@ -44,7 +44,7 @@
> #define GPU_CMD_BUF_SIZE (2 * 1024 * 1024)
> #define GPU_FB_START (64 * 1024)
> #define GPU_IOIF (0x0d000000UL)
> -#define GPU_ALIGN_UP(x) _ALIGN_UP((x), 64)
> +#define GPU_ALIGN_UP(x) ALIGN((x), 64)
> #define GPU_MAX_LINE_LENGTH (65536 - 64)
>
> #define GPU_INTR_STATUS_VSYNC_0 0 /* vsync on head A */
> @@ -1015,7 +1015,7 @@ static int ps3fb_probe(struct ps3_system_bus_device *dev)
> }
> #endif
>
> - max_ps3fb_size = _ALIGN_UP(GPU_IOIF, 256*1024*1024) - GPU_IOIF;
> + max_ps3fb_size = ALIGN(GPU_IOIF, 256*1024*1024) - GPU_IOIF;
> if (ps3fb_videomemory.size > max_ps3fb_size) {
> dev_info(&dev->core, "Limiting ps3fb mem size to %lu bytes\n",
> max_ps3fb_size);
> diff --git a/sound/ppc/snd_ps3.c b/sound/ppc/snd_ps3.c
> index 6d2a33b8faa0..b8161a08f2ca 100644
> --- a/sound/ppc/snd_ps3.c
> +++ b/sound/ppc/snd_ps3.c
> @@ -926,7 +926,7 @@ static int snd_ps3_driver_probe(struct ps3_system_bus_device *dev)
> PAGE_SHIFT, /* use system page size */
> 0, /* dma type; not used */
> NULL,
> - _ALIGN_UP(SND_PS3_DMA_REGION_SIZE, PAGE_SIZE));
> + ALIGN(SND_PS3_DMA_REGION_SIZE, PAGE_SIZE));
> dev->d_region->ioid = PS3_AUDIO_IOID;
>
> ret = ps3_dma_region_create(dev->d_region);
> --
> 2.25.0
>

2020-04-21 01:05:48

by Joel Stanley

[permalink] [raw]
Subject: Re: [PATCH 2/5] powerpc: Replace _ALIGN_DOWN() by ALIGN_DOWN()

On Mon, 20 Apr 2020 at 18:38, Christophe Leroy <[email protected]> wrote:
>
> _ALIGN_DOWN() is specific to powerpc
> ALIGN_DOWN() is generic and does the same
>
> Replace _ALIGN_DOWN() by ALIGN_DOWN()

This one is a bit less obvious. It becomes (leaving the typeof's alone
for clarity):

-((addr)&(~((typeof(addr))(size)-1)))
+((((addr) - ((size) - 1)) + ((typeof(addr))(size) - 1)) &
~((typeof(addr))(size)-1))

Which I assume the compiler will sort out?

Reviewed-by: Joel Stanley <[email protected]>




>
> Signed-off-by: Christophe Leroy <[email protected]>
> ---
> arch/powerpc/include/asm/book3s/32/pgtable.h | 2 +-
> arch/powerpc/include/asm/nohash/32/pgtable.h | 2 +-
> arch/powerpc/kernel/pci_64.c | 2 +-
> arch/powerpc/kernel/prom.c | 6 +++---
> arch/powerpc/kernel/prom_init.c | 8 ++++----
> arch/powerpc/mm/book3s64/hash_tlb.c | 4 ++--
> arch/powerpc/mm/init_64.c | 4 ++--
> arch/powerpc/platforms/powernv/opal-fadump.c | 2 +-
> arch/powerpc/platforms/powernv/pci-ioda.c | 2 +-
> arch/powerpc/platforms/ps3/mm.c | 14 +++++++-------
> arch/powerpc/platforms/pseries/rtas-fadump.c | 2 +-
> 11 files changed, 24 insertions(+), 24 deletions(-)
>
> diff --git a/arch/powerpc/include/asm/book3s/32/pgtable.h b/arch/powerpc/include/asm/book3s/32/pgtable.h
> index 7549393c4c43..53b5c93eaf5d 100644
> --- a/arch/powerpc/include/asm/book3s/32/pgtable.h
> +++ b/arch/powerpc/include/asm/book3s/32/pgtable.h
> @@ -195,7 +195,7 @@ int map_kernel_page(unsigned long va, phys_addr_t pa, pgprot_t prot);
> #endif
>
> #ifdef CONFIG_KASAN_VMALLOC
> -#define VMALLOC_END _ALIGN_DOWN(ioremap_bot, PAGE_SIZE << KASAN_SHADOW_SCALE_SHIFT)
> +#define VMALLOC_END ALIGN_DOWN(ioremap_bot, PAGE_SIZE << KASAN_SHADOW_SCALE_SHIFT)
> #else
> #define VMALLOC_END ioremap_bot
> #endif
> diff --git a/arch/powerpc/include/asm/nohash/32/pgtable.h b/arch/powerpc/include/asm/nohash/32/pgtable.h
> index b04ba257fddb..5b4d4c4297e1 100644
> --- a/arch/powerpc/include/asm/nohash/32/pgtable.h
> +++ b/arch/powerpc/include/asm/nohash/32/pgtable.h
> @@ -116,7 +116,7 @@ int map_kernel_page(unsigned long va, phys_addr_t pa, pgprot_t prot);
> #endif
>
> #ifdef CONFIG_KASAN_VMALLOC
> -#define VMALLOC_END _ALIGN_DOWN(ioremap_bot, PAGE_SIZE << KASAN_SHADOW_SCALE_SHIFT)
> +#define VMALLOC_END ALIGN_DOWN(ioremap_bot, PAGE_SIZE << KASAN_SHADOW_SCALE_SHIFT)
> #else
> #define VMALLOC_END ioremap_bot
> #endif
> diff --git a/arch/powerpc/kernel/pci_64.c b/arch/powerpc/kernel/pci_64.c
> index f83d1f69b1dd..e5d05af5a9af 100644
> --- a/arch/powerpc/kernel/pci_64.c
> +++ b/arch/powerpc/kernel/pci_64.c
> @@ -130,7 +130,7 @@ static int pcibios_map_phb_io_space(struct pci_controller *hose)
> unsigned long size_page;
> unsigned long io_virt_offset;
>
> - phys_page = _ALIGN_DOWN(hose->io_base_phys, PAGE_SIZE);
> + phys_page = ALIGN_DOWN(hose->io_base_phys, PAGE_SIZE);
> size_page = _ALIGN_UP(hose->pci_io_size, PAGE_SIZE);
>
> /* Make sure IO area address is clear */
> diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c
> index 6620f37abe73..10b5d5eafd34 100644
> --- a/arch/powerpc/kernel/prom.c
> +++ b/arch/powerpc/kernel/prom.c
> @@ -96,7 +96,7 @@ static inline int overlaps_initrd(unsigned long start, unsigned long size)
> if (!initrd_start)
> return 0;
>
> - return (start + size) > _ALIGN_DOWN(initrd_start, PAGE_SIZE) &&
> + return (start + size) > ALIGN_DOWN(initrd_start, PAGE_SIZE) &&
> start <= _ALIGN_UP(initrd_end, PAGE_SIZE);
> #else
> return 0;
> @@ -623,9 +623,9 @@ static void __init early_reserve_mem(void)
> #ifdef CONFIG_BLK_DEV_INITRD
> /* Then reserve the initrd, if any */
> if (initrd_start && (initrd_end > initrd_start)) {
> - memblock_reserve(_ALIGN_DOWN(__pa(initrd_start), PAGE_SIZE),
> + memblock_reserve(ALIGN_DOWN(__pa(initrd_start), PAGE_SIZE),
> _ALIGN_UP(initrd_end, PAGE_SIZE) -
> - _ALIGN_DOWN(initrd_start, PAGE_SIZE));
> + ALIGN_DOWN(initrd_start, PAGE_SIZE));
> }
> #endif /* CONFIG_BLK_DEV_INITRD */
>
> diff --git a/arch/powerpc/kernel/prom_init.c b/arch/powerpc/kernel/prom_init.c
> index 806be751c336..4cf5958eebd4 100644
> --- a/arch/powerpc/kernel/prom_init.c
> +++ b/arch/powerpc/kernel/prom_init.c
> @@ -1500,7 +1500,7 @@ static unsigned long __init alloc_down(unsigned long size, unsigned long align,
>
> if (highmem) {
> /* Carve out storage for the TCE table. */
> - addr = _ALIGN_DOWN(alloc_top_high - size, align);
> + addr = ALIGN_DOWN(alloc_top_high - size, align);
> if (addr <= alloc_bottom)
> return 0;
> /* Will we bump into the RMO ? If yes, check out that we
> @@ -1518,9 +1518,9 @@ static unsigned long __init alloc_down(unsigned long size, unsigned long align,
> goto bail;
> }
>
> - base = _ALIGN_DOWN(alloc_top - size, align);
> + base = ALIGN_DOWN(alloc_top - size, align);
> for (; base > alloc_bottom;
> - base = _ALIGN_DOWN(base - 0x100000, align)) {
> + base = ALIGN_DOWN(base - 0x100000, align)) {
> prom_debug(" trying: 0x%lx\n\r", base);
> addr = (unsigned long)prom_claim(base, size, 0);
> if (addr != PROM_ERROR && addr != 0)
> @@ -1586,7 +1586,7 @@ static void __init reserve_mem(u64 base, u64 size)
> * have our terminator with "size" set to 0 since we are
> * dumb and just copy this entire array to the boot params
> */
> - base = _ALIGN_DOWN(base, PAGE_SIZE);
> + base = ALIGN_DOWN(base, PAGE_SIZE);
> top = _ALIGN_UP(top, PAGE_SIZE);
> size = top - base;
>
> diff --git a/arch/powerpc/mm/book3s64/hash_tlb.c b/arch/powerpc/mm/book3s64/hash_tlb.c
> index 4a70d8dd39cd..2242d022b620 100644
> --- a/arch/powerpc/mm/book3s64/hash_tlb.c
> +++ b/arch/powerpc/mm/book3s64/hash_tlb.c
> @@ -196,7 +196,7 @@ void __flush_hash_table_range(struct mm_struct *mm, unsigned long start,
> int hugepage_shift;
> unsigned long flags;
>
> - start = _ALIGN_DOWN(start, PAGE_SIZE);
> + start = ALIGN_DOWN(start, PAGE_SIZE);
> end = _ALIGN_UP(end, PAGE_SIZE);
>
> BUG_ON(!mm->pgd);
> @@ -238,7 +238,7 @@ void flush_tlb_pmd_range(struct mm_struct *mm, pmd_t *pmd, unsigned long addr)
> pte_t *start_pte;
> unsigned long flags;
>
> - addr = _ALIGN_DOWN(addr, PMD_SIZE);
> + addr = ALIGN_DOWN(addr, PMD_SIZE);
> /*
> * Note: Normally, we should only ever use a batch within a
> * PTE locked section. This violates the rule, but will work
> diff --git a/arch/powerpc/mm/init_64.c b/arch/powerpc/mm/init_64.c
> index 4002ced3596f..c7ce4ec5060e 100644
> --- a/arch/powerpc/mm/init_64.c
> +++ b/arch/powerpc/mm/init_64.c
> @@ -203,7 +203,7 @@ int __meminit vmemmap_populate(unsigned long start, unsigned long end, int node,
> unsigned long page_size = 1 << mmu_psize_defs[mmu_vmemmap_psize].shift;
>
> /* Align to the page size of the linear mapping. */
> - start = _ALIGN_DOWN(start, page_size);
> + start = ALIGN_DOWN(start, page_size);
>
> pr_debug("vmemmap_populate %lx..%lx, node %d\n", start, end, node);
>
> @@ -292,7 +292,7 @@ void __ref vmemmap_free(unsigned long start, unsigned long end,
> unsigned long alt_start = ~0, alt_end = ~0;
> unsigned long base_pfn;
>
> - start = _ALIGN_DOWN(start, page_size);
> + start = ALIGN_DOWN(start, page_size);
> if (altmap) {
> alt_start = altmap->base_pfn;
> alt_end = altmap->base_pfn + altmap->reserve +
> diff --git a/arch/powerpc/platforms/powernv/opal-fadump.c b/arch/powerpc/platforms/powernv/opal-fadump.c
> index d361d37d975f..9a360ced663b 100644
> --- a/arch/powerpc/platforms/powernv/opal-fadump.c
> +++ b/arch/powerpc/platforms/powernv/opal-fadump.c
> @@ -671,7 +671,7 @@ void __init opal_fadump_dt_scan(struct fw_dump *fadump_conf, u64 node)
> * Firmware supports 32-bit field for size. Align it to PAGE_SIZE
> * and request firmware to copy multiple kernel boot memory regions.
> */
> - fadump_conf->max_copy_size = _ALIGN_DOWN(U32_MAX, PAGE_SIZE);
> + fadump_conf->max_copy_size = ALIGN_DOWN(U32_MAX, PAGE_SIZE);
>
> /*
> * Check if dump has been initiated on last reboot.
> diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c b/arch/powerpc/platforms/powernv/pci-ioda.c
> index 57d3a6af1d52..276b011cd45d 100644
> --- a/arch/powerpc/platforms/powernv/pci-ioda.c
> +++ b/arch/powerpc/platforms/powernv/pci-ioda.c
> @@ -264,7 +264,7 @@ static void pnv_ioda_reserve_dev_m64_pe(struct pci_dev *pdev,
> if (!r->parent || !pnv_pci_is_m64(phb, r))
> continue;
>
> - start = _ALIGN_DOWN(r->start - base, sgsz);
> + start = ALIGN_DOWN(r->start - base, sgsz);
> end = _ALIGN_UP(r->end - base, sgsz);
> for (segno = start / sgsz; segno < end / sgsz; segno++) {
> if (pe_bitmap)
> diff --git a/arch/powerpc/platforms/ps3/mm.c b/arch/powerpc/platforms/ps3/mm.c
> index 423be34f0f5f..71ed37f7f475 100644
> --- a/arch/powerpc/platforms/ps3/mm.c
> +++ b/arch/powerpc/platforms/ps3/mm.c
> @@ -263,7 +263,7 @@ static int ps3_mm_region_create(struct mem_region *r, unsigned long size)
> int result;
> u64 muid;
>
> - r->size = _ALIGN_DOWN(size, 1 << PAGE_SHIFT_16M);
> + r->size = ALIGN_DOWN(size, 1 << PAGE_SHIFT_16M);
>
> DBG("%s:%d requested %lxh\n", __func__, __LINE__, size);
> DBG("%s:%d actual %llxh\n", __func__, __LINE__, r->size);
> @@ -394,7 +394,7 @@ static struct dma_chunk * dma_find_chunk(struct ps3_dma_region *r,
> unsigned long bus_addr, unsigned long len)
> {
> struct dma_chunk *c;
> - unsigned long aligned_bus = _ALIGN_DOWN(bus_addr, 1 << r->page_size);
> + unsigned long aligned_bus = ALIGN_DOWN(bus_addr, 1 << r->page_size);
> unsigned long aligned_len = _ALIGN_UP(len+bus_addr-aligned_bus,
> 1 << r->page_size);
>
> @@ -423,7 +423,7 @@ static struct dma_chunk *dma_find_chunk_lpar(struct ps3_dma_region *r,
> unsigned long lpar_addr, unsigned long len)
> {
> struct dma_chunk *c;
> - unsigned long aligned_lpar = _ALIGN_DOWN(lpar_addr, 1 << r->page_size);
> + unsigned long aligned_lpar = ALIGN_DOWN(lpar_addr, 1 << r->page_size);
> unsigned long aligned_len = _ALIGN_UP(len + lpar_addr - aligned_lpar,
> 1 << r->page_size);
>
> @@ -775,7 +775,7 @@ static int dma_sb_map_area(struct ps3_dma_region *r, unsigned long virt_addr,
> struct dma_chunk *c;
> unsigned long phys_addr = is_kernel_addr(virt_addr) ? __pa(virt_addr)
> : virt_addr;
> - unsigned long aligned_phys = _ALIGN_DOWN(phys_addr, 1 << r->page_size);
> + unsigned long aligned_phys = ALIGN_DOWN(phys_addr, 1 << r->page_size);
> unsigned long aligned_len = _ALIGN_UP(len + phys_addr - aligned_phys,
> 1 << r->page_size);
> *bus_addr = dma_sb_lpar_to_bus(r, ps3_mm_phys_to_lpar(phys_addr));
> @@ -830,7 +830,7 @@ static int dma_ioc0_map_area(struct ps3_dma_region *r, unsigned long virt_addr,
> struct dma_chunk *c;
> unsigned long phys_addr = is_kernel_addr(virt_addr) ? __pa(virt_addr)
> : virt_addr;
> - unsigned long aligned_phys = _ALIGN_DOWN(phys_addr, 1 << r->page_size);
> + unsigned long aligned_phys = ALIGN_DOWN(phys_addr, 1 << r->page_size);
> unsigned long aligned_len = _ALIGN_UP(len + phys_addr - aligned_phys,
> 1 << r->page_size);
>
> @@ -889,7 +889,7 @@ static int dma_sb_unmap_area(struct ps3_dma_region *r, dma_addr_t bus_addr,
> c = dma_find_chunk(r, bus_addr, len);
>
> if (!c) {
> - unsigned long aligned_bus = _ALIGN_DOWN(bus_addr,
> + unsigned long aligned_bus = ALIGN_DOWN(bus_addr,
> 1 << r->page_size);
> unsigned long aligned_len = _ALIGN_UP(len + bus_addr
> - aligned_bus, 1 << r->page_size);
> @@ -926,7 +926,7 @@ static int dma_ioc0_unmap_area(struct ps3_dma_region *r,
> c = dma_find_chunk(r, bus_addr, len);
>
> if (!c) {
> - unsigned long aligned_bus = _ALIGN_DOWN(bus_addr,
> + unsigned long aligned_bus = ALIGN_DOWN(bus_addr,
> 1 << r->page_size);
> unsigned long aligned_len = _ALIGN_UP(len + bus_addr
> - aligned_bus,
> diff --git a/arch/powerpc/platforms/pseries/rtas-fadump.c b/arch/powerpc/platforms/pseries/rtas-fadump.c
> index 70c3013fdd07..81343908ed33 100644
> --- a/arch/powerpc/platforms/pseries/rtas-fadump.c
> +++ b/arch/powerpc/platforms/pseries/rtas-fadump.c
> @@ -506,7 +506,7 @@ void __init rtas_fadump_dt_scan(struct fw_dump *fadump_conf, u64 node)
> fadump_conf->fadump_supported = 1;
>
> /* Firmware supports 64-bit value for size, align it to pagesize. */
> - fadump_conf->max_copy_size = _ALIGN_DOWN(U64_MAX, PAGE_SIZE);
> + fadump_conf->max_copy_size = ALIGN_DOWN(U64_MAX, PAGE_SIZE);
>
> /*
> * The 'ibm,kernel-dump' rtas node is present only if there is
> --
> 2.25.0
>

2020-04-21 15:59:22

by Segher Boessenkool

[permalink] [raw]
Subject: Re: [PATCH 2/5] powerpc: Replace _ALIGN_DOWN() by ALIGN_DOWN()

Hi!

On Tue, Apr 21, 2020 at 01:04:05AM +0000, Joel Stanley wrote:
> On Mon, 20 Apr 2020 at 18:38, Christophe Leroy <[email protected]> wrote:
> > _ALIGN_DOWN() is specific to powerpc
> > ALIGN_DOWN() is generic and does the same
> >
> > Replace _ALIGN_DOWN() by ALIGN_DOWN()
>
> This one is a bit less obvious. It becomes (leaving the typeof's alone
> for clarity):
>
> -((addr)&(~((typeof(addr))(size)-1)))
> +((((addr) - ((size) - 1)) + ((typeof(addr))(size) - 1)) &
> ~((typeof(addr))(size)-1))
>
> Which I assume the compiler will sort out?

[ This is line-wrapped, something in your mailer? Took me a bit to figure
out the - and + are diff -u things :-) ]

In the common case where size is a constant integer power of two, the
compiler will have no problem with this. But why do so complicated?

Why are the casts there, btw?


Segher

2020-05-20 11:02:07

by Michael Ellerman

[permalink] [raw]
Subject: Re: [PATCH 1/5] drivers/powerpc: Replace _ALIGN_UP() by ALIGN()

On Mon, 20 Apr 2020 18:36:34 +0000 (UTC), Christophe Leroy wrote:
> _ALIGN_UP() is specific to powerpc
> ALIGN() is generic and does the same
>
> Replace _ALIGN_UP() by ALIGN()

Applied to powerpc/next.

[1/5] drivers/powerpc: Replace _ALIGN_UP() by ALIGN()
https://git.kernel.org/powerpc/c/7bfc3c84cbf5167d943cff9b3d2619dab0b7894c
[2/5] powerpc: Replace _ALIGN_DOWN() by ALIGN_DOWN()
https://git.kernel.org/powerpc/c/e96d904ede6756641563d27daa746875b478a6c8
[3/5] powerpc: Replace _ALIGN_UP() by ALIGN()
https://git.kernel.org/powerpc/c/b711531641038f3ff3723914f3d5ba79848d347e
[4/5] powerpc: Replace _ALIGN() by ALIGN()
https://git.kernel.org/powerpc/c/d3f3d3bf76cfb04e73436a15e3987d3573e7523a
[5/5] powerpc: Remove _ALIGN_UP(), _ALIGN_DOWN() and _ALIGN()
https://git.kernel.org/powerpc/c/4cdb2da654033d76e1b1cb4ac427d9193dce816b

cheers