This source file includes following definitions.
- pnp_get_resource
- pnp_resource_valid
- pnp_resource_enabled
- pnp_resource_len
- pnp_port_start
- pnp_port_end
- pnp_port_flags
- pnp_port_valid
- pnp_port_len
- pnp_mem_start
- pnp_mem_end
- pnp_mem_flags
- pnp_mem_valid
- pnp_mem_len
- pnp_irq
- pnp_irq_flags
- pnp_irq_valid
- pnp_dma
- pnp_dma_flags
- pnp_dma_valid
- pnp_get_card_drvdata
- pnp_set_card_drvdata
- pnp_get_drvdata
- pnp_set_drvdata
- pnp_acpi_device
- pnp_device_attach
- pnp_device_detach
- pnp_request_card_device
- pnp_release_card_device
- pnp_register_card_driver
- pnp_unregister_card_driver
- pnp_possible_config
- pnp_auto_config_dev
- pnp_start_dev
- pnp_stop_dev
- pnp_activate_dev
- pnp_disable_dev
- pnp_range_reserved
- pnp_is_active
- compare_pnp_id
- pnp_register_driver
- pnp_unregister_driver
1
2
3
4
5
6
7
8
9 #ifndef _LINUX_PNP_H
10 #define _LINUX_PNP_H
11
12 #include <linux/device.h>
13 #include <linux/list.h>
14 #include <linux/errno.h>
15 #include <linux/mod_devicetable.h>
16 #include <linux/console.h>
17
18 #define PNP_NAME_LEN 50
19
20 struct pnp_protocol;
21 struct pnp_dev;
22
23
24
25
26 #ifdef CONFIG_PNP
27 struct resource *pnp_get_resource(struct pnp_dev *dev, unsigned long type,
28 unsigned int num);
29 #else
30 static inline struct resource *pnp_get_resource(struct pnp_dev *dev,
31 unsigned long type, unsigned int num)
32 {
33 return NULL;
34 }
35 #endif
36
37 static inline int pnp_resource_valid(struct resource *res)
38 {
39 if (res)
40 return 1;
41 return 0;
42 }
43
44 static inline int pnp_resource_enabled(struct resource *res)
45 {
46 if (res && !(res->flags & IORESOURCE_DISABLED))
47 return 1;
48 return 0;
49 }
50
51 static inline resource_size_t pnp_resource_len(struct resource *res)
52 {
53 if (res->start == 0 && res->end == 0)
54 return 0;
55 return resource_size(res);
56 }
57
58
59 static inline resource_size_t pnp_port_start(struct pnp_dev *dev,
60 unsigned int bar)
61 {
62 struct resource *res = pnp_get_resource(dev, IORESOURCE_IO, bar);
63
64 if (pnp_resource_valid(res))
65 return res->start;
66 return 0;
67 }
68
69 static inline resource_size_t pnp_port_end(struct pnp_dev *dev,
70 unsigned int bar)
71 {
72 struct resource *res = pnp_get_resource(dev, IORESOURCE_IO, bar);
73
74 if (pnp_resource_valid(res))
75 return res->end;
76 return 0;
77 }
78
79 static inline unsigned long pnp_port_flags(struct pnp_dev *dev,
80 unsigned int bar)
81 {
82 struct resource *res = pnp_get_resource(dev, IORESOURCE_IO, bar);
83
84 if (pnp_resource_valid(res))
85 return res->flags;
86 return IORESOURCE_IO | IORESOURCE_AUTO;
87 }
88
89 static inline int pnp_port_valid(struct pnp_dev *dev, unsigned int bar)
90 {
91 return pnp_resource_valid(pnp_get_resource(dev, IORESOURCE_IO, bar));
92 }
93
94 static inline resource_size_t pnp_port_len(struct pnp_dev *dev,
95 unsigned int bar)
96 {
97 struct resource *res = pnp_get_resource(dev, IORESOURCE_IO, bar);
98
99 if (pnp_resource_valid(res))
100 return pnp_resource_len(res);
101 return 0;
102 }
103
104
105 static inline resource_size_t pnp_mem_start(struct pnp_dev *dev,
106 unsigned int bar)
107 {
108 struct resource *res = pnp_get_resource(dev, IORESOURCE_MEM, bar);
109
110 if (pnp_resource_valid(res))
111 return res->start;
112 return 0;
113 }
114
115 static inline resource_size_t pnp_mem_end(struct pnp_dev *dev,
116 unsigned int bar)
117 {
118 struct resource *res = pnp_get_resource(dev, IORESOURCE_MEM, bar);
119
120 if (pnp_resource_valid(res))
121 return res->end;
122 return 0;
123 }
124
125 static inline unsigned long pnp_mem_flags(struct pnp_dev *dev, unsigned int bar)
126 {
127 struct resource *res = pnp_get_resource(dev, IORESOURCE_MEM, bar);
128
129 if (pnp_resource_valid(res))
130 return res->flags;
131 return IORESOURCE_MEM | IORESOURCE_AUTO;
132 }
133
134 static inline int pnp_mem_valid(struct pnp_dev *dev, unsigned int bar)
135 {
136 return pnp_resource_valid(pnp_get_resource(dev, IORESOURCE_MEM, bar));
137 }
138
139 static inline resource_size_t pnp_mem_len(struct pnp_dev *dev,
140 unsigned int bar)
141 {
142 struct resource *res = pnp_get_resource(dev, IORESOURCE_MEM, bar);
143
144 if (pnp_resource_valid(res))
145 return pnp_resource_len(res);
146 return 0;
147 }
148
149
150 static inline resource_size_t pnp_irq(struct pnp_dev *dev, unsigned int bar)
151 {
152 struct resource *res = pnp_get_resource(dev, IORESOURCE_IRQ, bar);
153
154 if (pnp_resource_valid(res))
155 return res->start;
156 return -1;
157 }
158
159 static inline unsigned long pnp_irq_flags(struct pnp_dev *dev, unsigned int bar)
160 {
161 struct resource *res = pnp_get_resource(dev, IORESOURCE_IRQ, bar);
162
163 if (pnp_resource_valid(res))
164 return res->flags;
165 return IORESOURCE_IRQ | IORESOURCE_AUTO;
166 }
167
168 static inline int pnp_irq_valid(struct pnp_dev *dev, unsigned int bar)
169 {
170 return pnp_resource_valid(pnp_get_resource(dev, IORESOURCE_IRQ, bar));
171 }
172
173
174 static inline resource_size_t pnp_dma(struct pnp_dev *dev, unsigned int bar)
175 {
176 struct resource *res = pnp_get_resource(dev, IORESOURCE_DMA, bar);
177
178 if (pnp_resource_valid(res))
179 return res->start;
180 return -1;
181 }
182
183 static inline unsigned long pnp_dma_flags(struct pnp_dev *dev, unsigned int bar)
184 {
185 struct resource *res = pnp_get_resource(dev, IORESOURCE_DMA, bar);
186
187 if (pnp_resource_valid(res))
188 return res->flags;
189 return IORESOURCE_DMA | IORESOURCE_AUTO;
190 }
191
192 static inline int pnp_dma_valid(struct pnp_dev *dev, unsigned int bar)
193 {
194 return pnp_resource_valid(pnp_get_resource(dev, IORESOURCE_DMA, bar));
195 }
196
197
198
199
200
201
202 struct pnp_card {
203 struct device dev;
204 unsigned char number;
205 struct list_head global_list;
206 struct list_head protocol_list;
207 struct list_head devices;
208
209 struct pnp_protocol *protocol;
210 struct pnp_id *id;
211
212 char name[PNP_NAME_LEN];
213 unsigned char pnpver;
214 unsigned char productver;
215 unsigned int serial;
216 unsigned char checksum;
217 struct proc_dir_entry *procdir;
218 };
219
220 #define global_to_pnp_card(n) list_entry(n, struct pnp_card, global_list)
221 #define protocol_to_pnp_card(n) list_entry(n, struct pnp_card, protocol_list)
222 #define to_pnp_card(n) container_of(n, struct pnp_card, dev)
223 #define pnp_for_each_card(card) \
224 list_for_each_entry(card, &pnp_cards, global_list)
225
226 struct pnp_card_link {
227 struct pnp_card *card;
228 struct pnp_card_driver *driver;
229 void *driver_data;
230 pm_message_t pm_state;
231 };
232
233 static inline void *pnp_get_card_drvdata(struct pnp_card_link *pcard)
234 {
235 return pcard->driver_data;
236 }
237
238 static inline void pnp_set_card_drvdata(struct pnp_card_link *pcard, void *data)
239 {
240 pcard->driver_data = data;
241 }
242
243 struct pnp_dev {
244 struct device dev;
245 u64 dma_mask;
246 unsigned int number;
247 int status;
248
249 struct list_head global_list;
250 struct list_head protocol_list;
251 struct list_head card_list;
252 struct list_head rdev_list;
253
254 struct pnp_protocol *protocol;
255 struct pnp_card *card;
256 struct pnp_driver *driver;
257 struct pnp_card_link *card_link;
258
259 struct pnp_id *id;
260
261 int active;
262 int capabilities;
263 unsigned int num_dependent_sets;
264 struct list_head resources;
265 struct list_head options;
266
267 char name[PNP_NAME_LEN];
268 int flags;
269 struct proc_dir_entry *procent;
270 void *data;
271 };
272
273 #define global_to_pnp_dev(n) list_entry(n, struct pnp_dev, global_list)
274 #define card_to_pnp_dev(n) list_entry(n, struct pnp_dev, card_list)
275 #define protocol_to_pnp_dev(n) list_entry(n, struct pnp_dev, protocol_list)
276 #define to_pnp_dev(n) container_of(n, struct pnp_dev, dev)
277 #define pnp_for_each_dev(dev) list_for_each_entry(dev, &pnp_global, global_list)
278 #define card_for_each_dev(card, dev) \
279 list_for_each_entry(dev, &(card)->devices, card_list)
280 #define pnp_dev_name(dev) (dev)->name
281
282 static inline void *pnp_get_drvdata(struct pnp_dev *pdev)
283 {
284 return dev_get_drvdata(&pdev->dev);
285 }
286
287 static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
288 {
289 dev_set_drvdata(&pdev->dev, data);
290 }
291
292 struct pnp_fixup {
293 char id[7];
294 void (*quirk_function) (struct pnp_dev * dev);
295 };
296
297
298 #define PNP_CONFIG_NORMAL 0x0001
299 #define PNP_CONFIG_FORCE 0x0002
300
301
302 #define PNP_READ 0x0001
303 #define PNP_WRITE 0x0002
304 #define PNP_DISABLE 0x0004
305 #define PNP_CONFIGURABLE 0x0008
306 #define PNP_REMOVABLE 0x0010
307 #define PNP_CONSOLE 0x0020
308
309 #define pnp_can_read(dev) (((dev)->protocol->get) && \
310 ((dev)->capabilities & PNP_READ))
311 #define pnp_can_write(dev) (((dev)->protocol->set) && \
312 ((dev)->capabilities & PNP_WRITE))
313 #define pnp_can_disable(dev) (((dev)->protocol->disable) && \
314 ((dev)->capabilities & PNP_DISABLE) && \
315 (!((dev)->capabilities & PNP_CONSOLE) || \
316 console_suspend_enabled))
317 #define pnp_can_configure(dev) ((!(dev)->active) && \
318 ((dev)->capabilities & PNP_CONFIGURABLE))
319 #define pnp_can_suspend(dev) (((dev)->protocol->suspend) && \
320 (!((dev)->capabilities & PNP_CONSOLE) || \
321 console_suspend_enabled))
322
323
324 #ifdef CONFIG_ISAPNP
325 extern struct pnp_protocol isapnp_protocol;
326 #define pnp_device_is_isapnp(dev) ((dev)->protocol == (&isapnp_protocol))
327 #else
328 #define pnp_device_is_isapnp(dev) 0
329 #endif
330 extern struct mutex pnp_res_mutex;
331
332 #ifdef CONFIG_PNPBIOS
333 extern struct pnp_protocol pnpbios_protocol;
334 extern bool arch_pnpbios_disabled(void);
335 #define pnp_device_is_pnpbios(dev) ((dev)->protocol == (&pnpbios_protocol))
336 #else
337 #define pnp_device_is_pnpbios(dev) 0
338 #define arch_pnpbios_disabled() false
339 #endif
340
341 #ifdef CONFIG_PNPACPI
342 extern struct pnp_protocol pnpacpi_protocol;
343
344 static inline struct acpi_device *pnp_acpi_device(struct pnp_dev *dev)
345 {
346 if (dev->protocol == &pnpacpi_protocol)
347 return dev->data;
348 return NULL;
349 }
350 #else
351 #define pnp_acpi_device(dev) 0
352 #endif
353
354
355 #define PNP_READY 0x0000
356 #define PNP_ATTACHED 0x0001
357 #define PNP_BUSY 0x0002
358 #define PNP_FAULTY 0x0004
359
360
361
362 #define isapnp_card_number(dev) ((dev)->card ? (dev)->card->number : -1)
363 #define isapnp_csn_number(dev) ((dev)->number)
364
365
366
367
368
369 struct pnp_id {
370 char id[PNP_ID_LEN];
371 struct pnp_id *next;
372 };
373
374 struct pnp_driver {
375 char *name;
376 const struct pnp_device_id *id_table;
377 unsigned int flags;
378 int (*probe) (struct pnp_dev *dev, const struct pnp_device_id *dev_id);
379 void (*remove) (struct pnp_dev *dev);
380 void (*shutdown) (struct pnp_dev *dev);
381 int (*suspend) (struct pnp_dev *dev, pm_message_t state);
382 int (*resume) (struct pnp_dev *dev);
383 struct device_driver driver;
384 };
385
386 #define to_pnp_driver(drv) container_of(drv, struct pnp_driver, driver)
387
388 struct pnp_card_driver {
389 struct list_head global_list;
390 char *name;
391 const struct pnp_card_device_id *id_table;
392 unsigned int flags;
393 int (*probe) (struct pnp_card_link *card,
394 const struct pnp_card_device_id *card_id);
395 void (*remove) (struct pnp_card_link *card);
396 int (*suspend) (struct pnp_card_link *card, pm_message_t state);
397 int (*resume) (struct pnp_card_link *card);
398 struct pnp_driver link;
399 };
400
401 #define to_pnp_card_driver(drv) container_of(drv, struct pnp_card_driver, link)
402
403
404 #define PNP_DRIVER_RES_DO_NOT_CHANGE 0x0001
405 #define PNP_DRIVER_RES_DISABLE 0x0003
406
407
408
409
410
411 struct pnp_protocol {
412 struct list_head protocol_list;
413 char *name;
414
415
416 int (*get) (struct pnp_dev *dev);
417 int (*set) (struct pnp_dev *dev);
418 int (*disable) (struct pnp_dev *dev);
419
420
421 bool (*can_wakeup) (struct pnp_dev *dev);
422 int (*suspend) (struct pnp_dev * dev, pm_message_t state);
423 int (*resume) (struct pnp_dev * dev);
424
425
426 unsigned char number;
427 struct device dev;
428 struct list_head cards;
429 struct list_head devices;
430 };
431
432 #define to_pnp_protocol(n) list_entry(n, struct pnp_protocol, protocol_list)
433 #define protocol_for_each_card(protocol, card) \
434 list_for_each_entry(card, &(protocol)->cards, protocol_list)
435 #define protocol_for_each_dev(protocol, dev) \
436 list_for_each_entry(dev, &(protocol)->devices, protocol_list)
437
438 extern struct bus_type pnp_bus_type;
439
440 #if defined(CONFIG_PNP)
441
442
443 int pnp_device_attach(struct pnp_dev *pnp_dev);
444 void pnp_device_detach(struct pnp_dev *pnp_dev);
445 extern struct list_head pnp_global;
446 extern int pnp_platform_devices;
447
448
449 struct pnp_dev *pnp_request_card_device(struct pnp_card_link *clink,
450 const char *id, struct pnp_dev *from);
451 void pnp_release_card_device(struct pnp_dev *dev);
452 int pnp_register_card_driver(struct pnp_card_driver *drv);
453 void pnp_unregister_card_driver(struct pnp_card_driver *drv);
454 extern struct list_head pnp_cards;
455
456
457 int pnp_possible_config(struct pnp_dev *dev, int type, resource_size_t base,
458 resource_size_t size);
459 int pnp_auto_config_dev(struct pnp_dev *dev);
460 int pnp_start_dev(struct pnp_dev *dev);
461 int pnp_stop_dev(struct pnp_dev *dev);
462 int pnp_activate_dev(struct pnp_dev *dev);
463 int pnp_disable_dev(struct pnp_dev *dev);
464 int pnp_range_reserved(resource_size_t start, resource_size_t end);
465
466
467 int pnp_is_active(struct pnp_dev *dev);
468 int compare_pnp_id(struct pnp_id *pos, const char *id);
469 int pnp_register_driver(struct pnp_driver *drv);
470 void pnp_unregister_driver(struct pnp_driver *drv);
471
472 #else
473
474
475 static inline int pnp_device_attach(struct pnp_dev *pnp_dev) { return -ENODEV; }
476 static inline void pnp_device_detach(struct pnp_dev *pnp_dev) { }
477
478 #define pnp_platform_devices 0
479
480
481 static inline struct pnp_dev *pnp_request_card_device(struct pnp_card_link *clink, const char *id, struct pnp_dev *from) { return NULL; }
482 static inline void pnp_release_card_device(struct pnp_dev *dev) { }
483 static inline int pnp_register_card_driver(struct pnp_card_driver *drv) { return -ENODEV; }
484 static inline void pnp_unregister_card_driver(struct pnp_card_driver *drv) { }
485
486
487 static inline int pnp_possible_config(struct pnp_dev *dev, int type,
488 resource_size_t base,
489 resource_size_t size) { return 0; }
490 static inline int pnp_auto_config_dev(struct pnp_dev *dev) { return -ENODEV; }
491 static inline int pnp_start_dev(struct pnp_dev *dev) { return -ENODEV; }
492 static inline int pnp_stop_dev(struct pnp_dev *dev) { return -ENODEV; }
493 static inline int pnp_activate_dev(struct pnp_dev *dev) { return -ENODEV; }
494 static inline int pnp_disable_dev(struct pnp_dev *dev) { return -ENODEV; }
495 static inline int pnp_range_reserved(resource_size_t start, resource_size_t end) { return 0;}
496
497
498 static inline int pnp_is_active(struct pnp_dev *dev) { return 0; }
499 static inline int compare_pnp_id(struct pnp_id *pos, const char *id) { return -ENODEV; }
500 static inline int pnp_register_driver(struct pnp_driver *drv) { return -ENODEV; }
501 static inline void pnp_unregister_driver(struct pnp_driver *drv) { }
502
503 #endif
504
505
506
507
508
509
510
511
512
513 #define module_pnp_driver(__pnp_driver) \
514 module_driver(__pnp_driver, pnp_register_driver, \
515 pnp_unregister_driver)
516
517 #endif