Re: [PATCH v2 6/8] powerpc: introduce early_get_first_memblock_info
On Sun, 2013-08-04 at 08:45 +0800, Kevin Hao wrote: On Fri, Jul 26, 2013 at 07:18:01PM -0500, Scott Wood wrote: + * This function run before early_init_devtree, so we have to init + * initial_boot_params. Since early_init_dt_scan_memory_ppc will be + * executed again in early_init_devtree, we have to reinitialize the + * memblock data before return. + */ +void __init early_get_first_memblock_info(void *params, phys_addr_t *size) +{ + /* Setup flat device-tree pointer */ + initial_boot_params = params; + + /* Scan memory nodes and rebuild MEMBLOCKs */ + of_scan_flat_dt(early_init_dt_scan_root, NULL); + of_scan_flat_dt(early_init_dt_scan_memory_ppc, NULL); + + if (size) + *size = first_memblock_size; + + /* Undo what early_init_dt_scan_memory_ppc does to memblock */ + memblock_reinit(); +} +#endif Wouldn't it be simpler to set a flag so that early_init_dt_add_memory_arch() doesn't mess with memblocks on the first pass? Do you mean something like this? diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c index 9a69d2d..e861394 100644 --- a/arch/powerpc/kernel/prom.c +++ b/arch/powerpc/kernel/prom.c @@ -523,6 +523,10 @@ static int __init early_init_dt_scan_memory_ppc(unsigned long node, void __init early_init_dt_add_memory_arch(u64 base, u64 size) { +#if defined(CONFIG_RELOCATABLE) defined(CONFIG_FSL_BOOKE) + static int first_time = 1; +#endif + #ifdef CONFIG_PPC64 if (iommu_is_off) { if (base = 0x8000ul) @@ -541,6 +545,13 @@ void __init early_init_dt_add_memory_arch(u64 base, u64 size) } /* Add the chunk to the MEMBLOCK list */ + +#if defined(CONFIG_RELOCATABLE) defined(CONFIG_FSL_BOOKE) + if (first_time) { + first_time = 0; + return; + } +#endif memblock_add(base, size); } I think it'd be clearer for it to be an external variable that gets set by the relocation code -- plus, the above wouldn't work if this gets called twice due to having multiple memory regions. -Scott ___ Linuxppc-dev mailing list Linuxppc-dev@lists.ozlabs.org https://lists.ozlabs.org/listinfo/linuxppc-dev
Re: [PATCH v2 6/8] powerpc: introduce early_get_first_memblock_info
On Mon, Aug 05, 2013 at 06:59:28PM -0500, Scott Wood wrote: On Sun, 2013-08-04 at 08:45 +0800, Kevin Hao wrote: memblock_add(base, size); snip } I think it'd be clearer for it to be an external variable that gets set by the relocation code -- plus, the above wouldn't work if this gets called twice due to having multiple memory regions. Got it. Thanks, Kevin -Scott pgpGkxlBJhcVW.pgp Description: PGP signature ___ Linuxppc-dev mailing list Linuxppc-dev@lists.ozlabs.org https://lists.ozlabs.org/listinfo/linuxppc-dev
Re: [PATCH v2 6/8] powerpc: introduce early_get_first_memblock_info
On Fri, Jul 26, 2013 at 07:18:01PM -0500, Scott Wood wrote: + * This function run before early_init_devtree, so we have to init + * initial_boot_params. Since early_init_dt_scan_memory_ppc will be + * executed again in early_init_devtree, we have to reinitialize the + * memblock data before return. + */ +void __init early_get_first_memblock_info(void *params, phys_addr_t *size) +{ +/* Setup flat device-tree pointer */ +initial_boot_params = params; + +/* Scan memory nodes and rebuild MEMBLOCKs */ +of_scan_flat_dt(early_init_dt_scan_root, NULL); +of_scan_flat_dt(early_init_dt_scan_memory_ppc, NULL); + +if (size) +*size = first_memblock_size; + +/* Undo what early_init_dt_scan_memory_ppc does to memblock */ +memblock_reinit(); +} +#endif Wouldn't it be simpler to set a flag so that early_init_dt_add_memory_arch() doesn't mess with memblocks on the first pass? Do you mean something like this? diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c index 9a69d2d..e861394 100644 --- a/arch/powerpc/kernel/prom.c +++ b/arch/powerpc/kernel/prom.c @@ -523,6 +523,10 @@ static int __init early_init_dt_scan_memory_ppc(unsigned long node, void __init early_init_dt_add_memory_arch(u64 base, u64 size) { +#if defined(CONFIG_RELOCATABLE) defined(CONFIG_FSL_BOOKE) + static int first_time = 1; +#endif + #ifdef CONFIG_PPC64 if (iommu_is_off) { if (base = 0x8000ul) @@ -541,6 +545,13 @@ void __init early_init_dt_add_memory_arch(u64 base, u64 size) } /* Add the chunk to the MEMBLOCK list */ + +#if defined(CONFIG_RELOCATABLE) defined(CONFIG_FSL_BOOKE) + if (first_time) { + first_time = 0; + return; + } +#endif memblock_add(base, size); } Thanks, Kevin -Scott pgpZRszO_3VKD.pgp Description: PGP signature ___ Linuxppc-dev mailing list Linuxppc-dev@lists.ozlabs.org https://lists.ozlabs.org/listinfo/linuxppc-dev
Re: [PATCH v2 6/8] powerpc: introduce early_get_first_memblock_info
On 07/04/2013 07:54:12 AM, Kevin Hao wrote: For a relocatable kernel since it can be loaded at any place, there is no any relation between the kernel start addr and the memstart_addr. So we can't calculate the memstart_addr from kernel start addr. And also we can't wait to do the relocation after we get the real memstart_addr from device tree because it is so late. So introduce a new function we can use to get the first memblock address and size in a very early stage (before machine_init). Signed-off-by: Kevin Hao haoke...@gmail.com --- A new patch in v2. arch/powerpc/kernel/prom.c | 24 include/linux/of_fdt.h | 1 + 2 files changed, 25 insertions(+) diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c index eb23ac9..9a69d2d 100644 --- a/arch/powerpc/kernel/prom.c +++ b/arch/powerpc/kernel/prom.c @@ -753,6 +753,30 @@ void __init early_init_devtree(void *params) DBG( - early_init_devtree()\n); } +#ifdef CONFIG_RELOCATABLE +/* + * This function run before early_init_devtree, so we have to init + * initial_boot_params. Since early_init_dt_scan_memory_ppc will be + * executed again in early_init_devtree, we have to reinitialize the + * memblock data before return. + */ +void __init early_get_first_memblock_info(void *params, phys_addr_t *size) +{ + /* Setup flat device-tree pointer */ + initial_boot_params = params; + + /* Scan memory nodes and rebuild MEMBLOCKs */ + of_scan_flat_dt(early_init_dt_scan_root, NULL); + of_scan_flat_dt(early_init_dt_scan_memory_ppc, NULL); + + if (size) + *size = first_memblock_size; + + /* Undo what early_init_dt_scan_memory_ppc does to memblock */ + memblock_reinit(); +} +#endif Wouldn't it be simpler to set a flag so that early_init_dt_add_memory_arch() doesn't mess with memblocks on the first pass? -Scott ___ Linuxppc-dev mailing list Linuxppc-dev@lists.ozlabs.org https://lists.ozlabs.org/listinfo/linuxppc-dev
[PATCH v2 6/8] powerpc: introduce early_get_first_memblock_info
For a relocatable kernel since it can be loaded at any place, there is no any relation between the kernel start addr and the memstart_addr. So we can't calculate the memstart_addr from kernel start addr. And also we can't wait to do the relocation after we get the real memstart_addr from device tree because it is so late. So introduce a new function we can use to get the first memblock address and size in a very early stage (before machine_init). Signed-off-by: Kevin Hao haoke...@gmail.com --- A new patch in v2. arch/powerpc/kernel/prom.c | 24 include/linux/of_fdt.h | 1 + 2 files changed, 25 insertions(+) diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c index eb23ac9..9a69d2d 100644 --- a/arch/powerpc/kernel/prom.c +++ b/arch/powerpc/kernel/prom.c @@ -753,6 +753,30 @@ void __init early_init_devtree(void *params) DBG( - early_init_devtree()\n); } +#ifdef CONFIG_RELOCATABLE +/* + * This function run before early_init_devtree, so we have to init + * initial_boot_params. Since early_init_dt_scan_memory_ppc will be + * executed again in early_init_devtree, we have to reinitialize the + * memblock data before return. + */ +void __init early_get_first_memblock_info(void *params, phys_addr_t *size) +{ + /* Setup flat device-tree pointer */ + initial_boot_params = params; + + /* Scan memory nodes and rebuild MEMBLOCKs */ + of_scan_flat_dt(early_init_dt_scan_root, NULL); + of_scan_flat_dt(early_init_dt_scan_memory_ppc, NULL); + + if (size) + *size = first_memblock_size; + + /* Undo what early_init_dt_scan_memory_ppc does to memblock */ + memblock_reinit(); +} +#endif + /*** * * New implementation of the OF find APIs, return a refcounted diff --git a/include/linux/of_fdt.h b/include/linux/of_fdt.h index ed136ad..befe744 100644 --- a/include/linux/of_fdt.h +++ b/include/linux/of_fdt.h @@ -117,6 +117,7 @@ extern int early_init_dt_scan_root(unsigned long node, const char *uname, /* Other Prototypes */ extern void unflatten_device_tree(void); extern void early_init_devtree(void *); +extern void early_get_first_memblock_info(void *, phys_addr_t *); #else /* CONFIG_OF_FLATTREE */ static inline void unflatten_device_tree(void) {} #endif /* CONFIG_OF_FLATTREE */ -- 1.8.1.4 ___ Linuxppc-dev mailing list Linuxppc-dev@lists.ozlabs.org https://lists.ozlabs.org/listinfo/linuxppc-dev