diff options
author | Bjorn Helgaas <bjorn.helgaas@hp.com> | 2008-06-27 18:56:53 -0400 |
---|---|---|
committer | Andi Kleen <andi@basil.nowhere.org> | 2008-07-16 17:27:05 -0400 |
commit | 87e4acf3ebc02c9d0a2f7a37b655c49176c4d765 (patch) | |
tree | 1d5ee98084c9de22d2de95dad84ae23a188f6429 /drivers/pnp | |
parent | b897f46cf7941fff8130ccdaf85f39528bff6a51 (diff) |
PNP: remove pnp_resource.index
We used pnp_resource.index to keep track of which ISAPNP configuration
register a resource should be written to. We needed this only to
handle the case where a register is disabled but a subsequent register
in the same set is enabled.
Rather than explicitly maintaining the pnp_resource.index, this patch
adds a resource every time we read an ISAPNP configuration register
and marks the resource as IORESOURCE_DISABLED when appropriate. This
makes the position in the pnp_resource_table always correspond to the
config register index.
Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Signed-off-by: Len Brown <len.brown@intel.com>
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Diffstat (limited to 'drivers/pnp')
-rw-r--r-- | drivers/pnp/base.h | 1 | ||||
-rw-r--r-- | drivers/pnp/interface.c | 20 | ||||
-rw-r--r-- | drivers/pnp/isapnp/core.c | 84 | ||||
-rw-r--r-- | drivers/pnp/manager.c | 4 |
4 files changed, 33 insertions, 76 deletions
diff --git a/drivers/pnp/base.h b/drivers/pnp/base.h index 886dac823ed6..6f60097c4212 100644 --- a/drivers/pnp/base.h +++ b/drivers/pnp/base.h | |||
@@ -57,7 +57,6 @@ struct pnp_resource *pnp_get_pnp_resource(struct pnp_dev *dev, | |||
57 | 57 | ||
58 | struct pnp_resource { | 58 | struct pnp_resource { |
59 | struct resource res; | 59 | struct resource res; |
60 | unsigned int index; /* ISAPNP config register index */ | ||
61 | }; | 60 | }; |
62 | 61 | ||
63 | struct pnp_resource_table { | 62 | struct pnp_resource_table { |
diff --git a/drivers/pnp/interface.c b/drivers/pnp/interface.c index 5695a79f3a52..3f8007ab94e3 100644 --- a/drivers/pnp/interface.c +++ b/drivers/pnp/interface.c | |||
@@ -320,7 +320,6 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr, | |||
320 | const char *ubuf, size_t count) | 320 | const char *ubuf, size_t count) |
321 | { | 321 | { |
322 | struct pnp_dev *dev = to_pnp_dev(dmdev); | 322 | struct pnp_dev *dev = to_pnp_dev(dmdev); |
323 | struct pnp_resource *pnp_res; | ||
324 | char *buf = (void *)ubuf; | 323 | char *buf = (void *)ubuf; |
325 | int retval = 0; | 324 | int retval = 0; |
326 | resource_size_t start, end; | 325 | resource_size_t start, end; |
@@ -368,7 +367,6 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr, | |||
368 | goto done; | 367 | goto done; |
369 | } | 368 | } |
370 | if (!strnicmp(buf, "set", 3)) { | 369 | if (!strnicmp(buf, "set", 3)) { |
371 | int nport = 0, nmem = 0, nirq = 0, ndma = 0; | ||
372 | if (dev->active) | 370 | if (dev->active) |
373 | goto done; | 371 | goto done; |
374 | buf += 3; | 372 | buf += 3; |
@@ -391,10 +389,7 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr, | |||
391 | end = simple_strtoul(buf, &buf, 0); | 389 | end = simple_strtoul(buf, &buf, 0); |
392 | } else | 390 | } else |
393 | end = start; | 391 | end = start; |
394 | pnp_res = pnp_add_io_resource(dev, start, end, | 392 | pnp_add_io_resource(dev, start, end, 0); |
395 | 0); | ||
396 | if (pnp_res) | ||
397 | pnp_res->index = nport++; | ||
398 | continue; | 393 | continue; |
399 | } | 394 | } |
400 | if (!strnicmp(buf, "mem", 3)) { | 395 | if (!strnicmp(buf, "mem", 3)) { |
@@ -411,10 +406,7 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr, | |||
411 | end = simple_strtoul(buf, &buf, 0); | 406 | end = simple_strtoul(buf, &buf, 0); |
412 | } else | 407 | } else |
413 | end = start; | 408 | end = start; |
414 | pnp_res = pnp_add_mem_resource(dev, start, end, | 409 | pnp_add_mem_resource(dev, start, end, 0); |
415 | 0); | ||
416 | if (pnp_res) | ||
417 | pnp_res->index = nmem++; | ||
418 | continue; | 410 | continue; |
419 | } | 411 | } |
420 | if (!strnicmp(buf, "irq", 3)) { | 412 | if (!strnicmp(buf, "irq", 3)) { |
@@ -422,9 +414,7 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr, | |||
422 | while (isspace(*buf)) | 414 | while (isspace(*buf)) |
423 | ++buf; | 415 | ++buf; |
424 | start = simple_strtoul(buf, &buf, 0); | 416 | start = simple_strtoul(buf, &buf, 0); |
425 | pnp_res = pnp_add_irq_resource(dev, start, 0); | 417 | pnp_add_irq_resource(dev, start, 0); |
426 | if (pnp_res) | ||
427 | pnp_res->index = nirq++; | ||
428 | continue; | 418 | continue; |
429 | } | 419 | } |
430 | if (!strnicmp(buf, "dma", 3)) { | 420 | if (!strnicmp(buf, "dma", 3)) { |
@@ -432,9 +422,7 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr, | |||
432 | while (isspace(*buf)) | 422 | while (isspace(*buf)) |
433 | ++buf; | 423 | ++buf; |
434 | start = simple_strtoul(buf, &buf, 0); | 424 | start = simple_strtoul(buf, &buf, 0); |
435 | pnp_res = pnp_add_dma_resource(dev, start, 0); | 425 | pnp_add_dma_resource(dev, start, 0); |
436 | if (pnp_res) | ||
437 | pnp_res->index = ndma++; | ||
438 | continue; | 426 | continue; |
439 | } | 427 | } |
440 | break; | 428 | break; |
diff --git a/drivers/pnp/isapnp/core.c b/drivers/pnp/isapnp/core.c index f1bccdbdeb08..752b51fbaa6c 100644 --- a/drivers/pnp/isapnp/core.c +++ b/drivers/pnp/isapnp/core.c | |||
@@ -928,7 +928,6 @@ EXPORT_SYMBOL(isapnp_write_byte); | |||
928 | 928 | ||
929 | static int isapnp_get_resources(struct pnp_dev *dev) | 929 | static int isapnp_get_resources(struct pnp_dev *dev) |
930 | { | 930 | { |
931 | struct pnp_resource *pnp_res; | ||
932 | int i, ret; | 931 | int i, ret; |
933 | 932 | ||
934 | dev_dbg(&dev->dev, "get resources\n"); | 933 | dev_dbg(&dev->dev, "get resources\n"); |
@@ -940,35 +939,23 @@ static int isapnp_get_resources(struct pnp_dev *dev) | |||
940 | 939 | ||
941 | for (i = 0; i < ISAPNP_MAX_PORT; i++) { | 940 | for (i = 0; i < ISAPNP_MAX_PORT; i++) { |
942 | ret = isapnp_read_word(ISAPNP_CFG_PORT + (i << 1)); | 941 | ret = isapnp_read_word(ISAPNP_CFG_PORT + (i << 1)); |
943 | if (ret) { | 942 | pnp_add_io_resource(dev, ret, ret, |
944 | pnp_res = pnp_add_io_resource(dev, ret, ret, 0); | 943 | ret == 0 ? IORESOURCE_DISABLED : 0); |
945 | if (pnp_res) | ||
946 | pnp_res->index = i; | ||
947 | } | ||
948 | } | 944 | } |
949 | for (i = 0; i < ISAPNP_MAX_MEM; i++) { | 945 | for (i = 0; i < ISAPNP_MAX_MEM; i++) { |
950 | ret = isapnp_read_word(ISAPNP_CFG_MEM + (i << 3)) << 8; | 946 | ret = isapnp_read_word(ISAPNP_CFG_MEM + (i << 3)) << 8; |
951 | if (ret) { | 947 | pnp_add_mem_resource(dev, ret, ret, |
952 | pnp_res = pnp_add_mem_resource(dev, ret, ret, 0); | 948 | ret == 0 ? IORESOURCE_DISABLED : 0); |
953 | if (pnp_res) | ||
954 | pnp_res->index = i; | ||
955 | } | ||
956 | } | 949 | } |
957 | for (i = 0; i < ISAPNP_MAX_IRQ; i++) { | 950 | for (i = 0; i < ISAPNP_MAX_IRQ; i++) { |
958 | ret = isapnp_read_word(ISAPNP_CFG_IRQ + (i << 1)) >> 8; | 951 | ret = isapnp_read_word(ISAPNP_CFG_IRQ + (i << 1)) >> 8; |
959 | if (ret) { | 952 | pnp_add_irq_resource(dev, ret, |
960 | pnp_res = pnp_add_irq_resource(dev, ret, 0); | 953 | ret == 0 ? IORESOURCE_DISABLED : 0); |
961 | if (pnp_res) | ||
962 | pnp_res->index = i; | ||
963 | } | ||
964 | } | 954 | } |
965 | for (i = 0; i < ISAPNP_MAX_DMA; i++) { | 955 | for (i = 0; i < ISAPNP_MAX_DMA; i++) { |
966 | ret = isapnp_read_byte(ISAPNP_CFG_DMA + i); | 956 | ret = isapnp_read_byte(ISAPNP_CFG_DMA + i); |
967 | if (ret != 4) { | 957 | pnp_add_dma_resource(dev, ret, |
968 | pnp_res = pnp_add_dma_resource(dev, ret, 0); | 958 | ret == 4 ? IORESOURCE_DISABLED : 0); |
969 | if (pnp_res) | ||
970 | pnp_res->index = i; | ||
971 | } | ||
972 | } | 959 | } |
973 | 960 | ||
974 | __end: | 961 | __end: |
@@ -978,62 +965,49 @@ __end: | |||
978 | 965 | ||
979 | static int isapnp_set_resources(struct pnp_dev *dev) | 966 | static int isapnp_set_resources(struct pnp_dev *dev) |
980 | { | 967 | { |
981 | struct pnp_resource *pnp_res; | ||
982 | struct resource *res; | 968 | struct resource *res; |
983 | int tmp, index; | 969 | int tmp; |
984 | 970 | ||
985 | dev_dbg(&dev->dev, "set resources\n"); | 971 | dev_dbg(&dev->dev, "set resources\n"); |
986 | isapnp_cfg_begin(dev->card->number, dev->number); | 972 | isapnp_cfg_begin(dev->card->number, dev->number); |
987 | dev->active = 1; | 973 | dev->active = 1; |
988 | for (tmp = 0; tmp < ISAPNP_MAX_PORT; tmp++) { | 974 | for (tmp = 0; tmp < ISAPNP_MAX_PORT; tmp++) { |
989 | pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_IO, tmp); | 975 | res = pnp_get_resource(dev, IORESOURCE_IO, tmp); |
990 | if (!pnp_res) | 976 | if (res && pnp_resource_valid(res) && |
991 | continue; | 977 | !(res->flags & IORESOURCE_DISABLED)) { |
992 | res = &pnp_res->res; | ||
993 | if (pnp_resource_valid(res)) { | ||
994 | index = pnp_res->index; | ||
995 | dev_dbg(&dev->dev, " set io %d to %#llx\n", | 978 | dev_dbg(&dev->dev, " set io %d to %#llx\n", |
996 | index, (unsigned long long) res->start); | 979 | tmp, (unsigned long long) res->start); |
997 | isapnp_write_word(ISAPNP_CFG_PORT + (index << 1), | 980 | isapnp_write_word(ISAPNP_CFG_PORT + (tmp << 1), |
998 | res->start); | 981 | res->start); |
999 | } | 982 | } |
1000 | } | 983 | } |
1001 | for (tmp = 0; tmp < ISAPNP_MAX_IRQ; tmp++) { | 984 | for (tmp = 0; tmp < ISAPNP_MAX_IRQ; tmp++) { |
1002 | pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_IRQ, tmp); | 985 | res = pnp_get_resource(dev, IORESOURCE_IRQ, tmp); |
1003 | if (!pnp_res) | 986 | if (res && pnp_resource_valid(res) && |
1004 | continue; | 987 | !(res->flags & IORESOURCE_DISABLED)) { |
1005 | res = &pnp_res->res; | ||
1006 | if (pnp_resource_valid(res)) { | ||
1007 | int irq = res->start; | 988 | int irq = res->start; |
1008 | if (irq == 2) | 989 | if (irq == 2) |
1009 | irq = 9; | 990 | irq = 9; |
1010 | index = pnp_res->index; | 991 | dev_dbg(&dev->dev, " set irq %d to %d\n", tmp, irq); |
1011 | dev_dbg(&dev->dev, " set irq %d to %d\n", index, irq); | 992 | isapnp_write_byte(ISAPNP_CFG_IRQ + (tmp << 1), irq); |
1012 | isapnp_write_byte(ISAPNP_CFG_IRQ + (index << 1), irq); | ||
1013 | } | 993 | } |
1014 | } | 994 | } |
1015 | for (tmp = 0; tmp < ISAPNP_MAX_DMA; tmp++) { | 995 | for (tmp = 0; tmp < ISAPNP_MAX_DMA; tmp++) { |
1016 | pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_DMA, tmp); | 996 | res = pnp_get_resource(dev, IORESOURCE_DMA, tmp); |
1017 | if (!pnp_res) | 997 | if (res && pnp_resource_valid(res) && |
1018 | continue; | 998 | !(res->flags & IORESOURCE_DISABLED)) { |
1019 | res = &pnp_res->res; | ||
1020 | if (pnp_resource_valid(res)) { | ||
1021 | index = pnp_res->index; | ||
1022 | dev_dbg(&dev->dev, " set dma %d to %lld\n", | 999 | dev_dbg(&dev->dev, " set dma %d to %lld\n", |
1023 | index, (unsigned long long) res->start); | 1000 | tmp, (unsigned long long) res->start); |
1024 | isapnp_write_byte(ISAPNP_CFG_DMA + index, res->start); | 1001 | isapnp_write_byte(ISAPNP_CFG_DMA + tmp, res->start); |
1025 | } | 1002 | } |
1026 | } | 1003 | } |
1027 | for (tmp = 0; tmp < ISAPNP_MAX_MEM; tmp++) { | 1004 | for (tmp = 0; tmp < ISAPNP_MAX_MEM; tmp++) { |
1028 | pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_MEM, tmp); | 1005 | res = pnp_get_resource(dev, IORESOURCE_MEM, tmp); |
1029 | if (!pnp_res) | 1006 | if (res && pnp_resource_valid(res) && |
1030 | continue; | 1007 | !(res->flags & IORESOURCE_DISABLED)) { |
1031 | res = &pnp_res->res; | ||
1032 | if (pnp_resource_valid(res)) { | ||
1033 | index = pnp_res->index; | ||
1034 | dev_dbg(&dev->dev, " set mem %d to %#llx\n", | 1008 | dev_dbg(&dev->dev, " set mem %d to %#llx\n", |
1035 | index, (unsigned long long) res->start); | 1009 | tmp, (unsigned long long) res->start); |
1036 | isapnp_write_word(ISAPNP_CFG_MEM + (index << 3), | 1010 | isapnp_write_word(ISAPNP_CFG_MEM + (tmp << 3), |
1037 | (res->start >> 8) & 0xffff); | 1011 | (res->start >> 8) & 0xffff); |
1038 | } | 1012 | } |
1039 | } | 1013 | } |
diff --git a/drivers/pnp/manager.c b/drivers/pnp/manager.c index bea0914ff947..90bd9cb65563 100644 --- a/drivers/pnp/manager.c +++ b/drivers/pnp/manager.c | |||
@@ -40,7 +40,6 @@ static int pnp_assign_port(struct pnp_dev *dev, struct pnp_port *rule, int idx) | |||
40 | } | 40 | } |
41 | 41 | ||
42 | /* set the initial values */ | 42 | /* set the initial values */ |
43 | pnp_res->index = idx; | ||
44 | res->flags |= rule->flags | IORESOURCE_IO; | 43 | res->flags |= rule->flags | IORESOURCE_IO; |
45 | res->flags &= ~IORESOURCE_UNSET; | 44 | res->flags &= ~IORESOURCE_UNSET; |
46 | 45 | ||
@@ -90,7 +89,6 @@ static int pnp_assign_mem(struct pnp_dev *dev, struct pnp_mem *rule, int idx) | |||
90 | } | 89 | } |
91 | 90 | ||
92 | /* set the initial values */ | 91 | /* set the initial values */ |
93 | pnp_res->index = idx; | ||
94 | res->flags |= rule->flags | IORESOURCE_MEM; | 92 | res->flags |= rule->flags | IORESOURCE_MEM; |
95 | res->flags &= ~IORESOURCE_UNSET; | 93 | res->flags &= ~IORESOURCE_UNSET; |
96 | 94 | ||
@@ -155,7 +153,6 @@ static int pnp_assign_irq(struct pnp_dev *dev, struct pnp_irq *rule, int idx) | |||
155 | } | 153 | } |
156 | 154 | ||
157 | /* set the initial values */ | 155 | /* set the initial values */ |
158 | pnp_res->index = idx; | ||
159 | res->flags |= rule->flags | IORESOURCE_IRQ; | 156 | res->flags |= rule->flags | IORESOURCE_IRQ; |
160 | res->flags &= ~IORESOURCE_UNSET; | 157 | res->flags &= ~IORESOURCE_UNSET; |
161 | 158 | ||
@@ -214,7 +211,6 @@ static void pnp_assign_dma(struct pnp_dev *dev, struct pnp_dma *rule, int idx) | |||
214 | } | 211 | } |
215 | 212 | ||
216 | /* set the initial values */ | 213 | /* set the initial values */ |
217 | pnp_res->index = idx; | ||
218 | res->flags |= rule->flags | IORESOURCE_DMA; | 214 | res->flags |= rule->flags | IORESOURCE_DMA; |
219 | res->flags &= ~IORESOURCE_UNSET; | 215 | res->flags &= ~IORESOURCE_UNSET; |
220 | 216 | ||