summaryrefslogtreecommitdiff
path: root/arch/arm/mach-tegra/nv/include/nvrm_moduleloader.h
blob: 6214a1ac141315e1e3276b12a70003b1f24259f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
 * arch/arm/mach-tegra/include/nvrm_moduleloader.h
 *
 *
 *
 * Copyright (c) 2010, NVIDIA Corporation.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#ifndef INCLUDED_nvrm_moduleloader_H
#define INCLUDED_nvrm_moduleloader_H


#if defined(__cplusplus)
extern "C"
{
#endif

#include "nvrm_init.h"

#include "nvcommon.h"
#include "nvos.h"

/**
 * NvRmLibraryHandle is an opaque handle to the Module Loader interface
 *
 * @ingroup nvrm_moduleloader
 */

typedef struct NvRmLibraryRec *NvRmLibraryHandle;

/**
 * @brief Defines the pin state
 */

typedef enum
{
    NvRmModuleLoaderReason_Attach = 0,
    NvRmModuleLoaderReason_Detach,
    NvRmModuleLoaderReason_AttachGreedy,
    NvRmModuleLoaderReason_Num,
    NvRmModuleLoaderReason_Force32 = 0x7FFFFFFF
} NvRmModuleLoaderReason;

/**
 * Loads the segments of requested library name.
 * This method will parse the ELF dynamic library, relocate the address,
 * resolve the symbols and load the segments accordingly.
 * A successful load should return a valid handle.
 *
 * If some of the parameters passed are not valid assert
 * encountered in debug mode.
 *
 * @ingroup nvrm_moduleloader
 *
 * @param hDevice The handle to the RM device
 * @param pLibName The library to be loaded.
 * @param pArgs The arguments to be passed.
 * @param sizeOfArgs The size of arguments passed.
 * @param hLibHandle The handle to the loaded library
 *
 * @retval NvSuccess Load library operation completed successfully
 * @retval NvError_FileReadFailed Indicates that the fileoffset read failed
 * @retval NvError_LibraryNotFound Indicates the given library could not be found
 * @retval NvError_InsufficientMemory Indicates memory allocation failed
 * @retval NvError_InvalidElfFormat Indicates the ELF file is not valid
 */

 NvError NvRmLoadLibrary(
    NvRmDeviceHandle hDevice,
    const char * pLibName,
    void* pArgs,
    NvU32 sizeOfArgs,
    NvRmLibraryHandle * hLibHandle );

/**
 * Loads the segments of requested library name.This method will parse the ELF dynamic
 * library, relocate the address, resolve the symbols and load the segments depending
 * on the conservative or greedy approach. In both the approaches the the IRAM_MAND
 * sections are loaded in IRAM and DRAM_MAND sections are loaded in DRAM. In conservative
 * approach  the IRAM_PREF sections are always loaded in SDRAM. In greedy approach
 * the IRAM_PREF sections are first laoded in IRAM. If IRAM allocation fails for an IRAM_PREF
 * section, it would fallback to DRAM. A successful load should return a valid handle.
 *
 * IRAM_MAND_ADDR = 0x40000000
 * DRAM_MAND_ADDR = 0x10000000
 * Then
 *    If (vaddr < DRAM_MAND_ADDR)
 *       IRAM_PREF Section
 *   Else (vaddr >= IRAM_MAND_ADDR)
 *       IRAM_MAND Section
 *   Else
 *       DRAM_MAND Section
 *
 * If some of the parameters passed are not valid assert
 * encountered in debug mode.
 *
 * @ingroup nvrm_moduleloader
 *
 * @param hDevice The handle to the RM device
 * @param pLibName The library to be loaded.
 * @param pArgs The arguments to be passed.
 * @param sizeOfArgs The size of arguments passed.
 * @param IsApproachGreedy The approach used to load the segments.
 * @param hLibHandle The handle to the loaded library
 *
 * @retval NvSuccess Load library operation completed successfully
 * @retval NvError_FileReadFailed Indicates that the fileoffset read failed
 * @retval NvError_LibraryNotFound Indicates the given library could not be found
 * @retval NvError_InsufficientMemory Indicates memory allocation failed
 * @retval NvError_InvalidElfFormat Indicates the ELF file is not valid
 */

 NvError NvRmLoadLibraryEx(
    NvRmDeviceHandle hDevice,
    const char * pLibName,
    void* pArgs,
    NvU32 sizeOfArgs,
    NvBool IsApproachGreedy,
    NvRmLibraryHandle * hLibHandle );

/**
 * Get symbol address for a given symbol name and handle.
 *
 * Client will request for symbol address for a export function by
 * sending down the symbol name and handle to the loaded library.
 *
 * Assert encountered if some of the parameters passed are not valid
 *
 * NOTE: This function is currently only used to obtain the entry
 * point address (ie, the address of "main"). It should be noted
 * that the entry point must ALWAYS be in THUMB mode! Using ARM
 * mode will cause the module to crash.
 *
 * @ingroup nvrm_moduleloader
 *
 * @param hLibHandle Library handle which is returned by NvRmLoadLibrary().
 * @param pSymbolName pointer to a symbol name to be looked up
 * @param pSymAddress pointer to a symbol address
 *
 * @retval NvSuccess Symbol address is obtained successfully.
 * @retval NvError_SymbolNotFound Indicates the symbol requested is not found
 */

 NvError NvRmGetProcAddress(
    NvRmLibraryHandle hLibHandle,
    const char * pSymbolName,
    void* * pSymAddress );

/**
 * Free the losded memory of the corresponding library handle.
 *
 * This API will use the handle to get the base loaded address and free the memory
 *
 * @param hLibHandle The handle which is returned by NvRmLoadLibrary().
 *
 * @retval NvSuccess Successfuly unloaded the library memory.
 */

 NvError NvRmFreeLibrary(
    NvRmLibraryHandle hLibHandle );

#if defined(__cplusplus)
}
#endif

#endif