2 Copyright (c) 2013, IIT Madras
5 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9 * Neither the name of IIT Madras nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
11 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
12 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
14 ////////////////////////////////////////////////////////////////////////////////
15 // Copyright (c) 2010 Bluespec, Inc. ALL RIGHTS RESERVED.
16 ////////////////////////////////////////////////////////////////////////////////
17 // Filename : GDefines.bsv
18 // Description : Global type definitions
19 ////////////////////////////////////////////////////////////////////////////////
23 ////////////////////////////////////////////////////////////////////////////////
25 ////////////////////////////////////////////////////////////////////////////////
28 import DefaultValue ::*;
32 import ClientServer ::*;
34 `include "ARM.defines"
36 ////////////////////////////////////////////////////////////////////////////////
38 ////////////////////////////////////////////////////////////////////////////////
39 typedef TLMAddr#(`ARM_PRM) MemAddr;
40 typedef TLMData#(`ARM_PRM) MemData;
41 typedef TLMByteEn#(`ARM_PRM) MemBen;
45 ////////////////////////////////////////////////////////////////////////////////
47 ////////////////////////////////////////////////////////////////////////////////
64 } BusRequest deriving (Bits, Eq);
66 instance DefaultValue#(BusRequest);
67 defaultValue = BusRequest {
86 ////////////////////////////////////////////////////////////////////////////////
88 ////////////////////////////////////////////////////////////////////////////////
96 } BusResponse deriving (Bits, Eq);
98 instance DefaultValue#(BusResponse);
99 defaultValue = BusResponse {
110 ////////////////////////////////////////////////////////////////////////////////
111 /// Overloading Function for TLM conversions
112 ////////////////////////////////////////////////////////////////////////////////
113 instance TLMRequestTC#(BusRequest, `ARM_PRM);
114 function toTLMRequest(x);
116 RequestDescriptor#(`ARM_PRM) request = createBasicRequestDescriptor;
117 request.custom[11] = pack(x.reduced);
118 request.custom[10] = pack(x.gdb);
119 request.custom[9] = pack(x.cop);
120 request.custom[8] = 0;
121 request.custom[7] = 0;
122 request.custom[6] = 0;
123 request.custom[5] = pack(x.c);
124 request.custom[4] = pack(x.c);
125 request.custom[3] = pack(x.b);
126 request.custom[2] = pack(x.inst);
127 request.custom[1] = 1;
128 request.custom[0] = pack(!x.usermode);
129 request.burst_mode = (x.wrap) ? WRAP : INCR;
130 request.transaction_id = pack(x.id);
131 request.burst_size = truncate(pack(countOnesAlt(x.byteen) - 1));
132 request.burst_length = x.burst;
133 request.byte_enable = x.byteen;
134 request.command = (x.write) ? WRITE : READ;
135 request.addr = pack(x.address);
136 request.data = x.data;
137 return (tagged Descriptor request);
140 RequestData#(`ARM_PRM) request = unpack(0);
141 request.custom[11] = pack(x.reduced);
142 request.custom[10] = pack(x.gdb);
143 request.custom[9] = pack(x.cop);
144 request.custom[8] = 0;
145 request.custom[7] = 0;
146 request.custom[6] = 0;
147 request.custom[5] = pack(x.c);
148 request.custom[4] = pack(x.c);
149 request.custom[3] = pack(x.b);
150 request.custom[2] = pack(x.inst);
151 request.custom[1] = 1;
152 request.custom[0] = pack(!x.usermode);
153 request.transaction_id = pack(x.id);
154 request.data = x.data;
155 return (tagged Data request);
159 function fromTLMRequest(x);
161 tagged Descriptor .d: begin
164 reduced: unpack(d.custom[11]),
165 inst: unpack(d.custom[2]),
166 write: (d.command == WRITE),
167 cop: unpack(d.custom[9]),
168 gdb: unpack(d.custom[10]),
169 c: unpack(d.custom[4]),
170 b: unpack(d.custom[3]),
171 usermode: unpack(~d.custom[0]),
172 wrap: d.burst_mode == WRAP,
173 id: unpack(d.transaction_id),
174 burst: d.burst_length,
175 byteen: calculateByteEnables(d),
176 address: unpack(d.addr),
180 tagged Data .d: begin
183 reduced: unpack(d.custom[11]),
184 inst: unpack(d.custom[2]),
186 cop: unpack(d.custom[9]),
187 gdb: unpack(d.custom[10]),
188 c: unpack(d.custom[4]),
189 b: unpack(d.custom[3]),
190 usermode: unpack(~d.custom[0]),
192 id: unpack(d.transaction_id),
203 instance TLMResponseTC#(BusResponse, `ARM_PRM);
204 function toTLMResponse(x);
205 TLMResponse#(`ARM_PRM) response = unpack(0);
206 response.command = (x.write) ? WRITE : READ;
207 response.data = x.data;
208 response.status = (x.error) ? ERROR : SUCCESS;
209 response.custom[10] = pack(x.gdb);
210 response.custom[9] = pack(x.cop);
211 response.transaction_id = pack(x.id);
214 function fromTLMResponse(x);
216 error: (x.status != SUCCESS),
217 gdb: unpack(x.custom[10]),
218 cop: unpack(x.custom[9]),
219 write: (x.command == WRITE),
220 id: unpack(x.transaction_id),
226 ////////////////////////////////////////////////////////////////////////////////
228 ////////////////////////////////////////////////////////////////////////////////
229 function Bit#(4) calculateByteEnables(RequestDescriptor#(`ARM_PRM) desc);
230 let offset_mask = 3 - desc.burst_size;
231 let offset = desc.addr & zeroExtend(offset_mask);
232 let maskp1 = 1 << getTLMBurstSize(desc);
233 return (maskp1-1) << offset;