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