MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / drivers / pcmcia / cs_internal.h
blobe148fb96746ae1ed7c5c64f2b449f7e144af988b
1 /*
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 ERASEQ_MAGIC 0xFA67
25 typedef struct eraseq_t {
26 u_short eraseq_magic;
27 client_handle_t handle;
28 int count;
29 eraseq_entry_t *entry;
30 } eraseq_t;
32 #define CLIENT_MAGIC 0x51E6
33 typedef struct client_t {
34 u_short client_magic;
35 struct pcmcia_socket *Socket;
36 u_char Function;
37 dev_info_t dev_info;
38 u_int Attributes;
39 u_int state;
40 event_t EventMask, PendingEvents;
41 int (*event_handler)(event_t event, int priority,
42 event_callback_args_t *);
43 event_callback_args_t event_callback_args;
44 struct client_t *next;
45 u_int mtd_count;
46 wait_queue_head_t mtd_req;
47 erase_busy_t erase_busy;
48 } client_t;
50 /* Flags in client state */
51 #define CLIENT_CONFIG_LOCKED 0x0001
52 #define CLIENT_IRQ_REQ 0x0002
53 #define CLIENT_IO_REQ 0x0004
54 #define CLIENT_UNBOUND 0x0008
55 #define CLIENT_STALE 0x0010
56 #define CLIENT_WIN_REQ(i) (0x20<<(i))
57 #define CLIENT_CARDBUS 0x8000
59 #define REGION_MAGIC 0xE3C9
60 typedef struct region_t {
61 u_short region_magic;
62 u_short state;
63 dev_info_t dev_info;
64 client_handle_t mtd;
65 u_int MediaID;
66 region_info_t info;
67 } region_t;
69 #define REGION_STALE 0x01
71 /* Each card function gets one of these guys */
72 typedef struct config_t {
73 u_int state;
74 u_int Attributes;
75 u_int Vcc, Vpp1, Vpp2;
76 u_int IntType;
77 u_int ConfigBase;
78 u_char Status, Pin, Copy, Option, ExtStatus;
79 u_int Present;
80 u_int CardValues;
81 io_req_t io;
82 struct {
83 u_int Attributes;
84 } irq;
85 } config_t;
87 struct cis_cache_entry {
88 struct list_head node;
89 unsigned int addr;
90 unsigned int len;
91 unsigned int attr;
92 unsigned char cache[0];
95 /* Flags in config state */
96 #define CONFIG_LOCKED 0x01
97 #define CONFIG_IRQ_REQ 0x02
98 #define CONFIG_IO_REQ 0x04
100 /* Flags in socket state */
101 #define SOCKET_PRESENT 0x0008
102 #define SOCKET_INUSE 0x0010
103 #define SOCKET_SUSPEND 0x0080
104 #define SOCKET_WIN_REQ(i) (0x0100<<(i))
105 #define SOCKET_REGION_INFO 0x4000
106 #define SOCKET_CARDBUS 0x8000
107 #define SOCKET_CARDBUS_CONFIG 0x10000
109 static inline int cs_socket_get(struct pcmcia_socket *skt)
111 int ret;
113 WARN_ON(skt->state & SOCKET_INUSE);
115 ret = try_module_get(skt->owner);
116 if (ret)
117 skt->state |= SOCKET_INUSE;
118 return ret;
121 static inline void cs_socket_put(struct pcmcia_socket *skt)
123 if (skt->state & SOCKET_INUSE) {
124 skt->state &= ~SOCKET_INUSE;
125 module_put(skt->owner);
129 #define CHECK_HANDLE(h) \
130 (((h) == NULL) || ((h)->client_magic != CLIENT_MAGIC))
132 #define CHECK_SOCKET(s) \
133 (((s) >= sockets) || (socket_table[s]->ops == NULL))
135 #define SOCKET(h) (h->Socket)
136 #define CONFIG(h) (&SOCKET(h)->config[(h)->Function])
138 #define CHECK_REGION(r) \
139 (((r) == NULL) || ((r)->region_magic != REGION_MAGIC))
141 #define CHECK_ERASEQ(q) \
142 (((q) == NULL) || ((q)->eraseq_magic != ERASEQ_MAGIC))
144 #define EVENT(h, e, p) \
145 ((h)->event_handler((e), (p), &(h)->event_callback_args))
147 /* In cardbus.c */
148 int cb_alloc(struct pcmcia_socket *s);
149 void cb_free(struct pcmcia_socket *s);
150 int read_cb_mem(struct pcmcia_socket *s, int space, u_int addr, u_int len, void *ptr);
152 /* In cistpl.c */
153 int read_cis_mem(struct pcmcia_socket *s, int attr,
154 u_int addr, u_int len, void *ptr);
155 void write_cis_mem(struct pcmcia_socket *s, int attr,
156 u_int addr, u_int len, void *ptr);
157 void release_cis_mem(struct pcmcia_socket *s);
158 void destroy_cis_cache(struct pcmcia_socket *s);
159 int verify_cis_cache(struct pcmcia_socket *s);
160 void preload_cis_cache(struct pcmcia_socket *s);
161 int get_first_tuple(client_handle_t handle, tuple_t *tuple);
162 int get_next_tuple(client_handle_t handle, tuple_t *tuple);
163 int get_tuple_data(client_handle_t handle, tuple_t *tuple);
164 int parse_tuple(client_handle_t handle, tuple_t *tuple, cisparse_t *parse);
165 int validate_cis(client_handle_t handle, cisinfo_t *info);
166 int replace_cis(client_handle_t handle, cisdump_t *cis);
167 int read_tuple(client_handle_t handle, cisdata_t code, void *parse);
169 /* In bulkmem.c */
170 int get_first_region(client_handle_t handle, region_info_t *rgn);
171 int get_next_region(client_handle_t handle, region_info_t *rgn);
172 int register_mtd(client_handle_t handle, mtd_reg_t *reg);
173 int register_erase_queue(client_handle_t *handle, eraseq_hdr_t *header);
174 int deregister_erase_queue(eraseq_handle_t eraseq);
175 int check_erase_queue(eraseq_handle_t eraseq);
176 int open_memory(client_handle_t *handle, open_mem_t *open);
177 int close_memory(memory_handle_t handle);
178 int read_memory(memory_handle_t handle, mem_op_t *req, caddr_t buf);
179 int write_memory(memory_handle_t handle, mem_op_t *req, caddr_t buf);
180 int copy_memory(memory_handle_t handle, copy_op_t *req);
182 /* In rsrc_mgr */
183 void pcmcia_validate_mem(struct pcmcia_socket *s);
184 struct resource *find_io_region(unsigned long base, int num, unsigned long align,
185 char *name, struct pcmcia_socket *s);
186 int adjust_io_region(struct resource *res, unsigned long r_start,
187 unsigned long r_end, struct pcmcia_socket *s);
188 struct resource *find_mem_region(u_long base, u_long num, u_long align,
189 int low, char *name, struct pcmcia_socket *s);
190 int try_irq(u_int Attributes, int irq, int specific);
191 void undo_irq(u_int Attributes, int irq);
192 int adjust_resource_info(client_handle_t handle, adjust_t *adj);
193 void release_resource_db(void);
195 /* In socket_sysfs.c */
196 extern struct class_interface pccard_sysfs_interface;
198 /* In cs.c */
199 extern struct rw_semaphore pcmcia_socket_list_rwsem;
200 extern struct list_head pcmcia_socket_list;
202 #define cs_socket_name(skt) ((skt)->dev.class_id)
204 #ifdef DEBUG
205 extern int cs_debug_level(int);
207 #define cs_dbg(skt, lvl, fmt, arg...) do { \
208 if (cs_debug_level(lvl)) \
209 printk(KERN_DEBUG "cs: %s: " fmt, \
210 cs_socket_name(skt) , ## arg); \
211 } while (0)
213 #else
214 #define cs_dbg(skt, lvl, fmt, arg...) do { } while (0)
215 #endif
217 #define cs_err(skt, fmt, arg...) \
218 printk(KERN_ERR "cs: %s: " fmt, (skt)->dev.class_id , ## arg)
220 #endif /* _LINUX_CS_INTERNAL_H */