gem5  v22.0.0.2
mm_disk.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2006 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 #include "dev/sparc/mm_disk.hh"
35 
36 #include <cstring>
37 
38 #include "base/trace.hh"
39 #include "debug/IdeDisk.hh"
40 #include "dev/platform.hh"
41 #include "mem/packet_access.hh"
42 #include "mem/port.hh"
43 #include "sim/byteswap.hh"
44 #include "sim/system.hh"
45 
46 namespace gem5
47 {
48 
50  : BasicPioDevice(p, p.image->size() * SectorSize),
51  image(p.image), curSector((off_t)-1), dirty(false)
52 {
53  std::memset(&diskData, 0, SectorSize);
54 }
55 
56 Tick
58 {
59  Addr accessAddr;
60  off_t sector;
61  uint16_t d16;
62  uint32_t d32;
63  uint64_t d64;
64 
65  assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize);
66  accessAddr = pkt->getAddr() - pioAddr;
67 
68  sector = accessAddr / SectorSize;
69 
70  if (sector != curSector) {
71  if (dirty) {
72 #ifndef NDEBUG
73  off_t bytes_written =
74 #endif
76  assert(bytes_written == SectorSize);
77  }
78 #ifndef NDEBUG
79  off_t bytes_read =
80 #endif
81  image->read(diskData, sector);
82  assert(bytes_read == SectorSize);
83  curSector = sector;
84  }
85  switch (pkt->getSize()) {
86  case sizeof(uint8_t):
87  pkt->setRaw(diskData[accessAddr % SectorSize]);
88  DPRINTF(IdeDisk, "reading byte %#x value= %#x\n",
89  accessAddr, diskData[accessAddr % SectorSize]);
90  break;
91  case sizeof(uint16_t):
92  memcpy(&d16, diskData + (accessAddr % SectorSize), 2);
93  pkt->setRaw(d16);
94  DPRINTF(IdeDisk, "reading word %#x value= %#x\n", accessAddr, d16);
95  break;
96  case sizeof(uint32_t):
97  memcpy(&d32, diskData + (accessAddr % SectorSize), 4);
98  pkt->setRaw(d32);
99  DPRINTF(IdeDisk, "reading dword %#x value= %#x\n", accessAddr, d32);
100  break;
101  case sizeof(uint64_t):
102  memcpy(&d64, diskData + (accessAddr % SectorSize), 8);
103  pkt->setRaw(d64);
104  DPRINTF(IdeDisk, "reading qword %#x value= %#x\n", accessAddr, d64);
105  break;
106  default:
107  panic("Invalid access size\n");
108  }
109 
110  pkt->makeAtomicResponse();
111  return pioDelay;
112 }
113 
114 Tick
116 {
117  Addr accessAddr;
118  off_t sector;
119  uint16_t d16;
120  uint32_t d32;
121  uint64_t d64;
122 
123  assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize);
124  accessAddr = pkt->getAddr() - pioAddr;
125 
126  sector = accessAddr / SectorSize;
127 
128  if (sector != curSector) {
129  if (dirty) {
130 #ifndef NDEBUG
131  off_t bytes_written =
132 #endif
134  assert(bytes_written == SectorSize);
135  }
136 #ifndef NDEBUG
137  off_t bytes_read =
138 #endif
139  image->read(diskData, sector);
140  assert(bytes_read == SectorSize);
141  curSector = sector;
142  }
143  dirty = true;
144 
145  switch (pkt->getSize()) {
146  case sizeof(uint8_t):
147  diskData[accessAddr % SectorSize] = htobe(pkt->getRaw<uint8_t>());
148  DPRINTF(IdeDisk, "writing byte %#x value= %#x\n",
149  accessAddr, diskData[accessAddr % SectorSize]);
150  break;
151  case sizeof(uint16_t):
152  d16 = pkt->getRaw<uint16_t>();
153  memcpy(diskData + (accessAddr % SectorSize), &d16, 2);
154  DPRINTF(IdeDisk, "writing word %#x value= %#x\n", accessAddr, d16);
155  break;
156  case sizeof(uint32_t):
157  d32 = pkt->getRaw<uint32_t>();
158  memcpy(diskData + (accessAddr % SectorSize), &d32, 4);
159  DPRINTF(IdeDisk, "writing dword %#x value= %#x\n", accessAddr, d32);
160  break;
161  case sizeof(uint64_t):
162  d64 = pkt->getRaw<uint64_t>();
163  memcpy(diskData + (accessAddr % SectorSize), &d64, 8);
164  DPRINTF(IdeDisk, "writing qword %#x value= %#x\n", accessAddr, d64);
165  break;
166  default:
167  panic("Invalid access size\n");
168  }
169 
170  pkt->makeAtomicResponse();
171  return pioDelay;
172 }
173 
174 void
176 {
177  // just write any dirty changes to the cow layer it will take care of
178  // serialization
179  if (dirty) {
180 #ifndef NDEBUG
181  int bytes_read =
182 #endif
184  assert(bytes_read == SectorSize);
185  }
187 }
188 
189 } // namespace gem5
gem5::BasicPioDevice::pioAddr
Addr pioAddr
Address that the device listens to.
Definition: io_device.hh:151
system.hh
gem5::Packet::setRaw
void setRaw(T v)
Set the value in the data pointer to v without byte swapping.
Definition: packet_access.hh:61
gem5::MmDisk::image
DiskImage * image
Definition: mm_disk.hh:47
SectorSize
#define SectorSize
Definition: disk_image.hh:44
gem5::MmDisk::read
Tick read(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: mm_disk.cc:57
mm_disk.hh
gem5::Packet::makeAtomicResponse
void makeAtomicResponse()
Definition: packet.hh:1056
gem5::DiskImage::write
virtual std::streampos write(const uint8_t *data, std::streampos offset)=0
gem5::htobe
T htobe(T value)
Definition: byteswap.hh:174
gem5::PioDevice::Params
PioDeviceParams Params
Definition: io_device.hh:134
gem5::MmDisk::MmDisk
MmDisk(const Params &p)
Definition: mm_disk.cc:49
gem5::MmDisk::diskData
uint8_t diskData[SectorSize]
Definition: mm_disk.hh:50
gem5::Packet::getRaw
T getRaw() const
Get the data in the packet without byte swapping.
Definition: packet_access.hh:52
gem5::VegaISA::p
Bitfield< 54 > p
Definition: pagetable.hh:70
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:186
gem5::Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:291
gem5::Tick
uint64_t Tick
Tick count type.
Definition: types.hh:58
port.hh
gem5::BasicPioDevice::pioDelay
Tick pioDelay
Delay that the device experinces on an access.
Definition: io_device.hh:157
gem5::MmDisk::write
Tick write(PacketPtr pkt) override
Pure virtual function that the device must implement.
Definition: mm_disk.cc:115
gem5::ClockedObject::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: clocked_object.cc:59
platform.hh
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
packet_access.hh
gem5::MmDisk::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: mm_disk.cc:175
gem5::MmDisk::curSector
off_t curSector
Definition: mm_disk.hh:48
gem5::BasicPioDevice::pioSize
Addr pioSize
Size that the device's address range.
Definition: io_device.hh:154
gem5::MmDisk::dirty
bool dirty
Definition: mm_disk.hh:49
gem5::DiskImage::read
virtual std::streampos read(uint8_t *data, std::streampos offset) const =0
gem5::CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:66
gem5::IdeDisk
IDE Disk device model.
Definition: ide_disk.hh:216
trace.hh
gem5::Packet::getAddr
Addr getAddr() const
Definition: packet.hh:790
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::BasicPioDevice
Definition: io_device.hh:147
gem5::Packet::getSize
unsigned getSize() const
Definition: packet.hh:800
byteswap.hh
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:178

Generated on Thu Jul 28 2022 13:32:32 for gem5 by doxygen 1.8.17