pci_machdep.h revision 1.2 1 /* $NetBSD: pci_machdep.h,v 1.2 2007/10/17 19:56:41 garbled 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 * 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 #ifndef _PCI_MACHDEP_H_
40 #define _PCI_MACHDEP_H_
41
42 #include <prop/proplib.h>
43
44 /*
45 * Machine-specific definitions for PCI autoconfiguration.
46 */
47
48 #define __HAVE_PCI_CONF_HOOK
49
50 /*
51 * Types provided to machine-independent PCI code
52 */
53 typedef struct genppc_pci_chipset *pci_chipset_tag_t;
54 typedef int pcitag_t;
55 typedef int pci_intr_handle_t;
56
57 /*
58 * Forward declarations.
59 */
60 struct pci_attach_args;
61
62 /* Per bus information structure */
63 struct genppc_pci_chipset_businfo {
64 SIMPLEQ_ENTRY(genppc_pci_chipset_businfo) next;
65 prop_dictionary_t pbi_properties; /* chipset properties */
66 };
67
68 /*
69 * Generic PPC PCI structure and type definitions.
70 * NOT TO BE USED DIRECTLY BY MACHINE INDEPENDENT CODE.
71 */
72 struct genppc_pci_chipset {
73 void *pc_conf_v;
74 void (*pc_attach_hook)(struct device *,
75 struct device *, struct pcibus_attach_args *);
76 int (*pc_bus_maxdevs)(pci_chipset_tag_t, int);
77 pcitag_t (*pc_make_tag)(void *, int, int, int);
78 pcireg_t (*pc_conf_read)(void *, pcitag_t, int);
79 void (*pc_conf_write)(void *, pcitag_t, int, pcireg_t);
80
81 void *pc_intr_v;
82 int (*pc_intr_map)(struct pci_attach_args *,
83 pci_intr_handle_t *);
84 const char *(*pc_intr_string)(void *, pci_intr_handle_t);
85 const struct evcnt *(*pc_intr_evcnt)(void *, pci_intr_handle_t);
86 void *(*pc_intr_establish)(void *, pci_intr_handle_t,
87 int, int (*)(void *), void *);
88 void (*pc_intr_disestablish)(void *, void *);
89 void (*pc_conf_interrupt)(pci_chipset_tag_t, int, int, int,
90 int, int *);
91 void (*pc_decompose_tag)(void *, pcitag_t, int *,
92 int *, int *);
93 int (*pc_conf_hook)(pci_chipset_tag_t, int, int, int,
94 pcireg_t);
95
96 u_int32_t *pc_addr;
97 u_int32_t *pc_data;
98 int pc_node;
99 int pc_bus;
100 bus_space_tag_t pc_memt;
101 bus_space_tag_t pc_iot;
102
103 SIMPLEQ_HEAD(, genppc_pci_chipset_businfo) pc_pbi;
104 };
105
106 /*
107 * Functions provided to machine-independent PCI code.
108 */
109 #define pci_attach_hook(p, s, pba) \
110 (*(pba)->pba_pc->pc_attach_hook)((p), (s), (pba))
111 #define pci_bus_maxdevs(c, b) \
112 (*(c)->pc_bus_maxdevs)((c)->pc_conf_v, (b))
113 #define pci_make_tag(c, b, d, f) \
114 (*(c)->pc_make_tag)((c)->pc_conf_v, (b), (d), (f))
115 #define pci_conf_read(c, t, r) \
116 (*(c)->pc_conf_read)((c)->pc_conf_v, (t), (r))
117 #define pci_conf_write(c, t, r, v) \
118 (*(c)->pc_conf_write)((c)->pc_conf_v, (t), (r), (v))
119 #define pci_intr_map(pa, ihp) \
120 (*(pa)->pa_pc->pc_intr_map)((pa), (ihp))
121 #define pci_intr_string(c, ih) \
122 (*(c)->pc_intr_string)((c)->pc_intr_v, (ih))
123 #define pci_intr_evcnt(c, ih) \
124 (*(c)->pc_intr_evcnt)((c)->pc_intr_v, (ih))
125 #define pci_intr_establish(c, ih, l, h, a) \
126 (*(c)->pc_intr_establish)((c)->pc_intr_v, (ih), (l), (h), (a))
127 #define pci_intr_disestablish(c, iv) \
128 (*(c)->pc_intr_disestablish)((c)->pc_intr_v, (iv))
129 #define pci_conf_interrupt(c, b, d, p, s, ip) \
130 (*(c)->pc_conf_interrupt)((c)->pc_conf_v, (b), (d), (p), (s), (ip))
131 #define pci_decompose_tag(c, t, bp, dp, fp) \
132 (*(c)->pc_decompose_tag)((c)->pc_conf_v, (t), (bp), (dp), (fp))
133 #define pci_conf_hook(c, b, d, f, i) \
134 (*(c)->pc_conf_hook)((c)->pc_conf_v, (b), (d), (f), (i))
135
136 #ifdef _KERNEL
137
138 /*
139 * Generic PowerPC PCI functions. Override if necc.
140 */
141
142 int genppc_pci_bus_maxdevs(pci_chipset_tag_t, int);
143 const char *genppc_pci_intr_string(void *, pci_intr_handle_t);
144 const struct evcnt *genppc_pci_intr_evcnt(void *, pci_intr_handle_t);
145 void *genppc_pci_intr_establish(void *, pci_intr_handle_t, int, int (*)(void *),
146 void *);
147 void genppc_pci_intr_disestablish(void *, void *);
148 void genppc_pci_conf_interrupt(pci_chipset_tag_t, int, int, int, int, int *);
149 int genppc_pci_conf_hook(pci_chipset_tag_t, int, int, int, pcireg_t);
150 int genppc_pci_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp);
151
152 /* generic indirect PCI functions */
153 void genppc_pci_indirect_attach_hook(struct device *, struct device *,
154 struct pcibus_attach_args *);
155 pcitag_t genppc_pci_indirect_make_tag(void *, int, int, int);
156 pcireg_t genppc_pci_indirect_conf_read(void *, pcitag_t, int);
157 void genppc_pci_indirect_conf_write(void *, pcitag_t, int, pcireg_t);
158 void genppc_pci_indirect_decompose_tag(void *, pcitag_t, int *, int *, int *);
159
160 /* XXX for now macppc needs its own pci_bus_dma_tag */
161 #ifndef macppc
162 extern struct powerpc_bus_dma_tag pci_bus_dma_tag;
163 #endif
164
165 /* Generic OFW PCI functions */
166
167 int genofw_find_picnode(int);
168 void genofw_find_ofpics(int);
169 void genofw_fixup_picnode_offsets(void);
170 void genofw_setup_pciintr_map(struct genppc_pci_chipset_businfo *, int);
171 int genofw_find_node_by_devfunc(int, int, int, int);
172 int genofw_pci_intr_map(struct pci_attach_args *, pci_intr_handle_t *);
173 int genofw_pci_conf_hook(pci_chipset_tag_t, int, int, int, pcireg_t);
174
175
176 /* OFW PCI structures and defines */
177 #define PICNODE_TYPE_OPENPIC 1
178 #define PICNODE_TYPE_8259 2
179 #define PICNODE_TYPE_HEATHROW 3
180 #define PICNODE_TYPE_OHARE 4
181
182 typedef struct _ofw_pic_node_t {
183 int node;
184 int parent;
185 int16_t cells;
186 int16_t intrs;
187 int16_t offset;
188 int16_t type;
189 } ofw_pic_node_t;
190
191 #endif /* _KERNEL */
192
193 #endif /* _PCI_MACHDEP_H_ */
194