xref: /netbsd-src/sys/arch/powerpc/include/pci_machdep.h (revision 1b9578b8c2c1f848eeb16dabbfd7d1f0d9fdefbd)
1 /* $NetBSD: pci_machdep.h,v 1.11 2011/06/22 18:06:34 matt Exp $ */
2 
3 /*-
4  * Copyright (c) 2002,2007 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Klaus Klein 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  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef _PCI_MACHDEP_H_
33 #define _PCI_MACHDEP_H_
34 
35 #include <prop/proplib.h>
36 
37 /*
38  * Machine-specific definitions for PCI autoconfiguration.
39  */
40 
41 #define __HAVE_PCI_CONF_HOOK
42 
43 /*
44  * Types provided to machine-independent PCI code
45  */
46 typedef struct genppc_pci_chipset *pci_chipset_tag_t;
47 typedef int pcitag_t;
48 typedef int pci_intr_handle_t;
49 
50 /*
51  * Forward declarations.
52  */
53 struct pci_attach_args;
54 struct pcibus_attach_args;
55 
56 static inline pci_chipset_tag_t pcibus_attach_args_pc(
57     struct pcibus_attach_args *);
58 static inline pci_chipset_tag_t pci_attach_args_pc(
59     const struct pci_attach_args *);
60 
61 #include <dev/pci/pcireg.h>
62 
63 #ifdef _KERNEL
64 extern struct powerpc_bus_dma_tag pci_bus_dma_tag;
65 #endif
66 
67 
68 #if defined(_KERNEL) && (defined(_MODULE) || defined(__PCI_NOINLINE))
69 void		pci_attach_hook(device_t, device_t,
70 		    struct pcibus_attach_args *);
71 
72 int		pci_bus_maxdevs(pci_chipset_tag_t, int);
73 pcitag_t	pci_make_tag(pci_chipset_tag_t, int, int, int);
74 pcireg_t	pci_conf_read(pci_chipset_tag_t, pcitag_t, int);
75 void		pci_conf_write(pci_chipset_tag_t, pcitag_t, int, pcireg_t);
76 void		pci_decompose_tag(pci_chipset_tag_t, pcitag_t,
77 		    int *, int *, int *);
78 
79 const char *	pci_intr_string(pci_chipset_tag_t, pci_intr_handle_t);
80 const struct evcnt *
81 		pci_intr_evcnt(pci_chipset_tag_t, pci_intr_handle_t);
82 void *		pci_intr_establish(pci_chipset_tag_t, pci_intr_handle_t,
83 		    int, int (*)(void *), void *);
84 void		pci_intr_disestablish(pci_chipset_tag_t, void *);
85 int		pci_intr_map(const struct pci_attach_args *,
86 		    pci_intr_handle_t *ihp);
87 int		pci_intr_setattr(pci_chipset_tag_t, pci_intr_handle_t *,
88 		    int, uint64_t);
89 
90 void		pci_conf_interrupt(pci_chipset_tag_t, int, int, int,
91 		    int, int *);
92 int		pci_conf_hook(pci_chipset_tag_t, int, int, int, pcireg_t);
93 #endif /* _KERNEL && (_MODULE || __PCI_NOINLINE) */
94 
95 /* Per bus information structure */
96 struct genppc_pci_chipset_businfo {
97 	SIMPLEQ_ENTRY(genppc_pci_chipset_businfo) next;
98 	prop_dictionary_t	pbi_properties; /* chipset properties */
99 };
100 
101 #if !defined(_MODULE)
102 /*
103  * Generic PPC PCI structure and type definitions.
104  * NOT TO BE USED DIRECTLY BY MACHINE INDEPENDENT CODE.
105  */
106 struct genppc_pci_chipset {
107 	void		*pc_conf_v;
108 	void		(*pc_attach_hook)(device_t, device_t,
109 			    struct pcibus_attach_args *);
110 	int		(*pc_bus_maxdevs)(void *, int);
111 	pcitag_t	(*pc_make_tag)(void *, int, int, int);
112 	pcireg_t	(*pc_conf_read)(void *, pcitag_t, int);
113 	void		(*pc_conf_write)(void *, pcitag_t, int, pcireg_t);
114 
115 	void		*pc_intr_v;
116 	int		(*pc_intr_map)(const struct pci_attach_args *,
117 			    pci_intr_handle_t *);
118 	const char	*(*pc_intr_string)(void *, pci_intr_handle_t);
119 	const struct evcnt *(*pc_intr_evcnt)(void *, pci_intr_handle_t);
120 	void		*(*pc_intr_establish)(void *, pci_intr_handle_t,
121 			    int, int (*)(void *), void *);
122 	void		(*pc_intr_disestablish)(void *, void *);
123 	int		(*pc_intr_setattr)(void *, pci_intr_handle_t *,
124 			    int, uint64_t);
125 
126 	void		(*pc_conf_interrupt)(void *, int, int, int, int, int *);
127 	void		(*pc_decompose_tag)(void *, pcitag_t, int *,
128 			    int *, int *);
129 	int		(*pc_conf_hook)(void *, int, int, int, pcireg_t);
130 
131 	uint32_t	*pc_addr;
132 	uint32_t	*pc_data;
133 	int		pc_node;
134 	int		pc_ihandle;
135 	int		pc_bus;
136 	bus_space_tag_t	pc_memt;
137 	bus_space_tag_t	pc_iot;
138 
139 	SIMPLEQ_HEAD(, genppc_pci_chipset_businfo) pc_pbi;
140 };
141 
142 #ifdef _KERNEL
143 
144 #ifdef __PCI_NOINLINE
145 #define	__pci_inline
146 #else
147 #define	__pci_inline	static inline
148 #endif
149 
150 /*
151  * Functions provided to machine-independent PCI code.
152  */
153 __pci_inline void
154 pci_attach_hook(device_t parent, device_t self, struct pcibus_attach_args *pba)
155 {
156 	(*pcibus_attach_args_pc(pba)->pc_attach_hook)(parent, self, pba);
157 }
158 
159 __pci_inline int
160 pci_bus_maxdevs(pci_chipset_tag_t pc, int busno)
161 {
162 	return (*pc->pc_bus_maxdevs)(pc->pc_conf_v, busno);
163 }
164 
165 __pci_inline pcitag_t
166 pci_make_tag(pci_chipset_tag_t pc, int bus, int device, int function)
167 {
168 	return (*pc->pc_make_tag)(pc->pc_conf_v, bus, device, function);
169 }
170 
171 __pci_inline pcireg_t
172 pci_conf_read(pci_chipset_tag_t pc, pcitag_t tag, int reg)
173 {
174 	return (*pc->pc_conf_read)(pc->pc_conf_v, tag, reg);
175 }
176 
177 __pci_inline void
178 pci_conf_write(pci_chipset_tag_t pc, pcitag_t tag, int reg, pcireg_t val)
179 {
180 	(*pc->pc_conf_write)(pc->pc_conf_v, tag, reg, val);
181 }
182 
183 __pci_inline void
184 pci_decompose_tag(pci_chipset_tag_t pc, pcitag_t tag, int *bp, int *dp, int *fp)
185 {
186 	(*pc->pc_decompose_tag)(pc->pc_conf_v, tag, bp, dp, fp);
187 }
188 
189 __pci_inline int
190 pci_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
191 {
192 	return (*pci_attach_args_pc(pa)->pc_intr_map)(pa, ihp);
193 }
194 
195 __pci_inline const char	*
196 pci_intr_string(pci_chipset_tag_t pc, pci_intr_handle_t ih)
197 {
198 	return (*pc->pc_intr_string)(pc->pc_intr_v, ih);
199 }
200 
201 __pci_inline const struct evcnt *
202 pci_intr_evcnt(pci_chipset_tag_t pc, pci_intr_handle_t ih)
203 {
204 	return (*pc->pc_intr_evcnt)(pc->pc_intr_v, ih);
205 }
206 
207 __pci_inline void *
208 pci_intr_establish(pci_chipset_tag_t pc, pci_intr_handle_t ih, int ipl,
209     int (*handler)(void *), void *arg)
210 {
211 	return (*pc->pc_intr_establish)(pc->pc_intr_v, ih, ipl, handler, arg);
212 }
213 
214 __pci_inline void
215 pci_intr_disestablish(pci_chipset_tag_t pc, void *cookie)
216 {
217 	(*pc->pc_intr_disestablish)(pc->pc_intr_v, cookie);
218 }
219 
220 __pci_inline int
221 pci_intr_setattr(pci_chipset_tag_t pc, pci_intr_handle_t *ihp, int attr,
222     uint64_t data)
223 {
224 	return (*pc->pc_intr_setattr)(pc->pc_intr_v, ihp, attr, data);
225 }
226 
227 
228 __pci_inline void
229 pci_conf_interrupt(pci_chipset_tag_t pc, int bus, int device, int pin,
230     int swiz, int *iline)
231 {
232 	(*pc->pc_conf_interrupt)(pc->pc_conf_v, bus, device, pin, swiz, iline);
233 }
234 
235 __pci_inline int
236 pci_conf_hook(pci_chipset_tag_t pc, int bus, int device, int function,
237     pcireg_t id)
238 {
239 	return (*pc->pc_conf_hook)(pc->pc_conf_v, bus, device, function, id);
240 }
241 
242 #undef	__pci_inline
243 
244 /*
245  * Generic PowerPC PCI functions.  Override if necc.
246  */
247 
248 int genppc_pci_bus_maxdevs(void *, int);
249 const char *genppc_pci_intr_string(void *, pci_intr_handle_t);
250 const struct evcnt *genppc_pci_intr_evcnt(void *, pci_intr_handle_t);
251 void *genppc_pci_intr_establish(void *, pci_intr_handle_t, int, int (*)(void *),
252     void *);
253 void genppc_pci_intr_disestablish(void *, void *);
254 int genppc_pci_intr_setattr(void *, pci_intr_handle_t *, int, uint64_t);
255 void genppc_pci_conf_interrupt(void *, int, int, int, int, int *);
256 int genppc_pci_conf_hook(void *, int, int, int, pcireg_t);
257 int genppc_pci_intr_map(const struct pci_attach_args *,
258     pci_intr_handle_t *);
259 
260 /* generic indirect PCI functions */
261 void genppc_pci_indirect_attach_hook(device_t, device_t,
262     struct pcibus_attach_args *);
263 pcitag_t genppc_pci_indirect_make_tag(void *, int, int, int);
264 pcireg_t genppc_pci_indirect_conf_read(void *, pcitag_t, int);
265 void genppc_pci_indirect_conf_write(void *, pcitag_t, int, pcireg_t);
266 void genppc_pci_indirect_decompose_tag(void *, pcitag_t, int *, int *, int *);
267 
268 /* generic OFW method PCI functions */
269 void genppc_pci_ofmethod_attach_hook(device_t, device_t,
270     struct pcibus_attach_args *);
271 pcitag_t genppc_pci_ofmethod_make_tag(void *, int, int, int);
272 pcireg_t genppc_pci_ofmethod_conf_read(void *, pcitag_t, int);
273 void genppc_pci_ofmethod_conf_write(void *, pcitag_t, int, pcireg_t);
274 void genppc_pci_ofmethod_decompose_tag(void *, pcitag_t, int *, int *, int *);
275 
276 /* Generic OFW PCI functions */
277 
278 int genofw_find_picnode(int);
279 void genofw_find_ofpics(int);
280 void genofw_fixup_picnode_offsets(void);
281 void genofw_setup_pciintr_map(void *, struct genppc_pci_chipset_businfo *, int);
282 int genofw_find_node_by_devfunc(int, int, int, int);
283 int genofw_pci_intr_map(const struct pci_attach_args *, pci_intr_handle_t *);
284 int genofw_pci_conf_hook(void *, int, int, int, pcireg_t);
285 
286 /* OFW PCI structures and defines */
287 #define PICNODE_TYPE_OPENPIC	1
288 #define PICNODE_TYPE_8259	2
289 #define PICNODE_TYPE_HEATHROW	3
290 #define PICNODE_TYPE_OHARE	4
291 #define PICNODE_TYPE_IVR	5
292 
293 typedef struct _ofw_pic_node_t {
294 	int node;
295 	int parent;
296 	int16_t cells;
297 	int16_t intrs;
298 	int16_t offset;
299 	int16_t type;
300 } ofw_pic_node_t;
301 
302 #endif /* _KERNEL */
303 
304 #endif /* !_MODULE */
305 
306 #endif /* _PCI_MACHDEP_H_ */
307