Source-Changes-HG archive

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

[src/trunk]: src Add driver for QEMU Firmware Configuration device.



details:   https://anonhg.NetBSD.org/src/rev/a42f63baa2c0
branches:  trunk
changeset: 828054:a42f63baa2c0
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sat Nov 25 16:31:03 2017 +0000

description:
Add driver for QEMU Firmware Configuration device.

This interface allows the host to pass various data items and files to
the guest OS.

diffstat:

 distrib/sets/lists/comp/mi    |    3 +-
 etc/MAKEDEV.tmpl              |   12 ++-
 sys/conf/files                |    6 +-
 sys/conf/majors               |    3 +-
 sys/dev/acpi/files.acpi       |    6 +-
 sys/dev/acpi/qemufwcfg_acpi.c |  113 ++++++++++++++++++++++++++
 sys/dev/ic/Makefile           |    6 +-
 sys/dev/ic/qemufwcfg.c        |  179 ++++++++++++++++++++++++++++++++++++++++++
 sys/dev/ic/qemufwcfgio.h      |   42 +++++++++
 sys/dev/ic/qemufwcfgvar.h     |   43 ++++++++++
 10 files changed, 405 insertions(+), 8 deletions(-)

diffs (truncated from 513 to 300 lines):

diff -r 2c03bda323c3 -r a42f63baa2c0 distrib/sets/lists/comp/mi
--- a/distrib/sets/lists/comp/mi        Sat Nov 25 15:39:17 2017 +0000
+++ b/distrib/sets/lists/comp/mi        Sat Nov 25 16:31:03 2017 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: mi,v 1.2159 2017/11/07 22:20:05 christos Exp $
+#      $NetBSD: mi,v 1.2160 2017/11/25 16:31:03 jmcneill Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 ./etc/mtree/set.comp                           comp-sys-root
@@ -514,6 +514,7 @@
 ./usr/include/dev/ic/pckbcvar.h                        comp-obsolete           obsolete
 ./usr/include/dev/ic/pdqreg.h                  comp-obsolete           obsolete
 ./usr/include/dev/ic/pdqvar.h                  comp-obsolete           obsolete
+./usr/include/dev/ic/qemufwcfgio.h             comp-c-include
 ./usr/include/dev/ic/rrunnerreg.h              comp-c-include
 ./usr/include/dev/ic/rrunnervar.h              comp-c-include
 ./usr/include/dev/ic/smc83c170reg.h            comp-obsolete           obsolete
diff -r 2c03bda323c3 -r a42f63baa2c0 etc/MAKEDEV.tmpl
--- a/etc/MAKEDEV.tmpl  Sat Nov 25 15:39:17 2017 +0000
+++ b/etc/MAKEDEV.tmpl  Sat Nov 25 16:31:03 2017 +0000
@@ -1,5 +1,5 @@
 #!/bin/sh -
-#      $NetBSD: MAKEDEV.tmpl,v 1.186 2017/08/28 01:34:52 sevan Exp $
+#      $NetBSD: MAKEDEV.tmpl,v 1.187 2017/11/25 16:31:03 jmcneill Exp $
 #
 # Copyright (c) 2003,2007,2008 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -875,6 +875,11 @@
        lndev pad0 pad
        ;;
 
+qemufwcfg)
+       makedev qemufwcfg0
+       lndev qemufwcfg0 qemufwcfg
+       ;;
+
 radio)
        makedev radio0 radio1
        lndev radio0 radio
@@ -1761,6 +1766,11 @@
        mkdev pad$unit c %pad_chr% $unit 444
        ;;
 
+qemufwcfg[0-9]*)
+       unit=${i#qemufwcfg}
+       mkdev qemufwcfg$unit c %qemufwcfg_chr% $unit 660
+       ;;
+
 nvram)
        mkdev nvram c %nvram_chr% 0 644
        ;;
diff -r 2c03bda323c3 -r a42f63baa2c0 sys/conf/files
--- a/sys/conf/files    Sat Nov 25 15:39:17 2017 +0000
+++ b/sys/conf/files    Sat Nov 25 16:31:03 2017 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files,v 1.1184 2017/11/18 18:44:55 christos Exp $
+#      $NetBSD: files,v 1.1185 2017/11/25 16:31:03 jmcneill Exp $
 #      @(#)files.newconf       7.5 (Berkeley) 5/10/93
 
 version        20171118
@@ -1419,6 +1419,10 @@
 device bwfm: arp, ifnet, wlan
 file   dev/ic/bwfm.c                   bwfm
 
+# QEMU Firmware Configuration (fw_cfg) device
+device qemufwcfg
+file   dev/ic/qemufwcfg.c              qemufwcfg
+
 # legitimate pseudo-devices
 #
 defpseudodev vnd:      disk
diff -r 2c03bda323c3 -r a42f63baa2c0 sys/conf/majors
--- a/sys/conf/majors   Sat Nov 25 15:39:17 2017 +0000
+++ b/sys/conf/majors   Sat Nov 25 16:31:03 2017 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: majors,v 1.76 2016/12/08 11:31:08 nat Exp $
+# $NetBSD: majors,v 1.77 2017/11/25 16:31:03 jmcneill Exp $
 #
 # Device majors for Machine-Independent drivers.
 #
@@ -75,3 +75,4 @@
 
 device-major hdmicec   char 340            hdmicec
 device-major nvme      char 341                   nvme
+device-major qemufwcfg char 342                   qemufwcfg
diff -r 2c03bda323c3 -r a42f63baa2c0 sys/dev/acpi/files.acpi
--- a/sys/dev/acpi/files.acpi   Sat Nov 25 15:39:17 2017 +0000
+++ b/sys/dev/acpi/files.acpi   Sat Nov 25 16:31:03 2017 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.acpi,v 1.98 2016/06/21 11:35:47 nonaka Exp $
+#      $NetBSD: files.acpi,v 1.99 2017/11/25 16:31:03 jmcneill Exp $
 
 include "dev/acpi/acpica/files.acpica"
 
@@ -221,4 +221,8 @@
 attach sdhc at acpinodebus with sdhc_acpi
 file   dev/acpi/sdhc_acpi.c            sdhc_acpi
 
+# QEMU Firmware Configuration (fw_cfg) device
+attach qemufwcfg at acpinodebus with qemufwcfg_acpi
+file   dev/acpi/qemufwcfg_acpi.c       qemufwcfg_acpi
+
 include        "dev/acpi/wmi/files.wmi"
diff -r 2c03bda323c3 -r a42f63baa2c0 sys/dev/acpi/qemufwcfg_acpi.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/acpi/qemufwcfg_acpi.c     Sat Nov 25 16:31:03 2017 +0000
@@ -0,0 +1,113 @@
+/* $NetBSD: qemufwcfg_acpi.c,v 1.1 2017/11/25 16:31:03 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2017 Jared McNeill <jmcneill%invisible.ca@localhost>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: qemufwcfg_acpi.c,v 1.1 2017/11/25 16:31:03 jmcneill Exp $");
+
+#include <sys/param.h>
+#include <sys/device.h>
+#include <sys/systm.h>
+#include <sys/mutex.h>
+#include <sys/bus.h>
+
+#include <dev/acpi/acpireg.h>
+#include <dev/acpi/acpivar.h>
+
+#include <dev/ic/qemufwcfgvar.h>
+
+#define _COMPONENT     ACPI_RESOURCE_COMPONENT
+ACPI_MODULE_NAME       ("qemufwcfg_acpi")
+
+static int     fwcfg_acpi_match(device_t, cfdata_t, void *);
+static void    fwcfg_acpi_attach(device_t, device_t, void *);
+
+CFATTACH_DECL_NEW(qemufwcfg_acpi, sizeof(struct fwcfg_softc),
+    fwcfg_acpi_match,
+    fwcfg_acpi_attach,
+    NULL,
+    NULL
+);
+
+static const char * const fwcfg_acpi_ids[] = {
+       "QEMU0002",
+       NULL
+};
+
+static int
+fwcfg_acpi_match(device_t parent, cfdata_t match, void *opaque)
+{
+       struct acpi_attach_args *aa = opaque;
+
+       if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
+               return 0;
+
+       return acpi_match_hid(aa->aa_node->ad_devinfo, fwcfg_acpi_ids);
+}
+
+static void
+fwcfg_acpi_attach(device_t parent, device_t self, void *opaque)
+{
+       struct fwcfg_softc *sc = device_private(self);
+       struct acpi_attach_args *aa = opaque;
+       struct acpi_resources res;
+       struct acpi_mem *mem;
+       struct acpi_io *io;
+       bus_addr_t base;
+       bus_size_t size;
+       ACPI_STATUS rv;
+
+       rv = acpi_resource_parse(self, aa->aa_node->ad_handle, "_CRS",
+           &res, &acpi_resource_parse_ops_default);
+       if (ACPI_FAILURE(rv))
+               return;
+
+       sc->sc_dev = self;
+
+       if ((io = acpi_res_io(&res, 0)) != NULL) {
+               sc->sc_bst = aa->aa_iot;
+               base = io->ar_base;
+               size = io->ar_length;
+       } else if ((mem = acpi_res_mem(&res, 0)) != NULL) {
+               sc->sc_bst = aa->aa_memt;
+               base = mem->ar_base;
+               size = mem->ar_length;
+       } else {
+               aprint_error_dev(self, "couldn't acquire resources\n");
+               return;
+       }
+       acpi_resource_cleanup(&res);
+
+       if (bus_space_map(sc->sc_bst, base, size, 0, &sc->sc_bsh) != 0) {
+               aprint_error_dev(self, "couldn't map registers\n");
+               return;
+       }
+
+       fwcfg_attach(sc);
+
+       pmf_device_register(self, NULL, NULL);
+}
diff -r 2c03bda323c3 -r a42f63baa2c0 sys/dev/ic/Makefile
--- a/sys/dev/ic/Makefile       Sat Nov 25 15:39:17 2017 +0000
+++ b/sys/dev/ic/Makefile       Sat Nov 25 16:31:03 2017 +0000
@@ -1,10 +1,10 @@
-#      $NetBSD: Makefile,v 1.25 2016/06/04 16:11:51 nonaka Exp $
+#      $NetBSD: Makefile,v 1.26 2017/11/25 16:31:03 jmcneill Exp $
 
 INCSDIR= /usr/include/dev/ic
 
 # Only install includes which are used by userland
 INCS=  athioctl.h bt8xx.h hd44780var.h icpreg.h icp_ioctl.h isp_ioctl.h \
-       mlxreg.h mlxio.h nvmeio.h nvmereg.h rrunnerreg.h rrunnervar.h \
-       wdcreg.h wi_ieee.h
+       mlxreg.h mlxio.h nvmeio.h nvmereg.h qemufwcfgio.h rrunnerreg.h \
+       rrunnervar.h wdcreg.h wi_ieee.h
 
 .include <bsd.kinc.mk>
diff -r 2c03bda323c3 -r a42f63baa2c0 sys/dev/ic/qemufwcfg.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/ic/qemufwcfg.c    Sat Nov 25 16:31:03 2017 +0000
@@ -0,0 +1,179 @@
+/* $NetBSD: qemufwcfg.c,v 1.1 2017/11/25 16:31:03 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2017 Jared McNeill <jmcneill%invisible.ca@localhost>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: qemufwcfg.c,v 1.1 2017/11/25 16:31:03 jmcneill Exp $");
+
+#include <sys/param.h>
+#include <sys/device.h>
+#include <sys/systm.h>
+#include <sys/conf.h>
+#include <sys/mutex.h>
+#include <sys/bus.h>
+
+#include <dev/ic/qemufwcfgvar.h>
+#include <dev/ic/qemufwcfgio.h>
+
+#include "ioconf.h"
+
+/* Register locations are MD */
+#if defined(__i386__) || defined(__x86_64__)
+#define        FWCFG_SEL_REG           0x00
+#define        FWCFG_SEL_SWAP          htole16
+#define        FWCFG_DATA_REG          0x01
+#define        FWCFG_DMA_ADDR          0x04
+#elif defined(__arm__) || defined(__aarch64__)
+#define        FWCFG_SEL_REG           0x08
+#define        FWCFG_SEL_SWAP          htobe16
+#define        FWCFG_DATA_REG          0x00
+#define        FWCFG_DMA_ADDR          0x10
+#else
+#error driver does not support this architecture
+#endif
+
+static dev_type_open(fwcfg_open);



Home | Main Index | Thread Index | Old Index