2 * cs_internal.h -- definitions internal to the PCMCIA core modules
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
8 * The initial developer of the original code is David A. Hinds
9 * <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
10 * are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
12 * (C) 1999 David A. Hinds
13 * (C) 2003 - 2008 Dominik Brodowski
16 * This file contains definitions _only_ needed by the PCMCIA core modules.
17 * It must not be included by PCMCIA socket drivers or by PCMCIA device
21 #ifndef _LINUX_CS_INTERNAL_H
22 #define _LINUX_CS_INTERNAL_H
24 #include <linux/kref.h>
26 /* Flags in client state */
27 #define CLIENT_WIN_REQ(i) (0x1<<(i))
29 /* Each card function gets one of these guys */
30 typedef struct config_t
{
33 unsigned int Attributes
;
35 unsigned int ConfigBase
;
36 unsigned char Status
, Pin
, Copy
, Option
, ExtStatus
;
37 unsigned int CardValues
;
45 struct cis_cache_entry
{
46 struct list_head node
;
50 unsigned char cache
[0];
53 struct pccard_resource_ops
{
54 int (*validate_mem
) (struct pcmcia_socket
*s
);
55 int (*adjust_io_region
) (struct resource
*res
,
56 unsigned long r_start
,
58 struct pcmcia_socket
*s
);
59 struct resource
* (*find_io
) (unsigned long base
, int num
,
61 struct pcmcia_socket
*s
);
62 struct resource
* (*find_mem
) (unsigned long base
, unsigned long num
,
63 unsigned long align
, int low
,
64 struct pcmcia_socket
*s
);
65 int (*add_io
) (struct pcmcia_socket
*s
,
67 unsigned long r_start
,
69 int (*add_mem
) (struct pcmcia_socket
*s
,
71 unsigned long r_start
,
73 int (*init
) (struct pcmcia_socket
*s
);
74 void (*exit
) (struct pcmcia_socket
*s
);
77 /* Flags in config state */
78 #define CONFIG_LOCKED 0x01
79 #define CONFIG_IRQ_REQ 0x02
80 #define CONFIG_IO_REQ 0x04
82 /* Flags in socket state */
83 #define SOCKET_PRESENT 0x0008
84 #define SOCKET_INUSE 0x0010
85 #define SOCKET_SUSPEND 0x0080
86 #define SOCKET_WIN_REQ(i) (0x0100<<(i))
87 #define SOCKET_CARDBUS 0x8000
88 #define SOCKET_CARDBUS_CONFIG 0x10000
90 static inline int cs_socket_get(struct pcmcia_socket
*skt
)
94 WARN_ON(skt
->state
& SOCKET_INUSE
);
96 ret
= try_module_get(skt
->owner
);
98 skt
->state
|= SOCKET_INUSE
;
102 static inline void cs_socket_put(struct pcmcia_socket
*skt
)
104 if (skt
->state
& SOCKET_INUSE
) {
105 skt
->state
&= ~SOCKET_INUSE
;
106 module_put(skt
->owner
);
112 * Stuff internal to module "pcmcia_core":
116 int verify_cis_cache(struct pcmcia_socket
*s
);
119 void release_resource_db(struct pcmcia_socket
*s
);
122 extern int pccard_sysfs_add_socket(struct device
*dev
);
123 extern void pccard_sysfs_remove_socket(struct device
*dev
);
126 int cb_alloc(struct pcmcia_socket
*s
);
127 void cb_free(struct pcmcia_socket
*s
);
128 int read_cb_mem(struct pcmcia_socket
*s
, int space
, u_int addr
, u_int len
,
134 * Stuff exported by module "pcmcia_core" to module "pcmcia"
137 struct pcmcia_callback
{
138 struct module
*owner
;
139 int (*event
) (struct pcmcia_socket
*s
,
140 event_t event
, int priority
);
141 void (*requery
) (struct pcmcia_socket
*s
, int new_cis
);
142 int (*suspend
) (struct pcmcia_socket
*s
);
143 int (*resume
) (struct pcmcia_socket
*s
);
147 extern struct rw_semaphore pcmcia_socket_list_rwsem
;
148 extern struct list_head pcmcia_socket_list
;
149 extern struct class pcmcia_socket_class
;
151 int pccard_register_pcmcia(struct pcmcia_socket
*s
, struct pcmcia_callback
*c
);
152 struct pcmcia_socket
*pcmcia_get_socket_by_nr(unsigned int nr
);
154 int pcmcia_suspend_card(struct pcmcia_socket
*skt
);
155 int pcmcia_resume_card(struct pcmcia_socket
*skt
);
157 int pcmcia_eject_card(struct pcmcia_socket
*skt
);
158 int pcmcia_insert_card(struct pcmcia_socket
*skt
);
160 struct pcmcia_socket
*pcmcia_get_socket(struct pcmcia_socket
*skt
);
161 void pcmcia_put_socket(struct pcmcia_socket
*skt
);
164 int pcmcia_read_cis_mem(struct pcmcia_socket
*s
, int attr
,
165 u_int addr
, u_int len
, void *ptr
);
166 void pcmcia_write_cis_mem(struct pcmcia_socket
*s
, int attr
,
167 u_int addr
, u_int len
, void *ptr
);
168 void release_cis_mem(struct pcmcia_socket
*s
);
169 void destroy_cis_cache(struct pcmcia_socket
*s
);
170 int pccard_read_tuple(struct pcmcia_socket
*s
, unsigned int function
,
171 cisdata_t code
, void *parse
);
172 int pcmcia_replace_cis(struct pcmcia_socket
*s
,
173 const u8
*data
, const size_t len
);
174 int pccard_validate_cis(struct pcmcia_socket
*s
, unsigned int *count
);
176 /* loop over CIS entries */
177 int pccard_loop_tuple(struct pcmcia_socket
*s
, unsigned int function
,
178 cisdata_t code
, cisparse_t
*parse
, void *priv_data
,
179 int (*loop_tuple
) (tuple_t
*tuple
,
183 int pccard_get_first_tuple(struct pcmcia_socket
*s
, unsigned int function
,
186 int pccard_get_next_tuple(struct pcmcia_socket
*s
, unsigned int function
,
189 int pccard_get_tuple_data(struct pcmcia_socket
*s
, tuple_t
*tuple
);
193 int pcmcia_validate_mem(struct pcmcia_socket
*s
);
194 struct resource
*pcmcia_find_io_region(unsigned long base
,
197 struct pcmcia_socket
*s
);
198 int pcmcia_adjust_io_region(struct resource
*res
,
199 unsigned long r_start
,
201 struct pcmcia_socket
*s
);
202 struct resource
*pcmcia_find_mem_region(u_long base
,
206 struct pcmcia_socket
*s
);
209 * Stuff internal to module "pcmcia".
212 extern struct bus_type pcmcia_bus_type
;
214 /* pcmcia_resource.c */
215 extern int pcmcia_release_configuration(struct pcmcia_device
*p_dev
);
217 #ifdef CONFIG_PCMCIA_IOCTL
219 extern spinlock_t pcmcia_dev_list_lock
;
221 extern struct pcmcia_device
*pcmcia_get_dev(struct pcmcia_device
*p_dev
);
222 extern void pcmcia_put_dev(struct pcmcia_device
*p_dev
);
224 struct pcmcia_device
*pcmcia_device_add(struct pcmcia_socket
*s
,
225 unsigned int function
);
228 extern void __init
pcmcia_setup_ioctl(void);
229 extern void __exit
pcmcia_cleanup_ioctl(void);
230 extern void handle_event(struct pcmcia_socket
*s
, event_t event
);
231 extern int handle_request(struct pcmcia_socket
*s
, event_t event
);
233 #else /* CONFIG_PCMCIA_IOCTL */
235 static inline void __init
pcmcia_setup_ioctl(void) { return; }
236 static inline void __exit
pcmcia_cleanup_ioctl(void) { return; }
237 static inline void handle_event(struct pcmcia_socket
*s
, event_t event
)
241 static inline int handle_request(struct pcmcia_socket
*s
, event_t event
)
246 #endif /* CONFIG_PCMCIA_IOCTL */
248 #endif /* _LINUX_CS_INTERNAL_H */