upgrade to linux 2.6.10-1.12_FC2
[linux-2.6.git] / drivers / pcmcia / cs_internal.h
1 /*
2  * cs_internal.h 1.57 2002/10/24 06:11:43
3  *
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/
8  *
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. 
13  *
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.
17  */
18
19 #ifndef _LINUX_CS_INTERNAL_H
20 #define _LINUX_CS_INTERNAL_H
21
22 #include <linux/config.h>
23
24 #define CLIENT_MAGIC    0x51E6
25 typedef struct client_t {
26     u_short             client_magic;
27     struct pcmcia_socket *Socket;
28     u_char              Function;
29     dev_info_t          dev_info;
30     u_int               Attributes;
31     u_int               state;
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;
37 } client_t;
38
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
47
48 #define REGION_MAGIC    0xE3C9
49 typedef struct region_t {
50     u_short             region_magic;
51     u_short             state;
52     dev_info_t          dev_info;
53     client_handle_t     mtd;
54     u_int               MediaID;
55     region_info_t       info;
56 } region_t;
57
58 #define REGION_STALE    0x01
59
60 /* Each card function gets one of these guys */
61 typedef struct config_t {
62     u_int               state;
63     u_int               Attributes;
64     u_int               Vcc, Vpp1, Vpp2;
65     u_int               IntType;
66     u_int               ConfigBase;
67     u_char              Status, Pin, Copy, Option, ExtStatus;
68     u_int               Present;
69     u_int               CardValues;
70     io_req_t            io;
71     struct {
72         u_int           Attributes;
73     } irq;
74 } config_t;
75
76 struct cis_cache_entry {
77         struct list_head        node;
78         unsigned int            addr;
79         unsigned int            len;
80         unsigned int            attr;
81         unsigned char           cache[0];
82 };
83
84 /* Flags in config state */
85 #define CONFIG_LOCKED           0x01
86 #define CONFIG_IRQ_REQ          0x02
87 #define CONFIG_IO_REQ           0x04
88
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
97
98 static inline int cs_socket_get(struct pcmcia_socket *skt)
99 {
100         int ret;
101
102         WARN_ON(skt->state & SOCKET_INUSE);
103
104         ret = try_module_get(skt->owner);
105         if (ret)
106                 skt->state |= SOCKET_INUSE;
107         return ret;
108 }
109
110 static inline void cs_socket_put(struct pcmcia_socket *skt)
111 {
112         if (skt->state & SOCKET_INUSE) {
113                 skt->state &= ~SOCKET_INUSE;
114                 module_put(skt->owner);
115         }
116 }
117
118 #define CHECK_HANDLE(h) \
119     (((h) == NULL) || ((h)->client_magic != CLIENT_MAGIC))
120
121 #define CHECK_SOCKET(s) \
122     (((s) >= sockets) || (socket_table[s]->ops == NULL))
123
124 #define SOCKET(h) (h->Socket)
125 #define CONFIG(h) (&SOCKET(h)->config[(h)->Function])
126
127 #define CHECK_REGION(r) \
128     (((r) == NULL) || ((r)->region_magic != REGION_MAGIC))
129
130 #define CHECK_ERASEQ(q) \
131     (((q) == NULL) || ((q)->eraseq_magic != ERASEQ_MAGIC))
132
133 #define EVENT(h, e, p) \
134     ((h)->event_handler((e), (p), &(h)->event_callback_args))
135
136 /* In cardbus.c */
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);
140
141 /* In cistpl.c */
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);
150
151 /* In rsrc_mgr */
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);
163
164 /* In socket_sysfs.c */
165 extern struct class_interface pccard_sysfs_interface;
166
167 /* In cs.c */
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);
175
176 #define cs_socket_name(skt)     ((skt)->dev.class_id)
177
178 #ifdef DEBUG
179 extern int cs_debug_level(int);
180
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);   \
185 } while (0)
186
187 #else
188 #define cs_dbg(skt, lvl, fmt, arg...) do { } while (0)
189 #endif
190
191 #define cs_err(skt, fmt, arg...) \
192         printk(KERN_ERR "cs: %s: " fmt, (skt)->dev.class_id , ## arg)
193
194 #endif /* _LINUX_CS_INTERNAL_H */