1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright 2015 Advanced Micro Devices, Inc.
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
7bf215546Sopenharmony_ci * on the rights to use, copy, modify, merge, publish, distribute, sub
8bf215546Sopenharmony_ci * license, and/or sell copies of the Software, and to permit persons to whom
9bf215546Sopenharmony_ci * the Software is furnished to do so, subject to the following conditions:
10bf215546Sopenharmony_ci *
11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
13bf215546Sopenharmony_ci * Software.
14bf215546Sopenharmony_ci *
15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18bf215546Sopenharmony_ci * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19bf215546Sopenharmony_ci * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20bf215546Sopenharmony_ci * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21bf215546Sopenharmony_ci * USE OR OTHER DEALINGS IN THE SOFTWARE.
22bf215546Sopenharmony_ci */
23bf215546Sopenharmony_ci
24bf215546Sopenharmony_ci#ifndef AC_DEBUG_H
25bf215546Sopenharmony_ci#define AC_DEBUG_H
26bf215546Sopenharmony_ci
27bf215546Sopenharmony_ci#include "amd_family.h"
28bf215546Sopenharmony_ci
29bf215546Sopenharmony_ci#include <stdbool.h>
30bf215546Sopenharmony_ci#include <stdint.h>
31bf215546Sopenharmony_ci#include <stdio.h>
32bf215546Sopenharmony_ci
33bf215546Sopenharmony_ci#define AC_ENCODE_TRACE_POINT(id) (0xcafe0000 | ((id)&0xffff))
34bf215546Sopenharmony_ci#define AC_IS_TRACE_POINT(x)      (((x)&0xcafe0000) == 0xcafe0000)
35bf215546Sopenharmony_ci#define AC_GET_TRACE_POINT_ID(x)  ((x)&0xffff)
36bf215546Sopenharmony_ci
37bf215546Sopenharmony_ci#define AC_MAX_WAVES_PER_CHIP (64 * 40)
38bf215546Sopenharmony_ci
39bf215546Sopenharmony_ci#ifdef __cplusplus
40bf215546Sopenharmony_ciextern "C" {
41bf215546Sopenharmony_ci#endif
42bf215546Sopenharmony_ci
43bf215546Sopenharmony_cistruct ac_wave_info {
44bf215546Sopenharmony_ci   unsigned se; /* shader engine */
45bf215546Sopenharmony_ci   unsigned sh; /* shader array */
46bf215546Sopenharmony_ci   unsigned cu; /* compute unit */
47bf215546Sopenharmony_ci   unsigned simd;
48bf215546Sopenharmony_ci   unsigned wave;
49bf215546Sopenharmony_ci   uint32_t status;
50bf215546Sopenharmony_ci   uint64_t pc; /* program counter */
51bf215546Sopenharmony_ci   uint32_t inst_dw0;
52bf215546Sopenharmony_ci   uint32_t inst_dw1;
53bf215546Sopenharmony_ci   uint64_t exec;
54bf215546Sopenharmony_ci   bool matched; /* whether the wave is used by a currently-bound shader */
55bf215546Sopenharmony_ci};
56bf215546Sopenharmony_ci
57bf215546Sopenharmony_citypedef void *(*ac_debug_addr_callback)(void *data, uint64_t addr);
58bf215546Sopenharmony_ci
59bf215546Sopenharmony_ciconst char *ac_get_register_name(enum amd_gfx_level gfx_level, unsigned offset);
60bf215546Sopenharmony_civoid ac_dump_reg(FILE *file, enum amd_gfx_level gfx_level, unsigned offset, uint32_t value,
61bf215546Sopenharmony_ci                 uint32_t field_mask);
62bf215546Sopenharmony_civoid ac_parse_ib_chunk(FILE *f, uint32_t *ib, int num_dw, const int *trace_ids,
63bf215546Sopenharmony_ci                       unsigned trace_id_count, enum amd_gfx_level gfx_level,
64bf215546Sopenharmony_ci                       ac_debug_addr_callback addr_callback, void *addr_callback_data);
65bf215546Sopenharmony_civoid ac_parse_ib(FILE *f, uint32_t *ib, int num_dw, const int *trace_ids, unsigned trace_id_count,
66bf215546Sopenharmony_ci                 const char *name, enum amd_gfx_level gfx_level, ac_debug_addr_callback addr_callback,
67bf215546Sopenharmony_ci                 void *addr_callback_data);
68bf215546Sopenharmony_ci
69bf215546Sopenharmony_cibool ac_vm_fault_occured(enum amd_gfx_level gfx_level, uint64_t *old_dmesg_timestamp,
70bf215546Sopenharmony_ci                         uint64_t *out_addr);
71bf215546Sopenharmony_ci
72bf215546Sopenharmony_ciunsigned ac_get_wave_info(enum amd_gfx_level gfx_level,
73bf215546Sopenharmony_ci                          struct ac_wave_info waves[AC_MAX_WAVES_PER_CHIP]);
74bf215546Sopenharmony_ci
75bf215546Sopenharmony_ci#ifdef __cplusplus
76bf215546Sopenharmony_ci}
77bf215546Sopenharmony_ci#endif
78bf215546Sopenharmony_ci
79bf215546Sopenharmony_ci#endif
80