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-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 
   30 #include <sys/cdefs.h>
   31 __FBSDID("$FreeBSD: releng/6.0/sys/i386/i386/legacy.c 141942 2005-02-15 07:21:20Z njl $");
   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/cpu.h>
   42 #include <sys/kernel.h>
   43 #include <sys/malloc.h>
   44 #include <sys/module.h>
   45 #include <machine/bus.h>
   46 #include <sys/pcpu.h>
   47 #include <sys/rman.h>
   48 #include <sys/smp.h>
   49 
   50 #include "opt_mca.h"
   51 #ifdef DEV_MCA
   52 #include <i386/bios/mca_machdep.h>
   53 #endif
   54 
   55 #include <machine/legacyvar.h>
   56 #include <machine/resource.h>
   57 
   58 static MALLOC_DEFINE(M_LEGACYDEV, "legacydrv", "legacy system device");
   59 struct legacy_device {
   60         int                     lg_pcibus;
   61 };
   62 
   63 #define DEVTOAT(dev)    ((struct legacy_device *)device_get_ivars(dev))
   64 
   65 static void legacy_identify(driver_t *driver, device_t parent);
   66 static  int legacy_probe(device_t);
   67 static  int legacy_attach(device_t);
   68 static  int legacy_print_child(device_t, device_t);
   69 static device_t legacy_add_child(device_t bus, int order, const char *name,
   70                                 int unit);
   71 static  int legacy_read_ivar(device_t, device_t, int, uintptr_t *);
   72 static  int legacy_write_ivar(device_t, device_t, int, uintptr_t);
   73 
   74 static device_method_t legacy_methods[] = {
   75         /* Device interface */
   76         DEVMETHOD(device_identify,      legacy_identify),
   77         DEVMETHOD(device_probe,         legacy_probe),
   78         DEVMETHOD(device_attach,        legacy_attach),
   79         DEVMETHOD(device_detach,        bus_generic_detach),
   80         DEVMETHOD(device_shutdown,      bus_generic_shutdown),
   81         DEVMETHOD(device_suspend,       bus_generic_suspend),
   82         DEVMETHOD(device_resume,        bus_generic_resume),
   83 
   84         /* Bus interface */
   85         DEVMETHOD(bus_print_child,      legacy_print_child),
   86         DEVMETHOD(bus_add_child,        legacy_add_child),
   87         DEVMETHOD(bus_read_ivar,        legacy_read_ivar),
   88         DEVMETHOD(bus_write_ivar,       legacy_write_ivar),
   89         DEVMETHOD(bus_alloc_resource,   bus_generic_alloc_resource),
   90         DEVMETHOD(bus_release_resource, bus_generic_release_resource),
   91         DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
   92         DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
   93         DEVMETHOD(bus_setup_intr,       bus_generic_setup_intr),
   94         DEVMETHOD(bus_teardown_intr,    bus_generic_teardown_intr),
   95 
   96         { 0, 0 }
   97 };
   98 
   99 static driver_t legacy_driver = {
  100         "legacy",
  101         legacy_methods,
  102         1,                      /* no softc */
  103 };
  104 static devclass_t legacy_devclass;
  105 
  106 DRIVER_MODULE(legacy, nexus, legacy_driver, legacy_devclass, 0, 0);
  107 
  108 static void
  109 legacy_identify(driver_t *driver, device_t parent)
  110 {
  111 
  112         /*
  113          * Add child device with order of 1 so it gets probed
  114          * after ACPI (which is at order 0.
  115          */
  116         if (BUS_ADD_CHILD(parent, 1, "legacy", 0) == NULL)
  117                 panic("legacy: could not attach");
  118 }
  119 
  120 static int
  121 legacy_probe(device_t dev)
  122 {
  123         device_t acpi;
  124 
  125         /*
  126          * Fail to probe if ACPI is ok.
  127          */
  128         acpi = devclass_get_device(devclass_find("acpi"), 0);
  129         if (acpi != NULL && device_is_alive(acpi))
  130                 return (ENXIO);
  131         device_set_desc(dev, "legacy system");
  132         device_quiet(dev);
  133         return (0);
  134 }
  135 
  136 static int
  137 legacy_attach(device_t dev)
  138 {
  139         device_t child;
  140         int i;
  141 
  142         /* First, attach the CPU pseudo-driver. */
  143         for (i = 0; i <= mp_maxid; i++)
  144                 if (!CPU_ABSENT(i)) {
  145                         child = BUS_ADD_CHILD(dev, 0, "cpu", i);
  146                         if (child == NULL)
  147                                 panic("legacy_attach cpu");
  148                         device_probe_and_attach(child);
  149                 }
  150 
  151         /*
  152          * Second, let our child driver's identify any child devices that
  153          * they can find.  Once that is done attach any devices that we
  154          * found.
  155          */
  156         bus_generic_probe(dev);
  157         bus_generic_attach(dev);
  158 
  159 #ifndef PC98
  160         /*
  161          * If we didn't see EISA or ISA on a pci bridge, create some
  162          * connection points now so they show up "on motherboard".
  163          */
  164         if (!devclass_get_device(devclass_find("eisa"), 0)) {
  165                 child = BUS_ADD_CHILD(dev, 0, "eisa", 0);
  166                 if (child == NULL)
  167                         panic("legacy_attach eisa");
  168                 device_probe_and_attach(child);
  169         }
  170 #endif
  171 #ifdef DEV_MCA
  172         if (MCA_system && !devclass_get_device(devclass_find("mca"), 0)) {
  173                 child = BUS_ADD_CHILD(dev, 0, "mca", 0);
  174                 if (child == 0)
  175                         panic("legacy_probe mca");
  176                 device_probe_and_attach(child);
  177         }
  178 #endif
  179         if (!devclass_get_device(devclass_find("isa"), 0)) {
  180                 child = BUS_ADD_CHILD(dev, 0, "isa", 0);
  181                 if (child == NULL)
  182                         panic("legacy_attach isa");
  183                 device_probe_and_attach(child);
  184         }
  185 
  186         return 0;
  187 }
  188 
  189 static int
  190 legacy_print_child(device_t bus, device_t child)
  191 {
  192         struct legacy_device *atdev = DEVTOAT(child);
  193         int retval = 0;
  194 
  195         retval += bus_print_child_header(bus, child);
  196         if (atdev->lg_pcibus != -1)
  197                 retval += printf(" pcibus %d", atdev->lg_pcibus);
  198         retval += printf(" on motherboard\n");  /* XXX "motherboard", ick */
  199 
  200         return (retval);
  201 }
  202 
  203 static device_t
  204 legacy_add_child(device_t bus, int order, const char *name, int unit)
  205 {
  206         device_t child;
  207         struct legacy_device *atdev;
  208 
  209         atdev = malloc(sizeof(struct legacy_device), M_LEGACYDEV,
  210             M_NOWAIT | M_ZERO);
  211         if (atdev == NULL)
  212                 return(NULL);
  213         atdev->lg_pcibus = -1;
  214 
  215         child = device_add_child_ordered(bus, order, name, unit);
  216         if (child == NULL)
  217                 free(atdev, M_LEGACYDEV);
  218         else
  219                 /* should we free this in legacy_child_detached? */
  220                 device_set_ivars(child, atdev);
  221 
  222         return (child);
  223 }
  224 
  225 static int
  226 legacy_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
  227 {
  228         struct legacy_device *atdev = DEVTOAT(child);
  229 
  230         switch (which) {
  231         case LEGACY_IVAR_PCIBUS:
  232                 *result = atdev->lg_pcibus;
  233                 break;
  234         default:
  235                 return ENOENT;
  236         }
  237         return 0;
  238 }
  239         
  240 
  241 static int
  242 legacy_write_ivar(device_t dev, device_t child, int which, uintptr_t value)
  243 {
  244         struct legacy_device *atdev = DEVTOAT(child);
  245 
  246         switch (which) {
  247         case LEGACY_IVAR_PCIBUS:
  248                 atdev->lg_pcibus = value;
  249                 break;
  250         default:
  251                 return ENOENT;
  252         }
  253         return 0;
  254 }
  255 
  256 /*
  257  * Legacy CPU attachment when ACPI is not available.  Drivers like
  258  * cpufreq(4) hang off this.
  259  */
  260 static int      cpu_read_ivar(device_t dev, device_t child, int index,
  261                     uintptr_t *result);
  262 static device_t cpu_add_child(device_t bus, int order, const char *name,
  263                     int unit);
  264 static struct resource_list *cpu_get_rlist(device_t dev, device_t child);
  265 
  266 struct cpu_device {
  267         struct resource_list cd_rl;
  268         struct pcpu *cd_pcpu;
  269 };
  270 
  271 static device_method_t cpu_methods[] = {
  272         /* Device interface */
  273         DEVMETHOD(device_probe,         bus_generic_probe),
  274         DEVMETHOD(device_attach,        bus_generic_attach),
  275         DEVMETHOD(device_detach,        bus_generic_detach),
  276         DEVMETHOD(device_shutdown,      bus_generic_shutdown),
  277         DEVMETHOD(device_suspend,       bus_generic_suspend),
  278         DEVMETHOD(device_resume,        bus_generic_resume),
  279 
  280         /* Bus interface */
  281         DEVMETHOD(bus_add_child,        cpu_add_child),
  282         DEVMETHOD(bus_read_ivar,        cpu_read_ivar),
  283         DEVMETHOD(bus_print_child,      bus_generic_print_child),
  284         DEVMETHOD(bus_get_resource_list, cpu_get_rlist),
  285         DEVMETHOD(bus_get_resource,     bus_generic_rl_get_resource),
  286         DEVMETHOD(bus_set_resource,     bus_generic_rl_set_resource),
  287         DEVMETHOD(bus_alloc_resource,   bus_generic_rl_alloc_resource),
  288         DEVMETHOD(bus_release_resource, bus_generic_rl_release_resource),
  289         DEVMETHOD(bus_driver_added,     bus_generic_driver_added),
  290         DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
  291         DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
  292         DEVMETHOD(bus_setup_intr,       bus_generic_setup_intr),
  293         DEVMETHOD(bus_teardown_intr,    bus_generic_teardown_intr),
  294 
  295         { 0, 0 }
  296 };
  297 
  298 static driver_t cpu_driver = {
  299         "cpu",
  300         cpu_methods,
  301         1,              /* no softc */
  302 };
  303 static devclass_t cpu_devclass;
  304 DRIVER_MODULE(cpu, legacy, cpu_driver, cpu_devclass, 0, 0);
  305 
  306 static device_t
  307 cpu_add_child(device_t bus, int order, const char *name, int unit)
  308 {
  309         struct cpu_device *cd;
  310         device_t child;
  311         struct pcpu *pc;
  312 
  313         if ((cd = malloc(sizeof(*cd), M_DEVBUF, M_NOWAIT | M_ZERO)) == NULL)
  314                 return (NULL);
  315 
  316         resource_list_init(&cd->cd_rl);
  317         pc = pcpu_find(device_get_unit(bus));
  318         cd->cd_pcpu = pc;
  319 
  320         child = device_add_child_ordered(bus, order, name, unit);
  321         if (child != NULL) {
  322                 pc->pc_device = child;
  323                 device_set_ivars(child, cd);
  324         } else
  325                 free(cd, M_DEVBUF);
  326         return (child);
  327 }
  328 
  329 static struct resource_list *
  330 cpu_get_rlist(device_t dev, device_t child)
  331 {
  332         struct cpu_device *cpdev;
  333 
  334         cpdev = device_get_ivars(child);
  335         return (&cpdev->cd_rl);
  336 }
  337 
  338 static int
  339 cpu_read_ivar(device_t dev, device_t child, int index, uintptr_t *result)
  340 {
  341         struct cpu_device *cpdev;
  342 
  343         if (index != CPU_IVAR_PCPU)
  344                 return (ENOENT);
  345         cpdev = device_get_ivars(child);
  346         *result = (uintptr_t)cpdev->cd_pcpu;
  347         return (0);
  348 }

Cache object: ac13ba28daeff031d79cf2936eac6d65


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