mmapped_ipr.hh revision 9897
19897Sandreas@sandberg.pp.se/* 29897Sandreas@sandberg.pp.se * Copyright (c) 2013 Andreas Sandberg 39897Sandreas@sandberg.pp.se * All rights reserved. 49897Sandreas@sandberg.pp.se * 59897Sandreas@sandberg.pp.se * Redistribution and use in source and binary forms, with or without 69897Sandreas@sandberg.pp.se * modification, are permitted provided that the following conditions are 79897Sandreas@sandberg.pp.se * met: redistributions of source code must retain the above copyright 89897Sandreas@sandberg.pp.se * notice, this list of conditions and the following disclaimer; 99897Sandreas@sandberg.pp.se * redistributions in binary form must reproduce the above copyright 109897Sandreas@sandberg.pp.se * notice, this list of conditions and the following disclaimer in the 119897Sandreas@sandberg.pp.se * documentation and/or other materials provided with the distribution; 129897Sandreas@sandberg.pp.se * neither the name of the copyright holders nor the names of its 139897Sandreas@sandberg.pp.se * contributors may be used to endorse or promote products derived from 149897Sandreas@sandberg.pp.se * this software without specific prior written permission. 159897Sandreas@sandberg.pp.se * 169897Sandreas@sandberg.pp.se * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 179897Sandreas@sandberg.pp.se * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 189897Sandreas@sandberg.pp.se * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 199897Sandreas@sandberg.pp.se * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 209897Sandreas@sandberg.pp.se * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 219897Sandreas@sandberg.pp.se * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 229897Sandreas@sandberg.pp.se * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 239897Sandreas@sandberg.pp.se * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 249897Sandreas@sandberg.pp.se * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 259897Sandreas@sandberg.pp.se * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 269897Sandreas@sandberg.pp.se * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 279897Sandreas@sandberg.pp.se * 289897Sandreas@sandberg.pp.se * Authors: Andreas Sandberg 299897Sandreas@sandberg.pp.se */ 309897Sandreas@sandberg.pp.se 319897Sandreas@sandberg.pp.se#ifndef __ARCH_GENERIC_MMAPPED_IPR_HH__ 329897Sandreas@sandberg.pp.se#define __ARCH_GENERIC_MMAPPED_IPR_HH__ 339897Sandreas@sandberg.pp.se 349897Sandreas@sandberg.pp.se#include "base/types.hh" 359897Sandreas@sandberg.pp.se#include "mem/packet.hh" 369897Sandreas@sandberg.pp.se 379897Sandreas@sandberg.pp.seclass ThreadContext; 389897Sandreas@sandberg.pp.se 399897Sandreas@sandberg.pp.se/** 409897Sandreas@sandberg.pp.se * @file 419897Sandreas@sandberg.pp.se * 429897Sandreas@sandberg.pp.se * ISA-generic helper functions for memory mapped IPR accesses. 439897Sandreas@sandberg.pp.se */ 449897Sandreas@sandberg.pp.se 459897Sandreas@sandberg.pp.senamespace GenericISA 469897Sandreas@sandberg.pp.se{ 479897Sandreas@sandberg.pp.se /** @{ */ 489897Sandreas@sandberg.pp.se /** 499897Sandreas@sandberg.pp.se * Memory requests with the MMAPPED_IPR flag are generally mapped 509897Sandreas@sandberg.pp.se * to registers. There is a class of these registers that are 519897Sandreas@sandberg.pp.se * internal to gem5, for example gem5 pseudo-ops in virtualized 529897Sandreas@sandberg.pp.se * mode. 539897Sandreas@sandberg.pp.se * 549897Sandreas@sandberg.pp.se * In order to make the IPR space manageable we always set bit 63 559897Sandreas@sandberg.pp.se * (IPR_GENERIC) for accesses that should be handled by the 569897Sandreas@sandberg.pp.se * generic ISA code. Architectures may use the rest of the IPR 579897Sandreas@sandberg.pp.se * space internally. 589897Sandreas@sandberg.pp.se */ 599897Sandreas@sandberg.pp.se 609897Sandreas@sandberg.pp.se /** Is this a generic IPR access? */ 619897Sandreas@sandberg.pp.se const Addr IPR_GENERIC = ULL(0x8000000000000000); 629897Sandreas@sandberg.pp.se 639897Sandreas@sandberg.pp.se /** @{ */ 649897Sandreas@sandberg.pp.se /** Mask when extracting the class of a generic IPR */ 659897Sandreas@sandberg.pp.se const Addr IPR_CLASS_MASK = ULL(0x7FFF000000000000); 669897Sandreas@sandberg.pp.se /** Shift amount when extracting the class of a generic IPR */ 679897Sandreas@sandberg.pp.se const int IPR_CLASS_SHIFT = 48; 689897Sandreas@sandberg.pp.se /** @} */ 699897Sandreas@sandberg.pp.se 709897Sandreas@sandberg.pp.se /** Mask to extract the offset in within a generic IPR class */ 719897Sandreas@sandberg.pp.se const Addr IPR_IN_CLASS_MASK = ULL(0x0000FFFFFFFFFFFF); 729897Sandreas@sandberg.pp.se 739897Sandreas@sandberg.pp.se /** gem5 pseudo-inst emulation. 749897Sandreas@sandberg.pp.se * 759897Sandreas@sandberg.pp.se * Read and writes to this class execute gem5 769897Sandreas@sandberg.pp.se * pseudo-instructions. A write discards the return value of the 779897Sandreas@sandberg.pp.se * instruction, while a read returns it. 789897Sandreas@sandberg.pp.se * 799897Sandreas@sandberg.pp.se * @see pseudoInst() 809897Sandreas@sandberg.pp.se */ 819897Sandreas@sandberg.pp.se const Addr IPR_CLASS_PSEUDO_INST = 0x0; 829897Sandreas@sandberg.pp.se 839897Sandreas@sandberg.pp.se /** @} */ 849897Sandreas@sandberg.pp.se 859897Sandreas@sandberg.pp.se /** 869897Sandreas@sandberg.pp.se * Generate a generic IPR address that emulates a pseudo inst 879897Sandreas@sandberg.pp.se * 889897Sandreas@sandberg.pp.se * @see PseudoInst::pseudoInst() 899897Sandreas@sandberg.pp.se * 909897Sandreas@sandberg.pp.se * @param func Function ID to call. 919897Sandreas@sandberg.pp.se * @param subfunc Sub-function, usually 0. 929897Sandreas@sandberg.pp.se * @return Address in the IPR space corresponding to the call. 939897Sandreas@sandberg.pp.se */ 949897Sandreas@sandberg.pp.se inline Addr 959897Sandreas@sandberg.pp.se iprAddressPseudoInst(uint8_t func, uint8_t subfunc) 969897Sandreas@sandberg.pp.se { 979897Sandreas@sandberg.pp.se return IPR_GENERIC | (IPR_CLASS_PSEUDO_INST << IPR_CLASS_SHIFT) | 989897Sandreas@sandberg.pp.se (func << 8) | subfunc; 999897Sandreas@sandberg.pp.se } 1009897Sandreas@sandberg.pp.se 1019897Sandreas@sandberg.pp.se /** 1029897Sandreas@sandberg.pp.se * Check if this is an platform independent IPR access 1039897Sandreas@sandberg.pp.se * 1049897Sandreas@sandberg.pp.se * Accesses to internal platform independent gem5 registers are 1059897Sandreas@sandberg.pp.se * handled by handleGenericIprRead() and 1069897Sandreas@sandberg.pp.se * handleGenericIprWrite(). This method determines if a packet 1079897Sandreas@sandberg.pp.se * should be routed to those functions instead of the platform 1089897Sandreas@sandberg.pp.se * specific code. 1099897Sandreas@sandberg.pp.se * 1109897Sandreas@sandberg.pp.se * @see handleGenericIprRead 1119897Sandreas@sandberg.pp.se * @see handleGenericIprWrite 1129897Sandreas@sandberg.pp.se */ 1139897Sandreas@sandberg.pp.se inline bool 1149897Sandreas@sandberg.pp.se isGenericIprAccess(const Packet *pkt) 1159897Sandreas@sandberg.pp.se { 1169897Sandreas@sandberg.pp.se return pkt->getAddr() & IPR_GENERIC; 1179897Sandreas@sandberg.pp.se } 1189897Sandreas@sandberg.pp.se 1199897Sandreas@sandberg.pp.se /** 1209897Sandreas@sandberg.pp.se * Handle generic IPR reads 1219897Sandreas@sandberg.pp.se * 1229897Sandreas@sandberg.pp.se * @param xc Thread context of the current thread. 1239897Sandreas@sandberg.pp.se * @param pkt Packet from the CPU 1249897Sandreas@sandberg.pp.se * @return Latency in CPU cycles 1259897Sandreas@sandberg.pp.se */ 1269897Sandreas@sandberg.pp.se Cycles handleGenericIprRead(ThreadContext *xc, Packet *pkt); 1279897Sandreas@sandberg.pp.se /** 1289897Sandreas@sandberg.pp.se * Handle generic IPR writes 1299897Sandreas@sandberg.pp.se * 1309897Sandreas@sandberg.pp.se * @param xc Thread context of the current thread. 1319897Sandreas@sandberg.pp.se * @param pkt Packet from the CPU 1329897Sandreas@sandberg.pp.se * @return Latency in CPU cycles 1339897Sandreas@sandberg.pp.se */ 1349897Sandreas@sandberg.pp.se Cycles handleGenericIprWrite(ThreadContext *xc, Packet *pkt); 1359897Sandreas@sandberg.pp.se 1369897Sandreas@sandberg.pp.se /** 1379897Sandreas@sandberg.pp.se * Helper function to handle IPRs when the target architecture doesn't 1389897Sandreas@sandberg.pp.se * need its own IPR handling. 1399897Sandreas@sandberg.pp.se * 1409897Sandreas@sandberg.pp.se * This function calls handleGenericIprRead if the accessing a 1419897Sandreas@sandberg.pp.se * generic IPR and panics otherwise. 1429897Sandreas@sandberg.pp.se * 1439897Sandreas@sandberg.pp.se * @param xc Thread context of the current thread. 1449897Sandreas@sandberg.pp.se * @param pkt Packet from the CPU 1459897Sandreas@sandberg.pp.se * @return Latency in CPU cycles 1469897Sandreas@sandberg.pp.se */ 1479897Sandreas@sandberg.pp.se inline Cycles 1489897Sandreas@sandberg.pp.se handleIprRead(ThreadContext *xc, Packet *pkt) 1499897Sandreas@sandberg.pp.se { 1509897Sandreas@sandberg.pp.se if (!isGenericIprAccess(pkt)) 1519897Sandreas@sandberg.pp.se panic("Unhandled IPR access\n"); 1529897Sandreas@sandberg.pp.se 1539897Sandreas@sandberg.pp.se return handleGenericIprRead(xc, pkt); 1549897Sandreas@sandberg.pp.se } 1559897Sandreas@sandberg.pp.se 1569897Sandreas@sandberg.pp.se 1579897Sandreas@sandberg.pp.se /** 1589897Sandreas@sandberg.pp.se * Helper function to handle IPRs when the target architecture 1599897Sandreas@sandberg.pp.se * doesn't need its own IPR handling. 1609897Sandreas@sandberg.pp.se * 1619897Sandreas@sandberg.pp.se * This function calls handleGenericIprWrite if the accessing a 1629897Sandreas@sandberg.pp.se * generic IPR and panics otherwise. 1639897Sandreas@sandberg.pp.se * 1649897Sandreas@sandberg.pp.se * @param xc Thread context of the current thread. 1659897Sandreas@sandberg.pp.se * @param pkt Packet from the CPU 1669897Sandreas@sandberg.pp.se * @return Latency in CPU cycles 1679897Sandreas@sandberg.pp.se */ 1689897Sandreas@sandberg.pp.se inline Cycles 1699897Sandreas@sandberg.pp.se handleIprWrite(ThreadContext *xc, Packet *pkt) 1709897Sandreas@sandberg.pp.se { 1719897Sandreas@sandberg.pp.se if (!isGenericIprAccess(pkt)) 1729897Sandreas@sandberg.pp.se panic("Unhandled IPR access\n"); 1739897Sandreas@sandberg.pp.se 1749897Sandreas@sandberg.pp.se return handleGenericIprWrite(xc, pkt); 1759897Sandreas@sandberg.pp.se } 1769897Sandreas@sandberg.pp.se 1779897Sandreas@sandberg.pp.se} // namespace GenericISA 1789897Sandreas@sandberg.pp.se 1799897Sandreas@sandberg.pp.se 1809897Sandreas@sandberg.pp.se 1819897Sandreas@sandberg.pp.se#endif 182