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/amd64/amd64/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/5.3/sys/amd64/amd64/legacy.c 133898 2004-08-16 22:54:50Z peter $");
   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 <machine/legacyvar.h>
   50 #include <machine/resource.h>
   51 
   52 static MALLOC_DEFINE(M_LEGACYDEV, "legacydrv", "legacy system device");
   53 struct legacy_device {
   54         int                     lg_pcibus;
   55 };
   56 
   57 #define DEVTOAT(dev)    ((struct legacy_device *)device_get_ivars(dev))
   58 
   59 static void legacy_identify(driver_t *driver, device_t parent);
   60 static  int legacy_probe(device_t);
   61 static  int legacy_attach(device_t);
   62 static  int legacy_print_child(device_t, device_t);
   63 static device_t legacy_add_child(device_t bus, int order, const char *name,
   64                                 int unit);
   65 static  int legacy_read_ivar(device_t, device_t, int, uintptr_t *);
   66 static  int legacy_write_ivar(device_t, device_t, int, uintptr_t);
   67 
   68 static device_method_t legacy_methods[] = {
   69         /* Device interface */
   70         DEVMETHOD(device_identify,      legacy_identify),
   71         DEVMETHOD(device_probe,         legacy_probe),
   72         DEVMETHOD(device_attach,        legacy_attach),
   73         DEVMETHOD(device_detach,        bus_generic_detach),
   74         DEVMETHOD(device_shutdown,      bus_generic_shutdown),
   75         DEVMETHOD(device_suspend,       bus_generic_suspend),
   76         DEVMETHOD(device_resume,        bus_generic_resume),
   77 
   78         /* Bus interface */
   79         DEVMETHOD(bus_print_child,      legacy_print_child),
   80         DEVMETHOD(bus_add_child,        legacy_add_child),
   81         DEVMETHOD(bus_read_ivar,        legacy_read_ivar),
   82         DEVMETHOD(bus_write_ivar,       legacy_write_ivar),
   83         DEVMETHOD(bus_alloc_resource,   bus_generic_alloc_resource),
   84         DEVMETHOD(bus_release_resource, bus_generic_release_resource),
   85         DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
   86         DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
   87         DEVMETHOD(bus_setup_intr,       bus_generic_setup_intr),
   88         DEVMETHOD(bus_teardown_intr,    bus_generic_teardown_intr),
   89 
   90         { 0, 0 }
   91 };
   92 
   93 static driver_t legacy_driver = {
   94         "legacy",
   95         legacy_methods,
   96         1,                      /* no softc */
   97 };
   98 static devclass_t legacy_devclass;
   99 
  100 DRIVER_MODULE(legacy, nexus, legacy_driver, legacy_devclass, 0, 0);
  101 
  102 static void
  103 legacy_identify(driver_t *driver, device_t parent)
  104 {
  105 
  106         /*
  107          * Add child device with order of 1 so it gets probed
  108          * after ACPI (which is at order 0.
  109          */
  110         if (BUS_ADD_CHILD(parent, 1, "legacy", 0) == NULL)
  111                 panic("legacy: could not attach");
  112 }
  113 
  114 static int
  115 legacy_probe(device_t dev)
  116 {
  117         device_t acpi;
  118 
  119         /*
  120          * Fail to probe if ACPI is ok.
  121          */
  122         acpi = devclass_get_device(devclass_find("acpi"), 0);
  123         if (acpi != NULL && device_is_alive(acpi))
  124                 return (ENXIO);
  125         device_set_desc(dev, "legacy system");
  126         device_quiet(dev);
  127         return (0);
  128 }
  129 
  130 static int
  131 legacy_attach(device_t dev)
  132 {
  133         device_t child;
  134         int i;
  135         struct pcpu *pc;
  136 
  137         /*
  138          * First, let our child driver's identify any child devices that
  139          * they can find.  Once that is done attach any devices that we
  140          * found.
  141          */
  142         bus_generic_probe(dev);
  143         bus_generic_attach(dev);
  144 
  145         /* Attach CPU pseudo-driver. */
  146         if (!devclass_get_device(devclass_find("cpu"), 0)) {
  147                 for (i = 0; i <= mp_maxid; i++)
  148                         if (!CPU_ABSENT(i)) {
  149                                 pc = pcpu_find(i);
  150                                 KASSERT(pc != NULL, ("pcpu_find failed"));
  151                                 child = BUS_ADD_CHILD(dev, 0, "cpu", i);
  152                                 if (child == NULL)
  153                                         panic("legacy_attach cpu");
  154                                 device_probe_and_attach(child);
  155                                 pc->pc_device = child;
  156                                 device_set_ivars(child, pc);
  157                         }
  158         }
  159 
  160         /*
  161          * If we didn't see ISA on a pci bridge, create some
  162          * connection points now so it shows up "on motherboard".
  163          */
  164         if (!devclass_get_device(devclass_find("isa"), 0)) {
  165                 child = BUS_ADD_CHILD(dev, 0, "isa", 0);
  166                 if (child == NULL)
  167                         panic("legacy_attach isa");
  168                 device_probe_and_attach(child);
  169         }
  170 
  171         return 0;
  172 }
  173 
  174 static int
  175 legacy_print_child(device_t bus, device_t child)
  176 {
  177         struct legacy_device *atdev = DEVTOAT(child);
  178         int retval = 0;
  179 
  180         retval += bus_print_child_header(bus, child);
  181         if (atdev->lg_pcibus != -1)
  182                 retval += printf(" pcibus %d", atdev->lg_pcibus);
  183         retval += printf(" on motherboard\n");  /* XXX "motherboard", ick */
  184 
  185         return (retval);
  186 }
  187 
  188 static device_t
  189 legacy_add_child(device_t bus, int order, const char *name, int unit)
  190 {
  191         device_t child;
  192         struct legacy_device *atdev;
  193 
  194         atdev = malloc(sizeof(struct legacy_device), M_LEGACYDEV,
  195             M_NOWAIT | M_ZERO);
  196         if (atdev == NULL)
  197                 return(NULL);
  198         atdev->lg_pcibus = -1;
  199 
  200         child = device_add_child_ordered(bus, order, name, unit);
  201         if (child == NULL)
  202                 free(atdev, M_LEGACYDEV);
  203         else
  204                 /* should we free this in legacy_child_detached? */
  205                 device_set_ivars(child, atdev);
  206 
  207         return (child);
  208 }
  209 
  210 static int
  211 legacy_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
  212 {
  213         struct legacy_device *atdev = DEVTOAT(child);
  214 
  215         switch (which) {
  216         case LEGACY_IVAR_PCIBUS:
  217                 *result = atdev->lg_pcibus;
  218                 break;
  219         default:
  220                 return ENOENT;
  221         }
  222         return 0;
  223 }
  224         
  225 
  226 static int
  227 legacy_write_ivar(device_t dev, device_t child, int which, uintptr_t value)
  228 {
  229         struct legacy_device *atdev = DEVTOAT(child);
  230 
  231         switch (which) {
  232         case LEGACY_IVAR_PCIBUS:
  233                 atdev->lg_pcibus = value;
  234                 break;
  235         default:
  236                 return ENOENT;
  237         }
  238         return 0;
  239 }
  240 
  241 /*
  242  * Legacy CPU attachment when ACPI is not available.  Drivers like
  243  * cpufreq(4) hang off this.
  244  */
  245 static int      cpu_read_ivar(device_t dev, device_t child, int index,
  246                     uintptr_t *result);
  247 
  248 static device_method_t cpu_methods[] = {
  249         /* Device interface */
  250         DEVMETHOD(device_probe,         bus_generic_probe),
  251         DEVMETHOD(device_attach,        bus_generic_attach),
  252         DEVMETHOD(device_detach,        bus_generic_detach),
  253         DEVMETHOD(device_shutdown,      bus_generic_shutdown),
  254         DEVMETHOD(device_suspend,       bus_generic_suspend),
  255         DEVMETHOD(device_resume,        bus_generic_resume),
  256 
  257         /* Bus interface */
  258         DEVMETHOD(bus_read_ivar,        cpu_read_ivar),
  259         DEVMETHOD(bus_print_child,      bus_generic_print_child),
  260         DEVMETHOD(bus_alloc_resource,   bus_generic_alloc_resource),
  261         DEVMETHOD(bus_release_resource, bus_generic_release_resource),
  262         DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
  263         DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
  264         DEVMETHOD(bus_setup_intr,       bus_generic_setup_intr),
  265         DEVMETHOD(bus_teardown_intr,    bus_generic_teardown_intr),
  266 
  267         { 0, 0 }
  268 };
  269 
  270 static driver_t cpu_driver = {
  271         "cpu",
  272         cpu_methods,
  273         1,              /* no softc */
  274 };
  275 static devclass_t cpu_devclass;
  276 DRIVER_MODULE(cpu, legacy, cpu_driver, cpu_devclass, 0, 0);
  277 
  278 static int
  279 cpu_read_ivar(device_t dev, device_t child, int index, uintptr_t *result)
  280 {
  281         struct pcpu *pc;
  282 
  283         if (index != 0)
  284                 return (ENOENT);
  285         pc = device_get_ivars(child);
  286         if (pc == NULL)
  287                 return (ENOENT);
  288         *result = (uintptr_t)pc;
  289         return (0);
  290 }

Cache object: c6b28e3d676cf69d27b9f33b5098c917


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