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

Cache object: bb7f0b17a792356523d3d65fb77bf722


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