Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/arm Add support for ARM Power State Coordination In...
details: https://anonhg.NetBSD.org/src/rev/d8b75f696a3b
branches: trunk
changeset: 354764:d8b75f696a3b
user: jmcneill <jmcneill%NetBSD.org@localhost>
date: Wed Jun 28 23:48:22 2017 +0000
description:
Add support for ARM Power State Coordination Interface (PSCI).
diffstat:
sys/arch/arm/arm/psci.c | 120 ++++++++++++++++++++++++++++++
sys/arch/arm/arm/psci.h | 106 ++++++++++++++++++++++++++
sys/arch/arm/arm/psci_arm.S | 47 +++++++++++
sys/arch/arm/conf/files.arm | 7 +-
sys/arch/arm/fdt/files.fdt | 5 +-
sys/arch/arm/fdt/psci_fdt.c | 176 ++++++++++++++++++++++++++++++++++++++++++++
sys/arch/arm/fdt/psci_fdt.h | 35 ++++++++
7 files changed, 494 insertions(+), 2 deletions(-)
diffs (truncated from 543 to 300 lines):
diff -r d75e21d5058e -r d8b75f696a3b sys/arch/arm/arm/psci.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/arm/psci.c Wed Jun 28 23:48:22 2017 +0000
@@ -0,0 +1,120 @@
+/* $NetBSD: psci.c,v 1.1 2017/06/28 23:48:23 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 "opt_diagnostic.h"
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: psci.c,v 1.1 2017/06/28 23:48:23 jmcneill Exp $");
+
+#include <sys/param.h>
+#include <sys/bus.h>
+#include <sys/cpu.h>
+#include <sys/device.h>
+
+#include <arm/arm/psci.h>
+
+/* PSCI methods */
+#define PSCI_VERSION 0x84000000
+#define PSCI_SYSTEM_OFF 0x84000008
+#define PSCI_SYSTEM_RESET 0x84000009
+#if defined(__aarch64__)
+#define PSCI_CPU_ON 0xc4000002
+#else
+#define PSCI_CPU_ON 0x84000002
+#endif
+
+static psci_fn psci_call_fn;
+
+static uint32_t psci_functions[PSCI_FUNC_MAX] = {
+ [PSCI_FUNC_VERSION] = PSCI_VERSION,
+ [PSCI_FUNC_SYSTEM_OFF] = PSCI_SYSTEM_OFF,
+ [PSCI_FUNC_SYSTEM_RESET] = PSCI_SYSTEM_RESET,
+ [PSCI_FUNC_CPU_ON] = PSCI_CPU_ON,
+};
+
+static int
+psci_call(register_t fid, register_t arg1, register_t arg2, register_t arg3)
+{
+ KASSERT(psci_call_fn != NULL);
+
+ if (fid == 0)
+ return PSCI_NOT_SUPPORTED;
+
+ return psci_call_fn(fid, arg1, arg2, arg3);
+}
+
+uint32_t
+psci_version(void)
+{
+ if (psci_functions[PSCI_FUNC_VERSION] == 0) {
+ /* Pre-0.2 implementation */
+ return __SHIFTIN(0, PSCI_VERSION_MAJOR) |
+ __SHIFTIN(1, PSCI_VERSION_MINOR);
+ }
+
+ return psci_call(psci_functions[PSCI_FUNC_VERSION], 0, 0, 0);
+}
+
+int
+psci_cpu_on(register_t target_cpu, register_t entry_point_address,
+ register_t context_id)
+{
+ return psci_call(psci_functions[PSCI_FUNC_CPU_ON], target_cpu,
+ entry_point_address, context_id);
+}
+
+void
+psci_system_off(void)
+{
+ psci_call(psci_functions[PSCI_FUNC_SYSTEM_OFF], 0, 0, 0);
+}
+
+void
+psci_system_reset(void)
+{
+ psci_call(psci_functions[PSCI_FUNC_SYSTEM_RESET], 0, 0, 0);
+}
+
+void
+psci_init(psci_fn fn)
+{
+ psci_call_fn = fn;
+}
+
+void
+psci_clearfunc(void)
+{
+ for (int i = 0; i < PSCI_FUNC_MAX; i++)
+ psci_setfunc(i, 0);
+}
+
+void
+psci_setfunc(enum psci_function func, uint32_t fid)
+{
+ psci_functions[func] = fid;
+}
diff -r d75e21d5058e -r d8b75f696a3b sys/arch/arm/arm/psci.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/arm/psci.h Wed Jun 28 23:48:22 2017 +0000
@@ -0,0 +1,106 @@
+/* $NetBSD: psci.h,v 1.1 2017/06/28 23:48:23 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.
+ */
+
+#ifndef _ARM_PSCI_H
+#define _ARM_PSCI_H
+
+/*
+ * List of supported PSCI functions.
+ */
+enum psci_function {
+ PSCI_FUNC_VERSION,
+ PSCI_FUNC_CPU_ON,
+ PSCI_FUNC_SYSTEM_OFF,
+ PSCI_FUNC_SYSTEM_RESET,
+ PSCI_FUNC_MAX
+};
+
+/*
+ * PSCI error codes
+ */
+#define PSCI_SUCCESS 0
+#define PSCI_NOT_SUPPORTED -1
+#define PSCI_INVALID_PARAMETERS -2
+#define PSCI_DENIED -3
+#define PSCI_ALREADY_ON -4
+#define PSCI_ON_PENDING -5
+#define PSCI_INTERNAL_FAILURE -6
+#define PSCI_NOT_PRESENT -7
+#define PSCI_DISABLED -8
+#define PSCI_INVALID_ADDRESS -9
+
+/*
+ * PSCI call method interface.
+ */
+typedef int (*psci_fn)(register_t, register_t, register_t, register_t);
+
+/*
+ * Set the PSCI call method. Pass either psci_call_smc or psci_call_hvc.
+ */
+void psci_init(psci_fn);
+
+/*
+ * PSCI call methods, implemented in psci.S
+ */
+int psci_call_smc(register_t, register_t, register_t, register_t);
+int psci_call_hvc(register_t, register_t, register_t, register_t);
+
+/*
+ * Clear PSCI function table. The default table includes function IDs for
+ * PSCI 0.2+. A PSCI 0.1 implementation will use its own function ID mappings.
+ */
+void psci_clearfunc(void);
+
+/*
+ * Set PSCI function ID for a given PSCI function.
+ */
+void psci_setfunc(enum psci_function, uint32_t);
+
+/*
+ * Return the version of PSCI implemented.
+ */
+uint32_t psci_version(void);
+#define PSCI_VERSION_MAJOR __BITS(31,16)
+#define PSCI_VERSION_MINOR __BITS(15,0)
+
+/*
+ * Power up a core. Args: target_cpu, entry_point_address, context_id
+ */
+int psci_cpu_on(register_t, register_t, register_t);
+
+/*
+ * Shut down the system.
+ */
+void psci_system_off(void);
+
+/*
+ * Reset the system.
+ */
+void psci_system_reset(void);
+
+#endif /* _ARM_PSCI_H */
diff -r d75e21d5058e -r d8b75f696a3b sys/arch/arm/arm/psci_arm.S
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/arm/psci_arm.S Wed Jun 28 23:48:22 2017 +0000
@@ -0,0 +1,47 @@
+/* $NetBSD: psci_arm.S,v 1.1 2017/06/28 23:48:23 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 <machine/asm.h>
+
+RCSID("$NetBSD: psci_arm.S,v 1.1 2017/06/28 23:48:23 jmcneill Exp $");
+
+ .arch armv7a
+ .arch_extension sec
+ .arch_extension virt
+
+/* Invoke PSCI function using Secure Monitor Call interface */
+ENTRY(psci_call_smc)
+ smc #0
+ RET
+END(psci_call_smc)
+
+/* Invoke PSCI function using Hypervisor Call interface */
+ENTRY(psci_call_hvc)
+ hvc #0
+ RET
+END(psci_call_hvc)
diff -r d75e21d5058e -r d8b75f696a3b sys/arch/arm/conf/files.arm
--- a/sys/arch/arm/conf/files.arm Wed Jun 28 23:45:20 2017 +0000
+++ b/sys/arch/arm/conf/files.arm Wed Jun 28 23:48:22 2017 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.arm,v 1.132 2017/05/26 21:17:46 jmcneill Exp $
+# $NetBSD: files.arm,v 1.133 2017/06/28 23:48:23 jmcneill Exp $
# temporary define to allow easy moving to ../arch/arm/arm32
defflag ARM32
@@ -91,6 +91,11 @@
file arch/arm/vfp/vfp_init.c arm32
#file arch/arm/vfp/pmap_vfp.S arm32 & fpu_vfp
+# Power State Coordination Interface (PSCI)
+device psci
Home |
Main Index |
Thread Index |
Old Index