c581e15618df119bf33da07412f9095e5d601da5
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 "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"
50 using namespace TheISA
;
52 PciConfigAll::PciConfigAll(const string
&name
,
53 Addr a
, MemoryController
*mmu
,
54 HierParams
*hier
, Bus
*pio_bus
, Tick pio_latency
)
55 : PioDevice(name
, NULL
), addr(a
)
57 mmu
->add_child(this, RangeSize(addr
, size
));
60 pioInterface
= newPioInterface(name
+ ".pio", hier
, pio_bus
, this,
61 &PciConfigAll::cacheAccess
);
62 pioInterface
->addAddrRange(RangeSize(addr
, size
));
63 pioLatency
= pio_latency
* pio_bus
->clockRate
;
66 // Make all the pointers to devices null
67 for(int x
=0; x
< MAX_PCI_DEV
; x
++)
68 for(int y
=0; y
< MAX_PCI_FUNC
; y
++)
72 // If two interrupts share the same line largely bad things will happen.
73 // Since we don't track how many times an interrupt was set and correspondingly
74 // cleared two devices on the same interrupt line and assert and deassert each
75 // others interrupt "line". Interrupts will not work correctly.
77 PciConfigAll::startup()
83 for (int x
= 0; x
< MAX_PCI_DEV
; x
++) {
84 for (int y
= 0; y
< MAX_PCI_FUNC
; y
++) {
85 if (devices
[x
][y
] != NULL
) {
86 tempDev
= devices
[x
][y
];
87 intline
= tempDev
->interruptLine();
88 if (intLines
.test(intline
))
89 warn("Interrupt line %#X is used multiple times"
90 "(You probably want to fix this).\n", (uint32_t)intline
);
92 intLines
.set(intline
);
100 PciConfigAll::read(MemReqPtr
&req
, uint8_t *data
)
103 Addr daddr
= (req
->paddr
- (addr
& EV5::PAddrImplMask
));
105 DPRINTF(PciConfigAll
, "read va=%#x da=%#x size=%d\n",
106 req
->vaddr
, daddr
, req
->size
);
108 int device
= (daddr
>> 11) & 0x1F;
109 int func
= (daddr
>> 8) & 0x7;
110 int reg
= daddr
& 0xFF;
112 if (devices
[device
][func
] == NULL
) {
114 // case sizeof(uint64_t):
115 // *(uint64_t*)data = 0xFFFFFFFFFFFFFFFF;
117 case sizeof(uint32_t):
118 *(uint32_t*)data
= 0xFFFFFFFF;
120 case sizeof(uint16_t):
121 *(uint16_t*)data
= 0xFFFF;
123 case sizeof(uint8_t):
124 *(uint8_t*)data
= 0xFF;
127 panic("invalid access size(?) for PCI configspace!\n");
131 case sizeof(uint32_t):
132 case sizeof(uint16_t):
133 case sizeof(uint8_t):
134 devices
[device
][func
]->readConfig(reg
, req
->size
, data
);
137 panic("invalid access size(?) for PCI configspace!\n");
141 DPRINTFN("PCI Configspace ERROR: read daddr=%#x size=%d\n",
148 PciConfigAll::write(MemReqPtr
&req
, const uint8_t *data
)
150 Addr daddr
= (req
->paddr
- (addr
& EV5::PAddrImplMask
));
152 int device
= (daddr
>> 11) & 0x1F;
153 int func
= (daddr
>> 8) & 0x7;
154 int reg
= daddr
& 0xFF;
156 if (devices
[device
][func
] == NULL
)
157 panic("Attempting to write to config space on non-existant device\n");
158 else if (req
->size
!= sizeof(uint8_t) &&
159 req
->size
!= sizeof(uint16_t) &&
160 req
->size
!= sizeof(uint32_t))
161 panic("invalid access size(?) for PCI configspace!\n");
163 DPRINTF(PciConfigAll
, "write - va=%#x size=%d data=%#x\n",
164 req
->vaddr
, req
->size
, *(uint32_t*)data
);
166 devices
[device
][func
]->writeConfig(reg
, req
->size
, data
);
172 PciConfigAll::serialize(std::ostream
&os
)
175 * There is no state associated with this object that requires
176 * serialization. The only real state are the device pointers
177 * which are all setup by the constructor of the PciDev class
182 PciConfigAll::unserialize(Checkpoint
*cp
, const std::string
§ion
)
185 * There is no state associated with this object that requires
186 * serialization. The only real state are the device pointers
187 * which are all setup by the constructor of the PciDev class
192 PciConfigAll::cacheAccess(MemReqPtr
&req
)
194 return curTick
+ pioLatency
;
197 #ifndef DOXYGEN_SHOULD_SKIP_THIS
199 BEGIN_DECLARE_SIM_OBJECT_PARAMS(PciConfigAll
)
201 SimObjectParam
<MemoryController
*> mmu
;
204 SimObjectParam
<Bus
*> pio_bus
;
205 Param
<Tick
> pio_latency
;
206 SimObjectParam
<HierParams
*> hier
;
208 END_DECLARE_SIM_OBJECT_PARAMS(PciConfigAll
)
210 BEGIN_INIT_SIM_OBJECT_PARAMS(PciConfigAll
)
212 INIT_PARAM(mmu
, "Memory Controller"),
213 INIT_PARAM(addr
, "Device Address"),
214 INIT_PARAM(mask
, "Address Mask"),
215 INIT_PARAM_DFLT(pio_bus
, "The IO Bus to attach to", NULL
),
216 INIT_PARAM_DFLT(pio_latency
, "Programmed IO latency in bus cycles", 1),
217 INIT_PARAM_DFLT(hier
, "Hierarchy global variables", &defaultHierParams
)
219 END_INIT_SIM_OBJECT_PARAMS(PciConfigAll
)
221 CREATE_SIM_OBJECT(PciConfigAll
)
223 return new PciConfigAll(getInstanceName(), addr
, mmu
, hier
, pio_bus
,
227 REGISTER_SIM_OBJECT("PciConfigAll", PciConfigAll
)
229 #endif // DOXYGEN_SHOULD_SKIP_THIS