293203b1472dd30c63036080d0f2bc0d7baa22f2
2 * Copyright (C) 2017-2019 Lyude Paul
3 * Copyright (C) 2017-2019 Alyssa Rosenzweig
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 #ifndef __PAN_DECODE_H__
27 #define __PAN_DECODE_H__
33 #include "util/list.h"
35 struct pandecode_mapped_memory
{
36 struct list_head node
;
46 void pandecode_initialize(void);
48 char *pointer_as_memory_reference(uint64_t ptr
);
50 struct pandecode_mapped_memory
*pandecode_find_mapped_gpu_mem_containing(uint64_t addr
);
53 pandecode_inject_mmap(uint64_t gpu_va
, void *cpu
, unsigned sz
, const char *name
);
56 __pandecode_fetch_gpu_mem(const struct pandecode_mapped_memory
*mem
,
57 uint64_t gpu_va
, size_t size
,
58 int line
, const char *filename
)
61 mem
= pandecode_find_mapped_gpu_mem_containing(gpu_va
);
64 fprintf(stderr
, "Access to unknown memory %" PRIx64
" in %s:%d",
65 gpu_va
, filename
, line
);
70 assert(size
+ (gpu_va
- mem
->gpu_va
) <= mem
->length
);
72 return mem
->addr
+ gpu_va
- mem
->gpu_va
;
75 #define pandecode_fetch_gpu_mem(mem, gpu_va, size) \
76 __pandecode_fetch_gpu_mem(mem, gpu_va, size, __LINE__, __FILE__)
78 /* Returns a validated pointer to mapped GPU memory with the given pointer type,
79 * size automatically determined from the pointer type
81 #define PANDECODE_PTR(mem, gpu_va, type) \
82 ((type*)(__pandecode_fetch_gpu_mem(mem, gpu_va, sizeof(type), \
85 /* Usage: <variable type> PANDECODE_PTR_VAR(name, mem, gpu_va) */
86 #define PANDECODE_PTR_VAR(name, mem, gpu_va) \
87 name = __pandecode_fetch_gpu_mem(mem, gpu_va, sizeof(*name), \
90 /* Common entrypoint */
91 int pandecode_jc(uint64_t jc_gpu_va
, bool bifrost
);
93 #endif /* __MMAP_TRACE_H__ */