diff options
Diffstat (limited to 'drivers/pnp/manager.c')
| -rw-r--r-- | drivers/pnp/manager.c | 414 |
1 files changed, 131 insertions, 283 deletions
diff --git a/drivers/pnp/manager.c b/drivers/pnp/manager.c index bea0914ff947..b526eaad3f6c 100644 --- a/drivers/pnp/manager.c +++ b/drivers/pnp/manager.c | |||
| @@ -3,6 +3,8 @@ | |||
| 3 | * | 3 | * |
| 4 | * based on isapnp.c resource management (c) Jaroslav Kysela <perex@perex.cz> | 4 | * based on isapnp.c resource management (c) Jaroslav Kysela <perex@perex.cz> |
| 5 | * Copyright 2003 Adam Belay <ambx1@neo.rr.com> | 5 | * Copyright 2003 Adam Belay <ambx1@neo.rr.com> |
| 6 | * Copyright (C) 2008 Hewlett-Packard Development Company, L.P. | ||
| 7 | * Bjorn Helgaas <bjorn.helgaas@hp.com> | ||
| 6 | */ | 8 | */ |
| 7 | 9 | ||
| 8 | #include <linux/errno.h> | 10 | #include <linux/errno.h> |
| @@ -19,82 +21,64 @@ DEFINE_MUTEX(pnp_res_mutex); | |||
| 19 | 21 | ||
| 20 | static int pnp_assign_port(struct pnp_dev *dev, struct pnp_port *rule, int idx) | 22 | static int pnp_assign_port(struct pnp_dev *dev, struct pnp_port *rule, int idx) |
| 21 | { | 23 | { |
| 22 | struct pnp_resource *pnp_res; | 24 | struct resource *res, local_res; |
| 23 | struct resource *res; | ||
| 24 | |||
| 25 | pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_IO, idx); | ||
| 26 | if (!pnp_res) { | ||
| 27 | dev_err(&dev->dev, "too many I/O port resources\n"); | ||
| 28 | /* pretend we were successful so at least the manager won't try again */ | ||
| 29 | return 1; | ||
| 30 | } | ||
| 31 | |||
| 32 | res = &pnp_res->res; | ||
| 33 | 25 | ||
| 34 | /* check if this resource has been manually set, if so skip */ | 26 | res = pnp_get_resource(dev, IORESOURCE_IO, idx); |
| 35 | if (!(res->flags & IORESOURCE_AUTO)) { | 27 | if (res) { |
| 36 | dev_dbg(&dev->dev, " io %d already set to %#llx-%#llx " | 28 | dev_dbg(&dev->dev, " io %d already set to %#llx-%#llx " |
| 37 | "flags %#lx\n", idx, (unsigned long long) res->start, | 29 | "flags %#lx\n", idx, (unsigned long long) res->start, |
| 38 | (unsigned long long) res->end, res->flags); | 30 | (unsigned long long) res->end, res->flags); |
| 39 | return 1; | 31 | return 0; |
| 40 | } | 32 | } |
| 41 | 33 | ||
| 42 | /* set the initial values */ | 34 | res = &local_res; |
| 43 | pnp_res->index = idx; | 35 | res->flags = rule->flags | IORESOURCE_AUTO; |
| 44 | res->flags |= rule->flags | IORESOURCE_IO; | 36 | res->start = 0; |
| 45 | res->flags &= ~IORESOURCE_UNSET; | 37 | res->end = 0; |
| 46 | 38 | ||
| 47 | if (!rule->size) { | 39 | if (!rule->size) { |
| 48 | res->flags |= IORESOURCE_DISABLED; | 40 | res->flags |= IORESOURCE_DISABLED; |
| 49 | dev_dbg(&dev->dev, " io %d disabled\n", idx); | 41 | dev_dbg(&dev->dev, " io %d disabled\n", idx); |
| 50 | return 1; /* skip disabled resource requests */ | 42 | goto __add; |
| 51 | } | 43 | } |
| 52 | 44 | ||
| 53 | res->start = rule->min; | 45 | res->start = rule->min; |
| 54 | res->end = res->start + rule->size - 1; | 46 | res->end = res->start + rule->size - 1; |
| 55 | 47 | ||
| 56 | /* run through until pnp_check_port is happy */ | ||
| 57 | while (!pnp_check_port(dev, res)) { | 48 | while (!pnp_check_port(dev, res)) { |
| 58 | res->start += rule->align; | 49 | res->start += rule->align; |
| 59 | res->end = res->start + rule->size - 1; | 50 | res->end = res->start + rule->size - 1; |
| 60 | if (res->start > rule->max || !rule->align) { | 51 | if (res->start > rule->max || !rule->align) { |
| 61 | dev_dbg(&dev->dev, " couldn't assign io %d\n", idx); | 52 | dev_dbg(&dev->dev, " couldn't assign io %d " |
| 62 | return 0; | 53 | "(min %#llx max %#llx)\n", idx, |
| 54 | (unsigned long long) rule->min, | ||
| 55 | (unsigned long long) rule->max); | ||
| 56 | return -EBUSY; | ||
| 63 | } | 57 | } |
| 64 | } | 58 | } |
| 65 | dev_dbg(&dev->dev, " assign io %d %#llx-%#llx\n", idx, | 59 | |
| 66 | (unsigned long long) res->start, (unsigned long long) res->end); | 60 | __add: |
| 67 | return 1; | 61 | pnp_add_io_resource(dev, res->start, res->end, res->flags); |
| 62 | return 0; | ||
| 68 | } | 63 | } |
| 69 | 64 | ||
| 70 | static int pnp_assign_mem(struct pnp_dev *dev, struct pnp_mem *rule, int idx) | 65 | static int pnp_assign_mem(struct pnp_dev *dev, struct pnp_mem *rule, int idx) |
| 71 | { | 66 | { |
| 72 | struct pnp_resource *pnp_res; | 67 | struct resource *res, local_res; |
| 73 | struct resource *res; | ||
| 74 | |||
| 75 | pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_MEM, idx); | ||
| 76 | if (!pnp_res) { | ||
| 77 | dev_err(&dev->dev, "too many memory resources\n"); | ||
| 78 | /* pretend we were successful so at least the manager won't try again */ | ||
| 79 | return 1; | ||
| 80 | } | ||
| 81 | 68 | ||
| 82 | res = &pnp_res->res; | 69 | res = pnp_get_resource(dev, IORESOURCE_MEM, idx); |
| 83 | 70 | if (res) { | |
| 84 | /* check if this resource has been manually set, if so skip */ | ||
| 85 | if (!(res->flags & IORESOURCE_AUTO)) { | ||
| 86 | dev_dbg(&dev->dev, " mem %d already set to %#llx-%#llx " | 71 | dev_dbg(&dev->dev, " mem %d already set to %#llx-%#llx " |
| 87 | "flags %#lx\n", idx, (unsigned long long) res->start, | 72 | "flags %#lx\n", idx, (unsigned long long) res->start, |
| 88 | (unsigned long long) res->end, res->flags); | 73 | (unsigned long long) res->end, res->flags); |
| 89 | return 1; | 74 | return 0; |
| 90 | } | 75 | } |
| 91 | 76 | ||
| 92 | /* set the initial values */ | 77 | res = &local_res; |
| 93 | pnp_res->index = idx; | 78 | res->flags = rule->flags | IORESOURCE_AUTO; |
| 94 | res->flags |= rule->flags | IORESOURCE_MEM; | 79 | res->start = 0; |
| 95 | res->flags &= ~IORESOURCE_UNSET; | 80 | res->end = 0; |
| 96 | 81 | ||
| 97 | /* convert pnp flags to standard Linux flags */ | ||
| 98 | if (!(rule->flags & IORESOURCE_MEM_WRITEABLE)) | 82 | if (!(rule->flags & IORESOURCE_MEM_WRITEABLE)) |
| 99 | res->flags |= IORESOURCE_READONLY; | 83 | res->flags |= IORESOURCE_READONLY; |
| 100 | if (rule->flags & IORESOURCE_MEM_CACHEABLE) | 84 | if (rule->flags & IORESOURCE_MEM_CACHEABLE) |
| @@ -107,30 +91,32 @@ static int pnp_assign_mem(struct pnp_dev *dev, struct pnp_mem *rule, int idx) | |||
| 107 | if (!rule->size) { | 91 | if (!rule->size) { |
| 108 | res->flags |= IORESOURCE_DISABLED; | 92 | res->flags |= IORESOURCE_DISABLED; |
| 109 | dev_dbg(&dev->dev, " mem %d disabled\n", idx); | 93 | dev_dbg(&dev->dev, " mem %d disabled\n", idx); |
| 110 | return 1; /* skip disabled resource requests */ | 94 | goto __add; |
| 111 | } | 95 | } |
| 112 | 96 | ||
| 113 | res->start = rule->min; | 97 | res->start = rule->min; |
| 114 | res->end = res->start + rule->size - 1; | 98 | res->end = res->start + rule->size - 1; |
| 115 | 99 | ||
| 116 | /* run through until pnp_check_mem is happy */ | ||
| 117 | while (!pnp_check_mem(dev, res)) { | 100 | while (!pnp_check_mem(dev, res)) { |
| 118 | res->start += rule->align; | 101 | res->start += rule->align; |
| 119 | res->end = res->start + rule->size - 1; | 102 | res->end = res->start + rule->size - 1; |
| 120 | if (res->start > rule->max || !rule->align) { | 103 | if (res->start > rule->max || !rule->align) { |
| 121 | dev_dbg(&dev->dev, " couldn't assign mem %d\n", idx); | 104 | dev_dbg(&dev->dev, " couldn't assign mem %d " |
| 122 | return 0; | 105 | "(min %#llx max %#llx)\n", idx, |
| 106 | (unsigned long long) rule->min, | ||
| 107 | (unsigned long long) rule->max); | ||
| 108 | return -EBUSY; | ||
| 123 | } | 109 | } |
| 124 | } | 110 | } |
| 125 | dev_dbg(&dev->dev, " assign mem %d %#llx-%#llx\n", idx, | 111 | |
| 126 | (unsigned long long) res->start, (unsigned long long) res->end); | 112 | __add: |
| 127 | return 1; | 113 | pnp_add_mem_resource(dev, res->start, res->end, res->flags); |
| 114 | return 0; | ||
| 128 | } | 115 | } |
| 129 | 116 | ||
| 130 | static int pnp_assign_irq(struct pnp_dev *dev, struct pnp_irq *rule, int idx) | 117 | static int pnp_assign_irq(struct pnp_dev *dev, struct pnp_irq *rule, int idx) |
| 131 | { | 118 | { |
| 132 | struct pnp_resource *pnp_res; | 119 | struct resource *res, local_res; |
| 133 | struct resource *res; | ||
| 134 | int i; | 120 | int i; |
| 135 | 121 | ||
| 136 | /* IRQ priority: this table is good for i386 */ | 122 | /* IRQ priority: this table is good for i386 */ |
| @@ -138,59 +124,57 @@ static int pnp_assign_irq(struct pnp_dev *dev, struct pnp_irq *rule, int idx) | |||
| 138 | 5, 10, 11, 12, 9, 14, 15, 7, 3, 4, 13, 0, 1, 6, 8, 2 | 124 | 5, 10, 11, 12, 9, 14, 15, 7, 3, 4, 13, 0, 1, 6, 8, 2 |
| 139 | }; | 125 | }; |
| 140 | 126 | ||
| 141 | pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_IRQ, idx); | 127 | res = pnp_get_resource(dev, IORESOURCE_IRQ, idx); |
| 142 | if (!pnp_res) { | 128 | if (res) { |
| 143 | dev_err(&dev->dev, "too many IRQ resources\n"); | ||
| 144 | /* pretend we were successful so at least the manager won't try again */ | ||
| 145 | return 1; | ||
| 146 | } | ||
| 147 | |||
| 148 | res = &pnp_res->res; | ||
| 149 | |||
| 150 | /* check if this resource has been manually set, if so skip */ | ||
| 151 | if (!(res->flags & IORESOURCE_AUTO)) { | ||
| 152 | dev_dbg(&dev->dev, " irq %d already set to %d flags %#lx\n", | 129 | dev_dbg(&dev->dev, " irq %d already set to %d flags %#lx\n", |
| 153 | idx, (int) res->start, res->flags); | 130 | idx, (int) res->start, res->flags); |
| 154 | return 1; | 131 | return 0; |
| 155 | } | 132 | } |
| 156 | 133 | ||
| 157 | /* set the initial values */ | 134 | res = &local_res; |
| 158 | pnp_res->index = idx; | 135 | res->flags = rule->flags | IORESOURCE_AUTO; |
| 159 | res->flags |= rule->flags | IORESOURCE_IRQ; | 136 | res->start = -1; |
| 160 | res->flags &= ~IORESOURCE_UNSET; | 137 | res->end = -1; |
| 161 | 138 | ||
| 162 | if (bitmap_empty(rule->map, PNP_IRQ_NR)) { | 139 | if (bitmap_empty(rule->map.bits, PNP_IRQ_NR)) { |
| 163 | res->flags |= IORESOURCE_DISABLED; | 140 | res->flags |= IORESOURCE_DISABLED; |
| 164 | dev_dbg(&dev->dev, " irq %d disabled\n", idx); | 141 | dev_dbg(&dev->dev, " irq %d disabled\n", idx); |
| 165 | return 1; /* skip disabled resource requests */ | 142 | goto __add; |
| 166 | } | 143 | } |
| 167 | 144 | ||
| 168 | /* TBD: need check for >16 IRQ */ | 145 | /* TBD: need check for >16 IRQ */ |
| 169 | res->start = find_next_bit(rule->map, PNP_IRQ_NR, 16); | 146 | res->start = find_next_bit(rule->map.bits, PNP_IRQ_NR, 16); |
| 170 | if (res->start < PNP_IRQ_NR) { | 147 | if (res->start < PNP_IRQ_NR) { |
| 171 | res->end = res->start; | 148 | res->end = res->start; |
| 172 | dev_dbg(&dev->dev, " assign irq %d %d\n", idx, | 149 | goto __add; |
| 173 | (int) res->start); | ||
| 174 | return 1; | ||
| 175 | } | 150 | } |
| 176 | for (i = 0; i < 16; i++) { | 151 | for (i = 0; i < 16; i++) { |
| 177 | if (test_bit(xtab[i], rule->map)) { | 152 | if (test_bit(xtab[i], rule->map.bits)) { |
| 178 | res->start = res->end = xtab[i]; | 153 | res->start = res->end = xtab[i]; |
| 179 | if (pnp_check_irq(dev, res)) { | 154 | if (pnp_check_irq(dev, res)) |
| 180 | dev_dbg(&dev->dev, " assign irq %d %d\n", idx, | 155 | goto __add; |
| 181 | (int) res->start); | ||
| 182 | return 1; | ||
| 183 | } | ||
| 184 | } | 156 | } |
| 185 | } | 157 | } |
| 158 | |||
| 159 | if (rule->flags & IORESOURCE_IRQ_OPTIONAL) { | ||
| 160 | res->start = -1; | ||
| 161 | res->end = -1; | ||
| 162 | res->flags |= IORESOURCE_DISABLED; | ||
| 163 | dev_dbg(&dev->dev, " irq %d disabled (optional)\n", idx); | ||
| 164 | goto __add; | ||
| 165 | } | ||
| 166 | |||
| 186 | dev_dbg(&dev->dev, " couldn't assign irq %d\n", idx); | 167 | dev_dbg(&dev->dev, " couldn't assign irq %d\n", idx); |
| 168 | return -EBUSY; | ||
| 169 | |||
| 170 | __add: | ||
| 171 | pnp_add_irq_resource(dev, res->start, res->flags); | ||
| 187 | return 0; | 172 | return 0; |
| 188 | } | 173 | } |
| 189 | 174 | ||
| 190 | static void pnp_assign_dma(struct pnp_dev *dev, struct pnp_dma *rule, int idx) | 175 | static int pnp_assign_dma(struct pnp_dev *dev, struct pnp_dma *rule, int idx) |
| 191 | { | 176 | { |
| 192 | struct pnp_resource *pnp_res; | 177 | struct resource *res, local_res; |
| 193 | struct resource *res; | ||
| 194 | int i; | 178 | int i; |
| 195 | 179 | ||
| 196 | /* DMA priority: this table is good for i386 */ | 180 | /* DMA priority: this table is good for i386 */ |
| @@ -198,231 +182,99 @@ static void pnp_assign_dma(struct pnp_dev *dev, struct pnp_dma *rule, int idx) | |||
| 198 | 1, 3, 5, 6, 7, 0, 2, 4 | 182 | 1, 3, 5, 6, 7, 0, 2, 4 |
| 199 | }; | 183 | }; |
| 200 | 184 | ||
| 201 | pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_DMA, idx); | 185 | res = pnp_get_resource(dev, IORESOURCE_DMA, idx); |
| 202 | if (!pnp_res) { | 186 | if (res) { |
| 203 | dev_err(&dev->dev, "too many DMA resources\n"); | ||
| 204 | return; | ||
| 205 | } | ||
| 206 | |||
| 207 | res = &pnp_res->res; | ||
| 208 | |||
| 209 | /* check if this resource has been manually set, if so skip */ | ||
| 210 | if (!(res->flags & IORESOURCE_AUTO)) { | ||
| 211 | dev_dbg(&dev->dev, " dma %d already set to %d flags %#lx\n", | 187 | dev_dbg(&dev->dev, " dma %d already set to %d flags %#lx\n", |
| 212 | idx, (int) res->start, res->flags); | 188 | idx, (int) res->start, res->flags); |
| 213 | return; | 189 | return 0; |
| 214 | } | 190 | } |
| 215 | 191 | ||
| 216 | /* set the initial values */ | 192 | res = &local_res; |
| 217 | pnp_res->index = idx; | 193 | res->flags = rule->flags | IORESOURCE_AUTO; |
| 218 | res->flags |= rule->flags | IORESOURCE_DMA; | 194 | res->start = -1; |
| 219 | res->flags &= ~IORESOURCE_UNSET; | 195 | res->end = -1; |
| 220 | 196 | ||
| 221 | for (i = 0; i < 8; i++) { | 197 | for (i = 0; i < 8; i++) { |
| 222 | if (rule->map & (1 << xtab[i])) { | 198 | if (rule->map & (1 << xtab[i])) { |
| 223 | res->start = res->end = xtab[i]; | 199 | res->start = res->end = xtab[i]; |
| 224 | if (pnp_check_dma(dev, res)) { | 200 | if (pnp_check_dma(dev, res)) |
| 225 | dev_dbg(&dev->dev, " assign dma %d %d\n", idx, | 201 | goto __add; |
| 226 | (int) res->start); | ||
| 227 | return; | ||
| 228 | } | ||
| 229 | } | 202 | } |
| 230 | } | 203 | } |
| 231 | #ifdef MAX_DMA_CHANNELS | 204 | #ifdef MAX_DMA_CHANNELS |
| 232 | res->start = res->end = MAX_DMA_CHANNELS; | 205 | res->start = res->end = MAX_DMA_CHANNELS; |
| 233 | #endif | 206 | #endif |
| 234 | res->flags |= IORESOURCE_UNSET | IORESOURCE_DISABLED; | 207 | res->flags |= IORESOURCE_DISABLED; |
| 235 | dev_dbg(&dev->dev, " disable dma %d\n", idx); | 208 | dev_dbg(&dev->dev, " disable dma %d\n", idx); |
| 236 | } | ||
| 237 | |||
| 238 | void pnp_init_resource(struct resource *res) | ||
| 239 | { | ||
| 240 | unsigned long type; | ||
| 241 | |||
| 242 | type = res->flags & (IORESOURCE_IO | IORESOURCE_MEM | | ||
| 243 | IORESOURCE_IRQ | IORESOURCE_DMA); | ||
| 244 | 209 | ||
| 245 | res->name = NULL; | 210 | __add: |
| 246 | res->flags = type | IORESOURCE_AUTO | IORESOURCE_UNSET; | 211 | pnp_add_dma_resource(dev, res->start, res->flags); |
| 247 | if (type == IORESOURCE_IRQ || type == IORESOURCE_DMA) { | 212 | return 0; |
| 248 | res->start = -1; | ||
| 249 | res->end = -1; | ||
| 250 | } else { | ||
| 251 | res->start = 0; | ||
| 252 | res->end = 0; | ||
| 253 | } | ||
| 254 | } | 213 | } |
| 255 | 214 | ||
| 256 | /** | ||
| 257 | * pnp_init_resources - Resets a resource table to default values. | ||
| 258 | * @table: pointer to the desired resource table | ||
| 259 | */ | ||
| 260 | void pnp_init_resources(struct pnp_dev *dev) | 215 | void pnp_init_resources(struct pnp_dev *dev) |
| 261 | { | 216 | { |
| 262 | struct resource *res; | 217 | pnp_free_resources(dev); |
| 263 | int idx; | ||
| 264 | |||
| 265 | for (idx = 0; idx < PNP_MAX_IRQ; idx++) { | ||
| 266 | res = &dev->res->irq[idx].res; | ||
| 267 | res->flags = IORESOURCE_IRQ; | ||
| 268 | pnp_init_resource(res); | ||
| 269 | } | ||
| 270 | for (idx = 0; idx < PNP_MAX_DMA; idx++) { | ||
| 271 | res = &dev->res->dma[idx].res; | ||
| 272 | res->flags = IORESOURCE_DMA; | ||
| 273 | pnp_init_resource(res); | ||
| 274 | } | ||
| 275 | for (idx = 0; idx < PNP_MAX_PORT; idx++) { | ||
| 276 | res = &dev->res->port[idx].res; | ||
| 277 | res->flags = IORESOURCE_IO; | ||
| 278 | pnp_init_resource(res); | ||
| 279 | } | ||
| 280 | for (idx = 0; idx < PNP_MAX_MEM; idx++) { | ||
| 281 | res = &dev->res->mem[idx].res; | ||
| 282 | res->flags = IORESOURCE_MEM; | ||
| 283 | pnp_init_resource(res); | ||
| 284 | } | ||
| 285 | } | 218 | } |
| 286 | 219 | ||
| 287 | /** | ||
| 288 | * pnp_clean_resources - clears resources that were not manually set | ||
| 289 | * @res: the resources to clean | ||
| 290 | */ | ||
| 291 | static void pnp_clean_resource_table(struct pnp_dev *dev) | 220 | static void pnp_clean_resource_table(struct pnp_dev *dev) |
| 292 | { | 221 | { |
| 293 | struct resource *res; | 222 | struct pnp_resource *pnp_res, *tmp; |
| 294 | int idx; | 223 | |
| 295 | 224 | list_for_each_entry_safe(pnp_res, tmp, &dev->resources, list) { | |
| 296 | for (idx = 0; idx < PNP_MAX_IRQ; idx++) { | 225 | if (pnp_res->res.flags & IORESOURCE_AUTO) |
| 297 | res = &dev->res->irq[idx].res; | 226 | pnp_free_resource(pnp_res); |
| 298 | if (res->flags & IORESOURCE_AUTO) { | ||
| 299 | res->flags = IORESOURCE_IRQ; | ||
| 300 | pnp_init_resource(res); | ||
| 301 | } | ||
| 302 | } | ||
| 303 | for (idx = 0; idx < PNP_MAX_DMA; idx++) { | ||
| 304 | res = &dev->res->dma[idx].res; | ||
| 305 | if (res->flags & IORESOURCE_AUTO) { | ||
| 306 | res->flags = IORESOURCE_DMA; | ||
| 307 | pnp_init_resource(res); | ||
| 308 | } | ||
| 309 | } | ||
| 310 | for (idx = 0; idx < PNP_MAX_PORT; idx++) { | ||
| 311 | res = &dev->res->port[idx].res; | ||
| 312 | if (res->flags & IORESOURCE_AUTO) { | ||
| 313 | res->flags = IORESOURCE_IO; | ||
| 314 | pnp_init_resource(res); | ||
| 315 | } | ||
| 316 | } | ||
| 317 | for (idx = 0; idx < PNP_MAX_MEM; idx++) { | ||
| 318 | res = &dev->res->mem[idx].res; | ||
| 319 | if (res->flags & IORESOURCE_AUTO) { | ||
| 320 | res->flags = IORESOURCE_MEM; | ||
| 321 | pnp_init_resource(res); | ||
| 322 | } | ||
| 323 | } | 227 | } |
| 324 | } | 228 | } |
| 325 | 229 | ||
| 326 | /** | 230 | /** |
| 327 | * pnp_assign_resources - assigns resources to the device based on the specified dependent number | 231 | * pnp_assign_resources - assigns resources to the device based on the specified dependent number |
| 328 | * @dev: pointer to the desired device | 232 | * @dev: pointer to the desired device |
| 329 | * @depnum: the dependent function number | 233 | * @set: the dependent function number |
| 330 | * | ||
| 331 | * Only set depnum to 0 if the device does not have dependent options. | ||
| 332 | */ | 234 | */ |
| 333 | static int pnp_assign_resources(struct pnp_dev *dev, int depnum) | 235 | static int pnp_assign_resources(struct pnp_dev *dev, int set) |
| 334 | { | 236 | { |
| 335 | struct pnp_port *port; | 237 | struct pnp_option *option; |
| 336 | struct pnp_mem *mem; | ||
| 337 | struct pnp_irq *irq; | ||
| 338 | struct pnp_dma *dma; | ||
| 339 | int nport = 0, nmem = 0, nirq = 0, ndma = 0; | 238 | int nport = 0, nmem = 0, nirq = 0, ndma = 0; |
| 239 | int ret = 0; | ||
| 340 | 240 | ||
| 341 | if (!pnp_can_configure(dev)) | 241 | dev_dbg(&dev->dev, "pnp_assign_resources, try dependent set %d\n", set); |
| 342 | return -ENODEV; | ||
| 343 | |||
| 344 | dbg_pnp_show_resources(dev, "before pnp_assign_resources"); | ||
| 345 | mutex_lock(&pnp_res_mutex); | 242 | mutex_lock(&pnp_res_mutex); |
| 346 | pnp_clean_resource_table(dev); | 243 | pnp_clean_resource_table(dev); |
| 347 | if (dev->independent) { | ||
| 348 | dev_dbg(&dev->dev, "assigning independent options\n"); | ||
| 349 | port = dev->independent->port; | ||
| 350 | mem = dev->independent->mem; | ||
| 351 | irq = dev->independent->irq; | ||
| 352 | dma = dev->independent->dma; | ||
| 353 | while (port) { | ||
| 354 | if (!pnp_assign_port(dev, port, nport)) | ||
| 355 | goto fail; | ||
| 356 | nport++; | ||
| 357 | port = port->next; | ||
| 358 | } | ||
| 359 | while (mem) { | ||
| 360 | if (!pnp_assign_mem(dev, mem, nmem)) | ||
| 361 | goto fail; | ||
| 362 | nmem++; | ||
| 363 | mem = mem->next; | ||
| 364 | } | ||
| 365 | while (irq) { | ||
| 366 | if (!pnp_assign_irq(dev, irq, nirq)) | ||
| 367 | goto fail; | ||
| 368 | nirq++; | ||
| 369 | irq = irq->next; | ||
| 370 | } | ||
| 371 | while (dma) { | ||
| 372 | pnp_assign_dma(dev, dma, ndma); | ||
| 373 | ndma++; | ||
| 374 | dma = dma->next; | ||
| 375 | } | ||
| 376 | } | ||
| 377 | 244 | ||
| 378 | if (depnum) { | 245 | list_for_each_entry(option, &dev->options, list) { |
| 379 | struct pnp_option *dep; | 246 | if (pnp_option_is_dependent(option) && |
| 380 | int i; | 247 | pnp_option_set(option) != set) |
| 381 | 248 | continue; | |
| 382 | dev_dbg(&dev->dev, "assigning dependent option %d\n", depnum); | 249 | |
| 383 | for (i = 1, dep = dev->dependent; i < depnum; | 250 | switch (option->type) { |
| 384 | i++, dep = dep->next) | 251 | case IORESOURCE_IO: |
| 385 | if (!dep) | 252 | ret = pnp_assign_port(dev, &option->u.port, nport++); |
| 386 | goto fail; | 253 | break; |
| 387 | port = dep->port; | 254 | case IORESOURCE_MEM: |
| 388 | mem = dep->mem; | 255 | ret = pnp_assign_mem(dev, &option->u.mem, nmem++); |
| 389 | irq = dep->irq; | 256 | break; |
| 390 | dma = dep->dma; | 257 | case IORESOURCE_IRQ: |
| 391 | while (port) { | 258 | ret = pnp_assign_irq(dev, &option->u.irq, nirq++); |
| 392 | if (!pnp_assign_port(dev, port, nport)) | 259 | break; |
| 393 | goto fail; | 260 | case IORESOURCE_DMA: |
| 394 | nport++; | 261 | ret = pnp_assign_dma(dev, &option->u.dma, ndma++); |
| 395 | port = port->next; | 262 | break; |
| 396 | } | 263 | default: |
| 397 | while (mem) { | 264 | ret = -EINVAL; |
| 398 | if (!pnp_assign_mem(dev, mem, nmem)) | 265 | break; |
| 399 | goto fail; | ||
| 400 | nmem++; | ||
| 401 | mem = mem->next; | ||
| 402 | } | ||
| 403 | while (irq) { | ||
| 404 | if (!pnp_assign_irq(dev, irq, nirq)) | ||
| 405 | goto fail; | ||
| 406 | nirq++; | ||
| 407 | irq = irq->next; | ||
| 408 | } | 266 | } |
| 409 | while (dma) { | 267 | if (ret < 0) |
| 410 | pnp_assign_dma(dev, dma, ndma); | 268 | break; |
| 411 | ndma++; | 269 | } |
| 412 | dma = dma->next; | ||
| 413 | } | ||
| 414 | } else if (dev->dependent) | ||
| 415 | goto fail; | ||
| 416 | |||
| 417 | mutex_unlock(&pnp_res_mutex); | ||
| 418 | dbg_pnp_show_resources(dev, "after pnp_assign_resources"); | ||
| 419 | return 1; | ||
| 420 | 270 | ||
| 421 | fail: | ||
| 422 | pnp_clean_resource_table(dev); | ||
| 423 | mutex_unlock(&pnp_res_mutex); | 271 | mutex_unlock(&pnp_res_mutex); |
| 424 | dbg_pnp_show_resources(dev, "after pnp_assign_resources (failed)"); | 272 | if (ret < 0) { |
| 425 | return 0; | 273 | dev_dbg(&dev->dev, "pnp_assign_resources failed (%d)\n", ret); |
| 274 | pnp_clean_resource_table(dev); | ||
| 275 | } else | ||
| 276 | dbg_pnp_show_resources(dev, "pnp_assign_resources succeeded"); | ||
| 277 | return ret; | ||
| 426 | } | 278 | } |
| 427 | 279 | ||
| 428 | /** | 280 | /** |
| @@ -431,29 +283,25 @@ fail: | |||
| 431 | */ | 283 | */ |
| 432 | int pnp_auto_config_dev(struct pnp_dev *dev) | 284 | int pnp_auto_config_dev(struct pnp_dev *dev) |
| 433 | { | 285 | { |
| 434 | struct pnp_option *dep; | 286 | int i, ret; |
| 435 | int i = 1; | ||
| 436 | 287 | ||
| 437 | if (!pnp_can_configure(dev)) { | 288 | if (!pnp_can_configure(dev)) { |
| 438 | dev_dbg(&dev->dev, "configuration not supported\n"); | 289 | dev_dbg(&dev->dev, "configuration not supported\n"); |
| 439 | return -ENODEV; | 290 | return -ENODEV; |
| 440 | } | 291 | } |
| 441 | 292 | ||
| 442 | if (!dev->dependent) { | 293 | ret = pnp_assign_resources(dev, 0); |
| 443 | if (pnp_assign_resources(dev, 0)) | 294 | if (ret == 0) |
| 295 | return 0; | ||
| 296 | |||
| 297 | for (i = 1; i < dev->num_dependent_sets; i++) { | ||
| 298 | ret = pnp_assign_resources(dev, i); | ||
| 299 | if (ret == 0) | ||
| 444 | return 0; | 300 | return 0; |
| 445 | } else { | ||
| 446 | dep = dev->dependent; | ||
| 447 | do { | ||
| 448 | if (pnp_assign_resources(dev, i)) | ||
| 449 | return 0; | ||
| 450 | dep = dep->next; | ||
| 451 | i++; | ||
| 452 | } while (dep); | ||
| 453 | } | 301 | } |
| 454 | 302 | ||
| 455 | dev_err(&dev->dev, "unable to assign resources\n"); | 303 | dev_err(&dev->dev, "unable to assign resources\n"); |
| 456 | return -EBUSY; | 304 | return ret; |
| 457 | } | 305 | } |
| 458 | 306 | ||
| 459 | /** | 307 | /** |
