xref: /aosp_15_r20/external/mesa3d/src/intel/tools/aub_write.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright © 2007-2017 Intel Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  *
23  */
24 
25 #ifndef INTEL_AUB_WRITE
26 #define INTEL_AUB_WRITE
27 
28 #include <stdarg.h>
29 #include <stdint.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 
33 #include "dev/intel_device_info.h"
34 #include "common/intel_gem.h"
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 static inline void PRINTFLIKE(2, 3) NORETURN
_fail(const char * prefix,const char * format,...)41 _fail(const char *prefix, const char *format, ...)
42 {
43    va_list args;
44 
45    va_start(args, format);
46    if (prefix)
47       fprintf(stderr, "%s: ", prefix);
48    vfprintf(stderr, format, args);
49    va_end(args);
50 
51    abort();
52 }
53 
54 #define _fail_if(cond, prefix, ...) do { \
55    if (cond) \
56       _fail(prefix, __VA_ARGS__); \
57 } while (0)
58 
59 #define MAX_CONTEXT_COUNT 64
60 
61 struct aub_ppgtt_table {
62    uint64_t phys_addr;
63    struct aub_ppgtt_table *subtables[512];
64 };
65 
66 struct aub_hw_context {
67    bool initialized;
68    uint64_t ring_addr;
69    uint64_t pphwsp_addr;
70 };
71 
72 /* GEM context, as seen from userspace */
73 struct aub_context {
74    uint32_t id;
75    struct aub_hw_context hw_contexts[INTEL_ENGINE_CLASS_VIDEO + 1];
76 };
77 
78 struct aub_file {
79    FILE *file;
80 
81    bool has_default_setup;
82 
83    /* Set if you want extra logging */
84    FILE *verbose_log_file;
85 
86    uint16_t pci_id;
87    struct intel_device_info devinfo;
88 
89    int addr_bits;
90 
91    struct aub_ppgtt_table pml4;
92    uint64_t phys_addrs_allocator;
93    uint64_t ggtt_addrs_allocator;
94 
95    struct {
96       uint64_t hwsp_addr;
97    } engine_setup[INTEL_ENGINE_CLASS_VIDEO_ENHANCE + 1];
98 
99    struct aub_context contexts[MAX_CONTEXT_COUNT];
100    int num_contexts;
101 
102    uint32_t next_context_handle;
103 };
104 
105 void aub_file_init(struct aub_file *aub, FILE *file, FILE *debug, uint16_t pci_id, const char *app_name);
106 void aub_file_finish(struct aub_file *aub);
107 
aub_use_execlists(const struct aub_file * aub)108 static inline bool aub_use_execlists(const struct aub_file *aub)
109 {
110    return aub->devinfo.ver >= 8;
111 }
112 
113 uint32_t aub_gtt_size(struct aub_file *aub);
114 
115 static inline void
aub_write_reloc(const struct intel_device_info * devinfo,void * p,uint64_t v)116 aub_write_reloc(const struct intel_device_info *devinfo, void *p, uint64_t v)
117 {
118    if (devinfo->ver >= 8) {
119       *(uint64_t *)p = intel_canonical_address(v);
120    } else {
121       *(uint32_t *)p = v;
122    }
123 }
124 
125 void aub_write_default_setup(struct aub_file *aub);
126 void aub_map_ppgtt(struct aub_file *aub, uint64_t start, uint64_t size);
127 void aub_write_ggtt(struct aub_file *aub, uint64_t virt_addr, uint64_t size, const void *data);
128 void aub_write_trace_block(struct aub_file *aub,
129                            uint32_t type, void *virtual,
130                            uint32_t size, uint64_t gtt_offset);
131 void aub_write_exec(struct aub_file *aub, uint32_t ctx_id, uint64_t batch_addr,
132                     uint64_t offset, enum intel_engine_class engine_class);
133 void aub_write_context_execlists(struct aub_file *aub, uint64_t context_addr,
134                                  enum intel_engine_class engine_class);
135 
136 uint32_t aub_write_context_create(struct aub_file *aub, uint32_t *ctx_id);
137 
138 #ifdef __cplusplus
139 }
140 #endif
141 
142 #endif /* INTEL_AUB_WRITE */
143