root / hw / pci / pci_bridge.c @ 9a6ee9fd
History | View | Annotate | Download (13.1 kB)
1 | 783753fd | Isaku Yamahata | /*
|
---|---|---|---|
2 | 783753fd | Isaku Yamahata | * QEMU PCI bus manager
|
3 | 783753fd | Isaku Yamahata | *
|
4 | 783753fd | Isaku Yamahata | * Copyright (c) 2004 Fabrice Bellard
|
5 | 783753fd | Isaku Yamahata | *
|
6 | 783753fd | Isaku Yamahata | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | 783753fd | Isaku Yamahata | * of this software and associated documentation files (the "Software"), to dea
|
8 | 783753fd | Isaku Yamahata | |
9 | 783753fd | Isaku Yamahata | * in the Software without restriction, including without limitation the rights
|
10 | 783753fd | Isaku Yamahata | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11 | 783753fd | Isaku Yamahata | * copies of the Software, and to permit persons to whom the Software is
|
12 | 783753fd | Isaku Yamahata | * furnished to do so, subject to the following conditions:
|
13 | 783753fd | Isaku Yamahata | *
|
14 | 783753fd | Isaku Yamahata | * The above copyright notice and this permission notice shall be included in
|
15 | 783753fd | Isaku Yamahata | * all copies or substantial portions of the Software.
|
16 | 783753fd | Isaku Yamahata | *
|
17 | 783753fd | Isaku Yamahata | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18 | 783753fd | Isaku Yamahata | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19 | 783753fd | Isaku Yamahata | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
20 | 783753fd | Isaku Yamahata | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21 | 783753fd | Isaku Yamahata | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM
|
22 | 783753fd | Isaku Yamahata | |
23 | 783753fd | Isaku Yamahata | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
24 | 783753fd | Isaku Yamahata | * THE SOFTWARE.
|
25 | 783753fd | Isaku Yamahata | */
|
26 | 783753fd | Isaku Yamahata | /*
|
27 | 783753fd | Isaku Yamahata | * split out from pci.c
|
28 | 783753fd | Isaku Yamahata | * Copyright (c) 2010 Isaku Yamahata <yamahata at valinux co jp>
|
29 | 783753fd | Isaku Yamahata | * VA Linux Systems Japan K.K.
|
30 | 783753fd | Isaku Yamahata | */
|
31 | 783753fd | Isaku Yamahata | |
32 | c759b24f | Michael S. Tsirkin | #include "hw/pci/pci_bridge.h" |
33 | 06aac7bd | Michael S. Tsirkin | #include "hw/pci/pci_bus.h" |
34 | 1de7afc9 | Paolo Bonzini | #include "qemu/range.h" |
35 | 783753fd | Isaku Yamahata | |
36 | f4c817e0 | Isaku Yamahata | /* PCI bridge subsystem vendor ID helper functions */
|
37 | f4c817e0 | Isaku Yamahata | #define PCI_SSVID_SIZEOF 8 |
38 | f4c817e0 | Isaku Yamahata | #define PCI_SSVID_SVID 4 |
39 | f4c817e0 | Isaku Yamahata | #define PCI_SSVID_SSID 6 |
40 | f4c817e0 | Isaku Yamahata | |
41 | f4c817e0 | Isaku Yamahata | int pci_bridge_ssvid_init(PCIDevice *dev, uint8_t offset,
|
42 | f4c817e0 | Isaku Yamahata | uint16_t svid, uint16_t ssid) |
43 | f4c817e0 | Isaku Yamahata | { |
44 | f4c817e0 | Isaku Yamahata | int pos;
|
45 | f4c817e0 | Isaku Yamahata | pos = pci_add_capability(dev, PCI_CAP_ID_SSVID, offset, PCI_SSVID_SIZEOF); |
46 | f4c817e0 | Isaku Yamahata | if (pos < 0) { |
47 | f4c817e0 | Isaku Yamahata | return pos;
|
48 | f4c817e0 | Isaku Yamahata | } |
49 | f4c817e0 | Isaku Yamahata | |
50 | f4c817e0 | Isaku Yamahata | pci_set_word(dev->config + pos + PCI_SSVID_SVID, svid); |
51 | f4c817e0 | Isaku Yamahata | pci_set_word(dev->config + pos + PCI_SSVID_SSID, ssid); |
52 | f4c817e0 | Isaku Yamahata | return pos;
|
53 | f4c817e0 | Isaku Yamahata | } |
54 | f4c817e0 | Isaku Yamahata | |
55 | 68f79994 | Isaku Yamahata | /* Accessor function to get parent bridge device from pci bus. */
|
56 | 783753fd | Isaku Yamahata | PCIDevice *pci_bridge_get_device(PCIBus *bus) |
57 | 783753fd | Isaku Yamahata | { |
58 | 783753fd | Isaku Yamahata | return bus->parent_dev;
|
59 | 783753fd | Isaku Yamahata | } |
60 | 783753fd | Isaku Yamahata | |
61 | 68f79994 | Isaku Yamahata | /* Accessor function to get secondary bus from pci-to-pci bridge device */
|
62 | 68f79994 | Isaku Yamahata | PCIBus *pci_bridge_get_sec_bus(PCIBridge *br) |
63 | 68f79994 | Isaku Yamahata | { |
64 | 68f79994 | Isaku Yamahata | return &br->sec_bus;
|
65 | 68f79994 | Isaku Yamahata | } |
66 | 68f79994 | Isaku Yamahata | |
67 | 68f79994 | Isaku Yamahata | static uint32_t pci_config_get_io_base(const PCIDevice *d, |
68 | 783753fd | Isaku Yamahata | uint32_t base, uint32_t base_upper16) |
69 | 783753fd | Isaku Yamahata | { |
70 | 783753fd | Isaku Yamahata | uint32_t val; |
71 | 783753fd | Isaku Yamahata | |
72 | 783753fd | Isaku Yamahata | val = ((uint32_t)d->config[base] & PCI_IO_RANGE_MASK) << 8;
|
73 | 783753fd | Isaku Yamahata | if (d->config[base] & PCI_IO_RANGE_TYPE_32) {
|
74 | 783753fd | Isaku Yamahata | val |= (uint32_t)pci_get_word(d->config + base_upper16) << 16;
|
75 | 783753fd | Isaku Yamahata | } |
76 | 783753fd | Isaku Yamahata | return val;
|
77 | 783753fd | Isaku Yamahata | } |
78 | 783753fd | Isaku Yamahata | |
79 | 68f79994 | Isaku Yamahata | static pcibus_t pci_config_get_memory_base(const PCIDevice *d, uint32_t base) |
80 | 783753fd | Isaku Yamahata | { |
81 | 783753fd | Isaku Yamahata | return ((pcibus_t)pci_get_word(d->config + base) & PCI_MEMORY_RANGE_MASK)
|
82 | 783753fd | Isaku Yamahata | << 16;
|
83 | 783753fd | Isaku Yamahata | } |
84 | 783753fd | Isaku Yamahata | |
85 | 68f79994 | Isaku Yamahata | static pcibus_t pci_config_get_pref_base(const PCIDevice *d, |
86 | 783753fd | Isaku Yamahata | uint32_t base, uint32_t upper) |
87 | 783753fd | Isaku Yamahata | { |
88 | 783753fd | Isaku Yamahata | pcibus_t tmp; |
89 | 783753fd | Isaku Yamahata | pcibus_t val; |
90 | 783753fd | Isaku Yamahata | |
91 | 783753fd | Isaku Yamahata | tmp = (pcibus_t)pci_get_word(d->config + base); |
92 | 783753fd | Isaku Yamahata | val = (tmp & PCI_PREF_RANGE_MASK) << 16;
|
93 | 783753fd | Isaku Yamahata | if (tmp & PCI_PREF_RANGE_TYPE_64) {
|
94 | 783753fd | Isaku Yamahata | val |= (pcibus_t)pci_get_long(d->config + upper) << 32;
|
95 | 783753fd | Isaku Yamahata | } |
96 | 783753fd | Isaku Yamahata | return val;
|
97 | 783753fd | Isaku Yamahata | } |
98 | 783753fd | Isaku Yamahata | |
99 | 68f79994 | Isaku Yamahata | /* accessor function to get bridge filtering base address */
|
100 | 68f79994 | Isaku Yamahata | pcibus_t pci_bridge_get_base(const PCIDevice *bridge, uint8_t type)
|
101 | 783753fd | Isaku Yamahata | { |
102 | 783753fd | Isaku Yamahata | pcibus_t base; |
103 | 783753fd | Isaku Yamahata | if (type & PCI_BASE_ADDRESS_SPACE_IO) {
|
104 | 783753fd | Isaku Yamahata | base = pci_config_get_io_base(bridge, |
105 | 783753fd | Isaku Yamahata | PCI_IO_BASE, PCI_IO_BASE_UPPER16); |
106 | 783753fd | Isaku Yamahata | } else {
|
107 | 783753fd | Isaku Yamahata | if (type & PCI_BASE_ADDRESS_MEM_PREFETCH) {
|
108 | 783753fd | Isaku Yamahata | base = pci_config_get_pref_base( |
109 | 783753fd | Isaku Yamahata | bridge, PCI_PREF_MEMORY_BASE, PCI_PREF_BASE_UPPER32); |
110 | 783753fd | Isaku Yamahata | } else {
|
111 | 783753fd | Isaku Yamahata | base = pci_config_get_memory_base(bridge, PCI_MEMORY_BASE); |
112 | 783753fd | Isaku Yamahata | } |
113 | 783753fd | Isaku Yamahata | } |
114 | 783753fd | Isaku Yamahata | |
115 | 783753fd | Isaku Yamahata | return base;
|
116 | 783753fd | Isaku Yamahata | } |
117 | 783753fd | Isaku Yamahata | |
118 | 68f79994 | Isaku Yamahata | /* accessor funciton to get bridge filtering limit */
|
119 | 68f79994 | Isaku Yamahata | pcibus_t pci_bridge_get_limit(const PCIDevice *bridge, uint8_t type)
|
120 | 783753fd | Isaku Yamahata | { |
121 | 783753fd | Isaku Yamahata | pcibus_t limit; |
122 | 783753fd | Isaku Yamahata | if (type & PCI_BASE_ADDRESS_SPACE_IO) {
|
123 | 783753fd | Isaku Yamahata | limit = pci_config_get_io_base(bridge, |
124 | 783753fd | Isaku Yamahata | PCI_IO_LIMIT, PCI_IO_LIMIT_UPPER16); |
125 | 783753fd | Isaku Yamahata | limit |= 0xfff; /* PCI bridge spec 3.2.5.6. */ |
126 | 783753fd | Isaku Yamahata | } else {
|
127 | 783753fd | Isaku Yamahata | if (type & PCI_BASE_ADDRESS_MEM_PREFETCH) {
|
128 | 783753fd | Isaku Yamahata | limit = pci_config_get_pref_base( |
129 | 783753fd | Isaku Yamahata | bridge, PCI_PREF_MEMORY_LIMIT, PCI_PREF_LIMIT_UPPER32); |
130 | 783753fd | Isaku Yamahata | } else {
|
131 | 783753fd | Isaku Yamahata | limit = pci_config_get_memory_base(bridge, PCI_MEMORY_LIMIT); |
132 | 783753fd | Isaku Yamahata | } |
133 | 783753fd | Isaku Yamahata | limit |= 0xfffff; /* PCI bridge spec 3.2.5.{1, 8}. */ |
134 | 783753fd | Isaku Yamahata | } |
135 | 783753fd | Isaku Yamahata | return limit;
|
136 | 783753fd | Isaku Yamahata | } |
137 | 783753fd | Isaku Yamahata | |
138 | 7df32ca0 | Michael S. Tsirkin | static void pci_bridge_init_alias(PCIBridge *bridge, MemoryRegion *alias, |
139 | 7df32ca0 | Michael S. Tsirkin | uint8_t type, const char *name, |
140 | 7df32ca0 | Michael S. Tsirkin | MemoryRegion *space, |
141 | 7df32ca0 | Michael S. Tsirkin | MemoryRegion *parent_space, |
142 | 7df32ca0 | Michael S. Tsirkin | bool enabled)
|
143 | 7df32ca0 | Michael S. Tsirkin | { |
144 | 7df32ca0 | Michael S. Tsirkin | pcibus_t base = pci_bridge_get_base(&bridge->dev, type); |
145 | 7df32ca0 | Michael S. Tsirkin | pcibus_t limit = pci_bridge_get_limit(&bridge->dev, type); |
146 | 7df32ca0 | Michael S. Tsirkin | /* TODO: this doesn't handle base = 0 limit = 2^64 - 1 correctly.
|
147 | 7df32ca0 | Michael S. Tsirkin | * Apparently no way to do this with existing memory APIs. */
|
148 | 7df32ca0 | Michael S. Tsirkin | pcibus_t size = enabled && limit >= base ? limit + 1 - base : 0; |
149 | 7df32ca0 | Michael S. Tsirkin | |
150 | 7df32ca0 | Michael S. Tsirkin | memory_region_init_alias(alias, name, space, base, size); |
151 | 7df32ca0 | Michael S. Tsirkin | memory_region_add_subregion_overlap(parent_space, base, alias, 1);
|
152 | 7df32ca0 | Michael S. Tsirkin | } |
153 | 7df32ca0 | Michael S. Tsirkin | |
154 | b308c82c | Avi Kivity | static PCIBridgeWindows *pci_bridge_region_init(PCIBridge *br)
|
155 | 7df32ca0 | Michael S. Tsirkin | { |
156 | 7df32ca0 | Michael S. Tsirkin | PCIBus *parent = br->dev.bus; |
157 | b308c82c | Avi Kivity | PCIBridgeWindows *w = g_new(PCIBridgeWindows, 1);
|
158 | 7df32ca0 | Michael S. Tsirkin | uint16_t cmd = pci_get_word(br->dev.config + PCI_COMMAND); |
159 | 7df32ca0 | Michael S. Tsirkin | |
160 | b308c82c | Avi Kivity | pci_bridge_init_alias(br, &w->alias_pref_mem, |
161 | 7df32ca0 | Michael S. Tsirkin | PCI_BASE_ADDRESS_MEM_PREFETCH, |
162 | 7df32ca0 | Michael S. Tsirkin | "pci_bridge_pref_mem",
|
163 | 336411ca | Michael S. Tsirkin | &br->address_space_mem, |
164 | 7df32ca0 | Michael S. Tsirkin | parent->address_space_mem, |
165 | 7df32ca0 | Michael S. Tsirkin | cmd & PCI_COMMAND_MEMORY); |
166 | b308c82c | Avi Kivity | pci_bridge_init_alias(br, &w->alias_mem, |
167 | 7df32ca0 | Michael S. Tsirkin | PCI_BASE_ADDRESS_SPACE_MEMORY, |
168 | 7df32ca0 | Michael S. Tsirkin | "pci_bridge_mem",
|
169 | 336411ca | Michael S. Tsirkin | &br->address_space_mem, |
170 | 7df32ca0 | Michael S. Tsirkin | parent->address_space_mem, |
171 | 7df32ca0 | Michael S. Tsirkin | cmd & PCI_COMMAND_MEMORY); |
172 | b308c82c | Avi Kivity | pci_bridge_init_alias(br, &w->alias_io, |
173 | 7df32ca0 | Michael S. Tsirkin | PCI_BASE_ADDRESS_SPACE_IO, |
174 | 7df32ca0 | Michael S. Tsirkin | "pci_bridge_io",
|
175 | 336411ca | Michael S. Tsirkin | &br->address_space_io, |
176 | 7df32ca0 | Michael S. Tsirkin | parent->address_space_io, |
177 | 7df32ca0 | Michael S. Tsirkin | cmd & PCI_COMMAND_IO); |
178 | 7df32ca0 | Michael S. Tsirkin | /* TODO: optinal VGA and VGA palette snooping support. */
|
179 | b308c82c | Avi Kivity | |
180 | b308c82c | Avi Kivity | return w;
|
181 | 7df32ca0 | Michael S. Tsirkin | } |
182 | 7df32ca0 | Michael S. Tsirkin | |
183 | b308c82c | Avi Kivity | static void pci_bridge_region_del(PCIBridge *br, PCIBridgeWindows *w) |
184 | 7df32ca0 | Michael S. Tsirkin | { |
185 | 7df32ca0 | Michael S. Tsirkin | PCIBus *parent = br->dev.bus; |
186 | b308c82c | Avi Kivity | |
187 | b308c82c | Avi Kivity | memory_region_del_subregion(parent->address_space_io, &w->alias_io); |
188 | b308c82c | Avi Kivity | memory_region_del_subregion(parent->address_space_mem, &w->alias_mem); |
189 | b308c82c | Avi Kivity | memory_region_del_subregion(parent->address_space_mem, &w->alias_pref_mem); |
190 | b308c82c | Avi Kivity | } |
191 | b308c82c | Avi Kivity | |
192 | b308c82c | Avi Kivity | static void pci_bridge_region_cleanup(PCIBridge *br, PCIBridgeWindows *w) |
193 | b308c82c | Avi Kivity | { |
194 | b308c82c | Avi Kivity | memory_region_destroy(&w->alias_io); |
195 | b308c82c | Avi Kivity | memory_region_destroy(&w->alias_mem); |
196 | b308c82c | Avi Kivity | memory_region_destroy(&w->alias_pref_mem); |
197 | b308c82c | Avi Kivity | g_free(w); |
198 | 7df32ca0 | Michael S. Tsirkin | } |
199 | 7df32ca0 | Michael S. Tsirkin | |
200 | 7df32ca0 | Michael S. Tsirkin | static void pci_bridge_update_mappings(PCIBridge *br) |
201 | 7df32ca0 | Michael S. Tsirkin | { |
202 | b308c82c | Avi Kivity | PCIBridgeWindows *w = br->windows; |
203 | b308c82c | Avi Kivity | |
204 | 7df32ca0 | Michael S. Tsirkin | /* Make updates atomic to: handle the case of one VCPU updating the bridge
|
205 | 7df32ca0 | Michael S. Tsirkin | * while another accesses an unaffected region. */
|
206 | 7df32ca0 | Michael S. Tsirkin | memory_region_transaction_begin(); |
207 | b308c82c | Avi Kivity | pci_bridge_region_del(br, br->windows); |
208 | b308c82c | Avi Kivity | br->windows = pci_bridge_region_init(br); |
209 | 7df32ca0 | Michael S. Tsirkin | memory_region_transaction_commit(); |
210 | b308c82c | Avi Kivity | pci_bridge_region_cleanup(br, w); |
211 | 7df32ca0 | Michael S. Tsirkin | } |
212 | 7df32ca0 | Michael S. Tsirkin | |
213 | 68f79994 | Isaku Yamahata | /* default write_config function for PCI-to-PCI bridge */
|
214 | 68f79994 | Isaku Yamahata | void pci_bridge_write_config(PCIDevice *d,
|
215 | 783753fd | Isaku Yamahata | uint32_t address, uint32_t val, int len)
|
216 | 783753fd | Isaku Yamahata | { |
217 | a5fce077 | Isaku Yamahata | PCIBridge *s = container_of(d, PCIBridge, dev); |
218 | a5fce077 | Isaku Yamahata | uint16_t oldctl = pci_get_word(d->config + PCI_BRIDGE_CONTROL); |
219 | a5fce077 | Isaku Yamahata | uint16_t newctl; |
220 | a5fce077 | Isaku Yamahata | |
221 | 783753fd | Isaku Yamahata | pci_default_write_config(d, address, val, len); |
222 | 783753fd | Isaku Yamahata | |
223 | 7df32ca0 | Michael S. Tsirkin | if (ranges_overlap(address, len, PCI_COMMAND, 2) || |
224 | 7df32ca0 | Michael S. Tsirkin | |
225 | 7df32ca0 | Michael S. Tsirkin | /* io base/limit */
|
226 | 783753fd | Isaku Yamahata | ranges_overlap(address, len, PCI_IO_BASE, 2) ||
|
227 | 783753fd | Isaku Yamahata | |
228 | 783753fd | Isaku Yamahata | /* memory base/limit, prefetchable base/limit and
|
229 | 783753fd | Isaku Yamahata | io base/limit upper 16 */
|
230 | 783753fd | Isaku Yamahata | ranges_overlap(address, len, PCI_MEMORY_BASE, 20)) {
|
231 | 7df32ca0 | Michael S. Tsirkin | pci_bridge_update_mappings(s); |
232 | 783753fd | Isaku Yamahata | } |
233 | a5fce077 | Isaku Yamahata | |
234 | a5fce077 | Isaku Yamahata | newctl = pci_get_word(d->config + PCI_BRIDGE_CONTROL); |
235 | a5fce077 | Isaku Yamahata | if (~oldctl & newctl & PCI_BRIDGE_CTL_BUS_RESET) {
|
236 | a5fce077 | Isaku Yamahata | /* Trigger hot reset on 0->1 transition. */
|
237 | a5fce077 | Isaku Yamahata | pci_bus_reset(&s->sec_bus); |
238 | a5fce077 | Isaku Yamahata | } |
239 | 783753fd | Isaku Yamahata | } |
240 | 783753fd | Isaku Yamahata | |
241 | 0208def1 | Isaku Yamahata | void pci_bridge_disable_base_limit(PCIDevice *dev)
|
242 | 0208def1 | Isaku Yamahata | { |
243 | 0208def1 | Isaku Yamahata | uint8_t *conf = dev->config; |
244 | 0208def1 | Isaku Yamahata | |
245 | 0208def1 | Isaku Yamahata | pci_byte_test_and_set_mask(conf + PCI_IO_BASE, |
246 | 0208def1 | Isaku Yamahata | PCI_IO_RANGE_MASK & 0xff);
|
247 | 0208def1 | Isaku Yamahata | pci_byte_test_and_clear_mask(conf + PCI_IO_LIMIT, |
248 | 0208def1 | Isaku Yamahata | PCI_IO_RANGE_MASK & 0xff);
|
249 | 0208def1 | Isaku Yamahata | pci_word_test_and_set_mask(conf + PCI_MEMORY_BASE, |
250 | 0208def1 | Isaku Yamahata | PCI_MEMORY_RANGE_MASK & 0xffff);
|
251 | 0208def1 | Isaku Yamahata | pci_word_test_and_clear_mask(conf + PCI_MEMORY_LIMIT, |
252 | 0208def1 | Isaku Yamahata | PCI_MEMORY_RANGE_MASK & 0xffff);
|
253 | 0208def1 | Isaku Yamahata | pci_word_test_and_set_mask(conf + PCI_PREF_MEMORY_BASE, |
254 | 0208def1 | Isaku Yamahata | PCI_PREF_RANGE_MASK & 0xffff);
|
255 | 0208def1 | Isaku Yamahata | pci_word_test_and_clear_mask(conf + PCI_PREF_MEMORY_LIMIT, |
256 | 0208def1 | Isaku Yamahata | PCI_PREF_RANGE_MASK & 0xffff);
|
257 | cd7898f7 | Michael S. Tsirkin | pci_set_long(conf + PCI_PREF_BASE_UPPER32, 0);
|
258 | cd7898f7 | Michael S. Tsirkin | pci_set_long(conf + PCI_PREF_LIMIT_UPPER32, 0);
|
259 | 0208def1 | Isaku Yamahata | } |
260 | 0208def1 | Isaku Yamahata | |
261 | 68f79994 | Isaku Yamahata | /* reset bridge specific configuration registers */
|
262 | cbd2d434 | Jan Kiszka | void pci_bridge_reset(DeviceState *qdev)
|
263 | 68f79994 | Isaku Yamahata | { |
264 | cbd2d434 | Jan Kiszka | PCIDevice *dev = PCI_DEVICE(qdev); |
265 | 68f79994 | Isaku Yamahata | uint8_t *conf = dev->config; |
266 | 68f79994 | Isaku Yamahata | |
267 | 68f79994 | Isaku Yamahata | conf[PCI_PRIMARY_BUS] = 0;
|
268 | 68f79994 | Isaku Yamahata | conf[PCI_SECONDARY_BUS] = 0;
|
269 | 68f79994 | Isaku Yamahata | conf[PCI_SUBORDINATE_BUS] = 0;
|
270 | 68f79994 | Isaku Yamahata | conf[PCI_SEC_LATENCY_TIMER] = 0;
|
271 | 68f79994 | Isaku Yamahata | |
272 | 0208def1 | Isaku Yamahata | /*
|
273 | 0208def1 | Isaku Yamahata | * the default values for base/limit registers aren't specified
|
274 | 0208def1 | Isaku Yamahata | * in the PCI-to-PCI-bridge spec. So we don't thouch them here.
|
275 | 0208def1 | Isaku Yamahata | * Each implementation can override it.
|
276 | 0208def1 | Isaku Yamahata | * typical implementation does
|
277 | 0208def1 | Isaku Yamahata | * zero base/limit registers or
|
278 | 0208def1 | Isaku Yamahata | * disable forwarding: pci_bridge_disable_base_limit()
|
279 | 0208def1 | Isaku Yamahata | * If disable forwarding is wanted, call pci_bridge_disable_base_limit()
|
280 | 0208def1 | Isaku Yamahata | * after this function.
|
281 | 0208def1 | Isaku Yamahata | */
|
282 | 0208def1 | Isaku Yamahata | pci_byte_test_and_clear_mask(conf + PCI_IO_BASE, |
283 | 0208def1 | Isaku Yamahata | PCI_IO_RANGE_MASK & 0xff);
|
284 | 0208def1 | Isaku Yamahata | pci_byte_test_and_clear_mask(conf + PCI_IO_LIMIT, |
285 | 0208def1 | Isaku Yamahata | PCI_IO_RANGE_MASK & 0xff);
|
286 | 0208def1 | Isaku Yamahata | pci_word_test_and_clear_mask(conf + PCI_MEMORY_BASE, |
287 | 0208def1 | Isaku Yamahata | PCI_MEMORY_RANGE_MASK & 0xffff);
|
288 | 0208def1 | Isaku Yamahata | pci_word_test_and_clear_mask(conf + PCI_MEMORY_LIMIT, |
289 | 0208def1 | Isaku Yamahata | PCI_MEMORY_RANGE_MASK & 0xffff);
|
290 | 0208def1 | Isaku Yamahata | pci_word_test_and_clear_mask(conf + PCI_PREF_MEMORY_BASE, |
291 | 0208def1 | Isaku Yamahata | PCI_PREF_RANGE_MASK & 0xffff);
|
292 | 0208def1 | Isaku Yamahata | pci_word_test_and_clear_mask(conf + PCI_PREF_MEMORY_LIMIT, |
293 | 0208def1 | Isaku Yamahata | PCI_PREF_RANGE_MASK & 0xffff);
|
294 | cd7898f7 | Michael S. Tsirkin | pci_set_long(conf + PCI_PREF_BASE_UPPER32, 0);
|
295 | cd7898f7 | Michael S. Tsirkin | pci_set_long(conf + PCI_PREF_LIMIT_UPPER32, 0);
|
296 | 68f79994 | Isaku Yamahata | |
297 | 68f79994 | Isaku Yamahata | pci_set_word(conf + PCI_BRIDGE_CONTROL, 0);
|
298 | 68f79994 | Isaku Yamahata | } |
299 | 68f79994 | Isaku Yamahata | |
300 | 68f79994 | Isaku Yamahata | /* default qdev initialization function for PCI-to-PCI bridge */
|
301 | 68f79994 | Isaku Yamahata | int pci_bridge_initfn(PCIDevice *dev)
|
302 | 68f79994 | Isaku Yamahata | { |
303 | 68f79994 | Isaku Yamahata | PCIBus *parent = dev->bus; |
304 | 68f79994 | Isaku Yamahata | PCIBridge *br = DO_UPCAST(PCIBridge, dev, dev); |
305 | 68f79994 | Isaku Yamahata | PCIBus *sec_bus = &br->sec_bus; |
306 | 783753fd | Isaku Yamahata | |
307 | 95be1196 | Michael S. Tsirkin | pci_word_test_and_set_mask(dev->config + PCI_STATUS, |
308 | 95be1196 | Michael S. Tsirkin | PCI_STATUS_66MHZ | PCI_STATUS_FAST_BACK); |
309 | 783753fd | Isaku Yamahata | pci_config_set_class(dev->config, PCI_CLASS_BRIDGE_PCI); |
310 | 783753fd | Isaku Yamahata | dev->config[PCI_HEADER_TYPE] = |
311 | 783753fd | Isaku Yamahata | (dev->config[PCI_HEADER_TYPE] & PCI_HEADER_TYPE_MULTI_FUNCTION) | |
312 | 783753fd | Isaku Yamahata | PCI_HEADER_TYPE_BRIDGE; |
313 | 783753fd | Isaku Yamahata | pci_set_word(dev->config + PCI_SEC_STATUS, |
314 | 783753fd | Isaku Yamahata | PCI_STATUS_66MHZ | PCI_STATUS_FAST_BACK); |
315 | 68f79994 | Isaku Yamahata | |
316 | 8a3d80fa | Michael S. Tsirkin | /*
|
317 | 8a3d80fa | Michael S. Tsirkin | * If we don't specify the name, the bus will be addressed as <id>.0, where
|
318 | 8a3d80fa | Michael S. Tsirkin | * id is the device id.
|
319 | 8a3d80fa | Michael S. Tsirkin | * Since PCI Bridge devices have a single bus each, we don't need the index:
|
320 | 8a3d80fa | Michael S. Tsirkin | * let users address the bus using the device name.
|
321 | 8a3d80fa | Michael S. Tsirkin | */
|
322 | 8a3d80fa | Michael S. Tsirkin | if (!br->bus_name && dev->qdev.id && *dev->qdev.id) {
|
323 | 8a3d80fa | Michael S. Tsirkin | br->bus_name = dev->qdev.id; |
324 | 8a3d80fa | Michael S. Tsirkin | } |
325 | 8a3d80fa | Michael S. Tsirkin | |
326 | 0d936928 | Anthony Liguori | qbus_create_inplace(&sec_bus->qbus, TYPE_PCI_BUS, &dev->qdev, |
327 | 68f79994 | Isaku Yamahata | br->bus_name); |
328 | 68f79994 | Isaku Yamahata | sec_bus->parent_dev = dev; |
329 | 68f79994 | Isaku Yamahata | sec_bus->map_irq = br->map_irq; |
330 | 336411ca | Michael S. Tsirkin | sec_bus->address_space_mem = &br->address_space_mem; |
331 | 52ce6f05 | Blue Swirl | memory_region_init(&br->address_space_mem, "pci_bridge_pci", INT64_MAX);
|
332 | 336411ca | Michael S. Tsirkin | sec_bus->address_space_io = &br->address_space_io; |
333 | 336411ca | Michael S. Tsirkin | memory_region_init(&br->address_space_io, "pci_bridge_io", 65536); |
334 | b308c82c | Avi Kivity | br->windows = pci_bridge_region_init(br); |
335 | 68f79994 | Isaku Yamahata | QLIST_INIT(&sec_bus->child); |
336 | 68f79994 | Isaku Yamahata | QLIST_INSERT_HEAD(&parent->child, sec_bus, sibling); |
337 | 783753fd | Isaku Yamahata | return 0; |
338 | 783753fd | Isaku Yamahata | } |
339 | 783753fd | Isaku Yamahata | |
340 | 68f79994 | Isaku Yamahata | /* default qdev clean up function for PCI-to-PCI bridge */
|
341 | f90c2bcd | Alex Williamson | void pci_bridge_exitfn(PCIDevice *pci_dev)
|
342 | 783753fd | Isaku Yamahata | { |
343 | 783753fd | Isaku Yamahata | PCIBridge *s = DO_UPCAST(PCIBridge, dev, pci_dev); |
344 | 51a92333 | Isaku Yamahata | assert(QLIST_EMPTY(&s->sec_bus.child)); |
345 | 51a92333 | Isaku Yamahata | QLIST_REMOVE(&s->sec_bus, sibling); |
346 | b308c82c | Avi Kivity | pci_bridge_region_del(s, s->windows); |
347 | b308c82c | Avi Kivity | pci_bridge_region_cleanup(s, s->windows); |
348 | 336411ca | Michael S. Tsirkin | memory_region_destroy(&s->address_space_mem); |
349 | 336411ca | Michael S. Tsirkin | memory_region_destroy(&s->address_space_io); |
350 | 68f79994 | Isaku Yamahata | /* qbus_free() is called automatically by qdev_free() */
|
351 | 783753fd | Isaku Yamahata | } |
352 | 783753fd | Isaku Yamahata | |
353 | 68f79994 | Isaku Yamahata | /*
|
354 | 68f79994 | Isaku Yamahata | * before qdev initialization(qdev_init()), this function sets bus_name and
|
355 | 68f79994 | Isaku Yamahata | * map_irq callback which are necessry for pci_bridge_initfn() to
|
356 | 68f79994 | Isaku Yamahata | * initialize bus.
|
357 | 68f79994 | Isaku Yamahata | */
|
358 | 68f79994 | Isaku Yamahata | void pci_bridge_map_irq(PCIBridge *br, const char* bus_name, |
359 | 68f79994 | Isaku Yamahata | pci_map_irq_fn map_irq) |
360 | 783753fd | Isaku Yamahata | { |
361 | 68f79994 | Isaku Yamahata | br->map_irq = map_irq; |
362 | 68f79994 | Isaku Yamahata | br->bus_name = bus_name; |
363 | 783753fd | Isaku Yamahata | } |