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