diff options
-rw-r--r-- | core/Makefile.inc | 2 | ||||
-rw-r--r-- | core/init.c | 6 | ||||
-rw-r--r-- | core/sensor.c | 41 | ||||
-rw-r--r-- | hw/fsp/fsp-sensor.c | 13 | ||||
-rw-r--r-- | include/fsp.h | 2 | ||||
-rw-r--r-- | include/platform.h | 6 | ||||
-rw-r--r-- | include/sensor.h | 55 | ||||
-rw-r--r-- | platforms/ibm-fsp/common.c | 5 | ||||
-rw-r--r-- | platforms/ibm-fsp/firenze.c | 1 | ||||
-rw-r--r-- | platforms/ibm-fsp/ibm-fsp.h | 3 |
10 files changed, 122 insertions, 12 deletions
diff --git a/core/Makefile.inc b/core/Makefile.inc index 590780f..5f5fe04 100644 --- a/core/Makefile.inc +++ b/core/Makefile.inc @@ -7,7 +7,7 @@ CORE_OBJS += timebase.o opal-msg.o pci.o pci-opal.o fast-reboot.o CORE_OBJS += device.o exceptions.o trace.o affinity.o vpd.o CORE_OBJS += hostservices.o platform.o nvram.o hmi.o CORE_OBJS += console-log.o ipmi.o time-utils.o pel.o pool.o errorlog.o -CORE_OBJS += timer.o i2c.o rtc.o flash.o +CORE_OBJS += timer.o i2c.o rtc.o flash.o sensor.o CORE=core/built-in.o CFLAGS_SKIP_core/relocate.o = -pg -fstack-protector-all diff --git a/core/init.c b/core/init.c index f15ae5d..8acc44c 100644 --- a/core/init.c +++ b/core/init.c @@ -44,8 +44,7 @@ #include <libfdt/libfdt.h> #include <timer.h> #include <ipmi.h> - -#include <ipmi.h> +#include <sensor.h> /* * Boot semaphore, incremented by each CPU calling in @@ -644,6 +643,9 @@ void __noreturn main_cpu_entry(const void *fdt, u32 master_cpu) /* Initialize i2c */ p8_i2c_init(); + /* Register routine to dispatch and read sensors */ + sensor_init(); + /* * We have initialized the basic HW, we can now call into the * platform to perform subsequent inits, such as establishing diff --git a/core/sensor.c b/core/sensor.c new file mode 100644 index 0000000..2c96756 --- /dev/null +++ b/core/sensor.c @@ -0,0 +1,41 @@ +/* Copyright 2013-2015 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include <sensor.h> +#include <skiboot.h> +#include <device.h> +#include <opal.h> +#include <opal-api.h> + +struct dt_node *sensor_node; + +static int64_t opal_sensor_read(uint32_t sensor_hndl, int token, + uint32_t *sensor_data) +{ + if (platform.sensor_read) + return platform.sensor_read(sensor_hndl, token, sensor_data); + + return OPAL_PARAMETER; +} + +void sensor_init(void) +{ + sensor_node = dt_new(opal_node, "sensors"); + + /* Register OPAL interface */ + opal_register(OPAL_SENSOR_READ, opal_sensor_read, 3); +} diff --git a/hw/fsp/fsp-sensor.c b/hw/fsp/fsp-sensor.c index 39e4e8e..1435e67 100644 --- a/hw/fsp/fsp-sensor.c +++ b/hw/fsp/fsp-sensor.c @@ -36,7 +36,8 @@ #include <spcn.h> #include <opal-api.h> #include <opal-msg.h> -#include<errorlog.h> +#include <errorlog.h> +#include <sensor.h> #define INVALID_DATA ((uint32_t)-1) @@ -490,7 +491,7 @@ static int64_t parse_sensor_id(uint32_t id, struct opal_sensor_data *attr) } -static int64_t fsp_opal_read_sensor(uint32_t sensor_hndl, int token, +int64_t fsp_opal_read_sensor(uint32_t sensor_hndl, int token, uint32_t *sensor_data) { struct opal_sensor_data *attr; @@ -691,14 +692,11 @@ static void add_sensor_ids(struct dt_node *sensors) static void add_opal_sensor_node(void) { int index; - struct dt_node *sensors; if (!fsp_present()) return; - sensors = dt_new(opal_node, "sensors"); - - add_sensor_ids(sensors); + add_sensor_ids(sensor_node); /* Reset the entry count of each modifier */ for (index = 0; spcn_mod_data[index].mod != SPCN_MOD_LAST; @@ -729,9 +727,6 @@ void fsp_init_sensor(void) /* Map TCE */ fsp_tce_map(PSI_DMA_SENSOR_BUF, sensor_buffer, PSI_DMA_SENSOR_BUF_SZ); - /* Register OPAL interface */ - opal_register(OPAL_SENSOR_READ, fsp_opal_read_sensor, 3); - msg.resp = &resp; /* Traverse using all the modifiers to know all the sensors available diff --git a/include/fsp.h b/include/fsp.h index b192490..54b7060 100644 --- a/include/fsp.h +++ b/include/fsp.h @@ -783,6 +783,8 @@ extern void fsp_memory_err_init(void); /* Sensor */ extern void fsp_init_sensor(void); +extern int64_t fsp_opal_read_sensor(uint32_t sensor_hndl, int token, + uint32_t *sensor_data); /* Diagnostic */ extern void fsp_init_diag(void); diff --git a/include/platform.h b/include/platform.h index 2900b4e..be5999b 100644 --- a/include/platform.h +++ b/include/platform.h @@ -152,6 +152,12 @@ struct platform { * Executed just prior to handing control over to the payload. */ void (*exit)(void); + + /* + * Read a sensor value + */ + int64_t (*sensor_read)(uint32_t sensor_hndl, int token, + uint32_t *sensor_data); }; extern struct platform __platforms_start; diff --git a/include/sensor.h b/include/sensor.h new file mode 100644 index 0000000..6004bcc --- /dev/null +++ b/include/sensor.h @@ -0,0 +1,55 @@ +/* Copyright 2013-2015 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __SENSOR_H +#define __SENSOR_H + +/* + * A sensor handler is a four bytes value which identifies a sensor by + * its resource class (temperature, fans ...), a resource identifier + * and an attribute number (data, status, ...) : + * + * Res. + * | Attr. | Class | Resource Id | + * |--------|--------|----------------| + * + * + * Helper routines to build or use the sensor handler. + */ +#define sensor_make_handler(sensor_class, sensor_rid, sensor_attr) \ + (((sensor_attr) << 24) | ((sensor_class) & 0xff) << 16 | \ + ((sensor_rid) & 0xffff)) + +#define sensor_get_frc(handler) (((handler) >> 16) & 0xff) +#define sensor_get_rid(handler) ((handler) & 0xffff) +#define sensor_get_attr(handler) ((handler) >> 24) + +/* + * Sensor families + * + * This identifier is used to dispatch calls to OPAL_SENSOR_READ to + * the appropriate component. FSP is the initial family. + */ +#define SENSOR_FSP 0x0 + +/* + * root node of all sensors : /ibm,opal/sensors + */ +extern struct dt_node *sensor_node; + +extern void sensor_init(void); + +#endif /* __SENSOR_H */ diff --git a/platforms/ibm-fsp/common.c b/platforms/ibm-fsp/common.c index da1da5a..d993b95 100644 --- a/platforms/ibm-fsp/common.c +++ b/platforms/ibm-fsp/common.c @@ -217,3 +217,8 @@ int64_t ibm_fsp_cec_power_down(uint64_t request) return OPAL_SUCCESS; } +int64_t ibm_fsp_sensor_read(uint32_t sensor_hndl, int token, + uint32_t *sensor_data) +{ + return fsp_opal_read_sensor(sensor_hndl, token, sensor_data); +} diff --git a/platforms/ibm-fsp/firenze.c b/platforms/ibm-fsp/firenze.c index fbdbcf3..d473875 100644 --- a/platforms/ibm-fsp/firenze.c +++ b/platforms/ibm-fsp/firenze.c @@ -416,4 +416,5 @@ DECLARE_PLATFORM(firenze) = { .elog_commit = elog_fsp_commit, .start_preload_resource = fsp_start_preload_resource, .resource_loaded = fsp_resource_loaded, + .sensor_read = ibm_fsp_sensor_read, } ; diff --git a/platforms/ibm-fsp/ibm-fsp.h b/platforms/ibm-fsp/ibm-fsp.h index c045aac..3b24b5b 100644 --- a/platforms/ibm-fsp/ibm-fsp.h +++ b/platforms/ibm-fsp/ibm-fsp.h @@ -27,4 +27,7 @@ extern int64_t ibm_fsp_cec_reboot(void); struct errorlog; extern int elog_fsp_commit(struct errorlog *buf); +extern int64_t ibm_fsp_sensor_read(uint32_t sensor_hndl, int token, + uint32_t *sensor_data); + #endif /* __IBM_FSP_COMMON_H */ |