| 1 | // ========== Copyright Header Begin ========================================== |
| 2 | // |
| 3 | // OpenSPARC T2 Processor File: niu_intr_test_util.vr |
| 4 | // Copyright (C) 1995-2007 Sun Microsystems, Inc. All Rights Reserved |
| 5 | // 4150 Network Circle, Santa Clara, California 95054, U.S.A. |
| 6 | // |
| 7 | // * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 8 | // |
| 9 | // This program is free software; you can redistribute it and/or modify |
| 10 | // it under the terms of the GNU General Public License as published by |
| 11 | // the Free Software Foundation; version 2 of the License. |
| 12 | // |
| 13 | // This program is distributed in the hope that it will be useful, |
| 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | // GNU General Public License for more details. |
| 17 | // |
| 18 | // You should have received a copy of the GNU General Public License |
| 19 | // along with this program; if not, write to the Free Software |
| 20 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 | // |
| 22 | // For the avoidance of doubt, and except that if any non-GPL license |
| 23 | // choice is available it will apply instead, Sun elects to use only |
| 24 | // the General Public License version 2 (GPLv2) at this time for any |
| 25 | // software where a choice of GPL license versions is made |
| 26 | // available with the language indicating that GPLv2 or any later version |
| 27 | // may be used, or where a choice of which version of the GPL is applied is |
| 28 | // otherwise unspecified. |
| 29 | // |
| 30 | // Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 31 | // CA 95054 USA or visit www.sun.com if you need additional information or |
| 32 | // have any questions. |
| 33 | // |
| 34 | // ========== Copyright Header End ============================================ |
| 35 | #include "niu_int_mgr.vrh" |
| 36 | #include "niu_int_dev.vrh" |
| 37 | extern CNiuIntrMgr NiuIntrMgr; |
| 38 | |
| 39 | |
| 40 | |
| 41 | class sid_table { |
| 42 | |
| 43 | bit [68:0] dev_bound; |
| 44 | bit [6:0] sid_num; |
| 45 | integer ldgno_bound; |
| 46 | |
| 47 | task new() { |
| 48 | dev_bound = 69'h0; |
| 49 | sid_num = 7'h0; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | |
| 54 | class intr_test_util { |
| 55 | |
| 56 | integer intr_grpnum; |
| 57 | integer cmdl_grpnum; |
| 58 | |
| 59 | sid_table sid_tab[64]; |
| 60 | // CNiuIntrMgr NiuIntrMgr; |
| 61 | |
| 62 | task new(); |
| 63 | |
| 64 | task setup_sid_tab(CNiuIntrDev dev,integer ldgno,integer type); |
| 65 | task programme_intmgr(CNiuIntrDev dev,integer ldgno, integer type, integer func_num); |
| 66 | task compute_sid(integer func_num, var bit [6:0] sid); |
| 67 | |
| 68 | |
| 69 | } |
| 70 | |
| 71 | task intr_test_util :: new() { |
| 72 | |
| 73 | integer i = 0; |
| 74 | |
| 75 | for(i = 0;i <64; i++) { |
| 76 | sid_tab[i] = new(); |
| 77 | } |
| 78 | |
| 79 | if (get_plus_arg (CHECK,"INTR_GRPNUM=")) |
| 80 | intr_grpnum = get_plus_arg(NUM,"INTR_GRPNUM="); |
| 81 | else |
| 82 | intr_grpnum = 0; |
| 83 | |
| 84 | if (get_plus_arg (CHECK,"CMDL_GRPNUM=")) |
| 85 | cmdl_grpnum = get_plus_arg(NUM,"CMDL_GRPNUM="); |
| 86 | else |
| 87 | cmdl_grpnum = 0; |
| 88 | |
| 89 | NiuIntrMgr.initLdg(64'hffffffffffffffff); // Enable all LDG in Environment |
| 90 | printf("Init LDG\n"); |
| 91 | NiuIntrMgr.SetTmrRes(100); |
| 92 | printf("Set Time resolution\n"); |
| 93 | } |
| 94 | |
| 95 | task intr_test_util :: setup_sid_tab(CNiuIntrDev dev,integer ldgno,integer type) |
| 96 | { |
| 97 | integer group_num; |
| 98 | integer func_num; |
| 99 | static integer tmp_grp_num = 0; |
| 100 | |
| 101 | if(intr_grpnum == 0) |
| 102 | group_num = random()%64; |
| 103 | else if(intr_grpnum == 1) |
| 104 | group_num = cmdl_grpnum; |
| 105 | else if(intr_grpnum == 2) { |
| 106 | group_num = tmp_grp_num; |
| 107 | tmp_grp_num++; |
| 108 | } else if(intr_grpnum == 3) { |
| 109 | group_num = tmp_grp_num%64; |
| 110 | tmp_grp_num = tmp_grp_num + 16; |
| 111 | } |
| 112 | |
| 113 | |
| 114 | printf("Group number is %d for dev %d\n",group_num,dev.dev_id); |
| 115 | |
| 116 | if(group_num < 16) |
| 117 | func_num = 0; |
| 118 | else if(group_num < 32) |
| 119 | func_num = 1; |
| 120 | else if(group_num < 48) |
| 121 | func_num = 2; |
| 122 | else func_num = 3; |
| 123 | |
| 124 | programme_intmgr(dev,group_num,1,func_num); |
| 125 | |
| 126 | sid_tab[group_num].ldgno_bound = 1; |
| 127 | sid_tab[group_num].dev_bound[dev.dev_id] = 1; |
| 128 | |
| 129 | |
| 130 | } |
| 131 | |
| 132 | task intr_test_util :: programme_intmgr(CNiuIntrDev dev,integer ldgno, integer type, integer func_num) { |
| 133 | |
| 134 | bit[6:0] sid; |
| 135 | |
| 136 | if(sid_tab[ldgno].ldgno_bound) { |
| 137 | |
| 138 | // just do the bind |
| 139 | |
| 140 | dev.setGid(ldgno); |
| 141 | NiuIntrMgr.ldg[ldgno].SetIntrMgm(1/*Arm*/,10/*Timer*/); |
| 142 | NiuIntrMgr.ldg[ldgno].ldgbind(dev); |
| 143 | |
| 144 | } else { |
| 145 | compute_sid(func_num,sid); |
| 146 | |
| 147 | printf("Sid_table updated\n"); |
| 148 | NiuIntrMgr.updateSidTab(ldgno,sid); |
| 149 | |
| 150 | dev.setGid(ldgno); |
| 151 | NiuIntrMgr.ldg[ldgno].SetIntrMgm(1/*Arm*/,10/*Timer*/); |
| 152 | NiuIntrMgr.ldg[ldgno].ldgbind(dev); |
| 153 | NiuIntrMgr.ldg[ldgno].rearm = 1; |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | task intr_test_util :: compute_sid(integer func_num, var bit [6:0] sid) { |
| 158 | |
| 159 | bit [4:0] part_sid; |
| 160 | static bit [31:0] mask = 32'h0; |
| 161 | integer tmp_part_sid; |
| 162 | bit [6:0] tmp_sid; |
| 163 | bit [1:0] tmp_fn_num; |
| 164 | integer done = 0; |
| 165 | |
| 166 | |
| 167 | tmp_fn_num = func_num; |
| 168 | |
| 169 | while(!done) { |
| 170 | part_sid = random()%32; |
| 171 | tmp_part_sid = part_sid; |
| 172 | |
| 173 | if(mask[tmp_part_sid] == 0) { |
| 174 | // tmp_sid = {tmp_fn_num,tmp_part_sid}; |
| 175 | sid = {tmp_fn_num,part_sid}; |
| 176 | mask[tmp_part_sid] = 1; |
| 177 | done = 1; |
| 178 | } |
| 179 | |
| 180 | } |
| 181 | |
| 182 | |
| 183 | } |
| 184 | |