blob: 7f86d09a58308e5251f4443e6f447fe52de7118c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Dominik Brodowskidc953e52008-08-25 23:18:20 +02002 * cs_internal.h -- definitions internal to the PCMCIA core modules
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
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
Dominik Brodowskidc953e52008-08-25 23:18:20 +020013 * (C) 2003 - 2008 Dominik Brodowski
14 *
15 *
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
18 * drivers.
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 */
20
21#ifndef _LINUX_CS_INTERNAL_H
22#define _LINUX_CS_INTERNAL_H
23
Dominik Brodowski360b65b2006-01-10 20:50:39 +010024#include <linux/kref.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
Linus Torvalds1da177e2005-04-16 15:20:36 -070026/* Flags in client state */
Dominik Brodowskie2d40962006-03-02 00:09:29 +010027#define CLIENT_WIN_REQ(i) (0x1<<(i))
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Linus Torvalds1da177e2005-04-16 15:20:36 -070029/* Each card function gets one of these guys */
30typedef struct config_t {
Dominik Brodowski360b65b2006-01-10 20:50:39 +010031 struct kref ref;
Dominik Brodowskidc953e52008-08-25 23:18:20 +020032 unsigned int state;
33 unsigned int Attributes;
34 unsigned int IntType;
35 unsigned int ConfigBase;
36 unsigned char Status, Pin, Copy, Option, ExtStatus;
37 unsigned int CardValues;
38 io_req_t io;
39 struct {
40 u_int Attributes;
41 } irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070042} config_t;
43
Dominik Brodowskidc953e52008-08-25 23:18:20 +020044
Linus Torvalds1da177e2005-04-16 15:20:36 -070045struct cis_cache_entry {
46 struct list_head node;
47 unsigned int addr;
48 unsigned int len;
49 unsigned int attr;
50 unsigned char cache[0];
51};
52
Dominik Brodowskic23889c2008-08-26 00:09:56 +020053struct pccard_resource_ops {
54 int (*validate_mem) (struct pcmcia_socket *s);
55 int (*adjust_io_region) (struct resource *res,
56 unsigned long r_start,
57 unsigned long r_end,
58 struct pcmcia_socket *s);
59 struct resource* (*find_io) (unsigned long base, int num,
60 unsigned long align,
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,
66 unsigned int action,
67 unsigned long r_start,
68 unsigned long r_end);
69 int (*add_mem) (struct pcmcia_socket *s,
70 unsigned int action,
71 unsigned long r_start,
72 unsigned long r_end);
73 int (*init) (struct pcmcia_socket *s);
74 void (*exit) (struct pcmcia_socket *s);
75};
76
Linus Torvalds1da177e2005-04-16 15:20:36 -070077/* Flags in config state */
78#define CONFIG_LOCKED 0x01
79#define CONFIG_IRQ_REQ 0x02
80#define CONFIG_IO_REQ 0x04
81
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))
Linus Torvalds1da177e2005-04-16 15:20:36 -070087#define SOCKET_CARDBUS 0x8000
88#define SOCKET_CARDBUS_CONFIG 0x10000
89
Dominik Brodowskidc953e52008-08-25 23:18:20 +020090
91/*
92 * Stuff internal to module "pcmcia_core":
93 */
94
95/* cistpl.c */
96int verify_cis_cache(struct pcmcia_socket *s);
97
Dominik Brodowskidc953e52008-08-25 23:18:20 +020098/* socket_sysfs.c */
99extern int pccard_sysfs_add_socket(struct device *dev);
100extern void pccard_sysfs_remove_socket(struct device *dev);
101
102/* cardbus.c */
103int cb_alloc(struct pcmcia_socket *s);
104void cb_free(struct pcmcia_socket *s);
105int read_cb_mem(struct pcmcia_socket *s, int space, u_int addr, u_int len,
106 void *ptr);
107
108
109
110/*
111 * Stuff exported by module "pcmcia_core" to module "pcmcia"
112 */
113
114struct pcmcia_callback{
115 struct module *owner;
116 int (*event) (struct pcmcia_socket *s,
117 event_t event, int priority);
118 void (*requery) (struct pcmcia_socket *s, int new_cis);
119 int (*suspend) (struct pcmcia_socket *s);
120 int (*resume) (struct pcmcia_socket *s);
121};
122
123/* cs.c */
124extern struct rw_semaphore pcmcia_socket_list_rwsem;
125extern struct list_head pcmcia_socket_list;
Dominik Brodowskic23889c2008-08-26 00:09:56 +0200126extern struct class pcmcia_socket_class;
127
Dominik Brodowskidc953e52008-08-25 23:18:20 +0200128int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c);
Dominik Brodowskic23889c2008-08-26 00:09:56 +0200129struct pcmcia_socket *pcmcia_get_socket_by_nr(unsigned int nr);
Dominik Brodowskidc953e52008-08-25 23:18:20 +0200130
Dominik Brodowski994917f2008-08-31 15:20:26 +0200131int pcmcia_suspend_card(struct pcmcia_socket *skt);
132int pcmcia_resume_card(struct pcmcia_socket *skt);
133
134int pcmcia_eject_card(struct pcmcia_socket *skt);
135int pcmcia_insert_card(struct pcmcia_socket *skt);
136
137struct pcmcia_socket *pcmcia_get_socket(struct pcmcia_socket *skt);
138void pcmcia_put_socket(struct pcmcia_socket *skt);
139
Dominik Brodowskidc953e52008-08-25 23:18:20 +0200140/* cistpl.c */
141int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr,
142 u_int addr, u_int len, void *ptr);
143void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr,
144 u_int addr, u_int len, void *ptr);
145void release_cis_mem(struct pcmcia_socket *s);
146void destroy_cis_cache(struct pcmcia_socket *s);
147int pccard_read_tuple(struct pcmcia_socket *s, unsigned int function,
148 cisdata_t code, void *parse);
Dominik Brodowski994917f2008-08-31 15:20:26 +0200149int pcmcia_replace_cis(struct pcmcia_socket *s,
150 const u8 *data, const size_t len);
Dominik Brodowski84897fc2009-10-18 23:51:09 +0200151int pccard_validate_cis(struct pcmcia_socket *s, unsigned int *count);
Dominik Brodowskidc953e52008-08-25 23:18:20 +0200152
Dominik Brodowski91284222009-10-18 23:32:33 +0200153/* loop over CIS entries */
154int pccard_loop_tuple(struct pcmcia_socket *s, unsigned int function,
155 cisdata_t code, cisparse_t *parse, void *priv_data,
156 int (*loop_tuple) (tuple_t *tuple,
157 cisparse_t *parse,
158 void *priv_data));
159
Dominik Brodowski18a7a19b2009-10-19 00:07:39 +0200160int pccard_get_first_tuple(struct pcmcia_socket *s, unsigned int function,
161 tuple_t *tuple);
162
163int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int function,
164 tuple_t *tuple);
165
166int pccard_get_tuple_data(struct pcmcia_socket *s, tuple_t *tuple);
167
168
Dominik Brodowskidc953e52008-08-25 23:18:20 +0200169/* rsrc_mgr.c */
170int pcmcia_validate_mem(struct pcmcia_socket *s);
171struct resource *pcmcia_find_io_region(unsigned long base,
172 int num,
173 unsigned long align,
174 struct pcmcia_socket *s);
175int pcmcia_adjust_io_region(struct resource *res,
176 unsigned long r_start,
177 unsigned long r_end,
178 struct pcmcia_socket *s);
179struct resource *pcmcia_find_mem_region(u_long base,
180 u_long num,
181 u_long align,
182 int low,
183 struct pcmcia_socket *s);
184
Dominik Brodowskib60a5ed2008-08-25 23:32:37 +0200185/*
186 * Stuff internal to module "pcmcia".
187 */
188/* ds.c */
189extern struct bus_type pcmcia_bus_type;
190
191/* pcmcia_resource.c */
192extern int pcmcia_release_configuration(struct pcmcia_device *p_dev);
193
194#ifdef CONFIG_PCMCIA_IOCTL
195/* ds.c */
196extern spinlock_t pcmcia_dev_list_lock;
197
198extern struct pcmcia_device *pcmcia_get_dev(struct pcmcia_device *p_dev);
199extern void pcmcia_put_dev(struct pcmcia_device *p_dev);
200
201struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s,
202 unsigned int function);
203
204/* pcmcia_ioctl.c */
205extern void __init pcmcia_setup_ioctl(void);
206extern void __exit pcmcia_cleanup_ioctl(void);
207extern void handle_event(struct pcmcia_socket *s, event_t event);
208extern int handle_request(struct pcmcia_socket *s, event_t event);
209
210#else /* CONFIG_PCMCIA_IOCTL */
211
212static inline void __init pcmcia_setup_ioctl(void) { return; }
213static inline void __exit pcmcia_cleanup_ioctl(void) { return; }
214static inline void handle_event(struct pcmcia_socket *s, event_t event)
215{
216 return;
217}
218static inline int handle_request(struct pcmcia_socket *s, event_t event)
219{
220 return 0;
221}
222
223#endif /* CONFIG_PCMCIA_IOCTL */
224
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225#endif /* _LINUX_CS_INTERNAL_H */