From patchwork Mon May 8 21:20:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 9716711 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 185E460365 for ; Mon, 8 May 2017 21:20:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 00B1F265B9 for ; Mon, 8 May 2017 21:20:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E9C7D26B39; Mon, 8 May 2017 21:20:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 90A58265B9 for ; Mon, 8 May 2017 21:20:39 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D5ED26E2B5; Mon, 8 May 2017 21:20:36 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x243.google.com (mail-wm0-x243.google.com [IPv6:2a00:1450:400c:c09::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id E2BE86E2B1; Mon, 8 May 2017 21:20:33 +0000 (UTC) Received: by mail-wm0-x243.google.com with SMTP id d127so9856186wmf.1; Mon, 08 May 2017 14:20:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=oLVw3pXQK23SM6oH1OhjO/dHyHZyjRQ6UP9OhJx2AgU=; b=JSCYPOEeWIsXstr+hZ7kR3NZOw7//2PoTW2+l9h/4IuYjntJLAttxWdSCn982+jTCZ jBOzz+3UCFZLwG3WjOWDmL1XkN6OJIbxNjFCziMMYFXopuYB2uwvwd811AlXkLNuiI62 h7yMDYIuCTPYrvf9J79YG+fL4D42+6HsuOSJuWkEs1pEWb9p7SfB5aq6GTjQrQMbw2Iy 6XECzI7M40vOYqo32z9XR8+ZaBAkWebWDXDhgV0freP8pKoxuXB9p7/xIvN+aiJGBkGD Wtt9UA68oU9tGkSCZix0xK2jpifKu5FXaRXjQTZ1vQevTQ6q1wHVluXU5nglEeMzx2Hv fsfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=oLVw3pXQK23SM6oH1OhjO/dHyHZyjRQ6UP9OhJx2AgU=; b=iQ7yQo+vLvig8a3xDZAAJOJG3xh+TiKW74RUHSIHyZpJFHaByvHSn6/Vu91plNNC42 V4laS7z4ENwEOSB/kg1syCsIT3vl3tOWjFUJuuZv8gh9TqDLAa+DQTIiUfOECkogWTO+ ZoN5BuNAgdv89IphDBPvh6q2p8YcNqv9HlG4SAA78amzCmlXg40aA8gG23h1MnCIKPXh iSFUyV+r8aV6Y4gwAA02aPQuET6t+jIiY7eXJY37gJmdOmucJxZOnRf3pjJoUUPZ7sXJ pSgUNDgIcB+LfcbAJ7XiV/4x2mDtgZ0wagtcM4tSgLUz+d1h0yd7Pg4FfwM++HDnmUH1 JyZA== X-Gm-Message-State: AN3rC/5eikZ9nr9OZxs6JjWlcZa1Z3WeKyKbmvoR238zHvI4/E5DE1aL tp6nSOkJMLlz3+ji X-Received: by 10.28.12.211 with SMTP id 202mr13867294wmm.32.1494278432242; Mon, 08 May 2017 14:20:32 -0700 (PDT) Received: from localhost.localdomain (ip5f5adba3.dynamic.kabel-deutschland.de. [95.90.219.163]) by smtp.googlemail.com with ESMTPSA id v69sm4808199wmv.3.2017.05.08.14.20.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 08 May 2017 14:20:31 -0700 (PDT) From: Oscar Salvador To: nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [PATCH v6 2/5] nouveau/hwmon: Add nouveau_hwmon_ops structure with .is_visible/.read_string Date: Mon, 8 May 2017 23:20:47 +0200 Message-Id: <1494278450-11021-3-git-send-email-osalvador.vilardaga@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1494278450-11021-1-git-send-email-osalvador.vilardaga@gmail.com> References: <1494278450-11021-1-git-send-email-osalvador.vilardaga@gmail.com> Cc: Oscar Salvador X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP This patch introduces the nouveau_hwmon_ops structure, sets up .is_visible and .read_string operations and adds all the functions for these operations. This is also a preparation for the next patches, where most of the work is being done. This code doesn't interacture with the old one. It's just to make easier the review of all patches. Signed-off-by: Oscar Salvador Reviewed-by: Martin Peres --- drivers/gpu/drm/nouveau/nouveau_hwmon.c | 163 ++++++++++++++++++++++++++++++++ 1 file changed, 163 insertions(+) diff --git a/drivers/gpu/drm/nouveau/nouveau_hwmon.c b/drivers/gpu/drm/nouveau/nouveau_hwmon.c index 24b40c5..e9908fa 100644 --- a/drivers/gpu/drm/nouveau/nouveau_hwmon.c +++ b/drivers/gpu/drm/nouveau/nouveau_hwmon.c @@ -764,6 +764,169 @@ static const struct hwmon_channel_info *nouveau_info[] = { &nouveau_power, NULL }; + +static umode_t +nouveau_chip_is_visible(const void *data, u32 attr, int channel) +{ + switch (attr) { + case hwmon_chip_update_interval: + return 0444; + default: + return 0; + } +} + +static umode_t +nouveau_power_is_visible(const void *data, u32 attr, int channel) +{ + struct nouveau_drm *drm = nouveau_drm((struct drm_device *)data); + struct nvkm_iccsense *iccsense = nvxx_iccsense(&drm->client.device); + + if (!iccsense || !iccsense->data_valid || list_empty(&iccsense->rails)) + return 0; + + switch (attr) { + case hwmon_power_input: + return 0444; + case hwmon_power_max: + if (iccsense->power_w_max) + return 0444; + return 0; + case hwmon_power_crit: + if (iccsense->power_w_crit) + return 0444; + return 0; + default: + return 0; + } +} + +static umode_t +nouveau_temp_is_visible(const void *data, u32 attr, int channel) +{ + struct nouveau_drm *drm = nouveau_drm((struct drm_device *)data); + struct nvkm_therm *therm = nvxx_therm(&drm->client.device); + + if (therm && therm->attr_get && nvkm_therm_temp_get(therm) < 0) + return 0; + + switch (attr) { + case hwmon_temp_input: + case hwmon_temp_max: + case hwmon_temp_max_hyst: + case hwmon_temp_crit: + case hwmon_temp_crit_hyst: + case hwmon_temp_emergency: + case hwmon_temp_emergency_hyst: + return 0444; + default: + return 0; + } +} + +static umode_t +nouveau_pwm_is_visible(const void *data, u32 attr, int channel) +{ + struct nouveau_drm *drm = nouveau_drm((struct drm_device *)data); + struct nvkm_therm *therm = nvxx_therm(&drm->client.device); + + if (therm && therm->attr_get && therm->fan_get && + therm->fan_get(therm) < 0) + return 0; + + switch (attr) { + case hwmon_pwm_enable: + case hwmon_pwm_input: + return 0644; + default: + return 0; + } +} + +static umode_t +nouveau_input_is_visible(const void *data, u32 attr, int channel) +{ + struct nouveau_drm *drm = nouveau_drm((struct drm_device *)data); + struct nvkm_volt *volt = nvxx_volt(&drm->client.device); + + if (!volt || nvkm_volt_get(volt) < 0) + return 0; + + switch (attr) { + case hwmon_in_input: + case hwmon_in_label: + case hwmon_in_min: + case hwmon_in_max: + return 0444; + default: + return 0; + } +} + +static umode_t +nouveau_fan_is_visible(const void *data, u32 attr, int channel) +{ + struct nouveau_drm *drm = nouveau_drm((struct drm_device *)data); + struct nvkm_therm *therm = nvxx_therm(&drm->client.device); + + if (!therm || !therm->attr_get || nvkm_therm_fan_sense(therm) < 0) + return 0; + + switch (attr) { + case hwmon_fan_input: + return 0444; + default: + return 0; + } +} + +static umode_t +nouveau_is_visible(const void *data, enum hwmon_sensor_types type, u32 attr, + int channel) +{ + switch (type) { + case hwmon_chip: + return nouveau_chip_is_visible(data, attr, channel); + case hwmon_temp: + return nouveau_temp_is_visible(data, attr, channel); + case hwmon_fan: + return nouveau_fan_is_visible(data, attr, channel); + case hwmon_in: + return nouveau_input_is_visible(data, attr, channel); + case hwmon_pwm: + return nouveau_pwm_is_visible(data, attr, channel); + case hwmon_power: + return nouveau_power_is_visible(data, attr, channel); + default: + return 0; + } +} + +static const char input_label[] = "GPU core"; + +static int +nouveau_read_string(struct device *dev, enum hwmon_sensor_types type, u32 attr, + int channel, char **buf) +{ + if (type == hwmon_in && attr == hwmon_in_label) { + *buf = input_label; + return 0; + } + + return -EOPNOTSUPP; +} + +static const struct hwmon_ops nouveau_hwmon_ops = { + .is_visible = nouveau_is_visible, + .read = NULL, + .read_string = nouveau_read_string, + .write = NULL, +}; + +static const struct hwmon_chip_info nouveau_chip_info = { + .ops = &nouveau_hwmon_ops, + .info = nouveau_info, +}; #endif int