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