gem5 v24.0.0.0
Loading...
Searching...
No Matches
cfi_mem.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012-2013, 2021 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 * Copyright (c) 2001-2005 The Regents of The University of Michigan
15 * All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 */
40
41#ifndef __MEM_FLASH_MEM_HH__
42#define __MEM_FLASH_MEM_HH__
43
44#include "mem/abstract_mem.hh"
45#include "params/CfiMemory.hh"
46
47namespace gem5
48{
49
50namespace memory
51{
52
72{
73 private:
74 enum class CfiCommand
75 {
76 NO_CMD = 0,
77 LOCK_BLOCK = 0x1,
78 ERASE_BLOCK_SETUP = 0x20,
79 WORD_PROGRAM = 0x40,
80 CLEAR_STATUS_REG = 0x50,
81 LOCK_BLOCK_SETUP = 0x60,
82 READ_STATUS_REG = 0x70,
83 READ_DEVICE_ID = 0x90,
84 READ_CFI_QUERY = 0x98,
88 UNLOCK_BLOCK = 0xD0,
89 AMD_RESET=0xF0,
90 READ_ARRAY = 0xFF,
95 };
96
98 static const uint8_t STATUS_ERASE_ERROR = 0x30;
99 static const uint8_t STATUS_LOCK_ERROR = 0x12;
100 static const uint8_t STATUS_READY = 0x80;
101 static const uint8_t STATUS_PROGRAM_LOCK_BIT = 0x10;
102
104 struct BlockData : public Serializable
105 {
106 BlockData(const CfiMemory &_parent, ssize_t number, ssize_t size)
107 : Serializable(), locked(number, false), blockSize(size),
108 parent(_parent)
109 {}
110
119 bool isLocked(Addr block_address) const;
120
128 void lock(Addr block_address);
129
137 void unlock(Addr block_address);
138
144 void erase(PacketPtr pkt);
145
147 ssize_t number() const { return locked.size(); }
148
150 ssize_t size() const { return blockSize; }
151
152 private: // Serializable
153 void serialize(CheckpointOut &cp) const override;
154
155 void unserialize(CheckpointIn &cp) override;
156
157 private:
158 uint32_t blockIdx(Addr block_address) const;
159
160 // Per block flag. True if the block is locked
162
163 // Size of the block in bytes
164 const ssize_t blockSize;
165
167 };
168
174 {
175 public:
176 // program buffer max size = 32 words
177 static const ssize_t MAX_BUFFER_SIZE = 32 * 4;
178
179 ProgramBuffer(const CfiMemory &_parent)
180 : Serializable(), parent(_parent)
181 {}
182
187 void setup(ssize_t buffer_size);
188
200 bool write(Addr flash_address, void *data_ptr, ssize_t size);
201
202 bool writeback();
203
204 private:
205 void serialize(CheckpointOut &cp) const override;
206
207 void unserialize(CheckpointIn &cp) override;
208
209 private:
210 // program buffer
212
213 // Number of bytes written in the buffer
214 ssize_t bytesWritten = 0;
215
216 // Pointing to the latest written word in the buffer
218
220 };
221
227 {
228
229 public:
230
231 const Tick tick;
233
234 DeferredPacket(PacketPtr _pkt, Tick _tick) : tick(_tick), pkt(_pkt)
235 { }
236 };
237
239 {
240 private:
242
243 public:
244 MemoryPort(const std::string& _name, CfiMemory& _memory);
245
246 protected:
247 Tick recvAtomic(PacketPtr pkt) override;
249 PacketPtr pkt, MemBackdoorPtr &_backdoor) override;
250 void recvFunctional(PacketPtr pkt) override;
251 void recvMemBackdoorReq(const MemBackdoorReq &req,
252 MemBackdoorPtr &_backdoor) override;
253 bool recvTimingReq(PacketPtr pkt) override;
254 void recvRespRetry() override;
255 AddrRangeList getAddrRanges() const override;
256 };
257
259
265
270
277
283 const double bandwidth;
284
289 bool isBusy;
290
296
302
307 void release();
308
310
315 void dequeue();
316
318
324 Tick getLatency() const;
325
330 std::unique_ptr<Packet> pendingDelete;
331
332 const uint8_t numberOfChips;
333
334 const uint16_t vendorID;
335 const uint16_t deviceID;
336 const uint16_t bankWidth;
337
341
343
345
347
348 uint8_t cfiQueryTable[61];
349
350 public:
351 CfiMemory(const CfiMemoryParams &p);
352
353 DrainState drain() override;
354
355 Port &getPort(const std::string &if_name,
356 PortID idx=InvalidPortID) override;
357 void init() override;
358
359 void serialize(CheckpointOut &cp) const override;
360 void unserialize(CheckpointIn &cp) override;
361
362 protected:
365 void recvFunctional(PacketPtr pkt);
366 void recvMemBackdoorReq(const MemBackdoorReq &req,
367 MemBackdoorPtr &_backdoor);
368 bool recvTimingReq(PacketPtr pkt);
369 void recvRespRetry();
370
372 void cfiAccess(PacketPtr pkt);
373
375 void write(PacketPtr pkt);
376
378 void read(PacketPtr pkt);
379
389 uint64_t readDeviceID(Addr flash_address) const;
390
396 void handleCommand(CfiCommand command);
397
402 uint64_t cfiQuery(Addr addr);
403};
404
405} // namespace memory
406} // namespace gem5
407
408#endif
AbstractMemory declaration.
const std::string _name
Definition named.hh:41
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition packet.hh:295
Ports are used to interface objects to each other.
Definition port.hh:62
A ResponsePort is a specialization of a port.
Definition port.hh:349
Basic support for object serialization.
Definition serialize.hh:170
An abstract memory represents a contiguous block of physical memory, with an associated address range...
uint64_t size() const
Get the memory size.
A deferred packet stores a packet along with its scheduled transmission time.
Definition cfi_mem.hh:227
DeferredPacket(PacketPtr _pkt, Tick _tick)
Definition cfi_mem.hh:234
MemoryPort(const std::string &_name, CfiMemory &_memory)
Definition cfi_mem.cc:465
AddrRangeList getAddrRanges() const override
Get a list of the non-overlapping address ranges the owner is responsible for.
Definition cfi_mem.cc:471
Tick recvAtomicBackdoor(PacketPtr pkt, MemBackdoorPtr &_backdoor) override
Receive an atomic request packet from the peer, and optionally provide a backdoor to the data being a...
Definition cfi_mem.cc:485
void recvFunctional(PacketPtr pkt) override
Receive a functional request packet from the peer.
Definition cfi_mem.cc:492
bool recvTimingReq(PacketPtr pkt) override
Receive a timing request from the peer.
Definition cfi_mem.cc:505
void recvMemBackdoorReq(const MemBackdoorReq &req, MemBackdoorPtr &_backdoor) override
Receive a request for a back door to a range of memory.
Definition cfi_mem.cc:498
void recvRespRetry() override
Called by the peer if sendTimingResp was called on this protocol (causing recvTimingResp to be called...
Definition cfi_mem.cc:511
Tick recvAtomic(PacketPtr pkt) override
Receive an atomic request packet from the peer.
Definition cfi_mem.cc:479
CfiMemory: This is modelling a flash memory adhering to the Common Flash Interface (CFI):
Definition cfi_mem.hh:72
EventFunctionWrapper releaseEvent
Definition cfi_mem.hh:309
const uint16_t bankWidth
Definition cfi_mem.hh:336
static const uint8_t STATUS_ERASE_ERROR
Possible in the status register.
Definition cfi_mem.hh:98
void recvFunctional(PacketPtr pkt)
Definition cfi_mem.cc:261
const uint16_t vendorID
Definition cfi_mem.hh:334
CfiCommand readState
Previous command (issued in the previous write cycle)
Definition cfi_mem.hh:339
Tick recvAtomic(PacketPtr pkt)
Definition cfi_mem.cc:241
uint64_t readDeviceID(Addr flash_address) const
Helper function to read the device identifier after the read state machine is put in the CfiCommand::...
Definition cfi_mem.cc:668
static const uint8_t STATUS_PROGRAM_LOCK_BIT
Definition cfi_mem.hh:101
bool isBusy
Track the state of the memory as either idle or busy, no need for an enum with only two states.
Definition cfi_mem.hh:289
EventFunctionWrapper dequeueEvent
Definition cfi_mem.hh:317
static const uint8_t STATUS_LOCK_ERROR
Definition cfi_mem.hh:99
static const uint8_t STATUS_READY
Definition cfi_mem.hh:100
std::list< DeferredPacket > packetQueue
Internal (unbounded) storage to mimic the delay caused by the actual memory access.
Definition cfi_mem.hh:276
Port & getPort(const std::string &if_name, PortID idx=InvalidPortID) override
Get a port with a given name and index.
Definition cfi_mem.cc:421
void recvMemBackdoorReq(const MemBackdoorReq &req, MemBackdoorPtr &_backdoor)
Definition cfi_mem.cc:279
ProgramBuffer programBuffer
Definition cfi_mem.hh:346
bool recvTimingReq(PacketPtr pkt)
Definition cfi_mem.cc:287
void write(PacketPtr pkt)
Write request to the CFI Memory.
Definition cfi_mem.cc:527
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition cfi_mem.cc:229
DrainState drain() override
Draining is the process of clearing out the states of SimObjects.These are the SimObjects that are pa...
Definition cfi_mem.cc:431
CfiMemory(const CfiMemoryParams &p)
Definition cfi_mem.cc:156
void handleCommand(CfiCommand command)
Service a new command issued to the flash device.
Definition cfi_mem.cc:685
const uint8_t numberOfChips
Definition cfi_mem.hh:332
Tick recvAtomicBackdoor(PacketPtr pkt, MemBackdoorPtr &_backdoor)
Definition cfi_mem.cc:251
@ BUFFER_SIZE_READ
This is not a real command, but it is used by the internal model only to represent the 2nd write cycl...
Tick getLatency() const
Detemine the latency.
Definition cfi_mem.cc:406
bool retryReq
Remember if we have to retry an outstanding request that arrived while we were busy.
Definition cfi_mem.hh:295
uint64_t cfiQuery(Addr addr)
Return the selected entry in the CFI table.
Definition cfi_mem.cc:743
void read(PacketPtr pkt)
Read request to the CFI Memory.
Definition cfi_mem.cc:632
const uint16_t deviceID
Definition cfi_mem.hh:335
uint8_t cfiQueryTable[61]
Definition cfi_mem.hh:348
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition cfi_mem.cc:454
void release()
Release the memory after being busy and send a retry if a request was rejected in the meanwhile.
Definition cfi_mem.cc:370
void cfiAccess(PacketPtr pkt)
Make a read/write access to the CFI Memory.
Definition cfi_mem.cc:517
bool retryResp
Remember if we failed to send a response and are awaiting a retry.
Definition cfi_mem.hh:301
std::unique_ptr< Packet > pendingDelete
Upstream caches need this packet until true is returned, so hold it for deletion until a subsequent c...
Definition cfi_mem.hh:330
const Tick latency_var
Fudge factor added to the latency.
Definition cfi_mem.hh:269
void dequeue()
Dequeue a packet from our internal packet queue and move it to the port where it will be sent as soon...
Definition cfi_mem.cc:381
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition cfi_mem.cc:442
const Tick latency
Latency from that a request is accepted until the response is ready to be sent.
Definition cfi_mem.hh:264
const double bandwidth
Bandwidth in ticks per byte.
Definition cfi_mem.hh:283
STL vector class.
Definition stl.hh:37
DrainState
Object drain/handover states.
Definition drain.hh:75
Bitfield< 0 > p
Bitfield< 3 > addr
Definition types.hh:84
Bitfield< 5 > lock
Definition types.hh:82
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
const PortID InvalidPortID
Definition types.hh:246
std::ostream CheckpointOut
Definition serialize.hh:66
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition types.hh:245
uint64_t Tick
Tick count type.
Definition types.hh:58
Metadata about the erase blocks in flash.
Definition cfi_mem.hh:105
uint32_t blockIdx(Addr block_address) const
Definition cfi_mem.cc:88
void erase(PacketPtr pkt)
Erase a single block.
Definition cfi_mem.cc:755
void unlock(Addr block_address)
Unlock the block pointed by the block_address parameter.
Definition cfi_mem.cc:70
bool isLocked(Addr block_address) const
Return true if the block pointed by the block_address parameter is locked.
Definition cfi_mem.cc:58
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition cfi_mem.cc:82
BlockData(const CfiMemory &_parent, ssize_t number, ssize_t size)
Definition cfi_mem.hh:106
ssize_t number() const
Number of erase blocks in flash memory.
Definition cfi_mem.hh:147
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition cfi_mem.cc:76
ssize_t size() const
Size in bytes of a single erase block.
Definition cfi_mem.hh:150
Word Buffer used by the BUFFERED PROGRAM command to write (program) chunks of words to flash.
Definition cfi_mem.hh:174
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition cfi_mem.cc:141
void setup(ssize_t buffer_size)
Start buffering.
Definition cfi_mem.cc:94
static const ssize_t MAX_BUFFER_SIZE
Definition cfi_mem.hh:177
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition cfi_mem.cc:149
std::vector< uint8_t > buffer
Definition cfi_mem.hh:211
ProgramBuffer(const CfiMemory &_parent)
Definition cfi_mem.hh:179
bool write(Addr flash_address, void *data_ptr, ssize_t size)
Write data into the buffer.
Definition cfi_mem.cc:107
Definition mem.h:38

Generated on Tue Jun 18 2024 16:24:05 for gem5 by doxygen 1.11.0