Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/sparc64 sun4v: add support for hypervisor soft stat...



details:   https://anonhg.NetBSD.org/src/rev/6d30a8767dd4
branches:  trunk
changeset: 380048:6d30a8767dd4
user:      palle <palle%NetBSD.org@localhost>
date:      Sat Jul 03 19:18:55 2021 +0000

description:
sun4v: add support for hypervisor soft state - from OpenBSD

diffstat:

 sys/arch/sparc64/include/hypervisor.h  |   13 +++-
 sys/arch/sparc64/include/sparc64.h     |    4 +-
 sys/arch/sparc64/sparc64/autoconf.c    |  103 ++++++++++++++++++++++++++++++++-
 sys/arch/sparc64/sparc64/intr.c        |   74 +++++++++++++++++++++++-
 sys/arch/sparc64/sparc64/ofw_machdep.c |   50 +++++++++++++++-
 5 files changed, 236 insertions(+), 8 deletions(-)

diffs (truncated from 345 to 300 lines):

diff -r b62b27ff3fa3 -r 6d30a8767dd4 sys/arch/sparc64/include/hypervisor.h
--- a/sys/arch/sparc64/include/hypervisor.h     Sat Jul 03 14:59:49 2021 +0000
+++ b/sys/arch/sparc64/include/hypervisor.h     Sat Jul 03 19:18:55 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: hypervisor.h,v 1.7 2021/04/27 19:09:56 palle Exp $ */
+/*     $NetBSD: hypervisor.h,v 1.8 2021/07/03 19:18:55 palle Exp $ */
 /*     $OpenBSD: hypervisor.h,v 1.14 2011/06/26 17:23:46 kettenis Exp $        */
 
 /*
@@ -391,4 +391,15 @@ int64_t    hv_rng_data_read(paddr_t raddr, 
 #define H_ETOOMANY     15
 #define H_ECHANNEL     16
 
+#ifndef _LOCORE
+extern uint64_t sun4v_group_interrupt_major;
+extern uint64_t sun4v_group_sdio_major;
+
+int64_t sun4v_intr_devino_to_sysino(uint64_t, uint64_t, uint64_t *);
+int64_t sun4v_intr_setcookie(uint64_t, uint64_t, uint64_t);
+int64_t sun4v_intr_setenabled(uint64_t, uint64_t, uint64_t);
+int64_t        sun4v_intr_setstate(uint64_t, uint64_t, uint64_t);
+int64_t        sun4v_intr_settarget(uint64_t, uint64_t, uint64_t);
+#endif
+
 #endif /* _HYPERVISOR_H_ */
diff -r b62b27ff3fa3 -r 6d30a8767dd4 sys/arch/sparc64/include/sparc64.h
--- a/sys/arch/sparc64/include/sparc64.h        Sat Jul 03 14:59:49 2021 +0000
+++ b/sys/arch/sparc64/include/sparc64.h        Sat Jul 03 19:18:55 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sparc64.h,v 1.13 2014/09/06 20:56:39 palle Exp $       */
+/*     $NetBSD: sparc64.h,v 1.14 2021/07/03 19:18:55 palle Exp $       */
 
 /*
  * Copyright (C) 1996 Wolfgang Solfrank.
@@ -59,5 +59,7 @@ int  prom_stop_other(u_int);
 bool prom_has_stop_other(void);
 void prom_startcpu(u_int, void *, u_long);
 int prom_startcpu_by_cpuid(u_int, void *, u_long arg);
+uint64_t prom_set_sun4v_api_version(uint64_t, uint64_t, uint64_t, uint64_t *);
+void prom_sun4v_soft_state_supported(void);
 
 #endif /* _MACHINE_SPARC64_H_ */
diff -r b62b27ff3fa3 -r 6d30a8767dd4 sys/arch/sparc64/sparc64/autoconf.c
--- a/sys/arch/sparc64/sparc64/autoconf.c       Sat Jul 03 14:59:49 2021 +0000
+++ b/sys/arch/sparc64/sparc64/autoconf.c       Sat Jul 03 19:18:55 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: autoconf.c,v 1.231 2021/05/12 23:22:33 thorpej Exp $ */
+/*     $NetBSD: autoconf.c,v 1.232 2021/07/03 19:18:55 palle Exp $ */
 
 /*
  * Copyright (c) 1996
@@ -48,7 +48,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.231 2021/05/12 23:22:33 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.232 2021/07/03 19:18:55 palle Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -181,6 +181,21 @@ struct intrmap intrmap[] = {
        { NULL,         0 }
 };
 
+#ifdef SUN4V
+void   sun4v_soft_state_init(void);
+void   sun4v_set_soft_state(int, const char *);
+
+#define __align32 __attribute__((__aligned__(32)))
+char sun4v_soft_state_booting[] __align32 = "NetBSD booting";
+char sun4v_soft_state_running[] __align32 = "NetBSD running";
+
+#if 0
+XXX notyet             
+void   sun4v_interrupt_init(void);
+void   sun4v_sdio_init(void);
+#endif
+#endif
+
 int console_node, console_instance;
 struct genfb_colormap_callback gfb_cb;
 static void of_set_palette(void *, int, int, int, int);
@@ -358,6 +373,18 @@ die_old_boot_loader:
 
        get_ncpus();
        pmap_bootstrap(KERNBASE, bi_kend->addr);
+
+#ifdef SUN4V
+       if (CPU_ISSUN4V) {
+               sun4v_soft_state_init();
+               sun4v_set_soft_state(SIS_TRANSITION, sun4v_soft_state_booting);
+#if 0
+XXX notyet             
+               sun4v_interrupt_init();
+               sun4v_sdio_init();
+#endif 
+       }
+#endif
 }
 
 /*
@@ -499,8 +526,80 @@ cpu_configure(void)
         setpstate(getpstate()|PSTATE_IE);
 
        (void)spl0();
+
+#ifdef SUN4V
+       if (CPU_ISSUN4V)
+               sun4v_set_soft_state(SIS_NORMAL, sun4v_soft_state_running);
+#endif
 }
 
+#ifdef SUN4V
+
+#define HSVC_GROUP_INTERRUPT   0x002
+#define HSVC_GROUP_SOFT_STATE  0x003
+#define HSVC_GROUP_SDIO                0x108
+
+int sun4v_soft_state_initialized = 0;
+
+void
+sun4v_soft_state_init(void)
+{
+       uint64_t minor;
+
+       if (prom_set_sun4v_api_version(HSVC_GROUP_SOFT_STATE, 1, 0, &minor))
+               return;
+
+       prom_sun4v_soft_state_supported();
+       sun4v_soft_state_initialized = 1;
+}
+
+void
+sun4v_set_soft_state(int state, const char *desc)
+{
+       paddr_t pa;
+       int err;
+
+       if (!sun4v_soft_state_initialized)
+               return;
+
+       if (!pmap_extract(pmap_kernel(), (vaddr_t)desc, &pa))
+               panic("sun4v_set_soft_state: pmap_extract failed");
+
+       err = hv_soft_state_set(state, pa);
+       if (err != H_EOK)
+               printf("soft_state_set: %d\n", err);
+}
+
+#if 0
+XXX notyet             
+void
+sun4v_interrupt_init(void)
+{
+       uint64_t minor;
+
+       if (prom_set_sun4v_api_version(HSVC_GROUP_INTERRUPT, 3, 0, &minor))
+               return;
+
+       sun4v_group_interrupt_major = 3;
+}
+#endif
+
+#if 0
+XXX notyet             
+void
+sun4v_sdio_init(void)
+{
+       uint64_t minor;
+
+       if (prom_set_sun4v_api_version(HSVC_GROUP_SDIO, 1, 0, &minor))
+               return;
+
+       sun4v_group_sdio_major = 1;
+}
+#endif
+
+#endif
+
 void
 cpu_rootconf(void)
 {
diff -r b62b27ff3fa3 -r 6d30a8767dd4 sys/arch/sparc64/sparc64/intr.c
--- a/sys/arch/sparc64/sparc64/intr.c   Sat Jul 03 14:59:49 2021 +0000
+++ b/sys/arch/sparc64/sparc64/intr.c   Sat Jul 03 19:18:55 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: intr.c,v 1.69 2016/05/13 21:24:11 nakayama Exp $ */
+/*     $NetBSD: intr.c,v 1.70 2021/07/03 19:18:55 palle Exp $ */
 
 /*
  * Copyright (c) 1992, 1993
@@ -41,7 +41,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.69 2016/05/13 21:24:11 nakayama Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.70 2021/07/03 19:18:55 palle Exp $");
 
 #include "opt_ddb.h"
 #include "opt_multiprocessor.h"
@@ -361,3 +361,73 @@ softint_trigger(uintptr_t machdep)
        send_softint(-1, ih->ih_pil, ih);
 }
 #endif /* __HAVE_FAST_SOFTINTS */
+
+#ifdef SUN4V
+
+#include <machine/hypervisor.h>
+
+uint64_t sun4v_group_interrupt_major;
+
+#if 0
+XXX notyet
+wint64_t
+sun4v_intr_devino_to_sysino(uint64_t devhandle, uint64_t devino, uint64_t *ino)
+{
+       if (sun4v_group_interrupt_major < 3)
+               return hv_intr_devino_to_sysino(devhandle, devino, ino);
+
+       KASSERT(INTVEC(devino) == devino);
+       *ino = devino | INTR_DEVINO;
+       return H_EOK;
+}
+#endif
+
+#if 0
+XXX notyet             
+int64_t
+sun4v_intr_setcookie(uint64_t devhandle, uint64_t ino, uint64_t cookie_value)
+{
+       if (sun4v_group_interrupt_major < 3)
+               return H_EOK;
+       
+       return hv_vintr_setcookie(devhandle, ino, cookie_value);
+}
+#endif
+
+#if 0
+XXX notyet             
+int64_t
+sun4v_intr_setenabled(uint64_t devhandle, uint64_t ino, uint64_t intr_enabled)
+{
+       if (sun4v_group_interrupt_major < 3)
+               return hv_intr_setenabled(ino, intr_enabled);
+
+       return hv_vintr_setenabled(devhandle, ino, intr_enabled);
+}
+#endif
+
+#if 0
+XXX notyet             
+int64_t
+sun4v_intr_setstate(uint64_t devhandle, uint64_t ino, uint64_t intr_state)
+{
+       if (sun4v_group_interrupt_major < 3)
+               return hv_intr_setstate(ino, intr_state);
+
+       return hv_vintr_setstate(devhandle, ino, intr_state);
+}
+#endif
+
+#if 0
+XXX notyet             
+int64_t
+sun4v_intr_settarget(uint64_t devhandle, uint64_t ino, uint64_t cpuid)
+{
+       if (sun4v_group_interrupt_major < 3)
+               return hv_intr_settarget(ino, cpuid);
+
+       return hv_vintr_settarget(devhandle, ino, cpuid);
+}
+#endif
+
+#endif
diff -r b62b27ff3fa3 -r 6d30a8767dd4 sys/arch/sparc64/sparc64/ofw_machdep.c
--- a/sys/arch/sparc64/sparc64/ofw_machdep.c    Sat Jul 03 14:59:49 2021 +0000
+++ b/sys/arch/sparc64/sparc64/ofw_machdep.c    Sat Jul 03 19:18:55 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ofw_machdep.c,v 1.46 2016/07/07 06:55:38 msaitoh Exp $ */
+/*     $NetBSD: ofw_machdep.c,v 1.47 2021/07/03 19:18:55 palle Exp $   */
 
 /*
  * Copyright (C) 1996 Wolfgang Solfrank.
@@ -34,7 +34,7 @@
 #include "opt_multiprocessor.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ofw_machdep.c,v 1.46 2016/07/07 06:55:38 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_machdep.c,v 1.47 2021/07/03 19:18:55 palle Exp $");
 
 #include <sys/param.h>
 #include <sys/buf.h>
@@ -647,6 +647,52 @@ prom_has_stop_other(void)
 }
 #endif
 
+uint64_t
+prom_set_sun4v_api_version(uint64_t api_group, uint64_t major,
+    uint64_t minor, uint64_t *supported_minor)
+{



Home | Main Index | Thread Index | Old Index