request.hh revision 4040:eb894f3fc168
1/* 2 * Copyright (c) 2002-2005 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: Ron Dreslinski 29 * Steve Reinhardt 30 * Ali Saidi 31 */ 32 33/** 34 * @file 35 * Declaration of a request, the overall memory request consisting of 36 the parts of the request that are persistent throughout the transaction. 37 */ 38 39#ifndef __MEM_REQUEST_HH__ 40#define __MEM_REQUEST_HH__ 41 42#include "sim/host.hh" 43#include "sim/root.hh" 44 45#include <cassert> 46 47class Request; 48 49typedef Request* RequestPtr; 50 51 52/** ASI information for this request if it exsits. */ 53const uint32_t ASI_BITS = 0x000FF; 54/** The request is a Load locked/store conditional. */ 55const uint32_t LOCKED = 0x00100; 56/** The virtual address is also the physical address. */ 57const uint32_t PHYSICAL = 0x00200; 58/** The request is an ALPHA VPTE pal access (hw_ld). */ 59const uint32_t VPTE = 0x00400; 60/** Use the alternate mode bits in ALPHA. */ 61const uint32_t ALTMODE = 0x00800; 62/** The request is to an uncacheable address. */ 63const uint32_t UNCACHEABLE = 0x01000; 64/** The request should not cause a page fault. */ 65const uint32_t NO_FAULT = 0x02000; 66/** The request should be prefetched into the exclusive state. */ 67const uint32_t PF_EXCLUSIVE = 0x10000; 68/** The request should be marked as LRU. */ 69const uint32_t EVICT_NEXT = 0x20000; 70/** The request should ignore unaligned access faults */ 71const uint32_t NO_ALIGN_FAULT = 0x40000; 72/** The request was an instruction read. */ 73const uint32_t INST_READ = 0x80000; 74/** This request is for a memory swap. */ 75const uint32_t MEM_SWAP = 0x100000; 76const uint32_t MEM_SWAP_COND = 0x200000; 77 78 79class Request 80{ 81 private: 82 /** 83 * The physical address of the request. Valid only if validPaddr 84 * is set. */ 85 Addr paddr; 86 87 /** 88 * The size of the request. This field must be set when vaddr or 89 * paddr is written via setVirt() or setPhys(), so it is always 90 * valid as long as one of the address fields is valid. */ 91 int size; 92 93 /** Flag structure for the request. */ 94 uint32_t flags; 95 96 /** 97 * The time this request was started. Used to calculate 98 * latencies. This field is set to curTick any time paddr or vaddr 99 * is written. */ 100 Tick time; 101 102 /** The address space ID. */ 103 int asid; 104 105 /** This request is to a memory mapped register. */ 106 bool mmapedIpr; 107 108 /** The virtual address of the request. */ 109 Addr vaddr; 110 111 /** Extra data for the request, such as the return value of 112 * store conditional or the compare value for a CAS. */ 113 uint64_t extraData; 114 115 /** The cpu number (for statistics, typically). */ 116 int cpuNum; 117 /** The requesting thread id (for statistics, typically). */ 118 int threadNum; 119 120 /** program counter of initiating access; for tracing/debugging */ 121 Addr pc; 122 123 /** Whether or not paddr is valid (has been written yet). */ 124 bool validPaddr; 125 /** Whether or not the asid & vaddr are valid. */ 126 bool validAsidVaddr; 127 /** Whether or not the sc result is valid. */ 128 bool validExData; 129 /** Whether or not the cpu number & thread ID are valid. */ 130 bool validCpuAndThreadNums; 131 /** Whether or not the pc is valid. */ 132 bool validPC; 133 134 public: 135 /** Minimal constructor. No fields are initialized. */ 136 Request() 137 : validPaddr(false), validAsidVaddr(false), 138 validExData(false), validCpuAndThreadNums(false), validPC(false) 139 {} 140 141 /** 142 * Constructor for physical (e.g. device) requests. Initializes 143 * just physical address, size, flags, and timestamp (to curTick). 144 * These fields are adequate to perform a request. */ 145 Request(Addr _paddr, int _size, int _flags) 146 : validCpuAndThreadNums(false) 147 { setPhys(_paddr, _size, _flags); } 148 149 Request(int _asid, Addr _vaddr, int _size, int _flags, Addr _pc, 150 int _cpuNum, int _threadNum) 151 { 152 setThreadContext(_cpuNum, _threadNum); 153 setVirt(_asid, _vaddr, _size, _flags, _pc); 154 } 155 156 /** 157 * Set up CPU and thread numbers. */ 158 void setThreadContext(int _cpuNum, int _threadNum) 159 { 160 cpuNum = _cpuNum; 161 threadNum = _threadNum; 162 validCpuAndThreadNums = true; 163 } 164 165 /** 166 * Set up a physical (e.g. device) request in a previously 167 * allocated Request object. */ 168 void setPhys(Addr _paddr, int _size, int _flags) 169 { 170 paddr = _paddr; 171 size = _size; 172 flags = _flags; 173 time = curTick; 174 validPaddr = true; 175 validAsidVaddr = false; 176 validPC = false; 177 validExData = false; 178 mmapedIpr = false; 179 } 180 181 /** 182 * Set up a virtual (e.g., CPU) request in a previously 183 * allocated Request object. */ 184 void setVirt(int _asid, Addr _vaddr, int _size, int _flags, Addr _pc) 185 { 186 asid = _asid; 187 vaddr = _vaddr; 188 size = _size; 189 flags = _flags; 190 pc = _pc; 191 time = curTick; 192 validPaddr = false; 193 validAsidVaddr = true; 194 validPC = true; 195 validExData = false; 196 mmapedIpr = false; 197 } 198 199 /** Set just the physical address. This should only be used to 200 * record the result of a translation, and thus the vaddr must be 201 * valid before this method is called. Otherwise, use setPhys() 202 * to guarantee that the size and flags are also set. 203 */ 204 void setPaddr(Addr _paddr) 205 { 206 assert(validAsidVaddr); 207 paddr = _paddr; 208 validPaddr = true; 209 } 210 211 /** Accessor for paddr. */ 212 Addr getPaddr() { assert(validPaddr); return paddr; } 213 214 /** Accessor for size. */ 215 int getSize() { assert(validPaddr || validAsidVaddr); return size; } 216 /** Accessor for time. */ 217 Tick getTime() { assert(validPaddr || validAsidVaddr); return time; } 218 219 /** Accessor for flags. */ 220 uint32_t getFlags() { assert(validPaddr || validAsidVaddr); return flags; } 221 /** Accessor for paddr. */ 222 void setFlags(uint32_t _flags) 223 { assert(validPaddr || validAsidVaddr); flags = _flags; } 224 225 /** Accessor function for vaddr.*/ 226 Addr getVaddr() { assert(validAsidVaddr); return vaddr; } 227 228 /** Accessor function for asid.*/ 229 int getAsid() { assert(validAsidVaddr); return asid; } 230 231 /** Accessor function for asi.*/ 232 uint8_t getAsi() { assert(validAsidVaddr); return flags & ASI_BITS; } 233 234 /** Accessor function for asi.*/ 235 void setAsi(uint8_t a) 236 { assert(validAsidVaddr); flags = (flags & ~ASI_BITS) | a; } 237 238 /** Accessor function for asi.*/ 239 bool isMmapedIpr() { assert(validPaddr); return mmapedIpr; } 240 241 /** Accessor function for asi.*/ 242 void setMmapedIpr(bool r) { assert(validAsidVaddr); mmapedIpr = r; } 243 244 /** Accessor function to check if sc result is valid. */ 245 bool extraDataValid() { return validExData; } 246 /** Accessor function for store conditional return value.*/ 247 uint64_t getExtraData() { assert(validExData); return extraData; } 248 /** Accessor function for store conditional return value.*/ 249 void setExtraData(uint64_t _extraData) 250 { extraData = _extraData; validExData = true; } 251 252 /** Accessor function for cpu number.*/ 253 int getCpuNum() { assert(validCpuAndThreadNums); return cpuNum; } 254 /** Accessor function for thread number.*/ 255 int getThreadNum() { assert(validCpuAndThreadNums); return threadNum; } 256 257 /** Accessor function for pc.*/ 258 Addr getPC() { assert(validPC); return pc; } 259 260 /** Accessor Function to Check Cacheability. */ 261 bool isUncacheable() { return (getFlags() & UNCACHEABLE) != 0; } 262 263 bool isInstRead() { return (getFlags() & INST_READ) != 0; } 264 265 bool isLocked() { return (getFlags() & LOCKED) != 0; } 266 267 bool isSwap() { return (getFlags() & MEM_SWAP || 268 getFlags() & MEM_SWAP_COND); } 269 270 bool isCondSwap() { return (getFlags() & MEM_SWAP_COND) != 0; } 271 272 273 friend class Packet; 274}; 275 276#endif // __MEM_REQUEST_HH__ 277