gem5 [DEVELOP-FOR-25.1]
Loading...
Searching...
No Matches
ufs_device.hh
Go to the documentation of this file.
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
38
67
141
142#ifndef __DEV_ARM_UFS_DEVICE_HH__
143#define __DEV_ARM_UFS_DEVICE_HH__
144
145#include <deque>
146#include <functional>
147
148#include "base/addr_range.hh"
149#include "base/bitfield.hh"
150#include "base/statistics.hh"
151#include "debug/UFSHostDevice.hh"
153#include "dev/arm/base_gic.hh"
154#include "dev/dma_device.hh"
155#include "dev/io_device.hh"
157#include "mem/packet.hh"
158#include "mem/packet_access.hh"
159#include "sim/serialize.hh"
160#include "sim/stats.hh"
161
162namespace gem5
163{
164
165struct UFSHostDeviceParams;
166
174{
175 public:
176
177 UFSHostDevice(const UFSHostDeviceParams &p);
178
179 DrainState drain() override;
180 void checkDrain();
181 void serialize(CheckpointOut &cp) const override;
182 void unserialize(CheckpointIn &cp) override;
183
184 private:
192 struct HCIMem
193 {
197 uint32_t HCCAP;
198 uint32_t HCversion;
199 uint32_t HCHCDDID;
200 uint32_t HCHCPMID;
201
209 uint32_t ORUECPA;
210 uint32_t ORUECDL;
211 uint32_t ORUECN;
212 uint32_t ORUECT;
213 uint32_t ORUECDME;
214 uint32_t ORUTRIACR;
215
220
224 uint32_t TRUTRLBA;
225 uint32_t TRUTRLBAU;
226 uint32_t TRUTRLDBR;
227 uint32_t TRUTRLCLR;
228 uint32_t TRUTRLRSR;
229
233 uint32_t TMUTMRLBA;
234 uint32_t TMUTMRLBAU;
235 uint32_t TMUTMRLDBR;
236 uint32_t TMUTMRLCLR;
237 uint32_t TMUTMRLRSR;
238
242 uint32_t CMDUICCMDR;
243 uint32_t CMDUCMDARG1;
244 uint32_t CMDUCMDARG2;
245 uint32_t CMDUCMDARG3;
246 };
247
254
262 {
263 uint32_t dWord0;
264 uint32_t dWord1;
265 uint32_t dWord2;
266 };
267
277 {
280 uint32_t reserved[4];
281 uint16_t senseDataLen;
282 uint8_t senseData[18];
283 };
284
294 {
296 uint32_t inputParam1;
297 uint32_t inputParam2;
298 uint32_t inputParam3;
299 uint32_t reserved[2];
300 };
301
310 {
311 uint32_t baseAddr;
312 uint32_t upperAddr;
313 uint32_t reserved;
314 uint32_t size;
315 };
316
325 {
326 uint8_t commandUPIU[128];
327 uint8_t responseUPIU[128];
329 };
330
341
353 {
354
363 {
364 uint32_t dWord0;
365 uint32_t dWord1;
366 uint32_t dWord2;
367 uint32_t dWord3;
369
370 /* DW 4-5*/
373
374 /* DW 6 */
377
378 /* DW 7 */
381 };
382
388 {
389 void reset() {
390 memset(static_cast<void*>(this), 0, sizeof(*this));
391 }
392
393 uint8_t status;
394 uint32_t msgSize;
395 uint8_t LUN;
397 uint8_t senseSize;
398 uint8_t expectMore;//0x01 is for writes, 0x02 is for reads
399 uint64_t offset;
400 uint8_t senseCode[19];
401 };
402
408 struct LUNInfo
409 {
410 uint32_t dWord0;
411 uint32_t dWord1;
412 uint32_t vendor0;
413 uint32_t vendor1;
414 uint32_t product0;
415 uint32_t product1;
416 uint32_t product2;
417 uint32_t product3;
419 };
420
434
441 {
442 std::vector <uint8_t> buffer;
443 uint32_t size;
444 uint64_t offset;
445 uint32_t filePointer;
446 uint32_t lunID;
447 };
448
464
469 {
471 uint32_t mask;
473 uint32_t size;
474 uint32_t done;
475 uint32_t lun_id;
476 };
477
482 {
484 uint32_t mask;
486 uint32_t size;
487 bool done;
488 };
489
495 {
499 uint32_t finalSize;
500 std::vector <uint8_t> destination;
501 uint32_t done;
502 };
503
509 {
512 uint32_t size;
513 uint32_t LUN;
514 };
515
554
561 {
562 public:
563 using Callback = std::function<void()>;
564
568 UFSSCSIDevice(const UFSHostDeviceParams &p, uint32_t lun_id,
569 const Callback &transfer_cb, const Callback &read_cb);
571
577 struct SCSIReply SCSICMDHandle(uint32_t* SCSI_msg);
578
582
587 void readFlash(uint8_t* readaddr, uint64_t offset, uint32_t size);
588
593 void writeFlash(uint8_t* writeaddr, uint64_t offset, uint32_t size);
594
600 bool finishedCommand() const {return transferCompleted;};
601
607
615 bool finishedRead() const {return readCompleted;};
616
622
628 void SSDReadStart(uint32_t total_read);
629 void SSDWriteStart();
630
636 void setTotalWrite(uint32_t total_write) {totalWrite = total_write;};
637
642
648
653
659
667
668 private:
675 void readCallback();
676
681 void SSDReadDone();
682
686 void SSDWriteDone();
687
693 void statusCheck(uint8_t status, uint8_t* sensecodelist);
694
698 void setSignal() {transferCompleted = true;};
699
703 void setReadSignal() {readCompleted = true;};
704
712
716 const uint32_t blkSize;
717 const uint32_t lunAvail;
718 const uint64_t diskSize;
719 const uint32_t capacityLower;
720 const uint32_t capacityUpper;
721
727 const uint32_t lunID;
728
736
740 uint32_t totalRead;
741 uint32_t totalWrite;
742
748
754
760
761 /*
762 * Default response header layout. For more information refer to
763 * chapter 7 http://www.jedec.org/standards-documents/results/jesd220
764 */
765 static const unsigned int UPIUHeaderDataIndWord0 = 0x0000C022;
766 static const unsigned int UPIUHeaderDataIndWord1 = 0x00000000;
767 static const unsigned int UPIUHeaderDataIndWord2 = 0x40000000;
768
769 /*
770 * SCSI mode pages values assigned in ufs_device.cc
771 * The mode pages give device specific information via the SCSI
772 * protocol. They are defined in
773 * http://www.jedec.org/standards-documents/results/jesd220
774 */
775 static const unsigned int controlPage[3];
776 static const unsigned int recoveryPage[3];
777 static const unsigned int cachingPage[5];
778
779 /*
780 * SCSI command set; defined in
781 * http://www.jedec.org/standards-documents/results/jesd220
782 */
784 {
786 SCSIRead6 = 0x08,
801 //UFS SCSI additional command set for full functionality
806 SCSIUnmap = 0x42,
809 //SCSI commands not supported by UFS; but Linux send them anyway
811 };
812
813 /*
814 * SCSI status codes; defined in
815 * http://www.jedec.org/standards-documents/results/jesd220
816 */
831
832 /*
833 * SCSI sense codes; defined in
834 * http://www.jedec.org/standards-documents/results/jesd220
835 */
851
852 };
853
854 //All access functions are inherrited; no need to make them public
858 AddrRangeList getAddrRanges() const override;
859
863 Tick read(PacketPtr pkt) override;
864 Tick write(PacketPtr pkt) override;
865 // end of access functions
866
870 void setValues();
871
885 void requestHandler();
886
891 void commandHandler();
892
897 void taskStart();
898
904 void taskHandler(struct UTPUPIUTaskReq* request_in,
905 uint32_t req_pos, Addr finaladdress, uint32_t finalsize);
906
911 void transferStart();
912
922 void transferHandler(struct UTPTransferReqDesc*
923 request_in, int req_pos, Addr finaladdress,
924 uint32_t finalsize, uint32_t done);
925
930 void SCSIStart();
931
936 void SCSIResume(uint32_t lun_id);
937
941 void LUNSignal();
942
947 void transferDone(Addr responseStartAddr, uint32_t req_pos,
948 struct UTPUPIURSP request_out, uint32_t size,
949 Addr address, uint8_t* destination, bool finished,
950 uint32_t lun_id);
955 void finalUTP();
956
960 void clearInterrupt();
961 void generateInterrupt();
962
970 void writeDevice(Event* additional_action, bool toDisk, Addr start,
971 int size, uint8_t* destination, uint64_t SCSIDiskOffset,
972 uint32_t lun_id);
973 void readDevice(bool lastTransfer, Addr SCSIStart, uint32_t SCSISize,
974 uint8_t* SCSIDestination, bool no_cache,
975 Event* additional_action);
976
983 void manageWriteTransfer(uint8_t LUN, uint64_t offset, uint32_t
984 sg_table_length, struct UFSHCDSGEntry* sglist);
985 void manageReadTransfer(uint32_t size, uint32_t LUN, uint64_t offset,
986 uint32_t sg_table_length,
987 struct UFSHCDSGEntry* sglist);
988
995 void readDone();
996
1003 void writeDone();
1004
1011 void readCallback();
1012
1020 void readGarbage();
1021
1028 const int intNum;
1030 const uint32_t lunAvail;
1031 const uint8_t UFSSlots;
1032
1037
1043
1055
1063 uint32_t countInt;
1064
1075
1083
1090
1097
1105
1114
1126
1131
1136
1141
1146
1151
1163
1175
1180
1185
1193
1197 static const unsigned int UTPTransferREQCOMPL = 0x01;//UFS_BIT(0)
1198 static const unsigned int UTPTaskREQCOMPL = 0x200;//UFS_BIT(9)
1199 static const unsigned int UICCommandCOMPL = 0x400;//UFS_BIT(10)
1200 static const unsigned int UICCommandReady = 0x08;//UFS_BIT(3)
1201
1202 /*
1203 * UFSHCI Registers; please refer to
1204 * http://www.jedec.org/standards-documents/results/jesd223
1205 * for their definition.
1206 */
1238};
1239
1240} // namespace gem5
1241
1242#endif //__DEV_ARM_UFS_DEVICE_HH__
Base class for ARM GIC implementations.
This is an interface between the disk interface (which will handle the disk data transactions) and th...
Basic interface for accessing a disk image.
Definition disk_image.hh:53
DmaDevice(const Params &p)
static const unsigned int cachingPage[5]
void SSDWriteStart()
SSD write start.
bool finishedRead() const
Finished read.
transferDoneInfo transferInfo
End of transfer information.
bool finishedCommand() const
finished command.
void SSDReadDone()
SSD Read done; Determines if the final callback of the transaction should be made at the end of a rea...
static const unsigned int controlPage[3]
These pages are SCSI specific.
std::function< void()> Callback
void setSignal()
set signal to indicate that the transaction has been completed.
UFSSCSIDevice(const UFSHostDeviceParams &p, uint32_t lun_id, const Callback &transfer_cb, const Callback &read_cb)
Constructor and destructor.
Definition ufs_device.cc:80
bool transferCompleted
Signals to Host layer 1: signal for transaction completion 2: signal for read action completion.
void writeFlash(uint8_t *writeaddr, uint64_t offset, uint32_t size)
Write flash.
static const unsigned int UPIUHeaderDataIndWord0
std::deque< struct transferInfo > SSDWriteDoneInfo
SSDWriteDoneInfo: Structure from dma to disk, that contains data, and helper info to get it to the ri...
void readFlash(uint8_t *readaddr, uint64_t offset, uint32_t size)
Disk access functions.
void statusCheck(uint8_t status, uint8_t *sensecodelist)
Status of SCSI.
const uint32_t blkSize
Logic unit dimensions.
void setReadSignal()
set signal to indicate that the read action has been completed
Callback signalDone
Callbacks between Host and Device.
std::deque< struct transferInfo > SSDReadInfo
SSDReadInfo: Structure from disk to dma, that contains data, and helper info to get it to the right p...
std::deque< struct SCSIResumeInfo > SCSIInfoQueue
Information message queues, as there can be multiple messages queued for handling in this system.
Callback memReadCallback
Callbacks between Device and Memory.
static const unsigned int recoveryPage[3]
void setTotalWrite(uint32_t total_write)
Sets total amount of write transactions that needs to be made.
DiskImage * flashDisk
The objects this model links to.
struct SCSIReply SCSICMDHandle(uint32_t *SCSI_msg)
SCSI command handle function; determines what the command is and returns a reply structure that allow...
struct LUNInfo lunInfo
Logic unit info; needed for SCSI Info messages and LU identification.
static const unsigned int UPIUHeaderDataIndWord2
void clearReadSignal()
Clear signal.
void readCallback()
Functions to indicate that the action to the SSD has completed.
static const unsigned int UPIUHeaderDataIndWord1
uint32_t totalRead
Total amount transactions that need to be made.
void SSDReadStart(uint32_t total_read)
Start the transactions to (and from) the disk The host will queue all the transactions.
uint32_t amountOfWriteTransfers
transaction progress tracking
void SSDWriteDone()
SSD Write Done; This is the callback function for the memory model.
int readPendingNum
Track number of DMA transactions in progress.
void taskHandler(struct UTPUPIUTaskReq *request_in, uint32_t req_pos, Addr finaladdress, uint32_t finalsize)
Task handler function.
std::deque< EventFunctionWrapper > taskEventQueue
Multiple tasks transfers can be scheduled at once for the device, the only thing we know for sure abo...
void generateInterrupt()
set interrupt and sort out the doorbell register.
void writeDone()
Write done After a DMA write with data intended for the disk, this function is called.
std::deque< struct taskStart > taskInfo
When a task/transfer is started it needs information about the task/transfer it is about to perform.
std::deque< struct transferInfo > SSDWriteinfo
Information from DMA transaction to disk.
static const unsigned int UICCommandReady
std::deque< EventFunctionWrapper > transferEventQueue
EventFunctionWrapper SCSIResumeEvent
The events that control the functionality.
void serialize(CheckpointOut &cp) const override
Serialize; needed to make checkpoints.
void transferHandler(struct UTPTransferReqDesc *request_in, int req_pos, Addr finaladdress, uint32_t finalsize, uint32_t done)
Transfer handler function.
Tick transactionStart[32]
Helper for latency stats These variables keep track of the latency for every doorbell.
const Addr pioAddr
Host controller information.
void commandHandler()
Command handler function.
HCIMem UFSHCIMem
Host controller memory.
struct SCSIReply request_out_datain
SCSI reply structure, used for direct answering.
static const unsigned int UTPTaskREQCOMPL
void clearInterrupt()
Interrupt control functions.
static const unsigned int UTPTransferREQCOMPL
Bits of interest within UFS data packages.
static const unsigned int UICCommandCOMPL
void writeDevice(Event *additional_action, bool toDisk, Addr start, int size, uint8_t *destination, uint64_t SCSIDiskOffset, uint32_t lun_id)
DMA transfer functions These allow the host to push/pull the data to the memory The provided event in...
void finalUTP()
final UTP, sends the last acknowledge data structure to the system; prepares the clean up functions.
std::deque< struct writeToDiskBurst > dmaWriteInfo
Information to get a DMA transaction.
uint32_t transferTrack
Track the transfer This is allows the driver to "group" certain transfers together by using a tag in ...
DrainState drain() override
Drain; needed to enable checkpoints.
void setValues()
Initialization function.
void requestHandler()
Handler functions.
void unserialize(CheckpointIn &cp) override
Unserialize; needed to restore from checkpoints.
void manageWriteTransfer(uint8_t LUN, uint64_t offset, uint32_t sg_table_length, struct UFSHCDSGEntry *sglist)
Disk transfer management functions these set up the queues, and initiated them, leading to the data t...
struct SCSIResumeInfo SCSIInfo
SCSI resume info information structure for SCSI resume.
Tick read(PacketPtr pkt) override
register access functions
struct UFSHostDeviceStats stats
RequestHandler stats.
void readGarbage()
Read garbage A read from disk data structure can vary in size and is therefor allocated on creation.
std::deque< struct transferStart > transferEnd
To finish the transaction one needs information about the original message.
std::deque< EventFunctionWrapper > readDoneEvent
Transfer flow events Basically these events form two queues, one from memory to UFS device (DMA) and ...
uint32_t countInt
interrupt verification This keeps track of the number of interrupts generated.
std::deque< struct UTPTransferReqDesc * > garbage
garbage queue, ensure clearing of the allocated memory
uint8_t activeDoorbells
Statistics helper variables Active doorbells indicates how many doorbells are in teh process of being...
void manageReadTransfer(uint32_t size, uint32_t LUN, uint64_t offset, uint32_t sg_table_length, struct UFSHCDSGEntry *sglist)
Manage read transfer.
std::vector< UFSSCSIDevice * > UFSDevice
logic units connected to the UFS Host device Note again that the "device" as such is represented by o...
std::deque< struct transferInfo > SSDReadPending
Information from the Disk, waiting to be pushed to the DMA.
void SCSIResume(uint32_t lun_id)
Starts the scsi handling function in the apropriate Logic unit, prepares the right data transfer sche...
std::deque< EventFunctionWrapper > writeDoneEvent
Tick write(PacketPtr pkt) override
UFSHCD write function.
std::deque< struct transferStart > transferStartInfo
AddrRangeList getAddrRanges() const override
Address range functions.
std::deque< EventFunctionWrapper > readGarbageEventQueue
Event after a read to clean up the UTP data structures.
EventFunctionWrapper UTPEvent
Wait for the moment where we can send the last frame.
void readCallback()
Read callback Call back function for the logic units to indicate the completion of a read action.
UFSHostDevice(const UFSHostDeviceParams &p)
Constructor for the UFS Host device.
void transferStart()
Transfer Start function.
void taskStart()
Task Start function.
void transferDone(Addr responseStartAddr, uint32_t req_pos, struct UTPUPIURSP request_out, uint32_t size, Addr address, uint8_t *destination, bool finished, uint32_t lun_id)
transfer done, the beginning of the final stage of the transfer.
void LUNSignal()
LU callback function to indicate that the action has completed.
void readDone()
Read done Started at the end of a transaction after the last read action.
void readDevice(bool lastTransfer, Addr SCSIStart, uint32_t SCSISize, uint8_t *SCSIDestination, bool no_cache, Event *additional_action)
Dma transaction function: read device.
void checkDrain()
Checkdrain; needed to enable checkpoints.
const uint32_t lunAvail
const uint8_t UFSSlots
void SCSIStart()
Transfer SCSI function.
A stat that calculates the per tick average of a value.
A formula for statistics that is calculated when printed.
Statistics container.
Definition group.hh:93
A simple histogram stat.
This is a simple scalar statistic, like a counter.
STL deque class.
Definition stl.hh:44
STL vector class.
Definition stl.hh:37
Disk Image Interfaces.
std::list< AddrRange > AddrRangeList
Convenience typedef for a collection of address ranges.
Definition addr_range.hh:64
DrainState
Object drain/handover states.
Definition drain.hh:76
SimObject(const Params &p)
Definition sim_object.cc:58
Bitfield< 23, 0 > offset
Definition types.hh:144
Bitfield< 5, 0 > status
Bitfield< 0 > p
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
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
uint64_t Tick
Tick count type.
Definition types.hh:58
Packet * PacketPtr
output header
Definition nop.cc:36
Declaration of the Packet class.
Declaration of Statistics objects.
Host Controller Interface This is a set of registers that allow the driver to control the transaction...
uint32_t TMUTMRLBA
Task control registers.
uint32_t TRUTRLBA
Transfer control registers.
uint32_t ORInterruptStatus
Operation and runtime registers.
uint32_t CMDUICCMDR
Command registers.
uint32_t vendorSpecific
vendor specific register
uint32_t HCCAP
Specify the host capabilities.
Logic unit information structure.
SCSI reply structure.
After a SCSI command has been identified, the SCSI resume function will handle it.
struct UTPTransferReqDesc * RequestIn
std::vector< uint8_t > destination
struct UFSHCDSGEntry - UFSHCI PRD Entry baseAddr: Lower 32bit physical address DW-0 upperAddr: Upper ...
statistics::Average averageSCSIQueue
Average Queue lengths.
statistics::Formula averageReadSSDBW
Average bandwidth for reads and writes.
statistics::Scalar totalWriteDiskTransactions
UFSHostDeviceStats(UFSHostDevice *parent)
Amount of data read/written.
statistics::Histogram transactionLatency
Histogram of latencies.
statistics::Scalar totalReadSSD
Amount of data read/written.
statistics::Formula curDoorbell
Number of doorbells rung.
statistics::Scalar currentSCSIQueue
Queue lengths.
std::vector< uint32_t > dataMsg
struct UTPUPIUHeader header
struct UTPTransferCMDDesc - UFS Commad Descriptor structure commandUPIU: Command UPIU Frame address r...
struct UFSHCDSGEntry PRDTable[128]
struct RequestDescHeader dword0: Descriptor Header DW0 dword1: Descriptor Header DW1 dword2: Descript...
struct UTPTransferReqDesc - UTRD structure header: UTRD header DW-0 to DW-3 commandDescBaseAddrLo: UC...
All the data structures are defined in the UFS standard This standard be found at the JEDEC website f...
struct UTPUPIURSP - Response UPIU structure header: UPIU header DW-0 to DW-2 residualTransferCount: R...
struct UTPUPIUHeader header
struct UTPUPIUTaskReq - Task request UPIU structure header - UPIU header structure DW0 to DW-2 inputP...
Task start information.
struct UTPUPIUTaskReq destination
transfer completion info.
Different events, and scenarios require different types of information.
std::vector< uint8_t > buffer
Transfer start information.
struct UTPTransferReqDesc * destination
Disk transfer burst information.

Generated on Mon Oct 27 2025 04:13:01 for gem5 by doxygen 1.14.0