Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Linux Plug and Play Support |
| 4 | * Copyright by Adam Belay <ambx1@neo.rr.com> |
Bjorn Helgaas | 1f32ca3 | 2008-06-27 16:57:17 -0600 | [diff] [blame] | 5 | * Copyright (C) 2008 Hewlett-Packard Development Company, L.P. |
| 6 | * Bjorn Helgaas <bjorn.helgaas@hp.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #ifndef _LINUX_PNP_H |
| 10 | #define _LINUX_PNP_H |
| 11 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/device.h> |
| 13 | #include <linux/list.h> |
| 14 | #include <linux/errno.h> |
| 15 | #include <linux/mod_devicetable.h> |
Peter Hurley | 01395d7 | 2015-01-22 11:50:24 -0500 | [diff] [blame] | 16 | #include <linux/console.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #define PNP_NAME_LEN 50 |
| 19 | |
| 20 | struct pnp_protocol; |
| 21 | struct pnp_dev; |
| 22 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | /* |
| 24 | * Resource Management |
| 25 | */ |
David Miller | ef3d771 | 2008-09-16 15:00:11 -0700 | [diff] [blame] | 26 | #ifdef CONFIG_PNP |
Rene Herman | b563cf5 | 2008-10-15 22:03:58 -0700 | [diff] [blame] | 27 | struct resource *pnp_get_resource(struct pnp_dev *dev, unsigned long type, |
| 28 | unsigned int num); |
David Miller | ef3d771 | 2008-09-16 15:00:11 -0700 | [diff] [blame] | 29 | #else |
Rene Herman | b563cf5 | 2008-10-15 22:03:58 -0700 | [diff] [blame] | 30 | static inline struct resource *pnp_get_resource(struct pnp_dev *dev, |
| 31 | unsigned long type, unsigned int num) |
David Miller | ef3d771 | 2008-09-16 15:00:11 -0700 | [diff] [blame] | 32 | { |
| 33 | return NULL; |
| 34 | } |
| 35 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
Bjorn Helgaas | 13575e81 | 2008-04-28 16:34:16 -0600 | [diff] [blame] | 37 | static inline int pnp_resource_valid(struct resource *res) |
| 38 | { |
Bjorn Helgaas | aee3ad8 | 2008-06-27 16:56:57 -0600 | [diff] [blame] | 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)) |
Bjorn Helgaas | 13575e81 | 2008-04-28 16:34:16 -0600 | [diff] [blame] | 47 | return 1; |
| 48 | return 0; |
| 49 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
Bjorn Helgaas | 13575e81 | 2008-04-28 16:34:16 -0600 | [diff] [blame] | 51 | static inline resource_size_t pnp_resource_len(struct resource *res) |
| 52 | { |
| 53 | if (res->start == 0 && res->end == 0) |
| 54 | return 0; |
Joe Perches | 28f65c11 | 2011-06-09 09:13:32 -0700 | [diff] [blame] | 55 | return resource_size(res); |
Bjorn Helgaas | 13575e81 | 2008-04-28 16:34:16 -0600 | [diff] [blame] | 56 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Bjorn Helgaas | 13575e81 | 2008-04-28 16:34:16 -0600 | [diff] [blame] | 59 | static inline resource_size_t pnp_port_start(struct pnp_dev *dev, |
| 60 | unsigned int bar) |
| 61 | { |
Bjorn Helgaas | 20bfdbb | 2008-06-27 16:56:56 -0600 | [diff] [blame] | 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; |
Bjorn Helgaas | 13575e81 | 2008-04-28 16:34:16 -0600 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | static inline resource_size_t pnp_port_end(struct pnp_dev *dev, |
| 70 | unsigned int bar) |
| 71 | { |
Bjorn Helgaas | 20bfdbb | 2008-06-27 16:56:56 -0600 | [diff] [blame] | 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; |
Bjorn Helgaas | 13575e81 | 2008-04-28 16:34:16 -0600 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | static inline unsigned long pnp_port_flags(struct pnp_dev *dev, |
| 80 | unsigned int bar) |
| 81 | { |
Bjorn Helgaas | 20bfdbb | 2008-06-27 16:56:56 -0600 | [diff] [blame] | 82 | struct resource *res = pnp_get_resource(dev, IORESOURCE_IO, bar); |
| 83 | |
| 84 | if (pnp_resource_valid(res)) |
| 85 | return res->flags; |
Bjorn Helgaas | aee3ad8 | 2008-06-27 16:56:57 -0600 | [diff] [blame] | 86 | return IORESOURCE_IO | IORESOURCE_AUTO; |
Bjorn Helgaas | 13575e81 | 2008-04-28 16:34:16 -0600 | [diff] [blame] | 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 | { |
Bjorn Helgaas | 20bfdbb | 2008-06-27 16:56:56 -0600 | [diff] [blame] | 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; |
Bjorn Helgaas | 13575e81 | 2008-04-28 16:34:16 -0600 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | |
| 105 | static inline resource_size_t pnp_mem_start(struct pnp_dev *dev, |
| 106 | unsigned int bar) |
| 107 | { |
Bjorn Helgaas | 20bfdbb | 2008-06-27 16:56:56 -0600 | [diff] [blame] | 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; |
Bjorn Helgaas | 13575e81 | 2008-04-28 16:34:16 -0600 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | static inline resource_size_t pnp_mem_end(struct pnp_dev *dev, |
| 116 | unsigned int bar) |
| 117 | { |
Bjorn Helgaas | 20bfdbb | 2008-06-27 16:56:56 -0600 | [diff] [blame] | 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; |
Bjorn Helgaas | 13575e81 | 2008-04-28 16:34:16 -0600 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | static inline unsigned long pnp_mem_flags(struct pnp_dev *dev, unsigned int bar) |
| 126 | { |
Bjorn Helgaas | 20bfdbb | 2008-06-27 16:56:56 -0600 | [diff] [blame] | 127 | struct resource *res = pnp_get_resource(dev, IORESOURCE_MEM, bar); |
| 128 | |
| 129 | if (pnp_resource_valid(res)) |
| 130 | return res->flags; |
Bjorn Helgaas | aee3ad8 | 2008-06-27 16:56:57 -0600 | [diff] [blame] | 131 | return IORESOURCE_MEM | IORESOURCE_AUTO; |
Bjorn Helgaas | 13575e81 | 2008-04-28 16:34:16 -0600 | [diff] [blame] | 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 | { |
Bjorn Helgaas | 20bfdbb | 2008-06-27 16:56:56 -0600 | [diff] [blame] | 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; |
Bjorn Helgaas | 13575e81 | 2008-04-28 16:34:16 -0600 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | |
| 150 | static inline resource_size_t pnp_irq(struct pnp_dev *dev, unsigned int bar) |
| 151 | { |
Bjorn Helgaas | 20bfdbb | 2008-06-27 16:56:56 -0600 | [diff] [blame] | 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; |
Bjorn Helgaas | 13575e81 | 2008-04-28 16:34:16 -0600 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | static inline unsigned long pnp_irq_flags(struct pnp_dev *dev, unsigned int bar) |
| 160 | { |
Bjorn Helgaas | 20bfdbb | 2008-06-27 16:56:56 -0600 | [diff] [blame] | 161 | struct resource *res = pnp_get_resource(dev, IORESOURCE_IRQ, bar); |
| 162 | |
| 163 | if (pnp_resource_valid(res)) |
| 164 | return res->flags; |
Bjorn Helgaas | aee3ad8 | 2008-06-27 16:56:57 -0600 | [diff] [blame] | 165 | return IORESOURCE_IRQ | IORESOURCE_AUTO; |
Bjorn Helgaas | 13575e81 | 2008-04-28 16:34:16 -0600 | [diff] [blame] | 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 | { |
Bjorn Helgaas | 20bfdbb | 2008-06-27 16:56:56 -0600 | [diff] [blame] | 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; |
Bjorn Helgaas | 13575e81 | 2008-04-28 16:34:16 -0600 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | static inline unsigned long pnp_dma_flags(struct pnp_dev *dev, unsigned int bar) |
| 184 | { |
Bjorn Helgaas | 20bfdbb | 2008-06-27 16:56:56 -0600 | [diff] [blame] | 185 | struct resource *res = pnp_get_resource(dev, IORESOURCE_DMA, bar); |
| 186 | |
| 187 | if (pnp_resource_valid(res)) |
| 188 | return res->flags; |
Bjorn Helgaas | aee3ad8 | 2008-06-27 16:56:57 -0600 | [diff] [blame] | 189 | return IORESOURCE_DMA | IORESOURCE_AUTO; |
Bjorn Helgaas | 13575e81 | 2008-04-28 16:34:16 -0600 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | /* |
Joe Perches | fd3f898 | 2008-02-03 17:45:46 +0200 | [diff] [blame] | 199 | * Device Management |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | */ |
| 201 | |
| 202 | struct pnp_card { |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 203 | struct device dev; /* Driver Model device interface */ |
| 204 | unsigned char number; /* used as an index, must be unique */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | struct list_head global_list; /* node in global list of cards */ |
| 206 | struct list_head protocol_list; /* node in protocol's list of cards */ |
| 207 | struct list_head devices; /* devices attached to the card */ |
| 208 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 209 | struct pnp_protocol *protocol; |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 210 | struct pnp_id *id; /* contains supported EISA IDs */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | |
| 212 | char name[PNP_NAME_LEN]; /* contains a human-readable name */ |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 213 | unsigned char pnpver; /* Plug & Play version */ |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 214 | unsigned char productver; /* product version */ |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 215 | unsigned int serial; /* serial number */ |
| 216 | unsigned char checksum; /* if zero - checksum passed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | struct proc_dir_entry *procdir; /* directory entry in /proc/bus/isapnp */ |
| 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 | for((card) = global_to_pnp_card(pnp_cards.next); \ |
| 225 | (card) != global_to_pnp_card(&pnp_cards); \ |
| 226 | (card) = global_to_pnp_card((card)->global_list.next)) |
| 227 | |
| 228 | struct pnp_card_link { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 229 | struct pnp_card *card; |
| 230 | struct pnp_card_driver *driver; |
| 231 | void *driver_data; |
Takashi Iwai | 4c98cfe | 2005-11-29 09:09:32 +0100 | [diff] [blame] | 232 | pm_message_t pm_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | }; |
| 234 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 235 | static inline void *pnp_get_card_drvdata(struct pnp_card_link *pcard) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | { |
| 237 | return pcard->driver_data; |
| 238 | } |
| 239 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 240 | static inline void pnp_set_card_drvdata(struct pnp_card_link *pcard, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | { |
| 242 | pcard->driver_data = data; |
| 243 | } |
| 244 | |
| 245 | struct pnp_dev { |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 246 | struct device dev; /* Driver Model device interface */ |
David Brownell | 2e17c55 | 2007-05-08 00:25:29 -0700 | [diff] [blame] | 247 | u64 dma_mask; |
Bjorn Helgaas | 544451a | 2008-04-10 21:29:28 -0700 | [diff] [blame] | 248 | unsigned int number; /* used as an index, must be unique */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | int status; |
| 250 | |
| 251 | struct list_head global_list; /* node in global list of devices */ |
| 252 | struct list_head protocol_list; /* node in list of device's protocol */ |
| 253 | struct list_head card_list; /* node in card's list of devices */ |
| 254 | struct list_head rdev_list; /* node in cards list of requested devices */ |
| 255 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 256 | struct pnp_protocol *protocol; |
| 257 | struct pnp_card *card; /* card the device is attached to, none if NULL */ |
| 258 | struct pnp_driver *driver; |
| 259 | struct pnp_card_link *card_link; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 261 | struct pnp_id *id; /* supported EISA IDs */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | |
| 263 | int active; |
| 264 | int capabilities; |
Bjorn Helgaas | 1f32ca3 | 2008-06-27 16:57:17 -0600 | [diff] [blame] | 265 | unsigned int num_dependent_sets; |
Bjorn Helgaas | aee3ad8 | 2008-06-27 16:56:57 -0600 | [diff] [blame] | 266 | struct list_head resources; |
Bjorn Helgaas | 1f32ca3 | 2008-06-27 16:57:17 -0600 | [diff] [blame] | 267 | struct list_head options; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | |
| 269 | char name[PNP_NAME_LEN]; /* contains a human-readable name */ |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 270 | int flags; /* used by protocols */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | struct proc_dir_entry *procent; /* device entry in /proc/bus/isapnp */ |
| 272 | void *data; |
| 273 | }; |
| 274 | |
| 275 | #define global_to_pnp_dev(n) list_entry(n, struct pnp_dev, global_list) |
| 276 | #define card_to_pnp_dev(n) list_entry(n, struct pnp_dev, card_list) |
| 277 | #define protocol_to_pnp_dev(n) list_entry(n, struct pnp_dev, protocol_list) |
| 278 | #define to_pnp_dev(n) container_of(n, struct pnp_dev, dev) |
| 279 | #define pnp_for_each_dev(dev) \ |
| 280 | for((dev) = global_to_pnp_dev(pnp_global.next); \ |
| 281 | (dev) != global_to_pnp_dev(&pnp_global); \ |
| 282 | (dev) = global_to_pnp_dev((dev)->global_list.next)) |
| 283 | #define card_for_each_dev(card,dev) \ |
| 284 | for((dev) = card_to_pnp_dev((card)->devices.next); \ |
| 285 | (dev) != card_to_pnp_dev(&(card)->devices); \ |
| 286 | (dev) = card_to_pnp_dev((dev)->card_list.next)) |
| 287 | #define pnp_dev_name(dev) (dev)->name |
| 288 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 289 | static inline void *pnp_get_drvdata(struct pnp_dev *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | { |
| 291 | return dev_get_drvdata(&pdev->dev); |
| 292 | } |
| 293 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 294 | static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | { |
| 296 | dev_set_drvdata(&pdev->dev, data); |
| 297 | } |
| 298 | |
| 299 | struct pnp_fixup { |
| 300 | char id[7]; |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 301 | void (*quirk_function) (struct pnp_dev * dev); /* fixup function */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | }; |
| 303 | |
| 304 | /* config parameters */ |
| 305 | #define PNP_CONFIG_NORMAL 0x0001 |
| 306 | #define PNP_CONFIG_FORCE 0x0002 /* disables validity checking */ |
| 307 | |
| 308 | /* capabilities */ |
| 309 | #define PNP_READ 0x0001 |
| 310 | #define PNP_WRITE 0x0002 |
| 311 | #define PNP_DISABLE 0x0004 |
| 312 | #define PNP_CONFIGURABLE 0x0008 |
| 313 | #define PNP_REMOVABLE 0x0010 |
Peter Hurley | 01395d7 | 2015-01-22 11:50:24 -0500 | [diff] [blame] | 314 | #define PNP_CONSOLE 0x0020 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | |
Bjorn Helgaas | 402b310 | 2007-10-16 23:31:09 -0700 | [diff] [blame] | 316 | #define pnp_can_read(dev) (((dev)->protocol->get) && \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | ((dev)->capabilities & PNP_READ)) |
Bjorn Helgaas | 402b310 | 2007-10-16 23:31:09 -0700 | [diff] [blame] | 318 | #define pnp_can_write(dev) (((dev)->protocol->set) && \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | ((dev)->capabilities & PNP_WRITE)) |
Peter Hurley | 01395d7 | 2015-01-22 11:50:24 -0500 | [diff] [blame] | 320 | #define pnp_can_disable(dev) (((dev)->protocol->disable) && \ |
| 321 | ((dev)->capabilities & PNP_DISABLE) && \ |
| 322 | (!((dev)->capabilities & PNP_CONSOLE) || \ |
| 323 | console_suspend_enabled)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | #define pnp_can_configure(dev) ((!(dev)->active) && \ |
| 325 | ((dev)->capabilities & PNP_CONFIGURABLE)) |
Peter Hurley | 01395d7 | 2015-01-22 11:50:24 -0500 | [diff] [blame] | 326 | #define pnp_can_suspend(dev) (((dev)->protocol->suspend) && \ |
| 327 | (!((dev)->capabilities & PNP_CONSOLE) || \ |
| 328 | console_suspend_enabled)) |
| 329 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | |
| 331 | #ifdef CONFIG_ISAPNP |
| 332 | extern struct pnp_protocol isapnp_protocol; |
| 333 | #define pnp_device_is_isapnp(dev) ((dev)->protocol == (&isapnp_protocol)) |
| 334 | #else |
| 335 | #define pnp_device_is_isapnp(dev) 0 |
| 336 | #endif |
Daniel Walker | b3bd86e | 2008-02-06 01:40:04 -0800 | [diff] [blame] | 337 | extern struct mutex pnp_res_mutex; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | |
| 339 | #ifdef CONFIG_PNPBIOS |
| 340 | extern struct pnp_protocol pnpbios_protocol; |
Luis R. Rodriguez | 80dfd83 | 2016-04-13 17:04:41 -0700 | [diff] [blame] | 341 | extern bool arch_pnpbios_disabled(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | #define pnp_device_is_pnpbios(dev) ((dev)->protocol == (&pnpbios_protocol)) |
| 343 | #else |
| 344 | #define pnp_device_is_pnpbios(dev) 0 |
Luis R. Rodriguez | 80dfd83 | 2016-04-13 17:04:41 -0700 | [diff] [blame] | 345 | #define arch_pnpbios_disabled() false |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | #endif |
| 347 | |
Bjorn Helgaas | 9065ce4 | 2009-11-17 17:05:19 -0700 | [diff] [blame] | 348 | #ifdef CONFIG_PNPACPI |
| 349 | extern struct pnp_protocol pnpacpi_protocol; |
| 350 | |
| 351 | static inline struct acpi_device *pnp_acpi_device(struct pnp_dev *dev) |
| 352 | { |
| 353 | if (dev->protocol == &pnpacpi_protocol) |
| 354 | return dev->data; |
| 355 | return NULL; |
| 356 | } |
| 357 | #else |
| 358 | #define pnp_acpi_device(dev) 0 |
| 359 | #endif |
| 360 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | /* status */ |
| 362 | #define PNP_READY 0x0000 |
| 363 | #define PNP_ATTACHED 0x0001 |
| 364 | #define PNP_BUSY 0x0002 |
| 365 | #define PNP_FAULTY 0x0004 |
| 366 | |
| 367 | /* isapnp specific macros */ |
| 368 | |
| 369 | #define isapnp_card_number(dev) ((dev)->card ? (dev)->card->number : -1) |
| 370 | #define isapnp_csn_number(dev) ((dev)->number) |
| 371 | |
| 372 | /* |
| 373 | * Driver Management |
| 374 | */ |
| 375 | |
| 376 | struct pnp_id { |
| 377 | char id[PNP_ID_LEN]; |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 378 | struct pnp_id *next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | }; |
| 380 | |
| 381 | struct pnp_driver { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 382 | char *name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | const struct pnp_device_id *id_table; |
| 384 | unsigned int flags; |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 385 | int (*probe) (struct pnp_dev *dev, const struct pnp_device_id *dev_id); |
| 386 | void (*remove) (struct pnp_dev *dev); |
David Härdeman | abd6633 | 2009-09-21 17:04:52 -0700 | [diff] [blame] | 387 | void (*shutdown) (struct pnp_dev *dev); |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 388 | int (*suspend) (struct pnp_dev *dev, pm_message_t state); |
| 389 | int (*resume) (struct pnp_dev *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | struct device_driver driver; |
| 391 | }; |
| 392 | |
| 393 | #define to_pnp_driver(drv) container_of(drv, struct pnp_driver, driver) |
| 394 | |
| 395 | struct pnp_card_driver { |
| 396 | struct list_head global_list; |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 397 | char *name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | const struct pnp_card_device_id *id_table; |
| 399 | unsigned int flags; |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 400 | int (*probe) (struct pnp_card_link *card, |
| 401 | const struct pnp_card_device_id *card_id); |
| 402 | void (*remove) (struct pnp_card_link *card); |
| 403 | int (*suspend) (struct pnp_card_link *card, pm_message_t state); |
| 404 | int (*resume) (struct pnp_card_link *card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | struct pnp_driver link; |
| 406 | }; |
| 407 | |
| 408 | #define to_pnp_card_driver(drv) container_of(drv, struct pnp_card_driver, link) |
| 409 | |
| 410 | /* pnp driver flags */ |
| 411 | #define PNP_DRIVER_RES_DO_NOT_CHANGE 0x0001 /* do not change the state of the device */ |
| 412 | #define PNP_DRIVER_RES_DISABLE 0x0003 /* ensure the device is disabled */ |
| 413 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | /* |
| 415 | * Protocol Management |
| 416 | */ |
| 417 | |
| 418 | struct pnp_protocol { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 419 | struct list_head protocol_list; |
| 420 | char *name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | |
| 422 | /* resource control functions */ |
Bjorn Helgaas | 59284cb | 2008-04-28 16:34:05 -0600 | [diff] [blame] | 423 | int (*get) (struct pnp_dev *dev); |
| 424 | int (*set) (struct pnp_dev *dev); |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 425 | int (*disable) (struct pnp_dev *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | |
Shaohua Li | fc30e68 | 2007-07-20 10:03:20 +0800 | [diff] [blame] | 427 | /* protocol specific suspend/resume */ |
Alan Stern | b14e033e | 2010-06-29 22:49:24 +0200 | [diff] [blame] | 428 | bool (*can_wakeup) (struct pnp_dev *dev); |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 429 | int (*suspend) (struct pnp_dev * dev, pm_message_t state); |
| 430 | int (*resume) (struct pnp_dev * dev); |
Shaohua Li | fc30e68 | 2007-07-20 10:03:20 +0800 | [diff] [blame] | 431 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | /* used by pnp layer only (look but don't touch) */ |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 433 | unsigned char number; /* protocol number */ |
| 434 | struct device dev; /* link to driver model */ |
| 435 | struct list_head cards; |
| 436 | struct list_head devices; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | }; |
| 438 | |
| 439 | #define to_pnp_protocol(n) list_entry(n, struct pnp_protocol, protocol_list) |
| 440 | #define protocol_for_each_card(protocol,card) \ |
| 441 | for((card) = protocol_to_pnp_card((protocol)->cards.next); \ |
| 442 | (card) != protocol_to_pnp_card(&(protocol)->cards); \ |
| 443 | (card) = protocol_to_pnp_card((card)->protocol_list.next)) |
| 444 | #define protocol_for_each_dev(protocol,dev) \ |
| 445 | for((dev) = protocol_to_pnp_dev((protocol)->devices.next); \ |
| 446 | (dev) != protocol_to_pnp_dev(&(protocol)->devices); \ |
| 447 | (dev) = protocol_to_pnp_dev((dev)->protocol_list.next)) |
| 448 | |
David Brownell | cbcdc1d | 2007-02-10 01:45:13 -0800 | [diff] [blame] | 449 | extern struct bus_type pnp_bus_type; |
| 450 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | #if defined(CONFIG_PNP) |
| 452 | |
| 453 | /* device management */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | int pnp_device_attach(struct pnp_dev *pnp_dev); |
| 455 | void pnp_device_detach(struct pnp_dev *pnp_dev); |
| 456 | extern struct list_head pnp_global; |
Bjorn Helgaas | 8f81dd1 | 2007-05-08 00:35:54 -0700 | [diff] [blame] | 457 | extern int pnp_platform_devices; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | |
| 459 | /* multidevice card support */ |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 460 | struct pnp_dev *pnp_request_card_device(struct pnp_card_link *clink, |
| 461 | const char *id, struct pnp_dev *from); |
| 462 | void pnp_release_card_device(struct pnp_dev *dev); |
| 463 | int pnp_register_card_driver(struct pnp_card_driver *drv); |
| 464 | void pnp_unregister_card_driver(struct pnp_card_driver *drv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | extern struct list_head pnp_cards; |
| 466 | |
| 467 | /* resource management */ |
Bjorn Helgaas | 57fd51a | 2008-06-27 16:57:01 -0600 | [diff] [blame] | 468 | int pnp_possible_config(struct pnp_dev *dev, int type, resource_size_t base, |
| 469 | resource_size_t size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | int pnp_auto_config_dev(struct pnp_dev *dev); |
Pierre Ossman | 68094e3 | 2005-11-29 09:09:32 +0100 | [diff] [blame] | 471 | int pnp_start_dev(struct pnp_dev *dev); |
| 472 | int pnp_stop_dev(struct pnp_dev *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | int pnp_activate_dev(struct pnp_dev *dev); |
| 474 | int pnp_disable_dev(struct pnp_dev *dev); |
Bjorn Helgaas | 1b8e696 | 2009-06-05 14:37:23 +0000 | [diff] [blame] | 475 | int pnp_range_reserved(resource_size_t start, resource_size_t end); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | |
| 477 | /* protocol helpers */ |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 478 | int pnp_is_active(struct pnp_dev *dev); |
| 479 | int compare_pnp_id(struct pnp_id *pos, const char *id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | int pnp_register_driver(struct pnp_driver *drv); |
| 481 | void pnp_unregister_driver(struct pnp_driver *drv); |
| 482 | |
| 483 | #else |
| 484 | |
| 485 | /* device management */ |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 486 | static inline int pnp_device_attach(struct pnp_dev *pnp_dev) { return -ENODEV; } |
| 487 | static inline void pnp_device_detach(struct pnp_dev *pnp_dev) { } |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 488 | |
Bjorn Helgaas | 8f81dd1 | 2007-05-08 00:35:54 -0700 | [diff] [blame] | 489 | #define pnp_platform_devices 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | |
| 491 | /* multidevice card support */ |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 492 | static inline struct pnp_dev *pnp_request_card_device(struct pnp_card_link *clink, const char *id, struct pnp_dev *from) { return NULL; } |
| 493 | static inline void pnp_release_card_device(struct pnp_dev *dev) { } |
| 494 | static inline int pnp_register_card_driver(struct pnp_card_driver *drv) { return -ENODEV; } |
| 495 | static inline void pnp_unregister_card_driver(struct pnp_card_driver *drv) { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | |
| 497 | /* resource management */ |
Bjorn Helgaas | 57fd51a | 2008-06-27 16:57:01 -0600 | [diff] [blame] | 498 | static inline int pnp_possible_config(struct pnp_dev *dev, int type, |
| 499 | resource_size_t base, |
| 500 | resource_size_t size) { return 0; } |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 501 | static inline int pnp_auto_config_dev(struct pnp_dev *dev) { return -ENODEV; } |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 502 | static inline int pnp_start_dev(struct pnp_dev *dev) { return -ENODEV; } |
| 503 | static inline int pnp_stop_dev(struct pnp_dev *dev) { return -ENODEV; } |
| 504 | static inline int pnp_activate_dev(struct pnp_dev *dev) { return -ENODEV; } |
| 505 | static inline int pnp_disable_dev(struct pnp_dev *dev) { return -ENODEV; } |
Bjorn Helgaas | 1b8e696 | 2009-06-05 14:37:23 +0000 | [diff] [blame] | 506 | static inline int pnp_range_reserved(resource_size_t start, resource_size_t end) { return 0;} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | |
| 508 | /* protocol helpers */ |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 509 | static inline int pnp_is_active(struct pnp_dev *dev) { return 0; } |
| 510 | static inline int compare_pnp_id(struct pnp_id *pos, const char *id) { return -ENODEV; } |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 511 | static inline int pnp_register_driver(struct pnp_driver *drv) { return -ENODEV; } |
| 512 | static inline void pnp_unregister_driver(struct pnp_driver *drv) { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | |
| 514 | #endif /* CONFIG_PNP */ |
| 515 | |
Peter Huewe | 95c0fd4 | 2015-03-16 21:46:30 +0100 | [diff] [blame] | 516 | /** |
| 517 | * module_pnp_driver() - Helper macro for registering a PnP driver |
| 518 | * @__pnp_driver: pnp_driver struct |
| 519 | * |
| 520 | * Helper macro for PnP drivers which do not do anything special in module |
| 521 | * init/exit. This eliminates a lot of boilerplate. Each module may only |
| 522 | * use this macro once, and calling it replaces module_init() and module_exit() |
| 523 | */ |
| 524 | #define module_pnp_driver(__pnp_driver) \ |
| 525 | module_driver(__pnp_driver, pnp_register_driver, \ |
| 526 | pnp_unregister_driver) |
| 527 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | #endif /* _LINUX_PNP_H */ |