2 * Copyright (c) 2013-2018, Intel Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
12 * * Neither the name of Intel Corporation nor the names of its contributors
13 * may be used to endorse or promote products derived from this software
14 * without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
29 #include "pt_config.h"
30 #include "pt_opcodes.h"
38 int pt_cpu_errata(struct pt_errata *errata, const struct pt_cpu *cpu)
43 memset(errata, 0, sizeof(*errata));
45 /* We don't know about others. */
46 if (cpu->vendor != pcv_intel)
49 switch (cpu->family) {
90 int pt_config_from_user(struct pt_config *config,
91 const struct pt_config *uconfig)
102 size = uconfig->size;
103 if (size < offsetof(struct pt_config, decode))
104 return -pte_bad_config;
106 begin = uconfig->begin;
109 if (!begin || !end || end < begin)
110 return -pte_bad_config;
112 /* Ignore fields in the user's configuration we don't know; zero out
113 * fields the user didn't know about.
115 if (sizeof(*config) <= size)
116 size = sizeof(*config);
118 memset(((uint8_t *) config) + size, 0, sizeof(*config) - size);
120 /* Copy (portions of) the user's configuration. */
121 memcpy(config, uconfig, size);
123 /* We copied user's size - fix it. */
129 /* The maximum number of filter addresses that fit into the configuration. */
130 static inline size_t pt_filter_addr_ncfg(void)
132 return (sizeof(struct pt_conf_addr_filter) -
133 offsetof(struct pt_conf_addr_filter, addr0_a)) /
134 (2 * sizeof(uint64_t));
137 uint32_t pt_filter_addr_cfg(const struct pt_conf_addr_filter *filter, uint8_t n)
142 if (pt_filter_addr_ncfg() <= n)
145 return (filter->config.addr_cfg >> (4 * n)) & 0xf;
148 uint64_t pt_filter_addr_a(const struct pt_conf_addr_filter *filter, uint8_t n)
150 const uint64_t *addr;
155 if (pt_filter_addr_ncfg() <= n)
158 addr = &filter->addr0_a;
162 uint64_t pt_filter_addr_b(const struct pt_conf_addr_filter *filter, uint8_t n)
164 const uint64_t *addr;
169 if (pt_filter_addr_ncfg() <= n)
172 addr = &filter->addr0_a;
173 return addr[(2 * n) + 1];
176 static int pt_filter_check_cfg_filter(const struct pt_conf_addr_filter *filter,
182 return -pte_internal;
184 for (n = 0; n < pt_filter_addr_ncfg(); ++n) {
185 uint64_t addr_a, addr_b;
188 addr_cfg = pt_filter_addr_cfg(filter, n);
189 if (addr_cfg != pt_addr_cfg_filter)
192 addr_a = pt_filter_addr_a(filter, n);
193 addr_b = pt_filter_addr_b(filter, n);
195 /* Note that both A and B are inclusive. */
196 if ((addr_a <= addr) && (addr <= addr_b))
200 /* No filter hit. If we have at least one FilterEn filter, this means
201 * that tracing is disabled; otherwise, tracing is enabled.
203 for (n = 0; n < pt_filter_addr_ncfg(); ++n) {
206 addr_cfg = pt_filter_addr_cfg(filter, n);
207 if (addr_cfg == pt_addr_cfg_filter)
214 static int pt_filter_check_cfg_stop(const struct pt_conf_addr_filter *filter,
220 return -pte_internal;
222 for (n = 0; n < pt_filter_addr_ncfg(); ++n) {
223 uint64_t addr_a, addr_b;
226 addr_cfg = pt_filter_addr_cfg(filter, n);
227 if (addr_cfg != pt_addr_cfg_stop)
230 addr_a = pt_filter_addr_a(filter, n);
231 addr_b = pt_filter_addr_b(filter, n);
233 /* Note that both A and B are inclusive. */
234 if ((addr_a <= addr) && (addr <= addr_b))
241 int pt_filter_addr_check(const struct pt_conf_addr_filter *filter,
246 status = pt_filter_check_cfg_stop(filter, addr);
250 return pt_filter_check_cfg_filter(filter, addr);