Add support for a fake, para-virtualised machine
Subsystems (3)
v3 cover Add support for a fake, para-virtualised machine
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
Signature · 1 line
1.8.0
PATCH v3 1/6 ARM: opcodes: add missing include of linux/linkage.h
opcodes.h wants to declare an asmlinkage function, so we need to include linux/linkage.h
--- arch/arm/include/asm/opcodes.h | 1 + 1 file changed, 1 insertion(+)
arch/arm/include/asm/opcodes.h +1 -0
@@ -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
Signature · 1 line
1.8.0
PATCH v3 1/6 ARM: opcodes: add missing include of linux/linkage.h
In reply to Will Deaconopcodes.h wants to declare an asmlinkage function, so we need to include linux/linkage.h
--- arch/arm/include/asm/opcodes.h | 1 + 1 file changed, 1 insertion(+)
arch/arm/include/asm/opcodes.h +1 -0
@@ -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
Signature · 1 line
1.8.0
PATCH v3 2/6 ARM: opcodes: add opcodes definitions for ARM security extensions
In reply to Will DeaconThe 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.
--- arch/arm/include/asm/opcodes-sec.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 arch/arm/include/asm/opcodes-sec.h
arch/arm/include/asm/opcodes-sec.h new file +24 -0
@@ -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 */
Signature · 1 line
1.8.0
PATCH v3 2/6 ARM: opcodes: add opcodes definitions for ARM security extensions
In reply to Will DeaconThe 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.
--- arch/arm/include/asm/opcodes-sec.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 arch/arm/include/asm/opcodes-sec.h
arch/arm/include/asm/opcodes-sec.h new file +24 -0
@@ -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 */
Signature · 1 line
1.8.0
PATCH v3 3/6 ARM: psci: add devicetree binding for describing PSCI firmware
In reply to Will DeaconThis patch adds a new devicetree binding for describing PSCI firmware to Linux.
--- Documentation/devicetree/bindings/arm/psci.txt | 55 ++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Documentation/devicetree/bindings/arm/psci.txt
Documentation/devicetree/bindings/arm/psci.txt new file +55 -0
@@ -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>; + };
Signature · 1 line
1.8.0
PATCH v3 3/6 ARM: psci: add devicetree binding for describing PSCI firmware
Quoted 4 lines · Will Deacon
This patch adds a new devicetree binding for describing PSCI firmware to Linux.
Signed-off-by Will Deacon <[email protected]>
Quoted 69 lines
--- Documentation/devicetree/bindings/arm/psci.txt | 55 ++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Documentation/devicetree/bindings/arm/psci.txtDocumentation/devicetree/bindings/arm/psci.txt new file +55
-0@@ -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>; + };Signature · 1 line
1.8.0
Re: [PATCH v3 3/6] ARM: psci: add devicetree binding for describing PSCI firmware
In reply to Will DeaconQuoted 4 lines · Will Deacon
This patch adds a new devicetree binding for describing PSCI firmware to Linux.
Signed-off-by Will Deacon <[email protected]>
Quoted 69 lines
--- Documentation/devicetree/bindings/arm/psci.txt | 55 ++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Documentation/devicetree/bindings/arm/psci.txtDocumentation/devicetree/bindings/arm/psci.txt new file +55
-0@@ -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>; + };Signature · 1 line
1.8.0
PATCH v3 3/6 ARM: psci: add devicetree binding for describing PSCI firmware
In reply to Will DeaconThis patch adds a new devicetree binding for describing PSCI firmware to Linux.
--- Documentation/devicetree/bindings/arm/psci.txt | 55 ++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Documentation/devicetree/bindings/arm/psci.txt
Documentation/devicetree/bindings/arm/psci.txt new file +55 -0
@@ -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>; + };
Signature · 1 line
1.8.0
PATCH v3 4/6 ARM: psci: add support for PSCI invocations from the kernel
In reply to Will DeaconThis 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.
--- 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
arch/arm/Kconfig +10 -0
@@ -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
arch/arm/include/asm/psci.h new file +36 -0
@@ -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 */
arch/arm/kernel/Makefile +1 -0
@@ -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
arch/arm/kernel/psci.c new file +211 -0
211 lines not on this page · raw message
Signature · 1 line
1.8.0
PATCH v3 4/6 ARM: psci: add support for PSCI invocations from the kernel
Quoted 5 lines · Will Deacon
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 <[email protected]>
Quoted 303 lines
--- 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.carch/arm/Kconfig +10
-0@@ -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 SMParch/arm/include/asm/psci.h new file +36
-0@@ -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 */ arch/arm/kernel/Makefile +1
-0@@ -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.ldsarch/arm/kernel/psci.c new file +211
-0@@ -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 <[email protected]> +*/ + +#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) +{ + asmvolatile ( + __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) +{ + asmvolatile ( + __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);Signature · 1 line
1.8.0
Re: [PATCH v3 4/6] ARM: psci: add support for PSCI invocations from the kernel
In reply to Will DeaconQuoted 5 lines · Will Deacon
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 <[email protected]>
Quoted 303 lines
--- 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.carch/arm/Kconfig +10
-0@@ -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 SMParch/arm/include/asm/psci.h new file +36
-0@@ -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 */ arch/arm/kernel/Makefile +1
-0@@ -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.ldsarch/arm/kernel/psci.c new file +211
-0@@ -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 <[email protected]> +*/ + +#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) +{ + asmvolatile ( + __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) +{ + asmvolatile ( + __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);Signature · 1 line
1.8.0
PATCH v3 4/6 ARM: psci: add support for PSCI invocations from the kernel
In reply to Will DeaconThis 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.
--- 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
arch/arm/Kconfig +10 -0
@@ -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
arch/arm/include/asm/psci.h new file +36 -0
@@ -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 */
arch/arm/kernel/Makefile +1 -0
@@ -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
arch/arm/kernel/psci.c new file +211 -0
211 lines not on this page · raw message
Signature · 1 line
1.8.0
PATCH v3 5/6 ARM: Dummy Virtual Machine platform support
In reply to Will DeaconFrom: Marc Zyngier <[email protected]>
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.
--- 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
arch/arm/Kconfig +2 -0
@@ -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"
arch/arm/Makefile +1 -0
@@ -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
arch/arm/mach-virt/Kconfig new file +9 -0
@@ -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
arch/arm/mach-virt/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +# +# Makefile for the linux kernel. +# + +obj-y := virt.o
arch/arm/mach-virt/virt.c new file +65 -0
65 lines not on this page · raw message
Signature · 1 line
1.8.0
PATCH v3 5/6 ARM: Dummy Virtual Machine platform support
Quoted 10 lines · Will Deacon
From: Marc Zyngier <[email protected]>
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 <[email protected]>Signed-off-by Will Deacon <[email protected]>
Quoted 136 lines
--- 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.carch/arm/Kconfig +2
-0@@ -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"arch/arm/Makefile +1
-0@@ -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) += sunxiarch/arm/mach-virt/Kconfig new file +9
-0@@ -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_OFarch/arm/mach-virt/Makefile new file +5
-0@@ -0,0 +1,5 @@ +# +# Makefile for the linux kernel. +# + +obj-y := virt.oarch/arm/mach-virt/virt.c new file +65
-0@@ -0,0 +1,65 @@ +/* +* Dummy Virtual Machine - does what it says on the tin. +* +* Copyright (C) 2012 ARM Ltd +* Authors: Will Deacon <[email protected]>, +* Marc Zyngier <[email protected]> +* +* 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 Signature · 1 line
1.8.0
Re: [PATCH v3 5/6] ARM: Dummy Virtual Machine platform support
In reply to Will DeaconQuoted 10 lines · Will Deacon
From: Marc Zyngier <[email protected]>
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 <[email protected]>Signed-off-by Will Deacon <[email protected]>
Quoted 136 lines
--- 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.carch/arm/Kconfig +2
-0@@ -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"arch/arm/Makefile +1
-0@@ -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) += sunxiarch/arm/mach-virt/Kconfig new file +9
-0@@ -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_OFarch/arm/mach-virt/Makefile new file +5
-0@@ -0,0 +1,5 @@ +# +# Makefile for the linux kernel. +# + +obj-y := virt.oarch/arm/mach-virt/virt.c new file +65
-0@@ -0,0 +1,65 @@ +/* +* Dummy Virtual Machine - does what it says on the tin. +* +* Copyright (C) 2012 ARM Ltd +* Authors: Will Deacon <[email protected]>, +* Marc Zyngier <[email protected]> +* +* 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 Signature · 1 line
1.8.0
PATCH v3 5/6 ARM: Dummy Virtual Machine platform support
In reply to Will DeaconFrom: Marc Zyngier <[email protected]>
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.
--- 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
arch/arm/Kconfig +2 -0
@@ -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"
arch/arm/Makefile +1 -0
@@ -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
arch/arm/mach-virt/Kconfig new file +9 -0
@@ -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
arch/arm/mach-virt/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +# +# Makefile for the linux kernel. +# + +obj-y := virt.o
arch/arm/mach-virt/virt.c new file +65 -0
65 lines not on this page · raw message
Signature · 1 line
1.8.0
PATCH v3 6/6 ARM: mach-virt: add SMP support using PSCI
In reply to Will DeaconThis patch adds support for SMP to mach-virt using the PSCI infrastructure.
--- 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
arch/arm/mach-virt/Kconfig +1 -0
@@ -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
arch/arm/mach-virt/Makefile +1 -0
@@ -3,3 +3,4 @@ # obj-y := virt.o +obj-$(CONFIG_SMP) += platsmp.o
arch/arm/mach-virt/platsmp.c new file +58 -0
58 lines not on this page · raw message
arch/arm/mach-virt/virt.c +4 -0
@@ -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
Signature · 1 line
1.8.0
PATCH v3 6/6 ARM: mach-virt: add SMP support using PSCI
Quoted 4 lines · Will Deacon
This patch adds support for SMP to mach-virt using the PSCI infrastructure.
Signed-off-by Will Deacon <[email protected]>
Quoted 122 lines
--- 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.carch/arm/mach-virt/Kconfig +1
-0@@ -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_IRQarch/arm/mach-virt/Makefile +1
-0@@ -3,3 +3,4 @@ # obj-y := virt.o +obj-$(CONFIG_SMP) += platsmp.oarch/arm/mach-virt/platsmp.c new file +58
-0@@ -0,0 +1,58 @@ +/* +* Dummy Virtual Machine - does what it says on the tin. +* +* Copyright (C) 2012 ARM Ltd +* Author: Will Deacon <[email protected]> +* +* 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, +};arch/arm/mach-virt/virt.c +4
-0@@ -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 Signature · 1 line
1.8.0
Re: [PATCH v3 6/6] ARM: mach-virt: add SMP support using PSCI
In reply to Will DeaconQuoted 4 lines · Will Deacon
This patch adds support for SMP to mach-virt using the PSCI infrastructure.
Signed-off-by Will Deacon <[email protected]>
Quoted 122 lines
--- 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.carch/arm/mach-virt/Kconfig +1
-0@@ -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_IRQarch/arm/mach-virt/Makefile +1
-0@@ -3,3 +3,4 @@ # obj-y := virt.o +obj-$(CONFIG_SMP) += platsmp.oarch/arm/mach-virt/platsmp.c new file +58
-0@@ -0,0 +1,58 @@ +/* +* Dummy Virtual Machine - does what it says on the tin. +* +* Copyright (C) 2012 ARM Ltd +* Author: Will Deacon <[email protected]> +* +* 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, +};arch/arm/mach-virt/virt.c +4
-0@@ -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 Signature · 1 line
1.8.0
PATCH v3 6/6 ARM: mach-virt: add SMP support using PSCI
In reply to Will DeaconThis patch adds support for SMP to mach-virt using the PSCI infrastructure.
--- 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
arch/arm/mach-virt/Kconfig +1 -0
@@ -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
arch/arm/mach-virt/Makefile +1 -0
@@ -3,3 +3,4 @@ # obj-y := virt.o +obj-$(CONFIG_SMP) += platsmp.o
arch/arm/mach-virt/platsmp.c new file +58 -0
58 lines not on this page · raw message
arch/arm/mach-virt/virt.c +4 -0
@@ -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
Signature · 1 line
1.8.0
v3 cover Add support for a fake, para-virtualised machine
In reply to Will DeaconQuoted 15 lines · Will Deacon
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.htmlThanks 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
Quoted 3 lines
As usual, testing this relies on KVM support for PSCI, a magic kvmtool and Mark Rutland's arch-timer patches.
Quoted 15 lines · Will Deacon
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.htmlThanks 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
Quoted 3 lines
As usual, testing this relies on KVM support for PSCI, a magic kvmtool and Mark Rutland's arch-timer patches.