]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/sparc64/fhc/fhc_central.c
merge fix for boot-time hang on centos' xen
[FreeBSD/FreeBSD.git] / sys / sparc64 / fhc / fhc_central.c
1 /*-
2  * Copyright (c) 2003 Jake Burkholder.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  */
26
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
29
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/bus.h>
33 #include <sys/kernel.h>
34 #include <sys/malloc.h>
35 #include <sys/module.h>
36
37 #include <dev/ofw/ofw_bus.h>
38
39 #include <machine/bus.h>
40 #include <machine/resource.h>
41
42 #include <sys/rman.h>
43
44 #include <sparc64/fhc/fhcreg.h>
45 #include <sparc64/fhc/fhcvar.h>
46
47 static device_probe_t fhc_central_probe;
48 static device_attach_t fhc_central_attach;
49
50 static device_method_t fhc_central_methods[] = {
51         /* Device interface. */
52         DEVMETHOD(device_probe,         fhc_central_probe),
53         DEVMETHOD(device_attach,        fhc_central_attach),
54         DEVMETHOD(device_shutdown,      bus_generic_shutdown),
55         DEVMETHOD(device_suspend,       bus_generic_suspend),
56         DEVMETHOD(device_resume,        bus_generic_resume),
57
58         /* Bus interface. */
59         DEVMETHOD(bus_print_child,      fhc_print_child),
60         DEVMETHOD(bus_probe_nomatch,    fhc_probe_nomatch),
61         DEVMETHOD(bus_setup_intr,       fhc_setup_intr),
62         DEVMETHOD(bus_teardown_intr,    fhc_teardown_intr),
63         DEVMETHOD(bus_alloc_resource,   fhc_alloc_resource),
64         DEVMETHOD(bus_release_resource, bus_generic_rl_release_resource),
65         DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
66         DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
67         DEVMETHOD(bus_get_resource_list, fhc_get_resource_list),
68         DEVMETHOD(bus_get_resource,     bus_generic_rl_get_resource),
69
70         /* ofw_bus interface */
71         DEVMETHOD(ofw_bus_get_compat,   fhc_get_compat),
72         DEVMETHOD(ofw_bus_get_model,    fhc_get_model),
73         DEVMETHOD(ofw_bus_get_name,     fhc_get_name),
74         DEVMETHOD(ofw_bus_get_node,     fhc_get_node),
75         DEVMETHOD(ofw_bus_get_type,     fhc_get_type),
76
77         { NULL, NULL }
78 };
79
80 static driver_t fhc_central_driver = {
81         "fhc",
82         fhc_central_methods,
83         sizeof(struct fhc_softc),
84 };
85
86 static devclass_t fhc_central_devclass;
87
88 DRIVER_MODULE(fhc, central, fhc_central_driver, fhc_central_devclass, 0, 0);
89 MODULE_DEPEND(fhc, central, 1, 1, 1);
90
91 static int
92 fhc_central_probe(device_t dev)
93 {
94
95         if (strcmp(ofw_bus_get_name(dev), "fhc") == 0) {
96                 device_set_desc(dev, "fhc");
97                 return (fhc_probe(dev));
98         }
99         return (ENXIO);
100 }
101
102 static int
103 fhc_central_attach(device_t dev)
104 {
105         struct fhc_softc *sc;
106         phandle_t node;
107         int board;
108         int rid;
109         int i;
110
111         sc = device_get_softc(dev);
112         node = ofw_bus_get_node(dev);
113         sc->sc_node = node;
114         sc->sc_flags |= FHC_CENTRAL;
115
116         for (i = 0; i < FHC_NREG; i++) {
117                 rid = i;
118                 sc->sc_memres[i] = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
119                     &rid, RF_ACTIVE);
120                 if (sc->sc_memres[i] == NULL)
121                         panic("%s: can't allocate registers", __func__);
122                 sc->sc_bt[i] = rman_get_bustag(sc->sc_memres[i]);
123                 sc->sc_bh[i] = rman_get_bushandle(sc->sc_memres[i]);
124         }
125
126         board = bus_space_read_4(sc->sc_bt[FHC_INTERNAL],
127             sc->sc_bh[FHC_INTERNAL], FHC_BSR);
128         sc->sc_board = ((board >> 16) & 0x1) | ((board >> 12) & 0xe);
129
130         return (fhc_attach(dev));
131 }