pccardvar.h revision 147711
1/* $NetBSD: pcmciavar.h,v 1.12 2000/02/08 12:51:31 enami Exp $ */ 2/* $FreeBSD: head/sys/dev/pccard/pccardvar.h 147711 2005-07-01 03:40:28Z imp $ */ 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 33extern int pccard_verbose; 34 35/* 36 * PCCARD_API_LEVEL. When set to 5, we provide a 5.x compatable API 37 * for driver writers that have to share their code between 5.x and 6.x. 38 * The 5.x compatibility interfaces will be unsupported in 7.0, at which 39 * point we'll only support 6 and newer, etc. 40 */ 41#ifndef PCCARD_API_LEVEL 42#define PCCARD_API_LEVEL 6 43#elif PCCARD_API_LEVEL < 5 44#error "pccard API less than 5 unsupported" 45#endif 46 47/* 48 * Contains information about mapped/allocated i/o spaces. 49 */ 50struct pccard_io_handle { 51 bus_space_tag_t iot; /* bus space tag (from chipset) */ 52 bus_space_handle_t ioh; /* mapped space handle */ 53 bus_addr_t addr; /* resulting address in bus space */ 54 bus_size_t size; /* size of i/o space */ 55 int flags; /* misc. information */ 56 int width; 57}; 58 59#define PCCARD_IO_ALLOCATED 0x01 /* i/o space was allocated */ 60 61/* 62 * Contains information about allocated memory space. 63 */ 64struct pccard_mem_handle { 65 bus_space_tag_t memt; /* bus space tag (from chipset) */ 66 bus_space_handle_t memh; /* mapped space handle */ 67 bus_addr_t addr; /* resulting address in bus space */ 68 bus_size_t size; /* size of mem space */ 69 bus_size_t realsize; /* how much we really allocated */ 70 bus_addr_t cardaddr; /* Absolute address on card */ 71 int kind; 72}; 73 74/* pccard itself */ 75 76#define PCCARD_CFE_MWAIT_REQUIRED 0x0001 77#define PCCARD_CFE_RDYBSY_ACTIVE 0x0002 78#define PCCARD_CFE_WP_ACTIVE 0x0004 79#define PCCARD_CFE_BVD_ACTIVE 0x0008 80#define PCCARD_CFE_IO8 0x0010 81#define PCCARD_CFE_IO16 0x0020 82#define PCCARD_CFE_IRQSHARE 0x0040 83#define PCCARD_CFE_IRQPULSE 0x0080 84#define PCCARD_CFE_IRQLEVEL 0x0100 85#define PCCARD_CFE_POWERDOWN 0x0200 86#define PCCARD_CFE_READONLY 0x0400 87#define PCCARD_CFE_AUDIO 0x0800 88 89struct pccard_config_entry { 90 int number; 91 uint32_t flags; 92 int iftype; 93 int num_iospace; 94 95 /* 96 * The card will only decode this mask in any case, so we can 97 * do dynamic allocation with this in mind, in case the suggestions 98 * below are no good. 99 */ 100 u_long iomask; 101 struct { 102 u_long length; 103 u_long start; 104 } iospace[4]; /* XXX this could be as high as 16 */ 105 uint16_t irqmask; 106 int num_memspace; 107 struct { 108 u_long length; 109 u_long cardaddr; 110 u_long hostaddr; 111 } memspace[2]; /* XXX this could be as high as 8 */ 112 int maxtwins; 113 STAILQ_ENTRY(pccard_config_entry) cfe_list; 114}; 115 116struct pccard_funce_disk { 117 int pfd_interface; 118}; 119 120struct pccard_funce_lan { 121 int pfl_nidlen; 122 uint8_t pfl_nid[8]; 123}; 124 125union pccard_funce { 126 struct pccard_funce_disk pfv_disk; 127 struct pccard_funce_lan pfv_lan; 128}; 129 130struct pccard_function { 131 /* read off the card */ 132 int number; 133 int function; 134 int last_config_index; 135 uint32_t ccr_base; /* Offset with card's memory */ 136 uint32_t ccr_mask; 137 struct resource *ccr_res; 138 int ccr_rid; 139 STAILQ_HEAD(, pccard_config_entry) cfe_head; 140 STAILQ_ENTRY(pccard_function) pf_list; 141 /* run-time state */ 142 struct pccard_softc *sc; 143 struct pccard_config_entry *cfe; 144 struct pccard_mem_handle pf_pcmh; 145 device_t dev; 146#define pf_ccrt pf_pcmh.memt 147#define pf_ccrh pf_pcmh.memh 148#define pf_ccr_realsize pf_pcmh.realsize 149 uint32_t pf_ccr_offset; /* Offset from ccr_base of CIS */ 150 int pf_ccr_window; 151 bus_addr_t pf_mfc_iobase; 152 bus_addr_t pf_mfc_iomax; 153 int pf_flags; 154 driver_intr_t *intr_handler; 155 void *intr_handler_arg; 156 void *intr_handler_cookie; 157 158 union pccard_funce pf_funce; /* CISTPL_FUNCE */ 159#define pf_funce_disk_interface pf_funce.pfv_disk.pfd_interface 160#define pf_funce_lan_nid pf_funce.pfv_lan.pfl_nid 161#define pf_funce_lan_nidlen pf_funce.pfv_lan.pfl_nidlen 162}; 163 164/* pf_flags */ 165#define PFF_ENABLED 0x0001 /* function is enabled */ 166 167struct pccard_card { 168 int cis1_major; 169 int cis1_minor; 170 /* XXX waste of space? */ 171 char cis1_info_buf[256]; 172 char *cis1_info[4]; 173 /* 174 * Use int32_t for manufacturer and product so that they can 175 * hold the id value found in card CIS and special value that 176 * indicates no id was found. 177 */ 178 int32_t manufacturer; 179#define PCMCIA_VENDOR_INVALID -1 180 int32_t product; 181#define PCMCIA_PRODUCT_INVALID -1 182 int16_t prodext; 183 uint16_t error; 184#define PCMCIA_CIS_INVALID { NULL, NULL, NULL, NULL } 185 STAILQ_HEAD(, pccard_function) pf_head; 186}; 187 188#define PCCARD_WIDTH_AUTO 0 189#define PCCARD_WIDTH_IO8 1 190#define PCCARD_WIDTH_IO16 2 191 192/* More later? */ 193struct pccard_ivar { 194 struct resource_list resources; 195 struct pccard_function *fcn; 196}; 197 198struct pccard_softc { 199 device_t dev; 200 /* this stuff is for the socket */ 201 202 /* this stuff is for the card */ 203 struct pccard_card card; 204 int sc_enabled_count; /* num functions enabled */ 205}; 206 207struct pccard_cis_quirk { 208 int32_t manufacturer; 209 int32_t product; 210 char *cis1_info[4]; 211 struct pccard_function *pf; 212 struct pccard_config_entry *cfe; 213}; 214 215struct pccard_tuple { 216 unsigned int code; 217 unsigned int length; 218 u_long mult; 219 bus_addr_t ptr; 220 bus_space_tag_t memt; 221 bus_space_handle_t memh; 222}; 223 224typedef int (*pccard_scan_t)(struct pccard_tuple *, void *); 225 226struct pccard_product { 227 const char *pp_name; /* NULL if end of table */ 228#define PCCARD_VENDOR_ANY (0xffffffff) 229 uint32_t pp_vendor; 230#define PCCARD_PRODUCT_ANY (0xffffffff) 231 uint32_t pp_product; 232 const char *pp_cis[4]; 233}; 234 235typedef int (*pccard_product_match_fn) (device_t dev, 236 const struct pccard_product *ent, int vpfmatch); 237 238#include "card_if.h" 239 240/* 241 * make this inline so that we don't have to worry about dangling references 242 * to it in the modules or the code. 243 */ 244static __inline const struct pccard_product * 245pccard_product_lookup(device_t dev, const struct pccard_product *tab, 246 size_t ent_size, pccard_product_match_fn matchfn) 247{ 248 return CARD_DO_PRODUCT_LOOKUP(device_get_parent(dev), dev, 249 tab, ent_size, matchfn); 250} 251 252void pccard_read_cis(struct pccard_softc *); 253void pccard_check_cis_quirks(device_t); 254void pccard_print_cis(device_t); 255int pccard_scan_cis(device_t, pccard_scan_t, void *); 256 257#define pccard_cis_read_1(tuple, idx0) \ 258 (bus_space_read_1((tuple)->memt, (tuple)->memh, (tuple)->mult*(idx0))) 259 260#define pccard_tuple_read_1(tuple, idx1) \ 261 (pccard_cis_read_1((tuple), ((tuple)->ptr+(2+(idx1))))) 262 263#define pccard_tuple_read_2(tuple, idx2) \ 264 (pccard_tuple_read_1((tuple), (idx2)) | \ 265 (pccard_tuple_read_1((tuple), (idx2)+1)<<8)) 266 267#define pccard_tuple_read_3(tuple, idx3) \ 268 (pccard_tuple_read_1((tuple), (idx3)) | \ 269 (pccard_tuple_read_1((tuple), (idx3)+1)<<8) | \ 270 (pccard_tuple_read_1((tuple), (idx3)+2)<<16)) 271 272#define pccard_tuple_read_4(tuple, idx4) \ 273 (pccard_tuple_read_1((tuple), (idx4)) | \ 274 (pccard_tuple_read_1((tuple), (idx4)+1)<<8) | \ 275 (pccard_tuple_read_1((tuple), (idx4)+2)<<16) | \ 276 (pccard_tuple_read_1((tuple), (idx4)+3)<<24)) 277 278#define pccard_tuple_read_n(tuple, n, idxn) \ 279 (((n)==1)?pccard_tuple_read_1((tuple), (idxn)) : \ 280 (((n)==2)?pccard_tuple_read_2((tuple), (idxn)) : \ 281 (((n)==3)?pccard_tuple_read_3((tuple), (idxn)) : \ 282 /* n == 4 */ pccard_tuple_read_4((tuple), (idxn))))) 283 284#define PCCARD_SPACE_MEMORY 1 285#define PCCARD_SPACE_IO 2 286 287#define pccard_mfc(sc) \ 288 (STAILQ_FIRST(&(sc)->card.pf_head) && \ 289 STAILQ_NEXT(STAILQ_FIRST(&(sc)->card.pf_head),pf_list)) 290 291#define pccard_io_alloc(pf, start, size, align, pciop) \ 292 (pccard_chip_io_alloc((pf)->sc->pct, pf->sc->pch, (start), \ 293 (size), (align), (pciop))) 294 295#define pccard_io_free(pf, pciohp) \ 296 (pccard_chip_io_free((pf)->sc->pct, (pf)->sc->pch, (pciohp))) 297 298int pccard_io_map(struct pccard_function *, int, bus_addr_t, 299 bus_size_t, struct pccard_io_handle *, int *); 300void pccard_io_unmap(struct pccard_function *, int); 301 302#define pccard_mem_alloc(pf, size, pcmhp) \ 303 (pccard_chip_mem_alloc((pf)->sc->pct, (pf)->sc->pch, (size), (pcmhp))) 304#define pccard_mem_free(pf, pcmhp) \ 305 (pccard_chip_mem_free((pf)->sc->pct, (pf)->sc->pch, (pcmhp))) 306#define pccard_mem_map(pf, kind, card_addr, size, pcmhp, offsetp, windowp) \ 307 (pccard_chip_mem_map((pf)->sc->pct, (pf)->sc->pch, (kind), \ 308 (card_addr), (size), (pcmhp), (offsetp), (windowp))) 309#define pccard_mem_unmap(pf, window) \ 310 (pccard_chip_mem_unmap((pf)->sc->pct, (pf)->sc->pch, (window))) 311 312/* compat layer */ 313static __inline int 314pccard_compat_probe(device_t dev) 315{ 316 return (CARD_COMPAT_DO_PROBE(device_get_parent(dev), dev)); 317} 318 319static __inline int 320pccard_compat_attach(device_t dev) 321{ 322 return (CARD_COMPAT_DO_ATTACH(device_get_parent(dev), dev)); 323} 324 325/* ivar interface */ 326enum { 327 PCCARD_IVAR_ETHADDR, /* read ethernet address from CIS tupple */ 328 PCCARD_IVAR_VENDOR, 329 PCCARD_IVAR_PRODUCT, 330 PCCARD_IVAR_PRODEXT, 331 PCCARD_IVAR_FUNCTION_NUMBER, 332 PCCARD_IVAR_VENDOR_STR, /* CIS string for "Manufacturer" */ 333 PCCARD_IVAR_PRODUCT_STR,/* CIS strnig for "Product" */ 334 PCCARD_IVAR_CIS3_STR, 335 PCCARD_IVAR_CIS4_STR, 336 PCCARD_IVAR_FUNCTION 337}; 338 339#define PCCARD_ACCESSOR(A, B, T) \ 340__inline static int \ 341pccard_get_ ## A(device_t dev, T *t) \ 342{ \ 343 return BUS_READ_IVAR(device_get_parent(dev), dev, \ 344 PCCARD_IVAR_ ## B, (uintptr_t *) t); \ 345} 346 347PCCARD_ACCESSOR(ether, ETHADDR, uint8_t) 348PCCARD_ACCESSOR(vendor, VENDOR, uint32_t) 349PCCARD_ACCESSOR(product, PRODUCT, uint32_t) 350PCCARD_ACCESSOR(prodext, PRODEXT, uint16_t) 351PCCARD_ACCESSOR(function_number,FUNCTION_NUMBER, uint32_t) 352PCCARD_ACCESSOR(function, FUNCTION, uint32_t) 353PCCARD_ACCESSOR(vendor_str, VENDOR_STR, const char *) 354PCCARD_ACCESSOR(product_str, PRODUCT_STR, const char *) 355PCCARD_ACCESSOR(cis3_str, CIS3_STR, const char *) 356PCCARD_ACCESSOR(cis4_str, CIS4_STR, const char *) 357 358/* shared memory flags */ 359enum { 360 PCCARD_A_MEM_COM, /* common */ 361 PCCARD_A_MEM_ATTR, /* attribute */ 362 PCCARD_A_MEM_8BIT, /* 8 bit */ 363 PCCARD_A_MEM_16BIT /* 16 bit */ 364}; 365 366#define PCCARD_SOFTC(d) (struct pccard_softc *) device_get_softc(d) 367#define PCCARD_IVAR(d) (struct pccard_ivar *) device_get_ivars(d) 368 369#define PCCARD_S(a, b) PCMCIA_STR_ ## a ## _ ## b 370#define PCCARD_P(a, b) PCMCIA_PRODUCT_ ## a ## _ ## b 371#define PCCARD_C(a, b) PCMCIA_CIS_ ## a ## _ ## b 372#if PCCARD_API_LEVEL >= 6 373#define PCMCIA_CARD_D(v, p) { PCCARD_S(v, p), PCMCIA_VENDOR_ ## v, \ 374 PCCARD_P(v, p), PCCARD_C(v, p) } 375#define PCMCIA_CARD2_D(v1, p1, p2) \ 376 { PCMCIA_STR_ ## p2, PCMCIA_VENDOR_ ## v1, PCCARD_P(v1, p1), \ 377 PCMCIA_CIS_ ## p2} 378#define PCMCIA_CARD(v, p) { NULL, PCMCIA_VENDOR_ ## v, \ 379 PCCARD_P(v, p), PCCARD_C(v, p) } 380#define PCMCIA_CARD2(v1, p1, p2) \ 381 { NULL, PCMCIA_VENDOR_ ## v1, PCCARD_P(v1, p1), \ 382 PCMCIA_CIS_ ## p2} 383#else 384#define PCMCIA_CARD_D(v, p, f) { PCCARD_S(v, p), PCMCIA_VENDOR_ ## v, \ 385 PCCARD_P(v, p), PCCARD_C(v, p) } 386#define PCMCIA_CARD2_D(v1, p1, p2, f) \ 387 { PCMCIA_STR_ ## p2, PCMCIA_VENDOR_ ## v1, PCCARD_P(v1, p1), \ 388 PCMCIA_CIS_ ## p2} 389#define PCMCIA_CARD(v, p, f) { NULL, PCMCIA_VENDOR_ ## v, \ 390 PCCARD_P(v, p), PCCARD_C(v, p) } 391#define PCMCIA_CARD2(v1, p1, p2, f) \ 392 { NULL, PCMCIA_VENDOR_ ## v1, PCCARD_P(v1, p1), \ 393 PCMCIA_CIS_ ## p2} 394#endif 395