Deleted Added
sdiff udiff text old ( 279470 ) new ( 280970 )
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: stable/10/sys/dev/pci/pci_pci.c 279470 2015-03-01 04:22:06Z rstone $");
33
34/*
35 * PCI:PCI bridge support.
36 */
37
38#include <sys/param.h>
39#include <sys/bus.h>
40#include <sys/kernel.h>

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

125 * Is a resource from a child device sub-allocated from one of our
126 * resource managers?
127 */
128static int
129pcib_is_resource_managed(struct pcib_softc *sc, int type, struct resource *r)
130{
131
132 switch (type) {
133 case SYS_RES_IOPORT:
134 return (rman_is_region_manager(r, &sc->io.rman));
135 case SYS_RES_MEMORY:
136 /* Prefetchable resources may live in either memory rman. */
137 if (rman_get_flags(r) & RF_PREFETCHABLE &&
138 rman_is_region_manager(r, &sc->pmem.rman))
139 return (1);
140 return (rman_is_region_manager(r, &sc->mem.rman));

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

529 pci_read_config(dev, PCIR_PMLIMITL_1, 2));
530 max = 0xffffffff;
531 }
532 pcib_alloc_window(sc, &sc->pmem, SYS_RES_MEMORY,
533 RF_PREFETCHABLE, max);
534 }
535}
536
537#else
538
539/*
540 * Is the prefetch window open (eg, can we allocate memory in it?)
541 */
542static int
543pcib_is_prefetch_open(struct pcib_softc *sc)
544{

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

675pcib_cfg_save(struct pcib_softc *sc)
676{
677 device_t dev;
678
679 dev = sc->dev;
680
681 sc->command = pci_read_config(dev, PCIR_COMMAND, 2);
682 sc->pribus = pci_read_config(dev, PCIR_PRIBUS_1, 1);
683 sc->secbus = pci_read_config(dev, PCIR_SECBUS_1, 1);
684 sc->subbus = pci_read_config(dev, PCIR_SUBBUS_1, 1);
685 sc->bridgectl = pci_read_config(dev, PCIR_BRIDGECTL_1, 2);
686 sc->seclat = pci_read_config(dev, PCIR_SECLAT_1, 1);
687#ifndef NEW_PCIB
688 if (sc->command & PCIM_CMD_PORTEN)
689 pcib_get_io_decode(sc);
690 if (sc->command & PCIM_CMD_MEMEN)
691 pcib_get_mem_decode(sc);
692#endif

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

699pcib_cfg_restore(struct pcib_softc *sc)
700{
701 device_t dev;
702
703 dev = sc->dev;
704
705 pci_write_config(dev, PCIR_COMMAND, sc->command, 2);
706 pci_write_config(dev, PCIR_PRIBUS_1, sc->pribus, 1);
707 pci_write_config(dev, PCIR_SECBUS_1, sc->secbus, 1);
708 pci_write_config(dev, PCIR_SUBBUS_1, sc->subbus, 1);
709 pci_write_config(dev, PCIR_BRIDGECTL_1, sc->bridgectl, 2);
710 pci_write_config(dev, PCIR_SECLAT_1, sc->seclat, 1);
711#ifdef NEW_PCIB
712 pcib_write_windows(sc, WIN_IO | WIN_MEM | WIN_PMEM);
713#else
714 if (sc->command & PCIM_CMD_PORTEN)
715 pcib_set_io_decode(sc);
716 if (sc->command & PCIM_CMD_MEMEN)

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

746 /*
747 * Get current bridge configuration.
748 */
749 sc->domain = pci_get_domain(dev);
750 sc->secstat = pci_read_config(dev, PCIR_SECSTAT_1, 2);
751 pcib_cfg_save(sc);
752
753 /*
754 * Setup sysctl reporting nodes
755 */
756 sctx = device_get_sysctl_ctx(dev);
757 soid = device_get_sysctl_tree(dev);
758 SYSCTL_ADD_UINT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "domain",
759 CTLFLAG_RD, &sc->domain, 0, "Domain number");
760 SYSCTL_ADD_UINT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "pribus",
761 CTLFLAG_RD, &sc->pribus, 0, "Primary bus number");
762 SYSCTL_ADD_UINT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "secbus",
763 CTLFLAG_RD, &sc->secbus, 0, "Secondary bus number");
764 SYSCTL_ADD_UINT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "subbus",
765 CTLFLAG_RD, &sc->subbus, 0, "Subordinate bus number");
766
767 /*
768 * Quirk handling.
769 */
770 switch (pci_get_devid(dev)) {
771 case 0x12258086: /* Intel 82454KX/GX (Orion) */
772 {
773 uint8_t supbus;
774
775 supbus = pci_read_config(dev, 0x41, 1);
776 if (supbus != 0xff) {
777 sc->secbus = supbus + 1;
778 sc->subbus = supbus + 1;
779 }
780 break;
781 }
782
783 /*
784 * The i82380FB mobile docking controller is a PCI-PCI bridge,
785 * and it is a subtractive bridge. However, the ProgIf is wrong
786 * so the normal setting of PCIB_SUBTRACTIVE bit doesn't
787 * happen. There's also a Toshiba bridge that behaves this
788 * way.
789 */
790 case 0x124b8086: /* Intel 82380FB Mobile */
791 case 0x060513d7: /* Toshiba ???? */
792 sc->flags |= PCIB_SUBTRACTIVE;
793 break;
794
795 /* Compaq R3000 BIOS sets wrong subordinate bus number. */
796 case 0x00dd10de:
797 {
798 char *cp;
799
800 if ((cp = getenv("smbios.planar.maker")) == NULL)
801 break;
802 if (strncmp(cp, "Compal", 6) != 0) {
803 freeenv(cp);
804 break;
805 }
806 freeenv(cp);
807 if ((cp = getenv("smbios.planar.product")) == NULL)
808 break;
809 if (strncmp(cp, "08A0", 4) != 0) {
810 freeenv(cp);
811 break;
812 }
813 freeenv(cp);
814 if (sc->subbus < 0xa) {
815 pci_write_config(dev, PCIR_SUBBUS_1, 0xa, 1);
816 sc->subbus = pci_read_config(dev, PCIR_SUBBUS_1, 1);
817 }
818 break;
819 }
820 }
821
822 if (pci_msi_device_blacklisted(dev))
823 sc->flags |= PCIB_DISABLE_MSI;
824
825 if (pci_msix_device_blacklisted(dev))
826 sc->flags |= PCIB_DISABLE_MSIX;
827

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

833 * bridges and pass all transactions. Mark them and real ProgIf 1
834 * parts as subtractive.
835 */
836 if ((pci_get_devid(dev) & 0xff00ffff) == 0x24008086 ||
837 pci_read_config(dev, PCIR_PROGIF, 1) == PCIP_BRIDGE_PCI_SUBTRACTIVE)
838 sc->flags |= PCIB_SUBTRACTIVE;
839
840#ifdef NEW_PCIB
841 pcib_probe_windows(sc);
842#endif
843 if (bootverbose) {
844 device_printf(dev, " domain %d\n", sc->domain);
845 device_printf(dev, " secondary bus %d\n", sc->secbus);
846 device_printf(dev, " subordinate bus %d\n", sc->subbus);
847#ifdef NEW_PCIB
848 if (pcib_is_window_open(&sc->io))
849 device_printf(dev, " I/O decode 0x%jx-0x%jx\n",
850 (uintmax_t)sc->io.base, (uintmax_t)sc->io.limit);
851 if (pcib_is_window_open(&sc->mem))
852 device_printf(dev, " memory decode 0x%jx-0x%jx\n",
853 (uintmax_t)sc->mem.base, (uintmax_t)sc->mem.limit);
854 if (pcib_is_window_open(&sc->pmem))

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

879 }
880 if (sc->flags & PCIB_SUBTRACTIVE)
881 printf("%ssubtractive", comma ? ", " : "");
882 printf("\n");
883 }
884 }
885
886 /*
887 * XXX If the secondary bus number is zero, we should assign a bus number
888 * since the BIOS hasn't, then initialise the bridge. A simple
889 * bus_alloc_resource with the a couple of busses seems like the right
890 * approach, but we don't know what busses the BIOS might have already
891 * assigned to other bridges on this bus that probe later than we do.
892 *
893 * If the subordinate bus number is less than the secondary bus number,
894 * we should pick a better value. One sensible alternative would be to
895 * pick 255; the only tradeoff here is that configuration transactions
896 * would be more widely routed than absolutely necessary. We could
897 * then do a walk of the tree later and fix it.
898 */
899
900 /*
901 * Always enable busmastering on bridges so that transactions
902 * initiated on the secondary bus are passed through to the
903 * primary bus.
904 */
905 pci_enable_busmaster(dev);
906}
907
908int
909pcib_attach(device_t dev)
910{
911 struct pcib_softc *sc;
912 device_t child;
913
914 pcib_attach_common(dev);
915 sc = device_get_softc(dev);
916 if (sc->secbus != 0) {
917 child = device_add_child(dev, "pci", sc->secbus);
918 if (child != NULL)
919 return(bus_generic_attach(dev));
920 }
921
922 /* no secondary bus; we should have fixed this */
923 return(0);
924}
925

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

961{
962 struct pcib_softc *sc = device_get_softc(dev);
963
964 switch (which) {
965 case PCIB_IVAR_DOMAIN:
966 *result = sc->domain;
967 return(0);
968 case PCIB_IVAR_BUS:
969 *result = sc->secbus;
970 return(0);
971 }
972 return(ENOENT);
973}
974
975int
976pcib_write_ivar(device_t dev, device_t child, int which, uintptr_t value)
977{
978 struct pcib_softc *sc = device_get_softc(dev);
979
980 switch (which) {
981 case PCIB_IVAR_DOMAIN:
982 return(EINVAL);
983 case PCIB_IVAR_BUS:
984 sc->secbus = value;
985 return(0);
986 }
987 return(ENOENT);
988}
989
990#ifdef NEW_PCIB
991/*
992 * Attempt to allocate a resource from the existing resources assigned
993 * to a window.

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

1387 if (sc->bridgectl & PCIB_BCR_VGA_ENABLE)
1388 return (bus_generic_alloc_resource(dev, child, type,
1389 rid, start, end, count, flags));
1390 else
1391 return (NULL);
1392 }
1393
1394 switch (type) {
1395 case SYS_RES_IOPORT:
1396 if (pcib_is_isa_range(sc, start, end, count))
1397 return (NULL);
1398 r = pcib_suballoc_resource(sc, &sc->io, child, type, rid, start,
1399 end, count, flags);
1400 if (r != NULL || (sc->flags & PCIB_SUBTRACTIVE) != 0)
1401 break;
1402 if (pcib_grow_window(sc, &sc->io, type, start, end, count,

--- 520 unchanged lines hidden ---