1 /*======================================================================
3 PCMCIA Card Services -- core services
5 cs.c 1.228 1999/09/15 15:32:19
7 The contents of this file are subject to the Mozilla Public
8 License Version 1.1 (the "License"); you may not use this file
9 except in compliance with the License. You may obtain a copy of
10 the License at http://www.mozilla.org/MPL/
12 Software distributed under the License is distributed on an "AS
13 IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
14 implied. See the License for the specific language governing
15 rights and limitations under the License.
17 The initial developer of the original code is David A. Hinds
18 <dhinds@hyper.stanford.edu>. Portions created by David A. Hinds
19 are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
21 Alternatively, the contents of this file may be used under the
22 terms of the GNU Public License version 2 (the "GPL"), in which
23 case the provisions of the GPL are applicable instead of the
24 above. If you wish to allow the use of your version of this file
25 only under the terms of the GPL and not to allow others to use
26 your version of this file under the MPL, indicate your decision
27 by deleting the provisions above and replace them with the notice
28 and other provisions required by the GPL. If you do not delete
29 the provisions above, a recipient may use your version of this
30 file under either the MPL or the GPL.
32 ======================================================================*/
34 #include <linux/module.h>
35 #include <linux/init.h>
36 #include <linux/kernel.h>
37 #include <linux/config.h>
38 #include <linux/string.h>
39 #include <linux/major.h>
40 #include <linux/errno.h>
41 #include <linux/malloc.h>
43 #include <linux/sched.h>
44 #include <linux/timer.h>
45 #include <linux/ioport.h>
46 #include <linux/delay.h>
47 #include <linux/proc_fs.h>
48 #include <linux/compile.h>
49 #include <asm/system.h>
52 #define IN_CARD_SERVICES
53 #include <pcmcia/version.h>
54 #include <pcmcia/cs_types.h>
55 #include <pcmcia/ss.h>
56 #include <pcmcia/cs.h>
57 #include <pcmcia/bulkmem.h>
58 #include <pcmcia/cistpl.h>
59 #include <pcmcia/cisreg.h>
60 #include <pcmcia/bus_ops.h>
61 #include "cs_internal.h"
65 #include <linux/apm_bios.h>
66 static int handle_apm_event(apm_event_t event
);
70 int pc_debug
= PCMCIA_DEBUG
;
71 MODULE_PARM(pc_debug
, "i");
72 static const char *version
=
73 "cs.c 1.228 1999/09/15 15:32:19 (David Hinds)";
76 static const char *release
= "Linux PCMCIA Card Services " CS_RELEASE
;
78 static const char *kernel
= "kernel build: " UTS_RELEASE
" " UTS_VERSION
;
80 static const char *options
= "options: "
90 #if !defined(CONFIG_CARDBUS) && !defined(CONFIG_PCI) && \
91 !defined(CONFIG_APM) && !defined(CONFIG_PNP_BIOS)
96 /*====================================================================*/
98 /* Parameters that can be set with 'insmod' */
100 static int setup_delay
= HZ
/20; /* ticks */
101 static int resume_delay
= HZ
/5; /* ticks */
102 static int shutdown_delay
= HZ
/40; /* ticks */
103 static int vcc_settle
= HZ
*3/10; /* ticks */
104 static int reset_time
= 10; /* usecs */
105 static int unreset_delay
= HZ
/10; /* ticks */
106 static int unreset_check
= HZ
/10; /* ticks */
107 static int unreset_limit
= 30; /* unreset_check's */
109 /* Access speed for attribute memory windows */
110 static int cis_speed
= 300; /* ns */
112 /* Access speed for IO windows */
113 static int io_speed
= 0; /* ns */
115 /* Optional features */
117 static int do_apm
= 1;
118 MODULE_PARM(do_apm
, "i");
121 MODULE_PARM(setup_delay
, "i");
122 MODULE_PARM(resume_delay
, "i");
123 MODULE_PARM(shutdown_delay
, "i");
124 MODULE_PARM(vcc_settle
, "i");
125 MODULE_PARM(reset_time
, "i");
126 MODULE_PARM(unreset_delay
, "i");
127 MODULE_PARM(unreset_check
, "i");
128 MODULE_PARM(unreset_limit
, "i");
129 MODULE_PARM(cis_speed
, "i");
130 MODULE_PARM(io_speed
, "i");
132 /*====================================================================*/
134 static socket_state_t dead_socket
= {
135 0, SS_DETECT
, 0, 0, 0
138 /* Table of sockets */
139 socket_t sockets
= 0;
140 socket_info_t
*socket_table
[MAX_SOCK
];
142 #ifdef CONFIG_PROC_FS
143 struct proc_dir_entry
*proc_pccard
= NULL
;
146 /*====================================================================*/
148 /* String tables for error messages */
150 typedef struct lookup_t
{
155 static const lookup_t error_table
[] = {
156 { CS_SUCCESS
, "Operation succeeded" },
157 { CS_BAD_ADAPTER
, "Bad adapter" },
158 { CS_BAD_ATTRIBUTE
, "Bad attribute", },
159 { CS_BAD_BASE
, "Bad base address" },
160 { CS_BAD_EDC
, "Bad EDC" },
161 { CS_BAD_IRQ
, "Bad IRQ" },
162 { CS_BAD_OFFSET
, "Bad offset" },
163 { CS_BAD_PAGE
, "Bad page number" },
164 { CS_READ_FAILURE
, "Read failure" },
165 { CS_BAD_SIZE
, "Bad size" },
166 { CS_BAD_SOCKET
, "Bad socket" },
167 { CS_BAD_TYPE
, "Bad type" },
168 { CS_BAD_VCC
, "Bad Vcc" },
169 { CS_BAD_VPP
, "Bad Vpp" },
170 { CS_BAD_WINDOW
, "Bad window" },
171 { CS_WRITE_FAILURE
, "Write failure" },
172 { CS_NO_CARD
, "No card present" },
173 { CS_UNSUPPORTED_FUNCTION
, "Usupported function" },
174 { CS_UNSUPPORTED_MODE
, "Unsupported mode" },
175 { CS_BAD_SPEED
, "Bad speed" },
176 { CS_BUSY
, "Resource busy" },
177 { CS_GENERAL_FAILURE
, "General failure" },
178 { CS_WRITE_PROTECTED
, "Write protected" },
179 { CS_BAD_ARG_LENGTH
, "Bad argument length" },
180 { CS_BAD_ARGS
, "Bad arguments" },
181 { CS_CONFIGURATION_LOCKED
, "Configuration locked" },
182 { CS_IN_USE
, "Resource in use" },
183 { CS_NO_MORE_ITEMS
, "No more items" },
184 { CS_OUT_OF_RESOURCE
, "Out of resource" },
185 { CS_BAD_HANDLE
, "Bad handle" },
186 { CS_BAD_TUPLE
, "Bad CIS tuple" }
188 #define ERROR_COUNT (sizeof(error_table)/sizeof(lookup_t))
190 static const lookup_t service_table
[] = {
191 { AccessConfigurationRegister
, "AccessConfigurationRegister" },
192 { AddSocketServices
, "AddSocketServices" },
193 { AdjustResourceInfo
, "AdjustResourceInfo" },
194 { CheckEraseQueue
, "CheckEraseQueue" },
195 { CloseMemory
, "CloseMemory" },
196 { DeregisterClient
, "DeregisterClient" },
197 { DeregisterEraseQueue
, "DeregisterEraseQueue" },
198 { GetCardServicesInfo
, "GetCardServicesInfo" },
199 { GetClientInfo
, "GetClientInfo" },
200 { GetConfigurationInfo
, "GetConfigurationInfo" },
201 { GetEventMask
, "GetEventMask" },
202 { GetFirstClient
, "GetFirstClient" },
203 { GetFirstRegion
, "GetFirstRegion" },
204 { GetFirstTuple
, "GetFirstTuple" },
205 { GetNextClient
, "GetNextClient" },
206 { GetNextRegion
, "GetNextRegion" },
207 { GetNextTuple
, "GetNextTuple" },
208 { GetStatus
, "GetStatus" },
209 { GetTupleData
, "GetTupleData" },
210 { MapMemPage
, "MapMemPage" },
211 { ModifyConfiguration
, "ModifyConfiguration" },
212 { ModifyWindow
, "ModifyWindow" },
213 { OpenMemory
, "OpenMemory" },
214 { ParseTuple
, "ParseTuple" },
215 { ReadMemory
, "ReadMemory" },
216 { RegisterClient
, "RegisterClient" },
217 { RegisterEraseQueue
, "RegisterEraseQueue" },
218 { RegisterMTD
, "RegisterMTD" },
219 { ReleaseConfiguration
, "ReleaseConfiguration" },
220 { ReleaseIO
, "ReleaseIO" },
221 { ReleaseIRQ
, "ReleaseIRQ" },
222 { ReleaseWindow
, "ReleaseWindow" },
223 { RequestConfiguration
, "RequestConfiguration" },
224 { RequestIO
, "RequestIO" },
225 { RequestIRQ
, "RequestIRQ" },
226 { RequestSocketMask
, "RequestSocketMask" },
227 { RequestWindow
, "RequestWindow" },
228 { ResetCard
, "ResetCard" },
229 { SetEventMask
, "SetEventMask" },
230 { ValidateCIS
, "ValidateCIS" },
231 { WriteMemory
, "WriteMemory" },
232 { BindDevice
, "BindDevice" },
233 { BindMTD
, "BindMTD" },
234 { ReportError
, "ReportError" },
235 { SuspendCard
, "SuspendCard" },
236 { ResumeCard
, "ResumeCard" },
237 { EjectCard
, "EjectCard" },
238 { InsertCard
, "InsertCard" },
239 { ReplaceCIS
, "ReplaceCIS" }
241 #define SERVICE_COUNT (sizeof(service_table)/sizeof(lookup_t))
243 /*======================================================================
245 Reset a socket to the default state
247 ======================================================================*/
249 static void init_socket(socket_info_t
*s
)
252 pccard_io_map io
= { 0, 0, 0, 0, 1 };
253 pccard_mem_map mem
= { 0, 0, 0, 0, 0, 0 };
255 mem
.sys_stop
= s
->cap
.map_size
;
256 s
->socket
= dead_socket
;
257 s
->ss_entry(s
->sock
, SS_SetSocket
, &s
->socket
);
258 for (i
= 0; i
< 2; i
++) {
260 s
->ss_entry(s
->sock
, SS_SetIOMap
, &io
);
262 for (i
= 0; i
< 5; i
++) {
264 s
->ss_entry(s
->sock
, SS_SetMemMap
, &mem
);
268 /*====================================================================*/
270 #if defined(CONFIG_PROC_FS) && defined(PCMCIA_DEBUG)
271 int proc_read_clients(char *buf
, char **start
, off_t pos
,
272 int count
, int *eof
, void *data
)
274 socket_info_t
*s
= data
;
278 for (c
= s
->clients
; c
; c
= c
->next
)
279 p
+= sprintf(p
, "fn %x: '%s' [attr 0x%04x] [state 0x%04x]\n",
280 c
->Function
, c
->dev_info
, c
->Attributes
, c
->state
);
285 /*======================================================================
287 Low-level PC Card interface drivers need to register with Card
288 Services using these calls.
290 ======================================================================*/
292 static void setup_socket(u_long i
);
293 static void shutdown_socket(u_long i
);
294 static void reset_socket(u_long i
);
295 static void unreset_socket(u_long i
);
296 static void parse_events(void *info
, u_int events
);
298 int register_ss_entry(int nsock
, ss_entry_t ss_entry
)
303 DEBUG(0, "cs: register_ss_entry(%d, 0x%p)\n", nsock
, ss_entry
);
305 for (ns
= 0; ns
< nsock
; ns
++) {
306 s
= kmalloc(sizeof(struct socket_info_t
), GFP_KERNEL
);
307 memset(s
, 0, sizeof(socket_info_t
));
309 s
->ss_entry
= ss_entry
;
311 s
->setup
.data
= sockets
;
312 s
->setup
.function
= &setup_socket
;
313 s
->shutdown
.data
= sockets
;
314 s
->shutdown
.function
= &shutdown_socket
;
315 /* base address = 0, map = 0 */
316 s
->cis_mem
.flags
= 0;
317 s
->cis_mem
.speed
= cis_speed
;
318 s
->erase_busy
.next
= s
->erase_busy
.prev
= &s
->erase_busy
;
320 for (i
= 0; i
< sockets
; i
++)
321 if (socket_table
[i
] == NULL
) break;
323 if (i
== sockets
) sockets
++;
326 ss_entry(ns
, SS_InquireSocket
, &s
->cap
);
327 #ifdef CONFIG_PROC_FS
331 struct proc_dir_entry
*ent
;
333 sprintf(name
, "%02d", i
);
334 s
->proc
= create_proc_entry(name
, S_IFDIR
, proc_pccard
);
336 ent
= create_proc_entry("clients", 0, s
->proc
);
337 ent
->read_proc
= proc_read_clients
;
340 ss_entry(ns
, SS_ProcSetup
, s
->proc
);
346 } /* register_ss_entry */
348 /*====================================================================*/
350 void unregister_ss_entry(ss_entry_t ss_entry
)
353 socket_info_t
*s
= NULL
;
357 for (i
= 0; i
< sockets
; i
++) {
359 if (s
->ss_entry
== ss_entry
) break;
364 #ifdef CONFIG_PROC_FS
367 sprintf(name
, "%02d", i
);
369 remove_proc_entry("clients", s
->proc
);
371 remove_proc_entry(name
, proc_pccard
);
376 s
->clients
= s
->clients
->next
;
381 #ifdef CONFIG_CARDBUS
382 cb_release_cis_mem(s
);
386 socket_table
[i
] = NULL
;
387 for (j
= i
; j
< sockets
-1; j
++)
388 socket_table
[j
] = socket_table
[j
+1];
393 } /* unregister_ss_entry */
395 /*======================================================================
397 Shutdown_Socket() and setup_socket() are scheduled using add_timer
398 calls by the main event handler when card insertion and removal
399 events are received. Shutdown_Socket() unconfigures a socket and
400 turns off socket power. Setup_socket() turns on socket power
401 and resets the socket, in two stages.
403 ======================================================================*/
405 static void free_regions(memory_handle_t
*list
)
408 while (*list
!= NULL
) {
410 *list
= tmp
->info
.next
;
411 tmp
->region_magic
= 0;
416 static int send_event(socket_info_t
*s
, event_t event
, int priority
);
418 static void shutdown_socket(u_long i
)
420 socket_info_t
*s
= socket_table
[i
];
423 DEBUG(1, "cs: shutdown_socket(%ld)\n", i
);
425 /* Blank out the socket state */
426 s
->state
&= SOCKET_PRESENT
|SOCKET_SETUP_PENDING
;
428 s
->irq
.AssignedIRQ
= s
->irq
.Config
= 0;
436 #ifdef CONFIG_CARDBUS
437 cb_release_cis_mem(s
);
444 for (c
= &s
->clients
; *c
; ) {
445 if ((*c
)->state
& CLIENT_UNBOUND
) {
453 free_regions(&s
->a_region
);
454 free_regions(&s
->c_region
);
455 } /* shutdown_socket */
457 static void setup_socket(u_long i
)
460 socket_info_t
*s
= socket_table
[i
];
462 s
->ss_entry(s
->sock
, SS_GetStatus
, &val
);
463 if (val
& SS_DETECT
) {
464 DEBUG(1, "cs: setup_socket(%ld): applying power\n", i
);
465 s
->state
|= SOCKET_PRESENT
;
468 s
->socket
.Vcc
= s
->socket
.Vpp
= 33;
469 else if (!(val
& SS_XVCARD
))
470 s
->socket
.Vcc
= s
->socket
.Vpp
= 50;
472 printk(KERN_NOTICE
"cs: socket %ld: unsupported "
476 if (val
& SS_CARDBUS
) {
477 s
->state
|= SOCKET_CARDBUS
;
478 #ifndef CONFIG_CARDBUS
479 printk(KERN_NOTICE
"cs: unsupported card type detected!\n");
482 s
->ss_entry(s
->sock
, SS_SetSocket
, &s
->socket
);
483 s
->setup
.function
= &reset_socket
;
484 s
->setup
.expires
= jiffies
+ vcc_settle
;
485 add_timer(&s
->setup
);
487 DEBUG(0, "cs: setup_socket(%ld): no card!\n", i
);
490 /*======================================================================
492 Reset_socket() and unreset_socket() handle hard resets. Resets
493 have several causes: card insertion, a call to reset_socket, or
494 recovery from a suspend/resume cycle. Unreset_socket() sends
495 a CS event that matches the cause of the reset.
497 ======================================================================*/
499 static void reset_socket(u_long i
)
501 socket_info_t
*s
= socket_table
[i
];
503 DEBUG(1, "cs: resetting socket %ld\n", i
);
504 s
->socket
.flags
|= SS_OUTPUT_ENA
| SS_RESET
;
505 s
->ss_entry(s
->sock
, SS_SetSocket
, &s
->socket
);
506 udelay((long)reset_time
);
507 s
->socket
.flags
&= ~SS_RESET
;
508 s
->ss_entry(s
->sock
, SS_SetSocket
, &s
->socket
);
509 s
->unreset_timeout
= 0;
510 s
->setup
.expires
= jiffies
+ unreset_delay
;
511 s
->setup
.function
= &unreset_socket
;
512 add_timer(&s
->setup
);
516 (SOCKET_SETUP_PENDING|SOCKET_SUSPEND|SOCKET_RESET_PENDING)
518 static void unreset_socket(u_long i
)
520 socket_info_t
*s
= socket_table
[i
];
523 s
->ss_entry(s
->sock
, SS_GetStatus
, &val
);
524 if (val
& SS_READY
) {
525 DEBUG(1, "cs: reset done on socket %ld\n", i
);
526 if (s
->state
& SOCKET_SUSPEND
) {
527 s
->state
&= ~EVENT_MASK
;
528 if (verify_cis_cache(s
) != 0)
529 parse_events(s
, SS_DETECT
);
531 send_event(s
, CS_EVENT_PM_RESUME
, CS_EVENT_PRI_LOW
);
532 } else if (s
->state
& SOCKET_SETUP_PENDING
) {
533 #ifdef CONFIG_CARDBUS
534 if (s
->state
& SOCKET_CARDBUS
)
537 send_event(s
, CS_EVENT_CARD_INSERTION
, CS_EVENT_PRI_LOW
);
538 s
->state
&= ~SOCKET_SETUP_PENDING
;
540 send_event(s
, CS_EVENT_CARD_RESET
, CS_EVENT_PRI_LOW
);
541 s
->reset_handle
->event_callback_args
.info
= NULL
;
542 EVENT(s
->reset_handle
, CS_EVENT_RESET_COMPLETE
,
544 s
->state
&= ~EVENT_MASK
;
547 DEBUG(2, "cs: socket %ld not ready yet\n", i
);
548 if (s
->unreset_timeout
> unreset_limit
) {
549 printk(KERN_NOTICE
"cs: socket %ld timed out during"
551 s
->state
&= ~EVENT_MASK
;
553 s
->unreset_timeout
++;
554 s
->setup
.expires
= jiffies
+ unreset_check
;
555 add_timer(&s
->setup
);
558 } /* unreset_socket */
560 /*======================================================================
562 The central event handler. Send_event() sends an event to all
563 valid clients. Parse_events() interprets the event bits from
564 a card status change report. Do_shotdown() handles the high
565 priority stuff associated with a card removal.
567 ======================================================================*/
569 static int send_event(socket_info_t
*s
, event_t event
, int priority
)
571 client_t
*client
= s
->clients
;
573 DEBUG(1, "cs: send_event(sock %d, event %d, pri %d)\n",
574 s
->sock
, event
, priority
);
576 for (; client
; client
= client
->next
) {
577 if (client
->state
& (CLIENT_UNBOUND
|CLIENT_STALE
))
579 if (client
->EventMask
& event
) {
580 ret
= EVENT(client
, event
, priority
);
588 static void do_shutdown(socket_info_t
*s
)
591 if (s
->state
& SOCKET_SHUTDOWN_PENDING
)
593 s
->state
|= SOCKET_SHUTDOWN_PENDING
;
594 send_event(s
, CS_EVENT_CARD_REMOVAL
, CS_EVENT_PRI_HIGH
);
595 for (client
= s
->clients
; client
; client
= client
->next
)
596 if (!(client
->Attributes
& INFO_MASTER_CLIENT
))
597 client
->state
|= CLIENT_STALE
;
598 if (s
->state
& (SOCKET_SETUP_PENDING
|SOCKET_RESET_PENDING
)) {
599 DEBUG(0, "cs: flushing pending setup\n");
600 del_timer(&s
->setup
);
601 s
->state
&= ~EVENT_MASK
;
603 s
->shutdown
.expires
= jiffies
+ shutdown_delay
;
604 add_timer(&s
->shutdown
);
605 s
->state
&= ~SOCKET_PRESENT
;
608 static void parse_events(void *info
, u_int events
)
610 socket_info_t
*s
= info
;
611 if (events
& SS_DETECT
) {
614 spin_lock_irqsave(&s
->lock
, flags
);
615 s
->ss_entry(s
->sock
, SS_GetStatus
, &status
);
616 if ((s
->state
& SOCKET_PRESENT
) &&
617 (!(s
->state
& SOCKET_SUSPEND
) ||
618 !(status
& SS_DETECT
)))
620 if (status
& SS_DETECT
) {
621 if (s
->state
& SOCKET_SETUP_PENDING
) {
622 del_timer(&s
->setup
);
623 DEBUG(1, "cs: delaying pending setup\n");
625 s
->state
|= SOCKET_SETUP_PENDING
;
626 s
->setup
.function
= &setup_socket
;
627 if (s
->state
& SOCKET_SUSPEND
)
628 s
->setup
.expires
= jiffies
+ resume_delay
;
630 s
->setup
.expires
= jiffies
+ setup_delay
;
631 add_timer(&s
->setup
);
633 spin_unlock_irqrestore(&s
->lock
, flags
);
635 if (events
& SS_BATDEAD
)
636 send_event(s
, CS_EVENT_BATTERY_DEAD
, CS_EVENT_PRI_LOW
);
637 if (events
& SS_BATWARN
)
638 send_event(s
, CS_EVENT_BATTERY_LOW
, CS_EVENT_PRI_LOW
);
639 if (events
& SS_READY
) {
640 if (!(s
->state
& SOCKET_RESET_PENDING
))
641 send_event(s
, CS_EVENT_READY_CHANGE
, CS_EVENT_PRI_LOW
);
642 else DEBUG(1, "cs: ready change during reset\n");
646 /*======================================================================
648 Another event handler, for power management events.
650 This does not comply with the latest PC Card spec for handling
651 power management events.
653 ======================================================================*/
656 static int handle_apm_event(apm_event_t event
)
663 case APM_SYS_SUSPEND
:
664 case APM_USER_SUSPEND
:
665 DEBUG(1, "cs: received suspend notification\n");
667 printk(KERN_DEBUG
"cs: received extra suspend event\n");
671 for (i
= 0; i
< sockets
; i
++) {
673 if ((s
->state
& SOCKET_PRESENT
) &&
674 !(s
->state
& SOCKET_SUSPEND
)){
675 send_event(s
, CS_EVENT_PM_SUSPEND
, CS_EVENT_PRI_LOW
);
676 s
->ss_entry(s
->sock
, SS_SetSocket
, &dead_socket
);
677 s
->state
|= SOCKET_SUSPEND
;
681 case APM_NORMAL_RESUME
:
682 case APM_CRITICAL_RESUME
:
683 DEBUG(1, "cs: received resume notification\n");
685 printk(KERN_DEBUG
"cs: received bogus resume event\n");
689 for (i
= 0; i
< sockets
; i
++) {
691 /* Do this just to reinitialize the socket */
693 s
->ss_entry(s
->sock
, SS_GetStatus
, &stat
);
694 /* If there was or is a card here, we need to do something
695 about it... but parse_events will sort it all out. */
696 if ((s
->state
& SOCKET_PRESENT
) || (stat
& SS_DETECT
))
697 parse_events(s
, SS_DETECT
);
702 } /* handle_apm_event */
705 /*======================================================================
707 Special stuff for managing IO windows, because they are scarce.
709 ======================================================================*/
711 static int alloc_io_space(socket_info_t
*s
, u_int attr
, ioaddr_t
*base
,
712 ioaddr_t num
, char *name
)
717 for (i
= 0; i
< MAX_IO_WIN
; i
++) {
718 if (s
->io
[i
].NumPorts
== 0) {
719 if (find_io_region(base
, num
, name
) == 0) {
720 s
->io
[i
].Attributes
= attr
;
721 s
->io
[i
].BasePort
= *base
;
722 s
->io
[i
].NumPorts
= s
->io
[i
].InUse
= num
;
726 } else if (s
->io
[i
].Attributes
!= attr
)
728 /* Try to extend top of window */
729 try = s
->io
[i
].BasePort
+ s
->io
[i
].NumPorts
;
730 if ((*base
== 0) || (*base
== try))
731 if (find_io_region(&try, num
, name
) == 0) {
733 s
->io
[i
].NumPorts
+= num
;
734 s
->io
[i
].InUse
+= num
;
737 /* Try to extend bottom of window */
738 try = s
->io
[i
].BasePort
- num
;
739 if ((*base
== 0) || (*base
== try))
740 if (find_io_region(&try, num
, name
) == 0) {
741 s
->io
[i
].BasePort
= *base
= try;
742 s
->io
[i
].NumPorts
+= num
;
743 s
->io
[i
].InUse
+= num
;
747 return (i
== MAX_IO_WIN
);
748 } /* alloc_io_space */
750 static void release_io_space(socket_info_t
*s
, ioaddr_t base
,
754 release_region(base
, num
);
755 for (i
= 0; i
< MAX_IO_WIN
; i
++) {
756 if ((s
->io
[i
].BasePort
<= base
) &&
757 (s
->io
[i
].BasePort
+s
->io
[i
].NumPorts
>= base
+num
)) {
758 s
->io
[i
].InUse
-= num
;
759 /* Free the window if no one else is using it */
760 if (s
->io
[i
].InUse
== 0)
761 s
->io
[i
].NumPorts
= 0;
766 /*======================================================================
768 Access_configuration_register() reads and writes configuration
769 registers in attribute memory. Memory window 0 is reserved for
770 this and the tuple reading services.
772 ======================================================================*/
774 static int access_configuration_register(client_handle_t handle
,
782 if (CHECK_HANDLE(handle
))
783 return CS_BAD_HANDLE
;
785 if (handle
->Function
== BIND_FN_ALL
) {
786 if (reg
->Function
>= s
->functions
)
788 c
= &s
->config
[reg
->Function
];
791 if (!(c
->state
& CONFIG_LOCKED
))
792 return CS_CONFIGURATION_LOCKED
;
794 addr
= (c
->ConfigBase
+ reg
->Offset
) >> 1;
796 switch (reg
->Action
) {
798 read_cis_mem(s
, 1, addr
, 1, &val
);
803 write_cis_mem(s
, 1, addr
, 1, &val
);
810 } /* access_configuration_register */
812 /*======================================================================
814 Bind_device() associates a device driver with a particular socket.
815 It is normally called by Driver Services after it has identified
816 a newly inserted card. An instance of that driver will then be
817 eligible to register as a client of this socket.
819 ======================================================================*/
821 static int bind_device(bind_req_t
*req
)
826 if (CHECK_SOCKET(req
->Socket
))
827 return CS_BAD_SOCKET
;
830 client
= (client_t
*)kmalloc(sizeof(client_t
), GFP_KERNEL
);
831 memset(client
, '\0', sizeof(client_t
));
832 client
->client_magic
= CLIENT_MAGIC
;
833 strncpy(client
->dev_info
, (char *)req
->dev_info
, DEV_NAME_LEN
);
834 client
->Socket
= req
->Socket
;
835 client
->Function
= req
->Function
;
836 client
->state
= CLIENT_UNBOUND
;
837 client
->erase_busy
.next
= &client
->erase_busy
;
838 client
->erase_busy
.prev
= &client
->erase_busy
;
839 init_waitqueue_head(&client
->mtd_req
);
840 client
->next
= s
->clients
;
842 DEBUG(1, "cs: bind_device(): client 0x%p, sock %d, dev %s\n",
843 client
, client
->Socket
, client
->dev_info
);
847 /*======================================================================
849 Bind_mtd() associates a device driver with a particular memory
850 region. It is normally called by Driver Services after it has
851 identified a memory device type. An instance of the corresponding
852 driver will then be able to register to control this region.
854 ======================================================================*/
856 static int bind_mtd(mtd_bind_t
*req
)
859 memory_handle_t region
;
861 if (CHECK_SOCKET(req
->Socket
))
862 return CS_BAD_SOCKET
;
865 if (req
->Attributes
& REGION_TYPE_AM
)
866 region
= s
->a_region
;
868 region
= s
->c_region
;
871 if (region
->info
.CardOffset
== req
->CardOffset
) break;
872 region
= region
->info
.next
;
874 if (!region
|| (region
->mtd
!= NULL
))
875 return CS_BAD_OFFSET
;
876 strncpy(region
->dev_info
, (char *)req
->dev_info
, DEV_NAME_LEN
);
878 DEBUG(1, "cs: bind_mtd(): attr 0x%x, offset 0x%x, dev %s\n",
879 req
->Attributes
, req
->CardOffset
, (char *)req
->dev_info
);
883 /*====================================================================*/
885 static int deregister_client(client_handle_t handle
)
889 memory_handle_t region
;
893 DEBUG(1, "cs: deregister_client(%p)\n", handle
);
894 if (CHECK_HANDLE(handle
))
895 return CS_BAD_HANDLE
;
897 (CLIENT_IRQ_REQ
|CLIENT_IO_REQ
|CLIENT_CONFIG_LOCKED
))
899 for (i
= 0; i
< MAX_WIN
; i
++)
900 if (handle
->state
& CLIENT_WIN_REQ(i
))
903 /* Disconnect all MTD links */
905 if (handle
->mtd_count
) {
906 for (region
= s
->a_region
; region
; region
= region
->info
.next
)
907 if (region
->mtd
== handle
) region
->mtd
= NULL
;
908 for (region
= s
->c_region
; region
; region
= region
->info
.next
)
909 if (region
->mtd
== handle
) region
->mtd
= NULL
;
912 sn
= handle
->Socket
; s
= socket_table
[sn
];
914 if ((handle
->state
& CLIENT_STALE
) ||
915 (handle
->Attributes
& INFO_MASTER_CLIENT
)) {
916 spin_lock_irqsave(&s
->lock
, flags
);
917 client
= &s
->clients
;
918 while ((*client
) && ((*client
) != handle
))
919 client
= &(*client
)->next
;
921 return CS_BAD_HANDLE
;
922 *client
= handle
->next
;
923 handle
->client_magic
= 0;
925 spin_unlock_irqrestore(&s
->lock
, flags
);
927 handle
->state
= CLIENT_UNBOUND
;
928 handle
->mtd_count
= 0;
929 handle
->event_handler
= NULL
;
932 if (--s
->real_clients
== 0)
933 s
->ss_entry(sn
, SS_RegisterCallback
, NULL
);
936 } /* deregister_client */
938 /*====================================================================*/
940 static int get_configuration_info(client_handle_t handle
,
941 config_info_t
*config
)
946 if (CHECK_HANDLE(handle
))
947 return CS_BAD_HANDLE
;
949 if (!(s
->state
& SOCKET_PRESENT
))
952 if (handle
->Function
== BIND_FN_ALL
) {
953 if (config
->Function
&& (config
->Function
>= s
->functions
))
956 config
->Function
= handle
->Function
;
958 #ifdef CONFIG_CARDBUS
959 if (s
->state
& SOCKET_CARDBUS
) {
960 u_char fn
= config
->Function
;
961 memset(config
, 0, sizeof(config_info_t
));
962 config
->Function
= fn
;
963 config
->Vcc
= s
->socket
.Vcc
;
964 config
->Vpp1
= config
->Vpp2
= s
->socket
.Vpp
;
965 config
->Option
= s
->cap
.cardbus
;
967 config
->Attributes
= CONF_VALID_CLIENT
;
968 config
->IntType
= INT_CARDBUS
;
969 config
->AssignedIRQ
= s
->irq
.AssignedIRQ
;
970 if (config
->AssignedIRQ
)
971 config
->Attributes
|= CONF_ENABLE_IRQ
;
972 config
->BasePort1
= s
->io
[0].BasePort
;
973 config
->NumPorts1
= s
->io
[0].NumPorts
;
979 c
= (s
->config
!= NULL
) ? &s
->config
[config
->Function
] : NULL
;
981 if ((c
== NULL
) || !(c
->state
& CONFIG_LOCKED
)) {
982 config
->Attributes
= 0;
983 config
->Vcc
= s
->socket
.Vcc
;
984 config
->Vpp1
= config
->Vpp2
= s
->socket
.Vpp
;
988 /* !!! This is a hack !!! */
989 memcpy(&config
->Attributes
, &c
->Attributes
, sizeof(config_t
));
990 config
->Attributes
|= CONF_VALID_CLIENT
;
991 config
->CardValues
= c
->CardValues
;
992 config
->IRQAttributes
= c
->irq
.Attributes
;
993 config
->AssignedIRQ
= s
->irq
.AssignedIRQ
;
994 config
->BasePort1
= c
->io
.BasePort1
;
995 config
->NumPorts1
= c
->io
.NumPorts1
;
996 config
->Attributes1
= c
->io
.Attributes1
;
997 config
->BasePort2
= c
->io
.BasePort2
;
998 config
->NumPorts2
= c
->io
.NumPorts2
;
999 config
->Attributes2
= c
->io
.Attributes2
;
1000 config
->IOAddrLines
= c
->io
.IOAddrLines
;
1003 } /* get_configuration_info */
1005 /*======================================================================
1007 Return information about this version of Card Services.
1009 ======================================================================*/
1011 static int get_card_services_info(servinfo_t
*info
)
1013 info
->Signature
[0] = 'C';
1014 info
->Signature
[1] = 'S';
1015 info
->Count
= sockets
;
1016 info
->Revision
= CS_RELEASE_CODE
;
1017 info
->CSLevel
= 0x0210;
1018 info
->VendorString
= (char *)release
;
1020 } /* get_card_services_info */
1022 /*======================================================================
1024 Note that get_first_client() *does* recognize the Socket field
1025 in the request structure.
1027 ======================================================================*/
1029 static int get_first_client(client_handle_t
*handle
, client_req_t
*req
)
1032 if (req
->Attributes
& CLIENT_THIS_SOCKET
)
1036 if (CHECK_SOCKET(req
->Socket
))
1037 return CS_BAD_SOCKET
;
1038 if (socket_table
[s
]->clients
== NULL
)
1039 return CS_NO_MORE_ITEMS
;
1040 *handle
= socket_table
[s
]->clients
;
1042 } /* get_first_client */
1044 /*====================================================================*/
1046 static int get_next_client(client_handle_t
*handle
, client_req_t
*req
)
1049 if ((handle
== NULL
) || CHECK_HANDLE(*handle
))
1050 return CS_BAD_HANDLE
;
1051 if ((*handle
)->next
== NULL
) {
1052 if (req
->Attributes
& CLIENT_THIS_SOCKET
)
1053 return CS_NO_MORE_ITEMS
;
1054 s
= SOCKET(*handle
);
1055 if (s
->clients
== NULL
)
1056 return CS_NO_MORE_ITEMS
;
1057 *handle
= s
->clients
;
1059 *handle
= (*handle
)->next
;
1061 } /* get_next_client */
1063 /*====================================================================*/
1065 static int get_window(window_handle_t
*handle
, int idx
, win_req_t
*req
)
1072 s
= SOCKET((client_handle_t
)*handle
);
1074 s
= (*handle
)->sock
;
1075 if (!(s
->state
& SOCKET_PRESENT
))
1077 for (w
= idx
; w
< MAX_WIN
; w
++)
1078 if (s
->state
& SOCKET_WIN_REQ(w
)) break;
1080 return CS_NO_MORE_ITEMS
;
1082 req
->Base
= win
->ctl
.sys_start
;
1083 req
->Size
= win
->ctl
.sys_stop
- win
->ctl
.sys_start
+ 1;
1084 req
->AccessSpeed
= win
->ctl
.speed
;
1085 req
->Attributes
= 0;
1086 if (win
->ctl
.flags
& MAP_ATTRIB
)
1087 req
->Attributes
|= WIN_MEMORY_TYPE_AM
;
1088 if (win
->ctl
.flags
& MAP_ACTIVE
)
1089 req
->Attributes
|= WIN_ENABLE
;
1090 if (win
->ctl
.flags
& MAP_16BIT
)
1091 req
->Attributes
|= WIN_DATA_WIDTH
;
1092 if (win
->ctl
.flags
& MAP_USE_WAIT
)
1093 req
->Attributes
|= WIN_USE_WAIT
;
1098 static int get_first_window(client_handle_t
*handle
, win_req_t
*req
)
1100 if ((handle
== NULL
) || CHECK_HANDLE(*handle
))
1101 return CS_BAD_HANDLE
;
1102 return get_window((window_handle_t
*)handle
, 0, req
);
1105 static int get_next_window(window_handle_t
*win
, win_req_t
*req
)
1107 if ((win
== NULL
) || ((*win
)->magic
!= WINDOW_MAGIC
))
1108 return CS_BAD_HANDLE
;
1109 return get_window(win
, (*win
)->index
+1, req
);
1112 /*======================================================================
1114 Get the current socket state bits. We don't support the latched
1115 SocketState yet: I haven't seen any point for it.
1117 ======================================================================*/
1119 static int get_status(client_handle_t handle
, cs_status_t
*status
)
1125 if (CHECK_HANDLE(handle
))
1126 return CS_BAD_HANDLE
;
1128 s
->ss_entry(s
->sock
, SS_GetStatus
, &val
);
1129 status
->CardState
= status
->SocketState
= 0;
1130 status
->CardState
|= (val
& SS_DETECT
) ? CS_EVENT_CARD_DETECT
: 0;
1131 status
->CardState
|= (val
& SS_CARDBUS
) ? CS_EVENT_CB_DETECT
: 0;
1132 status
->CardState
|= (val
& SS_3VCARD
) ? CS_EVENT_3VCARD
: 0;
1133 status
->CardState
|= (val
& SS_XVCARD
) ? CS_EVENT_XVCARD
: 0;
1134 if (s
->state
& SOCKET_SUSPEND
)
1135 status
->CardState
|= CS_EVENT_PM_SUSPEND
;
1136 if (!(s
->state
& SOCKET_PRESENT
))
1138 if (s
->state
& SOCKET_SETUP_PENDING
)
1139 status
->CardState
|= CS_EVENT_CARD_INSERTION
;
1141 /* Get info from the PRR, if necessary */
1142 if (handle
->Function
== BIND_FN_ALL
) {
1143 if (status
->Function
&& (status
->Function
>= s
->functions
))
1145 c
= (s
->config
!= NULL
) ? &s
->config
[status
->Function
] : NULL
;
1148 if ((c
!= NULL
) && (c
->state
& CONFIG_LOCKED
) &&
1149 (c
->IntType
& INT_MEMORY_AND_IO
)) {
1151 if (c
->Present
& PRESENT_PIN_REPLACE
) {
1152 read_cis_mem(s
, 1, (c
->ConfigBase
+CISREG_PRR
)>>1, 1, ®
);
1153 status
->CardState
|=
1154 (reg
& PRR_WP_STATUS
) ? CS_EVENT_WRITE_PROTECT
: 0;
1155 status
->CardState
|=
1156 (reg
& PRR_READY_STATUS
) ? CS_EVENT_READY_CHANGE
: 0;
1157 status
->CardState
|=
1158 (reg
& PRR_BVD2_STATUS
) ? CS_EVENT_BATTERY_LOW
: 0;
1159 status
->CardState
|=
1160 (reg
& PRR_BVD1_STATUS
) ? CS_EVENT_BATTERY_DEAD
: 0;
1162 /* No PRR? Then assume we're always ready */
1163 status
->CardState
|= CS_EVENT_READY_CHANGE
;
1165 if (c
->Present
& PRESENT_EXT_STATUS
) {
1166 read_cis_mem(s
, 1, (c
->ConfigBase
+CISREG_ESR
)>>1, 1, ®
);
1167 status
->CardState
|=
1168 (reg
& ESR_REQ_ATTN
) ? CS_EVENT_REQUEST_ATTENTION
: 0;
1172 status
->CardState
|=
1173 (val
& SS_WRPROT
) ? CS_EVENT_WRITE_PROTECT
: 0;
1174 status
->CardState
|=
1175 (val
& SS_BATDEAD
) ? CS_EVENT_BATTERY_DEAD
: 0;
1176 status
->CardState
|=
1177 (val
& SS_BATWARN
) ? CS_EVENT_BATTERY_LOW
: 0;
1178 status
->CardState
|=
1179 (val
& SS_READY
) ? CS_EVENT_READY_CHANGE
: 0;
1183 /*======================================================================
1185 Change the card address of an already open memory window.
1187 ======================================================================*/
1189 static int get_mem_page(window_handle_t win
, memreq_t
*req
)
1191 if ((win
== NULL
) || (win
->magic
!= WINDOW_MAGIC
))
1192 return CS_BAD_HANDLE
;
1194 req
->CardOffset
= win
->ctl
.card_start
;
1196 } /* get_mem_page */
1198 static int map_mem_page(window_handle_t win
, memreq_t
*req
)
1201 if ((win
== NULL
) || (win
->magic
!= WINDOW_MAGIC
))
1202 return CS_BAD_HANDLE
;
1206 win
->ctl
.card_start
= req
->CardOffset
;
1207 if (s
->ss_entry(s
->sock
, SS_SetMemMap
, &win
->ctl
) != 0)
1208 return CS_BAD_OFFSET
;
1210 } /* map_mem_page */
1212 /*======================================================================
1214 Modify a locked socket configuration
1216 ======================================================================*/
1218 static int modify_configuration(client_handle_t handle
,
1224 if (CHECK_HANDLE(handle
))
1225 return CS_BAD_HANDLE
;
1226 s
= SOCKET(handle
); c
= CONFIG(handle
);
1227 if (!(s
->state
& SOCKET_PRESENT
))
1229 if (!(c
->state
& CONFIG_LOCKED
))
1230 return CS_CONFIGURATION_LOCKED
;
1232 if (mod
->Attributes
& CONF_IRQ_CHANGE_VALID
) {
1233 if (mod
->Attributes
& CONF_ENABLE_IRQ
) {
1234 c
->Attributes
|= CONF_ENABLE_IRQ
;
1235 s
->socket
.io_irq
= s
->irq
.AssignedIRQ
;
1237 c
->Attributes
&= ~CONF_ENABLE_IRQ
;
1238 s
->socket
.io_irq
= 0;
1240 s
->ss_entry(s
->sock
, SS_SetSocket
, &s
->socket
);
1243 if (mod
->Attributes
& CONF_VCC_CHANGE_VALID
)
1246 /* We only allow changing Vpp1 and Vpp2 to the same value */
1247 if ((mod
->Attributes
& CONF_VPP1_CHANGE_VALID
) &&
1248 (mod
->Attributes
& CONF_VPP2_CHANGE_VALID
)) {
1249 if (mod
->Vpp1
!= mod
->Vpp2
)
1251 c
->Vpp1
= c
->Vpp2
= s
->socket
.Vpp
= mod
->Vpp1
;
1252 if (s
->ss_entry(s
->sock
, SS_SetSocket
, &s
->socket
))
1254 } else if ((mod
->Attributes
& CONF_VPP1_CHANGE_VALID
) ||
1255 (mod
->Attributes
& CONF_VPP2_CHANGE_VALID
))
1259 } /* modify_configuration */
1261 /*======================================================================
1263 Modify the attributes of a window returned by RequestWindow.
1265 ======================================================================*/
1267 static int modify_window(window_handle_t win
, modwin_t
*req
)
1269 if ((win
== NULL
) || (win
->magic
!= WINDOW_MAGIC
))
1270 return CS_BAD_HANDLE
;
1272 win
->ctl
.flags
&= ~(MAP_ATTRIB
|MAP_ACTIVE
);
1273 if (req
->Attributes
& WIN_MEMORY_TYPE
)
1274 win
->ctl
.flags
|= MAP_ATTRIB
;
1275 if (req
->Attributes
& WIN_ENABLE
)
1276 win
->ctl
.flags
|= MAP_ACTIVE
;
1277 if (req
->Attributes
& WIN_DATA_WIDTH
)
1278 win
->ctl
.flags
|= MAP_16BIT
;
1279 if (req
->Attributes
& WIN_USE_WAIT
)
1280 win
->ctl
.flags
|= MAP_USE_WAIT
;
1281 win
->ctl
.speed
= req
->AccessSpeed
;
1282 win
->sock
->ss_entry(win
->sock
->sock
, SS_SetMemMap
, &win
->ctl
);
1285 } /* modify_window */
1287 /*======================================================================
1289 Register_client() uses the dev_info_t handle to match the
1290 caller with a socket. The driver must have already been bound
1291 to a socket with bind_device() -- in fact, bind_device()
1292 allocates the client structure that will be used.
1294 ======================================================================*/
1296 static int register_client(client_handle_t
*handle
, client_reg_t
*req
)
1302 /* Look for unbound client with matching dev_info */
1304 for (ns
= 0; ns
< sockets
; ns
++) {
1305 client
= socket_table
[ns
]->clients
;
1306 while (client
!= NULL
) {
1307 if ((strcmp(client
->dev_info
, (char *)req
->dev_info
) == 0)
1308 && (client
->state
& CLIENT_UNBOUND
)) break;
1309 client
= client
->next
;
1311 if (client
!= NULL
) break;
1314 return CS_OUT_OF_RESOURCE
;
1316 s
= socket_table
[ns
];
1317 if (++s
->real_clients
== 1) {
1320 call
.handler
= &parse_events
;
1322 s
->ss_entry(ns
, SS_RegisterCallback
, &call
);
1323 s
->ss_entry(ns
, SS_GetStatus
, &status
);
1324 if ((status
& SS_DETECT
) &&
1325 !(s
->state
& SOCKET_SETUP_PENDING
)) {
1326 s
->state
|= SOCKET_SETUP_PENDING
;
1332 client
->state
&= ~CLIENT_UNBOUND
;
1333 client
->Socket
= ns
;
1334 client
->Attributes
= req
->Attributes
;
1335 client
->EventMask
= req
->EventMask
;
1336 client
->event_handler
= req
->event_handler
;
1337 client
->event_callback_args
= req
->event_callback_args
;
1338 client
->event_callback_args
.client_handle
= client
;
1339 client
->event_callback_args
.bus
= s
->cap
.bus
;
1341 if (s
->state
& SOCKET_CARDBUS
)
1342 client
->state
|= CLIENT_CARDBUS
;
1344 if ((!(s
->state
& SOCKET_CARDBUS
)) && (s
->functions
== 0) &&
1345 (client
->Function
!= BIND_FN_ALL
)) {
1346 cistpl_longlink_mfc_t mfc
;
1347 if (read_tuple(client
, CISTPL_LONGLINK_MFC
, &mfc
)
1349 s
->functions
= mfc
.nfn
;
1352 s
->config
= kmalloc(sizeof(config_t
) * s
->functions
,
1354 memset(s
->config
, 0, sizeof(config_t
) * s
->functions
);
1357 DEBUG(1, "cs: register_client(): client 0x%p, sock %d, dev %s\n",
1358 client
, client
->Socket
, client
->dev_info
);
1359 if (client
->EventMask
& CS_EVENT_REGISTRATION_COMPLETE
)
1360 EVENT(client
, CS_EVENT_REGISTRATION_COMPLETE
, CS_EVENT_PRI_LOW
);
1361 if ((socket_table
[ns
]->state
& SOCKET_PRESENT
) &&
1362 !(socket_table
[ns
]->state
& SOCKET_SETUP_PENDING
)) {
1363 if (client
->EventMask
& CS_EVENT_CARD_INSERTION
)
1364 EVENT(client
, CS_EVENT_CARD_INSERTION
, CS_EVENT_PRI_LOW
);
1366 client
->PendingEvents
|= CS_EVENT_CARD_INSERTION
;
1369 } /* register_client */
1371 /*====================================================================*/
1373 static int release_configuration(client_handle_t handle
,
1380 if (CHECK_HANDLE(handle
) ||
1381 !(handle
->state
& CLIENT_CONFIG_LOCKED
))
1382 return CS_BAD_HANDLE
;
1383 handle
->state
&= ~CLIENT_CONFIG_LOCKED
;
1386 #ifdef CONFIG_CARDBUS
1387 if (handle
->state
& CLIENT_CARDBUS
) {
1394 if (!(handle
->state
& CLIENT_STALE
)) {
1395 config_t
*c
= CONFIG(handle
);
1396 if (--(s
->lock_count
) == 0) {
1397 s
->socket
.flags
= SS_OUTPUT_ENA
;
1399 s
->socket
.io_irq
= 0;
1400 s
->ss_entry(s
->sock
, SS_SetSocket
, &s
->socket
);
1402 if (c
->state
& CONFIG_IO_REQ
)
1403 for (i
= 0; i
< MAX_IO_WIN
; i
++) {
1404 if (s
->io
[i
].NumPorts
== 0)
1407 if (s
->io
[i
].Config
!= 0)
1410 s
->ss_entry(s
->sock
, SS_GetIOMap
, &io
);
1411 io
.flags
&= ~MAP_ACTIVE
;
1412 s
->ss_entry(s
->sock
, SS_SetIOMap
, &io
);
1414 c
->state
&= ~CONFIG_LOCKED
;
1418 } /* release_configuration */
1420 /*======================================================================
1422 Release_io() releases the I/O ranges allocated by a client. This
1423 may be invoked some time after a card ejection has already dumped
1424 the actual socket configuration, so if the client is "stale", we
1425 don't bother checking the port ranges against the current socket
1428 ======================================================================*/
1430 static int release_io(client_handle_t handle
, io_req_t
*req
)
1434 if (CHECK_HANDLE(handle
) || !(handle
->state
& CLIENT_IO_REQ
))
1435 return CS_BAD_HANDLE
;
1436 handle
->state
&= ~CLIENT_IO_REQ
;
1439 #ifdef CONFIG_CARDBUS
1440 if (handle
->state
& CLIENT_CARDBUS
) {
1446 if (!(handle
->state
& CLIENT_STALE
)) {
1447 config_t
*c
= CONFIG(handle
);
1448 if (c
->state
& CONFIG_LOCKED
)
1449 return CS_CONFIGURATION_LOCKED
;
1450 if ((c
->io
.BasePort1
!= req
->BasePort1
) ||
1451 (c
->io
.NumPorts1
!= req
->NumPorts1
) ||
1452 (c
->io
.BasePort2
!= req
->BasePort2
) ||
1453 (c
->io
.NumPorts2
!= req
->NumPorts2
))
1455 c
->state
&= ~CONFIG_IO_REQ
;
1458 release_io_space(s
, req
->BasePort1
, req
->NumPorts1
);
1460 release_io_space(s
, req
->BasePort2
, req
->NumPorts2
);
1465 /*====================================================================*/
1467 static int cs_release_irq(client_handle_t handle
, irq_req_t
*req
)
1470 if (CHECK_HANDLE(handle
) || !(handle
->state
& CLIENT_IRQ_REQ
))
1471 return CS_BAD_HANDLE
;
1472 handle
->state
&= ~CLIENT_IRQ_REQ
;
1475 if (!(handle
->state
& CLIENT_STALE
)) {
1476 config_t
*c
= CONFIG(handle
);
1477 if (c
->state
& CONFIG_LOCKED
)
1478 return CS_CONFIGURATION_LOCKED
;
1479 if (c
->irq
.Attributes
!= req
->Attributes
)
1480 return CS_BAD_ATTRIBUTE
;
1481 if (s
->irq
.AssignedIRQ
!= req
->AssignedIRQ
)
1483 if (--s
->irq
.Config
== 0) {
1484 c
->state
&= ~CONFIG_IRQ_REQ
;
1485 s
->irq
.AssignedIRQ
= 0;
1489 if (req
->Attributes
& IRQ_HANDLE_PRESENT
) {
1490 bus_free_irq(s
->cap
.bus
, req
->AssignedIRQ
, req
->Instance
);
1494 if (req
->AssignedIRQ
!= s
->cap
.pci_irq
)
1495 undo_irq(req
->Attributes
, req
->AssignedIRQ
);
1499 } /* cs_release_irq */
1501 /*====================================================================*/
1503 static int release_window(window_handle_t win
)
1507 if ((win
== NULL
) || (win
->magic
!= WINDOW_MAGIC
))
1508 return CS_BAD_HANDLE
;
1510 if (!(win
->handle
->state
& CLIENT_WIN_REQ(win
->index
)))
1511 return CS_BAD_HANDLE
;
1513 /* Shut down memory window */
1514 win
->ctl
.flags
&= ~MAP_ACTIVE
;
1515 s
->ss_entry(s
->sock
, SS_SetMemMap
, &win
->ctl
);
1516 s
->state
&= ~SOCKET_WIN_REQ(win
->index
);
1518 /* Release system memory */
1519 release_mem_region(win
->base
, win
->size
);
1520 win
->handle
->state
&= ~CLIENT_WIN_REQ(win
->index
);
1525 } /* release_window */
1527 /*====================================================================*/
1529 static int request_configuration(client_handle_t handle
,
1536 pccard_io_map iomap
;
1538 if (CHECK_HANDLE(handle
))
1539 return CS_BAD_HANDLE
;
1540 i
= handle
->Socket
; s
= socket_table
[i
];
1541 if (!(s
->state
& SOCKET_PRESENT
))
1544 #ifdef CONFIG_CARDBUS
1545 if (handle
->state
& CLIENT_CARDBUS
) {
1546 if (!(req
->IntType
& INT_CARDBUS
))
1547 return CS_UNSUPPORTED_MODE
;
1548 if (s
->lock_count
!= 0)
1549 return CS_CONFIGURATION_LOCKED
;
1551 handle
->state
|= CLIENT_CONFIG_LOCKED
;
1557 if (req
->IntType
& INT_CARDBUS
)
1558 return CS_UNSUPPORTED_MODE
;
1560 if (c
->state
& CONFIG_LOCKED
)
1561 return CS_CONFIGURATION_LOCKED
;
1563 /* Do power control. We don't allow changes in Vcc. */
1564 if (s
->socket
.Vcc
!= req
->Vcc
)
1566 if (req
->Vpp1
!= req
->Vpp2
)
1568 s
->socket
.Vpp
= req
->Vpp1
;
1569 if (s
->ss_entry(s
->sock
, SS_SetSocket
, &s
->socket
))
1572 c
->Vcc
= req
->Vcc
; c
->Vpp1
= c
->Vpp2
= req
->Vpp1
;
1574 /* Pick memory or I/O card, DMA mode, interrupt */
1575 c
->IntType
= req
->IntType
;
1576 c
->Attributes
= req
->Attributes
;
1577 if (req
->IntType
& INT_MEMORY_AND_IO
)
1578 s
->socket
.flags
|= SS_IOCARD
;
1579 if (req
->Attributes
& CONF_ENABLE_DMA
)
1580 s
->socket
.flags
|= SS_DMA_MODE
;
1581 if (req
->Attributes
& CONF_ENABLE_SPKR
)
1582 s
->socket
.flags
|= SS_SPKR_ENA
;
1583 if (req
->Attributes
& CONF_ENABLE_IRQ
)
1584 s
->socket
.io_irq
= s
->irq
.AssignedIRQ
;
1586 s
->socket
.io_irq
= 0;
1587 s
->ss_entry(s
->sock
, SS_SetSocket
, &s
->socket
);
1590 /* Set up CIS configuration registers */
1591 base
= c
->ConfigBase
= req
->ConfigBase
;
1592 c
->Present
= c
->CardValues
= req
->Present
;
1593 if (req
->Present
& PRESENT_COPY
) {
1594 c
->Copy
= req
->Copy
;
1595 write_cis_mem(s
, 1, (base
+ CISREG_SCR
)>>1, 1, &c
->Copy
);
1597 if (req
->Present
& PRESENT_OPTION
) {
1598 if (s
->functions
== 1)
1599 c
->Option
= req
->ConfigIndex
& COR_CONFIG_MASK
;
1601 c
->Option
= req
->ConfigIndex
& COR_MFC_CONFIG_MASK
;
1602 c
->Option
|= COR_FUNC_ENA
|COR_ADDR_DECODE
|COR_IREQ_ENA
;
1604 if (c
->state
& CONFIG_IRQ_REQ
)
1605 if (!(c
->irq
.Attributes
& IRQ_FORCED_PULSE
))
1606 c
->Option
|= COR_LEVEL_REQ
;
1607 write_cis_mem(s
, 1, (base
+ CISREG_COR
)>>1, 1, &c
->Option
);
1610 if (req
->Present
& PRESENT_STATUS
) {
1611 c
->Status
= req
->Status
;
1612 write_cis_mem(s
, 1, (base
+ CISREG_CCSR
)>>1, 1, &c
->Status
);
1614 if (req
->Present
& PRESENT_PIN_REPLACE
) {
1616 write_cis_mem(s
, 1, (base
+ CISREG_PRR
)>>1, 1, &c
->Pin
);
1618 if (req
->Present
& PRESENT_EXT_STATUS
) {
1619 c
->ExtStatus
= req
->ExtStatus
;
1620 write_cis_mem(s
, 1, (base
+ CISREG_ESR
)>>1, 1, &c
->ExtStatus
);
1622 if (req
->Present
& PRESENT_IOBASE_0
) {
1623 i
= c
->io
.BasePort1
& 0xff;
1624 write_cis_mem(s
, 1, (base
+ CISREG_IOBASE_0
)>>1, 1, &i
);
1625 i
= (c
->io
.BasePort1
>> 8) & 0xff;
1626 write_cis_mem(s
, 1, (base
+ CISREG_IOBASE_1
)>>1, 1, &i
);
1628 if (req
->Present
& PRESENT_IOSIZE
) {
1629 i
= c
->io
.NumPorts1
+ c
->io
.NumPorts2
- 1;
1630 write_cis_mem(s
, 1, (base
+ CISREG_IOSIZE
)>>1, 1, &i
);
1633 /* Configure I/O windows */
1634 if (c
->state
& CONFIG_IO_REQ
) {
1635 iomap
.speed
= io_speed
;
1636 for (i
= 0; i
< MAX_IO_WIN
; i
++)
1637 if (s
->io
[i
].NumPorts
!= 0) {
1639 iomap
.flags
= MAP_ACTIVE
;
1640 switch (s
->io
[i
].Attributes
& IO_DATA_PATH_WIDTH
) {
1641 case IO_DATA_PATH_WIDTH_16
:
1642 iomap
.flags
|= MAP_16BIT
; break;
1643 case IO_DATA_PATH_WIDTH_AUTO
:
1644 iomap
.flags
|= MAP_AUTOSZ
; break;
1648 iomap
.start
= s
->io
[i
].BasePort
;
1649 iomap
.stop
= iomap
.start
+ s
->io
[i
].NumPorts
- 1;
1650 s
->ss_entry(s
->sock
, SS_SetIOMap
, &iomap
);
1655 c
->state
|= CONFIG_LOCKED
;
1656 handle
->state
|= CLIENT_CONFIG_LOCKED
;
1658 } /* request_configuration */
1660 /*======================================================================
1662 Request_io() reserves ranges of port addresses for a socket.
1663 I have not implemented range sharing or alias addressing.
1665 ======================================================================*/
1667 static int request_io(client_handle_t handle
, io_req_t
*req
)
1672 if (CHECK_HANDLE(handle
))
1673 return CS_BAD_HANDLE
;
1675 if (!(s
->state
& SOCKET_PRESENT
))
1678 if (handle
->state
& CLIENT_CARDBUS
) {
1679 #ifdef CONFIG_CARDBUS
1680 int ret
= cb_config(s
);
1681 if (ret
== CS_SUCCESS
)
1682 handle
->state
|= CLIENT_IO_REQ
;
1685 return CS_UNSUPPORTED_FUNCTION
;
1690 return CS_UNSUPPORTED_MODE
;
1692 if (c
->state
& CONFIG_LOCKED
)
1693 return CS_CONFIGURATION_LOCKED
;
1694 if (c
->state
& CONFIG_IO_REQ
)
1696 if (req
->Attributes1
& (IO_SHARED
| IO_FORCE_ALIAS_ACCESS
))
1697 return CS_BAD_ATTRIBUTE
;
1698 if ((req
->NumPorts2
> 0) &&
1699 (req
->Attributes2
& (IO_SHARED
| IO_FORCE_ALIAS_ACCESS
)))
1700 return CS_BAD_ATTRIBUTE
;
1702 if (alloc_io_space(s
, req
->Attributes1
, &req
->BasePort1
,
1703 req
->NumPorts1
, handle
->dev_info
))
1706 if (req
->NumPorts2
) {
1707 if (alloc_io_space(s
, req
->Attributes2
, &req
->BasePort2
,
1708 req
->NumPorts2
, handle
->dev_info
)) {
1709 release_io_space(s
, req
->BasePort1
, req
->NumPorts1
);
1715 c
->state
|= CONFIG_IO_REQ
;
1716 handle
->state
|= CLIENT_IO_REQ
;
1720 /*======================================================================
1722 Request_irq() reserves an irq for this client.
1724 Also, since Linux only reserves irq's when they are actually
1725 hooked, we don't guarantee that an irq will still be available
1726 when the configuration is locked. Now that I think about it,
1727 there might be a way to fix this using a dummy handler.
1729 ======================================================================*/
1731 static int cs_request_irq(client_handle_t handle
, irq_req_t
*req
)
1735 int try, ret
= 0, irq
= 0;
1738 if (CHECK_HANDLE(handle
))
1739 return CS_BAD_HANDLE
;
1741 if (!(s
->state
& SOCKET_PRESENT
))
1744 if (c
->state
& CONFIG_LOCKED
)
1745 return CS_CONFIGURATION_LOCKED
;
1746 if (c
->state
& CONFIG_IRQ_REQ
)
1749 /* Short cut: if the interrupt is PCI, there are no options */
1750 if (s
->cap
.irq_mask
== (1 << s
->cap
.pci_irq
))
1751 irq
= s
->cap
.pci_irq
;
1753 else if (s
->irq
.AssignedIRQ
!= 0) {
1754 /* If the interrupt is already assigned, it must match */
1755 irq
= s
->irq
.AssignedIRQ
;
1756 if (req
->IRQInfo1
& IRQ_INFO2_VALID
) {
1757 mask
= req
->IRQInfo2
& s
->cap
.irq_mask
;
1758 ret
= ((mask
>> irq
) & 1) ? 0 : CS_BAD_ARGS
;
1760 ret
= ((req
->IRQInfo1
&IRQ_MASK
) == irq
) ? 0 : CS_BAD_ARGS
;
1763 if (req
->IRQInfo1
& IRQ_INFO2_VALID
) {
1764 mask
= req
->IRQInfo2
& s
->cap
.irq_mask
;
1765 mask
&= ~(1 << s
->cap
.pci_irq
);
1766 for (try = 0; try < 2; try++) {
1767 for (irq
= 0; irq
< 32; irq
++)
1768 if ((mask
>> irq
) & 1) {
1769 ret
= try_irq(req
->Attributes
, irq
, try);
1770 if (ret
== 0) break;
1772 if (ret
== 0) break;
1775 irq
= req
->IRQInfo1
& IRQ_MASK
;
1776 ret
= try_irq(req
->Attributes
, irq
, 1);
1780 if (ret
!= 0) return ret
;
1782 if (req
->Attributes
& IRQ_HANDLE_PRESENT
) {
1783 if (bus_request_irq(s
->cap
.bus
, irq
, req
->Handler
,
1784 ((req
->Attributes
& IRQ_TYPE_DYNAMIC_SHARING
) ||
1785 (s
->functions
> 1) ||
1786 (irq
== s
->cap
.pci_irq
)) ? SA_SHIRQ
: 0,
1787 handle
->dev_info
, req
->Instance
))
1791 c
->irq
.Attributes
= req
->Attributes
;
1792 s
->irq
.AssignedIRQ
= req
->AssignedIRQ
= irq
;
1795 c
->state
|= CONFIG_IRQ_REQ
;
1796 handle
->state
|= CLIENT_IRQ_REQ
;
1798 } /* cs_request_irq */
1800 /*======================================================================
1802 Request_window() establishes a mapping between card memory space
1803 and system memory space.
1805 ======================================================================*/
1807 static int request_window(client_handle_t
*handle
, win_req_t
*req
)
1813 if (CHECK_HANDLE(*handle
))
1814 return CS_BAD_HANDLE
;
1815 s
= SOCKET(*handle
);
1816 if (!(s
->state
& SOCKET_PRESENT
))
1818 if (req
->Attributes
& (WIN_PAGED
| WIN_SHARED
))
1819 return CS_BAD_ATTRIBUTE
;
1821 for (w
= 0; w
< MAX_WIN
; w
++)
1822 if (!(s
->state
& SOCKET_WIN_REQ(w
))) break;
1824 return CS_OUT_OF_RESOURCE
;
1826 /* Window size defaults to smallest available */
1828 req
->Size
= s
->cap
.map_size
;
1830 /* Allocate system memory window */
1832 win
->magic
= WINDOW_MAGIC
;
1834 win
->handle
= *handle
;
1836 win
->base
= req
->Base
;
1837 win
->size
= req
->Size
;
1838 if (find_mem_region(&win
->base
, win
->size
, (*handle
)->dev_info
,
1839 ((s
->cap
.features
& SS_CAP_MEM_ALIGN
) ?
1840 req
->Size
: s
->cap
.map_size
),
1841 (req
->Attributes
& WIN_MAP_BELOW_1MB
) ||
1842 !(s
->cap
.features
& SS_CAP_PAGE_REGS
)))
1844 req
->Base
= win
->base
;
1845 (*handle
)->state
|= CLIENT_WIN_REQ(w
);
1847 /* Configure the socket controller */
1850 win
->ctl
.speed
= req
->AccessSpeed
;
1851 if (req
->Attributes
& WIN_MEMORY_TYPE
)
1852 win
->ctl
.flags
|= MAP_ATTRIB
;
1853 if (req
->Attributes
& WIN_ENABLE
)
1854 win
->ctl
.flags
|= MAP_ACTIVE
;
1855 if (req
->Attributes
& WIN_DATA_WIDTH
)
1856 win
->ctl
.flags
|= MAP_16BIT
;
1857 if (req
->Attributes
& WIN_USE_WAIT
)
1858 win
->ctl
.flags
|= MAP_USE_WAIT
;
1859 win
->ctl
.sys_start
= req
->Base
;
1860 win
->ctl
.sys_stop
= req
->Base
+ req
->Size
-1;
1861 win
->ctl
.card_start
= 0;
1862 if (s
->ss_entry(s
->sock
, SS_SetMemMap
, &win
->ctl
) != 0)
1864 s
->state
|= SOCKET_WIN_REQ(w
);
1866 /* Return window handle */
1867 *handle
= (client_handle_t
)win
;
1870 } /* request_window */
1872 /*======================================================================
1874 I'm not sure which "reset" function this is supposed to use,
1875 but for now, it uses the low-level interface's reset, not the
1878 ======================================================================*/
1880 static int reset_card(client_handle_t handle
, client_req_t
*req
)
1885 if (CHECK_HANDLE(handle
))
1886 return CS_BAD_HANDLE
;
1887 i
= handle
->Socket
; s
= socket_table
[i
];
1888 if (!(s
->state
& SOCKET_PRESENT
))
1890 if (s
->state
& SOCKET_RESET_PENDING
)
1892 s
->state
|= SOCKET_RESET_PENDING
;
1894 ret
= send_event(s
, CS_EVENT_RESET_REQUEST
, CS_EVENT_PRI_LOW
);
1896 s
->state
&= ~SOCKET_RESET_PENDING
;
1897 handle
->event_callback_args
.info
= (void *)(u_long
)ret
;
1898 EVENT(handle
, CS_EVENT_RESET_COMPLETE
, CS_EVENT_PRI_LOW
);
1900 DEBUG(1, "cs: resetting socket %d\n", i
);
1901 send_event(s
, CS_EVENT_RESET_PHYSICAL
, CS_EVENT_PRI_LOW
);
1902 s
->reset_handle
= handle
;
1908 /*======================================================================
1910 These shut down or wake up a socket. They are sort of user
1911 initiated versions of the APM suspend and resume actions.
1913 ======================================================================*/
1915 static int suspend_card(client_handle_t handle
, client_req_t
*req
)
1920 if (CHECK_HANDLE(handle
))
1921 return CS_BAD_HANDLE
;
1922 i
= handle
->Socket
; s
= socket_table
[i
];
1923 if (!(s
->state
& SOCKET_PRESENT
))
1925 if (s
->state
& SOCKET_SUSPEND
)
1928 DEBUG(1, "cs: suspending socket %d\n", i
);
1929 send_event(s
, CS_EVENT_PM_SUSPEND
, CS_EVENT_PRI_LOW
);
1930 s
->ss_entry(s
->sock
, SS_SetSocket
, &dead_socket
);
1931 s
->state
|= SOCKET_SUSPEND
;
1934 } /* suspend_card */
1936 static int resume_card(client_handle_t handle
, client_req_t
*req
)
1941 if (CHECK_HANDLE(handle
))
1942 return CS_BAD_HANDLE
;
1943 i
= handle
->Socket
; s
= socket_table
[i
];
1944 if (!(s
->state
& SOCKET_PRESENT
))
1946 if (!(s
->state
& SOCKET_SUSPEND
))
1949 DEBUG(1, "cs: waking up socket %d\n", i
);
1955 /*======================================================================
1957 These handle user requests to eject or insert a card.
1959 ======================================================================*/
1961 static int eject_card(client_handle_t handle
, client_req_t
*req
)
1967 if (CHECK_HANDLE(handle
))
1968 return CS_BAD_HANDLE
;
1969 i
= handle
->Socket
; s
= socket_table
[i
];
1970 if (!(s
->state
& SOCKET_PRESENT
))
1973 DEBUG(1, "cs: user eject request on socket %d\n", i
);
1975 ret
= send_event(s
, CS_EVENT_EJECTION_REQUEST
, CS_EVENT_PRI_LOW
);
1979 spin_lock_irqsave(&s
->lock
, flags
);
1981 spin_unlock_irqrestore(&s
->lock
, flags
);
1987 static int insert_card(client_handle_t handle
, client_req_t
*req
)
1993 if (CHECK_HANDLE(handle
))
1994 return CS_BAD_HANDLE
;
1995 i
= handle
->Socket
; s
= socket_table
[i
];
1996 if (s
->state
& SOCKET_PRESENT
)
1999 DEBUG(1, "cs: user insert request on socket %d\n", i
);
2001 spin_lock_irqsave(&s
->lock
, flags
);
2002 if (!(s
->state
& SOCKET_SETUP_PENDING
)) {
2003 s
->state
|= SOCKET_SETUP_PENDING
;
2004 spin_unlock_irqrestore(&s
->lock
, flags
);
2005 s
->ss_entry(i
, SS_GetStatus
, &status
);
2006 if (status
& SS_DETECT
)
2009 s
->state
&= ~SOCKET_SETUP_PENDING
;
2013 spin_unlock_irqrestore(&s
->lock
, flags
);
2018 /*======================================================================
2020 Maybe this should send a CS_EVENT_CARD_INSERTION event if we
2021 haven't sent one to this client yet?
2023 ======================================================================*/
2025 static int set_event_mask(client_handle_t handle
, eventmask_t
*mask
)
2028 if (CHECK_HANDLE(handle
))
2029 return CS_BAD_HANDLE
;
2030 if (handle
->Attributes
& CONF_EVENT_MASK_VALID
)
2031 return CS_BAD_SOCKET
;
2032 handle
->EventMask
= mask
->EventMask
;
2033 events
= handle
->PendingEvents
& handle
->EventMask
;
2034 handle
->PendingEvents
-= events
;
2035 while (events
!= 0) {
2036 bit
= ((events
^ (events
-1)) + 1) >> 1;
2037 EVENT(handle
, bit
, CS_EVENT_PRI_LOW
);
2041 } /* set_event_mask */
2043 /*====================================================================*/
2045 static int report_error(client_handle_t handle
, error_info_t
*err
)
2050 if (CHECK_HANDLE(handle
))
2051 printk(KERN_NOTICE
);
2053 printk(KERN_NOTICE
"%s: ", handle
->dev_info
);
2055 for (i
= 0; i
< SERVICE_COUNT
; i
++)
2056 if (service_table
[i
].key
== err
->func
) break;
2057 if (i
< SERVICE_COUNT
)
2058 serv
= service_table
[i
].msg
;
2060 serv
= "Unknown service number";
2062 for (i
= 0; i
< ERROR_COUNT
; i
++)
2063 if (error_table
[i
].key
== err
->retcode
) break;
2064 if (i
< ERROR_COUNT
)
2065 printk("%s: %s\n", serv
, error_table
[i
].msg
);
2067 printk("%s: Unknown error code %#x\n", serv
, err
->retcode
);
2070 } /* report_error */
2072 /*====================================================================*/
2074 int CardServices(int func
, void *a1
, void *a2
, void *a3
)
2080 for (i
= 0; i
< SERVICE_COUNT
; i
++)
2081 if (service_table
[i
].key
== func
) break;
2082 if (i
< SERVICE_COUNT
)
2083 printk(KERN_DEBUG
"cs: CardServices(%s, 0x%p, 0x%p)\n",
2084 service_table
[i
].msg
, a1
, a2
);
2086 printk(KERN_DEBUG
"cs: CardServices(Unknown func %d, "
2087 "0x%p, 0x%p)\n", func
, a1
, a2
);
2091 case AccessConfigurationRegister
:
2092 return access_configuration_register(a1
, a2
); break;
2093 case AdjustResourceInfo
:
2094 return adjust_resource_info(a1
, a2
); break;
2095 case CheckEraseQueue
:
2096 return check_erase_queue(a1
); break;
2098 return close_memory(a1
); break;
2100 return copy_memory(a1
, a2
); break;
2101 case DeregisterClient
:
2102 return deregister_client(a1
); break;
2103 case DeregisterEraseQueue
:
2104 return deregister_erase_queue(a1
); break;
2105 case GetFirstClient
:
2106 return get_first_client(a1
, a2
); break;
2107 case GetCardServicesInfo
:
2108 return get_card_services_info(a1
); break;
2109 case GetConfigurationInfo
:
2110 return get_configuration_info(a1
, a2
); break;
2112 return get_next_client(a1
, a2
); break;
2113 case GetFirstRegion
:
2114 return get_first_region(a1
, a2
); break;
2116 return get_first_tuple(a1
, a2
); break;
2118 return get_next_region(a1
, a2
); break;
2120 return get_next_tuple(a1
, a2
); break;
2122 return get_status(a1
, a2
); break;
2124 return get_tuple_data(a1
, a2
); break;
2126 return map_mem_page(a1
, a2
); break;
2127 case ModifyConfiguration
:
2128 return modify_configuration(a1
, a2
); break;
2130 return modify_window(a1
, a2
); break;
2132 return open_memory(a1
, a2
);
2134 return parse_tuple(a1
, a2
, a3
); break;
2136 return read_memory(a1
, a2
, a3
); break;
2137 case RegisterClient
:
2138 return register_client(a1
, a2
); break;
2139 case RegisterEraseQueue
:
2140 return register_erase_queue(a1
, a2
); break;
2142 return register_mtd(a1
, a2
); break;
2143 case ReleaseConfiguration
:
2144 return release_configuration(a1
, a2
); break;
2146 return release_io(a1
, a2
); break;
2148 return cs_release_irq(a1
, a2
); break;
2150 return release_window(a1
); break;
2151 case RequestConfiguration
:
2152 return request_configuration(a1
, a2
); break;
2154 return request_io(a1
, a2
); break;
2156 return cs_request_irq(a1
, a2
); break;
2158 return request_window(a1
, a2
); break;
2160 return reset_card(a1
, a2
); break;
2162 return set_event_mask(a1
, a2
); break;
2164 return validate_cis(a1
, a2
); break;
2166 return write_memory(a1
, a2
, a3
); break;
2168 return bind_device(a1
); break;
2170 return bind_mtd(a1
); break;
2172 return report_error(a1
, a2
); break;
2174 return suspend_card(a1
, a2
); break;
2176 return resume_card(a1
, a2
); break;
2178 return eject_card(a1
, a2
); break;
2180 return insert_card(a1
, a2
); break;
2182 return replace_cis(a1
, a2
); break;
2183 case GetFirstWindow
:
2184 return get_first_window(a1
, a2
); break;
2186 return get_next_window(a1
, a2
); break;
2188 return get_mem_page(a1
, a2
); break;
2190 return CS_UNSUPPORTED_FUNCTION
; break;
2193 } /* CardServices */
2195 /*======================================================================
2197 OS-specific module glue goes here
2199 ======================================================================*/
2201 EXPORT_SYMBOL(register_ss_entry
);
2202 EXPORT_SYMBOL(unregister_ss_entry
);
2203 EXPORT_SYMBOL(CardServices
);
2204 EXPORT_SYMBOL(MTDHelperEntry
);
2206 static int __init
init_pcmcia_cs(void)
2208 printk(KERN_INFO
"%s\n", release
);
2210 printk(KERN_INFO
" %s\n", kernel
);
2212 printk(KERN_INFO
" %s\n", options
);
2213 DEBUG(0, "%s\n", version
);
2216 apm_register_callback(&handle_apm_event
);
2218 #ifdef CONFIG_PROC_FS
2219 proc_pccard
= create_proc_entry("pccard", S_IFDIR
, proc_bus
);
2224 static void __exit
exit_pcmcia_cs(void)
2226 printk(KERN_INFO
"unloading PCMCIA Card Services\n");
2227 #ifdef CONFIG_PROC_FS
2229 remove_proc_entry("pccard", proc_bus
);
2234 apm_unregister_callback(&handle_apm_event
);
2236 release_resource_db();
2239 module_init(init_pcmcia_cs
);
2240 module_exit(exit_pcmcia_cs
);
2242 /*====================================================================*/