pcmcia: deprecate CS_BAD_ARGS
[safe/jmp/linux-2.6] / include / pcmcia / cs.h
1 /*
2  * cs.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_H
16 #define _LINUX_CS_H
17
18 /* For AccessConfigurationRegister */
19 typedef struct conf_reg_t {
20     u_char      Function;
21     u_int       Action;
22     off_t       Offset;
23     u_int       Value;
24 } conf_reg_t;
25
26 /* Actions */
27 #define CS_READ         1
28 #define CS_WRITE        2
29
30 /* for AdjustResourceInfo */
31 typedef struct adjust_t {
32     u_int       Action;
33     u_int       Resource;
34     u_int       Attributes;
35     union {
36         struct memory {
37             u_long      Base;
38             u_long      Size;
39         } memory;
40         struct io {
41             ioaddr_t    BasePort;
42             ioaddr_t    NumPorts;
43             u_int       IOAddrLines;
44         } io;
45         struct irq {
46             u_int       IRQ;
47         } irq;
48     } resource;
49 } adjust_t;
50
51 /* Action field */
52 #define REMOVE_MANAGED_RESOURCE         1
53 #define ADD_MANAGED_RESOURCE            2
54 #define GET_FIRST_MANAGED_RESOURCE      3
55 #define GET_NEXT_MANAGED_RESOURCE       4
56 /* Resource field */
57 #define RES_MEMORY_RANGE                1
58 #define RES_IO_RANGE                    2
59 #define RES_IRQ                         3
60 /* Attribute field */
61 #define RES_IRQ_TYPE                    0x03
62 #define RES_IRQ_TYPE_EXCLUSIVE          0
63 #define RES_IRQ_TYPE_TIME               1
64 #define RES_IRQ_TYPE_DYNAMIC            2
65 #define RES_IRQ_CSC                     0x04
66 #define RES_SHARED                      0x08
67 #define RES_RESERVED                    0x10
68 #define RES_ALLOCATED                   0x20
69 #define RES_REMOVED                     0x40
70
71 typedef struct event_callback_args_t {
72         struct pcmcia_device    *client_handle;
73         void                    *client_data;
74 } event_callback_args_t;
75
76 /* For CardValues field */
77 #define CV_OPTION_VALUE         0x01
78 #define CV_STATUS_VALUE         0x02
79 #define CV_PIN_REPLACEMENT      0x04
80 #define CV_COPY_VALUE           0x08
81 #define CV_EXT_STATUS           0x10
82
83 /* For GetFirst/NextClient */
84 typedef struct client_req_t {
85     socket_t    Socket;
86     u_int       Attributes;
87 } client_req_t;
88
89 #define CLIENT_THIS_SOCKET      0x01
90
91 /* ModifyConfiguration */
92 typedef struct modconf_t {
93     u_int       Attributes;
94     u_int       Vcc, Vpp1, Vpp2;
95 } modconf_t;
96
97 /* Attributes for ModifyConfiguration */
98 #define CONF_IRQ_CHANGE_VALID   0x0100
99 #define CONF_VCC_CHANGE_VALID   0x0200
100 #define CONF_VPP1_CHANGE_VALID  0x0400
101 #define CONF_VPP2_CHANGE_VALID  0x0800
102 #define CONF_IO_CHANGE_WIDTH    0x1000
103
104 /* For RequestConfiguration */
105 typedef struct config_req_t {
106     u_int       Attributes;
107     u_int       Vpp; /* both Vpp1 and Vpp2 */
108     u_int       IntType;
109     u_int       ConfigBase;
110     u_char      Status, Pin, Copy, ExtStatus;
111     u_char      ConfigIndex;
112     u_int       Present;
113 } config_req_t;
114
115 /* Attributes for RequestConfiguration */
116 #define CONF_ENABLE_IRQ         0x01
117 #define CONF_ENABLE_DMA         0x02
118 #define CONF_ENABLE_SPKR        0x04
119 #define CONF_VALID_CLIENT       0x100
120
121 /* IntType field */
122 #define INT_MEMORY              0x01
123 #define INT_MEMORY_AND_IO       0x02
124 #define INT_CARDBUS             0x04
125 #define INT_ZOOMED_VIDEO        0x08
126
127 /* For RequestIO and ReleaseIO */
128 typedef struct io_req_t {
129     u_int       BasePort1;
130     u_int       NumPorts1;
131     u_int       Attributes1;
132     u_int       BasePort2;
133     u_int       NumPorts2;
134     u_int       Attributes2;
135     u_int       IOAddrLines;
136 } io_req_t;
137
138 /* Attributes for RequestIO and ReleaseIO */
139 #define IO_SHARED               0x01
140 #define IO_FIRST_SHARED         0x02
141 #define IO_FORCE_ALIAS_ACCESS   0x04
142 #define IO_DATA_PATH_WIDTH      0x18
143 #define IO_DATA_PATH_WIDTH_8    0x00
144 #define IO_DATA_PATH_WIDTH_16   0x08
145 #define IO_DATA_PATH_WIDTH_AUTO 0x10
146
147 /* For RequestIRQ and ReleaseIRQ */
148 typedef struct irq_req_t {
149     u_int       Attributes;
150     u_int       AssignedIRQ;
151     u_int       IRQInfo1, IRQInfo2; /* IRQInfo2 is ignored */
152     void        *Handler;
153     void        *Instance;
154 } irq_req_t;
155
156 /* Attributes for RequestIRQ and ReleaseIRQ */
157 #define IRQ_TYPE                        0x03
158 #define IRQ_TYPE_EXCLUSIVE              0x00
159 #define IRQ_TYPE_TIME                   0x01
160 #define IRQ_TYPE_DYNAMIC_SHARING        0x02
161 #define IRQ_FORCED_PULSE                0x04
162 #define IRQ_FIRST_SHARED                0x08
163 #define IRQ_HANDLE_PRESENT              0x10
164 #define IRQ_PULSE_ALLOCATED             0x100
165
166 /* Bits in IRQInfo1 field */
167 #define IRQ_MASK                0x0f
168 #define IRQ_NMI_ID              0x01
169 #define IRQ_IOCK_ID             0x02
170 #define IRQ_BERR_ID             0x04
171 #define IRQ_VEND_ID             0x08
172 #define IRQ_INFO2_VALID         0x10
173 #define IRQ_LEVEL_ID            0x20
174 #define IRQ_PULSE_ID            0x40
175 #define IRQ_SHARE_ID            0x80
176
177 typedef struct eventmask_t {
178     u_int       Attributes;
179     u_int       EventMask;
180 } eventmask_t;
181
182 #define CONF_EVENT_MASK_VALID   0x01
183
184 /* Configuration registers present */
185 #define PRESENT_OPTION          0x001
186 #define PRESENT_STATUS          0x002
187 #define PRESENT_PIN_REPLACE     0x004
188 #define PRESENT_COPY            0x008
189 #define PRESENT_EXT_STATUS      0x010
190 #define PRESENT_IOBASE_0        0x020
191 #define PRESENT_IOBASE_1        0x040
192 #define PRESENT_IOBASE_2        0x080
193 #define PRESENT_IOBASE_3        0x100
194 #define PRESENT_IOSIZE          0x200
195
196 /* For GetMemPage, MapMemPage */
197 typedef struct memreq_t {
198     u_int       CardOffset;
199     page_t      Page;
200 } memreq_t;
201
202 /* For ModifyWindow */
203 typedef struct modwin_t {
204     u_int       Attributes;
205     u_int       AccessSpeed;
206 } modwin_t;
207
208 /* For RequestWindow */
209 typedef struct win_req_t {
210     u_int       Attributes;
211     u_long      Base;
212     u_int       Size;
213     u_int       AccessSpeed;
214 } win_req_t;
215
216 /* Attributes for RequestWindow */
217 #define WIN_ADDR_SPACE          0x0001
218 #define WIN_ADDR_SPACE_MEM      0x0000
219 #define WIN_ADDR_SPACE_IO       0x0001
220 #define WIN_MEMORY_TYPE         0x0002
221 #define WIN_MEMORY_TYPE_CM      0x0000
222 #define WIN_MEMORY_TYPE_AM      0x0002
223 #define WIN_ENABLE              0x0004
224 #define WIN_DATA_WIDTH          0x0018
225 #define WIN_DATA_WIDTH_8        0x0000
226 #define WIN_DATA_WIDTH_16       0x0008
227 #define WIN_DATA_WIDTH_32       0x0010
228 #define WIN_PAGED               0x0020
229 #define WIN_SHARED              0x0040
230 #define WIN_FIRST_SHARED        0x0080
231 #define WIN_USE_WAIT            0x0100
232 #define WIN_STRICT_ALIGN        0x0200
233 #define WIN_MAP_BELOW_1MB       0x0400
234 #define WIN_PREFETCH            0x0800
235 #define WIN_CACHEABLE           0x1000
236 #define WIN_BAR_MASK            0xe000
237 #define WIN_BAR_SHIFT           13
238
239 /* Attributes for RegisterClient -- UNUSED -- */
240 #define INFO_MASTER_CLIENT      0x01
241 #define INFO_IO_CLIENT          0x02
242 #define INFO_MTD_CLIENT         0x04
243 #define INFO_MEM_CLIENT         0x08
244 #define MAX_NUM_CLIENTS         3
245
246 #define INFO_CARD_SHARE         0x10
247 #define INFO_CARD_EXCL          0x20
248
249 typedef struct cs_status_t {
250     u_char      Function;
251     event_t     CardState;
252     event_t     SocketState;
253 } cs_status_t;
254
255 typedef struct error_info_t {
256     int         func;
257     int         retcode;
258 } error_info_t;
259
260 /* Flag to bind to all functions */
261 #define BIND_FN_ALL     0xff
262
263 /* Events */
264 #define CS_EVENT_PRI_LOW                0
265 #define CS_EVENT_PRI_HIGH               1
266
267 #define CS_EVENT_WRITE_PROTECT          0x000001
268 #define CS_EVENT_CARD_LOCK              0x000002
269 #define CS_EVENT_CARD_INSERTION         0x000004
270 #define CS_EVENT_CARD_REMOVAL           0x000008
271 #define CS_EVENT_BATTERY_DEAD           0x000010
272 #define CS_EVENT_BATTERY_LOW            0x000020
273 #define CS_EVENT_READY_CHANGE           0x000040
274 #define CS_EVENT_CARD_DETECT            0x000080
275 #define CS_EVENT_RESET_REQUEST          0x000100
276 #define CS_EVENT_RESET_PHYSICAL         0x000200
277 #define CS_EVENT_CARD_RESET             0x000400
278 #define CS_EVENT_REGISTRATION_COMPLETE  0x000800
279 #define CS_EVENT_PM_SUSPEND             0x002000
280 #define CS_EVENT_PM_RESUME              0x004000
281 #define CS_EVENT_INSERTION_REQUEST      0x008000
282 #define CS_EVENT_EJECTION_REQUEST       0x010000
283 #define CS_EVENT_MTD_REQUEST            0x020000
284 #define CS_EVENT_ERASE_COMPLETE         0x040000
285 #define CS_EVENT_REQUEST_ATTENTION      0x080000
286 #define CS_EVENT_CB_DETECT              0x100000
287 #define CS_EVENT_3VCARD                 0x200000
288 #define CS_EVENT_XVCARD                 0x400000
289
290 /* Return codes */
291 #define CS_SUCCESS              0x00
292 #define CS_BAD_ADAPTER          -ENODEV
293 #define CS_BAD_ATTRIBUTE        -EINVAL
294 #define CS_BAD_BASE             -EINVAL
295 #define CS_BAD_EDC              -ENODEV
296 #define CS_BAD_IRQ              -EINVAL
297 #define CS_BAD_OFFSET           -EINVAL
298 #define CS_BAD_PAGE             -EINVAL
299 #define CS_READ_FAILURE         -EIO
300 #define CS_BAD_SIZE             -EINVAL
301 #define CS_BAD_SOCKET           -EINVAL
302 #define CS_BAD_TYPE             -EINVAL
303 #define CS_BAD_VCC              -EINVAL
304 #define CS_BAD_VPP              -EINVAL
305 #define CS_BAD_WINDOW           -ENODEV
306 #define CS_WRITE_FAILURE        -EIO
307 #define CS_NO_CARD              -ENODEV
308 #define CS_UNSUPPORTED_FUNCTION -ENODEV
309 #define CS_UNSUPPORTED_MODE     -ENODEV
310 #define CS_BAD_SPEED            -ENODEV
311 #define CS_BUSY                 -ENODEV
312 #define CS_GENERAL_FAILURE      -ETIMEDOUT
313 #define CS_WRITE_PROTECTED      -EPERM
314 #define CS_BAD_ARG_LENGTH       -ENODEV
315 #define CS_BAD_ARGS             -EINVAL
316 #define CS_CONFIGURATION_LOCKED -EACCES
317 #define CS_IN_USE               -EBUSY
318 #define CS_NO_MORE_ITEMS        -ENOSPC
319 #define CS_OUT_OF_RESOURCE      -ENOMEM
320 #define CS_BAD_HANDLE           -EINVAL
321
322 #define CS_BAD_TUPLE            0x40
323
324 #ifdef __KERNEL__
325
326 /*
327  *  The main Card Services entry point
328  */
329
330 enum service {
331     AccessConfigurationRegister, AddSocketServices,
332     AdjustResourceInfo, CheckEraseQueue, CloseMemory, CopyMemory,
333     DeregisterClient, DeregisterEraseQueue, GetCardServicesInfo,
334     GetClientInfo, GetConfigurationInfo, GetEventMask,
335     GetFirstClient, GetFirstPartion, GetFirstRegion, GetFirstTuple,
336     GetNextClient, GetNextPartition, GetNextRegion, GetNextTuple,
337     GetStatus, GetTupleData, MapLogSocket, MapLogWindow, MapMemPage,
338     MapPhySocket, MapPhyWindow, ModifyConfiguration, ModifyWindow,
339     OpenMemory, ParseTuple, ReadMemory, RegisterClient,
340     RegisterEraseQueue, RegisterMTD, RegisterTimer,
341     ReleaseConfiguration, ReleaseExclusive, ReleaseIO, ReleaseIRQ,
342     ReleaseSocketMask, ReleaseWindow, ReplaceSocketServices,
343     RequestConfiguration, RequestExclusive, RequestIO, RequestIRQ,
344     RequestSocketMask, RequestWindow, ResetCard, ReturnSSEntry,
345     SetEventMask, SetRegion, ValidateCIS, VendorSpecific,
346     WriteMemory, BindDevice, BindMTD, ReportError,
347     SuspendCard, ResumeCard, EjectCard, InsertCard, ReplaceCIS,
348     GetFirstWindow, GetNextWindow, GetMemPage
349 };
350
351 struct pcmcia_socket;
352
353 int pcmcia_access_configuration_register(struct pcmcia_device *p_dev, conf_reg_t *reg);
354 int pcmcia_get_mem_page(window_handle_t win, memreq_t *req);
355 int pcmcia_map_mem_page(window_handle_t win, memreq_t *req);
356 int pcmcia_modify_configuration(struct pcmcia_device *p_dev, modconf_t *mod);
357 int pcmcia_release_window(window_handle_t win);
358 int pcmcia_request_configuration(struct pcmcia_device *p_dev, config_req_t *req);
359 int pcmcia_request_io(struct pcmcia_device *p_dev, io_req_t *req);
360 int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req);
361 int pcmcia_request_window(struct pcmcia_device **p_dev, win_req_t *req, window_handle_t *wh);
362 int pcmcia_suspend_card(struct pcmcia_socket *skt);
363 int pcmcia_resume_card(struct pcmcia_socket *skt);
364 int pcmcia_eject_card(struct pcmcia_socket *skt);
365 int pcmcia_insert_card(struct pcmcia_socket *skt);
366 int pccard_reset_card(struct pcmcia_socket *skt);
367
368 struct pcmcia_device * pcmcia_dev_present(struct pcmcia_device *p_dev);
369 void pcmcia_disable_device(struct pcmcia_device *p_dev);
370
371 struct pcmcia_socket * pcmcia_get_socket(struct pcmcia_socket *skt);
372 void pcmcia_put_socket(struct pcmcia_socket *skt);
373
374 /* compatibility functions */
375 #define pcmcia_reset_card(p_dev, req) \
376                 pccard_reset_card(p_dev->socket)
377
378 #endif /* __KERNEL__ */
379
380 #endif /* _LINUX_CS_H */