From 6d2254bc922b4858cd479d8c7133f64143b6cac5 Mon Sep 17 00:00:00 2001 From: Alfredo Dal'Ava Junior Date: Wed, 30 Dec 2020 22:00:28 -0300 Subject: [PATCH] [POWERPC64LE] fix sysctl dev.opal_sensor.* on little-endian kernel - fix values returned by 'sysctls dev.opal_sensor.*.sensor' - fix missing 'dev.opal_sensor.*.sensor_[max|min]' on sysctl Reviewed-by: jhibbits Sponsored-by: Eldorado Research Institute (eldorado.org.br) Differential-Revision: https://reviews.freebsd.org/D27365 --- sys/powerpc/powernv/opal.h | 22 ++++++++++++++++++++++ sys/powerpc/powernv/opal_dev.c | 20 +++++++++++++++++--- sys/powerpc/powernv/opal_sensor.c | 7 ++++--- 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/sys/powerpc/powernv/opal.h b/sys/powerpc/powernv/opal.h index 7671ece28122..d7a81e33f809 100644 --- a/sys/powerpc/powernv/opal.h +++ b/sys/powerpc/powernv/opal.h @@ -138,15 +138,37 @@ int opal_call(uint64_t token, ...); #define OPAL_SUCCESS 0 #define OPAL_PARAMETER -1 #define OPAL_BUSY -2 +#define OPAL_PARTIAL -3 +#define OPAL_CONSTRAINED -4 #define OPAL_CLOSED -5 #define OPAL_HARDWARE -6 #define OPAL_UNSUPPORTED -7 +#define OPAL_PERMISSION -8 +#define OPAL_NO_MEM -9 #define OPAL_RESOURCE -10 +#define OPAL_INTERNAL_ERROR -11 #define OPAL_BUSY_EVENT -12 +#define OPAL_HARDWARE_FROZEN -13 +#define OPAL_WRONG_STATE -14 #define OPAL_ASYNC_COMPLETION -15 #define OPAL_EMPTY -16 +#define OPAL_I2C_TIMEOUT -17 +#define OPAL_I2C_INVALID_CMD -18 +#define OPAL_I2C_LBUS_PARITY -19 +#define OPAL_I2C_BKEND_OVERRUN -20 +#define OPAL_I2C_BKEND_ACCESS -21 +#define OPAL_I2C_ARBT_LOST -22 +#define OPAL_I2C_NACK_RCVD -23 +#define OPAL_I2C_STOP_ERR -24 +#define OPAL_XSCOM_PARTIAL_GOOD -25 +#define OPAL_XSCOM_ADDR_ERROR -26 +#define OPAL_XSCOM_CLOCK_ERROR -27 +#define OPAL_XSCOM_PARITY_ERROR -28 +#define OPAL_XSCOM_TIMEOUT -29 +#define OPAL_XSCOM_CTR_OFFLINED -30 #define OPAL_XIVE_PROVISIONING -31 #define OPAL_XIVE_FREE_ACTIVE -32 +#define OPAL_TIMEOUT -33 #define OPAL_TOKEN_ABSENT 0 #define OPAL_TOKEN_PRESENT 1 diff --git a/sys/powerpc/powernv/opal_dev.c b/sys/powerpc/powernv/opal_dev.c index ccd49bac7a68..e23844fde04d 100644 --- a/sys/powerpc/powernv/opal_dev.c +++ b/sys/powerpc/powernv/opal_dev.c @@ -382,8 +382,22 @@ opal_handle_messages(void) rv = opal_call(OPAL_GET_MSG, vtophys(&msg), sizeof(msg)); - if (rv != OPAL_SUCCESS) + switch (rv) { + case OPAL_SUCCESS: + break; + case OPAL_RESOURCE: + /* no available messages - return */ return; + case OPAL_PARAMETER: + printf("%s error: invalid buffer. Please file a bug report.\n", __func__); + return; + case OPAL_PARTIAL: + printf("%s error: buffer is too small and messages was discarded. Please file a bug report.\n", __func__); + return; + default: + printf("%s opal_call returned unknown result <%lu>\n", __func__, rv); + return; + } type = be32toh(msg.msg_type); switch (type) { @@ -406,7 +420,7 @@ opal_handle_messages(void) EVENTHANDLER_DIRECT_INVOKE(OPAL_OCC, &msg); break; default: - printf("Unknown OPAL message type %d\n", type); + printf("%s Unknown OPAL message type %d\n", __func__, type); } } @@ -418,7 +432,7 @@ opal_intr(void *xintr) opal_call(OPAL_HANDLE_INTERRUPT, (uint32_t)(uint64_t)xintr, vtophys(&events)); /* Wake up the heartbeat, if it's been setup. */ - if (events != 0 && opal_hb_proc != NULL) + if (be64toh(events) != 0 && opal_hb_proc != NULL) wakeup(opal_hb_proc); } diff --git a/sys/powerpc/powernv/opal_sensor.c b/sys/powerpc/powernv/opal_sensor.c index dae1f97bc989..a95746472975 100644 --- a/sys/powerpc/powernv/opal_sensor.c +++ b/sys/powerpc/powernv/opal_sensor.c @@ -33,6 +33,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -114,7 +115,7 @@ opal_sensor_get_val(struct opal_sensor_softc *sc, uint32_t key, uint64_t *val) SENSOR_UNLOCK(sc); if (rv == OPAL_SUCCESS) - *val = val32; + *val = be32toh(val32); else rv = EIO; @@ -218,7 +219,7 @@ opal_sensor_attach(device_t dev) SYSCTL_ADD_STRING(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, "label", CTLFLAG_RD, sc->sc_label, 0, ""); - if (OF_getprop(node, "sensor-data-min", + if (OF_getencprop(node, "sensor-data-min", &sensor_id, sizeof(sensor_id)) > 0) { sc->sc_min_handle = sensor_id; SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, @@ -228,7 +229,7 @@ opal_sensor_attach(device_t dev) "minimum value"); } - if (OF_getprop(node, "sensor-data-max", + if (OF_getencprop(node, "sensor-data-max", &sensor_id, sizeof(sensor_id)) > 0) { sc->sc_max_handle = sensor_id; SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,