Skip to contentSkip to conversation

PNP cleanups - Make use of pnp_{port,mem,irq,dma}_{start,end,flags} macros wherever possible

PATCH NAK Thomas Renninger 3 participants 3 messages Nov 20, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 PNP cleanups - Make use of pnp_{port,mem,irq,dma}_{start,end,flags} macros wherever possible

Make use of pnp_{port,mem,irq,dma}_{start,end,flags} macros wherever possible

The macros to access the resource table in pnp sublayer was not used consequently.
This patch makes use of these macros instead of accessing the resource arrays directly.

For dma and irq also pnp_{dma,irq}_{start,end} macros have been introduced to unify the access to the different resource types.

The pnp_{irq,dma} macros has now the same functionality than the:
pnp_{irq,dma}_start macros. This will be cleaned up by the next patch.

---
 drivers/pnp/interface.c    |   52 +++++++++++++++-----------------
 drivers/pnp/manager.c      |   28 ++++++++---------
 drivers/pnp/pnpacpi/core.c |    2 -
 drivers/pnp/resource.c     |   72 +++++++++++++++++++++------------------------
 drivers/pnp/support.c      |    2 -
 include/linux/pnp.h        |    4 ++
 6 files changed, 79 insertions(+), 81 deletions(-)
include/linux/pnp.h +4 -0
Index: torvalds.current/include/linux/pnp.h
===================================================================
@@ -56,12 +56,16 @@ struct pnp_dev;
 	  pnp_mem_start((dev),(bar)) + 1))
 
 #define pnp_irq(dev,bar)	 ((dev)->res.irq_resource[(bar)].start)
+#define pnp_irq_start(dev,bar)	 ((dev)->res.irq_resource[(bar)].start)
+#define pnp_irq_end(dev,bar)	 ((dev)->res.irq_resource[(bar)].end)
 #define pnp_irq_flags(dev,bar)	 ((dev)->res.irq_resource[(bar)].flags)
 #define pnp_irq_valid(dev,bar) \
 	((pnp_irq_flags((dev),(bar)) & (IORESOURCE_IRQ | IORESOURCE_UNSET)) \
 		== IORESOURCE_IRQ)
 
 #define pnp_dma(dev,bar)	 ((dev)->res.dma_resource[(bar)].start)
+#define pnp_dma_start(dev,bar)	 ((dev)->res.dma_resource[(bar)].start)
+#define pnp_dma_end(dev,bar)	 ((dev)->res.dma_resource[(bar)].end)
 #define pnp_dma_flags(dev,bar)	 ((dev)->res.dma_resource[(bar)].flags)
 #define pnp_dma_valid(dev,bar) \
 	((pnp_dma_flags((dev),(bar)) & (IORESOURCE_DMA | IORESOURCE_UNSET)) \
drivers/pnp/manager.c +14 -14
Index: torvalds.current/drivers/pnp/manager.c
===================================================================
@@ -28,12 +28,12 @@ static int pnp_assign_port(struct pnp_de
 	}
 
 	/* check if this resource has been manually set, if so skip */
-	if (!(dev->res.port_resource[idx].flags & IORESOURCE_AUTO))
+	if (!(pnp_port_flags(dev, idx) & IORESOURCE_AUTO))
 		return 1;
 
-	start = &dev->res.port_resource[idx].start;
-	end = &dev->res.port_resource[idx].end;
-	flags = &dev->res.port_resource[idx].flags;
+	start = &pnp_port_start(dev, idx);
+	end = &pnp_port_end(dev, idx);
+	flags = &pnp_port_flags(dev, idx);
 
 	/* set the initial values */
 	*flags |= rule->flags | IORESOURCE_IO;
@@ -72,9 +72,9 @@ static int pnp_assign_mem(struct pnp_dev
 	if (!(dev->res.mem_resource[idx].flags & IORESOURCE_AUTO))
 		return 1;
 
-	start = &dev->res.mem_resource[idx].start;
-	end = &dev->res.mem_resource[idx].end;
-	flags = &dev->res.mem_resource[idx].flags;
+	start = &pnp_mem_start(dev, idx);
+	end = &pnp_mem_end(dev, idx);
+	flags = &pnp_mem_flags(dev, idx);
 
 	/* set the initial values */
 	*flags |= rule->flags | IORESOURCE_MEM;
@@ -129,9 +129,9 @@ static int pnp_assign_irq(struct pnp_dev
 	if (!(dev->res.irq_resource[idx].flags & IORESOURCE_AUTO))
 		return 1;
 
-	start = &dev->res.irq_resource[idx].start;
-	end = &dev->res.irq_resource[idx].end;
-	flags = &dev->res.irq_resource[idx].flags;
+	start = &pnp_irq_start(dev, idx);
+	end = &pnp_irq_end(dev, idx);
+	flags = &pnp_irq_flags(dev, idx);
 
 	/* set the initial values */
 	*flags |= rule->flags | IORESOURCE_IRQ;
@@ -175,12 +175,12 @@ static void pnp_assign_dma(struct pnp_de
 	}
 
 	/* check if this resource has been manually set, if so skip */
-	if (!(dev->res.dma_resource[idx].flags & IORESOURCE_AUTO))
+	if (!(pnp_dma_flags(dev, idx) & IORESOURCE_AUTO))
 		return;
 
-	start = &dev->res.dma_resource[idx].start;
-	end = &dev->res.dma_resource[idx].end;
-	flags = &dev->res.dma_resource[idx].flags;
+	start = &pnp_dma_start(dev, idx);
+	end = &pnp_dma_end(dev, idx);
+	flags = &pnp_dma_flags(dev, idx);
 
 	/* set the initial values */
 	*flags |= rule->flags | IORESOURCE_DMA;
drivers/pnp/interface.c +25 -27

102 lines not on this page · raw message

drivers/pnp/resource.c +34 -38

156 lines not on this page · raw message

drivers/pnp/support.c +1 -1
Index: torvalds.current/drivers/pnp/support.c
===================================================================
@@ -18,7 +18,7 @@ int pnp_is_active(struct pnp_dev *dev)
 {
 	if (!pnp_port_start(dev, 0) && pnp_port_len(dev, 0) <= 1 &&
 	    !pnp_mem_start(dev, 0) && pnp_mem_len(dev, 0) <= 1 &&
-	    pnp_irq(dev, 0) == -1 && pnp_dma(dev, 0) == -1)
+	    pnp_irq_start(dev, 0) == -1 && pnp_dma_start(dev, 0) == -1)
 		return 0;
 	else
 		return 1;
drivers/pnp/pnpacpi/core.c +1 -1
Index: torvalds.current/drivers/pnp/pnpacpi/core.c
===================================================================
@@ -121,7 +121,7 @@ static int pnpacpi_disable_resources(str
 {
 	acpi_status status;
 
-	/* acpi_unregister_gsi(pnp_irq(dev, 0)); */
+	/* acpi_unregister_gsi(pnp_irq_start(dev, 0)); */
 	status = acpi_evaluate_object((acpi_handle) dev->data,
 				      "_DIS", NULL, NULL);
 	return ACPI_FAILURE(status) ? -ENODEV : 0;
Acked-by on v1 1/3
#1 lore raw
Quoted 7 lines · Thomas Renninger

Make use of pnp_{port,mem,irq,dma}_{start,end,flags} macros wherever possible

The macros to access the resource table in pnp sublayer was not used consequently.
This patch makes use of these macros instead of accessing the resource arrays directly.

Quoted 7 lines

For dma and irq also pnp_{dma,irq}_{start,end} macros have been introduced to unify the access to the different resource types.

The pnp_{irq,dma} macros has now the same functionality than the:
pnp_{irq,dma}_start macros. This will be cleaned up by the next patch.

Earlier comments (in private mail):

Quoted 10 lines
Quoted 5 lines
drivers/pnp/interface.c +1 -1
-                dev->res.port_resource[nport].start =
+                pnp_port_start(dev, nport) =
                     simple_strtoul(buf, &buf, 0);

If I'm not mistaken, there's a standing fatwa on macros as lvalues. Andrew?

Andrew Morton wrote:

Well, it's a pretty nasty thing to do, IMO. But given that we've already gone and done it I suppose the change is OK from a consistency POV.

Otherwise acked as identity transformation.

Rene.

#2 lore raw
In reply to Thomas Renninger

include/linux/pnp.h struct pnp_dev; · line 60

Quoted 3 lines

#define pnp_irq(dev,bar) ((dev)->res.irq_resource[(bar)].start)

include/linux/pnp.h +2 -0
+#define pnp_irq_start(dev,bar)	 ((dev)->res.irq_resource[(bar)].start)
+#define pnp_irq_end(dev,bar)	 ((dev)->res.irq_resource[(bar)].end)

NAK as discussed earlier.

include/linux/pnp.h struct pnp_dev; · line 68

Quoted 8 lines

#define pnp_irq_flags(dev,bar) ((dev)->res.irq_resource[(bar)].flags)
#define pnp_irq_valid(dev,bar) \

include/linux/pnp.h +2 -0
 	((pnp_irq_flags((dev),(bar)) & (IORESOURCE_IRQ | IORESOURCE_UNSET)) \
 		== IORESOURCE_IRQ)
 
 #define pnp_dma(dev,bar)	 ((dev)->res.dma_resource[(bar)].start)
+#define pnp_dma_start(dev,bar)	 ((dev)->res.dma_resource[(bar)].start)
+#define pnp_dma_end(dev,bar)	 ((dev)->res.dma_resource[(bar)].end)

Ditto DMA is not range based.