new file mode 100644
@@ -0,0 +1,50 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright IBM Corp. 2017, 2022
+ * Author(s): Claudio Imbrenda <imbrenda@linux.vnet.ibm.com>
+ * Nico Boehr <nrb@linux.ibm.com>
+ */
+#include <asm/interrupt.h>
+
+#ifndef PAGE_STATES_H
+#define PAGE_STATES_H
+
+#define ESSA_GET_STATE 0
+#define ESSA_SET_STABLE 1
+#define ESSA_SET_UNUSED 2
+#define ESSA_SET_VOLATILE 3
+#define ESSA_SET_POT_VOLATILE 4
+#define ESSA_SET_STABLE_RESIDENT 5
+#define ESSA_SET_STABLE_IF_RESIDENT 6
+#define ESSA_SET_STABLE_NODAT 7
+
+#define ESSA_MAX ESSA_SET_STABLE_NODAT
+
+#define ESSA_USAGE_STABLE 0
+#define ESSA_USAGE_UNUSED 1
+#define ESSA_USAGE_POT_VOLATILE 2
+#define ESSA_USAGE_VOLATILE 3
+
+static unsigned long essa(uint8_t state, unsigned long paddr)
+{
+ uint64_t extr_state;
+
+ asm volatile(".insn rrf,0xb9ab0000,%[extr_state],%[addr],%[new_state],0" \
+ : [extr_state] "=d" (extr_state) \
+ : [addr] "a" (paddr), [new_state] "i" (state));
+
+ return (unsigned long)extr_state;
+}
+
+/*
+ * Unfortunately the availability is not indicated by stfl bits, but
+ * we have to try to execute it and test for an operation exception.
+ */
+static inline bool check_essa_available(void)
+{
+ expect_pgm_int();
+ essa(ESSA_GET_STATE, 0);
+ return clear_pgm_int() == 0;
+}
+
+#endif
@@ -12,19 +12,10 @@
#include <asm/asm-offsets.h>
#include <asm/interrupt.h>
#include <asm/page.h>
+#include <asm/cmm.h>
static uint8_t pagebuf[PAGE_SIZE] __attribute__((aligned(PAGE_SIZE)));
-static unsigned long essa(uint8_t state, unsigned long paddr)
-{
- uint64_t extr_state;
-
- asm volatile(".insn rrf,0xb9ab0000,%[extr_state],%[addr],%[new_state],0"
- : [extr_state] "=d" (extr_state)
- : [addr] "a" (paddr), [new_state] "i" (state));
- return (unsigned long)extr_state;
-}
-
static void test_params(void)
{
report_prefix_push("invalid ORC 8");
@@ -39,24 +30,14 @@ static void test_priv(void)
report_prefix_push("privileged");
expect_pgm_int();
enter_pstate();
- essa(0, (unsigned long)pagebuf);
+ essa(ESSA_GET_STATE, (unsigned long)pagebuf);
check_pgm_int_code(PGM_INT_CODE_PRIVILEGED_OPERATION);
report_prefix_pop();
}
-/* Unfortunately the availability is not indicated by stfl bits, but
- * we have to try to execute it and test for an operation exception.
- */
-static bool test_availability(void)
-{
- expect_pgm_int();
- essa(0, (unsigned long)pagebuf);
- return clear_pgm_int() == 0;
-}
-
int main(void)
{
- bool has_essa = test_availability();
+ bool has_essa = check_essa_available();
report_prefix_push("cmm");
if (!has_essa) {