1 /* $NetBSD: cardbusvar.h,v 1.43 2008/06/26 12:33:17 drochner Exp $ */
4 * Copyright (c) 1998, 1999 and 2000
5 * HAYAKAWA Koichi. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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.
29 #ifndef _DEV_CARDBUS_CARDBUSVAR_H_
30 #define _DEV_CARDBUS_CARDBUSVAR_H_
32 #include <dev/cardbus/cardbusreg.h>
34 #include <dev/cardbus/rbus.h>
39 } cardbus_chipset_tag
;
41 typedef struct cardbus_chipset_tag
*cardbus_chipset_tag_t
;
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, cardbus_free_tag and
53 * int (*cardbus_space_alloc)(cardbus_chipset_tag_t ct, rbus_tag_t rb,
54 * bus_addr_t addr, bus_size_t size,
55 * bus_addr_t mask, bus_size_t align,
56 * int flags, bus_addr_t *addrp,
57 * bus_space_handle_t *bshp);
59 * int (*cardbus_space_free)(cardbus_chipset_tag_t ct, rbus_tag_t rb,
60 * bus_space_handle_t, bus_size_t);
62 * cardbus_space_alloc and cardbus_space_free allocates and
63 * disallocate bus space for the requesters.
65 * void *(*cardbus_intr_establish)(cardbus_chipset_tag_t ct, int irq,
66 * int level, int (*ih)(void *), void *sc);
68 * void (*cardbus_intr_disestablish)(cardbus_chipset_tag_t ct, void *ih);
69 * int (*cardbus_ctrl)(cardbus_chipset_tag_t ct, int command);
70 * int (*cardbus_power)(cardbus_chipset_tag_t ct, int voltage);
72 * cardbustag_t (*cardbus_make_tag)(cardbus_chipset_tag_t ct,
73 * int busno, int functionno);
74 * void (*cardbus_free_tag)(cardbus_chipset_tag_t ct, cardbustag_t tag);
75 * cardbusreg_t (*cardbus_conf_read)(cardbus_chipset_tag_t ct,
76 * cardbustag_t tag, int offs);
77 * void (*cardbus_conf_write)(cardbus_chipset_tag_t ct,
78 * cardbustag_t tag, int offs, cardbusreg_t val);
80 typedef const struct cardbus_functions
{
81 int (*cardbus_space_alloc
)(cardbus_chipset_tag_t
, rbus_tag_t
,
82 bus_addr_t
, bus_size_t
, bus_addr_t
, bus_size_t
,
83 int, bus_addr_t
*, bus_space_handle_t
*);
84 int (*cardbus_space_free
)(cardbus_chipset_tag_t
, rbus_tag_t
,
85 bus_space_handle_t
, bus_size_t
);
86 void *(*cardbus_intr_establish
)(cardbus_chipset_tag_t
,
87 cardbus_intr_line_t
, int, int (*)(void *), void *);
88 void (*cardbus_intr_disestablish
)(cardbus_chipset_tag_t
, void *);
89 int (*cardbus_ctrl
)(cardbus_chipset_tag_t
, int);
90 int (*cardbus_power
)(cardbus_chipset_tag_t
, int);
92 cardbustag_t (*cardbus_make_tag
)(cardbus_chipset_tag_t
, int, int);
93 void (*cardbus_free_tag
)(cardbus_chipset_tag_t
, cardbustag_t
);
94 cardbusreg_t (*cardbus_conf_read
)(cardbus_chipset_tag_t
,
96 void (*cardbus_conf_write
)(cardbus_chipset_tag_t
, cardbustag_t
,
98 } cardbus_function_t
, *cardbus_function_tag_t
;
102 typedef const struct cardbus_functions
{
103 int (*cardbus_ctrl
)(cardbus_chipset_tag_t
, int);
104 int (*cardbus_power
)(cardbus_chipset_tag_t
, int);
105 int (*cardbus_mem_open
)(cardbus_chipset_tag_t
, int, u_int32_t
,
107 int (*cardbus_mem_close
)(cardbus_chipset_tag_t
, int);
108 int (*cardbus_io_open
)(cardbus_chipset_tag_t
, int, u_int32_t
,
110 int (*cardbus_io_close
)(cardbus_chipset_tag_t
, int);
111 void *(*cardbus_intr_establish
)(cardbus_chipset_tag_t
, int, int,
112 int (*)(void *), void *);
113 void (*cardbus_intr_disestablish
)(cardbus_chipset_tag_t
, void *);
115 cardbustag_t (*cardbus_make_tag
)(cardbus_chipset_tag_t
, int, int);
116 cardbusreg_t (*cardbus_conf_read
)(cardbus_chipset_tag_t
,
118 void (*cardbus_conf_write
)(cardbus_chipset_tag_t
, cardbustag_t
,
120 } cardbus_function_t
, *cardbus_function_tag_t
;
124 * struct cbslot_attach_args is the attach argument for Cardbus cardslot.
126 struct cbslot_attach_args
{
127 bus_space_tag_t cba_iot
; /* cardbus i/o space tag */
128 bus_space_tag_t cba_memt
; /* cardbus mem space tag */
129 bus_dma_tag_t cba_dmat
; /* DMA tag */
131 int cba_bus
; /* cardbus bus number */
133 cardbus_chipset_tag_t cba_cc
; /* cardbus chipset */
134 cardbus_function_tag_t cba_cf
; /* cardbus functions */
135 cardbus_intr_line_t cba_intrline
; /* interrupt line */
138 rbus_tag_t cba_rbus_iot
; /* CardBus i/o rbus tag */
139 rbus_tag_t cba_rbus_memt
; /* CardBus mem rbus tag */
142 int cba_cacheline
; /* cache line size */
143 int cba_max_lattimer
; /* No card's latency timer may
144 * exceed this. On a PCI-Cardbus
145 * bridge, I let the latency timer on
146 * the primary bus (PCI bus) set
147 * the maximum. That is kind of an
148 * arbitrary choice. A more sensible
149 * choice may be either the
150 * latency timer on the primary bus,
151 * or the bridge's buffer size,
152 * whichever is larger.
157 struct cardbus_devfunc
;
160 * struct cardbus_softc is the softc for cardbus card.
162 struct cardbus_softc
{
163 device_t sc_dev
; /* fundamental device structure */
165 int sc_bus
; /* cardbus bus number */
166 cardbus_intr_line_t sc_intrline
; /* CardBus intrline */
168 bus_space_tag_t sc_iot
; /* CardBus I/O space tag */
169 bus_space_tag_t sc_memt
; /* CardBus MEM space tag */
170 bus_dma_tag_t sc_dmat
; /* DMA tag */
172 cardbus_chipset_tag_t sc_cc
; /* CardBus chipset */
173 cardbus_function_tag_t sc_cf
; /* CardBus function */
176 rbus_tag_t sc_rbus_iot
; /* CardBus i/o rbus tag */
177 rbus_tag_t sc_rbus_memt
; /* CardBus mem rbus tag */
180 int sc_cacheline
; /* cache line size */
181 int sc_max_lattimer
; /* No card's latency timer
182 * may exceed this. On a PCI-Cardbus
183 * bridge, the latency timer on
184 * the primary bus (PCI bus) sets
187 int sc_volt
; /* applied Vcc voltage */
188 #define PCCARD_33V 0x02
189 #define PCCARD_XXV 0x04
190 #define PCCARD_YYV 0x08
192 struct cardbus_devfunc
*sc_funcs
[8]; /* list of cardbus device functions */
195 struct cardbus_conf_state
{
196 cardbusreg_t reg
[16];
200 * struct cardbus_devfunc:
202 * This is the data deposit for each function of a CardBus device.
203 * This structure is used for memory or i/o space allocation and
206 typedef struct cardbus_devfunc
{
207 cardbus_chipset_tag_t ct_cc
;
208 cardbus_function_tag_t ct_cf
;
209 struct cardbus_softc
*ct_sc
; /* pointer to the parent */
210 int ct_bus
; /* bus number */
211 int ct_func
; /* function number */
214 rbus_tag_t ct_rbus_iot
; /* CardBus i/o rbus tag */
215 rbus_tag_t ct_rbus_memt
; /* CardBus mem rbus tag */
218 cardbusreg_t ct_bar
[6]; /* Base Address Regs 0 to 6 */
219 cardbusreg_t ct_bhlc
; /* Latency timer and cache line size */
220 /* u_int32_t ct_cisreg; */ /* CIS reg: is it needed??? */
222 device_t ct_device
; /* pointer to the device */
224 /* some data structure needed for tuple??? */
225 } *cardbus_devfunc_t
;
228 /* XXX various things extracted from CIS */
229 struct cardbus_cis_info
{
230 int32_t manufacturer
;
232 char cis1_info_buf
[256];
252 struct cardbus_attach_args
{
253 cardbus_devfunc_t ca_ct
;
255 bus_space_tag_t ca_iot
; /* CardBus I/O space tag */
256 bus_space_tag_t ca_memt
; /* CardBus MEM space tag */
257 bus_dma_tag_t ca_dmat
; /* DMA tag */
263 cardbusreg_t ca_class
;
265 /* interrupt information */
266 cardbus_intr_line_t ca_intrline
;
269 rbus_tag_t ca_rbus_iot
; /* CardBus i/o rbus tag */
270 rbus_tag_t ca_rbus_memt
; /* CardBus mem rbus tag */
273 struct cardbus_cis_info ca_cis
;
277 #define CARDBUS_ENABLE 1 /* enable the channel */
278 #define CARDBUS_DISABLE 2 /* disable the channel */
279 #define CARDBUS_RESET 4
281 # define CARDBUS_NOCARD 0
282 # define CARDBUS_5V_CARD 0x01 /* XXX: It must not exist */
283 # define CARDBUS_3V_CARD 0x02
284 # define CARDBUS_XV_CARD 0x04
285 # define CARDBUS_YV_CARD 0x08
286 #define CARDBUS_IO_ENABLE 100
287 #define CARDBUS_IO_DISABLE 101
288 #define CARDBUS_MEM_ENABLE 102
289 #define CARDBUS_MEM_DISABLE 103
290 #define CARDBUS_BM_ENABLE 104 /* bus master */
291 #define CARDBUS_BM_DISABLE 105
293 #define CARDBUS_VCC_UC 0x0000
294 #define CARDBUS_VCC_3V 0x0001
295 #define CARDBUS_VCC_XV 0x0002
296 #define CARDBUS_VCC_YV 0x0003
297 #define CARDBUS_VCC_0V 0x0004
298 #define CARDBUS_VCC_5V 0x0005 /* ??? */
299 #define CARDBUS_VCCMASK 0x000f
300 #define CARDBUS_VPP_UC 0x0000
301 #define CARDBUS_VPP_VCC 0x0010
302 #define CARDBUS_VPP_12V 0x0030
303 #define CARDBUS_VPP_0V 0x0040
304 #define CARDBUS_VPPMASK 0x00f0
307 int cardbus_attach_card(struct cardbus_softc
*);
308 void cardbus_detach_card(struct cardbus_softc
*);
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 *);
314 int cardbus_mapreg_map(struct cardbus_softc
*, int, int, cardbusreg_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
);
319 int cardbus_save_bar(cardbus_devfunc_t
);
320 int cardbus_restore_bar(cardbus_devfunc_t
);
322 int cardbus_function_enable(struct cardbus_softc
*, int);
323 int cardbus_function_disable(struct cardbus_softc
*, int);
325 void cardbus_disable_retry(cardbus_chipset_tag_t
, cardbus_function_tag_t
,
328 int cardbus_get_capability(cardbus_chipset_tag_t
, cardbus_function_tag_t
,
329 cardbustag_t
, int, int *, cardbusreg_t
*);
330 int cardbus_get_powerstate(cardbus_devfunc_t
, cardbustag_t
, cardbusreg_t
*);
331 int cardbus_set_powerstate(cardbus_devfunc_t
, cardbustag_t
, cardbusreg_t
);
333 void cardbus_conf_capture(cardbus_chipset_tag_t
, cardbus_function_tag_t
,
334 cardbustag_t
, struct cardbus_conf_state
*);
335 void cardbus_conf_restore(cardbus_chipset_tag_t
, cardbus_function_tag_t
,
336 cardbustag_t
, struct cardbus_conf_state
*);
338 #define Cardbus_function_enable(ct) cardbus_function_enable((ct)->ct_sc, (ct)->ct_func)
339 #define Cardbus_function_disable(ct) cardbus_function_disable((ct)->ct_sc, (ct)->ct_func)
343 #define Cardbus_mapreg_map(ct, reg, type, busflags, tagp, handlep, basep, sizep) \
344 cardbus_mapreg_map((ct)->ct_sc, (ct->ct_func), (reg), (type),\
345 (busflags), (tagp), (handlep), (basep), (sizep))
346 #define Cardbus_mapreg_unmap(ct, reg, tag, handle, size) \
347 cardbus_mapreg_unmap((ct)->ct_sc, (ct->ct_func), (reg), (tag), (handle), (size))
349 #define Cardbus_make_tag(ct) (*(ct)->ct_cf->cardbus_make_tag)((ct)->ct_cc, (ct)->ct_bus, (ct)->ct_func)
350 #define cardbus_make_tag(cc, cf, bus, function) ((cf)->cardbus_make_tag)((cc), (bus), (function))
352 #define Cardbus_free_tag(ct, tag) (*(ct)->ct_cf->cardbus_free_tag)((ct)->ct_cc, (tag))
353 #define cardbus_free_tag(cc, cf, tag) (*(cf)->cardbus_free_tag)(cc, (tag))
355 #define Cardbus_conf_read(ct, tag, offs) (*(ct)->ct_cf->cardbus_conf_read)((ct)->ct_cc, (tag), (offs))
356 #define cardbus_conf_read(cc, cf, tag, offs) ((cf)->cardbus_conf_read)((cc), (tag), (offs))
357 #define Cardbus_conf_write(ct, tag, offs, val) (*(ct)->ct_cf->cardbus_conf_write)((ct)->ct_cc, (tag), (offs), (val))
358 #define cardbus_conf_write(cc, cf, tag, offs, val) ((cf)->cardbus_conf_write)((cc), (tag), (offs), (val))
360 #endif /* !_DEV_CARDBUS_CARDBUSVAR_H_ */