17ec681f3Smrg/*
27ec681f3Smrg * Copyright (C) 2017-2019 Lyude Paul
37ec681f3Smrg * Copyright (C) 2017-2019 Alyssa Rosenzweig
47ec681f3Smrg *
57ec681f3Smrg * Permission is hereby granted, free of charge, to any person obtaining a
67ec681f3Smrg * copy of this software and associated documentation files (the "Software"),
77ec681f3Smrg * to deal in the Software without restriction, including without limitation
87ec681f3Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
97ec681f3Smrg * and/or sell copies of the Software, and to permit persons to whom the
107ec681f3Smrg * Software is furnished to do so, subject to the following conditions:
117ec681f3Smrg *
127ec681f3Smrg * The above copyright notice and this permission notice (including the next
137ec681f3Smrg * paragraph) shall be included in all copies or substantial portions of the
147ec681f3Smrg * Software.
157ec681f3Smrg *
167ec681f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
177ec681f3Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
187ec681f3Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
197ec681f3Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
207ec681f3Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
217ec681f3Smrg * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
227ec681f3Smrg * SOFTWARE.
237ec681f3Smrg *
247ec681f3Smrg */
257ec681f3Smrg
267ec681f3Smrg#ifndef __PAN_DECODE_H__
277ec681f3Smrg#define __PAN_DECODE_H__
287ec681f3Smrg
297ec681f3Smrg#include "genxml/gen_macros.h"
307ec681f3Smrg
317ec681f3Smrg#include "wrap.h"
327ec681f3Smrg
337ec681f3Smrgextern FILE *pandecode_dump_stream;
347ec681f3Smrg
357ec681f3Smrgvoid pandecode_dump_file_open(void);
367ec681f3Smrg
377ec681f3Smrgstruct pandecode_mapped_memory {
387ec681f3Smrg        size_t length;
397ec681f3Smrg        void *addr;
407ec681f3Smrg        uint64_t gpu_va;
417ec681f3Smrg        bool ro;
427ec681f3Smrg        char name[32];
437ec681f3Smrg};
447ec681f3Smrg
457ec681f3Smrgchar *pointer_as_memory_reference(uint64_t ptr);
467ec681f3Smrg
477ec681f3Smrgstruct pandecode_mapped_memory *pandecode_find_mapped_gpu_mem_containing(uint64_t addr);
487ec681f3Smrg
497ec681f3Smrgvoid pandecode_map_read_write(void);
507ec681f3Smrg
517ec681f3Smrgstatic inline void *
527ec681f3Smrg__pandecode_fetch_gpu_mem(const struct pandecode_mapped_memory *mem,
537ec681f3Smrg                          uint64_t gpu_va, size_t size,
547ec681f3Smrg                          int line, const char *filename)
557ec681f3Smrg{
567ec681f3Smrg        if (!mem)
577ec681f3Smrg                mem = pandecode_find_mapped_gpu_mem_containing(gpu_va);
587ec681f3Smrg
597ec681f3Smrg        if (!mem) {
607ec681f3Smrg                fprintf(stderr, "Access to unknown memory %" PRIx64 " in %s:%d\n",
617ec681f3Smrg                        gpu_va, filename, line);
627ec681f3Smrg                assert(0);
637ec681f3Smrg        }
647ec681f3Smrg
657ec681f3Smrg        assert(mem);
667ec681f3Smrg        assert(size + (gpu_va - mem->gpu_va) <= mem->length);
677ec681f3Smrg
687ec681f3Smrg        return mem->addr + gpu_va - mem->gpu_va;
697ec681f3Smrg}
707ec681f3Smrg
717ec681f3Smrg#define pandecode_fetch_gpu_mem(mem, gpu_va, size) \
727ec681f3Smrg	__pandecode_fetch_gpu_mem(mem, gpu_va, size, __LINE__, __FILE__)
737ec681f3Smrg
747ec681f3Smrg/* Returns a validated pointer to mapped GPU memory with the given pointer type,
757ec681f3Smrg * size automatically determined from the pointer type
767ec681f3Smrg */
777ec681f3Smrg#define PANDECODE_PTR(mem, gpu_va, type) \
787ec681f3Smrg	((type*)(__pandecode_fetch_gpu_mem(mem, gpu_va, sizeof(type), \
797ec681f3Smrg					 __LINE__, __FILE__)))
807ec681f3Smrg
817ec681f3Smrg/* Usage: <variable type> PANDECODE_PTR_VAR(name, mem, gpu_va) */
827ec681f3Smrg#define PANDECODE_PTR_VAR(name, mem, gpu_va) \
837ec681f3Smrg	name = __pandecode_fetch_gpu_mem(mem, gpu_va, sizeof(*name), \
847ec681f3Smrg				       __LINE__, __FILE__)
857ec681f3Smrg
867ec681f3Smrg#ifdef PAN_ARCH
877ec681f3Smrgvoid GENX(pandecode_jc)(mali_ptr jc_gpu_va, unsigned gpu_id);
887ec681f3Smrgvoid GENX(pandecode_abort_on_fault)(mali_ptr jc_gpu_va);
897ec681f3Smrg#endif
907ec681f3Smrg
917ec681f3Smrg#endif /* __MMAP_TRACE_H__ */
92