cardbusvar.h revision 1.38 1 /* $NetBSD: cardbusvar.h,v 1.38 2008/01/02 23:11:34 dyoung 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 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the author.
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
20 *
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
26 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 */
34
35 #ifndef _DEV_CARDBUS_CARDBUSVAR_H_
36 #define _DEV_CARDBUS_CARDBUSVAR_H_
37
38 #include <dev/cardbus/cardbusreg.h>
39 #if 1
40 #include <dev/cardbus/rbus.h>
41 #endif
42
43 struct {
44 int dummy;
45 } cardbus_chipset_tag;
46
47 typedef struct cardbus_chipset_tag *cardbus_chipset_tag_t;
48 typedef int cardbus_intr_handle_t;
49
50
51 #if rbus
52 /*
53 * struct cardbus_functions contains the pointers for basic cardbus
54 * functions. Those functions must be provided by cardbus bridge.
55 * The child devices can use those functions. The contained functions
56 * are: cardbus_space_alloc, cardbus_space_free,
57 * cardbus_intr_establish, cardbus_intr_disestablish, cardbus_ctrl,
58 * cardbus_power, cardbus_make_tag, cardbus_free_tag and
59 * cardbus_conf_write.
60 *
61 * int (*cardbus_space_alloc)(cardbus_chipset_tag_t ct, rbus_tag_t rb,
62 * bus_addr_t addr, bus_size_t size,
63 * bus_addr_t mask, bus_size_t align,
64 * int flags, bus_addr_t *addrp,
65 * bus_space_handle_t *bshp);
66 *
67 * int (*cardbus_space_free)(cardbus_chipset_tag_t ct, rbus_tag_t rb,
68 * bus_space_handle_t, bus_size_t);
69 *
70 * cardbus_space_alloc and cardbus_space_free allocates and
71 * disallocate bus space for the requesters.
72 *
73 * void *(*cardbus_intr_establish)(cardbus_chipset_tag_t ct, int irq,
74 * int level, int (*ih)(void *), void *sc);
75 *
76 * void (*cardbus_intr_disestablish)(cardbus_chipset_tag_t ct, void *ih);
77 * int (*cardbus_ctrl)(cardbus_chipset_tag_t ct, int command);
78 * int (*cardbus_power)(cardbus_chipset_tag_t ct, int voltage);
79 *
80 * cardbustag_t (*cardbus_make_tag)(cardbus_chipset_tag_t ct,
81 * int busno, int functionno);
82 * void (*cardbus_free_tag)(cardbus_chipset_tag_t ct, cardbustag_t tag);
83 * cardbusreg_t (*cardbus_conf_read)(cardbus_chipset_tag_t ct,
84 * cardbustag_t tag, int offs);
85 * void (*cardbus_conf_write)(cardbus_chipset_tag_t ct,
86 * cardbustag_t tag, int offs, cardbusreg_t val);
87 */
88 typedef struct cardbus_functions {
89 int (*cardbus_space_alloc)(cardbus_chipset_tag_t, rbus_tag_t,
90 bus_addr_t, bus_size_t, bus_addr_t, bus_size_t,
91 int, bus_addr_t *, bus_space_handle_t *);
92 int (*cardbus_space_free)(cardbus_chipset_tag_t, rbus_tag_t,
93 bus_space_handle_t, bus_size_t);
94 void *(*cardbus_intr_establish)(cardbus_chipset_tag_t, int, int,
95 int (*)(void *), void *);
96 void (*cardbus_intr_disestablish)(cardbus_chipset_tag_t, void *);
97 int (*cardbus_ctrl)(cardbus_chipset_tag_t, int);
98 int (*cardbus_power)(cardbus_chipset_tag_t, int);
99
100 cardbustag_t (*cardbus_make_tag)(cardbus_chipset_tag_t, int, int);
101 void (*cardbus_free_tag)(cardbus_chipset_tag_t, cardbustag_t);
102 cardbusreg_t (*cardbus_conf_read)(cardbus_chipset_tag_t,
103 cardbustag_t, int);
104 void (*cardbus_conf_write)(cardbus_chipset_tag_t, cardbustag_t,
105 int, cardbusreg_t);
106 } cardbus_function_t, *cardbus_function_tag_t;
107
108 #else
109
110 typedef struct cardbus_functions {
111 int (*cardbus_ctrl)(cardbus_chipset_tag_t, int);
112 int (*cardbus_power)(cardbus_chipset_tag_t, int);
113 int (*cardbus_mem_open)(cardbus_chipset_tag_t, int, u_int32_t,
114 u_int32_t);
115 int (*cardbus_mem_close)(cardbus_chipset_tag_t, int);
116 int (*cardbus_io_open)(cardbus_chipset_tag_t, int, u_int32_t,
117 u_int32_t);
118 int (*cardbus_io_close)(cardbus_chipset_tag_t, int);
119 void *(*cardbus_intr_establish)(cardbus_chipset_tag_t, int, int,
120 int (*)(void *), void *);
121 void (*cardbus_intr_disestablish)(cardbus_chipset_tag_t, void *);
122
123 cardbustag_t (*cardbus_make_tag)(cardbus_chipset_tag_t, int, int);
124 cardbusreg_t (*cardbus_conf_read)(cardbus_chipset_tag_t,
125 cardbustag_t, int);
126 void (*cardbus_conf_write)(cardbus_chipset_tag_t, cardbustag_t,
127 int, cardbusreg_t);
128 } cardbus_function_t, *cardbus_function_tag_t;
129 #endif /* rbus */
130
131 /*
132 * struct cbslot_attach_args is the attach argument for Cardbus cardslot.
133 */
134 struct cbslot_attach_args {
135 const char *cba_busname;
136 bus_space_tag_t cba_iot; /* cardbus i/o space tag */
137 bus_space_tag_t cba_memt; /* cardbus mem space tag */
138 bus_dma_tag_t cba_dmat; /* DMA tag */
139
140 int cba_bus; /* cardbus bus number */
141
142 cardbus_chipset_tag_t cba_cc; /* cardbus chipset */
143 cardbus_function_tag_t cba_cf; /* cardbus functions */
144 int cba_intrline; /* interrupt line */
145
146 #if rbus
147 rbus_tag_t cba_rbus_iot; /* CardBus i/o rbus tag */
148 rbus_tag_t cba_rbus_memt; /* CardBus mem rbus tag */
149 #endif
150
151 int cba_cacheline; /* cache line size */
152 int cba_max_lattimer; /* No card's latency timer may
153 * exceed this. On a PCI-Cardbus
154 * bridge, I let the latency timer on
155 * the primary bus (PCI bus) set
156 * the maximum. That is kind of an
157 * arbitrary choice. A more sensible
158 * choice may be either the
159 * latency timer on the primary bus,
160 * or the bridge's buffer size,
161 * whichever is larger.
162 */
163 };
164
165
166 struct cardbus_devfunc;
167
168 /*
169 * struct cardbus_softc is the softc for cardbus card.
170 */
171 struct cardbus_softc {
172 struct device sc_dev; /* fundamental device structure */
173
174 int sc_bus; /* cardbus bus number */
175 int sc_intrline; /* CardBus intrline */
176
177 bus_space_tag_t sc_iot; /* CardBus I/O space tag */
178 bus_space_tag_t sc_memt; /* CardBus MEM space tag */
179 bus_dma_tag_t sc_dmat; /* DMA tag */
180
181 cardbus_chipset_tag_t sc_cc; /* CardBus chipset */
182 cardbus_function_tag_t sc_cf; /* CardBus function */
183
184 #if rbus
185 rbus_tag_t sc_rbus_iot; /* CardBus i/o rbus tag */
186 rbus_tag_t sc_rbus_memt; /* CardBus mem rbus tag */
187 #endif
188
189 int sc_cacheline; /* cache line size */
190 int sc_max_lattimer; /* No card's latency timer
191 * may exceed this. On a PCI-Cardbus
192 * bridge, the latency timer on
193 * the primary bus (PCI bus) sets
194 * the maximum.
195 */
196 int sc_volt; /* applied Vcc voltage */
197 #define PCCARD_33V 0x02
198 #define PCCARD_XXV 0x04
199 #define PCCARD_YYV 0x08
200 int sc_poweron_func;
201 struct cardbus_devfunc *sc_funcs[8]; /* list of cardbus device functions */
202 };
203
204 struct cardbus_conf_state {
205 cardbusreg_t reg[16];
206 };
207
208 /*
209 * struct cardbus_devfunc:
210 *
211 * This is the data deposit for each function of a CardBus device.
212 * This structure is used for memory or i/o space allocation and
213 * disallocation.
214 */
215 typedef struct cardbus_devfunc {
216 cardbus_chipset_tag_t ct_cc;
217 cardbus_function_tag_t ct_cf;
218 struct cardbus_softc *ct_sc; /* pointer to the parent */
219 int ct_bus; /* bus number */
220 int ct_func; /* function number */
221
222 #if rbus
223 rbus_tag_t ct_rbus_iot; /* CardBus i/o rbus tag */
224 rbus_tag_t ct_rbus_memt; /* CardBus mem rbus tag */
225 #endif
226
227 cardbusreg_t ct_bar[6]; /* Base Address Regs 0 to 6 */
228 cardbusreg_t ct_bhlc; /* Latency timer and cache line size */
229 /* u_int32_t ct_cisreg; */ /* CIS reg: is it needed??? */
230
231 struct device *ct_device; /* pointer to the device */
232
233 /* some data structure needed for tuple??? */
234 } *cardbus_devfunc_t;
235
236
237 /* XXX various things extracted from CIS */
238 struct cardbus_cis_info {
239 int32_t manufacturer;
240 int32_t product;
241 char cis1_info_buf[256];
242 char* cis1_info[4];
243 struct cb_bar_info {
244 unsigned int flags;
245 unsigned int size;
246 } bar[7];
247 unsigned int funcid;
248 union {
249 struct {
250 int uart_type;
251 int uart_present;
252 } serial;
253 struct {
254 char netid[6];
255 char netid_present;
256 char __filler;
257 } network;
258 } funce;
259 };
260
261 struct cardbus_attach_args {
262 cardbus_devfunc_t ca_ct;
263
264 bus_space_tag_t ca_iot; /* CardBus I/O space tag */
265 bus_space_tag_t ca_memt; /* CardBus MEM space tag */
266 bus_dma_tag_t ca_dmat; /* DMA tag */
267
268 u_int ca_bus;
269 u_int ca_function;
270 cardbustag_t ca_tag;
271 cardbusreg_t ca_id;
272 cardbusreg_t ca_class;
273
274 /* interrupt information */
275 cardbus_intr_line_t ca_intrline;
276
277 #if rbus
278 rbus_tag_t ca_rbus_iot; /* CardBus i/o rbus tag */
279 rbus_tag_t ca_rbus_memt; /* CardBus mem rbus tag */
280 #endif
281
282 struct cardbus_cis_info ca_cis;
283 };
284
285
286 #define CARDBUS_ENABLE 1 /* enable the channel */
287 #define CARDBUS_DISABLE 2 /* disable the channel */
288 #define CARDBUS_RESET 4
289 #define CARDBUS_CD 7
290 # define CARDBUS_NOCARD 0
291 # define CARDBUS_5V_CARD 0x01 /* XXX: It must not exist */
292 # define CARDBUS_3V_CARD 0x02
293 # define CARDBUS_XV_CARD 0x04
294 # define CARDBUS_YV_CARD 0x08
295 #define CARDBUS_IO_ENABLE 100
296 #define CARDBUS_IO_DISABLE 101
297 #define CARDBUS_MEM_ENABLE 102
298 #define CARDBUS_MEM_DISABLE 103
299 #define CARDBUS_BM_ENABLE 104 /* bus master */
300 #define CARDBUS_BM_DISABLE 105
301
302 #define CARDBUS_VCC_UC 0x0000
303 #define CARDBUS_VCC_3V 0x0001
304 #define CARDBUS_VCC_XV 0x0002
305 #define CARDBUS_VCC_YV 0x0003
306 #define CARDBUS_VCC_0V 0x0004
307 #define CARDBUS_VCC_5V 0x0005 /* ??? */
308 #define CARDBUS_VCCMASK 0x000f
309 #define CARDBUS_VPP_UC 0x0000
310 #define CARDBUS_VPP_VCC 0x0010
311 #define CARDBUS_VPP_12V 0x0030
312 #define CARDBUS_VPP_0V 0x0040
313 #define CARDBUS_VPPMASK 0x00f0
314
315
316 int cardbus_attach_card(struct cardbus_softc *);
317 void cardbus_detach_card(struct cardbus_softc *);
318 void *cardbus_intr_establish(cardbus_chipset_tag_t, cardbus_function_tag_t,
319 cardbus_intr_handle_t, int, int (*) (void *), void *arg);
320 void cardbus_intr_disestablish(cardbus_chipset_tag_t,
321 cardbus_function_tag_t, void *);
322
323 int cardbus_mapreg_map(struct cardbus_softc *, int, int, cardbusreg_t,
324 int, bus_space_tag_t *, bus_space_handle_t *, bus_addr_t *, bus_size_t *);
325 int cardbus_mapreg_unmap(struct cardbus_softc *, int, int,
326 bus_space_tag_t, bus_space_handle_t, bus_size_t);
327
328 int cardbus_save_bar(cardbus_devfunc_t);
329 int cardbus_restore_bar(cardbus_devfunc_t);
330
331 int cardbus_function_enable(struct cardbus_softc *, int);
332 int cardbus_function_disable(struct cardbus_softc *, int);
333
334 void cardbus_disable_retry(cardbus_chipset_tag_t, cardbus_function_tag_t,
335 cardbustag_t);
336
337 int cardbus_get_capability(cardbus_chipset_tag_t, cardbus_function_tag_t,
338 cardbustag_t, int, int *, cardbusreg_t *);
339 int cardbus_get_powerstate(cardbus_devfunc_t, cardbustag_t, cardbusreg_t *);
340 int cardbus_set_powerstate(cardbus_devfunc_t, cardbustag_t, cardbusreg_t);
341
342 void cardbus_conf_capture(cardbus_chipset_tag_t, cardbus_function_tag_t,
343 cardbustag_t, struct cardbus_conf_state *);
344 void cardbus_conf_restore(cardbus_chipset_tag_t, cardbus_function_tag_t,
345 cardbustag_t, struct cardbus_conf_state *);
346
347 #define Cardbus_function_enable(ct) cardbus_function_enable((ct)->ct_sc, (ct)->ct_func)
348 #define Cardbus_function_disable(ct) cardbus_function_disable((ct)->ct_sc, (ct)->ct_func)
349
350
351
352 #define Cardbus_mapreg_map(ct, reg, type, busflags, tagp, handlep, basep, sizep) \
353 cardbus_mapreg_map((ct)->ct_sc, (ct->ct_func), (reg), (type),\
354 (busflags), (tagp), (handlep), (basep), (sizep))
355 #define Cardbus_mapreg_unmap(ct, reg, tag, handle, size) \
356 cardbus_mapreg_unmap((ct)->ct_sc, (ct->ct_func), (reg), (tag), (handle), (size))
357
358 #define Cardbus_make_tag(ct) (*(ct)->ct_cf->cardbus_make_tag)((ct)->ct_cc, (ct)->ct_bus, (ct)->ct_func)
359 #define cardbus_make_tag(cc, cf, bus, function) ((cf)->cardbus_make_tag)((cc), (bus), (function))
360
361 #define Cardbus_free_tag(ct, tag) (*(ct)->ct_cf->cardbus_free_tag)((ct)->ct_cc, (tag))
362 #define cardbus_free_tag(cc, cf, tag) (*(cf)->cardbus_free_tag)(cc, (tag))
363
364 #define Cardbus_conf_read(ct, tag, offs) (*(ct)->ct_cf->cardbus_conf_read)((ct)->ct_cc, (tag), (offs))
365 #define cardbus_conf_read(cc, cf, tag, offs) ((cf)->cardbus_conf_read)((cc), (tag), (offs))
366 #define Cardbus_conf_write(ct, tag, offs, val) (*(ct)->ct_cf->cardbus_conf_write)((ct)->ct_cc, (tag), (offs), (val))
367 #define cardbus_conf_write(cc, cf, tag, offs, val) ((cf)->cardbus_conf_write)((cc), (tag), (offs), (val))
368
369 #endif /* !_DEV_CARDBUS_CARDBUSVAR_H_ */
370