pccard.c revision 119755
1/* $NetBSD: pcmcia.c,v 1.23 2000/07/28 19:17:02 drochner 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__FBSDID("$FreeBSD: head/sys/dev/pccard/pccard.c 119755 2003-09-05 03:08:08Z imp $"); 34 35#include <sys/param.h> 36#include <sys/systm.h> 37#include <sys/malloc.h> 38#include <sys/module.h> 39#include <sys/kernel.h> 40#include <sys/queue.h> 41#include <sys/sysctl.h> 42#include <sys/types.h> 43 44#include <sys/bus.h> 45#include <machine/bus.h> 46#include <sys/rman.h> 47#include <machine/resource.h> 48 49#include <net/ethernet.h> 50 51#include <dev/pccard/pccardreg.h> 52#include <dev/pccard/pccardvar.h> 53 54#include "power_if.h" 55#include "card_if.h" 56 57#define PCCARDDEBUG 58 59/* sysctl vars */ 60SYSCTL_NODE(_hw, OID_AUTO, pccard, CTLFLAG_RD, 0, "PCCARD parameters"); 61 62int pccard_debug = 0; 63TUNABLE_INT("hw.pccard.debug", &pccard_debug); 64SYSCTL_INT(_hw_pccard, OID_AUTO, debug, CTLFLAG_RW, 65 &pccard_debug, 0, 66 "pccard debug"); 67 68int pccard_cis_debug = 0; 69TUNABLE_INT("hw.pccard.cis_debug", &pccard_cis_debug); 70SYSCTL_INT(_hw_pccard, OID_AUTO, cis_debug, CTLFLAG_RW, 71 &pccard_cis_debug, 0, "pccard CIS debug"); 72 73#ifdef PCCARDDEBUG 74#define DPRINTF(arg) if (pccard_debug) printf arg 75#define DEVPRINTF(arg) if (pccard_debug) device_printf arg 76#define PRVERBOSE(arg) printf arg 77#define DEVPRVERBOSE(arg) device_printf arg 78#else 79#define DPRINTF(arg) 80#define DEVPRINTF(arg) 81#define PRVERBOSE(arg) if (bootverbose) printf arg 82#define DEVPRVERBOSE(arg) if (bootverbose) device_printf arg 83#endif 84 85static int pccard_ccr_read(struct pccard_function *pf, int ccr); 86static void pccard_ccr_write(struct pccard_function *pf, int ccr, int val); 87static int pccard_attach_card(device_t dev); 88static int pccard_detach_card(device_t dev); 89static int pccard_card_gettype(device_t dev, int *type); 90static void pccard_function_init(struct pccard_function *pf); 91static void pccard_function_free(struct pccard_function *pf); 92static int pccard_function_enable(struct pccard_function *pf); 93static void pccard_function_disable(struct pccard_function *pf); 94static int pccard_compat_do_probe(device_t bus, device_t dev); 95static int pccard_compat_do_attach(device_t bus, device_t dev); 96static int pccard_add_children(device_t dev, int busno); 97static int pccard_probe(device_t dev); 98static int pccard_attach(device_t dev); 99static int pccard_detach(device_t dev); 100static void pccard_print_resources(struct resource_list *rl, 101 const char *name, int type, int count, const char *format); 102static int pccard_print_child(device_t dev, device_t child); 103static int pccard_set_resource(device_t dev, device_t child, int type, 104 int rid, u_long start, u_long count); 105static int pccard_get_resource(device_t dev, device_t child, int type, 106 int rid, u_long *startp, u_long *countp); 107static void pccard_delete_resource(device_t dev, device_t child, int type, 108 int rid); 109static int pccard_set_res_flags(device_t dev, device_t child, int type, 110 int rid, u_int32_t flags); 111static int pccard_set_memory_offset(device_t dev, device_t child, int rid, 112 u_int32_t offset, u_int32_t *deltap); 113static void pccard_probe_nomatch(device_t cbdev, device_t child); 114static int pccard_read_ivar(device_t bus, device_t child, int which, 115 u_char *result); 116static void pccard_driver_added(device_t dev, driver_t *driver); 117static struct resource *pccard_alloc_resource(device_t dev, 118 device_t child, int type, int *rid, u_long start, 119 u_long end, u_long count, u_int flags); 120static int pccard_release_resource(device_t dev, device_t child, int type, 121 int rid, struct resource *r); 122static void pccard_child_detached(device_t parent, device_t dev); 123static void pccard_intr(void *arg); 124static int pccard_setup_intr(device_t dev, device_t child, 125 struct resource *irq, int flags, driver_intr_t *intr, 126 void *arg, void **cookiep); 127static int pccard_teardown_intr(device_t dev, device_t child, 128 struct resource *r, void *cookie); 129 130static const struct pccard_product * 131pccard_do_product_lookup(device_t bus, device_t dev, 132 const struct pccard_product *tab, size_t ent_size, 133 pccard_product_match_fn matchfn); 134 135 136static int 137pccard_ccr_read(struct pccard_function *pf, int ccr) 138{ 139 return (bus_space_read_1(pf->pf_ccrt, pf->pf_ccrh, 140 pf->pf_ccr_offset + ccr)); 141} 142 143static void 144pccard_ccr_write(struct pccard_function *pf, int ccr, int val) 145{ 146 if ((pf->ccr_mask) & (1 << (ccr / 2))) { 147 bus_space_write_1(pf->pf_ccrt, pf->pf_ccrh, 148 pf->pf_ccr_offset + ccr, val); 149 } 150} 151 152static int 153pccard_set_default_descr(device_t dev) 154{ 155 char *vendorstr, *prodstr, *str; 156 157 if (pccard_get_vendor_str(dev, &vendorstr)) 158 return (0); 159 if (pccard_get_product_str(dev, &prodstr)) 160 return (0); 161 str = malloc(strlen(vendorstr) + strlen(prodstr) + 2, M_DEVBUF, 162 M_WAITOK); 163 sprintf(str, "%s %s", vendorstr, prodstr); 164 device_set_desc_copy(dev, str); 165 free(str, M_DEVBUF); 166 return (0); 167} 168 169static int 170pccard_attach_card(device_t dev) 171{ 172 struct pccard_softc *sc = PCCARD_SOFTC(dev); 173 struct pccard_function *pf; 174 struct pccard_ivar *ivar; 175 device_t child; 176 int i; 177 178 /* 179 * this is here so that when socket_enable calls gettype, trt happens 180 */ 181 STAILQ_INIT(&sc->card.pf_head); 182 183 DEVPRINTF((dev, "chip_socket_enable\n")); 184 POWER_ENABLE_SOCKET(device_get_parent(dev), dev); 185 186 DEVPRINTF((dev, "read_cis\n")); 187 pccard_read_cis(sc); 188 189 DEVPRINTF((dev, "check_cis_quirks\n")); 190 pccard_check_cis_quirks(dev); 191 192 /* 193 * bail now if the card has no functions, or if there was an error in 194 * the cis. 195 */ 196 197 if (sc->card.error) { 198 device_printf(dev, "CARD ERROR!\n"); 199 return (1); 200 } 201 if (STAILQ_EMPTY(&sc->card.pf_head)) { 202 device_printf(dev, "Card has no functions!\n"); 203 return (1); 204 } 205 206 if (bootverbose || pccard_debug) 207 pccard_print_cis(dev); 208 209 DEVPRINTF((dev, "functions scanning\n")); 210 i = -1; 211 STAILQ_FOREACH(pf, &sc->card.pf_head, pf_list) { 212 i++; 213 if (STAILQ_EMPTY(&pf->cfe_head)) { 214 device_printf(dev, 215 "Function %d has no config entries.!\n", i); 216 continue; 217 } 218 pf->sc = sc; 219 pf->cfe = NULL; 220 pf->dev = NULL; 221 } 222 DEVPRINTF((dev, "Card has %d functions. pccard_mfc is %d\n", i + 1, 223 pccard_mfc(sc))); 224 225 STAILQ_FOREACH(pf, &sc->card.pf_head, pf_list) { 226 if (STAILQ_EMPTY(&pf->cfe_head)) 227 continue; 228 /* 229 * In NetBSD, the drivers are responsible for activating 230 * each function of a card. I think that in FreeBSD we 231 * want to activate them enough for the usual bus_*_resource 232 * routines will do the right thing. This many mean a 233 * departure from the current NetBSD model. 234 * 235 * This seems to work well in practice for most cards. 236 * However, there are two cases that are problematic. 237 * If a driver wishes to pick and chose which config 238 * entry to use, then this method falls down. These 239 * are usually older cards. In addition, there are 240 * some cards that have multiple hardware units on the 241 * cards, but presents only one CIS chain. These cards 242 * are combination cards, but only one of these units 243 * can be on at a time. 244 */ 245 ivar = malloc(sizeof(struct pccard_ivar), M_DEVBUF, 246 M_WAITOK | M_ZERO); 247 child = device_add_child(dev, NULL, -1); 248 device_set_ivars(child, ivar); 249 ivar->fcn = pf; 250 pf->dev = child; 251 /* 252 * XXX We might want to move the next two lines into 253 * XXX the pccard interface layer. For the moment, this 254 * XXX is OK, but some drivers want to pick the config 255 * XXX entry to use as well as some address tweaks (mostly 256 * XXX due to bugs in decode logic that makes some 257 * XXX addresses illegal or broken). 258 */ 259 pccard_function_init(pf); 260 if (sc->sc_enabled_count == 0) 261 POWER_ENABLE_SOCKET(device_get_parent(dev), dev); 262 if (pccard_function_enable(pf) == 0 && 263 pccard_set_default_descr(child) == 0 && 264 device_probe_and_attach(child) == 0) { 265 DEVPRINTF((sc->dev, "function %d CCR at %d " 266 "offset %x: %x %x %x %x, %x %x %x %x, %x\n", 267 pf->number, pf->pf_ccr_window, pf->pf_ccr_offset, 268 pccard_ccr_read(pf, 0x00), 269 pccard_ccr_read(pf, 0x02), pccard_ccr_read(pf, 0x04), 270 pccard_ccr_read(pf, 0x06), pccard_ccr_read(pf, 0x0A), 271 pccard_ccr_read(pf, 0x0C), pccard_ccr_read(pf, 0x0E), 272 pccard_ccr_read(pf, 0x10), pccard_ccr_read(pf, 0x12))); 273 } else { 274 if (pf->cfe != NULL) 275 pccard_function_disable(pf); 276 } 277 } 278 return (0); 279} 280 281static int 282pccard_detach_card(device_t dev) 283{ 284 struct pccard_softc *sc = PCCARD_SOFTC(dev); 285 struct pccard_function *pf; 286 struct pccard_config_entry *cfe; 287 int state; 288 289 /* 290 * We are running on either the PCCARD socket's event thread 291 * or in user context detaching a device by user request. 292 */ 293 STAILQ_FOREACH(pf, &sc->card.pf_head, pf_list) { 294 if (pf->dev == NULL) 295 continue; 296 state = device_get_state(pf->dev); 297 if (state == DS_ATTACHED || state == DS_BUSY) 298 device_detach(pf->dev); 299 if (pf->cfe != NULL) 300 pccard_function_disable(pf); 301 pccard_function_free(pf); 302 device_delete_child(dev, pf->dev); 303 } 304 if (sc->sc_enabled_count == 0) 305 POWER_DISABLE_SOCKET(device_get_parent(dev), dev); 306 307 while (NULL != (pf = STAILQ_FIRST(&sc->card.pf_head))) { 308 while (NULL != (cfe = STAILQ_FIRST(&pf->cfe_head))) { 309 STAILQ_REMOVE_HEAD(&pf->cfe_head, cfe_list); 310 free(cfe, M_DEVBUF); 311 } 312 STAILQ_REMOVE_HEAD(&sc->card.pf_head, pf_list); 313 free(pf, M_DEVBUF); 314 } 315 return (0); 316} 317 318static const struct pccard_product * 319pccard_do_product_lookup(device_t bus, device_t dev, 320 const struct pccard_product *tab, size_t ent_size, 321 pccard_product_match_fn matchfn) 322{ 323 const struct pccard_product *ent; 324 int matches; 325 u_int32_t fcn; 326 u_int32_t vendor; 327 u_int32_t prod; 328 char *vendorstr; 329 char *prodstr; 330 331#ifdef DIAGNOSTIC 332 if (sizeof *ent > ent_size) 333 panic("pccard_product_lookup: bogus ent_size %jd", 334 (intmax_t) ent_size); 335#endif 336 if (pccard_get_vendor(dev, &vendor)) 337 return (NULL); 338 if (pccard_get_product(dev, &prod)) 339 return (NULL); 340 if (pccard_get_function_number(dev, &fcn)) 341 return (NULL); 342 if (pccard_get_vendor_str(dev, &vendorstr)) 343 return (NULL); 344 if (pccard_get_product_str(dev, &prodstr)) 345 return (NULL); 346 for (ent = tab; ent->pp_vendor != 0; ent = 347 (const struct pccard_product *) ((const char *) ent + ent_size)) { 348 matches = 1; 349 if (ent->pp_vendor == PCCARD_VENDOR_ANY && 350 ent->pp_product == PCCARD_PRODUCT_ANY && 351 ent->pp_cis[0] == NULL && 352 ent->pp_cis[1] == NULL) { 353 if (ent->pp_name) 354 device_printf(dev, 355 "Total wildcard entry ignored for %s\n", 356 ent->pp_name); 357 continue; 358 } 359 if (matches && ent->pp_vendor != PCCARD_VENDOR_ANY && 360 vendor != ent->pp_vendor) 361 matches = 0; 362 if (matches && ent->pp_product != PCCARD_PRODUCT_ANY && 363 prod != ent->pp_product) 364 matches = 0; 365 if (matches && fcn != ent->pp_expfunc) 366 matches = 0; 367 if (matches && ent->pp_cis[0] && 368 strcmp(ent->pp_cis[0], vendorstr) != 0) 369 matches = 0; 370 if (matches && ent->pp_cis[1] && 371 strcmp(ent->pp_cis[1], prodstr) != 0) 372 matches = 0; 373 /* XXX need to match cis[2] and cis[3] also XXX */ 374 if (matchfn != NULL) 375 matches = (*matchfn)(dev, ent, matches); 376 if (matches) 377 return (ent); 378 } 379 return (NULL); 380} 381 382static int 383pccard_card_gettype(device_t dev, int *type) 384{ 385 struct pccard_softc *sc = PCCARD_SOFTC(dev); 386 struct pccard_function *pf; 387 388 /* 389 * set the iftype to memory if this card has no functions (not yet 390 * probed), or only one function, and that is not initialized yet or 391 * that is memory. 392 */ 393 pf = STAILQ_FIRST(&sc->card.pf_head); 394 if (pf == NULL || 395 (STAILQ_NEXT(pf, pf_list) == NULL && 396 (pf->cfe == NULL || pf->cfe->iftype == PCCARD_IFTYPE_MEMORY))) 397 *type = PCCARD_IFTYPE_MEMORY; 398 else 399 *type = PCCARD_IFTYPE_IO; 400 return (0); 401} 402 403/* 404 * Initialize a PCCARD function. May be called as long as the function is 405 * disabled. 406 * 407 * Note: pccard_function_init should not keep resources allocated. It should 408 * only set them up ala isa pnp, set the values in the rl lists, and return. 409 * Any resource held after pccard_function_init is called is a bug. However, 410 * the bus routines to get the resources also assume that pccard_function_init 411 * does this, so they need to be fixed too. 412 */ 413static void 414pccard_function_init(struct pccard_function *pf) 415{ 416 struct pccard_config_entry *cfe; 417 int i; 418 struct pccard_ivar *devi = PCCARD_IVAR(pf->dev); 419 struct resource_list *rl = &devi->resources; 420 struct resource_list_entry *rle; 421 struct resource *r = 0; 422 device_t bus; 423 int start; 424 int end; 425 int spaces; 426 427 if (pf->pf_flags & PFF_ENABLED) { 428 printf("pccard_function_init: function is enabled"); 429 return; 430 } 431 bus = device_get_parent(pf->dev); 432 /* Remember which configuration entry we are using. */ 433 STAILQ_FOREACH(cfe, &pf->cfe_head, cfe_list) { 434 for (i = 0; i < cfe->num_iospace; i++) 435 cfe->iores[i] = NULL; 436 cfe->irqres = NULL; 437 spaces = 0; 438 for (i = 0; i < cfe->num_iospace; i++) { 439 start = cfe->iospace[i].start; 440 if (start) 441 end = start + cfe->iospace[i].length - 1; 442 else 443 end = ~0; 444 cfe->iorid[i] = i; 445 DEVPRINTF((bus, "I/O rid %d start %x end %x\n", 446 i, start, end)); 447 r = cfe->iores[i] = bus_alloc_resource(bus, 448 SYS_RES_IOPORT, &cfe->iorid[i], start, end, 449 cfe->iospace[i].length, 450 rman_make_alignment_flags(cfe->iospace[i].length)); 451 if (cfe->iores[i] == NULL) 452 goto not_this_one; 453 resource_list_add(rl, SYS_RES_IOPORT, cfe->iorid[i], 454 rman_get_start(r), rman_get_end(r), 455 cfe->iospace[i].length); 456 rle = resource_list_find(rl, SYS_RES_IOPORT, 457 cfe->iorid[i]); 458 rle->res = r; 459 spaces++; 460 } 461 if (cfe->num_memspace > 0) { 462 /* 463 * Not implement yet, Fix me. 464 */ 465 DEVPRINTF((bus, "Memory space not yet implemented.\n")); 466 } 467 if (spaces == 0) { 468 DEVPRINTF((bus, "Neither memory nor I/O mampped\n")); 469 goto not_this_one; 470 } 471 if (cfe->irqmask) { 472 cfe->irqrid = 0; 473 r = cfe->irqres = bus_alloc_resource(bus, SYS_RES_IRQ, 474 &cfe->irqrid, 0, ~0, 1, 0); 475 if (cfe->irqres == NULL) 476 goto not_this_one; 477 resource_list_add(rl, SYS_RES_IRQ, cfe->irqrid, 478 rman_get_start(r), rman_get_end(r), 1); 479 rle = resource_list_find(rl, SYS_RES_IRQ, 480 cfe->irqrid); 481 rle->res = r; 482 } 483 /* If we get to here, we've allocated all we need */ 484 pf->cfe = cfe; 485 break; 486 not_this_one:; 487 DEVPRVERBOSE((bus, "Allocation failed for cfe %d\n", 488 cfe->number)); 489 /* 490 * Release resources that we partially allocated 491 * from this config entry. 492 */ 493 for (i = 0; i < cfe->num_iospace; i++) { 494 if (cfe->iores[i] != NULL) { 495 bus_release_resource(bus, SYS_RES_IOPORT, 496 cfe->iorid[i], cfe->iores[i]); 497 rle = resource_list_find(rl, SYS_RES_IOPORT, 498 cfe->iorid[i]); 499 rle->res = NULL; 500 resource_list_delete(rl, SYS_RES_IOPORT, 501 cfe->iorid[i]); 502 } 503 cfe->iores[i] = NULL; 504 } 505 if (cfe->irqmask && cfe->irqres != NULL) { 506 bus_release_resource(bus, SYS_RES_IRQ, 507 cfe->irqrid, cfe->irqres); 508 rle = resource_list_find(rl, SYS_RES_IRQ, 509 cfe->irqrid); 510 rle->res = NULL; 511 resource_list_delete(rl, SYS_RES_IRQ, cfe->irqrid); 512 cfe->irqres = NULL; 513 } 514 } 515} 516 517/* 518 * Free resources allocated by pccard_function_init(), May be called as long 519 * as the function is disabled. 520 * 521 * NOTE: This function should be unnecessary. pccard_function_init should 522 * never keep resources initialized. 523 */ 524static void 525pccard_function_free(struct pccard_function *pf) 526{ 527 struct pccard_ivar *devi = PCCARD_IVAR(pf->dev); 528 struct resource_list_entry *rle; 529 530 if (pf->pf_flags & PFF_ENABLED) { 531 printf("pccard_function_init: function is enabled"); 532 return; 533 } 534 535 SLIST_FOREACH(rle, &devi->resources, link) { 536 if (rle->res) { 537 if (rman_get_device(rle->res) != pf->sc->dev) 538 device_printf(pf->sc->dev, 539 "function_free: Resource still owned by " 540 "child, oops. " 541 "(type=%d, rid=%d, addr=%lx)\n", 542 rle->type, rle->rid, 543 rman_get_start(rle->res)); 544 BUS_RELEASE_RESOURCE(device_get_parent(pf->sc->dev), 545 pf->sc->dev, rle->type, rle->rid, rle->res); 546 rle->res = NULL; 547 } 548 } 549 resource_list_free(&devi->resources); 550} 551 552/* Enable a PCCARD function */ 553static int 554pccard_function_enable(struct pccard_function *pf) 555{ 556 struct pccard_function *tmp; 557 int reg; 558 device_t dev = pf->sc->dev; 559 560 if (pf->cfe == NULL) { 561 DEVPRVERBOSE((dev, "No config entry could be allocated.\n")); 562 return (ENOMEM); 563 } 564 565 /* 566 * Increase the reference count on the socket, enabling power, if 567 * necessary. 568 */ 569 pf->sc->sc_enabled_count++; 570 571 if (pf->pf_flags & PFF_ENABLED) { 572 /* 573 * Don't do anything if we're already enabled. 574 */ 575 return (0); 576 } 577 578 /* 579 * it's possible for different functions' CCRs to be in the same 580 * underlying page. Check for that. 581 */ 582 STAILQ_FOREACH(tmp, &pf->sc->card.pf_head, pf_list) { 583 if ((tmp->pf_flags & PFF_ENABLED) && 584 (pf->ccr_base >= (tmp->ccr_base - tmp->pf_ccr_offset)) && 585 ((pf->ccr_base + PCCARD_CCR_SIZE) <= 586 (tmp->ccr_base - tmp->pf_ccr_offset + 587 tmp->pf_ccr_realsize))) { 588 pf->pf_ccrt = tmp->pf_ccrt; 589 pf->pf_ccrh = tmp->pf_ccrh; 590 pf->pf_ccr_realsize = tmp->pf_ccr_realsize; 591 592 /* 593 * pf->pf_ccr_offset = (tmp->pf_ccr_offset - 594 * tmp->ccr_base) + pf->ccr_base; 595 */ 596 /* pf->pf_ccr_offset = 597 (tmp->pf_ccr_offset + pf->ccr_base) - 598 tmp->ccr_base; */ 599 pf->pf_ccr_window = tmp->pf_ccr_window; 600 break; 601 } 602 } 603 if (tmp == NULL) { 604 pf->ccr_rid = 0; 605 pf->ccr_res = bus_alloc_resource(dev, SYS_RES_MEMORY, 606 &pf->ccr_rid, 0, ~0, 1 << 10, RF_ACTIVE); 607 if (!pf->ccr_res) 608 goto bad; 609 DEVPRINTF((dev, "ccr_res == %lx-%lx, base=%x\n", 610 rman_get_start(pf->ccr_res), rman_get_end(pf->ccr_res), 611 pf->ccr_base)); 612 CARD_SET_RES_FLAGS(device_get_parent(dev), dev, SYS_RES_MEMORY, 613 pf->ccr_rid, PCCARD_A_MEM_ATTR); 614 CARD_SET_MEMORY_OFFSET(device_get_parent(dev), dev, 615 pf->ccr_rid, pf->ccr_base, &pf->pf_ccr_offset); 616 pf->pf_ccrt = rman_get_bustag(pf->ccr_res); 617 pf->pf_ccrh = rman_get_bushandle(pf->ccr_res); 618 pf->pf_ccr_realsize = 1; 619 } 620 621 reg = (pf->cfe->number & PCCARD_CCR_OPTION_CFINDEX); 622 reg |= PCCARD_CCR_OPTION_LEVIREQ; 623 if (pccard_mfc(pf->sc)) { 624 reg |= (PCCARD_CCR_OPTION_FUNC_ENABLE | 625 PCCARD_CCR_OPTION_ADDR_DECODE); 626 /* PCCARD_CCR_OPTION_IRQ_ENABLE set elsewhere as needed */ 627 } 628 pccard_ccr_write(pf, PCCARD_CCR_OPTION, reg); 629 630 reg = 0; 631 if ((pf->cfe->flags & PCCARD_CFE_IO16) == 0) 632 reg |= PCCARD_CCR_STATUS_IOIS8; 633 if (pf->cfe->flags & PCCARD_CFE_AUDIO) 634 reg |= PCCARD_CCR_STATUS_AUDIO; 635 pccard_ccr_write(pf, PCCARD_CCR_STATUS, reg); 636 637 pccard_ccr_write(pf, PCCARD_CCR_SOCKETCOPY, 0); 638 639 if (pccard_mfc(pf->sc)) { 640 long tmp, iosize; 641 642 tmp = pf->pf_mfc_iomax - pf->pf_mfc_iobase; 643 /* round up to nearest (2^n)-1 */ 644 for (iosize = 1; iosize < tmp; iosize <<= 1) 645 ; 646 iosize--; 647 648 pccard_ccr_write(pf, PCCARD_CCR_IOBASE0, 649 pf->pf_mfc_iobase & 0xff); 650 pccard_ccr_write(pf, PCCARD_CCR_IOBASE1, 651 (pf->pf_mfc_iobase >> 8) & 0xff); 652 pccard_ccr_write(pf, PCCARD_CCR_IOBASE2, 0); 653 pccard_ccr_write(pf, PCCARD_CCR_IOBASE3, 0); 654 655 pccard_ccr_write(pf, PCCARD_CCR_IOSIZE, iosize); 656 } 657 658#ifdef PCCARDDEBUG 659 if (pccard_debug) { 660 STAILQ_FOREACH(tmp, &pf->sc->card.pf_head, pf_list) { 661 device_printf(tmp->sc->dev, 662 "function %d CCR at %d offset %x: " 663 "%x %x %x %x, %x %x %x %x, %x\n", 664 tmp->number, tmp->pf_ccr_window, 665 tmp->pf_ccr_offset, 666 pccard_ccr_read(tmp, 0x00), 667 pccard_ccr_read(tmp, 0x02), 668 pccard_ccr_read(tmp, 0x04), 669 pccard_ccr_read(tmp, 0x06), 670 pccard_ccr_read(tmp, 0x0A), 671 pccard_ccr_read(tmp, 0x0C), 672 pccard_ccr_read(tmp, 0x0E), 673 pccard_ccr_read(tmp, 0x10), 674 pccard_ccr_read(tmp, 0x12)); 675 } 676 } 677#endif 678 pf->pf_flags |= PFF_ENABLED; 679 return (0); 680 681 bad: 682 /* 683 * Decrement the reference count, and power down the socket, if 684 * necessary. 685 */ 686 pf->sc->sc_enabled_count--; 687 DEVPRINTF((dev, "bad --enabled_count = %d\n", pf->sc->sc_enabled_count)); 688 689 return (1); 690} 691 692/* Disable PCCARD function. */ 693static void 694pccard_function_disable(struct pccard_function *pf) 695{ 696 struct pccard_function *tmp; 697 device_t dev = pf->sc->dev; 698 699 if (pf->cfe == NULL) 700 panic("pccard_function_disable: function not initialized"); 701 702 if ((pf->pf_flags & PFF_ENABLED) == 0) { 703 /* 704 * Don't do anything if we're already disabled. 705 */ 706 return; 707 } 708 709 if (pf->intr_handler != NULL) { 710 struct pccard_ivar *devi = PCCARD_IVAR(pf->dev); 711 struct resource_list_entry *rle = 712 resource_list_find(&devi->resources, SYS_RES_IRQ, 0); 713 BUS_TEARDOWN_INTR(dev, pf->dev, rle->res, 714 pf->intr_handler_cookie); 715 } 716 717 /* 718 * it's possible for different functions' CCRs to be in the same 719 * underlying page. Check for that. Note we mark us as disabled 720 * first to avoid matching ourself. 721 */ 722 723 pf->pf_flags &= ~PFF_ENABLED; 724 STAILQ_FOREACH(tmp, &pf->sc->card.pf_head, pf_list) { 725 if ((tmp->pf_flags & PFF_ENABLED) && 726 (pf->ccr_base >= (tmp->ccr_base - tmp->pf_ccr_offset)) && 727 ((pf->ccr_base + PCCARD_CCR_SIZE) <= 728 (tmp->ccr_base - tmp->pf_ccr_offset + 729 tmp->pf_ccr_realsize))) 730 break; 731 } 732 733 /* Not used by anyone else; unmap the CCR. */ 734 if (tmp == NULL) { 735 bus_release_resource(dev, SYS_RES_MEMORY, pf->ccr_rid, 736 pf->ccr_res); 737 pf->ccr_res = NULL; 738 } 739 740 /* 741 * Decrement the reference count, and power down the socket, if 742 * necessary. 743 */ 744 pf->sc->sc_enabled_count--; 745} 746 747/* 748 * simulate the old "probe" routine. In the new world order, the driver 749 * needs to grab devices while in the old they were assigned to the device by 750 * the pccardd process. These symbols are exported to the upper layers. 751 */ 752static int 753pccard_compat_do_probe(device_t bus, device_t dev) 754{ 755 return (CARD_COMPAT_MATCH(dev)); 756} 757 758static int 759pccard_compat_do_attach(device_t bus, device_t dev) 760{ 761 int err; 762 763 err = CARD_COMPAT_PROBE(dev); 764 if (err <= 0) 765 err = CARD_COMPAT_ATTACH(dev); 766 return (err); 767} 768 769#define PCCARD_NPORT 2 770#define PCCARD_NMEM 5 771#define PCCARD_NIRQ 1 772#define PCCARD_NDRQ 0 773 774static int 775pccard_add_children(device_t dev, int busno) 776{ 777 /* Call parent to scan for any current children */ 778 return (0); 779} 780 781static int 782pccard_probe(device_t dev) 783{ 784 device_set_desc(dev, "16-bit PCCard bus"); 785 return (pccard_add_children(dev, device_get_unit(dev))); 786} 787 788static int 789pccard_attach(device_t dev) 790{ 791 struct pccard_softc *sc = PCCARD_SOFTC(dev); 792 793 sc->dev = dev; 794 sc->sc_enabled_count = 0; 795 return (bus_generic_attach(dev)); 796} 797 798static int 799pccard_detach(device_t dev) 800{ 801 pccard_detach_card(dev); 802 return 0; 803} 804 805static int 806pccard_suspend(device_t self) 807{ 808 pccard_detach_card(self); 809 return (0); 810} 811 812static 813int 814pccard_resume(device_t self) 815{ 816 return (0); 817} 818 819static void 820pccard_print_resources(struct resource_list *rl, const char *name, int type, 821 int count, const char *format) 822{ 823 struct resource_list_entry *rle; 824 int printed; 825 int i; 826 827 printed = 0; 828 for (i = 0; i < count; i++) { 829 rle = resource_list_find(rl, type, i); 830 if (rle != NULL) { 831 if (printed == 0) 832 printf(" %s ", name); 833 else if (printed > 0) 834 printf(","); 835 printed++; 836 printf(format, rle->start); 837 if (rle->count > 1) { 838 printf("-"); 839 printf(format, rle->start + rle->count - 1); 840 } 841 } else if (i > 3) { 842 /* check the first few regardless */ 843 break; 844 } 845 } 846} 847 848static int 849pccard_print_child(device_t dev, device_t child) 850{ 851 struct pccard_ivar *devi = PCCARD_IVAR(child); 852 struct resource_list *rl = &devi->resources; 853 int retval = 0; 854 855 retval += bus_print_child_header(dev, child); 856 retval += printf(" at"); 857 858 if (devi != NULL) { 859 pccard_print_resources(rl, "port", SYS_RES_IOPORT, 860 PCCARD_NPORT, "%#lx"); 861 pccard_print_resources(rl, "iomem", SYS_RES_MEMORY, 862 PCCARD_NMEM, "%#lx"); 863 pccard_print_resources(rl, "irq", SYS_RES_IRQ, PCCARD_NIRQ, 864 "%ld"); 865 pccard_print_resources(rl, "drq", SYS_RES_DRQ, PCCARD_NDRQ, 866 "%ld"); 867 retval += printf(" function %d config %d", devi->fcn->number, 868 devi->fcn->cfe->number); 869 } 870 871 retval += bus_print_child_footer(dev, child); 872 873 return (retval); 874} 875 876static int 877pccard_set_resource(device_t dev, device_t child, int type, int rid, 878 u_long start, u_long count) 879{ 880 struct pccard_ivar *devi = PCCARD_IVAR(child); 881 struct resource_list *rl = &devi->resources; 882 883 if (type != SYS_RES_IOPORT && type != SYS_RES_MEMORY 884 && type != SYS_RES_IRQ && type != SYS_RES_DRQ) 885 return (EINVAL); 886 if (rid < 0) 887 return (EINVAL); 888 if (type == SYS_RES_IOPORT && rid >= PCCARD_NPORT) 889 return (EINVAL); 890 if (type == SYS_RES_MEMORY && rid >= PCCARD_NMEM) 891 return (EINVAL); 892 if (type == SYS_RES_IRQ && rid >= PCCARD_NIRQ) 893 return (EINVAL); 894 if (type == SYS_RES_DRQ && rid >= PCCARD_NDRQ) 895 return (EINVAL); 896 897 resource_list_add(rl, type, rid, start, start + count - 1, count); 898 if (NULL != resource_list_alloc(rl, device_get_parent(dev), dev, 899 type, &rid, start, start + count - 1, count, 0)) 900 return 0; 901 else 902 return ENOMEM; 903} 904 905static int 906pccard_get_resource(device_t dev, device_t child, int type, int rid, 907 u_long *startp, u_long *countp) 908{ 909 struct pccard_ivar *devi = PCCARD_IVAR(child); 910 struct resource_list *rl = &devi->resources; 911 struct resource_list_entry *rle; 912 913 rle = resource_list_find(rl, type, rid); 914 if (rle == NULL) 915 return (ENOENT); 916 917 if (startp != NULL) 918 *startp = rle->start; 919 if (countp != NULL) 920 *countp = rle->count; 921 922 return (0); 923} 924 925static void 926pccard_delete_resource(device_t dev, device_t child, int type, int rid) 927{ 928 struct pccard_ivar *devi = PCCARD_IVAR(child); 929 struct resource_list *rl = &devi->resources; 930 resource_list_delete(rl, type, rid); 931} 932 933static int 934pccard_set_res_flags(device_t dev, device_t child, int type, int rid, 935 u_int32_t flags) 936{ 937 return (CARD_SET_RES_FLAGS(device_get_parent(dev), child, type, 938 rid, flags)); 939} 940 941static int 942pccard_set_memory_offset(device_t dev, device_t child, int rid, 943 u_int32_t offset, u_int32_t *deltap) 944 945{ 946 return (CARD_SET_MEMORY_OFFSET(device_get_parent(dev), child, rid, 947 offset, deltap)); 948} 949 950static void 951pccard_probe_nomatch(device_t bus, device_t child) 952{ 953 struct pccard_ivar *devi = PCCARD_IVAR(child); 954 struct pccard_function *func = devi->fcn; 955 struct pccard_softc *sc = PCCARD_SOFTC(bus); 956 957 device_printf(bus, "<unknown card>"); 958 printf(" (manufacturer=0x%04x, product=0x%04x) at function %d\n", 959 sc->card.manufacturer, sc->card.product, func->number); 960 device_printf(bus, " CIS info: %s, %s, %s\n", sc->card.cis1_info[0], 961 sc->card.cis1_info[1], sc->card.cis1_info[2]); 962 return; 963} 964 965static int 966pccard_child_location_str(device_t bus, device_t child, char *buf, 967 size_t buflen) 968{ 969 struct pccard_ivar *devi = PCCARD_IVAR(child); 970 struct pccard_function *func = devi->fcn; 971 972 snprintf(buf, buflen, "function=%d", func->number); 973 return (0); 974} 975 976static int 977pccard_child_pnpinfo_str(device_t bus, device_t child, char *buf, 978 size_t buflen) 979{ 980 struct pccard_ivar *devi = PCCARD_IVAR(child); 981 struct pccard_function *func = devi->fcn; 982 struct pccard_softc *sc = PCCARD_SOFTC(bus); 983 984 snprintf(buf, buflen, "manufacturer=0x%04x product=0x%04x " 985 "cisvendor=\"%s\" cisproduct=\"%s\" function_type=%d", 986 sc->card.manufacturer, sc->card.product, sc->card.cis1_info[0], 987 sc->card.cis1_info[1], func->function); 988 return (0); 989} 990 991static int 992pccard_read_ivar(device_t bus, device_t child, int which, u_char *result) 993{ 994 struct pccard_ivar *devi = PCCARD_IVAR(child); 995 struct pccard_function *func = devi->fcn; 996 struct pccard_softc *sc = PCCARD_SOFTC(bus); 997 998 switch (which) { 999 default: 1000 case PCCARD_IVAR_ETHADDR: 1001 bcopy(func->pf_funce_lan_nid, result, ETHER_ADDR_LEN); 1002 break; 1003 case PCCARD_IVAR_VENDOR: 1004 *(u_int32_t *) result = sc->card.manufacturer; 1005 break; 1006 case PCCARD_IVAR_PRODUCT: 1007 *(u_int32_t *) result = sc->card.product; 1008 break; 1009 case PCCARD_IVAR_PRODEXT: 1010 *(u_int16_t *) result = sc->card.prodext; 1011 break; 1012 case PCCARD_IVAR_FUNCTION: 1013 *(u_int32_t *) result = func->function; 1014 break; 1015 case PCCARD_IVAR_FUNCTION_NUMBER: 1016 if (!func) { 1017 device_printf(bus, "No function number, bug!\n"); 1018 return (ENOENT); 1019 } 1020 *(u_int32_t *) result = func->number; 1021 break; 1022 case PCCARD_IVAR_VENDOR_STR: 1023 *(char **) result = sc->card.cis1_info[0]; 1024 break; 1025 case PCCARD_IVAR_PRODUCT_STR: 1026 *(char **) result = sc->card.cis1_info[1]; 1027 break; 1028 case PCCARD_IVAR_CIS3_STR: 1029 *(char **) result = sc->card.cis1_info[2]; 1030 break; 1031 case PCCARD_IVAR_CIS4_STR: 1032 *(char **) result = sc->card.cis1_info[3]; 1033 break; 1034 } 1035 return (0); 1036} 1037 1038static void 1039pccard_driver_added(device_t dev, driver_t *driver) 1040{ 1041 struct pccard_softc *sc = PCCARD_SOFTC(dev); 1042 struct pccard_function *pf; 1043 device_t child; 1044 1045 STAILQ_FOREACH(pf, &sc->card.pf_head, pf_list) { 1046 if (STAILQ_EMPTY(&pf->cfe_head)) 1047 continue; 1048 child = pf->dev; 1049 if (device_get_state(child) != DS_NOTPRESENT) 1050 continue; 1051 if (pccard_function_enable(pf) == 0 && 1052 device_probe_and_attach(child) == 0) { 1053 DEVPRINTF((sc->dev, "function %d CCR at %d " 1054 "offset %x: %x %x %x %x, %x %x %x %x, %x\n", 1055 pf->number, pf->pf_ccr_window, pf->pf_ccr_offset, 1056 pccard_ccr_read(pf, 0x00), 1057 pccard_ccr_read(pf, 0x02), pccard_ccr_read(pf, 0x04), 1058 pccard_ccr_read(pf, 0x06), pccard_ccr_read(pf, 0x0A), 1059 pccard_ccr_read(pf, 0x0C), pccard_ccr_read(pf, 0x0E), 1060 pccard_ccr_read(pf, 0x10), pccard_ccr_read(pf, 0x12))); 1061 } else { 1062 if (pf->cfe != NULL) 1063 pccard_function_disable(pf); 1064 } 1065 } 1066 return; 1067} 1068 1069static struct resource * 1070pccard_alloc_resource(device_t dev, device_t child, int type, int *rid, 1071 u_long start, u_long end, u_long count, u_int flags) 1072{ 1073 struct pccard_ivar *dinfo; 1074 struct resource_list_entry *rle = 0; 1075 int passthrough = (device_get_parent(child) != dev); 1076 struct resource *r = NULL; 1077 1078 if (passthrough) { 1079 return (BUS_ALLOC_RESOURCE(device_get_parent(dev), child, 1080 type, rid, start, end, count, flags)); 1081 } 1082 1083 dinfo = device_get_ivars(child); 1084 rle = resource_list_find(&dinfo->resources, type, *rid); 1085 1086 if (rle == NULL) 1087 return (NULL); /* no resource of that type/rid */ 1088 1089 if (rle->res == NULL) { 1090 switch(type) { 1091 case SYS_RES_IOPORT: 1092 r = bus_alloc_resource(dev, type, rid, start, end, 1093 count, rman_make_alignment_flags(count)); 1094 if (r == NULL) 1095 goto bad; 1096 resource_list_add(&dinfo->resources, type, *rid, 1097 rman_get_start(r), rman_get_end(r), count); 1098 rle = resource_list_find(&dinfo->resources, type, *rid); 1099 if (!rle) 1100 goto bad; 1101 rle->res = r; 1102 break; 1103 case SYS_RES_MEMORY: 1104 break; 1105 case SYS_RES_IRQ: 1106 break; 1107 } 1108 return (rle->res); 1109 } 1110 if (rman_get_device(rle->res) != dev) 1111 return (NULL); 1112 bus_release_resource(dev, type, *rid, rle->res); 1113 rle->res = NULL; 1114 switch(type) { 1115 case SYS_RES_IOPORT: 1116 case SYS_RES_MEMORY: 1117 if (!(flags & RF_ALIGNMENT_MASK)) 1118 flags |= rman_make_alignment_flags(rle->count); 1119 break; 1120 case SYS_RES_IRQ: 1121 flags |= RF_SHAREABLE; 1122 break; 1123 } 1124 rle->res = resource_list_alloc(&dinfo->resources, dev, child, 1125 type, rid, rle->start, rle->end, rle->count, flags); 1126 return (rle->res); 1127bad:; 1128 device_printf(dev, "WARNING: Resource not reserved by pccard\n"); 1129 return (NULL); 1130} 1131 1132static int 1133pccard_release_resource(device_t dev, device_t child, int type, int rid, 1134 struct resource *r) 1135{ 1136 struct pccard_ivar *dinfo; 1137 int passthrough = (device_get_parent(child) != dev); 1138 struct resource_list_entry *rle = 0; 1139 int ret; 1140 int flags; 1141 1142 if (passthrough) 1143 return BUS_RELEASE_RESOURCE(device_get_parent(dev), child, 1144 type, rid, r); 1145 1146 dinfo = device_get_ivars(child); 1147 1148 rle = resource_list_find(&dinfo->resources, type, rid); 1149 1150 if (!rle) { 1151 device_printf(dev, "Allocated resource not found, " 1152 "%d %x %lx %lx\n", 1153 type, rid, rman_get_start(r), rman_get_size(r)); 1154 return ENOENT; 1155 } 1156 if (!rle->res) { 1157 device_printf(dev, "Allocated resource not recorded\n"); 1158 return ENOENT; 1159 } 1160 1161 ret = BUS_RELEASE_RESOURCE(device_get_parent(dev), child, 1162 type, rid, r); 1163 switch(type) { 1164 case SYS_RES_IOPORT: 1165 case SYS_RES_MEMORY: 1166 flags = rman_make_alignment_flags(rle->count); 1167 break; 1168 case SYS_RES_IRQ: 1169 flags = RF_SHAREABLE; 1170 break; 1171 default: 1172 flags = 0; 1173 } 1174 rle->res = bus_alloc_resource(dev, type, &rid, 1175 rle->start, rle->end, rle->count, flags); 1176 if (rle->res == NULL) 1177 device_printf(dev, "release_resource: " 1178 "unable to reaquire resource\n"); 1179 return ret; 1180} 1181 1182static void 1183pccard_child_detached(device_t parent, device_t dev) 1184{ 1185 struct pccard_ivar *ivar = PCCARD_IVAR(dev); 1186 struct pccard_function *pf = ivar->fcn; 1187 1188 pccard_function_disable(pf); 1189} 1190 1191static void 1192pccard_intr(void *arg) 1193{ 1194 struct pccard_function *pf = (struct pccard_function*) arg; 1195 int reg; 1196 int doisr = 1; 1197 1198 /* 1199 * MFC cards know if they interrupted, so we have to ack the 1200 * interrupt and call the ISR. Non-MFC cards don't have these 1201 * bits, so they always get called. Many non-MFC cards have 1202 * this bit set always upon read, but some do not. 1203 * 1204 * We always ack the interrupt, even if there's no ISR 1205 * for the card. This is done on the theory that acking 1206 * the interrupt will pacify the card enough to keep an 1207 * interrupt storm from happening. Of course this won't 1208 * help in the non-MFC case. 1209 * 1210 * This has no impact for MPSAFEness of the client drivers. 1211 * We register this with whatever flags the intr_handler 1212 * was registered with. All these functions are MPSAFE. 1213 */ 1214 if (pccard_mfc(pf->sc)) { 1215 reg = pccard_ccr_read(pf, PCCARD_CCR_STATUS); 1216 if (reg & PCCARD_CCR_STATUS_INTR) 1217 pccard_ccr_write(pf, PCCARD_CCR_STATUS, 1218 reg & ~PCCARD_CCR_STATUS_INTR); 1219 else 1220 doisr = 0; 1221 } 1222 if (pf->intr_handler != NULL && doisr) 1223 pf->intr_handler(pf->intr_handler_arg); 1224} 1225 1226static int 1227pccard_setup_intr(device_t dev, device_t child, struct resource *irq, 1228 int flags, driver_intr_t *intr, void *arg, void **cookiep) 1229{ 1230 struct pccard_softc *sc = PCCARD_SOFTC(dev); 1231 struct pccard_ivar *ivar = PCCARD_IVAR(child); 1232 struct pccard_function *func = ivar->fcn; 1233 int err; 1234 1235 if (func->intr_handler != NULL) 1236 panic("Only one interrupt handler per function allowed"); 1237 err = bus_generic_setup_intr(dev, child, irq, flags, pccard_intr, 1238 func, cookiep); 1239 if (err != 0) 1240 return (err); 1241 func->intr_handler = intr; 1242 func->intr_handler_arg = arg; 1243 func->intr_handler_cookie = *cookiep; 1244 if (pccard_mfc(sc)) { 1245 pccard_ccr_write(func, PCCARD_CCR_OPTION, 1246 pccard_ccr_read(func, PCCARD_CCR_OPTION) | 1247 PCCARD_CCR_OPTION_IREQ_ENABLE); 1248 } 1249 return (0); 1250} 1251 1252static int 1253pccard_teardown_intr(device_t dev, device_t child, struct resource *r, 1254 void *cookie) 1255{ 1256 struct pccard_softc *sc = PCCARD_SOFTC(dev); 1257 struct pccard_ivar *ivar = PCCARD_IVAR(child); 1258 struct pccard_function *func = ivar->fcn; 1259 int ret; 1260 1261 if (pccard_mfc(sc)) { 1262 pccard_ccr_write(func, PCCARD_CCR_OPTION, 1263 pccard_ccr_read(func, PCCARD_CCR_OPTION) & 1264 ~PCCARD_CCR_OPTION_IREQ_ENABLE); 1265 } 1266 ret = bus_generic_teardown_intr(dev, child, r, cookie); 1267 if (ret == 0) { 1268 func->intr_handler = NULL; 1269 func->intr_handler_arg = NULL; 1270 func->intr_handler_cookie = NULL; 1271 } 1272 1273 return (ret); 1274} 1275 1276static device_method_t pccard_methods[] = { 1277 /* Device interface */ 1278 DEVMETHOD(device_probe, pccard_probe), 1279 DEVMETHOD(device_attach, pccard_attach), 1280 DEVMETHOD(device_detach, pccard_detach), 1281 DEVMETHOD(device_shutdown, bus_generic_shutdown), 1282 DEVMETHOD(device_suspend, pccard_suspend), 1283 DEVMETHOD(device_resume, pccard_resume), 1284 1285 /* Bus interface */ 1286 DEVMETHOD(bus_print_child, pccard_print_child), 1287 DEVMETHOD(bus_driver_added, pccard_driver_added), 1288 DEVMETHOD(bus_child_detached, pccard_child_detached), 1289 DEVMETHOD(bus_alloc_resource, pccard_alloc_resource), 1290 DEVMETHOD(bus_release_resource, pccard_release_resource), 1291 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource), 1292 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource), 1293 DEVMETHOD(bus_setup_intr, pccard_setup_intr), 1294 DEVMETHOD(bus_teardown_intr, pccard_teardown_intr), 1295 DEVMETHOD(bus_set_resource, pccard_set_resource), 1296 DEVMETHOD(bus_get_resource, pccard_get_resource), 1297 DEVMETHOD(bus_delete_resource, pccard_delete_resource), 1298 DEVMETHOD(bus_probe_nomatch, pccard_probe_nomatch), 1299 DEVMETHOD(bus_read_ivar, pccard_read_ivar), 1300 DEVMETHOD(bus_child_pnpinfo_str, pccard_child_pnpinfo_str), 1301 DEVMETHOD(bus_child_location_str, pccard_child_location_str), 1302 1303 /* Card Interface */ 1304 DEVMETHOD(card_set_res_flags, pccard_set_res_flags), 1305 DEVMETHOD(card_set_memory_offset, pccard_set_memory_offset), 1306 DEVMETHOD(card_get_type, pccard_card_gettype), 1307 DEVMETHOD(card_attach_card, pccard_attach_card), 1308 DEVMETHOD(card_detach_card, pccard_detach_card), 1309 DEVMETHOD(card_compat_do_probe, pccard_compat_do_probe), 1310 DEVMETHOD(card_compat_do_attach, pccard_compat_do_attach), 1311 DEVMETHOD(card_do_product_lookup, pccard_do_product_lookup), 1312 1313 { 0, 0 } 1314}; 1315 1316static driver_t pccard_driver = { 1317 "pccard", 1318 pccard_methods, 1319 sizeof(struct pccard_softc) 1320}; 1321 1322devclass_t pccard_devclass; 1323 1324/* Maybe we need to have a slot device? */ 1325DRIVER_MODULE(pccard, pcic, pccard_driver, pccard_devclass, 0, 0); 1326DRIVER_MODULE(pccard, cbb, pccard_driver, pccard_devclass, 0, 0); 1327MODULE_VERSION(pccard, 1); 1328