forked from umd-memsys/DRAMSim2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AddressMapping.cpp
312 lines (264 loc) · 11.1 KB
/
AddressMapping.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
/*********************************************************************************
* Copyright (c) 2010-2011, Elliott Cooper-Balis
* Paul Rosenfeld
* Bruce Jacob
* University of Maryland
* dramninjas [at] gmail [dot] com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * 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.
*
* 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.
*********************************************************************************/
#include "SystemConfiguration.h"
#include "AddressMapping.h"
namespace DRAMSim
{
void addressMapping(uint64_t physicalAddress, unsigned &newTransactionChan, unsigned &newTransactionRank, unsigned &newTransactionBank, unsigned &newTransactionRow, unsigned &newTransactionColumn)
{
uint64_t tempA, tempB;
unsigned transactionSize = TRANSACTION_SIZE;
uint64_t transactionMask = transactionSize - 1; //ex: (64 bit bus width) x (8 Burst Length) - 1 = 64 bytes - 1 = 63 = 0x3f mask
unsigned channelBitWidth = NUM_CHANS_LOG;
unsigned rankBitWidth = NUM_RANKS_LOG;
unsigned bankBitWidth = NUM_BANKS_LOG;
unsigned rowBitWidth = NUM_ROWS_LOG;
unsigned colBitWidth = NUM_COLS_LOG;
// this forces the alignment to the width of a single burst (64 bits = 8 bytes = 3 address bits for DDR parts)
unsigned byteOffsetWidth = BYTE_OFFSET_WIDTH;
// Since we're assuming that a request is for BL*BUS_WIDTH, the bottom bits
// of this address *should* be all zeros if it's not, issue a warning
if ((physicalAddress & transactionMask) != 0)
{
DEBUG("WARNING: address 0x"<<std::hex<<physicalAddress<<std::dec<<" is not aligned to the request size of "<<transactionSize);
}
// each burst will contain JEDEC_DATA_BUS_BITS/8 bytes of data, so the bottom bits (3 bits for a single channel DDR system) are
// thrown away before mapping the other bits
physicalAddress >>= byteOffsetWidth;
// The next thing we have to consider is that when a request is made for a
// we've taken into account the granulaity of a single burst by shifting
// off the bottom 3 bits, but a transaction has to take into account the
// burst length (i.e. the requests will be aligned to cache line sizes which
// should be equal to transactionSize above).
//
// Since the column address increments internally on bursts, the bottom n
// bits of the column (colLow) have to be zero in order to account for the
// total size of the transaction. These n bits should be shifted off the
// address and also subtracted from the total column width.
//
// I am having a hard time explaining the reasoning here, but it comes down
// this: for a 64 byte transaction, the bottom 6 bits of the address must be
// zero. These zero bits must be made up of the byte offset (3 bits) and also
// from the bottom bits of the column
//
// For example: cowLowBits = log2(64bytes) - 3 bits = 3 bits
unsigned colLowBitWidth = COL_LOW_BIT_WIDTH;
physicalAddress >>= colLowBitWidth;
unsigned colHighBitWidth = colBitWidth - colLowBitWidth;
if (DEBUG_ADDR_MAP)
{
DEBUG("Bit widths: ch:"<<channelBitWidth<<" r:"<<rankBitWidth<<" b:"<<bankBitWidth
<<" row:"<<rowBitWidth<<" colLow:"<<colLowBitWidth
<< " colHigh:"<<colHighBitWidth<<" off:"<<byteOffsetWidth
<< " Total:"<< (channelBitWidth + rankBitWidth + bankBitWidth + rowBitWidth + colLowBitWidth + colHighBitWidth + byteOffsetWidth));
}
//perform various address mapping schemes
if (addressMappingScheme == Scheme1)
{
//chan:rank:row:col:bank
tempA = physicalAddress;
physicalAddress = physicalAddress >> bankBitWidth;
tempB = physicalAddress << bankBitWidth;
newTransactionBank = tempA ^ tempB;
tempA = physicalAddress;
physicalAddress = physicalAddress >> colHighBitWidth;
tempB = physicalAddress << colHighBitWidth;
newTransactionColumn = tempA ^ tempB;
tempA = physicalAddress;
physicalAddress = physicalAddress >> rowBitWidth;
tempB = physicalAddress << rowBitWidth;
newTransactionRow = tempA ^ tempB;
tempA = physicalAddress;
physicalAddress = physicalAddress >> rankBitWidth;
tempB = physicalAddress << rankBitWidth;
newTransactionRank = tempA ^ tempB;
tempA = physicalAddress;
physicalAddress = physicalAddress >> channelBitWidth;
tempB = physicalAddress << channelBitWidth;
newTransactionChan = tempA ^ tempB;
}
else if (addressMappingScheme == Scheme2)
{
//chan:row:col:bank:rank
tempA = physicalAddress;
physicalAddress = physicalAddress >> rankBitWidth;
tempB = physicalAddress << rankBitWidth;
newTransactionRank = tempA ^ tempB;
tempA = physicalAddress;
physicalAddress = physicalAddress >> bankBitWidth;
tempB = physicalAddress << bankBitWidth;
newTransactionBank = tempA ^ tempB;
tempA = physicalAddress;
physicalAddress = physicalAddress >> colHighBitWidth;
tempB = physicalAddress << colHighBitWidth;
newTransactionColumn = tempA ^ tempB;
tempA = physicalAddress;
physicalAddress = physicalAddress >> rowBitWidth;
tempB = physicalAddress << rowBitWidth;
newTransactionRow = tempA ^ tempB;
tempA = physicalAddress;
physicalAddress = physicalAddress >> channelBitWidth;
tempB = physicalAddress << channelBitWidth;
newTransactionChan = tempA ^ tempB;
}
else if (addressMappingScheme == Scheme3)
{
//chan:rank:bank:col:row
tempA = physicalAddress;
physicalAddress = physicalAddress >> rowBitWidth;
tempB = physicalAddress << rowBitWidth;
newTransactionRow = tempA ^ tempB;
tempA = physicalAddress;
physicalAddress = physicalAddress >> colHighBitWidth;
tempB = physicalAddress << colHighBitWidth;
newTransactionColumn = tempA ^ tempB;
tempA = physicalAddress;
physicalAddress = physicalAddress >> bankBitWidth;
tempB = physicalAddress << bankBitWidth;
newTransactionBank = tempA ^ tempB;
tempA = physicalAddress;
physicalAddress = physicalAddress >> rankBitWidth;
tempB = physicalAddress << rankBitWidth;
newTransactionRank = tempA ^ tempB;
tempA = physicalAddress;
physicalAddress = physicalAddress >> channelBitWidth;
tempB = physicalAddress << channelBitWidth;
newTransactionChan = tempA ^ tempB;
}
else if (addressMappingScheme == Scheme4)
{
//chan:rank:bank:row:col
tempA = physicalAddress;
physicalAddress = physicalAddress >> colHighBitWidth;
tempB = physicalAddress << colHighBitWidth;
newTransactionColumn = tempA ^ tempB;
tempA = physicalAddress;
physicalAddress = physicalAddress >> rowBitWidth;
tempB = physicalAddress << rowBitWidth;
newTransactionRow = tempA ^ tempB;
tempA = physicalAddress;
physicalAddress = physicalAddress >> bankBitWidth;
tempB = physicalAddress << bankBitWidth;
newTransactionBank = tempA ^ tempB;
tempA = physicalAddress;
physicalAddress = physicalAddress >> rankBitWidth;
tempB = physicalAddress << rankBitWidth;
newTransactionRank = tempA ^ tempB;
tempA = physicalAddress;
physicalAddress = physicalAddress >> channelBitWidth;
tempB = physicalAddress << channelBitWidth;
newTransactionChan = tempA ^ tempB;
}
else if (addressMappingScheme == Scheme5)
{
//chan:row:col:rank:bank
tempA = physicalAddress;
physicalAddress = physicalAddress >> bankBitWidth;
tempB = physicalAddress << bankBitWidth;
newTransactionBank = tempA ^ tempB;
tempA = physicalAddress;
physicalAddress = physicalAddress >> rankBitWidth;
tempB = physicalAddress << rankBitWidth;
newTransactionRank = tempA ^ tempB;
tempA = physicalAddress;
physicalAddress = physicalAddress >> colHighBitWidth;
tempB = physicalAddress << colHighBitWidth;
newTransactionColumn = tempA ^ tempB;
tempA = physicalAddress;
physicalAddress = physicalAddress >> rowBitWidth;
tempB = physicalAddress << rowBitWidth;
newTransactionRow = tempA ^ tempB;
tempA = physicalAddress;
physicalAddress = physicalAddress >> channelBitWidth;
tempB = physicalAddress << channelBitWidth;
newTransactionChan = tempA ^ tempB;
}
else if (addressMappingScheme == Scheme6)
{
//chan:rank:row:bank:col
tempA = physicalAddress;
physicalAddress = physicalAddress >> colHighBitWidth;
tempB = physicalAddress << colHighBitWidth;
newTransactionColumn = tempA ^ tempB;
tempA = physicalAddress;
physicalAddress = physicalAddress >> bankBitWidth;
tempB = physicalAddress << bankBitWidth;
newTransactionBank = tempA ^ tempB;
tempA = physicalAddress;
physicalAddress = physicalAddress >> rowBitWidth;
tempB = physicalAddress << rowBitWidth;
newTransactionRow = tempA ^ tempB;
tempA = physicalAddress;
physicalAddress = physicalAddress >> rankBitWidth;
tempB = physicalAddress << rankBitWidth;
newTransactionRank = tempA ^ tempB;
tempA = physicalAddress;
physicalAddress = physicalAddress >> channelBitWidth;
tempB = physicalAddress << channelBitWidth;
newTransactionChan = tempA ^ tempB;
}
// clone of scheme 5, but channel moved to lower bits
else if (addressMappingScheme == Scheme7)
{
//row:col:rank:bank:chan
tempA = physicalAddress;
physicalAddress = physicalAddress >> channelBitWidth;
tempB = physicalAddress << channelBitWidth;
newTransactionChan = tempA ^ tempB;
tempA = physicalAddress;
physicalAddress = physicalAddress >> bankBitWidth;
tempB = physicalAddress << bankBitWidth;
newTransactionBank = tempA ^ tempB;
tempA = physicalAddress;
physicalAddress = physicalAddress >> rankBitWidth;
tempB = physicalAddress << rankBitWidth;
newTransactionRank = tempA ^ tempB;
tempA = physicalAddress;
physicalAddress = physicalAddress >> colHighBitWidth;
tempB = physicalAddress << colHighBitWidth;
newTransactionColumn = tempA ^ tempB;
tempA = physicalAddress;
physicalAddress = physicalAddress >> rowBitWidth;
tempB = physicalAddress << rowBitWidth;
newTransactionRow = tempA ^ tempB;
}
else
{
ERROR("== Error - Unknown Address Mapping Scheme");
exit(-1);
}
if (DEBUG_ADDR_MAP)
{
DEBUG("Mapped Ch="<<newTransactionChan<<" Rank="<<newTransactionRank
<<" Bank="<<newTransactionBank<<" Row="<<newTransactionRow
<<" Col="<<newTransactionColumn<<"\n");
}
}
};