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/config.h>
18 #include <linux/module.h>
19 #include <linux/kernel.h>
20 #include <linux/interrupt.h>
21 #include <linux/delay.h>
22 #include <linux/pci.h>
23 #include <linux/device.h>
25 #define IN_CARD_SERVICES
26 #include <pcmcia/version.h>
27 #include <pcmcia/cs_types.h>
28 #include <pcmcia/ss.h>
29 #include <pcmcia/cs.h>
30 #include <pcmcia/bulkmem.h>
31 #include <pcmcia/cistpl.h>
32 #include <pcmcia/cisreg.h>
33 #include <pcmcia/ds.h>
35 #include "cs_internal.h"
36 #include "ds_internal.h"
39 static const char *release
= "Linux Kernel Card Services";
41 /* Access speed for IO windows */
42 static int io_speed
= 0;
43 module_param(io_speed
, int, 0444);
46 #ifdef CONFIG_PCMCIA_PROBE
47 /* mask of IRQs already reserved by other cards, we should avoid using them */
48 static u8 pcmcia_used_irq
[NR_IRQS
];
53 extern int ds_pc_debug
;
54 #define cs_socket_name(skt) ((skt)->dev.class_id)
56 #define ds_dbg(skt, lvl, fmt, arg...) do { \
57 if (ds_pc_debug >= lvl) \
58 printk(KERN_DEBUG "pcmcia_resource: %s: " fmt, \
59 cs_socket_name(skt) , ## arg); \
62 #define ds_dbg(lvl, fmt, arg...) do { } while (0)
69 * Special stuff for managing IO windows, because they are scarce
72 static int alloc_io_space(struct pcmcia_socket
*s
, u_int attr
, ioaddr_t
*base
,
73 ioaddr_t num
, u_int lines
)
76 kio_addr_t
try, align
;
78 align
= (*base
) ? (lines
? 1<<lines
: 0) : 1;
79 if (align
&& (align
< num
)) {
81 ds_dbg(s
, 0, "odd IO request: num %#x align %#lx\n",
85 while (align
&& (align
< num
)) align
<<= 1;
87 if (*base
& ~(align
-1)) {
88 ds_dbg(s
, 0, "odd IO request: base %#x align %#lx\n",
92 if ((s
->features
& SS_CAP_STATIC_MAP
) && s
->io_offset
) {
93 *base
= s
->io_offset
| (*base
& 0x0fff);
96 /* Check for an already-allocated window that must conflict with
97 * what was asked for. It is a hack because it does not catch all
98 * potential conflicts, just the most obvious ones.
100 for (i
= 0; i
< MAX_IO_WIN
; i
++)
101 if ((s
->io
[i
].NumPorts
!= 0) &&
102 ((s
->io
[i
].BasePort
& (align
-1)) == *base
))
104 for (i
= 0; i
< MAX_IO_WIN
; i
++) {
105 if (s
->io
[i
].NumPorts
== 0) {
106 s
->io
[i
].res
= pcmcia_find_io_region(*base
, num
, align
, s
);
108 s
->io
[i
].Attributes
= attr
;
109 s
->io
[i
].BasePort
= *base
= s
->io
[i
].res
->start
;
110 s
->io
[i
].NumPorts
= s
->io
[i
].InUse
= num
;
114 } else if (s
->io
[i
].Attributes
!= attr
)
116 /* Try to extend top of window */
117 try = s
->io
[i
].BasePort
+ s
->io
[i
].NumPorts
;
118 if ((*base
== 0) || (*base
== try))
119 if (pcmcia_adjust_io_region(s
->io
[i
].res
, s
->io
[i
].res
->start
,
120 s
->io
[i
].res
->end
+ num
, s
) == 0) {
122 s
->io
[i
].NumPorts
+= num
;
123 s
->io
[i
].InUse
+= num
;
126 /* Try to extend bottom of window */
127 try = s
->io
[i
].BasePort
- num
;
128 if ((*base
== 0) || (*base
== try))
129 if (pcmcia_adjust_io_region(s
->io
[i
].res
, s
->io
[i
].res
->start
- num
,
130 s
->io
[i
].res
->end
, s
) == 0) {
131 s
->io
[i
].BasePort
= *base
= try;
132 s
->io
[i
].NumPorts
+= num
;
133 s
->io
[i
].InUse
+= num
;
137 return (i
== MAX_IO_WIN
);
138 } /* alloc_io_space */
141 static void release_io_space(struct pcmcia_socket
*s
, ioaddr_t base
,
146 for (i
= 0; i
< MAX_IO_WIN
; i
++) {
147 if ((s
->io
[i
].BasePort
<= base
) &&
148 (s
->io
[i
].BasePort
+s
->io
[i
].NumPorts
>= base
+num
)) {
149 s
->io
[i
].InUse
-= num
;
150 /* Free the window if no one else is using it */
151 if (s
->io
[i
].InUse
== 0) {
152 s
->io
[i
].NumPorts
= 0;
153 release_resource(s
->io
[i
].res
);
159 } /* release_io_space */
162 /** pccard_access_configuration_register
164 * Access_configuration_register() reads and writes configuration
165 * registers in attribute memory. Memory window 0 is reserved for
166 * this and the tuple reading services.
169 int pccard_access_configuration_register(struct pcmcia_socket
*s
,
170 unsigned int function
,
177 if (!s
|| !s
->config
)
180 c
= &s
->config
[function
];
185 if (!(c
->state
& CONFIG_LOCKED
))
186 return CS_CONFIGURATION_LOCKED
;
188 addr
= (c
->ConfigBase
+ reg
->Offset
) >> 1;
190 switch (reg
->Action
) {
192 pcmcia_read_cis_mem(s
, 1, addr
, 1, &val
);
197 pcmcia_write_cis_mem(s
, 1, addr
, 1, &val
);
204 } /* pccard_access_configuration_register */
205 EXPORT_SYMBOL(pccard_access_configuration_register
);
208 int pccard_get_configuration_info(struct pcmcia_socket
*s
,
209 unsigned int function
,
210 config_info_t
*config
)
214 if (!(s
->state
& SOCKET_PRESENT
))
217 config
->Function
= function
;
219 #ifdef CONFIG_CARDBUS
220 if (s
->state
& SOCKET_CARDBUS
) {
221 memset(config
, 0, sizeof(config_info_t
));
222 config
->Vcc
= s
->socket
.Vcc
;
223 config
->Vpp1
= config
->Vpp2
= s
->socket
.Vpp
;
224 config
->Option
= s
->cb_dev
->subordinate
->number
;
225 if (s
->state
& SOCKET_CARDBUS_CONFIG
) {
226 config
->Attributes
= CONF_VALID_CLIENT
;
227 config
->IntType
= INT_CARDBUS
;
228 config
->AssignedIRQ
= s
->irq
.AssignedIRQ
;
229 if (config
->AssignedIRQ
)
230 config
->Attributes
|= CONF_ENABLE_IRQ
;
231 config
->BasePort1
= s
->io
[0].BasePort
;
232 config
->NumPorts1
= s
->io
[0].NumPorts
;
238 c
= (s
->config
!= NULL
) ? &s
->config
[function
] : NULL
;
240 if ((c
== NULL
) || !(c
->state
& CONFIG_LOCKED
)) {
241 config
->Attributes
= 0;
242 config
->Vcc
= s
->socket
.Vcc
;
243 config
->Vpp1
= config
->Vpp2
= s
->socket
.Vpp
;
247 /* !!! This is a hack !!! */
248 memcpy(&config
->Attributes
, &c
->Attributes
, sizeof(config_t
));
249 config
->Attributes
|= CONF_VALID_CLIENT
;
250 config
->CardValues
= c
->CardValues
;
251 config
->IRQAttributes
= c
->irq
.Attributes
;
252 config
->AssignedIRQ
= s
->irq
.AssignedIRQ
;
253 config
->BasePort1
= c
->io
.BasePort1
;
254 config
->NumPorts1
= c
->io
.NumPorts1
;
255 config
->Attributes1
= c
->io
.Attributes1
;
256 config
->BasePort2
= c
->io
.BasePort2
;
257 config
->NumPorts2
= c
->io
.NumPorts2
;
258 config
->Attributes2
= c
->io
.Attributes2
;
259 config
->IOAddrLines
= c
->io
.IOAddrLines
;
262 } /* pccard_get_configuration_info */
263 EXPORT_SYMBOL(pccard_get_configuration_info
);
266 /** pcmcia_get_card_services_info
268 * Return information about this version of Card Services
271 int pcmcia_get_card_services_info(servinfo_t
*info
)
273 unsigned int socket_count
= 0;
274 struct list_head
*tmp
;
275 info
->Signature
[0] = 'C';
276 info
->Signature
[1] = 'S';
277 down_read(&pcmcia_socket_list_rwsem
);
278 list_for_each(tmp
, &pcmcia_socket_list
)
280 up_read(&pcmcia_socket_list_rwsem
);
281 info
->Count
= socket_count
;
282 info
->Revision
= CS_RELEASE_CODE
;
283 info
->CSLevel
= 0x0210;
284 info
->VendorString
= (char *)release
;
286 } /* get_card_services_info */
287 EXPORT_SYMBOL(pcmcia_get_card_services_info
);
290 /** pcmcia_get_window
292 int pcmcia_get_window(struct pcmcia_socket
*s
, window_handle_t
*handle
,
293 int idx
, win_req_t
*req
)
298 if (!s
|| !(s
->state
& SOCKET_PRESENT
))
300 for (w
= idx
; w
< MAX_WIN
; w
++)
301 if (s
->state
& SOCKET_WIN_REQ(w
))
304 return CS_NO_MORE_ITEMS
;
306 req
->Base
= win
->ctl
.res
->start
;
307 req
->Size
= win
->ctl
.res
->end
- win
->ctl
.res
->start
+ 1;
308 req
->AccessSpeed
= win
->ctl
.speed
;
310 if (win
->ctl
.flags
& MAP_ATTRIB
)
311 req
->Attributes
|= WIN_MEMORY_TYPE_AM
;
312 if (win
->ctl
.flags
& MAP_ACTIVE
)
313 req
->Attributes
|= WIN_ENABLE
;
314 if (win
->ctl
.flags
& MAP_16BIT
)
315 req
->Attributes
|= WIN_DATA_WIDTH_16
;
316 if (win
->ctl
.flags
& MAP_USE_WAIT
)
317 req
->Attributes
|= WIN_USE_WAIT
;
320 } /* pcmcia_get_window */
321 EXPORT_SYMBOL(pcmcia_get_window
);
324 /** pccard_get_status
326 * Get the current socket state bits. We don't support the latched
327 * SocketState yet: I haven't seen any point for it.
330 int pccard_get_status(struct pcmcia_socket
*s
, unsigned int function
,
336 s
->ops
->get_status(s
, &val
);
337 status
->CardState
= status
->SocketState
= 0;
338 status
->CardState
|= (val
& SS_DETECT
) ? CS_EVENT_CARD_DETECT
: 0;
339 status
->CardState
|= (val
& SS_CARDBUS
) ? CS_EVENT_CB_DETECT
: 0;
340 status
->CardState
|= (val
& SS_3VCARD
) ? CS_EVENT_3VCARD
: 0;
341 status
->CardState
|= (val
& SS_XVCARD
) ? CS_EVENT_XVCARD
: 0;
342 if (s
->state
& SOCKET_SUSPEND
)
343 status
->CardState
|= CS_EVENT_PM_SUSPEND
;
344 if (!(s
->state
& SOCKET_PRESENT
))
347 c
= (s
->config
!= NULL
) ? &s
->config
[function
] : NULL
;
348 if ((c
!= NULL
) && (c
->state
& CONFIG_LOCKED
) &&
349 (c
->IntType
& (INT_MEMORY_AND_IO
| INT_ZOOMED_VIDEO
))) {
351 if (c
->Present
& PRESENT_PIN_REPLACE
) {
352 pcmcia_read_cis_mem(s
, 1, (c
->ConfigBase
+CISREG_PRR
)>>1, 1, ®
);
354 (reg
& PRR_WP_STATUS
) ? CS_EVENT_WRITE_PROTECT
: 0;
356 (reg
& PRR_READY_STATUS
) ? CS_EVENT_READY_CHANGE
: 0;
358 (reg
& PRR_BVD2_STATUS
) ? CS_EVENT_BATTERY_LOW
: 0;
360 (reg
& PRR_BVD1_STATUS
) ? CS_EVENT_BATTERY_DEAD
: 0;
362 /* No PRR? Then assume we're always ready */
363 status
->CardState
|= CS_EVENT_READY_CHANGE
;
365 if (c
->Present
& PRESENT_EXT_STATUS
) {
366 pcmcia_read_cis_mem(s
, 1, (c
->ConfigBase
+CISREG_ESR
)>>1, 1, ®
);
368 (reg
& ESR_REQ_ATTN
) ? CS_EVENT_REQUEST_ATTENTION
: 0;
373 (val
& SS_WRPROT
) ? CS_EVENT_WRITE_PROTECT
: 0;
375 (val
& SS_BATDEAD
) ? CS_EVENT_BATTERY_DEAD
: 0;
377 (val
& SS_BATWARN
) ? CS_EVENT_BATTERY_LOW
: 0;
379 (val
& SS_READY
) ? CS_EVENT_READY_CHANGE
: 0;
381 } /* pccard_get_status */
382 EXPORT_SYMBOL(pccard_get_status
);
385 /** pcmcia_get_mem_page
387 * Change the card address of an already open memory window.
389 int pcmcia_get_mem_page(window_handle_t win
, memreq_t
*req
)
391 if ((win
== NULL
) || (win
->magic
!= WINDOW_MAGIC
))
392 return CS_BAD_HANDLE
;
394 req
->CardOffset
= win
->ctl
.card_start
;
396 } /* pcmcia_get_mem_page */
397 EXPORT_SYMBOL(pcmcia_get_mem_page
);
400 int pcmcia_map_mem_page(window_handle_t win
, memreq_t
*req
)
402 struct pcmcia_socket
*s
;
403 if ((win
== NULL
) || (win
->magic
!= WINDOW_MAGIC
))
404 return CS_BAD_HANDLE
;
408 win
->ctl
.card_start
= req
->CardOffset
;
409 if (s
->ops
->set_mem_map(s
, &win
->ctl
) != 0)
410 return CS_BAD_OFFSET
;
412 } /* pcmcia_map_mem_page */
413 EXPORT_SYMBOL(pcmcia_map_mem_page
);
416 /** pcmcia_modify_configuration
418 * Modify a locked socket configuration
420 int pcmcia_modify_configuration(client_handle_t handle
,
423 struct pcmcia_socket
*s
;
426 if (CHECK_HANDLE(handle
))
427 return CS_BAD_HANDLE
;
430 if (!(s
->state
& SOCKET_PRESENT
))
432 if (!(c
->state
& CONFIG_LOCKED
))
433 return CS_CONFIGURATION_LOCKED
;
435 if (mod
->Attributes
& CONF_IRQ_CHANGE_VALID
) {
436 if (mod
->Attributes
& CONF_ENABLE_IRQ
) {
437 c
->Attributes
|= CONF_ENABLE_IRQ
;
438 s
->socket
.io_irq
= s
->irq
.AssignedIRQ
;
440 c
->Attributes
&= ~CONF_ENABLE_IRQ
;
441 s
->socket
.io_irq
= 0;
443 s
->ops
->set_socket(s
, &s
->socket
);
446 if (mod
->Attributes
& CONF_VCC_CHANGE_VALID
)
449 /* We only allow changing Vpp1 and Vpp2 to the same value */
450 if ((mod
->Attributes
& CONF_VPP1_CHANGE_VALID
) &&
451 (mod
->Attributes
& CONF_VPP2_CHANGE_VALID
)) {
452 if (mod
->Vpp1
!= mod
->Vpp2
)
454 c
->Vpp1
= c
->Vpp2
= s
->socket
.Vpp
= mod
->Vpp1
;
455 if (s
->ops
->set_socket(s
, &s
->socket
))
457 } else if ((mod
->Attributes
& CONF_VPP1_CHANGE_VALID
) ||
458 (mod
->Attributes
& CONF_VPP2_CHANGE_VALID
))
462 } /* modify_configuration */
463 EXPORT_SYMBOL(pcmcia_modify_configuration
);
466 int pcmcia_release_configuration(client_handle_t handle
)
468 pccard_io_map io
= { 0, 0, 0, 0, 1 };
469 struct pcmcia_socket
*s
;
472 if (CHECK_HANDLE(handle
) ||
473 !(handle
->state
& CLIENT_CONFIG_LOCKED
))
474 return CS_BAD_HANDLE
;
475 handle
->state
&= ~CLIENT_CONFIG_LOCKED
;
478 #ifdef CONFIG_CARDBUS
479 if (handle
->state
& CLIENT_CARDBUS
)
483 if (!(handle
->state
& CLIENT_STALE
)) {
484 config_t
*c
= CONFIG(handle
);
485 if (--(s
->lock_count
) == 0) {
486 s
->socket
.flags
= SS_OUTPUT_ENA
; /* Is this correct? */
488 s
->socket
.io_irq
= 0;
489 s
->ops
->set_socket(s
, &s
->socket
);
491 if (c
->state
& CONFIG_IO_REQ
)
492 for (i
= 0; i
< MAX_IO_WIN
; i
++) {
493 if (s
->io
[i
].NumPorts
== 0)
496 if (s
->io
[i
].Config
!= 0)
499 s
->ops
->set_io_map(s
, &io
);
501 c
->state
&= ~CONFIG_LOCKED
;
505 } /* pcmcia_release_configuration */
506 EXPORT_SYMBOL(pcmcia_release_configuration
);
509 /** pcmcia_release_io
511 * Release_io() releases the I/O ranges allocated by a client. This
512 * may be invoked some time after a card ejection has already dumped
513 * the actual socket configuration, so if the client is "stale", we
514 * don't bother checking the port ranges against the current socket
517 int pcmcia_release_io(client_handle_t handle
, io_req_t
*req
)
519 struct pcmcia_socket
*s
;
521 if (CHECK_HANDLE(handle
) || !(handle
->state
& CLIENT_IO_REQ
))
522 return CS_BAD_HANDLE
;
523 handle
->state
&= ~CLIENT_IO_REQ
;
526 #ifdef CONFIG_CARDBUS
527 if (handle
->state
& CLIENT_CARDBUS
)
531 if (!(handle
->state
& CLIENT_STALE
)) {
532 config_t
*c
= CONFIG(handle
);
533 if (c
->state
& CONFIG_LOCKED
)
534 return CS_CONFIGURATION_LOCKED
;
535 if ((c
->io
.BasePort1
!= req
->BasePort1
) ||
536 (c
->io
.NumPorts1
!= req
->NumPorts1
) ||
537 (c
->io
.BasePort2
!= req
->BasePort2
) ||
538 (c
->io
.NumPorts2
!= req
->NumPorts2
))
540 c
->state
&= ~CONFIG_IO_REQ
;
543 release_io_space(s
, req
->BasePort1
, req
->NumPorts1
);
545 release_io_space(s
, req
->BasePort2
, req
->NumPorts2
);
548 } /* pcmcia_release_io */
549 EXPORT_SYMBOL(pcmcia_release_io
);
552 int pcmcia_release_irq(client_handle_t handle
, irq_req_t
*req
)
554 struct pcmcia_socket
*s
;
555 if (CHECK_HANDLE(handle
) || !(handle
->state
& CLIENT_IRQ_REQ
))
556 return CS_BAD_HANDLE
;
557 handle
->state
&= ~CLIENT_IRQ_REQ
;
560 if (!(handle
->state
& CLIENT_STALE
)) {
561 config_t
*c
= CONFIG(handle
);
562 if (c
->state
& CONFIG_LOCKED
)
563 return CS_CONFIGURATION_LOCKED
;
564 if (c
->irq
.Attributes
!= req
->Attributes
)
565 return CS_BAD_ATTRIBUTE
;
566 if (s
->irq
.AssignedIRQ
!= req
->AssignedIRQ
)
568 if (--s
->irq
.Config
== 0) {
569 c
->state
&= ~CONFIG_IRQ_REQ
;
570 s
->irq
.AssignedIRQ
= 0;
574 if (req
->Attributes
& IRQ_HANDLE_PRESENT
) {
575 free_irq(req
->AssignedIRQ
, req
->Instance
);
578 #ifdef CONFIG_PCMCIA_PROBE
579 pcmcia_used_irq
[req
->AssignedIRQ
]--;
583 } /* pcmcia_release_irq */
584 EXPORT_SYMBOL(pcmcia_release_irq
);
587 int pcmcia_release_window(window_handle_t win
)
589 struct pcmcia_socket
*s
;
591 if ((win
== NULL
) || (win
->magic
!= WINDOW_MAGIC
))
592 return CS_BAD_HANDLE
;
594 if (!(win
->handle
->state
& CLIENT_WIN_REQ(win
->index
)))
595 return CS_BAD_HANDLE
;
597 /* Shut down memory window */
598 win
->ctl
.flags
&= ~MAP_ACTIVE
;
599 s
->ops
->set_mem_map(s
, &win
->ctl
);
600 s
->state
&= ~SOCKET_WIN_REQ(win
->index
);
602 /* Release system memory */
604 release_resource(win
->ctl
.res
);
608 win
->handle
->state
&= ~CLIENT_WIN_REQ(win
->index
);
613 } /* pcmcia_release_window */
614 EXPORT_SYMBOL(pcmcia_release_window
);
617 int pcmcia_request_configuration(client_handle_t handle
,
622 struct pcmcia_socket
*s
;
626 if (CHECK_HANDLE(handle
))
627 return CS_BAD_HANDLE
;
629 if (!(s
->state
& SOCKET_PRESENT
))
632 #ifdef CONFIG_CARDBUS
633 if (handle
->state
& CLIENT_CARDBUS
)
634 return CS_UNSUPPORTED_MODE
;
637 if (req
->IntType
& INT_CARDBUS
)
638 return CS_UNSUPPORTED_MODE
;
640 if (c
->state
& CONFIG_LOCKED
)
641 return CS_CONFIGURATION_LOCKED
;
643 /* Do power control. We don't allow changes in Vcc. */
644 if (s
->socket
.Vcc
!= req
->Vcc
)
646 if (req
->Vpp1
!= req
->Vpp2
)
648 s
->socket
.Vpp
= req
->Vpp1
;
649 if (s
->ops
->set_socket(s
, &s
->socket
))
652 c
->Vcc
= req
->Vcc
; c
->Vpp1
= c
->Vpp2
= req
->Vpp1
;
654 /* Pick memory or I/O card, DMA mode, interrupt */
655 c
->IntType
= req
->IntType
;
656 c
->Attributes
= req
->Attributes
;
657 if (req
->IntType
& INT_MEMORY_AND_IO
)
658 s
->socket
.flags
|= SS_IOCARD
;
659 if (req
->IntType
& INT_ZOOMED_VIDEO
)
660 s
->socket
.flags
|= SS_ZVCARD
| SS_IOCARD
;
661 if (req
->Attributes
& CONF_ENABLE_DMA
)
662 s
->socket
.flags
|= SS_DMA_MODE
;
663 if (req
->Attributes
& CONF_ENABLE_SPKR
)
664 s
->socket
.flags
|= SS_SPKR_ENA
;
665 if (req
->Attributes
& CONF_ENABLE_IRQ
)
666 s
->socket
.io_irq
= s
->irq
.AssignedIRQ
;
668 s
->socket
.io_irq
= 0;
669 s
->ops
->set_socket(s
, &s
->socket
);
672 /* Set up CIS configuration registers */
673 base
= c
->ConfigBase
= req
->ConfigBase
;
674 c
->Present
= c
->CardValues
= req
->Present
;
675 if (req
->Present
& PRESENT_COPY
) {
677 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_SCR
)>>1, 1, &c
->Copy
);
679 if (req
->Present
& PRESENT_OPTION
) {
680 if (s
->functions
== 1) {
681 c
->Option
= req
->ConfigIndex
& COR_CONFIG_MASK
;
683 c
->Option
= req
->ConfigIndex
& COR_MFC_CONFIG_MASK
;
684 c
->Option
|= COR_FUNC_ENA
|COR_IREQ_ENA
;
685 if (req
->Present
& PRESENT_IOBASE_0
)
686 c
->Option
|= COR_ADDR_DECODE
;
688 if (c
->state
& CONFIG_IRQ_REQ
)
689 if (!(c
->irq
.Attributes
& IRQ_FORCED_PULSE
))
690 c
->Option
|= COR_LEVEL_REQ
;
691 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_COR
)>>1, 1, &c
->Option
);
694 if (req
->Present
& PRESENT_STATUS
) {
695 c
->Status
= req
->Status
;
696 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_CCSR
)>>1, 1, &c
->Status
);
698 if (req
->Present
& PRESENT_PIN_REPLACE
) {
700 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_PRR
)>>1, 1, &c
->Pin
);
702 if (req
->Present
& PRESENT_EXT_STATUS
) {
703 c
->ExtStatus
= req
->ExtStatus
;
704 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_ESR
)>>1, 1, &c
->ExtStatus
);
706 if (req
->Present
& PRESENT_IOBASE_0
) {
707 u_char b
= c
->io
.BasePort1
& 0xff;
708 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_IOBASE_0
)>>1, 1, &b
);
709 b
= (c
->io
.BasePort1
>> 8) & 0xff;
710 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_IOBASE_1
)>>1, 1, &b
);
712 if (req
->Present
& PRESENT_IOSIZE
) {
713 u_char b
= c
->io
.NumPorts1
+ c
->io
.NumPorts2
- 1;
714 pcmcia_write_cis_mem(s
, 1, (base
+ CISREG_IOSIZE
)>>1, 1, &b
);
717 /* Configure I/O windows */
718 if (c
->state
& CONFIG_IO_REQ
) {
719 iomap
.speed
= io_speed
;
720 for (i
= 0; i
< MAX_IO_WIN
; i
++)
721 if (s
->io
[i
].NumPorts
!= 0) {
723 iomap
.flags
= MAP_ACTIVE
;
724 switch (s
->io
[i
].Attributes
& IO_DATA_PATH_WIDTH
) {
725 case IO_DATA_PATH_WIDTH_16
:
726 iomap
.flags
|= MAP_16BIT
; break;
727 case IO_DATA_PATH_WIDTH_AUTO
:
728 iomap
.flags
|= MAP_AUTOSZ
; break;
732 iomap
.start
= s
->io
[i
].BasePort
;
733 iomap
.stop
= iomap
.start
+ s
->io
[i
].NumPorts
- 1;
734 s
->ops
->set_io_map(s
, &iomap
);
739 c
->state
|= CONFIG_LOCKED
;
740 handle
->state
|= CLIENT_CONFIG_LOCKED
;
742 } /* pcmcia_request_configuration */
743 EXPORT_SYMBOL(pcmcia_request_configuration
);
746 /** pcmcia_request_io
748 * Request_io() reserves ranges of port addresses for a socket.
749 * I have not implemented range sharing or alias addressing.
751 int pcmcia_request_io(client_handle_t handle
, io_req_t
*req
)
753 struct pcmcia_socket
*s
;
756 if (CHECK_HANDLE(handle
))
757 return CS_BAD_HANDLE
;
759 if (!(s
->state
& SOCKET_PRESENT
))
762 if (handle
->state
& CLIENT_CARDBUS
) {
763 #ifdef CONFIG_CARDBUS
764 handle
->state
|= CLIENT_IO_REQ
;
767 return CS_UNSUPPORTED_FUNCTION
;
772 return CS_UNSUPPORTED_MODE
;
774 if (c
->state
& CONFIG_LOCKED
)
775 return CS_CONFIGURATION_LOCKED
;
776 if (c
->state
& CONFIG_IO_REQ
)
778 if (req
->Attributes1
& (IO_SHARED
| IO_FORCE_ALIAS_ACCESS
))
779 return CS_BAD_ATTRIBUTE
;
780 if ((req
->NumPorts2
> 0) &&
781 (req
->Attributes2
& (IO_SHARED
| IO_FORCE_ALIAS_ACCESS
)))
782 return CS_BAD_ATTRIBUTE
;
784 if (alloc_io_space(s
, req
->Attributes1
, &req
->BasePort1
,
785 req
->NumPorts1
, req
->IOAddrLines
))
788 if (req
->NumPorts2
) {
789 if (alloc_io_space(s
, req
->Attributes2
, &req
->BasePort2
,
790 req
->NumPorts2
, req
->IOAddrLines
)) {
791 release_io_space(s
, req
->BasePort1
, req
->NumPorts1
);
797 c
->state
|= CONFIG_IO_REQ
;
798 handle
->state
|= CLIENT_IO_REQ
;
800 } /* pcmcia_request_io */
801 EXPORT_SYMBOL(pcmcia_request_io
);
804 /** pcmcia_request_irq
806 * Request_irq() reserves an irq for this client.
808 * Also, since Linux only reserves irq's when they are actually
809 * hooked, we don't guarantee that an irq will still be available
810 * when the configuration is locked. Now that I think about it,
811 * there might be a way to fix this using a dummy handler.
814 #ifdef CONFIG_PCMCIA_PROBE
815 static irqreturn_t
test_action(int cpl
, void *dev_id
, struct pt_regs
*regs
)
821 int pcmcia_request_irq(client_handle_t handle
, irq_req_t
*req
)
823 struct pcmcia_socket
*s
;
825 int ret
= CS_IN_USE
, irq
= 0;
826 struct pcmcia_device
*p_dev
= handle_to_pdev(handle
);
828 if (CHECK_HANDLE(handle
))
829 return CS_BAD_HANDLE
;
831 if (!(s
->state
& SOCKET_PRESENT
))
834 if (c
->state
& CONFIG_LOCKED
)
835 return CS_CONFIGURATION_LOCKED
;
836 if (c
->state
& CONFIG_IRQ_REQ
)
839 #ifdef CONFIG_PCMCIA_PROBE
840 if (s
->irq
.AssignedIRQ
!= 0) {
841 /* If the interrupt is already assigned, it must be the same */
842 irq
= s
->irq
.AssignedIRQ
;
845 u32 mask
= s
->irq_mask
;
848 for (try = 0; try < 64; try++) {
851 /* marked as available by driver, and not blocked by userspace? */
852 if (!((mask
>> irq
) & 1))
855 /* avoid an IRQ which is already used by a PCMCIA card */
856 if ((try < 32) && pcmcia_used_irq
[irq
])
859 /* register the correct driver, if possible, of check whether
860 * registering a dummy handle works, i.e. if the IRQ isn't
861 * marked as used by the kernel resource management core */
862 ret
= request_irq(irq
,
863 (req
->Attributes
& IRQ_HANDLE_PRESENT
) ? req
->Handler
: test_action
,
864 ((req
->Attributes
& IRQ_TYPE_DYNAMIC_SHARING
) ||
865 (s
->functions
> 1) ||
866 (irq
== s
->pci_irq
)) ? SA_SHIRQ
: 0,
868 (req
->Attributes
& IRQ_HANDLE_PRESENT
) ? req
->Instance
: data
);
870 if (!(req
->Attributes
& IRQ_HANDLE_PRESENT
))
883 if (ret
&& req
->Attributes
& IRQ_HANDLE_PRESENT
) {
884 if (request_irq(irq
, req
->Handler
,
885 ((req
->Attributes
& IRQ_TYPE_DYNAMIC_SHARING
) ||
886 (s
->functions
> 1) ||
887 (irq
== s
->pci_irq
)) ? SA_SHIRQ
: 0,
888 p_dev
->dev
.bus_id
, req
->Instance
))
892 c
->irq
.Attributes
= req
->Attributes
;
893 s
->irq
.AssignedIRQ
= req
->AssignedIRQ
= irq
;
896 c
->state
|= CONFIG_IRQ_REQ
;
897 handle
->state
|= CLIENT_IRQ_REQ
;
899 #ifdef CONFIG_PCMCIA_PROBE
900 pcmcia_used_irq
[irq
]++;
904 } /* pcmcia_request_irq */
905 EXPORT_SYMBOL(pcmcia_request_irq
);
908 /** pcmcia_request_window
910 * Request_window() establishes a mapping between card memory space
911 * and system memory space.
913 int pcmcia_request_window(client_handle_t
*handle
, win_req_t
*req
, window_handle_t
*wh
)
915 struct pcmcia_socket
*s
;
920 if (CHECK_HANDLE(*handle
))
921 return CS_BAD_HANDLE
;
922 s
= (*handle
)->Socket
;
923 if (!(s
->state
& SOCKET_PRESENT
))
925 if (req
->Attributes
& (WIN_PAGED
| WIN_SHARED
))
926 return CS_BAD_ATTRIBUTE
;
928 /* Window size defaults to smallest available */
930 req
->Size
= s
->map_size
;
931 align
= (((s
->features
& SS_CAP_MEM_ALIGN
) ||
932 (req
->Attributes
& WIN_STRICT_ALIGN
)) ?
933 req
->Size
: s
->map_size
);
934 if (req
->Size
& (s
->map_size
-1))
936 if ((req
->Base
&& (s
->features
& SS_CAP_STATIC_MAP
)) ||
937 (req
->Base
& (align
-1)))
942 /* Allocate system memory window */
943 for (w
= 0; w
< MAX_WIN
; w
++)
944 if (!(s
->state
& SOCKET_WIN_REQ(w
))) break;
946 return CS_OUT_OF_RESOURCE
;
949 win
->magic
= WINDOW_MAGIC
;
951 win
->handle
= *handle
;
954 if (!(s
->features
& SS_CAP_STATIC_MAP
)) {
955 win
->ctl
.res
= pcmcia_find_mem_region(req
->Base
, req
->Size
, align
,
956 (req
->Attributes
& WIN_MAP_BELOW_1MB
), s
);
960 (*handle
)->state
|= CLIENT_WIN_REQ(w
);
962 /* Configure the socket controller */
965 win
->ctl
.speed
= req
->AccessSpeed
;
966 if (req
->Attributes
& WIN_MEMORY_TYPE
)
967 win
->ctl
.flags
|= MAP_ATTRIB
;
968 if (req
->Attributes
& WIN_ENABLE
)
969 win
->ctl
.flags
|= MAP_ACTIVE
;
970 if (req
->Attributes
& WIN_DATA_WIDTH_16
)
971 win
->ctl
.flags
|= MAP_16BIT
;
972 if (req
->Attributes
& WIN_USE_WAIT
)
973 win
->ctl
.flags
|= MAP_USE_WAIT
;
974 win
->ctl
.card_start
= 0;
975 if (s
->ops
->set_mem_map(s
, &win
->ctl
) != 0)
977 s
->state
|= SOCKET_WIN_REQ(w
);
979 /* Return window handle */
980 if (s
->features
& SS_CAP_STATIC_MAP
) {
981 req
->Base
= win
->ctl
.static_start
;
983 req
->Base
= win
->ctl
.res
->start
;
988 } /* pcmcia_request_window */
989 EXPORT_SYMBOL(pcmcia_request_window
);