xref: /openbsd/sys/dev/cardbus/cardbusvar.h (revision 898184e3)
1 /*	$OpenBSD: cardbusvar.h,v 1.19 2010/03/27 23:36:36 jsg Exp $	*/
2 /*	$NetBSD: cardbusvar.h,v 1.17 2000/04/02 19:11:37 mycroft Exp $	*/
3 
4 /*
5  * Copyright (c) 1998, 1999 and 2000
6  *       HAYAKAWA Koichi.  All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
22  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef _DEV_CARDBUS_CARDBUSVAR_H_
32 #define _DEV_CARDBUS_CARDBUSVAR_H_
33 
34 #include <dev/pci/pcivar.h>	/* for pcitag_t */
35 #include <dev/cardbus/rbus.h>
36 
37 typedef void *cardbus_chipset_tag_t;
38 typedef int cardbus_intr_handle_t;
39 
40 /* Base Registers */
41 #define CARDBUS_BASE0_REG  0x10
42 #define CARDBUS_BASE1_REG  0x14
43 #define CARDBUS_BASE2_REG  0x18
44 #define CARDBUS_BASE3_REG  0x1C
45 #define CARDBUS_BASE4_REG  0x20
46 #define CARDBUS_BASE5_REG  0x24
47 #define CARDBUS_CIS_REG    0x28
48 #define CARDBUS_ROM_REG	   0x30
49 #  define CARDBUS_CIS_ASIMASK 0x07
50 #    define CARDBUS_CIS_ASI(x) (CARDBUS_CIS_ASIMASK & (x))
51 #  define CARDBUS_CIS_ASI_TUPLE 0x00
52 #  define CARDBUS_CIS_ASI_BAR0  0x01
53 #  define CARDBUS_CIS_ASI_BAR1  0x02
54 #  define CARDBUS_CIS_ASI_BAR2  0x03
55 #  define CARDBUS_CIS_ASI_BAR3  0x04
56 #  define CARDBUS_CIS_ASI_BAR4  0x05
57 #  define CARDBUS_CIS_ASI_BAR5  0x06
58 #  define CARDBUS_CIS_ASI_ROM   0x07
59 #  define CARDBUS_CIS_ADDRMASK 0x0ffffff8
60 #    define CARDBUS_CIS_ADDR(x) (CARDBUS_CIS_ADDRMASK & (x))
61 #    define CARDBUS_CIS_ASI_BAR(x) (((CARDBUS_CIS_ASIMASK & (x))-1)*4+0x10)
62 #    define CARDBUS_CIS_ASI_ROM_IMAGE(x) (((x) >> 28) & 0xf)
63 
64 /* XXX end */
65 
66 typedef struct cardbus_functions {
67 	int (*cardbus_space_alloc)(cardbus_chipset_tag_t, rbus_tag_t,
68 	    bus_addr_t, bus_size_t, bus_addr_t, bus_size_t, int, bus_addr_t *,
69 	    bus_space_handle_t *);
70 	int (*cardbus_space_free)(cardbus_chipset_tag_t, rbus_tag_t,
71 	    bus_space_handle_t, bus_size_t);
72 	void *(*cardbus_intr_establish)(cardbus_chipset_tag_t, int, int,
73 	    int (*)(void *), void *, const char *);
74 	void (*cardbus_intr_disestablish)(cardbus_chipset_tag_t, void *);
75 	int (*cardbus_ctrl)(cardbus_chipset_tag_t, int);
76 	int (*cardbus_power)(cardbus_chipset_tag_t, int);
77 } cardbus_function_t, *cardbus_function_tag_t;
78 
79 /*
80  * struct cbslot_attach_args is the attach argument for cardbus card.
81  */
82 struct cbslot_attach_args {
83 	char *cba_busname;
84 	bus_space_tag_t cba_iot;	/* cardbus i/o space tag */
85 	bus_space_tag_t cba_memt;	/* cardbus mem space tag */
86 	bus_dma_tag_t cba_dmat;		/* DMA tag */
87 
88 	int cba_bus;			/* cardbus bus number */
89 
90 	cardbus_chipset_tag_t cba_cc;	/* cardbus chipset */
91 	pci_chipset_tag_t cba_pc;	/* pci chipset */
92 	cardbus_function_tag_t cba_cf;	/* cardbus functions */
93 	int cba_intrline;		/* interrupt line */
94 
95 	rbus_tag_t cba_rbus_iot;	/* CardBus i/o rbus tag */
96 	rbus_tag_t cba_rbus_memt;	/* CardBus mem rbus tag */
97 
98 	int cba_cacheline;		/* cache line size */
99 	int cba_lattimer;		/* latency timer */
100 };
101 
102 
103 #define cbslotcf_dev  cf_loc[0]
104 #define cbslotcf_func cf_loc[1]
105 #define CBSLOT_UNK_DEV -1
106 #define CBSLOT_UNK_FUNC -1
107 
108 
109 struct cardbus_devfunc;
110 
111 /*
112  * struct cardbus_softc is the softc for cardbus card.
113  */
114 struct cardbus_softc {
115 	struct device sc_dev;		/* fundamental device structure */
116 
117 	int sc_bus;			/* cardbus bus number */
118 	int sc_device;			/* cardbus device number */
119 	int sc_intrline;		/* CardBus intrline */
120 
121 	bus_space_tag_t sc_iot;		/* CardBus I/O space tag */
122 	bus_space_tag_t sc_memt;	/* CardBus MEM space tag */
123 	bus_dma_tag_t sc_dmat;		/* DMA tag */
124 
125 	cardbus_chipset_tag_t sc_cc;	/* CardBus chipset */
126 	pci_chipset_tag_t sc_pc;	/* PCI chipset */
127 	cardbus_function_tag_t sc_cf;	/* CardBus function */
128 
129 	rbus_tag_t sc_rbus_iot;		/* CardBus i/o rbus tag */
130 	rbus_tag_t sc_rbus_memt;	/* CardBus mem rbus tag */
131 
132 	int sc_cacheline;		/* cache line size */
133 	int sc_lattimer;		/* latency timer */
134 	int sc_volt;			/* applied Vcc voltage */
135 #define PCCARD_33V  0x02
136 #define PCCARD_XXV  0x04
137 #define PCCARD_YYV  0x08
138 	int sc_poweron_func;
139 	struct cardbus_devfunc *sc_funcs;
140 					/* list of cardbus device functions */
141 };
142 
143 
144 /*
145  * struct cardbus_devfunc:
146  *
147  *   This is the data deposit for each function of a CardBus device.
148  *   This structure is used for memory or i/o space allocation and
149  *   disallocation.
150  */
151 typedef struct cardbus_devfunc {
152 	cardbus_chipset_tag_t ct_cc;
153 	cardbus_function_tag_t ct_cf;
154 	struct cardbus_softc *ct_sc;	/* pointer to the parent */
155 	int ct_bus;			/* bus number */
156 	int ct_dev;			/* device number */
157 	int ct_func;			/* function number */
158 
159 	rbus_tag_t ct_rbus_iot;		/* CardBus i/o rbus tag */
160 	rbus_tag_t ct_rbus_memt;	/* CardBus mem rbus tag */
161 
162 	u_int32_t ct_lc;		/* Latency timer and cache line size */
163 	/* u_int32_t ct_cisreg; */	/* CIS reg: is it needed??? */
164 
165 	struct device *ct_device;	/* pointer to the device */
166 
167 	struct cardbus_devfunc *ct_next;
168 
169   /* some data structure needed for tuple??? */
170 } *cardbus_devfunc_t;
171 
172 
173 /* XXX various things extracted from CIS */
174 struct cardbus_cis_info {
175 	int32_t		manufacturer;
176 	int32_t		product;
177 	char		cis1_info_buf[256];
178 	char	       *cis1_info[4];
179 	struct cb_bar_info {
180 		unsigned int flags;
181 		unsigned int size;
182 	} bar[7];
183 	unsigned int	funcid;
184 	union {
185 		struct {
186 			int uart_type;
187 			int uart_present;
188 		} serial;
189 		struct {
190 			char netid[6];
191 			char netid_present;
192 			char __filler;
193 		} network;
194 	} funce;
195 };
196 
197 struct cardbus_attach_args {
198 	int ca_unit;
199 	cardbus_devfunc_t ca_ct;
200 	pci_chipset_tag_t ca_pc;	/* PCI chipset */
201 
202 	bus_space_tag_t ca_iot;		/* CardBus I/O space tag */
203 	bus_space_tag_t ca_memt;	/* CardBus MEM space tag */
204 	bus_dma_tag_t ca_dmat;		/* DMA tag */
205 
206 	u_int ca_bus;
207 	u_int ca_device;
208 	u_int ca_function;
209 	pcitag_t ca_tag;
210 	pcireg_t ca_id;
211 	pcireg_t ca_class;
212 
213 	/* Interrupt information */
214 	pci_intr_line_t ca_intrline;
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 #define CARDBUSCF_DEV			0
253 #define CARDBUSCF_DEV_DEFAULT		-1
254 #define CARDBUSCF_FUNCTION		1
255 #define CARDBUSCF_FUNCTION_DEFAULT	-1
256 
257 /*
258  * Locators devies that attach to 'cardbus', as specified to config.
259  */
260 #define cardbuscf_dev cf_loc[CARDBUSCF_DEV]
261 #define CARDBUS_UNK_DEV CARDBUSCF_DEV_DEFAULT
262 
263 #define cardbuscf_function cf_loc[CARDBUSCF_FUNCTION]
264 #define CARDBUS_UNK_FUNCTION CARDBUSCF_FUNCTION_DEFAULT
265 
266 int	cardbus_attach_card(struct cardbus_softc *);
267 void	cardbus_detach_card(struct cardbus_softc *);
268 void   *cardbus_intr_establish(cardbus_chipset_tag_t, cardbus_function_tag_t,
269 	    cardbus_intr_handle_t irq, int level, int (*func) (void *),
270 	    void *arg, const char *);
271 void	cardbus_intr_disestablish(cardbus_chipset_tag_t,
272 	    cardbus_function_tag_t, void *handler);
273 
274 int	cardbus_mapreg_map(struct cardbus_softc *, int, int, pcireg_t,
275 	    int, bus_space_tag_t *, bus_space_handle_t *, bus_addr_t *,
276 	    bus_size_t *);
277 int	cardbus_mapreg_unmap(struct cardbus_softc *, int, int,
278 	    bus_space_tag_t, bus_space_handle_t, bus_size_t);
279 
280 int	cardbus_function_enable(struct cardbus_softc *, int function);
281 int	cardbus_function_disable(struct cardbus_softc *, int function);
282 
283 int	cardbus_matchbyid(struct cardbus_attach_args *,
284 	    const struct pci_matchid *, int);
285 
286 #define Cardbus_function_enable(ct)			\
287     cardbus_function_enable((ct)->ct_sc, (ct)->ct_func)
288 #define Cardbus_function_disable(ct)			\
289     cardbus_function_disable((ct)->ct_sc, (ct)->ct_func)
290 
291 #define Cardbus_mapreg_map(ct, reg, type, busflags, tagp, handlep, basep, sizep) \
292     cardbus_mapreg_map((ct)->ct_sc, (ct->ct_func), 	\
293     (reg), (type), (busflags), (tagp), (handlep), (basep), (sizep))
294 #define Cardbus_mapreg_unmap(ct, reg, tag, handle, size)\
295     cardbus_mapreg_unmap((ct)->ct_sc, (ct->ct_func), 	\
296     (reg), (tag), (handle), (size))
297 
298 #endif /* !_DEV_CARDBUS_CARDBUSVAR_H_ */
299