1a138fb39345e5e63788ccf0a9c65e7441770277
2 * Copyright (c) 2004-2005 The Regents of The University of Michigan
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.
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.
30 * PCI Configspace implementation
38 #include "arch/alpha/ev5.hh"
39 #include "base/trace.hh"
40 #include "dev/pciconfigall.hh"
41 #include "dev/pcidev.hh"
42 #include "dev/pcireg.h"
43 #include "mem/bus/bus.hh"
44 #include "mem/bus/pio_interface.hh"
45 #include "mem/bus/pio_interface_impl.hh"
46 #include "mem/functional/memory_control.hh"
47 #include "sim/builder.hh"
48 #include "sim/system.hh"
51 using namespace TheISA
;
53 PciConfigAll::PciConfigAll(const string
&name
,
54 Addr a
, MemoryController
*mmu
,
55 HierParams
*hier
, Bus
*pio_bus
, Tick pio_latency
)
56 : PioDevice(name
, NULL
), addr(a
)
58 mmu
->add_child(this, RangeSize(addr
, size
));
61 pioInterface
= newPioInterface(name
+ ".pio", hier
, pio_bus
, this,
62 &PciConfigAll::cacheAccess
);
63 pioInterface
->addAddrRange(RangeSize(addr
, size
));
64 pioLatency
= pio_latency
* pio_bus
->clockRate
;
67 // Make all the pointers to devices null
68 for(int x
=0; x
< MAX_PCI_DEV
; x
++)
69 for(int y
=0; y
< MAX_PCI_FUNC
; y
++)
73 // If two interrupts share the same line largely bad things will happen.
74 // Since we don't track how many times an interrupt was set and correspondingly
75 // cleared two devices on the same interrupt line and assert and deassert each
76 // others interrupt "line". Interrupts will not work correctly.
78 PciConfigAll::startup()
84 for (int x
= 0; x
< MAX_PCI_DEV
; x
++) {
85 for (int y
= 0; y
< MAX_PCI_FUNC
; y
++) {
86 if (devices
[x
][y
] != NULL
) {
87 tempDev
= devices
[x
][y
];
88 intline
= tempDev
->interruptLine();
89 if (intLines
.test(intline
))
90 warn("Interrupt line %#X is used multiple times"
91 "(You probably want to fix this).\n", (uint32_t)intline
);
93 intLines
.set(intline
);
101 PciConfigAll::read(MemReqPtr
&req
, uint8_t *data
)
104 Addr daddr
= (req
->paddr
- (addr
& EV5::PAddrImplMask
));
106 DPRINTF(PciConfigAll
, "read va=%#x da=%#x size=%d\n",
107 req
->vaddr
, daddr
, req
->size
);
109 int device
= (daddr
>> 11) & 0x1F;
110 int func
= (daddr
>> 8) & 0x7;
111 int reg
= daddr
& 0xFF;
113 if (devices
[device
][func
] == NULL
) {
115 // case sizeof(uint64_t):
116 // *(uint64_t*)data = 0xFFFFFFFFFFFFFFFF;
118 case sizeof(uint32_t):
119 *(uint32_t*)data
= 0xFFFFFFFF;
121 case sizeof(uint16_t):
122 *(uint16_t*)data
= 0xFFFF;
124 case sizeof(uint8_t):
125 *(uint8_t*)data
= 0xFF;
128 panic("invalid access size(?) for PCI configspace!\n");
132 case sizeof(uint32_t):
133 case sizeof(uint16_t):
134 case sizeof(uint8_t):
135 devices
[device
][func
]->readConfig(reg
, req
->size
, data
);
138 panic("invalid access size(?) for PCI configspace!\n");
142 DPRINTFN("PCI Configspace ERROR: read daddr=%#x size=%d\n",
149 PciConfigAll::write(MemReqPtr
&req
, const uint8_t *data
)
151 Addr daddr
= (req
->paddr
- (addr
& EV5::PAddrImplMask
));
153 int device
= (daddr
>> 11) & 0x1F;
154 int func
= (daddr
>> 8) & 0x7;
155 int reg
= daddr
& 0xFF;
157 if (devices
[device
][func
] == NULL
)
158 panic("Attempting to write to config space on non-existant device\n");
159 else if (req
->size
!= sizeof(uint8_t) &&
160 req
->size
!= sizeof(uint16_t) &&
161 req
->size
!= sizeof(uint32_t))
162 panic("invalid access size(?) for PCI configspace!\n");
164 DPRINTF(PciConfigAll
, "write - va=%#x size=%d data=%#x\n",
165 req
->vaddr
, req
->size
, *(uint32_t*)data
);
167 devices
[device
][func
]->writeConfig(reg
, req
->size
, data
);
173 PciConfigAll::serialize(std::ostream
&os
)
176 * There is no state associated with this object that requires
177 * serialization. The only real state are the device pointers
178 * which are all setup by the constructor of the PciDev class
183 PciConfigAll::unserialize(Checkpoint
*cp
, const std::string
§ion
)
186 * There is no state associated with this object that requires
187 * serialization. The only real state are the device pointers
188 * which are all setup by the constructor of the PciDev class
193 PciConfigAll::cacheAccess(MemReqPtr
&req
)
195 return curTick
+ pioLatency
;
198 #ifndef DOXYGEN_SHOULD_SKIP_THIS
200 BEGIN_DECLARE_SIM_OBJECT_PARAMS(PciConfigAll
)
202 SimObjectParam
<MemoryController
*> mmu
;
205 SimObjectParam
<Bus
*> pio_bus
;
206 Param
<Tick
> pio_latency
;
207 SimObjectParam
<HierParams
*> hier
;
209 END_DECLARE_SIM_OBJECT_PARAMS(PciConfigAll
)
211 BEGIN_INIT_SIM_OBJECT_PARAMS(PciConfigAll
)
213 INIT_PARAM(mmu
, "Memory Controller"),
214 INIT_PARAM(addr
, "Device Address"),
215 INIT_PARAM(mask
, "Address Mask"),
216 INIT_PARAM_DFLT(pio_bus
, "The IO Bus to attach to", NULL
),
217 INIT_PARAM_DFLT(pio_latency
, "Programmed IO latency in bus cycles", 1),
218 INIT_PARAM_DFLT(hier
, "Hierarchy global variables", &defaultHierParams
)
220 END_INIT_SIM_OBJECT_PARAMS(PciConfigAll
)
222 CREATE_SIM_OBJECT(PciConfigAll
)
224 return new PciConfigAll(getInstanceName(), addr
, mmu
, hier
, pio_bus
,
228 REGISTER_SIM_OBJECT("PciConfigAll", PciConfigAll
)
230 #endif // DOXYGEN_SHOULD_SKIP_THIS