pciconf_ofmethod.c revision 1.1.10.2 1 /* $NetBSD: pciconf_ofmethod.c,v 1.1.10.2 2007/12/03 19:04:04 ad Exp $ */
2
3 /*-
4 * Copyright (c) 2007 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jochen Kunz and Tim Rightnour
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /*
40 * Generic PowerPC functions for talking to a PCI Bridge via the RTAS or
41 * OF methods of the device.
42 */
43
44 #include <sys/cdefs.h>
45 __KERNEL_RCSID(0, "$NetBSD: pciconf_ofmethod.c,v 1.1.10.2 2007/12/03 19:04:04 ad Exp $");
46
47 #include <sys/types.h>
48 #include <sys/param.h>
49 #include <sys/time.h>
50 #include <sys/systm.h>
51 #include <sys/errno.h>
52 #include <sys/device.h>
53
54 #include <uvm/uvm_extern.h>
55
56 #define _POWERPC_BUS_DMA_PRIVATE
57 #include <machine/bus.h>
58 #include <machine/intr.h>
59 #include <machine/pio.h>
60 #include <dev/ofw/openfirm.h>
61 #include <dev/ofw/ofw_pci.h>
62
63 #if NISA > 0
64 #include <dev/isa/isavar.h>
65 #endif
66
67 #include <dev/pci/pcivar.h>
68 #include <dev/pci/pcireg.h>
69 #include <dev/pci/pcidevs.h>
70
71 void
72 genppc_pci_ofmethod_attach_hook(struct device *parent, struct device *self,
73 struct pcibus_attach_args *pba)
74 {
75
76 if (pba->pba_bus != 0)
77 return;
78
79 aprint_normal(": OFW method configuration space access");
80 }
81
82 pcitag_t
83 genppc_pci_ofmethod_make_tag(void *v, int bus, int dev, int func)
84 {
85 return ((bus << OFW_PCI_PHYS_HI_BUSSHIFT) & OFW_PCI_PHYS_HI_BUSMASK) |
86 ((dev << OFW_PCI_PHYS_HI_DEVICESHIFT) & OFW_PCI_PHYS_HI_DEVICEMASK)|
87 ((func << OFW_PCI_PHYS_HI_FUNCTIONSHIFT) &
88 OFW_PCI_PHYS_HI_FUNCTIONMASK);
89 }
90
91 void
92 genppc_pci_ofmethod_decompose_tag(void *v, pcitag_t tag, int *bp, int *dp,
93 int *fp)
94 {
95
96 if (bp != NULL)
97 *bp = OFW_PCI_PHYS_HI_BUS(tag);
98 if (dp != NULL)
99 *dp = OFW_PCI_PHYS_HI_DEVICE(tag);
100 if (fp != NULL)
101 *fp = OFW_PCI_PHYS_HI_FUNCTION(tag);
102 return;
103 }
104
105 pcireg_t
106 genppc_pci_ofmethod_conf_read(void *v, pcitag_t tag, int reg)
107 {
108 pci_chipset_tag_t pc = (pci_chipset_tag_t)v;
109 pcireg_t data;
110
111 tag &= OFW_PCI_PHYS_HI_BUSMASK | OFW_PCI_PHYS_HI_DEVICEMASK |
112 OFW_PCI_PHYS_HI_FUNCTIONMASK;
113 tag |= reg & OFW_PCI_PHYS_HI_REGISTERMASK;
114 if (OF_call_method("config-l@", pc->pc_ihandle, 1, 1, tag, &data) < 0)
115 return (pcireg_t) -1;
116 /*printf("data=0x%x\n", data); */
117 return data;
118 }
119
120 void
121 genppc_pci_ofmethod_conf_write(void *v, pcitag_t tag, int reg, pcireg_t data)
122 {
123 pci_chipset_tag_t pc = (pci_chipset_tag_t)v;
124
125 tag &= OFW_PCI_PHYS_HI_BUSMASK | OFW_PCI_PHYS_HI_DEVICEMASK |
126 OFW_PCI_PHYS_HI_FUNCTIONMASK;
127 tag |= reg & OFW_PCI_PHYS_HI_REGISTERMASK;
128 OF_call_method("config-l!", pc->pc_ihandle, 2, 0, data, tag);
129 }
130 /* $NetBSD: pciconf_ofmethod.c,v 1.1.10.2 2007/12/03 19:04:04 ad Exp $ */
131
132 /*-
133 * Copyright (c) 2007 The NetBSD Foundation, Inc.
134 * All rights reserved.
135 *
136 * This code is derived from software contributed to The NetBSD Foundation
137 * by Jochen Kunz and Tim Rightnour
138 *
139 * Redistribution and use in source and binary forms, with or without
140 * modification, are permitted provided that the following conditions
141 * are met:
142 * 1. Redistributions of source code must retain the above copyright
143 * notice, this list of conditions and the following disclaimer.
144 * 2. Redistributions in binary form must reproduce the above copyright
145 * notice, this list of conditions and the following disclaimer in the
146 * documentation and/or other materials provided with the distribution.
147 * 3. All advertising materials mentioning features or use of this software
148 * must display the following acknowledgement:
149 * This product includes software developed by the NetBSD
150 * Foundation, Inc. and its contributors.
151 * 4. Neither the name of The NetBSD Foundation nor the names of its
152 * contributors may be used to endorse or promote products derived
153 * from this software without specific prior written permission.
154 *
155 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
156 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
157 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
158 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
159 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
160 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
161 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
162 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
163 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
164 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
165 * POSSIBILITY OF SUCH DAMAGE.
166 */
167
168 /*
169 * Generic PowerPC functions for talking to a PCI Bridge via the RTAS or
170 * OF methods of the device.
171 */
172
173 #include <sys/cdefs.h>
174 __KERNEL_RCSID(0, "$NetBSD: pciconf_ofmethod.c,v 1.1.10.2 2007/12/03 19:04:04 ad Exp $");
175
176 #include <sys/types.h>
177 #include <sys/param.h>
178 #include <sys/time.h>
179 #include <sys/systm.h>
180 #include <sys/errno.h>
181 #include <sys/device.h>
182
183 #include <uvm/uvm_extern.h>
184
185 #define _POWERPC_BUS_DMA_PRIVATE
186 #include <machine/bus.h>
187 #include <machine/intr.h>
188 #include <machine/pio.h>
189 #include <dev/ofw/openfirm.h>
190 #include <dev/ofw/ofw_pci.h>
191
192 #if NISA > 0
193 #include <dev/isa/isavar.h>
194 #endif
195
196 #include <dev/pci/pcivar.h>
197 #include <dev/pci/pcireg.h>
198 #include <dev/pci/pcidevs.h>
199
200 void
201 genppc_pci_ofmethod_attach_hook(struct device *parent, struct device *self,
202 struct pcibus_attach_args *pba)
203 {
204
205 if (pba->pba_bus != 0)
206 return;
207
208 aprint_normal(": OFW method configuration space access");
209 }
210
211 pcitag_t
212 genppc_pci_ofmethod_make_tag(void *v, int bus, int dev, int func)
213 {
214 return ((bus << OFW_PCI_PHYS_HI_BUSSHIFT) & OFW_PCI_PHYS_HI_BUSMASK) |
215 ((dev << OFW_PCI_PHYS_HI_DEVICESHIFT) & OFW_PCI_PHYS_HI_DEVICEMASK)|
216 ((func << OFW_PCI_PHYS_HI_FUNCTIONSHIFT) &
217 OFW_PCI_PHYS_HI_FUNCTIONMASK);
218 }
219
220 void
221 genppc_pci_ofmethod_decompose_tag(void *v, pcitag_t tag, int *bp, int *dp,
222 int *fp)
223 {
224
225 if (bp != NULL)
226 *bp = OFW_PCI_PHYS_HI_BUS(tag);
227 if (dp != NULL)
228 *dp = OFW_PCI_PHYS_HI_DEVICE(tag);
229 if (fp != NULL)
230 *fp = OFW_PCI_PHYS_HI_FUNCTION(tag);
231 return;
232 }
233
234 pcireg_t
235 genppc_pci_ofmethod_conf_read(void *v, pcitag_t tag, int reg)
236 {
237 pci_chipset_tag_t pc = (pci_chipset_tag_t)v;
238 pcireg_t data;
239
240 tag &= OFW_PCI_PHYS_HI_BUSMASK | OFW_PCI_PHYS_HI_DEVICEMASK |
241 OFW_PCI_PHYS_HI_FUNCTIONMASK;
242 tag |= reg & OFW_PCI_PHYS_HI_REGISTERMASK;
243 if (OF_call_method("config-l@", pc->pc_ihandle, 1, 1, tag, &data) < 0)
244 return (pcireg_t) -1;
245 /*printf("data=0x%x\n", data); */
246 return data;
247 }
248
249 void
250 genppc_pci_ofmethod_conf_write(void *v, pcitag_t tag, int reg, pcireg_t data)
251 {
252 pci_chipset_tag_t pc = (pci_chipset_tag_t)v;
253
254 tag &= OFW_PCI_PHYS_HI_BUSMASK | OFW_PCI_PHYS_HI_DEVICEMASK |
255 OFW_PCI_PHYS_HI_FUNCTIONMASK;
256 tag |= reg & OFW_PCI_PHYS_HI_REGISTERMASK;
257 OF_call_method("config-l!", pc->pc_ihandle, 2, 0, data, tag);
258 }
259 /* $NetBSD: pciconf_ofmethod.c,v 1.1.10.2 2007/12/03 19:04:04 ad Exp $ */
260
261 /*-
262 * Copyright (c) 2007 The NetBSD Foundation, Inc.
263 * All rights reserved.
264 *
265 * This code is derived from software contributed to The NetBSD Foundation
266 * by Jochen Kunz and Tim Rightnour
267 *
268 * Redistribution and use in source and binary forms, with or without
269 * modification, are permitted provided that the following conditions
270 * are met:
271 * 1. Redistributions of source code must retain the above copyright
272 * notice, this list of conditions and the following disclaimer.
273 * 2. Redistributions in binary form must reproduce the above copyright
274 * notice, this list of conditions and the following disclaimer in the
275 * documentation and/or other materials provided with the distribution.
276 * 3. All advertising materials mentioning features or use of this software
277 * must display the following acknowledgement:
278 * This product includes software developed by the NetBSD
279 * Foundation, Inc. and its contributors.
280 * 4. Neither the name of The NetBSD Foundation nor the names of its
281 * contributors may be used to endorse or promote products derived
282 * from this software without specific prior written permission.
283 *
284 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
285 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
286 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
287 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
288 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
289 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
290 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
291 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
292 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
293 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
294 * POSSIBILITY OF SUCH DAMAGE.
295 */
296
297 /*
298 * Generic PowerPC functions for talking to a PCI Bridge via the RTAS or
299 * OF methods of the device.
300 */
301
302 #include <sys/cdefs.h>
303 __KERNEL_RCSID(0, "$NetBSD: pciconf_ofmethod.c,v 1.1.10.2 2007/12/03 19:04:04 ad Exp $");
304
305 #include <sys/types.h>
306 #include <sys/param.h>
307 #include <sys/time.h>
308 #include <sys/systm.h>
309 #include <sys/errno.h>
310 #include <sys/device.h>
311
312 #include <uvm/uvm_extern.h>
313
314 #define _POWERPC_BUS_DMA_PRIVATE
315 #include <machine/bus.h>
316 #include <machine/intr.h>
317 #include <machine/pio.h>
318 #include <dev/ofw/openfirm.h>
319 #include <dev/ofw/ofw_pci.h>
320
321 #if NISA > 0
322 #include <dev/isa/isavar.h>
323 #endif
324
325 #include <dev/pci/pcivar.h>
326 #include <dev/pci/pcireg.h>
327 #include <dev/pci/pcidevs.h>
328
329 void
330 genppc_pci_ofmethod_attach_hook(struct device *parent, struct device *self,
331 struct pcibus_attach_args *pba)
332 {
333
334 if (pba->pba_bus != 0)
335 return;
336
337 aprint_normal(": OFW method configuration space access");
338 }
339
340 pcitag_t
341 genppc_pci_ofmethod_make_tag(void *v, int bus, int dev, int func)
342 {
343 return ((bus << OFW_PCI_PHYS_HI_BUSSHIFT) & OFW_PCI_PHYS_HI_BUSMASK) |
344 ((dev << OFW_PCI_PHYS_HI_DEVICESHIFT) & OFW_PCI_PHYS_HI_DEVICEMASK)|
345 ((func << OFW_PCI_PHYS_HI_FUNCTIONSHIFT) &
346 OFW_PCI_PHYS_HI_FUNCTIONMASK);
347 }
348
349 void
350 genppc_pci_ofmethod_decompose_tag(void *v, pcitag_t tag, int *bp, int *dp,
351 int *fp)
352 {
353
354 if (bp != NULL)
355 *bp = OFW_PCI_PHYS_HI_BUS(tag);
356 if (dp != NULL)
357 *dp = OFW_PCI_PHYS_HI_DEVICE(tag);
358 if (fp != NULL)
359 *fp = OFW_PCI_PHYS_HI_FUNCTION(tag);
360 return;
361 }
362
363 pcireg_t
364 genppc_pci_ofmethod_conf_read(void *v, pcitag_t tag, int reg)
365 {
366 pci_chipset_tag_t pc = (pci_chipset_tag_t)v;
367 pcireg_t data;
368
369 tag &= OFW_PCI_PHYS_HI_BUSMASK | OFW_PCI_PHYS_HI_DEVICEMASK |
370 OFW_PCI_PHYS_HI_FUNCTIONMASK;
371 tag |= reg & OFW_PCI_PHYS_HI_REGISTERMASK;
372 if (OF_call_method("config-l@", pc->pc_ihandle, 1, 1, tag, &data) < 0)
373 return (pcireg_t) -1;
374 /*printf("data=0x%x\n", data); */
375 return data;
376 }
377
378 void
379 genppc_pci_ofmethod_conf_write(void *v, pcitag_t tag, int reg, pcireg_t data)
380 {
381 pci_chipset_tag_t pc = (pci_chipset_tag_t)v;
382
383 tag &= OFW_PCI_PHYS_HI_BUSMASK | OFW_PCI_PHYS_HI_DEVICEMASK |
384 OFW_PCI_PHYS_HI_FUNCTIONMASK;
385 tag |= reg & OFW_PCI_PHYS_HI_REGISTERMASK;
386 OF_call_method("config-l!", pc->pc_ihandle, 2, 0, data, tag);
387 }
388