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