Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / hwtracing / coresight / coresight-trbe.h
blob45202c48accec7c86ba56130e2737bc2d1830fae
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * This contains all required hardware related helper functions for
4 * Trace Buffer Extension (TRBE) driver in the coresight framework.
6 * Copyright (C) 2020 ARM Ltd.
8 * Author: Anshuman Khandual <anshuman.khandual@arm.com>
9 */
10 #include <linux/acpi.h>
11 #include <linux/coresight.h>
12 #include <linux/device.h>
13 #include <linux/irq.h>
14 #include <linux/kernel.h>
15 #include <linux/of.h>
16 #include <linux/perf/arm_pmu.h>
17 #include <linux/platform_device.h>
18 #include <linux/smp.h>
20 #include "coresight-etm-perf.h"
22 static inline bool is_trbe_available(void)
24 u64 aa64dfr0 = read_sysreg_s(SYS_ID_AA64DFR0_EL1);
25 unsigned int trbe = cpuid_feature_extract_unsigned_field(aa64dfr0,
26 ID_AA64DFR0_EL1_TraceBuffer_SHIFT);
28 return trbe >= ID_AA64DFR0_EL1_TraceBuffer_IMP;
31 static inline bool is_trbe_enabled(void)
33 u64 trblimitr = read_sysreg_s(SYS_TRBLIMITR_EL1);
35 return trblimitr & TRBLIMITR_EL1_E;
38 #define TRBE_EC_OTHERS 0
39 #define TRBE_EC_STAGE1_ABORT 36
40 #define TRBE_EC_STAGE2_ABORT 37
42 static inline int get_trbe_ec(u64 trbsr)
44 return (trbsr & TRBSR_EL1_EC_MASK) >> TRBSR_EL1_EC_SHIFT;
47 #define TRBE_BSC_NOT_STOPPED 0
48 #define TRBE_BSC_FILLED 1
49 #define TRBE_BSC_TRIGGERED 2
51 static inline int get_trbe_bsc(u64 trbsr)
53 return (trbsr & TRBSR_EL1_BSC_MASK) >> TRBSR_EL1_BSC_SHIFT;
56 static inline void clr_trbe_irq(void)
58 u64 trbsr = read_sysreg_s(SYS_TRBSR_EL1);
60 trbsr &= ~TRBSR_EL1_IRQ;
61 write_sysreg_s(trbsr, SYS_TRBSR_EL1);
64 static inline bool is_trbe_irq(u64 trbsr)
66 return trbsr & TRBSR_EL1_IRQ;
69 static inline bool is_trbe_trg(u64 trbsr)
71 return trbsr & TRBSR_EL1_TRG;
74 static inline bool is_trbe_wrap(u64 trbsr)
76 return trbsr & TRBSR_EL1_WRAP;
79 static inline bool is_trbe_abort(u64 trbsr)
81 return trbsr & TRBSR_EL1_EA;
84 static inline bool is_trbe_running(u64 trbsr)
86 return !(trbsr & TRBSR_EL1_S);
89 static inline bool get_trbe_flag_update(u64 trbidr)
91 return trbidr & TRBIDR_EL1_F;
94 static inline bool is_trbe_programmable(u64 trbidr)
96 return !(trbidr & TRBIDR_EL1_P);
99 static inline int get_trbe_address_align(u64 trbidr)
101 return (trbidr & TRBIDR_EL1_Align_MASK) >> TRBIDR_EL1_Align_SHIFT;
104 static inline unsigned long get_trbe_write_pointer(void)
106 return read_sysreg_s(SYS_TRBPTR_EL1);
109 static inline void set_trbe_write_pointer(unsigned long addr)
111 WARN_ON(is_trbe_enabled());
112 write_sysreg_s(addr, SYS_TRBPTR_EL1);
115 static inline unsigned long get_trbe_limit_pointer(void)
117 u64 trblimitr = read_sysreg_s(SYS_TRBLIMITR_EL1);
118 unsigned long addr = trblimitr & TRBLIMITR_EL1_LIMIT_MASK;
120 WARN_ON(!IS_ALIGNED(addr, PAGE_SIZE));
121 return addr;
124 static inline unsigned long get_trbe_base_pointer(void)
126 u64 trbbaser = read_sysreg_s(SYS_TRBBASER_EL1);
127 unsigned long addr = trbbaser & TRBBASER_EL1_BASE_MASK;
129 WARN_ON(!IS_ALIGNED(addr, PAGE_SIZE));
130 return addr;
133 static inline void set_trbe_base_pointer(unsigned long addr)
135 WARN_ON(is_trbe_enabled());
136 WARN_ON(!IS_ALIGNED(addr, (1UL << TRBBASER_EL1_BASE_SHIFT)));
137 WARN_ON(!IS_ALIGNED(addr, PAGE_SIZE));
138 write_sysreg_s(addr, SYS_TRBBASER_EL1);