qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 5/5] qdev: add watchdog capability


From: Gerd Hoffmann
Subject: [Qemu-devel] [PATCH 5/5] qdev: add watchdog capability
Date: Mon, 31 Aug 2009 12:27:39 +0200

This patch add watchdog capability and tags the two watchdog drivers.
It also kill the private register functions and driver list in
watchdog.c, instead the qdev driver list and the watchdog capability
bit is used.

Signed-off-by: Gerd Hoffmann <address@hidden>
---
 hw/qdev.c         |    2 +-
 hw/qdev.h         |    3 +++
 hw/watchdog.c     |   53 +++++++++++++++++++++++++++++------------------------
 hw/watchdog.h     |   11 -----------
 hw/wdt_i6300esb.c |    8 ++------
 hw/wdt_ib700.c    |    8 ++------
 6 files changed, 37 insertions(+), 48 deletions(-)

diff --git a/hw/qdev.c b/hw/qdev.c
index b6a1a1d..a26bd46 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -33,7 +33,7 @@
 /* This is a nasty hack to allow passing a NULL bus to qdev_create.  */
 static BusState *main_system_bus;
 
-static DeviceInfo *device_info_list;
+DeviceInfo *device_info_list;
 
 static BusState *qbus_find_recursive(BusState *bus, const char *name,
                                      const BusInfo *info);
diff --git a/hw/qdev.h b/hw/qdev.h
index 2df6ad3..d443534 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -106,11 +106,13 @@ enum DeviceCapBits {
     DEV_CAP_BIT_AUDIO      = 0,
     DEV_CAP_BIT_ETHERNET   = 1,
     DEV_CAP_BIT_DISPLAY    = 2,
+    DEV_CAP_BIT_WATCHDOG   = 3,
 };
 
 #define DEV_CAP_AUDIO      (1 << DEV_CAP_BIT_AUDIO)
 #define DEV_CAP_ETHERNET   (1 << DEV_CAP_BIT_ETHERNET)
 #define DEV_CAP_DISPLAY    (1 << DEV_CAP_BIT_DISPLAY)
+#define DEV_CAP_WATCHDOG   (1 << DEV_CAP_BIT_WATCHDOG)
 
 struct DeviceInfo {
     const char *name;
@@ -126,6 +128,7 @@ struct DeviceInfo {
     BusInfo *bus_info;
     struct DeviceInfo *next;
 };
+extern DeviceInfo *device_info_list;
 
 void qdev_register(DeviceInfo *info);
 
diff --git a/hw/watchdog.c b/hw/watchdog.c
index adba872..5c6bb8a 100644
--- a/hw/watchdog.c
+++ b/hw/watchdog.c
@@ -24,6 +24,7 @@
 #include "qemu-config.h"
 #include "sys-queue.h"
 #include "sysemu.h"
+#include "qdev.h"
 #include "hw/watchdog.h"
 
 /* Possible values for action parameter. */
@@ -35,47 +36,51 @@
 #define WDT_NONE         6     /* Do nothing. */
 
 static int watchdog_action = WDT_RESET;
-static LIST_HEAD(watchdog_list, WatchdogTimerModel) watchdog_list;
-
-void watchdog_add_model(WatchdogTimerModel *model)
-{
-    LIST_INSERT_HEAD(&watchdog_list, model, entry);
-}
 
 /* Returns:
  *   0 = continue
  *   1 = exit program with error
  *   2 = exit program without error
  */
+
+static void print_watchdog_list(FILE *fp)
+{
+    DeviceInfo *info;
+
+    for (info = device_info_list; info != NULL; info = info->next) {
+        if (!(info->caps & DEV_CAP_WATCHDOG))
+            continue;
+        fprintf(fp, "    %-10s %s (%s)\n", info->name, info->desc, 
info->bus_info->name);
+    }
+}
+
 int select_watchdog(const char *p)
 {
-    WatchdogTimerModel *model;
+    DeviceInfo *info;
     QemuOpts *opts;
 
     /* -watchdog ? lists available devices and exits cleanly. */
     if (strcmp(p, "?") == 0) {
-        LIST_FOREACH(model, &watchdog_list, entry) {
-            fprintf(stderr, "\t%s\t%s\n",
-                     model->wdt_name, model->wdt_description);
-        }
+        print_watchdog_list(stderr);
         return 2;
     }
 
-    LIST_FOREACH(model, &watchdog_list, entry) {
-        if (strcasecmp(model->wdt_name, p) == 0) {
-            /* add the device */
-            opts = qemu_opts_create(&qemu_device_opts, NULL, 0);
-            qemu_opt_set(opts, "driver", p);
-            return 0;
-        }
+    for (info = device_info_list; info != NULL; info = info->next) {
+        if (!(info->caps & DEV_CAP_WATCHDOG))
+            continue;
+        if (strcmp(p, info->name) == 0)
+            break;
     }
-
-    fprintf(stderr, "Unknown -watchdog device. Supported devices are:\n");
-    LIST_FOREACH(model, &watchdog_list, entry) {
-        fprintf(stderr, "\t%s\t%s\n",
-                 model->wdt_name, model->wdt_description);
+    if (info == NULL) {
+        fprintf(stderr, "Unknown -watchdog device. Supported devices are:\n");
+        print_watchdog_list(stderr);
+        return 1;
     }
-    return 1;
+
+    /* add the device */
+    opts = qemu_opts_create(&qemu_device_opts, NULL, 0);
+    qemu_opt_set(opts, "driver", p);
+    return 0;
 }
 
 int select_watchdog_action(const char *p)
diff --git a/hw/watchdog.h b/hw/watchdog.h
index 8c54fa4..2c042af 100644
--- a/hw/watchdog.h
+++ b/hw/watchdog.h
@@ -22,20 +22,9 @@
 #ifndef QEMU_WATCHDOG_H
 #define QEMU_WATCHDOG_H
 
-struct WatchdogTimerModel {
-    LIST_ENTRY(WatchdogTimerModel) entry;
-
-    /* Short name of the device - used to select it on the command line. */
-    const char *wdt_name;
-    /* Longer description (eg. manufacturer and full model number). */
-    const char *wdt_description;
-};
-typedef struct WatchdogTimerModel WatchdogTimerModel;
-
 /* in hw/watchdog.c */
 extern int select_watchdog(const char *p);
 extern int select_watchdog_action(const char *action);
-extern void watchdog_add_model(WatchdogTimerModel *model);
 extern void watchdog_perform_action(void);
 
 #endif /* QEMU_WATCHDOG_H */
diff --git a/hw/wdt_i6300esb.c b/hw/wdt_i6300esb.c
index 6927d43..1b46cbf 100644
--- a/hw/wdt_i6300esb.c
+++ b/hw/wdt_i6300esb.c
@@ -446,14 +446,11 @@ static int i6300esb_init(PCIDevice *dev)
     return 0;
 }
 
-static WatchdogTimerModel model = {
-    .wdt_name = "i6300esb",
-    .wdt_description = "Intel 6300ESB",
-};
-
 static PCIDeviceInfo i6300esb_info = {
     .qdev.name    = "i6300esb",
+    .qdev.desc    = "Intel 6300ESB",
     .qdev.size    = sizeof(I6300State),
+    .qdev.caps    = DEV_CAP_WATCHDOG,
     .config_read  = i6300esb_config_read,
     .config_write = i6300esb_config_write,
     .init         = i6300esb_init,
@@ -461,7 +458,6 @@ static PCIDeviceInfo i6300esb_info = {
 
 static void i6300esb_register_devices(void)
 {
-    watchdog_add_model(&model);
     pci_qdev_register(&i6300esb_info);
 }
 
diff --git a/hw/wdt_ib700.c b/hw/wdt_ib700.c
index e0ee65a..c1570a4 100644
--- a/hw/wdt_ib700.c
+++ b/hw/wdt_ib700.c
@@ -98,20 +98,16 @@ static int wdt_ib700_init(ISADevice *dev)
     return 0;
 }
 
-static WatchdogTimerModel model = {
-    .wdt_name = "ib700",
-    .wdt_description = "iBASE 700",
-};
-
 static ISADeviceInfo wdt_ib700_info = {
     .qdev.name = "ib700",
+    .qdev.desc = "iBASE 700",
     .qdev.size = sizeof(ISADevice),
+    .qdev.caps = DEV_CAP_WATCHDOG,
     .init      = wdt_ib700_init,
 };
 
 static void wdt_ib700_register_devices(void)
 {
-    watchdog_add_model(&model);
     isa_qdev_register(&wdt_ib700_info);
 }
 
-- 
1.6.2.5





reply via email to

[Prev in Thread] Current Thread [Next in Thread]