Skip to contentSkip to conversation

PNP: Allow PNP resources to be disabled (interface)

PATCH Superseded Witold Szczeponik 2 participants 7 messages Apr 11, 2012 – Jun 3, 2012

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover PNP: Allow PNP resources to be disabled (interface)

Hello everybody,

this simple patch series continues the work begun in commit 18fd470a48396c8795ba7256c5973e92ffa25cb3 where ACPI PNP resource templates with empty/disabled resources are handled.

The aim of this patch series is to allow to set resources as "disabled" using the "/sys/bus/pnp/devices/*/resources" interface. Such "disabled" resources are needed by some vintage IBM ThinkPads like the 600E where some devices need to have their IRQs disabled in order to support all the devices the 600E has.

To better understand the motivation, let's look at an excerpt from the 600E's DSDT:

    Name (PLPT, ResourceTemplate ()
    {
        StartDependentFnNoPri ()
        {
            IO (Decode16, 0x03BC, 0x03BC, 0x01, 0x04)
            IRQNoFlags () {7}
        }
        /* Some entries deleted */
        StartDependentFnNoPri ()
        {
            IO (Decode16, 0x03BC, 0x03BC, 0x01, 0x04)
            IRQNoFlags () {}
        }
        EndDependentFn ()
    })

As one can see, the IRQ line for the second option is empty/disabled. Also, both options share the same priority. In order to be able to use the IRQ 7 for some other device, it is necessary to select the second option, which can be done with the patch series applied.

To this end, some preparatory work is done, simplifying the code, and fixing a potential issue when explicitely assigning resources.

Here's a brief description of these patches.

[1/3] - Factor out common some code
[2/3] - Perform the actual setting
[3/3] - Handle IORESOURCE_BITS in resource allocation

The patches are applied against Linux 3.3.x.

Comments are, as always, welcome.

Changes from previous versions:

V1 -> V2: Split [V1 2/3] into [V2 2/3] and [V2 3/3]
Removed [V1 3/3], will be submitted separately Wrote more comments in response to the previous version Sent to a broader audience

V1: Initial version (https://lkml.org/lkml/2012/3/20/358)

--- Witold

#1 lore raw

PATCH v2 1/3 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 will 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.

The patch is applied against Linux 3.3.x.

drivers/pnp/interface.c +68 -37
Index: linux/drivers/pnp/interface.c
===================================================================
@@ -298,6 +298,39 @@ static ssize_t pnp_show_current_resource
 	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,
 					 struct device_attribute *attr,
 					 const char *ubuf, size_t count)
@@ -305,7 +338,6 @@ static ssize_t pnp_set_current_resources
 	struct pnp_dev *dev = to_pnp_dev(dmdev);
 	char *buf = (void *)ubuf;
 	int retval = 0;
-	resource_size_t start, end;
 
 	if (dev->status & PNP_ATTACHED) {
 		retval = -EBUSY;
@@ -349,6 +381,10 @@ static ssize_t pnp_set_current_resources
 		goto done;
 	}
 	if (!strnicmp(buf, "set", 3)) {
+		resource_size_t start;
+		resource_size_t end;
+		unsigned long flags;
+
 		if (dev->active)
 			goto done;
 		buf += 3;
@@ -357,42 +393,37 @@ static ssize_t pnp_set_current_resources
 		while (1) {
 			buf = skip_spaces(buf);
 			if (!strnicmp(buf, "io", 2)) {
-				buf = skip_spaces(buf + 2);
-				start = simple_strtoul(buf, &buf, 0);
-				buf = skip_spaces(buf);
-				if (*buf == '-') {
-					buf = skip_spaces(buf + 1);
-					end = simple_strtoul(buf, &buf, 0);
-				} else
-					end = start;
-				pnp_add_io_resource(dev, start, end, 0);
-				continue;
-			}
-			if (!strnicmp(buf, "mem", 3)) {
-				buf = skip_spaces(buf + 3);
-				start = simple_strtoul(buf, &buf, 0);
-				buf = skip_spaces(buf);
-				if (*buf == '-') {
-					buf = skip_spaces(buf + 1);
-					end = simple_strtoul(buf, &buf, 0);
-				} else
-					end = start;
-				pnp_add_mem_resource(dev, start, end, 0);
-				continue;
-			}
-			if (!strnicmp(buf, "irq", 3)) {
-				buf = skip_spaces(buf + 3);
-				start = simple_strtoul(buf, &buf, 0);
-				pnp_add_irq_resource(dev, start, 0);
-				continue;
-			}
-			if (!strnicmp(buf, "dma", 3)) {
-				buf = skip_spaces(buf + 3);
-				start = simple_strtoul(buf, &buf, 0);
-				pnp_add_dma_resource(dev, start, 0);
-				continue;
-			}
-			break;
+				buf = pnp_get_resource_value(buf + 2,
+							     IORESOURCE_IO,
+							     &start, &end,
+							     &flags);
+				pnp_add_io_resource(dev, start, end, flags);
+			} else if (!strnicmp(buf, "mem", 3)) {
+				buf = pnp_get_resource_value(buf + 3,
+							     IORESOURCE_MEM,
+							     &start, &end,
+							     &flags);
+				pnp_add_mem_resource(dev, start, end, flags);
+			} else if (!strnicmp(buf, "irq", 3)) {
+				buf = pnp_get_resource_value(buf + 3,
+							     IORESOURCE_IRQ,
+							     &start, NULL,
+							     &flags);
+				pnp_add_irq_resource(dev, start, flags);
+			} else if (!strnicmp(buf, "dma", 3)) {
+				buf = pnp_get_resource_value(buf + 3,
+							     IORESOURCE_DMA,
+							     &start, NULL,
+							     &flags);
+				pnp_add_dma_resource(dev, start, flags);
+			} else if (!strnicmp(buf, "bus", 3)) {
+				buf = pnp_get_resource_value(buf + 3,
+							     IORESOURCE_BUS,
+							     &start, &end,
+							     NULL);
+				pnp_add_bus_resource(dev, start, end);
+			} else
+				break;
 		}
 		mutex_unlock(&pnp_res_mutex);
 		goto done;
#2 lore raw

PATCH v2 2/3 PNP: Allow resources to be set as disabled

In reply to Witold Szczeponik

This patch allows to set PNP resources as "disabled". As such, the patch is a follow-up to commit 18fd470a48396c8795ba7256c5973e92ffa25cb3 where parsing of ACPI PNP resources that can be disabled was made possible.

The patch achieves this by allowing the strings "disabled" and "<none>" to be used as a valid PNP resource value. The value "disabled" is used because it also appears when reporting PNP resources, whereas the string "<none>" is used when reporting PNP options.

The patch is required in order to support the setting of "disabled" IRQs like described in the commit 29df8d8f8702f0f53c1375015f09f04bc8d023c1, i.e., with this patch applied, some vintage IBM ThinkPads like the 600E can allocate the resources such that all devices can be used simultaneously.

The patch is applied against Linux 3.3.x.

drivers/pnp/interface.c +7 -3
Index: linux/drivers/pnp/interface.c
===================================================================
@@ -311,10 +311,14 @@ static char *pnp_get_resource_value(char
 	if (flags)
 		*flags = 0;
 
-	/* TBD: allow for disabled resources */
-
 	buf = skip_spaces(buf);
-	if (start) {
+	if (flags && !strnicmp(buf, "disabled", 8)) {
+		buf += 8;
+		*flags |= IORESOURCE_DISABLED;
+	} else if (flags && !strnicmp(buf, "<none>", 6)) {
+		buf += 6;
+		*flags |= IORESOURCE_DISABLED;
+	} else if (start) {
 		*start = simple_strtoull(buf, &buf, 0);
 		if (end) {
 			buf = skip_spaces(buf);
#3 lore raw

PATCH v2 3/3 PNP: Handle IORESOURCE_BITS in resource allocation

In reply to Witold Szczeponik

The patch copies the flags masked by IORESOURCE_BITS from a resource's template. This is necessary because the resource settings require proper IORESOURCE_BITS which are not known during the definition of these resources using the "/sys/bus/pnp/*/*/resources" interface. (In fact, they should not be set by the user as the resource templates define the proper settings.)

If the patch is not applied, the resource flags are not initialized properly and obscure messages in the kernel log have been seen ("invalid flags").

The patch is applied against Linux 3.3.x.

drivers/pnp/manager.c +21 -4
Index: linux/drivers/pnp/manager.c
===================================================================
@@ -18,11 +18,27 @@
 
 DEFINE_MUTEX(pnp_res_mutex);
 
+static struct resource *pnp_find_resource(struct pnp_dev *dev,
+					  unsigned char rule,
+					  unsigned long type,
+					  unsigned int bar)
+{
+	struct resource *res = pnp_get_resource(dev, type, bar);
+
+	/* when the resource already exists, set its resource bits from rule */
+	if (res) {
+		res->flags &= ~IORESOURCE_BITS;
+		res->flags |= rule & IORESOURCE_BITS;
+	}
+
+	return res;
+}
+
 static int pnp_assign_port(struct pnp_dev *dev, struct pnp_port *rule, int idx)
 {
 	struct resource *res, local_res;
 
-	res = pnp_get_resource(dev, IORESOURCE_IO, idx);
+	res = pnp_find_resource(dev, rule->flags, IORESOURCE_IO, idx);
 	if (res) {
 		pnp_dbg(&dev->dev, "  io %d already set to %#llx-%#llx "
 			"flags %#lx\n", idx, (unsigned long long) res->start,
@@ -65,7 +81,7 @@ static int pnp_assign_mem(struct pnp_dev
 {
 	struct resource *res, local_res;
 
-	res = pnp_get_resource(dev, IORESOURCE_MEM, idx);
+	res = pnp_find_resource(dev, rule->flags, IORESOURCE_MEM, idx);
 	if (res) {
 		pnp_dbg(&dev->dev, "  mem %d already set to %#llx-%#llx "
 			"flags %#lx\n", idx, (unsigned long long) res->start,
@@ -78,6 +94,7 @@ static int pnp_assign_mem(struct pnp_dev
 	res->start = 0;
 	res->end = 0;
 
+	/* ??? rule->flags restricted to 8 bits, all tests bogus ??? */
 	if (!(rule->flags & IORESOURCE_MEM_WRITEABLE))
 		res->flags |= IORESOURCE_READONLY;
 	if (rule->flags & IORESOURCE_MEM_CACHEABLE)
@@ -123,7 +140,7 @@ static int pnp_assign_irq(struct pnp_dev
 		5, 10, 11, 12, 9, 14, 15, 7, 3, 4, 13, 0, 1, 6, 8, 2
 	};
 
-	res = pnp_get_resource(dev, IORESOURCE_IRQ, idx);
+	res = pnp_find_resource(dev, rule->flags, IORESOURCE_IRQ, idx);
 	if (res) {
 		pnp_dbg(&dev->dev, "  irq %d already set to %d flags %#lx\n",
 			idx, (int) res->start, res->flags);
@@ -182,7 +199,7 @@ static int pnp_assign_dma(struct pnp_dev
 		1, 3, 5, 6, 7, 0, 2, 4
 	};
 
-	res = pnp_get_resource(dev, IORESOURCE_DMA, idx);
+	res = pnp_find_resource(dev, rule->flags, IORESOURCE_DMA, idx);
 	if (res) {
 		pnp_dbg(&dev->dev, "  dma %d already set to %d flags %#lx\n",
 			idx, (int) res->start, res->flags);
#4 lore raw

Re: [PATCH 3/3] PNP: Handle IORESOURCE_BITS in resource allocation

One small correction: the subject line should read

[PATCH V2 3/3] PNP: Handle IORESOURCE_BITS in resource allocation

to reflect that this patch is part of the second version of this patch series.

--- Witold

Quoted 86 lines · Witold Szczeponik

The patch copies the flags masked by IORESOURCE_BITS from a resource's template. This is necessary because the resource settings require proper IORESOURCE_BITS which are not known during the definition of these resources using the "/sys/bus/pnp/*/*/resources" interface. (In fact, they should not be set by the user as the resource templates define the proper settings.)

If the patch is not applied, the resource flags are not initialized properly and obscure messages in the kernel log have been seen ("invalid flags").

The patch is applied against Linux 3.3.x.

Index: linux/drivers/pnp/manager.c
===================================================================

drivers/pnp/manager.c +21 -4
@@ -18,11 +18,27 @@
 
  DEFINE_MUTEX(pnp_res_mutex);
 
+static struct resource *pnp_find_resource(struct pnp_dev *dev,
+					  unsigned char rule,
+					  unsigned long type,
+					  unsigned int bar)
+{
+	struct resource *res = pnp_get_resource(dev, type, bar);
+
+	/* when the resource already exists, set its resource bits from rule */
+	if (res) {
+		res->flags&= ~IORESOURCE_BITS;
+		res->flags |= rule&  IORESOURCE_BITS;
+	}
+
+	return res;
+}
+
  static int pnp_assign_port(struct pnp_dev *dev, struct pnp_port *rule, int idx)
  {
  	struct resource *res, local_res;
 
-	res = pnp_get_resource(dev, IORESOURCE_IO, idx);
+	res = pnp_find_resource(dev, rule->flags, IORESOURCE_IO, idx);
  	if (res) {
  		pnp_dbg(&dev->dev, "  io %d already set to %#llx-%#llx "
  			"flags %#lx\n", idx, (unsigned long long) res->start,
@@ -65,7 +81,7 @@ static int pnp_assign_mem(struct pnp_dev
  {
  	struct resource *res, local_res;
 
-	res = pnp_get_resource(dev, IORESOURCE_MEM, idx);
+	res = pnp_find_resource(dev, rule->flags, IORESOURCE_MEM, idx);
  	if (res) {
  		pnp_dbg(&dev->dev, "  mem %d already set to %#llx-%#llx "
  			"flags %#lx\n", idx, (unsigned long long) res->start,
@@ -78,6 +94,7 @@ static int pnp_assign_mem(struct pnp_dev
  	res->start = 0;
  	res->end = 0;
 
+	/* ??? rule->flags restricted to 8 bits, all tests bogus ??? */
  	if (!(rule->flags&  IORESOURCE_MEM_WRITEABLE))
  		res->flags |= IORESOURCE_READONLY;
  	if (rule->flags&  IORESOURCE_MEM_CACHEABLE)
@@ -123,7 +140,7 @@ static int pnp_assign_irq(struct pnp_dev
  		5, 10, 11, 12, 9, 14, 15, 7, 3, 4, 13, 0, 1, 6, 8, 2
  	};
 
-	res = pnp_get_resource(dev, IORESOURCE_IRQ, idx);
+	res = pnp_find_resource(dev, rule->flags, IORESOURCE_IRQ, idx);
  	if (res) {
  		pnp_dbg(&dev->dev, "  irq %d already set to %d flags %#lx\n",
  			idx, (int) res->start, res->flags);
@@ -182,7 +199,7 @@ static int pnp_assign_dma(struct pnp_dev
  		1, 3, 5, 6, 7, 0, 2, 4
  	};
 
-	res = pnp_get_resource(dev, IORESOURCE_DMA, idx);
+	res = pnp_find_resource(dev, rule->flags, IORESOURCE_DMA, idx);
  	if (res) {
  		pnp_dbg(&dev->dev, "  dma %d already set to %d flags %#lx\n",
  			idx, (int) res->start, res->flags);
#6 lore raw
Quoted 4 lines · Bjorn Helgaas
Quoted 2 lines · Witold Szczeponik

Hello everybody,

Quoted 8 lines
Quoted 3 lines

this simple patch series continues the work begun in commit 18fd470a48396c8795ba7256c5973e92ffa25cb3 where ACPI PNP resource templates with empty/disabled resources are handled.

For all three patches:

Hi Len,

I noticed that none of the patches made it into 3.5-rc1. These patches are important to support some (vintage) IBM ThinkPads, hence my interest in getting them included in the kernel. But they are also of general value and should not introduce any regressions.

If there is anything I still need to do, like providing better documentation, etc., just let me know.

NB: I am sending this mail to both the [email protected] and [email protected] addresses, for I received mails from you from either account. I apologize for any inconvenience caused by this.

Thanks. --- Witold