1 /* 2 * Copyright 2014-2019 Advanced Micro Devices, Inc. 3 * 4 * SPDX-License-Identifier: MIT 5 */ 6 7 #ifndef AC_RTLD_H 8 #define AC_RTLD_H 9 10 #include "compiler/shader_enums.h" 11 #include "util/u_dynarray.h" 12 #include "amd_family.h" 13 14 #include <stdbool.h> 15 #include <stddef.h> 16 #include <stdint.h> 17 18 #ifdef __cplusplus 19 extern "C" { 20 #endif 21 22 struct ac_rtld_part; 23 struct ac_shader_config; 24 struct radeon_info; 25 26 struct ac_rtld_symbol { 27 const char *name; 28 uint32_t size; 29 uint32_t align; 30 uint64_t offset; /* filled in by ac_rtld_open */ 31 unsigned part_idx; /* shader part in which this symbol appears */ 32 }; 33 34 struct ac_rtld_options { 35 /* Loader will insert an s_sethalt 1 instruction as the 36 * first instruction. */ 37 bool halt_at_entry : 1; 38 39 bool waitcnt_wa : 1; 40 }; 41 42 /* Lightweight wrapper around underlying ELF objects. */ 43 struct ac_rtld_binary { 44 struct ac_rtld_options options; 45 enum amd_gfx_level gfx_level; 46 unsigned wave_size; 47 48 /* Required buffer sizes, currently read/executable only. */ 49 uint64_t rx_size; 50 51 /* Size of executable code, for reporting purposes. */ 52 uint64_t exec_size; 53 54 uint64_t rx_end_markers; 55 56 unsigned num_parts; 57 struct ac_rtld_part *parts; 58 59 struct util_dynarray lds_symbols; 60 uint32_t lds_size; 61 }; 62 63 /** 64 * Callback function type used during upload to resolve external symbols that 65 * are not defined in any of the ELF binaries available to the linker. 66 * 67 * \param cb_data caller-defined data 68 * \param symbol NUL-terminated symbol name 69 * \param value to be filled in by the callback 70 * \return whether the symbol was found successfully 71 */ 72 typedef bool (*ac_rtld_get_external_symbol_cb)(enum amd_gfx_level gfx_level, void *cb_data, 73 const char *symbol, uint64_t *value); 74 75 /** 76 * Lifetimes of \ref info, in-memory ELF objects, and the names of 77 * \ref shared_lds_symbols must extend until \ref ac_rtld_close is called on 78 * the opened binary. 79 */ 80 struct ac_rtld_open_info { 81 const struct radeon_info *info; 82 struct ac_rtld_options options; 83 gl_shader_stage shader_type; 84 unsigned wave_size; 85 86 unsigned num_parts; 87 const char *const *elf_ptrs; /* in-memory ELF objects of each part */ 88 const size_t *elf_sizes; /* sizes of corresponding in-memory ELF objects in bytes */ 89 90 /* Shared LDS symbols are layouted such that they are accessible from 91 * all shader parts. Non-shared (private) LDS symbols of one part may 92 * overlap private LDS symbols of another shader part. 93 */ 94 unsigned num_shared_lds_symbols; 95 const struct ac_rtld_symbol *shared_lds_symbols; 96 }; 97 98 bool ac_rtld_open(struct ac_rtld_binary *binary, struct ac_rtld_open_info i); 99 100 void ac_rtld_close(struct ac_rtld_binary *binary); 101 102 bool ac_rtld_get_section_by_name(struct ac_rtld_binary *binary, const char *name, const char **data, 103 size_t *nbytes); 104 105 bool ac_rtld_read_config(const struct radeon_info *info, struct ac_rtld_binary *binary, 106 struct ac_shader_config *config); 107 108 struct ac_rtld_upload_info { 109 struct ac_rtld_binary *binary; 110 111 /** GPU mapping of the read/executable buffer. */ 112 uint64_t rx_va; 113 114 /** CPU mapping of the read/executable buffer */ 115 char *rx_ptr; 116 117 /** Optional callback function that will be queried for symbols not 118 * defined in any of the binary's parts. */ 119 ac_rtld_get_external_symbol_cb get_external_symbol; 120 121 /** Caller-defined data that will be passed to callback functions. */ 122 void *cb_data; 123 }; 124 125 int ac_rtld_upload(struct ac_rtld_upload_info *u); 126 127 #ifdef __cplusplus 128 } 129 #endif 130 131 #endif /* AC_RTLD_H */ 132