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$");
   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         int     lg_pcislot;
   62         int     lg_pcifunc;
   63 };
   64 
   65 #define DEVTOAT(dev)    ((struct legacy_device *)device_get_ivars(dev))
   66 
   67 static  int legacy_probe(device_t);
   68 static  int legacy_attach(device_t);
   69 static  int legacy_print_child(device_t, device_t);
   70 static device_t legacy_add_child(device_t bus, u_int order, const char *name,
   71                                 int unit);
   72 static  int legacy_read_ivar(device_t, device_t, int, uintptr_t *);
   73 static  int legacy_write_ivar(device_t, device_t, int, uintptr_t);
   74 
   75 static device_method_t legacy_methods[] = {
   76         /* Device interface */
   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_adjust_resource,  bus_generic_adjust_resource),
   91         DEVMETHOD(bus_release_resource, bus_generic_release_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 int
  110 legacy_probe(device_t dev)
  111 {
  112 
  113         device_set_desc(dev, "legacy system");
  114         device_quiet(dev);
  115         return (0);
  116 }
  117 
  118 static int
  119 legacy_attach(device_t dev)
  120 {
  121         device_t child;
  122 
  123         /*
  124          * Let our child drivers identify any child devices that they
  125          * can find.  Once that is done attach any devices that we
  126          * found.
  127          */
  128         bus_generic_probe(dev);
  129         bus_generic_attach(dev);
  130 
  131 #ifndef PC98
  132         /*
  133          * If we didn't see EISA or ISA on a pci bridge, create some
  134          * connection points now so they show up "on motherboard".
  135          */
  136         if (!devclass_get_device(devclass_find("eisa"), 0)) {
  137                 child = BUS_ADD_CHILD(dev, 0, "eisa", 0);
  138                 if (child == NULL)
  139                         panic("legacy_attach eisa");
  140                 device_probe_and_attach(child);
  141         }
  142 #endif
  143 #ifdef DEV_MCA
  144         if (MCA_system && !devclass_get_device(devclass_find("mca"), 0)) {
  145                 child = BUS_ADD_CHILD(dev, 0, "mca", 0);
  146                 if (child == 0)
  147                         panic("legacy_probe mca");
  148                 device_probe_and_attach(child);
  149         }
  150 #endif
  151         if (!devclass_get_device(devclass_find("isa"), 0)) {
  152                 child = BUS_ADD_CHILD(dev, 0, "isa", 0);
  153                 if (child == NULL)
  154                         panic("legacy_attach isa");
  155                 device_probe_and_attach(child);
  156         }
  157 
  158         return 0;
  159 }
  160 
  161 static int
  162 legacy_print_child(device_t bus, device_t child)
  163 {
  164         struct legacy_device *atdev = DEVTOAT(child);
  165         int retval = 0;
  166 
  167         retval += bus_print_child_header(bus, child);
  168         if (atdev->lg_pcibus != -1)
  169                 retval += printf(" pcibus %d", atdev->lg_pcibus);
  170         retval += printf(" on motherboard\n");  /* XXX "motherboard", ick */
  171 
  172         return (retval);
  173 }
  174 
  175 static device_t
  176 legacy_add_child(device_t bus, u_int order, const char *name, int unit)
  177 {
  178         device_t child;
  179         struct legacy_device *atdev;
  180 
  181         atdev = malloc(sizeof(struct legacy_device), M_LEGACYDEV,
  182             M_NOWAIT | M_ZERO);
  183         if (atdev == NULL)
  184                 return(NULL);
  185         atdev->lg_pcibus = -1;
  186         atdev->lg_pcislot = -1;
  187         atdev->lg_pcifunc = -1;
  188 
  189         child = device_add_child_ordered(bus, order, name, unit);
  190         if (child == NULL)
  191                 free(atdev, M_LEGACYDEV);
  192         else
  193                 /* should we free this in legacy_child_detached? */
  194                 device_set_ivars(child, atdev);
  195 
  196         return (child);
  197 }
  198 
  199 static int
  200 legacy_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
  201 {
  202         struct legacy_device *atdev = DEVTOAT(child);
  203 
  204         switch (which) {
  205         case LEGACY_IVAR_PCIDOMAIN:
  206                 *result = 0;
  207                 break;
  208         case LEGACY_IVAR_PCIBUS:
  209                 *result = atdev->lg_pcibus;
  210                 break;
  211         case LEGACY_IVAR_PCISLOT:
  212                 *result = atdev->lg_pcislot;
  213                 break;
  214         case LEGACY_IVAR_PCIFUNC:
  215                 *result = atdev->lg_pcifunc;
  216                 break;
  217         default:
  218                 return ENOENT;
  219         }
  220         return 0;
  221 }
  222         
  223 
  224 static int
  225 legacy_write_ivar(device_t dev, device_t child, int which, uintptr_t value)
  226 {
  227         struct legacy_device *atdev = DEVTOAT(child);
  228 
  229         switch (which) {
  230         case LEGACY_IVAR_PCIDOMAIN:
  231                 return EINVAL;
  232         case LEGACY_IVAR_PCIBUS:
  233                 atdev->lg_pcibus = value;
  234                 break;
  235         case LEGACY_IVAR_PCISLOT:
  236                 atdev->lg_pcislot = value;
  237                 break;
  238         case LEGACY_IVAR_PCIFUNC:
  239                 atdev->lg_pcifunc = value;
  240                 break;
  241         default:
  242                 return ENOENT;
  243         }
  244         return 0;
  245 }
  246 
  247 /*
  248  * Legacy CPU attachment when ACPI is not available.  Drivers like
  249  * cpufreq(4) hang off this.
  250  */
  251 static void     cpu_identify(driver_t *driver, device_t parent);
  252 static int      cpu_read_ivar(device_t dev, device_t child, int index,
  253                     uintptr_t *result);
  254 static device_t cpu_add_child(device_t bus, u_int order, const char *name,
  255                     int unit);
  256 static struct resource_list *cpu_get_rlist(device_t dev, device_t child);
  257 
  258 struct cpu_device {
  259         struct resource_list cd_rl;
  260         struct pcpu *cd_pcpu;
  261 };
  262 
  263 static device_method_t cpu_methods[] = {
  264         /* Device interface */
  265         DEVMETHOD(device_identify,      cpu_identify),
  266         DEVMETHOD(device_probe,         bus_generic_probe),
  267         DEVMETHOD(device_attach,        bus_generic_attach),
  268         DEVMETHOD(device_detach,        bus_generic_detach),
  269         DEVMETHOD(device_shutdown,      bus_generic_shutdown),
  270         DEVMETHOD(device_suspend,       bus_generic_suspend),
  271         DEVMETHOD(device_resume,        bus_generic_resume),
  272 
  273         /* Bus interface */
  274         DEVMETHOD(bus_add_child,        cpu_add_child),
  275         DEVMETHOD(bus_read_ivar,        cpu_read_ivar),
  276         DEVMETHOD(bus_get_resource_list, cpu_get_rlist),
  277         DEVMETHOD(bus_get_resource,     bus_generic_rl_get_resource),
  278         DEVMETHOD(bus_set_resource,     bus_generic_rl_set_resource),
  279         DEVMETHOD(bus_alloc_resource,   bus_generic_rl_alloc_resource),
  280         DEVMETHOD(bus_release_resource, bus_generic_rl_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         DEVMETHOD_END
  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 void
  298 cpu_identify(driver_t *driver, device_t parent)
  299 {
  300         device_t child;
  301         int i;
  302 
  303         /*
  304          * Attach a cpuX device for each CPU.  We use an order of 150
  305          * so that these devices are attached after the Host-PCI
  306          * bridges (which are added at order 100).
  307          */
  308         CPU_FOREACH(i) {
  309                 child = BUS_ADD_CHILD(parent, 150, "cpu", i);
  310                 if (child == NULL)
  311                         panic("legacy_attach cpu");
  312         }
  313 }
  314 
  315 static device_t
  316 cpu_add_child(device_t bus, u_int order, const char *name, int unit)
  317 {
  318         struct cpu_device *cd;
  319         device_t child;
  320         struct pcpu *pc;
  321 
  322         if ((cd = malloc(sizeof(*cd), M_DEVBUF, M_NOWAIT | M_ZERO)) == NULL)
  323                 return (NULL);
  324 
  325         resource_list_init(&cd->cd_rl);
  326         pc = pcpu_find(device_get_unit(bus));
  327         cd->cd_pcpu = pc;
  328 
  329         child = device_add_child_ordered(bus, order, name, unit);
  330         if (child != NULL) {
  331                 pc->pc_device = child;
  332                 device_set_ivars(child, cd);
  333         } else
  334                 free(cd, M_DEVBUF);
  335         return (child);
  336 }
  337 
  338 static struct resource_list *
  339 cpu_get_rlist(device_t dev, device_t child)
  340 {
  341         struct cpu_device *cpdev;
  342 
  343         cpdev = device_get_ivars(child);
  344         return (&cpdev->cd_rl);
  345 }
  346 
  347 static int
  348 cpu_read_ivar(device_t dev, device_t child, int index, uintptr_t *result)
  349 {
  350         struct cpu_device *cpdev;
  351 
  352         if (index != CPU_IVAR_PCPU)
  353                 return (ENOENT);
  354         cpdev = device_get_ivars(child);
  355         *result = (uintptr_t)cpdev->cd_pcpu;
  356         return (0);
  357 }

Cache object: cb66ca2f311f9e66289da79f2d40b107


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