gem5  v20.0.0.3
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"
51 #include "dev/storage/ide_atareg.h"
52 #include "dev/storage/ide_ctrl.hh"
53 #include "dev/storage/ide_wdcreg.h"
54 #include "params/IdeDisk.hh"
55 #include "sim/eventq.hh"
56 
57 class ChunkGenerator;
58 
59 #define DMA_BACKOFF_PERIOD 200
60 
61 #define MAX_DMA_SIZE 0x20000 // 128K
62 #define MAX_SINGLE_DMA_SIZE 0x10000
63 #define MAX_MULTSECT (128)
64 
65 #define PRD_BASE_MASK 0xfffffffe
66 #define PRD_COUNT_MASK 0xfffe
67 #define PRD_EOT_MASK 0x8000
68 
69 typedef struct PrdEntry {
70  uint32_t baseAddr;
71  uint16_t byteCount;
72  uint16_t endOfTable;
73 } PrdEntry_t;
74 
76  public:
78 
79  uint32_t getBaseAddr()
80  {
81  return (entry.baseAddr & PRD_BASE_MASK);
82  }
83 
84  uint32_t getByteCount()
85  {
86  return ((entry.byteCount == 0) ? MAX_SINGLE_DMA_SIZE :
87  (entry.byteCount & PRD_COUNT_MASK));
88  }
89 
90  uint16_t getEOT()
91  {
92  return (entry.endOfTable & PRD_EOT_MASK);
93  }
94 };
95 
96 #define DATA_OFFSET (0)
97 #define ERROR_OFFSET (1)
98 #define FEATURES_OFFSET (1)
99 #define NSECTOR_OFFSET (2)
100 #define SECTOR_OFFSET (3)
101 #define LCYL_OFFSET (4)
102 #define HCYL_OFFSET (5)
103 #define SELECT_OFFSET (6)
104 #define DRIVE_OFFSET (6)
105 #define STATUS_OFFSET (7)
106 #define COMMAND_OFFSET (7)
107 
108 #define CONTROL_OFFSET (2)
109 #define ALTSTAT_OFFSET (2)
110 
111 #define SELECT_DEV_BIT 0x10
112 #define CONTROL_RST_BIT 0x04
113 #define CONTROL_IEN_BIT 0x02
114 #define STATUS_BSY_BIT 0x80
115 #define STATUS_DRDY_BIT 0x40
116 #define STATUS_DRQ_BIT 0x08
117 #define STATUS_SEEK_BIT 0x10
118 #define STATUS_DF_BIT 0x20
119 #define DRIVE_LBA_BIT 0x40
120 
121 #define DEV0 (0)
122 #define DEV1 (1)
123 
124 typedef struct CommandReg {
125  uint16_t data;
126  uint8_t error;
127  uint8_t sec_count;
128  uint8_t sec_num;
129  uint8_t cyl_low;
130  uint8_t cyl_high;
131  union {
132  uint8_t drive;
133  uint8_t head;
134  };
135  uint8_t command;
136 } CommandReg_t;
137 
138 typedef enum Events {
139  None = 0,
146 } Events_t;
147 
148 typedef enum DevAction {
149  ACT_NONE = 0,
164 } DevAction_t;
165 
166 typedef enum DevState {
167  // Device idle
171 
172  // Software reset
174 
175  // Non-data commands
177 
178  // PIO data-in (data to host)
182 
183  // PIO data-out (data from host)
187 
188  // DMA protocol
192 } DevState_t;
193 
194 typedef enum DmaState {
195  Dma_Idle = 0,
198 } DmaState_t;
199 
200 class IdeController;
201 
205 class IdeDisk : public SimObject
206 {
207  protected:
212 
213  protected:
216 
217  private:
219  struct ataparams driveID;
221  uint8_t *dataBuffer;
223  uint32_t cmdBytes;
225  uint32_t cmdBytesLeft;
227  uint32_t drqBytesLeft;
229  uint32_t curSector;
233  uint8_t status;
235  bool nIENBit;
241  bool dmaRead;
245  uint32_t curPrdAddr;
249  int devID;
254 
261 
262  public:
263  typedef IdeDiskParams Params;
264  IdeDisk(const Params *p);
265 
269  ~IdeDisk();
270 
274  void reset(int id);
275 
279  void regStats() override;
280 
285  void
287  {
288  panic_if(ctrl, "Cannot change the controller once set!\n");
289  ctrl = c;
290  pageBytes = page_bytes;
291  }
292 
293  // Device register read/write
294  void readCommand(const Addr offset, int size, uint8_t *data);
295  void readControl(const Addr offset, int size, uint8_t *data);
296  void writeCommand(const Addr offset, int size, const uint8_t *data);
297  void writeControl(const Addr offset, int size, const uint8_t *data);
298 
299  // Start/abort functions
300  void startDma(const uint32_t &prdTableBase);
301  void abortDma();
302 
303  private:
304  void startCommand();
305 
306  // Interrupt management
307  void intrPost();
308  void intrClear();
309 
310  // DMA stuff
311  void doDmaTransfer();
313 
314  void doDmaDataRead();
315 
316  void doDmaRead();
319 
320  void doDmaDataWrite();
321 
322  void doDmaWrite();
325 
326  void dmaPrdReadDone();
328 
329  void dmaReadDone();
331 
332  void dmaWriteDone();
334 
335  // Disk image read/write
336  void readDisk(uint32_t sector, uint8_t *data);
337  void writeDisk(uint32_t sector, uint8_t *data);
338 
339  // State machine management
340  void updateState(DevAction_t action);
341 
342  // Utility functions
343  bool isBSYSet() { return (status & STATUS_BSY_BIT); }
344  bool isIENSet() { return nIENBit; }
345  bool isDEVSelect();
346 
347  void setComplete()
348  {
349  // clear out the status byte
350  status = 0;
351  // set the DRDY bit
352  status |= STATUS_DRDY_BIT;
353  // set the SEEK bit
354  status |= STATUS_SEEK_BIT;
355  }
356 
357  uint32_t getLBABase()
358  {
359  return (Addr)(((cmdReg.head & 0xf) << 24) | (cmdReg.cyl_high << 16) |
360  (cmdReg.cyl_low << 8) | (cmdReg.sec_num));
361  }
362 
363  inline Addr pciToDma(Addr pciAddr);
364 
365  void serialize(CheckpointOut &cp) const override;
366  void unserialize(CheckpointIn &cp) override;
367 };
368 
369 
370 #endif // __DEV_STORAGE_IDE_DISK_HH__
bool nIENBit
Interrupt enable bit.
Definition: ide_disk.hh:235
uint8_t head
Definition: ide_disk.hh:133
DmaState
Definition: ide_disk.hh:194
DmaState_t dmaState
Dma state.
Definition: ide_disk.hh:239
ChunkGenerator * dmaWriteCG
Definition: ide_disk.hh:323
EventFunctionWrapper dmaReadEvent
Definition: ide_disk.hh:330
struct PrdEntry PrdEntry_t
uint32_t curPrdAddr
PRD table base address.
Definition: ide_disk.hh:245
uint32_t baseAddr
Definition: ide_disk.hh:70
#define PRD_COUNT_MASK
Definition: ide_disk.hh:66
uint32_t getByteCount()
Definition: ide_disk.hh:84
uint8_t error
Definition: ide_disk.hh:126
PrdEntry_t entry
Definition: ide_disk.hh:77
Device model for an Intel PIIX4 IDE controller.
Definition: ide_ctrl.hh:48
struct CommandReg CommandReg_t
#define MAX_SINGLE_DMA_SIZE
Definition: ide_disk.hh:62
Stats::Scalar dmaReadTxs
Definition: ide_disk.hh:257
int devID
Device ID (master=0/slave=1)
Definition: ide_disk.hh:249
uint8_t cyl_high
Definition: ide_disk.hh:130
DiskImage * image
The image that contains the data of this disk.
Definition: ide_disk.hh:211
void reset()
Definition: statistics.cc:569
Simple PCI IDE controller with bus mastering capability and UDMA modeled after controller in the Inte...
Bitfield< 23, 0 > offset
Definition: types.hh:152
bool dmaAborted
DMA Aborted.
Definition: ide_disk.hh:253
Events
Definition: ide_disk.hh:138
uint32_t drqBytesLeft
Number of bytes left in DRQ block.
Definition: ide_disk.hh:227
Definition: cprintf.cc:40
Stats::Scalar dmaWriteBytes
Definition: ide_disk.hh:259
Declaration of Statistics objects.
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:2505
#define PRD_EOT_MASK
Definition: ide_disk.hh:67
uint8_t command
Definition: ide_disk.hh:135
DevState
Definition: ide_disk.hh:166
uint8_t drive
Definition: ide_disk.hh:132
#define STATUS_SEEK_BIT
Definition: ide_disk.hh:117
uint8_t sec_count
Definition: ide_disk.hh:127
uint32_t cmdBytesLeft
Number of bytes left in command data transfer.
Definition: ide_disk.hh:225
enum Events Events_t
Stats::Scalar dmaReadBytes
Definition: ide_disk.hh:256
This class takes an arbitrary memory region (address/length pair) and generates a series of appropria...
uint32_t getLBABase()
Definition: ide_disk.hh:357
uint16_t byteCount
Definition: ide_disk.hh:71
void serialize(const ThreadContext &tc, CheckpointOut &cp)
Thread context serialization helpers.
EventFunctionWrapper dmaWriteEvent
Definition: ide_disk.hh:333
enum DevState DevState_t
Basic interface for accessing a disk image.
Definition: disk_image.hh:49
enum DmaState DmaState_t
DevAction
Definition: ide_disk.hh:148
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:140
uint32_t getBaseAddr()
Definition: ide_disk.hh:79
uint32_t curSector
Current sector in access.
Definition: ide_disk.hh:229
Addr pageBytes
Size of OS pages.
Definition: ide_disk.hh:243
uint8_t status
Status register.
Definition: ide_disk.hh:233
EventFunctionWrapper dmaPrdReadEvent
Definition: ide_disk.hh:327
DevState_t devState
Device state.
Definition: ide_disk.hh:237
EventFunctionWrapper dmaWriteWaitEvent
Definition: ide_disk.hh:324
uint16_t data
Definition: ide_disk.hh:125
enum DevAction DevAction_t
ChunkGenerator * dmaReadCG
Definition: ide_disk.hh:317
uint16_t endOfTable
Definition: ide_disk.hh:72
uint32_t cmdBytes
Number of bytes in command data transfer.
Definition: ide_disk.hh:223
#define STATUS_BSY_BIT
Definition: ide_disk.hh:114
bool isBSYSet()
Definition: ide_disk.hh:343
#define PRD_BASE_MASK
Definition: ide_disk.hh:65
PrdTableEntry curPrd
PRD entry.
Definition: ide_disk.hh:247
uint8_t cyl_low
Definition: ide_disk.hh:129
Bitfield< 29 > c
IDE Disk device model.
Definition: ide_disk.hh:205
CommandReg_t cmdReg
Command block registers.
Definition: ide_disk.hh:231
bool intrPending
Interrupt pending.
Definition: ide_disk.hh:251
std::ostream CheckpointOut
Definition: serialize.hh:63
EventFunctionWrapper dmaReadWaitEvent
Definition: ide_disk.hh:318
IdeDiskParams Params
Definition: ide_disk.hh:263
bool dmaRead
Dma transaction is a read.
Definition: ide_disk.hh:241
Disk Image Interfaces.
bool isIENSet()
Definition: ide_disk.hh:344
uint8_t sec_num
Definition: ide_disk.hh:128
Stats::Scalar dmaReadFullPages
Definition: ide_disk.hh:255
#define STATUS_DRDY_BIT
Definition: ide_disk.hh:115
IdeController * ctrl
The IDE controller for this disk.
Definition: ide_disk.hh:209
void unserialize(ThreadContext &tc, CheckpointIn &cp)
EventFunctionWrapper dmaTransferEvent
Definition: ide_disk.hh:312
uint8_t * dataBuffer
Data buffer for transfers.
Definition: ide_disk.hh:221
uint16_t getEOT()
Definition: ide_disk.hh:90
void setController(IdeController *c, Addr page_bytes)
Set the controller for this device.
Definition: ide_disk.hh:286
Bitfield< 0 > p
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:181
const char data[]
void setComplete()
Definition: ide_disk.hh:347
Stats::Scalar dmaWriteFullPages
Definition: ide_disk.hh:258
Abstract superclass for simulation objects.
Definition: sim_object.hh:93
int diskDelay
The disk delay in microseconds.
Definition: ide_disk.hh:215
Stats::Scalar dmaWriteTxs
Definition: ide_disk.hh:260

Generated on Fri Jul 3 2020 15:53:02 for gem5 by doxygen 1.8.13