2 * cs_internal.h 1.57 2002/10/24 06:11:43
4 * The contents of this file are subject to the Mozilla Public License
5 * Version 1.1 (the "License"); you may not use this file except in
6 * compliance with the License. You may obtain a copy of the License
7 * at http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS"
10 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11 * the License for the specific language governing rights and
12 * limitations under the License.
14 * The initial developer of the original code is David A. Hinds
15 * <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
16 * are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
19 #ifndef _LINUX_CS_INTERNAL_H
20 #define _LINUX_CS_INTERNAL_H
22 #include <linux/config.h>
24 #define CLIENT_MAGIC 0x51E6
25 typedef struct client_t {
27 struct pcmcia_socket *Socket;
32 event_t EventMask, PendingEvents;
33 int (*event_handler)(event_t event, int priority,
34 event_callback_args_t *);
35 event_callback_args_t event_callback_args;
36 struct client_t *next;
39 /* Flags in client state */
40 #define CLIENT_CONFIG_LOCKED 0x0001
41 #define CLIENT_IRQ_REQ 0x0002
42 #define CLIENT_IO_REQ 0x0004
43 #define CLIENT_UNBOUND 0x0008
44 #define CLIENT_STALE 0x0010
45 #define CLIENT_WIN_REQ(i) (0x20<<(i))
46 #define CLIENT_CARDBUS 0x8000
48 #define REGION_MAGIC 0xE3C9
49 typedef struct region_t {
58 #define REGION_STALE 0x01
60 /* Each card function gets one of these guys */
61 typedef struct config_t {
64 u_int Vcc, Vpp1, Vpp2;
67 u_char Status, Pin, Copy, Option, ExtStatus;
76 struct cis_cache_entry {
77 struct list_head node;
81 unsigned char cache[0];
84 /* Flags in config state */
85 #define CONFIG_LOCKED 0x01
86 #define CONFIG_IRQ_REQ 0x02
87 #define CONFIG_IO_REQ 0x04
89 /* Flags in socket state */
90 #define SOCKET_PRESENT 0x0008
91 #define SOCKET_INUSE 0x0010
92 #define SOCKET_SUSPEND 0x0080
93 #define SOCKET_WIN_REQ(i) (0x0100<<(i))
94 #define SOCKET_REGION_INFO 0x4000
95 #define SOCKET_CARDBUS 0x8000
96 #define SOCKET_CARDBUS_CONFIG 0x10000
98 static inline int cs_socket_get(struct pcmcia_socket *skt)
102 WARN_ON(skt->state & SOCKET_INUSE);
104 ret = try_module_get(skt->owner);
106 skt->state |= SOCKET_INUSE;
110 static inline void cs_socket_put(struct pcmcia_socket *skt)
112 if (skt->state & SOCKET_INUSE) {
113 skt->state &= ~SOCKET_INUSE;
114 module_put(skt->owner);
118 #define CHECK_HANDLE(h) \
119 (((h) == NULL) || ((h)->client_magic != CLIENT_MAGIC))
121 #define CHECK_SOCKET(s) \
122 (((s) >= sockets) || (socket_table[s]->ops == NULL))
124 #define SOCKET(h) (h->Socket)
125 #define CONFIG(h) (&SOCKET(h)->config[(h)->Function])
127 #define CHECK_REGION(r) \
128 (((r) == NULL) || ((r)->region_magic != REGION_MAGIC))
130 #define CHECK_ERASEQ(q) \
131 (((q) == NULL) || ((q)->eraseq_magic != ERASEQ_MAGIC))
133 #define EVENT(h, e, p) \
134 ((h)->event_handler((e), (p), &(h)->event_callback_args))
137 int cb_alloc(struct pcmcia_socket *s);
138 void cb_free(struct pcmcia_socket *s);
139 int read_cb_mem(struct pcmcia_socket *s, int space, u_int addr, u_int len, void *ptr);
142 int read_cis_mem(struct pcmcia_socket *s, int attr,
143 u_int addr, u_int len, void *ptr);
144 void write_cis_mem(struct pcmcia_socket *s, int attr,
145 u_int addr, u_int len, void *ptr);
146 void release_cis_mem(struct pcmcia_socket *s);
147 void destroy_cis_cache(struct pcmcia_socket *s);
148 int verify_cis_cache(struct pcmcia_socket *s);
149 int pccard_read_tuple(struct pcmcia_socket *s, unsigned int function, cisdata_t code, void *parse);
152 void pcmcia_validate_mem(struct pcmcia_socket *s);
153 struct resource *find_io_region(unsigned long base, int num, unsigned long align,
154 char *name, struct pcmcia_socket *s);
155 int adjust_io_region(struct resource *res, unsigned long r_start,
156 unsigned long r_end, struct pcmcia_socket *s);
157 struct resource *find_mem_region(u_long base, u_long num, u_long align,
158 int low, char *name, struct pcmcia_socket *s);
159 int try_irq(u_int Attributes, int irq, int specific);
160 void undo_irq(u_int Attributes, int irq);
161 int adjust_resource_info(client_handle_t handle, adjust_t *adj);
162 void release_resource_db(void);
164 /* In socket_sysfs.c */
165 extern struct class_interface pccard_sysfs_interface;
168 extern struct rw_semaphore pcmcia_socket_list_rwsem;
169 extern struct list_head pcmcia_socket_list;
170 int pcmcia_get_window(struct pcmcia_socket *s, window_handle_t *handle, int idx, win_req_t *req);
171 int pccard_get_configuration_info(struct pcmcia_socket *s, unsigned int function, config_info_t *config);
172 int pccard_reset_card(struct pcmcia_socket *skt);
173 int pccard_get_status(struct pcmcia_socket *s, unsigned int function, cs_status_t *status);
174 int pccard_access_configuration_register(struct pcmcia_socket *s, unsigned int function, conf_reg_t *reg);
176 #define cs_socket_name(skt) ((skt)->dev.class_id)
179 extern int cs_debug_level(int);
181 #define cs_dbg(skt, lvl, fmt, arg...) do { \
182 if (cs_debug_level(lvl)) \
183 printk(KERN_DEBUG "cs: %s: " fmt, \
184 cs_socket_name(skt) , ## arg); \
188 #define cs_dbg(skt, lvl, fmt, arg...) do { } while (0)
191 #define cs_err(skt, fmt, arg...) \
192 printk(KERN_ERR "cs: %s: " fmt, (skt)->dev.class_id , ## arg)
194 #endif /* _LINUX_CS_INTERNAL_H */