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