diff options
author | Bjorn Helgaas <bjorn.helgaas@hp.com> | 2008-04-28 18:34:37 -0400 |
---|---|---|
committer | Len Brown <len.brown@intel.com> | 2008-04-29 03:22:29 -0400 |
commit | d6180f36617953990bf90d4c1ff85b77e9995cd1 (patch) | |
tree | a9fa336f7cb1f99a62c859926c6cbcfb53f5b81e /drivers | |
parent | cc8c2e308194f0997c718c7c735550ff06754d20 (diff) |
PNP: make generic pnp_add_mem_resource()
Add a pnp_add_mem_resource() that can be used by all the PNP
backends. This consolidates a little more pnp_resource_table
knowledge into one place.
Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Signed-off-by: Len Brown <len.brown@intel.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/pnp/base.h | 3 | ||||
-rw-r--r-- | drivers/pnp/interface.c | 19 | ||||
-rw-r--r-- | drivers/pnp/isapnp/core.c | 10 | ||||
-rw-r--r-- | drivers/pnp/pnpacpi/rsparser.c | 34 | ||||
-rw-r--r-- | drivers/pnp/pnpbios/rsparser.c | 23 | ||||
-rw-r--r-- | drivers/pnp/resource.c | 29 |
6 files changed, 57 insertions, 61 deletions
diff --git a/drivers/pnp/base.h b/drivers/pnp/base.h index bfb08abc311b..9b7bb62c98b1 100644 --- a/drivers/pnp/base.h +++ b/drivers/pnp/base.h | |||
@@ -48,3 +48,6 @@ struct pnp_resource *pnp_add_dma_resource(struct pnp_dev *dev, int dma, | |||
48 | struct pnp_resource *pnp_add_io_resource(struct pnp_dev *dev, | 48 | struct pnp_resource *pnp_add_io_resource(struct pnp_dev *dev, |
49 | resource_size_t start, | 49 | resource_size_t start, |
50 | resource_size_t end, int flags); | 50 | resource_size_t end, int flags); |
51 | struct pnp_resource *pnp_add_mem_resource(struct pnp_dev *dev, | ||
52 | resource_size_t start, | ||
53 | resource_size_t end, int flags); | ||
diff --git a/drivers/pnp/interface.c b/drivers/pnp/interface.c index 77d8bf01b485..5d9301de1778 100644 --- a/drivers/pnp/interface.c +++ b/drivers/pnp/interface.c | |||
@@ -321,7 +321,6 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr, | |||
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; | 323 | struct pnp_resource *pnp_res; |
324 | struct resource *res; | ||
325 | char *buf = (void *)ubuf; | 324 | char *buf = (void *)ubuf; |
326 | int retval = 0; | 325 | int retval = 0; |
327 | resource_size_t start, end; | 326 | resource_size_t start, end; |
@@ -402,24 +401,20 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr, | |||
402 | buf += 3; | 401 | buf += 3; |
403 | while (isspace(*buf)) | 402 | while (isspace(*buf)) |
404 | ++buf; | 403 | ++buf; |
405 | pnp_res = pnp_get_pnp_resource(dev, | 404 | start = simple_strtoul(buf, &buf, 0); |
406 | IORESOURCE_MEM, nmem); | ||
407 | if (!pnp_res) | ||
408 | break; | ||
409 | pnp_res->index = nmem; | ||
410 | res = &pnp_res->res; | ||
411 | res->start = simple_strtoul(buf, &buf, 0); | ||
412 | while (isspace(*buf)) | 405 | while (isspace(*buf)) |
413 | ++buf; | 406 | ++buf; |
414 | if (*buf == '-') { | 407 | if (*buf == '-') { |
415 | buf += 1; | 408 | buf += 1; |
416 | while (isspace(*buf)) | 409 | while (isspace(*buf)) |
417 | ++buf; | 410 | ++buf; |
418 | res->end = simple_strtoul(buf, &buf, 0); | 411 | end = simple_strtoul(buf, &buf, 0); |
419 | } else | 412 | } else |
420 | res->end = res->start; | 413 | end = start; |
421 | res->flags = IORESOURCE_MEM; | 414 | pnp_res = pnp_add_mem_resource(dev, start, end, |
422 | nmem++; | 415 | 0); |
416 | if (pnp_res) | ||
417 | pnp_res->index = nmem++; | ||
423 | continue; | 418 | continue; |
424 | } | 419 | } |
425 | if (!strnicmp(buf, "irq", 3)) { | 420 | if (!strnicmp(buf, "irq", 3)) { |
diff --git a/drivers/pnp/isapnp/core.c b/drivers/pnp/isapnp/core.c index bdd8508090da..f08399497e4c 100644 --- a/drivers/pnp/isapnp/core.c +++ b/drivers/pnp/isapnp/core.c | |||
@@ -932,7 +932,6 @@ EXPORT_SYMBOL(isapnp_write_byte); | |||
932 | static int isapnp_read_resources(struct pnp_dev *dev) | 932 | static int isapnp_read_resources(struct pnp_dev *dev) |
933 | { | 933 | { |
934 | struct pnp_resource *pnp_res; | 934 | struct pnp_resource *pnp_res; |
935 | struct resource *res; | ||
936 | int tmp, ret; | 935 | int tmp, ret; |
937 | 936 | ||
938 | dev->active = isapnp_read_byte(ISAPNP_CFG_ACTIVATE); | 937 | dev->active = isapnp_read_byte(ISAPNP_CFG_ACTIVATE); |
@@ -950,12 +949,9 @@ static int isapnp_read_resources(struct pnp_dev *dev) | |||
950 | isapnp_read_word(ISAPNP_CFG_MEM + (tmp << 3)) << 8; | 949 | isapnp_read_word(ISAPNP_CFG_MEM + (tmp << 3)) << 8; |
951 | if (!ret) | 950 | if (!ret) |
952 | continue; | 951 | continue; |
953 | pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_MEM, | 952 | pnp_res = pnp_add_mem_resource(dev, ret, ret, 0); |
954 | tmp); | 953 | if (pnp_res) |
955 | pnp_res->index = tmp; | 954 | pnp_res->index = tmp; |
956 | res = &pnp_res->res; | ||
957 | res->start = ret; | ||
958 | res->flags = IORESOURCE_MEM; | ||
959 | } | 955 | } |
960 | for (tmp = 0; tmp < ISAPNP_MAX_IRQ; tmp++) { | 956 | for (tmp = 0; tmp < ISAPNP_MAX_IRQ; tmp++) { |
961 | ret = | 957 | ret = |
diff --git a/drivers/pnp/pnpacpi/rsparser.c b/drivers/pnp/pnpacpi/rsparser.c index d3ca8e035c19..a512908bf4e3 100644 --- a/drivers/pnp/pnpacpi/rsparser.c +++ b/drivers/pnp/pnpacpi/rsparser.c | |||
@@ -173,34 +173,18 @@ static void pnpacpi_parse_allocated_ioresource(struct pnp_dev *dev, u64 start, | |||
173 | } | 173 | } |
174 | 174 | ||
175 | static void pnpacpi_parse_allocated_memresource(struct pnp_dev *dev, | 175 | static void pnpacpi_parse_allocated_memresource(struct pnp_dev *dev, |
176 | u64 mem, u64 len, | 176 | u64 start, u64 len, |
177 | int write_protect) | 177 | int write_protect) |
178 | { | 178 | { |
179 | struct resource *res; | 179 | int flags = 0; |
180 | int i; | 180 | u64 end = start + len - 1; |
181 | static unsigned char warned; | ||
182 | 181 | ||
183 | for (i = 0; i < PNP_MAX_MEM; i++) { | 182 | if (len == 0) |
184 | res = pnp_get_resource(dev, IORESOURCE_MEM, i); | 183 | flags |= IORESOURCE_DISABLED; |
185 | if (!pnp_resource_valid(res)) | 184 | if (write_protect == ACPI_READ_WRITE_MEMORY) |
186 | break; | 185 | flags |= IORESOURCE_MEM_WRITEABLE; |
187 | } | 186 | |
188 | if (i < PNP_MAX_MEM) { | 187 | pnp_add_mem_resource(dev, start, end, flags); |
189 | res->flags = IORESOURCE_MEM; // Also clears _UNSET flag | ||
190 | if (len <= 0) { | ||
191 | res->flags |= IORESOURCE_DISABLED; | ||
192 | return; | ||
193 | } | ||
194 | if (write_protect == ACPI_READ_WRITE_MEMORY) | ||
195 | res->flags |= IORESOURCE_MEM_WRITEABLE; | ||
196 | |||
197 | res->start = mem; | ||
198 | res->end = mem + len - 1; | ||
199 | } else if (!warned) { | ||
200 | printk(KERN_WARNING "pnpacpi: exceeded the max number of mem " | ||
201 | "resources: %d\n", PNP_MAX_MEM); | ||
202 | warned = 1; | ||
203 | } | ||
204 | } | 188 | } |
205 | 189 | ||
206 | static void pnpacpi_parse_allocated_address_space(struct pnp_dev *dev, | 190 | static void pnpacpi_parse_allocated_address_space(struct pnp_dev *dev, |
diff --git a/drivers/pnp/pnpbios/rsparser.c b/drivers/pnp/pnpbios/rsparser.c index 8c83bc16a9be..ed63ecd9bf40 100644 --- a/drivers/pnp/pnpbios/rsparser.c +++ b/drivers/pnp/pnpbios/rsparser.c | |||
@@ -67,26 +67,15 @@ static void pnpbios_parse_allocated_ioresource(struct pnp_dev *dev, | |||
67 | } | 67 | } |
68 | 68 | ||
69 | static void pnpbios_parse_allocated_memresource(struct pnp_dev *dev, | 69 | static void pnpbios_parse_allocated_memresource(struct pnp_dev *dev, |
70 | int mem, int len) | 70 | int start, int len) |
71 | { | 71 | { |
72 | struct resource *res; | 72 | int flags = 0; |
73 | int i; | 73 | int end = start + len - 1; |
74 | 74 | ||
75 | for (i = 0; i < PNP_MAX_MEM; i++) { | 75 | if (len <= 0) |
76 | res = pnp_get_resource(dev, IORESOURCE_MEM, i); | 76 | flags |= IORESOURCE_DISABLED; |
77 | if (!pnp_resource_valid(res)) | ||
78 | break; | ||
79 | } | ||
80 | 77 | ||
81 | if (i < PNP_MAX_MEM) { | 78 | pnp_add_mem_resource(dev, start, end, flags); |
82 | res->flags = IORESOURCE_MEM; // Also clears _UNSET flag | ||
83 | if (len <= 0) { | ||
84 | res->flags |= IORESOURCE_DISABLED; | ||
85 | return; | ||
86 | } | ||
87 | res->start = (unsigned long)mem; | ||
88 | res->end = (unsigned long)(mem + len - 1); | ||
89 | } | ||
90 | } | 79 | } |
91 | 80 | ||
92 | static unsigned char *pnpbios_parse_allocated_resource_data(struct pnp_dev *dev, | 81 | static unsigned char *pnpbios_parse_allocated_resource_data(struct pnp_dev *dev, |
diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c index 64387b70026a..2041620d5682 100644 --- a/drivers/pnp/resource.c +++ b/drivers/pnp/resource.c | |||
@@ -657,6 +657,35 @@ struct pnp_resource *pnp_add_io_resource(struct pnp_dev *dev, | |||
657 | return pnp_res; | 657 | return pnp_res; |
658 | } | 658 | } |
659 | 659 | ||
660 | struct pnp_resource *pnp_add_mem_resource(struct pnp_dev *dev, | ||
661 | resource_size_t start, | ||
662 | resource_size_t end, int flags) | ||
663 | { | ||
664 | struct pnp_resource *pnp_res; | ||
665 | struct resource *res; | ||
666 | static unsigned char warned; | ||
667 | |||
668 | pnp_res = pnp_new_resource(dev, IORESOURCE_MEM); | ||
669 | if (!pnp_res) { | ||
670 | if (!warned) { | ||
671 | dev_err(&dev->dev, "can't add resource for MEM " | ||
672 | "%#llx-%#llx\n",(unsigned long long) start, | ||
673 | (unsigned long long) end); | ||
674 | warned = 1; | ||
675 | } | ||
676 | return NULL; | ||
677 | } | ||
678 | |||
679 | res = &pnp_res->res; | ||
680 | res->flags = IORESOURCE_MEM | flags; | ||
681 | res->start = start; | ||
682 | res->end = end; | ||
683 | |||
684 | dev_dbg(&dev->dev, " add mem %#llx-%#llx flags %#x\n", | ||
685 | (unsigned long long) start, (unsigned long long) end, flags); | ||
686 | return pnp_res; | ||
687 | } | ||
688 | |||
660 | /* format is: pnp_reserve_irq=irq1[,irq2] .... */ | 689 | /* format is: pnp_reserve_irq=irq1[,irq2] .... */ |
661 | static int __init pnp_setup_reserve_irq(char *str) | 690 | static int __init pnp_setup_reserve_irq(char *str) |
662 | { | 691 | { |