Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * manager.c - Resource Management, Conflict Resolution, Activation and Disabling of Devices |
| 3 | * |
Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 4 | * based on isapnp.c resource management (c) Jaroslav Kysela <perex@perex.cz> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * Copyright 2003 Adam Belay <ambx1@neo.rr.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include <linux/errno.h> |
| 9 | #include <linux/module.h> |
| 10 | #include <linux/init.h> |
| 11 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/pnp.h> |
Tim Schmielau | 4e57b68 | 2005-10-30 15:03:48 -0800 | [diff] [blame] | 13 | #include <linux/slab.h> |
| 14 | #include <linux/bitmap.h> |
Daniel Walker | b3bd86e | 2008-02-06 01:40:04 -0800 | [diff] [blame] | 15 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include "base.h" |
| 17 | |
Daniel Walker | b3bd86e | 2008-02-06 01:40:04 -0800 | [diff] [blame] | 18 | DEFINE_MUTEX(pnp_res_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
| 20 | static int pnp_assign_port(struct pnp_dev *dev, struct pnp_port *rule, int idx) |
| 21 | { |
Bjorn Helgaas | 21855d6 | 2008-04-28 16:34:32 -0600 | [diff] [blame] | 22 | struct pnp_resource *pnp_res; |
Bjorn Helgaas | 28ccffc | 2008-04-28 16:34:18 -0600 | [diff] [blame] | 23 | struct resource *res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
Bjorn Helgaas | 21855d6 | 2008-04-28 16:34:32 -0600 | [diff] [blame] | 25 | pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_IO, idx); |
| 26 | if (!pnp_res) { |
Bjorn Helgaas | a05d078 | 2007-10-16 23:31:10 -0700 | [diff] [blame] | 27 | dev_err(&dev->dev, "too many I/O port resources\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | /* pretend we were successful so at least the manager won't try again */ |
| 29 | return 1; |
| 30 | } |
| 31 | |
Bjorn Helgaas | 21855d6 | 2008-04-28 16:34:32 -0600 | [diff] [blame] | 32 | res = &pnp_res->res; |
| 33 | |
Bjorn Helgaas | 81b5c75 | 2008-04-28 16:34:08 -0600 | [diff] [blame] | 34 | /* check if this resource has been manually set, if so skip */ |
Bjorn Helgaas | 28ccffc | 2008-04-28 16:34:18 -0600 | [diff] [blame] | 35 | if (!(res->flags & IORESOURCE_AUTO)) { |
Bjorn Helgaas | 81b5c75 | 2008-04-28 16:34:08 -0600 | [diff] [blame] | 36 | dev_dbg(&dev->dev, " io %d already set to %#llx-%#llx " |
Bjorn Helgaas | 28ccffc | 2008-04-28 16:34:18 -0600 | [diff] [blame] | 37 | "flags %#lx\n", idx, (unsigned long long) res->start, |
| 38 | (unsigned long long) res->end, res->flags); |
Bjorn Helgaas | 81b5c75 | 2008-04-28 16:34:08 -0600 | [diff] [blame] | 39 | return 1; |
| 40 | } |
| 41 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | /* set the initial values */ |
Bjorn Helgaas | 21855d6 | 2008-04-28 16:34:32 -0600 | [diff] [blame] | 43 | pnp_res->index = idx; |
Bjorn Helgaas | 28ccffc | 2008-04-28 16:34:18 -0600 | [diff] [blame] | 44 | res->flags |= rule->flags | IORESOURCE_IO; |
| 45 | res->flags &= ~IORESOURCE_UNSET; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
| 47 | if (!rule->size) { |
Bjorn Helgaas | 28ccffc | 2008-04-28 16:34:18 -0600 | [diff] [blame] | 48 | res->flags |= IORESOURCE_DISABLED; |
Bjorn Helgaas | 81b5c75 | 2008-04-28 16:34:08 -0600 | [diff] [blame] | 49 | dev_dbg(&dev->dev, " io %d disabled\n", idx); |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 50 | return 1; /* skip disabled resource requests */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | } |
| 52 | |
Bjorn Helgaas | 28ccffc | 2008-04-28 16:34:18 -0600 | [diff] [blame] | 53 | res->start = rule->min; |
| 54 | res->end = res->start + rule->size - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
| 56 | /* run through until pnp_check_port is happy */ |
Bjorn Helgaas | f5d94ff | 2008-04-28 16:34:22 -0600 | [diff] [blame] | 57 | while (!pnp_check_port(dev, res)) { |
Bjorn Helgaas | 28ccffc | 2008-04-28 16:34:18 -0600 | [diff] [blame] | 58 | res->start += rule->align; |
| 59 | res->end = res->start + rule->size - 1; |
| 60 | if (res->start > rule->max || !rule->align) { |
Bjorn Helgaas | 81b5c75 | 2008-04-28 16:34:08 -0600 | [diff] [blame] | 61 | dev_dbg(&dev->dev, " couldn't assign io %d\n", idx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | return 0; |
Bjorn Helgaas | 81b5c75 | 2008-04-28 16:34:08 -0600 | [diff] [blame] | 63 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | } |
Bjorn Helgaas | 81b5c75 | 2008-04-28 16:34:08 -0600 | [diff] [blame] | 65 | dev_dbg(&dev->dev, " assign io %d %#llx-%#llx\n", idx, |
Bjorn Helgaas | 28ccffc | 2008-04-28 16:34:18 -0600 | [diff] [blame] | 66 | (unsigned long long) res->start, (unsigned long long) res->end); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | return 1; |
| 68 | } |
| 69 | |
| 70 | static int pnp_assign_mem(struct pnp_dev *dev, struct pnp_mem *rule, int idx) |
| 71 | { |
Bjorn Helgaas | 21855d6 | 2008-04-28 16:34:32 -0600 | [diff] [blame] | 72 | struct pnp_resource *pnp_res; |
Bjorn Helgaas | 28ccffc | 2008-04-28 16:34:18 -0600 | [diff] [blame] | 73 | struct resource *res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
Bjorn Helgaas | 21855d6 | 2008-04-28 16:34:32 -0600 | [diff] [blame] | 75 | pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_MEM, idx); |
| 76 | if (!pnp_res) { |
Bjorn Helgaas | a05d078 | 2007-10-16 23:31:10 -0700 | [diff] [blame] | 77 | dev_err(&dev->dev, "too many memory resources\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | /* pretend we were successful so at least the manager won't try again */ |
| 79 | return 1; |
| 80 | } |
| 81 | |
Bjorn Helgaas | 21855d6 | 2008-04-28 16:34:32 -0600 | [diff] [blame] | 82 | res = &pnp_res->res; |
| 83 | |
Bjorn Helgaas | 81b5c75 | 2008-04-28 16:34:08 -0600 | [diff] [blame] | 84 | /* check if this resource has been manually set, if so skip */ |
Bjorn Helgaas | 28ccffc | 2008-04-28 16:34:18 -0600 | [diff] [blame] | 85 | if (!(res->flags & IORESOURCE_AUTO)) { |
Bjorn Helgaas | 81b5c75 | 2008-04-28 16:34:08 -0600 | [diff] [blame] | 86 | dev_dbg(&dev->dev, " mem %d already set to %#llx-%#llx " |
Bjorn Helgaas | 28ccffc | 2008-04-28 16:34:18 -0600 | [diff] [blame] | 87 | "flags %#lx\n", idx, (unsigned long long) res->start, |
| 88 | (unsigned long long) res->end, res->flags); |
Bjorn Helgaas | 81b5c75 | 2008-04-28 16:34:08 -0600 | [diff] [blame] | 89 | return 1; |
| 90 | } |
| 91 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | /* set the initial values */ |
Bjorn Helgaas | 21855d6 | 2008-04-28 16:34:32 -0600 | [diff] [blame] | 93 | pnp_res->index = idx; |
Bjorn Helgaas | 28ccffc | 2008-04-28 16:34:18 -0600 | [diff] [blame] | 94 | res->flags |= rule->flags | IORESOURCE_MEM; |
| 95 | res->flags &= ~IORESOURCE_UNSET; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | |
| 97 | /* convert pnp flags to standard Linux flags */ |
| 98 | if (!(rule->flags & IORESOURCE_MEM_WRITEABLE)) |
Bjorn Helgaas | 28ccffc | 2008-04-28 16:34:18 -0600 | [diff] [blame] | 99 | res->flags |= IORESOURCE_READONLY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | if (rule->flags & IORESOURCE_MEM_CACHEABLE) |
Bjorn Helgaas | 28ccffc | 2008-04-28 16:34:18 -0600 | [diff] [blame] | 101 | res->flags |= IORESOURCE_CACHEABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | if (rule->flags & IORESOURCE_MEM_RANGELENGTH) |
Bjorn Helgaas | 28ccffc | 2008-04-28 16:34:18 -0600 | [diff] [blame] | 103 | res->flags |= IORESOURCE_RANGELENGTH; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | if (rule->flags & IORESOURCE_MEM_SHADOWABLE) |
Bjorn Helgaas | 28ccffc | 2008-04-28 16:34:18 -0600 | [diff] [blame] | 105 | res->flags |= IORESOURCE_SHADOWABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
| 107 | if (!rule->size) { |
Bjorn Helgaas | 28ccffc | 2008-04-28 16:34:18 -0600 | [diff] [blame] | 108 | res->flags |= IORESOURCE_DISABLED; |
Bjorn Helgaas | 81b5c75 | 2008-04-28 16:34:08 -0600 | [diff] [blame] | 109 | dev_dbg(&dev->dev, " mem %d disabled\n", idx); |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 110 | return 1; /* skip disabled resource requests */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Bjorn Helgaas | 28ccffc | 2008-04-28 16:34:18 -0600 | [diff] [blame] | 113 | res->start = rule->min; |
| 114 | res->end = res->start + rule->size - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | |
| 116 | /* run through until pnp_check_mem is happy */ |
Bjorn Helgaas | f5d94ff | 2008-04-28 16:34:22 -0600 | [diff] [blame] | 117 | while (!pnp_check_mem(dev, res)) { |
Bjorn Helgaas | 28ccffc | 2008-04-28 16:34:18 -0600 | [diff] [blame] | 118 | res->start += rule->align; |
| 119 | res->end = res->start + rule->size - 1; |
| 120 | if (res->start > rule->max || !rule->align) { |
Bjorn Helgaas | 81b5c75 | 2008-04-28 16:34:08 -0600 | [diff] [blame] | 121 | dev_dbg(&dev->dev, " couldn't assign mem %d\n", idx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | return 0; |
Bjorn Helgaas | 81b5c75 | 2008-04-28 16:34:08 -0600 | [diff] [blame] | 123 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | } |
Bjorn Helgaas | 81b5c75 | 2008-04-28 16:34:08 -0600 | [diff] [blame] | 125 | dev_dbg(&dev->dev, " assign mem %d %#llx-%#llx\n", idx, |
Bjorn Helgaas | 28ccffc | 2008-04-28 16:34:18 -0600 | [diff] [blame] | 126 | (unsigned long long) res->start, (unsigned long long) res->end); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | return 1; |
| 128 | } |
| 129 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 130 | static int pnp_assign_irq(struct pnp_dev *dev, struct pnp_irq *rule, int idx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | { |
Bjorn Helgaas | 21855d6 | 2008-04-28 16:34:32 -0600 | [diff] [blame] | 132 | struct pnp_resource *pnp_res; |
Bjorn Helgaas | 28ccffc | 2008-04-28 16:34:18 -0600 | [diff] [blame] | 133 | struct resource *res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | int i; |
| 135 | |
| 136 | /* IRQ priority: this table is good for i386 */ |
| 137 | static unsigned short xtab[16] = { |
| 138 | 5, 10, 11, 12, 9, 14, 15, 7, 3, 4, 13, 0, 1, 6, 8, 2 |
| 139 | }; |
| 140 | |
Bjorn Helgaas | 21855d6 | 2008-04-28 16:34:32 -0600 | [diff] [blame] | 141 | pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_IRQ, idx); |
| 142 | if (!pnp_res) { |
Bjorn Helgaas | a05d078 | 2007-10-16 23:31:10 -0700 | [diff] [blame] | 143 | dev_err(&dev->dev, "too many IRQ resources\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | /* pretend we were successful so at least the manager won't try again */ |
| 145 | return 1; |
| 146 | } |
| 147 | |
Bjorn Helgaas | 21855d6 | 2008-04-28 16:34:32 -0600 | [diff] [blame] | 148 | res = &pnp_res->res; |
| 149 | |
Bjorn Helgaas | 81b5c75 | 2008-04-28 16:34:08 -0600 | [diff] [blame] | 150 | /* check if this resource has been manually set, if so skip */ |
Bjorn Helgaas | 28ccffc | 2008-04-28 16:34:18 -0600 | [diff] [blame] | 151 | if (!(res->flags & IORESOURCE_AUTO)) { |
Bjorn Helgaas | 81b5c75 | 2008-04-28 16:34:08 -0600 | [diff] [blame] | 152 | dev_dbg(&dev->dev, " irq %d already set to %d flags %#lx\n", |
Bjorn Helgaas | 28ccffc | 2008-04-28 16:34:18 -0600 | [diff] [blame] | 153 | idx, (int) res->start, res->flags); |
Bjorn Helgaas | 81b5c75 | 2008-04-28 16:34:08 -0600 | [diff] [blame] | 154 | return 1; |
| 155 | } |
| 156 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | /* set the initial values */ |
Bjorn Helgaas | 21855d6 | 2008-04-28 16:34:32 -0600 | [diff] [blame] | 158 | pnp_res->index = idx; |
Bjorn Helgaas | 28ccffc | 2008-04-28 16:34:18 -0600 | [diff] [blame] | 159 | res->flags |= rule->flags | IORESOURCE_IRQ; |
| 160 | res->flags &= ~IORESOURCE_UNSET; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
| 162 | if (bitmap_empty(rule->map, PNP_IRQ_NR)) { |
Bjorn Helgaas | 28ccffc | 2008-04-28 16:34:18 -0600 | [diff] [blame] | 163 | res->flags |= IORESOURCE_DISABLED; |
Bjorn Helgaas | 81b5c75 | 2008-04-28 16:34:08 -0600 | [diff] [blame] | 164 | dev_dbg(&dev->dev, " irq %d disabled\n", idx); |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 165 | return 1; /* skip disabled resource requests */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | /* TBD: need check for >16 IRQ */ |
Bjorn Helgaas | 28ccffc | 2008-04-28 16:34:18 -0600 | [diff] [blame] | 169 | res->start = find_next_bit(rule->map, PNP_IRQ_NR, 16); |
| 170 | if (res->start < PNP_IRQ_NR) { |
| 171 | res->end = res->start; |
| 172 | dev_dbg(&dev->dev, " assign irq %d %d\n", idx, |
| 173 | (int) res->start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | return 1; |
| 175 | } |
| 176 | for (i = 0; i < 16; i++) { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 177 | if (test_bit(xtab[i], rule->map)) { |
Bjorn Helgaas | 28ccffc | 2008-04-28 16:34:18 -0600 | [diff] [blame] | 178 | res->start = res->end = xtab[i]; |
Bjorn Helgaas | f5d94ff | 2008-04-28 16:34:22 -0600 | [diff] [blame] | 179 | if (pnp_check_irq(dev, res)) { |
Bjorn Helgaas | 81b5c75 | 2008-04-28 16:34:08 -0600 | [diff] [blame] | 180 | dev_dbg(&dev->dev, " assign irq %d %d\n", idx, |
Bjorn Helgaas | 28ccffc | 2008-04-28 16:34:18 -0600 | [diff] [blame] | 181 | (int) res->start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | return 1; |
Bjorn Helgaas | 81b5c75 | 2008-04-28 16:34:08 -0600 | [diff] [blame] | 183 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | } |
| 185 | } |
Bjorn Helgaas | 81b5c75 | 2008-04-28 16:34:08 -0600 | [diff] [blame] | 186 | dev_dbg(&dev->dev, " couldn't assign irq %d\n", idx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | return 0; |
| 188 | } |
| 189 | |
Jan Beulich | 7ef3639 | 2007-10-16 23:31:07 -0700 | [diff] [blame] | 190 | static void pnp_assign_dma(struct pnp_dev *dev, struct pnp_dma *rule, int idx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | { |
Bjorn Helgaas | 21855d6 | 2008-04-28 16:34:32 -0600 | [diff] [blame] | 192 | struct pnp_resource *pnp_res; |
Bjorn Helgaas | 28ccffc | 2008-04-28 16:34:18 -0600 | [diff] [blame] | 193 | struct resource *res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | int i; |
| 195 | |
| 196 | /* DMA priority: this table is good for i386 */ |
| 197 | static unsigned short xtab[8] = { |
| 198 | 1, 3, 5, 6, 7, 0, 2, 4 |
| 199 | }; |
| 200 | |
Bjorn Helgaas | 21855d6 | 2008-04-28 16:34:32 -0600 | [diff] [blame] | 201 | pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_DMA, idx); |
| 202 | if (!pnp_res) { |
Bjorn Helgaas | a05d078 | 2007-10-16 23:31:10 -0700 | [diff] [blame] | 203 | dev_err(&dev->dev, "too many DMA resources\n"); |
Jan Beulich | 7ef3639 | 2007-10-16 23:31:07 -0700 | [diff] [blame] | 204 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Bjorn Helgaas | 21855d6 | 2008-04-28 16:34:32 -0600 | [diff] [blame] | 207 | res = &pnp_res->res; |
| 208 | |
Bjorn Helgaas | 81b5c75 | 2008-04-28 16:34:08 -0600 | [diff] [blame] | 209 | /* check if this resource has been manually set, if so skip */ |
Bjorn Helgaas | 28ccffc | 2008-04-28 16:34:18 -0600 | [diff] [blame] | 210 | if (!(res->flags & IORESOURCE_AUTO)) { |
Bjorn Helgaas | 81b5c75 | 2008-04-28 16:34:08 -0600 | [diff] [blame] | 211 | dev_dbg(&dev->dev, " dma %d already set to %d flags %#lx\n", |
Bjorn Helgaas | 28ccffc | 2008-04-28 16:34:18 -0600 | [diff] [blame] | 212 | idx, (int) res->start, res->flags); |
Bjorn Helgaas | 81b5c75 | 2008-04-28 16:34:08 -0600 | [diff] [blame] | 213 | return; |
| 214 | } |
| 215 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | /* set the initial values */ |
Bjorn Helgaas | 21855d6 | 2008-04-28 16:34:32 -0600 | [diff] [blame] | 217 | pnp_res->index = idx; |
Bjorn Helgaas | 28ccffc | 2008-04-28 16:34:18 -0600 | [diff] [blame] | 218 | res->flags |= rule->flags | IORESOURCE_DMA; |
| 219 | res->flags &= ~IORESOURCE_UNSET; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | for (i = 0; i < 8; i++) { |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 222 | if (rule->map & (1 << xtab[i])) { |
Bjorn Helgaas | 28ccffc | 2008-04-28 16:34:18 -0600 | [diff] [blame] | 223 | res->start = res->end = xtab[i]; |
Bjorn Helgaas | f5d94ff | 2008-04-28 16:34:22 -0600 | [diff] [blame] | 224 | if (pnp_check_dma(dev, res)) { |
Bjorn Helgaas | 81b5c75 | 2008-04-28 16:34:08 -0600 | [diff] [blame] | 225 | dev_dbg(&dev->dev, " assign dma %d %d\n", idx, |
Bjorn Helgaas | 28ccffc | 2008-04-28 16:34:18 -0600 | [diff] [blame] | 226 | (int) res->start); |
Jan Beulich | 7ef3639 | 2007-10-16 23:31:07 -0700 | [diff] [blame] | 227 | return; |
Bjorn Helgaas | 81b5c75 | 2008-04-28 16:34:08 -0600 | [diff] [blame] | 228 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | } |
| 230 | } |
Jan Beulich | 7ef3639 | 2007-10-16 23:31:07 -0700 | [diff] [blame] | 231 | #ifdef MAX_DMA_CHANNELS |
Bjorn Helgaas | 28ccffc | 2008-04-28 16:34:18 -0600 | [diff] [blame] | 232 | res->start = res->end = MAX_DMA_CHANNELS; |
Jan Beulich | 7ef3639 | 2007-10-16 23:31:07 -0700 | [diff] [blame] | 233 | #endif |
Bjorn Helgaas | 28ccffc | 2008-04-28 16:34:18 -0600 | [diff] [blame] | 234 | res->flags |= IORESOURCE_UNSET | IORESOURCE_DISABLED; |
Bjorn Helgaas | 81b5c75 | 2008-04-28 16:34:08 -0600 | [diff] [blame] | 235 | dev_dbg(&dev->dev, " disable dma %d\n", idx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | } |
| 237 | |
Bjorn Helgaas | d948a8d | 2008-04-28 16:34:13 -0600 | [diff] [blame] | 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 | |
| 245 | res->name = NULL; |
| 246 | res->flags = type | IORESOURCE_AUTO | IORESOURCE_UNSET; |
| 247 | if (type == IORESOURCE_IRQ || type == IORESOURCE_DMA) { |
| 248 | res->start = -1; |
| 249 | res->end = -1; |
| 250 | } else { |
| 251 | res->start = 0; |
| 252 | res->end = 0; |
| 253 | } |
| 254 | } |
| 255 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | /** |
| 257 | * pnp_init_resources - Resets a resource table to default values. |
| 258 | * @table: pointer to the desired resource table |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | */ |
Bjorn Helgaas | 2cd139309 | 2008-04-28 16:34:11 -0600 | [diff] [blame] | 260 | void pnp_init_resources(struct pnp_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | { |
Bjorn Helgaas | d948a8d | 2008-04-28 16:34:13 -0600 | [diff] [blame] | 262 | struct resource *res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | int idx; |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 264 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | for (idx = 0; idx < PNP_MAX_IRQ; idx++) { |
Bjorn Helgaas | 784f01d | 2008-04-28 16:34:30 -0600 | [diff] [blame] | 266 | res = &dev->res->irq[idx].res; |
Bjorn Helgaas | d948a8d | 2008-04-28 16:34:13 -0600 | [diff] [blame] | 267 | res->flags = IORESOURCE_IRQ; |
| 268 | pnp_init_resource(res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | } |
| 270 | for (idx = 0; idx < PNP_MAX_DMA; idx++) { |
Bjorn Helgaas | 784f01d | 2008-04-28 16:34:30 -0600 | [diff] [blame] | 271 | res = &dev->res->dma[idx].res; |
Bjorn Helgaas | d948a8d | 2008-04-28 16:34:13 -0600 | [diff] [blame] | 272 | res->flags = IORESOURCE_DMA; |
| 273 | pnp_init_resource(res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | } |
| 275 | for (idx = 0; idx < PNP_MAX_PORT; idx++) { |
Bjorn Helgaas | 784f01d | 2008-04-28 16:34:30 -0600 | [diff] [blame] | 276 | res = &dev->res->port[idx].res; |
Bjorn Helgaas | d948a8d | 2008-04-28 16:34:13 -0600 | [diff] [blame] | 277 | res->flags = IORESOURCE_IO; |
| 278 | pnp_init_resource(res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | } |
| 280 | for (idx = 0; idx < PNP_MAX_MEM; idx++) { |
Bjorn Helgaas | 784f01d | 2008-04-28 16:34:30 -0600 | [diff] [blame] | 281 | res = &dev->res->mem[idx].res; |
Bjorn Helgaas | d948a8d | 2008-04-28 16:34:13 -0600 | [diff] [blame] | 282 | res->flags = IORESOURCE_MEM; |
| 283 | pnp_init_resource(res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | } |
| 285 | } |
| 286 | |
| 287 | /** |
| 288 | * pnp_clean_resources - clears resources that were not manually set |
Martin Waitz | 67be2dd | 2005-05-01 08:59:26 -0700 | [diff] [blame] | 289 | * @res: the resources to clean |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | */ |
Bjorn Helgaas | 6969c7e | 2008-04-28 16:34:10 -0600 | [diff] [blame] | 291 | static void pnp_clean_resource_table(struct pnp_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | { |
Bjorn Helgaas | d948a8d | 2008-04-28 16:34:13 -0600 | [diff] [blame] | 293 | struct resource *res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | int idx; |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 295 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | for (idx = 0; idx < PNP_MAX_IRQ; idx++) { |
Bjorn Helgaas | 784f01d | 2008-04-28 16:34:30 -0600 | [diff] [blame] | 297 | res = &dev->res->irq[idx].res; |
Bjorn Helgaas | d948a8d | 2008-04-28 16:34:13 -0600 | [diff] [blame] | 298 | if (res->flags & IORESOURCE_AUTO) { |
| 299 | res->flags = IORESOURCE_IRQ; |
| 300 | pnp_init_resource(res); |
| 301 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | } |
| 303 | for (idx = 0; idx < PNP_MAX_DMA; idx++) { |
Bjorn Helgaas | 784f01d | 2008-04-28 16:34:30 -0600 | [diff] [blame] | 304 | res = &dev->res->dma[idx].res; |
Bjorn Helgaas | d948a8d | 2008-04-28 16:34:13 -0600 | [diff] [blame] | 305 | if (res->flags & IORESOURCE_AUTO) { |
| 306 | res->flags = IORESOURCE_DMA; |
| 307 | pnp_init_resource(res); |
| 308 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | } |
| 310 | for (idx = 0; idx < PNP_MAX_PORT; idx++) { |
Bjorn Helgaas | 784f01d | 2008-04-28 16:34:30 -0600 | [diff] [blame] | 311 | res = &dev->res->port[idx].res; |
Bjorn Helgaas | d948a8d | 2008-04-28 16:34:13 -0600 | [diff] [blame] | 312 | if (res->flags & IORESOURCE_AUTO) { |
| 313 | res->flags = IORESOURCE_IO; |
| 314 | pnp_init_resource(res); |
| 315 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | } |
| 317 | for (idx = 0; idx < PNP_MAX_MEM; idx++) { |
Bjorn Helgaas | 784f01d | 2008-04-28 16:34:30 -0600 | [diff] [blame] | 318 | res = &dev->res->mem[idx].res; |
Bjorn Helgaas | d948a8d | 2008-04-28 16:34:13 -0600 | [diff] [blame] | 319 | if (res->flags & IORESOURCE_AUTO) { |
| 320 | res->flags = IORESOURCE_MEM; |
| 321 | pnp_init_resource(res); |
| 322 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | } |
| 324 | } |
| 325 | |
| 326 | /** |
| 327 | * pnp_assign_resources - assigns resources to the device based on the specified dependent number |
| 328 | * @dev: pointer to the desired device |
| 329 | * @depnum: the dependent function number |
| 330 | * |
| 331 | * Only set depnum to 0 if the device does not have dependent options. |
| 332 | */ |
| 333 | static int pnp_assign_resources(struct pnp_dev *dev, int depnum) |
| 334 | { |
| 335 | struct pnp_port *port; |
| 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; |
| 340 | |
| 341 | if (!pnp_can_configure(dev)) |
| 342 | return -ENODEV; |
| 343 | |
Bjorn Helgaas | 81b5c75 | 2008-04-28 16:34:08 -0600 | [diff] [blame] | 344 | dbg_pnp_show_resources(dev, "before pnp_assign_resources"); |
Daniel Walker | b3bd86e | 2008-02-06 01:40:04 -0800 | [diff] [blame] | 345 | mutex_lock(&pnp_res_mutex); |
Bjorn Helgaas | 6969c7e | 2008-04-28 16:34:10 -0600 | [diff] [blame] | 346 | pnp_clean_resource_table(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | if (dev->independent) { |
Bjorn Helgaas | 81b5c75 | 2008-04-28 16:34:08 -0600 | [diff] [blame] | 348 | dev_dbg(&dev->dev, "assigning independent options\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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) { |
Jan Beulich | 7ef3639 | 2007-10-16 23:31:07 -0700 | [diff] [blame] | 372 | pnp_assign_dma(dev, dma, ndma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | ndma++; |
| 374 | dma = dma->next; |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | if (depnum) { |
| 379 | struct pnp_option *dep; |
| 380 | int i; |
Bjorn Helgaas | 81b5c75 | 2008-04-28 16:34:08 -0600 | [diff] [blame] | 381 | |
| 382 | dev_dbg(&dev->dev, "assigning dependent option %d\n", depnum); |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 383 | for (i = 1, dep = dev->dependent; i < depnum; |
| 384 | i++, dep = dep->next) |
| 385 | if (!dep) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | goto fail; |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 387 | port = dep->port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | mem = dep->mem; |
| 389 | irq = dep->irq; |
| 390 | dma = dep->dma; |
| 391 | while (port) { |
| 392 | if (!pnp_assign_port(dev, port, nport)) |
| 393 | goto fail; |
| 394 | nport++; |
| 395 | port = port->next; |
| 396 | } |
| 397 | while (mem) { |
| 398 | if (!pnp_assign_mem(dev, mem, nmem)) |
| 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 | } |
| 409 | while (dma) { |
Jan Beulich | 7ef3639 | 2007-10-16 23:31:07 -0700 | [diff] [blame] | 410 | pnp_assign_dma(dev, dma, ndma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | ndma++; |
| 412 | dma = dma->next; |
| 413 | } |
| 414 | } else if (dev->dependent) |
| 415 | goto fail; |
| 416 | |
Daniel Walker | b3bd86e | 2008-02-06 01:40:04 -0800 | [diff] [blame] | 417 | mutex_unlock(&pnp_res_mutex); |
Bjorn Helgaas | 81b5c75 | 2008-04-28 16:34:08 -0600 | [diff] [blame] | 418 | dbg_pnp_show_resources(dev, "after pnp_assign_resources"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | return 1; |
| 420 | |
Bjorn Helgaas | 1e0aa9a | 2007-08-15 10:32:08 -0600 | [diff] [blame] | 421 | fail: |
Bjorn Helgaas | 6969c7e | 2008-04-28 16:34:10 -0600 | [diff] [blame] | 422 | pnp_clean_resource_table(dev); |
Daniel Walker | b3bd86e | 2008-02-06 01:40:04 -0800 | [diff] [blame] | 423 | mutex_unlock(&pnp_res_mutex); |
Bjorn Helgaas | 81b5c75 | 2008-04-28 16:34:08 -0600 | [diff] [blame] | 424 | dbg_pnp_show_resources(dev, "after pnp_assign_resources (failed)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | return 0; |
| 426 | } |
| 427 | |
| 428 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | * pnp_auto_config_dev - automatically assigns resources to a device |
| 430 | * @dev: pointer to the desired device |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | */ |
| 432 | int pnp_auto_config_dev(struct pnp_dev *dev) |
| 433 | { |
| 434 | struct pnp_option *dep; |
| 435 | int i = 1; |
| 436 | |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 437 | if (!pnp_can_configure(dev)) { |
Bjorn Helgaas | a05d078 | 2007-10-16 23:31:10 -0700 | [diff] [blame] | 438 | dev_dbg(&dev->dev, "configuration not supported\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | return -ENODEV; |
| 440 | } |
| 441 | |
| 442 | if (!dev->dependent) { |
| 443 | if (pnp_assign_resources(dev, 0)) |
| 444 | 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 | } |
| 454 | |
Bjorn Helgaas | a05d078 | 2007-10-16 23:31:10 -0700 | [diff] [blame] | 455 | dev_err(&dev->dev, "unable to assign resources\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | return -EBUSY; |
| 457 | } |
| 458 | |
| 459 | /** |
Pierre Ossman | 68094e3 | 2005-11-29 09:09:32 +0100 | [diff] [blame] | 460 | * pnp_start_dev - low-level start of the PnP device |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | * @dev: pointer to the desired device |
| 462 | * |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 463 | * assumes that resources have already been allocated |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | */ |
Pierre Ossman | 68094e3 | 2005-11-29 09:09:32 +0100 | [diff] [blame] | 465 | int pnp_start_dev(struct pnp_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | if (!pnp_can_write(dev)) { |
Bjorn Helgaas | a05d078 | 2007-10-16 23:31:10 -0700 | [diff] [blame] | 468 | dev_dbg(&dev->dev, "activation not supported\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | return -EINVAL; |
| 470 | } |
| 471 | |
Bjorn Helgaas | 81b5c75 | 2008-04-28 16:34:08 -0600 | [diff] [blame] | 472 | dbg_pnp_show_resources(dev, "pnp_start_dev"); |
Bjorn Helgaas | 59284cb | 2008-04-28 16:34:05 -0600 | [diff] [blame] | 473 | if (dev->protocol->set(dev) < 0) { |
Bjorn Helgaas | a05d078 | 2007-10-16 23:31:10 -0700 | [diff] [blame] | 474 | dev_err(&dev->dev, "activation failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | return -EIO; |
| 476 | } |
| 477 | |
Bjorn Helgaas | a05d078 | 2007-10-16 23:31:10 -0700 | [diff] [blame] | 478 | dev_info(&dev->dev, "activated\n"); |
Pierre Ossman | 68094e3 | 2005-11-29 09:09:32 +0100 | [diff] [blame] | 479 | return 0; |
| 480 | } |
| 481 | |
| 482 | /** |
| 483 | * pnp_stop_dev - low-level disable of the PnP device |
| 484 | * @dev: pointer to the desired device |
| 485 | * |
| 486 | * does not free resources |
| 487 | */ |
Pierre Ossman | 68094e3 | 2005-11-29 09:09:32 +0100 | [diff] [blame] | 488 | int pnp_stop_dev(struct pnp_dev *dev) |
| 489 | { |
| 490 | if (!pnp_can_disable(dev)) { |
Bjorn Helgaas | a05d078 | 2007-10-16 23:31:10 -0700 | [diff] [blame] | 491 | dev_dbg(&dev->dev, "disabling not supported\n"); |
Pierre Ossman | 68094e3 | 2005-11-29 09:09:32 +0100 | [diff] [blame] | 492 | return -EINVAL; |
| 493 | } |
Bjorn Helgaas | 9dd7846 | 2007-07-26 10:41:20 -0700 | [diff] [blame] | 494 | if (dev->protocol->disable(dev) < 0) { |
Bjorn Helgaas | a05d078 | 2007-10-16 23:31:10 -0700 | [diff] [blame] | 495 | dev_err(&dev->dev, "disable failed\n"); |
Pierre Ossman | 68094e3 | 2005-11-29 09:09:32 +0100 | [diff] [blame] | 496 | return -EIO; |
| 497 | } |
| 498 | |
Bjorn Helgaas | a05d078 | 2007-10-16 23:31:10 -0700 | [diff] [blame] | 499 | dev_info(&dev->dev, "disabled\n"); |
Pierre Ossman | 68094e3 | 2005-11-29 09:09:32 +0100 | [diff] [blame] | 500 | return 0; |
| 501 | } |
| 502 | |
| 503 | /** |
| 504 | * pnp_activate_dev - activates a PnP device for use |
| 505 | * @dev: pointer to the desired device |
| 506 | * |
| 507 | * does not validate or set resources so be careful. |
| 508 | */ |
| 509 | int pnp_activate_dev(struct pnp_dev *dev) |
| 510 | { |
| 511 | int error; |
| 512 | |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 513 | if (dev->active) |
Bjorn Helgaas | cc8259a | 2008-02-06 01:40:02 -0800 | [diff] [blame] | 514 | return 0; |
Pierre Ossman | 68094e3 | 2005-11-29 09:09:32 +0100 | [diff] [blame] | 515 | |
| 516 | /* ensure resources are allocated */ |
| 517 | if (pnp_auto_config_dev(dev)) |
| 518 | return -EBUSY; |
| 519 | |
| 520 | error = pnp_start_dev(dev); |
| 521 | if (error) |
| 522 | return error; |
| 523 | |
| 524 | dev->active = 1; |
Bjorn Helgaas | cc8259a | 2008-02-06 01:40:02 -0800 | [diff] [blame] | 525 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | /** |
| 529 | * pnp_disable_dev - disables device |
| 530 | * @dev: pointer to the desired device |
| 531 | * |
| 532 | * inform the correct pnp protocol so that resources can be used by other devices |
| 533 | */ |
| 534 | int pnp_disable_dev(struct pnp_dev *dev) |
| 535 | { |
Pierre Ossman | 68094e3 | 2005-11-29 09:09:32 +0100 | [diff] [blame] | 536 | int error; |
| 537 | |
Bjorn Helgaas | 07d4e9a | 2007-07-26 10:41:21 -0700 | [diff] [blame] | 538 | if (!dev->active) |
Bjorn Helgaas | cc8259a | 2008-02-06 01:40:02 -0800 | [diff] [blame] | 539 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | |
Pierre Ossman | 68094e3 | 2005-11-29 09:09:32 +0100 | [diff] [blame] | 541 | error = pnp_stop_dev(dev); |
| 542 | if (error) |
| 543 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | |
| 545 | dev->active = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | |
| 547 | /* release the resources so that other devices can use them */ |
Daniel Walker | b3bd86e | 2008-02-06 01:40:04 -0800 | [diff] [blame] | 548 | mutex_lock(&pnp_res_mutex); |
Bjorn Helgaas | 6969c7e | 2008-04-28 16:34:10 -0600 | [diff] [blame] | 549 | pnp_clean_resource_table(dev); |
Daniel Walker | b3bd86e | 2008-02-06 01:40:04 -0800 | [diff] [blame] | 550 | mutex_unlock(&pnp_res_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | |
Bjorn Helgaas | cc8259a | 2008-02-06 01:40:02 -0800 | [diff] [blame] | 552 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | } |
| 554 | |
Pierre Ossman | 68094e3 | 2005-11-29 09:09:32 +0100 | [diff] [blame] | 555 | EXPORT_SYMBOL(pnp_start_dev); |
| 556 | EXPORT_SYMBOL(pnp_stop_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | EXPORT_SYMBOL(pnp_activate_dev); |
| 558 | EXPORT_SYMBOL(pnp_disable_dev); |