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/i386/i386/nexus.c

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright 1998 Massachusetts Institute of Technology
    3  *
    4  * Permission to use, copy, modify, and distribute this software and
    5  * its documentation for any purpose and without fee is hereby
    6  * granted, provided that both the above copyright notice and this
    7  * permission notice appear in all copies, that both the above
    8  * copyright notice and this permission notice appear in all
    9  * supporting documentation, and that the name of M.I.T. not be used
   10  * in advertising or publicity pertaining to distribution of the
   11  * software without specific, written prior permission.  M.I.T. makes
   12  * no representations about the suitability of this software for any
   13  * purpose.  It is provided "as is" without express or implied
   14  * warranty.
   15  *
   16  * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''.  M.I.T. DISCLAIMS
   17  * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
   18  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
   19  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
   20  * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   23  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   25  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   26  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   27  * SUCH DAMAGE.
   28  */
   29 
   30 #include <sys/cdefs.h>
   31 __FBSDID("$FreeBSD: releng/7.4/sys/i386/i386/nexus.c 212893 2010-09-20 11:09:31Z avg $");
   32 
   33 /*
   34  * This code implements a `root nexus' for Intel Architecture
   35  * machines.  The function of the root nexus is to serve as an
   36  * attachment point for both processors and buses, and to manage
   37  * resources which are common to all of them.  In particular,
   38  * this code implements the core resource managers for interrupt
   39  * requests, DMA requests (which rightfully should be a part of the
   40  * ISA code but it's easier to do it here for now), I/O port addresses,
   41  * and I/O memory address space.
   42  */
   43 
   44 #include "opt_apic.h"
   45 #include "opt_isa.h"
   46 
   47 #include <sys/param.h>
   48 #include <sys/systm.h>
   49 #include <sys/bus.h>
   50 #include <sys/kernel.h>
   51 #include <sys/malloc.h>
   52 #include <sys/module.h>
   53 #include <machine/bus.h>
   54 #include <machine/intr_machdep.h>
   55 #include <sys/rman.h>
   56 #include <sys/interrupt.h>
   57 
   58 #include <machine/vmparam.h>
   59 #include <vm/vm.h>
   60 #include <vm/pmap.h>
   61 #include <machine/pmap.h>
   62 
   63 #include <machine/resource.h>
   64 
   65 #ifdef DEV_APIC
   66 #include "pcib_if.h"
   67 #endif
   68 
   69 #ifdef DEV_ISA
   70 #include <isa/isavar.h>
   71 #ifdef PC98
   72 #include <pc98/cbus/cbus.h>
   73 #else
   74 #include <i386/isa/isa.h>
   75 #endif
   76 #endif
   77 #include <sys/rtprio.h>
   78 
   79 static MALLOC_DEFINE(M_NEXUSDEV, "nexusdev", "Nexus device");
   80 struct nexus_device {
   81         struct resource_list    nx_resources;
   82 };
   83 
   84 #define DEVTONX(dev)    ((struct nexus_device *)device_get_ivars(dev))
   85 
   86 static struct rman irq_rman, drq_rman, port_rman, mem_rman;
   87 
   88 static  int nexus_probe(device_t);
   89 static  int nexus_attach(device_t);
   90 static  int nexus_print_all_resources(device_t dev);
   91 static  int nexus_print_child(device_t, device_t);
   92 static device_t nexus_add_child(device_t bus, u_int order, const char *name,
   93                                 int unit);
   94 static  struct resource *nexus_alloc_resource(device_t, device_t, int, int *,
   95                                               u_long, u_long, u_long, u_int);
   96 #ifdef SMP
   97 static  int nexus_bind_intr(device_t, device_t, struct resource *, int);
   98 #endif
   99 static  int nexus_config_intr(device_t, int, enum intr_trigger,
  100                               enum intr_polarity);
  101 static  int nexus_describe_intr(device_t dev, device_t child,
  102                                 struct resource *irq, void *cookie,
  103                                 const char *descr);
  104 static  int nexus_activate_resource(device_t, device_t, int, int,
  105                                     struct resource *);
  106 static  int nexus_deactivate_resource(device_t, device_t, int, int,
  107                                       struct resource *);
  108 static  int nexus_release_resource(device_t, device_t, int, int,
  109                                    struct resource *);
  110 static  int nexus_setup_intr(device_t, device_t, struct resource *, int flags,
  111                              driver_filter_t filter, void (*)(void *), void *,
  112                               void **);
  113 static  int nexus_teardown_intr(device_t, device_t, struct resource *,
  114                                 void *);
  115 static struct resource_list *nexus_get_reslist(device_t dev, device_t child);
  116 static  int nexus_set_resource(device_t, device_t, int, int, u_long, u_long);
  117 static  int nexus_get_resource(device_t, device_t, int, int, u_long *, u_long *);
  118 static void nexus_delete_resource(device_t, device_t, int, int);
  119 #ifdef DEV_APIC
  120 static  int nexus_alloc_msi(device_t pcib, device_t dev, int count, int maxcount, int *irqs);
  121 static  int nexus_release_msi(device_t pcib, device_t dev, int count, int *irqs);
  122 static  int nexus_alloc_msix(device_t pcib, device_t dev, int *irq);
  123 static  int nexus_release_msix(device_t pcib, device_t dev, int irq);
  124 static  int nexus_map_msi(device_t pcib, device_t dev, int irq, uint64_t *addr, uint32_t *data);
  125 #endif
  126 
  127 static device_method_t nexus_methods[] = {
  128         /* Device interface */
  129         DEVMETHOD(device_probe,         nexus_probe),
  130         DEVMETHOD(device_attach,        nexus_attach),
  131         DEVMETHOD(device_detach,        bus_generic_detach),
  132         DEVMETHOD(device_shutdown,      bus_generic_shutdown),
  133         DEVMETHOD(device_suspend,       bus_generic_suspend),
  134         DEVMETHOD(device_resume,        bus_generic_resume),
  135 
  136         /* Bus interface */
  137         DEVMETHOD(bus_print_child,      nexus_print_child),
  138         DEVMETHOD(bus_add_child,        nexus_add_child),
  139         DEVMETHOD(bus_alloc_resource,   nexus_alloc_resource),
  140         DEVMETHOD(bus_release_resource, nexus_release_resource),
  141         DEVMETHOD(bus_activate_resource, nexus_activate_resource),
  142         DEVMETHOD(bus_deactivate_resource, nexus_deactivate_resource),
  143         DEVMETHOD(bus_setup_intr,       nexus_setup_intr),
  144         DEVMETHOD(bus_teardown_intr,    nexus_teardown_intr),
  145 #ifdef SMP
  146         DEVMETHOD(bus_bind_intr,        nexus_bind_intr),
  147 #endif
  148         DEVMETHOD(bus_config_intr,      nexus_config_intr),
  149         DEVMETHOD(bus_describe_intr,    nexus_describe_intr),
  150         DEVMETHOD(bus_get_resource_list, nexus_get_reslist),
  151         DEVMETHOD(bus_set_resource,     nexus_set_resource),
  152         DEVMETHOD(bus_get_resource,     nexus_get_resource),
  153         DEVMETHOD(bus_delete_resource,  nexus_delete_resource),
  154 
  155         /* pcib interface */
  156 #ifdef DEV_APIC
  157         DEVMETHOD(pcib_alloc_msi,       nexus_alloc_msi),
  158         DEVMETHOD(pcib_release_msi,     nexus_release_msi),
  159         DEVMETHOD(pcib_alloc_msix,      nexus_alloc_msix),
  160         DEVMETHOD(pcib_release_msix,    nexus_release_msix),
  161         DEVMETHOD(pcib_map_msi,         nexus_map_msi),
  162 #endif
  163 
  164         { 0, 0 }
  165 };
  166 
  167 static driver_t nexus_driver = {
  168         "nexus",
  169         nexus_methods,
  170         1,                      /* no softc */
  171 };
  172 static devclass_t nexus_devclass;
  173 
  174 DRIVER_MODULE(nexus, root, nexus_driver, nexus_devclass, 0, 0);
  175 
  176 static int
  177 nexus_probe(device_t dev)
  178 {
  179         int irq;
  180 
  181         device_quiet(dev);      /* suppress attach message for neatness */
  182 
  183         /*
  184          * XXX working notes:
  185          *
  186          * - IRQ resource creation should be moved to the PIC/APIC driver.
  187          * - DRQ resource creation should be moved to the DMAC driver.
  188          * - The above should be sorted to probe earlier than any child busses.
  189          *
  190          * - Leave I/O and memory creation here, as child probes may need them.
  191          *   (especially eg. ACPI)
  192          */
  193 
  194         /*
  195          * IRQ's are on the mainboard on old systems, but on the ISA part
  196          * of PCI->ISA bridges.  There would be multiple sets of IRQs on
  197          * multi-ISA-bus systems.  PCI interrupts are routed to the ISA
  198          * component, so in a way, PCI can be a partial child of an ISA bus(!).
  199          * APIC interrupts are global though.
  200          */
  201         irq_rman.rm_start = 0;
  202         irq_rman.rm_type = RMAN_ARRAY;
  203         irq_rman.rm_descr = "Interrupt request lines";
  204         irq_rman.rm_end = NUM_IO_INTS - 1;
  205         if (rman_init(&irq_rman))
  206                 panic("nexus_probe irq_rman");
  207 
  208         /*
  209          * We search for regions of existing IRQs and add those to the IRQ
  210          * resource manager.
  211          */
  212         for (irq = 0; irq < NUM_IO_INTS; irq++)
  213                 if (intr_lookup_source(irq) != NULL)
  214                         if (rman_manage_region(&irq_rman, irq, irq) != 0)
  215                                 panic("nexus_probe irq_rman add");
  216 
  217         /*
  218          * ISA DMA on PCI systems is implemented in the ISA part of each
  219          * PCI->ISA bridge and the channels can be duplicated if there are
  220          * multiple bridges.  (eg: laptops with docking stations)
  221          */
  222         drq_rman.rm_start = 0;
  223 #ifdef PC98
  224         drq_rman.rm_end = 3;
  225 #else
  226         drq_rman.rm_end = 7;
  227 #endif
  228         drq_rman.rm_type = RMAN_ARRAY;
  229         drq_rman.rm_descr = "DMA request lines";
  230         /* XXX drq 0 not available on some machines */
  231         if (rman_init(&drq_rman)
  232             || rman_manage_region(&drq_rman,
  233                                   drq_rman.rm_start, drq_rman.rm_end))
  234                 panic("nexus_probe drq_rman");
  235 
  236         /*
  237          * However, IO ports and Memory truely are global at this level,
  238          * as are APIC interrupts (however many IO APICS there turn out
  239          * to be on large systems..)
  240          */
  241         port_rman.rm_start = 0;
  242         port_rman.rm_end = 0xffff;
  243         port_rman.rm_type = RMAN_ARRAY;
  244         port_rman.rm_descr = "I/O ports";
  245         if (rman_init(&port_rman)
  246             || rman_manage_region(&port_rman, 0, 0xffff))
  247                 panic("nexus_probe port_rman");
  248 
  249         mem_rman.rm_start = 0;
  250         mem_rman.rm_end = ~0u;
  251         mem_rman.rm_type = RMAN_ARRAY;
  252         mem_rman.rm_descr = "I/O memory addresses";
  253         if (rman_init(&mem_rman)
  254             || rman_manage_region(&mem_rman, 0, ~0))
  255                 panic("nexus_probe mem_rman");
  256 
  257         return 0;
  258 }
  259 
  260 static int
  261 nexus_attach(device_t dev)
  262 {
  263 
  264         bus_generic_probe(dev);
  265         bus_generic_attach(dev);
  266         return 0;
  267 }
  268 
  269 static int
  270 nexus_print_all_resources(device_t dev)
  271 {
  272         struct  nexus_device *ndev = DEVTONX(dev);
  273         struct resource_list *rl = &ndev->nx_resources;
  274         int retval = 0;
  275 
  276         if (STAILQ_FIRST(rl))
  277                 retval += printf(" at");
  278 
  279         retval += resource_list_print_type(rl, "port", SYS_RES_IOPORT, "%#lx");
  280         retval += resource_list_print_type(rl, "iomem", SYS_RES_MEMORY, "%#lx");
  281         retval += resource_list_print_type(rl, "irq", SYS_RES_IRQ, "%ld");
  282 
  283         return retval;
  284 }
  285 
  286 static int
  287 nexus_print_child(device_t bus, device_t child)
  288 {
  289         int retval = 0;
  290 
  291         retval += bus_print_child_header(bus, child);
  292         retval += nexus_print_all_resources(child);
  293         if (device_get_flags(child))
  294                 retval += printf(" flags %#x", device_get_flags(child));
  295         retval += printf(" on motherboard\n");  /* XXX "motherboard", ick */
  296 
  297         return (retval);
  298 }
  299 
  300 static device_t
  301 nexus_add_child(device_t bus, u_int order, const char *name, int unit)
  302 {
  303         device_t                child;
  304         struct nexus_device     *ndev;
  305 
  306         ndev = malloc(sizeof(struct nexus_device), M_NEXUSDEV, M_NOWAIT|M_ZERO);
  307         if (!ndev)
  308                 return(0);
  309         resource_list_init(&ndev->nx_resources);
  310 
  311         child = device_add_child_ordered(bus, order, name, unit);
  312 
  313         /* should we free this in nexus_child_detached? */
  314         device_set_ivars(child, ndev);
  315 
  316         return(child);
  317 }
  318 
  319 /*
  320  * Allocate a resource on behalf of child.  NB: child is usually going to be a
  321  * child of one of our descendants, not a direct child of nexus0.
  322  * (Exceptions include npx.)
  323  */
  324 static struct resource *
  325 nexus_alloc_resource(device_t bus, device_t child, int type, int *rid,
  326                      u_long start, u_long end, u_long count, u_int flags)
  327 {
  328         struct nexus_device *ndev = DEVTONX(child);
  329         struct  resource *rv;
  330         struct resource_list_entry *rle;
  331         struct  rman *rm;
  332         int needactivate = flags & RF_ACTIVE;
  333 
  334         /*
  335          * If this is an allocation of the "default" range for a given RID, and
  336          * we know what the resources for this device are (ie. they aren't maintained
  337          * by a child bus), then work out the start/end values.
  338          */
  339         if ((start == 0UL) && (end == ~0UL) && (count == 1)) {
  340                 if (ndev == NULL)
  341                         return(NULL);
  342                 rle = resource_list_find(&ndev->nx_resources, type, *rid);
  343                 if (rle == NULL)
  344                         return(NULL);
  345                 start = rle->start;
  346                 end = rle->end;
  347                 count = rle->count;
  348         }
  349 
  350         flags &= ~RF_ACTIVE;
  351 
  352         switch (type) {
  353         case SYS_RES_IRQ:
  354                 rm = &irq_rman;
  355                 break;
  356 
  357         case SYS_RES_DRQ:
  358                 rm = &drq_rman;
  359                 break;
  360 
  361         case SYS_RES_IOPORT:
  362                 rm = &port_rman;
  363                 break;
  364 
  365         case SYS_RES_MEMORY:
  366                 rm = &mem_rman;
  367                 break;
  368 
  369         default:
  370                 return 0;
  371         }
  372 
  373         rv = rman_reserve_resource(rm, start, end, count, flags, child);
  374         if (rv == 0)
  375                 return 0;
  376         rman_set_rid(rv, *rid);
  377 
  378         if (needactivate) {
  379                 if (bus_activate_resource(child, type, *rid, rv)) {
  380                         rman_release_resource(rv);
  381                         return 0;
  382                 }
  383         }
  384 
  385         return rv;
  386 }
  387 
  388 static int
  389 nexus_activate_resource(device_t bus, device_t child, int type, int rid,
  390                         struct resource *r)
  391 {
  392 #ifdef PC98
  393         bus_space_handle_t bh;
  394         int error;
  395 #endif
  396         void *vaddr;
  397 
  398         /*
  399          * If this is a memory resource, map it into the kernel.
  400          */
  401         switch (type) {
  402         case SYS_RES_IOPORT:
  403 #ifdef PC98
  404                 error = i386_bus_space_handle_alloc(I386_BUS_SPACE_IO,
  405                     rman_get_start(r), rman_get_size(r), &bh);
  406                 if (error)
  407                         return (error);
  408                 rman_set_bushandle(r, bh);
  409 #else
  410                 rman_set_bushandle(r, rman_get_start(r));
  411 #endif
  412                 rman_set_bustag(r, I386_BUS_SPACE_IO);
  413                 break;
  414         case SYS_RES_MEMORY:
  415 #ifdef PC98
  416                 error = i386_bus_space_handle_alloc(I386_BUS_SPACE_MEM,
  417                     rman_get_start(r), rman_get_size(r), &bh);
  418                 if (error)
  419                         return (error);
  420 #endif
  421                 vaddr = pmap_mapdev(rman_get_start(r), rman_get_size(r));
  422                 rman_set_virtual(r, vaddr);
  423                 rman_set_bustag(r, I386_BUS_SPACE_MEM);
  424 #ifdef PC98
  425                 /* PC-98: the type of bus_space_handle_t is the structure. */
  426                 bh->bsh_base = (bus_addr_t) vaddr;
  427                 rman_set_bushandle(r, bh);
  428 #else
  429                 /* IBM-PC: the type of bus_space_handle_t is u_int */
  430                 rman_set_bushandle(r, (bus_space_handle_t) vaddr);
  431 #endif
  432         }
  433         return (rman_activate_resource(r));
  434 }
  435 
  436 static int
  437 nexus_deactivate_resource(device_t bus, device_t child, int type, int rid,
  438                           struct resource *r)
  439 {
  440 
  441         /*
  442          * If this is a memory resource, unmap it.
  443          */
  444         if (type == SYS_RES_MEMORY) {
  445                 pmap_unmapdev((vm_offset_t)rman_get_virtual(r),
  446                     rman_get_size(r));
  447         }
  448 #ifdef PC98
  449         if (type == SYS_RES_MEMORY || type == SYS_RES_IOPORT) {
  450                 bus_space_handle_t bh;
  451 
  452                 bh = rman_get_bushandle(r);
  453                 i386_bus_space_handle_free(rman_get_bustag(r), bh, bh->bsh_sz);
  454         }
  455 #endif
  456         return (rman_deactivate_resource(r));
  457 }
  458 
  459 static int
  460 nexus_release_resource(device_t bus, device_t child, int type, int rid,
  461                        struct resource *r)
  462 {
  463         if (rman_get_flags(r) & RF_ACTIVE) {
  464                 int error = bus_deactivate_resource(child, type, rid, r);
  465                 if (error)
  466                         return error;
  467         }
  468         return (rman_release_resource(r));
  469 }
  470 
  471 /*
  472  * Currently this uses the really grody interface from kern/kern_intr.c
  473  * (which really doesn't belong in kern/anything.c).  Eventually, all of
  474  * the code in kern_intr.c and machdep_intr.c should get moved here, since
  475  * this is going to be the official interface.
  476  */
  477 static int
  478 nexus_setup_intr(device_t bus, device_t child, struct resource *irq,
  479                  int flags, driver_filter_t filter, void (*ihand)(void *),
  480                  void *arg, void **cookiep)
  481 {
  482         int             error;
  483 
  484         /* somebody tried to setup an irq that failed to allocate! */
  485         if (irq == NULL)
  486                 panic("nexus_setup_intr: NULL irq resource!");
  487 
  488         *cookiep = 0;
  489         if ((rman_get_flags(irq) & RF_SHAREABLE) == 0)
  490                 flags |= INTR_EXCL;
  491 
  492         /*
  493          * We depend here on rman_activate_resource() being idempotent.
  494          */
  495         error = rman_activate_resource(irq);
  496         if (error)
  497                 return (error);
  498 
  499         error = intr_add_handler(device_get_nameunit(child),
  500             rman_get_start(irq), filter, ihand, arg, flags, cookiep);
  501 
  502         return (error);
  503 }
  504 
  505 static int
  506 nexus_teardown_intr(device_t dev, device_t child, struct resource *r, void *ih)
  507 {
  508         return (intr_remove_handler(ih));
  509 }
  510 
  511 #ifdef SMP
  512 static int
  513 nexus_bind_intr(device_t dev, device_t child, struct resource *irq, int cpu)
  514 {
  515         return (intr_bind(rman_get_start(irq), cpu));
  516 }
  517 #endif
  518 
  519 static int
  520 nexus_config_intr(device_t dev, int irq, enum intr_trigger trig,
  521     enum intr_polarity pol)
  522 {
  523         return (intr_config_intr(irq, trig, pol));
  524 }
  525 
  526 static int
  527 nexus_describe_intr(device_t dev, device_t child, struct resource *irq,
  528     void *cookie, const char *descr)
  529 {
  530 
  531         return (intr_describe(rman_get_start(irq), cookie, descr));
  532 }
  533 
  534 static struct resource_list *
  535 nexus_get_reslist(device_t dev, device_t child)
  536 {
  537         struct nexus_device *ndev = DEVTONX(child);
  538 
  539         return (&ndev->nx_resources);
  540 }
  541 
  542 static int
  543 nexus_set_resource(device_t dev, device_t child, int type, int rid, u_long start, u_long count)
  544 {
  545         struct nexus_device     *ndev = DEVTONX(child);
  546         struct resource_list    *rl = &ndev->nx_resources;
  547 
  548         /* XXX this should return a success/failure indicator */
  549         resource_list_add(rl, type, rid, start, start + count - 1, count);
  550         return(0);
  551 }
  552 
  553 static int
  554 nexus_get_resource(device_t dev, device_t child, int type, int rid, u_long *startp, u_long *countp)
  555 {
  556         struct nexus_device     *ndev = DEVTONX(child);
  557         struct resource_list    *rl = &ndev->nx_resources;
  558         struct resource_list_entry *rle;
  559 
  560         rle = resource_list_find(rl, type, rid);
  561         if (!rle)
  562                 return(ENOENT);
  563         if (startp)
  564                 *startp = rle->start;
  565         if (countp)
  566                 *countp = rle->count;
  567         return(0);
  568 }
  569 
  570 static void
  571 nexus_delete_resource(device_t dev, device_t child, int type, int rid)
  572 {
  573         struct nexus_device     *ndev = DEVTONX(child);
  574         struct resource_list    *rl = &ndev->nx_resources;
  575 
  576         resource_list_delete(rl, type, rid);
  577 }
  578 
  579 /* Called from the MSI code to add new IRQs to the IRQ rman. */
  580 void
  581 nexus_add_irq(u_long irq)
  582 {
  583 
  584         if (rman_manage_region(&irq_rman, irq, irq) != 0)
  585                 panic("%s: failed", __func__);
  586 }
  587 
  588 #ifdef DEV_APIC
  589 static int
  590 nexus_alloc_msix(device_t pcib, device_t dev, int *irq)
  591 {
  592 
  593         return (msix_alloc(dev, irq));
  594 }
  595 
  596 static int
  597 nexus_release_msix(device_t pcib, device_t dev, int irq)
  598 {
  599 
  600         return (msix_release(irq));
  601 }
  602 
  603 static int
  604 nexus_alloc_msi(device_t pcib, device_t dev, int count, int maxcount, int *irqs)
  605 {
  606 
  607         return (msi_alloc(dev, count, maxcount, irqs));
  608 }
  609 
  610 static int
  611 nexus_release_msi(device_t pcib, device_t dev, int count, int *irqs)
  612 {
  613 
  614         return (msi_release(irqs, count));
  615 }
  616 
  617 static int
  618 nexus_map_msi(device_t pcib, device_t dev, int irq, uint64_t *addr, uint32_t *data)
  619 {
  620 
  621         return (msi_map(irq, addr, data));
  622 }
  623 #endif
  624 
  625 /* Placeholder for system RAM. */
  626 static void
  627 ram_identify(driver_t *driver, device_t parent)
  628 {
  629 
  630         if (resource_disabled("ram", 0))
  631                 return; 
  632         if (BUS_ADD_CHILD(parent, 0, "ram", 0) == NULL)
  633                 panic("ram_identify");
  634 }
  635 
  636 static int
  637 ram_probe(device_t dev)
  638 {
  639 
  640         device_quiet(dev);
  641         device_set_desc(dev, "System RAM");
  642         return (0);
  643 }
  644 
  645 static int
  646 ram_attach(device_t dev)
  647 {
  648         struct resource *res;
  649         vm_paddr_t *p;
  650         int error, i, rid;
  651 
  652         /*
  653          * We use the dump_avail[] array rather than phys_avail[] for
  654          * the memory map as phys_avail[] contains holes for kernel
  655          * memory, page 0, the message buffer, and the dcons buffer.
  656          * We test the end address in the loop instead of the start
  657          * since the start address for the first segment is 0.
  658          *
  659          * XXX: It would be preferable to use the SMAP if it exists
  660          * instead since if the SMAP is very fragmented we may not
  661          * include some memory regions in dump_avail[] and phys_avail[].
  662          */
  663         for (i = 0, p = dump_avail; p[1] != 0; i++, p += 2) {
  664                 rid = i;
  665 #ifdef PAE
  666                 /*
  667                  * Resources use long's to track resources, so we can't
  668                  * include memory regions above 4GB.
  669                  */
  670                 if (p[0] >= ~0ul)
  671                         break;
  672 #endif
  673                 error = bus_set_resource(dev, SYS_RES_MEMORY, rid, p[0],
  674                     p[1] - p[0]);
  675                 if (error)
  676                         panic("ram_attach: resource %d failed set with %d", i,
  677                             error);
  678                 res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, 0);
  679                 if (res == NULL)
  680                         panic("ram_attach: resource %d failed to attach", i);
  681         }
  682         return (0);
  683 }
  684 
  685 static device_method_t ram_methods[] = {
  686         /* Device interface */
  687         DEVMETHOD(device_identify,      ram_identify),
  688         DEVMETHOD(device_probe,         ram_probe),
  689         DEVMETHOD(device_attach,        ram_attach),
  690         { 0, 0 }
  691 };
  692 
  693 static driver_t ram_driver = {
  694         "ram",
  695         ram_methods,
  696         1,              /* no softc */
  697 };
  698 
  699 static devclass_t ram_devclass;
  700 
  701 DRIVER_MODULE(ram, nexus, ram_driver, ram_devclass, 0, 0);
  702 
  703 #ifdef DEV_ISA
  704 /*
  705  * Placeholder which claims PnP 'devices' which describe system
  706  * resources.
  707  */
  708 static struct isa_pnp_id sysresource_ids[] = {
  709         { 0x010cd041 /* PNP0c01 */, "System Memory" },
  710         { 0x020cd041 /* PNP0c02 */, "System Resource" },
  711         { 0 }
  712 };
  713 
  714 static int
  715 sysresource_probe(device_t dev)
  716 {
  717         int     result;
  718 
  719         if ((result = ISA_PNP_PROBE(device_get_parent(dev), dev, sysresource_ids)) <= 0) {
  720                 device_quiet(dev);
  721         }
  722         return(result);
  723 }
  724 
  725 static int
  726 sysresource_attach(device_t dev)
  727 {
  728         return(0);
  729 }
  730 
  731 static device_method_t sysresource_methods[] = {
  732         /* Device interface */
  733         DEVMETHOD(device_probe,         sysresource_probe),
  734         DEVMETHOD(device_attach,        sysresource_attach),
  735         DEVMETHOD(device_detach,        bus_generic_detach),
  736         DEVMETHOD(device_shutdown,      bus_generic_shutdown),
  737         DEVMETHOD(device_suspend,       bus_generic_suspend),
  738         DEVMETHOD(device_resume,        bus_generic_resume),
  739         { 0, 0 }
  740 };
  741 
  742 static driver_t sysresource_driver = {
  743         "sysresource",
  744         sysresource_methods,
  745         1,              /* no softc */
  746 };
  747 
  748 static devclass_t sysresource_devclass;
  749 
  750 DRIVER_MODULE(sysresource, isa, sysresource_driver, sysresource_devclass, 0, 0);
  751 #endif /* DEV_ISA */

Cache object: df699b6431b1edc5bb963549afcf8a7a


[ 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.