^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * intel_pt_log.h: Intel Processor Trace support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (c) 2013-2014, Intel Corporation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #ifndef INCLUDE__INTEL_PT_LOG_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #define INCLUDE__INTEL_PT_LOG_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/compiler.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <stdint.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <inttypes.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) struct intel_pt_pkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) void *intel_pt_log_fp(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) void intel_pt_log_enable(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) void intel_pt_log_disable(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) void intel_pt_log_set_name(const char *name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) void __intel_pt_log_packet(const struct intel_pt_pkt *packet, int pkt_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) uint64_t pos, const unsigned char *buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) struct intel_pt_insn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) void __intel_pt_log_insn(struct intel_pt_insn *intel_pt_insn, uint64_t ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) void __intel_pt_log_insn_no_data(struct intel_pt_insn *intel_pt_insn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) uint64_t ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) void __intel_pt_log(const char *fmt, ...) __printf(1, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define intel_pt_log(fmt, ...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) if (intel_pt_enable_logging) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) __intel_pt_log(fmt, ##__VA_ARGS__); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define intel_pt_log_packet(arg, ...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) if (intel_pt_enable_logging) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) __intel_pt_log_packet(arg, ##__VA_ARGS__); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #define intel_pt_log_insn(arg, ...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) if (intel_pt_enable_logging) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) __intel_pt_log_insn(arg, ##__VA_ARGS__); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define intel_pt_log_insn_no_data(arg, ...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) if (intel_pt_enable_logging) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) __intel_pt_log_insn_no_data(arg, ##__VA_ARGS__); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #define x64_fmt "0x%" PRIx64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) extern bool intel_pt_enable_logging;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) static inline void intel_pt_log_at(const char *msg, uint64_t u)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) intel_pt_log("%s at " x64_fmt "\n", msg, u);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) static inline void intel_pt_log_to(const char *msg, uint64_t u)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) intel_pt_log("%s to " x64_fmt "\n", msg, u);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) #endif