1 From 7b5e845f3243afd393ede5ca0e5de310115ccf30 Mon Sep 17 00:00:00 2001
2 From: Dom Cobley <popcornmix@gmail.com>
3 Date: Thu, 8 Jun 2023 11:33:08 +0100
4 Subject: [PATCH 0910/1085] perf/raspberry: Add support for 2712 axi
7 Also handle 2711 correctly which has a different configuration
10 Signed-off-by: Dom Cobley <popcornmix@gmail.com>
12 drivers/perf/raspberrypi_axi_monitor.c | 257 ++++++++++++++++++++++---
13 1 file changed, 225 insertions(+), 32 deletions(-)
15 --- a/drivers/perf/raspberrypi_axi_monitor.c
16 +++ b/drivers/perf/raspberrypi_axi_monitor.c
19 #define DEFAULT_SAMPLE_TIME 100
21 -#define NUM_BUS_WATCHER_RESULTS 9
22 +#define NUM_BUS_WATCHER_RESULTS 11
24 struct bus_watcher_data {
26 @@ -48,6 +48,8 @@ struct bus_watcher_data {
35 @@ -65,6 +67,9 @@ struct rpi_axiperf {
36 /* Sample time spent on for each bus */
39 + /* chip specific bus config */
40 + const struct bwconfig_config *config;
42 /* Now storage for the per monitor settings and the resulting
45 @@ -107,6 +112,7 @@ const int GEN_CTRL;
47 const int GEN_CTL_ENABLE_BIT = BIT(0);
48 const int GEN_CTL_RESET_BIT = BIT(1);
49 +const int GEN_CTL_WATCH_BIT = BIT(2);
51 /* Bus watcher registers */
52 const int BW_PITCH = 0x40;
53 @@ -136,7 +142,7 @@ const int BW_CTRL_BUS_WATCH_SHIFT;
54 const int BW_CTRL_BUS_WATCH_MASK = GENMASK(5, 0); // 6 bits
55 const int BW_CTRL_BUS_FILTER_SHIFT = 8;
57 -const static char *bus_filter_strings[] = {
58 +static const char *bus_filter_strings[] = {
62 @@ -171,9 +177,96 @@ const static char *bus_filter_strings[]
66 -const int num_bus_filters = ARRAY_SIZE(bus_filter_strings);
67 +static const char * const bus_filter_strings_2711[] = {
102 -const static char *system_bus_string[] = {
103 +static const char * const bus_filter_strings_2712[] = {
157 +static const char *system_bus_string[] = {
161 @@ -192,9 +285,38 @@ const static char *system_bus_string[] =
165 -const int num_system_buses = ARRAY_SIZE(system_bus_string);
166 +static const char * const system_bus_string_2711[] = {
181 +static const char * const system_bus_string_2712[] = {
197 -const static char *vpu_bus_string[] = {
198 +static const char *vpu_bus_string[] = {
202 @@ -213,7 +335,66 @@ const static char *vpu_bus_string[] = {
206 -const int num_vpu_buses = ARRAY_SIZE(vpu_bus_string);
207 +static const char * const vpu_bus_string_2711[] = {
224 +static const char * const vpu_bus_string_2712[] = {
241 +struct bwconfig_config {
242 + const char * const *bus_filter_strings;
243 + const int num_bus_filters;
244 + const char * const *system_bus_string;
245 + const int num_system_buses;
246 + const char * const *vpu_bus_string;
247 + const int num_vpu_buses;
250 +static const struct bwconfig_config config_2835 = {
251 + bus_filter_strings, ARRAY_SIZE(bus_filter_strings),
252 + system_bus_string, ARRAY_SIZE(system_bus_string),
253 + vpu_bus_string, ARRAY_SIZE(vpu_bus_string),
256 +static const struct bwconfig_config config_2711 = {
257 + bus_filter_strings_2711, ARRAY_SIZE(bus_filter_strings_2711),
258 + system_bus_string_2711, ARRAY_SIZE(system_bus_string_2711),
259 + vpu_bus_string_2711, ARRAY_SIZE(vpu_bus_string_2711),
262 +static const struct bwconfig_config config_2712 = {
263 + bus_filter_strings_2712, ARRAY_SIZE(bus_filter_strings_2712),
264 + system_bus_string_2712, ARRAY_SIZE(system_bus_string_2712),
265 + vpu_bus_string_2712, ARRAY_SIZE(vpu_bus_string_2712),
268 const static char *monitor_name[] = {
270 @@ -233,10 +414,10 @@ static inline u32 read_reg(int monitor,
271 static void read_bus_watcher(int monitor, int watcher, u32 *results)
273 if (state->monitor[monitor].use_mailbox_interface) {
274 - /* We have 9 results, plus the overheads of start address and
275 - * length So 11 u32 to define
276 + /* We have NUM_BUS_WATCHER_RESULTS results, plus the overheads
277 + * of start address and length
280 + u32 tmp[NUM_BUS_WATCHER_RESULTS+2];
283 tmp[0] = (u32)(uintptr_t)(state->monitor[monitor].base_address + watcher
284 @@ -352,7 +533,7 @@ static void monitor(struct rpi_axiperf *
287 /* start monitoring */
288 - set_monitor_control(monitor, GEN_CTL_ENABLE_BIT);
289 + set_monitor_control(monitor, GEN_CTL_ENABLE_BIT | GEN_CTL_WATCH_BIT);
292 mutex_unlock(&state->lock);
293 @@ -409,11 +590,12 @@ static ssize_t myreader(struct file *fp,
294 int buff_size = INIT_BUFF_SIZE;
296 typeof(state->monitor[0]) *mon = &(state->monitor[idx]);
297 + const struct bwconfig_config *config = state->config;
299 if (idx < 0 || idx > NUM_MONITORS)
302 - num_buses = idx == SYSTEM_MONITOR ? num_system_buses : num_vpu_buses;
303 + num_buses = idx == SYSTEM_MONITOR ? config->num_system_buses : config->num_vpu_buses;
305 string_buffer = kmalloc(buff_size, GFP_KERNEL);
307 @@ -428,17 +610,17 @@ static ssize_t myreader(struct file *fp,
308 mutex_lock(&state->lock);
310 if (mon->bus_filter) {
311 - int filt = min(mon->bus_filter & 0x1f, num_bus_filters);
312 + int filt = min(mon->bus_filter & 0x1f, config->num_bus_filters);
314 cnt = snprintf(p, buff_size,
315 "\nMonitoring transactions from %s only\n",
316 - bus_filter_strings[filt]);
317 + config->bus_filter_strings[filt]);
322 - cnt = snprintf(p, buff_size, " Bus | Atrans Atwait AMax Wtrans Wtwait WMax Rtrans Rtwait RMax\n"
323 - "======================================================================================================\n");
324 + cnt = snprintf(p, buff_size, " Bus | Atrans Atwait AMax Wtrans Wtwait WMax Rtrans Rtwait RMax RPend RAtrans\n"
325 + "===========================================================================================================================\n");
327 if (cnt >= buff_size)
329 @@ -446,25 +628,29 @@ static ssize_t myreader(struct file *fp,
333 +#define M(x) ((x) >= 1000000000 ? (x)/1000000 : (x) >= 1000 ? (x)/1000 : (x))
334 +#define N(x) ((x) >= 1000000000 ? 'M' : (x) >= 1000 ? 'K' : ' ')
336 for (i = 0; i < num_buses; i++) {
337 if (mon->bus_enabled & (1 << i)) {
338 -#define DIVIDER (1024)
339 typeof(mon->results[0]) *res = &(mon->results[i]);
341 cnt = snprintf(p, buff_size,
342 - "%10s | %8uK %8uK %8uK %8uK %8uK %8uK %8uK %8uK %8uK\n",
343 + "%11s | %8u%c %8u%c %8u%c %8u%c %8u%c %8u%c %8u%c %8u%c %8u%c %8u%c %8u%c\n",
344 idx == SYSTEM_MONITOR ?
345 - system_bus_string[i] :
347 - res->atrans/DIVIDER,
348 - res->atwait/DIVIDER,
350 - res->wtrans/DIVIDER,
351 - res->wtwait/DIVIDER,
353 - res->rtrans/DIVIDER,
354 - res->rtwait/DIVIDER,
356 + config->system_bus_string[i] :
357 + config->vpu_bus_string[i],
358 + M(res->atrans), N(res->atrans),
359 + M(res->atwait), N(res->atwait),
360 + M(res->amax), N(res->amax),
361 + M(res->wtrans), N(res->wtrans),
362 + M(res->wtwait), N(res->wtwait),
363 + M(res->wmax), N(res->wmax),
364 + M(res->rtrans), N(res->rtrans),
365 + M(res->rtwait), N(res->rtwait),
366 + M(res->rmax), N(res->rmax),
367 + M(res->rpend), N(res->rpend),
368 + M(res->ratrans), N(res->ratrans)
370 if (cnt >= buff_size)
372 @@ -526,6 +712,10 @@ static int rpi_axiperf_probe(struct plat
376 + state->config = of_device_get_match_data(dev);
377 + if (!state->config)
380 /* Get the firmware handle for future rpi-firmware-xxx calls */
381 fw_node = of_parse_phandle(np, "firmware", 0);
383 @@ -612,9 +802,12 @@ static int rpi_axiperf_remove(struct pla
386 static const struct of_device_id rpi_axiperf_match[] = {
388 - .compatible = "brcm,bcm2835-axiperf",
390 + { .compatible = "brcm,bcm2835-axiperf",
391 + .data = &config_2835 },
392 + { .compatible = "brcm,bcm2711-axiperf",
393 + .data = &config_2711 },
394 + { .compatible = "brcm,bcm2712-axiperf",
395 + .data = &config_2712 },
398 MODULE_DEVICE_TABLE(of, rpi_axiperf_match);