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/legacy.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  * $FreeBSD: releng/5.1/sys/amd64/amd64/legacy.c 114349 2003-05-01 01:05:25Z peter $
   30  */
   31 
   32 /*
   33  * This code implements a system driver for legacy systems that do not
   34  * support ACPI or when ACPI support is not present in the kernel.
   35  */
   36 
   37 #include <sys/param.h>
   38 #include <sys/systm.h>
   39 #include <sys/bus.h>
   40 #include <sys/kernel.h>
   41 #include <sys/malloc.h>
   42 #include <machine/bus.h>
   43 #include <sys/rman.h>
   44 
   45 #include <machine/legacyvar.h>
   46 #include <machine/resource.h>
   47 
   48 static MALLOC_DEFINE(M_LEGACYDEV, "legacydrv", "legacy system device");
   49 struct legacy_device {
   50         struct resource_list    lg_resources;
   51         int                     lg_pcibus;
   52 };
   53 
   54 #define DEVTOAT(dev)    ((struct legacy_device *)device_get_ivars(dev))
   55 
   56 static void legacy_identify(driver_t *driver, device_t parent);
   57 static  int legacy_probe(device_t);
   58 static  int legacy_attach(device_t);
   59 static  int legacy_print_child(device_t, device_t);
   60 static device_t legacy_add_child(device_t bus, int order, const char *name,
   61                                 int unit);
   62 static  struct resource *legacy_alloc_resource(device_t, device_t, int, int *,
   63                                               u_long, u_long, u_long, u_int);
   64 static  int legacy_read_ivar(device_t, device_t, int, uintptr_t *);
   65 static  int legacy_write_ivar(device_t, device_t, int, uintptr_t);
   66 static  int legacy_release_resource(device_t, device_t, int, int,
   67                                    struct resource *);
   68 static  int legacy_set_resource(device_t, device_t, int, int, u_long, u_long);
   69 static  int legacy_get_resource(device_t, device_t, int, int, u_long *, u_long *);
   70 static void legacy_delete_resource(device_t, device_t, int, int);
   71 
   72 static device_method_t legacy_methods[] = {
   73         /* Device interface */
   74         DEVMETHOD(device_identify,      legacy_identify),
   75         DEVMETHOD(device_probe,         legacy_probe),
   76         DEVMETHOD(device_attach,        legacy_attach),
   77         DEVMETHOD(device_detach,        bus_generic_detach),
   78         DEVMETHOD(device_shutdown,      bus_generic_shutdown),
   79         DEVMETHOD(device_suspend,       bus_generic_suspend),
   80         DEVMETHOD(device_resume,        bus_generic_resume),
   81 
   82         /* Bus interface */
   83         DEVMETHOD(bus_print_child,      legacy_print_child),
   84         DEVMETHOD(bus_add_child,        legacy_add_child),
   85         DEVMETHOD(bus_read_ivar,        legacy_read_ivar),
   86         DEVMETHOD(bus_write_ivar,       legacy_write_ivar),
   87         DEVMETHOD(bus_set_resource,     legacy_set_resource),
   88         DEVMETHOD(bus_get_resource,     legacy_get_resource),
   89         DEVMETHOD(bus_alloc_resource,   legacy_alloc_resource),
   90         DEVMETHOD(bus_release_resource, legacy_release_resource),
   91         DEVMETHOD(bus_delete_resource,  legacy_delete_resource),
   92         DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
   93         DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
   94         DEVMETHOD(bus_setup_intr,       bus_generic_setup_intr),
   95         DEVMETHOD(bus_teardown_intr,    bus_generic_teardown_intr),
   96 
   97         { 0, 0 }
   98 };
   99 
  100 static driver_t legacy_driver = {
  101         "legacy",
  102         legacy_methods,
  103         1,                      /* no softc */
  104 };
  105 static devclass_t legacy_devclass;
  106 
  107 DRIVER_MODULE(legacy, nexus, legacy_driver, legacy_devclass, 0, 0);
  108 
  109 static void
  110 legacy_identify(driver_t *driver, device_t parent)
  111 {
  112 
  113         /*
  114          * Add child device with order of 1 so it gets probed
  115          * after ACPI (which is at order 0.
  116          */
  117         if (BUS_ADD_CHILD(parent, 1, "legacy", 0) == NULL)
  118                 panic("legacy: could not attach");
  119 }
  120 
  121 static int
  122 legacy_probe(device_t dev)
  123 {
  124         device_t acpi;
  125 
  126         /*
  127          * Fail to probe if ACPI is ok.
  128          */
  129         acpi = devclass_get_device(devclass_find("acpi"), 0);
  130         if (acpi != NULL && device_is_alive(acpi))
  131                 return (ENXIO);
  132         device_set_desc(dev, "legacy system");
  133         device_quiet(dev);
  134         return (0);
  135 }
  136 
  137 static int
  138 legacy_attach(device_t dev)
  139 {
  140         device_t        child;
  141 
  142         /*
  143          * First, let our child driver's identify any child devices that
  144          * they can find.  Once that is done attach any devices that we
  145          * found.
  146          */
  147         bus_generic_probe(dev);
  148         bus_generic_attach(dev);
  149 
  150         /*
  151          * If we didn't see ISA on a pci bridge, create some
  152          * connection points now so it shows up "on motherboard".
  153          */
  154         if (!devclass_get_device(devclass_find("isa"), 0)) {
  155                 child = BUS_ADD_CHILD(dev, 0, "isa", 0);
  156                 if (child == NULL)
  157                         panic("legacy_attach isa");
  158                 device_probe_and_attach(child);
  159         }
  160 
  161         return 0;
  162 }
  163 
  164 static int
  165 legacy_print_all_resources(device_t dev)
  166 {
  167         struct legacy_device *atdev = DEVTOAT(dev);
  168         struct resource_list *rl = &atdev->lg_resources;
  169         int retval = 0;
  170 
  171         if (SLIST_FIRST(rl) || atdev->lg_pcibus != -1)
  172                 retval += printf(" at");
  173         
  174         retval += resource_list_print_type(rl, "port", SYS_RES_IOPORT, "%#lx");
  175         retval += resource_list_print_type(rl, "iomem", SYS_RES_MEMORY, "%#lx");
  176         retval += resource_list_print_type(rl, "irq", SYS_RES_IRQ, "%ld");
  177 
  178         return retval;
  179 }
  180 
  181 static int
  182 legacy_print_child(device_t bus, device_t child)
  183 {
  184         struct legacy_device *atdev = DEVTOAT(child);
  185         int retval = 0;
  186 
  187         retval += bus_print_child_header(bus, child);
  188         retval += legacy_print_all_resources(child);
  189         if (atdev->lg_pcibus != -1)
  190                 retval += printf(" pcibus %d", atdev->lg_pcibus);
  191         retval += printf(" on motherboard\n");  /* XXX "motherboard", ick */
  192 
  193         return (retval);
  194 }
  195 
  196 static device_t
  197 legacy_add_child(device_t bus, int order, const char *name, int unit)
  198 {
  199         device_t child;
  200         struct legacy_device *atdev;
  201 
  202         atdev = malloc(sizeof(struct legacy_device), M_LEGACYDEV,
  203             M_NOWAIT | M_ZERO);
  204         if (!atdev)
  205                 return(0);
  206         resource_list_init(&atdev->lg_resources);
  207         atdev->lg_pcibus = -1;
  208 
  209         child = device_add_child_ordered(bus, order, name, unit); 
  210 
  211         /* should we free this in legacy_child_detached? */
  212         device_set_ivars(child, atdev);
  213 
  214         return(child);
  215 }
  216 
  217 static int
  218 legacy_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
  219 {
  220         struct legacy_device *atdev = DEVTOAT(child);
  221 
  222         switch (which) {
  223         case LEGACY_IVAR_PCIBUS:
  224                 *result = atdev->lg_pcibus;
  225                 break;
  226         default:
  227                 return ENOENT;
  228         }
  229         return 0;
  230 }
  231         
  232 
  233 static int
  234 legacy_write_ivar(device_t dev, device_t child, int which, uintptr_t value)
  235 {
  236         struct legacy_device *atdev = DEVTOAT(child);
  237 
  238         switch (which) {
  239         case LEGACY_IVAR_PCIBUS:
  240                 atdev->lg_pcibus = value;
  241                 break;
  242         default:
  243                 return ENOENT;
  244         }
  245         return 0;
  246 }
  247 
  248 
  249 static struct resource *
  250 legacy_alloc_resource(device_t bus, device_t child, int type, int *rid,
  251                      u_long start, u_long end, u_long count, u_int flags)
  252 {
  253         struct legacy_device *atdev = DEVTOAT(child);
  254         struct resource_list *rl = &atdev->lg_resources;
  255 
  256         return (resource_list_alloc(rl, bus, child, type, rid, start, end,
  257                     count, flags));
  258 }
  259 
  260 static int
  261 legacy_release_resource(device_t bus, device_t child, int type, int rid,
  262                        struct resource *r)
  263 {
  264         struct legacy_device *atdev = DEVTOAT(child);
  265         struct resource_list *rl = &atdev->lg_resources;
  266 
  267         return (resource_list_release(rl, bus, child, type, rid, r));
  268 }
  269 
  270 static int
  271 legacy_set_resource(device_t dev, device_t child, int type, int rid,
  272     u_long start, u_long count)
  273 {
  274         struct legacy_device *atdev = DEVTOAT(child);
  275         struct resource_list *rl = &atdev->lg_resources;
  276 
  277         resource_list_add(rl, type, rid, start, start + count - 1, count);
  278         return(0);
  279 }
  280 
  281 static int
  282 legacy_get_resource(device_t dev, device_t child, int type, int rid,
  283     u_long *startp, u_long *countp)
  284 {
  285         struct legacy_device *atdev = DEVTOAT(child);
  286         struct resource_list *rl = &atdev->lg_resources;
  287         struct resource_list_entry *rle;
  288 
  289         rle = resource_list_find(rl, type, rid);
  290         if (!rle)
  291                 return(ENOENT);
  292         if (startp)
  293                 *startp = rle->start;
  294         if (countp)
  295                 *countp = rle->count;
  296         return(0);
  297 }
  298 
  299 static void
  300 legacy_delete_resource(device_t dev, device_t child, int type, int rid)
  301 {
  302         struct legacy_device *atdev = DEVTOAT(child);
  303         struct resource_list *rl = &atdev->lg_resources;
  304 
  305         resource_list_delete(rl, type, rid);
  306 }

Cache object: aeda9468c2ffead25ca6baa6de123bc0


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