Commit d6180f36617953990bf90d4c1ff85b77e9995cd1

Authored by Bjorn Helgaas
Committed by Len Brown
1 parent cc8c2e3081

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>

Showing 6 changed files with 57 additions and 61 deletions Side-by-side Diff

... ... @@ -48,4 +48,7 @@
48 48 struct pnp_resource *pnp_add_io_resource(struct pnp_dev *dev,
49 49 resource_size_t start,
50 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);
drivers/pnp/interface.c
... ... @@ -321,7 +321,6 @@
321 321 {
322 322 struct pnp_dev *dev = to_pnp_dev(dmdev);
323 323 struct pnp_resource *pnp_res;
324   - struct resource *res;
325 324 char *buf = (void *)ubuf;
326 325 int retval = 0;
327 326 resource_size_t start, end;
328 327  
329 328  
... ... @@ -402,24 +401,20 @@
402 401 buf += 3;
403 402 while (isspace(*buf))
404 403 ++buf;
405   - pnp_res = pnp_get_pnp_resource(dev,
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);
  404 + start = simple_strtoul(buf, &buf, 0);
412 405 while (isspace(*buf))
413 406 ++buf;
414 407 if (*buf == '-') {
415 408 buf += 1;
416 409 while (isspace(*buf))
417 410 ++buf;
418   - res->end = simple_strtoul(buf, &buf, 0);
  411 + end = simple_strtoul(buf, &buf, 0);
419 412 } else
420   - res->end = res->start;
421   - res->flags = IORESOURCE_MEM;
422   - nmem++;
  413 + end = start;
  414 + pnp_res = pnp_add_mem_resource(dev, start, end,
  415 + 0);
  416 + if (pnp_res)
  417 + pnp_res->index = nmem++;
423 418 continue;
424 419 }
425 420 if (!strnicmp(buf, "irq", 3)) {
drivers/pnp/isapnp/core.c
... ... @@ -932,7 +932,6 @@
932 932 static int isapnp_read_resources(struct pnp_dev *dev)
933 933 {
934 934 struct pnp_resource *pnp_res;
935   - struct resource *res;
936 935 int tmp, ret;
937 936  
938 937 dev->active = isapnp_read_byte(ISAPNP_CFG_ACTIVATE);
... ... @@ -950,12 +949,9 @@
950 949 isapnp_read_word(ISAPNP_CFG_MEM + (tmp << 3)) << 8;
951 950 if (!ret)
952 951 continue;
953   - pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_MEM,
954   - tmp);
955   - pnp_res->index = tmp;
956   - res = &pnp_res->res;
957   - res->start = ret;
958   - res->flags = IORESOURCE_MEM;
  952 + pnp_res = pnp_add_mem_resource(dev, ret, ret, 0);
  953 + if (pnp_res)
  954 + pnp_res->index = tmp;
959 955 }
960 956 for (tmp = 0; tmp < ISAPNP_MAX_IRQ; tmp++) {
961 957 ret =
drivers/pnp/pnpacpi/rsparser.c
... ... @@ -173,34 +173,18 @@
173 173 }
174 174  
175 175 static void pnpacpi_parse_allocated_memresource(struct pnp_dev *dev,
176   - u64 mem, u64 len,
  176 + u64 start, u64 len,
177 177 int write_protect)
178 178 {
179   - struct resource *res;
180   - int i;
181   - static unsigned char warned;
  179 + int flags = 0;
  180 + u64 end = start + len - 1;
182 181  
183   - for (i = 0; i < PNP_MAX_MEM; i++) {
184   - res = pnp_get_resource(dev, IORESOURCE_MEM, i);
185   - if (!pnp_resource_valid(res))
186   - break;
187   - }
188   - if (i < PNP_MAX_MEM) {
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;
  182 + if (len == 0)
  183 + flags |= IORESOURCE_DISABLED;
  184 + if (write_protect == ACPI_READ_WRITE_MEMORY)
  185 + flags |= IORESOURCE_MEM_WRITEABLE;
196 186  
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   - }
  187 + pnp_add_mem_resource(dev, start, end, flags);
204 188 }
205 189  
206 190 static void pnpacpi_parse_allocated_address_space(struct pnp_dev *dev,
drivers/pnp/pnpbios/rsparser.c
... ... @@ -67,26 +67,15 @@
67 67 }
68 68  
69 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;
73   - int i;
  72 + int flags = 0;
  73 + int end = start + len - 1;
74 74  
75   - for (i = 0; i < PNP_MAX_MEM; i++) {
76   - res = pnp_get_resource(dev, IORESOURCE_MEM, i);
77   - if (!pnp_resource_valid(res))
78   - break;
79   - }
  75 + if (len <= 0)
  76 + flags |= IORESOURCE_DISABLED;
80 77  
81   - if (i < PNP_MAX_MEM) {
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   - }
  78 + pnp_add_mem_resource(dev, start, end, flags);
90 79 }
91 80  
92 81 static unsigned char *pnpbios_parse_allocated_resource_data(struct pnp_dev *dev,
drivers/pnp/resource.c
... ... @@ -657,6 +657,35 @@
657 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 689 /* format is: pnp_reserve_irq=irq1[,irq2] .... */
661 690 static int __init pnp_setup_reserve_irq(char *str)
662 691 {