]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - sys/powerpc/mambo/mambo_openpic.c
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / sys / powerpc / mambo / mambo_openpic.c
1 /*-
2  * Copyright 2008 by Nathan Whitehorn. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
18  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
20  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
21  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23  * SUCH DAMAGE.
24  *
25  */
26
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
29
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/module.h>
33 #include <sys/bus.h>
34 #include <sys/conf.h>
35 #include <sys/kernel.h>
36
37 #include <dev/ofw/ofw_bus.h>
38 #include <dev/ofw/openfirm.h>
39
40 #include <machine/bus.h>
41 #include <machine/intr_machdep.h>
42 #include <machine/md_var.h>
43 #include <machine/pio.h>
44 #include <machine/resource.h>
45
46 #include <vm/vm.h>
47 #include <vm/pmap.h>
48
49 #include <sys/rman.h>
50
51 #include <machine/openpicvar.h>
52
53 #include "pic_if.h"
54
55 /*
56  * Mambo interface
57  */
58 static int      openpic_mambo_probe(device_t);
59 static int      openpic_mambo_attach(device_t);
60 static int      openpicbus_mambo_probe(device_t dev);
61 static int      openpicbus_mambo_attach(device_t dev);
62 static struct resource *openpicbus_alloc_resource(device_t bus, device_t dev,
63     int type, int *rid, u_long start, u_long end, u_long count, u_int flags);
64
65 static device_method_t  openpicbus_mambo_methods[] = {
66         /* Device interface */
67         DEVMETHOD(device_probe,         openpicbus_mambo_probe),
68         DEVMETHOD(device_attach,        openpicbus_mambo_attach),
69
70         /* Bus interface */
71         DEVMETHOD(bus_alloc_resource,   openpicbus_alloc_resource),
72
73         {0,0}
74 };
75
76 struct openpicbus_softc {
77         vm_offset_t picaddr;
78 };
79
80 static driver_t openpicbus_mambo_driver = {
81         "openpicbus",
82         openpicbus_mambo_methods,
83         sizeof(struct openpicbus_softc),
84 };
85
86 static device_method_t  openpic_mambo_methods[] = {
87         /* Device interface */
88         DEVMETHOD(device_probe,         openpic_mambo_probe),
89         DEVMETHOD(device_attach,        openpic_mambo_attach),
90
91         /* PIC interface */
92         DEVMETHOD(pic_config,           openpic_config),
93         DEVMETHOD(pic_dispatch,         openpic_dispatch),
94         DEVMETHOD(pic_enable,           openpic_enable),
95         DEVMETHOD(pic_eoi,              openpic_eoi),
96         DEVMETHOD(pic_ipi,              openpic_ipi),
97         DEVMETHOD(pic_mask,             openpic_mask),
98         DEVMETHOD(pic_unmask,           openpic_unmask),
99
100         { 0, 0 },
101 };
102
103 static driver_t openpic_mambo_driver = {
104         "openpic",
105         openpic_mambo_methods,
106         sizeof(struct openpic_softc),
107 };
108
109 static devclass_t openpicbus_devclass;
110
111 DRIVER_MODULE(openpicbus, nexus, openpicbus_mambo_driver, 
112     openpicbus_devclass, 0, 0);
113 DRIVER_MODULE(openpic, openpicbus, openpic_mambo_driver, 
114     openpic_devclass, 0, 0);
115
116 static int
117 openpicbus_mambo_probe(device_t dev)
118 {
119         const char *type = ofw_bus_get_type(dev);
120
121         if (type == NULL || strcmp(type, "open-pic") != 0)
122                 return (ENXIO);
123
124         device_set_desc(dev, "Mambo OpenPIC Container");
125
126         return (0);
127 }
128
129 static int
130 openpicbus_mambo_attach(device_t dev)
131 {
132         uint64_t picaddr;
133         phandle_t nexus;
134         struct openpicbus_softc *sc;
135
136         sc = device_get_softc(dev);
137
138         nexus = OF_parent(ofw_bus_get_node(dev));
139
140         OF_getprop(nexus,"platform-open-pic",
141             &picaddr,sizeof(picaddr));
142
143         sc->picaddr = picaddr;
144
145         device_add_child(dev,"openpic",-1);
146
147         return (bus_generic_attach(dev));
148 }
149
150 static struct resource *
151 openpicbus_alloc_resource(device_t bus, device_t dev, int type, int *rid,
152                    u_long start, u_long end, u_long count, u_int flags)
153 {
154         struct openpicbus_softc *sc;
155
156         sc = device_get_softc(bus);
157
158         count = 0x40000;
159         start = sc->picaddr;
160         end = start + count;
161
162         return (bus_alloc_resource(bus, type, rid, start, end, count, flags));
163 }
164
165 static int
166 openpic_mambo_probe(device_t dev)
167 {
168
169         device_set_desc(dev, OPENPIC_DEVSTR);
170         return (0);
171 }
172
173 static int
174 openpic_mambo_attach(device_t dev)
175 {
176  
177         return (openpic_common_attach(dev,
178             ofw_bus_get_node(device_get_parent(dev))));
179 }