summaryrefslogtreecommitdiff
path: root/ext/nomali/include/libnomali/nomali.h
blob: 9af2a417a1d9c87528c639d64c0ac988724fcba3 (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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
/*
 * Copyright (c) 2014-2015 ARM Limited
 * All rights reserved
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Authors: Andreas Sandberg
 */

#ifndef _LIBNOMALI_NOMALI_HH
#define _LIBNOMALI_NOMALI_HH

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
 * @file libnomali/nomali.h
 * @short This header defines the NoMali stub GPU model interface.
 *
 */

/** Opaque NoMali model handle. */
typedef void* nomali_handle_t;

/**
 * NoMali error codes.
 */
enum {
    /** No error */
    NOMALI_E_OK = 0,
    /** Unknown error */
    NOMALI_E_UNKNOWN,
    /** Memory allocation failed */
    NOMALI_E_MEMORY,
    /** Invalid model handle */
    NOMALI_E_HANDLE,
    /** Invalid parameter */
    NOMALI_E_INVALID,

    /**
     * Number of errors defined
     *
     * @note This error, and higher error numbers, can be issued if
     * the library is newer than the header file. Software should
     * tread this condition as an unknown error.
     */
    NOMALI_E_NUM_ERRORS
};
typedef int nomali_error_t;

enum {
    NOMALI_GPU_T60X = 0,
    NOMALI_GPU_T62X,
    NOMALI_GPU_T76X,

    NOMALI_GPU_T760 = NOMALI_GPU_T76X,
};
typedef int nomali_gpu_type_t;

typedef struct {
    nomali_gpu_type_t type;

    unsigned ver_maj;
    unsigned ver_min;
    unsigned ver_status;
} nomali_config_t;

enum {
    /** Model is signalling an interrupt */
    NOMALI_CALLBACK_INT = 0,
    /** Model read physical memory callback */
    NOMALI_CALLBACK_MEMREAD,
    /** Model write physical memory callback */
    NOMALI_CALLBACK_MEMWRITE,

    /** Number of defined callbacks */
    NOMALI_CALLBACK_NUM_CALLBACKS
};
typedef int nomali_callback_type_t;

enum {
    NOMALI_INT_GPU = 0,
    NOMALI_INT_JOB,
    NOMALI_INT_MMU,
};
typedef int nomali_int_t;

typedef uint64_t nomali_addr_t;
typedef uint64_t nomali_size_t;

/**
 * Callback information structure.
 */
typedef struct {
    /** Callback type */
    nomali_callback_type_t type;
    /** Pointer to user-defined data associated with callback */
    void *usr;
    /** Pointer to callback function */
    union {
        /**
         * Interrupt state change
         *
         * @param h Model instance handle.
         * @param usr User-defined data associated with callback.
         * @param intno Interrupt number.
         * @param set Non-zero if raising an interrupt, zero if clearing.
         */
        void (*interrupt)(nomali_handle_t h, void *usr,
                          nomali_int_t intno, int set);
        void (*memwrite)(nomali_handle_t h, void *usr,
                         nomali_addr_t addr, uint32_t value);
        uint32_t (*memread)(nomali_handle_t h, void *usr,
                            nomali_addr_t addr);
    } func;
} nomali_callback_t;

/**
 * GPU information struct. See nomali_get_info().
 */
typedef struct {
    /** Size (in bytes) of the register window used by the GPU */
    nomali_size_t reg_size;
} nomali_info_t;

typedef uint32_t nomali_api_version_t;

/**
 * Current version of the NoMali API
 *
 * This version number will increase whenever the API changes.
 *
 * @see nomali_api_version()
 */
#define NOMALI_API_VERSION 0

/**
 * Get the version of the API implemented by the library.
 *
 * Before instantiating a NoMali model, the driving application need
 * to ensure that the library implements a compatible version of the
 * NoMali API. This is done by calling this function and matching the
 * return value with the NOMALI_API_VERSION define. The result of any
 * call to the NoMali library is undefined if there is a miss-match
 * between the two.
 */
nomali_api_version_t nomali_api_version();

/**
 * Create an instance of the NoMali model.
 *
 * @param[out] h Handle of the new NoMali model instance, undefined on
 *               error.
 *
 * @param[in] cfg NoMali GPU configuration.
 *
 * @errors
 * @error NOMALI_E_OK on success.
 * @error NOMALI_E_MEMORY if a memory allocation failed.
 * @error NOMALI_E_INVALID if a pointer to an output parameter is
 *                         invalid.
 */
nomali_error_t nomali_create(nomali_handle_t *h, const nomali_config_t *cfg);
/**
 * Destroy and free resources used by an existing NoMali instance.
 *
 * @param[in] h Model instance handle.
 *
 * @errors
 * @error NOMALI_E_OK on success.
 * @error NOMALI_E_HANDLE if the handle was invalid.
 */
nomali_error_t nomali_destroy(nomali_handle_t h);


/**
 * Get a textual description of an error number.
 *
 * @param[in] error Error number to resolve.
 *
 * @return Pointer to a constant, null-terminated, string describing
 * an error number.
 */
const char *nomali_errstr(nomali_error_t error);

/**
 * Setup callbacks from the model.
 *
 * @param[in] h        Model instance handle.
 * @param[in] callback Structure describing the new callback to be
 *                     installed.
 *
 * @errors
 * @error NOMALI_E_OK on success.
 * @error NOMALI_E_HANDLE if the handle was invalid.
 * @error NOMALI_E_INVALID if the callback type was invalid.
 *
 * @see nomali_callback_t
 */
nomali_error_t nomali_set_callback(nomali_handle_t h,
                                   const nomali_callback_t *callback);

/**
 * Get information about the hardware simulated by the model.
 *
 * @param[in]  h       Model instance handle.
 * @param[out] info    Structure describing the model.
 *
 * @errors
 * @error NOMALI_E_OK on success.
 * @error NOMALI_E_HANDLE if the handle was invalid.
 * @error NOMALI_E_INVALID if info is not pointing to a valid
 *                         location.
 *
 * @see nomali_info_t
 */
nomali_error_t nomali_get_info(nomali_handle_t h,
                               nomali_info_t *info);

/**
 * Perform a reset of the device.
 *
 * @param[in]  h     Model instance handle.
 *
 * @errors
 * @error NOMALI_E_OK on success.
 * @error NOMALI_E_HANDLE if the handle was invalid.
 */
nomali_error_t nomali_reset(nomali_handle_t h);

/**
 * Read a register within the device.
 *
 * @param[in]  h     Model instance handle.
 * @param[out] value Pointer to output.
 * @param[in]  addr  Address to read.
 *
 * @errors
 * @error NOMALI_E_OK on success.
 * @error NOMALI_E_HANDLE if the handle was invalid.
 * @error NOMALI_E_INVALID if an invalid register was specified or if the
 *                         pointer to the output location was invalid.
 */
nomali_error_t nomali_reg_read(nomali_handle_t h, uint32_t *value,
                               nomali_addr_t addr);

/**
 * Write to a register within the device.
 *
 * @param[in] h     Model instance handle.
 * @param[in] addr  Address to read.
 * @param[in] value Value to write to the register.
 *
 * @errors
 * @error NOMALI_E_OK on success.
 * @error NOMALI_E_HANDLE if the handle was invalid.
 * @error NOMALI_E_INVALID if an invalid register was specified.
 */
nomali_error_t nomali_reg_write(nomali_handle_t h,
                                nomali_addr_t addr, uint32_t value);

/**
 * Read a register without side effects.
 *
 * @param[in]  h     Model instance handle.
 * @param[out] value Pointer to output.
 * @param[in]  addr  Address to read.
 *
 * @errors
 * @error NOMALI_E_OK on success.
 * @error NOMALI_E_HANDLE if the handle was invalid.
 * @error NOMALI_E_INVALID if an invalid register was specified or if the
 *                         pointer to the output location was invalid.
 */
nomali_error_t nomali_reg_read_raw(nomali_handle_t h, uint32_t *value,
                                   nomali_addr_t addr);

/**
 * Write to a register without side effects.
 *
 * @param[in] h     Model instance handle.
 * @param[in] addr  Address to read.
 * @param[in] value Value to write to the register.
 *
 * @errors
 * @error NOMALI_E_OK on success.
 * @error NOMALI_E_HANDLE if the handle was invalid.
 * @error NOMALI_E_INVALID if an invalid register was specified.
 */
nomali_error_t nomali_reg_write_raw(nomali_handle_t h,
                                    nomali_addr_t addr, uint32_t value);

/**
 * Get the state of an interrupt line
 *
 * This function queries the state of one of the GPU's interrupt
 * lines. The state of the interrupt line is returned in 'state',
 * which is 1 if the interrupt is being asserted and 0 otherwise. The
 * value of the state variable is undefined if the function call
 * fails.
 *
 * @param[in]  h     Model instance handle.
 * @param[out] state Pointer to output, 1 if the interrupt is
 *                   asserted, 0 otherwise.
 * @param[in]  intno Interrupt to query.
 *
 * @errors
 * @error NOMALI_E_OK on success.
 * @error NOMALI_E_HANDLE if the handle was invalid.
 * @error NOMALI_E_INVALID if an invalid interrupt was specified or if
 *                         pointer to the output location was invalid.
 */
nomali_error_t nomali_int_state(nomali_handle_t h, int *state,
                                nomali_int_t intno);

#ifdef __cplusplus
};
#endif

#endif /* _LIBNOMALI_NOMALI_HH */