2 * PCMCIA 16-bit resource management functions
4 * The initial developer of the original code is David A. Hinds
5 * <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
6 * are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
8 * Copyright (C) 1999 David A. Hinds
9 * Copyright (C) 2004-2005 Dominik Brodowski
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
17 #include <linux/module.h>
18 #include <linux/kernel.h>
19 #include <linux/interrupt.h>
20 #include <linux/delay.h>
21 #include <linux/pci.h>
22 #include <linux/device.h>
23 #include <linux/netdevice.h>
24 #include <linux/slab.h>
28 #include <pcmcia/ss.h>
29 #include <pcmcia/cs.h>
30 #include <pcmcia/cistpl.h>
31 #include <pcmcia/cisreg.h>
32 #include <pcmcia/ds.h>
34 #include "cs_internal.h"
37 /* Access speed for IO windows */
39 module_param(io_speed
, int, 0444);
42 int pcmcia_validate_mem(struct pcmcia_socket
*s
)
44 if (s
->resource_ops
->validate_mem
)
45 return s
->resource_ops
->validate_mem(s
);
46 /* if there is no callback, we can assume that everything is OK */
50 struct resource
*pcmcia_find_mem_region(u_long base
, u_long num
, u_long align
,
51 int low
, struct pcmcia_socket
*s
)
53 if (s
->resource_ops
->find_mem
)
54 return s
->resource_ops
->find_mem(base
, num
, align
, low
, s
);
59 static void release_io_space(struct pcmcia_socket
*s
, struct resource
*res
)
61 resource_size_t num
= resource_size(res
);
64 dev_dbg(&s
->dev
, "release_io_space for %pR\n", res
);
66 for (i
= 0; i
< MAX_IO_WIN
; i
++) {
69 if ((s
->io
[i
].res
->start
<= res
->start
) &&
70 (s
->io
[i
].res
->end
>= res
->end
)) {
71 s
->io
[i
].InUse
-= num
;
73 release_resource(res
);
74 res
->start
= res
->end
= 0;
75 res
->flags
= IORESOURCE_IO
;
76 /* Free the window if no one else is using it */
77 if (s
->io
[i
].InUse
== 0) {
78 release_resource(s
->io
[i
].res
);
84 } /* release_io_space */
88 * Special stuff for managing IO windows, because they are scarce
90 static int alloc_io_space(struct pcmcia_socket
*s
, struct resource
*res
,
94 unsigned int base
= res
->start
;
95 unsigned int num
= res
->end
;
98 res
->flags
|= IORESOURCE_IO
;
100 dev_dbg(&s
->dev
, "alloc_io_space request for %pR, %d lines\n",
103 align
= base
? (lines
? 1<<lines
: 0) : 1;
104 if (align
&& (align
< num
)) {
106 dev_dbg(&s
->dev
, "odd IO request\n");
109 while (align
&& (align
< num
))
112 if (base
& ~(align
-1)) {
113 dev_dbg(&s
->dev
, "odd IO request\n");
117 ret
= s
->resource_ops
->find_io(s
, res
->flags
, &base
, num
, align
,
120 dev_dbg(&s
->dev
, "alloc_io_space request failed (%d)\n", ret
);
125 res
->end
= res
->start
+ num
- 1;
128 ret
= request_resource(res
->parent
, res
);
131 "request_resource %pR failed: %d\n", res
, ret
);
133 release_io_space(s
, res
);
136 dev_dbg(&s
->dev
, "alloc_io_space request result %d: %pR\n", ret
, res
);
138 } /* alloc_io_space */
142 * pcmcia_access_config() - read or write card configuration registers
144 * pcmcia_access_config() reads and writes configuration registers in
145 * attribute memory. Memory window 0 is reserved for this and the tuple
146 * reading services. Drivers must use pcmcia_read_config_byte() or
147 * pcmcia_write_config_byte().
149 static int pcmcia_access_config(struct pcmcia_device
*p_dev
,
150 off_t where
, u8
*val
,
151 int (*accessf
) (struct pcmcia_socket
*s
,
152 int attr
, unsigned int addr
,
153 unsigned int len
, void *ptr
))
155 struct pcmcia_socket
*s
;
162 mutex_lock(&s
->ops_mutex
);
163 c
= p_dev
->function_config
;
165 if (!(c
->state
& CONFIG_LOCKED
)) {
166 dev_dbg(&s
->dev
, "Configuration isnt't locked\n");
167 mutex_unlock(&s
->ops_mutex
);
171 addr
= (c
->ConfigBase
+ where
) >> 1;
173 ret
= accessf(s
, 1, addr
, 1, val
);
175 mutex_unlock(&s
->ops_mutex
);
178 } /* pcmcia_access_config */
182 * pcmcia_read_config_byte() - read a byte from a card configuration register
184 * pcmcia_read_config_byte() reads a byte from a configuration register in
187 int pcmcia_read_config_byte(struct pcmcia_device
*p_dev
, off_t where
, u8
*val
)
189 return pcmcia_access_config(p_dev
, where
, val
, pcmcia_read_cis_mem
);
191 EXPORT_SYMBOL(pcmcia_read_config_byte
);
195 * pcmcia_write_config_byte() - write a byte to a card configuration register
197 * pcmcia_write_config_byte() writes a byte to a configuration register in
200 int pcmcia_write_config_byte(struct pcmcia_device
*p_dev
, off_t where
, u8 val
)
202 return pcmcia_access_config(p_dev
, where
, &val
, pcmcia_write_cis_mem
);
204 EXPORT_SYMBOL(pcmcia_write_config_byte
);
207 int pcmcia_map_mem_page(struct pcmcia_device
*p_dev
, window_handle_t wh
,
210 struct pcmcia_socket
*s
= p_dev
->socket
;
211 struct resource
*res
= wh
;
215 w
= ((res
->flags
& IORESOURCE_BITS
& WIN_FLAGS_REQ
) >> 2) - 1;
219 mutex_lock(&s
->ops_mutex
);
220 s
->win
[w
].card_start
= offset
;
221 ret
= s
->ops
->set_mem_map(s
, &s
->win
[w
]);
223 dev_warn(&s
->dev
, "failed to set_mem_map\n");
224 mutex_unlock(&s
->ops_mutex
);
226 } /* pcmcia_map_mem_page */
227 EXPORT_SYMBOL(pcmcia_map_mem_page
);
230 /** pcmcia_modify_configuration
232 * Modify a locked socket configuration
234 int pcmcia_modify_configuration(struct pcmcia_device
*p_dev
,
237 struct pcmcia_socket
*s
;
243 mutex_lock(&s
->ops_mutex
);
244 c
= p_dev
->function_config
;
246 if (!(s
->state
& SOCKET_PRESENT
)) {
247 dev_dbg(&s
->dev
, "No card present\n");
251 if (!(c
->state
& CONFIG_LOCKED
)) {
252 dev_dbg(&s
->dev
, "Configuration isnt't locked\n");
257 if (mod
->Attributes
& (CONF_IRQ_CHANGE_VALID
| CONF_VCC_CHANGE_VALID
)) {
259 "changing Vcc or IRQ is not allowed at this time\n");
264 /* We only allow changing Vpp1 and Vpp2 to the same value */
265 if ((mod
->Attributes
& CONF_VPP1_CHANGE_VALID
) &&
266 (mod
->Attributes
& CONF_VPP2_CHANGE_VALID
)) {
267 if (mod
->Vpp1
!= mod
->Vpp2
) {
268 dev_dbg(&s
->dev
, "Vpp1 and Vpp2 must be the same\n");
272 s
->socket
.Vpp
= mod
->Vpp1
;
273 if (s
->ops
->set_socket(s
, &s
->socket
)) {
274 dev_printk(KERN_WARNING
, &s
->dev
,
275 "Unable to set VPP\n");
279 } else if ((mod
->Attributes
& CONF_VPP1_CHANGE_VALID
) ||
280 (mod
->Attributes
& CONF_VPP2_CHANGE_VALID
)) {
281 dev_dbg(&s
->dev
, "changing Vcc is not allowed at this time\n");
286 if (mod
->Attributes
& CONF_IO_CHANGE_WIDTH
) {
287 pccard_io_map io_off
= { 0, 0, 0, 0, 1 };
291 io_on
.speed
= io_speed
;
292 for (i
= 0; i
< MAX_IO_WIN
; i
++) {
298 io_on
.flags
= MAP_ACTIVE
| IO_DATA_PATH_WIDTH_8
;
299 io_on
.start
= s
->io
[i
].res
->start
;
300 io_on
.stop
= s
->io
[i
].res
->end
;
302 s
->ops
->set_io_map(s
, &io_off
);
304 s
->ops
->set_io_map(s
, &io_on
);
309 mutex_unlock(&s
->ops_mutex
);
312 } /* modify_configuration */
313 EXPORT_SYMBOL(pcmcia_modify_configuration
);
316 int pcmcia_release_configuration(struct pcmcia_device
*p_dev
)
318 pccard_io_map io
= { 0, 0, 0, 0, 1 };
319 struct pcmcia_socket
*s
= p_dev
->socket
;
323 mutex_lock(&s
->ops_mutex
);
324 c
= p_dev
->function_config
;
325 if (p_dev
->_locked
) {
327 if (--(s
->lock_count
) == 0) {
328 s
->socket
.flags
= SS_OUTPUT_ENA
; /* Is this correct? */
330 s
->socket
.io_irq
= 0;
331 s
->ops
->set_socket(s
, &s
->socket
);
334 if (c
->state
& CONFIG_LOCKED
) {
335 c
->state
&= ~CONFIG_LOCKED
;
336 if (c
->state
& CONFIG_IO_REQ
)
337 for (i
= 0; i
< MAX_IO_WIN
; i
++) {
341 if (s
->io
[i
].Config
!= 0)
344 s
->ops
->set_io_map(s
, &io
);
347 mutex_unlock(&s
->ops_mutex
);
350 } /* pcmcia_release_configuration */
353 /** pcmcia_release_io
355 * Release_io() releases the I/O ranges allocated by a client. This
356 * may be invoked some time after a card ejection has already dumped
357 * the actual socket configuration, so if the client is "stale", we
358 * don't bother checking the port ranges against the current socket
361 static int pcmcia_release_io(struct pcmcia_device
*p_dev
)
363 struct pcmcia_socket
*s
= p_dev
->socket
;
367 mutex_lock(&s
->ops_mutex
);
371 c
= p_dev
->function_config
;
373 release_io_space(s
, &c
->io
[0]);
376 release_io_space(s
, &c
->io
[1]);
379 c
->state
&= ~CONFIG_IO_REQ
;
382 mutex_unlock(&s
->ops_mutex
);
385 } /* pcmcia_release_io */
388 int pcmcia_release_window(struct pcmcia_device
*p_dev
, struct resource
*res
)
390 struct pcmcia_socket
*s
= p_dev
->socket
;
394 dev_dbg(&p_dev
->dev
, "releasing window %pR\n", res
);
396 w
= ((res
->flags
& IORESOURCE_BITS
& WIN_FLAGS_REQ
) >> 2) - 1;
400 mutex_lock(&s
->ops_mutex
);
403 if (!(p_dev
->_win
& CLIENT_WIN_REQ(w
))) {
404 dev_dbg(&s
->dev
, "not releasing unknown window\n");
405 mutex_unlock(&s
->ops_mutex
);
409 /* Shut down memory window */
410 win
->flags
&= ~MAP_ACTIVE
;
411 s
->ops
->set_mem_map(s
, win
);
412 s
->state
&= ~SOCKET_WIN_REQ(w
);
414 /* Release system memory */
416 release_resource(res
);
417 release_resource(win
->res
);
421 p_dev
->_win
&= ~CLIENT_WIN_REQ(w
);
422 mutex_unlock(&s
->ops_mutex
);
425 } /* pcmcia_release_window */
426 EXPORT_SYMBOL(pcmcia_release_window
);
429 int pcmcia_request_configuration(struct pcmcia_device
*p_dev
,
434 struct pcmcia_socket
*s
= p_dev
->socket
;
438 if (!(s
->state
& SOCKET_PRESENT
))
441 if (req
->IntType
& INT_CARDBUS
) {
442 dev_dbg(&s
->dev
, "IntType may not be INT_CARDBUS\n");
446 mutex_lock(&s
->ops_mutex
);
447 c
= p_dev
->function_config
;
448 if (c
->state
& CONFIG_LOCKED
) {
449 mutex_unlock(&s
->ops_mutex
);
450 dev_dbg(&s
->dev
, "Configuration is locked\n");
454 /* Do power control. We don't allow changes in Vcc. */
455 s
->socket
.Vpp
= req
->Vpp
;
456 if (s
->ops
->set_socket(s
, &s
->socket
)) {
457 mutex_unlock(&s
->ops_mutex
);
458 dev_printk(KERN_WARNING
, &s
->dev
,
459 "Unable to set socket state\n");
463 /* Pick memory or I/O card, DMA mode, interrupt */
464 c
->IntType
= req
->IntType
;
465 c
->Attributes
= req
->Attributes
;
466 if (req
->IntType
& INT_MEMORY_AND_IO
)
467 s
->socket
.flags
|= SS_IOCARD
;
468 if (req
->IntType
& INT_ZOOMED_VIDEO
)
469 s
->socket
.flags
|= SS_ZVCARD
| SS_IOCARD
;
470 if (req
->Attributes
& CONF_ENABLE_DMA
)
471 s
->socket
.flags
|= SS_DMA_MODE
;
472 if (req
->Attributes
& CONF_ENABLE_SPKR
)
473 s
->socket
.flags
|= SS_SPKR_ENA
;
474 if (req
->Attributes
& CONF_ENABLE_IRQ
)
475 s
->socket
.io_irq
= s
->pcmcia_irq
;
477 s
->socket
.io_irq
= 0;
478 s
->ops
->set_socket(s
, &s
->socket
);
481 /* Set up CIS configuration registers */
482 base
= c
->ConfigBase
= req
->ConfigBase
;
483 c
->CardValues
= req
->Present
;
484 if (req
->Present
& PRESENT_COPY
) {
486 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_SCR
)>>1, 1, &c
->Copy
);
488 if (req
->Present
& PRESENT_OPTION
) {
489 if (s
->functions
== 1) {
490 c
->Option
= req
->ConfigIndex
& COR_CONFIG_MASK
;
492 c
->Option
= req
->ConfigIndex
& COR_MFC_CONFIG_MASK
;
493 c
->Option
|= COR_FUNC_ENA
|COR_IREQ_ENA
;
494 if (req
->Present
& PRESENT_IOBASE_0
)
495 c
->Option
|= COR_ADDR_DECODE
;
497 if ((req
->Attributes
& CONF_ENABLE_IRQ
) &&
498 !(req
->Attributes
& CONF_ENABLE_PULSE_IRQ
))
499 c
->Option
|= COR_LEVEL_REQ
;
500 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_COR
)>>1, 1, &c
->Option
);
503 if (req
->Present
& PRESENT_STATUS
) {
504 c
->Status
= req
->Status
;
505 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_CCSR
)>>1, 1, &c
->Status
);
507 if (req
->Present
& PRESENT_PIN_REPLACE
) {
509 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_PRR
)>>1, 1, &c
->Pin
);
511 if (req
->Present
& PRESENT_EXT_STATUS
) {
512 c
->ExtStatus
= req
->ExtStatus
;
513 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_ESR
)>>1, 1, &c
->ExtStatus
);
515 if (req
->Present
& PRESENT_IOBASE_0
) {
516 u8 b
= c
->io
[0].start
& 0xff;
517 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_IOBASE_0
)>>1, 1, &b
);
518 b
= (c
->io
[0].start
>> 8) & 0xff;
519 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_IOBASE_1
)>>1, 1, &b
);
521 if (req
->Present
& PRESENT_IOSIZE
) {
522 u8 b
= resource_size(&c
->io
[0]) + resource_size(&c
->io
[1]) - 1;
523 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_IOSIZE
)>>1, 1, &b
);
526 /* Configure I/O windows */
527 if (c
->state
& CONFIG_IO_REQ
) {
528 iomap
.speed
= io_speed
;
529 for (i
= 0; i
< MAX_IO_WIN
; i
++)
532 iomap
.flags
= MAP_ACTIVE
;
533 switch (s
->io
[i
].res
->flags
& IO_DATA_PATH_WIDTH
) {
534 case IO_DATA_PATH_WIDTH_16
:
535 iomap
.flags
|= MAP_16BIT
; break;
536 case IO_DATA_PATH_WIDTH_AUTO
:
537 iomap
.flags
|= MAP_AUTOSZ
; break;
541 iomap
.start
= s
->io
[i
].res
->start
;
542 iomap
.stop
= s
->io
[i
].res
->end
;
543 s
->ops
->set_io_map(s
, &iomap
);
548 c
->state
|= CONFIG_LOCKED
;
550 mutex_unlock(&s
->ops_mutex
);
552 } /* pcmcia_request_configuration */
553 EXPORT_SYMBOL(pcmcia_request_configuration
);
557 * pcmcia_request_io() - attempt to reserve port ranges for PCMCIA devices
559 * pcmcia_request_io() attepts to reserve the IO port ranges specified in
560 * &struct pcmcia_device @p_dev->resource[0] and @p_dev->resource[1]. The
561 * "start" value is the requested start of the IO port resource; "end"
562 * reflects the number of ports requested. The number of IO lines requested
563 * is specified in &struct pcmcia_device @p_dev->io_lines.
565 int pcmcia_request_io(struct pcmcia_device
*p_dev
)
567 struct pcmcia_socket
*s
= p_dev
->socket
;
568 config_t
*c
= p_dev
->function_config
;
571 mutex_lock(&s
->ops_mutex
);
572 dev_dbg(&s
->dev
, "pcmcia_request_io: %pR , %pR", &c
->io
[0], &c
->io
[1]);
574 if (!(s
->state
& SOCKET_PRESENT
)) {
575 dev_dbg(&s
->dev
, "pcmcia_request_io: No card present\n");
579 if (c
->state
& CONFIG_LOCKED
) {
580 dev_dbg(&s
->dev
, "Configuration is locked\n");
583 if (c
->state
& CONFIG_IO_REQ
) {
584 dev_dbg(&s
->dev
, "IO already configured\n");
588 ret
= alloc_io_space(s
, &c
->io
[0], p_dev
->io_lines
);
593 ret
= alloc_io_space(s
, &c
->io
[1], p_dev
->io_lines
);
595 release_io_space(s
, &c
->io
[0]);
601 c
->state
|= CONFIG_IO_REQ
;
604 dev_dbg(&s
->dev
, "pcmcia_request_io succeeded: %pR , %pR",
605 &c
->io
[0], &c
->io
[1]);
607 mutex_unlock(&s
->ops_mutex
);
610 } /* pcmcia_request_io */
611 EXPORT_SYMBOL(pcmcia_request_io
);
615 * pcmcia_request_irq() - attempt to request a IRQ for a PCMCIA device
617 * pcmcia_request_irq() is a wrapper around request_irq which will allow
618 * the PCMCIA core to clean up the registration in pcmcia_disable_device().
619 * Drivers are free to use request_irq() directly, but then they need to
620 * call free_irq themselfves, too. Also, only IRQF_SHARED capable IRQ
621 * handlers are allowed.
623 int __must_check
pcmcia_request_irq(struct pcmcia_device
*p_dev
,
624 irq_handler_t handler
)
631 ret
= request_irq(p_dev
->irq
, handler
, IRQF_SHARED
,
632 p_dev
->devname
, p_dev
->priv
);
638 EXPORT_SYMBOL(pcmcia_request_irq
);
642 * pcmcia_request_exclusive_irq() - attempt to request an exclusive IRQ first
644 * pcmcia_request_exclusive_irq() is a wrapper around request_irq which
645 * attempts first to request an exclusive IRQ. If it fails, it also accepts
646 * a shared IRQ, but prints out a warning. PCMCIA drivers should allow for
647 * IRQ sharing and either use request_irq directly (then they need to call
648 * free_irq themselves, too), or the pcmcia_request_irq() function.
651 __pcmcia_request_exclusive_irq(struct pcmcia_device
*p_dev
,
652 irq_handler_t handler
)
659 ret
= request_irq(p_dev
->irq
, handler
, 0, p_dev
->devname
, p_dev
->priv
);
661 ret
= pcmcia_request_irq(p_dev
, handler
);
662 dev_printk(KERN_WARNING
, &p_dev
->dev
, "pcmcia: "
663 "request for exclusive IRQ could not be fulfilled.\n");
664 dev_printk(KERN_WARNING
, &p_dev
->dev
, "pcmcia: the driver "
665 "needs updating to supported shared IRQ lines.\n");
668 dev_printk(KERN_INFO
, &p_dev
->dev
, "request_irq() failed\n");
673 } /* pcmcia_request_exclusive_irq */
674 EXPORT_SYMBOL(__pcmcia_request_exclusive_irq
);
677 #ifdef CONFIG_PCMCIA_PROBE
679 /* mask of IRQs already reserved by other cards, we should avoid using them */
680 static u8 pcmcia_used_irq
[32];
682 static irqreturn_t
test_action(int cpl
, void *dev_id
)
688 * pcmcia_setup_isa_irq() - determine whether an ISA IRQ can be used
689 * @p_dev - the associated PCMCIA device
691 * locking note: must be called with ops_mutex locked.
693 static int pcmcia_setup_isa_irq(struct pcmcia_device
*p_dev
, int type
)
695 struct pcmcia_socket
*s
= p_dev
->socket
;
696 unsigned int try, irq
;
697 u32 mask
= s
->irq_mask
;
700 for (try = 0; try < 64; try++) {
706 /* marked as available by driver, not blocked by userspace? */
707 if (!((mask
>> irq
) & 1))
710 /* avoid an IRQ which is already used by another PCMCIA card */
711 if ((try < 32) && pcmcia_used_irq
[irq
])
714 /* register the correct driver, if possible, to check whether
715 * registering a dummy handle works, i.e. if the IRQ isn't
716 * marked as used by the kernel resource management core */
717 ret
= request_irq(irq
, test_action
, type
, p_dev
->devname
,
720 free_irq(irq
, p_dev
);
721 p_dev
->irq
= s
->pcmcia_irq
= irq
;
722 pcmcia_used_irq
[irq
]++;
730 void pcmcia_cleanup_irq(struct pcmcia_socket
*s
)
732 pcmcia_used_irq
[s
->pcmcia_irq
]--;
736 #else /* CONFIG_PCMCIA_PROBE */
738 static int pcmcia_setup_isa_irq(struct pcmcia_device
*p_dev
, int type
)
743 void pcmcia_cleanup_irq(struct pcmcia_socket
*s
)
749 #endif /* CONFIG_PCMCIA_PROBE */
753 * pcmcia_setup_irq() - determine IRQ to be used for device
754 * @p_dev - the associated PCMCIA device
756 * locking note: must be called with ops_mutex locked.
758 int pcmcia_setup_irq(struct pcmcia_device
*p_dev
)
760 struct pcmcia_socket
*s
= p_dev
->socket
;
765 /* already assigned? */
767 p_dev
->irq
= s
->pcmcia_irq
;
771 /* prefer an exclusive ISA irq */
772 if (!pcmcia_setup_isa_irq(p_dev
, 0))
775 /* but accept a shared ISA irq */
776 if (!pcmcia_setup_isa_irq(p_dev
, IRQF_SHARED
))
779 /* but use the PCI irq otherwise */
781 p_dev
->irq
= s
->pcmcia_irq
= s
->pci_irq
;
789 /** pcmcia_request_window
791 * Request_window() establishes a mapping between card memory space
792 * and system memory space.
794 int pcmcia_request_window(struct pcmcia_device
*p_dev
, win_req_t
*req
, window_handle_t
*wh
)
796 struct pcmcia_socket
*s
= p_dev
->socket
;
799 struct resource
*res
;
802 if (!(s
->state
& SOCKET_PRESENT
)) {
803 dev_dbg(&s
->dev
, "No card present\n");
807 /* Window size defaults to smallest available */
809 req
->Size
= s
->map_size
;
810 align
= (s
->features
& SS_CAP_MEM_ALIGN
) ? req
->Size
: s
->map_size
;
811 if (req
->Size
& (s
->map_size
-1)) {
812 dev_dbg(&s
->dev
, "invalid map size\n");
815 if ((req
->Base
&& (s
->features
& SS_CAP_STATIC_MAP
)) ||
816 (req
->Base
& (align
-1))) {
817 dev_dbg(&s
->dev
, "invalid base address\n");
823 /* Allocate system memory window */
824 mutex_lock(&s
->ops_mutex
);
825 for (w
= 0; w
< MAX_WIN
; w
++)
826 if (!(s
->state
& SOCKET_WIN_REQ(w
)))
829 dev_dbg(&s
->dev
, "all windows are used already\n");
830 mutex_unlock(&s
->ops_mutex
);
836 if (!(s
->features
& SS_CAP_STATIC_MAP
)) {
837 win
->res
= pcmcia_find_mem_region(req
->Base
, req
->Size
, align
,
840 dev_dbg(&s
->dev
, "allocating mem region failed\n");
841 mutex_unlock(&s
->ops_mutex
);
845 p_dev
->_win
|= CLIENT_WIN_REQ(w
);
847 /* Configure the socket controller */
849 win
->flags
= req
->Attributes
;
850 win
->speed
= req
->AccessSpeed
;
853 if (s
->ops
->set_mem_map(s
, win
) != 0) {
854 dev_dbg(&s
->dev
, "failed to set memory mapping\n");
855 mutex_unlock(&s
->ops_mutex
);
858 s
->state
|= SOCKET_WIN_REQ(w
);
860 /* Return window handle */
861 if (s
->features
& SS_CAP_STATIC_MAP
)
862 req
->Base
= win
->static_start
;
864 req
->Base
= win
->res
->start
;
866 /* convert to new-style resources */
867 res
= p_dev
->resource
[w
+ MAX_IO_WIN
];
868 res
->start
= req
->Base
;
869 res
->end
= req
->Base
+ req
->Size
- 1;
870 res
->flags
&= ~IORESOURCE_BITS
;
871 res
->flags
|= (req
->Attributes
& WIN_FLAGS_MAP
) | (win
->map
<< 2);
872 res
->flags
|= IORESOURCE_MEM
;
873 res
->parent
= win
->res
;
875 request_resource(&iomem_resource
, res
);
877 dev_dbg(&s
->dev
, "request_window results in %pR\n", res
);
879 mutex_unlock(&s
->ops_mutex
);
883 } /* pcmcia_request_window */
884 EXPORT_SYMBOL(pcmcia_request_window
);
886 void pcmcia_disable_device(struct pcmcia_device
*p_dev
)
889 for (i
= 0; i
< MAX_WIN
; i
++) {
890 struct resource
*res
= p_dev
->resource
[MAX_IO_WIN
+ i
];
891 if (res
->flags
& WIN_FLAGS_REQ
)
892 pcmcia_release_window(p_dev
, res
);
895 pcmcia_release_configuration(p_dev
);
896 pcmcia_release_io(p_dev
);
898 free_irq(p_dev
->irq
, p_dev
->priv
);
902 EXPORT_SYMBOL(pcmcia_disable_device
);