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

Cache object: 6851ab792d5e0022b3ae3a8950db2e9a


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