gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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 :
89  (entry.byteCount & PRD_COUNT_MASK));
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:
221  struct ataparams driveID;
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;
247  uint32_t curPrdAddr;
251  int devID;
256 
263 
264  public:
265  typedef IdeDiskParams Params;
266  IdeDisk(const Params *p);
267 
271  ~IdeDisk();
272 
276  void reset(int id);
277 
281  void regStats() override;
282 
287  void
289  {
290  panic_if(ctrl, "Cannot change the controller once set!\n");
291  ctrl = c;
292  pageBytes = page_bytes;
293  }
294 
295  // Device register read/write
296  void readCommand(const Addr offset, int size, uint8_t *data);
297  void readControl(const Addr offset, int size, uint8_t *data);
298  void writeCommand(const Addr offset, int size, const uint8_t *data);
299  void writeControl(const Addr offset, int size, const uint8_t *data);
300 
301  // Start/abort functions
302  void startDma(const uint32_t &prdTableBase);
303  void abortDma();
304 
305  private:
306  void startCommand();
307 
308  // Interrupt management
309  void intrPost();
310  void intrClear();
311 
312  // DMA stuff
313  void doDmaTransfer();
315 
316  void doDmaDataRead();
317 
318  void doDmaRead();
321 
322  void doDmaDataWrite();
323 
324  void doDmaWrite();
327 
328  void dmaPrdReadDone();
330 
331  void dmaReadDone();
333 
334  void dmaWriteDone();
336 
337  // Disk image read/write
338  void readDisk(uint32_t sector, uint8_t *data);
339  void writeDisk(uint32_t sector, uint8_t *data);
340 
341  // State machine management
342  void updateState(DevAction_t action);
343 
344  // Utility functions
345  bool isBSYSet() { return (status & STATUS_BSY_BIT); }
346  bool isIENSet() { return nIENBit; }
347  bool isDEVSelect();
348 
349  void setComplete()
350  {
351  // clear out the status byte
352  status = 0;
353  // set the DRDY bit
354  status |= STATUS_DRDY_BIT;
355  // set the SEEK bit
356  status |= STATUS_SEEK_BIT;
357  }
358 
359  uint32_t getLBABase()
360  {
361  return (Addr)(((cmdReg.head & 0xf) << 24) | (cmdReg.cyl_high << 16) |
362  (cmdReg.cyl_low << 8) | (cmdReg.sec_num));
363  }
364 
365  inline Addr pciToDma(Addr pciAddr);
366 
367  void serialize(CheckpointOut &cp) const override;
368  void unserialize(CheckpointIn &cp) override;
369 };
370 
371 
372 #endif // __DEV_STORAGE_IDE_DISK_HH__
bool nIENBit
Interrupt enable bit.
Definition: ide_disk.hh:237
uint8_t head
Definition: ide_disk.hh:135
DmaState
Definition: ide_disk.hh:196
DmaState_t dmaState
Dma state.
Definition: ide_disk.hh:241
ChunkGenerator * dmaWriteCG
Definition: ide_disk.hh:325
EventFunctionWrapper dmaReadEvent
Definition: ide_disk.hh:332
struct PrdEntry PrdEntry_t
uint32_t curPrdAddr
PRD table base address.
Definition: ide_disk.hh:247
uint32_t baseAddr
Definition: ide_disk.hh:72
#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:259
int devID
Device ID (master=0/slave=1)
Definition: ide_disk.hh:251
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
void reset()
Definition: statistics.cc:570
Simple PCI IDE controller with bus mastering capability and UDMA modeled after controller in the Inte...
Bitfield< 23, 0 > offset
Definition: types.hh:154
bool dmaAborted
DMA Aborted.
Definition: ide_disk.hh:255
Events
Definition: ide_disk.hh:140
uint32_t drqBytesLeft
Number of bytes left in DRQ block.
Definition: ide_disk.hh:229
Definition: cprintf.cc:42
Stats::Scalar dmaWriteBytes
Definition: ide_disk.hh:261
Declaration of Statistics objects.
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:2508
#define PRD_EOT_MASK
Definition: ide_disk.hh:69
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
enum Events Events_t
Stats::Scalar dmaReadBytes
Definition: ide_disk.hh:258
This class takes an arbitrary memory region (address/length pair) and generates a series of appropria...
uint32_t getLBABase()
Definition: ide_disk.hh:359
uint16_t byteCount
Definition: ide_disk.hh:73
void serialize(const ThreadContext &tc, CheckpointOut &cp)
Thread context serialization helpers.
EventFunctionWrapper dmaWriteEvent
Definition: ide_disk.hh:335
enum DevState DevState_t
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
Addr pageBytes
Size of OS pages.
Definition: ide_disk.hh:245
uint8_t status
Status register.
Definition: ide_disk.hh:235
EventFunctionWrapper dmaPrdReadEvent
Definition: ide_disk.hh:329
DevState_t devState
Device state.
Definition: ide_disk.hh:239
EventFunctionWrapper dmaWriteWaitEvent
Definition: ide_disk.hh:326
uint16_t data
Definition: ide_disk.hh:127
enum DevAction DevAction_t
ChunkGenerator * dmaReadCG
Definition: ide_disk.hh:319
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:345
#define PRD_BASE_MASK
Definition: ide_disk.hh:67
PrdTableEntry curPrd
PRD entry.
Definition: ide_disk.hh:249
uint8_t cyl_low
Definition: ide_disk.hh:131
Bitfield< 29 > c
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:253
std::ostream CheckpointOut
Definition: serialize.hh:68
EventFunctionWrapper dmaReadWaitEvent
Definition: ide_disk.hh:320
IdeDiskParams Params
Definition: ide_disk.hh:265
bool dmaRead
Dma transaction is a read.
Definition: ide_disk.hh:243
Disk Image Interfaces.
bool isIENSet()
Definition: ide_disk.hh:346
uint8_t sec_num
Definition: ide_disk.hh:130
Stats::Scalar dmaReadFullPages
Definition: ide_disk.hh:257
#define STATUS_DRDY_BIT
Definition: ide_disk.hh:117
IdeController * ctrl
The IDE controller for this disk.
Definition: ide_disk.hh:211
void unserialize(ThreadContext &tc, CheckpointIn &cp)
EventFunctionWrapper dmaTransferEvent
Definition: ide_disk.hh:314
uint8_t * dataBuffer
Data buffer for transfers.
Definition: ide_disk.hh:223
uint16_t getEOT()
Definition: ide_disk.hh:92
void setController(IdeController *c, Addr page_bytes)
Set the controller for this device.
Definition: ide_disk.hh:288
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:185
const char data[]
void setComplete()
Definition: ide_disk.hh:349
Stats::Scalar dmaWriteFullPages
Definition: ide_disk.hh:260
Abstract superclass for simulation objects.
Definition: sim_object.hh:96
int diskDelay
The disk delay in microseconds.
Definition: ide_disk.hh:217
Stats::Scalar dmaWriteTxs
Definition: ide_disk.hh:262

Generated on Fri Feb 28 2020 16:27:01 for gem5 by doxygen 1.8.13