nomali.h revision 10915:71ace17ccb3d
111832SChristian.Menard@tu-dresden.de/* 211832SChristian.Menard@tu-dresden.de * Copyright (c) 2014-2015 ARM Limited 311832SChristian.Menard@tu-dresden.de * All rights reserved 411832SChristian.Menard@tu-dresden.de * 511832SChristian.Menard@tu-dresden.de * Licensed under the Apache License, Version 2.0 (the "License"); 610993Sjungma@eit.uni-kl.de * you may not use this file except in compliance with the License. 710993Sjungma@eit.uni-kl.de * You may obtain a copy of the License at 811832SChristian.Menard@tu-dresden.de * 911832SChristian.Menard@tu-dresden.de * http://www.apache.org/licenses/LICENSE-2.0 1011832SChristian.Menard@tu-dresden.de * 1111832SChristian.Menard@tu-dresden.de * Unless required by applicable law or agreed to in writing, software 1211832SChristian.Menard@tu-dresden.de * distributed under the License is distributed on an "AS IS" BASIS, 1311832SChristian.Menard@tu-dresden.de * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1411832SChristian.Menard@tu-dresden.de * See the License for the specific language governing permissions and 1511832SChristian.Menard@tu-dresden.de * limitations under the License. 1611832SChristian.Menard@tu-dresden.de * 1711832SChristian.Menard@tu-dresden.de * Authors: Andreas Sandberg 1811832SChristian.Menard@tu-dresden.de */ 1911832SChristian.Menard@tu-dresden.de 2011832SChristian.Menard@tu-dresden.de#ifndef _LIBNOMALI_NOMALI_HH 2111832SChristian.Menard@tu-dresden.de#define _LIBNOMALI_NOMALI_HH 2211832SChristian.Menard@tu-dresden.de 2311832SChristian.Menard@tu-dresden.de#include <stdint.h> 2411832SChristian.Menard@tu-dresden.de 2511832SChristian.Menard@tu-dresden.de#ifdef __cplusplus 2611832SChristian.Menard@tu-dresden.deextern "C" { 2711832SChristian.Menard@tu-dresden.de#endif 2811832SChristian.Menard@tu-dresden.de 2911832SChristian.Menard@tu-dresden.de/** 3011832SChristian.Menard@tu-dresden.de * @file libnomali/nomali.h 3111832SChristian.Menard@tu-dresden.de * @short This header defines the NoMali stub GPU model interface. 3211971Szulian@eit.uni-kl.de * 3311832SChristian.Menard@tu-dresden.de */ 3411832SChristian.Menard@tu-dresden.de 3511971Szulian@eit.uni-kl.de/** Opaque NoMali model handle. */ 3611971Szulian@eit.uni-kl.detypedef void* nomali_handle_t; 3711832SChristian.Menard@tu-dresden.de 3811832SChristian.Menard@tu-dresden.de/** 3911832SChristian.Menard@tu-dresden.de * NoMali error codes. 4011832SChristian.Menard@tu-dresden.de */ 4111832SChristian.Menard@tu-dresden.deenum { 4211832SChristian.Menard@tu-dresden.de /** No error */ 4311832SChristian.Menard@tu-dresden.de NOMALI_E_OK = 0, 4411832SChristian.Menard@tu-dresden.de /** Unknown error */ 4511832SChristian.Menard@tu-dresden.de NOMALI_E_UNKNOWN, 4611832SChristian.Menard@tu-dresden.de /** Memory allocation failed */ 4711832SChristian.Menard@tu-dresden.de NOMALI_E_MEMORY, 4811832SChristian.Menard@tu-dresden.de /** Invalid model handle */ 4911832SChristian.Menard@tu-dresden.de NOMALI_E_HANDLE, 5011832SChristian.Menard@tu-dresden.de /** Invalid parameter */ 5111832SChristian.Menard@tu-dresden.de NOMALI_E_INVALID, 5212047Schristian.menard@tu-dresden.de 5312047Schristian.menard@tu-dresden.de /** 5412047Schristian.menard@tu-dresden.de * Number of errors defined 5512047Schristian.menard@tu-dresden.de * 5612047Schristian.menard@tu-dresden.de * @note This error, and higher error numbers, can be issued if 5712047Schristian.menard@tu-dresden.de * the library is newer than the header file. Software should 5812047Schristian.menard@tu-dresden.de * tread this condition as an unknown error. 5912047Schristian.menard@tu-dresden.de */ 6011832SChristian.Menard@tu-dresden.de NOMALI_E_NUM_ERRORS 6112047Schristian.menard@tu-dresden.de}; 6212047Schristian.menard@tu-dresden.detypedef int nomali_error_t; 6311832SChristian.Menard@tu-dresden.de 6412047Schristian.menard@tu-dresden.deenum { 6512047Schristian.menard@tu-dresden.de NOMALI_GPU_T60X = 0, 6611832SChristian.Menard@tu-dresden.de NOMALI_GPU_T62X, 6712047Schristian.menard@tu-dresden.de NOMALI_GPU_T76X, 6812047Schristian.menard@tu-dresden.de 6911832SChristian.Menard@tu-dresden.de NOMALI_GPU_T760 = NOMALI_GPU_T76X, 7012047Schristian.menard@tu-dresden.de}; 7112047Schristian.menard@tu-dresden.detypedef int nomali_gpu_type_t; 7212047Schristian.menard@tu-dresden.de 7312047Schristian.menard@tu-dresden.detypedef struct { 7412047Schristian.menard@tu-dresden.de nomali_gpu_type_t type; 7512047Schristian.menard@tu-dresden.de 7612047Schristian.menard@tu-dresden.de unsigned ver_maj; 7712047Schristian.menard@tu-dresden.de unsigned ver_min; 7810993Sjungma@eit.uni-kl.de unsigned ver_status; 7910993Sjungma@eit.uni-kl.de} nomali_config_t; 8010993Sjungma@eit.uni-kl.de 8110993Sjungma@eit.uni-kl.deenum { 8210993Sjungma@eit.uni-kl.de /** Model is signalling an interrupt */ 8310993Sjungma@eit.uni-kl.de NOMALI_CALLBACK_INT = 0, 8410993Sjungma@eit.uni-kl.de /** Model read physical memory callback */ 8510993Sjungma@eit.uni-kl.de NOMALI_CALLBACK_MEMREAD, 8610993Sjungma@eit.uni-kl.de /** Model write physical memory callback */ 8711832SChristian.Menard@tu-dresden.de NOMALI_CALLBACK_MEMWRITE, 8811832SChristian.Menard@tu-dresden.de 8910993Sjungma@eit.uni-kl.de /** Number of defined callbacks */ 9010993Sjungma@eit.uni-kl.de NOMALI_CALLBACK_NUM_CALLBACKS 9110993Sjungma@eit.uni-kl.de}; 9210993Sjungma@eit.uni-kl.detypedef int nomali_callback_type_t; 9310993Sjungma@eit.uni-kl.de 9410993Sjungma@eit.uni-kl.deenum { 9510993Sjungma@eit.uni-kl.de NOMALI_INT_GPU = 0, 9611832SChristian.Menard@tu-dresden.de NOMALI_INT_JOB, 9711832SChristian.Menard@tu-dresden.de NOMALI_INT_MMU, 9811099Sabdul.mutaal@gmail.com}; 9910993Sjungma@eit.uni-kl.detypedef int nomali_int_t; 10011791Sjungma@eit.uni-kl.de 10111832SChristian.Menard@tu-dresden.detypedef uint64_t nomali_addr_t; 10211832SChristian.Menard@tu-dresden.detypedef uint64_t nomali_size_t; 10311791Sjungma@eit.uni-kl.de 10412047Schristian.menard@tu-dresden.de/** 10510993Sjungma@eit.uni-kl.de * Callback information structure. 10611832SChristian.Menard@tu-dresden.de */ 10711791Sjungma@eit.uni-kl.detypedef struct { 10810993Sjungma@eit.uni-kl.de /** Callback type */ 10911832SChristian.Menard@tu-dresden.de nomali_callback_type_t type; 11011832SChristian.Menard@tu-dresden.de /** Pointer to user-defined data associated with callback */ 11110993Sjungma@eit.uni-kl.de void *usr; 11211832SChristian.Menard@tu-dresden.de /** Pointer to callback function */ 11311832SChristian.Menard@tu-dresden.de union { 11411832SChristian.Menard@tu-dresden.de /** 11510993Sjungma@eit.uni-kl.de * Interrupt state change 11612047Schristian.menard@tu-dresden.de * 11711832SChristian.Menard@tu-dresden.de * @param h Model instance handle. 11811832SChristian.Menard@tu-dresden.de * @param usr User-defined data associated with callback. 11910993Sjungma@eit.uni-kl.de * @param intno Interrupt number. 12010993Sjungma@eit.uni-kl.de * @param set Non-zero if raising an interrupt, zero if clearing. 12112047Schristian.menard@tu-dresden.de */ 12212047Schristian.menard@tu-dresden.de void (*interrupt)(nomali_handle_t h, void *usr, 12312047Schristian.menard@tu-dresden.de nomali_int_t intno, int set); 12410993Sjungma@eit.uni-kl.de void (*memwrite)(nomali_handle_t h, void *usr, 12510993Sjungma@eit.uni-kl.de nomali_addr_t addr, uint32_t value); 12610993Sjungma@eit.uni-kl.de uint32_t (*memread)(nomali_handle_t h, void *usr, 12712047Schristian.menard@tu-dresden.de nomali_addr_t addr); 12810993Sjungma@eit.uni-kl.de } func; 12910993Sjungma@eit.uni-kl.de} nomali_callback_t; 13010993Sjungma@eit.uni-kl.de 13111832SChristian.Menard@tu-dresden.de/** 13210993Sjungma@eit.uni-kl.de * GPU information struct. See nomali_get_info(). 13312047Schristian.menard@tu-dresden.de */ 13410993Sjungma@eit.uni-kl.detypedef struct { 13511832SChristian.Menard@tu-dresden.de /** Size (in bytes) of the register window used by the GPU */ 13611832SChristian.Menard@tu-dresden.de nomali_size_t reg_size; 13710993Sjungma@eit.uni-kl.de} nomali_info_t; 13810993Sjungma@eit.uni-kl.de 13911832SChristian.Menard@tu-dresden.detypedef uint32_t nomali_api_version_t; 14011832SChristian.Menard@tu-dresden.de 14111832SChristian.Menard@tu-dresden.de/** 14211832SChristian.Menard@tu-dresden.de * Current version of the NoMali API 14310993Sjungma@eit.uni-kl.de * 14410993Sjungma@eit.uni-kl.de * This version number will increase whenever the API changes. 14512047Schristian.menard@tu-dresden.de * 14612047Schristian.menard@tu-dresden.de * @see nomali_api_version() 14711832SChristian.Menard@tu-dresden.de */ 14811832SChristian.Menard@tu-dresden.de#define NOMALI_API_VERSION 0 14911832SChristian.Menard@tu-dresden.de 15011832SChristian.Menard@tu-dresden.de/** 15110993Sjungma@eit.uni-kl.de * Get the version of the API implemented by the library. 15210993Sjungma@eit.uni-kl.de * 15311832SChristian.Menard@tu-dresden.de * Before instantiating a NoMali model, the driving application need 15410993Sjungma@eit.uni-kl.de * to ensure that the library implements a compatible version of the 15510993Sjungma@eit.uni-kl.de * NoMali API. This is done by calling this function and matching the 15612047Schristian.menard@tu-dresden.de * return value with the NOMALI_API_VERSION define. The result of any 15712047Schristian.menard@tu-dresden.de * call to the NoMali library is undefined if there is a miss-match 15810993Sjungma@eit.uni-kl.de * between the two. 15910993Sjungma@eit.uni-kl.de */ 16010993Sjungma@eit.uni-kl.denomali_api_version_t nomali_api_version(); 16112047Schristian.menard@tu-dresden.de 16210993Sjungma@eit.uni-kl.de/** 16310993Sjungma@eit.uni-kl.de * Create an instance of the NoMali model. 16410993Sjungma@eit.uni-kl.de * 16510993Sjungma@eit.uni-kl.de * @param[out] h Handle of the new NoMali model instance, undefined on 16612047Schristian.menard@tu-dresden.de * error. 16711554Sjungma@eit.uni-kl.de * 16811554Sjungma@eit.uni-kl.de * @param[in] cfg NoMali GPU configuration. 16911832SChristian.Menard@tu-dresden.de * 17011554Sjungma@eit.uni-kl.de * @errors 17111554Sjungma@eit.uni-kl.de * @error NOMALI_E_OK on success. 17211554Sjungma@eit.uni-kl.de * @error NOMALI_E_MEMORY if a memory allocation failed. 17311554Sjungma@eit.uni-kl.de * @error NOMALI_E_INVALID if a pointer to an output parameter is 17411554Sjungma@eit.uni-kl.de * invalid. 17511554Sjungma@eit.uni-kl.de */ 17611554Sjungma@eit.uni-kl.denomali_error_t nomali_create(nomali_handle_t *h, const nomali_config_t *cfg); 17711554Sjungma@eit.uni-kl.de/** 17811554Sjungma@eit.uni-kl.de * Destroy and free resources used by an existing NoMali instance. 17911554Sjungma@eit.uni-kl.de * 18011554Sjungma@eit.uni-kl.de * @param[in] h Model instance handle. 18111554Sjungma@eit.uni-kl.de * 18211554Sjungma@eit.uni-kl.de * @errors 18312047Schristian.menard@tu-dresden.de * @error NOMALI_E_OK on success. 18411554Sjungma@eit.uni-kl.de * @error NOMALI_E_HANDLE if the handle was invalid. 18512047Schristian.menard@tu-dresden.de */ 18611554Sjungma@eit.uni-kl.denomali_error_t nomali_destroy(nomali_handle_t h); 18711554Sjungma@eit.uni-kl.de 18811554Sjungma@eit.uni-kl.de 18912047Schristian.menard@tu-dresden.de/** 19011832SChristian.Menard@tu-dresden.de * Get a textual description of an error number. 19111832SChristian.Menard@tu-dresden.de * 19211832SChristian.Menard@tu-dresden.de * @param[in] error Error number to resolve. 19311832SChristian.Menard@tu-dresden.de * 19411832SChristian.Menard@tu-dresden.de * @return Pointer to a constant, null-terminated, string describing 19511832SChristian.Menard@tu-dresden.de * an error number. 19611832SChristian.Menard@tu-dresden.de */ 19711832SChristian.Menard@tu-dresden.deconst char *nomali_errstr(nomali_error_t error); 19812047Schristian.menard@tu-dresden.de 19912047Schristian.menard@tu-dresden.de/** 20012047Schristian.menard@tu-dresden.de * Setup callbacks from the model. 201 * 202 * @param[in] h Model instance handle. 203 * @param[in] callback Structure describing the new callback to be 204 * installed. 205 * 206 * @errors 207 * @error NOMALI_E_OK on success. 208 * @error NOMALI_E_HANDLE if the handle was invalid. 209 * @error NOMALI_E_INVALID if the callback type was invalid. 210 * 211 * @see nomali_callback_t 212 */ 213nomali_error_t nomali_set_callback(nomali_handle_t h, 214 const nomali_callback_t *callback); 215 216/** 217 * Get information about the hardware simulated by the model. 218 * 219 * @param[in] h Model instance handle. 220 * @param[out] info Structure describing the model. 221 * 222 * @errors 223 * @error NOMALI_E_OK on success. 224 * @error NOMALI_E_HANDLE if the handle was invalid. 225 * @error NOMALI_E_INVALID if info is not pointing to a valid 226 * location. 227 * 228 * @see nomali_info_t 229 */ 230nomali_error_t nomali_get_info(nomali_handle_t h, 231 nomali_info_t *info); 232 233/** 234 * Perform a reset of the device. 235 * 236 * @param[in] h Model instance handle. 237 * 238 * @errors 239 * @error NOMALI_E_OK on success. 240 * @error NOMALI_E_HANDLE if the handle was invalid. 241 */ 242nomali_error_t nomali_reset(nomali_handle_t h); 243 244/** 245 * Read a register within the device. 246 * 247 * @param[in] h Model instance handle. 248 * @param[out] value Pointer to output. 249 * @param[in] addr Address to read. 250 * 251 * @errors 252 * @error NOMALI_E_OK on success. 253 * @error NOMALI_E_HANDLE if the handle was invalid. 254 * @error NOMALI_E_INVALID if an invalid register was specified or if the 255 * pointer to the output location was invalid. 256 */ 257nomali_error_t nomali_reg_read(nomali_handle_t h, uint32_t *value, 258 nomali_addr_t addr); 259 260/** 261 * Write to a register within the device. 262 * 263 * @param[in] h Model instance handle. 264 * @param[in] addr Address to read. 265 * @param[in] value Value to write to the register. 266 * 267 * @errors 268 * @error NOMALI_E_OK on success. 269 * @error NOMALI_E_HANDLE if the handle was invalid. 270 * @error NOMALI_E_INVALID if an invalid register was specified. 271 */ 272nomali_error_t nomali_reg_write(nomali_handle_t h, 273 nomali_addr_t addr, uint32_t value); 274 275/** 276 * Read a register without side effects. 277 * 278 * @param[in] h Model instance handle. 279 * @param[out] value Pointer to output. 280 * @param[in] addr Address to read. 281 * 282 * @errors 283 * @error NOMALI_E_OK on success. 284 * @error NOMALI_E_HANDLE if the handle was invalid. 285 * @error NOMALI_E_INVALID if an invalid register was specified or if the 286 * pointer to the output location was invalid. 287 */ 288nomali_error_t nomali_reg_read_raw(nomali_handle_t h, uint32_t *value, 289 nomali_addr_t addr); 290 291/** 292 * Write to a register without side effects. 293 * 294 * @param[in] h Model instance handle. 295 * @param[in] addr Address to read. 296 * @param[in] value Value to write to the register. 297 * 298 * @errors 299 * @error NOMALI_E_OK on success. 300 * @error NOMALI_E_HANDLE if the handle was invalid. 301 * @error NOMALI_E_INVALID if an invalid register was specified. 302 */ 303nomali_error_t nomali_reg_write_raw(nomali_handle_t h, 304 nomali_addr_t addr, uint32_t value); 305 306/** 307 * Get the state of an interrupt line 308 * 309 * This function queries the state of one of the GPU's interrupt 310 * lines. The state of the interrupt line is returned in 'state', 311 * which is 1 if the interrupt is being asserted and 0 otherwise. The 312 * value of the state variable is undefined if the function call 313 * fails. 314 * 315 * @param[in] h Model instance handle. 316 * @param[out] state Pointer to output, 1 if the interrupt is 317 * asserted, 0 otherwise. 318 * @param[in] intno Interrupt to query. 319 * 320 * @errors 321 * @error NOMALI_E_OK on success. 322 * @error NOMALI_E_HANDLE if the handle was invalid. 323 * @error NOMALI_E_INVALID if an invalid interrupt was specified or if 324 * pointer to the output location was invalid. 325 */ 326nomali_error_t nomali_int_state(nomali_handle_t h, int *state, 327 nomali_int_t intno); 328 329#ifdef __cplusplus 330}; 331#endif 332 333#endif /* _LIBNOMALI_NOMALI_HH */ 334