Home | History | Annotate | Line # | Download | only in cardbus
cardbusvar.h revision 1.35.44.3
      1 /*	$NetBSD: cardbusvar.h,v 1.35.44.3 2007/11/06 14:27:15 joerg 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  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *	This product includes software developed by the author.
     18  * 4. The name of the author may not be used to endorse or promote products
     19  *    derived from this software without specific prior written permission.
     20  *
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     24  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     25  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
     26  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     27  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     28  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     30  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
     31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     32  * POSSIBILITY OF SUCH DAMAGE.
     33  */
     34 
     35 #ifndef _DEV_CARDBUS_CARDBUSVAR_H_
     36 #define _DEV_CARDBUS_CARDBUSVAR_H_
     37 
     38 #include <dev/cardbus/cardbusreg.h>
     39 #if 1
     40 #include <dev/cardbus/rbus.h>
     41 #endif
     42 
     43 
     44 
     45 typedef void *cardbus_chipset_tag_t;
     46 typedef int cardbus_intr_handle_t;
     47 
     48 
     49 #if rbus
     50 /*
     51  * struct cardbus_functions contains the pointers for basic cardbus
     52  * functions.  Those functions must be provided by cardbus bridge.
     53  * The child devices can use those functions.  The contained functions
     54  * are: cardbus_space_alloc, cardbus_space_free,
     55  * cardbus_intr_establish, cardbus_intr_disestablish, cardbus_ctrl,
     56  * cardbus_power, cardbus_make_tag, cardbus_free_tag and
     57  * cardbus_conf_write.
     58  *
     59  *	int (*cardbus_space_alloc)(cardbus_chipset_tag_t ct, rbus_tag_t rb,
     60  *	    bus_addr_t addr, bus_size_t size,
     61  *	    bus_addr_t mask, bus_size_t align,
     62  *	    int flags, bus_addr_t *addrp,
     63  *	    bus_space_handle_t *bshp);
     64  *
     65  *	int (*cardbus_space_free)(cardbus_chipset_tag_t ct, rbus_tag_t rb,
     66  *	    bus_space_handle_t, bus_size_t);
     67  *
     68  * cardbus_space_alloc and cardbus_space_free allocates and
     69  * disallocate bus space for the requesters.
     70  *
     71  *	void *(*cardbus_intr_establish)(cardbus_chipset_tag_t ct, int irq,
     72  *	     int level, int (*ih)(void *), void *sc);
     73  *
     74  *	void (*cardbus_intr_disestablish)(cardbus_chipset_tag_t ct, void *ih);
     75  *	int (*cardbus_ctrl)(cardbus_chipset_tag_t ct, int command);
     76  *	int (*cardbus_power)(cardbus_chipset_tag_t ct, int voltage);
     77  *
     78  *	cardbustag_t (*cardbus_make_tag)(cardbus_chipset_tag_t ct,
     79  *	    int busno, int functionno);
     80  *	void (*cardbus_free_tag)(cardbus_chipset_tag_t ct, cardbustag_t tag);
     81  *	cardbusreg_t (*cardbus_conf_read)(cardbus_chipset_tag_t ct,
     82  *	    cardbustag_t tag, int offs);
     83  *	void (*cardbus_conf_write)(cardbus_chipset_tag_t ct,
     84  *	    cardbustag_t tag, int offs, cardbusreg_t val);
     85  */
     86 typedef struct cardbus_functions {
     87 	int (*cardbus_space_alloc)(cardbus_chipset_tag_t, rbus_tag_t,
     88 	    bus_addr_t, bus_size_t, bus_addr_t, bus_size_t,
     89 	    int, bus_addr_t *, bus_space_handle_t *);
     90 	int (*cardbus_space_free)(cardbus_chipset_tag_t, rbus_tag_t,
     91 	    bus_space_handle_t, bus_size_t);
     92 	void *(*cardbus_intr_establish)(cardbus_chipset_tag_t, int, int,
     93 	    int (*)(void *), void *);
     94 	void (*cardbus_intr_disestablish)(cardbus_chipset_tag_t, void *);
     95 	int (*cardbus_ctrl)(cardbus_chipset_tag_t, int);
     96 	int (*cardbus_power)(cardbus_chipset_tag_t, int);
     97 
     98 	cardbustag_t (*cardbus_make_tag)(cardbus_chipset_tag_t, int, int);
     99 	void (*cardbus_free_tag)(cardbus_chipset_tag_t, cardbustag_t);
    100 	cardbusreg_t (*cardbus_conf_read)(cardbus_chipset_tag_t,
    101 	    cardbustag_t, int);
    102 	void (*cardbus_conf_write)(cardbus_chipset_tag_t, cardbustag_t,
    103 	    int, cardbusreg_t);
    104 } cardbus_function_t, *cardbus_function_tag_t;
    105 
    106 #else
    107 
    108 typedef struct cardbus_functions {
    109 	int (*cardbus_ctrl)(cardbus_chipset_tag_t, int);
    110 	int (*cardbus_power)(cardbus_chipset_tag_t, int);
    111 	int (*cardbus_mem_open)(cardbus_chipset_tag_t, int, u_int32_t,
    112 	    u_int32_t);
    113 	int (*cardbus_mem_close)(cardbus_chipset_tag_t, int);
    114 	int (*cardbus_io_open)(cardbus_chipset_tag_t, int, u_int32_t,
    115 	    u_int32_t);
    116 	int (*cardbus_io_close)(cardbus_chipset_tag_t, int);
    117 	void *(*cardbus_intr_establish)(cardbus_chipset_tag_t, int, int,
    118 	    int (*)(void *), void *);
    119 	void (*cardbus_intr_disestablish)(cardbus_chipset_tag_t, void *);
    120 
    121 	cardbustag_t (*cardbus_make_tag)(cardbus_chipset_tag_t, int, int);
    122 	cardbusreg_t (*cardbus_conf_read)(cardbus_chipset_tag_t,
    123 	    cardbustag_t, int);
    124 	void (*cardbus_conf_write)(cardbus_chipset_tag_t, cardbustag_t,
    125 	    int, cardbusreg_t);
    126 } cardbus_function_t, *cardbus_function_tag_t;
    127 #endif /* rbus */
    128 
    129 /*
    130  * struct cbslot_attach_args is the attach argument for cardbus card.
    131  */
    132 struct cbslot_attach_args {
    133 	const char *cba_busname;
    134 	bus_space_tag_t cba_iot;	/* cardbus i/o space tag */
    135 	bus_space_tag_t cba_memt;	/* cardbus mem space tag */
    136 	bus_dma_tag_t cba_dmat;		/* DMA tag */
    137 
    138 	int cba_bus;			/* cardbus bus number */
    139 
    140 	cardbus_chipset_tag_t cba_cc;	/* cardbus chipset */
    141 	cardbus_function_tag_t cba_cf; /* cardbus functions */
    142 	int cba_intrline;		/* interrupt line */
    143 
    144 #if rbus
    145 	rbus_tag_t cba_rbus_iot;	/* CardBus i/o rbus tag */
    146 	rbus_tag_t cba_rbus_memt;	/* CardBus mem rbus tag */
    147 #endif
    148 
    149 	int cba_cacheline;		/* cache line size */
    150 	int cba_lattimer;		/* latency timer */
    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 	struct device sc_dev;		/* fundamental device structure */
    161 
    162 	int sc_bus;			/* cardbus bus number */
    163 	int 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_lattimer;		/* latency timer */
    179 	int sc_volt;			/* applied Vcc voltage */
    180 #define PCCARD_33V  0x02
    181 #define PCCARD_XXV  0x04
    182 #define PCCARD_YYV  0x08
    183 	int sc_poweron_func;
    184   struct cardbus_devfunc *sc_funcs[8];	/* list of cardbus device functions */
    185 };
    186 
    187 struct cardbus_conf_state {
    188 	cardbusreg_t reg[16];
    189 };
    190 
    191 /*
    192  * struct cardbus_devfunc:
    193  *
    194  *   This is the data deposit for each function of a CardBus device.
    195  *   This structure is used for memory or i/o space allocation and
    196  *   disallocation.
    197  */
    198 typedef struct cardbus_devfunc {
    199 	cardbus_chipset_tag_t ct_cc;
    200 	cardbus_function_tag_t ct_cf;
    201 	struct cardbus_softc *ct_sc;	/* pointer to the parent */
    202 	int ct_bus;			/* bus number */
    203 	int ct_func;			/* function number */
    204 
    205 #if rbus
    206 	rbus_tag_t ct_rbus_iot;		/* CardBus i/o rbus tag */
    207 	rbus_tag_t ct_rbus_memt;	/* CardBus mem rbus tag */
    208 #endif
    209 
    210 	u_int32_t ct_bar[6];		/* Base Address Regs 0 to 6 */
    211 	u_int32_t ct_lc;		/* Latency timer and cache line size */
    212 	/* u_int32_t ct_cisreg; */	/* CIS reg: is it needed??? */
    213 
    214 	struct device *ct_device;	/* pointer to the device */
    215 
    216 	/* some data structure needed for tuple??? */
    217 } *cardbus_devfunc_t;
    218 
    219 
    220 /* XXX various things extracted from CIS */
    221 struct cardbus_cis_info {
    222 	int32_t		manufacturer;
    223 	int32_t		product;
    224 	char		cis1_info_buf[256];
    225 	char*		cis1_info[4];
    226 	struct cb_bar_info {
    227 		unsigned int flags;
    228 		unsigned int size;
    229 	} bar[7];
    230 	unsigned int	funcid;
    231 	union {
    232 		struct {
    233 			int uart_type;
    234 			int uart_present;
    235 		} serial;
    236 		struct {
    237 			char netid[6];
    238 			char netid_present;
    239 			char __filler;
    240 		} network;
    241 	} funce;
    242 };
    243 
    244 struct cardbus_attach_args {
    245 	cardbus_devfunc_t ca_ct;
    246 
    247 	bus_space_tag_t ca_iot;		/* CardBus I/O space tag */
    248 	bus_space_tag_t ca_memt;	/* CardBus MEM space tag */
    249 	bus_dma_tag_t ca_dmat;		/* DMA tag */
    250 
    251 	u_int ca_bus;
    252 	u_int ca_function;
    253 	cardbustag_t ca_tag;
    254 	cardbusreg_t ca_id;
    255 	cardbusreg_t ca_class;
    256 
    257 	/* interrupt information */
    258 	cardbus_intr_line_t ca_intrline;
    259 
    260 #if rbus
    261 	rbus_tag_t ca_rbus_iot;		/* CardBus i/o rbus tag */
    262 	rbus_tag_t ca_rbus_memt;	/* CardBus mem rbus tag */
    263 #endif
    264 
    265 	struct cardbus_cis_info ca_cis;
    266 };
    267 
    268 
    269 #define CARDBUS_ENABLE  1	/* enable the channel */
    270 #define CARDBUS_DISABLE 2	/* disable the channel */
    271 #define CARDBUS_RESET   4
    272 #define CARDBUS_CD      7
    273 #  define CARDBUS_NOCARD 0
    274 #  define CARDBUS_5V_CARD 0x01	/* XXX: It must not exist */
    275 #  define CARDBUS_3V_CARD 0x02
    276 #  define CARDBUS_XV_CARD 0x04
    277 #  define CARDBUS_YV_CARD 0x08
    278 #define CARDBUS_IO_ENABLE    100
    279 #define CARDBUS_IO_DISABLE   101
    280 #define CARDBUS_MEM_ENABLE   102
    281 #define CARDBUS_MEM_DISABLE  103
    282 #define CARDBUS_BM_ENABLE    104 /* bus master */
    283 #define CARDBUS_BM_DISABLE   105
    284 
    285 #define CARDBUS_VCC_UC  0x0000
    286 #define CARDBUS_VCC_3V  0x0001
    287 #define CARDBUS_VCC_XV  0x0002
    288 #define CARDBUS_VCC_YV  0x0003
    289 #define CARDBUS_VCC_0V  0x0004
    290 #define CARDBUS_VCC_5V  0x0005	/* ??? */
    291 #define CARDBUS_VCCMASK 0x000f
    292 #define CARDBUS_VPP_UC  0x0000
    293 #define CARDBUS_VPP_VCC 0x0010
    294 #define CARDBUS_VPP_12V 0x0030
    295 #define CARDBUS_VPP_0V  0x0040
    296 #define CARDBUS_VPPMASK 0x00f0
    297 
    298 
    299 int cardbus_attach_card(struct cardbus_softc *);
    300 void cardbus_detach_card(struct cardbus_softc *);
    301 void *cardbus_intr_establish(cardbus_chipset_tag_t, cardbus_function_tag_t,
    302     cardbus_intr_handle_t, int, int (*) (void *), void *arg);
    303 void cardbus_intr_disestablish(cardbus_chipset_tag_t,
    304     cardbus_function_tag_t, void *);
    305 
    306 int cardbus_mapreg_map(struct cardbus_softc *, int, int, cardbusreg_t,
    307     int, bus_space_tag_t *, bus_space_handle_t *, bus_addr_t *, bus_size_t *);
    308 int cardbus_mapreg_unmap(struct cardbus_softc *, int, int,
    309     bus_space_tag_t, bus_space_handle_t, bus_size_t);
    310 
    311 int cardbus_save_bar(cardbus_devfunc_t);
    312 int cardbus_restore_bar(cardbus_devfunc_t);
    313 
    314 int cardbus_function_enable(struct cardbus_softc *, int);
    315 int cardbus_function_disable(struct cardbus_softc *, int);
    316 
    317 void cardbus_disable_retry(cardbus_chipset_tag_t, cardbus_function_tag_t,
    318     cardbustag_t);
    319 
    320 int cardbus_get_capability(cardbus_chipset_tag_t, cardbus_function_tag_t,
    321     cardbustag_t, int, int *, cardbusreg_t *);
    322 int cardbus_get_powerstate(cardbus_devfunc_t, cardbustag_t, cardbusreg_t *);
    323 int cardbus_set_powerstate(cardbus_devfunc_t, cardbustag_t, cardbusreg_t);
    324 
    325 void cardbus_conf_capture(cardbus_chipset_tag_t, cardbus_function_tag_t,
    326     cardbustag_t, struct cardbus_conf_state *);
    327 void cardbus_conf_restore(cardbus_chipset_tag_t, cardbus_function_tag_t,
    328     cardbustag_t, struct cardbus_conf_state *);
    329 
    330 #define Cardbus_function_enable(ct) cardbus_function_enable((ct)->ct_sc, (ct)->ct_func)
    331 #define Cardbus_function_disable(ct) cardbus_function_disable((ct)->ct_sc, (ct)->ct_func)
    332 
    333 
    334 
    335 #define Cardbus_mapreg_map(ct, reg, type, busflags, tagp, handlep, basep, sizep) \
    336 	cardbus_mapreg_map((ct)->ct_sc, (ct->ct_func), (reg), (type),\
    337 			   (busflags), (tagp), (handlep), (basep), (sizep))
    338 #define Cardbus_mapreg_unmap(ct, reg, tag, handle, size) \
    339 	cardbus_mapreg_unmap((ct)->ct_sc, (ct->ct_func), (reg), (tag), (handle), (size))
    340 
    341 #define Cardbus_make_tag(ct) (*(ct)->ct_cf->cardbus_make_tag)((ct)->ct_cc, (ct)->ct_bus, (ct)->ct_func)
    342 #define cardbus_make_tag(cc, cf, bus, function) ((cf)->cardbus_make_tag)((cc), (bus), (function))
    343 
    344 #define Cardbus_free_tag(ct, tag) (*(ct)->ct_cf->cardbus_free_tag)((ct)->ct_cc, (tag))
    345 #define cardbus_free_tag(cc, cf, tag) (*(cf)->cardbus_free_tag)(cc, (tag))
    346 
    347 #define Cardbus_conf_read(ct, tag, offs) (*(ct)->ct_cf->cardbus_conf_read)((ct)->ct_cf, (tag), (offs))
    348 #define cardbus_conf_read(cc, cf, tag, offs) ((cf)->cardbus_conf_read)((cc), (tag), (offs))
    349 #define Cardbus_conf_write(ct, tag, offs, val) (*(ct)->ct_cf->cardbus_conf_write)((ct)->ct_cf, (tag), (offs), (val))
    350 #define cardbus_conf_write(cc, cf, tag, offs, val) ((cf)->cardbus_conf_write)((cc), (tag), (offs), (val))
    351 
    352 #endif /* !_DEV_CARDBUS_CARDBUSVAR_H_ */
    353