This source file includes following definitions.
- cardbus_function_t
- cardbus_function_tag_t
- cardbus_devfunc_t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 #ifndef _DEV_CARDBUS_CARDBUSVAR_H_
37 #define _DEV_CARDBUS_CARDBUSVAR_H_
38
39 #include <dev/pci/pcivar.h>
40 #include <dev/cardbus/rbus.h>
41
42 typedef void *cardbus_chipset_tag_t;
43 typedef int cardbus_intr_handle_t;
44
45
46 typedef u_int32_t cardbusreg_t;
47 typedef pcitag_t cardbustag_t;
48 typedef int cardbus_intr_line_t;
49
50 #define CARDBUS_ID_REG 0x00
51
52 typedef u_int16_t cardbus_vendor_id_t;
53 typedef u_int16_t cardbus_product_id_t;
54
55 # define CARDBUS_VENDOR_SHIFT 0
56 # define CARDBUS_VENDOR_MASK 0xffff
57 # define CARDBUS_VENDOR(id) \
58 (((id) >> CARDBUS_VENDOR_SHIFT) & CARDBUS_VENDOR_MASK)
59
60 # define CARDBUS_PRODUCT_SHIFT 16
61 # define CARDBUS_PRODUCT_MASK 0xffff
62 # define CARDBUS_PRODUCT(id) \
63 (((id) >> CARDBUS_PRODUCT_SHIFT) & CARDBUS_PRODUCT_MASK)
64
65
66 #define CARDBUS_COMMAND_STATUS_REG 0x04
67
68 # define CARDBUS_COMMAND_IO_ENABLE 0x00000001
69 # define CARDBUS_COMMAND_MEM_ENABLE 0x00000002
70 # define CARDBUS_COMMAND_MASTER_ENABLE 0x00000004
71
72
73 #define CARDBUS_CLASS_REG 0x08
74
75 #define CARDBUS_CLASS_SHIFT 24
76 #define CARDBUS_CLASS_MASK 0xff
77 #define CARDBUS_CLASS(cr) \
78 (((cr) >> CARDBUS_CLASS_SHIFT) & CARDBUS_CLASS_MASK)
79
80 #define CARDBUS_SUBCLASS_SHIFT 16
81 #define CARDBUS_SUBCLASS_MASK 0xff
82 #define CARDBUS_SUBCLASS(cr) \
83 (((cr) >> CARDBUS_SUBCLASS_SHIFT) & CARDBUS_SUBCLASS_MASK)
84
85 #define CARDBUS_INTERFACE_SHIFT 8
86 #define CARDBUS_INTERFACE_MASK 0xff
87 #define CARDBUS_INTERFACE(cr) \
88 (((cr) >> CARDBUS_INTERFACE_SHIFT) & CARDBUS_INTERFACE_MASK)
89
90 #define CARDBUS_REVISION_SHIFT 0
91 #define CARDBUS_REVISION_MASK 0xff
92 #define CARDBUS_REVISION(cr) \
93 (((cr) >> CARDBUS_REVISION_SHIFT) & CARDBUS_REVISION_MASK)
94
95
96 #define CARDBUS_CLASS_PREHISTORIC 0x00
97 #define CARDBUS_CLASS_MASS_STORAGE 0x01
98 #define CARDBUS_CLASS_NETWORK 0x02
99 #define CARDBUS_CLASS_DISPLAY 0x03
100 #define CARDBUS_CLASS_MULTIMEDIA 0x04
101 #define CARDBUS_CLASS_MEMORY 0x05
102 #define CARDBUS_CLASS_BRIDGE 0x06
103 #define CARDBUS_CLASS_COMMUNICATIONS 0x07
104 #define CARDBUS_CLASS_SYSTEM 0x08
105 #define CARDBUS_CLASS_INPUT 0x09
106 #define CARDBUS_CLASS_DOCK 0x0a
107 #define CARDBUS_CLASS_PROCESSOR 0x0b
108 #define CARDBUS_CLASS_SERIALBUS 0x0c
109 #define CARDBUS_CLASS_UNDEFINED 0xff
110
111
112 #define CARDBUS_SUBCLASS_SERIALBUS_FIREWIRE 0x00
113 #define CARDBUS_SUBCLASS_SERIALBUS_ACCESS 0x01
114 #define CARDBUS_SUBCLASS_SERIALBUS_SSA 0x02
115 #define CARDBUS_SUBCLASS_SERIALBUS_USB 0x03
116 #define CARDBUS_SUBCLASS_SERIALBUS_FIBER 0x04
117
118
119 #define CARDBUS_BHLC_REG 0x0c
120
121 #define CARDBUS_BIST_SHIFT 24
122 #define CARDBUS_BIST_MASK 0xff
123 #define CARDBUS_BIST(bhlcr) \
124 (((bhlcr) >> CARDBUS_BIST_SHIFT) & CARDBUS_BIST_MASK)
125
126 #define CARDBUS_HDRTYPE_SHIFT 16
127 #define CARDBUS_HDRTYPE_MASK 0xff
128 #define CARDBUS_HDRTYPE(bhlcr) \
129 (((bhlcr) >> CARDBUS_HDRTYPE_SHIFT) & CARDBUS_HDRTYPE_MASK)
130
131 #define CARDBUS_HDRTYPE_TYPE(bhlcr) \
132 (CARDBUS_HDRTYPE(bhlcr) & 0x7f)
133 #define CARDBUS_HDRTYPE_MULTIFN(bhlcr) \
134 ((CARDBUS_HDRTYPE(bhlcr) & 0x80) != 0)
135
136 #define CARDBUS_LATTIMER_SHIFT 8
137 #define CARDBUS_LATTIMER_MASK 0xff
138 #define CARDBUS_LATTIMER(bhlcr) \
139 (((bhlcr) >> CARDBUS_LATTIMER_SHIFT) & CARDBUS_LATTIMER_MASK)
140
141 #define CARDBUS_CACHELINE_SHIFT 0
142 #define CARDBUS_CACHELINE_MASK 0xff
143 #define CARDBUS_CACHELINE(bhlcr) \
144 (((bhlcr) >> CARDBUS_CACHELINE_SHIFT) & CARDBUS_CACHELINE_MASK)
145
146
147
148 #define CARDBUS_BASE0_REG 0x10
149 #define CARDBUS_BASE1_REG 0x14
150 #define CARDBUS_BASE2_REG 0x18
151 #define CARDBUS_BASE3_REG 0x1C
152 #define CARDBUS_BASE4_REG 0x20
153 #define CARDBUS_BASE5_REG 0x24
154 #define CARDBUS_CIS_REG 0x28
155 #define CARDBUS_ROM_REG 0x30
156 # define CARDBUS_CIS_ASIMASK 0x07
157 # define CARDBUS_CIS_ASI(x) (CARDBUS_CIS_ASIMASK & (x))
158 # define CARDBUS_CIS_ASI_TUPLE 0x00
159 # define CARDBUS_CIS_ASI_BAR0 0x01
160 # define CARDBUS_CIS_ASI_BAR1 0x02
161 # define CARDBUS_CIS_ASI_BAR2 0x03
162 # define CARDBUS_CIS_ASI_BAR3 0x04
163 # define CARDBUS_CIS_ASI_BAR4 0x05
164 # define CARDBUS_CIS_ASI_BAR5 0x06
165 # define CARDBUS_CIS_ASI_ROM 0x07
166 # define CARDBUS_CIS_ADDRMASK 0x0ffffff8
167 # define CARDBUS_CIS_ADDR(x) (CARDBUS_CIS_ADDRMASK & (x))
168 # define CARDBUS_CIS_ASI_BAR(x) (((CARDBUS_CIS_ASIMASK & (x))-1)*4+0x10)
169 # define CARDBUS_CIS_ASI_ROM_IMAGE(x) (((x) >> 28) & 0xf)
170
171 #define CARDBUS_INTERRUPT_REG 0x3c
172
173 #define CARDBUS_MAPREG_TYPE_MEM 0x00000000
174 #define CARDBUS_MAPREG_TYPE_IO 0x00000001
175
176
177
178 typedef struct cardbus_functions {
179 int (*cardbus_space_alloc)(cardbus_chipset_tag_t, rbus_tag_t,
180 bus_addr_t, bus_size_t, bus_addr_t, bus_size_t, int, bus_addr_t *,
181 bus_space_handle_t *);
182 int (*cardbus_space_free)(cardbus_chipset_tag_t, rbus_tag_t,
183 bus_space_handle_t, bus_size_t);
184 void *(*cardbus_intr_establish)(cardbus_chipset_tag_t, int, int,
185 int (*)(void *), void *, const char *);
186 void (*cardbus_intr_disestablish)(cardbus_chipset_tag_t, void *);
187 int (*cardbus_ctrl)(cardbus_chipset_tag_t, int);
188 int (*cardbus_power)(cardbus_chipset_tag_t, int);
189
190 cardbustag_t (*cardbus_make_tag)(cardbus_chipset_tag_t, int, int, int);
191 void (*cardbus_free_tag)(cardbus_chipset_tag_t, cardbustag_t);
192 cardbusreg_t (*cardbus_conf_read)(cardbus_chipset_tag_t,
193 cardbustag_t, int);
194 void (*cardbus_conf_write)(cardbus_chipset_tag_t, cardbustag_t, int,
195 cardbusreg_t);
196 } cardbus_function_t, *cardbus_function_tag_t;
197
198
199
200
201 struct cbslot_attach_args {
202 char *cba_busname;
203 bus_space_tag_t cba_iot;
204 bus_space_tag_t cba_memt;
205 bus_dma_tag_t cba_dmat;
206
207 int cba_bus;
208
209 cardbus_chipset_tag_t cba_cc;
210 cardbus_function_tag_t cba_cf;
211 int cba_intrline;
212
213 rbus_tag_t cba_rbus_iot;
214 rbus_tag_t cba_rbus_memt;
215
216 int cba_cacheline;
217 int cba_lattimer;
218 };
219
220
221 #define cbslotcf_dev cf_loc[0]
222 #define cbslotcf_func cf_loc[1]
223 #define CBSLOT_UNK_DEV -1
224 #define CBSLOT_UNK_FUNC -1
225
226
227 struct cardbus_devfunc;
228
229
230
231
232 struct cardbus_softc {
233 struct device sc_dev;
234
235 int sc_bus;
236 int sc_device;
237 int sc_intrline;
238
239 bus_space_tag_t sc_iot;
240 bus_space_tag_t sc_memt;
241 bus_dma_tag_t sc_dmat;
242
243 cardbus_chipset_tag_t sc_cc;
244 cardbus_function_tag_t sc_cf;
245
246 rbus_tag_t sc_rbus_iot;
247 rbus_tag_t sc_rbus_memt;
248
249 int sc_cacheline;
250 int sc_lattimer;
251 int sc_volt;
252 #define PCCARD_33V 0x02
253 #define PCCARD_XXV 0x04
254 #define PCCARD_YYV 0x08
255 int sc_poweron_func;
256 struct cardbus_devfunc *sc_funcs;
257
258 };
259
260
261
262
263
264
265
266
267
268 typedef struct cardbus_devfunc {
269 cardbus_chipset_tag_t ct_cc;
270 cardbus_function_tag_t ct_cf;
271 struct cardbus_softc *ct_sc;
272 int ct_bus;
273 int ct_dev;
274 int ct_func;
275
276 rbus_tag_t ct_rbus_iot;
277 rbus_tag_t ct_rbus_memt;
278
279 u_int32_t ct_bar[6];
280 u_int32_t ct_lc;
281
282
283 struct device *ct_device;
284
285 struct cardbus_devfunc *ct_next;
286
287
288 } *cardbus_devfunc_t;
289
290
291
292 struct cardbus_cis_info {
293 int32_t manufacturer;
294 int32_t product;
295 char cis1_info_buf[256];
296 char *cis1_info[4];
297 struct cb_bar_info {
298 unsigned int flags;
299 unsigned int size;
300 } bar[7];
301 unsigned int funcid;
302 union {
303 struct {
304 int uart_type;
305 int uart_present;
306 } serial;
307 struct {
308 char netid[6];
309 char netid_present;
310 char __filler;
311 } network;
312 } funce;
313 };
314
315 struct cardbus_attach_args {
316 int ca_unit;
317 cardbus_devfunc_t ca_ct;
318
319 bus_space_tag_t ca_iot;
320 bus_space_tag_t ca_memt;
321 bus_dma_tag_t ca_dmat;
322
323 u_int ca_bus;
324 u_int ca_device;
325 u_int ca_function;
326 cardbustag_t ca_tag;
327 cardbusreg_t ca_id;
328 cardbusreg_t ca_class;
329
330
331 cardbus_intr_line_t ca_intrline;
332
333 rbus_tag_t ca_rbus_iot;
334 rbus_tag_t ca_rbus_memt;
335
336 struct cardbus_cis_info ca_cis;
337 };
338
339
340 #define CARDBUS_ENABLE 1
341 #define CARDBUS_DISABLE 2
342 #define CARDBUS_RESET 4
343 #define CARDBUS_CD 7
344 # define CARDBUS_NOCARD 0
345 # define CARDBUS_5V_CARD 0x01
346 # define CARDBUS_3V_CARD 0x02
347 # define CARDBUS_XV_CARD 0x04
348 # define CARDBUS_YV_CARD 0x08
349 #define CARDBUS_IO_ENABLE 100
350 #define CARDBUS_IO_DISABLE 101
351 #define CARDBUS_MEM_ENABLE 102
352 #define CARDBUS_MEM_DISABLE 103
353 #define CARDBUS_BM_ENABLE 104
354 #define CARDBUS_BM_DISABLE 105
355
356 #define CARDBUS_VCC_UC 0x0000
357 #define CARDBUS_VCC_3V 0x0001
358 #define CARDBUS_VCC_XV 0x0002
359 #define CARDBUS_VCC_YV 0x0003
360 #define CARDBUS_VCC_0V 0x0004
361 #define CARDBUS_VCC_5V 0x0005
362 #define CARDBUS_VCCMASK 0x000f
363 #define CARDBUS_VPP_UC 0x0000
364 #define CARDBUS_VPP_VCC 0x0010
365 #define CARDBUS_VPP_12V 0x0030
366 #define CARDBUS_VPP_0V 0x0040
367 #define CARDBUS_VPPMASK 0x00f0
368
369 #define CARDBUSCF_DEV 0
370 #define CARDBUSCF_DEV_DEFAULT -1
371 #define CARDBUSCF_FUNCTION 1
372 #define CARDBUSCF_FUNCTION_DEFAULT -1
373
374
375
376
377 #define cardbuscf_dev cf_loc[CARDBUSCF_DEV]
378 #define CARDBUS_UNK_DEV CARDBUSCF_DEV_DEFAULT
379
380 #define cardbuscf_function cf_loc[CARDBUSCF_FUNCTION]
381 #define CARDBUS_UNK_FUNCTION CARDBUSCF_FUNCTION_DEFAULT
382
383 int cardbus_attach_card(struct cardbus_softc *);
384 void cardbus_detach_card(struct cardbus_softc *);
385 void *cardbus_intr_establish(cardbus_chipset_tag_t, cardbus_function_tag_t,
386 cardbus_intr_handle_t irq, int level, int (*func) (void *),
387 void *arg, const char *);
388 void cardbus_intr_disestablish(cardbus_chipset_tag_t,
389 cardbus_function_tag_t, void *handler);
390
391 int cardbus_mapreg_probe(cardbus_chipset_tag_t, cardbus_function_tag_t,
392 cardbustag_t, int, pcireg_t *);
393 int cardbus_mapreg_map(struct cardbus_softc *, int, int, cardbusreg_t,
394 int, bus_space_tag_t *, bus_space_handle_t *, bus_addr_t *,
395 bus_size_t *);
396 int cardbus_mapreg_unmap(struct cardbus_softc *, int, int,
397 bus_space_tag_t, bus_space_handle_t, bus_size_t);
398
399 int cardbus_save_bar(cardbus_devfunc_t);
400 int cardbus_restore_bar(cardbus_devfunc_t);
401
402 int cardbus_function_enable(struct cardbus_softc *, int function);
403 int cardbus_function_disable(struct cardbus_softc *, int function);
404
405 int cardbus_get_capability(cardbus_chipset_tag_t, cardbus_function_tag_t,
406 cardbustag_t, int, int *, cardbusreg_t *);
407
408 struct cardbus_matchid {
409 cardbus_vendor_id_t cm_vid;
410 cardbus_product_id_t cm_pid;
411 };
412
413 int cardbus_matchbyid(struct cardbus_attach_args *,
414 const struct cardbus_matchid *, int);
415
416 #define Cardbus_function_enable(ct) \
417 cardbus_function_enable((ct)->ct_sc, (ct)->ct_func)
418 #define Cardbus_function_disable(ct) \
419 cardbus_function_disable((ct)->ct_sc, (ct)->ct_func)
420
421 #define Cardbus_mapreg_map(ct, reg, type, busflags, tagp, handlep, basep, sizep) \
422 cardbus_mapreg_map((ct)->ct_sc, (ct->ct_func), \
423 (reg), (type), (busflags), (tagp), (handlep), (basep), (sizep))
424 #define Cardbus_mapreg_unmap(ct, reg, tag, handle, size)\
425 cardbus_mapreg_unmap((ct)->ct_sc, (ct->ct_func), \
426 (reg), (tag), (handle), (size))
427
428 #define Cardbus_make_tag(ct) \
429 (*(ct)->ct_cf->cardbus_make_tag)((ct)->ct_cc, \
430 (ct)->ct_bus, (ct)->ct_dev, (ct)->ct_func)
431 #define cardbus_make_tag(cc, cf, bus, device, function) \
432 ((cf)->cardbus_make_tag)((cc), (bus), (device), (function))
433
434 #define Cardbus_free_tag(ct, tag) \
435 (*(ct)->ct_cf->cardbus_free_tag)((ct)->ct_cc, (tag))
436 #define cardbus_free_tag(cc, cf, tag) \
437 (*(cf)->cardbus_free_tag)(cc, (tag))
438
439 #define Cardbus_conf_read(ct, tag, offs) \
440 (*(ct)->ct_cf->cardbus_conf_read)((ct)->ct_cf, (tag), (offs))
441 #define cardbus_conf_read(cc, cf, tag, offs) \
442 ((cf)->cardbus_conf_read)((cc), (tag), (offs))
443 #define Cardbus_conf_write(ct, tag, offs, val) \
444 (*(ct)->ct_cf->cardbus_conf_write)((ct)->ct_cf, (tag), (offs), (val))
445 #define cardbus_conf_write(cc, cf, tag, offs, val) \
446 ((cf)->cardbus_conf_write)((cc), (tag), (offs), (val))
447
448 #endif