mm_disk.cc revision 3898:42a529d97cf2
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 "base/trace.hh" 37#include "dev/sparc/mm_disk.hh" 38#include "dev/platform.hh" 39#include "mem/port.hh" 40#include "mem/packet_access.hh" 41#include "sim/builder.hh" 42#include "sim/byteswap.hh" 43#include "sim/system.hh" 44 45MmDisk::MmDisk(Params *p) 46 : BasicPioDevice(p), image(p->image), curSector((uint64_t)-1), dirty(false) 47{ 48 memset(&bytes, 0, SectorSize); 49 pioSize = image->size() * SectorSize; 50} 51 52Tick 53MmDisk::read(PacketPtr pkt) 54{ 55 Addr accessAddr; 56 off_t sector; 57 off_t bytes_read; 58 uint16_t *d16; 59 uint32_t *d32; 60 uint64_t *d64; 61 62 assert(pkt->result == Packet::Unknown); 63 assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize); 64 accessAddr = pkt->getAddr() - pioAddr; 65 66 sector = accessAddr / SectorSize; 67 68 if (sector != curSector) { 69 if (dirty) 70 bytes_read = image->write(bytes, curSector); 71 bytes_read = image->read(bytes, sector); 72 curSector = sector; 73 } 74 switch (pkt->getSize()) { 75 case sizeof(uint8_t): 76 pkt->set(bytes[accessAddr % SectorSize]); 77 break; 78 case sizeof(uint16_t): 79 d16 = (uint16_t*)bytes + (accessAddr % SectorSize)/2; 80 pkt->set(htobe(*d16)); 81 break; 82 case sizeof(uint32_t): 83 d32 = (uint32_t*)bytes + (accessAddr % SectorSize)/4; 84 pkt->set(htobe(*d32)); 85 break; 86 case sizeof(uint64_t): 87 d64 = (uint64_t*)bytes + (accessAddr % SectorSize)/8; 88 pkt->set(htobe(*d64)); 89 break; 90 default: 91 panic("Invalid access size\n"); 92 } 93 94 pkt->result = Packet::Success; 95 return pioDelay; 96} 97 98Tick 99MmDisk::write(PacketPtr pkt) 100{ 101 panic("need to implement\n"); 102} 103 104 105BEGIN_DECLARE_SIM_OBJECT_PARAMS(MmDisk) 106 Param<Addr> pio_addr; 107 Param<Tick> pio_latency; 108 Param<Addr> pio_size; 109 SimObjectParam<Platform *> platform; 110 SimObjectParam<System *> system; 111 SimObjectParam<DiskImage *> image; 112END_DECLARE_SIM_OBJECT_PARAMS(MmDisk) 113 114BEGIN_INIT_SIM_OBJECT_PARAMS(MmDisk) 115 116 INIT_PARAM(pio_addr, "Device Address"), 117 INIT_PARAM(pio_latency, "Programmed IO latency"), 118 INIT_PARAM(pio_size, "Size of address range"), 119 INIT_PARAM(platform, "platform"), 120 INIT_PARAM(system, "system object"), 121 INIT_PARAM(image, "disk image") 122 123END_INIT_SIM_OBJECT_PARAMS(MmDisk) 124 125CREATE_SIM_OBJECT(MmDisk) 126{ 127 MmDisk::Params *p = new MmDisk::Params; 128 p->name = getInstanceName(); 129 p->pio_addr = pio_addr; 130 p->pio_delay = pio_latency; 131 p->platform = platform; 132 p->system = system; 133 p->image = image; 134 return new MmDisk(p); 135} 136 137REGISTER_SIM_OBJECT("MmDisk", MmDisk) 138