From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Hildenbrand Subject: [kvm-unit-tests PATCH v1 4/5] s390x: query and store STFL(E) facilitites Date: Tue, 19 Sep 2017 16:50:32 +0200 Message-ID: <20170919145033.16959-5-david@redhat.com> References: <20170919145033.16959-1-david@redhat.com> Cc: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , david@redhat.com, Thomas Huth , Cornelia Huck , Christian Borntraeger To: kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:40676 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751589AbdISOuw (ORCPT ); Tue, 19 Sep 2017 10:50:52 -0400 In-Reply-To: <20170919145033.16959-1-david@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: 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 --- 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 + * + * 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 +#include +#include + +#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 #include #include +#include #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