From e495a51603bc98a328fc33420ed601ddaa8ac4fb Mon Sep 17 00:00:00 2001 From: Armin Luntzer <armin.luntzer@univie.ac.at> Date: Wed, 13 Nov 2019 12:40:07 +0100 Subject: [PATCH] SPARC bootmem: - rename struct - refactor code slightly - properly save and restore interrupt flags for critical sections --- arch/sparc/include/mm.h | 4 +-- arch/sparc/kernel/bootmem.c | 64 ++++++++++++++++++++++--------------- arch/sparc/kernel/mm.c | 2 +- 3 files changed, 42 insertions(+), 28 deletions(-) diff --git a/arch/sparc/include/mm.h b/arch/sparc/include/mm.h index 5508c19..e5a5f11 100644 --- a/arch/sparc/include/mm.h +++ b/arch/sparc/include/mm.h @@ -17,7 +17,7 @@ * last valid one has num_bytes==0. */ -struct sparc_physical_banks { +struct sparc_physical_bank { unsigned long base_addr; unsigned long num_bytes; }; @@ -28,7 +28,7 @@ struct sparc_physical_banks { #define SPARC_PHYS_BANKS 0 #endif -extern struct sparc_physical_banks sp_banks[SPARC_PHYS_BANKS + 1]; +extern struct sparc_physical_bank sp_banks[SPARC_PHYS_BANKS + 1]; /* linker symbol marking the the start of the program (image) */ diff --git a/arch/sparc/kernel/bootmem.c b/arch/sparc/kernel/bootmem.c index f554ccf..a5e15cf 100644 --- a/arch/sparc/kernel/bootmem.c +++ b/arch/sparc/kernel/bootmem.c @@ -100,14 +100,17 @@ void *bootmem_alloc(size_t size) { void *ptr; + unsigned long flags; + + if (!size) return NULL; - arch_local_irq_disable(); + flags = arch_local_irq_save(); spin_lock_raw(&bootmem_lock); ptr = chunk_alloc(&phys_mem_pool, size); spin_unlock(&bootmem_lock); - arch_local_irq_enable(); + arch_local_irq_restore(flags); if (!ptr) { pr_emerg("BOOTMEM: allocator out of memory\n"); @@ -126,17 +129,41 @@ void *bootmem_alloc(size_t size) void bootmem_free(void *ptr) { -#if 0 - arch_local_irq_disable(); -#endif + unsigned long flags; + + flags = arch_local_irq_save(); spin_lock_raw(&bootmem_lock); chunk_free(&phys_mem_pool, ptr); spin_unlock(&bootmem_lock); -#if 0 - arch_local_irq_enable(); -#endif + arch_local_irq_restore(flags); +} + + +/** + * @brief allocate and add a page map node + */ + +static void bootmem_init_page_map_node(struct page_map_node **pg_node) +{ + struct mm_pool *pool; + + + /* let's assume we always have enough memory, because if we + * don't, there is a serious configuration problem anyways + */ + + (*pg_node) = (struct page_map_node *) bootmem_alloc(sizeof(struct page_map_node)); + + pool = (*pg_node)->pool; + pool = (struct mm_pool *) bootmem_alloc(sizeof(struct mm_pool)); + + bzero(pool, sizeof(struct mm_pool)); + + pool->block_order = (struct list_head *) bootmem_alloc(sizeof(struct list_head) * (MM_BLOCK_ORDER_MAX + 1)); + pool->alloc_order = (unsigned char *) bootmem_alloc(MM_INIT_NUM_BLOCKS); + pool->blk_free = (unsigned long *) bootmem_alloc(MM_INIT_LEN_BITMAP * sizeof(unsigned long)); } @@ -150,6 +177,7 @@ void bootmem_init(void) int ret; + unsigned long base_pfn; unsigned long start_pfn; unsigned long start_img_pfn; @@ -283,7 +311,6 @@ void bootmem_init(void) #else for (i = 0; sp_banks[i].num_bytes != 0; i++) { #endif - BUG_ON(i > SPARC_PHYS_BANKS); /* this one has already been added */ @@ -299,24 +326,11 @@ void bootmem_init(void) break; } - /* let's assume we always have enough memory, because if we - * don't, there is a serious configuration problem anyways - * - * XXX this should be a function... - */ - - (*pg_node) = (struct page_map_node *) bootmem_alloc(sizeof(struct page_map_node)); - (*pg_node)->pool = (struct mm_pool *) bootmem_alloc(sizeof(struct mm_pool)); - - bzero((*pg_node)->pool, sizeof(struct mm_pool)); - - (*pg_node)->pool->block_order = (struct list_head *) bootmem_alloc(sizeof(struct list_head) * (MM_BLOCK_ORDER_MAX + 1)); - (*pg_node)->pool->alloc_order = (unsigned char *) bootmem_alloc(MM_INIT_NUM_BLOCKS); - (*pg_node)->pool->blk_free = (unsigned long *) bootmem_alloc(MM_INIT_LEN_BITMAP * sizeof(unsigned long)); + bootmem_init_page_map_node(pg_node); ret = page_map_add(sp_banks[i].base_addr, - sp_banks[i].base_addr + sp_banks[i].num_bytes, - PAGE_SIZE); + sp_banks[i].base_addr + sp_banks[i].num_bytes, + PAGE_SIZE); if (ret) { pr_emerg("BOOTMEM: cannot add page map node\n"); diff --git a/arch/sparc/kernel/mm.c b/arch/sparc/kernel/mm.c index fc3b53c..f694470 100644 --- a/arch/sparc/kernel/mm.c +++ b/arch/sparc/kernel/mm.c @@ -19,4 +19,4 @@ unsigned long phys_base; unsigned long pfn_base; -struct sparc_physical_banks sp_banks[SPARC_PHYS_BANKS + 1]; +struct sparc_physical_bank sp_banks[SPARC_PHYS_BANKS + 1]; -- GitLab