Home | History | Annotate | Line # | Download | only in pcmcia
pcmciavar.h revision 1.14
      1 /*	$NetBSD: pcmciavar.h,v 1.14 2001/01/18 20:28:26 jdolecek Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1997 Marc Horowitz.  All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. All advertising materials mentioning features or use of this software
     15  *    must display the following acknowledgement:
     16  *	This product includes software developed by Marc Horowitz.
     17  * 4. The name of the author may not be used to endorse or promote products
     18  *    derived from this software without specific prior written permission.
     19  *
     20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #include <sys/types.h>
     33 #include <sys/queue.h>
     34 
     35 #include <machine/bus.h>
     36 
     37 #include <dev/pcmcia/pcmciachip.h>
     38 
     39 extern int	pcmcia_verbose;
     40 
     41 /*
     42  * Contains information about mapped/allocated i/o spaces.
     43  */
     44 struct pcmcia_io_handle {
     45 	bus_space_tag_t iot;		/* bus space tag (from chipset) */
     46 	bus_space_handle_t ioh;		/* mapped space handle */
     47 	bus_addr_t      addr;		/* resulting address in bus space */
     48 	bus_size_t      size;		/* size of i/o space */
     49 	int             flags;		/* misc. information */
     50 };
     51 
     52 #define	PCMCIA_IO_ALLOCATED	0x01	/* i/o space was allocated */
     53 
     54 /*
     55  * Contains information about allocated memory space.
     56  */
     57 struct pcmcia_mem_handle {
     58 	bus_space_tag_t memt;		/* bus space tag (from chipset) */
     59 	bus_space_handle_t memh;	/* mapped space handle */
     60 	bus_addr_t      addr;		/* resulting address in bus space */
     61 	bus_size_t      size;		/* size of mem space */
     62 	pcmcia_mem_handle_t mhandle;	/* opaque memory handle */
     63 	bus_size_t      realsize;	/* how much we really allocated */
     64 };
     65 
     66 /* pcmcia itself */
     67 
     68 #define PCMCIA_CFE_MWAIT_REQUIRED	0x0001
     69 #define PCMCIA_CFE_RDYBSY_ACTIVE	0x0002
     70 #define PCMCIA_CFE_WP_ACTIVE		0x0004
     71 #define PCMCIA_CFE_BVD_ACTIVE		0x0008
     72 #define PCMCIA_CFE_IO8			0x0010
     73 #define PCMCIA_CFE_IO16			0x0020
     74 #define PCMCIA_CFE_IRQSHARE		0x0040
     75 #define PCMCIA_CFE_IRQPULSE		0x0080
     76 #define PCMCIA_CFE_IRQLEVEL		0x0100
     77 #define PCMCIA_CFE_POWERDOWN		0x0200
     78 #define PCMCIA_CFE_READONLY		0x0400
     79 #define PCMCIA_CFE_AUDIO		0x0800
     80 
     81 struct pcmcia_config_entry {
     82 	int		number;
     83 	u_int32_t	flags;
     84 	int		iftype;
     85 	int		num_iospace;
     86 
     87 	/*
     88 	 * The card will only decode this mask in any case, so we can
     89 	 * do dynamic allocation with this in mind, in case the suggestions
     90 	 * below are no good.
     91 	 */
     92 	u_long		iomask;
     93 	struct {
     94 		u_long	length;
     95 		u_long	start;
     96 	} iospace[4];		/* XXX this could be as high as 16 */
     97 	u_int16_t	irqmask;
     98 	int		num_memspace;
     99 	struct {
    100 		u_long	length;
    101 		u_long	cardaddr;
    102 		u_long	hostaddr;
    103 	} memspace[2];		/* XXX this could be as high as 8 */
    104 	int		maxtwins;
    105 	SIMPLEQ_ENTRY(pcmcia_config_entry) cfe_list;
    106 };
    107 
    108 
    109 struct pcmcia_funce_disk {
    110 	int pfd_interface;
    111 };
    112 
    113 struct pcmcia_funce_lan {
    114 	int pfl_nidlen;
    115 	u_int8_t pfl_nid[8];
    116 };
    117 
    118 union pcmcia_funce {
    119 	struct pcmcia_funce_disk pfv_disk;
    120 	struct pcmcia_funce_lan pfv_lan;
    121 };
    122 
    123 
    124 struct pcmcia_function {
    125 	/* read off the card */
    126 	int		number;
    127 	int		function;
    128 	int		last_config_index;
    129 	u_long		ccr_base;
    130 	u_long		ccr_mask;
    131 	SIMPLEQ_HEAD(, pcmcia_config_entry) cfe_head;
    132 	SIMPLEQ_ENTRY(pcmcia_function) pf_list;
    133 	/* run-time state */
    134 	struct pcmcia_softc *sc;
    135 	struct device *child;
    136 	struct pcmcia_config_entry *cfe;
    137 	struct pcmcia_mem_handle pf_pcmh;
    138 #define	pf_ccrt		pf_pcmh.memt
    139 #define	pf_ccrh		pf_pcmh.memh
    140 #define	pf_ccr_mhandle	pf_pcmh.mhandle
    141 #define	pf_ccr_realsize	pf_pcmh.realsize
    142 	bus_addr_t	pf_ccr_offset;
    143 	int		pf_ccr_window;
    144 	long		pf_mfc_iobase;
    145 	long		pf_mfc_iomax;
    146 	int		(*ih_fct) __P((void *));
    147 	void		*ih_arg;
    148 	int		ih_ipl;
    149 	int		pf_flags;
    150 
    151 	union pcmcia_funce pf_funce; /* CISTPL_FUNCE */
    152 #define pf_funce_disk_interface pf_funce.pfv_disk.pfd_interface
    153 #define pf_funce_lan_nid pf_funce.pfv_lan.pfl_nid
    154 #define pf_funce_lan_nidlen pf_funce.pfv_lan.pfl_nidlen
    155 };
    156 
    157 /* pf_flags */
    158 #define	PFF_ENABLED	0x0001		/* function is enabled */
    159 
    160 struct pcmcia_card {
    161 	int		cis1_major;
    162 	int		cis1_minor;
    163 	/* XXX waste of space? */
    164 	char		cis1_info_buf[256];
    165 	char		*cis1_info[4];
    166 	/*
    167 	 * Use int32_t for manufacturer and product so that they can
    168 	 * hold the id value found in card CIS and special value that
    169 	 * indicates no id was found.
    170 	 */
    171 	int32_t		manufacturer;
    172 #define	PCMCIA_VENDOR_INVALID	-1
    173 	int32_t		product;
    174 #define	PCMCIA_PRODUCT_INVALID		-1
    175 	u_int16_t	error;
    176 #define	PCMCIA_CIS_INVALID		{ NULL, NULL, NULL, NULL }
    177 	SIMPLEQ_HEAD(, pcmcia_function) pf_head;
    178 };
    179 
    180 struct pcmcia_softc {
    181 	struct device	dev;
    182 
    183 	/* this stuff is for the socket */
    184 	pcmcia_chipset_tag_t pct;
    185 	pcmcia_chipset_handle_t pch;
    186 
    187 	/* this stuff is for the card */
    188 	struct pcmcia_card card;
    189 	void		*ih;
    190 	int		sc_enabled_count;	/* how many functions are
    191 						   enabled */
    192 
    193 	/*
    194 	 * These are passed down from the PCMCIA chip, and exist only
    195 	 * so that cards with Very Special address allocation needs
    196 	 * know what range they should be dealing with.
    197 	 */
    198 	bus_addr_t iobase;		/* start i/o space allocation here */
    199 	bus_size_t iosize;		/* size of the i/o space range */
    200 };
    201 
    202 struct pcmcia_cis_quirk {
    203 	int32_t manufacturer;
    204 	int32_t product;
    205 	const char *cis1_info[4];
    206 	const struct pcmcia_function *pf;
    207 	const struct pcmcia_config_entry *cfe;
    208 };
    209 
    210 struct pcmcia_attach_args {
    211 	int32_t manufacturer;
    212 	int32_t product;
    213 	struct pcmcia_card *card;
    214 	struct pcmcia_function *pf;
    215 };
    216 
    217 struct pcmcia_tuple {
    218 	unsigned int	code;
    219 	unsigned int	length;
    220 	u_long		mult;
    221 	bus_addr_t	ptr;
    222 	bus_space_tag_t	memt;
    223 	bus_space_handle_t memh;
    224 };
    225 
    226 struct pcmcia_product {
    227 	const char	*pp_name;		/* NULL if end of table */
    228 	u_int32_t	pp_vendor;
    229 	u_int32_t	pp_product;
    230 	int		pp_expfunc;
    231 };
    232 
    233 typedef int (*pcmcia_product_match_fn) __P((struct pcmcia_attach_args *pa,
    234     const struct pcmcia_product *ent, int vpfmatch));
    235 
    236 const struct pcmcia_product
    237 	*pcmcia_product_lookup __P((struct pcmcia_attach_args *pa,
    238 	    const struct pcmcia_product *tab, size_t ent_size,
    239 	    pcmcia_product_match_fn matchfn));
    240 
    241 void	pcmcia_devinfo __P((struct pcmcia_card *card, int showhex, char *cp,
    242 	    int cplen));
    243 
    244 void	pcmcia_read_cis __P((struct pcmcia_softc *));
    245 void	pcmcia_check_cis_quirks __P((struct pcmcia_softc *));
    246 void	pcmcia_print_cis __P((struct pcmcia_softc *));
    247 int	pcmcia_scan_cis __P((struct device * dev,
    248 	    int (*) (struct pcmcia_tuple *, void *), void *));
    249 
    250 #define	pcmcia_cis_read_1(tuple, idx0)					\
    251 	(bus_space_read_1((tuple)->memt, (tuple)->memh, (tuple)->mult*(idx0)))
    252 
    253 #define	pcmcia_tuple_read_1(tuple, idx1)				\
    254 	(pcmcia_cis_read_1((tuple), ((tuple)->ptr+(2+(idx1)))))
    255 
    256 #define	pcmcia_tuple_read_2(tuple, idx2)				\
    257 	(pcmcia_tuple_read_1((tuple), (idx2)) | 			\
    258 	 (pcmcia_tuple_read_1((tuple), (idx2)+1)<<8))
    259 
    260 #define	pcmcia_tuple_read_3(tuple, idx3)				\
    261 	(pcmcia_tuple_read_1((tuple), (idx3)) |				\
    262 	 (pcmcia_tuple_read_1((tuple), (idx3)+1)<<8) |			\
    263 	 (pcmcia_tuple_read_1((tuple), (idx3)+2)<<16))
    264 
    265 #define	pcmcia_tuple_read_4(tuple, idx4)				\
    266 	(pcmcia_tuple_read_1((tuple), (idx4)) |				\
    267 	 (pcmcia_tuple_read_1((tuple), (idx4)+1)<<8) |			\
    268 	 (pcmcia_tuple_read_1((tuple), (idx4)+2)<<16) |			\
    269 	 (pcmcia_tuple_read_1((tuple), (idx4)+3)<<24))
    270 
    271 #define	pcmcia_tuple_read_n(tuple, n, idxn)				\
    272 	(((n)==1)?pcmcia_tuple_read_1((tuple), (idxn)) :		\
    273 	 (((n)==2)?pcmcia_tuple_read_2((tuple), (idxn)) :		\
    274 	  (((n)==3)?pcmcia_tuple_read_3((tuple), (idxn)) :		\
    275 	   /* n == 4 */ pcmcia_tuple_read_4((tuple), (idxn)))))
    276 
    277 #define	PCMCIA_SPACE_MEMORY	1
    278 #define	PCMCIA_SPACE_IO		2
    279 
    280 int	pcmcia_ccr_read __P((struct pcmcia_function *, int));
    281 void	pcmcia_ccr_write __P((struct pcmcia_function *, int, int));
    282 
    283 #define	pcmcia_mfc(sc)	((sc)->card.pf_head.sqh_first &&		\
    284 			 (sc)->card.pf_head.sqh_first->pf_list.sqe_next)
    285 
    286 void	pcmcia_function_init __P((struct pcmcia_function *,
    287 	    struct pcmcia_config_entry *));
    288 int	pcmcia_function_enable __P((struct pcmcia_function *));
    289 void	pcmcia_function_disable __P((struct pcmcia_function *));
    290 
    291 #define	pcmcia_io_alloc(pf, start, size, align, pciop)			\
    292 	(pcmcia_chip_io_alloc((pf)->sc->pct, pf->sc->pch, (start),	\
    293 	 (size), (align), (pciop)))
    294 
    295 #define	pcmcia_io_free(pf, pciohp)					\
    296 	(pcmcia_chip_io_free((pf)->sc->pct, (pf)->sc->pch, (pciohp)))
    297 
    298 int	pcmcia_io_map __P((struct pcmcia_function *, int, bus_addr_t,
    299 	    bus_size_t, struct pcmcia_io_handle *, int *));
    300 void	pcmcia_io_unmap __P((struct pcmcia_function *, int));
    301 
    302 #define pcmcia_mem_alloc(pf, size, pcmhp)				\
    303 	(pcmcia_chip_mem_alloc((pf)->sc->pct, (pf)->sc->pch, (size), (pcmhp)))
    304 
    305 #define pcmcia_mem_free(pf, pcmhp)					\
    306 	(pcmcia_chip_mem_free((pf)->sc->pct, (pf)->sc->pch, (pcmhp)))
    307 
    308 #define pcmcia_mem_map(pf, kind, card_addr, size, pcmhp, offsetp, windowp) \
    309 	(pcmcia_chip_mem_map((pf)->sc->pct, (pf)->sc->pch, (kind),	\
    310 	 (card_addr), (size), (pcmhp), (offsetp), (windowp)))
    311 
    312 #define	pcmcia_mem_unmap(pf, window)					\
    313 	(pcmcia_chip_mem_unmap((pf)->sc->pct, (pf)->sc->pch, (window)))
    314 
    315 void	*pcmcia_intr_establish __P((struct pcmcia_function *, int,
    316 	    int (*) (void *), void *));
    317 void 	pcmcia_intr_disestablish __P((struct pcmcia_function *, void *));
    318