Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / verif / env / niu / vera / niu_utils / niu_memcbmgr.vr
CommitLineData
86530b38
AT
1// ========== Copyright Header Begin ==========================================
2//
3// OpenSPARC T2 Processor File: niu_memcbmgr.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 <vera_defines.vrh>
36#include <ListMacros.vrh>
37#include "niu_cb_events.vri"
38
39/* A generic call back class to be used for Memory */
40#include "niu_cbclass.vrh"
41
42
43class CcbManager {
44
45 integer no_of_cbs;
46 CcbMem cbMem[];
47 string whoami;
48 task new(string s) {
49 no_of_cbs = 0;
50 whoami = s;
51 }
52
53 task setCallBack ( CcbMem cbMem) ;
54 function integer checkCallBack ( bit [63:0] attr, (integer req=0) );
55 local task docb( CcbMem cb);
56}
57
58task CcbManager::setCallBack ( CcbMem cb) {
59bit[95:0] hash_in;
60
61 if(cb.eventdfn == READ_REQUEST) {
62 hash_in = {READ_REQUEST,cb.attr};
63 } else {
64 hash_in = {cb.attr};
65 }
66
67 if ( assoc_index(CHECK,this.cbMem,hash_in)) {
68 printf("%s: CcbManager::setCallBack: CallBack already set for address - %x Ignoring this request-- \n",whoami,cb.attr);
69 return;
70 } else {
71 cbMem[hash_in] = new cb;
72 no_of_cbs ++;
73 printf("%s: CcbManager::setCallBack: MEM CB DEBUG- Callback Set for address - %x , NoofActiveCBS - %d \n",whoami,cb.attr,no_of_cbs);
74 }
75}
76
77function integer CcbManager::checkCallBack ( bit [63:0] attr, (integer req=0) ) {
78 CcbMem cb;
79 integer status;
80 bit[95:0] hash_in;
81
82
83 if(req == 1) {
84 hash_in = {READ_REQUEST,attr};
85 } else {
86 hash_in = {attr};
87 }
88
89
90 if(assoc_index(CHECK,this.cbMem,hash_in)) {
91 printf("%s: Found the entry in the cb mem- \n",whoami);
92 // do the appropriate action and return the status
93 checkCallBack = 1;
94 cb = new this.cbMem[hash_in];
95 if(req==0) {
96 status = assoc_index(DELETE,this.cbMem,hash_in);
97 }
98 docb(cb);
99 }
100 else checkCallBack = 0;
101
102}
103
104task CcbManager::docb( CcbMem cb) {
105
106 // Parse the events and do appropriate-
107 // cb.eventdfn ==
108
109 if(cb.eventdfn == -1) {
110 printf("%s: CcbManager::docb: ERROR Illegal CallBack event set!! FIX IT \n",whoami);
111 return;
112 }
113
114 if(cb.semId!=-1) {
115 semaphore_put(cb.semId,1);
116 no_of_cbs --;
117 if(cb.eventdfn == GOOD_PACKET) {
118 printf("%s: CcbManager::docb: MEM CB DEBUG- CallBack Success - Address - %x \n",whoami,cb.attr);
119 } else if(cb.eventdfn == DROP_PACKET) {
120 printf("%s: CcbManager::docb: ERROR- CallBack Success - Packet Written to address - %x : Packet expected to be dropped \n",whoami,cb.attr);
121
122 } else if( cb.eventdfn == CR_WAIT_FOR_ACK) {
123 printf("%s: CcbManager::docb: - CallBack Success - Sending Write Ack for address - %x : \n",whoami,cb.attr);
124 } else if( cb.eventdfn == READ_REQUEST) {
125 printf("%s: CcbManager::docb: - CallBack Success - Read Request for address - %x : \n",whoami,cb.attr);
126 }
127
128 }
129}