Home | History | Annotate | Line # | Download | only in pcmcia
pcmciavar.h revision 1.1.2.6
      1  1.1.2.6  thorpej /*	$NetBSD: pcmciavar.h,v 1.1.2.6 1997/10/14 04:56:41 thorpej Exp $	*/
      2  1.1.2.6  thorpej 
      3  1.1.2.1     marc #include <sys/types.h>
      4  1.1.2.1     marc #include <sys/queue.h>
      5  1.1.2.1     marc 
      6  1.1.2.1     marc #include <machine/bus.h>
      7  1.1.2.1     marc 
      8  1.1.2.1     marc #include <dev/pcmcia/pcmciachip.h>
      9  1.1.2.1     marc 
     10  1.1.2.3  thorpej /*
     11  1.1.2.3  thorpej  * Contains information about mapped/allocated i/o spaces.
     12  1.1.2.3  thorpej  */
     13  1.1.2.3  thorpej struct pcmcia_io_handle {
     14  1.1.2.6  thorpej 	bus_space_tag_t iot;		/* bus space tag (from chipset) */
     15  1.1.2.6  thorpej 	bus_space_handle_t ioh;		/* mapped space handle */
     16  1.1.2.6  thorpej 	bus_addr_t      addr;		/* resulting address in bus space */
     17  1.1.2.6  thorpej 	bus_size_t      size;		/* size of i/o space */
     18  1.1.2.6  thorpej 	int             flags;		/* misc. information */
     19  1.1.2.3  thorpej };
     20  1.1.2.3  thorpej 
     21  1.1.2.3  thorpej #define	PCMCIA_IO_ALLOCATED	0x01	/* i/o space was allocated */
     22  1.1.2.3  thorpej 
     23  1.1.2.3  thorpej /*
     24  1.1.2.3  thorpej  * Contains information about allocated memory space.
     25  1.1.2.3  thorpej  */
     26  1.1.2.3  thorpej struct pcmcia_mem_handle {
     27  1.1.2.6  thorpej 	bus_space_tag_t memt;		/* bus space tag (from chipset) */
     28  1.1.2.6  thorpej 	bus_space_handle_t memh;	/* mapped space handle */
     29  1.1.2.6  thorpej 	bus_addr_t      addr;		/* resulting address in bus space */
     30  1.1.2.6  thorpej 	bus_size_t      size;		/* size of mem space */
     31  1.1.2.6  thorpej 	pcmcia_mem_handle_t mhandle;	/* opaque memory handle */
     32  1.1.2.6  thorpej 	bus_size_t      realsize;	/* how much we really allocated */
     33  1.1.2.3  thorpej };
     34  1.1.2.3  thorpej 
     35  1.1.2.1     marc /* pcmcia itself */
     36  1.1.2.1     marc 
     37  1.1.2.1     marc #define PCMCIA_CFE_MWAIT_REQUIRED	0x0001
     38  1.1.2.1     marc #define PCMCIA_CFE_RDYBSY_ACTIVE	0x0002
     39  1.1.2.1     marc #define PCMCIA_CFE_WP_ACTIVE		0x0004
     40  1.1.2.1     marc #define PCMCIA_CFE_BVD_ACTIVE		0x0008
     41  1.1.2.1     marc #define PCMCIA_CFE_IO8			0x0010
     42  1.1.2.1     marc #define PCMCIA_CFE_IO16			0x0020
     43  1.1.2.1     marc #define PCMCIA_CFE_IRQSHARE		0x0040
     44  1.1.2.1     marc #define PCMCIA_CFE_IRQPULSE		0x0080
     45  1.1.2.1     marc #define PCMCIA_CFE_IRQLEVEL		0x0100
     46  1.1.2.1     marc #define PCMCIA_CFE_POWERDOWN		0x0200
     47  1.1.2.1     marc #define PCMCIA_CFE_READONLY		0x0400
     48  1.1.2.1     marc #define PCMCIA_CFE_AUDIO		0x0800
     49  1.1.2.1     marc 
     50  1.1.2.1     marc struct pcmcia_config_entry {
     51  1.1.2.6  thorpej 	int		number;
     52  1.1.2.6  thorpej 	u_int32_t	flags;
     53  1.1.2.6  thorpej 	int		iftype;
     54  1.1.2.6  thorpej 	int		num_iospace;
     55  1.1.2.6  thorpej 
     56  1.1.2.6  thorpej 	/*
     57  1.1.2.6  thorpej 	 * The card will only decode this mask in any case, so we can
     58  1.1.2.6  thorpej 	 * do dynamic allocation with this in mind, in case the suggestions
     59  1.1.2.6  thorpej 	 * below are no good.
     60  1.1.2.6  thorpej 	 */
     61  1.1.2.6  thorpej 	u_long		iomask;
     62  1.1.2.6  thorpej 	struct {
     63  1.1.2.6  thorpej 		u_long	length;
     64  1.1.2.6  thorpej 		u_long	start;
     65  1.1.2.6  thorpej 	} iospace[4];		/* XXX this could be as high as 16 */
     66  1.1.2.6  thorpej 	u_int16_t	irqmask;
     67  1.1.2.6  thorpej 	int		num_memspace;
     68  1.1.2.6  thorpej 	struct {
     69  1.1.2.6  thorpej 		u_long	length;
     70  1.1.2.6  thorpej 		u_long	cardaddr;
     71  1.1.2.6  thorpej 		u_long	hostaddr;
     72  1.1.2.6  thorpej 	} memspace[2];		/* XXX this could be as high as 8 */
     73  1.1.2.6  thorpej 	int		maxtwins;
     74  1.1.2.6  thorpej 	SIMPLEQ_ENTRY(pcmcia_config_entry) cfe_list;
     75  1.1.2.1     marc };
     76  1.1.2.1     marc 
     77  1.1.2.1     marc struct pcmcia_function {
     78  1.1.2.6  thorpej 	/* read off the card */
     79  1.1.2.6  thorpej 	int		number;
     80  1.1.2.6  thorpej 	int		function;
     81  1.1.2.6  thorpej 	int		last_config_index;
     82  1.1.2.6  thorpej 	u_long		ccr_base;
     83  1.1.2.6  thorpej 	u_long		ccr_mask;
     84  1.1.2.6  thorpej 	SIMPLEQ_HEAD(, pcmcia_config_entry) cfe_head;
     85  1.1.2.6  thorpej 	SIMPLEQ_ENTRY(pcmcia_function) pf_list;
     86  1.1.2.6  thorpej 	/* run-time state */
     87  1.1.2.6  thorpej 	struct pcmcia_softc *sc;
     88  1.1.2.6  thorpej 	struct pcmcia_config_entry *cfe;
     89  1.1.2.6  thorpej 	struct pcmcia_mem_handle pf_pcmh;
     90  1.1.2.3  thorpej #define	pf_ccrt		pf_pcmh.memt
     91  1.1.2.3  thorpej #define	pf_ccrh		pf_pcmh.memh
     92  1.1.2.3  thorpej #define	pf_ccr_mhandle	pf_pcmh.mhandle
     93  1.1.2.3  thorpej #define	pf_ccr_realsize	pf_pcmh.realsize
     94  1.1.2.6  thorpej 	bus_addr_t	pf_ccr_offset;
     95  1.1.2.6  thorpej 	int		pf_ccr_window;
     96  1.1.2.6  thorpej 	int		(*ih_fct) __P((void *));
     97  1.1.2.6  thorpej 	void		*ih_arg;
     98  1.1.2.6  thorpej 	int		ih_ipl;
     99  1.1.2.6  thorpej 	int		pf_flags;
    100  1.1.2.1     marc };
    101  1.1.2.1     marc 
    102  1.1.2.4  thorpej /* pf_flags */
    103  1.1.2.4  thorpej #define	PFF_ENABLED	0x0001		/* function is enabled */
    104  1.1.2.4  thorpej 
    105  1.1.2.1     marc struct pcmcia_card {
    106  1.1.2.6  thorpej 	int		cis1_major;
    107  1.1.2.6  thorpej 	int		cis1_minor;
    108  1.1.2.6  thorpej 	/* XXX waste of space? */
    109  1.1.2.6  thorpej 	char		cis1_info_buf[256];
    110  1.1.2.6  thorpej 	char		*cis1_info[4];
    111  1.1.2.6  thorpej 	int		manufacturer;
    112  1.1.2.6  thorpej 	u_int16_t	product;
    113  1.1.2.6  thorpej 	u_int16_t	error;
    114  1.1.2.6  thorpej 	SIMPLEQ_HEAD(, pcmcia_function) pf_head;
    115  1.1.2.1     marc };
    116  1.1.2.1     marc 
    117  1.1.2.1     marc struct pcmcia_softc {
    118  1.1.2.6  thorpej 	struct device	dev;
    119  1.1.2.6  thorpej 
    120  1.1.2.6  thorpej 	/* this stuff is for the socket */
    121  1.1.2.6  thorpej 	pcmcia_chipset_tag_t pct;
    122  1.1.2.6  thorpej 	pcmcia_chipset_handle_t pch;
    123  1.1.2.6  thorpej 
    124  1.1.2.6  thorpej 	/* this stuff is for the card */
    125  1.1.2.6  thorpej 	struct pcmcia_card card;
    126  1.1.2.6  thorpej 	void		*ih;
    127  1.1.2.6  thorpej 	int		sc_enabled_count;	/* how many functions are
    128  1.1.2.6  thorpej 						   enabled */
    129  1.1.2.1     marc };
    130  1.1.2.1     marc 
    131  1.1.2.1     marc struct pcmcia_attach_args {
    132  1.1.2.6  thorpej 	u_int16_t manufacturer;
    133  1.1.2.6  thorpej 	u_int16_t product;
    134  1.1.2.6  thorpej 	struct pcmcia_card *card;
    135  1.1.2.6  thorpej 	struct pcmcia_function *pf;
    136  1.1.2.1     marc };
    137  1.1.2.1     marc 
    138  1.1.2.1     marc struct pcmcia_tuple {
    139  1.1.2.6  thorpej 	unsigned int	code;
    140  1.1.2.6  thorpej 	unsigned int	length;
    141  1.1.2.6  thorpej 	u_long		mult;
    142  1.1.2.6  thorpej 	bus_addr_t	ptr;
    143  1.1.2.6  thorpej 	bus_space_tag_t	memt;
    144  1.1.2.6  thorpej 	bus_space_handle_t memh;
    145  1.1.2.6  thorpej };
    146  1.1.2.6  thorpej 
    147  1.1.2.6  thorpej void	pcmcia_read_cis __P((struct pcmcia_softc *));
    148  1.1.2.6  thorpej void	pcmcia_print_cis __P((struct pcmcia_softc *));
    149  1.1.2.6  thorpej int	pcmcia_scan_cis __P((struct device * dev,
    150  1.1.2.6  thorpej 	    int (*) (struct pcmcia_tuple *, void *), void *));
    151  1.1.2.6  thorpej 
    152  1.1.2.6  thorpej #define	pcmcia_cis_read_1(tuple, idx0)					\
    153  1.1.2.6  thorpej 	(bus_space_read_1((tuple)->memt, (tuple)->memh, (tuple)->mult*(idx0)))
    154  1.1.2.6  thorpej 
    155  1.1.2.6  thorpej #define	pcmcia_tuple_read_1(tuple, idx1)				\
    156  1.1.2.1     marc 	(pcmcia_cis_read_1((tuple), ((tuple)->ptr+(2+(idx1)))))
    157  1.1.2.6  thorpej 
    158  1.1.2.6  thorpej #define	pcmcia_tuple_read_2(tuple, idx2)				\
    159  1.1.2.6  thorpej 	(pcmcia_tuple_read_1((tuple), (idx2)) | 			\
    160  1.1.2.1     marc 	 (pcmcia_tuple_read_1((tuple), (idx2)+1)<<8))
    161  1.1.2.6  thorpej 
    162  1.1.2.6  thorpej #define	pcmcia_tuple_read_3(tuple, idx3)				\
    163  1.1.2.6  thorpej 	(pcmcia_tuple_read_1((tuple), (idx3)) |				\
    164  1.1.2.6  thorpej 	 (pcmcia_tuple_read_1((tuple), (idx3)+1)<<8) |			\
    165  1.1.2.1     marc 	 (pcmcia_tuple_read_1((tuple), (idx3)+2)<<16))
    166  1.1.2.6  thorpej 
    167  1.1.2.6  thorpej #define	pcmcia_tuple_read_4(tuple, idx4)				\
    168  1.1.2.6  thorpej 	(pcmcia_tuple_read_1((tuple), (idx4)) |				\
    169  1.1.2.6  thorpej 	 (pcmcia_tuple_read_1((tuple), (idx4)+1)<<8) |			\
    170  1.1.2.6  thorpej 	 (pcmcia_tuple_read_1((tuple), (idx4)+2)<<16) |			\
    171  1.1.2.1     marc 	 (pcmcia_tuple_read_1((tuple), (idx4)+3)<<24))
    172  1.1.2.6  thorpej 
    173  1.1.2.6  thorpej #define	pcmcia_tuple_read_n(tuple, n, idxn)				\
    174  1.1.2.6  thorpej 	(((n)==1)?pcmcia_tuple_read_1((tuple), (idxn)) :		\
    175  1.1.2.6  thorpej 	 (((n)==2)?pcmcia_tuple_read_2((tuple), (idxn)) :		\
    176  1.1.2.6  thorpej 	  (((n)==3)?pcmcia_tuple_read_3((tuple), (idxn)) :		\
    177  1.1.2.1     marc 	   /* n == 4 */ pcmcia_tuple_read_4((tuple), (idxn)))))
    178  1.1.2.1     marc 
    179  1.1.2.6  thorpej #define	PCMCIA_SPACE_MEMORY	1
    180  1.1.2.6  thorpej #define	PCMCIA_SPACE_IO		2
    181  1.1.2.1     marc 
    182  1.1.2.6  thorpej int	pcmcia_ccr_read __P((struct pcmcia_function *, int));
    183  1.1.2.6  thorpej void	pcmcia_ccr_write __P((struct pcmcia_function *, int, int));
    184  1.1.2.1     marc 
    185  1.1.2.6  thorpej #define	pcmcia_mfc(sc)	((sc)->card.pf_head.sqh_first &&		\
    186  1.1.2.6  thorpej 			 (sc)->card.pf_head.sqh_first->pf_list.sqe_next)
    187  1.1.2.1     marc 
    188  1.1.2.6  thorpej void	pcmcia_function_init __P((struct pcmcia_function *,
    189  1.1.2.6  thorpej 	    struct pcmcia_config_entry *));
    190  1.1.2.6  thorpej int	pcmcia_function_enable __P((struct pcmcia_function *));
    191  1.1.2.6  thorpej void	pcmcia_function_disable __P((struct pcmcia_function *));
    192  1.1.2.1     marc 
    193  1.1.2.6  thorpej #define	pcmcia_io_alloc(pf, start, size, align, pciop)			\
    194  1.1.2.6  thorpej 	(pcmcia_chip_io_alloc((pf)->sc->pct, pf->sc->pch, (start),	\
    195  1.1.2.6  thorpej 	 (size), (align), (pciop)))
    196  1.1.2.1     marc 
    197  1.1.2.6  thorpej int	pcmcia_io_map __P((struct pcmcia_function *, int, bus_addr_t,
    198  1.1.2.6  thorpej 	    bus_size_t, struct pcmcia_io_handle *, int *));
    199  1.1.2.1     marc 
    200  1.1.2.6  thorpej #define pcmcia_mem_alloc(pf, size, pcmhp)				\
    201  1.1.2.3  thorpej 	(pcmcia_chip_mem_alloc((pf)->sc->pct, (pf)->sc->pch, (size), (pcmhp)))
    202  1.1.2.6  thorpej 
    203  1.1.2.6  thorpej #define pcmcia_mem_free(pf, pcmhp)					\
    204  1.1.2.3  thorpej 	(pcmcia_chip_mem_free((pf)->sc->pct, (pf)->sc->pch, (pcmhp)))
    205  1.1.2.6  thorpej 
    206  1.1.2.3  thorpej #define pcmcia_mem_map(pf, kind, card_addr, size, pcmhp, offsetp, windowp) \
    207  1.1.2.6  thorpej 	(pcmcia_chip_mem_map((pf)->sc->pct, (pf)->sc->pch, (kind),	\
    208  1.1.2.6  thorpej 	 (card_addr), (size), (pcmhp), (offsetp), (windowp)))
    209  1.1.2.6  thorpej 
    210  1.1.2.6  thorpej #define	pcmcia_mem_unmap(pf, window)					\
    211  1.1.2.1     marc 	(pcmcia_chip_mem_unmap((pf)->sc->pct, (pf)->sc->pch, (window)))
    212  1.1.2.1     marc 
    213  1.1.2.6  thorpej void	*pcmcia_intr_establish __P((struct pcmcia_function *, int,
    214  1.1.2.6  thorpej 	    int (*) (void *), void *));
    215  1.1.2.6  thorpej void 	pcmcia_intr_disestablish __P((struct pcmcia_function *, void *));
    216