Home | History | Annotate | Line # | Download | only in pcmcia
pcmciavar.h revision 1.8
      1 /*	$NetBSD: pcmciavar.h,v 1.8 1998/12/24 04:51:59 marc 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 struct pcmcia_function {
    109 	/* read off the card */
    110 	int		number;
    111 	int		function;
    112 	int		last_config_index;
    113 	u_long		ccr_base;
    114 	u_long		ccr_mask;
    115 	SIMPLEQ_HEAD(, pcmcia_config_entry) cfe_head;
    116 	SIMPLEQ_ENTRY(pcmcia_function) pf_list;
    117 	/* run-time state */
    118 	struct pcmcia_softc *sc;
    119 	struct device *child;
    120 	struct pcmcia_config_entry *cfe;
    121 	struct pcmcia_mem_handle pf_pcmh;
    122 #define	pf_ccrt		pf_pcmh.memt
    123 #define	pf_ccrh		pf_pcmh.memh
    124 #define	pf_ccr_mhandle	pf_pcmh.mhandle
    125 #define	pf_ccr_realsize	pf_pcmh.realsize
    126 	bus_addr_t	pf_ccr_offset;
    127 	int		pf_ccr_window;
    128 	long		pf_mfc_iobase;
    129 	long		pf_mfc_iomax;
    130 	int		(*ih_fct) __P((void *));
    131 	void		*ih_arg;
    132 	int		ih_ipl;
    133 	int		pf_flags;
    134 };
    135 
    136 /* pf_flags */
    137 #define	PFF_ENABLED	0x0001		/* function is enabled */
    138 
    139 struct pcmcia_card {
    140 	int		cis1_major;
    141 	int		cis1_minor;
    142 	/* XXX waste of space? */
    143 	char		cis1_info_buf[256];
    144 	char		*cis1_info[4];
    145 	/*
    146 	 * Use int32_t for manufacturer and product so that they can
    147 	 * hold the id value found in card CIS and special value that
    148 	 * indicates no id was found.
    149 	 */
    150 	int32_t		manufacturer;
    151 #define	PCMCIA_VENDOR_INVALID	-1
    152 	int32_t		product;
    153 #define	PCMCIA_PRODUCT_INVALID		-1
    154 	u_int16_t	error;
    155 #define	PCMCIA_CIS_INVALID		{ NULL, NULL, NULL, NULL }
    156 	SIMPLEQ_HEAD(, pcmcia_function) pf_head;
    157 };
    158 
    159 struct pcmcia_softc {
    160 	struct device	dev;
    161 
    162 	/* this stuff is for the socket */
    163 	pcmcia_chipset_tag_t pct;
    164 	pcmcia_chipset_handle_t pch;
    165 
    166 	/* this stuff is for the card */
    167 	struct pcmcia_card card;
    168 	void		*ih;
    169 	int		sc_enabled_count;	/* how many functions are
    170 						   enabled */
    171 
    172 	/*
    173 	 * These are passed down from the PCMCIA chip, and exist only
    174 	 * so that cards with Very Special address allocation needs
    175 	 * know what range they should be dealing with.
    176 	 */
    177 	bus_addr_t iobase;		/* start i/o space allocation here */
    178 	bus_size_t iosize;		/* size of the i/o space range */
    179 };
    180 
    181 struct pcmcia_cis_quirk {
    182 	int32_t manufacturer;
    183 	int32_t product;
    184 	struct pcmcia_function *pf;
    185 	struct pcmcia_config_entry *cfe;
    186 };
    187 
    188 struct pcmcia_attach_args {
    189 	int32_t manufacturer;
    190 	int32_t product;
    191 	struct pcmcia_card *card;
    192 	struct pcmcia_function *pf;
    193 };
    194 
    195 struct pcmcia_tuple {
    196 	unsigned int	code;
    197 	unsigned int	length;
    198 	u_long		mult;
    199 	bus_addr_t	ptr;
    200 	bus_space_tag_t	memt;
    201 	bus_space_handle_t memh;
    202 };
    203 
    204 void	pcmcia_read_cis __P((struct pcmcia_softc *));
    205 void	pcmcia_check_cis_quirks __P((struct pcmcia_softc *));
    206 void	pcmcia_print_cis __P((struct pcmcia_softc *));
    207 int	pcmcia_scan_cis __P((struct device * dev,
    208 	    int (*) (struct pcmcia_tuple *, void *), void *));
    209 
    210 #define	pcmcia_cis_read_1(tuple, idx0)					\
    211 	(bus_space_read_1((tuple)->memt, (tuple)->memh, (tuple)->mult*(idx0)))
    212 
    213 #define	pcmcia_tuple_read_1(tuple, idx1)				\
    214 	(pcmcia_cis_read_1((tuple), ((tuple)->ptr+(2+(idx1)))))
    215 
    216 #define	pcmcia_tuple_read_2(tuple, idx2)				\
    217 	(pcmcia_tuple_read_1((tuple), (idx2)) | 			\
    218 	 (pcmcia_tuple_read_1((tuple), (idx2)+1)<<8))
    219 
    220 #define	pcmcia_tuple_read_3(tuple, idx3)				\
    221 	(pcmcia_tuple_read_1((tuple), (idx3)) |				\
    222 	 (pcmcia_tuple_read_1((tuple), (idx3)+1)<<8) |			\
    223 	 (pcmcia_tuple_read_1((tuple), (idx3)+2)<<16))
    224 
    225 #define	pcmcia_tuple_read_4(tuple, idx4)				\
    226 	(pcmcia_tuple_read_1((tuple), (idx4)) |				\
    227 	 (pcmcia_tuple_read_1((tuple), (idx4)+1)<<8) |			\
    228 	 (pcmcia_tuple_read_1((tuple), (idx4)+2)<<16) |			\
    229 	 (pcmcia_tuple_read_1((tuple), (idx4)+3)<<24))
    230 
    231 #define	pcmcia_tuple_read_n(tuple, n, idxn)				\
    232 	(((n)==1)?pcmcia_tuple_read_1((tuple), (idxn)) :		\
    233 	 (((n)==2)?pcmcia_tuple_read_2((tuple), (idxn)) :		\
    234 	  (((n)==3)?pcmcia_tuple_read_3((tuple), (idxn)) :		\
    235 	   /* n == 4 */ pcmcia_tuple_read_4((tuple), (idxn)))))
    236 
    237 #define	PCMCIA_SPACE_MEMORY	1
    238 #define	PCMCIA_SPACE_IO		2
    239 
    240 int	pcmcia_ccr_read __P((struct pcmcia_function *, int));
    241 void	pcmcia_ccr_write __P((struct pcmcia_function *, int, int));
    242 
    243 #define	pcmcia_mfc(sc)	((sc)->card.pf_head.sqh_first &&		\
    244 			 (sc)->card.pf_head.sqh_first->pf_list.sqe_next)
    245 
    246 void	pcmcia_function_init __P((struct pcmcia_function *,
    247 	    struct pcmcia_config_entry *));
    248 int	pcmcia_function_enable __P((struct pcmcia_function *));
    249 void	pcmcia_function_disable __P((struct pcmcia_function *));
    250 
    251 #define	pcmcia_io_alloc(pf, start, size, align, pciop)			\
    252 	(pcmcia_chip_io_alloc((pf)->sc->pct, pf->sc->pch, (start),	\
    253 	 (size), (align), (pciop)))
    254 
    255 #define	pcmcia_io_free(pf, pciohp)					\
    256 	(pcmcia_chip_io_free((pf)->sc->pct, (pf)->sc->pch, (pciohp)))
    257 
    258 int	pcmcia_io_map __P((struct pcmcia_function *, int, bus_addr_t,
    259 	    bus_size_t, struct pcmcia_io_handle *, int *));
    260 void	pcmcia_io_unmap __P((struct pcmcia_function *, int));
    261 
    262 #define pcmcia_mem_alloc(pf, size, pcmhp)				\
    263 	(pcmcia_chip_mem_alloc((pf)->sc->pct, (pf)->sc->pch, (size), (pcmhp)))
    264 
    265 #define pcmcia_mem_free(pf, pcmhp)					\
    266 	(pcmcia_chip_mem_free((pf)->sc->pct, (pf)->sc->pch, (pcmhp)))
    267 
    268 #define pcmcia_mem_map(pf, kind, card_addr, size, pcmhp, offsetp, windowp) \
    269 	(pcmcia_chip_mem_map((pf)->sc->pct, (pf)->sc->pch, (kind),	\
    270 	 (card_addr), (size), (pcmhp), (offsetp), (windowp)))
    271 
    272 #define	pcmcia_mem_unmap(pf, window)					\
    273 	(pcmcia_chip_mem_unmap((pf)->sc->pct, (pf)->sc->pch, (window)))
    274 
    275 void	*pcmcia_intr_establish __P((struct pcmcia_function *, int,
    276 	    int (*) (void *), void *));
    277 void 	pcmcia_intr_disestablish __P((struct pcmcia_function *, void *));
    278