/*1* Copyright 2014-2019 Advanced Micro Devices, Inc.2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,19* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE20* SOFTWARE.21*/2223#ifndef AC_RTLD_H24#define AC_RTLD_H2526#include "compiler/shader_enums.h"27#include "util/u_dynarray.h"2829#include <stdbool.h>30#include <stddef.h>31#include <stdint.h>3233#ifdef __cplusplus34extern "C" {35#endif3637struct ac_rtld_part;38struct ac_shader_config;39struct radeon_info;4041struct ac_rtld_symbol {42const char *name;43uint32_t size;44uint32_t align;45uint64_t offset; /* filled in by ac_rtld_open */46unsigned part_idx; /* shader part in which this symbol appears */47};4849struct ac_rtld_options {50/* Loader will insert an s_sethalt 1 instruction as the51* first instruction. */52bool halt_at_entry : 1;53};5455/* Lightweight wrapper around underlying ELF objects. */56struct ac_rtld_binary {57struct ac_rtld_options options;58unsigned wave_size;5960/* Required buffer sizes, currently read/executable only. */61uint64_t rx_size;6263/* Size of executable code, for reporting purposes. */64uint64_t exec_size;6566uint64_t rx_end_markers;6768unsigned num_parts;69struct ac_rtld_part *parts;7071struct util_dynarray lds_symbols;72uint32_t lds_size;73};7475/**76* Callback function type used during upload to resolve external symbols that77* are not defined in any of the ELF binaries available to the linker.78*79* \param cb_data caller-defined data80* \param symbol NUL-terminated symbol name81* \param value to be filled in by the callback82* \return whether the symbol was found successfully83*/84typedef bool (*ac_rtld_get_external_symbol_cb)(void *cb_data, const char *symbol, uint64_t *value);8586/**87* Lifetimes of \ref info, in-memory ELF objects, and the names of88* \ref shared_lds_symbols must extend until \ref ac_rtld_close is called on89* the opened binary.90*/91struct ac_rtld_open_info {92const struct radeon_info *info;93struct ac_rtld_options options;94gl_shader_stage shader_type;95unsigned wave_size;9697unsigned num_parts;98const char *const *elf_ptrs; /* in-memory ELF objects of each part */99const size_t *elf_sizes; /* sizes of corresponding in-memory ELF objects in bytes */100101/* Shared LDS symbols are layouted such that they are accessible from102* all shader parts. Non-shared (private) LDS symbols of one part may103* overlap private LDS symbols of another shader part.104*/105unsigned num_shared_lds_symbols;106const struct ac_rtld_symbol *shared_lds_symbols;107};108109bool ac_rtld_open(struct ac_rtld_binary *binary, struct ac_rtld_open_info i);110111void ac_rtld_close(struct ac_rtld_binary *binary);112113bool ac_rtld_get_section_by_name(struct ac_rtld_binary *binary, const char *name, const char **data,114size_t *nbytes);115116bool ac_rtld_read_config(const struct radeon_info *info, struct ac_rtld_binary *binary,117struct ac_shader_config *config);118119struct ac_rtld_upload_info {120struct ac_rtld_binary *binary;121122/** GPU mapping of the read/executable buffer. */123uint64_t rx_va;124125/** CPU mapping of the read/executable buffer */126char *rx_ptr;127128/** Optional callback function that will be queried for symbols not129* defined in any of the binary's parts. */130ac_rtld_get_external_symbol_cb get_external_symbol;131132/** Caller-defined data that will be passed to callback functions. */133void *cb_data;134};135136int ac_rtld_upload(struct ac_rtld_upload_info *u);137138#ifdef __cplusplus139}140#endif141142#endif /* AC_RTLD_H */143144145