18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#ifndef LINUX_POWERPC_PERF_HV_COMMON_H_ 38c2ecf20Sopenharmony_ci#define LINUX_POWERPC_PERF_HV_COMMON_H_ 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci#include <linux/perf_event.h> 68c2ecf20Sopenharmony_ci#include <linux/types.h> 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_cistruct hv_perf_caps { 98c2ecf20Sopenharmony_ci u16 version; 108c2ecf20Sopenharmony_ci u16 collect_privileged:1, 118c2ecf20Sopenharmony_ci ga:1, 128c2ecf20Sopenharmony_ci expanded:1, 138c2ecf20Sopenharmony_ci lab:1, 148c2ecf20Sopenharmony_ci unused:12; 158c2ecf20Sopenharmony_ci}; 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ciunsigned long hv_perf_caps_get(struct hv_perf_caps *caps); 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci#define EVENT_DEFINE_RANGE_FORMAT(name, attr_var, bit_start, bit_end) \ 218c2ecf20Sopenharmony_ciPMU_FORMAT_ATTR(name, #attr_var ":" #bit_start "-" #bit_end); \ 228c2ecf20Sopenharmony_ciEVENT_DEFINE_RANGE(name, attr_var, bit_start, bit_end) 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci/* 258c2ecf20Sopenharmony_ci * The EVENT_DEFINE_RANGE_FORMAT() macro above includes helper functions 268c2ecf20Sopenharmony_ci * for the fields (eg: event_get_starting_index()). For some fields we 278c2ecf20Sopenharmony_ci * need the bit-range definition, but no the helper functions. Define a 288c2ecf20Sopenharmony_ci * lite version of the above macro without the helpers and silence 298c2ecf20Sopenharmony_ci * compiler warnings unused static functions. 308c2ecf20Sopenharmony_ci */ 318c2ecf20Sopenharmony_ci#define EVENT_DEFINE_RANGE_FORMAT_LITE(name, attr_var, bit_start, bit_end) \ 328c2ecf20Sopenharmony_ciPMU_FORMAT_ATTR(name, #attr_var ":" #bit_start "-" #bit_end); 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci#define EVENT_DEFINE_RANGE(name, attr_var, bit_start, bit_end) \ 358c2ecf20Sopenharmony_cistatic u64 event_get_##name##_max(void) \ 368c2ecf20Sopenharmony_ci{ \ 378c2ecf20Sopenharmony_ci BUILD_BUG_ON((bit_start > bit_end) \ 388c2ecf20Sopenharmony_ci || (bit_end >= (sizeof(1ull) * 8))); \ 398c2ecf20Sopenharmony_ci return (((1ull << (bit_end - bit_start)) - 1) << 1) + 1; \ 408c2ecf20Sopenharmony_ci} \ 418c2ecf20Sopenharmony_cistatic u64 event_get_##name(struct perf_event *event) \ 428c2ecf20Sopenharmony_ci{ \ 438c2ecf20Sopenharmony_ci return (event->attr.attr_var >> (bit_start)) & \ 448c2ecf20Sopenharmony_ci event_get_##name##_max(); \ 458c2ecf20Sopenharmony_ci} 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci#endif 48