Annotation of sys/dev/cardbus/cardbusvar.h, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: cardbusvar.h,v 1.12 2006/10/12 16:35:51 grange 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: * 3. All advertising materials mentioning features or use of this software
17: * must display the following acknowledgement:
18: * This product includes software developed by the author.
19: * 4. The name of the author may not be used to endorse or promote products
20: * derived from this software without specific prior written permission.
21: *
22: *
23: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26: * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
27: * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29: * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31: * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32: * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33: * POSSIBILITY OF SUCH DAMAGE.
34: */
35:
36: #ifndef _DEV_CARDBUS_CARDBUSVAR_H_
37: #define _DEV_CARDBUS_CARDBUSVAR_H_
38:
39: #include <dev/pci/pcivar.h> /* for pcitag_t */
40: #include <dev/cardbus/rbus.h>
41:
42: typedef void *cardbus_chipset_tag_t;
43: typedef int cardbus_intr_handle_t;
44:
45: /* XXX they must be in cardbusreg.h */
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: /* base classes */
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: /* 0x0c serial bus subclasses */
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: /* BIST, Header Type, Latency Timer, Cache Line Size */
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: /* Base Registers */
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: /* XXX end */
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: * struct cbslot_attach_args is the attach argument for cardbus card.
200: */
201: struct cbslot_attach_args {
202: char *cba_busname;
203: bus_space_tag_t cba_iot; /* cardbus i/o space tag */
204: bus_space_tag_t cba_memt; /* cardbus mem space tag */
205: bus_dma_tag_t cba_dmat; /* DMA tag */
206:
207: int cba_bus; /* cardbus bus number */
208:
209: cardbus_chipset_tag_t cba_cc; /* cardbus chipset */
210: cardbus_function_tag_t cba_cf; /* cardbus functions */
211: int cba_intrline; /* interrupt line */
212:
213: rbus_tag_t cba_rbus_iot; /* CardBus i/o rbus tag */
214: rbus_tag_t cba_rbus_memt; /* CardBus mem rbus tag */
215:
216: int cba_cacheline; /* cache line size */
217: int cba_lattimer; /* latency timer */
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: * struct cardbus_softc is the softc for cardbus card.
231: */
232: struct cardbus_softc {
233: struct device sc_dev; /* fundamental device structure */
234:
235: int sc_bus; /* cardbus bus number */
236: int sc_device; /* cardbus device number */
237: int sc_intrline; /* CardBus intrline */
238:
239: bus_space_tag_t sc_iot; /* CardBus I/O space tag */
240: bus_space_tag_t sc_memt; /* CardBus MEM space tag */
241: bus_dma_tag_t sc_dmat; /* DMA tag */
242:
243: cardbus_chipset_tag_t sc_cc; /* CardBus chipset */
244: cardbus_function_tag_t sc_cf; /* CardBus function */
245:
246: rbus_tag_t sc_rbus_iot; /* CardBus i/o rbus tag */
247: rbus_tag_t sc_rbus_memt; /* CardBus mem rbus tag */
248:
249: int sc_cacheline; /* cache line size */
250: int sc_lattimer; /* latency timer */
251: int sc_volt; /* applied Vcc voltage */
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: /* list of cardbus device functions */
258: };
259:
260:
261: /*
262: * struct cardbus_devfunc:
263: *
264: * This is the data deposit for each function of a CardBus device.
265: * This structure is used for memory or i/o space allocation and
266: * disallocation.
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; /* pointer to the parent */
272: int ct_bus; /* bus number */
273: int ct_dev; /* device number */
274: int ct_func; /* function number */
275:
276: rbus_tag_t ct_rbus_iot; /* CardBus i/o rbus tag */
277: rbus_tag_t ct_rbus_memt; /* CardBus mem rbus tag */
278:
279: u_int32_t ct_bar[6]; /* Base Address Regs 0 to 6 */
280: u_int32_t ct_lc; /* Latency timer and cache line size */
281: /* u_int32_t ct_cisreg; */ /* CIS reg: is it needed??? */
282:
283: struct device *ct_device; /* pointer to the device */
284:
285: struct cardbus_devfunc *ct_next;
286:
287: /* some data structure needed for tuple??? */
288: } *cardbus_devfunc_t;
289:
290:
291: /* XXX various things extracted from CIS */
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; /* CardBus I/O space tag */
320: bus_space_tag_t ca_memt; /* CardBus MEM space tag */
321: bus_dma_tag_t ca_dmat; /* DMA tag */
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: /* Interrupt information */
331: cardbus_intr_line_t ca_intrline;
332:
333: rbus_tag_t ca_rbus_iot; /* CardBus i/o rbus tag */
334: rbus_tag_t ca_rbus_memt; /* CardBus mem rbus tag */
335:
336: struct cardbus_cis_info ca_cis;
337: };
338:
339:
340: #define CARDBUS_ENABLE 1 /* enable the channel */
341: #define CARDBUS_DISABLE 2 /* disable the channel */
342: #define CARDBUS_RESET 4
343: #define CARDBUS_CD 7
344: # define CARDBUS_NOCARD 0
345: # define CARDBUS_5V_CARD 0x01 /* XXX: It must not exist */
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 /* bus master */
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: * Locators devies that attach to 'cardbus', as specified to config.
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 /* !_DEV_CARDBUS_CARDBUSVAR_H_ */
CVSweb