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