gem5  v22.1.0.0
ide_ctrl.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2004-2005 The Regents of The University of Michigan
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met: redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer;
9  * redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution;
12  * neither the name of the copyright holders nor the names of its
13  * contributors may be used to endorse or promote products derived from
14  * this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
34 #ifndef __DEV_STORAGE_IDE_CTRL_HH__
35 #define __DEV_STORAGE_IDE_CTRL_HH__
36 
37 #include "base/bitunion.hh"
38 #include "dev/io_device.hh"
39 #include "dev/pci/device.hh"
40 #include "dev/reg_bank.hh"
41 #include "params/IdeController.hh"
42 
43 namespace gem5
44 {
45 
46 class IdeDisk;
47 
52 class IdeController : public PciDevice
53 {
54  private:
55  // Bus master IDE status register bit fields
56  BitUnion8(BMIStatusReg)
57  Bitfield<6> dmaCap0;
58  Bitfield<5> dmaCap1;
59  Bitfield<2> intStatus;
60  Bitfield<1> dmaError;
61  Bitfield<0> active;
62  EndBitUnion(BMIStatusReg)
63 
64  BitUnion8(BMICommandReg)
65  Bitfield<3> rw;
66  Bitfield<0> startStop;
67  EndBitUnion(BMICommandReg)
68 
69 
70  class ConfigSpaceRegs : public RegisterBankLE
71  {
72  public:
73  ConfigSpaceRegs(const std::string &name) :
75  {
76  // None of these registers are actually hooked up to control
77  // anything, so they have no specially defined behaviors. They
78  // just store values for now, but should presumably do something
79  // in a more accurate model.
80  addRegisters({primaryTiming, secondaryTiming, deviceTiming, raz0,
81  udmaControl, raz1, udmaTiming, raz2});
82  }
83 
84  enum
85  {
86  TimeRegWithDecodeEnabled = 0x8000
87  };
88 
89  /* Offset in config space */
90  /* 0x40-0x41 */ Register16 primaryTiming =
91  {"primary timing", TimeRegWithDecodeEnabled};
92  /* 0x42-0x43 */ Register16 secondaryTiming =
93  {"secondary timing", TimeRegWithDecodeEnabled};
94  /* 0x44 */ Register8 deviceTiming = {"device timing"};
95  /* 0x45-0x47 */ RegisterRaz raz0 = {"raz0", 3};
96  /* 0x48 */ Register8 udmaControl = {"udma control"};
97  /* 0x49 */ RegisterRaz raz1 = {"raz1", 1};
98  /* 0x4a-0x4b */ Register16 udmaTiming = {"udma timing"};
99  /* 0x4c-... */ RegisterRaz raz2 = {"raz2", PCI_CONFIG_SIZE - 0x4c};
100 
101  void serialize(CheckpointOut &cp) const;
102  void unserialize(CheckpointIn &cp);
103  };
104 
105  ConfigSpaceRegs configSpaceRegs;
106 
107  public:
108  class Channel : public Named
109  {
110  private:
112 
119  IdeDisk *device0 = nullptr, *device1 = nullptr;
120 
122  IdeDisk *_selected = nullptr;
123 
124  bool selectBit = false;
125  bool primary;
126 
127  bool _pendingInterrupt = false;
128 
129  public:
130  bool isPrimary() const { return primary; }
131 
132  bool pendingInterrupt() const { return _pendingInterrupt; }
133 
134  IdeDisk *selected() const { return _selected; }
135  IdeController *controller() const { return ctrl; }
136 
137  void
139  {
140  assert(!device0 && disk);
141  device0 = disk;
142  }
143 
144  void
146  {
147  assert(!device1 && disk);
148  device1 = disk;
149  }
150 
152  struct BMIRegs
153  {
154  void
156  {
157  memset(static_cast<void *>(this), 0, sizeof(*this));
158  }
159 
160  BMICommandReg command;
161  uint8_t reserved0;
162  BMIStatusReg status;
163  uint8_t reserved1;
164  uint32_t bmidtp;
166 
167  void
168  select(bool select_device_1)
169  {
170  selectBit = select_device_1;
172  }
173 
174  void accessCommand(Addr offset, int size, uint8_t *data, bool read);
175  void accessControl(Addr offset, int size, uint8_t *data, bool read);
176  void accessBMI(Addr offset, int size, uint8_t *data, bool read);
177 
178  void setDmaComplete();
179 
180  void postInterrupt();
181  void clearInterrupt();
182 
183  Channel(std::string new_name, IdeController *new_ctrl,
184  bool new_primary);
185 
186  void serialize(const std::string &base, std::ostream &os) const;
187  void unserialize(const std::string &base, CheckpointIn &cp);
188  };
189 
190  private:
193 
194  uint32_t ioShift, ctrlOffset;
195 
196  void dispatchAccess(PacketPtr pkt, bool read);
197 
198  public:
200  IdeController(const Params &p);
201 
202  virtual void postInterrupt(bool is_primary);
203  virtual void clearInterrupt(bool is_primary);
204 
205  Tick writeConfig(PacketPtr pkt) override;
206  Tick readConfig(PacketPtr pkt) override;
207 
208  Tick read(PacketPtr pkt) override;
209  Tick write(PacketPtr pkt) override;
210 
211  void serialize(CheckpointOut &cp) const override;
212  void unserialize(CheckpointIn &cp) override;
213 };
214 
215 } // namespace gem5
216 
217 #endif // __DEV_STORAGE_IDE_CTRL_HH_
const char data[]
DmaDeviceParams Params
Definition: dma_device.hh:209
void accessControl(Addr offset, int size, uint8_t *data, bool read)
Definition: ide_ctrl.cc:216
IdeDisk * selected() const
Definition: ide_ctrl.hh:134
void setDevice1(IdeDisk *disk)
Definition: ide_ctrl.hh:145
void select(bool select_device_1)
Definition: ide_ctrl.hh:168
void serialize(const std::string &base, std::ostream &os) const
Definition: ide_ctrl.cc:415
void accessCommand(Addr offset, int size, uint8_t *data, bool read)
Definition: ide_ctrl.cc:196
IdeController * controller() const
Definition: ide_ctrl.hh:135
void setDevice0(IdeDisk *disk)
Definition: ide_ctrl.hh:138
void accessBMI(Addr offset, int size, uint8_t *data, bool read)
Definition: ide_ctrl.cc:230
IdeDisk * _selected
Currently selected disk.
Definition: ide_ctrl.hh:122
void unserialize(const std::string &base, CheckpointIn &cp)
Definition: ide_ctrl.cc:443
bool pendingInterrupt() const
Definition: ide_ctrl.hh:132
IdeDisk * device0
IDE disks connected to this controller For more details about device0 and device1 see: https://en....
Definition: ide_ctrl.hh:119
struct gem5::IdeController::Channel::BMIRegs bmiRegs
Channel(std::string new_name, IdeController *new_ctrl, bool new_primary)
Definition: ide_ctrl.cc:64
Device model for an Intel PIIX4 IDE controller.
Definition: ide_ctrl.hh:53
virtual void postInterrupt(bool is_primary)
Definition: ide_ctrl.cc:140
EndBitUnion(BMIStatusReg) BitUnion8(BMICommandReg) Bitfield< 3 > rw
virtual void clearInterrupt(bool is_primary)
Definition: ide_ctrl.cc:149
Tick read(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: ide_ctrl.cc:387
Bitfield< 0 > startStop
Definition: ide_ctrl.hh:66
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: ide_ctrl.cc:394
IdeController(const Params &p)
Definition: ide_ctrl.cc:73
EndBitUnion(BMICommandReg) class ConfigSpaceRegs ConfigSpaceRegs configSpaceRegs
Registers used in device specific PCI configuration.
Definition: ide_ctrl.hh:67
void serialize(CheckpointOut &cp) const override
Serialize this object to the given output stream.
Definition: ide_ctrl.cc:401
BitUnion8(BMIStatusReg) Bitfield< 6 > dmaCap0
Bitfield< 2 > intStatus
Definition: ide_ctrl.hh:59
void dispatchAccess(PacketPtr pkt, bool read)
Definition: ide_ctrl.cc:317
uint32_t ctrlOffset
Definition: ide_ctrl.hh:194
Bitfield< 1 > dmaError
Definition: ide_ctrl.hh:60
Bitfield< 0 > active
Definition: ide_ctrl.hh:61
void unserialize(CheckpointIn &cp) override
Reconstruct the state of this object from a checkpoint.
Definition: ide_ctrl.cc:429
Bitfield< 5 > dmaCap1
Definition: ide_ctrl.hh:58
Tick readConfig(PacketPtr pkt) override
Read from the PCI config space data that is stored locally.
Definition: ide_ctrl.cc:158
PARAMS(IdeController)
Tick writeConfig(PacketPtr pkt) override
Write to the PCI config space data that is stored locally.
Definition: ide_ctrl.cc:177
IDE Disk device model.
Definition: ide_disk.hh:217
Interface for things with names.
Definition: named.hh:39
virtual std::string name() const
Definition: named.hh:47
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
PCI device, base implementation is only config space.
Definition: device.hh:270
Bitfield< 31 > rw
Definition: misc_types.hh:259
Bitfield< 23, 0 > offset
Definition: types.hh:144
Bitfield< 54 > p
Definition: pagetable.hh:70
Bitfield< 51, 12 > base
Definition: pagetable.hh:141
Bitfield< 17 > os
Definition: misc.hh:810
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
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
RegisterBank< ByteOrder::little > RegisterBankLE
Definition: reg_bank.hh:941
#define PCI_DEVICE_SPECIFIC
Definition: pcireg.h:164
#define PCI_CONFIG_SIZE
Definition: pcireg.h:165
Registers used for bus master interface.
Definition: ide_ctrl.hh:153

Generated on Wed Dec 21 2022 10:22:35 for gem5 by doxygen 1.9.1