1 /* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ 2 #ifndef __HWMON_PMU_H 3 #define __HWMON_PMU_H 4 5 #include "pmu.h" 6 #include <stdbool.h> 7 8 struct list_head; 9 struct perf_thread_map; 10 11 /** 12 * enum hwmon_type: 13 * 14 * As described in Documentation/hwmon/sysfs-interface.rst hwmon events are 15 * defined over multiple files of the form <type><num>_<item>. This enum 16 * captures potential <type> values. 17 * 18 * This enum is exposed for testing. 19 */ 20 enum hwmon_type { 21 HWMON_TYPE_NONE, 22 23 HWMON_TYPE_CPU, 24 HWMON_TYPE_CURR, 25 HWMON_TYPE_ENERGY, 26 HWMON_TYPE_FAN, 27 HWMON_TYPE_HUMIDITY, 28 HWMON_TYPE_IN, 29 HWMON_TYPE_INTRUSION, 30 HWMON_TYPE_POWER, 31 HWMON_TYPE_PWM, 32 HWMON_TYPE_TEMP, 33 34 HWMON_TYPE_MAX 35 }; 36 37 /** 38 * enum hwmon_item: 39 * 40 * Similar to enum hwmon_type but describes the item part of a a sysfs filename. 41 * 42 * This enum is exposed for testing. 43 */ 44 enum hwmon_item { 45 HWMON_ITEM_NONE, 46 47 HWMON_ITEM_ACCURACY, 48 HWMON_ITEM_ALARM, 49 HWMON_ITEM_AUTO_CHANNELS_TEMP, 50 HWMON_ITEM_AVERAGE, 51 HWMON_ITEM_AVERAGE_HIGHEST, 52 HWMON_ITEM_AVERAGE_INTERVAL, 53 HWMON_ITEM_AVERAGE_INTERVAL_MAX, 54 HWMON_ITEM_AVERAGE_INTERVAL_MIN, 55 HWMON_ITEM_AVERAGE_LOWEST, 56 HWMON_ITEM_AVERAGE_MAX, 57 HWMON_ITEM_AVERAGE_MIN, 58 HWMON_ITEM_BEEP, 59 HWMON_ITEM_CAP, 60 HWMON_ITEM_CAP_HYST, 61 HWMON_ITEM_CAP_MAX, 62 HWMON_ITEM_CAP_MIN, 63 HWMON_ITEM_CRIT, 64 HWMON_ITEM_CRIT_HYST, 65 HWMON_ITEM_DIV, 66 HWMON_ITEM_EMERGENCY, 67 HWMON_ITEM_EMERGENCY_HIST, 68 HWMON_ITEM_ENABLE, 69 HWMON_ITEM_FAULT, 70 HWMON_ITEM_FREQ, 71 HWMON_ITEM_HIGHEST, 72 HWMON_ITEM_INPUT, 73 HWMON_ITEM_LABEL, 74 HWMON_ITEM_LCRIT, 75 HWMON_ITEM_LCRIT_HYST, 76 HWMON_ITEM_LOWEST, 77 HWMON_ITEM_MAX, 78 HWMON_ITEM_MAX_HYST, 79 HWMON_ITEM_MIN, 80 HWMON_ITEM_MIN_HYST, 81 HWMON_ITEM_MOD, 82 HWMON_ITEM_OFFSET, 83 HWMON_ITEM_PULSES, 84 HWMON_ITEM_RATED_MAX, 85 HWMON_ITEM_RATED_MIN, 86 HWMON_ITEM_RESET_HISTORY, 87 HWMON_ITEM_TARGET, 88 HWMON_ITEM_TYPE, 89 HWMON_ITEM_VID, 90 91 HWMON_ITEM__MAX, 92 }; 93 94 bool perf_pmu__is_hwmon(const struct perf_pmu *pmu); 95 bool evsel__is_hwmon(const struct evsel *evsel); 96 97 /** 98 * parse_hwmon_filename() - Parse filename into constituent parts. 99 * 100 * @filename: To be parsed, of the form <type><number>_<item>. 101 * @type: The type defined from the parsed file name. 102 * @number: The number of the type, for example there may be more than 1 fan. 103 * @item: A hwmon <type><number> may have multiple associated items. 104 * @alarm: Is the filename for an alarm value? 105 * 106 * An example of a hwmon filename is "temp1_input". The type is temp for a 107 * temperature value. The number is 1. The item within the file is an input 108 * value - the temperature itself. This file doesn't contain an alarm value. 109 * 110 * Exposed for testing. 111 */ 112 bool parse_hwmon_filename(const char *filename, 113 enum hwmon_type *type, 114 int *number, 115 enum hwmon_item *item, 116 bool *alarm); 117 118 /** 119 * hwmon_pmu__new() - Allocate and construct a hwmon PMU. 120 * 121 * @pmus: The list of PMUs to be added to. 122 * @hwmon_dir: An O_DIRECTORY file descriptor for a hwmon directory. 123 * @sysfs_name: Name of the hwmon sysfs directory like hwmon0. 124 * @name: The contents of the "name" file in the hwmon directory. 125 * 126 * Exposed for testing. Regular construction should happen via 127 * perf_pmus__read_hwmon_pmus. 128 */ 129 struct perf_pmu *hwmon_pmu__new(struct list_head *pmus, int hwmon_dir, 130 const char *sysfs_name, const char *name); 131 void hwmon_pmu__exit(struct perf_pmu *pmu); 132 133 int hwmon_pmu__for_each_event(struct perf_pmu *pmu, void *state, pmu_event_callback cb); 134 size_t hwmon_pmu__num_events(struct perf_pmu *pmu); 135 bool hwmon_pmu__have_event(struct perf_pmu *pmu, const char *name); 136 int hwmon_pmu__config_terms(const struct perf_pmu *pmu, 137 struct perf_event_attr *attr, 138 struct parse_events_terms *terms, 139 struct parse_events_error *err); 140 int hwmon_pmu__check_alias(struct parse_events_terms *terms, struct perf_pmu_info *info, 141 struct parse_events_error *err); 142 143 int perf_pmus__read_hwmon_pmus(struct list_head *pmus); 144 145 146 int evsel__hwmon_pmu_open(struct evsel *evsel, 147 struct perf_thread_map *threads, 148 int start_cpu_map_idx, int end_cpu_map_idx); 149 int evsel__hwmon_pmu_read(struct evsel *evsel, int cpu_map_idx, int thread); 150 151 #endif /* __HWMON_PMU_H */ 152