pcmcia: add new CIS access helpers
[safe/jmp/linux-2.6] / include / pcmcia / ds.h
1 /*
2  * ds.h -- 16-bit PCMCIA core support
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  * (C) 2003 - 2008      Dominik Brodowski
14  */
15
16 #ifndef _LINUX_DS_H
17 #define _LINUX_DS_H
18
19 #ifdef __KERNEL__
20 #include <linux/mod_devicetable.h>
21 #endif
22
23 #include <pcmcia/cs_types.h>
24 #include <pcmcia/device_id.h>
25
26 #ifdef __KERNEL__
27 #include <linux/device.h>
28 #include <pcmcia/ss.h>
29
30 /*
31  * PCMCIA device drivers (16-bit cards only; 32-bit cards require CardBus
32  * a.k.a. PCI drivers
33  */
34 struct pcmcia_socket;
35 struct pcmcia_device;
36 struct config_t;
37 struct net_device;
38
39 /* dynamic device IDs for PCMCIA device drivers. See
40  * Documentation/pcmcia/driver.txt for details.
41 */
42 struct pcmcia_dynids {
43         spinlock_t              lock;
44         struct list_head        list;
45 };
46
47 struct pcmcia_driver {
48         int (*probe)            (struct pcmcia_device *dev);
49         void (*remove)          (struct pcmcia_device *dev);
50
51         int (*suspend)          (struct pcmcia_device *dev);
52         int (*resume)           (struct pcmcia_device *dev);
53
54         struct module           *owner;
55         struct pcmcia_device_id *id_table;
56         struct device_driver    drv;
57         struct pcmcia_dynids    dynids;
58 };
59
60 /* driver registration */
61 int pcmcia_register_driver(struct pcmcia_driver *driver);
62 void pcmcia_unregister_driver(struct pcmcia_driver *driver);
63
64 /* Some drivers use dev_node_t to store char or block device information.
65  * Don't use this in new drivers, though.
66  */
67 typedef struct dev_node_t {
68         char                    dev_name[DEV_NAME_LEN];
69         u_short                 major, minor;
70         struct dev_node_t       *next;
71 } dev_node_t;
72
73 struct pcmcia_device {
74         /* the socket and the device_no [for multifunction devices]
75            uniquely define a pcmcia_device */
76         struct pcmcia_socket    *socket;
77
78         char                    *devname;
79
80         u8                      device_no;
81
82         /* the hardware "function" device; certain subdevices can
83          * share one hardware "function" device. */
84         u8                      func;
85         struct config_t*        function_config;
86
87         struct list_head        socket_device_list;
88
89         /* deprecated, will be cleaned up soon */
90         dev_node_t              *dev_node;
91         u_int                   open;
92         io_req_t                io;
93         irq_req_t               irq;
94         config_req_t            conf;
95         window_handle_t         win;
96
97         /* Is the device suspended, or in the process of
98          * being removed? */
99         u16                     suspended:1;
100         u16                     _removed:1;
101
102         /* Flags whether io, irq, win configurations were
103          * requested, and whether the configuration is "locked" */
104         u16                     _irq:1;
105         u16                     _io:1;
106         u16                     _win:4;
107         u16                     _locked:1;
108
109         /* Flag whether a "fuzzy" func_id based match is
110          * allowed. */
111         u16                     allow_func_id_match:1;
112
113         /* information about this device */
114         u16                     has_manf_id:1;
115         u16                     has_card_id:1;
116         u16                     has_func_id:1;
117
118         u16                     reserved:3;
119
120         u8                      func_id;
121         u16                     manf_id;
122         u16                     card_id;
123
124         char *                  prod_id[4];
125
126         u64                     dma_mask;
127         struct device           dev;
128
129 #ifdef CONFIG_PCMCIA_IOCTL
130         /* device driver wanted by cardmgr */
131         struct pcmcia_driver *  cardmgr;
132 #endif
133
134         /* data private to drivers */
135         void                    *priv;
136 };
137
138 #define to_pcmcia_dev(n) container_of(n, struct pcmcia_device, dev)
139 #define to_pcmcia_drv(n) container_of(n, struct pcmcia_driver, drv)
140
141 /* deprecated -- don't use! */
142 #define handle_to_dev(handle) (handle->dev)
143
144
145 /* (deprecated) error reporting by PCMCIA devices. Use dev_printk()
146  * or dev_dbg() directly in the driver, without referring to pcmcia_error_func()
147  * and/or pcmcia_error_ret() for those functions will go away soon.
148  */
149 enum service {
150     AccessConfigurationRegister, AddSocketServices,
151     AdjustResourceInfo, CheckEraseQueue, CloseMemory, CopyMemory,
152     DeregisterClient, DeregisterEraseQueue, GetCardServicesInfo,
153     GetClientInfo, GetConfigurationInfo, GetEventMask,
154     GetFirstClient, GetFirstPartion, GetFirstRegion, GetFirstTuple,
155     GetNextClient, GetNextPartition, GetNextRegion, GetNextTuple,
156     GetStatus, GetTupleData, MapLogSocket, MapLogWindow, MapMemPage,
157     MapPhySocket, MapPhyWindow, ModifyConfiguration, ModifyWindow,
158     OpenMemory, ParseTuple, ReadMemory, RegisterClient,
159     RegisterEraseQueue, RegisterMTD, RegisterTimer,
160     ReleaseConfiguration, ReleaseExclusive, ReleaseIO, ReleaseIRQ,
161     ReleaseSocketMask, ReleaseWindow, ReplaceSocketServices,
162     RequestConfiguration, RequestExclusive, RequestIO, RequestIRQ,
163     RequestSocketMask, RequestWindow, ResetCard, ReturnSSEntry,
164     SetEventMask, SetRegion, ValidateCIS, VendorSpecific,
165     WriteMemory, BindDevice, BindMTD, ReportError,
166     SuspendCard, ResumeCard, EjectCard, InsertCard, ReplaceCIS,
167     GetFirstWindow, GetNextWindow, GetMemPage
168 };
169 const char *pcmcia_error_func(int func);
170 const char *pcmcia_error_ret(int ret);
171
172 #define cs_error(p_dev, func, ret)                      \
173         {                                               \
174                 dev_printk(KERN_NOTICE, &p_dev->dev,    \
175                            "%s : %s\n",                 \
176                            pcmcia_error_func(func),     \
177                            pcmcia_error_ret(ret));      \
178         }
179
180
181 /*
182  * CIS access.
183  *
184  * Please use the following functions to access CIS tuples:
185  * - pcmcia_get_tuple()
186  * - pcmcia_loop_tuple()
187  * - pcmcia_get_mac_from_cis()
188  *
189  * To parse a tuple_t, pcmcia_parse_tuple() exists. Its interface
190  * might change in future.
191  */
192
193 /* get the very first CIS entry of type @code. Note that buf is pointer
194  * to u8 *buf; and that you need to kfree(buf) afterwards. */
195 size_t pcmcia_get_tuple(struct pcmcia_device *p_dev, cisdata_t code,
196                         u8 **buf);
197
198 /* loop over CIS entries */
199 int pcmcia_loop_tuple(struct pcmcia_device *p_dev, cisdata_t code,
200                       int (*loop_tuple) (struct pcmcia_device *p_dev,
201                                          tuple_t *tuple,
202                                          void *priv_data),
203                       void *priv_data);
204
205 /* get the MAC address from CISTPL_FUNCE */
206 int pcmcia_get_mac_from_cis(struct pcmcia_device *p_dev,
207                             struct net_device *dev);
208
209
210 /* parse a tuple_t */
211 int pcmcia_parse_tuple(tuple_t *tuple, cisparse_t *parse);
212
213 /* loop CIS entries for valid configuration */
214 int pcmcia_loop_config(struct pcmcia_device *p_dev,
215                        int      (*conf_check)   (struct pcmcia_device *p_dev,
216                                                  cistpl_cftable_entry_t *cf,
217                                                  cistpl_cftable_entry_t *dflt,
218                                                  unsigned int vcc,
219                                                  void *priv_data),
220                        void *priv_data);
221
222 /* is the device still there? */
223 struct pcmcia_device *pcmcia_dev_present(struct pcmcia_device *p_dev);
224
225 /* low-level interface reset */
226 int pcmcia_reset_card(struct pcmcia_socket *skt);
227
228 /* CIS config */
229 int pcmcia_access_configuration_register(struct pcmcia_device *p_dev,
230                                          conf_reg_t *reg);
231
232 /* deprecated -- do not use in drivers. */
233 int pccard_get_first_tuple(struct pcmcia_socket *s, unsigned int function,
234                         tuple_t *tuple);
235 #define pcmcia_get_first_tuple(p_dev, tuple) \
236         pccard_get_first_tuple(p_dev->socket, p_dev->func, tuple)
237
238 int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int function,
239                         tuple_t *tuple);
240 #define pcmcia_get_next_tuple(p_dev, tuple) \
241         pccard_get_next_tuple(p_dev->socket, p_dev->func, tuple)
242
243 int pccard_get_tuple_data(struct pcmcia_socket *s, tuple_t *tuple);
244 #define pcmcia_get_tuple_data(p_dev, tuple) \
245         pccard_get_tuple_data(p_dev->socket, tuple)
246
247 /* device configuration */
248 int pcmcia_request_io(struct pcmcia_device *p_dev, io_req_t *req);
249 int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req);
250 int pcmcia_request_configuration(struct pcmcia_device *p_dev,
251                                  config_req_t *req);
252
253 int pcmcia_request_window(struct pcmcia_device **p_dev, win_req_t *req,
254                           window_handle_t *wh);
255 int pcmcia_release_window(window_handle_t win);
256
257 int pcmcia_get_mem_page(window_handle_t win, memreq_t *req);
258 int pcmcia_map_mem_page(window_handle_t win, memreq_t *req);
259
260 int pcmcia_modify_configuration(struct pcmcia_device *p_dev, modconf_t *mod);
261 void pcmcia_disable_device(struct pcmcia_device *p_dev);
262
263 #endif /* __KERNEL__ */
264
265
266
267 /* Below, there are only definitions which are used by
268  * - the PCMCIA ioctl
269  * - deprecated PCMCIA userspace tools only
270  *
271  * here be dragons ... here be dragons ... here be dragons ... here be drag
272  */
273
274 #if defined(CONFIG_PCMCIA_IOCTL) || !defined(__KERNEL__)
275
276 #if defined(__arm__) || defined(__mips__) || defined(__avr32__) || \
277         defined(__bfin__)
278 /* This (ioaddr_t) is exposed to userspace & hence cannot be changed. */
279 typedef u_int   ioaddr_t;
280 #else
281 typedef u_short ioaddr_t;
282 #endif
283
284 /* for AdjustResourceInfo */
285 typedef struct adjust_t {
286         u_int                   Action;
287         u_int                   Resource;
288         u_int                   Attributes;
289         union {
290                 struct memory {
291                         u_long          Base;
292                         u_long          Size;
293                 } memory;
294                 struct io {
295                         ioaddr_t        BasePort;
296                         ioaddr_t        NumPorts;
297                         u_int           IOAddrLines;
298                 } io;
299                 struct irq {
300                         u_int           IRQ;
301                 } irq;
302         } resource;
303 } adjust_t;
304
305 /* Action field */
306 #define REMOVE_MANAGED_RESOURCE         1
307 #define ADD_MANAGED_RESOURCE            2
308 #define GET_FIRST_MANAGED_RESOURCE      3
309 #define GET_NEXT_MANAGED_RESOURCE       4
310 /* Resource field */
311 #define RES_MEMORY_RANGE                1
312 #define RES_IO_RANGE                    2
313 #define RES_IRQ                         3
314 /* Attribute field */
315 #define RES_IRQ_TYPE                    0x03
316 #define RES_IRQ_TYPE_EXCLUSIVE          0
317 #define RES_IRQ_TYPE_TIME               1
318 #define RES_IRQ_TYPE_DYNAMIC            2
319 #define RES_IRQ_CSC                     0x04
320 #define RES_SHARED                      0x08
321 #define RES_RESERVED                    0x10
322 #define RES_ALLOCATED                   0x20
323 #define RES_REMOVED                     0x40
324
325
326 typedef struct tuple_parse_t {
327         tuple_t                 tuple;
328         cisdata_t               data[255];
329         cisparse_t              parse;
330 } tuple_parse_t;
331
332 typedef struct win_info_t {
333         window_handle_t         handle;
334         win_req_t               window;
335         memreq_t                map;
336 } win_info_t;
337
338 typedef struct bind_info_t {
339         dev_info_t              dev_info;
340         u_char                  function;
341         struct pcmcia_device    *instance;
342         char                    name[DEV_NAME_LEN];
343         u_short                 major, minor;
344         void                    *next;
345 } bind_info_t;
346
347 typedef struct mtd_info_t {
348         dev_info_t              dev_info;
349         u_int                   Attributes;
350         u_int                   CardOffset;
351 } mtd_info_t;
352
353 typedef struct region_info_t {
354         u_int                   Attributes;
355         u_int                   CardOffset;
356         u_int                   RegionSize;
357         u_int                   AccessSpeed;
358         u_int                   BlockSize;
359         u_int                   PartMultiple;
360         u_char                  JedecMfr, JedecInfo;
361         memory_handle_t         next;
362 } region_info_t;
363
364 #define REGION_TYPE             0x0001
365 #define REGION_TYPE_CM          0x0000
366 #define REGION_TYPE_AM          0x0001
367 #define REGION_PREFETCH         0x0008
368 #define REGION_CACHEABLE        0x0010
369 #define REGION_BAR_MASK         0xe000
370 #define REGION_BAR_SHIFT        13
371
372 /* For ReplaceCIS */
373 typedef struct cisdump_t {
374         u_int                   Length;
375         cisdata_t               Data[CISTPL_MAX_CIS_SIZE];
376 } cisdump_t;
377
378 /* for GetConfigurationInfo */
379 typedef struct config_info_t {
380         u_char                  Function;
381         u_int                   Attributes;
382         u_int                   Vcc, Vpp1, Vpp2;
383         u_int                   IntType;
384         u_int                   ConfigBase;
385         u_char                  Status, Pin, Copy, Option, ExtStatus;
386         u_int                   Present;
387         u_int                   CardValues;
388         u_int                   AssignedIRQ;
389         u_int                   IRQAttributes;
390         ioaddr_t                BasePort1;
391         ioaddr_t                NumPorts1;
392         u_int                   Attributes1;
393         ioaddr_t                BasePort2;
394         ioaddr_t                NumPorts2;
395         u_int                   Attributes2;
396         u_int                   IOAddrLines;
397 } config_info_t;
398
399 /* For ValidateCIS */
400 typedef struct cisinfo_t {
401         u_int                   Chains;
402 } cisinfo_t;
403
404 typedef struct cs_status_t {
405         u_char                  Function;
406         event_t                 CardState;
407         event_t                 SocketState;
408 } cs_status_t;
409
410 typedef union ds_ioctl_arg_t {
411         adjust_t                adjust;
412         config_info_t           config;
413         tuple_t                 tuple;
414         tuple_parse_t           tuple_parse;
415         client_req_t            client_req;
416         cs_status_t             status;
417         conf_reg_t              conf_reg;
418         cisinfo_t               cisinfo;
419         region_info_t           region;
420         bind_info_t             bind_info;
421         mtd_info_t              mtd_info;
422         win_info_t              win_info;
423         cisdump_t               cisdump;
424 } ds_ioctl_arg_t;
425
426 #define DS_ADJUST_RESOURCE_INFO                 _IOWR('d',  2, adjust_t)
427 #define DS_GET_CONFIGURATION_INFO               _IOWR('d',  3, config_info_t)
428 #define DS_GET_FIRST_TUPLE                      _IOWR('d',  4, tuple_t)
429 #define DS_GET_NEXT_TUPLE                       _IOWR('d',  5, tuple_t)
430 #define DS_GET_TUPLE_DATA                       _IOWR('d',  6, tuple_parse_t)
431 #define DS_PARSE_TUPLE                          _IOWR('d',  7, tuple_parse_t)
432 #define DS_RESET_CARD                           _IO  ('d',  8)
433 #define DS_GET_STATUS                           _IOWR('d',  9, cs_status_t)
434 #define DS_ACCESS_CONFIGURATION_REGISTER        _IOWR('d', 10, conf_reg_t)
435 #define DS_VALIDATE_CIS                         _IOR ('d', 11, cisinfo_t)
436 #define DS_SUSPEND_CARD                         _IO  ('d', 12)
437 #define DS_RESUME_CARD                          _IO  ('d', 13)
438 #define DS_EJECT_CARD                           _IO  ('d', 14)
439 #define DS_INSERT_CARD                          _IO  ('d', 15)
440 #define DS_GET_FIRST_REGION                     _IOWR('d', 16, region_info_t)
441 #define DS_GET_NEXT_REGION                      _IOWR('d', 17, region_info_t)
442 #define DS_REPLACE_CIS                          _IOWR('d', 18, cisdump_t)
443 #define DS_GET_FIRST_WINDOW                     _IOR ('d', 19, win_info_t)
444 #define DS_GET_NEXT_WINDOW                      _IOWR('d', 20, win_info_t)
445 #define DS_GET_MEM_PAGE                         _IOWR('d', 21, win_info_t)
446
447 #define DS_BIND_REQUEST                         _IOWR('d', 60, bind_info_t)
448 #define DS_GET_DEVICE_INFO                      _IOWR('d', 61, bind_info_t)
449 #define DS_GET_NEXT_DEVICE                      _IOWR('d', 62, bind_info_t)
450 #define DS_UNBIND_REQUEST                       _IOW ('d', 63, bind_info_t)
451 #define DS_BIND_MTD                             _IOWR('d', 64, mtd_info_t)
452
453
454 /* used in userspace only */
455 #define CS_IN_USE                       0x1e
456
457 #define INFO_MASTER_CLIENT      0x01
458 #define INFO_IO_CLIENT          0x02
459 #define INFO_MTD_CLIENT         0x04
460 #define INFO_MEM_CLIENT         0x08
461 #define MAX_NUM_CLIENTS         3
462
463 #define INFO_CARD_SHARE         0x10
464 #define INFO_CARD_EXCL          0x20
465
466
467 #endif /* !defined(__KERNEL__) || defined(CONFIG_PCMCIA_IOCTL) */
468
469 #endif /* _LINUX_DS_H */