Rev 2187 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1628 | serge | 1 | |
2 | #include |
||
3 | #include |
||
4 | #include |
||
5 | #include |
||
2187 | Serge | 6 | #include |
1628 | serge | 7 | |
8 | |||
1631 | serge | 9 | |
1628 | serge | 10 | |
1631 | serge | 11 | |
12 | |||
13 | |||
14 | |||
15 | |||
1628 | serge | 16 | |
17 | |||
1631 | serge | 18 | #define CARDBUS_RESERVE_BUSNR 3 |
19 | |||
20 | |||
9499 | turbocat | 21 | { |
1631 | serge | 22 | return 0; |
23 | }; |
||
24 | |||
25 | |||
26 | * Translate the low bits of the PCI base |
||
27 | * to the resource type |
||
28 | */ |
||
29 | static inline unsigned int pci_calc_resource_flags(unsigned int flags) |
||
30 | { |
||
31 | if (flags & PCI_BASE_ADDRESS_SPACE_IO) |
||
32 | return IORESOURCE_IO; |
||
33 | |||
34 | |||
35 | return IORESOURCE_MEM | IORESOURCE_PREFETCH; |
||
36 | |||
37 | |||
38 | } |
||
39 | |||
40 | |||
41 | { |
||
42 | u64 size = mask & maxbase; /* Find the significant bits */ |
||
43 | if (!size) |
||
44 | return 0; |
||
45 | |||
46 | |||
47 | from that the extent. */ |
||
48 | size = (size & ~(size-1)) - 1; |
||
49 | |||
50 | |||
51 | already been programmed with all 1s. */ |
||
52 | if (base == maxbase && ((base | size) & mask) != mask) |
||
53 | return 0; |
||
54 | |||
55 | |||
56 | } |
||
57 | |||
58 | |||
59 | { |
||
60 | if ((bar & PCI_BASE_ADDRESS_SPACE) == PCI_BASE_ADDRESS_SPACE_IO) { |
||
61 | res->flags = bar & ~PCI_BASE_ADDRESS_IO_MASK; |
||
62 | return pci_bar_io; |
||
63 | } |
||
64 | |||
65 | |||
66 | |||
67 | |||
68 | return pci_bar_mem64; |
||
69 | return pci_bar_mem32; |
||
70 | } |
||
71 | |||
72 | |||
73 | |||
74 | |||
75 | * pci_read_base - read a PCI BAR |
||
76 | * @dev: the PCI device |
||
77 | * @type: type of the BAR |
||
78 | * @res: resource buffer to be filled in |
||
79 | * @pos: BAR position in the config space |
||
80 | * |
||
81 | * Returns 1 if the BAR is 64-bit, or 0 if 32-bit. |
||
82 | */ |
||
83 | int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, |
||
84 | struct resource *res, unsigned int pos) |
||
85 | { |
||
86 | u32 l, sz, mask; |
||
87 | u16 orig_cmd; |
||
88 | |||
89 | |||
90 | |||
91 | |||
92 | pci_read_config_word(dev, PCI_COMMAND, &orig_cmd); |
||
93 | pci_write_config_word(dev, PCI_COMMAND, |
||
94 | orig_cmd & ~(PCI_COMMAND_MEMORY | PCI_COMMAND_IO)); |
||
95 | } |
||
96 | |||
97 | |||
98 | |||
99 | |||
100 | pci_write_config_dword(dev, pos, l | mask); |
||
101 | pci_read_config_dword(dev, pos, &sz); |
||
102 | pci_write_config_dword(dev, pos, l); |
||
103 | |||
104 | |||
105 | pci_write_config_word(dev, PCI_COMMAND, orig_cmd); |
||
106 | |||
107 | |||
108 | * All bits set in sz means the device isn't working properly. |
||
109 | * If the BAR isn't implemented, all bits must be 0. If it's a |
||
110 | * memory BAR or a ROM, bit 0 must be clear; if it's an io BAR, bit |
||
111 | * 1 must be clear. |
||
112 | */ |
||
113 | if (!sz || sz == 0xffffffff) |
||
114 | goto fail; |
||
115 | |||
116 | |||
117 | * I don't know how l can have all bits set. Copied from old code. |
||
118 | * Maybe it fixes a bug on some ancient platform. |
||
119 | */ |
||
120 | if (l == 0xffffffff) |
||
121 | l = 0; |
||
122 | |||
123 | |||
124 | type = decode_bar(res, l); |
||
125 | res->flags |= pci_calc_resource_flags(l) | IORESOURCE_SIZEALIGN; |
||
126 | if (type == pci_bar_io) { |
||
127 | l &= PCI_BASE_ADDRESS_IO_MASK; |
||
128 | mask = PCI_BASE_ADDRESS_IO_MASK & IO_SPACE_LIMIT; |
||
129 | } else { |
||
130 | l &= PCI_BASE_ADDRESS_MEM_MASK; |
||
131 | mask = (u32)PCI_BASE_ADDRESS_MEM_MASK; |
||
132 | } |
||
133 | } else { |
||
134 | res->flags |= (l & IORESOURCE_ROM_ENABLE); |
||
135 | l &= PCI_ROM_ADDRESS_MASK; |
||
136 | mask = (u32)PCI_ROM_ADDRESS_MASK; |
||
137 | } |
||
138 | |||
139 | |||
140 | u64 l64 = l; |
||
141 | u64 sz64 = sz; |
||
142 | u64 mask64 = mask | (u64)~0 << 32; |
||
143 | |||
144 | |||
145 | pci_write_config_dword(dev, pos + 4, ~0); |
||
146 | pci_read_config_dword(dev, pos + 4, &sz); |
||
147 | pci_write_config_dword(dev, pos + 4, l); |
||
148 | |||
149 | |||
150 | sz64 |= ((u64)sz << 32); |
||
151 | |||
152 | |||
153 | |||
154 | |||
155 | goto fail; |
||
156 | |||
157 | |||
158 | dbgprintf("%s reg %x: can't handle 64-bit BAR\n", |
||
159 | __FUNCTION__, pos); |
||
160 | goto fail; |
||
161 | } |
||
162 | |||
163 | |||
164 | if ((sizeof(resource_size_t) < 8) && l) { |
||
165 | /* Address above 32-bit boundary; disable the BAR */ |
||
166 | pci_write_config_dword(dev, pos, 0); |
||
167 | pci_write_config_dword(dev, pos + 4, 0); |
||
168 | res->start = 0; |
||
169 | res->end = sz64; |
||
170 | } else { |
||
171 | res->start = l64; |
||
172 | res->end = l64 + sz64; |
||
173 | dbgprintf("%s reg %x: %pR\n", __FUNCTION__, pos, res); |
||
174 | } |
||
175 | } else { |
||
176 | sz = pci_size(l, sz, mask); |
||
177 | |||
178 | |||
179 | goto fail; |
||
180 | |||
181 | |||
182 | res->end = l + sz; |
||
183 | |||
184 | |||
185 | } |
||
186 | |||
187 | |||
188 | return (type == pci_bar_mem64) ? 1 : 0; |
||
189 | fail: |
||
190 | res->flags = 0; |
||
191 | goto out; |
||
192 | } |
||
193 | |||
194 | |||
195 | { |
||
196 | unsigned int pos, reg; |
||
197 | |||
198 | |||
199 | struct resource *res = &dev->resource[pos]; |
||
200 | reg = PCI_BASE_ADDRESS_0 + (pos << 2); |
||
201 | pos += __pci_read_base(dev, pci_bar_unknown, res, reg); |
||
202 | } |
||
203 | |||
204 | |||
205 | struct resource *res = &dev->resource[PCI_ROM_RESOURCE]; |
||
206 | dev->rom_base_reg = rom; |
||
207 | res->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH | |
||
208 | IORESOURCE_READONLY | IORESOURCE_CACHEABLE | |
||
209 | IORESOURCE_SIZEALIGN; |
||
210 | __pci_read_base(dev, pci_bar_mem32, res, rom); |
||
211 | } |
||
212 | } |
||
213 | |||
214 | |||
215 | |||
216 | |||
217 | { |
||
218 | struct pci_dev *dev = child->self; |
||
219 | struct resource *res; |
||
220 | int i; |
||
221 | |||
222 | |||
223 | return; |
||
224 | |||
225 | |||
226 | child->secondary, child->subordinate, |
||
227 | dev->transparent ? " (subtractive decode)" : ""); |
||
228 | |||
229 | |||
230 | for (i = 0; i < PCI_BRIDGE_RESOURCE_NUM; i++) |
||
231 | child->resource[i] = &dev->resource[PCI_BRIDGE_RESOURCES+i]; |
||
232 | |||
233 | |||
234 | pci_read_bridge_mmio(child); |
||
235 | pci_read_bridge_mmio_pref(child); |
||
236 | |||
237 | |||
238 | pci_bus_for_each_resource(child->parent, res, i) { |
||
239 | if (res) { |
||
240 | pci_bus_add_resource(child, res, |
||
241 | PCI_SUBTRACTIVE_DECODE); |
||
242 | dbgprintf(" bridge window %pR (subtractive decode)\n", res); |
||
243 | } |
||
244 | } |
||
245 | } |
||
246 | } |
||
247 | |||
248 | |||
249 | |||
250 | |||
251 | { |
||
252 | struct pci_bus *b; |
||
253 | |||
254 | |||
255 | if (b) { |
||
256 | INIT_LIST_HEAD(&b->node); |
||
257 | INIT_LIST_HEAD(&b->children); |
||
258 | INIT_LIST_HEAD(&b->devices); |
||
259 | INIT_LIST_HEAD(&b->slots); |
||
260 | INIT_LIST_HEAD(&b->resources); |
||
261 | // b->max_bus_speed = PCI_SPEED_UNKNOWN; |
||
262 | // b->cur_bus_speed = PCI_SPEED_UNKNOWN; |
||
263 | } |
||
264 | return b; |
||
265 | } |
||
266 | |||
267 | |||
268 | |||
269 | |||
270 | |||
271 | PCI_SPEED_UNKNOWN, /* 0 */ |
||
272 | PCI_SPEED_66MHz_PCIX, /* 1 */ |
||
273 | PCI_SPEED_100MHz_PCIX, /* 2 */ |
||
274 | PCI_SPEED_133MHz_PCIX, /* 3 */ |
||
275 | PCI_SPEED_UNKNOWN, /* 4 */ |
||
276 | PCI_SPEED_66MHz_PCIX_ECC, /* 5 */ |
||
277 | PCI_SPEED_100MHz_PCIX_ECC, /* 6 */ |
||
278 | PCI_SPEED_133MHz_PCIX_ECC, /* 7 */ |
||
279 | PCI_SPEED_UNKNOWN, /* 8 */ |
||
280 | PCI_SPEED_66MHz_PCIX_266, /* 9 */ |
||
281 | PCI_SPEED_100MHz_PCIX_266, /* A */ |
||
282 | PCI_SPEED_133MHz_PCIX_266, /* B */ |
||
283 | PCI_SPEED_UNKNOWN, /* C */ |
||
284 | PCI_SPEED_66MHz_PCIX_533, /* D */ |
||
285 | PCI_SPEED_100MHz_PCIX_533, /* E */ |
||
286 | PCI_SPEED_133MHz_PCIX_533 /* F */ |
||
287 | }; |
||
288 | |||
289 | |||
290 | PCI_SPEED_UNKNOWN, /* 0 */ |
||
291 | PCIE_SPEED_2_5GT, /* 1 */ |
||
292 | PCIE_SPEED_5_0GT, /* 2 */ |
||
293 | PCIE_SPEED_8_0GT, /* 3 */ |
||
294 | PCI_SPEED_UNKNOWN, /* 4 */ |
||
295 | PCI_SPEED_UNKNOWN, /* 5 */ |
||
296 | PCI_SPEED_UNKNOWN, /* 6 */ |
||
297 | PCI_SPEED_UNKNOWN, /* 7 */ |
||
298 | PCI_SPEED_UNKNOWN, /* 8 */ |
||
299 | PCI_SPEED_UNKNOWN, /* 9 */ |
||
300 | PCI_SPEED_UNKNOWN, /* A */ |
||
301 | PCI_SPEED_UNKNOWN, /* B */ |
||
302 | PCI_SPEED_UNKNOWN, /* C */ |
||
303 | PCI_SPEED_UNKNOWN, /* D */ |
||
304 | PCI_SPEED_UNKNOWN, /* E */ |
||
305 | PCI_SPEED_UNKNOWN /* F */ |
||
306 | }; |
||
307 | |||
308 | |||
309 | |||
310 | { |
||
311 | struct pci_dev *bridge = bus->self; |
||
312 | int pos; |
||
313 | |||
314 | |||
315 | if (!pos) |
||
316 | pos = pci_find_capability(bridge, PCI_CAP_ID_AGP3); |
||
317 | if (pos) { |
||
318 | u32 agpstat, agpcmd; |
||
319 | |||
320 | |||
321 | bus->max_bus_speed = agp_speed(agpstat & 8, agpstat & 7); |
||
322 | |||
323 | |||
324 | bus->cur_bus_speed = agp_speed(agpstat & 8, agpcmd & 7); |
||
325 | } |
||
326 | |||
327 | |||
328 | if (pos) { |
||
329 | u16 status; |
||
330 | enum pci_bus_speed max; |
||
331 | pci_read_config_word(bridge, pos + 2, &status); |
||
332 | |||
333 | |||
334 | max = PCI_SPEED_133MHz_PCIX_533; |
||
335 | } else if (status & 0x4000) { |
||
336 | max = PCI_SPEED_133MHz_PCIX_266; |
||
337 | } else if (status & 0x0002) { |
||
338 | if (((status >> 12) & 0x3) == 2) { |
||
339 | max = PCI_SPEED_133MHz_PCIX_ECC; |
||
340 | } else { |
||
341 | max = PCI_SPEED_133MHz_PCIX; |
||
342 | } |
||
343 | } else { |
||
344 | max = PCI_SPEED_66MHz_PCIX; |
||
345 | } |
||
346 | |||
347 | |||
348 | bus->cur_bus_speed = pcix_bus_speed[(status >> 6) & 0xf]; |
||
349 | |||
350 | |||
351 | } |
||
352 | |||
353 | |||
354 | if (pos) { |
||
355 | u32 linkcap; |
||
356 | u16 linksta; |
||
357 | |||
358 | |||
359 | bus->max_bus_speed = pcie_link_speed[linkcap & 0xf]; |
||
360 | |||
361 | |||
362 | pcie_update_link_speed(bus, linksta); |
||
363 | } |
||
364 | } |
||
365 | |||
366 | |||
367 | |||
368 | |||
369 | |||
370 | struct pci_dev *bridge, int busnr) |
||
371 | { |
||
372 | struct pci_bus *child; |
||
373 | int i; |
||
374 | |||
375 | |||
376 | * Allocate a new bus, and inherit stuff from the parent.. |
||
377 | */ |
||
378 | child = pci_alloc_bus(); |
||
379 | if (!child) |
||
380 | return NULL; |
||
381 | |||
382 | |||
383 | child->ops = parent->ops; |
||
384 | child->sysdata = parent->sysdata; |
||
385 | child->bus_flags = parent->bus_flags; |
||
386 | |||
387 | |||
388 | * now as the parent is not properly set up yet. This device will get |
||
389 | * registered later in pci_bus_add_devices() |
||
390 | */ |
||
391 | // child->dev.class = &pcibus_class; |
||
392 | // dev_set_name(&child->dev, "%04x:%02x", pci_domain_nr(child), busnr); |
||
393 | |||
394 | |||
395 | * Set up the primary, secondary and subordinate |
||
396 | * bus numbers. |
||
397 | */ |
||
398 | child->number = child->secondary = busnr; |
||
399 | child->primary = parent->secondary; |
||
400 | child->subordinate = 0xff; |
||
401 | |||
402 | |||
403 | return child; |
||
404 | |||
405 | |||
406 | // child->bridge = get_device(&bridge->dev); |
||
407 | |||
408 | |||
409 | |||
410 | |||
411 | for (i = 0; i < PCI_BRIDGE_RESOURCE_NUM; i++) { |
||
412 | child->resource[i] = &bridge->resource[PCI_BRIDGE_RESOURCES+i]; |
||
413 | child->resource[i]->name = child->name; |
||
414 | } |
||
415 | bridge->subordinate = child; |
||
416 | |||
417 | |||
418 | } |
||
419 | |||
420 | |||
421 | { |
||
422 | struct pci_bus *child; |
||
423 | |||
424 | |||
425 | if (child) { |
||
426 | // down_write(&pci_bus_sem); |
||
427 | list_add_tail(&child->node, &parent->children); |
||
428 | // up_write(&pci_bus_sem); |
||
429 | } |
||
430 | return child; |
||
431 | } |
||
432 | |||
433 | |||
434 | |||
435 | { |
||
436 | struct pci_bus *parent = child->parent; |
||
437 | |||
438 | |||
439 | we're going to re-assign all bus numbers. */ |
||
440 | if (!pcibios_assign_all_busses()) |
||
441 | return; |
||
442 | |||
443 | |||
444 | parent->subordinate = max; |
||
445 | pci_write_config_byte(parent->self, PCI_SUBORDINATE_BUS, max); |
||
446 | parent = parent->parent; |
||
447 | } |
||
448 | } |
||
449 | |||
450 | |||
451 | |||
452 | * If it's a bridge, configure it and scan the bus behind it. |
||
453 | * For CardBus bridges, we don't scan behind as the devices will |
||
454 | * be handled by the bridge driver itself. |
||
455 | * |
||
456 | * We need to process bridges in two passes -- first we scan those |
||
457 | * already configured by the BIOS and after we are done with all of |
||
458 | * them, we proceed to assigning numbers to the remaining buses in |
||
459 | * order to avoid overlaps between old and new bus numbers. |
||
460 | */ |
||
461 | int pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max, int pass) |
||
462 | { |
||
463 | struct pci_bus *child; |
||
464 | int is_cardbus = (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS); |
||
465 | u32 buses, i, j = 0; |
||
466 | u16 bctl; |
||
467 | u8 primary, secondary, subordinate; |
||
468 | int broken = 0; |
||
469 | |||
470 | |||
471 | primary = buses & 0xFF; |
||
472 | secondary = (buses >> 8) & 0xFF; |
||
473 | subordinate = (buses >> 16) & 0xFF; |
||
474 | |||
475 | |||
476 | secondary, subordinate, pass); |
||
477 | |||
478 | |||
479 | if (!pass && |
||
480 | (primary != bus->number || secondary <= bus->number)) { |
||
481 | dbgprintf("bus configuration invalid, reconfiguring\n"); |
||
482 | broken = 1; |
||
483 | } |
||
484 | |||
485 | |||
486 | of bus errors (in some architectures) */ |
||
487 | pci_read_config_word(dev, PCI_BRIDGE_CONTROL, &bctl); |
||
488 | pci_write_config_word(dev, PCI_BRIDGE_CONTROL, |
||
489 | bctl & ~PCI_BRIDGE_CTL_MASTER_ABORT); |
||
490 | |||
491 | |||
492 | !is_cardbus && !broken) { |
||
493 | unsigned int cmax; |
||
494 | /* |
||
495 | * Bus already configured by firmware, process it in the first |
||
496 | * pass and just note the configuration. |
||
497 | */ |
||
498 | if (pass) |
||
499 | goto out; |
||
500 | |||
501 | |||
502 | * If we already got to this bus through a different bridge, |
||
503 | * don't re-add it. This can happen with the i450NX chipset. |
||
504 | * |
||
505 | * However, we continue to descend down the hierarchy and |
||
506 | * scan remaining child buses. |
||
507 | */ |
||
508 | child = pci_find_bus(pci_domain_nr(bus), secondary); |
||
509 | if (!child) { |
||
510 | child = pci_add_new_bus(bus, dev, secondary); |
||
511 | if (!child) |
||
512 | goto out; |
||
513 | child->primary = primary; |
||
514 | child->subordinate = subordinate; |
||
515 | child->bridge_ctl = bctl; |
||
516 | } |
||
517 | |||
518 | |||
519 | if (cmax > max) |
||
520 | max = cmax; |
||
521 | if (child->subordinate > max) |
||
522 | max = child->subordinate; |
||
523 | } else { |
||
524 | /* |
||
525 | * We need to assign a number to this bus which we always |
||
526 | * do in the second pass. |
||
527 | */ |
||
528 | if (!pass) { |
||
529 | if (pcibios_assign_all_busses() || broken) |
||
530 | /* Temporarily disable forwarding of the |
||
531 | configuration cycles on all bridges in |
||
532 | this bus segment to avoid possible |
||
533 | conflicts in the second pass between two |
||
534 | bridges programmed with overlapping |
||
535 | bus ranges. */ |
||
536 | pci_write_config_dword(dev, PCI_PRIMARY_BUS, |
||
537 | buses & ~0xffffff); |
||
538 | goto out; |
||
539 | } |
||
540 | |||
541 | |||
542 | pci_write_config_word(dev, PCI_STATUS, 0xffff); |
||
543 | |||
544 | |||
545 | * This can happen when a bridge is hot-plugged */ |
||
546 | if (pci_find_bus(pci_domain_nr(bus), max+1)) |
||
547 | goto out; |
||
548 | child = pci_add_new_bus(bus, dev, ++max); |
||
549 | buses = (buses & 0xff000000) |
||
550 | | ((unsigned int)(child->primary) << 0) |
||
551 | | ((unsigned int)(child->secondary) << 8) |
||
552 | | ((unsigned int)(child->subordinate) << 16); |
||
553 | |||
554 | |||
555 | * yenta.c forces a secondary latency timer of 176. |
||
556 | * Copy that behaviour here. |
||
557 | */ |
||
558 | if (is_cardbus) { |
||
559 | buses &= ~0xff000000; |
||
560 | buses |= CARDBUS_LATENCY_TIMER << 24; |
||
561 | } |
||
562 | |||
563 | |||
564 | * We need to blast all three values with a single write. |
||
565 | */ |
||
566 | pci_write_config_dword(dev, PCI_PRIMARY_BUS, buses); |
||
567 | |||
568 | |||
569 | child->bridge_ctl = bctl; |
||
570 | /* |
||
571 | * Adjust subordinate busnr in parent buses. |
||
572 | * We do this before scanning for children because |
||
573 | * some devices may not be detected if the bios |
||
574 | * was lazy. |
||
575 | */ |
||
576 | pci_fixup_parent_subordinate_busnr(child, max); |
||
577 | /* Now we can scan all subordinate buses... */ |
||
578 | max = pci_scan_child_bus(child); |
||
579 | /* |
||
580 | * now fix it up again since we have found |
||
581 | * the real value of max. |
||
582 | */ |
||
583 | pci_fixup_parent_subordinate_busnr(child, max); |
||
584 | } else { |
||
585 | /* |
||
586 | * For CardBus bridges, we leave 4 bus numbers |
||
587 | * as cards with a PCI-to-PCI bridge can be |
||
588 | * inserted later. |
||
589 | */ |
||
590 | for (i=0; i |
||
591 | struct pci_bus *parent = bus; |
||
592 | if (pci_find_bus(pci_domain_nr(bus), |
||
593 | max+i+1)) |
||
594 | break; |
||
595 | while (parent->parent) { |
||
596 | if ((!pcibios_assign_all_busses()) && |
||
597 | (parent->subordinate > max) && |
||
598 | (parent->subordinate <= max+i)) { |
||
599 | j = 1; |
||
600 | } |
||
601 | parent = parent->parent; |
||
602 | } |
||
603 | if (j) { |
||
604 | /* |
||
605 | * Often, there are two cardbus bridges |
||
606 | * -- try to leave one valid bus number |
||
607 | * for each one. |
||
608 | */ |
||
609 | i /= 2; |
||
610 | break; |
||
611 | } |
||
612 | } |
||
613 | max += i; |
||
614 | pci_fixup_parent_subordinate_busnr(child, max); |
||
615 | } |
||
616 | /* |
||
617 | * Set the subordinate bus number to its real value. |
||
618 | */ |
||
619 | child->subordinate = max; |
||
620 | pci_write_config_byte(dev, PCI_SUBORDINATE_BUS, max); |
||
621 | } |
||
622 | |||
623 | |||
9499 | turbocat | 624 | (is_cardbus ? "PCI CardBus %04x:%02x" : "PCI Bus %04x:%02x"), |
1631 | serge | 625 | pci_domain_nr(bus), child->number); |
626 | |||
627 | |||
628 | while (bus->parent) { |
||
629 | if ((child->subordinate > bus->subordinate) || |
||
630 | (child->number > bus->subordinate) || |
||
631 | (child->number < bus->number) || |
||
632 | (child->subordinate < bus->number)) { |
||
633 | dbgprintf("[bus %02x-%02x] %s " |
||
634 | "hidden behind%s bridge %s [bus %02x-%02x]\n", |
||
635 | child->number, child->subordinate, |
||
636 | (bus->number > child->subordinate && |
||
637 | bus->subordinate < child->number) ? |
||
638 | "wholly" : "partially", |
||
639 | bus->self->transparent ? " transparent" : "", |
||
640 | "FIX BRIDGE NAME", |
||
641 | bus->number, bus->subordinate); |
||
642 | } |
||
643 | bus = bus->parent; |
||
644 | } |
||
645 | |||
646 | |||
647 | pci_write_config_word(dev, PCI_BRIDGE_CONTROL, bctl); |
||
648 | |||
649 | |||
650 | } |
||
651 | |||
652 | |||
653 | { |
||
654 | int pos; |
||
655 | u16 reg16; |
||
656 | |||
657 | |||
658 | if (!pos) |
||
659 | return; |
||
660 | //pdev->is_pcie = 1; |
||
9499 | turbocat | 661 | pdev->pcie_cap = pos; |
1631 | serge | 662 | pci_read_config_word(pdev, pos + PCI_EXP_FLAGS, ®16); |
663 | pdev->pcie_type = (reg16 & PCI_EXP_FLAGS_TYPE) >> 4; |
||
664 | } |
||
665 | |||
666 | |||
667 | { |
||
668 | int pos; |
||
669 | u16 reg16; |
||
670 | u32 reg32; |
||
671 | |||
672 | |||
673 | if (!pos) |
||
674 | return; |
||
675 | pci_read_config_word(pdev, pos + PCI_EXP_FLAGS, ®16); |
||
676 | if (!(reg16 & PCI_EXP_FLAGS_SLOT)) |
||
677 | return; |
||
678 | pci_read_config_dword(pdev, pos + PCI_EXP_SLTCAP, ®32); |
||
679 | if (reg32 & PCI_EXP_SLTCAP_HPC) |
||
680 | pdev->is_hotplug_bridge = 1; |
||
681 | } |
||
682 | |||
683 | |||
684 | * Read interrupt line and base address registers. |
||
685 | * The architecture-dependent code can tweak these, of course. |
||
686 | */ |
||
687 | static void pci_read_irq(struct pci_dev *dev) |
||
688 | { |
||
689 | unsigned char irq; |
||
690 | |||
691 | |||
692 | dev->pin = irq; |
||
693 | if (irq) |
||
694 | pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &irq); |
||
695 | dev->irq = irq; |
||
696 | } |
||
697 | |||
698 | |||
699 | |||
700 | * pci_setup_device - fill in class and map information of a device |
||
1628 | serge | 701 | * @dev: the device structure to fill |
702 | * |
||
703 | * Initialize the device structure with information about the device's |
||
704 | * vendor,class,memory and IO-space addresses,IRQ lines etc. |
||
705 | * Called at initialisation of the PCI subsystem and by CardBus services. |
||
706 | * Returns 0 on success and negative if unknown type of device (not normal, |
||
707 | * bridge or CardBus). |
||
708 | */ |
||
709 | int pci_setup_device(struct pci_dev *dev) |
||
710 | { |
||
711 | u32 class; |
||
712 | u8 hdr_type; |
||
713 | struct pci_slot *slot; |
||
714 | int pos = 0; |
||
715 | |||
716 | |||
717 | return -EIO; |
||
718 | |||
719 | |||
720 | // dev->dev.parent = dev->bus->bridge; |
||
721 | // dev->dev.bus = &pci_bus_type; |
||
722 | dev->hdr_type = hdr_type & 0x7f; |
||
723 | dev->multifunction = !!(hdr_type & 0x80); |
||
724 | dev->error_state = pci_channel_io_normal; |
||
725 | set_pcie_port_type(dev); |
||
726 | |||
727 | |||
728 | if (PCI_SLOT(dev->devfn) == slot->number) |
||
729 | dev->slot = slot; |
||
730 | |||
731 | |||
732 | set this higher, assuming the system even supports it. */ |
||
733 | dev->dma_mask = 0xffffffff; |
||
734 | |||
735 | |||
736 | // dev->bus->number, PCI_SLOT(dev->devfn), |
||
737 | // PCI_FUNC(dev->devfn)); |
||
738 | |||
739 | |||
740 | dev->revision = class & 0xff; |
||
741 | class >>= 8; /* upper 3 bytes */ |
||
742 | dev->class = class; |
||
743 | class >>= 8; |
||
744 | |||
745 | |||
746 | dev->vendor, dev->device, class, dev->hdr_type); |
||
747 | |||
748 | |||
749 | dev->cfg_size = pci_cfg_space_size(dev); |
||
750 | |||
751 | |||
752 | dev->current_state = PCI_UNKNOWN; |
||
753 | |||
754 | |||
755 | // pci_fixup_device(pci_fixup_early, dev); |
||
756 | /* device class may be changed after fixup */ |
||
757 | class = dev->class >> 8; |
||
758 | |||
759 | |||
760 | case PCI_HEADER_TYPE_NORMAL: /* standard header */ |
||
761 | if (class == PCI_CLASS_BRIDGE_PCI) |
||
762 | goto bad; |
||
763 | pci_read_irq(dev); |
||
764 | pci_read_bases(dev, 6, PCI_ROM_ADDRESS); |
||
765 | pci_read_config_word(dev, PCI_SUBSYSTEM_VENDOR_ID, &dev->subsystem_vendor); |
||
766 | pci_read_config_word(dev, PCI_SUBSYSTEM_ID, &dev->subsystem_device); |
||
767 | |||
768 | |||
769 | * Do the ugly legacy mode stuff here rather than broken chip |
||
770 | * quirk code. Legacy mode ATA controllers have fixed |
||
771 | * addresses. These are not always echoed in BAR0-3, and |
||
772 | * BAR0-3 in a few cases contain junk! |
||
773 | */ |
||
774 | if (class == PCI_CLASS_STORAGE_IDE) { |
||
775 | u8 progif; |
||
776 | pci_read_config_byte(dev, PCI_CLASS_PROG, &progif); |
||
777 | if ((progif & 1) == 0) { |
||
778 | dev->resource[0].start = 0x1F0; |
||
779 | dev->resource[0].end = 0x1F7; |
||
780 | dev->resource[0].flags = LEGACY_IO_RESOURCE; |
||
781 | dev->resource[1].start = 0x3F6; |
||
782 | dev->resource[1].end = 0x3F6; |
||
783 | dev->resource[1].flags = LEGACY_IO_RESOURCE; |
||
784 | } |
||
785 | if ((progif & 4) == 0) { |
||
786 | dev->resource[2].start = 0x170; |
||
787 | dev->resource[2].end = 0x177; |
||
788 | dev->resource[2].flags = LEGACY_IO_RESOURCE; |
||
789 | dev->resource[3].start = 0x376; |
||
790 | dev->resource[3].end = 0x376; |
||
791 | dev->resource[3].flags = LEGACY_IO_RESOURCE; |
||
792 | } |
||
793 | } |
||
794 | break; |
||
795 | |||
796 | |||
797 | if (class != PCI_CLASS_BRIDGE_PCI) |
||
798 | goto bad; |
||
799 | /* The PCI-to-PCI bridge spec requires that subtractive |
||
800 | decoding (i.e. transparent) bridge must have programming |
||
801 | interface code of 0x01. */ |
||
802 | pci_read_irq(dev); |
||
803 | dev->transparent = ((dev->class & 0xff) == 1); |
||
804 | pci_read_bases(dev, 2, PCI_ROM_ADDRESS1); |
||
805 | set_pcie_hotplug_bridge(dev); |
||
806 | pos = pci_find_capability(dev, PCI_CAP_ID_SSVID); |
||
807 | if (pos) { |
||
808 | pci_read_config_word(dev, pos + PCI_SSVID_VENDOR_ID, &dev->subsystem_vendor); |
||
809 | pci_read_config_word(dev, pos + PCI_SSVID_DEVICE_ID, &dev->subsystem_device); |
||
810 | } |
||
811 | break; |
||
812 | |||
813 | |||
814 | if (class != PCI_CLASS_BRIDGE_CARDBUS) |
||
815 | goto bad; |
||
816 | pci_read_irq(dev); |
||
817 | pci_read_bases(dev, 1, 0); |
||
818 | pci_read_config_word(dev, PCI_CB_SUBSYSTEM_VENDOR_ID, &dev->subsystem_vendor); |
||
819 | pci_read_config_word(dev, PCI_CB_SUBSYSTEM_ID, &dev->subsystem_device); |
||
820 | break; |
||
821 | |||
822 | |||
823 | dbgprintf("unknown header type %02x, " |
||
824 | "ignoring device\n", dev->hdr_type); |
||
825 | return -EIO; |
||
826 | |||
827 | |||
828 | dbgprintf("ignoring class %02x (doesn't match header " |
||
829 | "type %02x)\n", class, dev->hdr_type); |
||
830 | dev->class = PCI_CLASS_NOT_DEFINED; |
||
831 | } |
||
832 | |||
833 | |||
834 | return 0; |
||
835 | } |
||
836 | |||
837 | |||
838 | |||
839 | |||
840 | { |
||
841 | struct pci_dev *dev; |
||
842 | |||
843 | |||
844 | if (!dev) |
||
845 | return NULL; |
||
846 | |||
847 | |||
848 | |||
849 | |||
850 | } |
||
851 | |||
852 | |||
853 | * Read the config data for a PCI device, sanity-check it |
||
854 | * and fill in the dev structure... |
||
855 | */ |
||
856 | static struct pci_dev *pci_scan_device(struct pci_bus *bus, int devfn) |
||
857 | { |
||
858 | struct pci_dev *dev; |
||
859 | u32 l; |
||
860 | int timeout = 10; |
||
861 | |||
862 | |||
863 | return NULL; |
||
864 | |||
865 | |||
866 | if (l == 0xffffffff || l == 0x00000000 || |
||
867 | l == 0x0000ffff || l == 0xffff0000) |
||
1633 | serge | 868 | return NULL; |
1628 | serge | 869 | |
870 | |||
871 | while (l == 0xffff0001) { |
||
872 | delay(timeout/10); |
||
873 | timeout *= 2; |
||
874 | if (pci_bus_read_config_dword(bus, devfn, PCI_VENDOR_ID, &l)) |
||
875 | return NULL; |
||
876 | /* Card hasn't responded in 60 seconds? Must be stuck. */ |
||
877 | if (timeout > 60 * 1000) { |
||
1631 | serge | 878 | printk(KERN_WARNING "pci %04x:%02x:%02x.%d: not " |
1628 | serge | 879 | "responding\n", pci_domain_nr(bus), |
880 | bus->number, PCI_SLOT(devfn), |
||
881 | PCI_FUNC(devfn)); |
||
882 | return NULL; |
||
883 | } |
||
884 | } |
||
885 | |||
886 | |||
887 | if (!dev) |
||
888 | return NULL; |
||
889 | |||
890 | |||
891 | dev->busnr = bus->number; |
||
1867 | serge | 892 | dev->devfn = devfn; |
1628 | serge | 893 | dev->vendor = l & 0xffff; |
894 | dev->device = (l >> 16) & 0xffff; |
||
895 | |||
896 | |||
897 | kfree(dev); |
||
898 | return NULL; |
||
899 | } |
||
900 | |||
901 | |||
902 | } |
||
903 | |||
904 | |||
1631 | serge | 905 | { |
906 | // device_initialize(&dev->dev); |
||
907 | // dev->dev.release = pci_release_dev; |
||
908 | // pci_dev_get(dev); |
||
909 | |||
1628 | serge | 910 | |
1631 | serge | 911 | // dev->dev.dma_parms = &dev->dma_parms; |
912 | // dev->dev.coherent_dma_mask = 0xffffffffull; |
||
913 | |||
914 | |||
915 | // pci_set_dma_seg_boundary(dev, 0xffffffff); |
||
916 | |||
917 | |||
918 | // pci_fixup_device(pci_fixup_header, dev); |
||
919 | |||
920 | |||
921 | dev->state_saved = false; |
||
922 | |||
923 | |||
924 | // pci_init_capabilities(dev); |
||
925 | |||
926 | |||
927 | * Add the device to our list of discovered devices |
||
928 | * and the bus list for fixup functions, etc. |
||
929 | */ |
||
930 | // down_write(&pci_bus_sem); |
||
931 | list_add_tail(&dev->bus_list, &bus->devices); |
||
932 | // up_write(&pci_bus_sem); |
||
933 | } |
||
934 | |||
935 | |||
1628 | serge | 936 | { |
937 | struct pci_dev *dev; |
||
938 | |||
939 | |||
940 | if (dev) { |
||
941 | // pci_dev_put(dev); |
||
942 | return dev; |
||
943 | } |
||
944 | |||
945 | |||
946 | if (!dev) |
||
947 | return NULL; |
||
948 | |||
949 | |||
950 | |||
951 | |||
952 | } |
||
953 | |||
954 | |||
955 | { |
||
956 | u16 cap; |
||
957 | unsigned pos, next_fn; |
||
958 | |||
959 | |||
960 | return 0; |
||
961 | |||
962 | |||
963 | if (!pos) |
||
964 | return 0; |
||
965 | pci_read_config_word(dev, pos + 4, &cap); |
||
966 | next_fn = cap >> 8; |
||
967 | if (next_fn <= fn) |
||
968 | return 0; |
||
969 | return next_fn; |
||
970 | } |
||
971 | |||
972 | |||
973 | { |
||
974 | return (fn + 1) % 8; |
||
975 | } |
||
976 | |||
977 | |||
978 | { |
||
979 | return 0; |
||
980 | } |
||
981 | |||
982 | |||
983 | { |
||
984 | struct pci_dev *parent = bus->self; |
||
985 | if (!parent || !pci_is_pcie(parent)) |
||
986 | return 0; |
||
987 | if (parent->pcie_type == PCI_EXP_TYPE_ROOT_PORT || |
||
988 | parent->pcie_type == PCI_EXP_TYPE_DOWNSTREAM) |
||
989 | return 1; |
||
990 | return 0; |
||
991 | } |
||
992 | |||
993 | |||
994 | * pci_scan_slot - scan a PCI slot on a bus for devices. |
||
995 | * @bus: PCI bus to scan |
||
996 | * @devfn: slot number to scan (must have zero function.) |
||
997 | * |
||
998 | * Scan a PCI slot on the specified PCI bus for devices, adding |
||
999 | * discovered devices to the @bus->devices list. New devices |
||
1000 | * will not have is_added set. |
||
1001 | * |
||
1002 | * Returns the number of new devices found. |
||
1003 | */ |
||
1004 | int pci_scan_slot(struct pci_bus *bus, int devfn) |
||
1005 | { |
||
1006 | unsigned fn, nr = 0; |
||
1007 | struct pci_dev *dev; |
||
1008 | unsigned (*next_fn)(struct pci_dev *, unsigned) = no_next_fn; |
||
1009 | |||
1010 | |||
1011 | return 0; /* Already scanned the entire slot */ |
||
1012 | |||
1013 | |||
1014 | if (!dev) |
||
1015 | return 0; |
||
1016 | if (!dev->is_added) |
||
1017 | nr++; |
||
1018 | |||
1019 | |||
1020 | next_fn = next_ari_fn; |
||
1021 | else if (dev->multifunction) |
||
1022 | next_fn = next_trad_fn; |
||
1023 | |||
1024 | |||
1025 | dev = pci_scan_single_device(bus, devfn + fn); |
||
1026 | if (dev) { |
||
1027 | if (!dev->is_added) |
||
1028 | nr++; |
||
1029 | dev->multifunction = 1; |
||
1030 | } |
||
1031 | } |
||
1032 | |||
1033 | |||
1034 | // if (bus->self && nr) |
||
1631 | serge | 1035 | // pcie_aspm_init_link_state(bus->self); |
1036 | |||
1628 | serge | 1037 | |
1038 | } |
||
1039 | |||
1040 | |||
1041 | |||
1042 | { |
||
1043 | unsigned int devfn, pass, max = bus->secondary; |
||
1044 | struct pci_dev *dev; |
||
1045 | |||
1046 | |||
1047 | |||
1048 | |||
1049 | for (devfn = 0; devfn < 0x100; devfn += 8) |
||
1050 | pci_scan_slot(bus, devfn); |
||
1051 | |||
1052 | |||
1053 | //max += pci_iov_bus_range(bus); |
||
9499 | turbocat | 1054 | |
1628 | serge | 1055 | |
1056 | * After performing arch-dependent fixup of the bus, look behind |
||
1057 | * all PCI-to-PCI bridges on this bus. |
||
1058 | */ |
||
1059 | if (!bus->is_added) { |
||
1060 | dbgprintf("fixups for bus\n"); |
||
1061 | // pcibios_fixup_bus(bus); |
||
1631 | serge | 1062 | if (pci_is_root_bus(bus)) |
1628 | serge | 1063 | bus->is_added = 1; |
1064 | } |
||
1065 | |||
1066 | |||
1067 | list_for_each_entry(dev, &bus->devices, bus_list) { |
||
1068 | if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE || |
||
1069 | dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) |
||
1070 | max = pci_scan_bridge(bus, dev, max, pass); |
||
1071 | } |
||
1072 | |||
1073 | |||
1074 | * We've scanned the bus and so we know all about what's on |
||
1075 | * the other side of any bridges that may be on this bus plus |
||
1076 | * any devices. |
||
1077 | * |
||
1078 | * Return how far we've got finding sub-buses. |
||
1079 | */ |
||
1080 | dbgprintf("bus scan returning with max=%02x\n", max); |
||
1081 | return max; |
||
1082 | } |
||
1083 | |||
1084 | |||
1085 | * pci_cfg_space_size - get the configuration space size of the PCI device. |
||
1086 | * @dev: PCI device |
||
1087 | * |
||
1088 | * Regular PCI devices have 256 bytes, but PCI-X 2 and PCI Express devices |
||
1089 | * have 4096 bytes. Even if the device is capable, that doesn't mean we can |
||
1090 | * access it. Maybe we don't have a way to generate extended config space |
||
1091 | * accesses, or the device is behind a reverse Express bridge. So we try |
||
1092 | * reading the dword at 0x100 which must either be 0 or a valid extended |
||
1093 | * capability header. |
||
1094 | */ |
||
1095 | int pci_cfg_space_size_ext(struct pci_dev *dev) |
||
1096 | { |
||
1097 | u32 status; |
||
1098 | int pos = PCI_CFG_SPACE_SIZE; |
||
1099 | |||
1100 | |||
1101 | goto fail; |
||
1102 | if (status == 0xffffffff) |
||
1103 | goto fail; |
||
1104 | |||
1105 | |||
1106 | |||
1107 | |||
1108 | return PCI_CFG_SPACE_SIZE; |
||
1109 | } |
||
1110 | |||
1111 | |||
1112 | { |
||
1113 | int pos; |
||
1114 | u32 status; |
||
1115 | u16 class; |
||
1116 | |||
1117 | |||
1118 | if (class == PCI_CLASS_BRIDGE_HOST) |
||
1119 | return pci_cfg_space_size_ext(dev); |
||
1120 | |||
1121 | |||
1122 | if (!pos) { |
||
1123 | pos = pci_find_capability(dev, PCI_CAP_ID_PCIX); |
||
1124 | if (!pos) |
||
1125 | goto fail; |
||
1126 | |||
1127 | |||
1128 | if (!(status & (PCI_X_STATUS_266MHZ | PCI_X_STATUS_533MHZ))) |
||
1129 | goto fail; |
||
1130 | } |
||
1131 | |||
1132 | |||
1133 | |||
1134 | |||
1135 | return PCI_CFG_SPACE_SIZE; |
||
1136 | } |
||
1137 | |||
1138 | |||
1139 | |||
1631 | serge | 1140 | |
1141 | { |
||
1142 | int error; |
||
1143 | struct pci_bus *b, *b2; |
||
1144 | |||
1145 | |||
1146 | if (!b) |
||
1147 | return NULL; |
||
1148 | |||
1149 | |||
1150 | b->ops = ops; |
||
1151 | |||
1152 | |||
1153 | if (b2) { |
||
1154 | /* If we already got to this bus through a different bridge, ignore it */ |
||
1155 | dbgprintf("bus already known\n"); |
||
1156 | goto err_out; |
||
1157 | } |
||
1158 | |||
1159 | |||
1160 | list_add_tail(&b->node, &pci_root_buses); |
||
1161 | // up_write(&pci_bus_sem); |
||
1162 | |||
1163 | |||
1164 | b->resource[0] = &ioport_resource; |
||
1165 | b->resource[1] = &iomem_resource; |
||
1166 | |||
1167 | |||
1168 | |||
1169 | |||
1170 | kfree(b); |
||
1171 | return NULL; |
||
1172 | }>>=>>>>=>><>><>><>><>=>>>>><>>>>><>><>><> |
||
1173 |