Commit c9377667 authored by Witold Szczeponik's avatar Witold Szczeponik Committed by Rafael J. Wysocki

PNP: Simplify setting of resources

This patch factors out the setting of PNP resources into one function which is
then reused for all PNP resource types.  This makes the code more concise and
avoids duplication.  The parameters "type" and "flags" are not used at the
moment but may be used by follow-up patches.  Placeholders for these patches
can be found in the comment lines that contain the "TBD" marker.

As the code does not make any changes to the ABI, no regressions are expected.

NB: While at it, support for bus type resources is added.
Signed-off-by: default avatarWitold Szczeponik <Witold.Szczeponik@gmx.net>
Reviewed-by: default avatarBjorn Helgaas <bhelgaas@google.com>
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent d1c3ed66
...@@ -298,6 +298,39 @@ static ssize_t pnp_show_current_resources(struct device *dmdev, ...@@ -298,6 +298,39 @@ static ssize_t pnp_show_current_resources(struct device *dmdev,
return ret; return ret;
} }
static char *pnp_get_resource_value(char *buf,
unsigned long type,
resource_size_t *start,
resource_size_t *end,
unsigned long *flags)
{
if (start)
*start = 0;
if (end)
*end = 0;
if (flags)
*flags = 0;
/* TBD: allow for disabled resources */
buf = skip_spaces(buf);
if (start) {
*start = simple_strtoull(buf, &buf, 0);
if (end) {
buf = skip_spaces(buf);
if (*buf == '-') {
buf = skip_spaces(buf + 1);
*end = simple_strtoull(buf, &buf, 0);
} else
*end = *start;
}
}
/* TBD: allow for additional flags, e.g., IORESOURCE_WINDOW */
return buf;
}
static ssize_t pnp_set_current_resources(struct device *dmdev, static ssize_t pnp_set_current_resources(struct device *dmdev,
struct device_attribute *attr, struct device_attribute *attr,
const char *ubuf, size_t count) const char *ubuf, size_t count)
...@@ -305,7 +338,6 @@ static ssize_t pnp_set_current_resources(struct device *dmdev, ...@@ -305,7 +338,6 @@ static ssize_t pnp_set_current_resources(struct device *dmdev,
struct pnp_dev *dev = to_pnp_dev(dmdev); struct pnp_dev *dev = to_pnp_dev(dmdev);
char *buf = (void *)ubuf; char *buf = (void *)ubuf;
int retval = 0; int retval = 0;
resource_size_t start, end;
if (dev->status & PNP_ATTACHED) { if (dev->status & PNP_ATTACHED) {
retval = -EBUSY; retval = -EBUSY;
...@@ -349,6 +381,10 @@ static ssize_t pnp_set_current_resources(struct device *dmdev, ...@@ -349,6 +381,10 @@ static ssize_t pnp_set_current_resources(struct device *dmdev,
goto done; goto done;
} }
if (!strnicmp(buf, "set", 3)) { if (!strnicmp(buf, "set", 3)) {
resource_size_t start;
resource_size_t end;
unsigned long flags;
if (dev->active) if (dev->active)
goto done; goto done;
buf += 3; buf += 3;
...@@ -357,42 +393,37 @@ static ssize_t pnp_set_current_resources(struct device *dmdev, ...@@ -357,42 +393,37 @@ static ssize_t pnp_set_current_resources(struct device *dmdev,
while (1) { while (1) {
buf = skip_spaces(buf); buf = skip_spaces(buf);
if (!strnicmp(buf, "io", 2)) { if (!strnicmp(buf, "io", 2)) {
buf = skip_spaces(buf + 2); buf = pnp_get_resource_value(buf + 2,
start = simple_strtoul(buf, &buf, 0); IORESOURCE_IO,
buf = skip_spaces(buf); &start, &end,
if (*buf == '-') { &flags);
buf = skip_spaces(buf + 1); pnp_add_io_resource(dev, start, end, flags);
end = simple_strtoul(buf, &buf, 0); } else if (!strnicmp(buf, "mem", 3)) {
} else buf = pnp_get_resource_value(buf + 3,
end = start; IORESOURCE_MEM,
pnp_add_io_resource(dev, start, end, 0); &start, &end,
continue; &flags);
} pnp_add_mem_resource(dev, start, end, flags);
if (!strnicmp(buf, "mem", 3)) { } else if (!strnicmp(buf, "irq", 3)) {
buf = skip_spaces(buf + 3); buf = pnp_get_resource_value(buf + 3,
start = simple_strtoul(buf, &buf, 0); IORESOURCE_IRQ,
buf = skip_spaces(buf); &start, NULL,
if (*buf == '-') { &flags);
buf = skip_spaces(buf + 1); pnp_add_irq_resource(dev, start, flags);
end = simple_strtoul(buf, &buf, 0); } else if (!strnicmp(buf, "dma", 3)) {
} else buf = pnp_get_resource_value(buf + 3,
end = start; IORESOURCE_DMA,
pnp_add_mem_resource(dev, start, end, 0); &start, NULL,
continue; &flags);
} pnp_add_dma_resource(dev, start, flags);
if (!strnicmp(buf, "irq", 3)) { } else if (!strnicmp(buf, "bus", 3)) {
buf = skip_spaces(buf + 3); buf = pnp_get_resource_value(buf + 3,
start = simple_strtoul(buf, &buf, 0); IORESOURCE_BUS,
pnp_add_irq_resource(dev, start, 0); &start, &end,
continue; NULL);
} pnp_add_bus_resource(dev, start, end);
if (!strnicmp(buf, "dma", 3)) { } else
buf = skip_spaces(buf + 3); break;
start = simple_strtoul(buf, &buf, 0);
pnp_add_dma_resource(dev, start, 0);
continue;
}
break;
} }
mutex_unlock(&pnp_res_mutex); mutex_unlock(&pnp_res_mutex);
goto done; goto done;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment