discover/powerpc: Separate ipmi bootdev handling into separate functions
authorJeremy Kerr <jk@ozlabs.org>
Tue, 2 Dec 2014 07:04:38 +0000 (15:04 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Mon, 15 Dec 2014 02:39:02 +0000 (10:39 +0800)
We'd like to add a new backend to the bootdev storage, so move the
common bootdev-handling code into separate functions, moving
ipmi_bootdev_is_valid to ipmi.c.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
discover/ipmi.c
discover/ipmi.h
discover/platform-powerpc.c

index 4bcdf30f7ac6cab4e62a762dfe9012e00ad3bb5b..b8f18301ecc4c75aaccdb0cdc62c84aba898348e 100644 (file)
@@ -1,6 +1,21 @@
 
 #include "ipmi.h"
 
+bool ipmi_bootdev_is_valid(int x)
+{
+       switch (x) {
+       case IPMI_BOOTDEV_NONE:
+       case IPMI_BOOTDEV_NETWORK:
+       case IPMI_BOOTDEV_DISK:
+       case IPMI_BOOTDEV_SAFE:
+       case IPMI_BOOTDEV_CDROM:
+       case IPMI_BOOTDEV_SETUP:
+               return true;
+       }
+
+       return false;
+}
+
 bool ipmi_present(void)
 {
        return false;
index 0ed6068f1a5395e447c58d2b1b5b0212b162822c..157cca898685f36e906ba1969f4a705457dbd4ab 100644 (file)
@@ -13,6 +13,7 @@ enum ipmi_bootdev {
        IPMI_BOOTDEV_SETUP = 0x6,
 };
 
+bool ipmi_bootdev_is_valid(int x);
 bool ipmi_present(void);
 
 #endif /* _IPMI_H */
index e5dac9efcc8e4b2b8a8f7ef540fe78e5232e8e04..6ae28f4cd59c4acb4043f5afd58f439e2ae42a33 100644 (file)
@@ -583,6 +583,30 @@ static void set_exclusive_devtype(struct config *config,
        config->boot_priorities[1].priority = -1;
 }
 
+static void set_ipmi_bootdev(struct config *config, enum ipmi_bootdev bootdev)
+{
+       switch (bootdev) {
+       case IPMI_BOOTDEV_NONE:
+               break;
+       case IPMI_BOOTDEV_DISK:
+               set_exclusive_devtype(config, DEVICE_TYPE_DISK);
+               break;
+       case IPMI_BOOTDEV_NETWORK:
+               set_exclusive_devtype(config, DEVICE_TYPE_NETWORK);
+               break;
+       case IPMI_BOOTDEV_CDROM:
+               set_exclusive_devtype(config, DEVICE_TYPE_OPTICAL);
+               break;
+       case IPMI_BOOTDEV_SETUP:
+               config->autoboot_enabled = false;
+               break;
+       case IPMI_BOOTDEV_SAFE:
+               config->autoboot_enabled = false;
+               config->safe_mode = true;
+               break;
+       }
+}
+
 static int read_bootdev_sysparam(const char *name, uint8_t *val)
 {
        uint8_t buf[2];
@@ -613,18 +637,10 @@ static int read_bootdev_sysparam(const char *name, uint8_t *val)
 
        pb_debug("powerpc: sysparam %s: 0x%02x\n", name, buf[0]);
 
-       switch (buf[0]) {
-       default:
+       if (!ipmi_bootdev_is_valid(buf[0]))
                return -1;
-       case IPMI_BOOTDEV_NONE:
-       case IPMI_BOOTDEV_NETWORK:
-       case IPMI_BOOTDEV_DISK:
-       case IPMI_BOOTDEV_SAFE:
-       case IPMI_BOOTDEV_CDROM:
-       case IPMI_BOOTDEV_SETUP:
-               *val = buf[0];
-       }
 
+       *val = buf[0];
        return 0;
 }
 
@@ -687,26 +703,7 @@ static void parse_opal_sysparams(struct config *config)
        if (!next_valid)
                next_bootdev = default_bootdev;
 
-       switch (next_bootdev) {
-       case IPMI_BOOTDEV_NONE:
-               return;
-       case IPMI_BOOTDEV_DISK:
-               set_exclusive_devtype(config, DEVICE_TYPE_DISK);
-               break;
-       case IPMI_BOOTDEV_NETWORK:
-               set_exclusive_devtype(config, DEVICE_TYPE_NETWORK);
-               break;
-       case IPMI_BOOTDEV_CDROM:
-               set_exclusive_devtype(config, DEVICE_TYPE_OPTICAL);
-               break;
-       case IPMI_BOOTDEV_SETUP:
-               config->autoboot_enabled = false;
-               break;
-       case IPMI_BOOTDEV_SAFE:
-               config->autoboot_enabled = false;
-               config->safe_mode = true;
-               break;
-       }
+       set_ipmi_bootdev(config, next_bootdev);
 }
 
 static int load_config(struct platform *p, struct config *config)