[PATCH] pcmcia: make config_t independent, add reference counting
[safe/jmp/linux-2.6] / drivers / pcmcia / cs_internal.h
1 /*
2  * cs_internal.h
3  *
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.
7  *
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.
11  *
12  * (C) 1999             David A. Hinds
13  */
14
15 #ifndef _LINUX_CS_INTERNAL_H
16 #define _LINUX_CS_INTERNAL_H
17
18 #include <linux/config.h>
19 #include <linux/kref.h>
20
21 /* Flags in client state */
22 #define CLIENT_CONFIG_LOCKED    0x0001
23 #define CLIENT_IRQ_REQ          0x0002
24 #define CLIENT_IO_REQ           0x0004
25 #define CLIENT_UNBOUND          0x0008
26 #define CLIENT_STALE            0x0010
27 #define CLIENT_WIN_REQ(i)       (0x20<<(i))
28 #define CLIENT_CARDBUS          0x8000
29
30 #define REGION_MAGIC    0xE3C9
31 typedef struct region_t {
32     u_short             region_magic;
33     u_short             state;
34     dev_info_t          dev_info;
35     client_handle_t     mtd;
36     u_int               MediaID;
37     region_info_t       info;
38 } region_t;
39
40 #define REGION_STALE    0x01
41
42 /* Each card function gets one of these guys */
43 typedef struct config_t {
44         struct kref     ref;
45     u_int               state;
46     u_int               Attributes;
47     u_int               IntType;
48     u_int               ConfigBase;
49     u_char              Status, Pin, Copy, Option, ExtStatus;
50     u_int               CardValues;
51     io_req_t            io;
52     struct {
53         u_int           Attributes;
54     } irq;
55 } config_t;
56
57 struct cis_cache_entry {
58         struct list_head        node;
59         unsigned int            addr;
60         unsigned int            len;
61         unsigned int            attr;
62         unsigned char           cache[0];
63 };
64
65 /* Flags in config state */
66 #define CONFIG_LOCKED           0x01
67 #define CONFIG_IRQ_REQ          0x02
68 #define CONFIG_IO_REQ           0x04
69
70 /* Flags in socket state */
71 #define SOCKET_PRESENT          0x0008
72 #define SOCKET_INUSE            0x0010
73 #define SOCKET_SUSPEND          0x0080
74 #define SOCKET_WIN_REQ(i)       (0x0100<<(i))
75 #define SOCKET_REGION_INFO      0x4000
76 #define SOCKET_CARDBUS          0x8000
77 #define SOCKET_CARDBUS_CONFIG   0x10000
78
79 static inline int cs_socket_get(struct pcmcia_socket *skt)
80 {
81         int ret;
82
83         WARN_ON(skt->state & SOCKET_INUSE);
84
85         ret = try_module_get(skt->owner);
86         if (ret)
87                 skt->state |= SOCKET_INUSE;
88         return ret;
89 }
90
91 static inline void cs_socket_put(struct pcmcia_socket *skt)
92 {
93         if (skt->state & SOCKET_INUSE) {
94                 skt->state &= ~SOCKET_INUSE;
95                 module_put(skt->owner);
96         }
97 }
98
99 /* In cardbus.c */
100 int cb_alloc(struct pcmcia_socket *s);
101 void cb_free(struct pcmcia_socket *s);
102 int read_cb_mem(struct pcmcia_socket *s, int space, u_int addr, u_int len, void *ptr);
103
104 /* In cistpl.c */
105 int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr,
106                  u_int addr, u_int len, void *ptr);
107 void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr,
108                    u_int addr, u_int len, void *ptr);
109 void release_cis_mem(struct pcmcia_socket *s);
110 void destroy_cis_cache(struct pcmcia_socket *s);
111 int verify_cis_cache(struct pcmcia_socket *s);
112 int pccard_read_tuple(struct pcmcia_socket *s, unsigned int function, cisdata_t code, void *parse);
113
114 /* In rsrc_mgr */
115 int pcmcia_validate_mem(struct pcmcia_socket *s);
116 struct resource *pcmcia_find_io_region(unsigned long base, int num, unsigned long align,
117                    struct pcmcia_socket *s);
118 int pcmcia_adjust_io_region(struct resource *res, unsigned long r_start,
119                      unsigned long r_end, struct pcmcia_socket *s);
120 struct resource *pcmcia_find_mem_region(u_long base, u_long num, u_long align,
121                     int low, struct pcmcia_socket *s);
122 void release_resource_db(struct pcmcia_socket *s);
123
124 /* In socket_sysfs.c */
125 extern struct class_interface pccard_sysfs_interface;
126
127 /* In cs.c */
128 extern struct rw_semaphore pcmcia_socket_list_rwsem;
129 extern struct list_head pcmcia_socket_list;
130 int pcmcia_get_window(struct pcmcia_socket *s, window_handle_t *handle, int idx, win_req_t *req);
131 int pccard_get_configuration_info(struct pcmcia_socket *s, struct pcmcia_device *p_dev, config_info_t *config);
132 int pccard_reset_card(struct pcmcia_socket *skt);
133 int pccard_get_status(struct pcmcia_socket *s, struct pcmcia_device *p_dev, cs_status_t *status);
134
135
136 struct pcmcia_callback{
137         struct module   *owner;
138         int             (*event) (struct pcmcia_socket *s, event_t event, int priority);
139         void            (*requery) (struct pcmcia_socket *s);
140         int             (*suspend) (struct pcmcia_socket *s);
141         int             (*resume) (struct pcmcia_socket *s);
142 };
143
144 int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c);
145
146 #define cs_socket_name(skt)     ((skt)->dev.class_id)
147
148 #ifdef DEBUG
149 extern int cs_debug_level(int);
150
151 #define cs_dbg(skt, lvl, fmt, arg...) do {              \
152         if (cs_debug_level(lvl))                        \
153                 printk(KERN_DEBUG "cs: %s: " fmt,       \
154                        cs_socket_name(skt) , ## arg);   \
155 } while (0)
156
157 #else
158 #define cs_dbg(skt, lvl, fmt, arg...) do { } while (0)
159 #endif
160
161 #define cs_err(skt, fmt, arg...) \
162         printk(KERN_ERR "cs: %s: " fmt, (skt)->dev.class_id , ## arg)
163
164 #endif /* _LINUX_CS_INTERNAL_H */