More documentation for 1.1 release.
[gem5.git] / dev / pciconfigall.cc
1 /*
2 * Copyright (c) 2004-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 /* @file
30 * PCI Configspace implementation
31 */
32
33 #include <deque>
34 #include <string>
35 #include <vector>
36 #include <bitset>
37
38 #include "base/trace.hh"
39 #include "dev/pciconfigall.hh"
40 #include "dev/pcidev.hh"
41 #include "dev/pcireg.h"
42 #include "mem/bus/bus.hh"
43 #include "mem/bus/pio_interface.hh"
44 #include "mem/bus/pio_interface_impl.hh"
45 #include "mem/functional/memory_control.hh"
46 #include "sim/builder.hh"
47 #include "sim/system.hh"
48
49 using namespace std;
50
51 PciConfigAll::PciConfigAll(const string &name,
52 Addr a, MemoryController *mmu,
53 HierParams *hier, Bus *bus, Tick pio_latency)
54 : PioDevice(name, NULL), addr(a)
55 {
56 mmu->add_child(this, RangeSize(addr, size));
57
58 if (bus) {
59 pioInterface = newPioInterface(name + ".pio", hier, bus, this,
60 &PciConfigAll::cacheAccess);
61 pioInterface->addAddrRange(RangeSize(addr, size));
62 pioLatency = pio_latency * bus->clockRate;
63 }
64
65 // Make all the pointers to devices null
66 for(int x=0; x < MAX_PCI_DEV; x++)
67 for(int y=0; y < MAX_PCI_FUNC; y++)
68 devices[x][y] = NULL;
69 }
70
71 // If two interrupts share the same line largely bad things will happen.
72 // Since we don't track how many times an interrupt was set and correspondingly
73 // cleared two devices on the same interrupt line and assert and deassert each
74 // others interrupt "line". Interrupts will not work correctly.
75 void
76 PciConfigAll::startup()
77 {
78 bitset<256> intLines;
79 PciDev *tempDev;
80 uint8_t intline;
81
82 for (int x = 0; x < MAX_PCI_DEV; x++) {
83 for (int y = 0; y < MAX_PCI_FUNC; y++) {
84 if (devices[x][y] != NULL) {
85 tempDev = devices[x][y];
86 intline = tempDev->interruptLine();
87 if (intLines.test(intline))
88 warn("Interrupt line %#X is used multiple times"
89 "(You probably want to fix this).\n", (uint32_t)intline);
90 else
91 intLines.set(intline);
92 } // devices != NULL
93 } // PCI_FUNC
94 } // PCI_DEV
95
96 }
97
98 Fault
99 PciConfigAll::read(MemReqPtr &req, uint8_t *data)
100 {
101
102 Addr daddr = (req->paddr - (addr & EV5::PAddrImplMask));
103
104 DPRINTF(PciConfigAll, "read va=%#x da=%#x size=%d\n",
105 req->vaddr, daddr, req->size);
106
107 int device = (daddr >> 11) & 0x1F;
108 int func = (daddr >> 8) & 0x7;
109 int reg = daddr & 0xFF;
110
111 if (devices[device][func] == NULL) {
112 switch (req->size) {
113 // case sizeof(uint64_t):
114 // *(uint64_t*)data = 0xFFFFFFFFFFFFFFFF;
115 // return No_Fault;
116 case sizeof(uint32_t):
117 *(uint32_t*)data = 0xFFFFFFFF;
118 return No_Fault;
119 case sizeof(uint16_t):
120 *(uint16_t*)data = 0xFFFF;
121 return No_Fault;
122 case sizeof(uint8_t):
123 *(uint8_t*)data = 0xFF;
124 return No_Fault;
125 default:
126 panic("invalid access size(?) for PCI configspace!\n");
127 }
128 } else {
129 switch (req->size) {
130 case sizeof(uint32_t):
131 case sizeof(uint16_t):
132 case sizeof(uint8_t):
133 devices[device][func]->readConfig(reg, req->size, data);
134 return No_Fault;
135 default:
136 panic("invalid access size(?) for PCI configspace!\n");
137 }
138 }
139
140 DPRINTFN("PCI Configspace ERROR: read daddr=%#x size=%d\n",
141 daddr, req->size);
142
143 return No_Fault;
144 }
145
146 Fault
147 PciConfigAll::write(MemReqPtr &req, const uint8_t *data)
148 {
149 Addr daddr = (req->paddr - (addr & EV5::PAddrImplMask));
150
151 int device = (daddr >> 11) & 0x1F;
152 int func = (daddr >> 8) & 0x7;
153 int reg = daddr & 0xFF;
154
155 if (devices[device][func] == NULL)
156 panic("Attempting to write to config space on non-existant device\n");
157 else if (req->size != sizeof(uint8_t) &&
158 req->size != sizeof(uint16_t) &&
159 req->size != sizeof(uint32_t))
160 panic("invalid access size(?) for PCI configspace!\n");
161
162 DPRINTF(PciConfigAll, "write - va=%#x size=%d data=%#x\n",
163 req->vaddr, req->size, *(uint32_t*)data);
164
165 devices[device][func]->writeConfig(reg, req->size, data);
166
167 return No_Fault;
168 }
169
170 void
171 PciConfigAll::serialize(std::ostream &os)
172 {
173 /*
174 * There is no state associated with this object that requires
175 * serialization. The only real state are the device pointers
176 * which are all setup by the constructor of the PciDev class
177 */
178 }
179
180 void
181 PciConfigAll::unserialize(Checkpoint *cp, const std::string &section)
182 {
183 /*
184 * There is no state associated with this object that requires
185 * serialization. The only real state are the device pointers
186 * which are all setup by the constructor of the PciDev class
187 */
188 }
189
190 Tick
191 PciConfigAll::cacheAccess(MemReqPtr &req)
192 {
193 return curTick + pioLatency;
194 }
195
196 #ifndef DOXYGEN_SHOULD_SKIP_THIS
197
198 BEGIN_DECLARE_SIM_OBJECT_PARAMS(PciConfigAll)
199
200 SimObjectParam<MemoryController *> mmu;
201 Param<Addr> addr;
202 Param<Addr> mask;
203 SimObjectParam<Bus*> io_bus;
204 Param<Tick> pio_latency;
205 SimObjectParam<HierParams *> hier;
206
207 END_DECLARE_SIM_OBJECT_PARAMS(PciConfigAll)
208
209 BEGIN_INIT_SIM_OBJECT_PARAMS(PciConfigAll)
210
211 INIT_PARAM(mmu, "Memory Controller"),
212 INIT_PARAM(addr, "Device Address"),
213 INIT_PARAM(mask, "Address Mask"),
214 INIT_PARAM_DFLT(io_bus, "The IO Bus to attach to", NULL),
215 INIT_PARAM_DFLT(pio_latency, "Programmed IO latency in bus cycles", 1),
216 INIT_PARAM_DFLT(hier, "Hierarchy global variables", &defaultHierParams)
217
218 END_INIT_SIM_OBJECT_PARAMS(PciConfigAll)
219
220 CREATE_SIM_OBJECT(PciConfigAll)
221 {
222 return new PciConfigAll(getInstanceName(), addr, mmu, hier, io_bus,
223 pio_latency);
224 }
225
226 REGISTER_SIM_OBJECT("PciConfigAll", PciConfigAll)
227
228 #endif // DOXYGEN_SHOULD_SKIP_THIS