Deleted Added
full compact
pccard.c (144927) pccard.c (144930)
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:

--- 16 unchanged lines hidden (view full) ---

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>
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:

--- 16 unchanged lines hidden (view full) ---

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 144927 2005-04-12 04:30:35Z imp $");
33__FBSDID("$FreeBSD: head/sys/dev/pccard/pccard.c 144930 2005-04-12 06:00:06Z 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>
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#include <dev/pccard/pccard_cis.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");

--- 351 unchanged lines hidden (view full) ---

412 * Any resource held after pccard_function_init is called is a bug. However,
413 * the bus routines to get the resources also assume that pccard_function_init
414 * does this, so they need to be fixed too.
415 */
416static void
417pccard_function_init(struct pccard_function *pf)
418{
419 struct pccard_config_entry *cfe;
54
55#include "power_if.h"
56#include "card_if.h"
57
58#define PCCARDDEBUG
59
60/* sysctl vars */
61SYSCTL_NODE(_hw, OID_AUTO, pccard, CTLFLAG_RD, 0, "PCCARD parameters");

--- 351 unchanged lines hidden (view full) ---

413 * Any resource held after pccard_function_init is called is a bug. However,
414 * the bus routines to get the resources also assume that pccard_function_init
415 * does this, so they need to be fixed too.
416 */
417static void
418pccard_function_init(struct pccard_function *pf)
419{
420 struct pccard_config_entry *cfe;
420 int i;
421 int i, rid;
421 struct pccard_ivar *devi = PCCARD_IVAR(pf->dev);
422 struct resource_list *rl = &devi->resources;
423 struct resource_list_entry *rle;
424 struct resource *r = 0;
425 device_t bus;
426 int start;
427 int end;
428 int spaces;
429
430 if (pf->pf_flags & PFF_ENABLED) {
431 printf("pccard_function_init: function is enabled");
432 return;
433 }
434 bus = device_get_parent(pf->dev);
435 /* Remember which configuration entry we are using. */
436 STAILQ_FOREACH(cfe, &pf->cfe_head, cfe_list) {
422 struct pccard_ivar *devi = PCCARD_IVAR(pf->dev);
423 struct resource_list *rl = &devi->resources;
424 struct resource_list_entry *rle;
425 struct resource *r = 0;
426 device_t bus;
427 int start;
428 int end;
429 int spaces;
430
431 if (pf->pf_flags & PFF_ENABLED) {
432 printf("pccard_function_init: function is enabled");
433 return;
434 }
435 bus = device_get_parent(pf->dev);
436 /* Remember which configuration entry we are using. */
437 STAILQ_FOREACH(cfe, &pf->cfe_head, cfe_list) {
438 if (cfe->iftype != PCCARD_IFTYPE_IO)
439 continue;
437 for (i = 0; i < cfe->num_iospace; i++)
438 cfe->iores[i] = NULL;
440 for (i = 0; i < cfe->num_iospace; i++)
441 cfe->iores[i] = NULL;
442 for (i = 0; i < cfe->num_memspace; i++)
443 cfe->memres[i] = NULL;
439 cfe->irqres = NULL;
440 spaces = 0;
441 for (i = 0; i < cfe->num_iospace; i++) {
442 start = cfe->iospace[i].start;
443 if (start)
444 end = start + cfe->iospace[i].length - 1;
445 else
444 cfe->irqres = NULL;
445 spaces = 0;
446 for (i = 0; i < cfe->num_iospace; i++) {
447 start = cfe->iospace[i].start;
448 if (start)
449 end = start + cfe->iospace[i].length - 1;
450 else
446 end = ~0;
447 cfe->iorid[i] = i;
451 end = ~0UL;
448 DEVPRINTF((bus, "I/O rid %d start %x end %x\n",
449 i, start, end));
452 DEVPRINTF((bus, "I/O rid %d start %x end %x\n",
453 i, start, end));
454 rid = i;
450 r = cfe->iores[i] = bus_alloc_resource(bus,
455 r = cfe->iores[i] = bus_alloc_resource(bus,
451 SYS_RES_IOPORT, &cfe->iorid[i], start, end,
456 SYS_RES_IOPORT, &rid, start, end,
452 cfe->iospace[i].length,
453 rman_make_alignment_flags(cfe->iospace[i].length));
454 if (cfe->iores[i] == NULL)
455 goto not_this_one;
456 rle = resource_list_add(rl, SYS_RES_IOPORT,
457 cfe->iospace[i].length,
458 rman_make_alignment_flags(cfe->iospace[i].length));
459 if (cfe->iores[i] == NULL)
460 goto not_this_one;
461 rle = resource_list_add(rl, SYS_RES_IOPORT,
457 cfe->iorid[i], rman_get_start(r), rman_get_end(r),
462 rid, rman_get_start(r), rman_get_end(r),
458 cfe->iospace[i].length);
459 if (rle == NULL)
463 cfe->iospace[i].length);
464 if (rle == NULL)
460 panic("Cannot add resource rid %d IOPORT",
461 cfe->iorid[i]);
465 panic("Cannot add resource rid %d IOPORT", rid);
462 rle->res = r;
463 spaces++;
464 }
466 rle->res = r;
467 spaces++;
468 }
465 if (cfe->num_memspace > 0) {
466 /*
467 * Not implement yet, Fix me.
468 */
469 DEVPRINTF((bus, "Memory space not yet implemented.\n"));
469 for (i = 0; i < cfe->num_memspace; i++) {
470 start = cfe->memspace[i].hostaddr;
471 if (start)
472 end = start + cfe->memspace[i].length - 1;
473 else
474 end = ~0UL;
475 DEVPRINTF((bus, "Memory rid %d start %x end %x\n",
476 i, start, end));
477 rid = i;
478 r = cfe->memres[i] = bus_alloc_resource(bus,
479 SYS_RES_MEMORY, &rid, start, end,
480 cfe->memspace[i].length,
481 rman_make_alignment_flags(cfe->memspace[i].length));
482 if (cfe->memres[i] == NULL)
483 goto not_this_one;
484 rle = resource_list_add(rl, SYS_RES_MEMORY,
485 rid, rman_get_start(r), rman_get_end(r),
486 cfe->memspace[i].length);
487 if (rle == NULL)
488 panic("Cannot add resource rid %d MEM", rid);
489 rle->res = r;
490 spaces++;
470 }
471 if (spaces == 0) {
472 DEVPRINTF((bus, "Neither memory nor I/O mapped\n"));
473 goto not_this_one;
474 }
475 if (cfe->irqmask) {
491 }
492 if (spaces == 0) {
493 DEVPRINTF((bus, "Neither memory nor I/O mapped\n"));
494 goto not_this_one;
495 }
496 if (cfe->irqmask) {
476 cfe->irqrid = 0;
497 rid = 0;
477 r = cfe->irqres = bus_alloc_resource_any(bus,
498 r = cfe->irqres = bus_alloc_resource_any(bus,
478 SYS_RES_IRQ, &cfe->irqrid, 0);
499 SYS_RES_IRQ, &rid, 0);
479 if (cfe->irqres == NULL)
480 goto not_this_one;
500 if (cfe->irqres == NULL)
501 goto not_this_one;
481 rle = resource_list_add(rl, SYS_RES_IRQ, cfe->irqrid,
502 rle = resource_list_add(rl, SYS_RES_IRQ, rid,
482 rman_get_start(r), rman_get_end(r), 1);
483 if (rle == NULL)
503 rman_get_start(r), rman_get_end(r), 1);
504 if (rle == NULL)
484 panic("Cannot add resource rid %d IRQ",
485 cfe->irqrid);
505 panic("Cannot add resource rid %d IRQ", rid);
486 rle->res = r;
487 }
488 /* If we get to here, we've allocated all we need */
489 pf->cfe = cfe;
490 break;
491 not_this_one:;
492 DEVPRVERBOSE((bus, "Allocation failed for cfe %d\n",
493 cfe->number));
494 /*
495 * Release resources that we partially allocated
496 * from this config entry.
497 */
498 for (i = 0; i < cfe->num_iospace; i++) {
506 rle->res = r;
507 }
508 /* If we get to here, we've allocated all we need */
509 pf->cfe = cfe;
510 break;
511 not_this_one:;
512 DEVPRVERBOSE((bus, "Allocation failed for cfe %d\n",
513 cfe->number));
514 /*
515 * Release resources that we partially allocated
516 * from this config entry.
517 */
518 for (i = 0; i < cfe->num_iospace; i++) {
499 if (cfe->iores[i] != NULL) {
500 bus_release_resource(bus, SYS_RES_IOPORT,
501 cfe->iorid[i], cfe->iores[i]);
502 rle = resource_list_find(rl, SYS_RES_IOPORT,
503 cfe->iorid[i]);
504 rle->res = NULL;
505 resource_list_delete(rl, SYS_RES_IOPORT,
506 cfe->iorid[i]);
507 }
519 r = cfe->iores[i];
520 if (r == NULL)
521 continue;
522 rid = rman_get_rid(r);
523 bus_release_resource(bus, SYS_RES_IOPORT, rid, r);
524 rle = resource_list_find(rl, SYS_RES_IOPORT, rid);
525 rle->res = NULL;
526 resource_list_delete(rl, SYS_RES_IOPORT, rid);
508 cfe->iores[i] = NULL;
509 }
527 cfe->iores[i] = NULL;
528 }
529 for (i = 0; i < cfe->num_memspace; i++) {
530 r = cfe->memres[i];
531 if (r == NULL)
532 continue;
533 rid = rman_get_rid(r);
534 bus_release_resource(bus, SYS_RES_MEMORY, rid, r);
535 rle = resource_list_find(rl, SYS_RES_MEMORY, rid);
536 rle->res = NULL;
537 resource_list_delete(rl, SYS_RES_MEMORY, rid);
538 cfe->memres[i] = NULL;
539 }
510 if (cfe->irqmask && cfe->irqres != NULL) {
540 if (cfe->irqmask && cfe->irqres != NULL) {
511 bus_release_resource(bus, SYS_RES_IRQ,
512 cfe->irqrid, cfe->irqres);
513 rle = resource_list_find(rl, SYS_RES_IRQ,
514 cfe->irqrid);
541 r = cfe->irqres;
542 rid = rman_get_rid(r);
543 bus_release_resource(bus, SYS_RES_IRQ, rid, r);
544 rle = resource_list_find(rl, SYS_RES_IRQ, rid);
515 rle->res = NULL;
545 rle->res = NULL;
516 resource_list_delete(rl, SYS_RES_IRQ, cfe->irqrid);
546 resource_list_delete(rl, SYS_RES_IRQ, rid);
517 cfe->irqres = NULL;
518 }
519 }
520}
521
522/*
523 * Free resources allocated by pccard_function_init(), May be called as long
524 * as the function is disabled.

--- 860 unchanged lines hidden ---
547 cfe->irqres = NULL;
548 }
549 }
550}
551
552/*
553 * Free resources allocated by pccard_function_init(), May be called as long
554 * as the function is disabled.

--- 860 unchanged lines hidden ---