vserver 1.9.5.x5
[linux-2.6.git] / 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 servinfo_t {
72     char        Signature[2];
73     u_int       Count;
74     u_int       Revision;
75     u_int       CSLevel;
76     char        *VendorString;
77 } servinfo_t;
78
79 typedef struct event_callback_args_t {
80     client_handle_t client_handle;
81     void        *info;
82     void        *mtdrequest;
83     void        *buffer;
84     void        *misc;
85     void        *client_data;
86 } event_callback_args_t;
87
88 /* for GetConfigurationInfo */
89 typedef struct config_info_t {
90     u_char      Function;
91     u_int       Attributes;
92     u_int       Vcc, Vpp1, Vpp2;
93     u_int       IntType;
94     u_int       ConfigBase;
95     u_char      Status, Pin, Copy, Option, ExtStatus;
96     u_int       Present;
97     u_int       CardValues;
98     u_int       AssignedIRQ;
99     u_int       IRQAttributes;
100     ioaddr_t    BasePort1;
101     ioaddr_t    NumPorts1;
102     u_int       Attributes1;
103     ioaddr_t    BasePort2;
104     ioaddr_t    NumPorts2;
105     u_int       Attributes2;
106     u_int       IOAddrLines;
107 } config_info_t;
108
109 /* For CardValues field */
110 #define CV_OPTION_VALUE         0x01
111 #define CV_STATUS_VALUE         0x02
112 #define CV_PIN_REPLACEMENT      0x04
113 #define CV_COPY_VALUE           0x08
114 #define CV_EXT_STATUS           0x10
115
116 /* For GetFirst/NextClient */
117 typedef struct client_req_t {
118     socket_t    Socket;
119     u_int       Attributes;
120 } client_req_t;
121
122 #define CLIENT_THIS_SOCKET      0x01
123
124 /* For RegisterClient */
125 typedef struct client_reg_t {
126     dev_info_t  *dev_info;
127     u_int       Attributes;  /* UNUSED */
128     u_int       EventMask;
129     int         (*event_handler)(event_t event, int priority,
130                                  event_callback_args_t *);
131     event_callback_args_t event_callback_args;
132     u_int       Version;
133 } client_reg_t;
134
135 /* ModifyConfiguration */
136 typedef struct modconf_t {
137     u_int       Attributes;
138     u_int       Vcc, Vpp1, Vpp2;
139 } modconf_t;
140
141 /* Attributes for ModifyConfiguration */
142 #define CONF_IRQ_CHANGE_VALID   0x100
143 #define CONF_VCC_CHANGE_VALID   0x200
144 #define CONF_VPP1_CHANGE_VALID  0x400
145 #define CONF_VPP2_CHANGE_VALID  0x800
146
147 /* For RequestConfiguration */
148 typedef struct config_req_t {
149     u_int       Attributes;
150     u_int       Vcc, Vpp1, Vpp2;
151     u_int       IntType;
152     u_int       ConfigBase;
153     u_char      Status, Pin, Copy, ExtStatus;
154     u_char      ConfigIndex;
155     u_int       Present;
156 } config_req_t;
157
158 /* Attributes for RequestConfiguration */
159 #define CONF_ENABLE_IRQ         0x01
160 #define CONF_ENABLE_DMA         0x02
161 #define CONF_ENABLE_SPKR        0x04
162 #define CONF_VALID_CLIENT       0x100
163
164 /* IntType field */
165 #define INT_MEMORY              0x01
166 #define INT_MEMORY_AND_IO       0x02
167 #define INT_CARDBUS             0x04
168 #define INT_ZOOMED_VIDEO        0x08
169
170 /* For RequestIO and ReleaseIO */
171 typedef struct io_req_t {
172     ioaddr_t    BasePort1;
173     ioaddr_t    NumPorts1;
174     u_int       Attributes1;
175     ioaddr_t    BasePort2;
176     ioaddr_t    NumPorts2;
177     u_int       Attributes2;
178     u_int       IOAddrLines;
179 } io_req_t;
180
181 /* Attributes for RequestIO and ReleaseIO */
182 #define IO_SHARED               0x01
183 #define IO_FIRST_SHARED         0x02
184 #define IO_FORCE_ALIAS_ACCESS   0x04
185 #define IO_DATA_PATH_WIDTH      0x18
186 #define IO_DATA_PATH_WIDTH_8    0x00
187 #define IO_DATA_PATH_WIDTH_16   0x08
188 #define IO_DATA_PATH_WIDTH_AUTO 0x10
189
190 /* For RequestIRQ and ReleaseIRQ */
191 typedef struct irq_req_t {
192     u_int       Attributes;
193     u_int       AssignedIRQ;
194     u_int       IRQInfo1, IRQInfo2; /* IRQInfo2 is ignored */
195     void        *Handler;
196     void        *Instance;
197 } irq_req_t;
198
199 /* Attributes for RequestIRQ and ReleaseIRQ */
200 #define IRQ_TYPE                        0x03
201 #define IRQ_TYPE_EXCLUSIVE              0x00
202 #define IRQ_TYPE_TIME                   0x01
203 #define IRQ_TYPE_DYNAMIC_SHARING        0x02
204 #define IRQ_FORCED_PULSE                0x04
205 #define IRQ_FIRST_SHARED                0x08
206 #define IRQ_HANDLE_PRESENT              0x10
207 #define IRQ_PULSE_ALLOCATED             0x100
208
209 /* Bits in IRQInfo1 field */
210 #define IRQ_MASK                0x0f
211 #define IRQ_NMI_ID              0x01
212 #define IRQ_IOCK_ID             0x02
213 #define IRQ_BERR_ID             0x04
214 #define IRQ_VEND_ID             0x08
215 #define IRQ_INFO2_VALID         0x10
216 #define IRQ_LEVEL_ID            0x20
217 #define IRQ_PULSE_ID            0x40
218 #define IRQ_SHARE_ID            0x80
219
220 typedef struct eventmask_t {
221     u_int       Attributes;
222     u_int       EventMask;
223 } eventmask_t;
224
225 #define CONF_EVENT_MASK_VALID   0x01
226
227 /* Configuration registers present */
228 #define PRESENT_OPTION          0x001
229 #define PRESENT_STATUS          0x002
230 #define PRESENT_PIN_REPLACE     0x004
231 #define PRESENT_COPY            0x008
232 #define PRESENT_EXT_STATUS      0x010
233 #define PRESENT_IOBASE_0        0x020
234 #define PRESENT_IOBASE_1        0x040
235 #define PRESENT_IOBASE_2        0x080
236 #define PRESENT_IOBASE_3        0x100
237 #define PRESENT_IOSIZE          0x200
238
239 /* For GetMemPage, MapMemPage */
240 typedef struct memreq_t {
241     u_int       CardOffset;
242     page_t      Page;
243 } memreq_t;
244
245 /* For ModifyWindow */
246 typedef struct modwin_t {
247     u_int       Attributes;
248     u_int       AccessSpeed;
249 } modwin_t;
250
251 /* For RequestWindow */
252 typedef struct win_req_t {
253     u_int       Attributes;
254     u_long      Base;
255     u_int       Size;
256     u_int       AccessSpeed;
257 } win_req_t;
258
259 /* Attributes for RequestWindow */
260 #define WIN_ADDR_SPACE          0x0001
261 #define WIN_ADDR_SPACE_MEM      0x0000
262 #define WIN_ADDR_SPACE_IO       0x0001
263 #define WIN_MEMORY_TYPE         0x0002
264 #define WIN_MEMORY_TYPE_CM      0x0000
265 #define WIN_MEMORY_TYPE_AM      0x0002
266 #define WIN_ENABLE              0x0004
267 #define WIN_DATA_WIDTH          0x0018
268 #define WIN_DATA_WIDTH_8        0x0000
269 #define WIN_DATA_WIDTH_16       0x0008
270 #define WIN_DATA_WIDTH_32       0x0010
271 #define WIN_PAGED               0x0020
272 #define WIN_SHARED              0x0040
273 #define WIN_FIRST_SHARED        0x0080
274 #define WIN_USE_WAIT            0x0100
275 #define WIN_STRICT_ALIGN        0x0200
276 #define WIN_MAP_BELOW_1MB       0x0400
277 #define WIN_PREFETCH            0x0800
278 #define WIN_CACHEABLE           0x1000
279 #define WIN_BAR_MASK            0xe000
280 #define WIN_BAR_SHIFT           13
281
282 /* Attributes for RegisterClient -- UNUSED -- */
283 #define INFO_MASTER_CLIENT      0x01
284 #define INFO_IO_CLIENT          0x02
285 #define INFO_MTD_CLIENT         0x04
286 #define INFO_MEM_CLIENT         0x08
287 #define MAX_NUM_CLIENTS         3
288
289 #define INFO_CARD_SHARE         0x10
290 #define INFO_CARD_EXCL          0x20
291
292 typedef struct cs_status_t {
293     u_char      Function;
294     event_t     CardState;
295     event_t     SocketState;
296 } cs_status_t;
297
298 typedef struct error_info_t {
299     int         func;
300     int         retcode;
301 } error_info_t;
302
303 /* Flag to bind to all functions */
304 #define BIND_FN_ALL     0xff
305
306 /* Events */
307 #define CS_EVENT_PRI_LOW                0
308 #define CS_EVENT_PRI_HIGH               1
309
310 #define CS_EVENT_WRITE_PROTECT          0x000001
311 #define CS_EVENT_CARD_LOCK              0x000002
312 #define CS_EVENT_CARD_INSERTION         0x000004
313 #define CS_EVENT_CARD_REMOVAL           0x000008
314 #define CS_EVENT_BATTERY_DEAD           0x000010
315 #define CS_EVENT_BATTERY_LOW            0x000020
316 #define CS_EVENT_READY_CHANGE           0x000040
317 #define CS_EVENT_CARD_DETECT            0x000080
318 #define CS_EVENT_RESET_REQUEST          0x000100
319 #define CS_EVENT_RESET_PHYSICAL         0x000200
320 #define CS_EVENT_CARD_RESET             0x000400
321 #define CS_EVENT_REGISTRATION_COMPLETE  0x000800
322 #define CS_EVENT_PM_SUSPEND             0x002000
323 #define CS_EVENT_PM_RESUME              0x004000
324 #define CS_EVENT_INSERTION_REQUEST      0x008000
325 #define CS_EVENT_EJECTION_REQUEST       0x010000
326 #define CS_EVENT_MTD_REQUEST            0x020000
327 #define CS_EVENT_ERASE_COMPLETE         0x040000
328 #define CS_EVENT_REQUEST_ATTENTION      0x080000
329 #define CS_EVENT_CB_DETECT              0x100000
330 #define CS_EVENT_3VCARD                 0x200000
331 #define CS_EVENT_XVCARD                 0x400000
332
333 /* Return codes */
334 #define CS_SUCCESS              0x00
335 #define CS_BAD_ADAPTER          0x01
336 #define CS_BAD_ATTRIBUTE        0x02
337 #define CS_BAD_BASE             0x03
338 #define CS_BAD_EDC              0x04
339 #define CS_BAD_IRQ              0x06
340 #define CS_BAD_OFFSET           0x07
341 #define CS_BAD_PAGE             0x08
342 #define CS_READ_FAILURE         0x09
343 #define CS_BAD_SIZE             0x0a
344 #define CS_BAD_SOCKET           0x0b
345 #define CS_BAD_TYPE             0x0d
346 #define CS_BAD_VCC              0x0e
347 #define CS_BAD_VPP              0x0f
348 #define CS_BAD_WINDOW           0x11
349 #define CS_WRITE_FAILURE        0x12
350 #define CS_NO_CARD              0x14
351 #define CS_UNSUPPORTED_FUNCTION 0x15
352 #define CS_UNSUPPORTED_MODE     0x16
353 #define CS_BAD_SPEED            0x17
354 #define CS_BUSY                 0x18
355 #define CS_GENERAL_FAILURE      0x19
356 #define CS_WRITE_PROTECTED      0x1a
357 #define CS_BAD_ARG_LENGTH       0x1b
358 #define CS_BAD_ARGS             0x1c
359 #define CS_CONFIGURATION_LOCKED 0x1d
360 #define CS_IN_USE               0x1e
361 #define CS_NO_MORE_ITEMS        0x1f
362 #define CS_OUT_OF_RESOURCE      0x20
363 #define CS_BAD_HANDLE           0x21
364
365 #define CS_BAD_TUPLE            0x40
366
367 #ifdef __KERNEL__
368
369 /*
370  *  The main Card Services entry point
371  */
372
373 enum service {
374     AccessConfigurationRegister, AddSocketServices,
375     AdjustResourceInfo, CheckEraseQueue, CloseMemory, CopyMemory,
376     DeregisterClient, DeregisterEraseQueue, GetCardServicesInfo,
377     GetClientInfo, GetConfigurationInfo, GetEventMask,
378     GetFirstClient, GetFirstPartion, GetFirstRegion, GetFirstTuple,
379     GetNextClient, GetNextPartition, GetNextRegion, GetNextTuple,
380     GetStatus, GetTupleData, MapLogSocket, MapLogWindow, MapMemPage,
381     MapPhySocket, MapPhyWindow, ModifyConfiguration, ModifyWindow,
382     OpenMemory, ParseTuple, ReadMemory, RegisterClient,
383     RegisterEraseQueue, RegisterMTD, RegisterTimer,
384     ReleaseConfiguration, ReleaseExclusive, ReleaseIO, ReleaseIRQ,
385     ReleaseSocketMask, ReleaseWindow, ReplaceSocketServices,
386     RequestConfiguration, RequestExclusive, RequestIO, RequestIRQ,
387     RequestSocketMask, RequestWindow, ResetCard, ReturnSSEntry,
388     SetEventMask, SetRegion, ValidateCIS, VendorSpecific,
389     WriteMemory, BindDevice, BindMTD, ReportError,
390     SuspendCard, ResumeCard, EjectCard, InsertCard, ReplaceCIS,
391     GetFirstWindow, GetNextWindow, GetMemPage
392 };
393
394 struct pcmcia_socket;
395
396 int pcmcia_access_configuration_register(client_handle_t handle, conf_reg_t *reg);
397 int pcmcia_deregister_client(client_handle_t handle);
398 int pcmcia_get_configuration_info(client_handle_t handle, config_info_t *config);
399 int pcmcia_get_card_services_info(servinfo_t *info);
400 int pcmcia_get_first_window(window_handle_t *win, win_req_t *req);
401 int pcmcia_get_next_window(window_handle_t *win, win_req_t *req);
402 int pcmcia_get_status(client_handle_t handle, cs_status_t *status);
403 int pcmcia_get_mem_page(window_handle_t win, memreq_t *req);
404 int pcmcia_map_mem_page(window_handle_t win, memreq_t *req);
405 int pcmcia_modify_configuration(client_handle_t handle, modconf_t *mod);
406 int pcmcia_register_client(client_handle_t *handle, client_reg_t *req);
407 int pcmcia_release_configuration(client_handle_t handle);
408 int pcmcia_release_io(client_handle_t handle, io_req_t *req);
409 int pcmcia_release_irq(client_handle_t handle, irq_req_t *req);
410 int pcmcia_release_window(window_handle_t win);
411 int pcmcia_request_configuration(client_handle_t handle, config_req_t *req);
412 int pcmcia_request_io(client_handle_t handle, io_req_t *req);
413 int pcmcia_request_irq(client_handle_t handle, irq_req_t *req);
414 int pcmcia_request_window(client_handle_t *handle, win_req_t *req, window_handle_t *wh);
415 int pcmcia_reset_card(client_handle_t handle, client_req_t *req);
416 int pcmcia_suspend_card(struct pcmcia_socket *skt);
417 int pcmcia_resume_card(struct pcmcia_socket *skt);
418 int pcmcia_eject_card(struct pcmcia_socket *skt);
419 int pcmcia_insert_card(struct pcmcia_socket *skt);
420 int pcmcia_report_error(client_handle_t handle, error_info_t *err);
421
422 struct pcmcia_socket * pcmcia_get_socket(struct pcmcia_socket *skt);
423 void pcmcia_put_socket(struct pcmcia_socket *skt);
424
425 #endif /* __KERNEL__ */
426
427 #endif /* _LINUX_CS_H */