pccard.c (55325) | pccard.c (55500) |
---|---|
1/* $NetBSD: pcmcia.c,v 1.13 1998/12/24 04:51:59 marc Exp $ */ | 1/* $NetBSD: pcmcia.c,v 1.13 1998/12/24 04:51:59 marc Exp $ */ |
2/* $FreeBSD: head/sys/dev/pccard/pccard.c 55325 2000-01-03 06:45:16Z imp $ */ | 2/* $FreeBSD: head/sys/dev/pccard/pccard.c 55500 2000-01-06 07:30:28Z 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 --- 31 unchanged lines hidden (view full) --- 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/pccardchip.h> 48#include <dev/pccard/pccardvar.h> 49 | 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 --- 31 unchanged lines hidden (view full) --- 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/pccardchip.h> 48#include <dev/pccard/pccardvar.h> 49 |
50#include "power_if.h" 51 52#define PCCARDDEBUG 53 |
|
50#ifdef PCCARDDEBUG | 54#ifdef PCCARDDEBUG |
51int pccard_debug = 0; | 55int pccard_debug = 1; |
52#define DPRINTF(arg) if (pccard_debug) printf arg | 56#define DPRINTF(arg) if (pccard_debug) printf arg |
57#define DEVPRINTF(arg) if (pccard_debug) device_printf arg |
|
53int pccardintr_debug = 0; 54/* this is done this way to avoid doing lots of conditionals 55 at interrupt level. */ 56#define PCCARD_CARD_INTR (pccardintr_debug?pccard_card_intrdebug:pccard_card_intr) 57#else 58#define DPRINTF(arg) | 58int pccardintr_debug = 0; 59/* this is done this way to avoid doing lots of conditionals 60 at interrupt level. */ 61#define PCCARD_CARD_INTR (pccardintr_debug?pccard_card_intrdebug:pccard_card_intr) 62#else 63#define DPRINTF(arg) |
64#define DEVPRINTF(arg) |
|
59#define PCCARD_CARD_INTR (pccard_card_intr) 60#endif 61 62#ifdef PCCARDVERBOSE 63int pccard_verbose = 1; 64#else 65int pccard_verbose = 0; 66#endif 67 68int pccard_print(void *, const char *); 69 | 65#define PCCARD_CARD_INTR (pccard_card_intr) 66#endif 67 68#ifdef PCCARDVERBOSE 69int pccard_verbose = 1; 70#else 71int pccard_verbose = 0; 72#endif 73 74int pccard_print(void *, const char *); 75 |
70static __inline void pccard_socket_enable(pccard_chipset_tag_t, 71 pccard_chipset_handle_t *); 72static __inline void pccard_socket_disable(pccard_chipset_tag_t, 73 pccard_chipset_handle_t *); 74 | |
75int pccard_card_intr(void *); 76#ifdef PCCARDDEBUG 77int pccard_card_intrdebug(void *); 78#endif 79 80/* XXX Shouldn't be touching hardware, that's a layering violation */ 81/* XXX imp */ 82int --- 19 unchanged lines hidden (view full) --- 102} 103 104int 105pccard_card_attach(device_t dev) 106{ 107 struct pccard_softc *sc = (struct pccard_softc *) 108 device_get_softc(dev); 109 struct pccard_function *pf; | 76int pccard_card_intr(void *); 77#ifdef PCCARDDEBUG 78int pccard_card_intrdebug(void *); 79#endif 80 81/* XXX Shouldn't be touching hardware, that's a layering violation */ 82/* XXX imp */ 83int --- 19 unchanged lines hidden (view full) --- 103} 104 105int 106pccard_card_attach(device_t dev) 107{ 108 struct pccard_softc *sc = (struct pccard_softc *) 109 device_get_softc(dev); 110 struct pccard_function *pf; |
110 struct pccard_attach_args paa; | |
111 int attached; 112 | 111 int attached; 112 |
113 DEVPRINTF((dev, "pccard_card_attach\n")); |
|
113 /* 114 * this is here so that when socket_enable calls gettype, trt happens 115 */ 116 STAILQ_INIT(&sc->card.pf_head); 117 | 114 /* 115 * this is here so that when socket_enable calls gettype, trt happens 116 */ 117 STAILQ_INIT(&sc->card.pf_head); 118 |
118 pccard_chip_socket_enable(sc->pct, sc->pch); | 119 DEVPRINTF((dev, "chip_socket_enable\n")); 120 POWER_ENABLE_SOCKET(device_get_parent(dev), dev); |
119 | 121 |
122 DEVPRINTF((dev, "read_cis\n")); |
|
120 pccard_read_cis(sc); 121 | 123 pccard_read_cis(sc); 124 |
122 pccard_chip_socket_disable(sc->pct, sc->pch); | 125 DEVPRINTF((dev, "chip_socket_disable\n")); 126 POWER_DISABLE_SOCKET(device_get_parent(dev), dev); |
123 | 127 |
128 DEVPRINTF((dev, "check_cis_quirks\n")); |
|
124 pccard_check_cis_quirks(dev); 125 126 /* 127 * bail now if the card has no functions, or if there was an error in 128 * the cis. 129 */ 130 131 if (sc->card.error) 132 return (1); 133 if (STAILQ_EMPTY(&sc->card.pf_head)) 134 return (1); 135 136 if (pccard_verbose) 137 pccard_print_cis(dev); 138 139 attached = 0; 140 | 129 pccard_check_cis_quirks(dev); 130 131 /* 132 * bail now if the card has no functions, or if there was an error in 133 * the cis. 134 */ 135 136 if (sc->card.error) 137 return (1); 138 if (STAILQ_EMPTY(&sc->card.pf_head)) 139 return (1); 140 141 if (pccard_verbose) 142 pccard_print_cis(dev); 143 144 attached = 0; 145 |
146 DEVPRINTF((dev, "functions scanning\n")); |
|
141 STAILQ_FOREACH(pf, &sc->card.pf_head, pf_list) { 142 if (STAILQ_EMPTY(&pf->cfe_head)) 143 continue; 144 145#ifdef DIAGNOSTIC 146 if (pf->child != NULL) { | 147 STAILQ_FOREACH(pf, &sc->card.pf_head, pf_list) { 148 if (STAILQ_EMPTY(&pf->cfe_head)) 149 continue; 150 151#ifdef DIAGNOSTIC 152 if (pf->child != NULL) { |
147 printf("%s: %s still attached to function %d!\n", 148 sc->dev.dv_xname, pf->child->dv_xname, 149 pf->number); | 153 device_printf(sc->dev, 154 "%s still attached to function %d!\n", 155 device_get_name(pf->child), pf->number); |
150 panic("pccard_card_attach"); 151 } 152#endif 153 pf->sc = sc; 154 pf->child = NULL; 155 pf->cfe = NULL; 156 pf->ih_fct = NULL; 157 pf->ih_arg = NULL; 158 } 159 160 STAILQ_FOREACH(pf, &sc->card.pf_head, pf_list) { 161 if (STAILQ_EMPTY(&pf->cfe_head)) 162 continue; 163 | 156 panic("pccard_card_attach"); 157 } 158#endif 159 pf->sc = sc; 160 pf->child = NULL; 161 pf->cfe = NULL; 162 pf->ih_fct = NULL; 163 pf->ih_arg = NULL; 164 } 165 166 STAILQ_FOREACH(pf, &sc->card.pf_head, pf_list) { 167 if (STAILQ_EMPTY(&pf->cfe_head)) 168 continue; 169 |
164 paa.manufacturer = sc->card.manufacturer; 165 paa.product = sc->card.product; 166 paa.card = &sc->card; 167 paa.pf = pf; 168 | |
169#if XXX 170 if (attach_child()) { 171 attached++; 172 | 170#if XXX 171 if (attach_child()) { 172 attached++; 173 |
173 DPRINTF(("%s: function %d CCR at %d " | 174 DEVPRINTF((sc->dev, "function %d CCR at %d " |
174 "offset %lx: %x %x %x %x, %x %x %x %x, %x\n", | 175 "offset %lx: %x %x %x %x, %x %x %x %x, %x\n", |
175 sc->dev.dv_xname, pf->number, 176 pf->pf_ccr_window, pf->pf_ccr_offset, | 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#endif 184 } --- 15 unchanged lines hidden (view full) --- 200 * We are running on either the PCCARD socket's event thread 201 * or in user context detaching a device by user request. 202 */ 203 STAILQ_FOREACH(pf, &sc->card.pf_head, pf_list) { 204 if (STAILQ_FIRST(&pf->cfe_head) == NULL) 205 continue; 206 if (pf->child == NULL) 207 continue; | 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#endif 184 } --- 15 unchanged lines hidden (view full) --- 200 * We are running on either the PCCARD socket's event thread 201 * or in user context detaching a device by user request. 202 */ 203 STAILQ_FOREACH(pf, &sc->card.pf_head, pf_list) { 204 if (STAILQ_FIRST(&pf->cfe_head) == NULL) 205 continue; 206 if (pf->child == NULL) 207 continue; |
208 DPRINTF(("%s: detaching %s (function %d)\n", 209 sc->dev.dv_xname, pf->child->dv_xname, pf->number)); | 208 DEVPRINTF((sc->dev, "detaching %s (function %d)\n", 209 device_get_name(pf->child), pf->number)); |
210#if XXX 211 if ((error = config_detach(pf->child, flags)) != 0) { | 210#if XXX 211 if ((error = config_detach(pf->child, flags)) != 0) { |
212 printf("%s: error %d detaching %s (function %d)\n", 213 sc->dev.dv_xname, error, pf->child->dv_xname, 214 pf->number); | 212 device_printf(sc->dev, 213 "error %d detaching %s (function %d)\n", 214 error, device_get_name(pf->child), pf->number); |
215 } else 216 pf->child = NULL; 217#endif 218 } 219} 220 221void 222pccard_card_deactivate(device_t dev) --- 7 unchanged lines hidden (view full) --- 230 * Deactivate the child driver. The PCCARD socket's 231 * event thread will run later to finish the detach. 232 */ 233 STAILQ_FOREACH(pf, &sc->card.pf_head, pf_list) { 234 if (STAILQ_FIRST(&pf->cfe_head) == NULL) 235 continue; 236 if (pf->child == NULL) 237 continue; | 215 } else 216 pf->child = NULL; 217#endif 218 } 219} 220 221void 222pccard_card_deactivate(device_t dev) --- 7 unchanged lines hidden (view full) --- 230 * Deactivate the child driver. The PCCARD socket's 231 * event thread will run later to finish the detach. 232 */ 233 STAILQ_FOREACH(pf, &sc->card.pf_head, pf_list) { 234 if (STAILQ_FIRST(&pf->cfe_head) == NULL) 235 continue; 236 if (pf->child == NULL) 237 continue; |
238 DPRINTF(("%s: deactivating %s (function %d)\n", 239 sc->dev.dv_xname, pf->child->dv_xname, pf->number)); | 238 DEVPRINTF((sc->dev, "deactivating %s (function %d)\n", 239 device_get_name(pf->child), pf->number)); |
240#if XXX 241 config_deactivate(pf->child); 242#endif 243 } 244} 245 246int 247pccard_card_gettype(device_t dev) --- 27 unchanged lines hidden (view full) --- 275{ 276 if (pf->pf_flags & PFF_ENABLED) 277 panic("pccard_function_init: function is enabled"); 278 279 /* Remember which configuration entry we are using. */ 280 pf->cfe = cfe; 281} 282 | 240#if XXX 241 config_deactivate(pf->child); 242#endif 243 } 244} 245 246int 247pccard_card_gettype(device_t dev) --- 27 unchanged lines hidden (view full) --- 275{ 276 if (pf->pf_flags & PFF_ENABLED) 277 panic("pccard_function_init: function is enabled"); 278 279 /* Remember which configuration entry we are using. */ 280 pf->cfe = cfe; 281} 282 |
283static __inline void pccard_socket_enable(pct, pch) 284 pccard_chipset_tag_t pct; 285 pccard_chipset_handle_t *pch; 286{ 287 pccard_chip_socket_enable(pct, pch); 288} 289 290static __inline void pccard_socket_disable(pct, pch) 291 pccard_chipset_tag_t pct; 292 pccard_chipset_handle_t *pch; 293{ 294 pccard_chip_socket_disable(pct, pch); 295} 296 | |
297/* Enable a PCCARD function */ 298int 299pccard_function_enable(pf) 300 struct pccard_function *pf; 301{ 302 struct pccard_function *tmp; 303 int reg; 304 305 if (pf->cfe == NULL) 306 panic("pccard_function_enable: function not initialized"); 307 308 /* 309 * Increase the reference count on the socket, enabling power, if 310 * necessary. 311 */ 312 if (pf->sc->sc_enabled_count++ == 0) | 283/* Enable a PCCARD function */ 284int 285pccard_function_enable(pf) 286 struct pccard_function *pf; 287{ 288 struct pccard_function *tmp; 289 int reg; 290 291 if (pf->cfe == NULL) 292 panic("pccard_function_enable: function not initialized"); 293 294 /* 295 * Increase the reference count on the socket, enabling power, if 296 * necessary. 297 */ 298 if (pf->sc->sc_enabled_count++ == 0) |
313 pccard_chip_socket_enable(pf->sc->pct, pf->sc->pch); 314 DPRINTF(("%s: ++enabled_count = %d\n", pf->sc->dev.dv_xname, 315 pf->sc->sc_enabled_count)); | 299 POWER_ENABLE_SOCKET(device_get_parent(pf->sc->dev), 300 pf->sc->dev); 301 DEVPRINTF((pf->sc->dev, "++enabled_count = %d\n", 302 pf->sc->sc_enabled_count)); |
316 317 if (pf->pf_flags & PFF_ENABLED) { 318 /* 319 * Don't do anything if we're already enabled. 320 */ 321 return (0); 322 } 323 --- 74 unchanged lines hidden (view full) --- 398 pccard_ccr_write(pf, PCCARD_CCR_IOBASE3, 0); 399 400 pccard_ccr_write(pf, PCCARD_CCR_IOSIZE, iosize); 401 } 402 403#ifdef PCCARDDEBUG 404 if (pccard_debug) { 405 STAILQ_FOREACH(tmp, &pf->sc->card.pf_head, pf_list) { | 303 304 if (pf->pf_flags & PFF_ENABLED) { 305 /* 306 * Don't do anything if we're already enabled. 307 */ 308 return (0); 309 } 310 --- 74 unchanged lines hidden (view full) --- 385 pccard_ccr_write(pf, PCCARD_CCR_IOBASE3, 0); 386 387 pccard_ccr_write(pf, PCCARD_CCR_IOSIZE, iosize); 388 } 389 390#ifdef PCCARDDEBUG 391 if (pccard_debug) { 392 STAILQ_FOREACH(tmp, &pf->sc->card.pf_head, pf_list) { |
406 printf("%s: function %d CCR at %d offset %lx: " 407 "%x %x %x %x, %x %x %x %x, %x\n", 408 tmp->sc->dev.dv_xname, tmp->number, 409 tmp->pf_ccr_window, tmp->pf_ccr_offset, 410 pccard_ccr_read(tmp, 0x00), 411 pccard_ccr_read(tmp, 0x02), 412 pccard_ccr_read(tmp, 0x04), 413 pccard_ccr_read(tmp, 0x06), 414 415 pccard_ccr_read(tmp, 0x0A), 416 pccard_ccr_read(tmp, 0x0C), 417 pccard_ccr_read(tmp, 0x0E), 418 pccard_ccr_read(tmp, 0x10), 419 420 pccard_ccr_read(tmp, 0x12)); | 393 device_printf(tmp->sc->dev, 394 "function %d CCR at %d offset %x: " 395 "%x %x %x %x, %x %x %x %x, %x\n", 396 tmp->number, tmp->pf_ccr_window, 397 tmp->pf_ccr_offset, 398 pccard_ccr_read(tmp, 0x00), 399 pccard_ccr_read(tmp, 0x02), 400 pccard_ccr_read(tmp, 0x04), 401 pccard_ccr_read(tmp, 0x06), 402 pccard_ccr_read(tmp, 0x0A), 403 pccard_ccr_read(tmp, 0x0C), 404 pccard_ccr_read(tmp, 0x0E), 405 pccard_ccr_read(tmp, 0x10), 406 pccard_ccr_read(tmp, 0x12)); |
421 } 422 } 423#endif 424 425 pf->pf_flags |= PFF_ENABLED; 426 return (0); 427 428 bad: 429 /* 430 * Decrement the reference count, and power down the socket, if 431 * necessary. 432 */ 433 if (--pf->sc->sc_enabled_count == 0) | 407 } 408 } 409#endif 410 411 pf->pf_flags |= PFF_ENABLED; 412 return (0); 413 414 bad: 415 /* 416 * Decrement the reference count, and power down the socket, if 417 * necessary. 418 */ 419 if (--pf->sc->sc_enabled_count == 0) |
434 pccard_chip_socket_disable(pf->sc->pct, pf->sc->pch); 435 DPRINTF(("%s: --enabled_count = %d\n", pf->sc->dev.dv_xname, | 420 POWER_DISABLE_SOCKET(device_get_parent(pf->sc->dev), 421 pf->sc->dev); 422 DEVPRINTF((pf->sc->dev, "--enabled_count = %d\n", |
436 pf->sc->sc_enabled_count)); 437 438 return (1); 439} 440 441/* Disable PCCARD function. */ 442void 443pccard_function_disable(pf) --- 32 unchanged lines hidden (view full) --- 476 pccard_mem_free(pf, &pf->pf_pcmh); 477 } 478 479 /* 480 * Decrement the reference count, and power down the socket, if 481 * necessary. 482 */ 483 if (--pf->sc->sc_enabled_count == 0) | 423 pf->sc->sc_enabled_count)); 424 425 return (1); 426} 427 428/* Disable PCCARD function. */ 429void 430pccard_function_disable(pf) --- 32 unchanged lines hidden (view full) --- 463 pccard_mem_free(pf, &pf->pf_pcmh); 464 } 465 466 /* 467 * Decrement the reference count, and power down the socket, if 468 * necessary. 469 */ 470 if (--pf->sc->sc_enabled_count == 0) |
484 pccard_chip_socket_disable(pf->sc->pct, pf->sc->pch); 485 DPRINTF(("%s: --enabled_count = %d\n", pf->sc->dev.dv_xname, 486 pf->sc->sc_enabled_count)); | 471 POWER_DISABLE_SOCKET(device_get_parent(pf->sc->dev), 472 pf->sc->dev); 473 DEVPRINTF((pf->sc->dev, "--enabled_count = %d\n", 474 pf->sc->sc_enabled_count)); |
487} 488 489int 490pccard_io_map(pf, width, offset, size, pcihp, windowp) 491 struct pccard_function *pf; 492 int width; 493 bus_addr_t offset; 494 bus_size_t size; --- 82 unchanged lines hidden (view full) --- 577 ihcnt = 0; 578 s = 0; /* this is only here to keep the compiler 579 happy */ 580 hiipl = 0; /* this is only here to keep the compiler 581 happy */ 582 583 STAILQ_FOREACH(pf2, &pf->sc->card.pf_head, pf_list) { 584 if (pf2->ih_fct) { | 475} 476 477int 478pccard_io_map(pf, width, offset, size, pcihp, windowp) 479 struct pccard_function *pf; 480 int width; 481 bus_addr_t offset; 482 bus_size_t size; --- 82 unchanged lines hidden (view full) --- 565 ihcnt = 0; 566 s = 0; /* this is only here to keep the compiler 567 happy */ 568 hiipl = 0; /* this is only here to keep the compiler 569 happy */ 570 571 STAILQ_FOREACH(pf2, &pf->sc->card.pf_head, pf_list) { 572 if (pf2->ih_fct) { |
585 DPRINTF(("%s: function %d has ih_fct %p\n", 586 pf->sc->dev.dv_xname, pf2->number, 587 pf2->ih_fct)); | 573 DEVPRINTF((pf2->sc->dev, 574 "function %d has ih_fct %p\n", 575 pf2->number, pf2->ih_fct)); |
588 589 if (ihcnt == 0) { 590 hiipl = pf2->ih_ipl; 591 } else { 592 if (pf2->ih_ipl > hiipl) 593 hiipl = pf2->ih_ipl; 594 } 595 --- 205 unchanged lines hidden (view full) --- 801{ 802 struct pccard_softc *sc = arg; 803 struct pccard_function *pf; 804 int reg, ret, ret2; 805 806 ret = 0; 807 808 STAILQ_FOREACH(pf, &sc->card.pf_head, pf_list) { | 576 577 if (ihcnt == 0) { 578 hiipl = pf2->ih_ipl; 579 } else { 580 if (pf2->ih_ipl > hiipl) 581 hiipl = pf2->ih_ipl; 582 } 583 --- 205 unchanged lines hidden (view full) --- 789{ 790 struct pccard_softc *sc = arg; 791 struct pccard_function *pf; 792 int reg, ret, ret2; 793 794 ret = 0; 795 796 STAILQ_FOREACH(pf, &sc->card.pf_head, pf_list) { |
809 printf("%s: intr flags=%x fct=%d cor=%02x csr=%02x pin=%02x", 810 sc->dev.dv_xname, pf->pf_flags, pf->number, 811 pccard_ccr_read(pf, PCCARD_CCR_OPTION), 812 pccard_ccr_read(pf, PCCARD_CCR_STATUS), 813 pccard_ccr_read(pf, PCCARD_CCR_PIN)); | 797 device_printf(sc->dev, 798 "intr flags=%x fct=%d cor=%02x csr=%02x pin=%02x", 799 pf->pf_flags, pf->number, 800 pccard_ccr_read(pf, PCCARD_CCR_OPTION), 801 pccard_ccr_read(pf, PCCARD_CCR_STATUS), 802 pccard_ccr_read(pf, PCCARD_CCR_PIN)); |
814 if (pf->ih_fct != NULL && 815 (pf->ccr_mask & (1 << (PCCARD_CCR_STATUS / 2)))) { 816 reg = pccard_ccr_read(pf, PCCARD_CCR_STATUS); 817 if (reg & PCCARD_CCR_STATUS_INTR) { 818 ret2 = (*pf->ih_fct)(pf->ih_arg); 819 if (ret2 != 0 && ret == 0) 820 ret = ret2; 821 reg = pccard_ccr_read(pf, PCCARD_CCR_STATUS); --- 177 unchanged lines hidden --- | 803 if (pf->ih_fct != NULL && 804 (pf->ccr_mask & (1 << (PCCARD_CCR_STATUS / 2)))) { 805 reg = pccard_ccr_read(pf, PCCARD_CCR_STATUS); 806 if (reg & PCCARD_CCR_STATUS_INTR) { 807 ret2 = (*pf->ih_fct)(pf->ih_arg); 808 if (ret2 != 0 && ret == 0) 809 ret = ret2; 810 reg = pccard_ccr_read(pf, PCCARD_CCR_STATUS); --- 177 unchanged lines hidden --- |