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 124365 2004-01-11 06:52:31Z imp $"); |
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 * Generic device interface 96 */ 97static int 98pcib_probe(device_t dev) 99{ 100 if ((pci_get_class(dev) == PCIC_BRIDGE) && 101 (pci_get_subclass(dev) == PCIS_BRIDGE_PCI)) { 102 device_set_desc(dev, "PCI-PCI bridge"); --- 53 unchanged lines hidden (view full) --- 156 sc->pmemlimit = PCI_PPBMEMLIMIT((pci_addr_t)pci_read_config(dev, PCIR_PMLIMITH_1, 4), 157 pci_read_config(dev, PCIR_PMLIMITL_1, 2)); 158 } 159 160 /* 161 * Quirk handling. 162 */ 163 switch (pci_get_devid(dev)) { |
164 case 0x12258086: /* Intel 82454KX/GX (Orion) */ |
165 { 166 uint8_t supbus; 167 168 supbus = pci_read_config(dev, 0x41, 1); 169 if (supbus != 0xff) { 170 sc->secbus = supbus + 1; 171 sc->subbus = supbus + 1; 172 } |
173 break; |
174 } |
175 176 /* 177 * The i82380FB mobile docking controller is a PCI-PCI bridge, 178 * and it is a subtractive bridge. However, the ProgIf is wrong 179 * so the normal setting of PCIB_SUBTRACTIVE bit doesn't 180 * happen. There's also a Toshiba bridge that behaves this 181 * way. 182 */ 183 case 0x124b8086: /* Intel 82380FB Mobile */ 184 case 0x060513d7: /* Toshiba ???? */ 185 sc->flags |= PCIB_SUBTRACTIVE; |
186 break; 187 } 188 |
189 /* 190 * Intel 815, 845 and other chipsets say they are PCI-PCI bridges, 191 * but have a ProgIF of 0x80. The 82801 family (AA, AB, BAM/CAM, 192 * BA/CA/DB and E) PCI bridges are HUB-PCI bridges, in Intelese. 193 * This means they act as if they were subtractively decoding 194 * bridges and pass all transactions. Mark them and real ProgIf 1 195 * parts as subtractive. 196 */ 197 if ((pci_get_devid(dev) & 0xff00ffff) == 0x24008086 || 198 pci_read_config(dev, PCIR_PROGIF, 1) == 1) 199 sc->flags |= PCIB_SUBTRACTIVE; 200 |
201 if (bootverbose) { 202 device_printf(dev, " secondary bus %d\n", sc->secbus); 203 device_printf(dev, " subordinate bus %d\n", sc->subbus); 204 device_printf(dev, " I/O decode 0x%x-0x%x\n", sc->iobase, sc->iolimit); 205 device_printf(dev, " memory decode 0x%x-0x%x\n", sc->membase, sc->memlimit); 206 device_printf(dev, " prefetched decode 0x%x-0x%x\n", sc->pmembase, sc->pmemlimit); |
207 if (sc->flags & PCIB_SUBTRACTIVE) 208 device_printf(dev, " Subtractively decoded bridge.\n"); |
209 } 210 211 /* 212 * XXX If the secondary bus number is zero, we should assign a bus number 213 * since the BIOS hasn't, then initialise the bridge. 214 */ 215 216 /* --- 44 unchanged lines hidden (view full) --- 261 case PCIB_IVAR_BUS: 262 sc->secbus = value; 263 break; 264 } 265 return(ENOENT); 266} 267 268/* |
269 * Is the prefetch window open (eg, can we allocate memory in it?) 270 */ 271static int 272pcib_is_prefetch_open(struct pcib_softc *sc) 273{ |
274 return (sc->pmembase > 0 && sc->pmembase < sc->pmemlimit); |
275} 276 277/* 278 * Is the nonprefetch window open (eg, can we allocate memory in it?) 279 */ 280static int 281pcib_is_nonprefetch_open(struct pcib_softc *sc) 282{ |
283 return (sc->membase > 0 && sc->membase < sc->memlimit); |
284} 285 286/* 287 * Is the io window open (eg, can we allocate ports in it?) 288 */ 289static int 290pcib_is_io_open(struct pcib_softc *sc) 291{ |
292 return (sc->iobase > 0 && sc->iobase < sc->iolimit); |
293} 294 295/* 296 * We have to trap resource allocation requests and ensure that the bridge 297 * is set up to, or capable of handling them. 298 */ 299struct resource * 300pcib_alloc_resource(device_t dev, device_t child, int type, int *rid, 301 u_long start, u_long end, u_long count, u_int flags) 302{ |
303 struct pcib_softc *sc = device_get_softc(dev); 304 int ok; |
305 |
306 /* 307 * Fail the allocation for this range if it's not supported. 308 */ 309 switch (type) { 310 case SYS_RES_IOPORT: |
311 ok = 0; |
312 if (!pcib_is_io_open(sc)) 313 break; 314 ok = (start >= sc->iobase && end <= sc->iolimit); 315 if ((sc->flags & PCIB_SUBTRACTIVE) == 0) { 316 if (!ok) { 317 if (start < sc->iobase) 318 start = sc->iobase; 319 if (end > sc->iolimit) 320 end = sc->iolimit; 321 } |
322 } else { |
323 ok = 1; 324 if (start < sc->iobase && end > sc->iolimit) { 325 start = sc->iobase; 326 end = sc->iolimit; 327 } 328 |
329 } |
330 if (end < start) { 331 device_printf(dev, "ioport: end (%lx) < start (%lx)\n", end, start); 332 start = 0; 333 end = 0; 334 ok = 0; 335 } 336 if (!ok) { 337 device_printf(dev, "device %s requested unsupported I/O " 338 "range 0x%lx-0x%lx (decoding 0x%x-0x%x)\n", 339 device_get_nameunit(child), start, end, 340 sc->iobase, sc->iolimit); 341 return (NULL); 342 } 343 if (bootverbose) 344 device_printf(dev, "device %s requested decoded I/O range 0x%lx-0x%lx\n", 345 device_get_nameunit(child), start, end); 346 break; |
347 348 case SYS_RES_MEMORY: |
349 ok = 0; 350 if (pcib_is_nonprefetch_open(sc)) |
351 ok = ok || (start >= sc->membase && end <= sc->memlimit); |
352 if (pcib_is_prefetch_open(sc)) |
353 ok = ok || (start >= sc->pmembase && end <= sc->pmemlimit); 354 if ((sc->flags & PCIB_SUBTRACTIVE) == 0) { 355 if (!ok) { 356 ok = 1; 357 if (flags & RF_PREFETCHABLE) { 358 if (pcib_is_prefetch_open(sc)) { 359 if (start < sc->pmembase) 360 start = sc->pmembase; 361 if (end > sc->pmemlimit) 362 end = sc->pmemlimit; 363 } else { 364 ok = 0; 365 } 366 } else { /* non-prefetchable */ 367 if (pcib_is_nonprefetch_open(sc)) { 368 if (start < sc->membase) 369 start = sc->membase; 370 if (end > sc->memlimit) 371 end = sc->memlimit; 372 } else { 373 ok = 0; 374 } 375 } |
376 } |
377 } else if (!ok) { |
378 ok = 1; /* subtractive bridge: always ok */ 379 if (pcib_is_nonprefetch_open(sc)) { 380 if (start < sc->membase && end > sc->memlimit) { 381 start = sc->membase; 382 end = sc->memlimit; 383 } 384 } 385 if (pcib_is_prefetch_open(sc)) { 386 if (start < sc->pmembase && end > sc->pmemlimit) { 387 start = sc->pmembase; 388 end = sc->pmemlimit; 389 } 390 } |
391 } |
392 if (end < start) { 393 device_printf(dev, "memory: end (%lx) < start (%lx)\n", end, start); 394 start = 0; 395 end = 0; 396 ok = 0; 397 } 398 if (!ok && bootverbose) 399 device_printf(dev, 400 "device %s requested unsupported memory range " 401 "0x%lx-0x%lx (decoding 0x%x-0x%x, 0x%x-0x%x)\n", 402 device_get_nameunit(child), start, end, 403 sc->membase, sc->memlimit, sc->pmembase, 404 sc->pmemlimit); 405 if (!ok) 406 return (NULL); 407 if (bootverbose) 408 device_printf(dev,"device %s requested decoded memory range 0x%lx-0x%lx\n", 409 device_get_nameunit(child), start, end); 410 break; |
411 412 default: |
413 break; |
414 } |
415 /* 416 * Bridge is OK decoding this resource, so pass it up. 417 */ 418 return (bus_generic_alloc_resource(dev, child, type, rid, start, end, count, flags)); |
419} 420 421/* 422 * PCIB interface. 423 */ 424int 425pcib_maxslots(device_t dev) 426{ --- 134 unchanged lines hidden --- |