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 529911Sandreas@sandberg.pp.se * mode. Such IPRs always have the flag GENERIC_IPR set and are 539911Sandreas@sandberg.pp.se * handled by this code. 549897Sandreas@sandberg.pp.se */ 559897Sandreas@sandberg.pp.se 569897Sandreas@sandberg.pp.se /** Shift amount when extracting the class of a generic IPR */ 579897Sandreas@sandberg.pp.se const int IPR_CLASS_SHIFT = 48; 589897Sandreas@sandberg.pp.se 599897Sandreas@sandberg.pp.se /** Mask to extract the offset in within a generic IPR class */ 609897Sandreas@sandberg.pp.se const Addr IPR_IN_CLASS_MASK = ULL(0x0000FFFFFFFFFFFF); 619897Sandreas@sandberg.pp.se 629897Sandreas@sandberg.pp.se /** gem5 pseudo-inst emulation. 639897Sandreas@sandberg.pp.se * 649897Sandreas@sandberg.pp.se * Read and writes to this class execute gem5 659897Sandreas@sandberg.pp.se * pseudo-instructions. A write discards the return value of the 669897Sandreas@sandberg.pp.se * instruction, while a read returns it. 679897Sandreas@sandberg.pp.se * 689897Sandreas@sandberg.pp.se * @see pseudoInst() 699897Sandreas@sandberg.pp.se */ 709897Sandreas@sandberg.pp.se const Addr IPR_CLASS_PSEUDO_INST = 0x0; 719897Sandreas@sandberg.pp.se 729897Sandreas@sandberg.pp.se /** @} */ 739897Sandreas@sandberg.pp.se 749897Sandreas@sandberg.pp.se /** 759897Sandreas@sandberg.pp.se * Generate a generic IPR address that emulates a pseudo inst 769897Sandreas@sandberg.pp.se * 779897Sandreas@sandberg.pp.se * @see PseudoInst::pseudoInst() 789897Sandreas@sandberg.pp.se * 799897Sandreas@sandberg.pp.se * @param func Function ID to call. 809897Sandreas@sandberg.pp.se * @param subfunc Sub-function, usually 0. 819897Sandreas@sandberg.pp.se * @return Address in the IPR space corresponding to the call. 829897Sandreas@sandberg.pp.se */ 839897Sandreas@sandberg.pp.se inline Addr 849897Sandreas@sandberg.pp.se iprAddressPseudoInst(uint8_t func, uint8_t subfunc) 859897Sandreas@sandberg.pp.se { 869911Sandreas@sandberg.pp.se return (IPR_CLASS_PSEUDO_INST << IPR_CLASS_SHIFT) | 879897Sandreas@sandberg.pp.se (func << 8) | subfunc; 889897Sandreas@sandberg.pp.se } 899897Sandreas@sandberg.pp.se 909897Sandreas@sandberg.pp.se /** 919897Sandreas@sandberg.pp.se * Check if this is an platform independent IPR access 929897Sandreas@sandberg.pp.se * 939897Sandreas@sandberg.pp.se * Accesses to internal platform independent gem5 registers are 949897Sandreas@sandberg.pp.se * handled by handleGenericIprRead() and 959897Sandreas@sandberg.pp.se * handleGenericIprWrite(). This method determines if a packet 969897Sandreas@sandberg.pp.se * should be routed to those functions instead of the platform 979897Sandreas@sandberg.pp.se * specific code. 989897Sandreas@sandberg.pp.se * 999897Sandreas@sandberg.pp.se * @see handleGenericIprRead 1009897Sandreas@sandberg.pp.se * @see handleGenericIprWrite 1019897Sandreas@sandberg.pp.se */ 1029897Sandreas@sandberg.pp.se inline bool 1039897Sandreas@sandberg.pp.se isGenericIprAccess(const Packet *pkt) 1049897Sandreas@sandberg.pp.se { 1059911Sandreas@sandberg.pp.se Request::Flags flags(pkt->req->getFlags()); 1069911Sandreas@sandberg.pp.se return (flags & Request::MMAPPED_IPR) && 1079911Sandreas@sandberg.pp.se (flags & Request::GENERIC_IPR); 1089897Sandreas@sandberg.pp.se } 1099897Sandreas@sandberg.pp.se 1109897Sandreas@sandberg.pp.se /** 1119897Sandreas@sandberg.pp.se * Handle generic IPR reads 1129897Sandreas@sandberg.pp.se * 1139897Sandreas@sandberg.pp.se * @param xc Thread context of the current thread. 1149897Sandreas@sandberg.pp.se * @param pkt Packet from the CPU 1159897Sandreas@sandberg.pp.se * @return Latency in CPU cycles 1169897Sandreas@sandberg.pp.se */ 1179897Sandreas@sandberg.pp.se Cycles handleGenericIprRead(ThreadContext *xc, Packet *pkt); 1189897Sandreas@sandberg.pp.se /** 1199897Sandreas@sandberg.pp.se * Handle generic IPR writes 1209897Sandreas@sandberg.pp.se * 1219897Sandreas@sandberg.pp.se * @param xc Thread context of the current thread. 1229897Sandreas@sandberg.pp.se * @param pkt Packet from the CPU 1239897Sandreas@sandberg.pp.se * @return Latency in CPU cycles 1249897Sandreas@sandberg.pp.se */ 1259897Sandreas@sandberg.pp.se Cycles handleGenericIprWrite(ThreadContext *xc, Packet *pkt); 1269897Sandreas@sandberg.pp.se 1279897Sandreas@sandberg.pp.se /** 1289897Sandreas@sandberg.pp.se * Helper function to handle IPRs when the target architecture doesn't 1299897Sandreas@sandberg.pp.se * need its own IPR handling. 1309897Sandreas@sandberg.pp.se * 1319897Sandreas@sandberg.pp.se * This function calls handleGenericIprRead if the accessing a 1329897Sandreas@sandberg.pp.se * generic IPR and panics otherwise. 1339897Sandreas@sandberg.pp.se * 1349897Sandreas@sandberg.pp.se * @param xc Thread context of the current thread. 1359897Sandreas@sandberg.pp.se * @param pkt Packet from the CPU 1369897Sandreas@sandberg.pp.se * @return Latency in CPU cycles 1379897Sandreas@sandberg.pp.se */ 1389897Sandreas@sandberg.pp.se inline Cycles 1399897Sandreas@sandberg.pp.se handleIprRead(ThreadContext *xc, Packet *pkt) 1409897Sandreas@sandberg.pp.se { 1419897Sandreas@sandberg.pp.se if (!isGenericIprAccess(pkt)) 1429897Sandreas@sandberg.pp.se panic("Unhandled IPR access\n"); 1439897Sandreas@sandberg.pp.se 1449897Sandreas@sandberg.pp.se return handleGenericIprRead(xc, pkt); 1459897Sandreas@sandberg.pp.se } 1469897Sandreas@sandberg.pp.se 1479897Sandreas@sandberg.pp.se 1489897Sandreas@sandberg.pp.se /** 1499897Sandreas@sandberg.pp.se * Helper function to handle IPRs when the target architecture 1509897Sandreas@sandberg.pp.se * doesn't need its own IPR handling. 1519897Sandreas@sandberg.pp.se * 1529897Sandreas@sandberg.pp.se * This function calls handleGenericIprWrite if the accessing a 1539897Sandreas@sandberg.pp.se * generic IPR and panics otherwise. 1549897Sandreas@sandberg.pp.se * 1559897Sandreas@sandberg.pp.se * @param xc Thread context of the current thread. 1569897Sandreas@sandberg.pp.se * @param pkt Packet from the CPU 1579897Sandreas@sandberg.pp.se * @return Latency in CPU cycles 1589897Sandreas@sandberg.pp.se */ 1599897Sandreas@sandberg.pp.se inline Cycles 1609897Sandreas@sandberg.pp.se handleIprWrite(ThreadContext *xc, Packet *pkt) 1619897Sandreas@sandberg.pp.se { 1629897Sandreas@sandberg.pp.se if (!isGenericIprAccess(pkt)) 1639897Sandreas@sandberg.pp.se panic("Unhandled IPR access\n"); 1649897Sandreas@sandberg.pp.se 1659897Sandreas@sandberg.pp.se return handleGenericIprWrite(xc, pkt); 1669897Sandreas@sandberg.pp.se } 1679897Sandreas@sandberg.pp.se 1689897Sandreas@sandberg.pp.se} // namespace GenericISA 1699897Sandreas@sandberg.pp.se 1709897Sandreas@sandberg.pp.se 1719897Sandreas@sandberg.pp.se 1729897Sandreas@sandberg.pp.se#endif 173