@@ -60,43 +60,60 @@ struct resource *pcmcia_find_mem_region(u_long base, u_long num, u_long align,
6060 *
6161 * Special stuff for managing IO windows, because they are scarce
6262 */
63-
64- static int alloc_io_space (struct pcmcia_socket * s , u_int attr ,
65- unsigned int * base , unsigned int num , u_int lines )
63+ static int alloc_io_space (struct pcmcia_socket * s , struct resource * res ,
64+ unsigned int lines )
6665{
6766 unsigned int align ;
67+ unsigned int base = res -> start ;
68+ unsigned int num = res -> end ;
69+ int ret ;
70+
71+ res -> flags |= IORESOURCE_IO ;
6872
69- align = (* base ) ? (lines ? 1 <<lines : 0 ) : 1 ;
73+ dev_dbg (& s -> dev , "alloc_io_space request for %pR\n" , res );
74+
75+ align = base ? (lines ? 1 <<lines : 0 ) : 1 ;
7076 if (align && (align < num )) {
71- if (* base ) {
72- dev_dbg (& s -> dev , "odd IO request: num %#x align %#x\n" ,
73- num , align );
77+ if (base ) {
78+ dev_dbg (& s -> dev , "odd IO request\n" );
7479 align = 0 ;
7580 } else
7681 while (align && (align < num ))
7782 align <<= 1 ;
7883 }
79- if (* base & ~(align - 1 )) {
80- dev_dbg (& s -> dev , "odd IO request: base %#x align %#x\n" ,
81- * base , align );
84+ if (base & ~(align - 1 )) {
85+ dev_dbg (& s -> dev , "odd IO request\n" );
8286 align = 0 ;
8387 }
8488
85- return s -> resource_ops -> find_io (s , attr , base , num , align );
89+ ret = s -> resource_ops -> find_io (s , res -> flags , & base , num , align );
90+ if (ret ) {
91+ dev_dbg (& s -> dev , "alloc_io_space request returned %d" , ret );
92+ return - EINVAL ;
93+ }
94+
95+ res -> start = base ;
96+ res -> end = res -> start + num - 1 ;
97+ dev_dbg (& s -> dev , "alloc_io_space request returned %pR, %d\n" , res , ret );
98+ return 0 ;
8699} /* alloc_io_space */
87100
88101
89- static void release_io_space (struct pcmcia_socket * s , unsigned int base ,
90- unsigned int num )
102+ static void release_io_space (struct pcmcia_socket * s , struct resource * res )
91103{
104+ resource_size_t num = resource_size (res );
92105 int i ;
93106
107+ dev_dbg (& s -> dev , "release_io_space for %pR\n" , res );
108+
94109 for (i = 0 ; i < MAX_IO_WIN ; i ++ ) {
95110 if (!s -> io [i ].res )
96111 continue ;
97- if ((s -> io [i ].res -> start <= base ) &&
98- (s -> io [i ].res -> end >= base + num - 1 )) {
112+ if ((s -> io [i ].res -> start <= res -> start ) &&
113+ (s -> io [i ].res -> end >= res -> end )) {
99114 s -> io [i ].InUse -= num ;
115+ res -> start = res -> end = 0 ;
116+ res -> flags = IORESOURCE_IO ;
100117 /* Free the window if no one else is using it */
101118 if (s -> io [i ].InUse == 0 ) {
102119 release_resource (s -> io [i ].res );
@@ -329,31 +346,25 @@ int pcmcia_release_configuration(struct pcmcia_device *p_dev)
329346 * don't bother checking the port ranges against the current socket
330347 * values.
331348 */
332- static int pcmcia_release_io (struct pcmcia_device * p_dev , io_req_t * req )
349+ static int pcmcia_release_io (struct pcmcia_device * p_dev )
333350{
334351 struct pcmcia_socket * s = p_dev -> socket ;
335352 int ret = - EINVAL ;
336353 config_t * c ;
337354
338355 mutex_lock (& s -> ops_mutex );
339- c = p_dev -> function_config ;
340-
341356 if (!p_dev -> _io )
342357 goto out ;
343358
344- p_dev -> _io = 0 ;
359+ c = p_dev -> function_config ;
345360
346- if ((c -> io .BasePort1 != req -> BasePort1 ) ||
347- (c -> io .NumPorts1 != req -> NumPorts1 ) ||
348- (c -> io .BasePort2 != req -> BasePort2 ) ||
349- (c -> io .NumPorts2 != req -> NumPorts2 ))
350- goto out ;
361+ release_io_space (s , & c -> io [0 ]);
351362
352- c -> state &= ~CONFIG_IO_REQ ;
363+ if (c -> io [1 ].end )
364+ release_io_space (s , & c -> io [1 ]);
353365
354- release_io_space (s , req -> BasePort1 , req -> NumPorts1 );
355- if (req -> NumPorts2 )
356- release_io_space (s , req -> BasePort2 , req -> NumPorts2 );
366+ p_dev -> _io = 0 ;
367+ c -> state &= ~CONFIG_IO_REQ ;
357368
358369out :
359370 mutex_unlock (& s -> ops_mutex );
@@ -486,13 +497,13 @@ int pcmcia_request_configuration(struct pcmcia_device *p_dev,
486497 pcmcia_write_cis_mem (s , 1 , (base + CISREG_ESR )>>1 , 1 , & c -> ExtStatus );
487498 }
488499 if (req -> Present & PRESENT_IOBASE_0 ) {
489- u_char b = c -> io . BasePort1 & 0xff ;
500+ u8 b = c -> io [ 0 ]. start & 0xff ;
490501 pcmcia_write_cis_mem (s , 1 , (base + CISREG_IOBASE_0 )>>1 , 1 , & b );
491- b = (c -> io . BasePort1 >> 8 ) & 0xff ;
502+ b = (c -> io [ 0 ]. start >> 8 ) & 0xff ;
492503 pcmcia_write_cis_mem (s , 1 , (base + CISREG_IOBASE_1 )>>1 , 1 , & b );
493504 }
494505 if (req -> Present & PRESENT_IOSIZE ) {
495- u_char b = c -> io . NumPorts1 + c -> io . NumPorts2 - 1 ;
506+ u8 b = resource_size ( & c -> io [ 0 ]) + resource_size ( & c -> io [ 1 ]) - 1 ;
496507 pcmcia_write_cis_mem (s , 1 , (base + CISREG_IOSIZE )>>1 , 1 , & b );
497508 }
498509
@@ -526,28 +537,42 @@ int pcmcia_request_configuration(struct pcmcia_device *p_dev,
526537EXPORT_SYMBOL (pcmcia_request_configuration );
527538
528539
529- /** pcmcia_request_io
540+ /**
541+ * pcmcia_request_io() - attempt to reserve port ranges for PCMCIA devices
542+ *
543+ * pcmcia_request_io() attepts to reserve the IO port ranges specified in
544+ * struct pcmcia_device *p_dev->resource[0] and *p_dev->resource[1]. The
545+ * "start" value is the requested start of the IO port resource; "end"
546+ * relfects the number of ports requested.
530547 *
531- * Request_io() reserves ranges of port addresses for a socket.
532- * I have not implemented range sharing or alias addressing.
548+ * If io_req_t is passed, those values are converted automatically.
533549 */
534550int pcmcia_request_io (struct pcmcia_device * p_dev , io_req_t * req )
535551{
536552 struct pcmcia_socket * s = p_dev -> socket ;
537553 config_t * c ;
538554 int ret = - EINVAL ;
555+ unsigned int lines = req -> IOAddrLines ;
539556
540557 mutex_lock (& s -> ops_mutex );
541558
542559 if (!(s -> state & SOCKET_PRESENT )) {
543- dev_dbg (& s -> dev , "No card present\n" );
560+ dev_dbg (& s -> dev , "pcmcia_request_io: No card present\n" );
544561 goto out ;
545562 }
546563
547- if (!req )
548- goto out ;
549-
550564 c = p_dev -> function_config ;
565+ if (req ) {
566+ c -> io [0 ].start = req -> BasePort1 ;
567+ c -> io [0 ].end = req -> NumPorts1 ;
568+ c -> io [0 ].flags |= req -> Attributes1 ;
569+ c -> io [1 ].start = req -> BasePort2 ;
570+ c -> io [1 ].end = req -> NumPorts2 ;
571+ c -> io [1 ].flags |= req -> Attributes2 ;
572+ }
573+
574+ dev_dbg (& s -> dev , "pcmcia_request_io: %pR , %pR" , & c -> io [0 ], & c -> io [1 ]);
575+
551576 if (c -> state & CONFIG_LOCKED ) {
552577 dev_dbg (& s -> dev , "Configuration is locked\n" );
553578 goto out ;
@@ -556,40 +581,30 @@ int pcmcia_request_io(struct pcmcia_device *p_dev, io_req_t *req)
556581 dev_dbg (& s -> dev , "IO already configured\n" );
557582 goto out ;
558583 }
559- if (req -> Attributes1 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS )) {
560- dev_dbg (& s -> dev , "bad attribute setting for IO region 1\n" );
561- goto out ;
562- }
563- if ((req -> NumPorts2 > 0 ) &&
564- (req -> Attributes2 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS ))) {
565- dev_dbg (& s -> dev , "bad attribute setting for IO region 2\n" );
566- goto out ;
567- }
568584
569- dev_dbg (& s -> dev , "trying to allocate resource 1\n" );
570- ret = alloc_io_space (s , req -> Attributes1 , & req -> BasePort1 ,
571- req -> NumPorts1 , req -> IOAddrLines );
572- if (ret ) {
573- dev_dbg (& s -> dev , "allocation of resource 1 failed\n" );
585+ ret = alloc_io_space (s , & c -> io [0 ], lines );
586+ if (ret )
574587 goto out ;
575- }
576588
577- if (req -> NumPorts2 ) {
578- dev_dbg (& s -> dev , "trying to allocate resource 2\n" );
579- ret = alloc_io_space (s , req -> Attributes2 , & req -> BasePort2 ,
580- req -> NumPorts2 , req -> IOAddrLines );
589+ if (c -> io [1 ].end ) {
590+ ret = alloc_io_space (s , & c -> io [1 ], lines );
581591 if (ret ) {
582- dev_dbg (& s -> dev , "allocation of resource 2 failed\n" );
583- release_io_space (s , req -> BasePort1 , req -> NumPorts1 );
592+ release_io_space (s , & c -> io [0 ]);
584593 goto out ;
585594 }
586- }
595+ } else
596+ c -> io [1 ].start = 0 ;
587597
588- c -> io = * req ;
589598 c -> state |= CONFIG_IO_REQ ;
590599 p_dev -> _io = 1 ;
591- dev_dbg (& s -> dev , "allocating resources succeeded: %d\n" , ret );
592600
601+ if (!ret ) {
602+ req -> BasePort1 = c -> io [0 ].start ;
603+ req -> BasePort2 = c -> io [1 ].start ;
604+ }
605+
606+ dev_dbg (& s -> dev , "pcmcia_request_io succeeded: %pR , %pR" ,
607+ & c -> io [0 ], & c -> io [1 ]);
593608out :
594609 mutex_unlock (& s -> ops_mutex );
595610
@@ -869,7 +884,7 @@ EXPORT_SYMBOL(pcmcia_request_window);
869884void pcmcia_disable_device (struct pcmcia_device * p_dev )
870885{
871886 pcmcia_release_configuration (p_dev );
872- pcmcia_release_io (p_dev , & p_dev -> io );
887+ pcmcia_release_io (p_dev );
873888 if (p_dev -> _irq ) {
874889 free_irq (p_dev -> irq , p_dev -> priv );
875890 p_dev -> _irq = 0 ;
0 commit comments