Deleted Added
sdiff udiff text old ( 121307 ) new ( 124365 )
full compact
1/*-
2 * Copyright (c) 1994,1995 Stefan Esser, Wolfgang StanglMeier
3 * Copyright (c) 2000 Michael Smith <msmith@freebsd.org>
4 * Copyright (c) 2000 BSDi
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 15 unchanged lines hidden (view full) ---

24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31#include <sys/cdefs.h>
32__FBSDID("$FreeBSD: head/sys/dev/pci/pci_pci.c 121307 2003-10-21 18:28:36Z silby $");
33
34/*
35 * PCI:PCI bridge support.
36 */
37
38#include <sys/param.h>
39#include <sys/systm.h>
40#include <sys/kernel.h>

--- 46 unchanged lines hidden (view full) ---

87 sizeof(struct pcib_softc),
88};
89
90devclass_t pcib_devclass;
91
92DRIVER_MODULE(pcib, pci, pcib_driver, pcib_devclass, 0, 0);
93
94/*
95 * sysctl and tunable vars
96 */
97static int pci_allow_unsupported_io_range = 0;
98TUNABLE_INT("hw.pci.allow_unsupported_io_range",
99 (int *)&pci_allow_unsupported_io_range);
100SYSCTL_DECL(_hw_pci);
101SYSCTL_INT(_hw_pci, OID_AUTO, allow_unsupported_io_range, CTLFLAG_RDTUN,
102 &pci_allow_unsupported_io_range, 0,
103 "Allows the PCI Bridge to pass through an unsupported memory range "
104 "assigned by the BIOS.");
105
106/*
107 * Generic device interface
108 */
109static int
110pcib_probe(device_t dev)
111{
112 if ((pci_get_class(dev) == PCIC_BRIDGE) &&
113 (pci_get_subclass(dev) == PCIS_BRIDGE_PCI)) {
114 device_set_desc(dev, "PCI-PCI bridge");

--- 53 unchanged lines hidden (view full) ---

168 sc->pmemlimit = PCI_PPBMEMLIMIT((pci_addr_t)pci_read_config(dev, PCIR_PMLIMITH_1, 4),
169 pci_read_config(dev, PCIR_PMLIMITL_1, 2));
170 }
171
172 /*
173 * Quirk handling.
174 */
175 switch (pci_get_devid(dev)) {
176 case 0x12258086: /* Intel 82454KX/GX (Orion) */
177 {
178 uint8_t supbus;
179
180 supbus = pci_read_config(dev, 0x41, 1);
181 if (supbus != 0xff) {
182 sc->secbus = supbus + 1;
183 sc->subbus = supbus + 1;
184 }
185 }
186 break;
187 }
188
189 if (bootverbose) {
190 device_printf(dev, " secondary bus %d\n", sc->secbus);
191 device_printf(dev, " subordinate bus %d\n", sc->subbus);
192 device_printf(dev, " I/O decode 0x%x-0x%x\n", sc->iobase, sc->iolimit);
193 device_printf(dev, " memory decode 0x%x-0x%x\n", sc->membase, sc->memlimit);
194 device_printf(dev, " prefetched decode 0x%x-0x%x\n", sc->pmembase, sc->pmemlimit);
195 }
196
197 /*
198 * XXX If the secondary bus number is zero, we should assign a bus number
199 * since the BIOS hasn't, then initialise the bridge.
200 */
201
202 /*

--- 44 unchanged lines hidden (view full) ---

247 case PCIB_IVAR_BUS:
248 sc->secbus = value;
249 break;
250 }
251 return(ENOENT);
252}
253
254/*
255 * Is this a decoded ISA I/O port address? Note, we need to do the mask that
256 * we do below because of the ISA alias addresses. I'm not 100% sure that
257 * this is correct. Maybe the bridge needs to be subtractive decode for
258 * this to work?
259 */
260static int
261pcib_is_isa_io(u_long start)
262{
263 if ((start & 0xfffUL) > 0x3ffUL || start == 0)
264 return (0);
265 return (1);
266}
267
268/*
269 * Is this a decoded ISA memory address?
270 */
271static int
272pcib_is_isa_mem(u_long start)
273{
274 if (start > 0xfffffUL || start == 0)
275 return (0);
276 return (1);
277}
278
279/*
280 * Is the prefetch window open (eg, can we allocate memory in it?)
281 */
282static int
283pcib_is_prefetch_open(struct pcib_softc *sc)
284{
285 return (sc->pmembase > 0 && sc->pmembase < sc->pmemlimit);
286}
287
288/*
289 * Is the nonprefetch window open (eg, can we allocate memory in it?)
290 */
291static int
292pcib_is_nonprefetch_open(struct pcib_softc *sc)
293{
294 return (sc->membase > 0 && sc->membase < sc->memlimit);
295}
296
297/*
298 * Is the io window open (eg, can we allocate ports in it?)
299 */
300static int
301pcib_is_io_open(struct pcib_softc *sc)
302{
303 return (sc->iobase > 0 && sc->iobase < sc->iolimit);
304}
305
306/*
307 * We have to trap resource allocation requests and ensure that the bridge
308 * is set up to, or capable of handling them.
309 */
310struct resource *
311pcib_alloc_resource(device_t dev, device_t child, int type, int *rid,
312 u_long start, u_long end, u_long count, u_int flags)
313{
314 struct pcib_softc *sc = device_get_softc(dev);
315 int ok;
316
317 /*
318 * If this is a "default" allocation against this rid, we can't work
319 * out where it's coming from (we should actually never see these) so we
320 * just have to punt.
321 */
322 if ((start == 0) && (end == ~0)) {
323 device_printf(dev, "can't decode default resource id %d for %s%d, bypassing\n",
324 *rid, device_get_name(child), device_get_unit(child));
325 } else {
326 /*
327 * Fail the allocation for this range if it's not supported.
328 */
329 switch (type) {
330 case SYS_RES_IOPORT:
331 ok = 1;
332 if (!pcib_is_isa_io(start)) {
333 ok = 0;
334 if (pcib_is_io_open(sc))
335 ok = (start >= sc->iobase && end <= sc->iolimit);
336 if (!pci_allow_unsupported_io_range) {
337 if (!ok) {
338 if (start < sc->iobase)
339 start = sc->iobase;
340 if (end > sc->iolimit)
341 end = sc->iolimit;
342 }
343 } else {
344 if (start < sc->iobase)
345 printf("start (%lx) < sc->iobase (%x)\n", start,
346 sc->iobase);
347 if (end > sc->iolimit)
348 printf("end (%lx) > sc->iolimit (%x)\n",
349 end, sc->iolimit);
350 if (end < start)
351 printf("end (%lx) < start (%lx)\n", end, start);
352 }
353 }
354 if (end < start) {
355 start = 0;
356 end = 0;
357 ok = 0;
358 }
359 if (!ok) {
360 device_printf(dev, "device %s%d requested unsupported I/O "
361 "range 0x%lx-0x%lx (decoding 0x%x-0x%x)\n",
362 device_get_name(child), device_get_unit(child), start, end,
363 sc->iobase, sc->iolimit);
364 return (NULL);
365 }
366 if (bootverbose)
367 device_printf(sc->dev, "device %s%d requested decoded I/O range 0x%lx-0x%lx\n",
368 device_get_name(child), device_get_unit(child), start, end);
369 break;
370
371 case SYS_RES_MEMORY:
372 ok = 1;
373 if (!pcib_is_isa_mem(start)) {
374 ok = 0;
375 if (pcib_is_nonprefetch_open(sc))
376 ok = ok || (start >= sc->membase && end <= sc->memlimit);
377 if (pcib_is_prefetch_open(sc))
378 ok = ok || (start >= sc->pmembase && end <= sc->pmemlimit);
379 if (!pci_allow_unsupported_io_range) {
380 if (!ok) {
381 ok = 1;
382 if (flags & RF_PREFETCHABLE) {
383 if (pcib_is_prefetch_open(sc)) {
384 if (start < sc->pmembase)
385 start = sc->pmembase;
386 if (end > sc->pmemlimit)
387 end = sc->pmemlimit;
388 } else {
389 ok = 0;
390 }
391 } else { /* non-prefetchable */
392 if (pcib_is_nonprefetch_open(sc)) {
393 if (start < sc->membase)
394 start = sc->membase;
395 if (end > sc->memlimit)
396 end = sc->memlimit;
397 } else {
398 ok = 0;
399 }
400 }
401 }
402 } else if (!ok) {
403 ok = 1; /* pci_allow_unsupported_ranges -> always ok */
404 if (pcib_is_nonprefetch_open(sc)) {
405 if (start < sc->membase)
406 printf("start (%lx) < sc->membase (%x)\n",
407 start, sc->membase);
408 if (end > sc->memlimit)
409 printf("end (%lx) > sc->memlimit (%x)\n",
410 end, sc->memlimit);
411 }
412 if (pcib_is_prefetch_open(sc)) {
413 if (start < sc->pmembase)
414 printf("start (%lx) < sc->pmembase (%x)\n",
415 start, sc->pmembase);
416 if (end > sc->pmemlimit)
417 printf("end (%lx) > sc->pmemlimit (%x)\n",
418 end, sc->memlimit);
419 }
420 if (end < start)
421 printf("end (%lx) < start (%lx)\n", end, start);
422 }
423 }
424 if (end < start) {
425 start = 0;
426 end = 0;
427 ok = 0;
428 }
429 if (!ok && bootverbose)
430 device_printf(dev,
431 "device %s%d requested unsupported memory range "
432 "0x%lx-0x%lx (decoding 0x%x-0x%x, 0x%x-0x%x)\n",
433 device_get_name(child), device_get_unit(child), start,
434 end, sc->membase, sc->memlimit, sc->pmembase,
435 sc->pmemlimit);
436 if (!ok)
437 return (NULL);
438 if (bootverbose)
439 device_printf(sc->dev, "device %s%d requested decoded memory range 0x%lx-0x%lx\n",
440 device_get_name(child), device_get_unit(child), start, end);
441 break;
442
443 default:
444 break;
445 }
446 }
447
448 /*
449 * Bridge is OK decoding this resource, so pass it up.
450 */
451 return(bus_generic_alloc_resource(dev, child, type, rid, start, end, count, flags));
452}
453
454/*
455 * PCIB interface.
456 */
457int
458pcib_maxslots(device_t dev)
459{

--- 134 unchanged lines hidden ---