162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Intel(R) Processor Trace PMU driver for perf 462306a36Sopenharmony_ci * Copyright (c) 2013-2014, Intel Corporation. 562306a36Sopenharmony_ci * 662306a36Sopenharmony_ci * Intel PT is specified in the Intel Architecture Instruction Set Extensions 762306a36Sopenharmony_ci * Programming Reference: 862306a36Sopenharmony_ci * http://software.intel.com/en-us/intel-isa-extensions 962306a36Sopenharmony_ci */ 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ci#ifndef __INTEL_PT_H__ 1262306a36Sopenharmony_ci#define __INTEL_PT_H__ 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci/* 1562306a36Sopenharmony_ci * Single-entry ToPA: when this close to region boundary, switch 1662306a36Sopenharmony_ci * buffers to avoid losing data. 1762306a36Sopenharmony_ci */ 1862306a36Sopenharmony_ci#define TOPA_PMI_MARGIN 512 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ci#define TOPA_SHIFT 12 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_cistatic inline unsigned int sizes(unsigned int tsz) 2362306a36Sopenharmony_ci{ 2462306a36Sopenharmony_ci return 1 << (tsz + TOPA_SHIFT); 2562306a36Sopenharmony_ci}; 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_cistruct topa_entry { 2862306a36Sopenharmony_ci u64 end : 1; 2962306a36Sopenharmony_ci u64 rsvd0 : 1; 3062306a36Sopenharmony_ci u64 intr : 1; 3162306a36Sopenharmony_ci u64 rsvd1 : 1; 3262306a36Sopenharmony_ci u64 stop : 1; 3362306a36Sopenharmony_ci u64 rsvd2 : 1; 3462306a36Sopenharmony_ci u64 size : 4; 3562306a36Sopenharmony_ci u64 rsvd3 : 2; 3662306a36Sopenharmony_ci u64 base : 36; 3762306a36Sopenharmony_ci u64 rsvd4 : 16; 3862306a36Sopenharmony_ci}; 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_ci/* TSC to Core Crystal Clock Ratio */ 4162306a36Sopenharmony_ci#define CPUID_TSC_LEAF 0x15 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_cistruct pt_pmu { 4462306a36Sopenharmony_ci struct pmu pmu; 4562306a36Sopenharmony_ci u32 caps[PT_CPUID_REGS_NUM * PT_CPUID_LEAVES]; 4662306a36Sopenharmony_ci bool vmx; 4762306a36Sopenharmony_ci bool branch_en_always_on; 4862306a36Sopenharmony_ci unsigned long max_nonturbo_ratio; 4962306a36Sopenharmony_ci unsigned int tsc_art_num; 5062306a36Sopenharmony_ci unsigned int tsc_art_den; 5162306a36Sopenharmony_ci}; 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_ci/** 5462306a36Sopenharmony_ci * struct pt_buffer - buffer configuration; one buffer per task_struct or 5562306a36Sopenharmony_ci * cpu, depending on perf event configuration 5662306a36Sopenharmony_ci * @tables: list of ToPA tables in this buffer 5762306a36Sopenharmony_ci * @first: shorthand for first topa table 5862306a36Sopenharmony_ci * @last: shorthand for last topa table 5962306a36Sopenharmony_ci * @cur: current topa table 6062306a36Sopenharmony_ci * @nr_pages: buffer size in pages 6162306a36Sopenharmony_ci * @cur_idx: current output region's index within @cur table 6262306a36Sopenharmony_ci * @output_off: offset within the current output region 6362306a36Sopenharmony_ci * @data_size: running total of the amount of data in this buffer 6462306a36Sopenharmony_ci * @lost: if data was lost/truncated 6562306a36Sopenharmony_ci * @head: logical write offset inside the buffer 6662306a36Sopenharmony_ci * @snapshot: if this is for a snapshot/overwrite counter 6762306a36Sopenharmony_ci * @single: use Single Range Output instead of ToPA 6862306a36Sopenharmony_ci * @stop_pos: STOP topa entry index 6962306a36Sopenharmony_ci * @intr_pos: INT topa entry index 7062306a36Sopenharmony_ci * @stop_te: STOP topa entry pointer 7162306a36Sopenharmony_ci * @intr_te: INT topa entry pointer 7262306a36Sopenharmony_ci * @data_pages: array of pages from perf 7362306a36Sopenharmony_ci * @topa_index: table of topa entries indexed by page offset 7462306a36Sopenharmony_ci */ 7562306a36Sopenharmony_cistruct pt_buffer { 7662306a36Sopenharmony_ci struct list_head tables; 7762306a36Sopenharmony_ci struct topa *first, *last, *cur; 7862306a36Sopenharmony_ci unsigned int cur_idx; 7962306a36Sopenharmony_ci size_t output_off; 8062306a36Sopenharmony_ci unsigned long nr_pages; 8162306a36Sopenharmony_ci local_t data_size; 8262306a36Sopenharmony_ci local64_t head; 8362306a36Sopenharmony_ci bool snapshot; 8462306a36Sopenharmony_ci bool single; 8562306a36Sopenharmony_ci long stop_pos, intr_pos; 8662306a36Sopenharmony_ci struct topa_entry *stop_te, *intr_te; 8762306a36Sopenharmony_ci void **data_pages; 8862306a36Sopenharmony_ci}; 8962306a36Sopenharmony_ci 9062306a36Sopenharmony_ci#define PT_FILTERS_NUM 4 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_ci/** 9362306a36Sopenharmony_ci * struct pt_filter - IP range filter configuration 9462306a36Sopenharmony_ci * @msr_a: range start, goes to RTIT_ADDRn_A 9562306a36Sopenharmony_ci * @msr_b: range end, goes to RTIT_ADDRn_B 9662306a36Sopenharmony_ci * @config: 4-bit field in RTIT_CTL 9762306a36Sopenharmony_ci */ 9862306a36Sopenharmony_cistruct pt_filter { 9962306a36Sopenharmony_ci unsigned long msr_a; 10062306a36Sopenharmony_ci unsigned long msr_b; 10162306a36Sopenharmony_ci unsigned long config; 10262306a36Sopenharmony_ci}; 10362306a36Sopenharmony_ci 10462306a36Sopenharmony_ci/** 10562306a36Sopenharmony_ci * struct pt_filters - IP range filtering context 10662306a36Sopenharmony_ci * @filter: filters defined for this context 10762306a36Sopenharmony_ci * @nr_filters: number of defined filters in the @filter array 10862306a36Sopenharmony_ci */ 10962306a36Sopenharmony_cistruct pt_filters { 11062306a36Sopenharmony_ci struct pt_filter filter[PT_FILTERS_NUM]; 11162306a36Sopenharmony_ci unsigned int nr_filters; 11262306a36Sopenharmony_ci}; 11362306a36Sopenharmony_ci 11462306a36Sopenharmony_ci/** 11562306a36Sopenharmony_ci * struct pt - per-cpu pt context 11662306a36Sopenharmony_ci * @handle: perf output handle 11762306a36Sopenharmony_ci * @filters: last configured filters 11862306a36Sopenharmony_ci * @handle_nmi: do handle PT PMI on this cpu, there's an active event 11962306a36Sopenharmony_ci * @vmx_on: 1 if VMX is ON on this cpu 12062306a36Sopenharmony_ci * @output_base: cached RTIT_OUTPUT_BASE MSR value 12162306a36Sopenharmony_ci * @output_mask: cached RTIT_OUTPUT_MASK MSR value 12262306a36Sopenharmony_ci */ 12362306a36Sopenharmony_cistruct pt { 12462306a36Sopenharmony_ci struct perf_output_handle handle; 12562306a36Sopenharmony_ci struct pt_filters filters; 12662306a36Sopenharmony_ci int handle_nmi; 12762306a36Sopenharmony_ci int vmx_on; 12862306a36Sopenharmony_ci u64 output_base; 12962306a36Sopenharmony_ci u64 output_mask; 13062306a36Sopenharmony_ci}; 13162306a36Sopenharmony_ci 13262306a36Sopenharmony_ci#endif /* __INTEL_PT_H__ */ 133