Home | History | Annotate | Line # | Download | only in cardbus
      1  1.56      matt /*	$NetBSD: cardbusvar.h,v 1.56 2012/02/18 00:36:57 matt Exp $	*/
      2   1.1      haya 
      3   1.1      haya /*
      4  1.14      haya  * Copyright (c) 1998, 1999 and 2000
      5   1.1      haya  *       HAYAKAWA Koichi.  All rights reserved.
      6   1.1      haya  *
      7   1.1      haya  * Redistribution and use in source and binary forms, with or without
      8   1.1      haya  * modification, are permitted provided that the following conditions
      9   1.1      haya  * are met:
     10   1.1      haya  * 1. Redistributions of source code must retain the above copyright
     11   1.1      haya  *    notice, this list of conditions and the following disclaimer.
     12   1.1      haya  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1      haya  *    notice, this list of conditions and the following disclaimer in the
     14   1.1      haya  *    documentation and/or other materials provided with the distribution.
     15   1.1      haya  *
     16   1.1      haya  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17   1.1      haya  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     18   1.1      haya  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     19   1.1      haya  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
     20   1.1      haya  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     21   1.1      haya  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     22   1.1      haya  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23   1.1      haya  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     24   1.1      haya  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
     25   1.1      haya  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26   1.1      haya  * POSSIBILITY OF SUCH DAMAGE.
     27   1.1      haya  */
     28   1.1      haya 
     29  1.11    kleink #ifndef _DEV_CARDBUS_CARDBUSVAR_H_
     30  1.11    kleink #define _DEV_CARDBUS_CARDBUSVAR_H_
     31   1.1      haya 
     32  1.22      haya #include <dev/cardbus/cardbusreg.h>
     33   1.1      haya #include <dev/cardbus/rbus.h>
     34   1.1      haya 
     35  1.38    dyoung typedef struct cardbus_chipset_tag *cardbus_chipset_tag_t;
     36   1.1      haya 
     37  1.21      haya /*
     38  1.21      haya  * struct cardbus_functions contains the pointers for basic cardbus
     39  1.21      haya  * functions.  Those functions must be provided by cardbus bridge.
     40  1.21      haya  * The child devices can use those functions.  The contained functions
     41  1.21      haya  * are: cardbus_space_alloc, cardbus_space_free,
     42  1.21      haya  * cardbus_intr_establish, cardbus_intr_disestablish, cardbus_ctrl,
     43  1.47    dyoung  * cardbus_power, cardbus_make_tag, and cardbus_conf_write.
     44  1.21      haya  *
     45  1.21      haya  *	int (*cardbus_space_alloc)(cardbus_chipset_tag_t ct, rbus_tag_t rb,
     46  1.21      haya  *	    bus_addr_t addr, bus_size_t size,
     47  1.21      haya  *	    bus_addr_t mask, bus_size_t align,
     48  1.21      haya  *	    int flags, bus_addr_t *addrp,
     49  1.21      haya  *	    bus_space_handle_t *bshp);
     50  1.21      haya  *
     51  1.21      haya  *	int (*cardbus_space_free)(cardbus_chipset_tag_t ct, rbus_tag_t rb,
     52  1.21      haya  *	    bus_space_handle_t, bus_size_t);
     53  1.21      haya  *
     54  1.21      haya  * cardbus_space_alloc and cardbus_space_free allocates and
     55  1.21      haya  * disallocate bus space for the requesters.
     56  1.32     perry  *
     57  1.21      haya  *	void *(*cardbus_intr_establish)(cardbus_chipset_tag_t ct, int irq,
     58  1.21      haya  *	     int level, int (*ih)(void *), void *sc);
     59  1.21      haya  *
     60  1.21      haya  *	void (*cardbus_intr_disestablish)(cardbus_chipset_tag_t ct, void *ih);
     61  1.21      haya  *	int (*cardbus_ctrl)(cardbus_chipset_tag_t ct, int command);
     62  1.21      haya  *	int (*cardbus_power)(cardbus_chipset_tag_t ct, int voltage);
     63  1.21      haya  *
     64  1.46    dyoung  *	pcitag_t (*cardbus_make_tag)(cardbus_chipset_tag_t ct,
     65  1.34  drochner  *	    int busno, int functionno);
     66  1.46    dyoung  *	pcireg_t (*cardbus_conf_read)(cardbus_chipset_tag_t ct,
     67  1.46    dyoung  *	    pcitag_t tag, int offs);
     68  1.21      haya  *	void (*cardbus_conf_write)(cardbus_chipset_tag_t ct,
     69  1.46    dyoung  *	    pcitag_t tag, int offs, pcireg_t val);
     70  1.21      haya  */
     71  1.43  drochner typedef const struct cardbus_functions {
     72  1.31     perry 	int (*cardbus_space_alloc)(cardbus_chipset_tag_t, rbus_tag_t,
     73  1.21      haya 	    bus_addr_t, bus_size_t, bus_addr_t, bus_size_t,
     74  1.31     perry 	    int, bus_addr_t *, bus_space_handle_t *);
     75  1.31     perry 	int (*cardbus_space_free)(cardbus_chipset_tag_t, rbus_tag_t,
     76  1.31     perry 	    bus_space_handle_t, bus_size_t);
     77  1.41  drochner 	void *(*cardbus_intr_establish)(cardbus_chipset_tag_t,
     78  1.55  drochner 	    int, int (*)(void *), void *);
     79  1.31     perry 	void (*cardbus_intr_disestablish)(cardbus_chipset_tag_t, void *);
     80  1.31     perry 	int (*cardbus_ctrl)(cardbus_chipset_tag_t, int);
     81  1.31     perry 	int (*cardbus_power)(cardbus_chipset_tag_t, int);
     82  1.31     perry 
     83  1.46    dyoung 	pcitag_t (*cardbus_make_tag)(cardbus_chipset_tag_t, int, int);
     84  1.46    dyoung 	pcireg_t (*cardbus_conf_read)(cardbus_chipset_tag_t,
     85  1.46    dyoung 	    pcitag_t, int);
     86  1.46    dyoung 	void (*cardbus_conf_write)(cardbus_chipset_tag_t, pcitag_t,
     87  1.46    dyoung 	    int, pcireg_t);
     88   1.1      haya } cardbus_function_t, *cardbus_function_tag_t;
     89   1.1      haya 
     90   1.7      haya /*
     91  1.36    dyoung  * struct cbslot_attach_args is the attach argument for Cardbus cardslot.
     92   1.7      haya  */
     93   1.1      haya struct cbslot_attach_args {
     94  1.21      haya 	bus_space_tag_t cba_iot;	/* cardbus i/o space tag */
     95  1.21      haya 	bus_space_tag_t cba_memt;	/* cardbus mem space tag */
     96  1.21      haya 	bus_dma_tag_t cba_dmat;		/* DMA tag */
     97  1.21      haya 
     98  1.21      haya 	int cba_bus;			/* cardbus bus number */
     99  1.21      haya 
    100  1.21      haya 	cardbus_chipset_tag_t cba_cc;	/* cardbus chipset */
    101  1.21      haya 	cardbus_function_tag_t cba_cf; /* cardbus functions */
    102   1.1      haya 
    103  1.21      haya 	rbus_tag_t cba_rbus_iot;	/* CardBus i/o rbus tag */
    104  1.21      haya 	rbus_tag_t cba_rbus_memt;	/* CardBus mem rbus tag */
    105   1.1      haya 
    106  1.21      haya 	int cba_cacheline;		/* cache line size */
    107  1.36    dyoung 	int cba_max_lattimer;		/* No card's latency timer may
    108  1.36    dyoung 					 * exceed this.  On a PCI-Cardbus
    109  1.36    dyoung 					 * bridge, I let the latency timer on
    110  1.36    dyoung 					 * the primary bus (PCI bus) set
    111  1.36    dyoung 					 * the maximum.  That is kind of an
    112  1.36    dyoung 					 * arbitrary choice.  A more sensible
    113  1.36    dyoung 					 * choice may be either the
    114  1.36    dyoung 					 * latency timer on the primary bus,
    115  1.36    dyoung 					 * or the bridge's buffer size,
    116  1.36    dyoung 					 * whichever is larger.
    117  1.36    dyoung 					 */
    118   1.1      haya };
    119   1.1      haya 
    120   1.1      haya 
    121   1.1      haya struct cardbus_devfunc;
    122   1.1      haya 
    123   1.7      haya /*
    124   1.7      haya  * struct cardbus_softc is the softc for cardbus card.
    125   1.7      haya  */
    126   1.1      haya struct cardbus_softc {
    127  1.42  drochner 	device_t sc_dev;		/* fundamental device structure */
    128   1.1      haya 
    129  1.21      haya 	int sc_bus;			/* cardbus bus number */
    130  1.32     perry 
    131  1.21      haya 	bus_space_tag_t sc_iot;		/* CardBus I/O space tag */
    132  1.21      haya 	bus_space_tag_t sc_memt;	/* CardBus MEM space tag */
    133  1.21      haya 	bus_dma_tag_t sc_dmat;		/* DMA tag */
    134   1.1      haya 
    135  1.21      haya 	cardbus_chipset_tag_t sc_cc;	/* CardBus chipset */
    136  1.21      haya 	cardbus_function_tag_t sc_cf;	/* CardBus function */
    137   1.1      haya 
    138  1.21      haya 	rbus_tag_t sc_rbus_iot;		/* CardBus i/o rbus tag */
    139  1.21      haya 	rbus_tag_t sc_rbus_memt;	/* CardBus mem rbus tag */
    140   1.1      haya 
    141  1.21      haya 	int sc_cacheline;		/* cache line size */
    142  1.36    dyoung 	int sc_max_lattimer;		/* No card's latency timer
    143  1.36    dyoung 					 * may exceed this.  On a PCI-Cardbus
    144  1.36    dyoung 					 * bridge, the latency timer on
    145  1.36    dyoung 					 * the primary bus (PCI bus) sets
    146  1.36    dyoung 					 * the maximum.
    147  1.36    dyoung 					 */
    148  1.21      haya 	int sc_poweron_func;
    149  1.28  drochner   struct cardbus_devfunc *sc_funcs[8];	/* list of cardbus device functions */
    150   1.1      haya };
    151   1.1      haya 
    152  1.37  jmcneill struct cardbus_conf_state {
    153  1.46    dyoung 	pcireg_t reg[16];
    154  1.37  jmcneill };
    155   1.1      haya 
    156   1.7      haya /*
    157   1.1      haya  * struct cardbus_devfunc:
    158   1.1      haya  *
    159   1.1      haya  *   This is the data deposit for each function of a CardBus device.
    160   1.1      haya  *   This structure is used for memory or i/o space allocation and
    161   1.1      haya  *   disallocation.
    162   1.7      haya  */
    163   1.1      haya typedef struct cardbus_devfunc {
    164  1.21      haya 	cardbus_chipset_tag_t ct_cc;
    165  1.21      haya 	cardbus_function_tag_t ct_cf;
    166  1.21      haya 	struct cardbus_softc *ct_sc;	/* pointer to the parent */
    167  1.21      haya 	int ct_bus;			/* bus number */
    168  1.21      haya 	int ct_func;			/* function number */
    169   1.1      haya 
    170  1.46    dyoung 	pcireg_t ct_bhlc;		/* Latency timer and cache line size */
    171  1.21      haya 	/* u_int32_t ct_cisreg; */	/* CIS reg: is it needed??? */
    172   1.1      haya 
    173  1.39    dyoung 	device_t ct_device;	/* pointer to the device */
    174   1.1      haya 
    175  1.21      haya 	/* some data structure needed for tuple??? */
    176   1.1      haya } *cardbus_devfunc_t;
    177   1.1      haya 
    178   1.1      haya 
    179   1.8      joda /* XXX various things extracted from CIS */
    180   1.8      joda struct cardbus_cis_info {
    181  1.21      haya 	int32_t		manufacturer;
    182  1.21      haya 	int32_t		product;
    183  1.21      haya 	char		cis1_info_buf[256];
    184  1.21      haya 	char*		cis1_info[4];
    185  1.21      haya 	struct cb_bar_info {
    186  1.21      haya 		unsigned int flags;
    187  1.21      haya 		unsigned int size;
    188  1.21      haya 	} bar[7];
    189  1.21      haya 	unsigned int	funcid;
    190  1.21      haya 	union {
    191  1.21      haya 		struct {
    192  1.21      haya 			int uart_type;
    193  1.21      haya 			int uart_present;
    194  1.21      haya 		} serial;
    195  1.21      haya 		struct {
    196  1.21      haya 			char netid[6];
    197  1.21      haya 			char netid_present;
    198  1.21      haya 			char __filler;
    199  1.21      haya 		} network;
    200  1.21      haya 	} funce;
    201   1.8      joda };
    202   1.8      joda 
    203   1.1      haya struct cardbus_attach_args {
    204  1.21      haya 	cardbus_devfunc_t ca_ct;
    205   1.1      haya 
    206  1.21      haya 	bus_space_tag_t ca_iot;		/* CardBus I/O space tag */
    207  1.21      haya 	bus_space_tag_t ca_memt;	/* CardBus MEM space tag */
    208  1.21      haya 	bus_dma_tag_t ca_dmat;		/* DMA tag */
    209  1.21      haya 
    210  1.24  augustss 	u_int ca_bus;
    211  1.21      haya 	u_int ca_function;
    212  1.46    dyoung 	pcitag_t ca_tag;
    213  1.46    dyoung 	pcireg_t ca_id;
    214  1.46    dyoung 	pcireg_t ca_class;
    215   1.1      haya 
    216  1.21      haya 	rbus_tag_t ca_rbus_iot;		/* CardBus i/o rbus tag */
    217  1.21      haya 	rbus_tag_t ca_rbus_memt;	/* CardBus mem rbus tag */
    218   1.8      joda 
    219  1.21      haya 	struct cardbus_cis_info ca_cis;
    220   1.1      haya };
    221   1.1      haya 
    222   1.1      haya 
    223   1.1      haya #define CARDBUS_ENABLE  1	/* enable the channel */
    224   1.1      haya #define CARDBUS_DISABLE 2	/* disable the channel */
    225   1.1      haya #define CARDBUS_RESET   4
    226   1.1      haya #define CARDBUS_CD      7
    227   1.1      haya #  define CARDBUS_NOCARD 0
    228   1.1      haya #  define CARDBUS_5V_CARD 0x01	/* XXX: It must not exist */
    229   1.1      haya #  define CARDBUS_3V_CARD 0x02
    230   1.1      haya #  define CARDBUS_XV_CARD 0x04
    231   1.1      haya #  define CARDBUS_YV_CARD 0x08
    232   1.1      haya #define CARDBUS_IO_ENABLE    100
    233   1.1      haya #define CARDBUS_IO_DISABLE   101
    234   1.1      haya #define CARDBUS_MEM_ENABLE   102
    235   1.1      haya #define CARDBUS_MEM_DISABLE  103
    236   1.1      haya #define CARDBUS_BM_ENABLE    104 /* bus master */
    237   1.1      haya #define CARDBUS_BM_DISABLE   105
    238   1.1      haya 
    239   1.1      haya #define CARDBUS_VCC_UC  0x0000
    240   1.1      haya #define CARDBUS_VCC_3V  0x0001
    241   1.1      haya #define CARDBUS_VCC_XV  0x0002
    242   1.1      haya #define CARDBUS_VCC_YV  0x0003
    243   1.1      haya #define CARDBUS_VCC_0V  0x0004
    244   1.1      haya #define CARDBUS_VCC_5V  0x0005	/* ??? */
    245   1.1      haya #define CARDBUS_VCCMASK 0x000f
    246   1.1      haya #define CARDBUS_VPP_UC  0x0000
    247   1.1      haya #define CARDBUS_VPP_VCC 0x0010
    248   1.1      haya #define CARDBUS_VPP_12V 0x0030
    249   1.1      haya #define CARDBUS_VPP_0V  0x0040
    250   1.1      haya #define CARDBUS_VPPMASK 0x00f0
    251   1.1      haya 
    252   1.1      haya 
    253  1.31     perry int cardbus_attach_card(struct cardbus_softc *);
    254  1.31     perry void cardbus_detach_card(struct cardbus_softc *);
    255  1.49    dyoung void *Cardbus_intr_establish(cardbus_devfunc_t,
    256  1.55  drochner     int, int (*)(void *), void *);
    257  1.48    dyoung void Cardbus_intr_disestablish(cardbus_devfunc_t, void *);
    258  1.31     perry void *cardbus_intr_establish(cardbus_chipset_tag_t, cardbus_function_tag_t,
    259  1.55  drochner     int, int (*) (void *), void *arg);
    260  1.50    dyoung void cardbus_intr_disestablish(cardbus_chipset_tag_t, cardbus_function_tag_t,
    261  1.50    dyoung     void *);
    262  1.31     perry 
    263  1.46    dyoung int cardbus_mapreg_map(struct cardbus_softc *, int, int, pcireg_t,
    264  1.31     perry     int, bus_space_tag_t *, bus_space_handle_t *, bus_addr_t *, bus_size_t *);
    265  1.31     perry int cardbus_mapreg_unmap(struct cardbus_softc *, int, int,
    266  1.31     perry     bus_space_tag_t, bus_space_handle_t, bus_size_t);
    267  1.31     perry 
    268  1.31     perry int cardbus_function_enable(struct cardbus_softc *, int);
    269  1.31     perry int cardbus_function_disable(struct cardbus_softc *, int);
    270  1.31     perry 
    271  1.31     perry int cardbus_get_capability(cardbus_chipset_tag_t, cardbus_function_tag_t,
    272  1.46    dyoung     pcitag_t, int, int *, pcireg_t *);
    273  1.46    dyoung int cardbus_get_powerstate(cardbus_devfunc_t, pcitag_t, pcireg_t *);
    274  1.46    dyoung int cardbus_set_powerstate(cardbus_devfunc_t, pcitag_t, pcireg_t);
    275  1.37  jmcneill 
    276  1.37  jmcneill void cardbus_conf_capture(cardbus_chipset_tag_t, cardbus_function_tag_t,
    277  1.46    dyoung     pcitag_t, struct cardbus_conf_state *);
    278  1.37  jmcneill void cardbus_conf_restore(cardbus_chipset_tag_t, cardbus_function_tag_t,
    279  1.46    dyoung     pcitag_t, struct cardbus_conf_state *);
    280   1.7      haya 
    281   1.7      haya #define Cardbus_function_enable(ct) cardbus_function_enable((ct)->ct_sc, (ct)->ct_func)
    282   1.7      haya #define Cardbus_function_disable(ct) cardbus_function_disable((ct)->ct_sc, (ct)->ct_func)
    283   1.7      haya 
    284   1.7      haya 
    285   1.1      haya 
    286   1.4      haya #define Cardbus_mapreg_map(ct, reg, type, busflags, tagp, handlep, basep, sizep) \
    287   1.4      haya 	cardbus_mapreg_map((ct)->ct_sc, (ct->ct_func), (reg), (type),\
    288   1.4      haya 			   (busflags), (tagp), (handlep), (basep), (sizep))
    289  1.15      haya #define Cardbus_mapreg_unmap(ct, reg, tag, handle, size) \
    290  1.15      haya 	cardbus_mapreg_unmap((ct)->ct_sc, (ct->ct_func), (reg), (tag), (handle), (size))
    291   1.4      haya 
    292  1.34  drochner #define Cardbus_make_tag(ct) (*(ct)->ct_cf->cardbus_make_tag)((ct)->ct_cc, (ct)->ct_bus, (ct)->ct_func)
    293  1.34  drochner #define cardbus_make_tag(cc, cf, bus, function) ((cf)->cardbus_make_tag)((cc), (bus), (function))
    294   1.1      haya 
    295  1.38    dyoung #define Cardbus_conf_read(ct, tag, offs) (*(ct)->ct_cf->cardbus_conf_read)((ct)->ct_cc, (tag), (offs))
    296   1.1      haya #define cardbus_conf_read(cc, cf, tag, offs) ((cf)->cardbus_conf_read)((cc), (tag), (offs))
    297  1.38    dyoung #define Cardbus_conf_write(ct, tag, offs, val) (*(ct)->ct_cf->cardbus_conf_write)((ct)->ct_cc, (tag), (offs), (val))
    298  1.12       abs #define cardbus_conf_write(cc, cf, tag, offs, val) ((cf)->cardbus_conf_write)((cc), (tag), (offs), (val))
    299  1.12       abs 
    300  1.11    kleink #endif /* !_DEV_CARDBUS_CARDBUSVAR_H_ */
    301