1 /*-
2 * Copyright (c) 2018-2020 Ruslan Bukin <br@bsdpad.com>
3 * All rights reserved.
4 *
5 * This software was developed by SRI International and the University of
6 * Cambridge Computer Laboratory under DARPA/AFRL contract FA8750-10-C-0237
7 * ("CTSRD"), as part of the DARPA CRASH research programme.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 *
30 * $FreeBSD$
31 */
32
33 #ifndef _ARM64_CORESIGHT_CORESIGHT_H_
34 #define _ARM64_CORESIGHT_CORESIGHT_H_
35
36 #include "opt_acpi.h"
37 #include "opt_platform.h"
38
39 #include <sys/bus.h>
40 #include <sys/malloc.h>
41
42 #ifdef FDT
43 #include <dev/ofw/openfirm.h>
44 #endif
45
46 #ifdef DEV_ACPI
47 #include <contrib/dev/acpica/include/acpi.h>
48 #include <dev/acpica/acpivar.h>
49 #endif
50
51 #define CORESIGHT_ITCTRL 0xf00
52 #define CORESIGHT_CLAIMSET 0xfa0
53 #define CORESIGHT_CLAIMCLR 0xfa4
54 #define CORESIGHT_LAR 0xfb0
55 #define CORESIGHT_UNLOCK 0xc5acce55
56 #define CORESIGHT_LSR 0xfb4
57 #define CORESIGHT_AUTHSTATUS 0xfb8
58 #define CORESIGHT_DEVID 0xfc8
59 #define CORESIGHT_DEVTYPE 0xfcc
60
61 enum cs_dev_type {
62 CORESIGHT_ETMV4,
63 CORESIGHT_TMC,
64 CORESIGHT_DYNAMIC_REPLICATOR,
65 CORESIGHT_FUNNEL,
66 CORESIGHT_CPU_DEBUG,
67 };
68
69 enum cs_bus_type {
70 CORESIGHT_BUS_ACPI,
71 CORESIGHT_BUS_FDT,
72 };
73
74 struct coresight_device {
75 TAILQ_ENTRY(coresight_device) link;
76 device_t dev;
77 enum cs_dev_type dev_type;
78 struct coresight_platform_data *pdata;
79 };
80
81 struct endpoint {
82 TAILQ_ENTRY(endpoint) link;
83 #ifdef FDT
84 phandle_t my_node;
85 phandle_t their_node;
86 phandle_t dev_node;
87 #endif
88 #ifdef DEV_ACPI
89 ACPI_HANDLE their_handle;
90 ACPI_HANDLE my_handle;
91 #endif
92 boolean_t input;
93 int reg;
94 struct coresight_device *cs_dev;
95 LIST_ENTRY(endpoint) endplink;
96 };
97
98 struct coresight_platform_data {
99 int cpu;
100 int in_ports;
101 int out_ports;
102 struct mtx mtx_lock;
103 TAILQ_HEAD(endpoint_list, endpoint) endpoints;
104 enum cs_bus_type bus_type;
105 };
106
107 struct coresight_desc {
108 struct coresight_platform_data *pdata;
109 device_t dev;
110 enum cs_dev_type dev_type;
111 };
112
113 TAILQ_HEAD(coresight_device_list, coresight_device);
114
115 #define ETM_N_COMPRATOR 16
116
117 struct etm_state {
118 uint32_t trace_id;
119 };
120
121 struct etr_state {
122 boolean_t started;
123 uint32_t cycle;
124 uint32_t offset;
125 uint32_t low;
126 uint32_t high;
127 uint32_t bufsize;
128 uint32_t flags;
129 #define ETR_FLAG_ALLOCATE (1 << 0)
130 #define ETR_FLAG_RELEASE (1 << 1)
131 };
132
133 struct coresight_event {
134 LIST_HEAD(, endpoint) endplist;
135
136 uint64_t addr[ETM_N_COMPRATOR];
137 uint32_t naddr;
138 uint8_t excp_level;
139 enum cs_dev_type src;
140 enum cs_dev_type sink;
141
142 struct etr_state etr;
143 struct etm_state etm;
144 };
145
146 struct etm_config {
147 uint64_t addr[ETM_N_COMPRATOR];
148 uint32_t naddr;
149 uint8_t excp_level;
150 };
151
152 static MALLOC_DEFINE(M_CORESIGHT, "coresight", "ARM Coresight");
153
154 struct coresight_platform_data *coresight_fdt_get_platform_data(device_t dev);
155 struct coresight_platform_data *coresight_acpi_get_platform_data(device_t dev);
156 struct endpoint * coresight_get_output_endpoint(struct coresight_platform_data *pdata);
157 struct coresight_device * coresight_get_output_device(struct endpoint *endp, struct endpoint **);
158 int coresight_register(struct coresight_desc *desc);
159 int coresight_init_event(int cpu, struct coresight_event *event);
160 void coresight_enable(int cpu, struct coresight_event *event);
161 void coresight_disable(int cpu, struct coresight_event *event);
162 void coresight_read(int cpu, struct coresight_event *event);
163
164 #endif /* !_ARM64_CORESIGHT_CORESIGHT_H_ */
Cache object: de8ea75cd91741ff532c7bdf5978c1cf
|