1 /* $NetBSD: pcmciavar.h,v 1.9 1998/12/29 09:00:28 marc Exp $ */ 2 /* $FreeBSD$ */ 3 4 /* 5 * Copyright (c) 1997 Marc Horowitz. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by Marc Horowitz. 18 * 4. The name of the author may not be used to endorse or promote products 19 * derived from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 #include <sys/types.h> 34 #include <sys/queue.h> 35 36 #include <machine/bus.h> 37 38 #include <dev/pccard/pccardchip.h> 39 40 extern int pccard_verbose; 41 42 /* 43 * Contains information about mapped/allocated i/o spaces. 44 */ 45 struct pccard_io_handle { 46 bus_space_tag_t iot; /* bus space tag (from chipset) */ 47 bus_space_handle_t ioh; /* mapped space handle */ 48 bus_addr_t addr; /* resulting address in bus space */ 49 bus_size_t size; /* size of i/o space */ 50 int flags; /* misc. information */ 51 }; 52 53 #define PCCARD_IO_ALLOCATED 0x01 /* i/o space was allocated */ 54 55 /* 56 * Contains information about allocated memory space. 57 */ 58 struct pccard_mem_handle { 59 bus_space_tag_t memt; /* bus space tag (from chipset) */ 60 bus_space_handle_t memh; /* mapped space handle */ 61 bus_addr_t addr; /* resulting address in bus space */ 62 bus_size_t size; /* size of mem space */ 63 pccard_mem_handle_t mhandle; /* opaque memory handle */ 64 bus_size_t realsize; /* how much we really allocated */ 65 }; 66 67 /* pccard itself */ 68 69 #define PCCARD_CFE_MWAIT_REQUIRED 0x0001 70 #define PCCARD_CFE_RDYBSY_ACTIVE 0x0002 71 #define PCCARD_CFE_WP_ACTIVE 0x0004 72 #define PCCARD_CFE_BVD_ACTIVE 0x0008 73 #define PCCARD_CFE_IO8 0x0010 74 #define PCCARD_CFE_IO16 0x0020 75 #define PCCARD_CFE_IRQSHARE 0x0040 76 #define PCCARD_CFE_IRQPULSE 0x0080 77 #define PCCARD_CFE_IRQLEVEL 0x0100 78 #define PCCARD_CFE_POWERDOWN 0x0200 79 #define PCCARD_CFE_READONLY 0x0400 80 #define PCCARD_CFE_AUDIO 0x0800 81 82 struct pccard_config_entry { 83 int number; 84 u_int32_t flags; 85 int iftype; 86 int num_iospace; 87 88 /* 89 * The card will only decode this mask in any case, so we can 90 * do dynamic allocation with this in mind, in case the suggestions 91 * below are no good. 92 */ 93 u_long iomask; 94 struct { 95 u_long length; 96 u_long start; 97 } iospace[4]; /* XXX this could be as high as 16 */ 98 u_int16_t irqmask; 99 int num_memspace; 100 struct { 101 u_long length; 102 u_long cardaddr; 103 u_long hostaddr; 104 } memspace[2]; /* XXX this could be as high as 8 */ 105 int maxtwins; 106 STAILQ_ENTRY(pccard_config_entry) cfe_list; 107 }; 108 109 struct pccard_function { 110 /* read off the card */ 111 int number; 112 int function; 113 int last_config_index; 114 u_long ccr_base; 115 u_long ccr_mask; 116 STAILQ_HEAD(, pccard_config_entry) cfe_head; 117 STAILQ_ENTRY(pccard_function) pf_list; 118 /* run-time state */ 119 struct pccard_softc *sc; 120 struct device *child; 121 struct pccard_config_entry *cfe; 122 struct pccard_mem_handle pf_pcmh; 123 #define pf_ccrt pf_pcmh.memt 124 #define pf_ccrh pf_pcmh.memh 125 #define pf_ccr_mhandle pf_pcmh.mhandle 126 #define pf_ccr_realsize pf_pcmh.realsize 127 bus_addr_t pf_ccr_offset; 128 int pf_ccr_window; 129 long pf_mfc_iobase; 130 long pf_mfc_iomax; 131 int (*ih_fct) __P((void *)); 132 void *ih_arg; 133 int ih_ipl; 134 int pf_flags; 135 }; 136 137 /* pf_flags */ 138 #define PFF_ENABLED 0x0001 /* function is enabled */ 139 140 struct pccard_card { 141 int cis1_major; 142 int cis1_minor; 143 /* XXX waste of space? */ 144 char cis1_info_buf[256]; 145 char *cis1_info[4]; 146 /* 147 * Use int32_t for manufacturer and product so that they can 148 * hold the id value found in card CIS and special value that 149 * indicates no id was found. 150 */ 151 int32_t manufacturer; 152 #define PCCARD_VENDOR_INVALID -1 153 int32_t product; 154 #define PCCARD_PRODUCT_INVALID -1 155 u_int16_t error; 156 #define PCCARD_CIS_INVALID { NULL, NULL, NULL, NULL } 157 STAILQ_HEAD(, pccard_function) pf_head; 158 }; 159 160 struct pccardbus_if { 161 int (*if_card_attach) __P((struct device*)); 162 void (*if_card_detach) __P((struct device*, int)); 163 void (*if_card_deactivate) __P((struct device*)); 164 int (*if_card_gettype) __P((struct device*)); 165 }; 166 167 struct pccard_softc { 168 169 /* this stuff is for the socket */ 170 pccard_chipset_tag_t pct; 171 pccard_chipset_handle_t pch; 172 173 /* this stuff is for the card */ 174 struct pccard_card card; 175 void *ih; 176 int sc_enabled_count; /* how many functions are 177 enabled */ 178 179 /* 180 * These are passed down from the PCCARD chip, and exist only 181 * so that cards with Very Special address allocation needs 182 * know what range they should be dealing with. 183 */ 184 bus_addr_t iobase; /* start i/o space allocation here */ 185 bus_size_t iosize; /* size of the i/o space range */ 186 /* pccardbus (upper) interface functions */ 187 struct pccardbus_if sc_if; 188 }; 189 190 void 191 pccardbus_if_setup __P((struct pccard_softc*)); 192 193 struct pccard_cis_quirk { 194 int32_t manufacturer; 195 int32_t product; 196 char *cis1_info[4]; 197 struct pccard_function *pf; 198 struct pccard_config_entry *cfe; 199 }; 200 201 struct pccard_attach_args { 202 int32_t manufacturer; 203 int32_t product; 204 struct pccard_card *card; 205 struct pccard_function *pf; 206 }; 207 208 struct pccard_tuple { 209 unsigned int code; 210 unsigned int length; 211 u_long mult; 212 bus_addr_t ptr; 213 bus_space_tag_t memt; 214 bus_space_handle_t memh; 215 }; 216 217 void pccard_read_cis __P((struct pccard_softc *)); 218 void pccard_check_cis_quirks(device_t); 219 void pccard_print_cis(device_t); 220 int pccard_scan_cis __P((struct device * dev, 221 int (*) (struct pccard_tuple *, void *), void *)); 222 223 #define pccard_cis_read_1(tuple, idx0) \ 224 (bus_space_read_1((tuple)->memt, (tuple)->memh, (tuple)->mult*(idx0))) 225 226 #define pccard_tuple_read_1(tuple, idx1) \ 227 (pccard_cis_read_1((tuple), ((tuple)->ptr+(2+(idx1))))) 228 229 #define pccard_tuple_read_2(tuple, idx2) \ 230 (pccard_tuple_read_1((tuple), (idx2)) | \ 231 (pccard_tuple_read_1((tuple), (idx2)+1)<<8)) 232 233 #define pccard_tuple_read_3(tuple, idx3) \ 234 (pccard_tuple_read_1((tuple), (idx3)) | \ 235 (pccard_tuple_read_1((tuple), (idx3)+1)<<8) | \ 236 (pccard_tuple_read_1((tuple), (idx3)+2)<<16)) 237 238 #define pccard_tuple_read_4(tuple, idx4) \ 239 (pccard_tuple_read_1((tuple), (idx4)) | \ 240 (pccard_tuple_read_1((tuple), (idx4)+1)<<8) | \ 241 (pccard_tuple_read_1((tuple), (idx4)+2)<<16) | \ 242 (pccard_tuple_read_1((tuple), (idx4)+3)<<24)) 243 244 #define pccard_tuple_read_n(tuple, n, idxn) \ 245 (((n)==1)?pccard_tuple_read_1((tuple), (idxn)) : \ 246 (((n)==2)?pccard_tuple_read_2((tuple), (idxn)) : \ 247 (((n)==3)?pccard_tuple_read_3((tuple), (idxn)) : \ 248 /* n == 4 */ pccard_tuple_read_4((tuple), (idxn))))) 249 250 #define PCCARD_SPACE_MEMORY 1 251 #define PCCARD_SPACE_IO 2 252 253 int pccard_ccr_read __P((struct pccard_function *, int)); 254 void pccard_ccr_write __P((struct pccard_function *, int, int)); 255 256 #define pccard_mfc(sc) (STAILQ_FIRST(&(sc)->card.pf_head) && \ 257 STAILQ_NEXT(STAILQ_FIRST(&(sc)->card.pf_head),pf_list)) 258 259 void pccard_function_init __P((struct pccard_function *, 260 struct pccard_config_entry *)); 261 int pccard_function_enable __P((struct pccard_function *)); 262 void pccard_function_disable __P((struct pccard_function *)); 263 264 #define pccard_io_alloc(pf, start, size, align, pciop) \ 265 (pccard_chip_io_alloc((pf)->sc->pct, pf->sc->pch, (start), \ 266 (size), (align), (pciop))) 267 268 #define pccard_io_free(pf, pciohp) \ 269 (pccard_chip_io_free((pf)->sc->pct, (pf)->sc->pch, (pciohp))) 270 271 int pccard_io_map __P((struct pccard_function *, int, bus_addr_t, 272 bus_size_t, struct pccard_io_handle *, int *)); 273 void pccard_io_unmap __P((struct pccard_function *, int)); 274 275 #define pccard_mem_alloc(pf, size, pcmhp) \ 276 (pccard_chip_mem_alloc((pf)->sc->pct, (pf)->sc->pch, (size), (pcmhp))) 277 278 #define pccard_mem_free(pf, pcmhp) \ 279 (pccard_chip_mem_free((pf)->sc->pct, (pf)->sc->pch, (pcmhp))) 280 281 #define pccard_mem_map(pf, kind, card_addr, size, pcmhp, offsetp, windowp) \ 282 (pccard_chip_mem_map((pf)->sc->pct, (pf)->sc->pch, (kind), \ 283 (card_addr), (size), (pcmhp), (offsetp), (windowp))) 284 285 #define pccard_mem_unmap(pf, window) \ 286 (pccard_chip_mem_unmap((pf)->sc->pct, (pf)->sc->pch, (window))) 287 288 void *pccard_intr_establish __P((struct pccard_function *, int, 289 int (*) (void *), void *)); 290 void pccard_intr_disestablish __P((struct pccard_function *, void *)); 291