190 191 /* Base Address 4 */ 192 IXPPCIB_WRITE_CONF(sc, PCI_MAPREG_BAR4, 0xffffffff); 193 194 /* Base Address 5 */ 195 IXPPCIB_WRITE_CONF(sc, PCI_MAPREG_BAR5, 0x00000000); 196 197 /* Assert some PCI errors */ 198 PCI_CSR_WRITE_4(sc, PCI_ISR, ISR_AHBE | ISR_PPE | ISR_PFE | ISR_PSE); 199 200#ifdef __ARMEB__ 201 /* 202 * Set up byte lane swapping between little-endian PCI 203 * and the big-endian AHB bus 204 */ 205 PCI_CSR_WRITE_4(sc, PCI_CSR, CSR_IC | CSR_ABE | CSR_PDS); 206#else 207 PCI_CSR_WRITE_4(sc, PCI_CSR, CSR_IC | CSR_ABE); 208#endif 209 210 /* 211 * Enable bus mastering and I/O,memory access 212 */ 213 IXPPCIB_WRITE_CONF(sc, PCIR_COMMAND, 214 PCIM_CMD_MEMEN | PCIM_CMD_BUSMASTEREN); 215 216 /* 217 * Wait some more to ensure PCI devices have stabilised. 218 */ 219 DELAY(50000); 220 221 device_add_child(dev, "pci", -1); 222 return (bus_generic_attach(dev)); 223} 224 225static int 226ixppcib_read_ivar(device_t dev, device_t child, int which, uintptr_t *result) 227{ 228 struct ixppcib_softc *sc; 229 230 sc = device_get_softc(dev); 231 switch (which) { 232 case PCIB_IVAR_DOMAIN: 233 *result = 0; 234 return (0); 235 case PCIB_IVAR_BUS: 236 *result = sc->sc_bus; 237 return (0); 238 } 239 240 return (ENOENT); 241} 242 243static int 244ixppcib_write_ivar(device_t dev, device_t child, int which, uintptr_t value) 245{ 246 struct ixppcib_softc *sc; 247 248 sc = device_get_softc(dev); 249 switch (which) { 250 case PCIB_IVAR_DOMAIN: 251 return (EINVAL); 252 case PCIB_IVAR_BUS: 253 sc->sc_bus = value; 254 return (0); 255 } 256 257 return (ENOENT); 258} 259 260static int 261ixppcib_setup_intr(device_t dev, device_t child, struct resource *ires, 262 int flags, driver_filter_t *filt, driver_intr_t *intr, void *arg, 263 void **cookiep) 264{ 265 266 return (BUS_SETUP_INTR(device_get_parent(dev), child, ires, flags, 267 filt, intr, arg, cookiep)); 268} 269 270static int 271ixppcib_teardown_intr(device_t dev, device_t child, struct resource *vec, 272 void *cookie) 273{ 274 275 return (BUS_TEARDOWN_INTR(device_get_parent(dev), child, vec, cookie)); 276} 277 278static struct resource * 279ixppcib_alloc_resource(device_t bus, device_t child, int type, int *rid, 280 u_long start, u_long end, u_long count, u_int flags) 281{ 282 bus_space_tag_t tag; 283 struct ixppcib_softc *sc = device_get_softc(bus); 284 struct rman *rmanp; 285 struct resource *rv; 286 287 tag = NULL; /* shut up stupid gcc */ 288 rv = NULL; 289 switch (type) { 290 case SYS_RES_IRQ: 291 rmanp = &sc->sc_irq_rman; 292 break; 293 294 case SYS_RES_IOPORT: 295 rmanp = &sc->sc_io_rman; 296 tag = &sc->sc_pci_iot; 297 break; 298 299 case SYS_RES_MEMORY: 300 rmanp = &sc->sc_mem_rman; 301 tag = &sc->sc_pci_memt; 302 break; 303 304 default: 305 return (rv); 306 } 307 308 rv = rman_reserve_resource(rmanp, start, end, count, flags, child); 309 if (rv != NULL) { 310 rman_set_rid(rv, *rid); 311 if (type == SYS_RES_IOPORT) { 312 rman_set_bustag(rv, tag); 313 rman_set_bushandle(rv, rman_get_start(rv)); 314 } else if (type == SYS_RES_MEMORY) { 315 rman_set_bustag(rv, tag); 316 rman_set_bushandle(rv, rman_get_bushandle(sc->sc_mem) + 317 (rman_get_start(rv) - IXP425_PCI_MEM_HWBASE)); 318 } 319 } 320 321 return (rv); 322} 323 324static int 325ixppcib_activate_resource(device_t bus, device_t child, int type, int rid, 326 struct resource *r) 327{ 328 329 device_printf(bus, "%s called activate_resource\n", device_get_nameunit(child)); 330 return (ENXIO); 331} 332 333static int 334ixppcib_deactivate_resource(device_t bus, device_t child, int type, int rid, 335 struct resource *r) 336{ 337 338 device_printf(bus, "%s called deactivate_resource\n", device_get_nameunit(child)); 339 return (ENXIO); 340} 341 342static int 343ixppcib_release_resource(device_t bus, device_t child, int type, int rid, 344 struct resource *r) 345{ 346 347 device_printf(bus, "%s called release_resource\n", device_get_nameunit(child)); 348 return (ENXIO); 349} 350 351static void 352ixppcib_conf_setup(struct ixppcib_softc *sc, int bus, int slot, int func, 353 int reg) 354{ 355 if (bus == 0) { 356 if (slot == 0 && func == 0) { 357 PCI_CSR_WRITE_4(sc, PCI_NP_AD, (reg & ~3)); 358 } else { 359 bus &= 0xff; 360 slot &= 0x1f; 361 func &= 0x07; 362 /* configuration type 0 */ 363 PCI_CSR_WRITE_4(sc, PCI_NP_AD, (1U << (32 - slot)) | 364 (func << 8) | (reg & ~3)); 365 } 366 } else { 367 /* configuration type 1 */ 368 PCI_CSR_WRITE_4(sc, PCI_NP_AD, 369 (bus << 16) | (slot << 11) | 370 (func << 8) | (reg & ~3) | 1); 371 } 372 373} 374 375static int 376ixppcib_maxslots(device_t dev) 377{ 378 379 return (PCI_SLOTMAX); 380} 381 382static u_int32_t 383ixppcib_read_config(device_t dev, u_int bus, u_int slot, u_int func, u_int reg, 384 int bytes) 385{ 386 struct ixppcib_softc *sc = device_get_softc(dev); 387 u_int32_t data, ret; 388 389 ixppcib_conf_setup(sc, bus, slot, func, reg & ~3); 390 391 PCI_CSR_WRITE_4(sc, PCI_NP_CBE, COMMAND_NP_CONF_READ); 392 ret = PCI_CSR_READ_4(sc, PCI_NP_RDATA); 393 ret >>= (reg & 3) * 8; 394 ret &= 0xffffffff >> ((4 - bytes) * 8); 395#if 0 396 device_printf(dev, "read config: %u:%u:%u %#x(%d) = %#x\n", bus, slot, func, reg, bytes, ret); 397#endif 398 399 /* check & clear PCI abort */ 400 data = PCI_CSR_READ_4(sc, PCI_ISR); 401 if (data & ISR_PFE) { 402 PCI_CSR_WRITE_4(sc, PCI_ISR, ISR_PFE); 403 return (-1); 404 } 405 return (ret); 406} 407 408static const int byteenables[] = { 0, 0x10, 0x30, 0x70, 0xf0 }; 409 410static void 411ixppcib_write_config(device_t dev, u_int bus, u_int slot, u_int func, u_int reg, 412 u_int32_t val, int bytes) 413{ 414 struct ixppcib_softc *sc = device_get_softc(dev); 415 u_int32_t data; 416 417#if 0 418 device_printf(dev, "write config: %u:%u:%u %#x(%d) = %#x\n", bus, slot, func, reg, bytes, val); 419#endif 420 421 ixppcib_conf_setup(sc, bus, slot, func, reg & ~3); 422 423 /* Byte enables are active low, so not them first */ 424 PCI_CSR_WRITE_4(sc, PCI_NP_CBE, COMMAND_NP_CONF_WRITE | 425 (~(byteenables[bytes] << (reg & 3)) & 0xf0)); 426 PCI_CSR_WRITE_4(sc, PCI_NP_WDATA, val << ((reg & 3) * 8)); 427 428 /* check & clear PCI abort */ 429 data = PCI_CSR_READ_4(sc, PCI_ISR); 430 if (data & ISR_PFE) 431 PCI_CSR_WRITE_4(sc, PCI_ISR, ISR_PFE); 432} 433 434static int 435ixppcib_route_interrupt(device_t bridge, device_t device, int pin) 436{ 437 438 return (ixp425_md_route_interrupt(bridge, device, pin)); 439} 440 441static device_method_t ixppcib_methods[] = { 442 /* Device interface */ 443 DEVMETHOD(device_probe, ixppcib_probe), 444 DEVMETHOD(device_attach, ixppcib_attach), 445 446 /* Bus interface */ 447 DEVMETHOD(bus_print_child, bus_generic_print_child), 448 DEVMETHOD(bus_read_ivar, ixppcib_read_ivar), 449 DEVMETHOD(bus_write_ivar, ixppcib_write_ivar), 450 DEVMETHOD(bus_setup_intr, ixppcib_setup_intr), 451 DEVMETHOD(bus_teardown_intr, ixppcib_teardown_intr), 452 DEVMETHOD(bus_alloc_resource, ixppcib_alloc_resource), 453 DEVMETHOD(bus_activate_resource, ixppcib_activate_resource), 454 DEVMETHOD(bus_deactivate_resource, ixppcib_deactivate_resource), 455 DEVMETHOD(bus_release_resource, ixppcib_release_resource), 456 /* DEVMETHOD(bus_get_dma_tag, ixppcib_get_dma_tag), */ 457 458 /* pcib interface */ 459 DEVMETHOD(pcib_maxslots, ixppcib_maxslots), 460 DEVMETHOD(pcib_read_config, ixppcib_read_config), 461 DEVMETHOD(pcib_write_config, ixppcib_write_config), 462 DEVMETHOD(pcib_route_interrupt, ixppcib_route_interrupt), 463 464 {0, 0}, 465}; 466 467static driver_t ixppcib_driver = { 468 "pcib", 469 ixppcib_methods, 470 sizeof(struct ixppcib_softc), 471}; 472static devclass_t ixppcib_devclass; 473 474DRIVER_MODULE(ixppcib, ixp, ixppcib_driver, ixppcib_devclass, 0, 0);
| 189 190 /* Base Address 4 */ 191 IXPPCIB_WRITE_CONF(sc, PCI_MAPREG_BAR4, 0xffffffff); 192 193 /* Base Address 5 */ 194 IXPPCIB_WRITE_CONF(sc, PCI_MAPREG_BAR5, 0x00000000); 195 196 /* Assert some PCI errors */ 197 PCI_CSR_WRITE_4(sc, PCI_ISR, ISR_AHBE | ISR_PPE | ISR_PFE | ISR_PSE); 198 199#ifdef __ARMEB__ 200 /* 201 * Set up byte lane swapping between little-endian PCI 202 * and the big-endian AHB bus 203 */ 204 PCI_CSR_WRITE_4(sc, PCI_CSR, CSR_IC | CSR_ABE | CSR_PDS); 205#else 206 PCI_CSR_WRITE_4(sc, PCI_CSR, CSR_IC | CSR_ABE); 207#endif 208 209 /* 210 * Enable bus mastering and I/O,memory access 211 */ 212 IXPPCIB_WRITE_CONF(sc, PCIR_COMMAND, 213 PCIM_CMD_MEMEN | PCIM_CMD_BUSMASTEREN); 214 215 /* 216 * Wait some more to ensure PCI devices have stabilised. 217 */ 218 DELAY(50000); 219 220 device_add_child(dev, "pci", -1); 221 return (bus_generic_attach(dev)); 222} 223 224static int 225ixppcib_read_ivar(device_t dev, device_t child, int which, uintptr_t *result) 226{ 227 struct ixppcib_softc *sc; 228 229 sc = device_get_softc(dev); 230 switch (which) { 231 case PCIB_IVAR_DOMAIN: 232 *result = 0; 233 return (0); 234 case PCIB_IVAR_BUS: 235 *result = sc->sc_bus; 236 return (0); 237 } 238 239 return (ENOENT); 240} 241 242static int 243ixppcib_write_ivar(device_t dev, device_t child, int which, uintptr_t value) 244{ 245 struct ixppcib_softc *sc; 246 247 sc = device_get_softc(dev); 248 switch (which) { 249 case PCIB_IVAR_DOMAIN: 250 return (EINVAL); 251 case PCIB_IVAR_BUS: 252 sc->sc_bus = value; 253 return (0); 254 } 255 256 return (ENOENT); 257} 258 259static int 260ixppcib_setup_intr(device_t dev, device_t child, struct resource *ires, 261 int flags, driver_filter_t *filt, driver_intr_t *intr, void *arg, 262 void **cookiep) 263{ 264 265 return (BUS_SETUP_INTR(device_get_parent(dev), child, ires, flags, 266 filt, intr, arg, cookiep)); 267} 268 269static int 270ixppcib_teardown_intr(device_t dev, device_t child, struct resource *vec, 271 void *cookie) 272{ 273 274 return (BUS_TEARDOWN_INTR(device_get_parent(dev), child, vec, cookie)); 275} 276 277static struct resource * 278ixppcib_alloc_resource(device_t bus, device_t child, int type, int *rid, 279 u_long start, u_long end, u_long count, u_int flags) 280{ 281 bus_space_tag_t tag; 282 struct ixppcib_softc *sc = device_get_softc(bus); 283 struct rman *rmanp; 284 struct resource *rv; 285 286 tag = NULL; /* shut up stupid gcc */ 287 rv = NULL; 288 switch (type) { 289 case SYS_RES_IRQ: 290 rmanp = &sc->sc_irq_rman; 291 break; 292 293 case SYS_RES_IOPORT: 294 rmanp = &sc->sc_io_rman; 295 tag = &sc->sc_pci_iot; 296 break; 297 298 case SYS_RES_MEMORY: 299 rmanp = &sc->sc_mem_rman; 300 tag = &sc->sc_pci_memt; 301 break; 302 303 default: 304 return (rv); 305 } 306 307 rv = rman_reserve_resource(rmanp, start, end, count, flags, child); 308 if (rv != NULL) { 309 rman_set_rid(rv, *rid); 310 if (type == SYS_RES_IOPORT) { 311 rman_set_bustag(rv, tag); 312 rman_set_bushandle(rv, rman_get_start(rv)); 313 } else if (type == SYS_RES_MEMORY) { 314 rman_set_bustag(rv, tag); 315 rman_set_bushandle(rv, rman_get_bushandle(sc->sc_mem) + 316 (rman_get_start(rv) - IXP425_PCI_MEM_HWBASE)); 317 } 318 } 319 320 return (rv); 321} 322 323static int 324ixppcib_activate_resource(device_t bus, device_t child, int type, int rid, 325 struct resource *r) 326{ 327 328 device_printf(bus, "%s called activate_resource\n", device_get_nameunit(child)); 329 return (ENXIO); 330} 331 332static int 333ixppcib_deactivate_resource(device_t bus, device_t child, int type, int rid, 334 struct resource *r) 335{ 336 337 device_printf(bus, "%s called deactivate_resource\n", device_get_nameunit(child)); 338 return (ENXIO); 339} 340 341static int 342ixppcib_release_resource(device_t bus, device_t child, int type, int rid, 343 struct resource *r) 344{ 345 346 device_printf(bus, "%s called release_resource\n", device_get_nameunit(child)); 347 return (ENXIO); 348} 349 350static void 351ixppcib_conf_setup(struct ixppcib_softc *sc, int bus, int slot, int func, 352 int reg) 353{ 354 if (bus == 0) { 355 if (slot == 0 && func == 0) { 356 PCI_CSR_WRITE_4(sc, PCI_NP_AD, (reg & ~3)); 357 } else { 358 bus &= 0xff; 359 slot &= 0x1f; 360 func &= 0x07; 361 /* configuration type 0 */ 362 PCI_CSR_WRITE_4(sc, PCI_NP_AD, (1U << (32 - slot)) | 363 (func << 8) | (reg & ~3)); 364 } 365 } else { 366 /* configuration type 1 */ 367 PCI_CSR_WRITE_4(sc, PCI_NP_AD, 368 (bus << 16) | (slot << 11) | 369 (func << 8) | (reg & ~3) | 1); 370 } 371 372} 373 374static int 375ixppcib_maxslots(device_t dev) 376{ 377 378 return (PCI_SLOTMAX); 379} 380 381static u_int32_t 382ixppcib_read_config(device_t dev, u_int bus, u_int slot, u_int func, u_int reg, 383 int bytes) 384{ 385 struct ixppcib_softc *sc = device_get_softc(dev); 386 u_int32_t data, ret; 387 388 ixppcib_conf_setup(sc, bus, slot, func, reg & ~3); 389 390 PCI_CSR_WRITE_4(sc, PCI_NP_CBE, COMMAND_NP_CONF_READ); 391 ret = PCI_CSR_READ_4(sc, PCI_NP_RDATA); 392 ret >>= (reg & 3) * 8; 393 ret &= 0xffffffff >> ((4 - bytes) * 8); 394#if 0 395 device_printf(dev, "read config: %u:%u:%u %#x(%d) = %#x\n", bus, slot, func, reg, bytes, ret); 396#endif 397 398 /* check & clear PCI abort */ 399 data = PCI_CSR_READ_4(sc, PCI_ISR); 400 if (data & ISR_PFE) { 401 PCI_CSR_WRITE_4(sc, PCI_ISR, ISR_PFE); 402 return (-1); 403 } 404 return (ret); 405} 406 407static const int byteenables[] = { 0, 0x10, 0x30, 0x70, 0xf0 }; 408 409static void 410ixppcib_write_config(device_t dev, u_int bus, u_int slot, u_int func, u_int reg, 411 u_int32_t val, int bytes) 412{ 413 struct ixppcib_softc *sc = device_get_softc(dev); 414 u_int32_t data; 415 416#if 0 417 device_printf(dev, "write config: %u:%u:%u %#x(%d) = %#x\n", bus, slot, func, reg, bytes, val); 418#endif 419 420 ixppcib_conf_setup(sc, bus, slot, func, reg & ~3); 421 422 /* Byte enables are active low, so not them first */ 423 PCI_CSR_WRITE_4(sc, PCI_NP_CBE, COMMAND_NP_CONF_WRITE | 424 (~(byteenables[bytes] << (reg & 3)) & 0xf0)); 425 PCI_CSR_WRITE_4(sc, PCI_NP_WDATA, val << ((reg & 3) * 8)); 426 427 /* check & clear PCI abort */ 428 data = PCI_CSR_READ_4(sc, PCI_ISR); 429 if (data & ISR_PFE) 430 PCI_CSR_WRITE_4(sc, PCI_ISR, ISR_PFE); 431} 432 433static int 434ixppcib_route_interrupt(device_t bridge, device_t device, int pin) 435{ 436 437 return (ixp425_md_route_interrupt(bridge, device, pin)); 438} 439 440static device_method_t ixppcib_methods[] = { 441 /* Device interface */ 442 DEVMETHOD(device_probe, ixppcib_probe), 443 DEVMETHOD(device_attach, ixppcib_attach), 444 445 /* Bus interface */ 446 DEVMETHOD(bus_print_child, bus_generic_print_child), 447 DEVMETHOD(bus_read_ivar, ixppcib_read_ivar), 448 DEVMETHOD(bus_write_ivar, ixppcib_write_ivar), 449 DEVMETHOD(bus_setup_intr, ixppcib_setup_intr), 450 DEVMETHOD(bus_teardown_intr, ixppcib_teardown_intr), 451 DEVMETHOD(bus_alloc_resource, ixppcib_alloc_resource), 452 DEVMETHOD(bus_activate_resource, ixppcib_activate_resource), 453 DEVMETHOD(bus_deactivate_resource, ixppcib_deactivate_resource), 454 DEVMETHOD(bus_release_resource, ixppcib_release_resource), 455 /* DEVMETHOD(bus_get_dma_tag, ixppcib_get_dma_tag), */ 456 457 /* pcib interface */ 458 DEVMETHOD(pcib_maxslots, ixppcib_maxslots), 459 DEVMETHOD(pcib_read_config, ixppcib_read_config), 460 DEVMETHOD(pcib_write_config, ixppcib_write_config), 461 DEVMETHOD(pcib_route_interrupt, ixppcib_route_interrupt), 462 463 {0, 0}, 464}; 465 466static driver_t ixppcib_driver = { 467 "pcib", 468 ixppcib_methods, 469 sizeof(struct ixppcib_softc), 470}; 471static devclass_t ixppcib_devclass; 472 473DRIVER_MODULE(ixppcib, ixp, ixppcib_driver, ixppcib_devclass, 0, 0);
|