1/* $NetBSD: pcmcia.c,v 1.23 2000/07/28 19:17:02 drochner Exp $ */ |
2/* $FreeBSD: head/sys/dev/pccard/pccard.c 82378 2001-08-27 00:09:42Z jon $ */ |
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 --- 54 unchanged lines hidden (view full) --- 65#endif 66 67#ifdef PCCARDVERBOSE 68int pccard_verbose = 1; 69#else 70int pccard_verbose = 0; 71#endif 72 |
73static int pccard_ccr_read(struct pccard_function *pf, int ccr); 74static void pccard_ccr_write(struct pccard_function *pf, int ccr, int val); 75static int pccard_attach_card(device_t dev); 76static int pccard_detach_card(device_t dev, int flags); 77static const struct pccard_product *pccard_product_lookup(device_t dev, 78 const struct pccard_product *tab, size_t ent_size, 79 pccard_product_match_fn matchfn); 80static int pccard_card_gettype(device_t dev, int *type); 81static void pccard_function_init(struct pccard_function *pf); 82static void pccard_function_free(struct pccard_function *pf); 83static int pccard_function_enable(struct pccard_function *pf); 84static void pccard_function_disable(struct pccard_function *pf); 85static int pccard_compat_do_probe(device_t bus, device_t dev); 86static int pccard_compat_do_attach(device_t bus, device_t dev); 87static int pccard_add_children(device_t dev, int busno); 88static int pccard_probe(device_t dev); 89static int pccard_attach(device_t dev); 90static int pccard_detach(device_t dev); 91static void pccard_print_resources(struct resource_list *rl, 92 const char *name, int type, int count, const char *format); 93static int pccard_print_child(device_t dev, device_t child); 94static int pccard_set_resource(device_t dev, device_t child, int type, 95 int rid, u_long start, u_long count); 96static int pccard_get_resource(device_t dev, device_t child, int type, 97 int rid, u_long *startp, u_long *countp); 98static void pccard_delete_resource(device_t dev, device_t child, int type, 99 int rid); 100static int pccard_set_res_flags(device_t dev, device_t child, int type, 101 int rid, u_int32_t flags); 102static int pccard_set_memory_offset(device_t dev, device_t child, int rid, 103 u_int32_t offset, u_int32_t *deltap); 104static int pccard_read_ivar(device_t bus, device_t child, int which, 105 u_char *result); 106static void pccard_driver_added(device_t dev, driver_t *driver); 107static struct resource *pccard_alloc_resource(device_t dev, 108 device_t child, int type, int *rid, u_long start, 109 u_long end, u_long count, u_int flags); 110static int pccard_release_resource(device_t dev, device_t child, int type, 111 int rid, struct resource *r); 112static void pccard_child_detached(device_t parent, device_t dev); 113static void pccard_intr(void *arg); 114static int pccard_setup_intr(device_t dev, device_t child, 115 struct resource *irq, int flags, driver_intr_t *intr, 116 void *arg, void **cookiep); 117static int pccard_teardown_intr(device_t dev, device_t child, 118 struct resource *r, void *cookie); |
119 |
120static int |
121pccard_ccr_read(struct pccard_function *pf, int ccr) 122{ 123 return (bus_space_read_1(pf->pf_ccrt, pf->pf_ccrh, 124 pf->pf_ccr_offset + ccr)); 125} 126 |
127static void |
128pccard_ccr_write(struct pccard_function *pf, int ccr, int val) 129{ 130 if ((pf->ccr_mask) & (1 << (ccr / 2))) { 131 bus_space_write_1(pf->pf_ccrt, pf->pf_ccrh, 132 pf->pf_ccr_offset + ccr, val); 133 } 134} 135 136static int 137pccard_attach_card(device_t dev) 138{ 139 struct pccard_softc *sc = PCCARD_SOFTC(dev); 140 struct pccard_function *pf; 141 struct pccard_ivar *ivar; 142 device_t child; |
143 |
144 /* 145 * this is here so that when socket_enable calls gettype, trt happens 146 */ 147 STAILQ_INIT(&sc->card.pf_head); 148 149 DEVPRINTF((dev, "chip_socket_enable\n")); 150 POWER_ENABLE_SOCKET(device_get_parent(dev), dev); 151 --- 15 unchanged lines hidden (view full) --- 167 if (STAILQ_EMPTY(&sc->card.pf_head)) { 168 device_printf (dev, "Card has no functions!\n"); 169 return (1); 170 } 171 172 if (1) 173 pccard_print_cis(dev); 174 |
175 DEVPRINTF((dev, "functions scanning\n")); 176 STAILQ_FOREACH(pf, &sc->card.pf_head, pf_list) { 177 if (STAILQ_EMPTY(&pf->cfe_head)) 178 continue; 179 180 pf->sc = sc; 181 pf->cfe = NULL; 182 pf->dev = NULL; 183 } |
184 |
185 STAILQ_FOREACH(pf, &sc->card.pf_head, pf_list) { 186 if (STAILQ_EMPTY(&pf->cfe_head)) 187 continue; 188 /* 189 * In NetBSD, the drivers are responsible for activating 190 * each function of a card. I think that in FreeBSD we 191 * want to activate them enough for the usual bus_*_resource 192 * routines will do the right thing. This many mean a --- 13 unchanged lines hidden (view full) --- 206 * XXX We might want to move the next two lines into 207 * XXX the pccard interface layer. For the moment, this 208 * XXX is OK, but some drivers want to pick the config 209 * XXX entry to use as well as some address tweaks (mostly 210 * XXX due to bugs in decode logic that makes some 211 * XXX addresses illegal or broken). 212 */ 213 pccard_function_init(pf); |
214 if (sc->sc_enabled_count == 0) 215 POWER_ENABLE_SOCKET(device_get_parent(dev), dev); |
216 if (pccard_function_enable(pf) == 0 && 217 device_probe_and_attach(child) == 0) { |
218 DEVPRINTF((sc->dev, "function %d CCR at %d " 219 "offset %x: %x %x %x %x, %x %x %x %x, %x\n", 220 pf->number, pf->pf_ccr_window, pf->pf_ccr_offset, 221 pccard_ccr_read(pf, 0x00), 222 pccard_ccr_read(pf, 0x02), pccard_ccr_read(pf, 0x04), 223 pccard_ccr_read(pf, 0x06), pccard_ccr_read(pf, 0x0A), 224 pccard_ccr_read(pf, 0x0C), pccard_ccr_read(pf, 0x0E), 225 pccard_ccr_read(pf, 0x10), pccard_ccr_read(pf, 0x12))); 226 } else { |
227 pccard_function_disable(pf); |
228 } 229 } |
230 if (sc->sc_enabled_count == 0) 231 pccard_detach_card(dev, 0); |
232 return (0); 233} 234 235static int 236pccard_detach_card(device_t dev, int flags) 237{ 238 struct pccard_softc *sc = PCCARD_SOFTC(dev); 239 struct pccard_function *pf; |
240 struct pccard_config_entry *cfe; |
241 242 /* 243 * We are running on either the PCCARD socket's event thread 244 * or in user context detaching a device by user request. 245 */ 246 STAILQ_FOREACH(pf, &sc->card.pf_head, pf_list) { |
247 int state = device_get_state(pf->dev); |
248 |
249 if (state == DS_ATTACHED || state == DS_BUSY) 250 device_detach(pf->dev); |
251 pccard_function_disable(pf); |
252 pccard_function_free(pf); |
253 if (pf->dev != NULL) 254 device_delete_child(dev, pf->dev); 255 } |
256 if (sc->sc_enabled_count == 0) 257 POWER_DISABLE_SOCKET(device_get_parent(dev), dev); 258 259 while (NULL != (pf = STAILQ_FIRST(&sc->card.pf_head))) { 260 while (NULL != (cfe = STAILQ_FIRST(&pf->cfe_head))) { 261 STAILQ_REMOVE_HEAD(&pf->cfe_head, cfe_list); 262 free(cfe, M_DEVBUF); 263 } 264 STAILQ_REMOVE_HEAD(&sc->card.pf_head, pf_list); 265 free(pf, M_DEVBUF); 266 } |
267 return (0); 268} 269 |
270static const struct pccard_product * |
271pccard_product_lookup(device_t dev, const struct pccard_product *tab, 272 size_t ent_size, pccard_product_match_fn matchfn) 273{ 274 const struct pccard_product *ent; 275 int matches; 276 u_int32_t fcn; 277 u_int32_t vendor; 278 u_int32_t prod; --- 10 unchanged lines hidden (view full) --- 289 if (pccard_get_product(dev, &prod)) 290 return (NULL); 291 if (pccard_get_function_number(dev, &fcn)) 292 return (NULL); 293 if (pccard_get_vendor_str(dev, &vendorstr)) 294 return (NULL); 295 if (pccard_get_product_str(dev, &prodstr)) 296 return (NULL); |
297 for (ent = tab; ent->pp_name != NULL; ent = 298 (const struct pccard_product *) ((const char *) ent + ent_size)) { |
299 matches = 1; 300 if (matches && ent->pp_vendor != PCCARD_VENDOR_ANY && 301 vendor != ent->pp_vendor) 302 matches = 0; 303 if (matches && ent->pp_product != PCCARD_PRODUCT_ANY && 304 prod != ent->pp_product) 305 matches = 0; 306 if (matches && fcn != ent->pp_expfunc) --- 33 unchanged lines hidden (view full) --- 340 *type = PCCARD_IFTYPE_IO; 341 return (0); 342} 343 344/* 345 * Initialize a PCCARD function. May be called as long as the function is 346 * disabled. 347 */ |
348static void |
349pccard_function_init(struct pccard_function *pf) 350{ 351 struct pccard_config_entry *cfe; 352 int i; 353 struct pccard_ivar *devi = PCCARD_IVAR(pf->dev); 354 struct resource_list *rl = &devi->resources; 355 struct resource_list_entry *rle; 356 struct resource *r = 0; --- 55 unchanged lines hidden (view full) --- 412 /* 413 * Release resources that we partially allocated 414 * from this config entry. 415 */ 416 for (i = 0; i < cfe->num_iospace; i++) { 417 if (cfe->iores[i] != NULL) { 418 bus_release_resource(bus, SYS_RES_IOPORT, 419 cfe->iorid[i], cfe->iores[i]); |
420 rle = resource_list_find(rl, SYS_RES_IOPORT, |
421 cfe->iorid[i]); 422 rle->res = NULL; 423 resource_list_delete(rl, SYS_RES_IOPORT, 424 cfe->iorid[i]); 425 } 426 cfe->iores[i] = NULL; 427 } 428 if (cfe->irqmask && cfe->irqres != NULL) { 429 bus_release_resource(bus, SYS_RES_IRQ, 430 cfe->irqrid, cfe->irqres); 431 rle = resource_list_find(rl, SYS_RES_IRQ, 432 cfe->irqrid); 433 rle->res = NULL; 434 resource_list_delete(rl, SYS_RES_IRQ, cfe->irqrid); 435 cfe->irqres = NULL; 436 } 437 } 438} 439 |
440/* 441 * Free resources allocated by pccard_function_init(), May be called as long 442 * as the function is disabled. 443 */ 444static void 445pccard_function_free(struct pccard_function *pf) 446{ 447 struct pccard_ivar *devi = PCCARD_IVAR(pf->dev); 448 struct resource_list_entry *rle; 449 450 if (pf->pf_flags & PFF_ENABLED) { 451 printf("pccard_function_init: function is enabled"); 452 return; 453 } 454 455 SLIST_FOREACH(rle, &devi->resources, link) { 456 if (rle->res) { 457 if (rle->res->r_dev != pf->sc->dev) 458 device_printf(pf->sc->dev, 459 "function_free: Resource still owned by " 460 "child, oops. " 461 "(type=%d, rid=%d, addr=%lx)\n", 462 rle->type, rle->rid, 463 rman_get_start(rle->res)); 464 BUS_RELEASE_RESOURCE(device_get_parent(pf->sc->dev), 465 rle->res->r_dev, rle->type, rle->rid, rle->res); 466 rle->res = NULL; 467 } 468 } 469 resource_list_free(&devi->resources); 470} 471 |
472/* Enable a PCCARD function */ |
473static int |
474pccard_function_enable(struct pccard_function *pf) 475{ 476 struct pccard_function *tmp; 477 int reg; 478 device_t dev = pf->sc->dev; 479 480 if (pf->cfe == NULL) { 481 DEVPRVERBOSE((dev, "No config entry could be allocated.\n")); 482 return (ENOMEM); 483 } 484 485 /* 486 * Increase the reference count on the socket, enabling power, if 487 * necessary. 488 */ |
489 pf->sc->sc_enabled_count++; |
490 491 if (pf->pf_flags & PFF_ENABLED) { 492 /* 493 * Don't do anything if we're already enabled. 494 */ 495 return (0); 496 } 497 498 /* 499 * it's possible for different functions' CCRs to be in the same 500 * underlying page. Check for that. 501 */ 502 STAILQ_FOREACH(tmp, &pf->sc->card.pf_head, pf_list) { 503 if ((tmp->pf_flags & PFF_ENABLED) && 504 (pf->ccr_base >= (tmp->ccr_base - tmp->pf_ccr_offset)) && 505 ((pf->ccr_base + PCCARD_CCR_SIZE) <= |
506 (tmp->ccr_base - tmp->pf_ccr_offset + 507 tmp->pf_ccr_realsize))) { |
508 pf->pf_ccrt = tmp->pf_ccrt; 509 pf->pf_ccrh = tmp->pf_ccrh; 510 pf->pf_ccr_realsize = tmp->pf_ccr_realsize; 511 512 /* 513 * pf->pf_ccr_offset = (tmp->pf_ccr_offset - 514 * tmp->ccr_base) + pf->ccr_base; 515 */ --- 87 unchanged lines hidden (view full) --- 603 pf->pf_flags |= PFF_ENABLED; 604 return (0); 605 606 bad: 607 /* 608 * Decrement the reference count, and power down the socket, if 609 * necessary. 610 */ |
611 pf->sc->sc_enabled_count--; |
612 DEVPRINTF((dev, "bad --enabled_count = %d\n", pf->sc->sc_enabled_count)); 613 614 return (1); 615} 616 617/* Disable PCCARD function. */ |
618static void |
619pccard_function_disable(struct pccard_function *pf) 620{ 621 struct pccard_function *tmp; 622 device_t dev = pf->sc->dev; 623 624 if (pf->cfe == NULL) 625 panic("pccard_function_disable: function not initialized"); 626 627 if ((pf->pf_flags & PFF_ENABLED) == 0) { 628 /* 629 * Don't do anything if we're already disabled. 630 */ 631 return; 632 } 633 634 if (pf->intr_handler != NULL) { |
635 struct pccard_ivar *devi = PCCARD_IVAR(pf->dev); 636 struct resource_list_entry *rle = 637 resource_list_find(&devi->resources, SYS_RES_IRQ, 0); 638 BUS_TEARDOWN_INTR(dev, pf->dev, rle->res, 639 pf->intr_handler_cookie); |
640 } 641 642 /* 643 * it's possible for different functions' CCRs to be in the same 644 * underlying page. Check for that. Note we mark us as disabled 645 * first to avoid matching ourself. 646 */ 647 648 pf->pf_flags &= ~PFF_ENABLED; 649 STAILQ_FOREACH(tmp, &pf->sc->card.pf_head, pf_list) { 650 if ((tmp->pf_flags & PFF_ENABLED) && 651 (pf->ccr_base >= (tmp->ccr_base - tmp->pf_ccr_offset)) && 652 ((pf->ccr_base + PCCARD_CCR_SIZE) <= |
653 (tmp->ccr_base - tmp->pf_ccr_offset + 654 tmp->pf_ccr_realsize))) |
655 break; 656 } 657 658 /* Not used by anyone else; unmap the CCR. */ 659 if (tmp == NULL) { 660 bus_release_resource(dev, SYS_RES_MEMORY, pf->ccr_rid, 661 pf->ccr_res); 662 pf->ccr_res = NULL; 663 } 664 665 /* 666 * Decrement the reference count, and power down the socket, if 667 * necessary. 668 */ |
669 pf->sc->sc_enabled_count--; |
670} 671 672#if 0 673/* XXX These functions are needed, but not like this XXX */ 674int 675pccard_io_map(struct pccard_function *pf, int width, bus_addr_t offset, 676 bus_size_t size, struct pccard_io_handle *pcihp, int *windowp) 677{ --- 101 unchanged lines hidden (view full) --- 779{ 780 struct pccard_softc *sc = PCCARD_SOFTC(dev); 781 782 sc->dev = dev; 783 sc->sc_enabled_count = 0; 784 return (bus_generic_attach(dev)); 785} 786 |
787static int 788pccard_detach(device_t dev) 789{ 790 pccard_detach_card(dev, 0); 791 return 0; 792} 793 |
794static void 795pccard_print_resources(struct resource_list *rl, const char *name, int type, 796 int count, const char *format) 797{ 798 struct resource_list_entry *rle; 799 int printed; 800 int i; 801 --- 63 unchanged lines hidden (view full) --- 865 if (type == SYS_RES_MEMORY && rid >= PCCARD_NMEM) 866 return (EINVAL); 867 if (type == SYS_RES_IRQ && rid >= PCCARD_NIRQ) 868 return (EINVAL); 869 if (type == SYS_RES_DRQ && rid >= PCCARD_NDRQ) 870 return (EINVAL); 871 872 resource_list_add(rl, type, rid, start, start + count - 1, count); |
873 if (NULL != resource_list_alloc(rl, device_get_parent(dev), dev, 874 type, &rid, start, start + count - 1, count, 0)) 875 return 0; 876 else 877 return ENOMEM; |
878} 879 880static int 881pccard_get_resource(device_t dev, device_t child, int type, int rid, 882 u_long *startp, u_long *countp) 883{ 884 struct pccard_ivar *devi = PCCARD_IVAR(child); 885 struct resource_list *rl = &devi->resources; --- 24 unchanged lines hidden (view full) --- 910 u_int32_t flags) 911{ 912 return (CARD_SET_RES_FLAGS(device_get_parent(dev), child, type, 913 rid, flags)); 914} 915 916static int 917pccard_set_memory_offset(device_t dev, device_t child, int rid, |
918 u_int32_t offset, u_int32_t *deltap) |
919 920{ 921 return (CARD_SET_MEMORY_OFFSET(device_get_parent(dev), child, rid, 922 offset, deltap)); 923} 924 925static int 926pccard_read_ivar(device_t bus, device_t child, int which, u_char *result) --- 38 unchanged lines hidden (view full) --- 965 break; 966 } 967 return (0); 968} 969 970static void 971pccard_driver_added(device_t dev, driver_t *driver) 972{ |
973 struct pccard_softc *sc = PCCARD_SOFTC(dev); 974 struct pccard_function *pf; 975 device_t child; 976 977 if (sc->sc_enabled_count == 0) { 978 CARD_REPROBE_CARD(device_get_parent(dev), dev); 979 return; 980 } 981 982 STAILQ_FOREACH(pf, &sc->card.pf_head, pf_list) { 983 if (STAILQ_EMPTY(&pf->cfe_head)) 984 continue; 985 child = pf->dev; 986 if (device_get_state(child) != DS_NOTPRESENT) 987 continue; 988 if (pccard_function_enable(pf) == 0 && 989 device_probe_and_attach(child) == 0) { 990 DEVPRINTF((sc->dev, "function %d CCR at %d " 991 "offset %x: %x %x %x %x, %x %x %x %x, %x\n", 992 pf->number, pf->pf_ccr_window, pf->pf_ccr_offset, 993 pccard_ccr_read(pf, 0x00), 994 pccard_ccr_read(pf, 0x02), pccard_ccr_read(pf, 0x04), 995 pccard_ccr_read(pf, 0x06), pccard_ccr_read(pf, 0x0A), 996 pccard_ccr_read(pf, 0x0C), pccard_ccr_read(pf, 0x0E), 997 pccard_ccr_read(pf, 0x10), pccard_ccr_read(pf, 0x12))); 998 } else { 999 pccard_function_disable(pf); 1000 } 1001 } 1002 return; |
1003} 1004 1005static struct resource * 1006pccard_alloc_resource(device_t dev, device_t child, int type, int *rid, 1007 u_long start, u_long end, u_long count, u_int flags) 1008{ |
1009 struct pccard_ivar *dinfo; 1010 struct resource_list_entry *rle = 0; 1011 int passthrough = (device_get_parent(child) != dev); |
1012 |
1013 if (passthrough) { 1014 return (BUS_ALLOC_RESOURCE(device_get_parent(dev), child, 1015 type, rid, start, end, count, flags)); 1016 } |
1017 |
1018 dinfo = device_get_ivars(child); 1019 rle = resource_list_find(&dinfo->resources, type, *rid); |
1020 |
1021 if (!rle) 1022 return NULL; /* no resource of that type/rid */ |
1023 |
1024 if (!rle->res) { 1025 device_printf(dev, "WARNING: Resource not reserved by pccard bus\n"); 1026 return NULL; 1027 } else { 1028 if (rle->res->r_dev != dev) return NULL; 1029 bus_release_resource(dev, type, *rid, rle->res); 1030 rle->res = NULL; 1031 switch(type) { 1032 case SYS_RES_IOPORT: 1033 case SYS_RES_MEMORY: 1034 if (!(flags & RF_ALIGNMENT_MASK)) 1035 flags |= rman_make_alignment_flags(rle->count); 1036 break; 1037 case SYS_RES_IRQ: 1038 flags |= RF_SHAREABLE; 1039 break; 1040 } 1041 return resource_list_alloc(&dinfo->resources, dev, child, type, 1042 rid, rle->start, rle->end, rle->count, flags); |
1043 } |
1044} 1045 1046static int 1047pccard_release_resource(device_t dev, device_t child, int type, int rid, 1048 struct resource *r) 1049{ |
1050 struct pccard_ivar *dinfo; 1051 int passthrough = (device_get_parent(child) != dev); 1052 struct resource_list_entry *rle = 0; 1053 int ret; 1054 int flags; |
1055 |
1056 if (passthrough) 1057 return BUS_RELEASE_RESOURCE(device_get_parent(dev), child, 1058 type, rid, r); |
1059 |
1060 dinfo = device_get_ivars(child); |
1061 |
1062 rle = resource_list_find(&dinfo->resources, type, rid); |
1063 |
1064 if (!rle) { 1065 device_printf(dev, "Allocated resource not found, " 1066 "%d %x %lx %lx\n", 1067 type, rid, rman_get_start(r), rman_get_size(r)); 1068 return ENOENT; |
1069 } |
1070 if (!rle->res) { 1071 device_printf(dev, "Allocated resource not recorded\n"); 1072 return ENOENT; |
1073 } 1074 |
1075 ret = BUS_RELEASE_RESOURCE(device_get_parent(dev), child, 1076 type, rid, r); 1077 switch(type) { 1078 case SYS_RES_IOPORT: 1079 case SYS_RES_MEMORY: 1080 flags = rman_make_alignment_flags(rle->count); 1081 break; 1082 case SYS_RES_IRQ: 1083 flags = RF_SHAREABLE; 1084 break; 1085 default: 1086 flags = 0; |
1087 } |
1088 rle->res = bus_alloc_resource(dev, type, &rid, 1089 rle->start, rle->end, rle->count, flags); 1090 if (rle->res == NULL) 1091 device_printf(dev, "release_resource: " 1092 "unable to reaquire resource\n"); 1093 return ret; |
1094} 1095 1096static void 1097pccard_child_detached(device_t parent, device_t dev) 1098{ 1099 struct pccard_ivar *ivar = PCCARD_IVAR(dev); |
1100 struct pccard_function *pf = ivar->fcn; |
1101 |
1102 pccard_function_disable(pf); |
1103} 1104 1105static void 1106pccard_intr(void *arg) 1107{ |
1108 struct pccard_function *pf = (struct pccard_function*) arg; 1109 int reg; 1110 1111 if (pf->intr_handler == NULL) 1112 panic("Null interrupt handler?\n"); 1113 1114 reg = pccard_ccr_read(pf, PCCARD_CCR_STATUS); 1115 if (reg & PCCARD_CCR_STATUS_INTR) { 1116 pccard_ccr_write(pf, PCCARD_CCR_STATUS, 1117 reg & ~PCCARD_CCR_STATUS_INTR); 1118 pf->intr_handler(pf->intr_handler_arg); |
1119 } 1120} 1121 1122static int 1123pccard_setup_intr(device_t dev, device_t child, struct resource *irq, 1124 int flags, driver_intr_t *intr, void *arg, void **cookiep) 1125{ 1126 struct pccard_ivar *ivar = PCCARD_IVAR(child); 1127 struct pccard_function *func = ivar->fcn; |
1128 1129 if (func->intr_handler != NULL) 1130 panic("Only one interrupt handler per function allowed\n"); 1131 |
1132 func->intr_handler = intr; 1133 func->intr_handler_arg = arg; |
1134 func->intr_handler_cookie = *cookiep; |
1135 pccard_ccr_write(func, PCCARD_CCR_OPTION, |
1136 pccard_ccr_read(func, PCCARD_CCR_OPTION) | |
1137 PCCARD_CCR_OPTION_IREQ_ENABLE); 1138 |
1139 bus_setup_intr(dev, irq, INTR_TYPE_TTY/* | INTR_FAST*/, 1140 pccard_intr, func, cookiep); |
1141 return (0); 1142} 1143 1144static int 1145pccard_teardown_intr(device_t dev, device_t child, struct resource *r, 1146 void *cookie) 1147{ 1148 struct pccard_ivar *ivar = PCCARD_IVAR(child); 1149 struct pccard_function *func = ivar->fcn; |
1150 int ret; |
1151 |
1152 pccard_ccr_write(func, PCCARD_CCR_OPTION, 1153 pccard_ccr_read(func, PCCARD_CCR_OPTION) & 1154 ~PCCARD_CCR_OPTION_IREQ_ENABLE); 1155 |
1156 ret = bus_teardown_intr(dev, r, cookie); 1157 if (ret == 0) { 1158 func->intr_handler = NULL; 1159 func->intr_handler_arg = NULL; 1160 func->intr_handler_cookie = NULL; |
1161 } |
1162 1163 return (ret); |
1164} 1165 1166static device_method_t pccard_methods[] = { 1167 /* Device interface */ 1168 DEVMETHOD(device_probe, pccard_probe), 1169 DEVMETHOD(device_attach, pccard_attach), |
1170 DEVMETHOD(device_detach, pccard_detach), |
1171 DEVMETHOD(device_shutdown, bus_generic_shutdown), 1172 DEVMETHOD(device_suspend, bus_generic_suspend), 1173 DEVMETHOD(device_resume, bus_generic_resume), 1174 1175 /* Bus interface */ 1176 DEVMETHOD(bus_print_child, pccard_print_child), 1177 DEVMETHOD(bus_driver_added, pccard_driver_added), 1178 DEVMETHOD(bus_child_detached, pccard_child_detached), 1179 DEVMETHOD(bus_alloc_resource, pccard_alloc_resource), 1180 DEVMETHOD(bus_release_resource, pccard_release_resource), |
1181 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource), 1182 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource), |
1183 DEVMETHOD(bus_setup_intr, pccard_setup_intr), 1184 DEVMETHOD(bus_teardown_intr, pccard_teardown_intr), 1185 DEVMETHOD(bus_set_resource, pccard_set_resource), 1186 DEVMETHOD(bus_get_resource, pccard_get_resource), 1187 DEVMETHOD(bus_delete_resource, pccard_delete_resource), 1188 DEVMETHOD(bus_read_ivar, pccard_read_ivar), 1189 1190 /* Card Interface */ --- 25 unchanged lines hidden --- |