From 1045e13a248d94941f864998aa859970ae3a4154 Mon Sep 17 00:00:00 2001 From: Robert Mustacchi Date: Fri, 24 Jul 2020 11:42:23 -0700 Subject: 13079 Add ksensor support for voltage and current sensors Reviewed by: Andy Fiddaman Reviewed by: Paul Winder Approved by: Dan McDonald --- usr/src/uts/common/os/ksensor.c | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) (limited to 'usr/src/uts/common/os/ksensor.c') diff --git a/usr/src/uts/common/os/ksensor.c b/usr/src/uts/common/os/ksensor.c index c89cad4206..491fbcc7cd 100644 --- a/usr/src/uts/common/os/ksensor.c +++ b/usr/src/uts/common/os/ksensor.c @@ -544,14 +544,29 @@ ksensor_create(dev_info_t *dip, const ksensor_ops_t *ops, void *arg, } int -ksensor_create_temp_pcidev(dev_info_t *dip, const ksensor_ops_t *ops, - void *arg, const char *name, id_t *idp) +ksensor_create_scalar_pcidev(dev_info_t *dip, uint_t kind, + const ksensor_ops_t *ops, void *arg, const char *name, id_t *idp) { char *pci_name, *type; + const char *class; int *regs, ret; uint_t nregs; uint16_t bus, dev; + switch (kind) { + case SENSOR_KIND_TEMPERATURE: + class = "ddi_sensor:temperature:pci"; + break; + case SENSOR_KIND_VOLTAGE: + class = "ddi_sensor:voltage:pci"; + break; + case SENSOR_KIND_CURRENT: + class = "ddi_sensor:current:pci"; + break; + default: + return (ENOTSUP); + } + if (ddi_prop_lookup_string(DDI_DEV_T_ANY, dip, 0, "device_type", &type) != DDI_PROP_SUCCESS) { return (EINVAL); @@ -579,8 +594,7 @@ ksensor_create_temp_pcidev(dev_info_t *dip, const ksensor_ops_t *ops, pci_name = kmem_asprintf("%x.%x:%s", bus, dev, name); - ret = ksensor_create(dip, ops, arg, pci_name, - "ddi_sensor:temperature:pci", idp); + ret = ksensor_create(dip, ops, arg, pci_name, class, idp); strfree(pci_name); return (ret); } @@ -750,7 +764,7 @@ ksensor_op_kind(id_t id, sensor_ioctl_kind_t *kind) } int -ksensor_op_temperature(id_t id, sensor_ioctl_temperature_t *temp) +ksensor_op_scalar(id_t id, sensor_ioctl_scalar_t *scalar) { int ret; ksensor_t *sensor; @@ -759,7 +773,7 @@ ksensor_op_temperature(id_t id, sensor_ioctl_temperature_t *temp) return (ret); } - ret = sensor->ksensor_ops->kso_temp(sensor->ksensor_arg, temp); + ret = sensor->ksensor_ops->kso_scalar(sensor->ksensor_arg, scalar); ksensor_release(sensor); return (ret); @@ -831,6 +845,20 @@ ksensor_kind_temperature(void *unused, sensor_ioctl_kind_t *k) return (0); } +int +ksensor_kind_current(void *unused, sensor_ioctl_kind_t *k) +{ + k->sik_kind = SENSOR_KIND_CURRENT; + return (0); +} + +int +ksensor_kind_voltage(void *unused, sensor_ioctl_kind_t *k) +{ + k->sik_kind = SENSOR_KIND_VOLTAGE; + return (0); +} + void ksensor_init(void) { -- cgit v1.2.3