dev: Delete the authors list from files in src/dev.
[gem5.git] / src / dev / arm / flash_device.hh
1 /*
2 * Copyright (c) 2013-2015 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions are
16 * met: redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer;
18 * redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution;
21 * neither the name of the copyright holders nor the names of its
22 * contributors may be used to endorse or promote products derived from
23 * this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37 #ifndef __DEV_ARM_FLASH_DEVICE_HH__
38 #define __DEV_ARM_FLASH_DEVICE_HH__
39
40 #include <deque>
41
42 #include "base/statistics.hh"
43 #include "debug/FlashDevice.hh"
44 #include "dev/arm/abstract_nvm.hh"
45 #include "enums/DataDistribution.hh"
46 #include "params/FlashDevice.hh"
47 #include "sim/serialize.hh"
48
49 /**
50 * Flash Device model
51 * The Flash Device model is a timing model for a NAND flash device.
52 * It doesn't tranfer any data
53 */
54 class FlashDevice : public AbstractNVM
55 {
56 public:
57
58 /** Initialize functions*/
59 FlashDevice(const FlashDeviceParams*);
60 ~FlashDevice();
61
62 /** Checkpoint functions*/
63 DrainState drain() override;
64 void checkDrain();
65
66 void serialize(CheckpointOut &cp) const override;
67 void unserialize(CheckpointIn &cp) override;
68
69 private:
70 /** Defines the possible actions to the flash*/
71 enum Actions {
72 ActionRead,
73 ActionWrite,
74 ActionErase,
75 /**
76 * A copy involves taking all the used pages from a block and store
77 * it in another
78 */
79 ActionCopy
80 };
81
82 /** Every logical address maps to a physical block and a physical page*/
83 struct PageMapEntry {
84 uint32_t page;
85 uint32_t block;
86 };
87
88 struct CallBackEntry {
89 Tick time;
90 Callback *function;
91 };
92
93 struct FlashDeviceStats {
94 /** Amount of GC activations*/
95 Stats::Scalar totalGCActivations;
96
97 /** Histogram of address accesses*/
98 Stats::Histogram writeAccess;
99 Stats::Histogram readAccess;
100 Stats::Histogram fileSystemAccess;
101
102 /** Histogram of access latencies*/
103 Stats::Histogram writeLatency;
104 Stats::Histogram readLatency;
105 };
106
107 /** Device access functions Inherrited from AbstractNVM*/
108 void initializeMemory(uint64_t disk_size, uint32_t sector_size) override
109 {
110 initializeFlash(disk_size, sector_size);
111 }
112
113 void readMemory(uint64_t address, uint32_t amount,
114 Callback *event) override
115 {
116 accessDevice(address, amount, event, ActionRead);
117 }
118
119 void writeMemory(uint64_t address, uint32_t amount,
120 Callback *event) override
121 {
122 accessDevice(address, amount, event, ActionWrite);
123 }
124
125 /**Initialization function; called when all disk specifics are known*/
126 void initializeFlash(uint64_t disk_size, uint32_t sector_size);
127
128 /**Flash action function*/
129 void accessDevice(uint64_t address, uint32_t amount, Callback *event,
130 Actions action);
131
132 /** Event rescheduler*/
133 void actionComplete();
134
135 /** FTL functionality */
136 Tick remap(uint64_t logic_page_addr);
137
138 /** Access time calculator*/
139 Tick accessTimes(uint64_t address, Actions accesstype);
140
141 /** Function to indicate that a page is known*/
142 void clearUnknownPages(uint32_t index);
143
144 /** Function to test if a page is known*/
145 bool getUnknownPages(uint32_t index);
146
147 /**Stats register function*/
148 void regStats() override;
149
150 /** Disk sizes in bytes */
151 uint64_t diskSize;
152 const uint32_t blockSize;
153 const uint32_t pageSize;
154
155 /** Garbage collection algorithm emulator */
156 const uint32_t GCActivePercentage;
157
158 /** Access latencies */
159 const Tick readLatency;
160 const Tick writeLatency;
161 const Tick eraseLatency;
162
163 /** Flash organization */
164 const Enums::DataDistribution dataDistribution;
165 const uint32_t numPlanes;
166
167 /** RequestHandler stats */
168 struct FlashDeviceStats stats;
169
170 /** Disk dimensions in pages and blocks */
171 uint32_t pagesPerBlock;
172 uint32_t pagesPerDisk;
173 uint32_t blocksPerDisk;
174
175 uint32_t planeMask;
176
177 /**
178 * when the disk is first started we are unsure of the number of
179 * used pages, this variable will help determining what we do know.
180 */
181 std::vector<uint32_t> unknownPages;
182 /** address to logic place has a block and a page field*/
183 std::vector<struct PageMapEntry> locationTable;
184 /** number of valid entries per block*/
185 std::vector<uint32_t> blockValidEntries;
186 /** number of empty entries*/
187 std::vector<uint32_t> blockEmptyEntries;
188
189 /**This vector of queues keeps track of all the callbacks per plane*/
190 std::vector<std::deque<struct CallBackEntry> > planeEventQueue;
191
192 /** Completion event */
193 EventFunctionWrapper planeEvent;
194 };
195 #endif //__DEV_ARM_FLASH_DEVICE_HH__