fs_translating_port_proxy.hh revision 2521
12810Srdreslin@umich.edu/* 22810Srdreslin@umich.edu * Copyright (c) 2006 The Regents of The University of Michigan 32810Srdreslin@umich.edu * All rights reserved. 42810Srdreslin@umich.edu * 52810Srdreslin@umich.edu * Redistribution and use in source and binary forms, with or without 62810Srdreslin@umich.edu * modification, are permitted provided that the following conditions are 72810Srdreslin@umich.edu * met: redistributions of source code must retain the above copyright 82810Srdreslin@umich.edu * notice, this list of conditions and the following disclaimer; 92810Srdreslin@umich.edu * redistributions in binary form must reproduce the above copyright 102810Srdreslin@umich.edu * notice, this list of conditions and the following disclaimer in the 112810Srdreslin@umich.edu * documentation and/or other materials provided with the distribution; 122810Srdreslin@umich.edu * neither the name of the copyright holders nor the names of its 132810Srdreslin@umich.edu * contributors may be used to endorse or promote products derived from 142810Srdreslin@umich.edu * this software without specific prior written permission. 152810Srdreslin@umich.edu * 162810Srdreslin@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172810Srdreslin@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182810Srdreslin@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192810Srdreslin@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202810Srdreslin@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212810Srdreslin@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222810Srdreslin@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232810Srdreslin@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242810Srdreslin@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252810Srdreslin@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262810Srdreslin@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272810Srdreslin@umich.edu */ 282810Srdreslin@umich.edu 292810Srdreslin@umich.edu/** 302810Srdreslin@umich.edu * @file 314458Sstever@eecs.umich.edu * Virtual Port Object Decleration. These ports incorporate some translation 322810Srdreslin@umich.edu * into their access methods. Thus you can use one to read and write data 332810Srdreslin@umich.edu * to/from virtual addresses. 342810Srdreslin@umich.edu */ 352810Srdreslin@umich.edu 362810Srdreslin@umich.edu#ifndef __MEM_VPORT_HH__ 372810Srdreslin@umich.edu#define __MEM_VPORT_HH__ 382810Srdreslin@umich.edu 392810Srdreslin@umich.edu#include "mem/port.hh" 402810Srdreslin@umich.edu#include "config/full_system.hh" 412810Srdreslin@umich.edu#include "arch/vtophys.hh" 422810Srdreslin@umich.edu 432810Srdreslin@umich.edu 445338Sstever@gmail.com/** A class that translates a virtual address to a physical address and then 455338Sstever@gmail.com * calls the above read/write functions. If an execution context is provided the 465338Sstever@gmail.com * address can alway be translated, If not it can only be translated if it is a 472810Srdreslin@umich.edu * simple address masking operation (such as alpha super page accesses). 484458Sstever@eecs.umich.edu */ 494458Sstever@eecs.umich.edu 502813Srdreslin@umich.educlass VirtualPort : public FunctionalPort 513861Sstever@eecs.umich.edu{ 522810Srdreslin@umich.edu private: 532810Srdreslin@umich.edu ExecContext *xc; 542810Srdreslin@umich.edu 552810Srdreslin@umich.edu public: 564672Sstever@eecs.umich.edu VirtualPort(ExecContext *_xc = NULL) 572810Srdreslin@umich.edu : xc(_xc) 584672Sstever@eecs.umich.edu {} 592810Srdreslin@umich.edu 602810Srdreslin@umich.edu /** Return true if we have an exec context. This is used to prevent someone 612810Srdreslin@umich.edu * from accidently deleting the cpus statically allocated vport. 622810Srdreslin@umich.edu * @return true if an execution context isn't valid 632810Srdreslin@umich.edu */ 643860Sstever@eecs.umich.edu bool nullExecContext() { return xc != NULL; } 653860Sstever@eecs.umich.edu 662810Srdreslin@umich.edu /** Write a piece of data into a virtual address. 672810Srdreslin@umich.edu * @param vaddr virtual address to write to 683738Sstever@eecs.umich.edu * @param data data to write 692810Srdreslin@umich.edu */ 702810Srdreslin@umich.edu template <typename T> 713738Sstever@eecs.umich.edu inline void write(Addr vaddr, T data) 723738Sstever@eecs.umich.edu { 733738Sstever@eecs.umich.edu Addr paddr; 743738Sstever@eecs.umich.edu if (xc) 754965Ssaidi@eecs.umich.edu paddr = TheISA::vtophys(xc,vaddr); 765314Sstever@gmail.com else 774965Ssaidi@eecs.umich.edu paddr = TheISA::vtophys(vaddr); 783738Sstever@eecs.umich.edu 793738Sstever@eecs.umich.edu FunctionalPort::write(paddr, data); 803738Sstever@eecs.umich.edu } 813738Sstever@eecs.umich.edu 824672Sstever@eecs.umich.edu /** Read data from a virtual address and return it. 834672Sstever@eecs.umich.edu * @param vaddr address to read 843738Sstever@eecs.umich.edu * @return data read 853738Sstever@eecs.umich.edu */ 864478Sstever@eecs.umich.edu 874478Sstever@eecs.umich.edu template <typename T> 884478Sstever@eecs.umich.edu inline T read(Addr vaddr) 893738Sstever@eecs.umich.edu { 903738Sstever@eecs.umich.edu Addr paddr; 913738Sstever@eecs.umich.edu if (xc) 923738Sstever@eecs.umich.edu paddr = TheISA::vtophys(xc,vaddr); 933738Sstever@eecs.umich.edu else 943738Sstever@eecs.umich.edu paddr = TheISA::vtophys(vaddr); 953738Sstever@eecs.umich.edu 963738Sstever@eecs.umich.edu return FunctionalPort::read<T>(paddr); 973738Sstever@eecs.umich.edu } 983738Sstever@eecs.umich.edu 993738Sstever@eecs.umich.edu /** Version of readblob that translates virt->phys and deals 1004965Ssaidi@eecs.umich.edu * with page boundries. */ 1015314Sstever@gmail.com virtual void readBlob(Addr addr, uint8_t *p, int size); 1024965Ssaidi@eecs.umich.edu 1033738Sstever@eecs.umich.edu /** Version of writeBlob that translates virt->phys and deals 1043738Sstever@eecs.umich.edu * with page boundries. */ 1053738Sstever@eecs.umich.edu virtual void writeBlob(Addr addr, uint8_t *p, int size); 1063738Sstever@eecs.umich.edu}; 1074672Sstever@eecs.umich.edu 1084672Sstever@eecs.umich.edu#endif //__MEM_VPORT_HH__ 1093738Sstever@eecs.umich.edu 1103738Sstever@eecs.umich.edu