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