The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/sparc64/pci/apb.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    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  * Copyright (c) 2001, 2003 Thomas Moestl <tmm@FreeBSD.org>
    6  * All rights reserved.
    7  *
    8  * Redistribution and use in source and binary forms, with or without
    9  * modification, are permitted provided that the following conditions
   10  * are met:
   11  * 1. Redistributions of source code must retain the above copyright
   12  *    notice, this list of conditions and the following disclaimer.
   13  * 2. Redistributions in binary form must reproduce the above copyright
   14  *    notice, this list of conditions and the following disclaimer in the
   15  *    documentation and/or other materials provided with the distribution.
   16  * 3. The name of the author may not be used to endorse or promote products
   17  *    derived from this software without specific prior written permission.
   18  *
   19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   29  * SUCH DAMAGE.
   30  *
   31  *      from: FreeBSD: src/sys/dev/pci/pci_pci.c,v 1.3 2000/12/13
   32  *
   33  * $FreeBSD: releng/6.0/sys/sparc64/pci/apb.c 145610 2005-04-28 03:33:46Z marcel $
   34  */
   35 
   36 /*
   37  * Support for the Sun APB (Advanced PCI Bridge) PCI-PCI bridge.
   38  * This bridge does not fully comply to the PCI bridge specification, and is
   39  * therefore not supported by the generic driver.
   40  * We can use some of the pcib methods anyway.
   41  */
   42 
   43 #include "opt_ofw_pci.h"
   44 
   45 #include <sys/param.h>
   46 #include <sys/systm.h>
   47 #include <sys/kernel.h>
   48 #include <sys/module.h>
   49 #include <sys/bus.h>
   50 
   51 #include <dev/ofw/ofw_bus.h>
   52 #include <dev/ofw/openfirm.h>
   53 
   54 #include <machine/bus.h>
   55 #include <machine/ofw_bus.h>
   56 #include <machine/resource.h>
   57 
   58 #include <dev/pci/pcireg.h>
   59 #include <dev/pci/pcivar.h>
   60 #include <dev/pci/pcib_private.h>
   61 
   62 #include "pcib_if.h"
   63 
   64 #include <sparc64/pci/ofw_pci.h>
   65 #include <sparc64/pci/ofw_pcib_subr.h>
   66 
   67 /*
   68  * Bridge-specific data.
   69  */
   70 struct apb_softc {
   71         struct ofw_pcib_gen_softc       sc_bsc;
   72         u_int8_t        sc_iomap;
   73         u_int8_t        sc_memmap;
   74 };
   75 
   76 static device_probe_t apb_probe;
   77 static device_attach_t apb_attach;
   78 static bus_alloc_resource_t apb_alloc_resource;
   79 
   80 static device_method_t apb_methods[] = {
   81         /* Device interface */
   82         DEVMETHOD(device_probe,         apb_probe),
   83         DEVMETHOD(device_attach,        apb_attach),
   84         DEVMETHOD(device_shutdown,      bus_generic_shutdown),
   85         DEVMETHOD(device_suspend,       bus_generic_suspend),
   86         DEVMETHOD(device_resume,        bus_generic_resume),
   87 
   88         /* Bus interface */
   89         DEVMETHOD(bus_print_child,      bus_generic_print_child),
   90         DEVMETHOD(bus_read_ivar,        pcib_read_ivar),
   91         DEVMETHOD(bus_write_ivar,       pcib_write_ivar),
   92         DEVMETHOD(bus_alloc_resource,   apb_alloc_resource),
   93         DEVMETHOD(bus_release_resource, bus_generic_release_resource),
   94         DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
   95         DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
   96         DEVMETHOD(bus_setup_intr,       bus_generic_setup_intr),
   97         DEVMETHOD(bus_teardown_intr,    bus_generic_teardown_intr),
   98 
   99         /* pcib interface */
  100         DEVMETHOD(pcib_maxslots,        pcib_maxslots),
  101         DEVMETHOD(pcib_read_config,     pcib_read_config),
  102         DEVMETHOD(pcib_write_config,    pcib_write_config),
  103         DEVMETHOD(pcib_route_interrupt, ofw_pcib_gen_route_interrupt),
  104 
  105         /* ofw_bus interface */
  106         DEVMETHOD(ofw_bus_get_node,     ofw_pcib_gen_get_node),
  107 
  108         /* ofw_pci interface */
  109         DEVMETHOD(ofw_pci_adjust_busrange,      ofw_pcib_gen_adjust_busrange),
  110 
  111         { 0, 0 }
  112 };
  113 
  114 static driver_t apb_driver = {
  115         "pcib",
  116         apb_methods,
  117         sizeof(struct apb_softc),
  118 };
  119 
  120 DRIVER_MODULE(apb, pci, apb_driver, pcib_devclass, 0, 0);
  121 
  122 /* APB specific registers */
  123 #define APBR_IOMAP      0xde
  124 #define APBR_MEMMAP     0xdf
  125 
  126 /* Definitions for the mapping registers */
  127 #define APB_IO_SCALE    0x200000
  128 #define APB_MEM_SCALE   0x20000000
  129 
  130 /*
  131  * Generic device interface
  132  */
  133 static int
  134 apb_probe(device_t dev)
  135 {
  136 
  137         if (pci_get_vendor(dev) == 0x108e &&    /* Sun */
  138             pci_get_device(dev) == 0x5000)  {   /* APB */
  139                 device_set_desc(dev, "APB PCI-PCI bridge");
  140                 return (0);
  141         }
  142         return (ENXIO);
  143 }
  144 
  145 static void
  146 apb_map_print(u_int8_t map, u_long scale)
  147 {
  148         int i, first;
  149 
  150         for (first = 1, i = 0; i < 8; i++) {
  151                 if ((map & (1 << i)) != 0) {
  152                         printf("%s0x%lx-0x%lx", first ? "" : ", ",
  153                             i * scale, (i + 1) * scale - 1);
  154                         first = 0;
  155                 }
  156         }
  157 }
  158 
  159 static int
  160 apb_checkrange(u_int8_t map, u_long scale, u_long start, u_long end)
  161 {
  162         int i, ei;
  163 
  164         i = start / scale;
  165         ei = end / scale;
  166         if (i > 7 || ei > 7)
  167                 return (0);
  168         for (; i <= ei; i++)
  169                 if ((map & (1 << i)) == 0)
  170                         return (0);
  171         return (1);
  172 }
  173 
  174 static int
  175 apb_attach(device_t dev)
  176 {
  177         struct apb_softc *sc;
  178 
  179         sc = device_get_softc(dev);
  180 
  181         /*
  182          * Get current bridge configuration.
  183          */
  184         sc->sc_iomap = pci_read_config(dev, APBR_IOMAP, 1);
  185         sc->sc_memmap = pci_read_config(dev, APBR_MEMMAP, 1);
  186         ofw_pcib_gen_setup(dev);
  187 
  188         if (bootverbose) {
  189                 device_printf(dev, "  secondary bus     %d\n",
  190                     sc->sc_bsc.ops_pcib_sc.secbus);
  191                 device_printf(dev, "  subordinate bus   %d\n",
  192                     sc->sc_bsc.ops_pcib_sc.subbus);
  193                 device_printf(dev, "  I/O decode        ");
  194                 apb_map_print(sc->sc_iomap, APB_IO_SCALE);
  195                 printf("\n");
  196                 device_printf(dev, "  memory decode     ");
  197                 apb_map_print(sc->sc_memmap, APB_MEM_SCALE);
  198                 printf("\n");
  199         }
  200 
  201         device_add_child(dev, "pci", sc->sc_bsc.ops_pcib_sc.secbus);
  202         return (bus_generic_attach(dev));
  203 }
  204 
  205 /*
  206  * We have to trap resource allocation requests and ensure that the bridge
  207  * is set up to, or capable of handling them.
  208  */
  209 static struct resource *
  210 apb_alloc_resource(device_t dev, device_t child, int type, int *rid, 
  211     u_long start, u_long end, u_long count, u_int flags)
  212 {
  213         struct apb_softc *sc;
  214 
  215         sc = device_get_softc(dev);
  216 
  217         /*
  218          * If this is a "default" allocation against this rid, we can't work
  219          * out where it's coming from (we should actually never see these) so
  220          * we just have to punt.
  221          */
  222         if (start == 0 && end == ~0) {
  223                 device_printf(dev, "can't decode default resource id %d for "
  224                     "%s%d, bypassing\n", *rid, device_get_name(child),
  225                     device_get_unit(child));
  226                 goto passup;
  227         }
  228 
  229         /*
  230          * Fail the allocation for this range if it's not supported.
  231          * XXX we should probably just fix up the bridge decode and
  232          * soldier on.
  233          */
  234         switch (type) {
  235         case SYS_RES_IOPORT:
  236                 if (!apb_checkrange(sc->sc_iomap, APB_IO_SCALE, start, end)) {
  237                         device_printf(dev, "device %s%d requested unsupported "
  238                             "I/O range 0x%lx-0x%lx\n", device_get_name(child),
  239                             device_get_unit(child), start, end);
  240                         return (NULL);
  241                 }
  242                 if (bootverbose)
  243                         device_printf(sc->sc_bsc.ops_pcib_sc.dev, "device "
  244                             "%s%d requested decoded I/O range 0x%lx-0x%lx\n",
  245                             device_get_name(child), device_get_unit(child),
  246                             start, end);
  247                 break;
  248 
  249         case SYS_RES_MEMORY:
  250                 if (!apb_checkrange(sc->sc_memmap, APB_MEM_SCALE, start, end)) {
  251                         device_printf(dev, "device %s%d requested unsupported "
  252                             "memory range 0x%lx-0x%lx\n",
  253                             device_get_name(child), device_get_unit(child),
  254                             start, end);
  255                         return (NULL);
  256                 }
  257                 if (bootverbose)
  258                         device_printf(sc->sc_bsc.ops_pcib_sc.dev, "device "
  259                             "%s%d requested decoded memory range 0x%lx-0x%lx\n",
  260                             device_get_name(child), device_get_unit(child),
  261                             start, end);
  262                 break;
  263 
  264         default:
  265                 break;
  266         }
  267 
  268  passup:
  269         /*
  270          * Bridge is OK decoding this resource, so pass it up.
  271          */
  272         return (bus_generic_alloc_resource(dev, child, type, rid, start, end,
  273             count, flags));
  274 }

Cache object: 82aa5411c2e01dfc7cdd41149efc0903


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.