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

Cache object: 05e79874e405642b61dd2943c62decf1


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