Deleted Added
full compact
pccard.c (70761) pccard.c (70762)
1/* $NetBSD: pcmcia.c,v 1.23 2000/07/28 19:17:02 drochner Exp $ */
1/* $NetBSD: pcmcia.c,v 1.23 2000/07/28 19:17:02 drochner Exp $ */
2/* $FreeBSD: head/sys/dev/pccard/pccard.c 70761 2001-01-07 20:36:27Z imp $ */
2/* $FreeBSD: head/sys/dev/pccard/pccard.c 70762 2001-01-07 20:40:23Z 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

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

299 */
300void
301pccard_function_init(struct pccard_function *pf)
302{
303 struct pccard_config_entry *cfe;
304 int i;
305 struct pccard_ivar *devi = PCCARD_IVAR(pf->dev);
306 struct resource_list *rl = &devi->resources;
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

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

299 */
300void
301pccard_function_init(struct pccard_function *pf)
302{
303 struct pccard_config_entry *cfe;
304 int i;
305 struct pccard_ivar *devi = PCCARD_IVAR(pf->dev);
306 struct resource_list *rl = &devi->resources;
307 struct resource_list_entry *rle;
307 struct resource *r = 0;
308 device_t bus;
309 int start;
310 int end;
311
312 if (pf->pf_flags & PFF_ENABLED) {
313 printf("pccard_function_init: function is enabled");
314 return;

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

332 cfe->iospace[i].length,
333 rman_make_alignment_flags(cfe->iospace[i].length));
334 if (cfe->iores[i] == 0)
335 goto not_this_one;
336 resource_list_add(rl, SYS_RES_IOPORT, cfe->iorid[i],
337 rman_get_start(r), rman_get_end(r),
338 cfe->iospace[i].length);
339 {
308 struct resource *r = 0;
309 device_t bus;
310 int start;
311 int end;
312
313 if (pf->pf_flags & PFF_ENABLED) {
314 printf("pccard_function_init: function is enabled");
315 return;

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

333 cfe->iospace[i].length,
334 rman_make_alignment_flags(cfe->iospace[i].length));
335 if (cfe->iores[i] == 0)
336 goto not_this_one;
337 resource_list_add(rl, SYS_RES_IOPORT, cfe->iorid[i],
338 rman_get_start(r), rman_get_end(r),
339 cfe->iospace[i].length);
340 {
340 struct resource_list_entry *rle = resource_list_find(rl, SYS_RES_IOPORT, cfe->iorid[i]);
341 rle = resource_list_find(rl, SYS_RES_IOPORT,
342 cfe->iorid[i]);
341 rle->res = r;
342 }
343 }
344 if (cfe->num_memspace > 0) {
345 goto not_this_one;
346 }
347 if (cfe->irqmask) {
348 cfe->irqrid = 0;
349 r = cfe->irqres = bus_alloc_resource(bus, SYS_RES_IRQ,
350 &cfe->irqrid, 0, ~0, 1, 0);
351 if (cfe->irqres == 0)
352 goto not_this_one;
353 resource_list_add(rl, SYS_RES_IRQ, cfe->irqrid,
354 rman_get_start(r), rman_get_end(r), 1);
355 {
343 rle->res = r;
344 }
345 }
346 if (cfe->num_memspace > 0) {
347 goto not_this_one;
348 }
349 if (cfe->irqmask) {
350 cfe->irqrid = 0;
351 r = cfe->irqres = bus_alloc_resource(bus, SYS_RES_IRQ,
352 &cfe->irqrid, 0, ~0, 1, 0);
353 if (cfe->irqres == 0)
354 goto not_this_one;
355 resource_list_add(rl, SYS_RES_IRQ, cfe->irqrid,
356 rman_get_start(r), rman_get_end(r), 1);
357 {
356 struct resource_list_entry *rle = resource_list_find(rl, SYS_RES_IRQ, cfe->irqrid);
358 rle = resource_list_find(rl, SYS_RES_IRQ,
359 cfe->irqrid);
357 rle->res = r;
358 }
359 }
360 /* XXX Don't know how to deal with maxtwins */
361 /* If we get to here, we've allocated all we need */
362 pf->cfe = cfe;
363 break;
364 not_this_one:;

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

557 pccard_ccr_read(pf, PCCARD_CCR_OPTION) &
558 ~PCCARD_CCR_OPTION_IREQ_ENABLE);
559
560 if (pf->sc->intr_handler_count == 1) {
561 struct pccard_ivar *ivar = PCCARD_IVAR(pf->dev);
562 struct resource_list_entry *rle = NULL;
563
564 pf->sc->intr_handler_count--;
360 rle->res = r;
361 }
362 }
363 /* XXX Don't know how to deal with maxtwins */
364 /* If we get to here, we've allocated all we need */
365 pf->cfe = cfe;
366 break;
367 not_this_one:;

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

560 pccard_ccr_read(pf, PCCARD_CCR_OPTION) &
561 ~PCCARD_CCR_OPTION_IREQ_ENABLE);
562
563 if (pf->sc->intr_handler_count == 1) {
564 struct pccard_ivar *ivar = PCCARD_IVAR(pf->dev);
565 struct resource_list_entry *rle = NULL;
566
567 pf->sc->intr_handler_count--;
565 rle = resource_list_find(&ivar->resources, SYS_RES_IRQ, 0);
568 rle = resource_list_find(&ivar->resources, SYS_RES_IRQ,
569 0);
566 if (rle == NULL)
567 panic("No IRQ for pccard?");
568
570 if (rle == NULL)
571 panic("No IRQ for pccard?");
572
569 bus_teardown_intr(dev, rle->res, &pf->sc->intr_handler_count);
573 bus_teardown_intr(dev, rle->res,
574 &pf->sc->intr_handler_count);
570 }
571 }
572
573 /*
574 * it's possible for different functions' CCRs to be in the same
575 * underlying page. Check for that. Note we mark us as disabled
576 * first to avoid matching ourself.
577 */

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

988{
989 struct pccard_ivar *ivar = PCCARD_IVAR(dev);
990
991 if (parent == device_get_parent(dev))
992 free(ivar, M_DEVBUF);
993}
994
995static void
575 }
576 }
577
578 /*
579 * it's possible for different functions' CCRs to be in the same
580 * underlying page. Check for that. Note we mark us as disabled
581 * first to avoid matching ourself.
582 */

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

993{
994 struct pccard_ivar *ivar = PCCARD_IVAR(dev);
995
996 if (parent == device_get_parent(dev))
997 free(ivar, M_DEVBUF);
998}
999
1000static void
996pccard_intr(void *arg) {
1001pccard_intr(void *arg)
1002{
1003 struct pccard_softc *sc = (struct pccard_softc *) arg;
997 struct pccard_function *pf;
1004 struct pccard_function *pf;
998 STAILQ_FOREACH(pf, &((struct pccard_softc*)arg)->card.pf_head, pf_list) {
1005 STAILQ_FOREACH(pf, &sc->card.pf_head, pf_list) {
999 if (pf->intr_handler != NULL) {
1000 int reg = pccard_ccr_read(pf, PCCARD_CCR_STATUS);
1001 if (reg & PCCARD_CCR_STATUS_INTR) {
1002 pccard_ccr_write(pf, PCCARD_CCR_STATUS,
1006 if (pf->intr_handler != NULL) {
1007 int reg = pccard_ccr_read(pf, PCCARD_CCR_STATUS);
1008 if (reg & PCCARD_CCR_STATUS_INTR) {
1009 pccard_ccr_write(pf, PCCARD_CCR_STATUS,
1003 reg & ~PCCARD_CCR_STATUS_INTR);
1010 reg & ~PCCARD_CCR_STATUS_INTR);
1004 pf->intr_handler(pf->intr_handler_arg);
1005 }
1006 }
1007 }
1008}
1009
1010static int
1011 pf->intr_handler(pf->intr_handler_arg);
1012 }
1013 }
1014 }
1015}
1016
1017static int
1011pccard_setup_intr(device_t dev, device_t child,
1012 struct resource *irq, int flags,
1013 driver_intr_t *intr, void *arg, void **cookiep)
1018pccard_setup_intr(device_t dev, device_t child, struct resource *irq,
1019 int flags, driver_intr_t *intr, void *arg, void **cookiep)
1014{
1015 struct pccard_ivar *ivar = PCCARD_IVAR(child);
1016 struct pccard_function *func = ivar->fcn;
1017 struct resource_list_entry *rle = NULL;
1018 struct pccard_softc *sc = device_get_softc(dev);
1019
1020 if (func->intr_handler != NULL)
1020{
1021 struct pccard_ivar *ivar = PCCARD_IVAR(child);
1022 struct pccard_function *func = ivar->fcn;
1023 struct resource_list_entry *rle = NULL;
1024 struct pccard_softc *sc = device_get_softc(dev);
1025
1026 if (func->intr_handler != NULL)
1021 panic("Only one interrupt handler per function allowed for pccard\n");
1027 panic("Only one interrupt handler per function allowed\n");
1022
1023 rle = resource_list_find(&ivar->resources, SYS_RES_IRQ, 0);
1024 if (rle == NULL || rle->res != irq)
1025 panic("irq in setup_intr does not match allocated irq\n");
1026
1027 func->intr_handler = intr;
1028 func->intr_handler_arg = arg;
1029 func->intr_handler_cookie = *cookiep = func;
1030 pccard_ccr_write(func, PCCARD_CCR_OPTION,
1028
1029 rle = resource_list_find(&ivar->resources, SYS_RES_IRQ, 0);
1030 if (rle == NULL || rle->res != irq)
1031 panic("irq in setup_intr does not match allocated irq\n");
1032
1033 func->intr_handler = intr;
1034 func->intr_handler_arg = arg;
1035 func->intr_handler_cookie = *cookiep = func;
1036 pccard_ccr_write(func, PCCARD_CCR_OPTION,
1031 pccard_ccr_read(func, PCCARD_CCR_OPTION) |
1032 PCCARD_CCR_OPTION_IREQ_ENABLE);
1037 pccard_ccr_read(func, PCCARD_CCR_OPTION) |
1038 PCCARD_CCR_OPTION_IREQ_ENABLE);
1033
1034 if (sc->intr_handler_count++ == 0) {
1035 rle = resource_list_find(&ivar->resources, SYS_RES_IRQ, 0);
1036 if (rle == NULL)
1037 panic("No IRQ for pccard?");
1038
1039 bus_setup_intr(dev, rle->res, INTR_TYPE_TTY/* | INTR_FAST*/,
1039
1040 if (sc->intr_handler_count++ == 0) {
1041 rle = resource_list_find(&ivar->resources, SYS_RES_IRQ, 0);
1042 if (rle == NULL)
1043 panic("No IRQ for pccard?");
1044
1045 bus_setup_intr(dev, rle->res, INTR_TYPE_TTY/* | INTR_FAST*/,
1040 pccard_intr, sc, (void*)&sc->intr_handler_count);
1046 pccard_intr, sc, (void*)&sc->intr_handler_count);
1041 }
1042 return 0;
1043}
1044
1045static int
1047 }
1048 return 0;
1049}
1050
1051static int
1046pccard_teardown_intr(device_t dev, device_t child, struct resource *r, void *cookie)
1052pccard_teardown_intr(device_t dev, device_t child, struct resource *r,
1053 void *cookie)
1047{
1048 struct pccard_ivar *ivar = PCCARD_IVAR(child);
1049 struct pccard_function *func = ivar->fcn;
1050 struct pccard_softc *sc = device_get_softc(dev);
1051
1052 if (func->intr_handler_cookie != cookie)
1053 panic("pccard teardown of unknown interrupt handler\n");
1054
1055 func->intr_handler = NULL;
1056 func->intr_handler_arg = NULL;
1057 func->intr_handler_cookie = NULL;
1058 pccard_ccr_write(func, PCCARD_CCR_OPTION,
1054{
1055 struct pccard_ivar *ivar = PCCARD_IVAR(child);
1056 struct pccard_function *func = ivar->fcn;
1057 struct pccard_softc *sc = device_get_softc(dev);
1058
1059 if (func->intr_handler_cookie != cookie)
1060 panic("pccard teardown of unknown interrupt handler\n");
1061
1062 func->intr_handler = NULL;
1063 func->intr_handler_arg = NULL;
1064 func->intr_handler_cookie = NULL;
1065 pccard_ccr_write(func, PCCARD_CCR_OPTION,
1059 pccard_ccr_read(func, PCCARD_CCR_OPTION) &
1060 ~PCCARD_CCR_OPTION_IREQ_ENABLE);
1066 pccard_ccr_read(func, PCCARD_CCR_OPTION) &
1067 ~PCCARD_CCR_OPTION_IREQ_ENABLE);
1061
1062 if (--sc->intr_handler_count == 0) {
1063 struct resource_list_entry *rle = NULL;
1064
1065 rle = resource_list_find(&ivar->resources, SYS_RES_IRQ, 0);
1066 if (rle == NULL)
1067 panic("No IRQ for pccard?");
1068

--- 53 unchanged lines hidden ---
1068
1069 if (--sc->intr_handler_count == 0) {
1070 struct resource_list_entry *rle = NULL;
1071
1072 rle = resource_list_find(&ivar->resources, SYS_RES_IRQ, 0);
1073 if (rle == NULL)
1074 panic("No IRQ for pccard?");
1075

--- 53 unchanged lines hidden ---