mm_disk.cc (4198:4ada78de338c) mm_disk.cc (4762:c94e103c83ad)
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 * Authors: Ali Saidi
29 */
30
31/** @file
32 * This device acts as a disk similar to the memory mapped disk device
33 * in legion. Any access is translated to an offset in the disk image.
34 */
35
36#include <cstring>
37
38#include "base/trace.hh"
39#include "dev/sparc/mm_disk.hh"
40#include "dev/platform.hh"
41#include "mem/port.hh"
42#include "mem/packet_access.hh"
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 * Authors: Ali Saidi
29 */
30
31/** @file
32 * This device acts as a disk similar to the memory mapped disk device
33 * in legion. Any access is translated to an offset in the disk image.
34 */
35
36#include <cstring>
37
38#include "base/trace.hh"
39#include "dev/sparc/mm_disk.hh"
40#include "dev/platform.hh"
41#include "mem/port.hh"
42#include "mem/packet_access.hh"
43#include "sim/builder.hh"
44#include "sim/byteswap.hh"
45#include "sim/system.hh"
46
43#include "sim/byteswap.hh"
44#include "sim/system.hh"
45
47MmDisk::MmDisk(Params *p)
46MmDisk::MmDisk(const Params *p)
48 : BasicPioDevice(p), image(p->image), curSector((off_t)-1), dirty(false)
49{
50 std::memset(&diskData, 0, SectorSize);
51 pioSize = image->size() * SectorSize;
52}
53
54Tick
55MmDisk::read(PacketPtr pkt)
56{
57 Addr accessAddr;
58 off_t sector;
59 off_t bytes_read;
60 uint16_t d16;
61 uint32_t d32;
62 uint64_t d64;
63
64 assert(pkt->result == Packet::Unknown);
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 bytes_read = image->write(diskData, curSector);
73 assert(bytes_read == SectorSize);
74 }
75 bytes_read = image->read(diskData, sector);
76 assert(bytes_read == SectorSize);
77 curSector = sector;
78 }
79 switch (pkt->getSize()) {
80 case sizeof(uint8_t):
81 pkt->set(diskData[accessAddr % SectorSize]);
82 DPRINTF(IdeDisk, "reading byte %#x value= %#x\n", accessAddr, diskData[accessAddr %
83 SectorSize]);
84 break;
85 case sizeof(uint16_t):
86 memcpy(&d16, diskData + (accessAddr % SectorSize), 2);
87 pkt->set(htobe(d32));
88 DPRINTF(IdeDisk, "reading word %#x value= %#x\n", accessAddr, d16);
89 break;
90 case sizeof(uint32_t):
91 memcpy(&d32, diskData + (accessAddr % SectorSize), 4);
92 pkt->set(htobe(d32));
93 DPRINTF(IdeDisk, "reading dword %#x value= %#x\n", accessAddr, d32);
94 break;
95 case sizeof(uint64_t):
96 memcpy(&d64, diskData + (accessAddr % SectorSize), 8);
97 pkt->set(htobe(d64));
98 DPRINTF(IdeDisk, "reading qword %#x value= %#x\n", accessAddr, d64);
99 break;
100 default:
101 panic("Invalid access size\n");
102 }
103
104 pkt->result = Packet::Success;
105 return pioDelay;
106}
107
108Tick
109MmDisk::write(PacketPtr pkt)
110{
111 Addr accessAddr;
112 off_t sector;
113 off_t bytes_read;
114 uint16_t d16;
115 uint32_t d32;
116 uint64_t d64;
117
118 assert(pkt->result == Packet::Unknown);
119 assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize);
120 accessAddr = pkt->getAddr() - pioAddr;
121
122 sector = accessAddr / SectorSize;
123
124 if (sector != curSector) {
125 if (dirty) {
126 bytes_read = image->write(diskData, curSector);
127 assert(bytes_read == SectorSize);
128 }
129 bytes_read = image->read(diskData, sector);
130 assert(bytes_read == SectorSize);
131 curSector = sector;
132 }
133 dirty = true;
134
135 switch (pkt->getSize()) {
136 case sizeof(uint8_t):
137 diskData[accessAddr % SectorSize] = htobe(pkt->get<uint8_t>());
138 DPRINTF(IdeDisk, "writing byte %#x value= %#x\n", accessAddr, diskData[accessAddr %
139 SectorSize]);
140 break;
141 case sizeof(uint16_t):
142 d16 = htobe(pkt->get<uint16_t>());
143 memcpy(diskData + (accessAddr % SectorSize), &d16, 2);
144 DPRINTF(IdeDisk, "writing word %#x value= %#x\n", accessAddr, d16);
145 break;
146 case sizeof(uint32_t):
147 d32 = htobe(pkt->get<uint32_t>());
148 memcpy(diskData + (accessAddr % SectorSize), &d32, 4);
149 DPRINTF(IdeDisk, "writing dword %#x value= %#x\n", accessAddr, d32);
150 break;
151 case sizeof(uint64_t):
152 d64 = htobe(pkt->get<uint64_t>());
153 memcpy(diskData + (accessAddr % SectorSize), &d64, 8);
154 DPRINTF(IdeDisk, "writing qword %#x value= %#x\n", accessAddr, d64);
155 break;
156 default:
157 panic("Invalid access size\n");
158 }
159
160 pkt->result = Packet::Success;
161 return pioDelay;
162}
163
164void
165MmDisk::serialize(std::ostream &os)
166{
167 // just write any dirty changes to the cow layer it will take care of
168 // serialization
169 int bytes_read;
170 if (dirty) {
171 bytes_read = image->write(diskData, curSector);
172 assert(bytes_read == SectorSize);
173 }
174}
175
47 : BasicPioDevice(p), image(p->image), curSector((off_t)-1), dirty(false)
48{
49 std::memset(&diskData, 0, SectorSize);
50 pioSize = image->size() * SectorSize;
51}
52
53Tick
54MmDisk::read(PacketPtr pkt)
55{
56 Addr accessAddr;
57 off_t sector;
58 off_t bytes_read;
59 uint16_t d16;
60 uint32_t d32;
61 uint64_t d64;
62
63 assert(pkt->result == Packet::Unknown);
64 assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize);
65 accessAddr = pkt->getAddr() - pioAddr;
66
67 sector = accessAddr / SectorSize;
68
69 if (sector != curSector) {
70 if (dirty) {
71 bytes_read = image->write(diskData, curSector);
72 assert(bytes_read == SectorSize);
73 }
74 bytes_read = image->read(diskData, sector);
75 assert(bytes_read == SectorSize);
76 curSector = sector;
77 }
78 switch (pkt->getSize()) {
79 case sizeof(uint8_t):
80 pkt->set(diskData[accessAddr % SectorSize]);
81 DPRINTF(IdeDisk, "reading byte %#x value= %#x\n", accessAddr, diskData[accessAddr %
82 SectorSize]);
83 break;
84 case sizeof(uint16_t):
85 memcpy(&d16, diskData + (accessAddr % SectorSize), 2);
86 pkt->set(htobe(d32));
87 DPRINTF(IdeDisk, "reading word %#x value= %#x\n", accessAddr, d16);
88 break;
89 case sizeof(uint32_t):
90 memcpy(&d32, diskData + (accessAddr % SectorSize), 4);
91 pkt->set(htobe(d32));
92 DPRINTF(IdeDisk, "reading dword %#x value= %#x\n", accessAddr, d32);
93 break;
94 case sizeof(uint64_t):
95 memcpy(&d64, diskData + (accessAddr % SectorSize), 8);
96 pkt->set(htobe(d64));
97 DPRINTF(IdeDisk, "reading qword %#x value= %#x\n", accessAddr, d64);
98 break;
99 default:
100 panic("Invalid access size\n");
101 }
102
103 pkt->result = Packet::Success;
104 return pioDelay;
105}
106
107Tick
108MmDisk::write(PacketPtr pkt)
109{
110 Addr accessAddr;
111 off_t sector;
112 off_t bytes_read;
113 uint16_t d16;
114 uint32_t d32;
115 uint64_t d64;
116
117 assert(pkt->result == Packet::Unknown);
118 assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize);
119 accessAddr = pkt->getAddr() - pioAddr;
120
121 sector = accessAddr / SectorSize;
122
123 if (sector != curSector) {
124 if (dirty) {
125 bytes_read = image->write(diskData, curSector);
126 assert(bytes_read == SectorSize);
127 }
128 bytes_read = image->read(diskData, sector);
129 assert(bytes_read == SectorSize);
130 curSector = sector;
131 }
132 dirty = true;
133
134 switch (pkt->getSize()) {
135 case sizeof(uint8_t):
136 diskData[accessAddr % SectorSize] = htobe(pkt->get<uint8_t>());
137 DPRINTF(IdeDisk, "writing byte %#x value= %#x\n", accessAddr, diskData[accessAddr %
138 SectorSize]);
139 break;
140 case sizeof(uint16_t):
141 d16 = htobe(pkt->get<uint16_t>());
142 memcpy(diskData + (accessAddr % SectorSize), &d16, 2);
143 DPRINTF(IdeDisk, "writing word %#x value= %#x\n", accessAddr, d16);
144 break;
145 case sizeof(uint32_t):
146 d32 = htobe(pkt->get<uint32_t>());
147 memcpy(diskData + (accessAddr % SectorSize), &d32, 4);
148 DPRINTF(IdeDisk, "writing dword %#x value= %#x\n", accessAddr, d32);
149 break;
150 case sizeof(uint64_t):
151 d64 = htobe(pkt->get<uint64_t>());
152 memcpy(diskData + (accessAddr % SectorSize), &d64, 8);
153 DPRINTF(IdeDisk, "writing qword %#x value= %#x\n", accessAddr, d64);
154 break;
155 default:
156 panic("Invalid access size\n");
157 }
158
159 pkt->result = Packet::Success;
160 return pioDelay;
161}
162
163void
164MmDisk::serialize(std::ostream &os)
165{
166 // just write any dirty changes to the cow layer it will take care of
167 // serialization
168 int bytes_read;
169 if (dirty) {
170 bytes_read = image->write(diskData, curSector);
171 assert(bytes_read == SectorSize);
172 }
173}
174
176
177
178
179BEGIN_DECLARE_SIM_OBJECT_PARAMS(MmDisk)
180 Param<Addr> pio_addr;
181 Param<Tick> pio_latency;
182 Param<Addr> pio_size;
183 SimObjectParam<Platform *> platform;
184 SimObjectParam<System *> system;
185 SimObjectParam<DiskImage *> image;
186END_DECLARE_SIM_OBJECT_PARAMS(MmDisk)
187
188BEGIN_INIT_SIM_OBJECT_PARAMS(MmDisk)
189
190 INIT_PARAM(pio_addr, "Device Address"),
191 INIT_PARAM(pio_latency, "Programmed IO latency"),
192 INIT_PARAM(pio_size, "Size of address range"),
193 INIT_PARAM(platform, "platform"),
194 INIT_PARAM(system, "system object"),
195 INIT_PARAM(image, "disk image")
196
197END_INIT_SIM_OBJECT_PARAMS(MmDisk)
198
199CREATE_SIM_OBJECT(MmDisk)
175MmDisk *
176MmDiskParams::create()
200{
177{
201 MmDisk::Params *p = new MmDisk::Params;
202 p->name = getInstanceName();
203 p->pio_addr = pio_addr;
204 p->pio_delay = pio_latency;
205 p->platform = platform;
206 p->system = system;
207 p->image = image;
208 return new MmDisk(p);
178 return new MmDisk(this);
209}
179}
210
211REGISTER_SIM_OBJECT("MmDisk", MmDisk)