* [PATCH v3 0/6] Add support for a fake, para-virtualised machine
@ 2012-12-18 17:53 Will Deacon
[not found] ` <1355853196-23676-1-git-send-email-will.deacon-5wv7dgnIgG8@public.gmane.org>
2012-12-18 17:53 ` [PATCH v3 6/6] ARM: mach-virt: add SMP support using PSCI Will Deacon
0 siblings, 2 replies; 12+ messages in thread
From: Will Deacon @ 2012-12-18 17:53 UTC (permalink / raw)
To: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ, Will Deacon,
xen-devel-GuqFBffKawuEi8DpZVb4nw
Hi,
This is version three of the patches originally posted here:
v1.) http://lists.infradead.org/pipermail/linux-arm-kernel/2012-December/135870.html
v2.) http://lists.infradead.org/pipermail/linux-arm-kernel/2012-December/137750.html
Thanks to all those who have provided comments so far.
Changes for v3 include:
* Ripped out *even more* SMP code by rebasing onto latest
mainline
* Removed function-base property from device-tree binding
* Annotated the low-level firmware invocation functions with
noinline to clarify intent
* Minor cleanups
As usual, testing this relies on KVM support for PSCI, a magic kvmtool
and Mark Rutland's arch-timer patches.
Comments welcome,
Will
Marc Zyngier (1):
ARM: Dummy Virtual Machine platform support
Will Deacon (5):
ARM: opcodes: add missing include of linux/linkage.h
ARM: opcodes: add opcodes definitions for ARM security extensions
ARM: psci: add devicetree binding for describing PSCI firmware
ARM: psci: add support for PSCI invocations from the kernel
ARM: mach-virt: add SMP support using PSCI
Documentation/devicetree/bindings/arm/psci.txt | 55 +++++++
arch/arm/Kconfig | 12 ++
arch/arm/Makefile | 1 +
arch/arm/include/asm/opcodes-sec.h | 24 +++
arch/arm/include/asm/opcodes.h | 1 +
arch/arm/include/asm/psci.h | 36 +++++
arch/arm/kernel/Makefile | 1 +
arch/arm/kernel/psci.c | 211 +++++++++++++++++++++++++
arch/arm/mach-virt/Kconfig | 10 ++
arch/arm/mach-virt/Makefile | 6 +
arch/arm/mach-virt/platsmp.c | 58 +++++++
arch/arm/mach-virt/virt.c | 69 ++++++++
12 files changed, 484 insertions(+)
create mode 100644 Documentation/devicetree/bindings/arm/psci.txt
create mode 100644 arch/arm/include/asm/opcodes-sec.h
create mode 100644 arch/arm/include/asm/psci.h
create mode 100644 arch/arm/kernel/psci.c
create mode 100644 arch/arm/mach-virt/Kconfig
create mode 100644 arch/arm/mach-virt/Makefile
create mode 100644 arch/arm/mach-virt/platsmp.c
create mode 100644 arch/arm/mach-virt/virt.c
--
1.8.0
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v3 1/6] ARM: opcodes: add missing include of linux/linkage.h
[not found] ` <1355853196-23676-1-git-send-email-will.deacon-5wv7dgnIgG8@public.gmane.org>
@ 2012-12-18 17:53 ` Will Deacon
2012-12-18 17:53 ` [PATCH v3 2/6] ARM: opcodes: add opcodes definitions for ARM security extensions Will Deacon
` (4 subsequent siblings)
5 siblings, 0 replies; 12+ messages in thread
From: Will Deacon @ 2012-12-18 17:53 UTC (permalink / raw)
To: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ, Will Deacon,
xen-devel-GuqFBffKawuEi8DpZVb4nw
opcodes.h wants to declare an asmlinkage function, so we need to include
linux/linkage.h
Acked-by: Dave Martin <dave.martin-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
Signed-off-by: Will Deacon <will.deacon-5wv7dgnIgG8@public.gmane.org>
---
arch/arm/include/asm/opcodes.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/arm/include/asm/opcodes.h b/arch/arm/include/asm/opcodes.h
index 74e211a..e796c59 100644
--- a/arch/arm/include/asm/opcodes.h
+++ b/arch/arm/include/asm/opcodes.h
@@ -10,6 +10,7 @@
#define __ASM_ARM_OPCODES_H
#ifndef __ASSEMBLY__
+#include <linux/linkage.h>
extern asmlinkage unsigned int arm_check_condition(u32 opcode, u32 psr);
#endif
--
1.8.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v3 2/6] ARM: opcodes: add opcodes definitions for ARM security extensions
[not found] ` <1355853196-23676-1-git-send-email-will.deacon-5wv7dgnIgG8@public.gmane.org>
2012-12-18 17:53 ` [PATCH v3 1/6] ARM: opcodes: add missing include of linux/linkage.h Will Deacon
@ 2012-12-18 17:53 ` Will Deacon
2012-12-18 17:53 ` [PATCH v3 3/6] ARM: psci: add devicetree binding for describing PSCI firmware Will Deacon
` (3 subsequent siblings)
5 siblings, 0 replies; 12+ messages in thread
From: Will Deacon @ 2012-12-18 17:53 UTC (permalink / raw)
To: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ, Will Deacon,
xen-devel-GuqFBffKawuEi8DpZVb4nw
The ARM security extensions introduced the smc instruction, which is not
supported by all versions of GAS.
This patch introduces opcodes-sec.h, so that smc is made available in a
similar manner to hvc.
Acked-by: Dave Martin <dave.martin-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
Signed-off-by: Will Deacon <will.deacon-5wv7dgnIgG8@public.gmane.org>
---
arch/arm/include/asm/opcodes-sec.h | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
create mode 100644 arch/arm/include/asm/opcodes-sec.h
diff --git a/arch/arm/include/asm/opcodes-sec.h b/arch/arm/include/asm/opcodes-sec.h
new file mode 100644
index 0000000..bc3a917
--- /dev/null
+++ b/arch/arm/include/asm/opcodes-sec.h
@@ -0,0 +1,24 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * Copyright (C) 2012 ARM Limited
+ */
+
+#ifndef __ASM_ARM_OPCODES_SEC_H
+#define __ASM_ARM_OPCODES_SEC_H
+
+#include <asm/opcodes.h>
+
+#define __SMC(imm4) __inst_arm_thumb32( \
+ 0xE1600070 | (((imm4) & 0xF) << 0), \
+ 0xF7F08000 | (((imm4) & 0xF) << 16) \
+)
+
+#endif /* __ASM_ARM_OPCODES_SEC_H */
--
1.8.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v3 3/6] ARM: psci: add devicetree binding for describing PSCI firmware
[not found] ` <1355853196-23676-1-git-send-email-will.deacon-5wv7dgnIgG8@public.gmane.org>
2012-12-18 17:53 ` [PATCH v3 1/6] ARM: opcodes: add missing include of linux/linkage.h Will Deacon
2012-12-18 17:53 ` [PATCH v3 2/6] ARM: opcodes: add opcodes definitions for ARM security extensions Will Deacon
@ 2012-12-18 17:53 ` Will Deacon
2012-12-19 4:11 ` Nicolas Pitre
2012-12-18 17:53 ` [PATCH v3 4/6] ARM: psci: add support for PSCI invocations from the kernel Will Deacon
` (2 subsequent siblings)
5 siblings, 1 reply; 12+ messages in thread
From: Will Deacon @ 2012-12-18 17:53 UTC (permalink / raw)
To: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ, Will Deacon,
xen-devel-GuqFBffKawuEi8DpZVb4nw
This patch adds a new devicetree binding for describing PSCI firmware
to Linux.
Signed-off-by: Will Deacon <will.deacon-5wv7dgnIgG8@public.gmane.org>
---
Documentation/devicetree/bindings/arm/psci.txt | 55 ++++++++++++++++++++++++++
1 file changed, 55 insertions(+)
create mode 100644 Documentation/devicetree/bindings/arm/psci.txt
diff --git a/Documentation/devicetree/bindings/arm/psci.txt b/Documentation/devicetree/bindings/arm/psci.txt
new file mode 100644
index 0000000..433afe9
--- /dev/null
+++ b/Documentation/devicetree/bindings/arm/psci.txt
@@ -0,0 +1,55 @@
+* Power State Coordination Interface (PSCI)
+
+Firmware implementing the PSCI functions described in ARM document number
+ARM DEN 0022A ("Power State Coordination Interface System Software on ARM
+processors") can be used by Linux to initiate various CPU-centric power
+operations.
+
+Issue A of the specification describes functions for CPU suspend, hotplug
+and migration of secure software.
+
+Functions are invoked by trapping to the privilege level of the PSCI
+firmware (specified as part of the binding below) and passing arguments
+in a manner similar to that specified by AAPCS:
+
+ r0 => 32-bit Function ID / return value
+ {r1 - r3} => Parameters
+
+Note that the immediate field of the trapping instruction must be set
+to #0.
+
+
+Main node required properties:
+
+ - compatible : Must be "arm,psci"
+
+ - method : The method of calling the PSCI firmware. Permitted
+ values are:
+
+ "smc" : SMC #0, with the register assignments specified
+ in this binding.
+
+ "hvc" : HVC #0, with the register assignments specified
+ in this binding.
+
+Main node optional properties:
+
+ - cpu_suspend : Function ID for CPU_SUSPEND operation
+
+ - cpu_off : Function ID for CPU_OFF operation
+
+ - cpu_on : Function ID for CPU_ON operation
+
+ - migrate : Function ID for MIGRATE operation
+
+
+Example:
+
+ psci {
+ compatible = "arm,psci";
+ method = "smc";
+ cpu_suspend = <0x95c10000>;
+ cpu_off = <0x95c10001>;
+ cpu_on = <0x95c10002>;
+ migrate = <0x95c10003>;
+ };
--
1.8.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v3 4/6] ARM: psci: add support for PSCI invocations from the kernel
[not found] ` <1355853196-23676-1-git-send-email-will.deacon-5wv7dgnIgG8@public.gmane.org>
` (2 preceding siblings ...)
2012-12-18 17:53 ` [PATCH v3 3/6] ARM: psci: add devicetree binding for describing PSCI firmware Will Deacon
@ 2012-12-18 17:53 ` Will Deacon
[not found] ` <1355853196-23676-5-git-send-email-will.deacon-5wv7dgnIgG8@public.gmane.org>
2012-12-18 17:53 ` [PATCH v3 5/6] ARM: Dummy Virtual Machine platform support Will Deacon
2012-12-18 17:59 ` [PATCH v3 0/6] Add support for a fake, para-virtualised machine Arnd Bergmann
5 siblings, 1 reply; 12+ messages in thread
From: Will Deacon @ 2012-12-18 17:53 UTC (permalink / raw)
To: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ, Will Deacon,
xen-devel-GuqFBffKawuEi8DpZVb4nw
This patch adds support for the Power State Coordination Interface
defined by ARM, allowing Linux to request CPU-centric power-management
operations from firmware implementing the PSCI protocol.
Signed-off-by: Will Deacon <will.deacon-5wv7dgnIgG8@public.gmane.org>
---
arch/arm/Kconfig | 10 +++
arch/arm/include/asm/psci.h | 36 ++++++++
arch/arm/kernel/Makefile | 1 +
arch/arm/kernel/psci.c | 211 ++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 258 insertions(+)
create mode 100644 arch/arm/include/asm/psci.h
create mode 100644 arch/arm/kernel/psci.c
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 8c83d98..80d54b8 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -1617,6 +1617,16 @@ config HOTPLUG_CPU
Say Y here to experiment with turning CPUs off and on. CPUs
can be controlled through /sys/devices/system/cpu.
+config ARM_PSCI
+ bool "Support for the ARM Power State Coordination Interface (PSCI)"
+ depends on CPU_V7
+ help
+ Say Y here if you want Linux to communicate with system firmware
+ implementing the PSCI specification for CPU-centric power
+ management operations described in ARM document number ARM DEN
+ 0022A ("Power State Coordination Interface System Software on
+ ARM processors").
+
config LOCAL_TIMERS
bool "Use local timer interrupts"
depends on SMP
diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
new file mode 100644
index 0000000..ce0dbe7
--- /dev/null
+++ b/arch/arm/include/asm/psci.h
@@ -0,0 +1,36 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * Copyright (C) 2012 ARM Limited
+ */
+
+#ifndef __ASM_ARM_PSCI_H
+#define __ASM_ARM_PSCI_H
+
+#define PSCI_POWER_STATE_TYPE_STANDBY 0
+#define PSCI_POWER_STATE_TYPE_POWER_DOWN 1
+
+struct psci_power_state {
+ u16 id;
+ u8 type;
+ u8 affinity_level;
+};
+
+struct psci_operations {
+ int (*cpu_suspend)(struct psci_power_state state,
+ unsigned long entry_point);
+ int (*cpu_off)(struct psci_power_state state);
+ int (*cpu_on)(unsigned long cpuid, unsigned long entry_point);
+ int (*migrate)(unsigned long cpuid);
+};
+
+extern struct psci_operations psci_ops;
+
+#endif /* __ASM_ARM_PSCI_H */
diff --git a/arch/arm/kernel/Makefile b/arch/arm/kernel/Makefile
index 5bbec7b..5f3338e 100644
--- a/arch/arm/kernel/Makefile
+++ b/arch/arm/kernel/Makefile
@@ -82,5 +82,6 @@ obj-$(CONFIG_DEBUG_LL) += debug.o
obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
obj-$(CONFIG_ARM_VIRT_EXT) += hyp-stub.o
+obj-$(CONFIG_ARM_PSCI) += psci.o
extra-y := $(head-y) vmlinux.lds
diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
new file mode 100644
index 0000000..3653164
--- /dev/null
+++ b/arch/arm/kernel/psci.c
@@ -0,0 +1,211 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * Copyright (C) 2012 ARM Limited
+ *
+ * Author: Will Deacon <will.deacon-5wv7dgnIgG8@public.gmane.org>
+ */
+
+#define pr_fmt(fmt) "psci: " fmt
+
+#include <linux/init.h>
+#include <linux/of.h>
+
+#include <asm/compiler.h>
+#include <asm/errno.h>
+#include <asm/opcodes-sec.h>
+#include <asm/opcodes-virt.h>
+#include <asm/psci.h>
+
+struct psci_operations psci_ops;
+
+static int (*invoke_psci_fn)(u32, u32, u32, u32);
+
+enum psci_function {
+ PSCI_FN_CPU_SUSPEND,
+ PSCI_FN_CPU_ON,
+ PSCI_FN_CPU_OFF,
+ PSCI_FN_MIGRATE,
+ PSCI_FN_MAX,
+};
+
+static u32 psci_function_id[PSCI_FN_MAX];
+
+#define PSCI_RET_SUCCESS 0
+#define PSCI_RET_EOPNOTSUPP -1
+#define PSCI_RET_EINVAL -2
+#define PSCI_RET_EPERM -3
+
+static int psci_to_linux_errno(int errno)
+{
+ switch (errno) {
+ case PSCI_RET_SUCCESS:
+ return 0;
+ case PSCI_RET_EOPNOTSUPP:
+ return -EOPNOTSUPP;
+ case PSCI_RET_EINVAL:
+ return -EINVAL;
+ case PSCI_RET_EPERM:
+ return -EPERM;
+ };
+
+ return -EINVAL;
+}
+
+#define PSCI_POWER_STATE_ID_MASK 0xffff
+#define PSCI_POWER_STATE_ID_SHIFT 0
+#define PSCI_POWER_STATE_TYPE_MASK 0x1
+#define PSCI_POWER_STATE_TYPE_SHIFT 16
+#define PSCI_POWER_STATE_AFFL_MASK 0x3
+#define PSCI_POWER_STATE_AFFL_SHIFT 24
+
+static u32 psci_power_state_pack(struct psci_power_state state)
+{
+ return ((state.id & PSCI_POWER_STATE_ID_MASK)
+ << PSCI_POWER_STATE_ID_SHIFT) |
+ ((state.type & PSCI_POWER_STATE_TYPE_MASK)
+ << PSCI_POWER_STATE_TYPE_SHIFT) |
+ ((state.affinity_level & PSCI_POWER_STATE_AFFL_MASK)
+ << PSCI_POWER_STATE_AFFL_SHIFT);
+}
+
+/*
+ * The following two functions are invoked via the invoke_psci_fn pointer
+ * and will not be inlined, allowing us to piggyback on the AAPCS.
+ */
+static noinline int __invoke_psci_fn_hvc(u32 function_id, u32 arg0, u32 arg1,
+ u32 arg2)
+{
+ asm volatile(
+ __asmeq("%0", "r0")
+ __asmeq("%1", "r1")
+ __asmeq("%2", "r2")
+ __asmeq("%3", "r3")
+ __HVC(0)
+ : "+r" (function_id)
+ : "r" (arg0), "r" (arg1), "r" (arg2));
+
+ return function_id;
+}
+
+static noinline int __invoke_psci_fn_smc(u32 function_id, u32 arg0, u32 arg1,
+ u32 arg2)
+{
+ asm volatile(
+ __asmeq("%0", "r0")
+ __asmeq("%1", "r1")
+ __asmeq("%2", "r2")
+ __asmeq("%3", "r3")
+ __SMC(0)
+ : "+r" (function_id)
+ : "r" (arg0), "r" (arg1), "r" (arg2));
+
+ return function_id;
+}
+
+static int psci_cpu_suspend(struct psci_power_state state,
+ unsigned long entry_point)
+{
+ int err;
+ u32 fn, power_state;
+
+ fn = psci_function_id[PSCI_FN_CPU_SUSPEND];
+ power_state = psci_power_state_pack(state);
+ err = invoke_psci_fn(fn, power_state, entry_point, 0);
+ return psci_to_linux_errno(err);
+}
+
+static int psci_cpu_off(struct psci_power_state state)
+{
+ int err;
+ u32 fn, power_state;
+
+ fn = psci_function_id[PSCI_FN_CPU_OFF];
+ power_state = psci_power_state_pack(state);
+ err = invoke_psci_fn(fn, power_state, 0, 0);
+ return psci_to_linux_errno(err);
+}
+
+static int psci_cpu_on(unsigned long cpuid, unsigned long entry_point)
+{
+ int err;
+ u32 fn;
+
+ fn = psci_function_id[PSCI_FN_CPU_ON];
+ err = invoke_psci_fn(fn, cpuid, entry_point, 0);
+ return psci_to_linux_errno(err);
+}
+
+static int psci_migrate(unsigned long cpuid)
+{
+ int err;
+ u32 fn;
+
+ fn = psci_function_id[PSCI_FN_MIGRATE];
+ err = invoke_psci_fn(fn, cpuid, 0, 0);
+ return psci_to_linux_errno(err);
+}
+
+static const struct of_device_id psci_of_match[] __initconst = {
+ { .compatible = "arm,psci", },
+ {},
+};
+
+static int __init psci_init(void)
+{
+ struct device_node *np;
+ const char *method;
+ u32 id;
+
+ np = of_find_matching_node(NULL, psci_of_match);
+ if (!np)
+ return 0;
+
+ pr_info("probing function IDs from device-tree\n");
+
+ if (of_property_read_string(np, "method", &method)) {
+ pr_warning("missing \"method\" property\n");
+ goto out_put_node;
+ }
+
+ if (!strcmp("hvc", method)) {
+ invoke_psci_fn = __invoke_psci_fn_hvc;
+ } else if (!strcmp("smc", method)) {
+ invoke_psci_fn = __invoke_psci_fn_smc;
+ } else {
+ pr_warning("invalid \"method\" property: %s\n", method);
+ goto out_put_node;
+ }
+
+ if (!of_property_read_u32(np, "cpu_suspend", &id)) {
+ psci_function_id[PSCI_FN_CPU_SUSPEND] = id;
+ psci_ops.cpu_suspend = psci_cpu_suspend;
+ }
+
+ if (!of_property_read_u32(np, "cpu_off", &id)) {
+ psci_function_id[PSCI_FN_CPU_OFF] = id;
+ psci_ops.cpu_off = psci_cpu_off;
+ }
+
+ if (!of_property_read_u32(np, "cpu_on", &id)) {
+ psci_function_id[PSCI_FN_CPU_ON] = id;
+ psci_ops.cpu_on = psci_cpu_on;
+ }
+
+ if (!of_property_read_u32(np, "migrate", &id)) {
+ psci_function_id[PSCI_FN_MIGRATE] = id;
+ psci_ops.migrate = psci_migrate;
+ }
+
+out_put_node:
+ of_node_put(np);
+ return 0;
+}
+early_initcall(psci_init);
--
1.8.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v3 5/6] ARM: Dummy Virtual Machine platform support
[not found] ` <1355853196-23676-1-git-send-email-will.deacon-5wv7dgnIgG8@public.gmane.org>
` (3 preceding siblings ...)
2012-12-18 17:53 ` [PATCH v3 4/6] ARM: psci: add support for PSCI invocations from the kernel Will Deacon
@ 2012-12-18 17:53 ` Will Deacon
[not found] ` <1355853196-23676-6-git-send-email-will.deacon-5wv7dgnIgG8@public.gmane.org>
2012-12-18 17:59 ` [PATCH v3 0/6] Add support for a fake, para-virtualised machine Arnd Bergmann
5 siblings, 1 reply; 12+ messages in thread
From: Will Deacon @ 2012-12-18 17:53 UTC (permalink / raw)
To: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ, Will Deacon,
xen-devel-GuqFBffKawuEi8DpZVb4nw
From: Marc Zyngier <marc.zyngier-5wv7dgnIgG8@public.gmane.org>
Add support for the smallest, dumbest possible platform, to be
used as a guest for KVM or other hypervisors.
It only mandates a GIC and architected timers. Fits nicely with
a multiplatform zImage. Uses very little silicon area.
Signed-off-by: Marc Zyngier <marc.zyngier-5wv7dgnIgG8@public.gmane.org>
Signed-off-by: Will Deacon <will.deacon-5wv7dgnIgG8@public.gmane.org>
---
arch/arm/Kconfig | 2 ++
arch/arm/Makefile | 1 +
arch/arm/mach-virt/Kconfig | 9 +++++++
arch/arm/mach-virt/Makefile | 5 ++++
arch/arm/mach-virt/virt.c | 65 +++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 82 insertions(+)
create mode 100644 arch/arm/mach-virt/Kconfig
create mode 100644 arch/arm/mach-virt/Makefile
create mode 100644 arch/arm/mach-virt/virt.c
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 80d54b8..3443d89 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -1130,6 +1130,8 @@ source "arch/arm/mach-versatile/Kconfig"
source "arch/arm/mach-vexpress/Kconfig"
source "arch/arm/plat-versatile/Kconfig"
+source "arch/arm/mach-virt/Kconfig"
+
source "arch/arm/mach-vt8500/Kconfig"
source "arch/arm/mach-w90x900/Kconfig"
diff --git a/arch/arm/Makefile b/arch/arm/Makefile
index 30c443c..ea4f481 100644
--- a/arch/arm/Makefile
+++ b/arch/arm/Makefile
@@ -194,6 +194,7 @@ machine-$(CONFIG_ARCH_SOCFPGA) += socfpga
machine-$(CONFIG_ARCH_SPEAR13XX) += spear13xx
machine-$(CONFIG_ARCH_SPEAR3XX) += spear3xx
machine-$(CONFIG_MACH_SPEAR600) += spear6xx
+machine-$(CONFIG_ARCH_VIRT) += virt
machine-$(CONFIG_ARCH_ZYNQ) += zynq
machine-$(CONFIG_ARCH_SUNXI) += sunxi
diff --git a/arch/arm/mach-virt/Kconfig b/arch/arm/mach-virt/Kconfig
new file mode 100644
index 0000000..a568a2a
--- /dev/null
+++ b/arch/arm/mach-virt/Kconfig
@@ -0,0 +1,9 @@
+config ARCH_VIRT
+ bool "Dummy Virtual Machine" if ARCH_MULTI_V7
+ select ARCH_WANT_OPTIONAL_GPIOLIB
+ select ARM_GIC
+ select ARM_ARCH_TIMER
+ select HAVE_SMP
+ select CPU_V7
+ select SPARSE_IRQ
+ select USE_OF
diff --git a/arch/arm/mach-virt/Makefile b/arch/arm/mach-virt/Makefile
new file mode 100644
index 0000000..7ddbfa6
--- /dev/null
+++ b/arch/arm/mach-virt/Makefile
@@ -0,0 +1,5 @@
+#
+# Makefile for the linux kernel.
+#
+
+obj-y := virt.o
diff --git a/arch/arm/mach-virt/virt.c b/arch/arm/mach-virt/virt.c
new file mode 100644
index 0000000..174b9da
--- /dev/null
+++ b/arch/arm/mach-virt/virt.c
@@ -0,0 +1,65 @@
+/*
+ * Dummy Virtual Machine - does what it says on the tin.
+ *
+ * Copyright (C) 2012 ARM Ltd
+ * Authors: Will Deacon <will.deacon-5wv7dgnIgG8@public.gmane.org>,
+ * Marc Zyngier <marc.zyngier-5wv7dgnIgG8@public.gmane.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/of_irq.h>
+#include <linux/of_platform.h>
+
+#include <asm/arch_timer.h>
+#include <asm/hardware/gic.h>
+#include <asm/mach/arch.h>
+#include <asm/mach/time.h>
+
+const static struct of_device_id irq_match[] = {
+ { .compatible = "arm,cortex-a15-gic", .data = gic_of_init, },
+ {}
+};
+
+static void __init gic_init_irq(void)
+{
+ of_irq_init(irq_match);
+}
+
+static void __init virt_init(void)
+{
+ of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
+}
+
+static void __init virt_timer_init(void)
+{
+ WARN_ON(arch_timer_of_register() != 0);
+ WARN_ON(arch_timer_sched_clock_init() != 0);
+}
+
+static const char *virt_dt_match[] = {
+ "linux,dummy-virt",
+ NULL
+};
+
+static struct sys_timer virt_timer = {
+ .init = virt_timer_init,
+};
+
+DT_MACHINE_START(VIRT, "Dummy Virtual Machine")
+ .init_irq = gic_init_irq,
+ .handle_irq = gic_handle_irq,
+ .timer = &virt_timer,
+ .init_machine = virt_init,
+ .dt_compat = virt_dt_match,
+MACHINE_END
--
1.8.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v3 6/6] ARM: mach-virt: add SMP support using PSCI
2012-12-18 17:53 [PATCH v3 0/6] Add support for a fake, para-virtualised machine Will Deacon
[not found] ` <1355853196-23676-1-git-send-email-will.deacon-5wv7dgnIgG8@public.gmane.org>
@ 2012-12-18 17:53 ` Will Deacon
[not found] ` <1355853196-23676-7-git-send-email-will.deacon-5wv7dgnIgG8@public.gmane.org>
1 sibling, 1 reply; 12+ messages in thread
From: Will Deacon @ 2012-12-18 17:53 UTC (permalink / raw)
To: linux-arm-kernel
Cc: dave.martin, arnd, nico, Marc.Zyngier, devicetree-discuss,
Will Deacon, xen-devel
This patch adds support for SMP to mach-virt using the PSCI
infrastructure.
Signed-off-by: Will Deacon <will.deacon@arm.com>
---
arch/arm/mach-virt/Kconfig | 1 +
arch/arm/mach-virt/Makefile | 1 +
arch/arm/mach-virt/platsmp.c | 58 ++++++++++++++++++++++++++++++++++++++++++++
arch/arm/mach-virt/virt.c | 4 +++
4 files changed, 64 insertions(+)
create mode 100644 arch/arm/mach-virt/platsmp.c
diff --git a/arch/arm/mach-virt/Kconfig b/arch/arm/mach-virt/Kconfig
index a568a2a..8958f0d 100644
--- a/arch/arm/mach-virt/Kconfig
+++ b/arch/arm/mach-virt/Kconfig
@@ -3,6 +3,7 @@ config ARCH_VIRT
select ARCH_WANT_OPTIONAL_GPIOLIB
select ARM_GIC
select ARM_ARCH_TIMER
+ select ARM_PSCI
select HAVE_SMP
select CPU_V7
select SPARSE_IRQ
diff --git a/arch/arm/mach-virt/Makefile b/arch/arm/mach-virt/Makefile
index 7ddbfa6..042afc1 100644
--- a/arch/arm/mach-virt/Makefile
+++ b/arch/arm/mach-virt/Makefile
@@ -3,3 +3,4 @@
#
obj-y := virt.o
+obj-$(CONFIG_SMP) += platsmp.o
diff --git a/arch/arm/mach-virt/platsmp.c b/arch/arm/mach-virt/platsmp.c
new file mode 100644
index 0000000..e358beb
--- /dev/null
+++ b/arch/arm/mach-virt/platsmp.c
@@ -0,0 +1,58 @@
+/*
+ * Dummy Virtual Machine - does what it says on the tin.
+ *
+ * Copyright (C) 2012 ARM Ltd
+ * Author: Will Deacon <will.deacon@arm.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/init.h>
+#include <linux/smp.h>
+#include <linux/of.h>
+
+#include <asm/psci.h>
+#include <asm/smp_plat.h>
+#include <asm/hardware/gic.h>
+
+extern void secondary_startup(void);
+
+static void __init virt_smp_init_cpus(void)
+{
+ set_smp_cross_call(gic_raise_softirq);
+}
+
+static void __init virt_smp_prepare_cpus(unsigned int max_cpus)
+{
+}
+
+static int __cpuinit virt_boot_secondary(unsigned int cpu,
+ struct task_struct *idle)
+{
+ if (psci_ops.cpu_on)
+ return psci_ops.cpu_on(cpu_logical_map(cpu),
+ __pa(secondary_startup));
+ return -ENODEV;
+}
+
+static void __cpuinit virt_secondary_init(unsigned int cpu)
+{
+ gic_secondary_init(0);
+}
+
+struct smp_operations __initdata virt_smp_ops = {
+ .smp_init_cpus = virt_smp_init_cpus,
+ .smp_prepare_cpus = virt_smp_prepare_cpus,
+ .smp_secondary_init = virt_secondary_init,
+ .smp_boot_secondary = virt_boot_secondary,
+};
diff --git a/arch/arm/mach-virt/virt.c b/arch/arm/mach-virt/virt.c
index 174b9da..1d0a85a 100644
--- a/arch/arm/mach-virt/virt.c
+++ b/arch/arm/mach-virt/virt.c
@@ -20,6 +20,7 @@
#include <linux/of_irq.h>
#include <linux/of_platform.h>
+#include <linux/smp.h>
#include <asm/arch_timer.h>
#include <asm/hardware/gic.h>
@@ -56,10 +57,13 @@ static struct sys_timer virt_timer = {
.init = virt_timer_init,
};
+extern struct smp_operations virt_smp_ops;
+
DT_MACHINE_START(VIRT, "Dummy Virtual Machine")
.init_irq = gic_init_irq,
.handle_irq = gic_handle_irq,
.timer = &virt_timer,
.init_machine = virt_init,
+ .smp = smp_ops(virt_smp_ops),
.dt_compat = virt_dt_match,
MACHINE_END
--
1.8.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH v3 0/6] Add support for a fake, para-virtualised machine
[not found] ` <1355853196-23676-1-git-send-email-will.deacon-5wv7dgnIgG8@public.gmane.org>
` (4 preceding siblings ...)
2012-12-18 17:53 ` [PATCH v3 5/6] ARM: Dummy Virtual Machine platform support Will Deacon
@ 2012-12-18 17:59 ` Arnd Bergmann
5 siblings, 0 replies; 12+ messages in thread
From: Arnd Bergmann @ 2012-12-18 17:59 UTC (permalink / raw)
To: Will Deacon
Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
xen-devel-GuqFBffKawuEi8DpZVb4nw,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
On Tuesday 18 December 2012, Will Deacon wrote:
> This is version three of the patches originally posted here:
>
> v1.) http://lists.infradead.org/pipermail/linux-arm-kernel/2012-December/135870.html
> v2.) http://lists.infradead.org/pipermail/linux-arm-kernel/2012-December/137750.html
>
> Thanks to all those who have provided comments so far.
> Changes for v3 include:
>
> * Ripped out *even more* SMP code by rebasing onto latest
> mainline
> * Removed function-base property from device-tree binding
> * Annotated the low-level firmware invocation functions with
> noinline to clarify intent
> * Minor cleanups
>
> As usual, testing this relies on KVM support for PSCI, a magic kvmtool
> and Mark Rutland's arch-timer patches.
>
Acked-by: Arnd Bergmann <arnd-r2nGTMty4D4@public.gmane.org>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v3 6/6] ARM: mach-virt: add SMP support using PSCI
[not found] ` <1355853196-23676-7-git-send-email-will.deacon-5wv7dgnIgG8@public.gmane.org>
@ 2012-12-19 4:09 ` Nicolas Pitre
0 siblings, 0 replies; 12+ messages in thread
From: Nicolas Pitre @ 2012-12-19 4:09 UTC (permalink / raw)
To: Will Deacon
Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
xen-devel-GuqFBffKawuEi8DpZVb4nw,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
On Tue, 18 Dec 2012, Will Deacon wrote:
> This patch adds support for SMP to mach-virt using the PSCI
> infrastructure.
>
> Signed-off-by: Will Deacon <will.deacon-5wv7dgnIgG8@public.gmane.org>
Reviewed-by: Nicolas Pitre <nico-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
> ---
> arch/arm/mach-virt/Kconfig | 1 +
> arch/arm/mach-virt/Makefile | 1 +
> arch/arm/mach-virt/platsmp.c | 58 ++++++++++++++++++++++++++++++++++++++++++++
> arch/arm/mach-virt/virt.c | 4 +++
> 4 files changed, 64 insertions(+)
> create mode 100644 arch/arm/mach-virt/platsmp.c
>
> diff --git a/arch/arm/mach-virt/Kconfig b/arch/arm/mach-virt/Kconfig
> index a568a2a..8958f0d 100644
> --- a/arch/arm/mach-virt/Kconfig
> +++ b/arch/arm/mach-virt/Kconfig
> @@ -3,6 +3,7 @@ config ARCH_VIRT
> select ARCH_WANT_OPTIONAL_GPIOLIB
> select ARM_GIC
> select ARM_ARCH_TIMER
> + select ARM_PSCI
> select HAVE_SMP
> select CPU_V7
> select SPARSE_IRQ
> diff --git a/arch/arm/mach-virt/Makefile b/arch/arm/mach-virt/Makefile
> index 7ddbfa6..042afc1 100644
> --- a/arch/arm/mach-virt/Makefile
> +++ b/arch/arm/mach-virt/Makefile
> @@ -3,3 +3,4 @@
> #
>
> obj-y := virt.o
> +obj-$(CONFIG_SMP) += platsmp.o
> diff --git a/arch/arm/mach-virt/platsmp.c b/arch/arm/mach-virt/platsmp.c
> new file mode 100644
> index 0000000..e358beb
> --- /dev/null
> +++ b/arch/arm/mach-virt/platsmp.c
> @@ -0,0 +1,58 @@
> +/*
> + * Dummy Virtual Machine - does what it says on the tin.
> + *
> + * Copyright (C) 2012 ARM Ltd
> + * Author: Will Deacon <will.deacon-5wv7dgnIgG8@public.gmane.org>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program. If not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#include <linux/init.h>
> +#include <linux/smp.h>
> +#include <linux/of.h>
> +
> +#include <asm/psci.h>
> +#include <asm/smp_plat.h>
> +#include <asm/hardware/gic.h>
> +
> +extern void secondary_startup(void);
> +
> +static void __init virt_smp_init_cpus(void)
> +{
> + set_smp_cross_call(gic_raise_softirq);
> +}
> +
> +static void __init virt_smp_prepare_cpus(unsigned int max_cpus)
> +{
> +}
> +
> +static int __cpuinit virt_boot_secondary(unsigned int cpu,
> + struct task_struct *idle)
> +{
> + if (psci_ops.cpu_on)
> + return psci_ops.cpu_on(cpu_logical_map(cpu),
> + __pa(secondary_startup));
> + return -ENODEV;
> +}
> +
> +static void __cpuinit virt_secondary_init(unsigned int cpu)
> +{
> + gic_secondary_init(0);
> +}
> +
> +struct smp_operations __initdata virt_smp_ops = {
> + .smp_init_cpus = virt_smp_init_cpus,
> + .smp_prepare_cpus = virt_smp_prepare_cpus,
> + .smp_secondary_init = virt_secondary_init,
> + .smp_boot_secondary = virt_boot_secondary,
> +};
> diff --git a/arch/arm/mach-virt/virt.c b/arch/arm/mach-virt/virt.c
> index 174b9da..1d0a85a 100644
> --- a/arch/arm/mach-virt/virt.c
> +++ b/arch/arm/mach-virt/virt.c
> @@ -20,6 +20,7 @@
>
> #include <linux/of_irq.h>
> #include <linux/of_platform.h>
> +#include <linux/smp.h>
>
> #include <asm/arch_timer.h>
> #include <asm/hardware/gic.h>
> @@ -56,10 +57,13 @@ static struct sys_timer virt_timer = {
> .init = virt_timer_init,
> };
>
> +extern struct smp_operations virt_smp_ops;
> +
> DT_MACHINE_START(VIRT, "Dummy Virtual Machine")
> .init_irq = gic_init_irq,
> .handle_irq = gic_handle_irq,
> .timer = &virt_timer,
> .init_machine = virt_init,
> + .smp = smp_ops(virt_smp_ops),
> .dt_compat = virt_dt_match,
> MACHINE_END
> --
> 1.8.0
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v3 3/6] ARM: psci: add devicetree binding for describing PSCI firmware
2012-12-18 17:53 ` [PATCH v3 3/6] ARM: psci: add devicetree binding for describing PSCI firmware Will Deacon
@ 2012-12-19 4:11 ` Nicolas Pitre
0 siblings, 0 replies; 12+ messages in thread
From: Nicolas Pitre @ 2012-12-19 4:11 UTC (permalink / raw)
To: Will Deacon
Cc: dave.martin, arnd, Marc.Zyngier, devicetree-discuss, xen-devel,
linux-arm-kernel
On Tue, 18 Dec 2012, Will Deacon wrote:
> This patch adds a new devicetree binding for describing PSCI firmware
> to Linux.
>
> Signed-off-by: Will Deacon <will.deacon@arm.com>
Acked-by: Nicolas Pitre <nico@linaro.org>
> ---
> Documentation/devicetree/bindings/arm/psci.txt | 55 ++++++++++++++++++++++++++
> 1 file changed, 55 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/arm/psci.txt
>
> diff --git a/Documentation/devicetree/bindings/arm/psci.txt b/Documentation/devicetree/bindings/arm/psci.txt
> new file mode 100644
> index 0000000..433afe9
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/arm/psci.txt
> @@ -0,0 +1,55 @@
> +* Power State Coordination Interface (PSCI)
> +
> +Firmware implementing the PSCI functions described in ARM document number
> +ARM DEN 0022A ("Power State Coordination Interface System Software on ARM
> +processors") can be used by Linux to initiate various CPU-centric power
> +operations.
> +
> +Issue A of the specification describes functions for CPU suspend, hotplug
> +and migration of secure software.
> +
> +Functions are invoked by trapping to the privilege level of the PSCI
> +firmware (specified as part of the binding below) and passing arguments
> +in a manner similar to that specified by AAPCS:
> +
> + r0 => 32-bit Function ID / return value
> + {r1 - r3} => Parameters
> +
> +Note that the immediate field of the trapping instruction must be set
> +to #0.
> +
> +
> +Main node required properties:
> +
> + - compatible : Must be "arm,psci"
> +
> + - method : The method of calling the PSCI firmware. Permitted
> + values are:
> +
> + "smc" : SMC #0, with the register assignments specified
> + in this binding.
> +
> + "hvc" : HVC #0, with the register assignments specified
> + in this binding.
> +
> +Main node optional properties:
> +
> + - cpu_suspend : Function ID for CPU_SUSPEND operation
> +
> + - cpu_off : Function ID for CPU_OFF operation
> +
> + - cpu_on : Function ID for CPU_ON operation
> +
> + - migrate : Function ID for MIGRATE operation
> +
> +
> +Example:
> +
> + psci {
> + compatible = "arm,psci";
> + method = "smc";
> + cpu_suspend = <0x95c10000>;
> + cpu_off = <0x95c10001>;
> + cpu_on = <0x95c10002>;
> + migrate = <0x95c10003>;
> + };
> --
> 1.8.0
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v3 4/6] ARM: psci: add support for PSCI invocations from the kernel
[not found] ` <1355853196-23676-5-git-send-email-will.deacon-5wv7dgnIgG8@public.gmane.org>
@ 2012-12-19 4:16 ` Nicolas Pitre
0 siblings, 0 replies; 12+ messages in thread
From: Nicolas Pitre @ 2012-12-19 4:16 UTC (permalink / raw)
To: Will Deacon
Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
xen-devel-GuqFBffKawuEi8DpZVb4nw,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
On Tue, 18 Dec 2012, Will Deacon wrote:
> This patch adds support for the Power State Coordination Interface
> defined by ARM, allowing Linux to request CPU-centric power-management
> operations from firmware implementing the PSCI protocol.
>
> Signed-off-by: Will Deacon <will.deacon-5wv7dgnIgG8@public.gmane.org>
Acked-by: Nicolas Pitre <nico-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
> ---
> arch/arm/Kconfig | 10 +++
> arch/arm/include/asm/psci.h | 36 ++++++++
> arch/arm/kernel/Makefile | 1 +
> arch/arm/kernel/psci.c | 211 ++++++++++++++++++++++++++++++++++++++++++++
> 4 files changed, 258 insertions(+)
> create mode 100644 arch/arm/include/asm/psci.h
> create mode 100644 arch/arm/kernel/psci.c
>
> diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
> index 8c83d98..80d54b8 100644
> --- a/arch/arm/Kconfig
> +++ b/arch/arm/Kconfig
> @@ -1617,6 +1617,16 @@ config HOTPLUG_CPU
> Say Y here to experiment with turning CPUs off and on. CPUs
> can be controlled through /sys/devices/system/cpu.
>
> +config ARM_PSCI
> + bool "Support for the ARM Power State Coordination Interface (PSCI)"
> + depends on CPU_V7
> + help
> + Say Y here if you want Linux to communicate with system firmware
> + implementing the PSCI specification for CPU-centric power
> + management operations described in ARM document number ARM DEN
> + 0022A ("Power State Coordination Interface System Software on
> + ARM processors").
> +
> config LOCAL_TIMERS
> bool "Use local timer interrupts"
> depends on SMP
> diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
> new file mode 100644
> index 0000000..ce0dbe7
> --- /dev/null
> +++ b/arch/arm/include/asm/psci.h
> @@ -0,0 +1,36 @@
> +/*
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * Copyright (C) 2012 ARM Limited
> + */
> +
> +#ifndef __ASM_ARM_PSCI_H
> +#define __ASM_ARM_PSCI_H
> +
> +#define PSCI_POWER_STATE_TYPE_STANDBY 0
> +#define PSCI_POWER_STATE_TYPE_POWER_DOWN 1
> +
> +struct psci_power_state {
> + u16 id;
> + u8 type;
> + u8 affinity_level;
> +};
> +
> +struct psci_operations {
> + int (*cpu_suspend)(struct psci_power_state state,
> + unsigned long entry_point);
> + int (*cpu_off)(struct psci_power_state state);
> + int (*cpu_on)(unsigned long cpuid, unsigned long entry_point);
> + int (*migrate)(unsigned long cpuid);
> +};
> +
> +extern struct psci_operations psci_ops;
> +
> +#endif /* __ASM_ARM_PSCI_H */
> diff --git a/arch/arm/kernel/Makefile b/arch/arm/kernel/Makefile
> index 5bbec7b..5f3338e 100644
> --- a/arch/arm/kernel/Makefile
> +++ b/arch/arm/kernel/Makefile
> @@ -82,5 +82,6 @@ obj-$(CONFIG_DEBUG_LL) += debug.o
> obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
>
> obj-$(CONFIG_ARM_VIRT_EXT) += hyp-stub.o
> +obj-$(CONFIG_ARM_PSCI) += psci.o
>
> extra-y := $(head-y) vmlinux.lds
> diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
> new file mode 100644
> index 0000000..3653164
> --- /dev/null
> +++ b/arch/arm/kernel/psci.c
> @@ -0,0 +1,211 @@
> +/*
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * Copyright (C) 2012 ARM Limited
> + *
> + * Author: Will Deacon <will.deacon-5wv7dgnIgG8@public.gmane.org>
> + */
> +
> +#define pr_fmt(fmt) "psci: " fmt
> +
> +#include <linux/init.h>
> +#include <linux/of.h>
> +
> +#include <asm/compiler.h>
> +#include <asm/errno.h>
> +#include <asm/opcodes-sec.h>
> +#include <asm/opcodes-virt.h>
> +#include <asm/psci.h>
> +
> +struct psci_operations psci_ops;
> +
> +static int (*invoke_psci_fn)(u32, u32, u32, u32);
> +
> +enum psci_function {
> + PSCI_FN_CPU_SUSPEND,
> + PSCI_FN_CPU_ON,
> + PSCI_FN_CPU_OFF,
> + PSCI_FN_MIGRATE,
> + PSCI_FN_MAX,
> +};
> +
> +static u32 psci_function_id[PSCI_FN_MAX];
> +
> +#define PSCI_RET_SUCCESS 0
> +#define PSCI_RET_EOPNOTSUPP -1
> +#define PSCI_RET_EINVAL -2
> +#define PSCI_RET_EPERM -3
> +
> +static int psci_to_linux_errno(int errno)
> +{
> + switch (errno) {
> + case PSCI_RET_SUCCESS:
> + return 0;
> + case PSCI_RET_EOPNOTSUPP:
> + return -EOPNOTSUPP;
> + case PSCI_RET_EINVAL:
> + return -EINVAL;
> + case PSCI_RET_EPERM:
> + return -EPERM;
> + };
> +
> + return -EINVAL;
> +}
> +
> +#define PSCI_POWER_STATE_ID_MASK 0xffff
> +#define PSCI_POWER_STATE_ID_SHIFT 0
> +#define PSCI_POWER_STATE_TYPE_MASK 0x1
> +#define PSCI_POWER_STATE_TYPE_SHIFT 16
> +#define PSCI_POWER_STATE_AFFL_MASK 0x3
> +#define PSCI_POWER_STATE_AFFL_SHIFT 24
> +
> +static u32 psci_power_state_pack(struct psci_power_state state)
> +{
> + return ((state.id & PSCI_POWER_STATE_ID_MASK)
> + << PSCI_POWER_STATE_ID_SHIFT) |
> + ((state.type & PSCI_POWER_STATE_TYPE_MASK)
> + << PSCI_POWER_STATE_TYPE_SHIFT) |
> + ((state.affinity_level & PSCI_POWER_STATE_AFFL_MASK)
> + << PSCI_POWER_STATE_AFFL_SHIFT);
> +}
> +
> +/*
> + * The following two functions are invoked via the invoke_psci_fn pointer
> + * and will not be inlined, allowing us to piggyback on the AAPCS.
> + */
> +static noinline int __invoke_psci_fn_hvc(u32 function_id, u32 arg0, u32 arg1,
> + u32 arg2)
> +{
> + asm volatile(
> + __asmeq("%0", "r0")
> + __asmeq("%1", "r1")
> + __asmeq("%2", "r2")
> + __asmeq("%3", "r3")
> + __HVC(0)
> + : "+r" (function_id)
> + : "r" (arg0), "r" (arg1), "r" (arg2));
> +
> + return function_id;
> +}
> +
> +static noinline int __invoke_psci_fn_smc(u32 function_id, u32 arg0, u32 arg1,
> + u32 arg2)
> +{
> + asm volatile(
> + __asmeq("%0", "r0")
> + __asmeq("%1", "r1")
> + __asmeq("%2", "r2")
> + __asmeq("%3", "r3")
> + __SMC(0)
> + : "+r" (function_id)
> + : "r" (arg0), "r" (arg1), "r" (arg2));
> +
> + return function_id;
> +}
> +
> +static int psci_cpu_suspend(struct psci_power_state state,
> + unsigned long entry_point)
> +{
> + int err;
> + u32 fn, power_state;
> +
> + fn = psci_function_id[PSCI_FN_CPU_SUSPEND];
> + power_state = psci_power_state_pack(state);
> + err = invoke_psci_fn(fn, power_state, entry_point, 0);
> + return psci_to_linux_errno(err);
> +}
> +
> +static int psci_cpu_off(struct psci_power_state state)
> +{
> + int err;
> + u32 fn, power_state;
> +
> + fn = psci_function_id[PSCI_FN_CPU_OFF];
> + power_state = psci_power_state_pack(state);
> + err = invoke_psci_fn(fn, power_state, 0, 0);
> + return psci_to_linux_errno(err);
> +}
> +
> +static int psci_cpu_on(unsigned long cpuid, unsigned long entry_point)
> +{
> + int err;
> + u32 fn;
> +
> + fn = psci_function_id[PSCI_FN_CPU_ON];
> + err = invoke_psci_fn(fn, cpuid, entry_point, 0);
> + return psci_to_linux_errno(err);
> +}
> +
> +static int psci_migrate(unsigned long cpuid)
> +{
> + int err;
> + u32 fn;
> +
> + fn = psci_function_id[PSCI_FN_MIGRATE];
> + err = invoke_psci_fn(fn, cpuid, 0, 0);
> + return psci_to_linux_errno(err);
> +}
> +
> +static const struct of_device_id psci_of_match[] __initconst = {
> + { .compatible = "arm,psci", },
> + {},
> +};
> +
> +static int __init psci_init(void)
> +{
> + struct device_node *np;
> + const char *method;
> + u32 id;
> +
> + np = of_find_matching_node(NULL, psci_of_match);
> + if (!np)
> + return 0;
> +
> + pr_info("probing function IDs from device-tree\n");
> +
> + if (of_property_read_string(np, "method", &method)) {
> + pr_warning("missing \"method\" property\n");
> + goto out_put_node;
> + }
> +
> + if (!strcmp("hvc", method)) {
> + invoke_psci_fn = __invoke_psci_fn_hvc;
> + } else if (!strcmp("smc", method)) {
> + invoke_psci_fn = __invoke_psci_fn_smc;
> + } else {
> + pr_warning("invalid \"method\" property: %s\n", method);
> + goto out_put_node;
> + }
> +
> + if (!of_property_read_u32(np, "cpu_suspend", &id)) {
> + psci_function_id[PSCI_FN_CPU_SUSPEND] = id;
> + psci_ops.cpu_suspend = psci_cpu_suspend;
> + }
> +
> + if (!of_property_read_u32(np, "cpu_off", &id)) {
> + psci_function_id[PSCI_FN_CPU_OFF] = id;
> + psci_ops.cpu_off = psci_cpu_off;
> + }
> +
> + if (!of_property_read_u32(np, "cpu_on", &id)) {
> + psci_function_id[PSCI_FN_CPU_ON] = id;
> + psci_ops.cpu_on = psci_cpu_on;
> + }
> +
> + if (!of_property_read_u32(np, "migrate", &id)) {
> + psci_function_id[PSCI_FN_MIGRATE] = id;
> + psci_ops.migrate = psci_migrate;
> + }
> +
> +out_put_node:
> + of_node_put(np);
> + return 0;
> +}
> +early_initcall(psci_init);
> --
> 1.8.0
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v3 5/6] ARM: Dummy Virtual Machine platform support
[not found] ` <1355853196-23676-6-git-send-email-will.deacon-5wv7dgnIgG8@public.gmane.org>
@ 2012-12-19 4:17 ` Nicolas Pitre
0 siblings, 0 replies; 12+ messages in thread
From: Nicolas Pitre @ 2012-12-19 4:17 UTC (permalink / raw)
To: Will Deacon
Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
xen-devel-GuqFBffKawuEi8DpZVb4nw,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
On Tue, 18 Dec 2012, Will Deacon wrote:
> From: Marc Zyngier <marc.zyngier-5wv7dgnIgG8@public.gmane.org>
>
> Add support for the smallest, dumbest possible platform, to be
> used as a guest for KVM or other hypervisors.
>
> It only mandates a GIC and architected timers. Fits nicely with
> a multiplatform zImage. Uses very little silicon area.
>
> Signed-off-by: Marc Zyngier <marc.zyngier-5wv7dgnIgG8@public.gmane.org>
> Signed-off-by: Will Deacon <will.deacon-5wv7dgnIgG8@public.gmane.org>
Acked-by: Nicolas Pitre <nico-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
> ---
> arch/arm/Kconfig | 2 ++
> arch/arm/Makefile | 1 +
> arch/arm/mach-virt/Kconfig | 9 +++++++
> arch/arm/mach-virt/Makefile | 5 ++++
> arch/arm/mach-virt/virt.c | 65 +++++++++++++++++++++++++++++++++++++++++++++
> 5 files changed, 82 insertions(+)
> create mode 100644 arch/arm/mach-virt/Kconfig
> create mode 100644 arch/arm/mach-virt/Makefile
> create mode 100644 arch/arm/mach-virt/virt.c
>
> diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
> index 80d54b8..3443d89 100644
> --- a/arch/arm/Kconfig
> +++ b/arch/arm/Kconfig
> @@ -1130,6 +1130,8 @@ source "arch/arm/mach-versatile/Kconfig"
> source "arch/arm/mach-vexpress/Kconfig"
> source "arch/arm/plat-versatile/Kconfig"
>
> +source "arch/arm/mach-virt/Kconfig"
> +
> source "arch/arm/mach-vt8500/Kconfig"
>
> source "arch/arm/mach-w90x900/Kconfig"
> diff --git a/arch/arm/Makefile b/arch/arm/Makefile
> index 30c443c..ea4f481 100644
> --- a/arch/arm/Makefile
> +++ b/arch/arm/Makefile
> @@ -194,6 +194,7 @@ machine-$(CONFIG_ARCH_SOCFPGA) += socfpga
> machine-$(CONFIG_ARCH_SPEAR13XX) += spear13xx
> machine-$(CONFIG_ARCH_SPEAR3XX) += spear3xx
> machine-$(CONFIG_MACH_SPEAR600) += spear6xx
> +machine-$(CONFIG_ARCH_VIRT) += virt
> machine-$(CONFIG_ARCH_ZYNQ) += zynq
> machine-$(CONFIG_ARCH_SUNXI) += sunxi
>
> diff --git a/arch/arm/mach-virt/Kconfig b/arch/arm/mach-virt/Kconfig
> new file mode 100644
> index 0000000..a568a2a
> --- /dev/null
> +++ b/arch/arm/mach-virt/Kconfig
> @@ -0,0 +1,9 @@
> +config ARCH_VIRT
> + bool "Dummy Virtual Machine" if ARCH_MULTI_V7
> + select ARCH_WANT_OPTIONAL_GPIOLIB
> + select ARM_GIC
> + select ARM_ARCH_TIMER
> + select HAVE_SMP
> + select CPU_V7
> + select SPARSE_IRQ
> + select USE_OF
> diff --git a/arch/arm/mach-virt/Makefile b/arch/arm/mach-virt/Makefile
> new file mode 100644
> index 0000000..7ddbfa6
> --- /dev/null
> +++ b/arch/arm/mach-virt/Makefile
> @@ -0,0 +1,5 @@
> +#
> +# Makefile for the linux kernel.
> +#
> +
> +obj-y := virt.o
> diff --git a/arch/arm/mach-virt/virt.c b/arch/arm/mach-virt/virt.c
> new file mode 100644
> index 0000000..174b9da
> --- /dev/null
> +++ b/arch/arm/mach-virt/virt.c
> @@ -0,0 +1,65 @@
> +/*
> + * Dummy Virtual Machine - does what it says on the tin.
> + *
> + * Copyright (C) 2012 ARM Ltd
> + * Authors: Will Deacon <will.deacon-5wv7dgnIgG8@public.gmane.org>,
> + * Marc Zyngier <marc.zyngier-5wv7dgnIgG8@public.gmane.org>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program. If not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#include <linux/of_irq.h>
> +#include <linux/of_platform.h>
> +
> +#include <asm/arch_timer.h>
> +#include <asm/hardware/gic.h>
> +#include <asm/mach/arch.h>
> +#include <asm/mach/time.h>
> +
> +const static struct of_device_id irq_match[] = {
> + { .compatible = "arm,cortex-a15-gic", .data = gic_of_init, },
> + {}
> +};
> +
> +static void __init gic_init_irq(void)
> +{
> + of_irq_init(irq_match);
> +}
> +
> +static void __init virt_init(void)
> +{
> + of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
> +}
> +
> +static void __init virt_timer_init(void)
> +{
> + WARN_ON(arch_timer_of_register() != 0);
> + WARN_ON(arch_timer_sched_clock_init() != 0);
> +}
> +
> +static const char *virt_dt_match[] = {
> + "linux,dummy-virt",
> + NULL
> +};
> +
> +static struct sys_timer virt_timer = {
> + .init = virt_timer_init,
> +};
> +
> +DT_MACHINE_START(VIRT, "Dummy Virtual Machine")
> + .init_irq = gic_init_irq,
> + .handle_irq = gic_handle_irq,
> + .timer = &virt_timer,
> + .init_machine = virt_init,
> + .dt_compat = virt_dt_match,
> +MACHINE_END
> --
> 1.8.0
>
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2012-12-19 4:17 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-18 17:53 [PATCH v3 0/6] Add support for a fake, para-virtualised machine Will Deacon
[not found] ` <1355853196-23676-1-git-send-email-will.deacon-5wv7dgnIgG8@public.gmane.org>
2012-12-18 17:53 ` [PATCH v3 1/6] ARM: opcodes: add missing include of linux/linkage.h Will Deacon
2012-12-18 17:53 ` [PATCH v3 2/6] ARM: opcodes: add opcodes definitions for ARM security extensions Will Deacon
2012-12-18 17:53 ` [PATCH v3 3/6] ARM: psci: add devicetree binding for describing PSCI firmware Will Deacon
2012-12-19 4:11 ` Nicolas Pitre
2012-12-18 17:53 ` [PATCH v3 4/6] ARM: psci: add support for PSCI invocations from the kernel Will Deacon
[not found] ` <1355853196-23676-5-git-send-email-will.deacon-5wv7dgnIgG8@public.gmane.org>
2012-12-19 4:16 ` Nicolas Pitre
2012-12-18 17:53 ` [PATCH v3 5/6] ARM: Dummy Virtual Machine platform support Will Deacon
[not found] ` <1355853196-23676-6-git-send-email-will.deacon-5wv7dgnIgG8@public.gmane.org>
2012-12-19 4:17 ` Nicolas Pitre
2012-12-18 17:59 ` [PATCH v3 0/6] Add support for a fake, para-virtualised machine Arnd Bergmann
2012-12-18 17:53 ` [PATCH v3 6/6] ARM: mach-virt: add SMP support using PSCI Will Deacon
[not found] ` <1355853196-23676-7-git-send-email-will.deacon-5wv7dgnIgG8@public.gmane.org>
2012-12-19 4:09 ` Nicolas Pitre
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).