types: Move stuff for global types into src/base/types.hh
[gem5.git] / src / mem / rubymem.hh
1 /*
2 * Copyright (c) 2001-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: Daniel Sanchez
29 */
30
31 #ifndef __RUBY_MEMORY_HH__
32 #define __RUBY_MEMORY_HH__
33
34 #include <map>
35
36 #include "mem/physical.hh"
37 #include "params/RubyMemory.hh"
38 #include "base/callback.hh"
39 #include "mem/ruby/common/Driver.hh"
40
41 class RubyMemory : public PhysicalMemory, public Driver
42 {
43 class RubyMemoryPort : public MemoryPort
44 {
45 RubyMemory* ruby_mem;
46
47 public:
48 RubyMemoryPort(const std::string &_name, RubyMemory *_memory);
49 void sendTiming(PacketPtr pkt);
50
51 protected:
52 virtual bool recvTiming(PacketPtr pkt);
53 };
54
55 class RubyEvent : public Event
56 {
57 RubyMemory *ruby_ptr;
58 public:
59 RubyEvent(RubyMemory *p)
60 : Event(), ruby_ptr(p) {}
61
62 virtual void process() { ruby_ptr->tick(); }
63
64 virtual const char *description() const { return "ruby tick"; }
65 };
66
67
68 private:
69 // prevent copying of a RubyMemory object
70 RubyMemory(const RubyMemory &specmem);
71 const RubyMemory &operator=(const RubyMemory &specmem);
72
73 RubyEvent* rubyTickEvent;
74
75 public:
76 typedef RubyMemoryParams Params;
77 RubyMemory(const Params *p);
78 virtual ~RubyMemory();
79
80 public:
81 virtual Port *getPort(const std::string &if_name, int idx = -1);
82 void virtual init();
83
84 //Ruby-related specifics
85 void printConfigStats(); //dsm: Maybe this function should disappear once the configuration options change & M5 determines the stats file to use
86
87 void hitCallback(Packet* pkt); // called by the Ruby sequencer
88
89 void printStats(std::ostream & out) const;
90 void clearStats();
91 void printConfig(std::ostream & out) const;
92
93 void tick();
94
95 private:
96 //Parameters passed
97 std::string config_file, config_options, stats_file, debug_file;
98 bool debug;
99 int num_cpus;
100 Tick ruby_clock, ruby_phase;
101
102 std::map<Packet*, RubyMemoryPort*> m_packet_to_port_map;
103 };
104
105 class RubyExitCallback : public Callback
106 {
107 private:
108 RubyMemory* ruby;
109
110 public:
111 /**
112 * virtualize the destructor to make sure that the correct one
113 * gets called.
114 */
115
116 virtual ~RubyExitCallback() {};
117
118 RubyExitCallback(RubyMemory* rm) {ruby=rm;};
119
120 /**
121 * virtual process function that is invoked when the callback
122 * queue is executed.
123 */
124 virtual void process() {ruby->printConfigStats(); /*delete ruby; was doing double delete...*/};
125 };
126
127
128 #endif //__RUBY_MEMORY_HH__
129