Re: [PATCH 3/3] PNP cleanups - Version 2 - Pass struct pnp_dev to pnp_clean_resource_table for cleanup reasons

Previous thread: [PATCH 2/3] PNP cleanups - Version 2 - Unify the pnp macros to access resources in the pnp resource table by Thomas Renninger on Tuesday, November 20, 2007 - 10:52 am. (1 message)

Next thread: [GIT PATCH] ACPI patches for 2.6.24-rc3 by Len Brown on Tuesday, November 20, 2007 - 11:13 am. (1 message)
From: Thomas Renninger
Date: Tuesday, November 20, 2007 - 10:52 am

Pass struct pnp_dev to pnp_clean_resource_table for cleanup reasons

Signed-off-by: Thomas Renninger <trenn@suse.de>

---
 drivers/pnp/manager.c |   36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)

Index: linux-2.6.24-rc2-mm1/drivers/pnp/manager.c
===================================================================
--- linux-2.6.24-rc2-mm1.orig/drivers/pnp/manager.c
+++ linux-2.6.24-rc2-mm1/drivers/pnp/manager.c
@@ -235,38 +235,38 @@ void pnp_init_resource_table(struct pnp_
  * pnp_clean_resources - clears resources that were not manually set
  * @res: the resources to clean
  */
-static void pnp_clean_resource_table(struct pnp_resource_table *res)
+static void pnp_clean_resource_table(struct pnp_dev *dev)
 {
 	int idx;
 
 	for (idx = 0; idx < PNP_MAX_IRQ; idx++) {
-		if (!(res->irq_resource[idx].flags & IORESOURCE_AUTO))
+		if (!(pnp_irq_flags(dev, idx) & IORESOURCE_AUTO))
 			continue;
-		res->irq_resource[idx].start = -1;
-		res->irq_resource[idx].flags =
+		pnp_irq_no(dev, idx) = -1;
+		pnp_irq_flags(dev, idx) =
 		    IORESOURCE_IRQ | IORESOURCE_AUTO | IORESOURCE_UNSET;
 	}
 	for (idx = 0; idx < PNP_MAX_DMA; idx++) {
-		if (!(res->dma_resource[idx].flags & IORESOURCE_AUTO))
+		if (!(pnp_dma_flags(dev, idx) & IORESOURCE_AUTO))
 			continue;
-		res->dma_resource[idx].start = -1;
-		res->dma_resource[idx].flags =
+		pnp_dma_no(dev, idx) = -1;
+		pnp_dma_flags(dev, idx) =
 		    IORESOURCE_DMA | IORESOURCE_AUTO | IORESOURCE_UNSET;
 	}
 	for (idx = 0; idx < PNP_MAX_PORT; idx++) {
-		if (!(res->port_resource[idx].flags & IORESOURCE_AUTO))
+		if (!(pnp_port_flags(dev, idx) & IORESOURCE_AUTO))
 			continue;
-		res->port_resource[idx].start = 0;
-		res->port_resource[idx].end = 0;
-		res->port_resource[idx].flags =
+		pnp_port_start(dev, idx) = 0;
+		pnp_port_end(dev, idx) = 0;
+		pnp_port_flags(dev, idx) =
 		    IORESOURCE_IO | IORESOURCE_AUTO | IORESOURCE_UNSET;
 	}
 	for (idx = 0; idx < PNP_MAX_MEM; idx++) {
-		if ...

On Tue, 20 Nov 2007 18:52:04 +0100

Again I don't see the point of this change. A routine for cleaning up
resource tables expects logically to be passed a resource table to clean
up not some device it may be attached to.

Perhaps if you could explain where you are trying to end up, it would
help understand what you are trying to do.

I don't see why pnp_dma() and pnp_irq() should change either. It just
causes noise and breaks driver code. I don't see where it needs to change
to make internal pnp changes work ?

Alan
-


He needs to pass the pnp_dev to later be able to replace the:

	for (idx = 0; idx < PNP_MAX_PORT; idx++)

loops with:

	for (idx = 0; pnp_port(dev, idx); idx++)

in a later patch when he introduces dynamic resource tables -- pnp-acpi can 
(and does) now sometimes require more resources than the current pnp limits 
allow but simply upping the limits uncoditionally wastes too much space in 

As he explained in his 0/3, his pnp_port() would look like:

#define pnp_port(dev,bar)      ((dev)->res.allocated_ports > (bar) \
	? (&(dev)->res.port_resource[(bar)]) : NULL)

If the above replacement was the only use for the macros, he could as well do:

	for (idx = 0; idx < dev->res.allocated_ports; idx++)

but given that he'll need to get at the resource more generally, the simple 
pnp_port(), pnp_irq(), pnp_dma() and pnp_mem() names sound best. It would 
ofcourse be possible to call them something like pnp_port_addr() as well but 
given that he only needs to get rid of pnp_irq() and pnp_dma() to have these 
better names available, I'd say go for it.

pnp_{irq,dma}_no(), or pnp_{irq,dma}_start() as he originally proposed and 
which has consistency both with the existing pnp_{port,mem}_start() and the 
struct resource name as its plus should be fine and he then frees up the 
better names for the new use which should make for better readable code at 
the end of things.

My vote's with pnp_irq_start(). As said, consistent both with the port and 
mem variants and the struct resource usage and name.

Rene.

-


I can see why he does it, but that doesn't answer the problem that the

That bit is fine, but put the count in the resource structure. Then you
can pass a resource around as a meaningful self contained object. That
means you can pass them, ref count them and whatever else is needed.

(Remember if you krealloc a pnp resource you have to know *nobody* is
using the existing resource pointer at that moment, so you will need

You don't need to change the names - just the code. 

Lets split the problems I have with it into three areas

1.	Changes the interface to drivers but for no apparent reason in
part.

2.	Hides a lot of stuff in macros so we get peculiar un C like
assignments that hide the actual functionality. I want to *see* what is
going on when I touch the code not hide it, at least within the pnp layer

3.	Object lifetime and internal completeness - dev->res should
point to everything that is neccessary to manage the resource set. It
should be updatable in a consistent locked manner. That matters the
moment you do any dynamic reassignment of resources affecting a live
object, it matters the moment you want to do things like work with
resources cleanly without the device structure.

Now I would suggest that #2 and #3 actually matter right now. We can
argue about whether its called a wombat or banana and rename them any day
of the week.


What I would thus like to see is a patch set which

1.	Switches to krealloc resources internally and moves the
resource count sizes into the resource object but without hiding internal
detail in magic macros (macros for device side are good internal bad
generally). Nothing dynamic after setup *yet*

2.	Update any driver specific assumptions about resource walking

-

From: Rene Herman
Date: Wednesday, November 21, 2007 - 1:37 am

Not much of an interface. Note that pnp_clean_resource_table is an internal 
helper function in drivers/pnp/manager.c, unexported and with a mere three 
call sites that each call it as pnp_clean_resource_table(&dev->res). A small 

I suppose you mean put the count inside the resource _table_ structure? It 
is a count of resource structures after all. Inside the table is where he 
did in fact propose it would go (dev->res.allocated_ports) but logically a 
pnp_dev and its pnp_resource_table are one and the same; "res" is embedded 
in the pnp_dev. That is, the resources are tied to the device, with struct 
pnp_resource_table being no more than a handy container to group them under 
a single name.

Only the pnp_resource_change export (that is, the pnp_init_resource_table 
and pnp_manual_config_dev exports) give a pnp_resource_table struct slightly 
more of a life of its own but those are only used by the ALSA ISAPnP drivers 
in what I as stated before personally consider a bad layering violation and 
would be more than happy to fix after which they can just go -- they have no 
possible uses _other_ than layering violations.

See the existing pnp design as well; all the resource stuff does the same 
thing in taking a pnp_dev and then returning from dev->res:

#define pnp_port_start(dev,bar)   ((dev)->res.port_resource[(bar)].start)
#define pnp_port_end(dev,bar)     ((dev)->res.port_resource[(bar)].end)

and so on. From a consistency standpoint making his new setup use this same 

Yes, I dont know how he intends to deal with this (nor, in fact, just how 

Really. Only pnp_irq -> pnp_irq_start (or _no if really need be) and same 

Yes, not hugely fond of the lvalue thing either. Andrew commented that he 
found if to be okay-ish from a consistency standpoint. <shrug>

Quite frankly, I've had enough email to PnP maintainer(s) disappear into 
blackholes now that I'm happy already to see some action. If I'm right that 
I should consider Bjorn Helgaas the PnP maintainer now, I'd vote ...
From: Thomas Renninger
Date: Wednesday, November 21, 2007 - 2:43 am

The idea is to not rely on the exact pnp resource table structure and
abstracting this to macros. If krealloc approach works,
dev->res.port_resource[i].start would even still work, if not, it's
Krealloc should only get used at early pnp init time, when the BIOS
structures are parsed. The devices shouldn't be active then...
A bit of a problem, as said, could be the sysfs interfaces, there it
Ok, I think I see the main problem: Externally built drivers would
break.
I can try with a "do not alter exported interfaces if it could be
avoided" approach.

I'd add these then:
#define pnp_port_ptr(dev,bar)
#define pnp_dma_ptr(dev,bar)
...

I will come back in some days...

    Thomas

-


Externally in drivers yes. Internally in code no - it makes the code

I don't think its that simple but that can be dealt with one the changes
are in place if the objects are sensibly laid out.

Alan
-

From: Thomas Renninger
Date: Wednesday, November 21, 2007 - 4:05 pm

The additional variable would only make sense for the pnp layer, or only
for the pnp resource table in the pnp layer, but struct resource is used
at much more places...
It is meant for System Memory and IO port resources in general, why
waste bytes and an additional name at all places it is used, just for

I hope it is, stay tuned there will come something soon...
If it's not that easy, another structure would be needed and every
dev->res.port_resource[i].start and friends need to be touched (I don't
see how this could still be resolved in a simple array then...).

    Thomas

-

Previous thread: [PATCH 2/3] PNP cleanups - Version 2 - Unify the pnp macros to access resources in the pnp resource table by Thomas Renninger on Tuesday, November 20, 2007 - 10:52 am. (1 message)

Next thread: [GIT PATCH] ACPI patches for 2.6.24-rc3 by Len Brown on Tuesday, November 20, 2007 - 11:13 am. (1 message)