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

Cache object: 8dcf9ae62aadf82dbc5c177082d92de9


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