diff mbox

[kvm-unit-tests,v3,07/11] s390x: initialize the physical allocator

Message ID 20180213162321.20522-8-david@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

David Hildenbrand Feb. 13, 2018, 4:23 p.m. UTC
We now have the range of free memory, let's initialize the physical
allocator. It is now possible to use use malloc and memalign, based on the
early-ops. alloc_pages() cannot be used yet (as it has to be initialized
via free_pages() - e.g. via setup_vm() - first)

Signed-off-by: David Hildenbrand <david@redhat.com>
---
 lib/s390x/sclp.c | 12 ++++++++++++
 s390x/Makefile   |  3 +++
 2 files changed, 15 insertions(+)

Comments

Thomas Huth Feb. 14, 2018, 12:05 p.m. UTC | #1
On 13.02.2018 17:23, David Hildenbrand wrote:
> We now have the range of free memory, let's initialize the physical
> allocator. It is now possible to use use malloc and memalign, based on the
> early-ops. alloc_pages() cannot be used yet (as it has to be initialized
> via free_pages() - e.g. via setup_vm() - first)
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
>  lib/s390x/sclp.c | 12 ++++++++++++
>  s390x/Makefile   |  3 +++
>  2 files changed, 15 insertions(+)
> 
> diff --git a/lib/s390x/sclp.c b/lib/s390x/sclp.c
> index 199405c..c7471b1 100644
> --- a/lib/s390x/sclp.c
> +++ b/lib/s390x/sclp.c
> @@ -15,11 +15,21 @@
>  #include <asm/arch_def.h>
>  #include <asm/interrupt.h>
>  #include "sclp.h"
> +#include <alloc_phys.h>
> +
> +extern unsigned long stacktop;
>  
>  static uint64_t storage_increment_size;
>  static uint64_t max_ram_size;
>  static uint64_t ram_size;
>  
> +static void mem_init(phys_addr_t mem_end)
> +{
> +	phys_addr_t freemem_start = (phys_addr_t)&stacktop & PAGE_MASK;

Should be ok since stacktop should be aligned. Otherwise this should
maybe better be (stacktop + PAGE_SIZE - 1) & PAGE_MASK ?

 Thomas
David Hildenbrand Feb. 14, 2018, 12:22 p.m. UTC | #2
On 14.02.2018 13:05, Thomas Huth wrote:
> On 13.02.2018 17:23, David Hildenbrand wrote:
>> We now have the range of free memory, let's initialize the physical
>> allocator. It is now possible to use use malloc and memalign, based on the
>> early-ops. alloc_pages() cannot be used yet (as it has to be initialized
>> via free_pages() - e.g. via setup_vm() - first)
>>
>> Signed-off-by: David Hildenbrand <david@redhat.com>
>> ---
>>  lib/s390x/sclp.c | 12 ++++++++++++
>>  s390x/Makefile   |  3 +++
>>  2 files changed, 15 insertions(+)
>>
>> diff --git a/lib/s390x/sclp.c b/lib/s390x/sclp.c
>> index 199405c..c7471b1 100644
>> --- a/lib/s390x/sclp.c
>> +++ b/lib/s390x/sclp.c
>> @@ -15,11 +15,21 @@
>>  #include <asm/arch_def.h>
>>  #include <asm/interrupt.h>
>>  #include "sclp.h"
>> +#include <alloc_phys.h>
>> +
>> +extern unsigned long stacktop;
>>  
>>  static uint64_t storage_increment_size;
>>  static uint64_t max_ram_size;
>>  static uint64_t ram_size;
>>  
>> +static void mem_init(phys_addr_t mem_end)
>> +{
>> +	phys_addr_t freemem_start = (phys_addr_t)&stacktop & PAGE_MASK;
> 
> Should be ok since stacktop should be aligned. Otherwise this should
> maybe better be (stacktop + PAGE_SIZE - 1) & PAGE_MASK ?
> 

Either that or drop the "& PAGE_MASK". But guess this doesn't really
make a difference right now. Thanks!

>  Thomas
>
diff mbox

Patch

diff --git a/lib/s390x/sclp.c b/lib/s390x/sclp.c
index 199405c..c7471b1 100644
--- a/lib/s390x/sclp.c
+++ b/lib/s390x/sclp.c
@@ -15,11 +15,21 @@ 
 #include <asm/arch_def.h>
 #include <asm/interrupt.h>
 #include "sclp.h"
+#include <alloc_phys.h>
+
+extern unsigned long stacktop;
 
 static uint64_t storage_increment_size;
 static uint64_t max_ram_size;
 static uint64_t ram_size;
 
+static void mem_init(phys_addr_t mem_end)
+{
+	phys_addr_t freemem_start = (phys_addr_t)&stacktop & PAGE_MASK;
+
+	phys_alloc_init(freemem_start, mem_end - freemem_start);
+}
+
 void sclp_memory_setup(void)
 {
 	ReadInfo *ri = (void *)_sccb;
@@ -55,4 +65,6 @@  void sclp_memory_setup(void)
 			break;
 		ram_size += storage_increment_size;
 	}
+
+	mem_init(ram_size);
 }
diff --git a/s390x/Makefile b/s390x/Makefile
index ce63dd1..4198fdc 100644
--- a/s390x/Makefile
+++ b/s390x/Makefile
@@ -21,6 +21,9 @@  asm-offsets = lib/$(ARCH)/asm-offsets.h
 include $(SRCDIR)/scripts/asm-offsets.mak
 
 cflatobjs += lib/util.o
+cflatobjs += lib/alloc.o
+cflatobjs += lib/alloc_phys.o
+cflatobjs += lib/alloc_page.o
 cflatobjs += lib/alloc_phys.o
 cflatobjs += lib/s390x/io.o
 cflatobjs += lib/s390x/stack.o