pcmcia_cis.c revision 1.46
1/* $NetBSD: pcmcia_cis.c,v 1.46 2006/04/08 20:55:22 christos Exp $ */ 2 3/* 4 * Copyright (c) 1997 Marc Horowitz. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. All advertising materials mentioning features or use of this software 15 * must display the following acknowledgement: 16 * This product includes software developed by Marc Horowitz. 17 * 4. The name of the author may not be used to endorse or promote products 18 * derived from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32#include <sys/cdefs.h> 33__KERNEL_RCSID(0, "$NetBSD: pcmcia_cis.c,v 1.46 2006/04/08 20:55:22 christos Exp $"); 34 35#include <sys/param.h> 36#include <sys/systm.h> 37#include <sys/device.h> 38#include <sys/malloc.h> 39 40#include <dev/pcmcia/pcmciareg.h> 41#include <dev/pcmcia/pcmciachip.h> 42#include <dev/pcmcia/pcmciavar.h> 43 44#ifdef PCMCIACISDEBUG 45int pcmciacis_debug = 0; 46#define DPRINTF(arg) if (pcmciacis_debug) printf arg 47#else 48#define DPRINTF(arg) 49#endif 50 51#define PCMCIA_CIS_SIZE 1024 52 53struct cis_state { 54 int count; 55 int gotmfc; 56 struct pcmcia_config_entry temp_cfe; 57 struct pcmcia_config_entry *default_cfe; 58 struct pcmcia_card *card; 59 struct pcmcia_function *pf; 60}; 61 62int pcmcia_parse_cis_tuple(struct pcmcia_tuple *, void *); 63static void create_pf(struct cis_state *); 64 65static void decode_end(struct pcmcia_tuple *, struct cis_state *); 66static void decode_longlink_mfc(struct pcmcia_tuple *, struct cis_state *); 67static void decode_device(struct pcmcia_tuple *, struct cis_state *); 68static void decode_vers_1(struct pcmcia_tuple *, struct cis_state *); 69static void decode_manfid(struct pcmcia_tuple *, struct cis_state *); 70static void decode_funcid(struct pcmcia_tuple *, struct cis_state *); 71static void decode_funce(struct pcmcia_tuple *, struct cis_state *); 72static void decode_config(struct pcmcia_tuple *, struct cis_state *); 73static void decode_cftable_entry(struct pcmcia_tuple *, struct cis_state *); 74 75 76static void 77create_pf(struct cis_state *state) 78{ 79 state->pf = malloc(sizeof(*state->pf), M_DEVBUF, M_NOWAIT|M_ZERO); 80 state->pf->number = state->count++; 81 state->pf->last_config_index = -1; 82 SIMPLEQ_INIT(&state->pf->cfe_head); 83 SIMPLEQ_INSERT_TAIL(&state->card->pf_head, state->pf, pf_list); 84} 85 86void 87pcmcia_free_pf(struct pcmcia_function_head *pfhead) 88{ 89 struct pcmcia_function *pf, *npf; 90 struct pcmcia_config_entry *cfe, *ncfe; 91 92 for (pf = SIMPLEQ_FIRST(pfhead); pf != NULL; pf = npf) { 93 npf = SIMPLEQ_NEXT(pf, pf_list); 94 for (cfe = SIMPLEQ_FIRST(&pf->cfe_head); cfe != NULL; 95 cfe = ncfe) { 96 ncfe = SIMPLEQ_NEXT(cfe, cfe_list); 97 free(cfe, M_DEVBUF); 98 } 99 free(pf, M_DEVBUF); 100 } 101 102 SIMPLEQ_INIT(pfhead); 103} 104 105void 106pcmcia_read_cis(sc) 107 struct pcmcia_softc *sc; 108{ 109 struct cis_state state; 110 111 memset(&state, 0, sizeof state); 112 113 state.card = &sc->card; 114 115 state.card->error = 0; 116 state.card->cis1_major = -1; 117 state.card->cis1_minor = -1; 118 state.card->cis1_info[0] = NULL; 119 state.card->cis1_info[1] = NULL; 120 state.card->cis1_info[2] = NULL; 121 state.card->cis1_info[3] = NULL; 122 state.card->manufacturer = PCMCIA_VENDOR_INVALID; 123 state.card->product = PCMCIA_PRODUCT_INVALID; 124 SIMPLEQ_INIT(&state.card->pf_head); 125 126 state.pf = NULL; 127 128 if (pcmcia_scan_cis((struct device *)sc, pcmcia_parse_cis_tuple, 129 &state) == -1) 130 state.card->error++; 131} 132 133int 134pcmcia_scan_cis(dev, fct, arg) 135 struct device *dev; 136 int (*fct)(struct pcmcia_tuple *, void *); 137 void *arg; 138{ 139 struct pcmcia_softc *sc = (struct pcmcia_softc *) dev; 140 pcmcia_chipset_tag_t pct; 141 pcmcia_chipset_handle_t pch; 142 int window; 143 struct pcmcia_mem_handle pcmh; 144 struct pcmcia_tuple tuple; 145 int longlink_present; 146 int longlink_common; 147 u_long longlink_addr; 148 int mfc_count; 149 int mfc_index; 150 struct { 151 int common; 152 u_long addr; 153 } mfc[256 / 5]; 154 int ret; 155 156 ret = 0; 157 158 pct = sc->pct; 159 pch = sc->pch; 160 161 /* allocate some memory */ 162 163 if (pcmcia_chip_mem_alloc(pct, pch, PCMCIA_CIS_SIZE, &pcmh)) { 164#ifdef DIAGNOSTIC 165 printf("%s: can't alloc memory to read attributes\n", 166 sc->dev.dv_xname); 167#endif 168 return -1; 169 } 170 /* initialize state for the primary tuple chain */ 171 if (pcmcia_chip_mem_map(pct, pch, PCMCIA_MEM_ATTR, 0, 172 PCMCIA_CIS_SIZE, &pcmh, &tuple.ptr, &window)) { 173 pcmcia_chip_mem_free(pct, pch, &pcmh); 174#ifdef DIAGNOSTIC 175 printf("%s: can't map memory to read attributes\n", 176 sc->dev.dv_xname); 177#endif 178 return -1; 179 } 180 tuple.memt = pcmh.memt; 181 tuple.memh = pcmh.memh; 182 183 DPRINTF(("cis mem map %x\n", (unsigned int) tuple.memh)); 184 185 tuple.mult = 2; 186 187 longlink_present = 1; 188 longlink_common = 1; 189 longlink_addr = 0; 190 191 mfc_count = 0; 192 mfc_index = 0; 193 194 DPRINTF(("%s: CIS tuple chain:\n", sc->dev.dv_xname)); 195 196 while (1) { 197 DELAY(1000); 198 199 while (1) { 200 /* 201 * Perform boundary check for insane cards. 202 * If CIS is too long, simulate CIS end. 203 * (This check may not be sufficient for 204 * malicious cards.) 205 */ 206 if (tuple.mult * tuple.ptr >= PCMCIA_CIS_SIZE - 1 207 - 32 /* ad hoc value */ ) { 208 DPRINTF(("CISTPL_END (too long CIS)\n")); 209 tuple.code = PCMCIA_CISTPL_END; 210 goto cis_end; 211 } 212 213 /* get the tuple code */ 214 215 tuple.code = pcmcia_cis_read_1(&tuple, tuple.ptr); 216 217 /* two special-case tuples */ 218 219 if (tuple.code == PCMCIA_CISTPL_NULL) { 220 DPRINTF((" 00\nCISTPL_NONE\n")); 221 tuple.ptr++; 222 continue; 223 } else if (tuple.code == PCMCIA_CISTPL_END) { 224 DPRINTF((" ff\nCISTPL_END\n")); 225 cis_end: 226 /* Call the function for the END tuple, since 227 the CIS semantics depend on it */ 228 if ((*fct) (&tuple, arg)) { 229 pcmcia_chip_mem_unmap(pct, pch, 230 window); 231 ret = 1; 232 goto done; 233 } 234 tuple.ptr++; 235 break; 236 } 237 238 /* now all the normal tuples */ 239 240 tuple.length = pcmcia_cis_read_1(&tuple, tuple.ptr + 1); 241#ifdef PCMCIACISDEBUG 242 /* print the tuple */ 243 { 244 int i; 245 246 DPRINTF((" %02x %02x", tuple.code, 247 tuple.length)); 248 249 for (i = 0; i < tuple.length; i++) { 250 DPRINTF((" %02x", 251 pcmcia_tuple_read_1(&tuple, i))); 252 if ((i % 16) == 13) 253 DPRINTF(("\n")); 254 } 255 if ((i % 16) != 14) 256 DPRINTF(("\n")); 257 } 258#endif 259 switch (tuple.code) { 260 case PCMCIA_CISTPL_LONGLINK_A: 261 case PCMCIA_CISTPL_LONGLINK_C: 262 if (tuple.length < 4) { 263 DPRINTF(("CISTPL_LONGLINK_%s too " 264 "short %d\n", 265 longlink_common ? "C" : "A", 266 tuple.length)); 267 break; 268 } 269 longlink_present = 1; 270 longlink_common = (tuple.code == 271 PCMCIA_CISTPL_LONGLINK_C) ? 1 : 0; 272 longlink_addr = pcmcia_tuple_read_4(&tuple, 0); 273 DPRINTF(("CISTPL_LONGLINK_%s %lx\n", 274 longlink_common ? "C" : "A", 275 longlink_addr)); 276 break; 277 case PCMCIA_CISTPL_NO_LINK: 278 longlink_present = 0; 279 DPRINTF(("CISTPL_NO_LINK\n")); 280 break; 281 case PCMCIA_CISTPL_CHECKSUM: 282 if (tuple.length < 5) { 283 DPRINTF(("CISTPL_CHECKSUM too " 284 "short %d\n", tuple.length)); 285 break; 286 } { 287 int16_t offset; 288 u_long addr, length; 289 u_int cksum, sum; 290 int i; 291 292 *((u_int16_t *) & offset) = 293 pcmcia_tuple_read_2(&tuple, 0); 294 length = pcmcia_tuple_read_2(&tuple, 2); 295 cksum = pcmcia_tuple_read_1(&tuple, 4); 296 297 addr = tuple.ptr + offset; 298 299 DPRINTF(("CISTPL_CHECKSUM addr=%lx " 300 "len=%lx cksum=%x", 301 addr, length, cksum)); 302 303 /* 304 * XXX do more work to deal with 305 * distant regions 306 */ 307 if ((addr >= PCMCIA_CIS_SIZE) || 308 ((addr + length) < 0) || 309 ((addr + length) >= 310 PCMCIA_CIS_SIZE)) { 311 DPRINTF((" skipped, " 312 "too distant\n")); 313 break; 314 } 315 sum = 0; 316 for (i = 0; i < length; i++) 317 sum += 318 bus_space_read_1(tuple.memt, 319 tuple.memh, 320 addr + tuple.mult * i); 321 if (cksum != (sum & 0xff)) { 322 DPRINTF((" failed sum=%x\n", 323 sum)); 324 printf("%s: CIS checksum " 325 "failed\n", 326 sc->dev.dv_xname); 327#if 0 328 /* 329 * XXX Some working cards have 330 * XXX bad checksums!! 331 */ 332 ret = -1; 333#endif 334 } else { 335 DPRINTF((" ok\n")); 336 } 337 } 338 break; 339 case PCMCIA_CISTPL_LONGLINK_MFC: 340 if (tuple.length < 1) { 341 DPRINTF(("CISTPL_LONGLINK_MFC too " 342 "short %d\n", tuple.length)); 343 break; 344 } 345 if (((tuple.length - 1) % 5) != 0) { 346 DPRINTF(("CISTPL_LONGLINK_MFC bogus " 347 "length %d\n", tuple.length)); 348 break; 349 } 350 /* 351 * this is kind of ad hoc, as I don't have 352 * any real documentation 353 */ 354 { 355 int i, tmp_count; 356 357 /* 358 * put count into tmp var so that 359 * if we have to bail (because it's 360 * a bogus count) it won't be 361 * remembered for later use. 362 */ 363 tmp_count = 364 pcmcia_tuple_read_1(&tuple, 0); 365 DPRINTF(("CISTPL_LONGLINK_MFC %d", 366 tmp_count)); 367 368 /* 369 * make _sure_ it's the right size; 370 * if too short, it may be a weird 371 * (unknown/undefined) format 372 */ 373 if (tuple.length != (tmp_count*5 + 1)) { 374 DPRINTF((" bogus length %d\n", 375 tuple.length)); 376 break; 377 } 378 379#ifdef PCMCIACISDEBUG /* maybe enable all the time? */ 380 /* 381 * sanity check for a programming 382 * error which is difficult to find 383 * when debugging. 384 */ 385 if (tmp_count > 386 howmany(sizeof mfc, sizeof mfc[0])) 387 panic("CISTPL_LONGLINK_MFC mfc " 388 "count would blow stack"); 389#endif 390 391 mfc_count = tmp_count; 392 for (i = 0; i < mfc_count; i++) { 393 mfc[i].common = 394 (pcmcia_tuple_read_1(&tuple, 395 1 + 5 * i) == 396 PCMCIA_MFC_MEM_COMMON) ? 397 1 : 0; 398 mfc[i].addr = 399 pcmcia_tuple_read_4(&tuple, 400 1 + 5 * i + 1); 401 DPRINTF((" %s:%lx", 402 mfc[i].common ? "common" : 403 "attr", mfc[i].addr)); 404 } 405 DPRINTF(("\n")); 406 } 407 /* 408 * for LONGLINK_MFC, fall through to the 409 * function. This tuple has structural and 410 * semantic content. 411 */ 412 default: 413 { 414 if ((*fct) (&tuple, arg)) { 415 pcmcia_chip_mem_unmap(pct, 416 pch, window); 417 ret = 1; 418 goto done; 419 } 420 } 421 break; 422 } /* switch */ 423 /* skip to the next tuple */ 424 tuple.ptr += 2 + tuple.length; 425 } 426 427 /* 428 * the chain is done. Clean up and move onto the next one, 429 * if any. The loop is here in the case that there is an MFC 430 * card with no longlink (which defaults to existing, == 0). 431 * In general, this means that if one pointer fails, it will 432 * try the next one, instead of just bailing. 433 */ 434 435 while (1) { 436 pcmcia_chip_mem_unmap(pct, pch, window); 437 438 if (longlink_present) { 439 /* 440 * if the longlink is to attribute memory, 441 * then it is unindexed. That is, if the 442 * link value is 0x100, then the actual 443 * memory address is 0x200. This means that 444 * we need to multiply by 2 before calling 445 * mem_map, and then divide the resulting ptr 446 * by 2 after. 447 */ 448 449 if (!longlink_common) 450 longlink_addr *= 2; 451 452 pcmcia_chip_mem_map(pct, pch, longlink_common ? 453 (PCMCIA_WIDTH_MEM8 | PCMCIA_MEM_COMMON) : 454 PCMCIA_MEM_ATTR, 455 longlink_addr, PCMCIA_CIS_SIZE, 456 &pcmh, &tuple.ptr, &window); 457 458 tuple.memt = pcmh.memt; 459 tuple.memh = pcmh.memh; 460 461 if (!longlink_common) 462 tuple.ptr /= 2; 463 464 DPRINTF(("cis mem map %x\n", 465 (unsigned int) tuple.memh)); 466 467 tuple.mult = longlink_common ? 1 : 2; 468 longlink_present = 0; 469 longlink_common = 1; 470 longlink_addr = 0; 471 } else if (mfc_count && (mfc_index < mfc_count)) { 472 if (!mfc[mfc_index].common) 473 mfc[mfc_index].addr *= 2; 474 475 pcmcia_chip_mem_map(pct, pch, 476 mfc[mfc_index].common ? 477 (PCMCIA_WIDTH_MEM8 | PCMCIA_MEM_COMMON) : 478 PCMCIA_MEM_ATTR, 479 mfc[mfc_index].addr, PCMCIA_CIS_SIZE, 480 &pcmh, &tuple.ptr, &window); 481 482 if (!mfc[mfc_index].common) 483 tuple.ptr /= 2; 484 485 DPRINTF(("cis mem map %x\n", 486 (unsigned int) tuple.memh)); 487 488 /* set parse state, and point at the next one */ 489 490 tuple.mult = mfc[mfc_index].common ? 1 : 2; 491 492 mfc_index++; 493 } else { 494 goto done; 495 } 496 497 /* make sure that the link is valid */ 498 tuple.code = pcmcia_cis_read_1(&tuple, tuple.ptr); 499 if (tuple.code != PCMCIA_CISTPL_LINKTARGET) { 500 DPRINTF(("CISTPL_LINKTARGET expected, " 501 "code %02x observed\n", tuple.code)); 502 continue; 503 } 504 tuple.length = pcmcia_cis_read_1(&tuple, tuple.ptr + 1); 505 if (tuple.length < 3) { 506 DPRINTF(("CISTPL_LINKTARGET too short %d\n", 507 tuple.length)); 508 continue; 509 } 510 if ((pcmcia_tuple_read_1(&tuple, 0) != 'C') || 511 (pcmcia_tuple_read_1(&tuple, 1) != 'I') || 512 (pcmcia_tuple_read_1(&tuple, 2) != 'S')) { 513 DPRINTF(("CISTPL_LINKTARGET magic " 514 "%02x%02x%02x incorrect\n", 515 pcmcia_tuple_read_1(&tuple, 0), 516 pcmcia_tuple_read_1(&tuple, 1), 517 pcmcia_tuple_read_1(&tuple, 2))); 518 continue; 519 } 520 tuple.ptr += 2 + tuple.length; 521 522 break; 523 } 524 } 525 526 pcmcia_chip_mem_unmap(pct, pch, window); 527 528done: 529 /* Last, free the allocated memory block */ 530 pcmcia_chip_mem_free(pct, pch, &pcmh); 531 532 return (ret); 533} 534 535/* XXX this is incredibly verbose. Not sure what trt is */ 536 537void 538pcmcia_print_cis(sc) 539 struct pcmcia_softc *sc; 540{ 541 struct pcmcia_card *card = &sc->card; 542 struct pcmcia_function *pf; 543 struct pcmcia_config_entry *cfe; 544 int i; 545 546 printf("%s: CIS version ", sc->dev.dv_xname); 547 if (card->cis1_major == 4) { 548 if (card->cis1_minor == 0) 549 printf("PCMCIA 1.0\n"); 550 else if (card->cis1_minor == 1) 551 printf("PCMCIA 2.0 or 2.1\n"); 552 } else if (card->cis1_major >= 5) 553 printf("PC Card Standard %d.%d\n", card->cis1_major, card->cis1_minor); 554 else 555 printf("unknown (major=%d, minor=%d)\n", 556 card->cis1_major, card->cis1_minor); 557 558 printf("%s: CIS info: ", sc->dev.dv_xname); 559 for (i = 0; i < 4; i++) { 560 if (card->cis1_info[i] == NULL) 561 break; 562 if (i) 563 printf(", "); 564 printf("%s", card->cis1_info[i]); 565 } 566 printf("\n"); 567 568 printf("%s: Manufacturer code 0x%x, product 0x%x\n", 569 sc->dev.dv_xname, card->manufacturer, card->product); 570 571 SIMPLEQ_FOREACH(pf, &card->pf_head, pf_list) { 572 printf("%s: function %d: ", sc->dev.dv_xname, pf->number); 573 574 switch (pf->function) { 575 case PCMCIA_FUNCTION_UNSPEC: 576 printf("unspecified"); 577 break; 578 case PCMCIA_FUNCTION_MULTIFUNCTION: 579 printf("multi-function"); 580 break; 581 case PCMCIA_FUNCTION_MEMORY: 582 printf("memory"); 583 break; 584 case PCMCIA_FUNCTION_SERIAL: 585 printf("serial port"); 586 break; 587 case PCMCIA_FUNCTION_PARALLEL: 588 printf("parallel port"); 589 break; 590 case PCMCIA_FUNCTION_DISK: 591 printf("fixed disk"); 592 switch (pf->pf_funce_disk_interface) { 593 case PCMCIA_TPLFE_DDI_PCCARD_ATA: 594 printf("(ata)"); 595 break; 596 default: 597 break; 598 } 599 break; 600 case PCMCIA_FUNCTION_VIDEO: 601 printf("video adapter"); 602 break; 603 case PCMCIA_FUNCTION_NETWORK: 604 printf("network adapter"); 605 break; 606 case PCMCIA_FUNCTION_AIMS: 607 printf("auto incrementing mass storage"); 608 break; 609 case PCMCIA_FUNCTION_SCSI: 610 printf("SCSI bridge"); 611 break; 612 case PCMCIA_FUNCTION_SECURITY: 613 printf("Security services"); 614 break; 615 case PCMCIA_FUNCTION_INSTRUMENT: 616 printf("Instrument"); 617 break; 618 default: 619 printf("unknown (%d)", pf->function); 620 break; 621 } 622 623 printf(", ccr addr %lx mask %lx\n", pf->ccr_base, pf->ccr_mask); 624 625 SIMPLEQ_FOREACH(cfe, &pf->cfe_head, cfe_list) { 626 printf("%s: function %d, config table entry %d: ", 627 sc->dev.dv_xname, pf->number, cfe->number); 628 629 switch (cfe->iftype) { 630 case PCMCIA_IFTYPE_MEMORY: 631 printf("memory card"); 632 break; 633 case PCMCIA_IFTYPE_IO: 634 printf("I/O card"); 635 break; 636 default: 637 printf("card type unknown"); 638 break; 639 } 640 641 printf("; irq mask %x", cfe->irqmask); 642 643 if (cfe->num_iospace) { 644 printf("; iomask %lx, iospace", cfe->iomask); 645 646 for (i = 0; i < cfe->num_iospace; i++) { 647 printf(" %lx", cfe->iospace[i].start); 648 if (cfe->iospace[i].length) 649 printf("-%lx", 650 cfe->iospace[i].start + 651 cfe->iospace[i].length - 1); 652 } 653 } 654 if (cfe->num_memspace) { 655 printf("; memspace"); 656 657 for (i = 0; i < cfe->num_memspace; i++) { 658 printf(" %lx", 659 cfe->memspace[i].cardaddr); 660 if (cfe->memspace[i].length) 661 printf("-%lx", 662 cfe->memspace[i].cardaddr + 663 cfe->memspace[i].length - 1); 664 if (cfe->memspace[i].hostaddr) 665 printf("@%lx", 666 cfe->memspace[i].hostaddr); 667 } 668 } 669 if (cfe->maxtwins) 670 printf("; maxtwins %d", cfe->maxtwins); 671 672 printf(";"); 673 674 if (cfe->flags & PCMCIA_CFE_MWAIT_REQUIRED) 675 printf(" mwait_required"); 676 if (cfe->flags & PCMCIA_CFE_RDYBSY_ACTIVE) 677 printf(" rdybsy_active"); 678 if (cfe->flags & PCMCIA_CFE_WP_ACTIVE) 679 printf(" wp_active"); 680 if (cfe->flags & PCMCIA_CFE_BVD_ACTIVE) 681 printf(" bvd_active"); 682 if (cfe->flags & PCMCIA_CFE_IO8) 683 printf(" io8"); 684 if (cfe->flags & PCMCIA_CFE_IO16) 685 printf(" io16"); 686 if (cfe->flags & PCMCIA_CFE_IRQSHARE) 687 printf(" irqshare"); 688 if (cfe->flags & PCMCIA_CFE_IRQPULSE) 689 printf(" irqpulse"); 690 if (cfe->flags & PCMCIA_CFE_IRQLEVEL) 691 printf(" irqlevel"); 692 if (cfe->flags & PCMCIA_CFE_POWERDOWN) 693 printf(" powerdown"); 694 if (cfe->flags & PCMCIA_CFE_READONLY) 695 printf(" readonly"); 696 if (cfe->flags & PCMCIA_CFE_AUDIO) 697 printf(" audio"); 698 699 printf("\n"); 700 } 701 } 702 703 if (card->error) 704 printf("%s: %d errors found while parsing CIS\n", 705 sc->dev.dv_xname, card->error); 706} 707 708int 709pcmcia_parse_cis_tuple(tuple, arg) 710 struct pcmcia_tuple *tuple; 711 void *arg; 712{ 713 struct cis_state *state = arg; 714 715 switch (tuple->code) { 716 case PCMCIA_CISTPL_END: 717 decode_end(tuple, state); 718 break; 719 720 case PCMCIA_CISTPL_LONGLINK_MFC: 721 decode_longlink_mfc(tuple, state); 722 break; 723 724 case PCMCIA_CISTPL_DEVICE: 725 case PCMCIA_CISTPL_DEVICE_A: 726 decode_device(tuple, state); 727 break; 728 729 case PCMCIA_CISTPL_VERS_1: 730 decode_vers_1(tuple, state); 731 break; 732 733 case PCMCIA_CISTPL_MANFID: 734 decode_manfid(tuple, state); 735 break; 736 737 case PCMCIA_CISTPL_FUNCID: 738 decode_funcid(tuple, state); 739 break; 740 741 case PCMCIA_CISTPL_FUNCE: 742 decode_funce(tuple, state); 743 break; 744 745 case PCMCIA_CISTPL_CONFIG: 746 decode_config(tuple, state); 747 break; 748 749 case PCMCIA_CISTPL_CFTABLE_ENTRY: 750 decode_cftable_entry(tuple, state); 751 break; 752 default: 753 DPRINTF(("unhandled CISTPL %x\n", tuple->code)); 754 break; 755 } 756 757 return (0); 758} 759 760static void 761decode_end(struct pcmcia_tuple *tuple, struct cis_state *state) 762{ 763 /* if we've seen a LONGLINK_MFC, and this is the first 764 * END after it, reset the function list. 765 * 766 * XXX This might also be the right place to start a 767 * new function, but that assumes that a function 768 * definition never crosses any longlink, and I'm not 769 * sure about that. This is probably safe for MFC 770 * cards, but what we have now isn't broken, so I'd 771 * rather not change it. 772 */ 773 if (state->gotmfc == 1) { 774 state->gotmfc = 2; 775 state->count = 0; 776 state->pf = NULL; 777 778 pcmcia_free_pf(&state->card->pf_head); 779 } 780} 781 782static void 783decode_longlink_mfc(struct pcmcia_tuple *tuple, struct cis_state *state) 784{ 785 /* 786 * this tuple's structure was dealt with in scan_cis. here, 787 * record the fact that the MFC tuple was seen, so that 788 * functions declared before the MFC link can be cleaned 789 * up. 790 */ 791 if (state->gotmfc == 0) { 792 state->gotmfc = 1; 793 } else { 794 DPRINTF(("got LONGLINK_MFC again!")); 795 } 796} 797 798static void 799decode_device(struct pcmcia_tuple *tuple, struct cis_state *state) 800{ 801#ifdef PCMCIACISDEBUG 802 u_int reg, dtype, dspeed; 803 804 reg = pcmcia_tuple_read_1(tuple, 0); 805 dtype = reg & PCMCIA_DTYPE_MASK; 806 dspeed = reg & PCMCIA_DSPEED_MASK; 807 808 DPRINTF(("CISTPL_DEVICE%s type=", 809 (tuple->code == PCMCIA_CISTPL_DEVICE) ? "" : "_A")); 810 switch (dtype) { 811 case PCMCIA_DTYPE_NULL: 812 DPRINTF(("null")); 813 break; 814 case PCMCIA_DTYPE_ROM: 815 DPRINTF(("rom")); 816 break; 817 case PCMCIA_DTYPE_OTPROM: 818 DPRINTF(("otprom")); 819 break; 820 case PCMCIA_DTYPE_EPROM: 821 DPRINTF(("eprom")); 822 break; 823 case PCMCIA_DTYPE_EEPROM: 824 DPRINTF(("eeprom")); 825 break; 826 case PCMCIA_DTYPE_FLASH: 827 DPRINTF(("flash")); 828 break; 829 case PCMCIA_DTYPE_SRAM: 830 DPRINTF(("sram")); 831 break; 832 case PCMCIA_DTYPE_DRAM: 833 DPRINTF(("dram")); 834 break; 835 case PCMCIA_DTYPE_FUNCSPEC: 836 DPRINTF(("funcspec")); 837 break; 838 case PCMCIA_DTYPE_EXTEND: 839 DPRINTF(("extend")); 840 break; 841 default: 842 DPRINTF(("reserved")); 843 break; 844 } 845 DPRINTF((" speed=")); 846 switch (dspeed) { 847 case PCMCIA_DSPEED_NULL: 848 DPRINTF(("null")); 849 break; 850 case PCMCIA_DSPEED_250NS: 851 DPRINTF(("250ns")); 852 break; 853 case PCMCIA_DSPEED_200NS: 854 DPRINTF(("200ns")); 855 break; 856 case PCMCIA_DSPEED_150NS: 857 DPRINTF(("150ns")); 858 break; 859 case PCMCIA_DSPEED_100NS: 860 DPRINTF(("100ns")); 861 break; 862 case PCMCIA_DSPEED_EXT: 863 DPRINTF(("ext")); 864 break; 865 default: 866 DPRINTF(("reserved")); 867 break; 868 } 869 DPRINTF(("\n")); 870#endif 871} 872 873static void 874decode_vers_1(struct pcmcia_tuple *tuple, struct cis_state *state) 875{ 876 int start, i, ch, count; 877 878 if (tuple->length < 6) { 879 DPRINTF(("CISTPL_VERS_1 too short %d\n", 880 tuple->length)); 881 return; 882 } 883 state->card->cis1_major = pcmcia_tuple_read_1(tuple, 0); 884 state->card->cis1_minor = pcmcia_tuple_read_1(tuple, 1); 885 886 for (count = 0, start = 0, i = 0; 887 (count < 4) && ((i + 4) < 256); i++) { 888 ch = pcmcia_tuple_read_1(tuple, 2 + i); 889 if (ch == 0xff) { 890 if (i > start) { 891 state->card->cis1_info_buf[i] = 0; 892 state->card->cis1_info[count] = 893 state->card->cis1_info_buf + start; 894 } 895 break; 896 } 897 state->card->cis1_info_buf[i] = ch; 898 if (ch == 0) { 899 state->card->cis1_info[count] = 900 state->card->cis1_info_buf + start; 901 start = i + 1; 902 count++; 903 } 904 } 905 DPRINTF(("CISTPL_VERS_1\n")); 906} 907 908static void 909decode_manfid(struct pcmcia_tuple *tuple, struct cis_state *state) 910{ 911 if (tuple->length < 4) { 912 DPRINTF(("CISTPL_MANFID too short %d\n", 913 tuple->length)); 914 return; 915 } 916 state->card->manufacturer = pcmcia_tuple_read_2(tuple, 0); 917 state->card->product = pcmcia_tuple_read_2(tuple, 2); 918 DPRINTF(("CISTPL_MANFID\n")); 919} 920 921static void 922decode_funcid(struct pcmcia_tuple *tuple, struct cis_state *state) 923{ 924 if (tuple->length < 1) { 925 DPRINTF(("CISTPL_FUNCID too short %d\n", 926 tuple->length)); 927 return; 928 } 929 if (state->pf) { 930 if (state->pf->function == PCMCIA_FUNCTION_UNSPEC) { 931 /* 932 * This looks like a opportunistic function 933 * created by a CONFIG tuple. Just keep it. 934 */ 935 } else { 936 /* 937 * A function is being defined, end it. 938 */ 939 state->pf = NULL; 940 } 941 } 942 if (state->pf == NULL) 943 create_pf(state); 944 state->pf->function = pcmcia_tuple_read_1(tuple, 0); 945 946 DPRINTF(("CISTPL_FUNCID\n")); 947} 948 949static void 950decode_funce(struct pcmcia_tuple *tuple, struct cis_state *state) 951{ 952 struct pcmcia_function *pf = state->pf; 953 int type = pcmcia_tuple_read_1(tuple, 0); 954 955 if (state->pf == NULL || state->pf->function <= 0) { 956 DPRINTF(("CISTPL_FUNCE is not followed by " 957 "valid CISTPL_FUNCID\n")); 958 return; 959 } 960 if (tuple->length < 2) 961 return; 962 switch (pf->function) { 963 case PCMCIA_FUNCTION_DISK: 964 if (type == PCMCIA_TPLFE_TYPE_DISK_DEVICE_INTERFACE) { 965 pf->pf_funce_disk_interface 966 = pcmcia_tuple_read_1(tuple, 1); 967 } 968 break; 969 case PCMCIA_FUNCTION_NETWORK: 970 if (type == PCMCIA_TPLFE_TYPE_LAN_NID) { 971 int i; 972 int len = pcmcia_tuple_read_1(tuple, 1); 973 if (tuple->length < 2 + len || len > 8) { 974 /* tuple length not enough or nid too long */ 975 break; 976 } 977 for (i = 0; i < len; ++i) { 978 pf->pf_funce_lan_nid[i] 979 = pcmcia_tuple_read_1(tuple, 2 + i); 980 } 981 pf->pf_funce_lan_nidlen = len; 982 } 983 break; 984 default: 985 break; 986 } 987 988 return; 989} 990 991static void 992decode_config(struct pcmcia_tuple *tuple, struct cis_state *state) 993{ 994 u_int reg, rasz, rmsz, rfsz; 995 int i; 996 /* most of these are educated guesses */ 997 static const struct pcmcia_config_entry init_cfe = { 998 -1, PCMCIA_CFE_RDYBSY_ACTIVE | PCMCIA_CFE_WP_ACTIVE | 999 PCMCIA_CFE_BVD_ACTIVE, PCMCIA_IFTYPE_MEMORY, 1000 }; 1001 1002 if (tuple->length < 3) { 1003 DPRINTF(("CISTPL_CONFIG too short %d\n", tuple->length)); 1004 return; 1005 } 1006 reg = pcmcia_tuple_read_1(tuple, 0); 1007 rasz = 1 + ((reg & PCMCIA_TPCC_RASZ_MASK) >> 1008 PCMCIA_TPCC_RASZ_SHIFT); 1009 rmsz = 1 + ((reg & PCMCIA_TPCC_RMSZ_MASK) >> 1010 PCMCIA_TPCC_RMSZ_SHIFT); 1011 rfsz = ((reg & PCMCIA_TPCC_RFSZ_MASK) >> 1012 PCMCIA_TPCC_RFSZ_SHIFT); 1013 1014 if (tuple->length < (rasz + rmsz + rfsz)) { 1015 DPRINTF(("CISTPL_CONFIG (%d,%d,%d) too short %d\n", 1016 rasz, rmsz, rfsz, tuple->length)); 1017 return; 1018 } 1019 if (state->pf == NULL) { 1020 create_pf(state); 1021 state->pf->function = PCMCIA_FUNCTION_UNSPEC; 1022 } 1023 state->pf->last_config_index = 1024 pcmcia_tuple_read_1(tuple, 1); 1025 1026 state->pf->ccr_base = 0; 1027 for (i = 0; i < rasz; i++) 1028 state->pf->ccr_base |= ((pcmcia_tuple_read_1(tuple, 2 + i)) << 1029 (i * 8)); 1030 1031 state->pf->ccr_mask = 0; 1032 for (i = 0; i < rmsz; i++) 1033 state->pf->ccr_mask |= ((pcmcia_tuple_read_1(tuple, 1034 2 + rasz + i)) << (i * 8)); 1035 1036 /* skip the reserved area and subtuples */ 1037 1038 /* reset the default cfe for each cfe list */ 1039 state->temp_cfe = init_cfe; 1040 state->default_cfe = &state->temp_cfe; 1041 DPRINTF(("CISTPL_CONFIG\n")); 1042} 1043 1044static void 1045decode_cftable_entry(struct pcmcia_tuple *tuple, struct cis_state *state) 1046{ 1047 int idx, i, j; 1048 u_int reg, reg2; 1049 u_int intface, def, num; 1050 u_int power, timing, iospace, irq, memspace, misc; 1051 struct pcmcia_config_entry *cfe; 1052 1053 idx = 0; 1054 1055 reg = pcmcia_tuple_read_1(tuple, idx); 1056 idx++; 1057 intface = reg & PCMCIA_TPCE_INDX_INTFACE; 1058 def = reg & PCMCIA_TPCE_INDX_DEFAULT; 1059 num = reg & PCMCIA_TPCE_INDX_NUM_MASK; 1060 1061 /* 1062 * this is a little messy. Some cards have only a 1063 * cfentry with the default bit set. So, as we go 1064 * through the list, we add new indexes to the queue, 1065 * and keep a pointer to the last one with the 1066 * default bit set. if we see a record with the same 1067 * index, as the default, we stash the default and 1068 * replace the queue entry. otherwise, we just add 1069 * new entries to the queue, pointing the default ptr 1070 * at them if the default bit is set. if we get to 1071 * the end with the default pointer pointing at a 1072 * record which hasn't had a matching index, that's 1073 * ok; it just becomes a cfentry like any other. 1074 */ 1075 1076 /* 1077 * if the index in the cis differs from the default 1078 * cis, create new entry in the queue and start it 1079 * with the current default 1080 */ 1081 if (state->default_cfe == NULL) { 1082 DPRINTF(("CISTPL_CFTABLE_ENTRY with no " 1083 "default\n")); 1084 return; 1085 } 1086 if (num != state->default_cfe->number) { 1087 cfe = malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT); 1088 if (cfe == NULL) { 1089 printf("Cannot allocate cfe entry\n"); 1090 return; 1091 } 1092 1093 *cfe = *state->default_cfe; 1094 1095 SIMPLEQ_INSERT_TAIL(&state->pf->cfe_head, cfe, cfe_list); 1096 1097 cfe->number = num; 1098 1099 /* 1100 * if the default bit is set in the cis, then 1101 * point the new default at whatever is being 1102 * filled in 1103 */ 1104 if (def) 1105 state->default_cfe = cfe; 1106 } else { 1107 /* 1108 * the cis index matches the default index, 1109 * fill in the default cfentry. It is 1110 * assumed that the cfdefault index is in the 1111 * queue. For it to be otherwise, the cis 1112 * index would have to be -1 (initial 1113 * condition) which is not possible, or there 1114 * would have to be a preceding cis entry 1115 * which had the same cis index and had the 1116 * default bit unset. Neither condition 1117 * should happen. If it does, this cfentry 1118 * is lost (written into temp space), which 1119 * is an acceptable failure mode. 1120 */ 1121 1122 cfe = state->default_cfe; 1123 1124 /* 1125 * if the cis entry does not have the default 1126 * bit set, copy the default out of the way 1127 * first. 1128 */ 1129 if (!def) { 1130 state->temp_cfe = *state->default_cfe; 1131 state->default_cfe = &state->temp_cfe; 1132 } 1133 } 1134 1135 if (intface) { 1136 reg = pcmcia_tuple_read_1(tuple, idx); 1137 idx++; 1138 cfe->flags &= ~(PCMCIA_CFE_MWAIT_REQUIRED 1139 | PCMCIA_CFE_RDYBSY_ACTIVE 1140 | PCMCIA_CFE_WP_ACTIVE 1141 | PCMCIA_CFE_BVD_ACTIVE); 1142 if (reg & PCMCIA_TPCE_IF_MWAIT) 1143 cfe->flags |= PCMCIA_CFE_MWAIT_REQUIRED; 1144 if (reg & PCMCIA_TPCE_IF_RDYBSY) 1145 cfe->flags |= PCMCIA_CFE_RDYBSY_ACTIVE; 1146 if (reg & PCMCIA_TPCE_IF_WP) 1147 cfe->flags |= PCMCIA_CFE_WP_ACTIVE; 1148 if (reg & PCMCIA_TPCE_IF_BVD) 1149 cfe->flags |= PCMCIA_CFE_BVD_ACTIVE; 1150 cfe->iftype = reg & PCMCIA_TPCE_IF_IFTYPE; 1151 } 1152 reg = pcmcia_tuple_read_1(tuple, idx); 1153 idx++; 1154 1155 power = reg & PCMCIA_TPCE_FS_POWER_MASK; 1156 timing = reg & PCMCIA_TPCE_FS_TIMING; 1157 iospace = reg & PCMCIA_TPCE_FS_IOSPACE; 1158 irq = reg & PCMCIA_TPCE_FS_IRQ; 1159 memspace = reg & PCMCIA_TPCE_FS_MEMSPACE_MASK; 1160 misc = reg & PCMCIA_TPCE_FS_MISC; 1161 1162 if (power) { 1163 /* skip over power, don't save */ 1164 /* for each parameter selection byte */ 1165 for (i = 0; i < power; i++) { 1166 reg = pcmcia_tuple_read_1(tuple, idx); 1167 idx++; 1168 /* for each bit */ 1169 for (j = 0; j < 7; j++) { 1170 /* if the bit is set */ 1171 if ((reg >> j) & 0x01) { 1172 /* skip over bytes */ 1173 do { 1174 reg2 = pcmcia_tuple_read_1(tuple, idx); 1175 idx++; 1176 /* 1177 * until 1178 * non- 1179 * extension 1180 * byte 1181 */ 1182 } while (reg2 & 0x80); 1183 } 1184 } 1185 } 1186 } 1187 if (timing) { 1188 /* skip over timing, don't save */ 1189 reg = pcmcia_tuple_read_1(tuple, idx); 1190 idx++; 1191 1192 if ((reg & PCMCIA_TPCE_TD_RESERVED_MASK) != 1193 PCMCIA_TPCE_TD_RESERVED_MASK) 1194 idx++; 1195 if ((reg & PCMCIA_TPCE_TD_RDYBSY_MASK) != 1196 PCMCIA_TPCE_TD_RDYBSY_MASK) 1197 idx++; 1198 if ((reg & PCMCIA_TPCE_TD_WAIT_MASK) != 1199 PCMCIA_TPCE_TD_WAIT_MASK) 1200 idx++; 1201 } 1202 if (iospace) { 1203 if (tuple->length <= idx) { 1204 DPRINTF(("ran out of space before TCPE_IO\n")); 1205 goto abort_cfe; 1206 } 1207 1208 reg = pcmcia_tuple_read_1(tuple, idx); 1209 idx++; 1210 1211 cfe->flags &= 1212 ~(PCMCIA_CFE_IO8 | PCMCIA_CFE_IO16); 1213 if (reg & PCMCIA_TPCE_IO_BUSWIDTH_8BIT) 1214 cfe->flags |= PCMCIA_CFE_IO8; 1215 if (reg & PCMCIA_TPCE_IO_BUSWIDTH_16BIT) 1216 cfe->flags |= PCMCIA_CFE_IO16; 1217 cfe->iomask = 1218 reg & PCMCIA_TPCE_IO_IOADDRLINES_MASK; 1219 1220 if (reg & PCMCIA_TPCE_IO_HASRANGE) { 1221 reg = pcmcia_tuple_read_1(tuple, idx); 1222 idx++; 1223 1224 cfe->num_iospace = 1 + (reg & 1225 PCMCIA_TPCE_IO_RANGE_COUNT); 1226 1227 if (cfe->num_iospace > 1228 (sizeof(cfe->iospace) / 1229 sizeof(cfe->iospace[0]))) { 1230 DPRINTF(("too many io " 1231 "spaces %d", 1232 cfe->num_iospace)); 1233 state->card->error++; 1234 return; 1235 } 1236 for (i = 0; i < cfe->num_iospace; i++) { 1237 switch (reg & PCMCIA_TPCE_IO_RANGE_ADDRSIZE_MASK) { 1238 case PCMCIA_TPCE_IO_RANGE_ADDRSIZE_NONE: 1239 cfe->iospace[i].start = 1240 0; 1241 break; 1242 case PCMCIA_TPCE_IO_RANGE_ADDRSIZE_ONE: 1243 cfe->iospace[i].start = 1244 pcmcia_tuple_read_1(tuple, idx); 1245 idx++; 1246 break; 1247 case PCMCIA_TPCE_IO_RANGE_ADDRSIZE_TWO: 1248 cfe->iospace[i].start = 1249 pcmcia_tuple_read_2(tuple, idx); 1250 idx += 2; 1251 break; 1252 case PCMCIA_TPCE_IO_RANGE_ADDRSIZE_FOUR: 1253 cfe->iospace[i].start = 1254 pcmcia_tuple_read_4(tuple, idx); 1255 idx += 4; 1256 break; 1257 } 1258 switch (reg & 1259 PCMCIA_TPCE_IO_RANGE_LENGTHSIZE_MASK) { 1260 case PCMCIA_TPCE_IO_RANGE_LENGTHSIZE_NONE: 1261 cfe->iospace[i].length = 1262 0; 1263 break; 1264 case PCMCIA_TPCE_IO_RANGE_LENGTHSIZE_ONE: 1265 cfe->iospace[i].length = 1266 pcmcia_tuple_read_1(tuple, idx); 1267 idx++; 1268 break; 1269 case PCMCIA_TPCE_IO_RANGE_LENGTHSIZE_TWO: 1270 cfe->iospace[i].length = 1271 pcmcia_tuple_read_2(tuple, idx); 1272 idx += 2; 1273 break; 1274 case PCMCIA_TPCE_IO_RANGE_LENGTHSIZE_FOUR: 1275 cfe->iospace[i].length = 1276 pcmcia_tuple_read_4(tuple, idx); 1277 idx += 4; 1278 break; 1279 } 1280 cfe->iospace[i].length++; 1281 } 1282 } else { 1283 cfe->num_iospace = 1; 1284 cfe->iospace[0].start = 0; 1285 cfe->iospace[0].length = 1286 (1 << cfe->iomask); 1287 } 1288 } 1289 if (irq) { 1290 if (tuple->length <= idx) { 1291 DPRINTF(("ran out of space before TCPE_IR\n")); 1292 goto abort_cfe; 1293 } 1294 1295 reg = pcmcia_tuple_read_1(tuple, idx); 1296 idx++; 1297 1298 cfe->flags &= ~(PCMCIA_CFE_IRQSHARE 1299 | PCMCIA_CFE_IRQPULSE 1300 | PCMCIA_CFE_IRQLEVEL); 1301 if (reg & PCMCIA_TPCE_IR_SHARE) 1302 cfe->flags |= PCMCIA_CFE_IRQSHARE; 1303 if (reg & PCMCIA_TPCE_IR_PULSE) 1304 cfe->flags |= PCMCIA_CFE_IRQPULSE; 1305 if (reg & PCMCIA_TPCE_IR_LEVEL) 1306 cfe->flags |= PCMCIA_CFE_IRQLEVEL; 1307 1308 if (reg & PCMCIA_TPCE_IR_HASMASK) { 1309 /* 1310 * it's legal to ignore the 1311 * special-interrupt bits, so I will 1312 */ 1313 1314 cfe->irqmask = 1315 pcmcia_tuple_read_2(tuple, idx); 1316 idx += 2; 1317 } else { 1318 cfe->irqmask = 1319 (1 << (reg & PCMCIA_TPCE_IR_IRQ)); 1320 } 1321 } 1322 if (memspace) { 1323 int lengthsize; 1324 int cardaddrsize; 1325 int hostaddrsize; 1326 1327 if (tuple->length <= idx) { 1328 DPRINTF(("ran out of space before TCPE_MS\n")); 1329 goto abort_cfe; 1330 } 1331 1332 switch (memspace) { 1333#ifdef notdef /* This is 0 */ 1334 case PCMCIA_TPCE_FS_MEMSPACE_NONE: 1335 cfe->num_memspace = 0; 1336 break; 1337#endif 1338 1339 case PCMCIA_TPCE_FS_MEMSPACE_LENGTH: 1340 cfe->num_memspace = 1; 1341 cfe->memspace[0].length = 256 * 1342 pcmcia_tuple_read_2(tuple, idx); 1343 idx += 2; 1344 cfe->memspace[0].cardaddr = 0; 1345 cfe->memspace[0].hostaddr = 0; 1346 break; 1347 1348 case PCMCIA_TPCE_FS_MEMSPACE_LENGTHADDR: 1349 cfe->num_memspace = 1; 1350 cfe->memspace[0].length = 256 * 1351 pcmcia_tuple_read_2(tuple, idx); 1352 idx += 2; 1353 cfe->memspace[0].cardaddr = 256 * 1354 pcmcia_tuple_read_2(tuple, idx); 1355 idx += 2; 1356 cfe->memspace[0].hostaddr = 1357 cfe->memspace[0].cardaddr; 1358 break; 1359 1360 default: 1361 reg = pcmcia_tuple_read_1(tuple, idx); 1362 idx++; 1363 1364 cfe->num_memspace = (reg & PCMCIA_TPCE_MS_COUNT) 1365 + 1; 1366 1367 if (cfe->num_memspace > 1368 (sizeof(cfe->memspace) / 1369 sizeof(cfe->memspace[0]))) { 1370 DPRINTF(("too many mem spaces %d", 1371 cfe->num_memspace)); 1372 state->card->error++; 1373 return; 1374 } 1375 lengthsize = 1376 ((reg & PCMCIA_TPCE_MS_LENGTH_SIZE_MASK) >> 1377 PCMCIA_TPCE_MS_LENGTH_SIZE_SHIFT); 1378 cardaddrsize = 1379 ((reg & 1380 PCMCIA_TPCE_MS_CARDADDR_SIZE_MASK) >> 1381 PCMCIA_TPCE_MS_CARDADDR_SIZE_SHIFT); 1382 hostaddrsize = 1383 (reg & PCMCIA_TPCE_MS_HOSTADDR) ? 1384 cardaddrsize : 0; 1385 1386 if (lengthsize == 0) { 1387 DPRINTF(("cfe memspace " 1388 "lengthsize == 0")); 1389 state->card->error++; 1390 } 1391 for (i = 0; i < cfe->num_memspace; i++) { 1392 if (lengthsize) { 1393 cfe->memspace[i].length = 256 * 1394 pcmcia_tuple_read_n(tuple, 1395 lengthsize, idx); 1396 idx += lengthsize; 1397 } else { 1398 cfe->memspace[i].length = 0; 1399 } 1400 if (cfe->memspace[i].length == 0) { 1401 DPRINTF(("cfe->memspace" 1402 "[%d].length == 0", i)); 1403 state->card->error++; 1404 } 1405 if (cardaddrsize) { 1406 cfe->memspace[i].cardaddr = 1407 256 * 1408 pcmcia_tuple_read_n(tuple, 1409 cardaddrsize, idx); 1410 idx += cardaddrsize; 1411 } else { 1412 cfe->memspace[i].cardaddr = 0; 1413 } 1414 if (hostaddrsize) { 1415 cfe->memspace[i].hostaddr = 1416 256 * 1417 pcmcia_tuple_read_n(tuple, 1418 hostaddrsize, idx); 1419 idx += hostaddrsize; 1420 } else { 1421 cfe->memspace[i].hostaddr = 0; 1422 } 1423 } 1424 } 1425 } 1426 1427 if (misc) { 1428 if (tuple->length <= idx) { 1429 DPRINTF(("ran out of space before TCPE_MI\n")); 1430 goto abort_cfe; 1431 } 1432 1433 reg = pcmcia_tuple_read_1(tuple, idx); 1434 idx++; 1435 1436 cfe->flags &= ~(PCMCIA_CFE_POWERDOWN 1437 | PCMCIA_CFE_READONLY 1438 | PCMCIA_CFE_AUDIO); 1439 if (reg & PCMCIA_TPCE_MI_PWRDOWN) 1440 cfe->flags |= PCMCIA_CFE_POWERDOWN; 1441 if (reg & PCMCIA_TPCE_MI_READONLY) 1442 cfe->flags |= PCMCIA_CFE_READONLY; 1443 if (reg & PCMCIA_TPCE_MI_AUDIO) 1444 cfe->flags |= PCMCIA_CFE_AUDIO; 1445 cfe->maxtwins = reg & PCMCIA_TPCE_MI_MAXTWINS; 1446 1447 while (reg & PCMCIA_TPCE_MI_EXT) { 1448 reg = pcmcia_tuple_read_1(tuple, idx); 1449 idx++; 1450 } 1451 } 1452 1453 /* skip all the subtuples */ 1454abort_cfe: 1455 DPRINTF(("CISTPL_CFTABLE_ENTRY\n")); 1456} 1457