1 | /* $NetBSD: cardbusvar.h,v 1.56 2012/02/18 00:36:57 matt Exp $ */ |
2 | |
3 | /* |
4 | * Copyright (c) 1998, 1999 and 2000 |
5 | * HAYAKAWA Koichi. All rights reserved. |
6 | * |
7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions |
9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. |
15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, |
20 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
22 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
24 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
25 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
26 | * POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
28 | |
29 | #ifndef _DEV_CARDBUS_CARDBUSVAR_H_ |
30 | #define _DEV_CARDBUS_CARDBUSVAR_H_ |
31 | |
32 | #include <dev/cardbus/cardbusreg.h> |
33 | #include <dev/cardbus/rbus.h> |
34 | |
35 | typedef struct cardbus_chipset_tag *cardbus_chipset_tag_t; |
36 | |
37 | /* |
38 | * struct cardbus_functions contains the pointers for basic cardbus |
39 | * functions. Those functions must be provided by cardbus bridge. |
40 | * The child devices can use those functions. The contained functions |
41 | * are: cardbus_space_alloc, cardbus_space_free, |
42 | * cardbus_intr_establish, cardbus_intr_disestablish, cardbus_ctrl, |
43 | * cardbus_power, cardbus_make_tag, and cardbus_conf_write. |
44 | * |
45 | * int (*cardbus_space_alloc)(cardbus_chipset_tag_t ct, rbus_tag_t rb, |
46 | * bus_addr_t addr, bus_size_t size, |
47 | * bus_addr_t mask, bus_size_t align, |
48 | * int flags, bus_addr_t *addrp, |
49 | * bus_space_handle_t *bshp); |
50 | * |
51 | * int (*cardbus_space_free)(cardbus_chipset_tag_t ct, rbus_tag_t rb, |
52 | * bus_space_handle_t, bus_size_t); |
53 | * |
54 | * cardbus_space_alloc and cardbus_space_free allocates and |
55 | * disallocate bus space for the requesters. |
56 | * |
57 | * void *(*cardbus_intr_establish)(cardbus_chipset_tag_t ct, int irq, |
58 | * int level, int (*ih)(void *), void *sc); |
59 | * |
60 | * void (*cardbus_intr_disestablish)(cardbus_chipset_tag_t ct, void *ih); |
61 | * int (*cardbus_ctrl)(cardbus_chipset_tag_t ct, int command); |
62 | * int (*cardbus_power)(cardbus_chipset_tag_t ct, int voltage); |
63 | * |
64 | * pcitag_t (*cardbus_make_tag)(cardbus_chipset_tag_t ct, |
65 | * int busno, int functionno); |
66 | * pcireg_t (*cardbus_conf_read)(cardbus_chipset_tag_t ct, |
67 | * pcitag_t tag, int offs); |
68 | * void (*cardbus_conf_write)(cardbus_chipset_tag_t ct, |
69 | * pcitag_t tag, int offs, pcireg_t val); |
70 | */ |
71 | typedef const struct cardbus_functions { |
72 | int (*cardbus_space_alloc)(cardbus_chipset_tag_t, rbus_tag_t, |
73 | bus_addr_t, bus_size_t, bus_addr_t, bus_size_t, |
74 | int, bus_addr_t *, bus_space_handle_t *); |
75 | int (*cardbus_space_free)(cardbus_chipset_tag_t, rbus_tag_t, |
76 | bus_space_handle_t, bus_size_t); |
77 | void *(*cardbus_intr_establish)(cardbus_chipset_tag_t, |
78 | int, int (*)(void *), void *); |
79 | void (*cardbus_intr_disestablish)(cardbus_chipset_tag_t, void *); |
80 | int (*cardbus_ctrl)(cardbus_chipset_tag_t, int); |
81 | int (*cardbus_power)(cardbus_chipset_tag_t, int); |
82 | |
83 | pcitag_t (*cardbus_make_tag)(cardbus_chipset_tag_t, int, int); |
84 | pcireg_t (*cardbus_conf_read)(cardbus_chipset_tag_t, |
85 | pcitag_t, int); |
86 | void (*cardbus_conf_write)(cardbus_chipset_tag_t, pcitag_t, |
87 | int, pcireg_t); |
88 | } cardbus_function_t, *cardbus_function_tag_t; |
89 | |
90 | /* |
91 | * struct cbslot_attach_args is the attach argument for Cardbus cardslot. |
92 | */ |
93 | struct cbslot_attach_args { |
94 | bus_space_tag_t cba_iot; /* cardbus i/o space tag */ |
95 | bus_space_tag_t cba_memt; /* cardbus mem space tag */ |
96 | bus_dma_tag_t cba_dmat; /* DMA tag */ |
97 | |
98 | int cba_bus; /* cardbus bus number */ |
99 | |
100 | cardbus_chipset_tag_t cba_cc; /* cardbus chipset */ |
101 | cardbus_function_tag_t cba_cf; /* cardbus functions */ |
102 | |
103 | rbus_tag_t cba_rbus_iot; /* CardBus i/o rbus tag */ |
104 | rbus_tag_t cba_rbus_memt; /* CardBus mem rbus tag */ |
105 | |
106 | int cba_cacheline; /* cache line size */ |
107 | int cba_max_lattimer; /* No card's latency timer may |
108 | * exceed this. On a PCI-Cardbus |
109 | * bridge, I let the latency timer on |
110 | * the primary bus (PCI bus) set |
111 | * the maximum. That is kind of an |
112 | * arbitrary choice. A more sensible |
113 | * choice may be either the |
114 | * latency timer on the primary bus, |
115 | * or the bridge's buffer size, |
116 | * whichever is larger. |
117 | */ |
118 | }; |
119 | |
120 | |
121 | struct cardbus_devfunc; |
122 | |
123 | /* |
124 | * struct cardbus_softc is the softc for cardbus card. |
125 | */ |
126 | struct cardbus_softc { |
127 | device_t sc_dev; /* fundamental device structure */ |
128 | |
129 | int sc_bus; /* cardbus bus number */ |
130 | |
131 | bus_space_tag_t sc_iot; /* CardBus I/O space tag */ |
132 | bus_space_tag_t sc_memt; /* CardBus MEM space tag */ |
133 | bus_dma_tag_t sc_dmat; /* DMA tag */ |
134 | |
135 | cardbus_chipset_tag_t sc_cc; /* CardBus chipset */ |
136 | cardbus_function_tag_t sc_cf; /* CardBus function */ |
137 | |
138 | rbus_tag_t sc_rbus_iot; /* CardBus i/o rbus tag */ |
139 | rbus_tag_t sc_rbus_memt; /* CardBus mem rbus tag */ |
140 | |
141 | int sc_cacheline; /* cache line size */ |
142 | int sc_max_lattimer; /* No card's latency timer |
143 | * may exceed this. On a PCI-Cardbus |
144 | * bridge, the latency timer on |
145 | * the primary bus (PCI bus) sets |
146 | * the maximum. |
147 | */ |
148 | int sc_poweron_func; |
149 | struct cardbus_devfunc *sc_funcs[8]; /* list of cardbus device functions */ |
150 | }; |
151 | |
152 | struct cardbus_conf_state { |
153 | pcireg_t reg[16]; |
154 | }; |
155 | |
156 | /* |
157 | * struct cardbus_devfunc: |
158 | * |
159 | * This is the data deposit for each function of a CardBus device. |
160 | * This structure is used for memory or i/o space allocation and |
161 | * disallocation. |
162 | */ |
163 | typedef struct cardbus_devfunc { |
164 | cardbus_chipset_tag_t ct_cc; |
165 | cardbus_function_tag_t ct_cf; |
166 | struct cardbus_softc *ct_sc; /* pointer to the parent */ |
167 | int ct_bus; /* bus number */ |
168 | int ct_func; /* function number */ |
169 | |
170 | pcireg_t ct_bhlc; /* Latency timer and cache line size */ |
171 | /* u_int32_t ct_cisreg; */ /* CIS reg: is it needed??? */ |
172 | |
173 | device_t ct_device; /* pointer to the device */ |
174 | |
175 | /* some data structure needed for tuple??? */ |
176 | } *cardbus_devfunc_t; |
177 | |
178 | |
179 | /* XXX various things extracted from CIS */ |
180 | struct cardbus_cis_info { |
181 | int32_t manufacturer; |
182 | int32_t product; |
183 | char cis1_info_buf[256]; |
184 | char* cis1_info[4]; |
185 | struct cb_bar_info { |
186 | unsigned int flags; |
187 | unsigned int size; |
188 | } bar[7]; |
189 | unsigned int funcid; |
190 | union { |
191 | struct { |
192 | int uart_type; |
193 | int uart_present; |
194 | } serial; |
195 | struct { |
196 | char netid[6]; |
197 | char netid_present; |
198 | char __filler; |
199 | } network; |
200 | } funce; |
201 | }; |
202 | |
203 | struct cardbus_attach_args { |
204 | cardbus_devfunc_t ca_ct; |
205 | |
206 | bus_space_tag_t ca_iot; /* CardBus I/O space tag */ |
207 | bus_space_tag_t ca_memt; /* CardBus MEM space tag */ |
208 | bus_dma_tag_t ca_dmat; /* DMA tag */ |
209 | |
210 | u_int ca_bus; |
211 | u_int ca_function; |
212 | pcitag_t ca_tag; |
213 | pcireg_t ca_id; |
214 | pcireg_t ca_class; |
215 | |
216 | rbus_tag_t ca_rbus_iot; /* CardBus i/o rbus tag */ |
217 | rbus_tag_t ca_rbus_memt; /* CardBus mem rbus tag */ |
218 | |
219 | struct cardbus_cis_info ca_cis; |
220 | }; |
221 | |
222 | |
223 | #define CARDBUS_ENABLE 1 /* enable the channel */ |
224 | #define CARDBUS_DISABLE 2 /* disable the channel */ |
225 | #define CARDBUS_RESET 4 |
226 | #define CARDBUS_CD 7 |
227 | # define CARDBUS_NOCARD 0 |
228 | # define CARDBUS_5V_CARD 0x01 /* XXX: It must not exist */ |
229 | # define CARDBUS_3V_CARD 0x02 |
230 | # define CARDBUS_XV_CARD 0x04 |
231 | # define CARDBUS_YV_CARD 0x08 |
232 | #define CARDBUS_IO_ENABLE 100 |
233 | #define CARDBUS_IO_DISABLE 101 |
234 | #define CARDBUS_MEM_ENABLE 102 |
235 | #define CARDBUS_MEM_DISABLE 103 |
236 | #define CARDBUS_BM_ENABLE 104 /* bus master */ |
237 | #define CARDBUS_BM_DISABLE 105 |
238 | |
239 | #define CARDBUS_VCC_UC 0x0000 |
240 | #define CARDBUS_VCC_3V 0x0001 |
241 | #define CARDBUS_VCC_XV 0x0002 |
242 | #define CARDBUS_VCC_YV 0x0003 |
243 | #define CARDBUS_VCC_0V 0x0004 |
244 | #define CARDBUS_VCC_5V 0x0005 /* ??? */ |
245 | #define CARDBUS_VCCMASK 0x000f |
246 | #define CARDBUS_VPP_UC 0x0000 |
247 | #define CARDBUS_VPP_VCC 0x0010 |
248 | #define CARDBUS_VPP_12V 0x0030 |
249 | #define CARDBUS_VPP_0V 0x0040 |
250 | #define CARDBUS_VPPMASK 0x00f0 |
251 | |
252 | |
253 | int cardbus_attach_card(struct cardbus_softc *); |
254 | void cardbus_detach_card(struct cardbus_softc *); |
255 | void *Cardbus_intr_establish(cardbus_devfunc_t, |
256 | int, int (*)(void *), void *); |
257 | void Cardbus_intr_disestablish(cardbus_devfunc_t, void *); |
258 | void *cardbus_intr_establish(cardbus_chipset_tag_t, cardbus_function_tag_t, |
259 | int, int (*) (void *), void *arg); |
260 | void cardbus_intr_disestablish(cardbus_chipset_tag_t, cardbus_function_tag_t, |
261 | void *); |
262 | |
263 | int cardbus_mapreg_map(struct cardbus_softc *, int, int, pcireg_t, |
264 | int, bus_space_tag_t *, bus_space_handle_t *, bus_addr_t *, bus_size_t *); |
265 | int cardbus_mapreg_unmap(struct cardbus_softc *, int, int, |
266 | bus_space_tag_t, bus_space_handle_t, bus_size_t); |
267 | |
268 | int cardbus_function_enable(struct cardbus_softc *, int); |
269 | int cardbus_function_disable(struct cardbus_softc *, int); |
270 | |
271 | int cardbus_get_capability(cardbus_chipset_tag_t, cardbus_function_tag_t, |
272 | pcitag_t, int, int *, pcireg_t *); |
273 | int cardbus_get_powerstate(cardbus_devfunc_t, pcitag_t, pcireg_t *); |
274 | int cardbus_set_powerstate(cardbus_devfunc_t, pcitag_t, pcireg_t); |
275 | |
276 | void cardbus_conf_capture(cardbus_chipset_tag_t, cardbus_function_tag_t, |
277 | pcitag_t, struct cardbus_conf_state *); |
278 | void cardbus_conf_restore(cardbus_chipset_tag_t, cardbus_function_tag_t, |
279 | pcitag_t, struct cardbus_conf_state *); |
280 | |
281 | #define Cardbus_function_enable(ct) cardbus_function_enable((ct)->ct_sc, (ct)->ct_func) |
282 | #define Cardbus_function_disable(ct) cardbus_function_disable((ct)->ct_sc, (ct)->ct_func) |
283 | |
284 | |
285 | |
286 | #define Cardbus_mapreg_map(ct, reg, type, busflags, tagp, handlep, basep, sizep) \ |
287 | cardbus_mapreg_map((ct)->ct_sc, (ct->ct_func), (reg), (type),\ |
288 | (busflags), (tagp), (handlep), (basep), (sizep)) |
289 | #define Cardbus_mapreg_unmap(ct, reg, tag, handle, size) \ |
290 | cardbus_mapreg_unmap((ct)->ct_sc, (ct->ct_func), (reg), (tag), (handle), (size)) |
291 | |
292 | #define Cardbus_make_tag(ct) (*(ct)->ct_cf->cardbus_make_tag)((ct)->ct_cc, (ct)->ct_bus, (ct)->ct_func) |
293 | #define cardbus_make_tag(cc, cf, bus, function) ((cf)->cardbus_make_tag)((cc), (bus), (function)) |
294 | |
295 | #define Cardbus_conf_read(ct, tag, offs) (*(ct)->ct_cf->cardbus_conf_read)((ct)->ct_cc, (tag), (offs)) |
296 | #define cardbus_conf_read(cc, cf, tag, offs) ((cf)->cardbus_conf_read)((cc), (tag), (offs)) |
297 | #define Cardbus_conf_write(ct, tag, offs, val) (*(ct)->ct_cf->cardbus_conf_write)((ct)->ct_cc, (tag), (offs), (val)) |
298 | #define cardbus_conf_write(cc, cf, tag, offs, val) ((cf)->cardbus_conf_write)((cc), (tag), (offs), (val)) |
299 | |
300 | #endif /* !_DEV_CARDBUS_CARDBUSVAR_H_ */ |
301 | |