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/legacy.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  * $FreeBSD: releng/5.0/sys/i386/i386/legacy.c 104224 2002-09-30 18:47:11Z jhb $
   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 EISA or ISA on a pci bridge, create some
  152          * connection points now so they show up "on motherboard".
  153          */
  154         if (!devclass_get_device(devclass_find("eisa"), 0)) {
  155                 child = BUS_ADD_CHILD(dev, 0, "eisa", 0);
  156                 if (child == NULL)
  157                         panic("legacy_attach eisa");
  158                 device_probe_and_attach(child);
  159         }
  160         if (!devclass_get_device(devclass_find("mca"), 0)) {
  161                 child = BUS_ADD_CHILD(dev, 0, "mca", 0);
  162                 if (child == 0)
  163                         panic("legacy_probe mca");
  164                 device_probe_and_attach(child);
  165         }
  166         if (!devclass_get_device(devclass_find("isa"), 0)) {
  167                 child = BUS_ADD_CHILD(dev, 0, "isa", 0);
  168                 if (child == NULL)
  169                         panic("legacy_attach isa");
  170                 device_probe_and_attach(child);
  171         }
  172 
  173         return 0;
  174 }
  175 
  176 static int
  177 legacy_print_all_resources(device_t dev)
  178 {
  179         struct legacy_device *atdev = DEVTOAT(dev);
  180         struct resource_list *rl = &atdev->lg_resources;
  181         int retval = 0;
  182 
  183         if (SLIST_FIRST(rl) || atdev->lg_pcibus != -1)
  184                 retval += printf(" at");
  185         
  186         retval += resource_list_print_type(rl, "port", SYS_RES_IOPORT, "%#lx");
  187         retval += resource_list_print_type(rl, "iomem", SYS_RES_MEMORY, "%#lx");
  188         retval += resource_list_print_type(rl, "irq", SYS_RES_IRQ, "%ld");
  189 
  190         return retval;
  191 }
  192 
  193 static int
  194 legacy_print_child(device_t bus, device_t child)
  195 {
  196         struct legacy_device *atdev = DEVTOAT(child);
  197         int retval = 0;
  198 
  199         retval += bus_print_child_header(bus, child);
  200         retval += legacy_print_all_resources(child);
  201         if (atdev->lg_pcibus != -1)
  202                 retval += printf(" pcibus %d", atdev->lg_pcibus);
  203         retval += printf(" on motherboard\n");  /* XXX "motherboard", ick */
  204 
  205         return (retval);
  206 }
  207 
  208 static device_t
  209 legacy_add_child(device_t bus, int order, const char *name, int unit)
  210 {
  211         device_t child;
  212         struct legacy_device *atdev;
  213 
  214         atdev = malloc(sizeof(struct legacy_device), M_LEGACYDEV,
  215             M_NOWAIT | M_ZERO);
  216         if (!atdev)
  217                 return(0);
  218         resource_list_init(&atdev->lg_resources);
  219         atdev->lg_pcibus = -1;
  220 
  221         child = device_add_child_ordered(bus, order, name, unit); 
  222 
  223         /* should we free this in legacy_child_detached? */
  224         device_set_ivars(child, atdev);
  225 
  226         return(child);
  227 }
  228 
  229 static int
  230 legacy_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
  231 {
  232         struct legacy_device *atdev = DEVTOAT(child);
  233 
  234         switch (which) {
  235         case LEGACY_IVAR_PCIBUS:
  236                 *result = atdev->lg_pcibus;
  237                 break;
  238         default:
  239                 return ENOENT;
  240         }
  241         return 0;
  242 }
  243         
  244 
  245 static int
  246 legacy_write_ivar(device_t dev, device_t child, int which, uintptr_t value)
  247 {
  248         struct legacy_device *atdev = DEVTOAT(child);
  249 
  250         switch (which) {
  251         case LEGACY_IVAR_PCIBUS:
  252                 atdev->lg_pcibus = value;
  253                 break;
  254         default:
  255                 return ENOENT;
  256         }
  257         return 0;
  258 }
  259 
  260 
  261 static struct resource *
  262 legacy_alloc_resource(device_t bus, device_t child, int type, int *rid,
  263                      u_long start, u_long end, u_long count, u_int flags)
  264 {
  265         struct legacy_device *atdev = DEVTOAT(child);
  266         struct resource_list *rl = &atdev->lg_resources;
  267 
  268         return (resource_list_alloc(rl, bus, child, type, rid, start, end,
  269                     count, flags));
  270 }
  271 
  272 static int
  273 legacy_release_resource(device_t bus, device_t child, int type, int rid,
  274                        struct resource *r)
  275 {
  276         struct legacy_device *atdev = DEVTOAT(child);
  277         struct resource_list *rl = &atdev->lg_resources;
  278 
  279         return (resource_list_release(rl, bus, child, type, rid, r));
  280 }
  281 
  282 static int
  283 legacy_set_resource(device_t dev, device_t child, int type, int rid,
  284     u_long start, u_long count)
  285 {
  286         struct legacy_device *atdev = DEVTOAT(child);
  287         struct resource_list *rl = &atdev->lg_resources;
  288 
  289         resource_list_add(rl, type, rid, start, start + count - 1, count);
  290         return(0);
  291 }
  292 
  293 static int
  294 legacy_get_resource(device_t dev, device_t child, int type, int rid,
  295     u_long *startp, u_long *countp)
  296 {
  297         struct legacy_device *atdev = DEVTOAT(child);
  298         struct resource_list *rl = &atdev->lg_resources;
  299         struct resource_list_entry *rle;
  300 
  301         rle = resource_list_find(rl, type, rid);
  302         if (!rle)
  303                 return(ENOENT);
  304         if (startp)
  305                 *startp = rle->start;
  306         if (countp)
  307                 *countp = rle->count;
  308         return(0);
  309 }
  310 
  311 static void
  312 legacy_delete_resource(device_t dev, device_t child, int type, int rid)
  313 {
  314         struct legacy_device *atdev = DEVTOAT(child);
  315         struct resource_list *rl = &atdev->lg_resources;
  316 
  317         resource_list_delete(rl, type, rid);
  318 }

Cache object: 5cf738c6e18155d20e4120a9cfc835e2


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