Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 87e4acf3 authored by Bjorn Helgaas's avatar Bjorn Helgaas Committed by Andi Kleen
Browse files

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: default avatarBjorn Helgaas <bjorn.helgaas@hp.com>
Signed-off-by: default avatarLen Brown <len.brown@intel.com>
Signed-off-by: default avatarAndi Kleen <ak@linux.intel.com>
parent b897f46c
Loading
Loading
Loading
Loading
+0 −1
Original line number Original line Diff line number Diff line
@@ -57,7 +57,6 @@ struct pnp_resource *pnp_get_pnp_resource(struct pnp_dev *dev,


struct pnp_resource {
struct pnp_resource {
	struct resource res;
	struct resource res;
	unsigned int index;		/* ISAPNP config register index */
};
};


struct pnp_resource_table {
struct pnp_resource_table {
+4 −16
Original line number Original line Diff line number Diff line
@@ -320,7 +320,6 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr,
			  const char *ubuf, size_t count)
			  const char *ubuf, size_t count)
{
{
	struct pnp_dev *dev = to_pnp_dev(dmdev);
	struct pnp_dev *dev = to_pnp_dev(dmdev);
	struct pnp_resource *pnp_res;
	char *buf = (void *)ubuf;
	char *buf = (void *)ubuf;
	int retval = 0;
	int retval = 0;
	resource_size_t start, end;
	resource_size_t start, end;
@@ -368,7 +367,6 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr,
		goto done;
		goto done;
	}
	}
	if (!strnicmp(buf, "set", 3)) {
	if (!strnicmp(buf, "set", 3)) {
		int nport = 0, nmem = 0, nirq = 0, ndma = 0;
		if (dev->active)
		if (dev->active)
			goto done;
			goto done;
		buf += 3;
		buf += 3;
@@ -391,10 +389,7 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr,
					end = simple_strtoul(buf, &buf, 0);
					end = simple_strtoul(buf, &buf, 0);
				} else
				} else
					end = start;
					end = start;
				pnp_res = pnp_add_io_resource(dev, start, end,
				pnp_add_io_resource(dev, start, end, 0);
							      0);
				if (pnp_res)
					pnp_res->index = nport++;
				continue;
				continue;
			}
			}
			if (!strnicmp(buf, "mem", 3)) {
			if (!strnicmp(buf, "mem", 3)) {
@@ -411,10 +406,7 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr,
					end = simple_strtoul(buf, &buf, 0);
					end = simple_strtoul(buf, &buf, 0);
				} else
				} else
					end = start;
					end = start;
				pnp_res = pnp_add_mem_resource(dev, start, end,
				pnp_add_mem_resource(dev, start, end, 0);
							       0);
				if (pnp_res)
					pnp_res->index = nmem++;
				continue;
				continue;
			}
			}
			if (!strnicmp(buf, "irq", 3)) {
			if (!strnicmp(buf, "irq", 3)) {
@@ -422,9 +414,7 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr,
				while (isspace(*buf))
				while (isspace(*buf))
					++buf;
					++buf;
				start = simple_strtoul(buf, &buf, 0);
				start = simple_strtoul(buf, &buf, 0);
				pnp_res = pnp_add_irq_resource(dev, start, 0);
				pnp_add_irq_resource(dev, start, 0);
				if (pnp_res)
					pnp_res->index = nirq++;
				continue;
				continue;
			}
			}
			if (!strnicmp(buf, "dma", 3)) {
			if (!strnicmp(buf, "dma", 3)) {
@@ -432,9 +422,7 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr,
				while (isspace(*buf))
				while (isspace(*buf))
					++buf;
					++buf;
				start = simple_strtoul(buf, &buf, 0);
				start = simple_strtoul(buf, &buf, 0);
				pnp_res = pnp_add_dma_resource(dev, start, 0);
				pnp_add_dma_resource(dev, start, 0);
				if (pnp_res)
					pnp_res->index = ndma++;
				continue;
				continue;
			}
			}
			break;
			break;
+29 −55
Original line number Original line Diff line number Diff line
@@ -928,7 +928,6 @@ EXPORT_SYMBOL(isapnp_write_byte);


static int isapnp_get_resources(struct pnp_dev *dev)
static int isapnp_get_resources(struct pnp_dev *dev)
{
{
	struct pnp_resource *pnp_res;
	int i, ret;
	int i, ret;


	dev_dbg(&dev->dev, "get resources\n");
	dev_dbg(&dev->dev, "get resources\n");
@@ -940,35 +939,23 @@ static int isapnp_get_resources(struct pnp_dev *dev)


	for (i = 0; i < ISAPNP_MAX_PORT; i++) {
	for (i = 0; i < ISAPNP_MAX_PORT; i++) {
		ret = isapnp_read_word(ISAPNP_CFG_PORT + (i << 1));
		ret = isapnp_read_word(ISAPNP_CFG_PORT + (i << 1));
		if (ret) {
		pnp_add_io_resource(dev, ret, ret,
			pnp_res = pnp_add_io_resource(dev, ret, ret, 0);
				    ret == 0 ? IORESOURCE_DISABLED : 0);
			if (pnp_res)
				pnp_res->index = i;
		}
	}
	}
	for (i = 0; i < ISAPNP_MAX_MEM; i++) {
	for (i = 0; i < ISAPNP_MAX_MEM; i++) {
		ret = isapnp_read_word(ISAPNP_CFG_MEM + (i << 3)) << 8;
		ret = isapnp_read_word(ISAPNP_CFG_MEM + (i << 3)) << 8;
		if (ret) {
		pnp_add_mem_resource(dev, ret, ret,
			pnp_res = pnp_add_mem_resource(dev, ret, ret, 0);
				     ret == 0 ? IORESOURCE_DISABLED : 0);
			if (pnp_res)
				pnp_res->index = i;
		}
	}
	}
	for (i = 0; i < ISAPNP_MAX_IRQ; i++) {
	for (i = 0; i < ISAPNP_MAX_IRQ; i++) {
		ret = isapnp_read_word(ISAPNP_CFG_IRQ + (i << 1)) >> 8;
		ret = isapnp_read_word(ISAPNP_CFG_IRQ + (i << 1)) >> 8;
		if (ret) {
		pnp_add_irq_resource(dev, ret,
			pnp_res = pnp_add_irq_resource(dev, ret, 0);
				     ret == 0 ? IORESOURCE_DISABLED : 0);
			if (pnp_res)
				pnp_res->index = i;
		}
	}
	}
	for (i = 0; i < ISAPNP_MAX_DMA; i++) {
	for (i = 0; i < ISAPNP_MAX_DMA; i++) {
		ret = isapnp_read_byte(ISAPNP_CFG_DMA + i);
		ret = isapnp_read_byte(ISAPNP_CFG_DMA + i);
		if (ret != 4) {
		pnp_add_dma_resource(dev, ret,
			pnp_res = pnp_add_dma_resource(dev, ret, 0);
				     ret == 4 ? IORESOURCE_DISABLED : 0);
			if  (pnp_res)
				pnp_res->index = i;
		}
	}
	}


__end:
__end:
@@ -978,62 +965,49 @@ static int isapnp_get_resources(struct pnp_dev *dev)


static int isapnp_set_resources(struct pnp_dev *dev)
static int isapnp_set_resources(struct pnp_dev *dev)
{
{
	struct pnp_resource *pnp_res;
	struct resource *res;
	struct resource *res;
	int tmp, index;
	int tmp;


	dev_dbg(&dev->dev, "set resources\n");
	dev_dbg(&dev->dev, "set resources\n");
	isapnp_cfg_begin(dev->card->number, dev->number);
	isapnp_cfg_begin(dev->card->number, dev->number);
	dev->active = 1;
	dev->active = 1;
	for (tmp = 0; tmp < ISAPNP_MAX_PORT; tmp++) {
	for (tmp = 0; tmp < ISAPNP_MAX_PORT; tmp++) {
		pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_IO, tmp);
		res = pnp_get_resource(dev, IORESOURCE_IO, tmp);
		if (!pnp_res)
		if (res && pnp_resource_valid(res) &&
			continue;
		    !(res->flags & IORESOURCE_DISABLED)) {
		res = &pnp_res->res;
		if (pnp_resource_valid(res)) {
			index = pnp_res->index;
			dev_dbg(&dev->dev, "  set io  %d to %#llx\n",
			dev_dbg(&dev->dev, "  set io  %d to %#llx\n",
				index, (unsigned long long) res->start);
				tmp, (unsigned long long) res->start);
			isapnp_write_word(ISAPNP_CFG_PORT + (index << 1),
			isapnp_write_word(ISAPNP_CFG_PORT + (tmp << 1),
					  res->start);
					  res->start);
		}
		}
	}
	}
	for (tmp = 0; tmp < ISAPNP_MAX_IRQ; tmp++) {
	for (tmp = 0; tmp < ISAPNP_MAX_IRQ; tmp++) {
		pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_IRQ, tmp);
		res = pnp_get_resource(dev, IORESOURCE_IRQ, tmp);
		if (!pnp_res)
		if (res && pnp_resource_valid(res) &&
			continue;
		    !(res->flags & IORESOURCE_DISABLED)) {
		res = &pnp_res->res;
		if (pnp_resource_valid(res)) {
			int irq = res->start;
			int irq = res->start;
			if (irq == 2)
			if (irq == 2)
				irq = 9;
				irq = 9;
			index = pnp_res->index;
			dev_dbg(&dev->dev, "  set irq %d to %d\n", tmp, irq);
			dev_dbg(&dev->dev, "  set irq %d to %d\n", index, irq);
			isapnp_write_byte(ISAPNP_CFG_IRQ + (tmp << 1), irq);
			isapnp_write_byte(ISAPNP_CFG_IRQ + (index << 1), irq);
		}
		}
	}
	}
	for (tmp = 0; tmp < ISAPNP_MAX_DMA; tmp++) {
	for (tmp = 0; tmp < ISAPNP_MAX_DMA; tmp++) {
		pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_DMA, tmp);
		res = pnp_get_resource(dev, IORESOURCE_DMA, tmp);
		if (!pnp_res)
		if (res && pnp_resource_valid(res) &&
			continue;
		    !(res->flags & IORESOURCE_DISABLED)) {
		res = &pnp_res->res;
		if (pnp_resource_valid(res)) {
			index = pnp_res->index;
			dev_dbg(&dev->dev, "  set dma %d to %lld\n",
			dev_dbg(&dev->dev, "  set dma %d to %lld\n",
				index, (unsigned long long) res->start);
				tmp, (unsigned long long) res->start);
			isapnp_write_byte(ISAPNP_CFG_DMA + index, res->start);
			isapnp_write_byte(ISAPNP_CFG_DMA + tmp, res->start);
		}
		}
	}
	}
	for (tmp = 0; tmp < ISAPNP_MAX_MEM; tmp++) {
	for (tmp = 0; tmp < ISAPNP_MAX_MEM; tmp++) {
		pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_MEM, tmp);
		res = pnp_get_resource(dev, IORESOURCE_MEM, tmp);
		if (!pnp_res)
		if (res && pnp_resource_valid(res) &&
			continue;
		    !(res->flags & IORESOURCE_DISABLED)) {
		res = &pnp_res->res;
		if (pnp_resource_valid(res)) {
			index = pnp_res->index;
			dev_dbg(&dev->dev, "  set mem %d to %#llx\n",
			dev_dbg(&dev->dev, "  set mem %d to %#llx\n",
				index, (unsigned long long) res->start);
				tmp, (unsigned long long) res->start);
			isapnp_write_word(ISAPNP_CFG_MEM + (index << 3),
			isapnp_write_word(ISAPNP_CFG_MEM + (tmp << 3),
					  (res->start >> 8) & 0xffff);
					  (res->start >> 8) & 0xffff);
		}
		}
	}
	}
+0 −4
Original line number Original line Diff line number Diff line
@@ -40,7 +40,6 @@ static int pnp_assign_port(struct pnp_dev *dev, struct pnp_port *rule, int idx)
	}
	}


	/* set the initial values */
	/* set the initial values */
	pnp_res->index = idx;
	res->flags |= rule->flags | IORESOURCE_IO;
	res->flags |= rule->flags | IORESOURCE_IO;
	res->flags &= ~IORESOURCE_UNSET;
	res->flags &= ~IORESOURCE_UNSET;


@@ -90,7 +89,6 @@ static int pnp_assign_mem(struct pnp_dev *dev, struct pnp_mem *rule, int idx)
	}
	}


	/* set the initial values */
	/* set the initial values */
	pnp_res->index = idx;
	res->flags |= rule->flags | IORESOURCE_MEM;
	res->flags |= rule->flags | IORESOURCE_MEM;
	res->flags &= ~IORESOURCE_UNSET;
	res->flags &= ~IORESOURCE_UNSET;


@@ -155,7 +153,6 @@ static int pnp_assign_irq(struct pnp_dev *dev, struct pnp_irq *rule, int idx)
	}
	}


	/* set the initial values */
	/* set the initial values */
	pnp_res->index = idx;
	res->flags |= rule->flags | IORESOURCE_IRQ;
	res->flags |= rule->flags | IORESOURCE_IRQ;
	res->flags &= ~IORESOURCE_UNSET;
	res->flags &= ~IORESOURCE_UNSET;


@@ -214,7 +211,6 @@ static void pnp_assign_dma(struct pnp_dev *dev, struct pnp_dma *rule, int idx)
	}
	}


	/* set the initial values */
	/* set the initial values */
	pnp_res->index = idx;
	res->flags |= rule->flags | IORESOURCE_DMA;
	res->flags |= rule->flags | IORESOURCE_DMA;
	res->flags &= ~IORESOURCE_UNSET;
	res->flags &= ~IORESOURCE_UNSET;