pccard.c revision 66200
1/* $NetBSD: pcmcia.c,v 1.23 2000/07/28 19:17:02 drochner Exp $ */ 2/* $FreeBSD: head/sys/dev/pccard/pccard.c 66200 2000-09-22 01:15:26Z 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 33#include <sys/param.h> 34#include <sys/systm.h> 35#include <sys/malloc.h> 36#include <sys/module.h> 37#include <sys/kernel.h> 38#include <sys/queue.h> 39#include <sys/types.h> 40 41#include <sys/bus.h> 42#include <machine/bus.h> 43#include <sys/rman.h> 44#include <machine/resource.h> 45 46#include <dev/pccard/pccardreg.h> 47#include <dev/pccard/pccardvar.h> 48 49#include "power_if.h" 50#include "card_if.h" 51 52#define PCCARDDEBUG 53 54#ifdef PCCARDDEBUG 55int pccard_debug = 1; 56#define DPRINTF(arg) if (pccard_debug) printf arg 57#define DEVPRINTF(arg) if (pccard_debug) device_printf arg 58#else 59#define DPRINTF(arg) 60#define DEVPRINTF(arg) 61#endif 62 63#ifdef PCCARDVERBOSE 64int pccard_verbose = 1; 65#else 66int pccard_verbose = 0; 67#endif 68 69int pccard_print(void *, const char *); 70 71int 72pccard_ccr_read(pf, ccr) 73 struct pccard_function *pf; 74 int ccr; 75{ 76 return (bus_space_read_1(pf->pf_ccrt, pf->pf_ccrh, 77 pf->pf_ccr_offset + ccr)); 78} 79 80void 81pccard_ccr_write(pf, ccr, val) 82 struct pccard_function *pf; 83 int ccr; 84 int val; 85{ 86 87 if ((pf->ccr_mask) & (1 << (ccr / 2))) { 88 bus_space_write_1(pf->pf_ccrt, pf->pf_ccrh, 89 pf->pf_ccr_offset + ccr, val); 90 } 91} 92 93static int 94pccard_attach_card(device_t dev) 95{ 96 struct pccard_softc *sc = PCCARD_SOFTC(dev); 97 struct pccard_function *pf; 98 struct pccard_ivar *ivar; 99 device_t child; 100 int attached; 101 102 DEVPRINTF((dev, "pccard_card_attach\n")); 103 /* 104 * this is here so that when socket_enable calls gettype, trt happens 105 */ 106 STAILQ_INIT(&sc->card.pf_head); 107 108 DEVPRINTF((dev, "chip_socket_enable\n")); 109 POWER_ENABLE_SOCKET(device_get_parent(dev), dev); 110 111 DEVPRINTF((dev, "read_cis\n")); 112 pccard_read_cis(sc); 113 114 DEVPRINTF((dev, "check_cis_quirks\n")); 115 pccard_check_cis_quirks(dev); 116 117 /* 118 * bail now if the card has no functions, or if there was an error in 119 * the cis. 120 */ 121 122 if (sc->card.error) 123 return (1); 124 if (STAILQ_EMPTY(&sc->card.pf_head)) 125 return (1); 126 127 if (1) 128 pccard_print_cis(dev); 129 130 attached = 0; 131 132 DEVPRINTF((dev, "functions scanning\n")); 133 STAILQ_FOREACH(pf, &sc->card.pf_head, pf_list) { 134 if (STAILQ_EMPTY(&pf->cfe_head)) 135 continue; 136 137 pf->sc = sc; 138 pf->cfe = NULL; 139 pf->ih_fct = NULL; 140 pf->ih_arg = NULL; 141 pf->dev = NULL; 142 } 143#if 0 144 DEVPRINTF((dev, "chip_socket_disable\n")); 145 POWER_DISABLE_SOCKET(device_get_parent(dev), dev); 146#endif 147 148 STAILQ_FOREACH(pf, &sc->card.pf_head, pf_list) { 149 if (STAILQ_EMPTY(&pf->cfe_head)) 150 continue; 151 /* 152 * In NetBSD, the drivers are responsible for activating 153 * each function of a card. I think that in FreeBSD we 154 * want to activate them enough for the usual bus_*_resource 155 * routines will do the right thing. This many mean a 156 * departure from the current NetBSD model. 157 * 158 * This could get really ugly for multifunction cards. But 159 * it might also just fall out of the FreeBSD resource model. 160 * 161 */ 162 device_printf(dev, "Starting to attach....\n"); 163 /* XXX Need ivars XXXimpXXX */ 164 ivar = malloc(sizeof(struct pccard_ivar), M_DEVBUF, M_WAITOK); 165 child = device_add_child(dev, NULL, -1); 166 device_set_ivars(child, ivar); 167 pccard_function_init(pf); 168 pccard_function_enable(pf); 169 device_printf(dev, "pf %p pf->sc %p\n", pf, pf->sc); 170 if (device_probe_and_attach(child) == 0) { 171 attached++; 172 pf->dev = child; 173 174 DEVPRINTF((sc->dev, "function %d CCR at %d " 175 "offset %x: %x %x %x %x, %x %x %x %x, %x\n", 176 pf->number, pf->pf_ccr_window, pf->pf_ccr_offset, 177 pccard_ccr_read(pf, 0x00), 178 pccard_ccr_read(pf, 0x02), pccard_ccr_read(pf, 0x04), 179 pccard_ccr_read(pf, 0x06), pccard_ccr_read(pf, 0x0A), 180 pccard_ccr_read(pf, 0x0C), pccard_ccr_read(pf, 0x0E), 181 pccard_ccr_read(pf, 0x10), pccard_ccr_read(pf, 0x12))); 182 } 183 } 184 return 0; 185} 186 187static int 188pccard_detach_card(device_t dev, int flags) 189{ 190 struct pccard_softc *sc = PCCARD_SOFTC(dev); 191 struct pccard_function *pf; 192 193 /* 194 * We are running on either the PCCARD socket's event thread 195 * or in user context detaching a device by user request. 196 */ 197 STAILQ_FOREACH(pf, &sc->card.pf_head, pf_list) { 198 if (STAILQ_FIRST(&pf->cfe_head) == NULL) 199 continue; 200 201 pccard_function_disable(pf); 202 if (pf->dev) 203 device_delete_child(dev, pf->dev); 204 } 205 return 0; 206} 207 208const struct pccard_product * 209pccard_product_lookup(device_t dev, const struct pccard_product *tab, 210 size_t ent_size, pccard_product_match_fn matchfn) 211{ 212 const struct pccard_product *ent; 213 int matches; 214 u_int32_t fcn; 215 u_int32_t vendor; 216 u_int32_t prod; 217 char *vendorstr; 218 char *prodstr; 219 220#ifdef DIAGNOSTIC 221 if (sizeof *ent > ent_size) 222 panic("pccard_product_lookup: bogus ent_size %ld", 223 (long) ent_size); 224#endif 225 if (pccard_get_vendor(dev, &vendor)) 226 return (NULL); 227 if (pccard_get_product(dev, &prod)) 228 return (NULL); 229 if (pccard_get_function_number(dev, &fcn)) 230 return (NULL); 231 if (pccard_get_vendor_str(dev, &vendorstr)) 232 return (NULL); 233 if (pccard_get_product_str(dev, &prodstr)) 234 return (NULL); 235 for (ent = tab; ent->pp_name != NULL; 236 ent = (const struct pccard_product *) 237 ((const char *) ent + ent_size)) { 238 matches = 1; 239 if (matches && ent->pp_vendor != PCCARD_VENDOR_ANY && 240 vendor != ent->pp_vendor) 241 matches = 0; 242 if (matches && ent->pp_product != PCCARD_PRODUCT_ANY && 243 prod != ent->pp_product) 244 matches = 0; 245 if (matches && fcn != ent->pp_expfunc) 246 matches = 0; 247 if (matches && ent->pp_vendor_str && 248 strcmp(ent->pp_vendor_str, vendorstr) != 0) 249 matches = 0; 250 if (matches && ent->pp_product_str && 251 strcmp(ent->pp_product_str, prodstr) != 0) 252 matches = 0; 253 if (matchfn != NULL) 254 matches = (*matchfn)(dev, ent, matches); 255 if (matches) 256 return (ent); 257 } 258 return (NULL); 259} 260 261static int 262pccard_card_gettype(device_t dev, int *type) 263{ 264 struct pccard_softc *sc = PCCARD_SOFTC(dev); 265 struct pccard_function *pf; 266 267 /* 268 * set the iftype to memory if this card has no functions (not yet 269 * probed), or only one function, and that is not initialized yet or 270 * that is memory. 271 */ 272 pf = STAILQ_FIRST(&sc->card.pf_head); 273 if (pf == NULL || 274 (STAILQ_NEXT(pf, pf_list) == NULL && 275 (pf->cfe == NULL || pf->cfe->iftype == PCCARD_IFTYPE_MEMORY))) 276 *type = PCCARD_IFTYPE_MEMORY; 277 else 278 *type = PCCARD_IFTYPE_IO; 279 return 0; 280} 281 282/* 283 * Initialize a PCCARD function. May be called as long as the function is 284 * disabled. 285 */ 286void 287pccard_function_init(struct pccard_function *pf) 288{ 289 struct pccard_config_entry *cfe; 290 291 if (pf->pf_flags & PFF_ENABLED) 292 panic("pccard_function_init: function is enabled"); 293 294 /* Remember which configuration entry we are using. */ 295 /* XXX 296 * need to look for one we can allocate the resources 297 * and then set them so the alloc_resources work later. 298 */ 299 cfe = STAILQ_FIRST(&pf->cfe_head); 300 pf->cfe = cfe; 301 302} 303 304/* Enable a PCCARD function */ 305int 306pccard_function_enable(struct pccard_function *pf) 307{ 308 struct pccard_function *tmp; 309 int reg; 310 device_t dev = pf->sc->dev; 311 312 if (pf->cfe == NULL) 313 panic("pccard_function_enable: function not initialized"); 314 315 /* 316 * Increase the reference count on the socket, enabling power, if 317 * necessary. 318 */ 319 if (pf->sc->sc_enabled_count++ == 0) 320 POWER_ENABLE_SOCKET(device_get_parent(dev), dev); 321 DEVPRINTF((dev, "++enabled_count = %d\n", pf->sc->sc_enabled_count)); 322 323 if (pf->pf_flags & PFF_ENABLED) { 324 /* 325 * Don't do anything if we're already enabled. 326 */ 327 return (0); 328 } 329 330 /* 331 * it's possible for different functions' CCRs to be in the same 332 * underlying page. Check for that. 333 */ 334 STAILQ_FOREACH(tmp, &pf->sc->card.pf_head, pf_list) { 335 if ((tmp->pf_flags & PFF_ENABLED) && 336 (pf->ccr_base >= (tmp->ccr_base - tmp->pf_ccr_offset)) && 337 ((pf->ccr_base + PCCARD_CCR_SIZE) <= 338 (tmp->ccr_base - tmp->pf_ccr_offset + 339 tmp->pf_ccr_realsize))) { 340 pf->pf_ccrt = tmp->pf_ccrt; 341 pf->pf_ccrh = tmp->pf_ccrh; 342 pf->pf_ccr_realsize = tmp->pf_ccr_realsize; 343 344 /* 345 * pf->pf_ccr_offset = (tmp->pf_ccr_offset - 346 * tmp->ccr_base) + pf->ccr_base; 347 */ 348 pf->pf_ccr_offset = 349 (tmp->pf_ccr_offset + pf->ccr_base) - 350 tmp->ccr_base; 351 pf->pf_ccr_window = tmp->pf_ccr_window; 352 break; 353 } 354 } 355 356 if (tmp == NULL) { 357 pf->ccr_rid = 0; 358 pf->ccr_res = bus_alloc_resource(dev, SYS_RES_MEMORY, 359 &pf->ccr_rid, 0xa0000, 0xdffff, 1 << 10, RF_ACTIVE); 360 if (!pf->ccr_res) { 361 DEVPRINTF((dev, "ccr_res == 0\n")); 362 goto bad; 363 } 364 CARD_SET_RES_FLAGS(device_get_parent(dev), dev, SYS_RES_MEMORY, 365 pf->ccr_rid, PCCARD_A_MEM_ATTR); 366 CARD_SET_MEMORY_OFFSET(device_get_parent(dev), dev, 367 pf->ccr_rid, (pf->ccr_rid >> 10) << 10); 368 pf->pf_ccrt = rman_get_bustag(pf->ccr_res); 369 pf->pf_ccrh = rman_get_bushandle(pf->ccr_res); 370 pf->pf_ccr_offset = rman_get_start(pf->ccr_res); 371 pf->pf_ccr_realsize = 1; 372 } 373 374 reg = (pf->cfe->number & PCCARD_CCR_OPTION_CFINDEX); 375 reg |= PCCARD_CCR_OPTION_LEVIREQ; 376 if (pccard_mfc(pf->sc)) { 377 reg |= (PCCARD_CCR_OPTION_FUNC_ENABLE | 378 PCCARD_CCR_OPTION_ADDR_DECODE); 379 if (pf->ih_fct) 380 reg |= PCCARD_CCR_OPTION_IREQ_ENABLE; 381 382 } 383 pccard_ccr_write(pf, PCCARD_CCR_OPTION, reg); 384 385 reg = 0; 386 387 if ((pf->cfe->flags & PCCARD_CFE_IO16) == 0) 388 reg |= PCCARD_CCR_STATUS_IOIS8; 389 if (pf->cfe->flags & PCCARD_CFE_AUDIO) 390 reg |= PCCARD_CCR_STATUS_AUDIO; 391 pccard_ccr_write(pf, PCCARD_CCR_STATUS, reg); 392 393 pccard_ccr_write(pf, PCCARD_CCR_SOCKETCOPY, 0); 394 395 if (pccard_mfc(pf->sc)) { 396 long tmp, iosize; 397 398 tmp = pf->pf_mfc_iomax - pf->pf_mfc_iobase; 399 /* round up to nearest (2^n)-1 */ 400 for (iosize = 1; iosize < tmp; iosize <<= 1) 401 ; 402 iosize--; 403 404 pccard_ccr_write(pf, PCCARD_CCR_IOBASE0, 405 pf->pf_mfc_iobase & 0xff); 406 pccard_ccr_write(pf, PCCARD_CCR_IOBASE1, 407 (pf->pf_mfc_iobase >> 8) & 0xff); 408 pccard_ccr_write(pf, PCCARD_CCR_IOBASE2, 0); 409 pccard_ccr_write(pf, PCCARD_CCR_IOBASE3, 0); 410 411 pccard_ccr_write(pf, PCCARD_CCR_IOSIZE, iosize); 412 } 413 414#ifdef PCCARDDEBUG 415 if (pccard_debug) { 416 STAILQ_FOREACH(tmp, &pf->sc->card.pf_head, pf_list) { 417 device_printf(tmp->sc->dev, 418 "function %d CCR at %d offset %x: " 419 "%x %x %x %x, %x %x %x %x, %x\n", 420 tmp->number, tmp->pf_ccr_window, 421 tmp->pf_ccr_offset, 422 pccard_ccr_read(tmp, 0x00), 423 pccard_ccr_read(tmp, 0x02), 424 pccard_ccr_read(tmp, 0x04), 425 pccard_ccr_read(tmp, 0x06), 426 pccard_ccr_read(tmp, 0x0A), 427 pccard_ccr_read(tmp, 0x0C), 428 pccard_ccr_read(tmp, 0x0E), 429 pccard_ccr_read(tmp, 0x10), 430 pccard_ccr_read(tmp, 0x12)); 431 } 432 } 433#endif 434 pf->pf_flags |= PFF_ENABLED; 435 return (0); 436 437 bad: 438 /* 439 * Decrement the reference count, and power down the socket, if 440 * necessary. 441 */ 442 if (--pf->sc->sc_enabled_count == 0) 443 POWER_DISABLE_SOCKET(device_get_parent(dev), dev); 444 DEVPRINTF((dev, "bad --enabled_count = %d\n", pf->sc->sc_enabled_count)); 445 446 return (1); 447} 448 449/* Disable PCCARD function. */ 450void 451pccard_function_disable(struct pccard_function *pf) 452{ 453 struct pccard_function *tmp; 454 device_t dev = pf->sc->dev; 455 456 if (pf->cfe == NULL) 457 panic("pccard_function_disable: function not initialized"); 458 459 if ((pf->pf_flags & PFF_ENABLED) == 0) { 460 /* 461 * Don't do anything if we're already disabled. 462 */ 463 return; 464 } 465 466 /* 467 * it's possible for different functions' CCRs to be in the same 468 * underlying page. Check for that. Note we mark us as disabled 469 * first to avoid matching ourself. 470 */ 471 472 pf->pf_flags &= ~PFF_ENABLED; 473 STAILQ_FOREACH(tmp, &pf->sc->card.pf_head, pf_list) { 474 if ((tmp->pf_flags & PFF_ENABLED) && 475 (pf->ccr_base >= (tmp->ccr_base - tmp->pf_ccr_offset)) && 476 ((pf->ccr_base + PCCARD_CCR_SIZE) <= 477 (tmp->ccr_base - tmp->pf_ccr_offset + tmp->pf_ccr_realsize))) 478 break; 479 } 480 481 /* Not used by anyone else; unmap the CCR. */ 482 if (tmp == NULL) { 483 bus_release_resource(dev, SYS_RES_MEMORY, pf->ccr_rid, 484 pf->ccr_res); 485 pf->ccr_res = NULL; 486 } 487 488 /* 489 * Decrement the reference count, and power down the socket, if 490 * necessary. 491 */ 492 if (--pf->sc->sc_enabled_count == 0) 493 POWER_DISABLE_SOCKET(device_get_parent(dev), dev); 494 DEVPRINTF((dev, "--enabled_count = %d\n", pf->sc->sc_enabled_count)); 495} 496 497#if 0 498/* XXX These functions are needed, but not like this XXX */ 499int 500pccard_io_map(struct pccard_function *pf, int width, bus_addr_t offset, 501 bus_size_t size, struct pccard_io_handle *pcihp, int *windowp) 502{ 503 int reg; 504 505 if (pccard_chip_io_map(pf->sc->pct, pf->sc->pch, 506 width, offset, size, pcihp, windowp)) 507 return (1); 508 509 /* 510 * XXX in the multifunction multi-iospace-per-function case, this 511 * needs to cooperate with io_alloc to make sure that the spaces 512 * don't overlap, and that the ccr's are set correctly 513 */ 514 515 if (pccard_mfc(pf->sc)) { 516 long tmp, iosize; 517 518 if (pf->pf_mfc_iomax == 0) { 519 pf->pf_mfc_iobase = pcihp->addr + offset; 520 pf->pf_mfc_iomax = pf->pf_mfc_iobase + size; 521 } else { 522 /* this makes the assumption that nothing overlaps */ 523 if (pf->pf_mfc_iobase > pcihp->addr + offset) 524 pf->pf_mfc_iobase = pcihp->addr + offset; 525 if (pf->pf_mfc_iomax < pcihp->addr + offset + size) 526 pf->pf_mfc_iomax = pcihp->addr + offset + size; 527 } 528 529 tmp = pf->pf_mfc_iomax - pf->pf_mfc_iobase; 530 /* round up to nearest (2^n)-1 */ 531 for (iosize = 1; iosize >= tmp; iosize <<= 1) 532 ; 533 iosize--; 534 535 pccard_ccr_write(pf, PCCARD_CCR_IOBASE0, 536 pf->pf_mfc_iobase & 0xff); 537 pccard_ccr_write(pf, PCCARD_CCR_IOBASE1, 538 (pf->pf_mfc_iobase >> 8) & 0xff); 539 pccard_ccr_write(pf, PCCARD_CCR_IOBASE2, 0); 540 pccard_ccr_write(pf, PCCARD_CCR_IOBASE3, 0); 541 542 pccard_ccr_write(pf, PCCARD_CCR_IOSIZE, iosize); 543 544 reg = pccard_ccr_read(pf, PCCARD_CCR_OPTION); 545 reg |= PCCARD_CCR_OPTION_ADDR_DECODE; 546 pccard_ccr_write(pf, PCCARD_CCR_OPTION, reg); 547 } 548 return (0); 549} 550 551void 552pccard_io_unmap(struct pccard_function *pf, int window) 553{ 554 555 pccard_chip_io_unmap(pf->sc->pct, pf->sc->pch, window); 556 557 /* XXX Anything for multi-function cards? */ 558} 559#endif 560 561/* 562 * simulate the old "probe" routine. In the new world order, the driver 563 * needs to grab devices while in the old they were assigned to the device by 564 * the pccardd process. These symbols are exported to the upper layers. 565 */ 566int 567pccard_compat_probe(device_t dev) 568{ 569 return (CARD_COMPAT_MATCH(dev)); 570} 571 572int 573pccard_compat_attach(device_t dev) 574{ 575 int err; 576 577 err = CARD_COMPAT_PROBE(dev); 578 if (err == 0) 579 err = CARD_COMPAT_ATTACH(dev); 580 return (err); 581} 582 583#define PCCARD_NPORT 2 584#define PCCARD_NMEM 5 585#define PCCARD_NIRQ 1 586#define PCCARD_NDRQ 0 587 588static int 589pccard_add_children(device_t dev, int busno) 590{ 591 /* Call parent to scan for any current children */ 592 return 0; 593} 594 595static int 596pccard_probe(device_t dev) 597{ 598 device_set_desc(dev, "PC Card bus -- newconfig version"); 599 return pccard_add_children(dev, device_get_unit(dev)); 600} 601 602static int 603pccard_attach(device_t dev) 604{ 605 struct pccard_softc *sc = PCCARD_SOFTC(dev); 606 607 sc->dev = dev; 608 sc->sc_enabled_count = 0; 609 DEVPRINTF((dev, "pccard_attach %p\n", dev)); 610 return bus_generic_attach(dev); 611} 612 613static void 614pccard_print_resources(struct resource_list *rl, const char *name, int type, 615 int count, const char *format) 616{ 617 struct resource_list_entry *rle; 618 int printed; 619 int i; 620 621 printed = 0; 622 for (i = 0; i < count; i++) { 623 rle = resource_list_find(rl, type, i); 624 if (rle) { 625 if (printed == 0) 626 printf(" %s ", name); 627 else if (printed > 0) 628 printf(","); 629 printed++; 630 printf(format, rle->start); 631 if (rle->count > 1) { 632 printf("-"); 633 printf(format, rle->start + rle->count - 1); 634 } 635 } else if (i > 3) { 636 /* check the first few regardless */ 637 break; 638 } 639 } 640} 641 642static int 643pccard_print_child(device_t dev, device_t child) 644{ 645 struct pccard_ivar *devi = (struct pccard_ivar *) device_get_ivars(child); 646 struct resource_list *rl = &devi->resources; 647 int retval = 0; 648 649 retval += bus_print_child_header(dev, child); 650 retval += printf(" at"); 651 652 if (devi) { 653 pccard_print_resources(rl, "port", SYS_RES_IOPORT, 654 PCCARD_NPORT, "%#lx"); 655 pccard_print_resources(rl, "iomem", SYS_RES_MEMORY, 656 PCCARD_NMEM, "%#lx"); 657 pccard_print_resources(rl, "irq", SYS_RES_IRQ, PCCARD_NIRQ, 658 "%ld"); 659 pccard_print_resources(rl, "drq", SYS_RES_DRQ, PCCARD_NDRQ, 660 "%ld"); 661 retval += printf(" slot ?"); /* XXX imp */ 662 } 663 664 retval += bus_print_child_footer(dev, child); 665 666 return (retval); 667} 668 669static int 670pccard_set_resource(device_t dev, device_t child, int type, int rid, 671 u_long start, u_long count) 672{ 673 struct pccard_ivar *devi = (struct pccard_ivar *) device_get_ivars(child); 674 struct resource_list *rl = &devi->resources; 675 676 if (type != SYS_RES_IOPORT && type != SYS_RES_MEMORY 677 && type != SYS_RES_IRQ && type != SYS_RES_DRQ) 678 return EINVAL; 679 if (rid < 0) 680 return EINVAL; 681 if (type == SYS_RES_IOPORT && rid >= PCCARD_NPORT) 682 return EINVAL; 683 if (type == SYS_RES_MEMORY && rid >= PCCARD_NMEM) 684 return EINVAL; 685 if (type == SYS_RES_IRQ && rid >= PCCARD_NIRQ) 686 return EINVAL; 687 if (type == SYS_RES_DRQ && rid >= PCCARD_NDRQ) 688 return EINVAL; 689 690 resource_list_add(rl, type, rid, start, start + count - 1, count); 691 692 return 0; 693} 694 695static int 696pccard_get_resource(device_t dev, device_t child, int type, int rid, 697 u_long *startp, u_long *countp) 698{ 699 struct pccard_ivar *devi = (struct pccard_ivar *) device_get_ivars(child); 700 struct resource_list *rl = &devi->resources; 701 struct resource_list_entry *rle; 702 703 rle = resource_list_find(rl, type, rid); 704 if (!rle) 705 return ENOENT; 706 707 if (startp) 708 *startp = rle->start; 709 if (countp) 710 *countp = rle->count; 711 712 return 0; 713} 714 715static void 716pccard_delete_resource(device_t dev, device_t child, int type, int rid) 717{ 718 struct pccard_ivar *devi = (struct pccard_ivar *) device_get_ivars(child); 719 struct resource_list *rl = &devi->resources; 720 resource_list_delete(rl, type, rid); 721} 722 723static int 724pccard_set_res_flags(device_t dev, device_t child, int type, int rid, 725 u_int32_t flags) 726{ 727 return CARD_SET_RES_FLAGS(device_get_parent(dev), child, type, 728 rid, flags); 729} 730 731static int 732pccard_set_memory_offset(device_t dev, device_t child, int rid, 733 u_int32_t offset) 734{ 735 return CARD_SET_MEMORY_OFFSET(device_get_parent(dev), child, rid, 736 offset); 737} 738 739static int 740pccard_read_ivar(device_t bus, device_t child, int which, u_char *result) 741{ 742 /* PCCARD_IVAR_ETHADDR unhandled from oldcard */ 743 return ENOENT; 744} 745 746 747static device_method_t pccard_methods[] = { 748 /* Device interface */ 749 DEVMETHOD(device_probe, pccard_probe), 750 DEVMETHOD(device_attach, pccard_attach), 751 DEVMETHOD(device_detach, bus_generic_detach), 752 DEVMETHOD(device_shutdown, bus_generic_shutdown), 753 DEVMETHOD(device_suspend, bus_generic_suspend), 754 DEVMETHOD(device_resume, bus_generic_resume), 755 756 /* Bus interface */ 757 DEVMETHOD(bus_print_child, pccard_print_child), 758 DEVMETHOD(bus_driver_added, bus_generic_driver_added), 759 DEVMETHOD(bus_alloc_resource, bus_generic_alloc_resource), 760 DEVMETHOD(bus_release_resource, bus_generic_release_resource), 761 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource), 762 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource), 763 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr), 764 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr), 765 DEVMETHOD(bus_set_resource, pccard_set_resource), 766 DEVMETHOD(bus_get_resource, pccard_get_resource), 767 DEVMETHOD(bus_delete_resource, pccard_delete_resource), 768 DEVMETHOD(bus_read_ivar, pccard_read_ivar), 769 770 /* Card Interface */ 771 DEVMETHOD(card_set_res_flags, pccard_set_res_flags), 772 DEVMETHOD(card_set_memory_offset, pccard_set_memory_offset), 773 DEVMETHOD(card_get_type, pccard_card_gettype), 774 DEVMETHOD(card_attach_card, pccard_attach_card), 775 DEVMETHOD(card_detach_card, pccard_detach_card), 776 777 { 0, 0 } 778}; 779 780static driver_t pccard_driver = { 781 "pccard", 782 pccard_methods, 783 sizeof(struct pccard_softc) 784}; 785 786devclass_t pccard_devclass; 787 788DRIVER_MODULE(pccard, pcic, pccard_driver, pccard_devclass, 0, 0); 789DRIVER_MODULE(pccard, pc98pcic, pccard_driver, pccard_devclass, 0, 0); 790DRIVER_MODULE(pccard, pccbb, pccard_driver, pccard_devclass, 0, 0); 791DRIVER_MODULE(pccard, tcic, pccard_driver, pccard_devclass, 0, 0); 792MODULE_VERSION(pccard, 1); 793MODULE_DEPEND(pccard, pcic, 1, 1, 1); 794