All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Michael Walle" <michael@walle.cc>, "Fam Zheng" <fam@euphon.net>,
	"Daniel P . Berrangé" <berrange@redhat.com>,
	"Gerd Hoffmann" <kraxel@redhat.com>,
	"Brad Smith" <brad@comstyle.com>,
	"Philippe Mathieu-Daudé" <philmd@redhat.com>
Subject: [Qemu-devel] [PATCH v3 5/5] hw/display/milkymist-tmu2: Move inlined code from header to source
Date: Tue, 29 Jan 2019 16:00:29 +0100	[thread overview]
Message-ID: <20190129150029.29829-6-philmd@redhat.com> (raw)
In-Reply-To: <20190129150029.29829-1-philmd@redhat.com>

Move the complexity of milkymist_tmu2_create() into the
source file. Doing so we avoid to include the X11/OpenGL
headers in all LM32 devices, and we also avoid the duplicate
declaration of glx_fbconfig_attr[] (it is already declared
in hw/display/milkymist-tmu2.c).
Since TYPE_MILKYMIST_TMU2 is now accessible, use it.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 MAINTAINERS                         |  1 +
 hw/display/milkymist-tmu2.c         | 49 ++++++++++++++++++++++
 hw/lm32/milkymist-hw.h              | 63 -----------------------------
 hw/lm32/milkymist.c                 |  1 +
 include/hw/display/milkymist_tmu2.h | 41 +++++++++++++++++++
 5 files changed, 92 insertions(+), 63 deletions(-)
 create mode 100644 include/hw/display/milkymist_tmu2.h

diff --git a/MAINTAINERS b/MAINTAINERS
index b334b53979..737a33b102 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -185,6 +185,7 @@ F: disas/lm32.c
 F: hw/lm32/
 F: hw/*/lm32_*
 F: hw/*/milkymist-*
+F: include/hw/display/milkymist_tmu2.h
 F: include/hw/char/lm32_juart.h
 F: include/hw/lm32/
 F: tests/tcg/lm32/
diff --git a/hw/display/milkymist-tmu2.c b/hw/display/milkymist-tmu2.c
index 3ce44fdfce..b33fc234e9 100644
--- a/hw/display/milkymist-tmu2.c
+++ b/hw/display/milkymist-tmu2.c
@@ -31,6 +31,7 @@
 #include "qapi/error.h"
 #include "qemu/error-report.h"
 #include "qapi/error.h"
+#include "hw/display/milkymist_tmu2.h"
 
 #include <X11/Xlib.h>
 #include <epoxy/gl.h>
@@ -499,3 +500,51 @@ static void milkymist_tmu2_register_types(void)
 }
 
 type_init(milkymist_tmu2_register_types)
+
+DeviceState *milkymist_tmu2_create(hwaddr base, qemu_irq irq)
+{
+    DeviceState *dev;
+    Display *d;
+    GLXFBConfig *configs;
+    int nelements;
+    int ver_major, ver_minor;
+
+    /* check that GLX will work */
+    d = XOpenDisplay(NULL);
+    if (d == NULL) {
+        return NULL;
+    }
+
+    if (!glXQueryVersion(d, &ver_major, &ver_minor)) {
+        /*
+         * Yeah, sometimes getting the GLX version can fail.
+         * Isn't X beautiful?
+         */
+        XCloseDisplay(d);
+        return NULL;
+    }
+
+    if ((ver_major < 1) || ((ver_major == 1) && (ver_minor < 3))) {
+        printf("Your GLX version is %d.%d,"
+          "but TMU emulation needs at least 1.3. TMU disabled.\n",
+          ver_major, ver_minor);
+        XCloseDisplay(d);
+        return NULL;
+    }
+
+    configs = glXChooseFBConfig(d, 0, glx_fbconfig_attr, &nelements);
+    if (configs == NULL) {
+        XCloseDisplay(d);
+        return NULL;
+    }
+
+    XFree(configs);
+    XCloseDisplay(d);
+
+    dev = qdev_create(NULL, TYPE_MILKYMIST_TMU2);
+    qdev_init_nofail(dev);
+    sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
+    sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, irq);
+
+    return dev;
+}
diff --git a/hw/lm32/milkymist-hw.h b/hw/lm32/milkymist-hw.h
index 32c344ef9f..976cf9254d 100644
--- a/hw/lm32/milkymist-hw.h
+++ b/hw/lm32/milkymist-hw.h
@@ -88,69 +88,6 @@ static inline DeviceState *milkymist_pfpu_create(hwaddr base,
     return dev;
 }
 
-#if defined(CONFIG_X11) && defined(CONFIG_OPENGL)
-#include <X11/Xlib.h>
-#include <epoxy/gl.h>
-#include <epoxy/glx.h>
-static const int glx_fbconfig_attr[] = {
-    GLX_GREEN_SIZE, 5,
-    GLX_GREEN_SIZE, 6,
-    GLX_BLUE_SIZE, 5,
-    None
-};
-#endif
-
-static inline DeviceState *milkymist_tmu2_create(hwaddr base,
-        qemu_irq irq)
-{
-#if defined(CONFIG_X11) && defined(CONFIG_OPENGL)
-    DeviceState *dev;
-    Display *d;
-    GLXFBConfig *configs;
-    int nelements;
-    int ver_major, ver_minor;
-
-    /* check that GLX will work */
-    d = XOpenDisplay(NULL);
-    if (d == NULL) {
-        return NULL;
-    }
-
-    if (!glXQueryVersion(d, &ver_major, &ver_minor)) {
-        /* Yeah, sometimes getting the GLX version can fail.
-         * Isn't X beautiful? */
-        XCloseDisplay(d);
-        return NULL;
-    }
-
-    if ((ver_major < 1) || ((ver_major == 1) && (ver_minor < 3))) {
-        printf("Your GLX version is %d.%d,"
-          "but TMU emulation needs at least 1.3. TMU disabled.\n",
-          ver_major, ver_minor);
-        XCloseDisplay(d);
-        return NULL;
-    }
-
-    configs = glXChooseFBConfig(d, 0, glx_fbconfig_attr, &nelements);
-    if (configs == NULL) {
-        XCloseDisplay(d);
-        return NULL;
-    }
-
-    XFree(configs);
-    XCloseDisplay(d);
-
-    dev = qdev_create(NULL, "milkymist-tmu2");
-    qdev_init_nofail(dev);
-    sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
-    sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, irq);
-
-    return dev;
-#else
-    return NULL;
-#endif
-}
-
 static inline DeviceState *milkymist_ac97_create(hwaddr base,
         qemu_irq crrequest_irq, qemu_irq crreply_irq, qemu_irq dmar_irq,
         qemu_irq dmaw_irq)
diff --git a/hw/lm32/milkymist.c b/hw/lm32/milkymist.c
index 63c6894c95..26a2398354 100644
--- a/hw/lm32/milkymist.c
+++ b/hw/lm32/milkymist.c
@@ -32,6 +32,7 @@
 #include "hw/loader.h"
 #include "elf.h"
 #include "milkymist-hw.h"
+#include "hw/display/milkymist_tmu2.h"
 #include "lm32.h"
 #include "exec/address-spaces.h"
 
diff --git a/include/hw/display/milkymist_tmu2.h b/include/hw/display/milkymist_tmu2.h
new file mode 100644
index 0000000000..148a119a1d
--- /dev/null
+++ b/include/hw/display/milkymist_tmu2.h
@@ -0,0 +1,41 @@
+/*
+ *  QEMU model of the Milkymist texture mapping unit.
+ *
+ *  Copyright (c) 2010 Michael Walle <michael@walle.cc>
+ *  Copyright (c) 2010 Sebastien Bourdeauducq
+ *                       <sebastien.bourdeauducq@lekernel.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ *
+ *
+ * Specification available at:
+ *   http://milkymist.walle.cc/socdoc/tmu2.pdf
+ *
+ */
+
+#ifndef HW_DISPLAY_MILKYMIST_TMU2_H
+#define HW_DISPLAY_MILKYMIST_TMU2_H
+
+#include "hw/qdev.h"
+
+#if defined(CONFIG_X11) && defined(CONFIG_OPENGL)
+DeviceState *milkymist_tmu2_create(hwaddr base, qemu_irq irq);
+#else
+static inline DeviceState *milkymist_tmu2_create(hwaddr base, qemu_irq irq)
+{
+    return NULL;
+}
+#endif
+
+#endif /* HW_DISPLAY_MILKYMIST_TMU2_H */
-- 
2.20.1

  parent reply	other threads:[~2019-01-29 15:03 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-29 15:00 [Qemu-devel] [PATCH v3 0/5] sdl: Let it be optional (in particular, on OpenBSD) Philippe Mathieu-Daudé
2019-01-29 15:00 ` [Qemu-devel] [PATCH v3 1/5] hw/lm32: Move LM32 specific hardware out of common-obj list Philippe Mathieu-Daudé
2019-01-30  7:44   ` Gerd Hoffmann
2019-01-29 15:00 ` [Qemu-devel] [PATCH v3 2/5] configure: LM32 Milkymist Texture Mapping Unit (tmu2) also depends of X11 Philippe Mathieu-Daudé
2019-01-29 15:00 ` [Qemu-devel] [PATCH v3 3/5] hw/display/milkymist-tmu2: Explicit the dependency to both X11 / OpenGL Philippe Mathieu-Daudé
2019-01-29 15:00 ` [Qemu-devel] [PATCH v3 4/5] configure: Let SDL support be optional on OpenBSD Philippe Mathieu-Daudé
2019-01-30  7:52   ` Gerd Hoffmann
2019-01-29 15:00 ` Philippe Mathieu-Daudé [this message]
2019-02-03  1:24 ` [Qemu-devel] [PATCH v3 0/5] sdl: Let it be optional (in particular, on OpenBSD) no-reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190129150029.29829-6-philmd@redhat.com \
    --to=philmd@redhat.com \
    --cc=berrange@redhat.com \
    --cc=brad@comstyle.com \
    --cc=fam@euphon.net \
    --cc=kraxel@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=michael@walle.cc \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.