-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_buffer.c
264 lines (219 loc) · 9.52 KB
/
data_buffer.c
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
//////////////////////////////////////////////////////////////////////////////////
// data_buffer.c for Cosmos+ OpenSSD
// Copyright (c) 2017 Hanyang University ENC Lab.
// Contributed by Yong Ho Song <[email protected]>
// Jaewook Kwak <[email protected]>
//
// This file is part of Cosmos+ OpenSSD.
//
// Cosmos+ OpenSSD is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3, or (at your option)
// any later version.
//
// Cosmos+ OpenSSD is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Cosmos+ OpenSSD; see the file COPYING.
// If not, see <http://www.gnu.org/licenses/>.
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
// Company: ENC Lab. <http://enc.hanyang.ac.kr>
// Engineer: Jaewook Kwak <[email protected]>
//
// Project Name: Cosmos+ OpenSSD
// Design Name: Cosmos+ Firmware
// Module Name: Data Buffer Manager
// File Name: data_buffer.c
//
// Version: v1.0.0
//
// Description:
// - manage data buffer used to transfer data between host system and NAND device
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
// Revision History:
//
// * v1.0.0
// - First draft
//////////////////////////////////////////////////////////////////////////////////
#include "xil_printf.h"
#include <assert.h>
#include "memory_map.h"
P_DATA_BUF_MAP dataBufMapPtr;
DATA_BUF_LRU_LIST dataBufLruList;
P_DATA_BUF_HASH_TABLE dataBufHashTablePtr;
P_TEMPORARY_DATA_BUF_MAP tempDataBufMapPtr;
void InitDataBuf()
{
int bufEntry;
dataBufMapPtr = (P_DATA_BUF_MAP) DATA_BUFFER_MAP_ADDR;
dataBufHashTablePtr = (P_DATA_BUF_HASH_TABLE)DATA_BUFFFER_HASH_TABLE_ADDR;
tempDataBufMapPtr = (P_TEMPORARY_DATA_BUF_MAP)TEMPORARY_DATA_BUFFER_MAP_ADDR;
for(bufEntry = 0; bufEntry < AVAILABLE_DATA_BUFFER_ENTRY_COUNT; bufEntry++)
{
dataBufMapPtr->dataBuf[bufEntry].logicalSliceAddr = LSA_NONE;
dataBufMapPtr->dataBuf[bufEntry].prevEntry = bufEntry-1;
dataBufMapPtr->dataBuf[bufEntry].nextEntry = bufEntry+1;
dataBufMapPtr->dataBuf[bufEntry].dirty = DATA_BUF_CLEAN;
dataBufMapPtr->dataBuf[bufEntry].blockingReqTail = REQ_SLOT_TAG_NONE;
dataBufHashTablePtr->dataBufHash[bufEntry].headEntry = DATA_BUF_NONE;
dataBufHashTablePtr->dataBufHash[bufEntry].tailEntry = DATA_BUF_NONE;
dataBufMapPtr->dataBuf[bufEntry].hashPrevEntry = DATA_BUF_NONE;
dataBufMapPtr->dataBuf[bufEntry].hashNextEntry = DATA_BUF_NONE;
}
dataBufMapPtr->dataBuf[0].prevEntry = DATA_BUF_NONE;
dataBufMapPtr->dataBuf[AVAILABLE_DATA_BUFFER_ENTRY_COUNT - 1].nextEntry = DATA_BUF_NONE;
dataBufLruList.headEntry = 0 ;
dataBufLruList.tailEntry = AVAILABLE_DATA_BUFFER_ENTRY_COUNT - 1;
for(bufEntry = 0; bufEntry < AVAILABLE_TEMPORARY_DATA_BUFFER_ENTRY_COUNT; bufEntry++)
tempDataBufMapPtr->tempDataBuf[bufEntry].blockingReqTail = REQ_SLOT_TAG_NONE;
}
unsigned int CheckDataBufHit(unsigned int reqSlotTag)
{
unsigned int bufEntry, logicalSliceAddr;
logicalSliceAddr = reqPoolPtr->reqPool[reqSlotTag].logicalSliceAddr;
bufEntry = dataBufHashTablePtr->dataBufHash[FindDataBufHashTableEntry(logicalSliceAddr)].headEntry;
while(bufEntry != DATA_BUF_NONE)
{
if(dataBufMapPtr->dataBuf[bufEntry].logicalSliceAddr == logicalSliceAddr)
{
if((dataBufMapPtr->dataBuf[bufEntry].nextEntry != DATA_BUF_NONE) && (dataBufMapPtr->dataBuf[bufEntry].prevEntry != DATA_BUF_NONE))
{
dataBufMapPtr->dataBuf[dataBufMapPtr->dataBuf[bufEntry].prevEntry].nextEntry = dataBufMapPtr->dataBuf[bufEntry].nextEntry;
dataBufMapPtr->dataBuf[dataBufMapPtr->dataBuf[bufEntry].nextEntry].prevEntry = dataBufMapPtr->dataBuf[bufEntry].prevEntry;
}
else if((dataBufMapPtr->dataBuf[bufEntry].nextEntry == DATA_BUF_NONE) && (dataBufMapPtr->dataBuf[bufEntry].prevEntry != DATA_BUF_NONE))
{
dataBufMapPtr->dataBuf[dataBufMapPtr->dataBuf[bufEntry].prevEntry].nextEntry = DATA_BUF_NONE;
dataBufLruList.tailEntry = dataBufMapPtr->dataBuf[bufEntry].prevEntry;
}
else if((dataBufMapPtr->dataBuf[bufEntry].nextEntry != DATA_BUF_NONE) && (dataBufMapPtr->dataBuf[bufEntry].prevEntry== DATA_BUF_NONE))
{
dataBufMapPtr->dataBuf[dataBufMapPtr->dataBuf[bufEntry].nextEntry].prevEntry = DATA_BUF_NONE;
dataBufLruList.headEntry = dataBufMapPtr->dataBuf[bufEntry].nextEntry;
}
else
{
dataBufLruList.tailEntry = DATA_BUF_NONE;
dataBufLruList.headEntry = DATA_BUF_NONE;
}
if(dataBufLruList.headEntry != DATA_BUF_NONE)
{
dataBufMapPtr->dataBuf[bufEntry].prevEntry = DATA_BUF_NONE;
dataBufMapPtr->dataBuf[bufEntry].nextEntry = dataBufLruList.headEntry;
dataBufMapPtr->dataBuf[dataBufLruList.headEntry].prevEntry = bufEntry;
dataBufLruList.headEntry = bufEntry;
}
else
{
dataBufMapPtr->dataBuf[bufEntry].prevEntry = DATA_BUF_NONE;
dataBufMapPtr->dataBuf[bufEntry].nextEntry = DATA_BUF_NONE;
dataBufLruList.headEntry = bufEntry;
dataBufLruList.tailEntry = bufEntry;
}
return bufEntry;
}
else
bufEntry = dataBufMapPtr->dataBuf[bufEntry].hashNextEntry;
}
return DATA_BUF_FAIL;
}
unsigned int AllocateDataBuf()
{
unsigned int evictedEntry = dataBufLruList.tailEntry;
if(evictedEntry == DATA_BUF_NONE)
assert(!"[WARNING] There is no valid buffer entry [WARNING]");
if(dataBufMapPtr->dataBuf[evictedEntry].prevEntry != DATA_BUF_NONE)
{
dataBufMapPtr->dataBuf[dataBufMapPtr->dataBuf[evictedEntry].prevEntry].nextEntry = DATA_BUF_NONE;
dataBufLruList.tailEntry = dataBufMapPtr->dataBuf[evictedEntry].prevEntry;
dataBufMapPtr->dataBuf[evictedEntry].prevEntry = DATA_BUF_NONE;
dataBufMapPtr->dataBuf[evictedEntry].nextEntry = dataBufLruList.headEntry;
dataBufMapPtr->dataBuf[dataBufLruList.headEntry].prevEntry = evictedEntry;
dataBufLruList.headEntry = evictedEntry;
}
else
{
dataBufMapPtr->dataBuf[evictedEntry].prevEntry = DATA_BUF_NONE;
dataBufMapPtr->dataBuf[evictedEntry].nextEntry = DATA_BUF_NONE;
dataBufLruList.headEntry = evictedEntry;
dataBufLruList.tailEntry = evictedEntry;
}
SelectiveGetFromDataBufHashList(evictedEntry);
return evictedEntry;
}
void UpdateDataBufEntryInfoBlockingReq(unsigned int bufEntry, unsigned int reqSlotTag)
{
if(dataBufMapPtr->dataBuf[bufEntry].blockingReqTail != REQ_SLOT_TAG_NONE)
{
reqPoolPtr->reqPool[reqSlotTag].prevBlockingReq = dataBufMapPtr->dataBuf[bufEntry].blockingReqTail;
reqPoolPtr->reqPool[reqPoolPtr->reqPool[reqSlotTag].prevBlockingReq].nextBlockingReq = reqSlotTag;
}
dataBufMapPtr->dataBuf[bufEntry].blockingReqTail = reqSlotTag;
}
unsigned int AllocateTempDataBuf(unsigned int dieNo)
{
return dieNo;
}
void UpdateTempDataBufEntryInfoBlockingReq(unsigned int bufEntry, unsigned int reqSlotTag)
{
if(tempDataBufMapPtr->tempDataBuf[bufEntry].blockingReqTail != REQ_SLOT_TAG_NONE)
{
reqPoolPtr->reqPool[reqSlotTag].prevBlockingReq = tempDataBufMapPtr->tempDataBuf[bufEntry].blockingReqTail;
reqPoolPtr->reqPool[reqPoolPtr->reqPool[reqSlotTag].prevBlockingReq].nextBlockingReq = reqSlotTag;
}
tempDataBufMapPtr->tempDataBuf[bufEntry].blockingReqTail = reqSlotTag;
}
void PutToDataBufHashList(unsigned int bufEntry)
{
unsigned int hashEntry;
hashEntry = FindDataBufHashTableEntry(dataBufMapPtr->dataBuf[bufEntry].logicalSliceAddr);
if(dataBufHashTablePtr->dataBufHash[hashEntry].tailEntry != DATA_BUF_NONE)
{
dataBufMapPtr->dataBuf[bufEntry].hashPrevEntry = dataBufHashTablePtr->dataBufHash[hashEntry].tailEntry ;
dataBufMapPtr->dataBuf[bufEntry].hashNextEntry = REQ_SLOT_TAG_NONE;
dataBufMapPtr->dataBuf[dataBufHashTablePtr->dataBufHash[hashEntry].tailEntry].hashNextEntry = bufEntry;
dataBufHashTablePtr->dataBufHash[hashEntry].tailEntry = bufEntry;
}
else
{
dataBufMapPtr->dataBuf[bufEntry].hashPrevEntry = REQ_SLOT_TAG_NONE;
dataBufMapPtr->dataBuf[bufEntry].hashNextEntry = REQ_SLOT_TAG_NONE;
dataBufHashTablePtr->dataBufHash[hashEntry].headEntry = bufEntry;
dataBufHashTablePtr->dataBufHash[hashEntry].tailEntry = bufEntry;
}
}
void SelectiveGetFromDataBufHashList(unsigned int bufEntry)
{
if(dataBufMapPtr->dataBuf[bufEntry].logicalSliceAddr != LSA_NONE)
{
unsigned int prevBufEntry, nextBufEntry, hashEntry;
prevBufEntry = dataBufMapPtr->dataBuf[bufEntry].hashPrevEntry;
nextBufEntry = dataBufMapPtr->dataBuf[bufEntry].hashNextEntry;
hashEntry = FindDataBufHashTableEntry(dataBufMapPtr->dataBuf[bufEntry].logicalSliceAddr);
if((nextBufEntry != DATA_BUF_NONE) && (prevBufEntry != DATA_BUF_NONE))
{
dataBufMapPtr->dataBuf[prevBufEntry].hashNextEntry = nextBufEntry;
dataBufMapPtr->dataBuf[nextBufEntry].hashPrevEntry = prevBufEntry;
}
else if((nextBufEntry == DATA_BUF_NONE) && (prevBufEntry != DATA_BUF_NONE))
{
dataBufMapPtr->dataBuf[prevBufEntry].hashNextEntry = DATA_BUF_NONE;
dataBufHashTablePtr->dataBufHash[hashEntry].tailEntry = prevBufEntry;
}
else if((nextBufEntry != DATA_BUF_NONE) && (prevBufEntry == DATA_BUF_NONE))
{
dataBufMapPtr->dataBuf[nextBufEntry].hashPrevEntry = DATA_BUF_NONE;
dataBufHashTablePtr->dataBufHash[hashEntry].headEntry = nextBufEntry;
}
else
{
dataBufHashTablePtr->dataBufHash[hashEntry].headEntry = DATA_BUF_NONE;
dataBufHashTablePtr->dataBufHash[hashEntry].tailEntry = DATA_BUF_NONE;
}
}
}