101e04c3fSmrg/*
201e04c3fSmrg * Copyright 2015 Advanced Micro Devices, Inc.
301e04c3fSmrg *
401e04c3fSmrg * Permission is hereby granted, free of charge, to any person obtaining a
501e04c3fSmrg * copy of this software and associated documentation files (the "Software"),
601e04c3fSmrg * to deal in the Software without restriction, including without limitation
701e04c3fSmrg * on the rights to use, copy, modify, merge, publish, distribute, sub
801e04c3fSmrg * license, and/or sell copies of the Software, and to permit persons to whom
901e04c3fSmrg * the Software is furnished to do so, subject to the following conditions:
1001e04c3fSmrg *
1101e04c3fSmrg * The above copyright notice and this permission notice (including the next
1201e04c3fSmrg * paragraph) shall be included in all copies or substantial portions of the
1301e04c3fSmrg * Software.
1401e04c3fSmrg *
1501e04c3fSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1601e04c3fSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1701e04c3fSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
1801e04c3fSmrg * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
1901e04c3fSmrg * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
2001e04c3fSmrg * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
2101e04c3fSmrg * USE OR OTHER DEALINGS IN THE SOFTWARE.
2201e04c3fSmrg */
2301e04c3fSmrg
2401e04c3fSmrg#ifndef AC_DEBUG_H
2501e04c3fSmrg#define AC_DEBUG_H
2601e04c3fSmrg
277ec681f3Smrg#include "amd_family.h"
287ec681f3Smrg
297ec681f3Smrg#include <stdbool.h>
3001e04c3fSmrg#include <stdint.h>
3101e04c3fSmrg#include <stdio.h>
3201e04c3fSmrg
337ec681f3Smrg#define AC_ENCODE_TRACE_POINT(id) (0xcafe0000 | ((id)&0xffff))
347ec681f3Smrg#define AC_IS_TRACE_POINT(x)      (((x)&0xcafe0000) == 0xcafe0000)
357ec681f3Smrg#define AC_GET_TRACE_POINT_ID(x)  ((x)&0xffff)
3601e04c3fSmrg
3701e04c3fSmrg#define AC_MAX_WAVES_PER_CHIP (64 * 40)
3801e04c3fSmrg
397ec681f3Smrg#ifdef __cplusplus
407ec681f3Smrgextern "C" {
417ec681f3Smrg#endif
427ec681f3Smrg
4301e04c3fSmrgstruct ac_wave_info {
447ec681f3Smrg   unsigned se; /* shader engine */
457ec681f3Smrg   unsigned sh; /* shader array */
467ec681f3Smrg   unsigned cu; /* compute unit */
477ec681f3Smrg   unsigned simd;
487ec681f3Smrg   unsigned wave;
497ec681f3Smrg   uint32_t status;
507ec681f3Smrg   uint64_t pc; /* program counter */
517ec681f3Smrg   uint32_t inst_dw0;
527ec681f3Smrg   uint32_t inst_dw1;
537ec681f3Smrg   uint64_t exec;
547ec681f3Smrg   bool matched; /* whether the wave is used by a currently-bound shader */
5501e04c3fSmrg};
5601e04c3fSmrg
5701e04c3fSmrgtypedef void *(*ac_debug_addr_callback)(void *data, uint64_t addr);
5801e04c3fSmrg
597ec681f3Smrgconst char *ac_get_register_name(enum chip_class chip_class, unsigned offset);
607ec681f3Smrgvoid ac_dump_reg(FILE *file, enum chip_class chip_class, unsigned offset, uint32_t value,
617ec681f3Smrg                 uint32_t field_mask);
6201e04c3fSmrgvoid ac_parse_ib_chunk(FILE *f, uint32_t *ib, int num_dw, const int *trace_ids,
637ec681f3Smrg                       unsigned trace_id_count, enum chip_class chip_class,
647ec681f3Smrg                       ac_debug_addr_callback addr_callback, void *addr_callback_data);
657ec681f3Smrgvoid ac_parse_ib(FILE *f, uint32_t *ib, int num_dw, const int *trace_ids, unsigned trace_id_count,
667ec681f3Smrg                 const char *name, enum chip_class chip_class, ac_debug_addr_callback addr_callback,
677ec681f3Smrg                 void *addr_callback_data);
6801e04c3fSmrg
697ec681f3Smrgbool ac_vm_fault_occured(enum chip_class chip_class, uint64_t *old_dmesg_timestamp,
707ec681f3Smrg                         uint64_t *out_addr);
7101e04c3fSmrg
727ec681f3Smrgunsigned ac_get_wave_info(enum chip_class chip_class,
737ec681f3Smrg                          struct ac_wave_info waves[AC_MAX_WAVES_PER_CHIP]);
747ec681f3Smrg
757ec681f3Smrg#ifdef __cplusplus
767ec681f3Smrg}
777ec681f3Smrg#endif
7801e04c3fSmrg
7901e04c3fSmrg#endif
80