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
);
61 * Special stuff for managing IO windows, because they are scarce
64 static int alloc_io_space(struct pcmcia_socket
*s
, u_int attr
,
65 unsigned int *base
, unsigned int num
, u_int lines
)
69 align
= (*base
) ? (lines
? 1<<lines
: 0) : 1;
70 if (align
&& (align
< num
)) {
72 dev_dbg(&s
->dev
, "odd IO request: num %#x align %#x\n",
76 while (align
&& (align
< num
))
79 if (*base
& ~(align
-1)) {
80 dev_dbg(&s
->dev
, "odd IO request: base %#x align %#x\n",
85 return s
->resource_ops
->find_io(s
, attr
, base
, num
, align
);
86 } /* alloc_io_space */
89 static void release_io_space(struct pcmcia_socket
*s
, unsigned int base
,
94 for (i
= 0; i
< MAX_IO_WIN
; i
++) {
97 if ((s
->io
[i
].res
->start
<= base
) &&
98 (s
->io
[i
].res
->end
>= base
+num
-1)) {
99 s
->io
[i
].InUse
-= num
;
100 /* Free the window if no one else is using it */
101 if (s
->io
[i
].InUse
== 0) {
102 release_resource(s
->io
[i
].res
);
108 } /* release_io_space */
112 * pcmcia_access_config() - read or write card configuration registers
114 * pcmcia_access_config() reads and writes configuration registers in
115 * attribute memory. Memory window 0 is reserved for this and the tuple
116 * reading services. Drivers must use pcmcia_read_config_byte() or
117 * pcmcia_write_config_byte().
119 static int pcmcia_access_config(struct pcmcia_device
*p_dev
,
120 off_t where
, u8
*val
,
121 int (*accessf
) (struct pcmcia_socket
*s
,
122 int attr
, unsigned int addr
,
123 unsigned int len
, void *ptr
))
125 struct pcmcia_socket
*s
;
132 mutex_lock(&s
->ops_mutex
);
133 c
= p_dev
->function_config
;
135 if (!(c
->state
& CONFIG_LOCKED
)) {
136 dev_dbg(&s
->dev
, "Configuration isnt't locked\n");
137 mutex_unlock(&s
->ops_mutex
);
141 addr
= (c
->ConfigBase
+ where
) >> 1;
143 ret
= accessf(s
, 1, addr
, 1, val
);
145 mutex_unlock(&s
->ops_mutex
);
148 } /* pcmcia_access_config */
152 * pcmcia_read_config_byte() - read a byte from a card configuration register
154 * pcmcia_read_config_byte() reads a byte from a configuration register in
157 int pcmcia_read_config_byte(struct pcmcia_device
*p_dev
, off_t where
, u8
*val
)
159 return pcmcia_access_config(p_dev
, where
, val
, pcmcia_read_cis_mem
);
161 EXPORT_SYMBOL(pcmcia_read_config_byte
);
165 * pcmcia_write_config_byte() - write a byte to a card configuration register
167 * pcmcia_write_config_byte() writes a byte to a configuration register in
170 int pcmcia_write_config_byte(struct pcmcia_device
*p_dev
, off_t where
, u8 val
)
172 return pcmcia_access_config(p_dev
, where
, &val
, pcmcia_write_cis_mem
);
174 EXPORT_SYMBOL(pcmcia_write_config_byte
);
177 int pcmcia_map_mem_page(struct pcmcia_device
*p_dev
, window_handle_t wh
,
180 struct pcmcia_socket
*s
= p_dev
->socket
;
186 if (req
->Page
!= 0) {
187 dev_dbg(&s
->dev
, "failure: requested page is zero\n");
190 mutex_lock(&s
->ops_mutex
);
191 s
->win
[wh
].card_start
= req
->CardOffset
;
192 ret
= s
->ops
->set_mem_map(s
, &s
->win
[wh
]);
194 dev_warn(&s
->dev
, "failed to set_mem_map\n");
195 mutex_unlock(&s
->ops_mutex
);
197 } /* pcmcia_map_mem_page */
198 EXPORT_SYMBOL(pcmcia_map_mem_page
);
201 /** pcmcia_modify_configuration
203 * Modify a locked socket configuration
205 int pcmcia_modify_configuration(struct pcmcia_device
*p_dev
,
208 struct pcmcia_socket
*s
;
214 mutex_lock(&s
->ops_mutex
);
215 c
= p_dev
->function_config
;
217 if (!(s
->state
& SOCKET_PRESENT
)) {
218 dev_dbg(&s
->dev
, "No card present\n");
222 if (!(c
->state
& CONFIG_LOCKED
)) {
223 dev_dbg(&s
->dev
, "Configuration isnt't locked\n");
228 if (mod
->Attributes
& (CONF_IRQ_CHANGE_VALID
| CONF_VCC_CHANGE_VALID
)) {
230 "changing Vcc or IRQ is not allowed at this time\n");
235 /* We only allow changing Vpp1 and Vpp2 to the same value */
236 if ((mod
->Attributes
& CONF_VPP1_CHANGE_VALID
) &&
237 (mod
->Attributes
& CONF_VPP2_CHANGE_VALID
)) {
238 if (mod
->Vpp1
!= mod
->Vpp2
) {
239 dev_dbg(&s
->dev
, "Vpp1 and Vpp2 must be the same\n");
243 s
->socket
.Vpp
= mod
->Vpp1
;
244 if (s
->ops
->set_socket(s
, &s
->socket
)) {
245 dev_printk(KERN_WARNING
, &s
->dev
,
246 "Unable to set VPP\n");
250 } else if ((mod
->Attributes
& CONF_VPP1_CHANGE_VALID
) ||
251 (mod
->Attributes
& CONF_VPP2_CHANGE_VALID
)) {
252 dev_dbg(&s
->dev
, "changing Vcc is not allowed at this time\n");
257 if (mod
->Attributes
& CONF_IO_CHANGE_WIDTH
) {
258 pccard_io_map io_off
= { 0, 0, 0, 0, 1 };
262 io_on
.speed
= io_speed
;
263 for (i
= 0; i
< MAX_IO_WIN
; i
++) {
269 io_on
.flags
= MAP_ACTIVE
| IO_DATA_PATH_WIDTH_8
;
270 io_on
.start
= s
->io
[i
].res
->start
;
271 io_on
.stop
= s
->io
[i
].res
->end
;
273 s
->ops
->set_io_map(s
, &io_off
);
275 s
->ops
->set_io_map(s
, &io_on
);
280 mutex_unlock(&s
->ops_mutex
);
283 } /* modify_configuration */
284 EXPORT_SYMBOL(pcmcia_modify_configuration
);
287 int pcmcia_release_configuration(struct pcmcia_device
*p_dev
)
289 pccard_io_map io
= { 0, 0, 0, 0, 1 };
290 struct pcmcia_socket
*s
= p_dev
->socket
;
294 mutex_lock(&s
->ops_mutex
);
295 c
= p_dev
->function_config
;
296 if (p_dev
->_locked
) {
298 if (--(s
->lock_count
) == 0) {
299 s
->socket
.flags
= SS_OUTPUT_ENA
; /* Is this correct? */
301 s
->socket
.io_irq
= 0;
302 s
->ops
->set_socket(s
, &s
->socket
);
305 if (c
->state
& CONFIG_LOCKED
) {
306 c
->state
&= ~CONFIG_LOCKED
;
307 if (c
->state
& CONFIG_IO_REQ
)
308 for (i
= 0; i
< MAX_IO_WIN
; i
++) {
312 if (s
->io
[i
].Config
!= 0)
315 s
->ops
->set_io_map(s
, &io
);
318 mutex_unlock(&s
->ops_mutex
);
321 } /* pcmcia_release_configuration */
324 /** pcmcia_release_io
326 * Release_io() releases the I/O ranges allocated by a client. This
327 * may be invoked some time after a card ejection has already dumped
328 * the actual socket configuration, so if the client is "stale", we
329 * don't bother checking the port ranges against the current socket
332 static int pcmcia_release_io(struct pcmcia_device
*p_dev
, io_req_t
*req
)
334 struct pcmcia_socket
*s
= p_dev
->socket
;
338 mutex_lock(&s
->ops_mutex
);
339 c
= p_dev
->function_config
;
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
))
352 c
->state
&= ~CONFIG_IO_REQ
;
354 release_io_space(s
, req
->BasePort1
, req
->NumPorts1
);
356 release_io_space(s
, req
->BasePort2
, req
->NumPorts2
);
359 mutex_unlock(&s
->ops_mutex
);
362 } /* pcmcia_release_io */
365 int pcmcia_release_window(struct pcmcia_device
*p_dev
, window_handle_t wh
)
367 struct pcmcia_socket
*s
= p_dev
->socket
;
374 mutex_lock(&s
->ops_mutex
);
377 if (!(p_dev
->_win
& CLIENT_WIN_REQ(wh
))) {
378 dev_dbg(&s
->dev
, "not releasing unknown window\n");
379 mutex_unlock(&s
->ops_mutex
);
383 /* Shut down memory window */
384 win
->flags
&= ~MAP_ACTIVE
;
385 s
->ops
->set_mem_map(s
, win
);
386 s
->state
&= ~SOCKET_WIN_REQ(wh
);
388 /* Release system memory */
390 release_resource(win
->res
);
394 p_dev
->_win
&= ~CLIENT_WIN_REQ(wh
);
395 mutex_unlock(&s
->ops_mutex
);
398 } /* pcmcia_release_window */
399 EXPORT_SYMBOL(pcmcia_release_window
);
402 int pcmcia_request_configuration(struct pcmcia_device
*p_dev
,
407 struct pcmcia_socket
*s
= p_dev
->socket
;
411 if (!(s
->state
& SOCKET_PRESENT
))
414 if (req
->IntType
& INT_CARDBUS
) {
415 dev_dbg(&s
->dev
, "IntType may not be INT_CARDBUS\n");
419 mutex_lock(&s
->ops_mutex
);
420 c
= p_dev
->function_config
;
421 if (c
->state
& CONFIG_LOCKED
) {
422 mutex_unlock(&s
->ops_mutex
);
423 dev_dbg(&s
->dev
, "Configuration is locked\n");
427 /* Do power control. We don't allow changes in Vcc. */
428 s
->socket
.Vpp
= req
->Vpp
;
429 if (s
->ops
->set_socket(s
, &s
->socket
)) {
430 mutex_unlock(&s
->ops_mutex
);
431 dev_printk(KERN_WARNING
, &s
->dev
,
432 "Unable to set socket state\n");
436 /* Pick memory or I/O card, DMA mode, interrupt */
437 c
->IntType
= req
->IntType
;
438 c
->Attributes
= req
->Attributes
;
439 if (req
->IntType
& INT_MEMORY_AND_IO
)
440 s
->socket
.flags
|= SS_IOCARD
;
441 if (req
->IntType
& INT_ZOOMED_VIDEO
)
442 s
->socket
.flags
|= SS_ZVCARD
| SS_IOCARD
;
443 if (req
->Attributes
& CONF_ENABLE_DMA
)
444 s
->socket
.flags
|= SS_DMA_MODE
;
445 if (req
->Attributes
& CONF_ENABLE_SPKR
)
446 s
->socket
.flags
|= SS_SPKR_ENA
;
447 if (req
->Attributes
& CONF_ENABLE_IRQ
)
448 s
->socket
.io_irq
= s
->pcmcia_irq
;
450 s
->socket
.io_irq
= 0;
451 s
->ops
->set_socket(s
, &s
->socket
);
454 /* Set up CIS configuration registers */
455 base
= c
->ConfigBase
= req
->ConfigBase
;
456 c
->CardValues
= req
->Present
;
457 if (req
->Present
& PRESENT_COPY
) {
459 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_SCR
)>>1, 1, &c
->Copy
);
461 if (req
->Present
& PRESENT_OPTION
) {
462 if (s
->functions
== 1) {
463 c
->Option
= req
->ConfigIndex
& COR_CONFIG_MASK
;
465 c
->Option
= req
->ConfigIndex
& COR_MFC_CONFIG_MASK
;
466 c
->Option
|= COR_FUNC_ENA
|COR_IREQ_ENA
;
467 if (req
->Present
& PRESENT_IOBASE_0
)
468 c
->Option
|= COR_ADDR_DECODE
;
470 if ((req
->Attributes
& CONF_ENABLE_IRQ
) &&
471 !(req
->Attributes
& CONF_ENABLE_PULSE_IRQ
))
472 c
->Option
|= COR_LEVEL_REQ
;
473 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_COR
)>>1, 1, &c
->Option
);
476 if (req
->Present
& PRESENT_STATUS
) {
477 c
->Status
= req
->Status
;
478 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_CCSR
)>>1, 1, &c
->Status
);
480 if (req
->Present
& PRESENT_PIN_REPLACE
) {
482 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_PRR
)>>1, 1, &c
->Pin
);
484 if (req
->Present
& PRESENT_EXT_STATUS
) {
485 c
->ExtStatus
= req
->ExtStatus
;
486 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_ESR
)>>1, 1, &c
->ExtStatus
);
488 if (req
->Present
& PRESENT_IOBASE_0
) {
489 u_char b
= c
->io
.BasePort1
& 0xff;
490 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_IOBASE_0
)>>1, 1, &b
);
491 b
= (c
->io
.BasePort1
>> 8) & 0xff;
492 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_IOBASE_1
)>>1, 1, &b
);
494 if (req
->Present
& PRESENT_IOSIZE
) {
495 u_char b
= c
->io
.NumPorts1
+ c
->io
.NumPorts2
- 1;
496 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_IOSIZE
)>>1, 1, &b
);
499 /* Configure I/O windows */
500 if (c
->state
& CONFIG_IO_REQ
) {
501 iomap
.speed
= io_speed
;
502 for (i
= 0; i
< MAX_IO_WIN
; i
++)
505 iomap
.flags
= MAP_ACTIVE
;
506 switch (s
->io
[i
].res
->flags
& IO_DATA_PATH_WIDTH
) {
507 case IO_DATA_PATH_WIDTH_16
:
508 iomap
.flags
|= MAP_16BIT
; break;
509 case IO_DATA_PATH_WIDTH_AUTO
:
510 iomap
.flags
|= MAP_AUTOSZ
; break;
514 iomap
.start
= s
->io
[i
].res
->start
;
515 iomap
.stop
= s
->io
[i
].res
->end
;
516 s
->ops
->set_io_map(s
, &iomap
);
521 c
->state
|= CONFIG_LOCKED
;
523 mutex_unlock(&s
->ops_mutex
);
525 } /* pcmcia_request_configuration */
526 EXPORT_SYMBOL(pcmcia_request_configuration
);
529 /** pcmcia_request_io
531 * Request_io() reserves ranges of port addresses for a socket.
532 * I have not implemented range sharing or alias addressing.
534 int pcmcia_request_io(struct pcmcia_device
*p_dev
, io_req_t
*req
)
536 struct pcmcia_socket
*s
= p_dev
->socket
;
540 mutex_lock(&s
->ops_mutex
);
542 if (!(s
->state
& SOCKET_PRESENT
)) {
543 dev_dbg(&s
->dev
, "No card present\n");
550 c
= p_dev
->function_config
;
551 if (c
->state
& CONFIG_LOCKED
) {
552 dev_dbg(&s
->dev
, "Configuration is locked\n");
555 if (c
->state
& CONFIG_IO_REQ
) {
556 dev_dbg(&s
->dev
, "IO already configured\n");
559 if (req
->Attributes1
& (IO_SHARED
| IO_FORCE_ALIAS_ACCESS
)) {
560 dev_dbg(&s
->dev
, "bad attribute setting for IO region 1\n");
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");
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
);
573 dev_dbg(&s
->dev
, "allocation of resource 1 failed\n");
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
);
582 dev_dbg(&s
->dev
, "allocation of resource 2 failed\n");
583 release_io_space(s
, req
->BasePort1
, req
->NumPorts1
);
589 c
->state
|= CONFIG_IO_REQ
;
591 dev_dbg(&s
->dev
, "allocating resources succeeded: %d\n", ret
);
594 mutex_unlock(&s
->ops_mutex
);
597 } /* pcmcia_request_io */
598 EXPORT_SYMBOL(pcmcia_request_io
);
602 * pcmcia_request_irq() - attempt to request a IRQ for a PCMCIA device
604 * pcmcia_request_irq() is a wrapper around request_irq which will allow
605 * the PCMCIA core to clean up the registration in pcmcia_disable_device().
606 * Drivers are free to use request_irq() directly, but then they need to
607 * call free_irq themselfves, too. Also, only IRQF_SHARED capable IRQ
608 * handlers are allowed.
610 int __must_check
pcmcia_request_irq(struct pcmcia_device
*p_dev
,
611 irq_handler_t handler
)
618 ret
= request_irq(p_dev
->irq
, handler
, IRQF_SHARED
,
619 p_dev
->devname
, p_dev
->priv
);
625 EXPORT_SYMBOL(pcmcia_request_irq
);
629 * pcmcia_request_exclusive_irq() - attempt to request an exclusive IRQ first
631 * pcmcia_request_exclusive_irq() is a wrapper around request_irq which
632 * attempts first to request an exclusive IRQ. If it fails, it also accepts
633 * a shared IRQ, but prints out a warning. PCMCIA drivers should allow for
634 * IRQ sharing and either use request_irq directly (then they need to call
635 * free_irq themselves, too), or the pcmcia_request_irq() function.
638 __pcmcia_request_exclusive_irq(struct pcmcia_device
*p_dev
,
639 irq_handler_t handler
)
646 ret
= request_irq(p_dev
->irq
, handler
, 0, p_dev
->devname
, p_dev
->priv
);
648 ret
= pcmcia_request_irq(p_dev
, handler
);
649 dev_printk(KERN_WARNING
, &p_dev
->dev
, "pcmcia: "
650 "request for exclusive IRQ could not be fulfilled.\n");
651 dev_printk(KERN_WARNING
, &p_dev
->dev
, "pcmcia: the driver "
652 "needs updating to supported shared IRQ lines.\n");
655 dev_printk(KERN_INFO
, &p_dev
->dev
, "request_irq() failed\n");
660 } /* pcmcia_request_exclusive_irq */
661 EXPORT_SYMBOL(__pcmcia_request_exclusive_irq
);
664 #ifdef CONFIG_PCMCIA_PROBE
666 /* mask of IRQs already reserved by other cards, we should avoid using them */
667 static u8 pcmcia_used_irq
[NR_IRQS
];
669 static irqreturn_t
test_action(int cpl
, void *dev_id
)
675 * pcmcia_setup_isa_irq() - determine whether an ISA IRQ can be used
676 * @p_dev - the associated PCMCIA device
678 * locking note: must be called with ops_mutex locked.
680 static int pcmcia_setup_isa_irq(struct pcmcia_device
*p_dev
, int type
)
682 struct pcmcia_socket
*s
= p_dev
->socket
;
683 unsigned int try, irq
;
684 u32 mask
= s
->irq_mask
;
687 for (try = 0; try < 64; try++) {
690 /* marked as available by driver, not blocked by userspace? */
691 if (!((mask
>> irq
) & 1))
694 /* avoid an IRQ which is already used by another PCMCIA card */
695 if ((try < 32) && pcmcia_used_irq
[irq
])
698 /* register the correct driver, if possible, to check whether
699 * registering a dummy handle works, i.e. if the IRQ isn't
700 * marked as used by the kernel resource management core */
701 ret
= request_irq(irq
, test_action
, type
, p_dev
->devname
,
704 free_irq(irq
, p_dev
);
705 p_dev
->irq
= s
->pcmcia_irq
= irq
;
706 pcmcia_used_irq
[irq
]++;
714 void pcmcia_cleanup_irq(struct pcmcia_socket
*s
)
716 pcmcia_used_irq
[s
->pcmcia_irq
]--;
720 #else /* CONFIG_PCMCIA_PROBE */
722 static int pcmcia_setup_isa_irq(struct pcmcia_device
*p_dev
, int type
)
727 void pcmcia_cleanup_irq(struct pcmcia_socket
*s
)
733 #endif /* CONFIG_PCMCIA_PROBE */
737 * pcmcia_setup_irq() - determine IRQ to be used for device
738 * @p_dev - the associated PCMCIA device
740 * locking note: must be called with ops_mutex locked.
742 int pcmcia_setup_irq(struct pcmcia_device
*p_dev
)
744 struct pcmcia_socket
*s
= p_dev
->socket
;
749 /* already assigned? */
751 p_dev
->irq
= s
->pcmcia_irq
;
755 /* prefer an exclusive ISA irq */
756 if (!pcmcia_setup_isa_irq(p_dev
, 0))
759 /* but accept a shared ISA irq */
760 if (!pcmcia_setup_isa_irq(p_dev
, IRQF_SHARED
))
763 /* but use the PCI irq otherwise */
765 p_dev
->irq
= s
->pcmcia_irq
= s
->pci_irq
;
773 /** pcmcia_request_window
775 * Request_window() establishes a mapping between card memory space
776 * and system memory space.
778 int pcmcia_request_window(struct pcmcia_device
*p_dev
, win_req_t
*req
, window_handle_t
*wh
)
780 struct pcmcia_socket
*s
= p_dev
->socket
;
785 if (!(s
->state
& SOCKET_PRESENT
)) {
786 dev_dbg(&s
->dev
, "No card present\n");
789 if (req
->Attributes
& (WIN_PAGED
| WIN_SHARED
)) {
790 dev_dbg(&s
->dev
, "bad attribute setting for iomem region\n");
794 /* Window size defaults to smallest available */
796 req
->Size
= s
->map_size
;
797 align
= (((s
->features
& SS_CAP_MEM_ALIGN
) ||
798 (req
->Attributes
& WIN_STRICT_ALIGN
)) ?
799 req
->Size
: s
->map_size
);
800 if (req
->Size
& (s
->map_size
-1)) {
801 dev_dbg(&s
->dev
, "invalid map size\n");
804 if ((req
->Base
&& (s
->features
& SS_CAP_STATIC_MAP
)) ||
805 (req
->Base
& (align
-1))) {
806 dev_dbg(&s
->dev
, "invalid base address\n");
812 /* Allocate system memory window */
813 for (w
= 0; w
< MAX_WIN
; w
++)
814 if (!(s
->state
& SOCKET_WIN_REQ(w
)))
817 dev_dbg(&s
->dev
, "all windows are used already\n");
821 mutex_lock(&s
->ops_mutex
);
824 if (!(s
->features
& SS_CAP_STATIC_MAP
)) {
825 win
->res
= pcmcia_find_mem_region(req
->Base
, req
->Size
, align
,
826 (req
->Attributes
& WIN_MAP_BELOW_1MB
), s
);
828 dev_dbg(&s
->dev
, "allocating mem region failed\n");
829 mutex_unlock(&s
->ops_mutex
);
833 p_dev
->_win
|= CLIENT_WIN_REQ(w
);
835 /* Configure the socket controller */
838 win
->speed
= req
->AccessSpeed
;
839 if (req
->Attributes
& WIN_MEMORY_TYPE
)
840 win
->flags
|= MAP_ATTRIB
;
841 if (req
->Attributes
& WIN_ENABLE
)
842 win
->flags
|= MAP_ACTIVE
;
843 if (req
->Attributes
& WIN_DATA_WIDTH_16
)
844 win
->flags
|= MAP_16BIT
;
845 if (req
->Attributes
& WIN_USE_WAIT
)
846 win
->flags
|= MAP_USE_WAIT
;
849 if (s
->ops
->set_mem_map(s
, win
) != 0) {
850 dev_dbg(&s
->dev
, "failed to set memory mapping\n");
851 mutex_unlock(&s
->ops_mutex
);
854 s
->state
|= SOCKET_WIN_REQ(w
);
856 /* Return window handle */
857 if (s
->features
& SS_CAP_STATIC_MAP
)
858 req
->Base
= win
->static_start
;
860 req
->Base
= win
->res
->start
;
862 mutex_unlock(&s
->ops_mutex
);
866 } /* pcmcia_request_window */
867 EXPORT_SYMBOL(pcmcia_request_window
);
869 void pcmcia_disable_device(struct pcmcia_device
*p_dev
)
871 pcmcia_release_configuration(p_dev
);
872 pcmcia_release_io(p_dev
, &p_dev
->io
);
874 free_irq(p_dev
->irq
, p_dev
->priv
);
878 pcmcia_release_window(p_dev
, p_dev
->win
);
880 EXPORT_SYMBOL(pcmcia_disable_device
);