Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
422 giacomo 1
/*
2
 * Linux Plug and Play Support
3
 * Copyright by Adam Belay <ambx1@neo.rr.com>
4
 *
5
 */
6
 
7
#ifndef _LINUX_PNP_H
8
#define _LINUX_PNP_H
9
 
10
#ifdef __KERNEL__
11
 
12
#include <linux/device.h>
13
#include <linux/list.h>
14
#include <linux/errno.h>
15
 
16
#define PNP_MAX_PORT            8
17
#define PNP_MAX_MEM             4
18
#define PNP_MAX_IRQ             2
19
#define PNP_MAX_DMA             2
20
#define PNP_MAX_DEVICES         8
21
#define PNP_ID_LEN              8
22
#define PNP_NAME_LEN            50
23
 
24
struct pnp_protocol;
25
struct pnp_dev;
26
 
27
 
28
/*
29
 * Resource Management
30
 */
31
 
32
/* Use these instead of directly reading pnp_dev to get resource information */
33
#define pnp_port_start(dev,bar)   ((dev)->res.port_resource[(bar)].start)
34
#define pnp_port_end(dev,bar)     ((dev)->res.port_resource[(bar)].end)
35
#define pnp_port_flags(dev,bar)   ((dev)->res.port_resource[(bar)].flags)
36
#define pnp_port_valid(dev,bar)   (pnp_port_flags((dev),(bar)) & IORESOURCE_IO)
37
#define pnp_port_len(dev,bar) \
38
        ((pnp_port_start((dev),(bar)) == 0 &&   \
39
          pnp_port_end((dev),(bar)) ==          \
40
          pnp_port_start((dev),(bar))) ? 0 :    \
41
                                                \
42
         (pnp_port_end((dev),(bar)) -           \
43
          pnp_port_start((dev),(bar)) + 1))
44
 
45
#define pnp_mem_start(dev,bar)   ((dev)->res.mem_resource[(bar)].start)
46
#define pnp_mem_end(dev,bar)     ((dev)->res.mem_resource[(bar)].end)
47
#define pnp_mem_flags(dev,bar)   ((dev)->res.mem_resource[(bar)].flags)
48
#define pnp_mem_valid(dev,bar)   (pnp_mem_flags((dev),(bar)) & IORESOURCE_MEM)
49
#define pnp_mem_len(dev,bar) \
50
        ((pnp_mem_start((dev),(bar)) == 0 &&    \
51
          pnp_mem_end((dev),(bar)) ==           \
52
          pnp_mem_start((dev),(bar))) ? 0 :     \
53
                                                \
54
         (pnp_mem_end((dev),(bar)) -            \
55
          pnp_mem_start((dev),(bar)) + 1))
56
 
57
#define pnp_irq(dev,bar)         ((dev)->res.irq_resource[(bar)].start)
58
#define pnp_irq_flags(dev,bar)   ((dev)->res.irq_resource[(bar)].flags)
59
#define pnp_irq_valid(dev,bar)   (pnp_irq_flags((dev),(bar)) & IORESOURCE_IRQ)
60
 
61
#define pnp_dma(dev,bar)         ((dev)->res.dma_resource[(bar)].start)
62
#define pnp_dma_flags(dev,bar)   ((dev)->res.dma_resource[(bar)].flags)
63
#define pnp_dma_valid(dev,bar)   (pnp_dma_flags((dev),(bar)) & IORESOURCE_DMA)
64
 
65
#define PNP_PORT_FLAG_16BITADDR (1<<0)
66
#define PNP_PORT_FLAG_FIXED     (1<<1)
67
 
68
struct pnp_port {
69
        unsigned short min;             /* min base number */
70
        unsigned short max;             /* max base number */
71
        unsigned char align;            /* align boundary */
72
        unsigned char size;             /* size of range */
73
        unsigned char flags;            /* port flags */
74
        unsigned char pad;              /* pad */
75
        struct pnp_port *next;          /* next port */
76
};
77
 
78
struct pnp_irq {
79
        unsigned short map;             /* bitmaks for IRQ lines */
80
        unsigned char flags;            /* IRQ flags */
81
        unsigned char pad;              /* pad */
82
        struct pnp_irq *next;           /* next IRQ */
83
};
84
 
85
struct pnp_dma {
86
        unsigned char map;              /* bitmask for DMA channels */
87
        unsigned char flags;            /* DMA flags */
88
        struct pnp_dma *next;           /* next port */
89
};
90
 
91
struct pnp_mem {
92
        unsigned int min;               /* min base number */
93
        unsigned int max;               /* max base number */
94
        unsigned int align;             /* align boundary */
95
        unsigned int size;              /* size of range */
96
        unsigned char flags;            /* memory flags */
97
        unsigned char pad;              /* pad */
98
        struct pnp_mem *next;           /* next memory resource */
99
};
100
 
101
#define PNP_RES_PRIORITY_PREFERRED      0
102
#define PNP_RES_PRIORITY_ACCEPTABLE     1
103
#define PNP_RES_PRIORITY_FUNCTIONAL     2
104
#define PNP_RES_PRIORITY_INVALID        65535
105
 
106
struct pnp_option {
107
        unsigned short priority;        /* priority */
108
        struct pnp_port *port;          /* first port */
109
        struct pnp_irq *irq;            /* first IRQ */
110
        struct pnp_dma *dma;            /* first DMA */
111
        struct pnp_mem *mem;            /* first memory resource */
112
        struct pnp_option *next;        /* used to chain dependent resources */
113
};
114
 
115
struct pnp_resource_table {
116
        struct resource port_resource[PNP_MAX_PORT];
117
        struct resource mem_resource[PNP_MAX_MEM];
118
        struct resource dma_resource[PNP_MAX_DMA];
119
        struct resource irq_resource[PNP_MAX_IRQ];
120
};
121
 
122
 
123
/*
124
 * Device Managemnt
125
 */
126
 
127
struct pnp_card {
128
        struct device dev;              /* Driver Model device interface */
129
        unsigned char number;           /* used as an index, must be unique */
130
        struct list_head global_list;   /* node in global list of cards */
131
        struct list_head protocol_list; /* node in protocol's list of cards */
132
        struct list_head devices;       /* devices attached to the card */
133
 
134
        struct pnp_protocol * protocol;
135
        struct pnp_id * id;             /* contains supported EISA IDs*/
136
 
137
        char name[PNP_NAME_LEN];        /* contains a human-readable name */
138
        unsigned char   pnpver;         /* Plug & Play version */
139
        unsigned char   productver;     /* product version */
140
        unsigned int    serial;         /* serial number */
141
        unsigned char   checksum;       /* if zero - checksum passed */
142
        struct proc_dir_entry *procdir; /* directory entry in /proc/bus/isapnp */
143
};
144
 
145
#define global_to_pnp_card(n) list_entry(n, struct pnp_card, global_list)
146
#define protocol_to_pnp_card(n) list_entry(n, struct pnp_card, protocol_list)
147
#define to_pnp_card(n) container_of(n, struct pnp_card, dev)
148
#define pnp_for_each_card(card) \
149
        for((card) = global_to_pnp_card(pnp_cards.next); \
150
        (card) != global_to_pnp_card(&pnp_cards); \
151
        (card) = global_to_pnp_card((card)->global_list.next))
152
 
153
struct pnp_card_link {
154
        struct pnp_card * card;
155
        struct pnp_card_driver * driver;
156
        void * driver_data;
157
};
158
 
159
static inline void *pnp_get_card_drvdata (struct pnp_card_link *pcard)
160
{
161
        return pcard->driver_data;
162
}
163
 
164
static inline void pnp_set_card_drvdata (struct pnp_card_link *pcard, void *data)
165
{
166
        pcard->driver_data = data;
167
}
168
 
169
struct pnp_dev {
170
        struct device dev;              /* Driver Model device interface */
171
        unsigned char number;           /* used as an index, must be unique */
172
        int status;
173
 
174
        struct list_head global_list;   /* node in global list of devices */
175
        struct list_head protocol_list; /* node in list of device's protocol */
176
        struct list_head card_list;     /* node in card's list of devices */
177
        struct list_head rdev_list;     /* node in cards list of requested devices */
178
 
179
        struct pnp_protocol * protocol;
180
        struct pnp_card * card;         /* card the device is attached to, none if NULL */
181
        struct pnp_driver * driver;
182
        struct pnp_card_link * card_link;
183
 
184
        struct pnp_id   * id;   /* supported EISA IDs*/
185
 
186
        int active;
187
        int capabilities;
188
        struct pnp_option * independent;
189
        struct pnp_option * dependent;
190
        struct pnp_resource_table res;
191
 
192
        char name[PNP_NAME_LEN];        /* contains a human-readable name */
193
        unsigned short  regs;           /* ISAPnP: supported registers */
194
        int             flags;          /* used by protocols */
195
        struct proc_dir_entry *procent; /* device entry in /proc/bus/isapnp */
196
};
197
 
198
#define global_to_pnp_dev(n) list_entry(n, struct pnp_dev, global_list)
199
#define card_to_pnp_dev(n) list_entry(n, struct pnp_dev, card_list)
200
#define protocol_to_pnp_dev(n) list_entry(n, struct pnp_dev, protocol_list)
201
#define to_pnp_dev(n) container_of(n, struct pnp_dev, dev)
202
#define pnp_for_each_dev(dev) \
203
        for((dev) = global_to_pnp_dev(pnp_global.next); \
204
        (dev) != global_to_pnp_dev(&pnp_global); \
205
        (dev) = global_to_pnp_dev((dev)->global_list.next))
206
#define card_for_each_dev(card,dev) \
207
        for((dev) = card_to_pnp_dev((card)->devices.next); \
208
        (dev) != card_to_pnp_dev(&(card)->devices); \
209
        (dev) = card_to_pnp_dev((dev)->card_list.next))
210
#define pnp_dev_name(dev) (dev)->name
211
 
212
static inline void *pnp_get_drvdata (struct pnp_dev *pdev)
213
{
214
        return dev_get_drvdata(&pdev->dev);
215
}
216
 
217
static inline void pnp_set_drvdata (struct pnp_dev *pdev, void *data)
218
{
219
        dev_set_drvdata(&pdev->dev, data);
220
}
221
 
222
struct pnp_fixup {
223
        char id[7];
224
        void (*quirk_function)(struct pnp_dev *dev);    /* fixup function */
225
};
226
 
227
/* config parameters */
228
#define PNP_CONFIG_NORMAL       0x0001
229
#define PNP_CONFIG_FORCE        0x0002  /* disables validity checking */
230
 
231
/* capabilities */
232
#define PNP_READ                0x0001
233
#define PNP_WRITE               0x0002
234
#define PNP_DISABLE             0x0004
235
#define PNP_CONFIGURABLE        0x0008
236
#define PNP_REMOVABLE           0x0010
237
 
238
#define pnp_can_read(dev)       (((dev)->protocol) && ((dev)->protocol->get) && \
239
                                 ((dev)->capabilities & PNP_READ))
240
#define pnp_can_write(dev)      (((dev)->protocol) && ((dev)->protocol->set) && \
241
                                 ((dev)->capabilities & PNP_WRITE))
242
#define pnp_can_disable(dev)    (((dev)->protocol) && ((dev)->protocol->disable) && \
243
                                 ((dev)->capabilities & PNP_DISABLE))
244
#define pnp_can_configure(dev)  ((!(dev)->active) && \
245
                                 ((dev)->capabilities & PNP_CONFIGURABLE))
246
 
247
#ifdef CONFIG_ISAPNP
248
extern struct pnp_protocol isapnp_protocol;
249
#define pnp_device_is_isapnp(dev) ((dev)->protocol == (&isapnp_protocol))
250
#else
251
#define pnp_device_is_isapnp(dev) 0
252
#endif
253
 
254
#ifdef CONFIG_PNPBIOS
255
extern struct pnp_protocol pnpbios_protocol;
256
#define pnp_device_is_pnpbios(dev) ((dev)->protocol == (&pnpbios_protocol))
257
#else
258
#define pnp_device_is_pnpbios(dev) 0
259
#endif
260
 
261
 
262
/* status */
263
#define PNP_READY               0x0000
264
#define PNP_ATTACHED            0x0001
265
#define PNP_BUSY                0x0002
266
#define PNP_FAULTY              0x0004
267
 
268
/* isapnp specific macros */
269
 
270
#define isapnp_card_number(dev) ((dev)->card ? (dev)->card->number : -1)
271
#define isapnp_csn_number(dev)  ((dev)->number)
272
 
273
/*
274
 * Driver Management
275
 */
276
 
277
struct pnp_id {
278
        char id[PNP_ID_LEN];
279
        struct pnp_id * next;
280
};
281
 
282
struct pnp_device_id {
283
        char id[PNP_ID_LEN];
284
        unsigned long driver_data;      /* data private to the driver */
285
};
286
 
287
struct pnp_card_device_id {
288
        char id[PNP_ID_LEN];
289
        unsigned long driver_data;      /* data private to the driver */
290
        struct {
291
                char id[PNP_ID_LEN];
292
        } devs[PNP_MAX_DEVICES];        /* logical devices */
293
};
294
 
295
struct pnp_driver {
296
        char * name;
297
        const struct pnp_device_id *id_table;
298
        unsigned int flags;
299
        int  (*probe)  (struct pnp_dev *dev, const struct pnp_device_id *dev_id);
300
        void (*remove) (struct pnp_dev *dev);
301
        struct device_driver driver;
302
};
303
 
304
#define to_pnp_driver(drv) container_of(drv, struct pnp_driver, driver)
305
 
306
struct pnp_card_driver {
307
        struct list_head global_list;
308
        char * name;
309
        const struct pnp_card_device_id *id_table;
310
        unsigned int flags;
311
        int  (*probe)  (struct pnp_card_link *card, const struct pnp_card_device_id *card_id);
312
        void (*remove) (struct pnp_card_link *card);
313
        struct pnp_driver link;
314
};
315
 
316
#define to_pnp_card_driver(drv) container_of(drv, struct pnp_card_driver, link)
317
 
318
/* pnp driver flags */
319
#define PNP_DRIVER_RES_DO_NOT_CHANGE    0x0001  /* do not change the state of the device */
320
#define PNP_DRIVER_RES_DISABLE          0x0003  /* ensure the device is disabled */
321
 
322
 
323
/*
324
 * Protocol Management
325
 */
326
 
327
struct pnp_protocol {
328
        struct list_head        protocol_list;
329
        char                  * name;
330
 
331
        /* resource control functions */
332
        int (*get)(struct pnp_dev *dev, struct pnp_resource_table *res);
333
        int (*set)(struct pnp_dev *dev, struct pnp_resource_table *res);
334
        int (*disable)(struct pnp_dev *dev);
335
 
336
        /* used by pnp layer only (look but don't touch) */
337
        unsigned char           number;         /* protocol number*/
338
        struct device           dev;            /* link to driver model */
339
        struct list_head        cards;
340
        struct list_head        devices;
341
};
342
 
343
#define to_pnp_protocol(n) list_entry(n, struct pnp_protocol, protocol_list)
344
#define protocol_for_each_card(protocol,card) \
345
        for((card) = protocol_to_pnp_card((protocol)->cards.next); \
346
        (card) != protocol_to_pnp_card(&(protocol)->cards); \
347
        (card) = protocol_to_pnp_card((card)->protocol_list.next))
348
#define protocol_for_each_dev(protocol,dev) \
349
        for((dev) = protocol_to_pnp_dev((protocol)->devices.next); \
350
        (dev) != protocol_to_pnp_dev(&(protocol)->devices); \
351
        (dev) = protocol_to_pnp_dev((dev)->protocol_list.next))
352
 
353
 
354
#if defined(CONFIG_PNP)
355
 
356
/* device management */
357
int pnp_register_protocol(struct pnp_protocol *protocol);
358
void pnp_unregister_protocol(struct pnp_protocol *protocol);
359
int pnp_add_device(struct pnp_dev *dev);
360
void pnp_remove_device(struct pnp_dev *dev);
361
int pnp_device_attach(struct pnp_dev *pnp_dev);
362
void pnp_device_detach(struct pnp_dev *pnp_dev);
363
extern struct list_head pnp_global;
364
 
365
/* multidevice card support */
366
int pnp_add_card(struct pnp_card *card);
367
void pnp_remove_card(struct pnp_card *card);
368
int pnp_add_card_device(struct pnp_card *card, struct pnp_dev *dev);
369
void pnp_remove_card_device(struct pnp_dev *dev);
370
int pnp_add_card_id(struct pnp_id *id, struct pnp_card *card);
371
struct pnp_dev * pnp_request_card_device(struct pnp_card_link *clink, const char * id, struct pnp_dev * from);
372
void pnp_release_card_device(struct pnp_dev * dev);
373
int pnp_register_card_driver(struct pnp_card_driver * drv);
374
void pnp_unregister_card_driver(struct pnp_card_driver * drv);
375
extern struct list_head pnp_cards;
376
 
377
/* resource management */
378
struct pnp_option * pnp_register_independent_option(struct pnp_dev *dev);
379
struct pnp_option * pnp_register_dependent_option(struct pnp_dev *dev, int priority);
380
int pnp_register_irq_resource(struct pnp_option *option, struct pnp_irq *data);
381
int pnp_register_dma_resource(struct pnp_option *option, struct pnp_dma *data);
382
int pnp_register_port_resource(struct pnp_option *option, struct pnp_port *data);
383
int pnp_register_mem_resource(struct pnp_option *option, struct pnp_mem *data);
384
void pnp_init_resource_table(struct pnp_resource_table *table);
385
int pnp_assign_resources(struct pnp_dev *dev, int depnum);
386
int pnp_manual_config_dev(struct pnp_dev *dev, struct pnp_resource_table *res, int mode);
387
int pnp_auto_config_dev(struct pnp_dev *dev);
388
int pnp_validate_config(struct pnp_dev *dev);
389
int pnp_activate_dev(struct pnp_dev *dev);
390
int pnp_disable_dev(struct pnp_dev *dev);
391
void pnp_resource_change(struct resource *resource, unsigned long start, unsigned long size);
392
 
393
/* protocol helpers */
394
int pnp_is_active(struct pnp_dev * dev);
395
int compare_pnp_id(struct pnp_id * pos, const char * id);
396
int pnp_add_id(struct pnp_id *id, struct pnp_dev *dev);
397
int pnp_register_driver(struct pnp_driver *drv);
398
void pnp_unregister_driver(struct pnp_driver *drv);
399
 
400
#else
401
 
402
/* device management */
403
static inline int pnp_register_protocol(struct pnp_protocol *protocol) { return -ENODEV; }
404
static inline void pnp_unregister_protocol(struct pnp_protocol *protocol) { }
405
static inline int pnp_init_device(struct pnp_dev *dev) { return -ENODEV; }
406
static inline int pnp_add_device(struct pnp_dev *dev) { return -ENODEV; }
407
static inline void pnp_remove_device(struct pnp_dev *dev) { }
408
static inline int pnp_device_attach(struct pnp_dev *pnp_dev) { return -ENODEV; }
409
static inline void pnp_device_detach(struct pnp_dev *pnp_dev) { ; }
410
 
411
/* multidevice card support */
412
static inline int pnp_add_card(struct pnp_card *card) { return -ENODEV; }
413
static inline void pnp_remove_card(struct pnp_card *card) { ; }
414
static inline int pnp_add_card_device(struct pnp_card *card, struct pnp_dev *dev) { return -ENODEV; }
415
static inline void pnp_remove_card_device(struct pnp_dev *dev) { ; }
416
static inline int pnp_add_card_id(struct pnp_id *id, struct pnp_card *card) { return -ENODEV; }
417
static inline struct pnp_dev * pnp_request_card_device(struct pnp_card_link *clink, const char * id, struct pnp_dev * from) { return NULL; }
418
static inline void pnp_release_card_device(struct pnp_dev * dev) { ; }
419
static inline int pnp_register_card_driver(struct pnp_card_driver * drv) { return -ENODEV; }
420
static inline void pnp_unregister_card_driver(struct pnp_card_driver * drv) { ; }
421
 
422
/* resource management */
423
static inline struct pnp_option * pnp_register_independent_option(struct pnp_dev *dev) { return NULL; }
424
static inline struct pnp_option * pnp_register_dependent_option(struct pnp_dev *dev, int priority) { return NULL; }
425
static inline int pnp_register_irq_resource(struct pnp_option *option, struct pnp_irq *data) { return -ENODEV; }
426
static inline int pnp_register_dma_resource(struct pnp_option *option, struct pnp_dma *data) { return -ENODEV; }
427
static inline int pnp_register_port_resource(struct pnp_option *option, struct pnp_port *data) { return -ENODEV; }
428
static inline int pnp_register_mem_resource(struct pnp_option *option, struct pnp_mem *data) { return -ENODEV; }
429
static inline void pnp_init_resource_table(struct pnp_resource_table *table) { }
430
static inline int pnp_assign_resources(struct pnp_dev *dev, int depnum) { return -ENODEV; }
431
static inline int pnp_manual_config_dev(struct pnp_dev *dev, struct pnp_resource_table *res, int mode) { return -ENODEV; }
432
static inline int pnp_auto_config_dev(struct pnp_dev *dev) { return -ENODEV; }
433
static inline int pnp_validate_config(struct pnp_dev *dev) { return -ENODEV; }
434
static inline int pnp_activate_dev(struct pnp_dev *dev) { return -ENODEV; }
435
static inline int pnp_disable_dev(struct pnp_dev *dev) { return -ENODEV; }
436
static inline void pnp_resource_change(struct resource *resource, unsigned long start, unsigned long size) { }
437
 
438
/* protocol helpers */
439
static inline int pnp_is_active(struct pnp_dev * dev) { return 0; }
440
static inline int compare_pnp_id(struct pnp_id * pos, const char * id) { return -ENODEV; }
441
static inline int pnp_add_id(struct pnp_id *id, struct pnp_dev *dev) { return -ENODEV; }
442
static inline int pnp_register_driver(struct pnp_driver *drv) { return -ENODEV; }
443
static inline void pnp_unregister_driver(struct pnp_driver *drv) { ; }
444
 
445
#endif /* CONFIG_PNP */
446
 
447
 
448
#define pnp_err(format, arg...) printk(KERN_ERR "pnp: " format "\n" , ## arg)
449
#define pnp_info(format, arg...) printk(KERN_INFO "pnp: " format "\n" , ## arg)
450
#define pnp_warn(format, arg...) printk(KERN_WARNING "pnp: " format "\n" , ## arg)
451
 
452
#ifdef DEBUG
453
#define pnp_dbg(format, arg...) printk(KERN_DEBUG "pnp: " format "\n" , ## arg)
454
#else
455
#define pnp_dbg(format, arg...) do {} while (0)
456
#endif
457
 
458
#endif /* __KERNEL__ */
459
 
460
#endif /* _LINUX_PNP_H */