diff options
-rw-r--r-- | core/direct-controls.c | 4 | ||||
-rw-r--r-- | core/sensor.c | 2 | ||||
-rw-r--r-- | hw/dts.c | 74 | ||||
-rw-r--r-- | include/cpu.h | 14 | ||||
-rw-r--r-- | include/dts.h | 2 |
5 files changed, 79 insertions, 17 deletions
diff --git a/core/direct-controls.c b/core/direct-controls.c index 512cb36..fcb9350 100644 --- a/core/direct-controls.c +++ b/core/direct-controls.c @@ -220,7 +220,7 @@ static int p9_sreset_thread(struct cpu_thread *cpu) return 0; } -static int dctl_set_special_wakeup(struct cpu_thread *t) +int dctl_set_special_wakeup(struct cpu_thread *t) { struct cpu_thread *c = t->primary; int rc = OPAL_SUCCESS; @@ -238,7 +238,7 @@ static int dctl_set_special_wakeup(struct cpu_thread *t) return rc; } -static int dctl_clear_special_wakeup(struct cpu_thread *t) +int dctl_clear_special_wakeup(struct cpu_thread *t) { struct cpu_thread *c = t->primary; int rc = OPAL_SUCCESS; diff --git a/core/sensor.c b/core/sensor.c index 57b21bc..0e2a5ca 100644 --- a/core/sensor.c +++ b/core/sensor.c @@ -28,7 +28,7 @@ static int64_t opal_sensor_read(uint32_t sensor_hndl, int token, { switch (sensor_get_family(sensor_hndl)) { case SENSOR_DTS: - return dts_sensor_read(sensor_hndl, sensor_data); + return dts_sensor_read(sensor_hndl, token, sensor_data); case SENSOR_OCC: return occ_sensor_read(sensor_hndl, sensor_data); default: @@ -20,6 +20,9 @@ #include <dts.h> #include <skiboot.h> #include <opal-api.h> +#include <opal-msg.h> +#include <timer.h> +#include <timebase.h> struct dts { uint8_t valid; @@ -27,6 +30,14 @@ struct dts { int16_t temp; }; +/* + * Attributes for the core temperature sensor + */ +enum { + SENSOR_DTS_ATTR_TEMP_MAX, + SENSOR_DTS_ATTR_TEMP_TRIP +}; + /* Different sensor locations */ #define P7_CT_ZONE_LSU 0 #define P7_CT_ZONE_ISU 1 @@ -225,8 +236,37 @@ static int dts_read_core_temp_p9(uint32_t pir, struct dts *dts) return 0; } -static int dts_read_core_temp(uint32_t pir, struct dts *dts) +static void dts_async_read_temp(struct timer *t __unused, void *data, + u64 now __unused) +{ + struct dts dts; + int rc, swkup_rc; + struct cpu_thread *cpu = data; + + swkup_rc = dctl_set_special_wakeup(cpu); + + rc = dts_read_core_temp_p9(cpu->pir, &dts); + if (!rc) { + if (cpu->sensor_attr == SENSOR_DTS_ATTR_TEMP_MAX) + *(u32 *)cpu->sensor_data = dts.temp; + else if (cpu->sensor_attr == SENSOR_DTS_ATTR_TEMP_TRIP) + *(u32 *)cpu->sensor_data = dts.trip; + } + + if (!swkup_rc) + dctl_clear_special_wakeup(cpu); + + rc = opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL, cpu->token, rc); + if (rc) + prerror("Failed to queue async message\n"); + + cpu->dts_read_in_progress = false; +} + +static int dts_read_core_temp(u32 pir, struct dts *dts, u8 attr, + int token, u32 *sensor_data) { + struct cpu_thread *cpu; int rc; switch (proc_gen) { @@ -236,8 +276,22 @@ static int dts_read_core_temp(uint32_t pir, struct dts *dts) case proc_gen_p8: rc = dts_read_core_temp_p8(pir, dts); break; - case proc_gen_p9: - rc = dts_read_core_temp_p9(pir, dts); + case proc_gen_p9: /* Asynchronus read */ + cpu = find_cpu_by_pir(pir); + if (!cpu) + return OPAL_PARAMETER; + lock(&cpu->dts_lock); + if (cpu->dts_read_in_progress) { + unlock(&cpu->dts_lock); + return OPAL_BUSY; + } + cpu->dts_read_in_progress = true; + cpu->sensor_attr = attr; + cpu->sensor_data = sensor_data; + cpu->token = token; + schedule_timer(&cpu->dts_timer, 0); + rc = OPAL_ASYNC_COMPLETION; + unlock(&cpu->dts_lock); break; default: rc = OPAL_UNSUPPORTED; @@ -303,20 +357,12 @@ enum sensor_dts_class { }; /* - * Attributes for the core temperature sensor - */ -enum { - SENSOR_DTS_ATTR_TEMP_MAX, - SENSOR_DTS_ATTR_TEMP_TRIP -}; - -/* * Extract the centaur chip id which was truncated to fit in the * resource identifier field of the sensor handler */ #define centaur_get_id(rid) (0x80000000 | ((rid) & 0x3ff)) -int64_t dts_sensor_read(uint32_t sensor_hndl, uint32_t *sensor_data) +int64_t dts_sensor_read(u32 sensor_hndl, int token, u32 *sensor_data) { uint8_t attr = sensor_get_attr(sensor_hndl); uint32_t rid = sensor_get_rid(sensor_hndl); @@ -330,7 +376,7 @@ int64_t dts_sensor_read(uint32_t sensor_hndl, uint32_t *sensor_data) switch (sensor_get_frc(sensor_hndl)) { case SENSOR_DTS_CORE_TEMP: - rc = dts_read_core_temp(rid, &dts); + rc = dts_read_core_temp(rid, &dts, attr, token, sensor_data); break; case SENSOR_DTS_MEM_TEMP: rc = dts_read_mem_temp(centaur_get_id(rid), &dts); @@ -403,6 +449,8 @@ bool dts_sensor_create_nodes(struct dt_node *sensors) dt_add_property_string(node, "sensor-type", "temp"); dt_add_property_cells(node, "ibm,pir", c->pir); dt_add_property_string(node, "label", "Core"); + init_timer(&c->dts_timer, dts_async_read_temp, c); + c->dts_read_in_progress = false; } } diff --git a/include/cpu.h b/include/cpu.h index 168fa99..d4b7a42 100644 --- a/include/cpu.h +++ b/include/cpu.h @@ -23,6 +23,7 @@ #include <device.h> #include <opal.h> #include <stack.h> +#include <timer.h> /* * cpu_thread is our internal structure representing each @@ -102,6 +103,16 @@ struct cpu_thread { struct lock dctl_lock; /* primary only */ bool dctl_stopped; /* per thread */ uint32_t special_wakeup_count; /* primary */ + + /* + * For reading DTS sensors async + */ + struct lock dts_lock; + struct timer dts_timer; + void *sensor_data; + u32 sensor_attr; + u32 token; + bool dts_read_in_progress; }; /* This global is set to 1 to allow secondaries to callin, @@ -284,4 +295,7 @@ extern void cpu_idle_delay(unsigned long delay); extern void cpu_set_radix_mode(void); extern void cpu_fast_reboot_complete(void); +int dctl_set_special_wakeup(struct cpu_thread *t); +int dctl_clear_special_wakeup(struct cpu_thread *t); + #endif /* __CPU_H */ diff --git a/include/dts.h b/include/dts.h index b37919f..17e2e15 100644 --- a/include/dts.h +++ b/include/dts.h @@ -19,7 +19,7 @@ #include <stdint.h> -extern int64_t dts_sensor_read(uint32_t sensor_hndl, uint32_t *sensor_data); +extern int64_t dts_sensor_read(u32 sensor_hndl, int token, u32 *sensor_data); extern bool dts_sensor_create_nodes(struct dt_node *sensors); #endif /* __DTS_H */ |