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