nomali_test_ints.c revision 10915:71ace17ccb3d
1/* 2 * Copyright (c) 2014-2015 ARM Limited 3 * All rights reserved 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 * Authors: Andreas Sandberg 18 */ 19 20#include <libnomali/nomali.h> 21#include <inttypes.h> 22 23#include "nomali_test_helpers.h" 24#include "../lib/mali_midg_regmap.h" 25 26static void 27on_int(nomali_handle_t h, void *usr, nomali_int_t intno, int set) 28{ 29 test_diag("on_int: intno: %i, set: %i", intno, set); 30 *(int*)usr = !!set; 31} 32 33static void 34test_gpu_int(nomali_handle_t h) 35{ 36 nomali_error_t error = NOMALI_E_OK; 37 int int_triggered = 0; 38 nomali_callback_t int_callback = { 39 .type = NOMALI_CALLBACK_INT, 40 .usr = &int_triggered, 41 .func.interrupt = on_int, 42 }; 43 44 nomali_callback_t int_null_callback = { 45 .type = NOMALI_CALLBACK_INT, 46 .usr = NULL, 47 .func.interrupt = NULL, 48 }; 49 50 /* 51 * Raise an interrupt without callbacks 52 */ 53 E_NOMALI_BAIL(nomali_reg_write(h, 54 GPU_CONTROL_REG(GPU_IRQ_CLEAR), 55 GPU_IRQ_REG_ALL)); 56 57 E_NOMALI_BAIL(nomali_reg_write(h, GPU_CONTROL_REG(GPU_IRQ_MASK), 58 GPU_FAULT)); 59 60 E_NOMALI_BAIL(nomali_reg_write(h, GPU_CONTROL_REG(GPU_IRQ_RAWSTAT), 61 GPU_FAULT)); 62 63 E_NOMALI_BAIL(nomali_reg_write(h, 64 GPU_CONTROL_REG(GPU_IRQ_CLEAR), 65 GPU_IRQ_REG_ALL)); 66 67 /* 68 * Register callbacks and raise interrupt again. 69 */ 70 E_NOMALI_BAIL(nomali_set_callback(h, &int_callback)); 71 if (int_triggered != 0) { 72 test_diag("Got spurious interrupt\n"); 73 test_fail("gpu_int"); 74 } 75 76 E_NOMALI_BAIL(nomali_reg_write(h, GPU_CONTROL_REG(GPU_IRQ_RAWSTAT), 77 GPU_FAULT)); 78 if (int_triggered == 1) { 79 test_ok("gpu_int"); 80 } else { 81 test_fail("gpu_int"); 82 } 83 int_triggered = 0; 84 85 86 /* 87 * Register mask interrupts and raise interrupt again. 88 */ 89 E_NOMALI_BAIL(nomali_reg_write(h, 90 GPU_CONTROL_REG(GPU_IRQ_CLEAR), 91 GPU_IRQ_REG_ALL)); 92 E_NOMALI_BAIL(nomali_reg_write(h, GPU_CONTROL_REG(GPU_IRQ_MASK), 93 0)); 94 E_NOMALI_BAIL(nomali_reg_write(h, GPU_CONTROL_REG(GPU_IRQ_RAWSTAT), 95 GPU_FAULT)); 96 if (int_triggered == 0) { 97 test_ok("gpu_int_masked"); 98 } else { 99 test_fail("gpu_int_maked"); 100 } 101 E_NOMALI_BAIL(nomali_reg_write(h, 102 GPU_CONTROL_REG(GPU_IRQ_CLEAR), 103 GPU_IRQ_REG_ALL)); 104 E_NOMALI_BAIL(nomali_set_callback(h, &int_null_callback)); 105} 106 107int 108main(int argc, char **argv) 109{ 110 const nomali_config_t cfg = { 111 .type = NOMALI_GPU_T60X, 112 .ver_maj = 0, 113 .ver_min = 1, 114 .ver_status = 0, 115 }; 116 117 nomali_handle_t h; 118 nomali_error_t error = NOMALI_E_OK; 119 120 E_NOMALI_BAIL(nomali_create(&h, &cfg)); 121 122 test_gpu_int(h); 123 124 E_NOMALI_BAIL(nomali_destroy(h)); 125 126 return 0; 127} 128