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.3/sys/i386/i386/legacy.c 133886 2004-08-16 21:55:29Z gibbs $");
   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 <sys/module.h>
   44 #include <machine/bus.h>
   45 #include <sys/pcpu.h>
   46 #include <sys/rman.h>
   47 #include <sys/smp.h>
   48 
   49 #include "opt_mca.h"
   50 #ifdef DEV_MCA
   51 #include <i386/bios/mca_machdep.h>
   52 #endif
   53 
   54 #include <machine/legacyvar.h>
   55 #include <machine/resource.h>
   56 
   57 static MALLOC_DEFINE(M_LEGACYDEV, "legacydrv", "legacy system device");
   58 struct legacy_device {
   59         int                     lg_pcibus;
   60 };
   61 
   62 #define DEVTOAT(dev)    ((struct legacy_device *)device_get_ivars(dev))
   63 
   64 static void legacy_identify(driver_t *driver, device_t parent);
   65 static  int legacy_probe(device_t);
   66 static  int legacy_attach(device_t);
   67 static  int legacy_print_child(device_t, device_t);
   68 static device_t legacy_add_child(device_t bus, int order, const char *name,
   69                                 int unit);
   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 
   73 static device_method_t legacy_methods[] = {
   74         /* Device interface */
   75         DEVMETHOD(device_identify,      legacy_identify),
   76         DEVMETHOD(device_probe,         legacy_probe),
   77         DEVMETHOD(device_attach,        legacy_attach),
   78         DEVMETHOD(device_detach,        bus_generic_detach),
   79         DEVMETHOD(device_shutdown,      bus_generic_shutdown),
   80         DEVMETHOD(device_suspend,       bus_generic_suspend),
   81         DEVMETHOD(device_resume,        bus_generic_resume),
   82 
   83         /* Bus interface */
   84         DEVMETHOD(bus_print_child,      legacy_print_child),
   85         DEVMETHOD(bus_add_child,        legacy_add_child),
   86         DEVMETHOD(bus_read_ivar,        legacy_read_ivar),
   87         DEVMETHOD(bus_write_ivar,       legacy_write_ivar),
   88         DEVMETHOD(bus_alloc_resource,   bus_generic_alloc_resource),
   89         DEVMETHOD(bus_release_resource, bus_generic_release_resource),
   90         DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
   91         DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
   92         DEVMETHOD(bus_setup_intr,       bus_generic_setup_intr),
   93         DEVMETHOD(bus_teardown_intr,    bus_generic_teardown_intr),
   94 
   95         { 0, 0 }
   96 };
   97 
   98 static driver_t legacy_driver = {
   99         "legacy",
  100         legacy_methods,
  101         1,                      /* no softc */
  102 };
  103 static devclass_t legacy_devclass;
  104 
  105 DRIVER_MODULE(legacy, nexus, legacy_driver, legacy_devclass, 0, 0);
  106 
  107 static void
  108 legacy_identify(driver_t *driver, device_t parent)
  109 {
  110 
  111         /*
  112          * Add child device with order of 1 so it gets probed
  113          * after ACPI (which is at order 0.
  114          */
  115         if (BUS_ADD_CHILD(parent, 1, "legacy", 0) == NULL)
  116                 panic("legacy: could not attach");
  117 }
  118 
  119 static int
  120 legacy_probe(device_t dev)
  121 {
  122         device_t acpi;
  123 
  124         /*
  125          * Fail to probe if ACPI is ok.
  126          */
  127         acpi = devclass_get_device(devclass_find("acpi"), 0);
  128         if (acpi != NULL && device_is_alive(acpi))
  129                 return (ENXIO);
  130         device_set_desc(dev, "legacy system");
  131         device_quiet(dev);
  132         return (0);
  133 }
  134 
  135 static int
  136 legacy_attach(device_t dev)
  137 {
  138         device_t child;
  139         int i;
  140         struct pcpu *pc;
  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         /* Attach CPU pseudo-driver. */
  151         if (!devclass_get_device(devclass_find("cpu"), 0)) {
  152                 for (i = 0; i <= mp_maxid; i++)
  153                         if (!CPU_ABSENT(i)) {
  154                                 pc = pcpu_find(i);
  155                                 KASSERT(pc != NULL, ("pcpu_find failed"));
  156                                 child = BUS_ADD_CHILD(dev, 0, "cpu", i);
  157                                 if (child == NULL)
  158                                         panic("legacy_attach cpu");
  159                                 device_probe_and_attach(child);
  160                                 pc->pc_device = child;
  161                                 device_set_ivars(child, pc);
  162                         }
  163         }
  164 
  165         /*
  166          * If we didn't see EISA or ISA on a pci bridge, create some
  167          * connection points now so they show up "on motherboard".
  168          */
  169         if (!devclass_get_device(devclass_find("eisa"), 0)) {
  170                 child = BUS_ADD_CHILD(dev, 0, "eisa", 0);
  171                 if (child == NULL)
  172                         panic("legacy_attach eisa");
  173                 device_probe_and_attach(child);
  174         }
  175 #ifdef DEV_MCA
  176         if (MCA_system && !devclass_get_device(devclass_find("mca"), 0)) {
  177                 child = BUS_ADD_CHILD(dev, 0, "mca", 0);
  178                 if (child == 0)
  179                         panic("legacy_probe mca");
  180                 device_probe_and_attach(child);
  181         }
  182 #endif
  183         if (!devclass_get_device(devclass_find("isa"), 0)) {
  184                 child = BUS_ADD_CHILD(dev, 0, "isa", 0);
  185                 if (child == NULL)
  186                         panic("legacy_attach isa");
  187                 device_probe_and_attach(child);
  188         }
  189 
  190         return 0;
  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         if (atdev->lg_pcibus != -1)
  201                 retval += printf(" pcibus %d", atdev->lg_pcibus);
  202         retval += printf(" on motherboard\n");  /* XXX "motherboard", ick */
  203 
  204         return (retval);
  205 }
  206 
  207 static device_t
  208 legacy_add_child(device_t bus, int order, const char *name, int unit)
  209 {
  210         device_t child;
  211         struct legacy_device *atdev;
  212 
  213         atdev = malloc(sizeof(struct legacy_device), M_LEGACYDEV,
  214             M_NOWAIT | M_ZERO);
  215         if (atdev == NULL)
  216                 return(NULL);
  217         atdev->lg_pcibus = -1;
  218 
  219         child = device_add_child_ordered(bus, order, name, unit);
  220         if (child == NULL)
  221                 free(atdev, M_LEGACYDEV);
  222         else
  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  * Legacy CPU attachment when ACPI is not available.  Drivers like
  262  * cpufreq(4) hang off this.
  263  */
  264 static int      cpu_read_ivar(device_t dev, device_t child, int index,
  265                     uintptr_t *result);
  266 
  267 static device_method_t cpu_methods[] = {
  268         /* Device interface */
  269         DEVMETHOD(device_probe,         bus_generic_probe),
  270         DEVMETHOD(device_attach,        bus_generic_attach),
  271         DEVMETHOD(device_detach,        bus_generic_detach),
  272         DEVMETHOD(device_shutdown,      bus_generic_shutdown),
  273         DEVMETHOD(device_suspend,       bus_generic_suspend),
  274         DEVMETHOD(device_resume,        bus_generic_resume),
  275 
  276         /* Bus interface */
  277         DEVMETHOD(bus_read_ivar,        cpu_read_ivar),
  278         DEVMETHOD(bus_print_child,      bus_generic_print_child),
  279         DEVMETHOD(bus_alloc_resource,   bus_generic_alloc_resource),
  280         DEVMETHOD(bus_release_resource, bus_generic_release_resource),
  281         DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
  282         DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
  283         DEVMETHOD(bus_setup_intr,       bus_generic_setup_intr),
  284         DEVMETHOD(bus_teardown_intr,    bus_generic_teardown_intr),
  285 
  286         { 0, 0 }
  287 };
  288 
  289 static driver_t cpu_driver = {
  290         "cpu",
  291         cpu_methods,
  292         1,              /* no softc */
  293 };
  294 static devclass_t cpu_devclass;
  295 DRIVER_MODULE(cpu, legacy, cpu_driver, cpu_devclass, 0, 0);
  296 
  297 static int
  298 cpu_read_ivar(device_t dev, device_t child, int index, uintptr_t *result)
  299 {
  300         struct pcpu *pc;
  301 
  302         if (index != 0)
  303                 return (ENOENT);
  304         pc = device_get_ivars(child);
  305         if (pc == NULL)
  306                 return (ENOENT);
  307         *result = (uintptr_t)pc;
  308         return (0);
  309 }

Cache object: 7980e0599a1feb58196c0ca69b848e90


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