2018-07-16 07:51:14

by Mike Rapoport

[permalink] [raw]
Subject: [PATCH] hexagon: switch to NO_BOOTMEM

This patch adds registration of the system memory with memblock, eliminates
bootmem initialization and converts early memory reservations from bootmem
to memblock.

Signed-off-by: Mike Rapoport <[email protected]>
---

Build tested only.

arch/hexagon/Kconfig | 3 +++
arch/hexagon/mm/init.c | 20 ++++++++------------
2 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/arch/hexagon/Kconfig b/arch/hexagon/Kconfig
index 37adb20..66fb2d5 100644
--- a/arch/hexagon/Kconfig
+++ b/arch/hexagon/Kconfig
@@ -28,6 +28,9 @@ config HEXAGON
select GENERIC_CLOCKEVENTS_BROADCAST
select MODULES_USE_ELF_RELA
select GENERIC_CPU_DEVICES
+ select HAVE_MEMBLOCK
+ select ARCH_DISCARD_MEMBLOCK
+ select NO_BOOTMEM
---help---
Qualcomm Hexagon is a processor architecture designed for high
performance and low power across a wide variety of applications.
diff --git a/arch/hexagon/mm/init.c b/arch/hexagon/mm/init.c
index 1495d45..8d265bf 100644
--- a/arch/hexagon/mm/init.c
+++ b/arch/hexagon/mm/init.c
@@ -21,6 +21,7 @@
#include <linux/init.h>
#include <linux/mm.h>
#include <linux/bootmem.h>
+#include <linux/memblock.h>
#include <asm/atomic.h>
#include <linux/highmem.h>
#include <asm/tlb.h>
@@ -176,7 +177,6 @@ size_t hexagon_coherent_pool_size = (size_t) (DMA_RESERVE << 22);

void __init setup_arch_memory(void)
{
- int bootmap_size;
/* XXX Todo: this probably should be cleaned up */
u32 *segtable = (u32 *) &swapper_pg_dir[0];
u32 *segtable_end;
@@ -195,18 +195,22 @@ void __init setup_arch_memory(void)
bootmem_lastpg = PFN_DOWN((bootmem_lastpg << PAGE_SHIFT) &
~((BIG_KERNEL_PAGE_SIZE) - 1));

+ memblock_add(PHYS_OFFSET,
+ (bootmem_lastpg - ARCH_PFN_OFFSET) << PAGE_SHIFT);
+
+ /* Reserve kernel text/data/bss */
+ memblock_reserve(PHYS_OFFSET,
+ (bootmem_startpg - PHYS_OFFSET) << PAGE_SHIFT);
/*
* Reserve the top DMA_RESERVE bytes of RAM for DMA (uncached)
* memory allocation
*/
-
max_low_pfn = bootmem_lastpg - PFN_DOWN(DMA_RESERVED_BYTES);
min_low_pfn = ARCH_PFN_OFFSET;
- bootmap_size = init_bootmem_node(NODE_DATA(0), bootmem_startpg, min_low_pfn, max_low_pfn);
+ memblock_reserve(PFN_PHYS(max_low_pfn), DMA_RESERVED_BYTES);

printk(KERN_INFO "bootmem_startpg: 0x%08lx\n", bootmem_startpg);
printk(KERN_INFO "bootmem_lastpg: 0x%08lx\n", bootmem_lastpg);
- printk(KERN_INFO "bootmap_size: %d\n", bootmap_size);
printk(KERN_INFO "min_low_pfn: 0x%08lx\n", min_low_pfn);
printk(KERN_INFO "max_low_pfn: 0x%08lx\n", max_low_pfn);

@@ -257,14 +261,6 @@ void __init setup_arch_memory(void)
#endif

/*
- * Free all the memory that wasn't taken up by the bootmap, the DMA
- * reserve, or kernel itself.
- */
- free_bootmem(PFN_PHYS(bootmem_startpg) + bootmap_size,
- PFN_PHYS(bootmem_lastpg - bootmem_startpg) - bootmap_size -
- DMA_RESERVED_BYTES);
-
- /*
* The bootmem allocator seemingly just lives to feed memory
* to the paging system
*/
--
2.7.4



2018-07-23 21:25:52

by Richard Kuo

[permalink] [raw]
Subject: Re: [PATCH] hexagon: switch to NO_BOOTMEM


On Mon, Jul 16, 2018 at 10:43:18AM +0300, Mike Rapoport wrote:
> This patch adds registration of the system memory with memblock, eliminates
> bootmem initialization and converts early memory reservations from bootmem
> to memblock.
>
> Signed-off-by: Mike Rapoport <[email protected]>

Sorry for the delay, and thanks for this patch.

I think the first memblock_reserve should use ARCH_PFN_OFFSET instead of
PHYS_OFFSET.

If you can amend that I'd be happy to take it through my tree or it can go
through any other.


Thanks,
Richard Kuo


--
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

2018-07-24 05:48:48

by Mike Rapoport

[permalink] [raw]
Subject: Re: [PATCH] hexagon: switch to NO_BOOTMEM

On Mon, Jul 23, 2018 at 04:23:39PM -0500, Richard Kuo wrote:
>
> On Mon, Jul 16, 2018 at 10:43:18AM +0300, Mike Rapoport wrote:
> > This patch adds registration of the system memory with memblock, eliminates
> > bootmem initialization and converts early memory reservations from bootmem
> > to memblock.
> >
> > Signed-off-by: Mike Rapoport <[email protected]>
>
> Sorry for the delay, and thanks for this patch.
>
> I think the first memblock_reserve should use ARCH_PFN_OFFSET instead of
> PHYS_OFFSET.

memblock_reserve gets physical address rather than a pfn.

If I read arch/hexagon/include/asm/mem-layout.h correctly, the PHYS_OFFSET
*is* the physical address of the RAM and ARCH_PFN_OFFSET is the first pfn:

#define PHYS_PFN_OFFSET (PHYS_OFFSET >> PAGE_SHIFT)
#define ARCH_PFN_OFFSET PHYS_PFN_OFFSET

Did I miss something?

> If you can amend that I'd be happy to take it through my tree or it can go
> through any other.
>
>
> Thanks,
> Richard Kuo
>
>
> --
> Employee of Qualcomm Innovation Center, Inc.
> Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> a Linux Foundation Collaborative Project
>

--
Sincerely yours,
Mike.


2018-07-25 02:14:00

by Richard Kuo

[permalink] [raw]
Subject: Re: [PATCH] hexagon: switch to NO_BOOTMEM

On Tue, Jul 24, 2018 at 08:47:04AM +0300, Mike Rapoport wrote:
> On Mon, Jul 23, 2018 at 04:23:39PM -0500, Richard Kuo wrote:
> >
> > On Mon, Jul 16, 2018 at 10:43:18AM +0300, Mike Rapoport wrote:
> > > This patch adds registration of the system memory with memblock, eliminates
> > > bootmem initialization and converts early memory reservations from bootmem
> > > to memblock.
> > >
> > > Signed-off-by: Mike Rapoport <[email protected]>
> >
> > Sorry for the delay, and thanks for this patch.
> >
> > I think the first memblock_reserve should use ARCH_PFN_OFFSET instead of
> > PHYS_OFFSET.
>
> memblock_reserve gets physical address rather than a pfn.
>
> If I read arch/hexagon/include/asm/mem-layout.h correctly, the PHYS_OFFSET
> *is* the physical address of the RAM and ARCH_PFN_OFFSET is the first pfn:
>
> #define PHYS_PFN_OFFSET (PHYS_OFFSET >> PAGE_SHIFT)
> #define ARCH_PFN_OFFSET PHYS_PFN_OFFSET
>
> Did I miss something?

Sorry, I should have been more clear. In the size calculation, it's
subtracting the unshifted PHYS_OFFSET from the start page number, which
I'm pretty sure is wrong.


Thanks,
Richard Kuo


--
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

2018-07-25 05:30:26

by Mike Rapoport

[permalink] [raw]
Subject: Re: [PATCH] hexagon: switch to NO_BOOTMEM

On Tue, Jul 24, 2018 at 09:12:55PM -0500, Richard Kuo wrote:
> On Tue, Jul 24, 2018 at 08:47:04AM +0300, Mike Rapoport wrote:
> > On Mon, Jul 23, 2018 at 04:23:39PM -0500, Richard Kuo wrote:
> > >
> > > On Mon, Jul 16, 2018 at 10:43:18AM +0300, Mike Rapoport wrote:
> > > > This patch adds registration of the system memory with memblock, eliminates
> > > > bootmem initialization and converts early memory reservations from bootmem
> > > > to memblock.
> > > >
> > > > Signed-off-by: Mike Rapoport <[email protected]>
> > >
> > > Sorry for the delay, and thanks for this patch.
> > >
> > > I think the first memblock_reserve should use ARCH_PFN_OFFSET instead of
> > > PHYS_OFFSET.
> >
> > memblock_reserve gets physical address rather than a pfn.
> >
> > If I read arch/hexagon/include/asm/mem-layout.h correctly, the PHYS_OFFSET
> > *is* the physical address of the RAM and ARCH_PFN_OFFSET is the first pfn:
> >
> > #define PHYS_PFN_OFFSET (PHYS_OFFSET >> PAGE_SHIFT)
> > #define ARCH_PFN_OFFSET PHYS_PFN_OFFSET
> >
> > Did I miss something?
>
> Sorry, I should have been more clear. In the size calculation, it's
> subtracting the unshifted PHYS_OFFSET from the start page number, which
> I'm pretty sure is wrong.

Yeah, you're right. I've missed that one.

> Thanks,
> Richard Kuo
>
>
> --
> Employee of Qualcomm Innovation Center, Inc.
> Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> a Linux Foundation Collaborative Project
>

--
Sincerely yours,
Mike.