pnp: Register implementations of enter/exit config state

Find all the (ramstage) implementations of enter()/exit() functions
for the configuration state, register and call them through the new
struct pnp_mode_ops. As our standard PnP functions are aware of the
pnp_mode_ops, it's not necessary to call enter()/exit() around them
anymore.

Patch generated with the cocci below. It's not perfect. The movement
of the enter()/exit() calls is somehow fragile. So I checked the
remaining calls for sense, and changed some empty lines. Also a
duplicate insertion of pnp_conf_mode_ops had to be removed.
    /* Try to find enter and exit functions by their outb() structure and
       their usage around calls to our standard pnp functions: */
    @ enter_match @
    identifier enter;
    identifier dev;
    type device_t;
    @@
     void enter(device_t dev)
     {
             <...
             outb(..., dev->path.pnp.port);
             ...>
     }

    @ exit_match @
    identifier exit;
    identifier dev;
    type device_t;
    @@
     void exit(device_t dev)
     {
             <...
             outb(..., dev->path.pnp.port);
             ...>
     }

    @ pnp_match @
    identifier op;
    identifier pnp_op =~ "^pnp_((alt_|)enable|(set|enable)_resources)$";
    identifier enter_match.enter, exit_match.exit;
    type device_t;
    identifier dev;
    @@
     void op(device_t dev)
     {
             ...
             enter(dev);
             ...
             pnp_op(dev);
             ...
             exit(dev);
             ...
     }

    /* Now add enter/exit to a pnp_mode_ops structure: */
    @ depends on pnp_match @
    identifier enter_match.enter;
    identifier exit_match.exit;
    identifier ops;
    @@
    +static const struct pnp_mode_ops pnp_conf_mode_ops = {
    +        .enter_conf_mode  = enter,
    +        .exit_conf_mode   = exit,
    +};
    +
     struct device_operations ops = {
             ...,
    +        .ops_pnp_mode     = &pnp_conf_mode_ops,
     };

    /* Match against the new structure as we change the code and the above
       matches might not work anymore: */
    @ mode_match @
    identifier enter, exit, ops;
    @@
     struct pnp_mode_ops ops = {
             .enter_conf_mode  = enter,
             .exit_conf_mode   = exit,
     };

    /* Replace enter()/enter() calls with new standard calls (e.g.
       pnp_enter_conf_mode()): */
    @@
    identifier mode_match.enter;
    expression e;
    @@
    -enter(e)
    +pnp_enter_conf_mode(e)

    @@
    identifier mode_match.exit;
    expression e;
    @@
    -exit(e)
    +pnp_exit_conf_mode(e)

    /* If there are calls to standard PnP functions, (re)move the
       enter()/exit() calls around them: */
    @@
    identifier pnp_op =~ "^pnp_((alt_|)enable|(set|enable)_resources)$";
    expression e;
    @@
    -pnp_enter_conf_mode(e);
     pnp_op(e);
    +pnp_enter_conf_mode(e);
     ...
     pnp_exit_conf_mode(e);

    @@
    identifier pnp_op =~ "^pnp_((alt_|)enable|(set|enable)_resources)$";
    expression e;
    @@
     pnp_enter_conf_mode(e);
     ...
    +pnp_exit_conf_mode(e);
     pnp_op(e);
    -pnp_exit_conf_mode(e);

    @@
    expression e;
    @@
    -pnp_enter_conf_mode(e);
    -pnp_exit_conf_mode(e);

Change-Id: I5c04b0c6a8f01a30bc25fe195797c02e75b6c276
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: http://review.coreboot.org/3482
Tested-by: build bot (Jenkins)
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
diff --git a/src/superio/winbond/w83627uhg/superio.c b/src/superio/winbond/w83627uhg/superio.c
index b4a4efe..adae491 100644
--- a/src/superio/winbond/w83627uhg/superio.c
+++ b/src/superio/winbond/w83627uhg/superio.c
@@ -60,13 +60,13 @@
 {
 	u8 value;
 
-	w83627uhg_enter_ext_func_mode(dev);
+	pnp_enter_conf_mode(dev);
 	pnp_set_logical_device(dev);
 	value = pnp_read_config(dev, 0xf0);
 	value &= ~0x03;
 	value |= (uart_clock & 0x03);
 	pnp_write_config(dev, 0xf0, value);
-	w83627uhg_exit_ext_func_mode(dev);
+	pnp_exit_conf_mode(dev);
 }
 
 static void w83627uhg_init(device_t dev)
@@ -103,31 +103,31 @@
 
 static void w83627uhg_set_resources(device_t dev)
 {
-	w83627uhg_enter_ext_func_mode(dev);
 	pnp_set_resources(dev);
-	w83627uhg_exit_ext_func_mode(dev);
 }
 
 static void w83627uhg_enable_resources(device_t dev)
 {
-	w83627uhg_enter_ext_func_mode(dev);
 	pnp_enable_resources(dev);
-	w83627uhg_exit_ext_func_mode(dev);
 }
 
 static void w83627uhg_enable(device_t dev)
 {
-	w83627uhg_enter_ext_func_mode(dev);
 	pnp_enable(dev);
-	w83627uhg_exit_ext_func_mode(dev);
 }
 
+static const struct pnp_mode_ops pnp_conf_mode_ops = {
+	.enter_conf_mode  = w83627uhg_enter_ext_func_mode,
+	.exit_conf_mode   = w83627uhg_exit_ext_func_mode,
+};
+
 static struct device_operations ops = {
 	.read_resources   = pnp_read_resources,
 	.set_resources    = w83627uhg_set_resources,
 	.enable_resources = w83627uhg_enable_resources,
 	.enable           = w83627uhg_enable,
 	.init             = w83627uhg_init,
+	.ops_pnp_mode     = &pnp_conf_mode_ops,
 };
 
 static struct pnp_info pnp_dev_info[] = {