pccard.c revision 66058
1/* $NetBSD: pcmcia.c,v 1.13 1998/12/24 04:51:59 marc Exp $ */ 2/* $FreeBSD: head/sys/dev/pccard/pccard.c 66058 2000-09-19 04:39:20Z 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 208static int 209pccard_card_gettype(device_t dev, int *type) 210{ 211 struct pccard_softc *sc = PCCARD_SOFTC(dev); 212 struct pccard_function *pf; 213 214 /* 215 * set the iftype to memory if this card has no functions (not yet 216 * probed), or only one function, and that is not initialized yet or 217 * that is memory. 218 */ 219 pf = STAILQ_FIRST(&sc->card.pf_head); 220 if (pf == NULL || 221 (STAILQ_NEXT(pf, pf_list) == NULL && 222 (pf->cfe == NULL || pf->cfe->iftype == PCCARD_IFTYPE_MEMORY))) 223 *type = PCCARD_IFTYPE_MEMORY; 224 else 225 *type = PCCARD_IFTYPE_IO; 226 return 0; 227} 228 229/* 230 * Initialize a PCCARD function. May be called as long as the function is 231 * disabled. 232 */ 233void 234pccard_function_init(struct pccard_function *pf) 235{ 236 struct pccard_config_entry *cfe; 237 238 if (pf->pf_flags & PFF_ENABLED) 239 panic("pccard_function_init: function is enabled"); 240 241 /* Remember which configuration entry we are using. */ 242 /* XXX 243 * need to look for one we can allocate the resources 244 * and then set them so the alloc_resources work later. 245 */ 246 cfe = STAILQ_FIRST(&pf->cfe_head); 247 pf->cfe = cfe; 248 249} 250 251/* Enable a PCCARD function */ 252int 253pccard_function_enable(struct pccard_function *pf) 254{ 255 struct pccard_function *tmp; 256 int reg; 257 device_t dev = pf->sc->dev; 258 259 if (pf->cfe == NULL) 260 panic("pccard_function_enable: function not initialized"); 261 262 /* 263 * Increase the reference count on the socket, enabling power, if 264 * necessary. 265 */ 266 if (pf->sc->sc_enabled_count++ == 0) 267 POWER_ENABLE_SOCKET(device_get_parent(dev), dev); 268 DEVPRINTF((dev, "++enabled_count = %d\n", pf->sc->sc_enabled_count)); 269 270 if (pf->pf_flags & PFF_ENABLED) { 271 /* 272 * Don't do anything if we're already enabled. 273 */ 274 return (0); 275 } 276 277 /* 278 * it's possible for different functions' CCRs to be in the same 279 * underlying page. Check for that. 280 */ 281 STAILQ_FOREACH(tmp, &pf->sc->card.pf_head, pf_list) { 282 if ((tmp->pf_flags & PFF_ENABLED) && 283 (pf->ccr_base >= (tmp->ccr_base - tmp->pf_ccr_offset)) && 284 ((pf->ccr_base + PCCARD_CCR_SIZE) <= 285 (tmp->ccr_base - tmp->pf_ccr_offset + 286 tmp->pf_ccr_realsize))) { 287 pf->pf_ccrt = tmp->pf_ccrt; 288 pf->pf_ccrh = tmp->pf_ccrh; 289 pf->pf_ccr_realsize = tmp->pf_ccr_realsize; 290 291 /* 292 * pf->pf_ccr_offset = (tmp->pf_ccr_offset - 293 * tmp->ccr_base) + pf->ccr_base; 294 */ 295 pf->pf_ccr_offset = 296 (tmp->pf_ccr_offset + pf->ccr_base) - 297 tmp->ccr_base; 298 pf->pf_ccr_window = tmp->pf_ccr_window; 299 break; 300 } 301 } 302 303 if (tmp == NULL) { 304 pf->ccr_rid = 0; 305 pf->ccr_res = bus_alloc_resource(dev, SYS_RES_MEMORY, 306 &pf->ccr_rid, 0xa0000, 0xdffff, 1 << 10, RF_ACTIVE); 307 if (!pf->ccr_res) { 308 DEVPRINTF((dev, "ccr_res == 0\n")); 309 goto bad; 310 } 311 CARD_SET_RES_FLAGS(device_get_parent(dev), dev, SYS_RES_MEMORY, 312 pf->ccr_rid, PCCARD_A_MEM_ATTR); 313 CARD_SET_MEMORY_OFFSET(device_get_parent(dev), dev, 314 pf->ccr_rid, (pf->ccr_rid >> 10) << 10); 315 pf->pf_ccrt = rman_get_bustag(pf->ccr_res); 316 pf->pf_ccrh = rman_get_bushandle(pf->ccr_res); 317 pf->pf_ccr_offset = rman_get_start(pf->ccr_res); 318 pf->pf_ccr_realsize = 1; 319 } 320 321 reg = (pf->cfe->number & PCCARD_CCR_OPTION_CFINDEX); 322 reg |= PCCARD_CCR_OPTION_LEVIREQ; 323 if (pccard_mfc(pf->sc)) { 324 reg |= (PCCARD_CCR_OPTION_FUNC_ENABLE | 325 PCCARD_CCR_OPTION_ADDR_DECODE); 326 if (pf->ih_fct) 327 reg |= PCCARD_CCR_OPTION_IREQ_ENABLE; 328 329 } 330 pccard_ccr_write(pf, PCCARD_CCR_OPTION, reg); 331 332 reg = 0; 333 334 if ((pf->cfe->flags & PCCARD_CFE_IO16) == 0) 335 reg |= PCCARD_CCR_STATUS_IOIS8; 336 if (pf->cfe->flags & PCCARD_CFE_AUDIO) 337 reg |= PCCARD_CCR_STATUS_AUDIO; 338 pccard_ccr_write(pf, PCCARD_CCR_STATUS, reg); 339 340 pccard_ccr_write(pf, PCCARD_CCR_SOCKETCOPY, 0); 341 342 if (pccard_mfc(pf->sc)) { 343 long tmp, iosize; 344 345 tmp = pf->pf_mfc_iomax - pf->pf_mfc_iobase; 346 /* round up to nearest (2^n)-1 */ 347 for (iosize = 1; iosize < tmp; iosize <<= 1) 348 ; 349 iosize--; 350 351 pccard_ccr_write(pf, PCCARD_CCR_IOBASE0, 352 pf->pf_mfc_iobase & 0xff); 353 pccard_ccr_write(pf, PCCARD_CCR_IOBASE1, 354 (pf->pf_mfc_iobase >> 8) & 0xff); 355 pccard_ccr_write(pf, PCCARD_CCR_IOBASE2, 0); 356 pccard_ccr_write(pf, PCCARD_CCR_IOBASE3, 0); 357 358 pccard_ccr_write(pf, PCCARD_CCR_IOSIZE, iosize); 359 } 360 361#ifdef PCCARDDEBUG 362 if (pccard_debug) { 363 STAILQ_FOREACH(tmp, &pf->sc->card.pf_head, pf_list) { 364 device_printf(tmp->sc->dev, 365 "function %d CCR at %d offset %x: " 366 "%x %x %x %x, %x %x %x %x, %x\n", 367 tmp->number, tmp->pf_ccr_window, 368 tmp->pf_ccr_offset, 369 pccard_ccr_read(tmp, 0x00), 370 pccard_ccr_read(tmp, 0x02), 371 pccard_ccr_read(tmp, 0x04), 372 pccard_ccr_read(tmp, 0x06), 373 pccard_ccr_read(tmp, 0x0A), 374 pccard_ccr_read(tmp, 0x0C), 375 pccard_ccr_read(tmp, 0x0E), 376 pccard_ccr_read(tmp, 0x10), 377 pccard_ccr_read(tmp, 0x12)); 378 } 379 } 380#endif 381 pf->pf_flags |= PFF_ENABLED; 382 return (0); 383 384 bad: 385 /* 386 * Decrement the reference count, and power down the socket, if 387 * necessary. 388 */ 389 if (--pf->sc->sc_enabled_count == 0) 390 POWER_DISABLE_SOCKET(device_get_parent(dev), dev); 391 DEVPRINTF((dev, "bad --enabled_count = %d\n", pf->sc->sc_enabled_count)); 392 393 return (1); 394} 395 396/* Disable PCCARD function. */ 397void 398pccard_function_disable(struct pccard_function *pf) 399{ 400 struct pccard_function *tmp; 401 device_t dev = pf->sc->dev; 402 403 if (pf->cfe == NULL) 404 panic("pccard_function_disable: function not initialized"); 405 406 if ((pf->pf_flags & PFF_ENABLED) == 0) { 407 /* 408 * Don't do anything if we're already disabled. 409 */ 410 return; 411 } 412 413 /* 414 * it's possible for different functions' CCRs to be in the same 415 * underlying page. Check for that. Note we mark us as disabled 416 * first to avoid matching ourself. 417 */ 418 419 pf->pf_flags &= ~PFF_ENABLED; 420 STAILQ_FOREACH(tmp, &pf->sc->card.pf_head, pf_list) { 421 if ((tmp->pf_flags & PFF_ENABLED) && 422 (pf->ccr_base >= (tmp->ccr_base - tmp->pf_ccr_offset)) && 423 ((pf->ccr_base + PCCARD_CCR_SIZE) <= 424 (tmp->ccr_base - tmp->pf_ccr_offset + tmp->pf_ccr_realsize))) 425 break; 426 } 427 428 /* Not used by anyone else; unmap the CCR. */ 429 if (tmp == NULL) { 430 bus_release_resource(dev, SYS_RES_MEMORY, pf->ccr_rid, 431 pf->ccr_res); 432 pf->ccr_res = NULL; 433 } 434 435 /* 436 * Decrement the reference count, and power down the socket, if 437 * necessary. 438 */ 439 if (--pf->sc->sc_enabled_count == 0) 440 POWER_DISABLE_SOCKET(device_get_parent(dev), dev); 441 DEVPRINTF((dev, "--enabled_count = %d\n", pf->sc->sc_enabled_count)); 442} 443 444#if 0 445/* XXX These functions are needed, but not like this XXX */ 446int 447pccard_io_map(struct pccard_function *pf, int width, bus_addr_t offset, 448 bus_size_t size, struct pccard_io_handle *pcihp, int *windowp) 449{ 450 int reg; 451 452 if (pccard_chip_io_map(pf->sc->pct, pf->sc->pch, 453 width, offset, size, pcihp, windowp)) 454 return (1); 455 456 /* 457 * XXX in the multifunction multi-iospace-per-function case, this 458 * needs to cooperate with io_alloc to make sure that the spaces 459 * don't overlap, and that the ccr's are set correctly 460 */ 461 462 if (pccard_mfc(pf->sc)) { 463 long tmp, iosize; 464 465 if (pf->pf_mfc_iomax == 0) { 466 pf->pf_mfc_iobase = pcihp->addr + offset; 467 pf->pf_mfc_iomax = pf->pf_mfc_iobase + size; 468 } else { 469 /* this makes the assumption that nothing overlaps */ 470 if (pf->pf_mfc_iobase > pcihp->addr + offset) 471 pf->pf_mfc_iobase = pcihp->addr + offset; 472 if (pf->pf_mfc_iomax < pcihp->addr + offset + size) 473 pf->pf_mfc_iomax = pcihp->addr + offset + size; 474 } 475 476 tmp = pf->pf_mfc_iomax - pf->pf_mfc_iobase; 477 /* round up to nearest (2^n)-1 */ 478 for (iosize = 1; iosize >= tmp; iosize <<= 1) 479 ; 480 iosize--; 481 482 pccard_ccr_write(pf, PCCARD_CCR_IOBASE0, 483 pf->pf_mfc_iobase & 0xff); 484 pccard_ccr_write(pf, PCCARD_CCR_IOBASE1, 485 (pf->pf_mfc_iobase >> 8) & 0xff); 486 pccard_ccr_write(pf, PCCARD_CCR_IOBASE2, 0); 487 pccard_ccr_write(pf, PCCARD_CCR_IOBASE3, 0); 488 489 pccard_ccr_write(pf, PCCARD_CCR_IOSIZE, iosize); 490 491 reg = pccard_ccr_read(pf, PCCARD_CCR_OPTION); 492 reg |= PCCARD_CCR_OPTION_ADDR_DECODE; 493 pccard_ccr_write(pf, PCCARD_CCR_OPTION, reg); 494 } 495 return (0); 496} 497 498void 499pccard_io_unmap(struct pccard_function *pf, int window) 500{ 501 502 pccard_chip_io_unmap(pf->sc->pct, pf->sc->pch, window); 503 504 /* XXX Anything for multi-function cards? */ 505} 506#endif 507 508/* 509 * simulate the old "probe" routine. In the new world order, the driver 510 * needs to grab devices while in the old they were assigned to the device by 511 * the pccardd process. These symbols are exported to the upper layers. 512 */ 513int 514pccard_compat_probe(device_t dev) 515{ 516 return (CARD_COMPAT_MATCH(dev)); 517} 518 519int 520pccard_compat_attach(device_t dev) 521{ 522 int err; 523 524 err = CARD_COMPAT_PROBE(dev); 525 if (err == 0) 526 err = CARD_COMPAT_ATTACH(dev); 527 return (err); 528} 529 530#define PCCARD_NPORT 2 531#define PCCARD_NMEM 5 532#define PCCARD_NIRQ 1 533#define PCCARD_NDRQ 0 534 535static int 536pccard_add_children(device_t dev, int busno) 537{ 538 /* Call parent to scan for any current children */ 539 return 0; 540} 541 542static int 543pccard_probe(device_t dev) 544{ 545 device_set_desc(dev, "PC Card bus -- newconfig version"); 546 return pccard_add_children(dev, device_get_unit(dev)); 547} 548 549static int 550pccard_attach(device_t dev) 551{ 552 struct pccard_softc *sc = PCCARD_SOFTC(dev); 553 554 sc->dev = dev; 555 sc->sc_enabled_count = 0; 556 DEVPRINTF((dev, "pccard_attach %p\n", dev)); 557 return bus_generic_attach(dev); 558} 559 560static void 561pccard_print_resources(struct resource_list *rl, const char *name, int type, 562 int count, const char *format) 563{ 564 struct resource_list_entry *rle; 565 int printed; 566 int i; 567 568 printed = 0; 569 for (i = 0; i < count; i++) { 570 rle = resource_list_find(rl, type, i); 571 if (rle) { 572 if (printed == 0) 573 printf(" %s ", name); 574 else if (printed > 0) 575 printf(","); 576 printed++; 577 printf(format, rle->start); 578 if (rle->count > 1) { 579 printf("-"); 580 printf(format, rle->start + rle->count - 1); 581 } 582 } else if (i > 3) { 583 /* check the first few regardless */ 584 break; 585 } 586 } 587} 588 589static int 590pccard_print_child(device_t dev, device_t child) 591{ 592 struct pccard_ivar *devi = (struct pccard_ivar *) device_get_ivars(child); 593 struct resource_list *rl = &devi->resources; 594 int retval = 0; 595 596 retval += bus_print_child_header(dev, child); 597 retval += printf(" at"); 598 599 if (devi) { 600 pccard_print_resources(rl, "port", SYS_RES_IOPORT, 601 PCCARD_NPORT, "%#lx"); 602 pccard_print_resources(rl, "iomem", SYS_RES_MEMORY, 603 PCCARD_NMEM, "%#lx"); 604 pccard_print_resources(rl, "irq", SYS_RES_IRQ, PCCARD_NIRQ, 605 "%ld"); 606 pccard_print_resources(rl, "drq", SYS_RES_DRQ, PCCARD_NDRQ, 607 "%ld"); 608 retval += printf(" slot ?"); /* XXX imp */ 609 } 610 611 retval += bus_print_child_footer(dev, child); 612 613 return (retval); 614} 615 616static int 617pccard_set_resource(device_t dev, device_t child, int type, int rid, 618 u_long start, u_long count) 619{ 620 struct pccard_ivar *devi = (struct pccard_ivar *) device_get_ivars(child); 621 struct resource_list *rl = &devi->resources; 622 623 if (type != SYS_RES_IOPORT && type != SYS_RES_MEMORY 624 && type != SYS_RES_IRQ && type != SYS_RES_DRQ) 625 return EINVAL; 626 if (rid < 0) 627 return EINVAL; 628 if (type == SYS_RES_IOPORT && rid >= PCCARD_NPORT) 629 return EINVAL; 630 if (type == SYS_RES_MEMORY && rid >= PCCARD_NMEM) 631 return EINVAL; 632 if (type == SYS_RES_IRQ && rid >= PCCARD_NIRQ) 633 return EINVAL; 634 if (type == SYS_RES_DRQ && rid >= PCCARD_NDRQ) 635 return EINVAL; 636 637 resource_list_add(rl, type, rid, start, start + count - 1, count); 638 639 return 0; 640} 641 642static int 643pccard_get_resource(device_t dev, device_t child, int type, int rid, 644 u_long *startp, u_long *countp) 645{ 646 struct pccard_ivar *devi = (struct pccard_ivar *) device_get_ivars(child); 647 struct resource_list *rl = &devi->resources; 648 struct resource_list_entry *rle; 649 650 rle = resource_list_find(rl, type, rid); 651 if (!rle) 652 return ENOENT; 653 654 if (startp) 655 *startp = rle->start; 656 if (countp) 657 *countp = rle->count; 658 659 return 0; 660} 661 662static void 663pccard_delete_resource(device_t dev, device_t child, int type, int rid) 664{ 665 struct pccard_ivar *devi = (struct pccard_ivar *) device_get_ivars(child); 666 struct resource_list *rl = &devi->resources; 667 resource_list_delete(rl, type, rid); 668} 669 670static int 671pccard_set_res_flags(device_t dev, device_t child, int type, int rid, 672 u_int32_t flags) 673{ 674 return CARD_SET_RES_FLAGS(device_get_parent(dev), child, type, 675 rid, flags); 676} 677 678static int 679pccard_set_memory_offset(device_t dev, device_t child, int rid, 680 u_int32_t offset) 681{ 682 return CARD_SET_MEMORY_OFFSET(device_get_parent(dev), child, rid, 683 offset); 684} 685 686static int 687pccard_read_ivar(device_t bus, device_t child, int which, u_char *result) 688{ 689 /* PCCARD_IVAR_ETHADDR unhandled from oldcard */ 690 return ENOENT; 691} 692 693 694static device_method_t pccard_methods[] = { 695 /* Device interface */ 696 DEVMETHOD(device_probe, pccard_probe), 697 DEVMETHOD(device_attach, pccard_attach), 698 DEVMETHOD(device_detach, bus_generic_detach), 699 DEVMETHOD(device_shutdown, bus_generic_shutdown), 700 DEVMETHOD(device_suspend, bus_generic_suspend), 701 DEVMETHOD(device_resume, bus_generic_resume), 702 703 /* Bus interface */ 704 DEVMETHOD(bus_print_child, pccard_print_child), 705 DEVMETHOD(bus_driver_added, bus_generic_driver_added), 706 DEVMETHOD(bus_alloc_resource, bus_generic_alloc_resource), 707 DEVMETHOD(bus_release_resource, bus_generic_release_resource), 708 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource), 709 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource), 710 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr), 711 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr), 712 DEVMETHOD(bus_set_resource, pccard_set_resource), 713 DEVMETHOD(bus_get_resource, pccard_get_resource), 714 DEVMETHOD(bus_delete_resource, pccard_delete_resource), 715 DEVMETHOD(bus_read_ivar, pccard_read_ivar), 716 717 /* Card Interface */ 718 DEVMETHOD(card_set_res_flags, pccard_set_res_flags), 719 DEVMETHOD(card_set_memory_offset, pccard_set_memory_offset), 720 DEVMETHOD(card_get_type, pccard_card_gettype), 721 DEVMETHOD(card_attach_card, pccard_attach_card), 722 DEVMETHOD(card_detach_card, pccard_detach_card), 723 724 { 0, 0 } 725}; 726 727static driver_t pccard_driver = { 728 "pccard", 729 pccard_methods, 730 sizeof(struct pccard_softc) 731}; 732 733devclass_t pccard_devclass; 734 735DRIVER_MODULE(pccard, pcic, pccard_driver, pccard_devclass, 0, 0); 736DRIVER_MODULE(pccard, pc98pcic, pccard_driver, pccard_devclass, 0, 0); 737DRIVER_MODULE(pccard, pccbb, pccard_driver, pccard_devclass, 0, 0); 738DRIVER_MODULE(pccard, tcic, pccard_driver, pccard_devclass, 0, 0); 739MODULE_VERSION(pccard, 1); 740MODULE_DEPEND(pccard, pcic, 1, 1, 1); 741