Patchwork [5/5] boards: move all machine type functions to boards.c

login
register
mail settings
Submitter Luiz Capitulino
Date Feb. 24, 2012, 2:13 p.m.
Message ID <1330092792-22455-6-git-send-email-lcapitulino@redhat.com>
Download mbox | patch
Permalink /patch/142895/
State New
Headers show

Comments

Luiz Capitulino - Feb. 24, 2012, 2:13 p.m.
The license text is the same as used in vl.c. Also note that it's
necessary to make machine_parse() public.

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 Makefile.target |    3 +-
 hw/boards.c     |   86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/boards.h     |    1 +
 vl.c            |   65 -----------------------------------------
 4 files changed, 89 insertions(+), 66 deletions(-)
 create mode 100644 hw/boards.c
Andreas Färber - Feb. 24, 2012, 3:10 p.m.
Am 24.02.2012 15:13, schrieb Luiz Capitulino:
> The license text is the same as used in vl.c. Also note that it's
> necessary to make machine_parse() public.
> 
> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
> ---
>  Makefile.target |    3 +-
>  hw/boards.c     |   86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  hw/boards.h     |    1 +
>  vl.c            |   65 -----------------------------------------
>  4 files changed, 89 insertions(+), 66 deletions(-)
>  create mode 100644 hw/boards.c

In anticipation of a "board" class derived from "container" I would
rather have the file name match the class name, i.e. board.c.
Unfortunately boards.h is used in quite a lot of places already, but
when we QOM'ify it we might want to move it to include/qemu so all users
would need to be touched anyway.

> diff --git a/Makefile.target b/Makefile.target
> index d5eb70d..dc76eba 100644
> --- a/Makefile.target
> +++ b/Makefile.target
> @@ -195,7 +195,8 @@ endif #CONFIG_BSD_USER
>  # System emulator target
>  ifdef CONFIG_SOFTMMU
>  
> -obj-y = arch_init.o cpus.o monitor.o machine.o gdbstub.o balloon.o ioport.o
> +obj-y = arch_init.o cpus.o monitor.o machine.o gdbstub.o balloon.o ioport.o \
> +		boards.o

Please use obj-y += ... instead of the line break.

Otherwise looks okay.

Andreas
Luiz Capitulino - Feb. 24, 2012, 3:22 p.m.
On Fri, 24 Feb 2012 16:10:17 +0100
Andreas Färber <afaerber@suse.de> wrote:

> Am 24.02.2012 15:13, schrieb Luiz Capitulino:
> > The license text is the same as used in vl.c. Also note that it's
> > necessary to make machine_parse() public.
> > 
> > Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
> > ---
> >  Makefile.target |    3 +-
> >  hw/boards.c     |   86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
> >  hw/boards.h     |    1 +
> >  vl.c            |   65 -----------------------------------------
> >  4 files changed, 89 insertions(+), 66 deletions(-)
> >  create mode 100644 hw/boards.c
> 
> In anticipation of a "board" class derived from "container" I would
> rather have the file name match the class name, i.e. board.c.
> Unfortunately boards.h is used in quite a lot of places already, but
> when we QOM'ify it we might want to move it to include/qemu so all users
> would need to be touched anyway.

I don't min doing the rename work, but Anthony is talking about having a Machine
type. So, maybe it's a better idea to do rename along with the QOM conversion,
as that's when we'll be sure about the class name.

> > diff --git a/Makefile.target b/Makefile.target
> > index d5eb70d..dc76eba 100644
> > --- a/Makefile.target
> > +++ b/Makefile.target
> > @@ -195,7 +195,8 @@ endif #CONFIG_BSD_USER
> >  # System emulator target
> >  ifdef CONFIG_SOFTMMU
> >  
> > -obj-y = arch_init.o cpus.o monitor.o machine.o gdbstub.o balloon.o ioport.o
> > +obj-y = arch_init.o cpus.o monitor.o machine.o gdbstub.o balloon.o ioport.o \
> > +		boards.o
> 
> Please use obj-y += ... instead of the line break.

Ok.

> 
> Otherwise looks okay.
> 
> Andreas
>

Patch

diff --git a/Makefile.target b/Makefile.target
index d5eb70d..dc76eba 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -195,7 +195,8 @@  endif #CONFIG_BSD_USER
 # System emulator target
 ifdef CONFIG_SOFTMMU
 
-obj-y = arch_init.o cpus.o monitor.o machine.o gdbstub.o balloon.o ioport.o
+obj-y = arch_init.o cpus.o monitor.o machine.o gdbstub.o balloon.o ioport.o \
+		boards.o
 # virtio has to be here due to weird dependency between PCI and virtio-net.
 # need to fix this properly
 obj-$(CONFIG_NO_PCI) += pci-stub.o
diff --git a/hw/boards.c b/hw/boards.c
new file mode 100644
index 0000000..73d6b93
--- /dev/null
+++ b/hw/boards.c
@@ -0,0 +1,86 @@ 
+/*
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "hw/boards.h"
+#include "qemu-queue.h"
+
+static QTAILQ_HEAD(QEMUMachineHead, QEMUMachine) machine_types = 
+    QTAILQ_HEAD_INITIALIZER(machine_types);
+QEMUMachine *current_machine = NULL;
+
+void machine_register(QEMUMachine *m)
+{
+    QTAILQ_INSERT_TAIL(&machine_types, m, next);
+}
+
+static QEMUMachine *machine_find(const char *name)
+{
+    QEMUMachine *m;
+
+    QTAILQ_FOREACH(m, &machine_types, next) {
+        if (!strcmp(m->name, name))
+            return m;
+        if (m->alias && !strcmp(m->alias, name))
+            return m;
+    }
+    return NULL;
+}
+
+QEMUMachine *machine_find_default(void)
+{
+    QEMUMachine *m;
+
+    QTAILQ_FOREACH(m, &machine_types, next) {
+        if (m->is_default) {
+            return m;
+        }
+    }
+    return NULL;
+}
+
+void machine_print_all(void)
+{
+    QEMUMachine *m;
+
+    printf("Supported machines are:\n");
+    QTAILQ_FOREACH(m, &machine_types, next) {
+        if (m->alias) {
+            printf("%-10s %s (alias of %s)\n", m->alias, m->desc, m->name);
+        }
+        printf("%-10s %s%s\n", m->name, m->desc,
+               m->is_default ? " (default)" : "");
+    }
+}
+
+QEMUMachine *machine_parse(const char *name)
+{
+    QEMUMachine *machine = NULL;
+
+    if (name) {
+        machine = machine_find(name);
+    }
+    if (machine) {
+        return machine;
+    }
+    machine_print_all();
+    exit(!name || *name != '?');
+}
diff --git a/hw/boards.h b/hw/boards.h
index 1eb8314..d5e110f 100644
--- a/hw/boards.h
+++ b/hw/boards.h
@@ -35,6 +35,7 @@  typedef struct QEMUMachine {
 void machine_register(QEMUMachine *m);
 QEMUMachine *machine_find_default(void);
 void machine_print_all(void);
+QEMUMachine *machine_parse(const char *name);
 
 extern QEMUMachine *current_machine;
 
diff --git a/vl.c b/vl.c
index 4935106..4ae05fd 100644
--- a/vl.c
+++ b/vl.c
@@ -1158,57 +1158,6 @@  void pcmcia_info(Monitor *mon)
 }
 
 /***********************************************************/
-/* machine registration */
-
-static QTAILQ_HEAD(QEMUMachineHead, QEMUMachine) machine_types = 
-    QTAILQ_HEAD_INITIALIZER(machine_types);
-QEMUMachine *current_machine = NULL;
-
-void machine_register(QEMUMachine *m)
-{
-    QTAILQ_INSERT_TAIL(&machine_types, m, next);
-}
-
-static QEMUMachine *machine_find(const char *name)
-{
-    QEMUMachine *m;
-
-    QTAILQ_FOREACH(m, &machine_types, next) {
-        if (!strcmp(m->name, name))
-            return m;
-        if (m->alias && !strcmp(m->alias, name))
-            return m;
-    }
-    return NULL;
-}
-
-QEMUMachine *machine_find_default(void)
-{
-    QEMUMachine *m;
-
-    QTAILQ_FOREACH(m, &machine_types, next) {
-        if (m->is_default) {
-            return m;
-        }
-    }
-    return NULL;
-}
-
-void machine_print_all(void)
-{
-    QEMUMachine *m;
-
-    printf("Supported machines are:\n");
-    QTAILQ_FOREACH(m, &machine_types, next) {
-        if (m->alias) {
-            printf("%-10s %s (alias of %s)\n", m->alias, m->desc, m->name);
-        }
-        printf("%-10s %s%s\n", m->name, m->desc,
-               m->is_default ? " (default)" : "");
-    }
-}
-
-/***********************************************************/
 /* main execution loop */
 
 static void gui_update(void *opaque)
@@ -1995,20 +1944,6 @@  static int debugcon_parse(const char *devname)
     return 0;
 }
 
-static QEMUMachine *machine_parse(const char *name)
-{
-    QEMUMachine *machine = NULL;
-
-    if (name) {
-        machine = machine_find(name);
-    }
-    if (machine) {
-        return machine;
-    }
-    machine_print_all();
-    exit(!name || *name != '?');
-}
-
 static int tcg_init(void)
 {
     tcg_exec_init(tcg_tb_size * 1024 * 1024);