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