From: David Hildenbrand <david@redhat.com>
To: kvm@vger.kernel.org
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
"Radim Krčmář" <rkrcmar@redhat.com>,
"Thomas Huth" <thuth@redhat.com>,
"Cornelia Huck" <cohuck@redhat.com>,
"Christian Borntraeger" <borntraeger@de.ibm.com>,
"David Hildenbrand" <david@redhat.com>
Subject: [PATCH kvm-unit-tests v3 06/11] s390x: detect installed memory
Date: Tue, 13 Feb 2018 17:23:16 +0100 [thread overview]
Message-ID: <20180213162321.20522-7-david@redhat.com> (raw)
In-Reply-To: <20180213162321.20522-1-david@redhat.com>
Unfortunately, there is no easy way to simply read out the amount
of installed memory. We have to probe (via TEST PROTECTION) for installed
memory in a given range.
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
lib/s390x/asm/arch_def.h | 12 ++++++++++
lib/s390x/asm/interrupt.h | 1 +
lib/s390x/interrupt.c | 11 +++++++++
lib/s390x/io.c | 1 +
lib/s390x/sclp.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++
lib/s390x/sclp.h | 1 +
s390x/Makefile | 1 +
7 files changed, 85 insertions(+)
create mode 100644 lib/s390x/sclp.c
diff --git a/lib/s390x/asm/arch_def.h b/lib/s390x/asm/arch_def.h
index 72e5c60..ee4c96f 100644
--- a/lib/s390x/asm/arch_def.h
+++ b/lib/s390x/asm/arch_def.h
@@ -151,4 +151,16 @@ struct cpuid {
uint64_t reserved : 15;
};
+static inline int tprot(unsigned long addr)
+{
+ int cc;
+
+ asm volatile(
+ " tprot 0(%1),0\n"
+ " ipm %0\n"
+ " srl %0,28\n"
+ : "=d" (cc) : "a" (addr) : "cc");
+ return cc;
+}
+
#endif
diff --git a/lib/s390x/asm/interrupt.h b/lib/s390x/asm/interrupt.h
index 41be039..3ccc8e3 100644
--- a/lib/s390x/asm/interrupt.h
+++ b/lib/s390x/asm/interrupt.h
@@ -13,6 +13,7 @@
void handle_pgm_int(void);
void expect_pgm_int(void);
+uint16_t clear_pgm_int(void);
void check_pgm_int_code(uint16_t code);
/* Activate low-address protection */
diff --git a/lib/s390x/interrupt.c b/lib/s390x/interrupt.c
index 8d861a2..67d581b 100644
--- a/lib/s390x/interrupt.c
+++ b/lib/s390x/interrupt.c
@@ -23,6 +23,17 @@ void expect_pgm_int(void)
mb();
}
+uint16_t clear_pgm_int(void)
+{
+ uint16_t code;
+
+ mb();
+ code = lc->pgm_int_code;
+ lc->pgm_int_code = 0;
+ pgm_int_expected = false;
+ return code;
+}
+
void check_pgm_int_code(uint16_t code)
{
mb();
diff --git a/lib/s390x/io.c b/lib/s390x/io.c
index 3121a78..eb4d171 100644
--- a/lib/s390x/io.c
+++ b/lib/s390x/io.c
@@ -43,6 +43,7 @@ void setup()
setup_args_progname(ipl_args);
setup_facilities();
sclp_ascii_setup();
+ sclp_memory_setup();
}
void exit(int code)
diff --git a/lib/s390x/sclp.c b/lib/s390x/sclp.c
new file mode 100644
index 0000000..199405c
--- /dev/null
+++ b/lib/s390x/sclp.c
@@ -0,0 +1,58 @@
+/*
+ * s390x SCLP driver
+ *
+ * Copyright (c) 2017 Red Hat Inc
+ *
+ * Authors:
+ * David Hildenbrand <david@redhat.com>
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Library General Public License version 2.
+ */
+
+#include <libcflat.h>
+#include <asm/page.h>
+#include <asm/arch_def.h>
+#include <asm/interrupt.h>
+#include "sclp.h"
+
+static uint64_t storage_increment_size;
+static uint64_t max_ram_size;
+static uint64_t ram_size;
+
+void sclp_memory_setup(void)
+{
+ ReadInfo *ri = (void *)_sccb;
+ uint64_t rnmax, rnsize;
+ int cc;
+
+ ri->h.length = SCCB_SIZE;
+ sclp_service_call(SCLP_CMDW_READ_SCP_INFO_FORCED, ri);
+
+ /* calculate the storage increment size */
+ rnsize = ri->rnsize;
+ if (!rnsize) {
+ rnsize = ri->rnsize2;
+ }
+ storage_increment_size = rnsize << 20;
+
+ /* calculate the maximum memory size */
+ rnmax = ri->rnmax;
+ if (!rnmax) {
+ rnmax = ri->rnmax2;
+ }
+ max_ram_size = rnmax * storage_increment_size;
+
+ /* lowcore is always accessible, so the first increment is accessible */
+ ram_size = storage_increment_size;
+
+ /* probe for r/w memory up to max memory size */
+ while (ram_size < max_ram_size) {
+ expect_pgm_int();
+ cc = tprot(ram_size + storage_increment_size - 1);
+ /* stop once we receive an exception or have protected memory */
+ if (clear_pgm_int() || cc != 0)
+ break;
+ ram_size += storage_increment_size;
+ }
+}
diff --git a/lib/s390x/sclp.h b/lib/s390x/sclp.h
index d113cf8..21d482b 100644
--- a/lib/s390x/sclp.h
+++ b/lib/s390x/sclp.h
@@ -211,5 +211,6 @@ void sclp_ascii_setup(void);
void sclp_print(const char *str);
extern char _sccb[];
int sclp_service_call(unsigned int command, void *sccb);
+void sclp_memory_setup(void);
#endif /* SCLP_H */
diff --git a/s390x/Makefile b/s390x/Makefile
index f585faf..ce63dd1 100644
--- a/s390x/Makefile
+++ b/s390x/Makefile
@@ -24,6 +24,7 @@ cflatobjs += lib/util.o
cflatobjs += lib/alloc_phys.o
cflatobjs += lib/s390x/io.o
cflatobjs += lib/s390x/stack.o
+cflatobjs += lib/s390x/sclp.o
cflatobjs += lib/s390x/sclp-ascii.o
cflatobjs += lib/s390x/interrupt.o
--
2.14.3
next prev parent reply other threads:[~2018-02-13 16:23 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-13 16:23 [PATCH kvm-unit-tests v3 00/11] s390x: vmalloc support David Hildenbrand
2018-02-13 16:23 ` [PATCH kvm-unit-tests v3 01/11] s390x: fix TEST BLOCK tests David Hildenbrand
2018-02-13 16:23 ` [PATCH kvm-unit-tests v3 02/11] s390x: use highest addresses for PGM_ADDRESSING errors David Hildenbrand
2018-02-13 16:23 ` [PATCH kvm-unit-tests v3 03/11] s390x: set initital stack pointer to stackptr, not stacktop David Hildenbrand
2018-02-13 16:23 ` [PATCH kvm-unit-tests v3 04/11] s390x: add missing sclp definitions from QEMU David Hildenbrand
2018-02-13 16:23 ` [PATCH kvm-unit-tests v3 05/11] s390x: rename sclp_setup() to sclp_ascii_setup() David Hildenbrand
2018-02-13 16:23 ` David Hildenbrand [this message]
2018-02-13 16:23 ` [PATCH kvm-unit-tests v3 07/11] s390x: initialize the physical allocator David Hildenbrand
2018-02-14 12:05 ` Thomas Huth
2018-02-14 12:22 ` David Hildenbrand
2018-02-13 16:23 ` [PATCH kvm-unit-tests v3 08/11] s390x: add vmalloc support David Hildenbrand
2018-02-13 16:23 ` [PATCH kvm-unit-tests v3 09/11] s390x: enable DAT in PGM interrupt handler David Hildenbrand
2018-02-13 16:23 ` [PATCH kvm-unit-tests v3 10/11] s390x: add test for (v)malloc David Hildenbrand
2018-02-13 16:23 ` [PATCH kvm-unit-tests v3 11/11] s390x: add sieve test David Hildenbrand
2018-02-13 16:26 ` Christian Borntraeger
2018-02-13 16:44 ` Paolo Bonzini
2018-02-13 17:02 ` David Hildenbrand
2018-02-13 17:08 ` David Hildenbrand
2018-02-14 11:51 ` Paolo Bonzini
2018-02-14 12:56 ` David Hildenbrand
2018-02-14 13:15 ` David Hildenbrand
2018-02-13 17:09 ` David Hildenbrand
2018-02-14 11:52 ` [PATCH kvm-unit-tests v3 00/11] s390x: vmalloc support Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180213162321.20522-7-david@redhat.com \
--to=david@redhat.com \
--cc=borntraeger@de.ibm.com \
--cc=cohuck@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=rkrcmar@redhat.com \
--cc=thuth@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox