gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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  * Authors: Andrew Schultz
41  */
42 
47 #ifndef __DEV_STORAGE_IDE_DISK_HH__
48 #define __DEV_STORAGE_IDE_DISK_HH__
49 
50 #include "base/statistics.hh"
51 #include "dev/io_device.hh"
53 #include "dev/storage/ide_atareg.h"
54 #include "dev/storage/ide_ctrl.hh"
55 #include "dev/storage/ide_wdcreg.h"
56 #include "params/IdeDisk.hh"
57 #include "sim/eventq.hh"
58 
59 class ChunkGenerator;
60 
61 #define DMA_BACKOFF_PERIOD 200
62 
63 #define MAX_DMA_SIZE 0x20000 // 128K
64 #define MAX_SINGLE_DMA_SIZE 0x10000
65 #define MAX_MULTSECT (128)
66 
67 #define PRD_BASE_MASK 0xfffffffe
68 #define PRD_COUNT_MASK 0xfffe
69 #define PRD_EOT_MASK 0x8000
70 
71 typedef struct PrdEntry {
72  uint32_t baseAddr;
73  uint16_t byteCount;
74  uint16_t endOfTable;
75 } PrdEntry_t;
76 
78  public:
80 
81  uint32_t getBaseAddr()
82  {
83  return (entry.baseAddr & PRD_BASE_MASK);
84  }
85 
86  uint32_t getByteCount()
87  {
88  return ((entry.byteCount == 0) ? MAX_SINGLE_DMA_SIZE :
90  }
91 
92  uint16_t getEOT()
93  {
94  return (entry.endOfTable & PRD_EOT_MASK);
95  }
96 };
97 
98 #define DATA_OFFSET (0)
99 #define ERROR_OFFSET (1)
100 #define FEATURES_OFFSET (1)
101 #define NSECTOR_OFFSET (2)
102 #define SECTOR_OFFSET (3)
103 #define LCYL_OFFSET (4)
104 #define HCYL_OFFSET (5)
105 #define SELECT_OFFSET (6)
106 #define DRIVE_OFFSET (6)
107 #define STATUS_OFFSET (7)
108 #define COMMAND_OFFSET (7)
109 
110 #define CONTROL_OFFSET (2)
111 #define ALTSTAT_OFFSET (2)
112 
113 #define SELECT_DEV_BIT 0x10
114 #define CONTROL_RST_BIT 0x04
115 #define CONTROL_IEN_BIT 0x02
116 #define STATUS_BSY_BIT 0x80
117 #define STATUS_DRDY_BIT 0x40
118 #define STATUS_DRQ_BIT 0x08
119 #define STATUS_SEEK_BIT 0x10
120 #define STATUS_DF_BIT 0x20
121 #define DRIVE_LBA_BIT 0x40
122 
123 #define DEV0 (0)
124 #define DEV1 (1)
125 
126 typedef struct CommandReg {
127  uint16_t data;
128  uint8_t error;
129  uint8_t sec_count;
130  uint8_t sec_num;
131  uint8_t cyl_low;
132  uint8_t cyl_high;
133  union {
134  uint8_t drive;
135  uint8_t head;
136  };
137  uint8_t command;
138 } CommandReg_t;
139 
140 typedef enum Events {
141  None = 0,
148 } Events_t;
149 
150 typedef enum DevAction {
151  ACT_NONE = 0,
166 } DevAction_t;
167 
168 typedef enum DevState {
169  // Device idle
173 
174  // Software reset
176 
177  // Non-data commands
179 
180  // PIO data-in (data to host)
184 
185  // PIO data-out (data from host)
189 
190  // DMA protocol
194 } DevState_t;
195 
196 typedef enum DmaState {
197  Dma_Idle = 0,
200 } DmaState_t;
201 
202 class IdeController;
203 
207 class IdeDisk : public SimObject
208 {
209  protected:
214 
215  protected:
218 
219  private:
223  uint8_t *dataBuffer;
225  uint32_t cmdBytes;
227  uint32_t cmdBytesLeft;
229  uint32_t drqBytesLeft;
231  uint32_t curSector;
235  uint8_t status;
237  bool nIENBit;
243  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 
286  if (ctrl) panic("Cannot change the controller once set!\n");
287  ctrl = c;
288  }
289 
290  // Device register read/write
291  void readCommand(const Addr offset, int size, uint8_t *data);
292  void readControl(const Addr offset, int size, uint8_t *data);
293  void writeCommand(const Addr offset, int size, const uint8_t *data);
294  void writeControl(const Addr offset, int size, const uint8_t *data);
295 
296  // Start/abort functions
297  void startDma(const uint32_t &prdTableBase);
298  void abortDma();
299 
300  private:
301  void startCommand();
302 
303  // Interrupt management
304  void intrPost();
305  void intrClear();
306 
307  // DMA stuff
308  void doDmaTransfer();
311 
312  void doDmaDataRead();
313 
314  void doDmaRead();
318 
319  void doDmaDataWrite();
320 
321  void doDmaWrite();
325 
326  void dmaPrdReadDone();
329 
330  void dmaReadDone();
333 
334  void dmaWriteDone();
337 
338  // Disk image read/write
339  void readDisk(uint32_t sector, uint8_t *data);
340  void writeDisk(uint32_t sector, uint8_t *data);
341 
342  // State machine management
343  void updateState(DevAction_t action);
344 
345  // Utility functions
346  bool isBSYSet() { return (status & STATUS_BSY_BIT); }
347  bool isIENSet() { return nIENBit; }
348  bool isDEVSelect();
349 
350  void setComplete()
351  {
352  // clear out the status byte
353  status = 0;
354  // set the DRDY bit
356  // set the SEEK bit
358  }
359 
360  uint32_t getLBABase()
361  {
362  return (Addr)(((cmdReg.head & 0xf) << 24) | (cmdReg.cyl_high << 16) |
363  (cmdReg.cyl_low << 8) | (cmdReg.sec_num));
364  }
365 
366  inline Addr pciToDma(Addr pciAddr);
367 
368  void serialize(CheckpointOut &cp) const override;
369  void unserialize(CheckpointIn &cp) override;
370 };
371 
372 
373 #endif // __DEV_STORAGE_IDE_DISK_HH__
bool nIENBit
Interrupt enable bit.
Definition: ide_disk.hh:237
uint8_t head
Definition: ide_disk.hh:135
void dmaWriteDone()
Definition: ide_disk.cc:552
DmaState
Definition: ide_disk.hh:196
void dmaPrdReadDone()
Definition: ide_disk.cc:357
void reset(int id)
Reset the device state.
Definition: ide_disk.cc:145
void writeCommand(const Addr offset, int size, const uint8_t *data)
Definition: ide_disk.cc:264
EventWrapper< IdeDisk,&IdeDisk::dmaWriteDone > dmaWriteEvent
Definition: ide_disk.hh:336
~IdeDisk()
Delete the data buffer.
Definition: ide_disk.cc:138
DmaState_t dmaState
Dma state.
Definition: ide_disk.hh:241
ChunkGenerator * dmaWriteCG
Definition: ide_disk.hh:322
#define panic(...)
Definition: misc.hh:153
void doDmaRead()
Definition: ide_disk.cc:426
struct PrdEntry PrdEntry_t
uint32_t curPrdAddr
PRD table base address.
Definition: ide_disk.hh:245
void regStats() override
Register Statistics.
Definition: ide_disk.cc:393
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: ide_disk.cc:1073
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: ide_disk.cc:1151
uint32_t baseAddr
Definition: ide_disk.hh:72
void doDmaTransfer()
Definition: ide_disk.cc:336
void startCommand()
Definition: ide_disk.cc:625
#define PRD_COUNT_MASK
Definition: ide_disk.hh:68
uint32_t getByteCount()
Definition: ide_disk.hh:86
uint8_t error
Definition: ide_disk.hh:128
PrdEntry_t entry
Definition: ide_disk.hh:79
Device model for an Intel PIIX4 IDE controller.
Definition: ide_ctrl.hh:51
struct CommandReg CommandReg_t
#define MAX_SINGLE_DMA_SIZE
Definition: ide_disk.hh:64
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:132
DiskImage * image
The image that contains the data of this disk.
Definition: ide_disk.hh:213
Simple PCI IDE controller with bus mastering capability and UDMA modeled after controller in the Inte...
Bitfield< 23, 0 > offset
Definition: types.hh:149
bool dmaAborted
DMA Aborted.
Definition: ide_disk.hh:253
Events
Definition: ide_disk.hh:140
EventWrapper< IdeDisk,&IdeDisk::dmaPrdReadDone > dmaPrdReadEvent
Definition: ide_disk.hh:328
uint32_t drqBytesLeft
Number of bytes left in DRQ block.
Definition: ide_disk.hh:229
void updateState(DevAction_t action)
Definition: ide_disk.cc:773
Stats::Scalar dmaWriteBytes
Definition: ide_disk.hh:259
Declaration of Statistics objects.
EventWrapper< IdeDisk,&IdeDisk::doDmaTransfer > dmaTransferEvent
Definition: ide_disk.hh:310
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:2475
void intrClear()
Definition: ide_disk.cc:755
const char data[]
Definition: circlebuf.cc:43
bool isDEVSelect()
Definition: ide_disk.cc:189
#define PRD_EOT_MASK
Definition: ide_disk.hh:69
void dmaReadDone()
Definition: ide_disk.cc:465
uint8_t command
Definition: ide_disk.hh:137
DevState
Definition: ide_disk.hh:168
uint8_t drive
Definition: ide_disk.hh:134
#define STATUS_SEEK_BIT
Definition: ide_disk.hh:119
uint8_t sec_count
Definition: ide_disk.hh:129
uint32_t cmdBytesLeft
Number of bytes left in command data transfer.
Definition: ide_disk.hh:227
void readCommand(const Addr offset, int size, uint8_t *data)
Definition: ide_disk.cc:208
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...
void doDmaDataRead()
Definition: ide_disk.cc:381
uint32_t getLBABase()
Definition: ide_disk.hh:360
uint16_t byteCount
Definition: ide_disk.hh:73
struct ataparams driveID
Drive identification structure for this disk.
Definition: ide_disk.hh:221
IdeDisk(const Params *p)
Definition: ide_disk.cc:69
EventWrapper< IdeDisk,&IdeDisk::doDmaWrite > dmaWriteWaitEvent
Definition: ide_disk.hh:324
enum DevState DevState_t
void writeControl(const Addr offset, int size, const uint8_t *data)
Definition: ide_disk.cc:312
void abortDma()
Definition: ide_disk.cc:613
Basic interface for accessing a disk image.
Definition: disk_image.hh:51
enum DmaState DmaState_t
DevAction
Definition: ide_disk.hh:150
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
uint32_t getBaseAddr()
Definition: ide_disk.hh:81
uint32_t curSector
Current sector in access.
Definition: ide_disk.hh:231
uint8_t status
Status register.
Definition: ide_disk.hh:235
EventWrapper< IdeDisk,&IdeDisk::doDmaRead > dmaReadWaitEvent
Definition: ide_disk.hh:317
DevState_t devState
Device state.
Definition: ide_disk.hh:239
void doDmaWrite()
Definition: ide_disk.cc:511
uint16_t data
Definition: ide_disk.hh:127
enum DevAction DevAction_t
ChunkGenerator * dmaReadCG
Definition: ide_disk.hh:315
uint16_t endOfTable
Definition: ide_disk.hh:74
uint32_t cmdBytes
Number of bytes in command data transfer.
Definition: ide_disk.hh:225
#define STATUS_BSY_BIT
Definition: ide_disk.hh:116
bool isBSYSet()
Definition: ide_disk.hh:346
#define PRD_BASE_MASK
Definition: ide_disk.hh:67
PrdTableEntry curPrd
PRD entry.
Definition: ide_disk.hh:247
int size()
Definition: pagetable.hh:146
uint8_t cyl_low
Definition: ide_disk.hh:131
Bitfield< 29 > c
Definition: miscregs.hh:1365
IDE Disk device model.
Definition: ide_disk.hh:207
CommandReg_t cmdReg
Command block registers.
Definition: ide_disk.hh:233
bool intrPending
Interrupt pending.
Definition: ide_disk.hh:251
std::ostream CheckpointOut
Definition: serialize.hh:67
EventWrapper< IdeDisk,&IdeDisk::dmaReadDone > dmaReadEvent
Definition: ide_disk.hh:332
IdeDiskParams Params
Definition: ide_disk.hh:263
bool dmaRead
Dma transaction is a read.
Definition: ide_disk.hh:243
Disk Image Interfaces.
bool isIENSet()
Definition: ide_disk.hh:347
void startDma(const uint32_t &prdTableBase)
Definition: ide_disk.cc:595
void doDmaDataWrite()
Definition: ide_disk.cc:488
Addr pciToDma(Addr pciAddr)
Definition: ide_disk.cc:195
uint8_t sec_num
Definition: ide_disk.hh:130
Stats::Scalar dmaReadFullPages
Definition: ide_disk.hh:255
#define STATUS_DRDY_BIT
Definition: ide_disk.hh:117
IdeController * ctrl
The IDE controller for this disk.
Definition: ide_disk.hh:211
void writeDisk(uint32_t sector, uint8_t *data)
Definition: ide_disk.cc:581
uint8_t * dataBuffer
Data buffer for transfers.
Definition: ide_disk.hh:223
void setController(IdeController *c)
Set the controller for this device.
Definition: ide_disk.hh:285
uint16_t getEOT()
Definition: ide_disk.hh:92
void readControl(const Addr offset, int size, uint8_t *data)
Definition: ide_disk.cc:254
Bitfield< 0 > p
void readDisk(uint32_t sector, uint8_t *data)
Definition: ide_disk.cc:571
void setComplete()
Definition: ide_disk.hh:350
Stats::Scalar dmaWriteFullPages
Definition: ide_disk.hh:258
Abstract superclass for simulation objects.
Definition: sim_object.hh:94
int diskDelay
The disk delay in microseconds.
Definition: ide_disk.hh:217
void intrPost()
Definition: ide_disk.cc:740
Stats::Scalar dmaWriteTxs
Definition: ide_disk.hh:260

Generated on Fri Jun 9 2017 13:03:47 for gem5 by doxygen 1.8.6