| @@ -1,16 +1,17 @@ | | | @@ -1,16 +1,17 @@ |
1 | $NetBSD: patch-ac,v 1.11 2012/07/14 23:42:13 wiz Exp $ | | 1 | $NetBSD: patch-ac,v 1.12 2012/07/15 08:12:42 wiz Exp $ |
2 | | | 2 | |
3 | Improve NetBSD support. From Michael Lorenz <macallan@NetBSD.org>. | | 3 | Improve NetBSD support. From Michael Lorenz <macallan@NetBSD.org>. |
| | | 4 | Enable boot_vga support only if WSDISPLAYIO_GET_BUSID is defined. |
4 | | | 5 | |
5 | --- src/netbsd_pci.c.orig 2012-04-09 17:02:57.000000000 +0000 | | 6 | --- src/netbsd_pci.c.orig 2012-04-09 17:02:57.000000000 +0000 |
6 | +++ src/netbsd_pci.c | | 7 | +++ src/netbsd_pci.c |
7 | @@ -1,6 +1,7 @@ | | 8 | @@ -1,6 +1,7 @@ |
8 | /* | | 9 | /* |
9 | * Copyright (c) 2008 Juan Romero Pardines | | 10 | * Copyright (c) 2008 Juan Romero Pardines |
10 | * Copyright (c) 2008 Mark Kettenis | | 11 | * Copyright (c) 2008 Mark Kettenis |
11 | + * Copyright (c) 2009 Michael Lorenz | | 12 | + * Copyright (c) 2009 Michael Lorenz |
12 | * | | 13 | * |
13 | * Permission to use, copy, modify, and distribute this software for any | | 14 | * Permission to use, copy, modify, and distribute this software for any |
14 | * purpose with or without fee is hereby granted, provided that the above | | 15 | * purpose with or without fee is hereby granted, provided that the above |
15 | @@ -20,8 +21,13 @@ | | 16 | @@ -20,8 +21,13 @@ |
16 | #include <sys/mman.h> | | 17 | #include <sys/mman.h> |
| @@ -300,30 +301,31 @@ Improve NetBSD support. From Michael Lor | | | @@ -300,30 +301,31 @@ Improve NetBSD support. From Michael Lor |
300 | | | 301 | |
301 | - if (ioctl(pcifd, PCI_IOC_BDF_CFGWRITE, &io) == -1) | | 302 | - if (ioctl(pcifd, PCI_IOC_BDF_CFGWRITE, &io) == -1) |
302 | + if ((pcibus_conf_write(buses[dev->domain].fd, | | 303 | + if ((pcibus_conf_write(buses[dev->domain].fd, |
303 | + (unsigned int)dev->bus, (unsigned int)dev->dev, | | 304 | + (unsigned int)dev->bus, (unsigned int)dev->dev, |
304 | + (unsigned int)dev->func, reg, val)) == -1) | | 305 | + (unsigned int)dev->func, reg, val)) == -1) |
305 | return errno; | | 306 | return errno; |
306 | | | 307 | |
307 | offset += 4; | | 308 | offset += 4; |
308 | - data = (char *)data + 4; | | 309 | - data = (char *)data + 4; |
309 | + data = (const char *)data + 4; | | 310 | + data = (const char *)data + 4; |
310 | size -= 4; | | 311 | size -= 4; |
311 | *bytes_written += 4; | | 312 | *bytes_written += 4; |
312 | } | | 313 | } |
313 | @@ -222,10 +250,51 @@ pci_device_netbsd_write(struct pci_devic | | 314 | @@ -222,10 +250,53 @@ pci_device_netbsd_write(struct pci_devic |
314 | return 0; | | 315 | return 0; |
315 | } | | 316 | } |
316 | | | 317 | |
| | | 318 | +#if defined(WSDISPLAYIO_GET_BUSID) |
317 | +static int | | 319 | +static int |
318 | +pci_device_netbsd_boot_vga(struct pci_device *dev) | | 320 | +pci_device_netbsd_boot_vga(struct pci_device *dev) |
319 | +{ | | 321 | +{ |
320 | + int ret; | | 322 | + int ret; |
321 | + struct wsdisplayio_bus_id busid; | | 323 | + struct wsdisplayio_bus_id busid; |
322 | + int fd; | | 324 | + int fd; |
323 | + | | 325 | + |
324 | + fd = open("/dev/ttyE0", O_RDONLY); | | 326 | + fd = open("/dev/ttyE0", O_RDONLY); |
325 | + if (fd == -1) { | | 327 | + if (fd == -1) { |
326 | + fprintf(stderr, "failed to open /dev/ttyE0: %s\n", | | 328 | + fprintf(stderr, "failed to open /dev/ttyE0: %s\n", |
327 | + strerror(errno)); | | 329 | + strerror(errno)); |
328 | + return 0; | | 330 | + return 0; |
329 | + } | | 331 | + } |
| @@ -340,40 +342,41 @@ Improve NetBSD support. From Michael Lor | | | @@ -340,40 +342,41 @@ Improve NetBSD support. From Michael Lor |
340 | + return 0; | | 342 | + return 0; |
341 | + | | 343 | + |
342 | + if (busid.ubus.pci.domain != dev->domain) | | 344 | + if (busid.ubus.pci.domain != dev->domain) |
343 | + return 0; | | 345 | + return 0; |
344 | + if (busid.ubus.pci.bus != dev->bus) | | 346 | + if (busid.ubus.pci.bus != dev->bus) |
345 | + return 0; | | 347 | + return 0; |
346 | + if (busid.ubus.pci.device != dev->dev) | | 348 | + if (busid.ubus.pci.device != dev->dev) |
347 | + return 0; | | 349 | + return 0; |
348 | + if (busid.ubus.pci.function != dev->func) | | 350 | + if (busid.ubus.pci.function != dev->func) |
349 | + return 0; | | 351 | + return 0; |
350 | + | | 352 | + |
351 | + return 1; | | 353 | + return 1; |
352 | +} | | 354 | +} |
| | | 355 | +#endif |
353 | + | | 356 | + |
354 | static void | | 357 | static void |
355 | pci_system_netbsd_destroy(void) | | 358 | pci_system_netbsd_destroy(void) |
356 | { | | 359 | { |
357 | - close(pcifd); | | 360 | - close(pcifd); |
358 | + int i; | | 361 | + int i; |
359 | + | | 362 | + |
360 | + for (i = 0; i < nbuses; i++) { | | 363 | + for (i = 0; i < nbuses; i++) { |
361 | + close(buses[i].fd); | | 364 | + close(buses[i].fd); |
362 | + } | | 365 | + } |
363 | free(pci_sys); | | 366 | free(pci_sys); |
364 | pci_sys = NULL; | | 367 | pci_sys = NULL; |
365 | } | | 368 | } |
366 | @@ -233,17 +302,34 @@ pci_system_netbsd_destroy(void) | | 369 | @@ -233,17 +304,34 @@ pci_system_netbsd_destroy(void) |
367 | static int | | 370 | static int |
368 | pci_device_netbsd_probe(struct pci_device *device) | | 371 | pci_device_netbsd_probe(struct pci_device *device) |
369 | { | | 372 | { |
370 | - struct pci_device_private *priv = (struct pci_device_private *)device; | | 373 | - struct pci_device_private *priv = (struct pci_device_private *)device; |
371 | + struct pci_device_private *priv = | | 374 | + struct pci_device_private *priv = |
372 | + (struct pci_device_private *)(void *)device; | | 375 | + (struct pci_device_private *)(void *)device; |
373 | struct pci_mem_region *region; | | 376 | struct pci_mem_region *region; |
374 | uint64_t reg64, size64; | | 377 | uint64_t reg64, size64; |
375 | uint32_t bar, reg, size; | | 378 | uint32_t bar, reg, size; |
376 | - int bus, dev, func, err; | | 379 | - int bus, dev, func, err; |
377 | + int bus, dev, func, err, domain; | | 380 | + int bus, dev, func, err, domain; |
378 | | | 381 | |
379 | + domain = device->domain; | | 382 | + domain = device->domain; |
| @@ -391,48 +394,48 @@ Improve NetBSD support. From Michael Lor | | | @@ -391,48 +394,48 @@ Improve NetBSD support. From Michael Lor |
391 | + reg |= PCI_COMMAND_IO_ENABLE | | | 394 | + reg |= PCI_COMMAND_IO_ENABLE | |
392 | + PCI_COMMAND_MEM_ENABLE | | | 395 | + PCI_COMMAND_MEM_ENABLE | |
393 | + PCI_COMMAND_MASTER_ENABLE; | | 396 | + PCI_COMMAND_MASTER_ENABLE; |
394 | + err = pci_write(domain, bus, dev, func, PCI_COMMAND_STATUS_REG, | | 397 | + err = pci_write(domain, bus, dev, func, PCI_COMMAND_STATUS_REG, |
395 | + reg); | | 398 | + reg); |
396 | + if (err) | | 399 | + if (err) |
397 | + return err; | | 400 | + return err; |
398 | + } | | 401 | + } |
399 | + | | 402 | + |
400 | + err = pci_read(domain, bus, dev, func, PCI_BHLC_REG, ®); | | 403 | + err = pci_read(domain, bus, dev, func, PCI_BHLC_REG, ®); |
401 | if (err) | | 404 | if (err) |
402 | return err; | | 405 | return err; |
403 | | | 406 | |
404 | @@ -254,16 +340,16 @@ pci_device_netbsd_probe(struct pci_devic | | 407 | @@ -254,16 +342,16 @@ pci_device_netbsd_probe(struct pci_devic |
405 | region = device->regions; | | 408 | region = device->regions; |
406 | for (bar = PCI_MAPREG_START; bar < PCI_MAPREG_END; | | 409 | for (bar = PCI_MAPREG_START; bar < PCI_MAPREG_END; |
407 | bar += sizeof(uint32_t), region++) { | | 410 | bar += sizeof(uint32_t), region++) { |
408 | - err = pci_read(bus, dev, func, bar, ®); | | 411 | - err = pci_read(bus, dev, func, bar, ®); |
409 | + err = pci_read(domain, bus, dev, func, bar, ®); | | 412 | + err = pci_read(domain, bus, dev, func, bar, ®); |
410 | if (err) | | 413 | if (err) |
411 | return err; | | 414 | return err; |
412 | | | 415 | |
413 | /* Probe the size of the region. */ | | 416 | /* Probe the size of the region. */ |
414 | - err = pci_write(bus, dev, func, bar, ~0); | | 417 | - err = pci_write(bus, dev, func, bar, ~0); |
415 | + err = pci_write(domain, bus, dev, func, bar, (unsigned int)~0); | | 418 | + err = pci_write(domain, bus, dev, func, bar, (unsigned int)~0); |
416 | if (err) | | 419 | if (err) |
417 | return err; | | 420 | return err; |
418 | - pci_read(bus, dev, func, bar, &size); | | 421 | - pci_read(bus, dev, func, bar, &size); |
419 | - pci_write(bus, dev, func, bar, reg); | | 422 | - pci_write(bus, dev, func, bar, reg); |
420 | + pci_read(domain, bus, dev, func, bar, &size); | | 423 | + pci_read(domain, bus, dev, func, bar, &size); |
421 | + pci_write(domain, bus, dev, func, bar, reg); | | 424 | + pci_write(domain, bus, dev, func, bar, reg); |
422 | | | 425 | |
423 | if (PCI_MAPREG_TYPE(reg) == PCI_MAPREG_TYPE_IO) { | | 426 | if (PCI_MAPREG_TYPE(reg) == PCI_MAPREG_TYPE_IO) { |
424 | region->is_IO = 1; | | 427 | region->is_IO = 1; |
425 | @@ -286,66 +372,185 @@ pci_device_netbsd_probe(struct pci_devic | | 428 | @@ -286,66 +374,189 @@ pci_device_netbsd_probe(struct pci_devic |
426 | | | 429 | |
427 | bar += sizeof(uint32_t); | | 430 | bar += sizeof(uint32_t); |
428 | | | 431 | |
429 | - err = pci_read(bus, dev, func, bar, ®); | | 432 | - err = pci_read(bus, dev, func, bar, ®); |
430 | + err = pci_read(domain, bus, dev, func, bar, ®); | | 433 | + err = pci_read(domain, bus, dev, func, bar, ®); |
431 | if (err) | | 434 | if (err) |
432 | return err; | | 435 | return err; |
433 | reg64 |= (uint64_t)reg << 32; | | 436 | reg64 |= (uint64_t)reg << 32; |
434 | | | 437 | |
435 | - err = pci_write(bus, dev, func, bar, ~0); | | 438 | - err = pci_write(bus, dev, func, bar, ~0); |
436 | + err = pci_write(domain, bus, dev, func, bar, | | 439 | + err = pci_write(domain, bus, dev, func, bar, |
437 | + (unsigned int)~0); | | 440 | + (unsigned int)~0); |
438 | if (err) | | 441 | if (err) |
| @@ -579,27 +582,31 @@ Improve NetBSD support. From Michael Lor | | | @@ -579,27 +582,31 @@ Improve NetBSD support. From Michael Lor |
579 | - pci_device_netbsd_unmap_range, | | 582 | - pci_device_netbsd_unmap_range, |
580 | - pci_device_netbsd_read, | | 583 | - pci_device_netbsd_read, |
581 | - pci_device_netbsd_write, | | 584 | - pci_device_netbsd_write, |
582 | - pci_fill_capabilities_generic | | 585 | - pci_fill_capabilities_generic |
583 | + .destroy = pci_system_netbsd_destroy, | | 586 | + .destroy = pci_system_netbsd_destroy, |
584 | + .destroy_device = NULL, | | 587 | + .destroy_device = NULL, |
585 | + .read_rom = pci_device_netbsd_read_rom, | | 588 | + .read_rom = pci_device_netbsd_read_rom, |
586 | + .probe = pci_device_netbsd_probe, | | 589 | + .probe = pci_device_netbsd_probe, |
587 | + .map_range = pci_device_netbsd_map_range, | | 590 | + .map_range = pci_device_netbsd_map_range, |
588 | + .unmap_range = pci_device_netbsd_unmap_range, | | 591 | + .unmap_range = pci_device_netbsd_unmap_range, |
589 | + .read = pci_device_netbsd_read, | | 592 | + .read = pci_device_netbsd_read, |
590 | + .write = pci_device_netbsd_write, | | 593 | + .write = pci_device_netbsd_write, |
591 | + .fill_capabilities = pci_fill_capabilities_generic, | | 594 | + .fill_capabilities = pci_fill_capabilities_generic, |
| | | 595 | +#if defined(WSDISPLAYIO_GET_BUSID) |
592 | + .boot_vga = pci_device_netbsd_boot_vga, | | 596 | + .boot_vga = pci_device_netbsd_boot_vga, |
| | | 597 | +#else |
| | | 598 | + .boot_vga = NULL |
| | | 599 | +#endif |
593 | }; | | 600 | }; |
594 | | | 601 | |
595 | int | | 602 | int |
596 | pci_system_netbsd_create(void) | | 603 | pci_system_netbsd_create(void) |
597 | { | | 604 | { |
598 | struct pci_device_private *device; | | 605 | struct pci_device_private *device; |
599 | - int bus, dev, func, ndevs, nfuncs; | | 606 | - int bus, dev, func, ndevs, nfuncs; |
600 | + int bus, dev, func, ndevs, nfuncs, domain, pcifd; | | 607 | + int bus, dev, func, ndevs, nfuncs, domain, pcifd; |
601 | uint32_t reg; | | 608 | uint32_t reg; |
602 | - | | 609 | - |
603 | - pcifd = open("/dev/pci0", O_RDWR | O_CLOEXEC); | | 610 | - pcifd = open("/dev/pci0", O_RDWR | O_CLOEXEC); |
604 | - if (pcifd == -1) | | 611 | - if (pcifd == -1) |
605 | - return ENXIO; | | 612 | - return ENXIO; |
| @@ -626,27 +633,27 @@ Improve NetBSD support. From Michael Lor | | | @@ -626,27 +633,27 @@ Improve NetBSD support. From Michael Lor |
626 | + buses[nbuses].fd = pcifd; | | 633 | + buses[nbuses].fd = pcifd; |
627 | + buses[nbuses].num = bus = businfo.busno; | | 634 | + buses[nbuses].num = bus = businfo.busno; |
628 | + buses[nbuses].maxdevs = businfo.maxdevs; | | 635 | + buses[nbuses].maxdevs = businfo.maxdevs; |
629 | + domain = nbuses; | | 636 | + domain = nbuses; |
630 | + nbuses++; | | 637 | + nbuses++; |
631 | + for (dev = 0; dev < businfo.maxdevs; dev++) { | | 638 | + for (dev = 0; dev < businfo.maxdevs; dev++) { |
632 | + nfuncs = pci_nfuncs(domain, bus, dev); | | 639 | + nfuncs = pci_nfuncs(domain, bus, dev); |
633 | for (func = 0; func < nfuncs; func++) { | | 640 | for (func = 0; func < nfuncs; func++) { |
634 | - if (pci_read(bus, dev, func, PCI_ID_REG, | | 641 | - if (pci_read(bus, dev, func, PCI_ID_REG, |
635 | + if (pci_read(domain, bus, dev, func, PCI_ID_REG, | | 642 | + if (pci_read(domain, bus, dev, func, PCI_ID_REG, |
636 | ®) != 0) | | 643 | ®) != 0) |
637 | continue; | | 644 | continue; |
638 | if (PCI_VENDOR(reg) == PCI_VENDOR_INVALID || | | 645 | if (PCI_VENDOR(reg) == PCI_VENDOR_INVALID || |
639 | @@ -355,37 +560,43 @@ pci_system_netbsd_create(void) | | 646 | @@ -355,37 +566,43 @@ pci_system_netbsd_create(void) |
640 | ndevs++; | | 647 | ndevs++; |
641 | } | | 648 | } |
642 | } | | 649 | } |
643 | + snprintf(netbsd_devname, 32, "/dev/pci%d", nbuses); | | 650 | + snprintf(netbsd_devname, 32, "/dev/pci%d", nbuses); |
644 | + pcifd = open(netbsd_devname, O_RDWR); | | 651 | + pcifd = open(netbsd_devname, O_RDWR); |
645 | } | | 652 | } |
646 | | | 653 | |
647 | pci_sys->num_devices = ndevs; | | 654 | pci_sys->num_devices = ndevs; |
648 | pci_sys->devices = calloc(ndevs, sizeof(struct pci_device_private)); | | 655 | pci_sys->devices = calloc(ndevs, sizeof(struct pci_device_private)); |
649 | if (pci_sys->devices == NULL) { | | 656 | if (pci_sys->devices == NULL) { |
650 | + int i; | | 657 | + int i; |
651 | + | | 658 | + |
652 | + for (i = 0; i < nbuses; i++) | | 659 | + for (i = 0; i < nbuses; i++) |
| @@ -679,24 +686,24 @@ Improve NetBSD support. From Michael Lor | | | @@ -679,24 +686,24 @@ Improve NetBSD support. From Michael Lor |
679 | device->base.bus = bus; | | 686 | device->base.bus = bus; |
680 | device->base.dev = dev; | | 687 | device->base.dev = dev; |
681 | device->base.func = func; | | 688 | device->base.func = func; |
682 | device->base.vendor_id = PCI_VENDOR(reg); | | 689 | device->base.vendor_id = PCI_VENDOR(reg); |
683 | device->base.device_id = PCI_PRODUCT(reg); | | 690 | device->base.device_id = PCI_PRODUCT(reg); |
684 | | | 691 | |
685 | - if (pci_read(bus, dev, func, PCI_CLASS_REG, | | 692 | - if (pci_read(bus, dev, func, PCI_CLASS_REG, |
686 | - ®) != 0) | | 693 | - ®) != 0) |
687 | + if (pci_read(domain, bus, dev, func, | | 694 | + if (pci_read(domain, bus, dev, func, |
688 | + PCI_CLASS_REG, ®) != 0) | | 695 | + PCI_CLASS_REG, ®) != 0) |
689 | continue; | | 696 | continue; |
690 | | | 697 | |
691 | device->base.device_class = | | 698 | device->base.device_class = |
692 | @@ -393,8 +604,8 @@ pci_system_netbsd_create(void) | | 699 | @@ -393,8 +610,8 @@ pci_system_netbsd_create(void) |
693 | PCI_SUBCLASS(reg) << 8; | | 700 | PCI_SUBCLASS(reg) << 8; |
694 | device->base.revision = PCI_REVISION(reg); | | 701 | device->base.revision = PCI_REVISION(reg); |
695 | | | 702 | |
696 | - if (pci_read(bus, dev, func, PCI_SUBSYS_ID_REG, | | 703 | - if (pci_read(bus, dev, func, PCI_SUBSYS_ID_REG, |
697 | - ®) != 0) | | 704 | - ®) != 0) |
698 | + if (pci_read(domain, bus, dev, func, | | 705 | + if (pci_read(domain, bus, dev, func, |
699 | + PCI_SUBSYS_ID_REG, ®) != 0) | | 706 | + PCI_SUBSYS_ID_REG, ®) != 0) |
700 | continue; | | 707 | continue; |
701 | | | 708 | |
702 | device->base.subvendor_id = PCI_VENDOR(reg); | | 709 | device->base.subvendor_id = PCI_VENDOR(reg); |