New directory structure:
[gem5.git] / src / mem / bus.hh
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
29 /**
30 * @file Decleration of a bus object.
31 */
32
33 #ifndef __MEM_BUS_HH__
34 #define __MEM_BUS_HH__
35
36 #include <string>
37 #include <list>
38 #include <inttypes.h>
39
40 #include "base/range.hh"
41 #include "mem/mem_object.hh"
42 #include "mem/packet.hh"
43 #include "mem/port.hh"
44 #include "mem/request.hh"
45
46 class Bus : public MemObject
47 {
48 /** a globally unique id for this bus. */
49 int busId;
50
51 struct DevMap {
52 int portId;
53 Range<Addr> range;
54 };
55 std::vector<DevMap> portList;
56
57
58 /** Function called by the port when the bus is recieving a Timing
59 transaction.*/
60 bool recvTiming(Packet *pkt);
61
62 /** Function called by the port when the bus is recieving a Atomic
63 transaction.*/
64 Tick recvAtomic(Packet *pkt);
65
66 /** Function called by the port when the bus is recieving a Functional
67 transaction.*/
68 void recvFunctional(Packet *pkt);
69
70 /** Function called by the port when the bus is recieving a status change.*/
71 void recvStatusChange(Port::Status status, int id);
72
73 /** Find which port connected to this bus (if any) should be given a packet
74 * with this address.
75 * @param addr Address to find port for.
76 * @param id Id of the port this packet was received from (to prevent
77 * loops)
78 * @return pointer to port that the packet should be sent out of.
79 */
80 Port *findPort(Addr addr, int id);
81
82 /** Process address range request.
83 * @param resp addresses that we can respond to
84 * @param snoop addresses that we would like to snoop
85 * @param id ide of the busport that made the request.
86 */
87 void addressRanges(AddrRangeList &resp, AddrRangeList &snoop, int id);
88
89
90 /** Decleration of the buses port type, one will be instantiated for each
91 of the interfaces connecting to the bus. */
92 class BusPort : public Port
93 {
94 /** A pointer to the bus to which this port belongs. */
95 Bus *bus;
96
97 /** A id to keep track of the intercafe ID this port is connected to. */
98 int id;
99
100 public:
101
102 /** Constructor for the BusPort.*/
103 BusPort(Bus *_bus, int _id)
104 : bus(_bus), id(_id)
105 { }
106
107 protected:
108
109 /** When reciving a timing request from the peer port (at id),
110 pass it to the bus. */
111 virtual bool recvTiming(Packet *pkt)
112 { pkt->src = id; return bus->recvTiming(pkt); }
113
114 /** When reciving a Atomic requestfrom the peer port (at id),
115 pass it to the bus. */
116 virtual Tick recvAtomic(Packet *pkt)
117 { pkt->src = id; return bus->recvAtomic(pkt); }
118
119 /** When reciving a Functional requestfrom the peer port (at id),
120 pass it to the bus. */
121 virtual void recvFunctional(Packet *pkt)
122 { pkt->src = id; bus->recvFunctional(pkt); }
123
124 /** When reciving a status changefrom the peer port (at id),
125 pass it to the bus. */
126 virtual void recvStatusChange(Status status)
127 { bus->recvStatusChange(status, id); }
128
129 // This should return all the 'owned' addresses that are
130 // downstream from this bus, yes? That is, the union of all
131 // the 'owned' address ranges of all the other interfaces on
132 // this bus...
133 virtual void getDeviceAddressRanges(AddrRangeList &resp,
134 AddrRangeList &snoop)
135 { bus->addressRanges(resp, snoop, id); }
136
137 // Hack to make translating port work without changes
138 virtual int deviceBlockSize() { return 32; }
139
140 };
141
142 /** An array of pointers to the peer port interfaces
143 connected to this bus.*/
144 std::vector<Port*> interfaces;
145
146 public:
147
148 /** A function used to return the port associated with this bus object. */
149 virtual Port *getPort(const std::string &if_name)
150 {
151 // if_name ignored? forced to be empty?
152 int id = interfaces.size();
153 interfaces.push_back(new BusPort(this, id));
154 return interfaces.back();
155 }
156
157 virtual void init();
158
159 Bus(const std::string &n, int bus_id)
160 : MemObject(n), busId(bus_id) {}
161
162 };
163
164 #endif //__MEM_BUS_HH__