Source-Changes-HG archive

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

[src/trunk]: src/sys Register NVMM as an actual pseudo-device. Without PMF ha...



details:   https://anonhg.NetBSD.org/src/rev/69f28ed530c5
branches:  trunk
changeset: 973279:69f28ed530c5
user:      maxv <maxv%NetBSD.org@localhost>
date:      Thu Jun 25 17:01:19 2020 +0000

description:
Register NVMM as an actual pseudo-device. Without PMF handler, to
explicitly disallow ACPI suspend if NVMM is running.

Should fix PR/55406.

diffstat:

 sys/dev/nvmm/files.nvmm      |    4 +-
 sys/dev/nvmm/nvmm.c          |  160 ++++++++++++++++++++++++++++++++----------
 sys/modules/nvmm/nvmm.ioconf |    3 +-
 3 files changed, 126 insertions(+), 41 deletions(-)

diffs (253 lines):

diff -r f85a4f0a1dbf -r 69f28ed530c5 sys/dev/nvmm/files.nvmm
--- a/sys/dev/nvmm/files.nvmm   Thu Jun 25 16:57:00 2020 +0000
+++ b/sys/dev/nvmm/files.nvmm   Thu Jun 25 17:01:19 2020 +0000
@@ -1,6 +1,6 @@
-#      $NetBSD: files.nvmm,v 1.2 2019/03/28 19:00:40 maxv Exp $
+#      $NetBSD: files.nvmm,v 1.3 2020/06/25 17:01:19 maxv Exp $
 
-defpseudo nvmm
+defpseudodev nvmm
 
 file   dev/nvmm/nvmm.c                 nvmm
 
diff -r f85a4f0a1dbf -r 69f28ed530c5 sys/dev/nvmm/nvmm.c
--- a/sys/dev/nvmm/nvmm.c       Thu Jun 25 16:57:00 2020 +0000
+++ b/sys/dev/nvmm/nvmm.c       Thu Jun 25 17:01:19 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nvmm.c,v 1.30 2020/05/24 08:08:49 maxv Exp $   */
+/*     $NetBSD: nvmm.c,v 1.31 2020/06/25 17:01:19 maxv Exp $   */
 
 /*
  * Copyright (c) 2018-2019 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nvmm.c,v 1.30 2020/05/24 08:08:49 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvmm.c,v 1.31 2020/06/25 17:01:19 maxv Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -44,7 +44,7 @@
 #include <sys/mman.h>
 #include <sys/file.h>
 #include <sys/filedesc.h>
-#include <sys/kauth.h>
+#include <sys/device.h>
 
 #include <uvm/uvm.h>
 #include <uvm/uvm_page.h>
@@ -960,22 +960,27 @@
 
 /* -------------------------------------------------------------------------- */
 
+static const struct nvmm_impl *
+nvmm_ident(void)
+{
+       size_t i;
+
+       for (i = 0; i < __arraycount(nvmm_impl_list); i++) {
+               if ((*nvmm_impl_list[i]->ident)())
+                       return nvmm_impl_list[i];
+       }
+
+       return NULL;
+}
+
 static int
 nvmm_init(void)
 {
        size_t i, n;
 
-       for (i = 0; i < __arraycount(nvmm_impl_list); i++) {
-               if (!(*nvmm_impl_list[i]->ident)()) {
-                       continue;
-               }
-               nvmm_impl = nvmm_impl_list[i];
-               break;
-       }
-       if (nvmm_impl == NULL) {
-               printf("NVMM: CPU not supported\n");
+       nvmm_impl = nvmm_ident();
+       if (nvmm_impl == NULL)
                return ENOTSUP;
-       }
 
        for (i = 0; i < NVMM_MAX_MACHINES; i++) {
                machines[i].machid = i;
@@ -1169,6 +1174,53 @@
 
 /* -------------------------------------------------------------------------- */
 
+static int nvmm_match(device_t, cfdata_t, void *);
+static void nvmm_attach(device_t, device_t, void *);
+static int nvmm_detach(device_t, int);
+
+extern struct cfdriver nvmm_cd;
+
+CFATTACH_DECL_NEW(nvmm, 0, nvmm_match, nvmm_attach, nvmm_detach, NULL);
+
+static struct cfdata nvmm_cfdata[] = {
+       {
+               .cf_name = "nvmm",
+               .cf_atname = "nvmm",
+               .cf_unit = 0,
+               .cf_fstate = FSTATE_STAR,
+               .cf_loc = NULL,
+               .cf_flags = 0,
+               .cf_pspec = NULL,
+       },
+       { NULL, NULL, 0, FSTATE_NOTFOUND, NULL, 0, NULL }
+};
+
+static int
+nvmm_match(device_t self, cfdata_t cfdata, void *arg)
+{
+       return 1;
+}
+
+static void
+nvmm_attach(device_t parent, device_t self, void *aux)
+{
+       int error;
+
+       error = nvmm_init();
+       if (error)
+               panic("%s: impossible", __func__);
+       aprint_normal_dev(self, "attached\n");
+}
+
+static int
+nvmm_detach(device_t self, int flags)
+{
+       if (nmachines > 0)
+               return EBUSY;
+       nvmm_fini();
+       return 0;
+}
+
 void
 nvmmattach(int nunits)
 {
@@ -1177,51 +1229,83 @@
 
 MODULE(MODULE_CLASS_MISC, nvmm, NULL);
 
+#if defined(_MODULE)
+CFDRIVER_DECL(nvmm, DV_VIRTUAL, NULL);
+#endif
+
 static int
 nvmm_modcmd(modcmd_t cmd, void *arg)
 {
+#if defined(_MODULE)
+       devmajor_t bmajor = NODEVMAJOR;
+       devmajor_t cmajor = 345;
+#endif
        int error;
 
        switch (cmd) {
        case MODULE_CMD_INIT:
-               error = nvmm_init();
+               if (nvmm_ident() == NULL) {
+                       aprint_error("%s: cpu not supported\n",
+                           nvmm_cd.cd_name);
+                       return ENOTSUP;
+               }
+#if defined(_MODULE)
+               error = config_cfdriver_attach(&nvmm_cd);
                if (error)
                        return error;
+#endif
+               error = config_cfattach_attach(nvmm_cd.cd_name, &nvmm_ca);
+               if (error) {
+                       config_cfdriver_detach(&nvmm_cd);
+                       aprint_error("%s: config_cfattach_attach failed\n",
+                           nvmm_cd.cd_name);
+                       return error;
+               }
+
+               error = config_cfdata_attach(nvmm_cfdata, 1);
+               if (error) {
+                       config_cfattach_detach(nvmm_cd.cd_name, &nvmm_ca);
+                       config_cfdriver_detach(&nvmm_cd);
+                       aprint_error("%s: unable to register cfdata\n",
+                           nvmm_cd.cd_name);
+                       return error;
+               }
+
+               if (config_attach_pseudo(nvmm_cfdata) == NULL) {
+                       aprint_error("%s: config_attach_pseudo failed\n",
+                           nvmm_cd.cd_name);
+                       config_cfattach_detach(nvmm_cd.cd_name, &nvmm_ca);
+                       config_cfdriver_detach(&nvmm_cd);
+                       return ENXIO;
+               }
 
 #if defined(_MODULE)
-               {
-                       devmajor_t bmajor = NODEVMAJOR;
-                       devmajor_t cmajor = 345;
-
-                       /* mknod /dev/nvmm c 345 0 */
-                       error = devsw_attach("nvmm", NULL, &bmajor,
-                           &nvmm_cdevsw, &cmajor);
-                       if (error) {
-                               nvmm_fini();
-                               return error;
-                       }
+               /* mknod /dev/nvmm c 345 0 */
+               error = devsw_attach(nvmm_cd.cd_name, NULL, &bmajor,
+                       &nvmm_cdevsw, &cmajor);
+               if (error) {
+                       aprint_error("%s: unable to register devsw\n",
+                           nvmm_cd.cd_name);
+                       config_cfattach_detach(nvmm_cd.cd_name, &nvmm_ca);
+                       config_cfdriver_detach(&nvmm_cd);
+                       return error;
                }
 #endif
                return 0;
-
        case MODULE_CMD_FINI:
-               if (nmachines > 0) {
-                       return EBUSY;
-               }
+               error = config_cfdata_detach(nvmm_cfdata);
+               if (error)
+                       return error;
+               error = config_cfattach_detach(nvmm_cd.cd_name, &nvmm_ca);
+               if (error)
+                       return error;
 #if defined(_MODULE)
-               {
-                       error = devsw_detach(NULL, &nvmm_cdevsw);
-                       if (error) {
-                               return error;
-                       }
-               }
+               config_cfdriver_detach(&nvmm_cd);
+               devsw_detach(NULL, &nvmm_cdevsw);
 #endif
-               nvmm_fini();
                return 0;
-
        case MODULE_CMD_AUTOUNLOAD:
                return EBUSY;
-
        default:
                return ENOTTY;
        }
diff -r f85a4f0a1dbf -r 69f28ed530c5 sys/modules/nvmm/nvmm.ioconf
--- a/sys/modules/nvmm/nvmm.ioconf      Thu Jun 25 16:57:00 2020 +0000
+++ b/sys/modules/nvmm/nvmm.ioconf      Thu Jun 25 17:01:19 2020 +0000
@@ -1,7 +1,8 @@
-#      $NetBSD: nvmm.ioconf,v 1.1 2018/11/07 07:43:08 maxv Exp $
+#      $NetBSD: nvmm.ioconf,v 1.2 2020/06/25 17:01:20 maxv Exp $
 
 ioconf         nvmm
 
 include                "conf/files"
+include                "dev/nvmm/files.nvmm"
 
 pseudo-device   nvmm



Home | Main Index | Thread Index | Old Index