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