gem5 v24.0.0.0
Loading...
Searching...
No Matches
ide_disk.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2013 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) 2004-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
45#ifndef __DEV_STORAGE_IDE_DISK_HH__
46#define __DEV_STORAGE_IDE_DISK_HH__
47
48#include "base/statistics.hh"
49#include "dev/io_device.hh"
54#include "params/IdeDisk.hh"
55#include "sim/eventq.hh"
56
57namespace gem5
58{
59
60class ChunkGenerator;
61
62#define DMA_BACKOFF_PERIOD 200
63
64#define MAX_DMA_SIZE 0x20000 // 128K
65#define MAX_SINGLE_DMA_SIZE 0x10000
66#define MAX_MULTSECT (128)
67
68#define PRD_BASE_MASK 0xfffffffe
69#define PRD_COUNT_MASK 0xfffe
70#define PRD_EOT_MASK 0x8000
71
73{
74 uint32_t baseAddr;
75 uint16_t byteCount;
76 uint16_t endOfTable;
77};
78
80{
81 public:
83
84 uint32_t getBaseAddr()
85 {
86 return (entry.baseAddr & PRD_BASE_MASK);
87 }
88
89 uint32_t getByteCount()
90 {
91 return ((entry.byteCount == 0) ? MAX_SINGLE_DMA_SIZE :
93 }
94
95 uint16_t getEOT()
96 {
97 return (entry.endOfTable & PRD_EOT_MASK);
98 }
99};
100
101#define DATA_OFFSET (0)
102#define ERROR_OFFSET (1)
103#define FEATURES_OFFSET (1)
104#define NSECTOR_OFFSET (2)
105#define SECTOR_OFFSET (3)
106#define LCYL_OFFSET (4)
107#define HCYL_OFFSET (5)
108#define SELECT_OFFSET (6)
109#define DRIVE_OFFSET (6)
110#define STATUS_OFFSET (7)
111#define COMMAND_OFFSET (7)
112
113#define CONTROL_OFFSET (2)
114#define ALTSTAT_OFFSET (2)
115
116#define SELECT_DEV_BIT 0x10
117#define CONTROL_RST_BIT 0x04
118#define CONTROL_IEN_BIT 0x02
119#define STATUS_BSY_BIT 0x80
120#define STATUS_DRDY_BIT 0x40
121#define STATUS_DRQ_BIT 0x08
122#define STATUS_SEEK_BIT 0x10
123#define STATUS_DF_BIT 0x20
124#define DRIVE_LBA_BIT 0x40
125
126#define DEV0 (0)
127#define DEV1 (1)
128
130{
131 uint16_t data;
132 uint8_t error;
133 uint8_t sec_count;
134 uint8_t sec_num;
135 uint8_t cyl_low;
136 uint8_t cyl_high;
137 union
138 {
139 uint8_t drive;
140 uint8_t head;
141 };
142 uint8_t command;
143};
144
155
174
176{
177 // Device idle
181
182 // Software reset
184
185 // Non-data commands
187
188 // PIO data-in (data to host)
192
193 // PIO data-out (data from host)
197
198 // DMA protocol
203
210
211class IdeController;
212
216class IdeDisk : public SimObject
217{
218 protected:
220 IdeController *ctrl = nullptr;
225
226 protected:
229
230 private:
234 uint8_t *dataBuffer;
236 uint32_t cmdBytes;
238 uint32_t cmdBytesLeft;
240 uint32_t drqBytesLeft;
242 uint32_t curSector;
246 uint8_t status;
258 uint32_t curPrdAddr;
262 int devID;
267
279
280 public:
281 typedef IdeDiskParams Params;
282 IdeDisk(const Params &p);
283
287 ~IdeDisk();
288
292 void reset(int id);
293
298 void
299 setChannel(IdeController::Channel *_channel, Addr chunk_bytes)
300 {
301 panic_if(channel, "Cannot change the channel once set!");
302 channel = _channel;
304 chunkBytes = chunk_bytes;
305 }
306
307 // Device register read/write
308 void readCommand(const Addr offset, int size, uint8_t *data);
309 void readControl(const Addr offset, int size, uint8_t *data);
310 void writeCommand(const Addr offset, int size, const uint8_t *data);
311 void writeControl(const Addr offset, int size, const uint8_t *data);
312
313 // Start/abort functions
314 void startDma(const uint32_t &prdTableBase);
315 void abortDma();
316
317 private:
318 void startCommand();
319
320 // Interrupt management
321 void postInterrupt();
322 void clearInterrupt();
323
324 // DMA stuff
325 void doDmaTransfer();
327
328 void doDmaDataRead();
329
330 void doDmaRead();
333
334 void doDmaDataWrite();
335
336 void doDmaWrite();
339
340 void dmaPrdReadDone();
342
343 void dmaReadDone();
345
346 void dmaWriteDone();
348
349 // Disk image read/write
350 void readDisk(uint32_t sector, uint8_t *data);
351 void writeDisk(uint32_t sector, uint8_t *data);
352
353 // State machine management
354 void updateState(DevAction_t action);
355
356 // Utility functions
357 bool isBSYSet() { return (status & STATUS_BSY_BIT); }
358 bool isIENSet() { return nIENBit; }
359 bool isDEVSelect();
360
361 void
363 {
364 // clear out the status byte
365 status = 0;
366 // set the DRDY bit
368 // set the SEEK bit
370 }
371
372 uint32_t
374 {
375 return ((cmdReg.head & 0xf) << 24) |
376 (cmdReg.cyl_high << 16) |
377 (cmdReg.cyl_low << 8) |
378 (cmdReg.sec_num);
379 }
380
381 inline Addr pciToDma(Addr pciAddr);
382
383 void serialize(CheckpointOut &cp) const override;
384 void unserialize(CheckpointIn &cp) override;
385};
386
387} // namespace gem5
388
389#endif // __DEV_STORAGE_IDE_DISK_HH__
const char data[]
This class takes an arbitrary memory region (address/length pair) and generates a series of appropria...
Basic interface for accessing a disk image.
Definition disk_image.hh:53
IdeController * controller() const
Definition ide_ctrl.hh:136
Device model for an Intel PIIX4 IDE controller.
Definition ide_ctrl.hh:53
IDE Disk device model.
Definition ide_disk.hh:217
EventFunctionWrapper dmaReadEvent
Definition ide_disk.hh:344
void startCommand()
Definition ide_disk.cc:611
uint32_t drqBytesLeft
Number of bytes left in DRQ block.
Definition ide_disk.hh:240
void dmaReadDone()
Definition ide_disk.cc:450
void doDmaTransfer()
Definition ide_disk.cc:334
EventFunctionWrapper dmaPrdReadEvent
Definition ide_disk.hh:341
void setChannel(IdeController::Channel *_channel, Addr chunk_bytes)
Set the controller for this device.
Definition ide_disk.hh:299
void doDmaDataRead()
Definition ide_disk.cc:381
void startDma(const uint32_t &prdTableBase)
Definition ide_disk.cc:581
void doDmaDataWrite()
Definition ide_disk.cc:473
void abortDma()
Definition ide_disk.cc:599
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition ide_disk.cc:1068
~IdeDisk()
Delete the data buffer.
Definition ide_disk.cc:138
void writeDisk(uint32_t sector, uint8_t *data)
Definition ide_disk.cc:567
bool isDEVSelect()
Definition ide_disk.cc:189
bool nIENBit
Interrupt enable bit.
Definition ide_disk.hh:248
uint32_t cmdBytes
Number of bytes in command data transfer.
Definition ide_disk.hh:236
void readControl(const Addr offset, int size, uint8_t *data)
Definition ide_disk.cc:252
IdeController * ctrl
The IDE controller for this disk.
Definition ide_disk.hh:220
void writeCommand(const Addr offset, int size, const uint8_t *data)
Definition ide_disk.cc:262
uint32_t curPrdAddr
PRD table base address.
Definition ide_disk.hh:258
bool isIENSet()
Definition ide_disk.hh:358
void clearInterrupt()
Definition ide_disk.cc:752
void dmaPrdReadDone()
Definition ide_disk.cc:357
struct ataparams driveID
Drive identification structure for this disk.
Definition ide_disk.hh:232
void postInterrupt()
Definition ide_disk.cc:739
IdeDisk(const Params &p)
Definition ide_disk.cc:66
uint8_t * dataBuffer
Data buffer for transfers.
Definition ide_disk.hh:234
ChunkGenerator * dmaWriteCG
Definition ide_disk.hh:337
PrdTableEntry curPrd
PRD entry.
Definition ide_disk.hh:260
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition ide_disk.cc:1146
IdeDiskParams Params
Definition ide_disk.hh:281
EventFunctionWrapper dmaWriteEvent
Definition ide_disk.hh:347
uint32_t curSector
Current sector in access.
Definition ide_disk.hh:242
bool dmaRead
Dma transaction is a read.
Definition ide_disk.hh:254
bool pendingInterrupt
Interrupt pending.
Definition ide_disk.hh:264
DiskImage * image
The image that contains the data of this disk.
Definition ide_disk.hh:224
void doDmaRead()
Definition ide_disk.cc:411
EventFunctionWrapper dmaWriteWaitEvent
Definition ide_disk.hh:338
void doDmaWrite()
Definition ide_disk.cc:496
gem5::IdeDisk::IdeDiskStats ideDiskStats
ChunkGenerator * dmaReadCG
Definition ide_disk.hh:331
void readDisk(uint32_t sector, uint8_t *data)
Definition ide_disk.cc:557
DevState_t devState
Device state.
Definition ide_disk.hh:250
int diskDelay
The disk delay in microseconds.
Definition ide_disk.hh:228
EventFunctionWrapper dmaTransferEvent
Definition ide_disk.hh:326
bool isBSYSet()
Definition ide_disk.hh:357
void writeControl(const Addr offset, int size, const uint8_t *data)
Definition ide_disk.cc:310
bool dmaAborted
DMA Aborted.
Definition ide_disk.hh:266
void dmaWriteDone()
Definition ide_disk.cc:537
void setComplete()
Definition ide_disk.hh:362
uint8_t status
Status register.
Definition ide_disk.hh:246
Addr pciToDma(Addr pciAddr)
Definition ide_disk.cc:195
Addr chunkBytes
Size of chunks to DMA.
Definition ide_disk.hh:256
IdeController::Channel * channel
The channel this disk is connected to.
Definition ide_disk.hh:222
DmaState_t dmaState
Dma state.
Definition ide_disk.hh:252
void readCommand(const Addr offset, int size, uint8_t *data)
Definition ide_disk.cc:206
uint32_t cmdBytesLeft
Number of bytes left in command data transfer.
Definition ide_disk.hh:238
EventFunctionWrapper dmaReadWaitEvent
Definition ide_disk.hh:332
CommandReg_t cmdReg
Command block registers.
Definition ide_disk.hh:244
int devID
Device ID (device0=0/device1=1)
Definition ide_disk.hh:262
void updateState(DevAction_t action)
Definition ide_disk.cc:768
uint32_t getLBABase()
Definition ide_disk.hh:373
uint32_t getByteCount()
Definition ide_disk.hh:89
uint16_t getEOT()
Definition ide_disk.hh:95
PrdEntry_t entry
Definition ide_disk.hh:82
uint32_t getBaseAddr()
Definition ide_disk.hh:84
Abstract superclass for simulation objects.
Statistics container.
Definition group.hh:93
This is a simple scalar statistic, like a counter.
Disk Image Interfaces.
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition logging.hh:214
#define PRD_BASE_MASK
Definition ide_disk.hh:68
#define STATUS_BSY_BIT
Definition ide_disk.hh:119
#define STATUS_SEEK_BIT
Definition ide_disk.hh:122
#define PRD_EOT_MASK
Definition ide_disk.hh:70
#define STATUS_DRDY_BIT
Definition ide_disk.hh:120
#define MAX_SINGLE_DMA_SIZE
Definition ide_disk.hh:65
#define PRD_COUNT_MASK
Definition ide_disk.hh:69
Bitfield< 23, 0 > offset
Definition types.hh:144
Bitfield< 0 > p
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
DevAction_t
Definition ide_disk.hh:157
@ ACT_NONE
Definition ide_disk.hh:158
@ ACT_CMD_ERROR
Definition ide_disk.hh:161
@ ACT_DMA_DONE
Definition ide_disk.hh:170
@ ACT_CMD_COMPLETE
Definition ide_disk.hh:160
@ ACT_DMA_READY
Definition ide_disk.hh:169
@ ACT_DATA_READY
Definition ide_disk.hh:164
@ ACT_DATA_WRITE_BYTE
Definition ide_disk.hh:167
@ ACT_SELECT_WRITE
Definition ide_disk.hh:162
@ ACT_DATA_READ_BYTE
Definition ide_disk.hh:165
@ ACT_SRST_SET
Definition ide_disk.hh:171
@ ACT_CMD_WRITE
Definition ide_disk.hh:159
@ ACT_SRST_CLEAR
Definition ide_disk.hh:172
@ ACT_STAT_READ
Definition ide_disk.hh:163
@ ACT_DATA_READ_SHORT
Definition ide_disk.hh:166
@ ACT_DATA_WRITE_SHORT
Definition ide_disk.hh:168
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
@ DmaRead
Definition ide_disk.hh:152
@ DmaWrite
Definition ide_disk.hh:153
@ ReadWait
Definition ide_disk.hh:149
@ PrdRead
Definition ide_disk.hh:151
@ None
Definition ide_disk.hh:147
@ WriteWait
Definition ide_disk.hh:150
@ Transfer
Definition ide_disk.hh:148
DevState_t
Definition ide_disk.hh:176
@ Device_Idle_NS
Definition ide_disk.hh:180
@ Device_Dma_Abort
Definition ide_disk.hh:201
@ Device_Idle_SI
Definition ide_disk.hh:179
@ Data_Ready_INTRQ_Out
Definition ide_disk.hh:195
@ Transfer_Data_Dma
Definition ide_disk.hh:200
@ Device_Srst
Definition ide_disk.hh:183
@ Prepare_Data_Out
Definition ide_disk.hh:194
@ Prepare_Data_In
Definition ide_disk.hh:189
@ Command_Execution
Definition ide_disk.hh:186
@ Device_Idle_S
Definition ide_disk.hh:178
@ Data_Ready_INTRQ_In
Definition ide_disk.hh:190
@ Transfer_Data_Out
Definition ide_disk.hh:196
@ Prepare_Data_Dma
Definition ide_disk.hh:199
@ Transfer_Data_In
Definition ide_disk.hh:191
DmaState_t
Definition ide_disk.hh:205
@ Dma_Start
Definition ide_disk.hh:207
@ Dma_Idle
Definition ide_disk.hh:206
@ Dma_Transfer
Definition ide_disk.hh:208
Declaration of Statistics objects.
Simple PCI IDE controller with bus mastering capability and UDMA modeled after controller in the Inte...
statistics::Scalar dmaWriteTxs
Definition ide_disk.hh:277
statistics::Scalar dmaWriteBytes
Definition ide_disk.hh:276
IdeDiskStats(statistics::Group *parent)
Definition ide_disk.cc:393
statistics::Scalar dmaWriteFullPages
Definition ide_disk.hh:275
statistics::Scalar dmaReadBytes
Definition ide_disk.hh:273
statistics::Scalar dmaReadFullPages
Definition ide_disk.hh:272
statistics::Scalar dmaReadTxs
Definition ide_disk.hh:274
uint16_t endOfTable
Definition ide_disk.hh:76
uint32_t baseAddr
Definition ide_disk.hh:74
uint16_t byteCount
Definition ide_disk.hh:75

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