pccard.c (67187) | pccard.c (67242) |
---|---|
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 67187 2000-10-16 07:51:12Z imp $ */ | 2/* $FreeBSD: head/sys/dev/pccard/pccard.c 67242 2000-10-17 06:29:21Z 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 --- 281 unchanged lines hidden (view full) --- 292 * Initialize a PCCARD function. May be called as long as the function is 293 * disabled. 294 */ 295void 296pccard_function_init(struct pccard_function *pf) 297{ 298 struct pccard_config_entry *cfe; 299 int i; | 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 --- 281 unchanged lines hidden (view full) --- 292 * Initialize a PCCARD function. May be called as long as the function is 293 * disabled. 294 */ 295void 296pccard_function_init(struct pccard_function *pf) 297{ 298 struct pccard_config_entry *cfe; 299 int i; |
300 struct pccard_ivar *devi = PCCARD_IVAR(pf->dev); 301 struct resource_list *rl = &devi->resources; 302 struct resource *r = 0; 303 device_t bus; |
|
300 301 if (pf->pf_flags & PFF_ENABLED) 302 panic("pccard_function_init: function is enabled"); 303 | 304 305 if (pf->pf_flags & PFF_ENABLED) 306 panic("pccard_function_init: function is enabled"); 307 |
308 bus = device_get_parent(pf->dev); |
|
304 /* Remember which configuration entry we are using. */ 305 for (cfe = STAILQ_FIRST(&pf->cfe_head); cfe != NULL; 306 cfe = STAILQ_NEXT(cfe, cfe_list)) { 307 for (i = 0; i < cfe->num_iospace; i++) 308 cfe->iores[i] = NULL; 309 cfe->irqres = NULL; 310 for (i = 0; i < cfe->num_iospace; i++) { 311 /* XXX kludge, need to not ignore start */ 312 /* XXX start is a hint here, so this would break */ 313 /* XXX modems */ | 309 /* Remember which configuration entry we are using. */ 310 for (cfe = STAILQ_FIRST(&pf->cfe_head); cfe != NULL; 311 cfe = STAILQ_NEXT(cfe, cfe_list)) { 312 for (i = 0; i < cfe->num_iospace; i++) 313 cfe->iores[i] = NULL; 314 cfe->irqres = NULL; 315 for (i = 0; i < cfe->num_iospace; i++) { 316 /* XXX kludge, need to not ignore start */ 317 /* XXX start is a hint here, so this would break */ 318 /* XXX modems */ |
319 /* XXX ALSO: should just ask for the range 0 to */ 320 /* XXX 1 << decode bits - 1, so we have a layering */ 321 /* XXX violation now */ |
|
314 cfe->iorid[i] = i; | 322 cfe->iorid[i] = i; |
315 cfe->iores[i] = bus_alloc_resource(pf->dev, 316 SYS_RES_IOPORT, &cfe->iorid[i], 0x300, 0x3ff, | 323 r = cfe->iores[i] = bus_alloc_resource(bus, 324 SYS_RES_IOPORT, &cfe->iorid[i], 0x100, 0x3ff, |
317 cfe->iospace[i].length, 0); 318 if (cfe->iores[i] == 0) 319 goto not_this_one; | 325 cfe->iospace[i].length, 0); 326 if (cfe->iores[i] == 0) 327 goto not_this_one; |
328 resource_list_add(rl, SYS_RES_IOPORT, cfe->iorid[i], 329 rman_get_start(r), rman_get_end(r), 330 cfe->iospace[i].length); |
|
320 321 } 322 if (cfe->num_memspace > 0) { 323 goto not_this_one; 324 } 325 if (cfe->irqmask) { 326 cfe->irqrid = 0; | 331 332 } 333 if (cfe->num_memspace > 0) { 334 goto not_this_one; 335 } 336 if (cfe->irqmask) { 337 cfe->irqrid = 0; |
327 cfe->irqres = bus_alloc_resource(pf->dev, SYS_RES_IRQ, | 338 cfe->irqres = bus_alloc_resource(bus, SYS_RES_IRQ, |
328 &cfe->irqrid, 10, 12, 1, 0); 329 if (cfe->irqres == 0) 330 goto not_this_one; | 339 &cfe->irqrid, 10, 12, 1, 0); 340 if (cfe->irqres == 0) 341 goto not_this_one; |
342 resource_list_add(rl, SYS_RES_IRQ, cfe->irqrid, 343 rman_get_start(r), rman_get_end(r), 1); |
|
331 } 332 /* XXX Don't know how to deal with maxtwins */ 333 /* If we get to here, we've allocated all we need */ 334 pf->cfe = cfe; 335 break; 336 not_this_one:; 337 for (i = 0; i < cfe->num_iospace; i++) { | 344 } 345 /* XXX Don't know how to deal with maxtwins */ 346 /* If we get to here, we've allocated all we need */ 347 pf->cfe = cfe; 348 break; 349 not_this_one:; 350 for (i = 0; i < cfe->num_iospace; i++) { |
351 resource_list_delete(rl, SYS_RES_IOPORT, i); |
|
338 if (cfe->iores[i]) | 352 if (cfe->iores[i]) |
339 bus_release_resource(pf->dev, SYS_RES_IOPORT, | 353 bus_release_resource(bus, SYS_RES_IOPORT, |
340 cfe->iorid[i], cfe->iores[i]); 341 cfe->iores[i] = NULL; 342 } 343 if (cfe->irqmask && cfe->irqres) { | 354 cfe->iorid[i], cfe->iores[i]); 355 cfe->iores[i] = NULL; 356 } 357 if (cfe->irqmask && cfe->irqres) { |
344 bus_release_resource(pf->dev, SYS_RES_IRQ, | 358 resource_list_delete(rl, SYS_RES_IRQ, cfe->irqrid); 359 bus_release_resource(bus, SYS_RES_IRQ, |
345 cfe->irqrid, cfe->irqres); 346 cfe->irqres = NULL; 347 } 348 } 349} 350 351/* Enable a PCCARD function */ 352int --- 482 unchanged lines hidden (view full) --- 835 /* 836 * XXX eventually we need to attach stuff when we know we 837 * XXX have kids. For now we do nothing because we normally 838 * XXX add children ourselves. We don't want to necessarily 839 * XXX force a reprobe. 840 */ 841} 842 | 360 cfe->irqrid, cfe->irqres); 361 cfe->irqres = NULL; 362 } 363 } 364} 365 366/* Enable a PCCARD function */ 367int --- 482 unchanged lines hidden (view full) --- 850 /* 851 * XXX eventually we need to attach stuff when we know we 852 * XXX have kids. For now we do nothing because we normally 853 * XXX add children ourselves. We don't want to necessarily 854 * XXX force a reprobe. 855 */ 856} 857 |
858static struct resource * 859pccard_alloc_resource(device_t dev, device_t child, int type, int *rid, 860 u_long start, u_long end, u_long count, u_int flags) 861{ 862 struct pccard_ivar *ivar; 863 struct pccard_function *pf; 864 865 if (device_get_parent(child) == dev) { 866 ivar = PCCARD_IVAR(child); 867 pf = ivar->fcn; 868 switch (type) { 869 case SYS_RES_IRQ: 870 if (*rid > 0) 871 return NULL; 872 return (pf->cfe->irqres); 873 case SYS_RES_IOPORT: 874 if (*rid > 3) /* XXX */ 875 return NULL; 876 return (pf->cfe->iores[*rid]); 877 } 878 } 879 return (bus_generic_alloc_resource(dev, child, type, rid, start, 880 end, count, flags)); 881} 882 883static int 884pccard_release_resource(device_t dev, device_t child, int type, int rid, 885 struct resource *r) 886{ 887 return bus_generic_release_resource(dev, child, type, rid, r); 888} 889 890static int 891pccard_activate_resource(device_t dev, device_t child, int type, int rid, 892 struct resource *r) 893{ 894 /* XXX need to write to the COR to activate this */ 895 return (bus_generic_activate_resource(dev, child, type, rid, r)); 896} 897 898static int 899pccard_deactivate_resource(device_t dev, device_t child, int type, int rid, 900 struct resource *r) 901{ 902 /* XXX need to write to the COR to deactivate this */ 903 return (bus_generic_deactivate_resource(dev, child, type, rid, r)); 904} 905 |
|
843static device_method_t pccard_methods[] = { 844 /* Device interface */ 845 DEVMETHOD(device_probe, pccard_probe), 846 DEVMETHOD(device_attach, pccard_attach), 847 DEVMETHOD(device_detach, bus_generic_detach), 848 DEVMETHOD(device_shutdown, bus_generic_shutdown), 849 DEVMETHOD(device_suspend, bus_generic_suspend), 850 DEVMETHOD(device_resume, bus_generic_resume), 851 852 /* Bus interface */ 853 DEVMETHOD(bus_print_child, pccard_print_child), 854 DEVMETHOD(bus_driver_added, pccard_driver_added), | 906static device_method_t pccard_methods[] = { 907 /* Device interface */ 908 DEVMETHOD(device_probe, pccard_probe), 909 DEVMETHOD(device_attach, pccard_attach), 910 DEVMETHOD(device_detach, bus_generic_detach), 911 DEVMETHOD(device_shutdown, bus_generic_shutdown), 912 DEVMETHOD(device_suspend, bus_generic_suspend), 913 DEVMETHOD(device_resume, bus_generic_resume), 914 915 /* Bus interface */ 916 DEVMETHOD(bus_print_child, pccard_print_child), 917 DEVMETHOD(bus_driver_added, pccard_driver_added), |
855 DEVMETHOD(bus_alloc_resource, bus_generic_alloc_resource), 856 DEVMETHOD(bus_release_resource, bus_generic_release_resource), 857 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource), 858 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource), | 918 DEVMETHOD(bus_alloc_resource, pccard_alloc_resource), 919 DEVMETHOD(bus_release_resource, pccard_release_resource), 920 DEVMETHOD(bus_activate_resource, pccard_activate_resource), 921 DEVMETHOD(bus_deactivate_resource, pccard_deactivate_resource), |
859 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr), 860 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr), 861 DEVMETHOD(bus_set_resource, pccard_set_resource), 862 DEVMETHOD(bus_get_resource, pccard_get_resource), 863 DEVMETHOD(bus_delete_resource, pccard_delete_resource), 864 DEVMETHOD(bus_read_ivar, pccard_read_ivar), 865 866 /* Card Interface */ --- 23 unchanged lines hidden --- | 922 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr), 923 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr), 924 DEVMETHOD(bus_set_resource, pccard_set_resource), 925 DEVMETHOD(bus_get_resource, pccard_get_resource), 926 DEVMETHOD(bus_delete_resource, pccard_delete_resource), 927 DEVMETHOD(bus_read_ivar, pccard_read_ivar), 928 929 /* Card Interface */ --- 23 unchanged lines hidden --- |