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-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/8.3/sys/amd64/amd64/legacy.c 230714 2012-01-29 01:22:48Z marius $");
   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 <machine/legacyvar.h>
   51 #include <machine/resource.h>
   52 
   53 static MALLOC_DEFINE(M_LEGACYDEV, "legacydrv", "legacy system device");
   54 struct legacy_device {
   55         int                     lg_pcibus;
   56 };
   57 
   58 #define DEVTOAT(dev)    ((struct legacy_device *)device_get_ivars(dev))
   59 
   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, u_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_probe,         legacy_probe),
   71         DEVMETHOD(device_attach,        legacy_attach),
   72         DEVMETHOD(device_detach,        bus_generic_detach),
   73         DEVMETHOD(device_shutdown,      bus_generic_shutdown),
   74         DEVMETHOD(device_suspend,       bus_generic_suspend),
   75         DEVMETHOD(device_resume,        bus_generic_resume),
   76 
   77         /* Bus interface */
   78         DEVMETHOD(bus_print_child,      legacy_print_child),
   79         DEVMETHOD(bus_add_child,        legacy_add_child),
   80         DEVMETHOD(bus_read_ivar,        legacy_read_ivar),
   81         DEVMETHOD(bus_write_ivar,       legacy_write_ivar),
   82         DEVMETHOD(bus_alloc_resource,   bus_generic_alloc_resource),
   83         DEVMETHOD(bus_adjust_resource,  bus_generic_adjust_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 int
  103 legacy_probe(device_t dev)
  104 {
  105 
  106         device_set_desc(dev, "legacy system");
  107         device_quiet(dev);
  108         return (0);
  109 }
  110 
  111 static int
  112 legacy_attach(device_t dev)
  113 {
  114         device_t child;
  115 
  116         /*
  117          * Let our child drivers identify any child devices that they
  118          * can find.  Once that is done attach any devices that we
  119          * found.
  120          */
  121         bus_generic_probe(dev);
  122         bus_generic_attach(dev);
  123 
  124         /*
  125          * If we didn't see ISA on a pci bridge, create some
  126          * connection points now so it shows up "on motherboard".
  127          */
  128         if (!devclass_get_device(devclass_find("isa"), 0)) {
  129                 child = BUS_ADD_CHILD(dev, 0, "isa", 0);
  130                 if (child == NULL)
  131                         panic("legacy_attach isa");
  132                 device_probe_and_attach(child);
  133         }
  134 
  135         return 0;
  136 }
  137 
  138 static int
  139 legacy_print_child(device_t bus, device_t child)
  140 {
  141         struct legacy_device *atdev = DEVTOAT(child);
  142         int retval = 0;
  143 
  144         retval += bus_print_child_header(bus, child);
  145         if (atdev->lg_pcibus != -1)
  146                 retval += printf(" pcibus %d", atdev->lg_pcibus);
  147         retval += printf(" on motherboard\n");  /* XXX "motherboard", ick */
  148 
  149         return (retval);
  150 }
  151 
  152 static device_t
  153 legacy_add_child(device_t bus, u_int order, const char *name, int unit)
  154 {
  155         device_t child;
  156         struct legacy_device *atdev;
  157 
  158         atdev = malloc(sizeof(struct legacy_device), M_LEGACYDEV,
  159             M_NOWAIT | M_ZERO);
  160         if (atdev == NULL)
  161                 return(NULL);
  162         atdev->lg_pcibus = -1;
  163 
  164         child = device_add_child_ordered(bus, order, name, unit);
  165         if (child == NULL)
  166                 free(atdev, M_LEGACYDEV);
  167         else
  168                 /* should we free this in legacy_child_detached? */
  169                 device_set_ivars(child, atdev);
  170 
  171         return (child);
  172 }
  173 
  174 static int
  175 legacy_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
  176 {
  177         struct legacy_device *atdev = DEVTOAT(child);
  178 
  179         switch (which) {
  180         case LEGACY_IVAR_PCIDOMAIN:
  181                 *result = 0;
  182                 break;
  183         case LEGACY_IVAR_PCIBUS:
  184                 *result = atdev->lg_pcibus;
  185                 break;
  186         default:
  187                 return ENOENT;
  188         }
  189         return 0;
  190 }
  191         
  192 
  193 static int
  194 legacy_write_ivar(device_t dev, device_t child, int which, uintptr_t value)
  195 {
  196         struct legacy_device *atdev = DEVTOAT(child);
  197 
  198         switch (which) {
  199         case LEGACY_IVAR_PCIDOMAIN:
  200                 return EINVAL;
  201         case LEGACY_IVAR_PCIBUS:
  202                 atdev->lg_pcibus = value;
  203                 break;
  204         default:
  205                 return ENOENT;
  206         }
  207         return 0;
  208 }
  209 
  210 /*
  211  * Legacy CPU attachment when ACPI is not available.  Drivers like
  212  * cpufreq(4) hang off this.
  213  */
  214 static void     cpu_identify(driver_t *driver, device_t parent);
  215 static int      cpu_read_ivar(device_t dev, device_t child, int index,
  216                     uintptr_t *result);
  217 static device_t cpu_add_child(device_t bus, u_int order, const char *name,
  218                     int unit);
  219 static struct resource_list *cpu_get_rlist(device_t dev, device_t child);
  220 
  221 struct cpu_device {
  222         struct resource_list cd_rl;
  223         struct pcpu *cd_pcpu;
  224 };
  225 
  226 static device_method_t cpu_methods[] = {
  227         /* Device interface */
  228         DEVMETHOD(device_identify,      cpu_identify),
  229         DEVMETHOD(device_probe,         bus_generic_probe),
  230         DEVMETHOD(device_attach,        bus_generic_attach),
  231         DEVMETHOD(device_detach,        bus_generic_detach),
  232         DEVMETHOD(device_shutdown,      bus_generic_shutdown),
  233         DEVMETHOD(device_suspend,       bus_generic_suspend),
  234         DEVMETHOD(device_resume,        bus_generic_resume),
  235 
  236         /* Bus interface */
  237         DEVMETHOD(bus_add_child,        cpu_add_child),
  238         DEVMETHOD(bus_read_ivar,        cpu_read_ivar),
  239         DEVMETHOD(bus_get_resource_list, cpu_get_rlist),
  240         DEVMETHOD(bus_get_resource,     bus_generic_rl_get_resource),
  241         DEVMETHOD(bus_set_resource,     bus_generic_rl_set_resource),
  242         DEVMETHOD(bus_alloc_resource,   bus_generic_rl_alloc_resource),
  243         DEVMETHOD(bus_release_resource, bus_generic_rl_release_resource),
  244         DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
  245         DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
  246         DEVMETHOD(bus_setup_intr,       bus_generic_setup_intr),
  247         DEVMETHOD(bus_teardown_intr,    bus_generic_teardown_intr),
  248 
  249         DEVMETHOD_END
  250 };
  251 
  252 static driver_t cpu_driver = {
  253         "cpu",
  254         cpu_methods,
  255         1,              /* no softc */
  256 };
  257 static devclass_t cpu_devclass;
  258 DRIVER_MODULE(cpu, legacy, cpu_driver, cpu_devclass, 0, 0);
  259 
  260 static void
  261 cpu_identify(driver_t *driver, device_t parent)
  262 {
  263         device_t child;
  264         int i;
  265 
  266         /*
  267          * Attach a cpuX device for each CPU.  We use an order of 150
  268          * so that these devices are attached after the Host-PCI
  269          * bridges (which are added at order 100).
  270          */
  271         CPU_FOREACH(i) {
  272                 child = BUS_ADD_CHILD(parent, 150, "cpu", i);
  273                 if (child == NULL)
  274                         panic("legacy_attach cpu");
  275         }
  276 }
  277 
  278 static device_t
  279 cpu_add_child(device_t bus, u_int order, const char *name, int unit)
  280 {
  281         struct cpu_device *cd;
  282         device_t child;
  283         struct pcpu *pc;
  284 
  285         if ((cd = malloc(sizeof(*cd), M_DEVBUF, M_NOWAIT | M_ZERO)) == NULL)
  286                 return (NULL);
  287 
  288         resource_list_init(&cd->cd_rl);
  289         pc = pcpu_find(device_get_unit(bus));
  290         cd->cd_pcpu = pc;
  291 
  292         child = device_add_child_ordered(bus, order, name, unit);
  293         if (child != NULL) {
  294                 pc->pc_device = child;
  295                 device_set_ivars(child, cd);
  296         } else
  297                 free(cd, M_DEVBUF);
  298         return (child);
  299 }
  300 
  301 static struct resource_list *
  302 cpu_get_rlist(device_t dev, device_t child)
  303 {
  304         struct cpu_device *cpdev;
  305 
  306         cpdev = device_get_ivars(child);
  307         return (&cpdev->cd_rl);
  308 }
  309 
  310 static int
  311 cpu_read_ivar(device_t dev, device_t child, int index, uintptr_t *result)
  312 {
  313         struct cpu_device *cpdev;
  314 
  315         if (index != CPU_IVAR_PCPU)
  316                 return (ENOENT);
  317         cpdev = device_get_ivars(child);
  318         *result = (uintptr_t)cpdev->cd_pcpu;
  319         return (0);
  320 }

Cache object: 7d39eb8f2655828f76664969b23f1da6


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