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>
24 #include <pcmcia/cs_types.h>
25 #include <pcmcia/ss.h>
26 #include <pcmcia/cs.h>
27 #include <pcmcia/cistpl.h>
28 #include <pcmcia/cisreg.h>
29 #include <pcmcia/ds.h>
31 #include "cs_internal.h"
34 /* Access speed for IO windows */
35 static int io_speed
= 0;
36 module_param(io_speed
, int, 0444);
39 #ifdef CONFIG_PCMCIA_PROBE
41 /* mask of IRQs already reserved by other cards, we should avoid using them */
42 static u8 pcmcia_used_irq
[NR_IRQS
];
46 #ifdef CONFIG_PCMCIA_DEBUG
47 extern int ds_pc_debug
;
49 #define ds_dbg(skt, lvl, fmt, arg...) do { \
50 if (ds_pc_debug >= lvl) \
51 dev_printk(KERN_DEBUG, &skt->dev, \
52 "pcmcia_resource: " fmt, \
56 #define ds_dbg(skt, lvl, fmt, arg...) do { } while (0)
63 * Special stuff for managing IO windows, because they are scarce
66 static int alloc_io_space(struct pcmcia_socket
*s
, u_int attr
,
67 unsigned int *base
, unsigned int num
, u_int lines
)
70 unsigned int try, align
;
72 align
= (*base
) ? (lines
? 1<<lines
: 0) : 1;
73 if (align
&& (align
< num
)) {
75 ds_dbg(s
, 0, "odd IO request: num %#x align %#x\n",
79 while (align
&& (align
< num
)) align
<<= 1;
81 if (*base
& ~(align
-1)) {
82 ds_dbg(s
, 0, "odd IO request: base %#x align %#x\n",
86 if ((s
->features
& SS_CAP_STATIC_MAP
) && s
->io_offset
) {
87 *base
= s
->io_offset
| (*base
& 0x0fff);
90 /* Check for an already-allocated window that must conflict with
91 * what was asked for. It is a hack because it does not catch all
92 * potential conflicts, just the most obvious ones.
94 for (i
= 0; i
< MAX_IO_WIN
; i
++)
95 if ((s
->io
[i
].res
) && *base
&&
96 ((s
->io
[i
].res
->start
& (align
-1)) == *base
))
98 for (i
= 0; i
< MAX_IO_WIN
; i
++) {
100 s
->io
[i
].res
= pcmcia_find_io_region(*base
, num
, align
, s
);
102 *base
= s
->io
[i
].res
->start
;
103 s
->io
[i
].res
->flags
= (s
->io
[i
].res
->flags
& ~IORESOURCE_BITS
) | (attr
& IORESOURCE_BITS
);
104 s
->io
[i
].InUse
= num
;
108 } else if ((s
->io
[i
].res
->flags
& IORESOURCE_BITS
) != (attr
& IORESOURCE_BITS
))
110 /* Try to extend top of window */
111 try = s
->io
[i
].res
->end
+ 1;
112 if ((*base
== 0) || (*base
== try))
113 if (pcmcia_adjust_io_region(s
->io
[i
].res
, s
->io
[i
].res
->start
,
114 s
->io
[i
].res
->end
+ num
, s
) == 0) {
116 s
->io
[i
].InUse
+= num
;
119 /* Try to extend bottom of window */
120 try = s
->io
[i
].res
->start
- num
;
121 if ((*base
== 0) || (*base
== try))
122 if (pcmcia_adjust_io_region(s
->io
[i
].res
, s
->io
[i
].res
->start
- num
,
123 s
->io
[i
].res
->end
, s
) == 0) {
125 s
->io
[i
].InUse
+= num
;
129 return (i
== MAX_IO_WIN
);
130 } /* alloc_io_space */
133 static void release_io_space(struct pcmcia_socket
*s
, unsigned int base
,
138 for (i
= 0; i
< MAX_IO_WIN
; i
++) {
141 if ((s
->io
[i
].res
->start
<= base
) &&
142 (s
->io
[i
].res
->end
>= base
+num
-1)) {
143 s
->io
[i
].InUse
-= num
;
144 /* Free the window if no one else is using it */
145 if (s
->io
[i
].InUse
== 0) {
146 release_resource(s
->io
[i
].res
);
152 } /* release_io_space */
155 /** pccard_access_configuration_register
157 * Access_configuration_register() reads and writes configuration
158 * registers in attribute memory. Memory window 0 is reserved for
159 * this and the tuple reading services.
162 int pcmcia_access_configuration_register(struct pcmcia_device
*p_dev
,
165 struct pcmcia_socket
*s
;
170 if (!p_dev
|| !p_dev
->function_config
)
174 c
= p_dev
->function_config
;
176 if (!(c
->state
& CONFIG_LOCKED
))
179 addr
= (c
->ConfigBase
+ reg
->Offset
) >> 1;
181 switch (reg
->Action
) {
183 pcmcia_read_cis_mem(s
, 1, addr
, 1, &val
);
188 pcmcia_write_cis_mem(s
, 1, addr
, 1, &val
);
195 } /* pcmcia_access_configuration_register */
196 EXPORT_SYMBOL(pcmcia_access_configuration_register
);
199 /** pcmcia_get_window
201 int pcmcia_get_window(struct pcmcia_socket
*s
, window_handle_t
*handle
,
202 int idx
, win_req_t
*req
)
207 if (!s
|| !(s
->state
& SOCKET_PRESENT
))
209 for (w
= idx
; w
< MAX_WIN
; w
++)
210 if (s
->state
& SOCKET_WIN_REQ(w
))
215 req
->Base
= win
->ctl
.res
->start
;
216 req
->Size
= win
->ctl
.res
->end
- win
->ctl
.res
->start
+ 1;
217 req
->AccessSpeed
= win
->ctl
.speed
;
219 if (win
->ctl
.flags
& MAP_ATTRIB
)
220 req
->Attributes
|= WIN_MEMORY_TYPE_AM
;
221 if (win
->ctl
.flags
& MAP_ACTIVE
)
222 req
->Attributes
|= WIN_ENABLE
;
223 if (win
->ctl
.flags
& MAP_16BIT
)
224 req
->Attributes
|= WIN_DATA_WIDTH_16
;
225 if (win
->ctl
.flags
& MAP_USE_WAIT
)
226 req
->Attributes
|= WIN_USE_WAIT
;
229 } /* pcmcia_get_window */
230 EXPORT_SYMBOL(pcmcia_get_window
);
233 /** pcmcia_get_mem_page
235 * Change the card address of an already open memory window.
237 int pcmcia_get_mem_page(window_handle_t win
, memreq_t
*req
)
239 if ((win
== NULL
) || (win
->magic
!= WINDOW_MAGIC
))
242 req
->CardOffset
= win
->ctl
.card_start
;
244 } /* pcmcia_get_mem_page */
245 EXPORT_SYMBOL(pcmcia_get_mem_page
);
248 int pcmcia_map_mem_page(window_handle_t win
, memreq_t
*req
)
250 struct pcmcia_socket
*s
;
251 if ((win
== NULL
) || (win
->magic
!= WINDOW_MAGIC
))
254 if (req
->Page
!= 0) {
255 ds_dbg(s
, 0, "failure: requested page is zero\n");
258 win
->ctl
.card_start
= req
->CardOffset
;
259 if (s
->ops
->set_mem_map(s
, &win
->ctl
) != 0) {
260 ds_dbg(s
, 0, "failed to set_mem_map\n");
264 } /* pcmcia_map_mem_page */
265 EXPORT_SYMBOL(pcmcia_map_mem_page
);
268 /** pcmcia_modify_configuration
270 * Modify a locked socket configuration
272 int pcmcia_modify_configuration(struct pcmcia_device
*p_dev
,
275 struct pcmcia_socket
*s
;
279 c
= p_dev
->function_config
;
281 if (!(s
->state
& SOCKET_PRESENT
))
283 if (!(c
->state
& CONFIG_LOCKED
))
286 if (mod
->Attributes
& CONF_IRQ_CHANGE_VALID
) {
287 if (mod
->Attributes
& CONF_ENABLE_IRQ
) {
288 c
->Attributes
|= CONF_ENABLE_IRQ
;
289 s
->socket
.io_irq
= s
->irq
.AssignedIRQ
;
291 c
->Attributes
&= ~CONF_ENABLE_IRQ
;
292 s
->socket
.io_irq
= 0;
294 s
->ops
->set_socket(s
, &s
->socket
);
297 if (mod
->Attributes
& CONF_VCC_CHANGE_VALID
) {
298 ds_dbg(s
, 0, "changing Vcc is not allowed at this time\n");
302 /* We only allow changing Vpp1 and Vpp2 to the same value */
303 if ((mod
->Attributes
& CONF_VPP1_CHANGE_VALID
) &&
304 (mod
->Attributes
& CONF_VPP2_CHANGE_VALID
)) {
305 if (mod
->Vpp1
!= mod
->Vpp2
)
306 ds_dbg(s
, 0, "Vpp1 and Vpp2 must be the same\n");
308 s
->socket
.Vpp
= mod
->Vpp1
;
309 if (s
->ops
->set_socket(s
, &s
->socket
)) {
310 dev_printk(KERN_WARNING
, &s
->dev
,
311 "Unable to set VPP\n");
314 } else if ((mod
->Attributes
& CONF_VPP1_CHANGE_VALID
) ||
315 (mod
->Attributes
& CONF_VPP2_CHANGE_VALID
)) {
316 ds_dbg(s
, 0, "changing Vcc is not allowed at this time\n");
320 if (mod
->Attributes
& CONF_IO_CHANGE_WIDTH
) {
321 pccard_io_map io_off
= { 0, 0, 0, 0, 1 };
325 io_on
.speed
= io_speed
;
326 for (i
= 0; i
< MAX_IO_WIN
; i
++) {
332 io_on
.flags
= MAP_ACTIVE
| IO_DATA_PATH_WIDTH_8
;
333 io_on
.start
= s
->io
[i
].res
->start
;
334 io_on
.stop
= s
->io
[i
].res
->end
;
336 s
->ops
->set_io_map(s
, &io_off
);
338 s
->ops
->set_io_map(s
, &io_on
);
343 } /* modify_configuration */
344 EXPORT_SYMBOL(pcmcia_modify_configuration
);
347 int pcmcia_release_configuration(struct pcmcia_device
*p_dev
)
349 pccard_io_map io
= { 0, 0, 0, 0, 1 };
350 struct pcmcia_socket
*s
= p_dev
->socket
;
351 config_t
*c
= p_dev
->function_config
;
354 if (p_dev
->_locked
) {
356 if (--(s
->lock_count
) == 0) {
357 s
->socket
.flags
= SS_OUTPUT_ENA
; /* Is this correct? */
359 s
->socket
.io_irq
= 0;
360 s
->ops
->set_socket(s
, &s
->socket
);
363 if (c
->state
& CONFIG_LOCKED
) {
364 c
->state
&= ~CONFIG_LOCKED
;
365 if (c
->state
& CONFIG_IO_REQ
)
366 for (i
= 0; i
< MAX_IO_WIN
; i
++) {
370 if (s
->io
[i
].Config
!= 0)
373 s
->ops
->set_io_map(s
, &io
);
378 } /* pcmcia_release_configuration */
381 /** pcmcia_release_io
383 * Release_io() releases the I/O ranges allocated by a client. This
384 * may be invoked some time after a card ejection has already dumped
385 * the actual socket configuration, so if the client is "stale", we
386 * don't bother checking the port ranges against the current socket
389 static int pcmcia_release_io(struct pcmcia_device
*p_dev
, io_req_t
*req
)
391 struct pcmcia_socket
*s
= p_dev
->socket
;
392 config_t
*c
= p_dev
->function_config
;
399 if ((c
->io
.BasePort1
!= req
->BasePort1
) ||
400 (c
->io
.NumPorts1
!= req
->NumPorts1
) ||
401 (c
->io
.BasePort2
!= req
->BasePort2
) ||
402 (c
->io
.NumPorts2
!= req
->NumPorts2
))
405 c
->state
&= ~CONFIG_IO_REQ
;
407 release_io_space(s
, req
->BasePort1
, req
->NumPorts1
);
409 release_io_space(s
, req
->BasePort2
, req
->NumPorts2
);
412 } /* pcmcia_release_io */
415 static int pcmcia_release_irq(struct pcmcia_device
*p_dev
, irq_req_t
*req
)
417 struct pcmcia_socket
*s
= p_dev
->socket
;
418 config_t
*c
= p_dev
->function_config
;
424 if (c
->state
& CONFIG_LOCKED
)
426 if (c
->irq
.Attributes
!= req
->Attributes
) {
427 ds_dbg(s
, 0, "IRQ attributes must match assigned ones\n");
430 if (s
->irq
.AssignedIRQ
!= req
->AssignedIRQ
) {
431 ds_dbg(s
, 0, "IRQ must match assigned one\n");
434 if (--s
->irq
.Config
== 0) {
435 c
->state
&= ~CONFIG_IRQ_REQ
;
436 s
->irq
.AssignedIRQ
= 0;
439 if (req
->Attributes
& IRQ_HANDLE_PRESENT
) {
440 free_irq(req
->AssignedIRQ
, req
->Instance
);
443 #ifdef CONFIG_PCMCIA_PROBE
444 pcmcia_used_irq
[req
->AssignedIRQ
]--;
448 } /* pcmcia_release_irq */
451 int pcmcia_release_window(window_handle_t win
)
453 struct pcmcia_socket
*s
;
455 if ((win
== NULL
) || (win
->magic
!= WINDOW_MAGIC
))
458 if (!(win
->handle
->_win
& CLIENT_WIN_REQ(win
->index
)))
461 /* Shut down memory window */
462 win
->ctl
.flags
&= ~MAP_ACTIVE
;
463 s
->ops
->set_mem_map(s
, &win
->ctl
);
464 s
->state
&= ~SOCKET_WIN_REQ(win
->index
);
466 /* Release system memory */
468 release_resource(win
->ctl
.res
);
472 win
->handle
->_win
&= ~CLIENT_WIN_REQ(win
->index
);
477 } /* pcmcia_release_window */
478 EXPORT_SYMBOL(pcmcia_release_window
);
481 int pcmcia_request_configuration(struct pcmcia_device
*p_dev
,
486 struct pcmcia_socket
*s
= p_dev
->socket
;
490 if (!(s
->state
& SOCKET_PRESENT
))
493 if (req
->IntType
& INT_CARDBUS
) {
494 ds_dbg(p_dev
->socket
, 0, "IntType may not be INT_CARDBUS\n");
497 c
= p_dev
->function_config
;
498 if (c
->state
& CONFIG_LOCKED
)
501 /* Do power control. We don't allow changes in Vcc. */
502 s
->socket
.Vpp
= req
->Vpp
;
503 if (s
->ops
->set_socket(s
, &s
->socket
)) {
504 dev_printk(KERN_WARNING
, &s
->dev
,
505 "Unable to set socket state\n");
509 /* Pick memory or I/O card, DMA mode, interrupt */
510 c
->IntType
= req
->IntType
;
511 c
->Attributes
= req
->Attributes
;
512 if (req
->IntType
& INT_MEMORY_AND_IO
)
513 s
->socket
.flags
|= SS_IOCARD
;
514 if (req
->IntType
& INT_ZOOMED_VIDEO
)
515 s
->socket
.flags
|= SS_ZVCARD
| SS_IOCARD
;
516 if (req
->Attributes
& CONF_ENABLE_DMA
)
517 s
->socket
.flags
|= SS_DMA_MODE
;
518 if (req
->Attributes
& CONF_ENABLE_SPKR
)
519 s
->socket
.flags
|= SS_SPKR_ENA
;
520 if (req
->Attributes
& CONF_ENABLE_IRQ
)
521 s
->socket
.io_irq
= s
->irq
.AssignedIRQ
;
523 s
->socket
.io_irq
= 0;
524 s
->ops
->set_socket(s
, &s
->socket
);
527 /* Set up CIS configuration registers */
528 base
= c
->ConfigBase
= req
->ConfigBase
;
529 c
->CardValues
= req
->Present
;
530 if (req
->Present
& PRESENT_COPY
) {
532 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_SCR
)>>1, 1, &c
->Copy
);
534 if (req
->Present
& PRESENT_OPTION
) {
535 if (s
->functions
== 1) {
536 c
->Option
= req
->ConfigIndex
& COR_CONFIG_MASK
;
538 c
->Option
= req
->ConfigIndex
& COR_MFC_CONFIG_MASK
;
539 c
->Option
|= COR_FUNC_ENA
|COR_IREQ_ENA
;
540 if (req
->Present
& PRESENT_IOBASE_0
)
541 c
->Option
|= COR_ADDR_DECODE
;
543 if (c
->state
& CONFIG_IRQ_REQ
)
544 if (!(c
->irq
.Attributes
& IRQ_FORCED_PULSE
))
545 c
->Option
|= COR_LEVEL_REQ
;
546 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_COR
)>>1, 1, &c
->Option
);
549 if (req
->Present
& PRESENT_STATUS
) {
550 c
->Status
= req
->Status
;
551 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_CCSR
)>>1, 1, &c
->Status
);
553 if (req
->Present
& PRESENT_PIN_REPLACE
) {
555 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_PRR
)>>1, 1, &c
->Pin
);
557 if (req
->Present
& PRESENT_EXT_STATUS
) {
558 c
->ExtStatus
= req
->ExtStatus
;
559 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_ESR
)>>1, 1, &c
->ExtStatus
);
561 if (req
->Present
& PRESENT_IOBASE_0
) {
562 u_char b
= c
->io
.BasePort1
& 0xff;
563 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_IOBASE_0
)>>1, 1, &b
);
564 b
= (c
->io
.BasePort1
>> 8) & 0xff;
565 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_IOBASE_1
)>>1, 1, &b
);
567 if (req
->Present
& PRESENT_IOSIZE
) {
568 u_char b
= c
->io
.NumPorts1
+ c
->io
.NumPorts2
- 1;
569 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_IOSIZE
)>>1, 1, &b
);
572 /* Configure I/O windows */
573 if (c
->state
& CONFIG_IO_REQ
) {
574 iomap
.speed
= io_speed
;
575 for (i
= 0; i
< MAX_IO_WIN
; i
++)
578 iomap
.flags
= MAP_ACTIVE
;
579 switch (s
->io
[i
].res
->flags
& IO_DATA_PATH_WIDTH
) {
580 case IO_DATA_PATH_WIDTH_16
:
581 iomap
.flags
|= MAP_16BIT
; break;
582 case IO_DATA_PATH_WIDTH_AUTO
:
583 iomap
.flags
|= MAP_AUTOSZ
; break;
587 iomap
.start
= s
->io
[i
].res
->start
;
588 iomap
.stop
= s
->io
[i
].res
->end
;
589 s
->ops
->set_io_map(s
, &iomap
);
594 c
->state
|= CONFIG_LOCKED
;
597 } /* pcmcia_request_configuration */
598 EXPORT_SYMBOL(pcmcia_request_configuration
);
601 /** pcmcia_request_io
603 * Request_io() reserves ranges of port addresses for a socket.
604 * I have not implemented range sharing or alias addressing.
606 int pcmcia_request_io(struct pcmcia_device
*p_dev
, io_req_t
*req
)
608 struct pcmcia_socket
*s
= p_dev
->socket
;
611 if (!(s
->state
& SOCKET_PRESENT
))
616 c
= p_dev
->function_config
;
617 if (c
->state
& CONFIG_LOCKED
)
619 if (c
->state
& CONFIG_IO_REQ
) {
620 ds_dbg(s
, 0, "IO already configured\n");
623 if (req
->Attributes1
& (IO_SHARED
| IO_FORCE_ALIAS_ACCESS
)) {
624 ds_dbg(s
, 0, "bad attribute setting for IO region 1\n");
627 if ((req
->NumPorts2
> 0) &&
628 (req
->Attributes2
& (IO_SHARED
| IO_FORCE_ALIAS_ACCESS
))) {
629 ds_dbg(s
, 0, "bad attribute setting for IO region 2\n");
633 ds_dbg(s
, 1, "trying to allocate resource 1\n");
634 if (alloc_io_space(s
, req
->Attributes1
, &req
->BasePort1
,
635 req
->NumPorts1
, req
->IOAddrLines
)) {
636 ds_dbg(s
, 0, "allocation of resource 1 failed\n");
640 if (req
->NumPorts2
) {
641 ds_dbg(s
, 1, "trying to allocate resource 2\n");
642 if (alloc_io_space(s
, req
->Attributes2
, &req
->BasePort2
,
643 req
->NumPorts2
, req
->IOAddrLines
)) {
644 ds_dbg(s
, 0, "allocation of resource 2 failed\n");
645 release_io_space(s
, req
->BasePort1
, req
->NumPorts1
);
651 c
->state
|= CONFIG_IO_REQ
;
654 } /* pcmcia_request_io */
655 EXPORT_SYMBOL(pcmcia_request_io
);
658 /** pcmcia_request_irq
660 * Request_irq() reserves an irq for this client.
662 * Also, since Linux only reserves irq's when they are actually
663 * hooked, we don't guarantee that an irq will still be available
664 * when the configuration is locked. Now that I think about it,
665 * there might be a way to fix this using a dummy handler.
668 #ifdef CONFIG_PCMCIA_PROBE
669 static irqreturn_t
test_action(int cpl
, void *dev_id
)
675 int pcmcia_request_irq(struct pcmcia_device
*p_dev
, irq_req_t
*req
)
677 struct pcmcia_socket
*s
= p_dev
->socket
;
679 int ret
= -EINVAL
, irq
= 0;
682 if (!(s
->state
& SOCKET_PRESENT
))
684 c
= p_dev
->function_config
;
685 if (c
->state
& CONFIG_LOCKED
)
687 if (c
->state
& CONFIG_IRQ_REQ
) {
688 ds_dbg(s
, 0, "IRQ already configured\n");
692 /* Decide what type of interrupt we are registering */
694 if (s
->functions
> 1) /* All of this ought to be handled higher up */
696 if (req
->Attributes
& IRQ_TYPE_DYNAMIC_SHARING
)
699 #ifdef CONFIG_PCMCIA_PROBE
702 /* if the underlying IRQ infrastructure allows for it, only allocate
703 * the IRQ, but do not enable it
705 if (!(req
->Attributes
& IRQ_HANDLE_PRESENT
))
706 type
|= IRQ_NOAUTOEN
;
707 #endif /* IRQ_NOAUTOEN */
709 if (s
->irq
.AssignedIRQ
!= 0) {
710 /* If the interrupt is already assigned, it must be the same */
711 irq
= s
->irq
.AssignedIRQ
;
714 u32 mask
= s
->irq_mask
;
715 void *data
= &p_dev
->dev
.driver
; /* something unique to this device */
717 for (try = 0; try < 64; try++) {
720 /* marked as available by driver, and not blocked by userspace? */
721 if (!((mask
>> irq
) & 1))
724 /* avoid an IRQ which is already used by a PCMCIA card */
725 if ((try < 32) && pcmcia_used_irq
[irq
])
728 /* register the correct driver, if possible, of check whether
729 * registering a dummy handle works, i.e. if the IRQ isn't
730 * marked as used by the kernel resource management core */
731 ret
= request_irq(irq
,
732 (req
->Attributes
& IRQ_HANDLE_PRESENT
) ? req
->Handler
: test_action
,
735 (req
->Attributes
& IRQ_HANDLE_PRESENT
) ? req
->Instance
: data
);
737 if (!(req
->Attributes
& IRQ_HANDLE_PRESENT
))
744 /* only assign PCI irq if no IRQ already assigned */
745 if (ret
&& !s
->irq
.AssignedIRQ
) {
752 if (ret
&& (req
->Attributes
& IRQ_HANDLE_PRESENT
)) {
753 ret
= request_irq(irq
, req
->Handler
, type
,
754 p_dev
->devname
, req
->Instance
);
759 /* Make sure the fact the request type was overridden is passed back */
760 if (type
== IRQF_SHARED
&& !(req
->Attributes
& IRQ_TYPE_DYNAMIC_SHARING
)) {
761 req
->Attributes
|= IRQ_TYPE_DYNAMIC_SHARING
;
762 dev_printk(KERN_WARNING
, &p_dev
->dev
, "pcmcia: "
763 "request for exclusive IRQ could not be fulfilled.\n");
764 dev_printk(KERN_WARNING
, &p_dev
->dev
, "pcmcia: the driver "
765 "needs updating to supported shared IRQ lines.\n");
767 c
->irq
.Attributes
= req
->Attributes
;
768 s
->irq
.AssignedIRQ
= req
->AssignedIRQ
= irq
;
771 c
->state
|= CONFIG_IRQ_REQ
;
774 #ifdef CONFIG_PCMCIA_PROBE
775 pcmcia_used_irq
[irq
]++;
779 } /* pcmcia_request_irq */
780 EXPORT_SYMBOL(pcmcia_request_irq
);
783 /** pcmcia_request_window
785 * Request_window() establishes a mapping between card memory space
786 * and system memory space.
788 int pcmcia_request_window(struct pcmcia_device
**p_dev
, win_req_t
*req
, window_handle_t
*wh
)
790 struct pcmcia_socket
*s
= (*p_dev
)->socket
;
795 if (!(s
->state
& SOCKET_PRESENT
))
797 if (req
->Attributes
& (WIN_PAGED
| WIN_SHARED
)) {
798 ds_dbg(s
, 0, "bad attribute setting for iomem region\n");
802 /* Window size defaults to smallest available */
804 req
->Size
= s
->map_size
;
805 align
= (((s
->features
& SS_CAP_MEM_ALIGN
) ||
806 (req
->Attributes
& WIN_STRICT_ALIGN
)) ?
807 req
->Size
: s
->map_size
);
808 if (req
->Size
& (s
->map_size
-1)) {
809 ds_dbg(s
, 0, "invalid map size\n");
812 if ((req
->Base
&& (s
->features
& SS_CAP_STATIC_MAP
)) ||
813 (req
->Base
& (align
-1))) {
814 ds_dbg(s
, 0, "invalid base address\n");
820 /* Allocate system memory window */
821 for (w
= 0; w
< MAX_WIN
; w
++)
822 if (!(s
->state
& SOCKET_WIN_REQ(w
))) break;
824 ds_dbg(s
, 0, "all windows are used already\n");
829 win
->magic
= WINDOW_MAGIC
;
831 win
->handle
= *p_dev
;
834 if (!(s
->features
& SS_CAP_STATIC_MAP
)) {
835 win
->ctl
.res
= pcmcia_find_mem_region(req
->Base
, req
->Size
, align
,
836 (req
->Attributes
& WIN_MAP_BELOW_1MB
), s
);
838 ds_dbg(s
, 0, "allocating mem region failed\n");
842 (*p_dev
)->_win
|= CLIENT_WIN_REQ(w
);
844 /* Configure the socket controller */
847 win
->ctl
.speed
= req
->AccessSpeed
;
848 if (req
->Attributes
& WIN_MEMORY_TYPE
)
849 win
->ctl
.flags
|= MAP_ATTRIB
;
850 if (req
->Attributes
& WIN_ENABLE
)
851 win
->ctl
.flags
|= MAP_ACTIVE
;
852 if (req
->Attributes
& WIN_DATA_WIDTH_16
)
853 win
->ctl
.flags
|= MAP_16BIT
;
854 if (req
->Attributes
& WIN_USE_WAIT
)
855 win
->ctl
.flags
|= MAP_USE_WAIT
;
856 win
->ctl
.card_start
= 0;
857 if (s
->ops
->set_mem_map(s
, &win
->ctl
) != 0) {
858 ds_dbg(s
, 0, "failed to set memory mapping\n");
861 s
->state
|= SOCKET_WIN_REQ(w
);
863 /* Return window handle */
864 if (s
->features
& SS_CAP_STATIC_MAP
) {
865 req
->Base
= win
->ctl
.static_start
;
867 req
->Base
= win
->ctl
.res
->start
;
872 } /* pcmcia_request_window */
873 EXPORT_SYMBOL(pcmcia_request_window
);
875 void pcmcia_disable_device(struct pcmcia_device
*p_dev
) {
876 pcmcia_release_configuration(p_dev
);
877 pcmcia_release_io(p_dev
, &p_dev
->io
);
878 pcmcia_release_irq(p_dev
, &p_dev
->irq
);
880 pcmcia_release_window(p_dev
->win
);
882 EXPORT_SYMBOL(pcmcia_disable_device
);
885 struct pcmcia_cfg_mem
{
889 cistpl_cftable_entry_t dflt
;
893 * pcmcia_loop_config() - loop over configuration options
894 * @p_dev: the struct pcmcia_device which we need to loop for.
895 * @conf_check: function to call for each configuration option.
896 * It gets passed the struct pcmcia_device, the CIS data
897 * describing the configuration option, and private data
898 * being passed to pcmcia_loop_config()
899 * @priv_data: private data to be passed to the conf_check function.
901 * pcmcia_loop_config() loops over all configuration options, and calls
902 * the driver-specific conf_check() for each one, checking whether
905 int pcmcia_loop_config(struct pcmcia_device
*p_dev
,
906 int (*conf_check
) (struct pcmcia_device
*p_dev
,
907 cistpl_cftable_entry_t
*cfg
,
908 cistpl_cftable_entry_t
*dflt
,
913 struct pcmcia_cfg_mem
*cfg_mem
;
919 cfg_mem
= kzalloc(sizeof(struct pcmcia_cfg_mem
), GFP_KERNEL
);
923 /* get the current Vcc setting */
924 vcc
= p_dev
->socket
->socket
.Vcc
;
926 tuple
= &cfg_mem
->tuple
;
927 tuple
->TupleData
= cfg_mem
->buf
;
928 tuple
->TupleDataMax
= 255;
929 tuple
->TupleOffset
= 0;
930 tuple
->DesiredTuple
= CISTPL_CFTABLE_ENTRY
;
931 tuple
->Attributes
= 0;
933 ret
= pcmcia_get_first_tuple(p_dev
, tuple
);
935 cistpl_cftable_entry_t
*cfg
= &cfg_mem
->parse
.cftable_entry
;
937 if (pcmcia_get_tuple_data(p_dev
, tuple
))
940 if (pcmcia_parse_tuple(tuple
, &cfg_mem
->parse
))
944 p_dev
->conf
.ConfigIndex
= cfg
->index
;
945 if (cfg
->flags
& CISTPL_CFTABLE_DEFAULT
)
946 cfg_mem
->dflt
= *cfg
;
948 ret
= conf_check(p_dev
, cfg
, &cfg_mem
->dflt
, vcc
, priv_data
);
953 ret
= pcmcia_get_next_tuple(p_dev
, tuple
);
958 EXPORT_SYMBOL(pcmcia_loop_config
);