1/* 2 * Copyright (c) 2012-2014, TU Delft 3 * Copyright (c) 2012-2014, TU Eindhoven 4 * Copyright (c) 2012-2014, TU Kaiserslautern 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions are 9 * met: 10 * 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * 3. Neither the name of the copyright holder nor the names of its 19 * contributors may be used to endorse or promote products derived from 20 * this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 23 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 24 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 25 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 28 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 30 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 31 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 * 34 * Authors: Karthik Chandrasekar 35 * 36 */ 37 38#ifndef MEMCOMMAND_H 39#define MEMCOMMAND_H 40 41#include <stdint.h> 42#include <cassert> 43#include <string> 44 45#include "MemorySpecification.h" 46 47namespace Data { 48class MemCommand { 49 public: 50 /* 51 * 1. ACT - Activate 52 * 2. RD - Read 53 * 3. WR - Write 54 * 4. PRE - Explicit Precharge per bank 55 * 5. REF - Refresh all banks 56 * 6 REFB- Refresh a particular bank 57 * 7. END - To indicate end of trace 58 * 8. RDA - Read with auto-precharge 59 * 9. WRA - Write with auto-precharge 60 * 10. PREA - Precharge all banks 61 * 11. PDN_F_PRE - Precharge Power-down Entry command (Fast-Exit) 62 * 12. PDN_S_PRE - Precharge Power-down Entry command (Slow-Exit) 63 * 13. PDN_F_ACT - Active Power-down Entry command (Fast-Exit) 64 * 14. PDN_S_ACT - Active Power-down Entry command (Slow-Exit) 65 * 15. PUP_PRE - Precharge Power-down Exit 66 * 16. PUP_ACT - Active Power-down Exit 67 * 17. SREN - Self-Refresh Entry command 68 * 18. SREX - Self-refresh Exit 69 * 19. NOP - To indicate end of trace 70 */ 71 72 enum cmds { 73 ACT = 0, 74 RD = 1, 75 WR = 2, 76 PRE = 3, 77 REF = 4, 78 REFB = 5, 79 END = 6, 80 RDA = 7, 81 WRA = 8, 82 PREA = 9, 83 PDN_F_PRE = 10, 84 PDN_S_PRE = 11, 85 PDN_F_ACT = 12, 86 PDN_S_ACT = 13, 87 PUP_PRE = 14, 88 PUP_ACT = 15, 89 SREN = 16, 90 SREX = 17, 91 NOP = 18, 92 UNINITIALIZED = 19 93 }; 94 95// MemCommand(); 96 MemCommand( 97 // Command Type 98 MemCommand::cmds type = UNINITIALIZED, 99 // Target Bank 100 unsigned bank = 0, 101 // Command Issue Timestamp (in cc) 102 int64_t timestamp = 0L); 103 104 // Get command type 105 cmds getType() const; 106 107 // Set command type 108 void setType(MemCommand::cmds type); 109 110 // Set target Bank 111 void setBank(unsigned bank); 112 113 // Get target Bank 114 unsigned getBank() const; 115 116 // Set timestamp 117 void setTime(int64_t _timestamp); 118 119 // Get timestamp 120 int64_t getTimeInt64() const; 121 122 cmds typeWithoutAutoPrechargeFlag() const; 123 124 // To calculate precharge offset after read or write with auto-precharge 125 int64_t getPrechargeOffset(const MemorySpecification& memSpec, 126 MemCommand::cmds type) const; 127 128 // To check for equivalence 129 130 bool operator==(const MemCommand& other) const 131 { 132 if ((getType() == other.getType()) && 133 (getBank() == other.getBank()) 134 ) { 135 return true; 136 } else { 137 return false; 138 } 139 } 140 141 static const unsigned int nCommands = 20; 142 143 static std::string* getCommandTypeStrings() 144 { 145 static std::string type_map[nCommands] = { "ACT", 146 "RD", 147 "WR", 148 "PRE", 149 "REF", 150 "REFB", 151 "END", 152 "RDA", 153 "WRA", 154 "PREA", 155 "PDN_F_PRE", 156 "PDN_S_PRE", 157 "PDN_F_ACT", 158 "PDN_S_ACT", 159 "PUP_PRE", 160 "PUP_ACT", 161 "SREN", 162 "SREX", 163 "NOP", 164 "UNINITIALIZED" }; 165 166 return type_map; 167 } 168 169 // To identify command type from name 170 static cmds getTypeFromName(const std::string& name) 171 { 172 std::string* typeStrings = getCommandTypeStrings(); 173 174 for (size_t typeId = 0; typeId < nCommands; typeId++) { 175 if (typeStrings[typeId] == name) { 176 cmds commandType = static_cast<cmds>(typeId); 177 return commandType; 178 } 179 } 180 assert(false); // Unknown name. 181 return NOP; // For clang compilation 182 } 183 184 private: 185 MemCommand::cmds type; 186 unsigned bank; 187 int64_t timestamp; 188}; 189} 190#endif // ifndef MEMCOMMAND_H 191