Module Name: src
Committed By: palle
Date: Sat Jul 3 19:18:56 UTC 2021
Modified Files:
src/sys/arch/sparc64/include: hypervisor.h sparc64.h
src/sys/arch/sparc64/sparc64: autoconf.c intr.c ofw_machdep.c
Log Message:
sun4v: add support for hypervisor soft state - from OpenBSD
To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/sparc64/include/hypervisor.h
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/sparc64/include/sparc64.h
cvs rdiff -u -r1.231 -r1.232 src/sys/arch/sparc64/sparc64/autoconf.c
cvs rdiff -u -r1.69 -r1.70 src/sys/arch/sparc64/sparc64/intr.c
cvs rdiff -u -r1.46 -r1.47 src/sys/arch/sparc64/sparc64/ofw_machdep.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/sparc64/include/hypervisor.h
diff -u src/sys/arch/sparc64/include/hypervisor.h:1.7 src/sys/arch/sparc64/include/hypervisor.h:1.8
--- src/sys/arch/sparc64/include/hypervisor.h:1.7 Tue Apr 27 19:09:56 2021
+++ src/sys/arch/sparc64/include/hypervisor.h Sat Jul 3 19:18:55 2021
@@ -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_ */
Index: src/sys/arch/sparc64/include/sparc64.h
diff -u src/sys/arch/sparc64/include/sparc64.h:1.13 src/sys/arch/sparc64/include/sparc64.h:1.14
--- src/sys/arch/sparc64/include/sparc64.h:1.13 Sat Sep 6 20:56:39 2014
+++ src/sys/arch/sparc64/include/sparc64.h Sat Jul 3 19:18:55 2021
@@ -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_ */
Index: src/sys/arch/sparc64/sparc64/autoconf.c
diff -u src/sys/arch/sparc64/sparc64/autoconf.c:1.231 src/sys/arch/sparc64/sparc64/autoconf.c:1.232
--- src/sys/arch/sparc64/sparc64/autoconf.c:1.231 Wed May 12 23:22:33 2021
+++ src/sys/arch/sparc64/sparc64/autoconf.c Sat Jul 3 19:18:55 2021
@@ -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,7 +526,79 @@ 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)
Index: src/sys/arch/sparc64/sparc64/intr.c
diff -u src/sys/arch/sparc64/sparc64/intr.c:1.69 src/sys/arch/sparc64/sparc64/intr.c:1.70
--- src/sys/arch/sparc64/sparc64/intr.c:1.69 Fri May 13 21:24:11 2016
+++ src/sys/arch/sparc64/sparc64/intr.c Sat Jul 3 19:18:55 2021
@@ -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
Index: src/sys/arch/sparc64/sparc64/ofw_machdep.c
diff -u src/sys/arch/sparc64/sparc64/ofw_machdep.c:1.46 src/sys/arch/sparc64/sparc64/ofw_machdep.c:1.47
--- src/sys/arch/sparc64/sparc64/ofw_machdep.c:1.46 Thu Jul 7 06:55:38 2016
+++ src/sys/arch/sparc64/sparc64/ofw_machdep.c Sat Jul 3 19:18:55 2021
@@ -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)
+{
+ static struct {
+ cell_t name;
+ cell_t nargs;
+ cell_t nreturns;
+ cell_t api_group;
+ cell_t major;
+ cell_t minor;
+ cell_t status;
+ cell_t supported_minor;
+ } args;
+
+ args.name = ADR2CELL("SUNW,set-sun4v-api-version");
+ args.nargs = 3;
+ args.nreturns = 2;
+ args.api_group = api_group;
+ args.major = major;
+ args.minor = minor;
+ args.status = -1;
+ args.supported_minor = -1;
+
+ openfirmware(&args);
+
+ *supported_minor = args.supported_minor;
+ return (uint64_t)args.status;
+}
+
+void
+prom_sun4v_soft_state_supported(void)
+{
+ static struct {
+ cell_t name;
+ cell_t nargs;
+ cell_t nreturns;
+ } args;
+
+ args.name = ADR2CELL("SUNW,soft-state-supported");
+ args.nargs = 0;
+ args.nreturns = 0;
+
+ openfirmware(&args);
+}
+
#ifdef DEBUG
int ofmapintrdebug = 0;
#define DPRINTF(x) if (ofmapintrdebug) printf x