Home | History | Annotate | Line # | Download | only in pcmcia
pcmciavar.h revision 1.1.2.2
      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 /* pcmcia itself */
      9 
     10 #define PCMCIA_CFE_MWAIT_REQUIRED	0x0001
     11 #define PCMCIA_CFE_RDYBSY_ACTIVE	0x0002
     12 #define PCMCIA_CFE_WP_ACTIVE		0x0004
     13 #define PCMCIA_CFE_BVD_ACTIVE		0x0008
     14 #define PCMCIA_CFE_IO8			0x0010
     15 #define PCMCIA_CFE_IO16			0x0020
     16 #define PCMCIA_CFE_IRQSHARE		0x0040
     17 #define PCMCIA_CFE_IRQPULSE		0x0080
     18 #define PCMCIA_CFE_IRQLEVEL		0x0100
     19 #define PCMCIA_CFE_POWERDOWN		0x0200
     20 #define PCMCIA_CFE_READONLY		0x0400
     21 #define PCMCIA_CFE_AUDIO		0x0800
     22 
     23 struct pcmcia_config_entry {
     24     int number;
     25     u_int32_t flags;
     26     int iftype;
     27     int num_iospace;
     28     u_long iomask;	/* the card will only decode this mask in any case,
     29 			   so we can do dynamic allocation with this in
     30 			   mind, in case the suggestions below are no good */
     31     struct {
     32 	u_long length;
     33 	u_long start;
     34     } iospace[4];	/* XXX this could be as high as 16 */
     35     u_int16_t irqmask;
     36     int num_memspace;
     37     struct {
     38 	u_long length;
     39 	u_long cardaddr;
     40 	u_long hostaddr;
     41     } memspace[2];	/* XXX this could be as high as 8 */
     42     int maxtwins;
     43     SIMPLEQ_ENTRY(pcmcia_config_entry) cfe_list;
     44 };
     45 
     46 struct pcmcia_function {
     47     /* read off the card */
     48     int number;
     49     int function;
     50     int last_config_index;
     51     u_long ccr_base;
     52     u_long ccr_mask;
     53     SIMPLEQ_HEAD(, pcmcia_config_entry) cfe_head;
     54     SIMPLEQ_ENTRY(pcmcia_function) pf_list;
     55     /* run-time state */
     56     struct pcmcia_softc *sc;
     57     struct pcmcia_config_entry *cfe;
     58     bus_space_tag_t ccrt;
     59     bus_space_handle_t ccrh;
     60     u_long ccr_offset;
     61     int ccr_window;
     62     pcmcia_mem_handle_t ccr_mhandle;
     63     u_long ccr_realsize;
     64     int (*ih_fct) __P((void *));
     65     void *ih_arg;
     66     int ih_ipl;
     67 };
     68 
     69 struct pcmcia_card {
     70     int cis1_major, cis1_minor;
     71     /* XXX waste of space? */
     72     char cis1_info_buf[256];
     73     char *cis1_info[4];
     74     int manufacturer;
     75     u_int16_t product;
     76     u_int16_t error;
     77     SIMPLEQ_HEAD(, pcmcia_function) pf_head;
     78 };
     79 
     80 struct pcmcia_softc {
     81     struct device dev;
     82     /* this stuff is for the socket */
     83     pcmcia_chipset_tag_t pct;
     84     pcmcia_chipset_handle_t pch;
     85     /* this stuff is for the card */
     86     struct pcmcia_card card;
     87     void *ih;
     88 };
     89 
     90 struct pcmcia_attach_args {
     91     u_int16_t manufacturer;
     92     u_int16_t product;
     93     struct pcmcia_card *card;
     94     struct pcmcia_function *pf;
     95 };
     96 
     97 struct pcmcia_tuple {
     98     unsigned int code;
     99     unsigned int length;
    100     u_long mult;
    101     u_long ptr;
    102     bus_space_tag_t memt;
    103     bus_space_handle_t memh;
    104 };
    105 
    106 void pcmcia_read_cis __P((struct pcmcia_softc *));
    107 void pcmcia_print_cis __P((struct pcmcia_softc *));
    108 int pcmcia_scan_cis __P((struct device *dev,
    109 			 int (*)(struct pcmcia_tuple *, void *), void *));
    110 
    111 #define pcmcia_cis_read_1(tuple, idx0) \
    112 	(bus_space_read_1((tuple)->memt, (tuple)->memh, \
    113 			  (tuple)->mult*(idx0)))
    114 #define pcmcia_tuple_read_1(tuple, idx1) \
    115 	(pcmcia_cis_read_1((tuple), ((tuple)->ptr+(2+(idx1)))))
    116 #define pcmcia_tuple_read_2(tuple, idx2) \
    117 	(pcmcia_tuple_read_1((tuple), (idx2)) | \
    118 	 (pcmcia_tuple_read_1((tuple), (idx2)+1)<<8))
    119 #define pcmcia_tuple_read_3(tuple, idx3) \
    120 	(pcmcia_tuple_read_1((tuple), (idx3)) | \
    121 	 (pcmcia_tuple_read_1((tuple), (idx3)+1)<<8) | \
    122 	 (pcmcia_tuple_read_1((tuple), (idx3)+2)<<16))
    123 #define pcmcia_tuple_read_4(tuple, idx4) \
    124 	(pcmcia_tuple_read_1((tuple), (idx4)) | \
    125 	 (pcmcia_tuple_read_1((tuple), (idx4)+1)<<8) | \
    126 	 (pcmcia_tuple_read_1((tuple), (idx4)+2)<<16) | \
    127 	 (pcmcia_tuple_read_1((tuple), (idx4)+3)<<24))
    128 #define pcmcia_tuple_read_n(tuple, n, idxn) \
    129 	(((n)==1)?pcmcia_tuple_read_1((tuple), (idxn)): \
    130 	 (((n)==2)?pcmcia_tuple_read_2((tuple), (idxn)): \
    131 	  (((n)==3)?pcmcia_tuple_read_3((tuple), (idxn)): \
    132 	   /* n == 4 */ pcmcia_tuple_read_4((tuple), (idxn)))))
    133 
    134 #define PCMCIA_SPACE_MEMORY	1
    135 #define PCMCIA_SPACE_IO		2
    136 
    137 int pcmcia_ccr_read __P((struct pcmcia_function *, int));
    138 void pcmcia_ccr_write __P((struct pcmcia_function *, int, int));
    139 
    140 #define pcmcia_mfc(sc) ((sc)->card.pf_head.sqh_first && \
    141 			(sc)->card.pf_head.sqh_first->pf_list.sqe_next)
    142 
    143 int pcmcia_enable_function __P((struct pcmcia_function *,
    144 				struct device *,
    145 				struct pcmcia_config_entry *));
    146 
    147 #define pcmcia_io_alloc(pf, start, size, iotp, iohp) \
    148 	(pcmcia_chip_io_alloc((pf)->sc->pct, pf->sc->pch, \
    149 			      (start), (size), (iotp), (iohp)))
    150 
    151 int pcmcia_io_map __P((struct pcmcia_function *, int, bus_size_t,
    152 		       bus_space_tag_t, bus_space_handle_t, int *));
    153 
    154 #define pcmcia_mem_alloc(pf, size, memtp, memhp, mhandle, realsize) \
    155 	(pcmcia_chip_mem_alloc((pf)->sc->pct, (pf)->sc->pch, \
    156 			       (size), (memtp), (memhp), (mhandle), \
    157 			       (realsize)))
    158 #define pcmcia_mem_free(pf, size, memt, memh, mhandle) \
    159 	(pcmcia_chip_mem_free((pf)->sc->pct, (pf)->sc->pch, \
    160 			      (size), (memt), (memh), (mhandle)))
    161 #define pcmcia_mem_map(pf, kind, size, memt, memh, \
    162 			    card_addr, offsetp, windowp) \
    163 	(pcmcia_chip_mem_map((pf)->sc->pct, (pf)->sc->pch, \
    164 			     (kind), (size), (memt), (memh), \
    165 			     (card_addr), (offsetp), (windowp)))
    166 #define pcmcia_mem_unmap(pf, window) \
    167 	(pcmcia_chip_mem_unmap((pf)->sc->pct, (pf)->sc->pch, (window)))
    168 
    169 void *pcmcia_intr_establish __P((struct pcmcia_function *, int,
    170 				 int (*)(void *), void *));
    171 void pcmcia_intr_disestablish __P((struct pcmcia_function *, void *));
    172 
    173