MemCommand.h revision 11555:2efa95cf8504
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. END - To indicate end of trace
57   * 7. RDA - Read with auto-precharge
58   * 8. WRA - Write with auto-precharge
59   * 9. PREA - Precharge all banks
60   * 10. PDN_F_PRE - Precharge Power-down Entry command (Fast-Exit)
61   * 11. PDN_S_PRE - Precharge Power-down Entry command (Slow-Exit)
62   * 12. PDN_F_ACT - Active Power-down Entry command (Fast-Exit)
63   * 13. PDN_S_ACT - Active Power-down Entry command (Slow-Exit)
64   * 14. PUP_PRE - Precharge Power-down Exit
65   * 15. PUP_ACT - Active Power-down Exit
66   * 16. SREN - Self-Refresh Entry command
67   * 17. SREX - Self-refresh Exit
68   * 18. NOP - To indicate end of trace
69   */
70
71  enum cmds {
72    ACT       = 0,
73    RD        = 1,
74    WR        = 2,
75    PRE       = 3,
76    REF       = 4,
77    END       = 5,
78    RDA       = 6,
79    WRA       = 7,
80    PREA      = 8,
81    PDN_F_PRE = 9,
82    PDN_S_PRE = 10,
83    PDN_F_ACT = 11,
84    PDN_S_ACT = 12,
85    PUP_PRE   = 13,
86    PUP_ACT   = 14,
87    SREN      = 15,
88    SREX      = 16,
89    NOP       = 17,
90    UNINITIALIZED = 18
91  };
92
93//  MemCommand();
94  MemCommand(
95    // Command Type
96    MemCommand::cmds type = UNINITIALIZED,
97    // Target Bank
98    unsigned         bank = 0,
99    // Command Issue Timestamp (in cc)
100    int64_t          timestamp = 0L);
101
102  // Get command type
103  cmds getType() const;
104
105  // Set command type
106  void setType(MemCommand::cmds type);
107
108  // Set target Bank
109  void setBank(unsigned bank);
110
111  // Get target Bank
112  unsigned getBank() const;
113
114  // Set timestamp
115  void setTime(int64_t _timestamp);
116
117  // Get timestamp
118  int64_t getTimeInt64() const;
119
120  cmds typeWithoutAutoPrechargeFlag() const;
121
122  // To calculate precharge offset after read or write with auto-precharge
123  int64_t getPrechargeOffset(const MemorySpecification& memSpec,
124                         MemCommand::cmds           type) const;
125
126  // To check for equivalence
127
128  bool operator==(const MemCommand& other) const
129  {
130    if ((getType() == other.getType()) &&
131        (getBank() == other.getBank())
132        ) {
133      return true;
134    } else {
135      return false;
136    }
137  }
138
139  static const unsigned int nCommands = 19;
140
141  static std::string* getCommandTypeStrings()
142  {
143    static std::string type_map[nCommands] = { "ACT",
144                                               "RD",
145                                               "WR",
146                                               "PRE",
147                                               "REF",
148                                               "END",
149                                               "RDA",
150                                               "WRA",
151                                               "PREA",
152                                               "PDN_F_PRE",
153                                               "PDN_S_PRE",
154                                               "PDN_F_ACT",
155                                               "PDN_S_ACT",
156                                               "PUP_PRE",
157                                               "PUP_ACT",
158                                               "SREN",
159                                               "SREX",
160                                               "NOP",
161                                               "UNINITIALIZED" };
162
163    return type_map;
164  }
165
166  // To identify command type from name
167  static cmds getTypeFromName(const std::string& name)
168  {
169    std::string* typeStrings = getCommandTypeStrings();
170
171    for (size_t typeId = 0; typeId < nCommands; typeId++) {
172      if (typeStrings[typeId] == name) {
173        cmds commandType = static_cast<cmds>(typeId);
174        return commandType;
175      }
176    }
177    assert(false); // Unknown name.
178    return NOP;  // For clang compilation
179  }
180
181 private:
182  MemCommand::cmds type;
183  unsigned bank;
184  int64_t timestamp;
185};
186}
187#endif // ifndef MEMCOMMAND_H
188