gem5  v22.1.0.0
i8237.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008 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 
29 #include "dev/x86/i8237.hh"
30 
31 #include "base/cprintf.hh"
32 #include "mem/packet.hh"
33 #include "mem/packet_access.hh"
34 
35 namespace gem5
36 {
37 
38 namespace X86ISA
39 {
40 
41 namespace
42 {
43 
44 I8237::Register::ReadFunc
45 readUnimpl(const std::string &label)
46 {
47  return [label](I8237::Register &reg) -> uint8_t {
48  panic("Read from i8237 %s unimplemented.", label);
49  };
50 }
51 
52 I8237::Register::WriteFunc
53 writeUnimpl(const std::string &label)
54 {
55  return [label](I8237::Register &reg, const uint8_t &value) {
56  panic("Write to i8237 %s unimplemented.", label);
57  };
58 }
59 
60 } // anonymous namespace
61 
63  Register(csprintf("channel %d current address", channel.number))
64 {
65  reader(readUnimpl(name()));
66  writer(writeUnimpl(name()));
67 }
68 
70  Register(csprintf("channel %d remaining word count", channel.number))
71 {
72  reader(readUnimpl(name()));
73  writer(writeUnimpl(name()));
74 }
75 
76 I8237::WriteOnlyReg::WriteOnlyReg(const std::string &new_name, Addr offset) :
77  Register(new_name)
78 {
79  reader([offset](I8237::Register &reg) -> uint8_t {
80  panic("Illegal read from i8237 register %d.", offset);
81  });
82 }
83 
84 I8237::I8237(const Params &p) : BasicPioDevice(p, 16), latency(p.pio_latency),
85  regs("registers", pioAddr), channels{{{0}, {1}, {2}, {3}}},
86  statusCommandReg("status/command"),
87  requestReg("request", 0x9),
88  setMaskBitReg("set mask bit", 0xa),
89  modeReg("mode", 0xb),
90  clearFlipFlopReg("clear flip-flop", 0xc),
91  temporaryMasterClearReg("temporary/maskter clear"),
92  clearMaskReg("clear mask", 0xe),
93  writeMaskReg("write mask", 0xf)
94 {
95  // Add the channel address and remaining registers.
96  for (auto &channel: channels)
97  regs.addRegisters({ channel.addrReg, channel.remainingReg });
98 
99  // Add the other registers individually.
100  regs.addRegisters({
101  statusCommandReg.
102  reader([this](auto &reg) -> uint8_t { return statusVal; }).
103  writer([this](auto &reg, const uint8_t &value) {
104  commandVal = value;
105  }),
106 
107  requestReg.
109 
110  setMaskBitReg.
111  writer(this, &I8237::setMaskBit),
112 
113  modeReg.
114  writer([this](auto &reg, const uint8_t &value) {
115  channels[bits(value, 1, 0)].mode = value;
116  }),
117 
118  clearFlipFlopReg.
119  writer([this](auto &reg, const uint8_t &value) {
120  highByte = false;
121  }),
122 
123  temporaryMasterClearReg.
124  reader([this](auto &reg) ->uint8_t { return tempVal; }).
125  writer([this](auto &reg, const uint8_t &value) { reset(); }),
126 
127  clearMaskReg.
128  writer([this](auto &reg, const uint8_t &value) { maskVal = 0x0; }),
129 
130  writeMaskReg.
131  writer([this](auto &reg, const uint8_t &value) {
132  maskVal = bits(value, 3, 0);
133  })
134  });
135 
136  reset();
137 }
138 
139 void
141 {
142  maskVal = 0xf;
143  requestVal = 0x0;
144  commandVal = 0x0;
145  statusVal = 0x0;
146  tempVal = 0x0;
147  highByte = false;
148 }
149 
150 void
151 I8237::setMaskBit(Register &reg, const uint8_t &command)
152 {
153  uint8_t select = bits(command, 1, 0);
154  uint8_t bitVal = bits(command, 2);
155  panic_if(!bitVal, "Turning on i8237 channels unimplemented.");
156  replaceBits(maskVal, select, bitVal);
157 }
158 
159 void
160 I8237::setRequestBit(Register &reg, const uint8_t &command)
161 {
162  uint8_t select = bits(command, 1, 0);
163  uint8_t bitVal = bits(command, 2);
164  panic_if(bitVal, "Requesting i8237 DMA transfers is unimplemented.");
165  replaceBits(requestVal, select, bitVal);
166 }
167 
168 Tick
170 {
171  regs.read(pkt->getAddr(), pkt->getPtr<void>(), pkt->getSize());
172  pkt->makeAtomicResponse();
173  return latency;
174 }
175 
176 Tick
178 {
179  regs.write(pkt->getAddr(), pkt->getPtr<void>(), pkt->getSize());
180  pkt->makeAtomicResponse();
181  return latency;
182 }
183 
184 void
186 {
187  paramOut(cp, "maskReg", maskVal);
188 }
189 
190 void
192 {
193  paramIn(cp, "maskReg", maskVal);
194 }
195 
196 } // namespace X86ISA
197 } // namespace gem5
Addr pioAddr
Address that the device listens to.
Definition: io_device.hh:151
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
T * getPtr()
get a pointer to the data ptr.
Definition: packet.hh:1212
Addr getAddr() const
Definition: packet.hh:805
unsigned getSize() const
Definition: packet.hh:815
void makeAtomicResponse()
Definition: packet.hh:1071
PioDeviceParams Params
Definition: io_device.hh:134
virtual void read(Addr addr, void *buf, Addr bytes)
Definition: reg_bank.hh:827
virtual void write(Addr addr, const void *buf, Addr bytes)
Definition: reg_bank.hh:884
WriteOnlyReg(const std::string &new_name, Addr offset)
Definition: i8237.cc:76
void setMaskBit(Register &reg, const uint8_t &command)
Definition: i8237.cc:151
Tick read(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: i8237.cc:169
uint8_t requestVal
Definition: i8237.hh:53
std::array< Channel, 4 > channels
Definition: i8237.hh:93
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: i8237.cc:191
uint8_t maskVal
Definition: i8237.hh:51
void setRequestBit(Register &reg, const uint8_t &command)
Definition: i8237.cc:160
uint8_t commandVal
Definition: i8237.hh:54
uint8_t statusVal
Definition: i8237.hh:55
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: i8237.cc:185
RegisterBankLE::Register8 Register
Definition: i8237.hh:47
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: i8237.cc:177
I8237(const Params &p)
Definition: i8237.cc:84
uint8_t tempVal
Definition: i8237.hh:56
RegisterBankLE regs
Definition: i8237.hh:59
Definition: test.h:49
constexpr T bits(T val, unsigned first, unsigned last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it.
Definition: bitfield.hh:76
constexpr void replaceBits(T &val, unsigned first, unsigned last, B bit_val)
A convenience function to replace bits first to last of val with bit_val in place.
Definition: bitfield.hh:197
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:178
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:204
Bitfield< 5, 3 > reg
Definition: types.hh:92
Bitfield< 0 > p
Definition: pagetable.hh:151
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
void paramOut(CheckpointOut &cp, const std::string &name, ExtMachInst const &machInst)
Definition: types.cc:40
void paramIn(CheckpointIn &cp, const std::string &name, ExtMachInst &machInst)
Definition: types.cc:72
uint64_t Tick
Tick count type.
Definition: types.hh:58
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:161
Declaration of the Packet class.

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