public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: kvm@vger.kernel.org
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
	"Radim Krčmář" <rkrcmar@redhat.com>,
	david@redhat.com, "Thomas Huth" <thuth@redhat.com>,
	"Cornelia Huck" <cohuck@redhat.com>,
	"Christian Borntraeger" <borntraeger@de.ibm.com>
Subject: [kvm-unit-tests PATCH v1 4/5] s390x: query and store STFL(E) facilitites
Date: Tue, 19 Sep 2017 16:50:32 +0200	[thread overview]
Message-ID: <20170919145033.16959-5-david@redhat.com> (raw)
In-Reply-To: <20170919145033.16959-1-david@redhat.com>

cpacf.h will require the test_facility() function, so let's properly
query and store the STFL(E) facilities.

STFLE requires double word alignment.

Signed-off-by: David Hildenbrand <david@redhat.com>
---
 lib/s390x/asm/facility.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 lib/s390x/io.c           |  3 +++
 2 files changed, 51 insertions(+)
 create mode 100644 lib/s390x/asm/facility.h

diff --git a/lib/s390x/asm/facility.h b/lib/s390x/asm/facility.h
new file mode 100644
index 0000000..5103dd4
--- /dev/null
+++ b/lib/s390x/asm/facility.h
@@ -0,0 +1,48 @@
+/*
+ * 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.
+ */
+#ifndef _ASM_S390X_FACILITY_H_
+#define _ASM_S390X_FACILITY_H_
+
+#include <libcflat.h>
+#include <asm/facility.h>
+#include <asm/arch_def.h>
+
+#define NR_STFL_BYTES 256
+extern uint8_t stfl_bytes[];
+
+static inline bool test_facility(int nr)
+{
+	return stfl_bytes[nr / 8] & (0x80U >> (nr % 8));
+}
+
+static inline void stfl(void)
+{
+	asm volatile("	stfl	0(0)\n");
+}
+
+static inline void stfle(uint8_t *fac, unsigned int len)
+{
+	register unsigned long r0 asm("0") = len - 1;
+
+	asm volatile("	.insn	s,0xb2b00000,0(%1)\n"
+		     : "+d" (r0) : "a" (fac) : "memory", "cc");
+}
+
+static inline void setup_facilities(void)
+{
+	struct lowcore *lc = NULL;
+
+	stfl();
+	memcpy(stfl_bytes, &lc->stfl, sizeof(lc->stfl));
+	if (test_facility(7))
+		stfle(stfl_bytes, NR_STFL_BYTES);
+}
+
+#endif
diff --git a/lib/s390x/io.c b/lib/s390x/io.c
index 4ab5bd9..12f9d26 100644
--- a/lib/s390x/io.c
+++ b/lib/s390x/io.c
@@ -13,9 +13,11 @@
 #include <libcflat.h>
 #include <argv.h>
 #include <asm/spinlock.h>
+#include <asm/facility.h>
 #include "sclp.h"
 
 extern char ipl_args[];
+uint8_t stfl_bytes[NR_STFL_BYTES] __attribute__((aligned(8)));
 
 static struct spinlock lock;
 
@@ -39,6 +41,7 @@ static void sigp_stop()
 void setup()
 {
 	setup_args_progname(ipl_args);
+	setup_facilities();
 	sclp_setup();
 }
 
-- 
2.13.5

  parent reply	other threads:[~2017-09-19 14:50 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-19 14:50 [kvm-unit-tests PATCH v1 0/5] s390x: IPM/SPM and MSA tests David Hildenbrand
2017-09-19 14:50 ` [kvm-unit-tests PATCH v1 1/5] s390x: add a test case for the ipm + spm instructions David Hildenbrand
2017-09-19 14:50 ` [kvm-unit-tests PATCH v1 2/5] s390x: add cpacf.h from Linux David Hildenbrand
2017-09-19 14:50 ` [kvm-unit-tests PATCH v1 3/5] s390x: make sure cpacf.h can be used David Hildenbrand
2017-09-19 14:50 ` David Hildenbrand [this message]
2017-09-19 14:50 ` [kvm-unit-tests PATCH v1 5/5] s390x: test for various MSA instructions David Hildenbrand
2017-09-20  7:25 ` [kvm-unit-tests PATCH v1 0/5] s390x: IPM/SPM and MSA tests 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=20170919145033.16959-5-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