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