SlideShare a Scribd company logo
1 of 27
Download to read offline
Linux : PSCI
2016/5/7(土)、作成
2016/11/19 (土)、追記
@Vengineer
PSCIとは
PSCIは、POWER STATE COORDINATION INTERFACE の略
ARMv8(ARM64)では、多くのSoCがPSCIをサポートしている
参考資料
"Power State Coordination Interface System Software on ARM processors"
http://infocenter.arm.com/help/topic/com.arm.doc.den0022c/
LinuxのDevice Tree Binding
https://www.kernel.org/doc/Documentation/devicetree/bindings/arm/psci.txt
cpuノードのenable-methodプロパティ
http://lxr.free-electrons.com/source/Documentation/devicetree/bindings/arm/cpus.txt
- enable-method
Value type: <stringlist>
Usage and definition depend on ARM architecture version.
# On ARM v8 64-bit this property is required and must
be one of:
"psci"
"spin-table"
- cpu-release-addr
Usage: required for systems that have an "enable-method"
property value of "spin-table".
Value type: <prop-encoded-array>
Definition:
# On ARM v8 64-bit systems must be a two cell
property identifying a 64-bit zero-initialised memory location.
psciの例 : Hisilicon 6220 (HiKey)
http://lxr.free-electrons.com/source/arch/arm64/boot/dts/hisilicon/hi6220.dt
si
cpu0: cpu@0 {
compatible = "arm,cortex-a53", "arm,armv8";
device_type = "cpu";
reg = <0x0 0x0>;
enable-method = "psci";
  };
追記)、2016.11.19
  DragonBoard 410cでも、Linaro Debian 16.09からPSCIをサポート
spin-tableの例 : APM X-Gene SoC
http://lxr.free-electrons.com/source/arch/arm64/boot/dts/apm/apm-shadowcat.d
tsi
cpu0: cpu@0 {
compatible = apm,strega", "arm,armv8";
device_type = "cpu";
reg = <0x0 0x000>;
enable-method = "spin-table";
cpu-release-addr = <0x1 0x0000fff8>;
ext-level-cache = <&xgene_L2_0>;
};
spin-tableの例 : Raspberry Pi3
h追記)、2016.11.19
  Raspberry Pi3は、Linux 4.8でサポートされたが ”spin-table”
arch/arm64/boot/dts/broadcom/bcm2837.dtsi
参考資料)、
 2016年11月号、第2章
 なるほどそうやって動くのか!リセット直後から丸はだか!
 完全理解! ラズベリー・パイの32/64ビットLinux起動シーケンス
                          原山 みや
 http://www.kumikomi.net/interface/sample/201611/if11_037.pdf
enable-methodプロパティのチェック
http://lxr.free-electrons.com/source/arch/arm64/kernel/cpu_ops.c
static const char *__init cpu_read_enable_method(int cpu) 
{
struct device_node *dn = of_get_cpu_node(cpu, NULL);
enable_method = of_get_property(dn, "enable-method", NULL);
if (!enable_method) {
/* The boot CPU may not have an enable method (e.g.
* when spin-table is used for secondaries).
* Don't warn spuriously. */
if (cpu != 0)
pr_err("%s: missing enable-method propertyn", dn->full_name);
}
}
psci
http://lxr.free-electrons.com/source/arch/arm64/kernel/psci.
c
const struct cpu_operations cpu_psci_ops = {
.name = "psci",
#ifdef CONFIG_CPU_IDLE
.cpu_init_idle = cpu_psci_cpu_init_idle,
.cpu_suspend = cpu_psci_cpu_suspend,
#endif
.cpu_init = cpu_psci_cpu_init,
.cpu_prepare = cpu_psci_cpu_prepare,
.cpu_boot = cpu_psci_cpu_boot,
#ifdef CONFIG_HOTPLUG_CPU
.cpu_disable = cpu_psci_cpu_disable,
.cpu_die = cpu_psci_cpu_die,
.cpu_kill = cpu_psci_cpu_kill,
#endif
};
サスペンドをサポート
ホットプラグをサポート
spin_table
http://lxr.free-electrons.com/source/arch/arm64/kernel/smp_spin_table.c
const strucsmp_spin_table.ct cpu_operations smp_spin_table_ops = {
.name = "spin-table",
.cpu_init = smp_spin_table_cpu_init,
.cpu_prepare = smp_spin_table_cpu_prepare,
.cpu_boot = smp_spin_table_cpu_boot,
};
サスペンドにも、ホットプラグもサポートしていない。
.cpu_init_idle = NULL,
.cpu_suspend = NULL,
.cpu_disable = NULL,
.cpu_die = NULL,
.cpu_kill = NULL,
drivers/firmware/psci.c (Linux 4.3〜
static u32 psci_get_version(void)
{
return invoke_psci_fn(PSCI_0_2_FN_PSCI_VERSION,
0, 0, 0);
}
drivers/firmware/psci.c (Linux 4.3〜
static int psci_cpu_suspend(u32 state,
unsigned long entry_point)
{
int err;
u32 fn;
fn = psci_function_id[PSCI_FN_CPU_SUSPEND];
err = invoke_psci_fn(fn, state, entry_point, 0);
return psci_to_linux_errno(err);
}
drivers/firmware/psci.c (Linux 4.3〜
static void psci_sys_reset(enum reboot_mode reboot_mode,
const char *cmd)
{
invoke_psci_fn(PSCI_0_2_FN_SYSTEM_RESET, 0, 0, 0);
}
static void psci_sys_poweroff(void)1
{
invoke_psci_fn(PSCI_0_2_FN_SYSTEM_OFF, 0, 0, 0);
}
drivers/firmware/psci.c (Linux 4.3〜
static int psci_system_suspend(unsigned long unused)
{
return invoke_psci_fn(
PSCI_FN_NATIVE(1_0,
SYSTEM_SUSPEND),
virt_to_phys(cpu_resume), 0, 0);
}
static int psci_system_suspend_enter(suspend_state_t state)
{
return cpu_suspend(0, psci_system_suspend);
}
drivers/firmware/psci.c (Linux 4.3〜
static int get_set_conduit_method(struct device_node *np)
{
if (of_property_read_string(np, "method", &method)) {
pr_warn("missing "method" propertyn");
return -ENXIO;
}
if (!strcmp("hvc", method)) {
invoke_psci_fn = __invoke_psci_fn_hvc;
} else if (!strcmp("smc", method)) {
invoke_psci_fn = __invoke_psci_fn_smc;
}
drivers/firmware/psci.c (Linux 4.3〜
static unsigned long __invoke_psci_fn_smc(
unsigned long function_id,
unsigned long arg0,
unsigned long arg1,
unsigned long arg2)
{
struct arm_smccc_res res;
arm_smccc_smc(function_id, arg0, arg1, arg2,
0, 0, 0, 0, &res);
return res.a0;
}
arch/arm64/kernel/smccc-call.S
/*
* void arm_smccc_smc(unsigned long a0, unsigned long a1,
            unsigned long a2, unsigned long a3,
unsigned long a4, unsigned long a5,
unsigned long a6, unsigned long a7,
struct arm_smccc_res *res)
*/
ENTRY(arm_smccc_smc)
SMCCC smc
ENDPROC(arm_smccc_smc)
arch/arm64/kernel/smccc-call.S
.macro SMCCC instr
.cfi_startproc
instr #0
ldr x4, [sp]
stp x0, x1, [x4, #ARM_SMCCC_RES_X0_OFFS]
stp x2, x3, [x4, #ARM_SMCCC_RES_X2_OFFS]
ret
.cfi_endproc
.endm
LinuxからATFへはどのように伝える?
http://lxr.free-electrons.com/source/arch/arm64/kernel/smccc-call.S
・SMC (Secure Monitor Call) を使う
 http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0204ij/Cjaeeged.html
/*
* void arm_smccc_smc(unsigned long a0, unsigned long a1, unsigned long a2,
* unsigned long a3, unsigned long a4, unsigned long a5,
* unsigned long a6, unsigned long a7, struct arm_smccc_res *res)
*/
ENTRY(arm_smccc_smc)
SMCCC smc /* SMCCC は、このファイル(smccc-call.S内でマクロ定義されてい
る)*/
ENDPROC(arm_smccc_smc)
EL3 Runtime Service
https://github.com/ARM-software/arm-trusted-firmware/blob/master/docs/rt-svc-writers-guide.
md
Software executing in the normal world and in the trusted world at exception levels lower
than EL3 will request runtime services using the Secure Monitor Call (SMC) instruction.
These requests will follow the convention described in the SMC Calling Convention PDD
(SMCCC). The SMCCC assigns function identifiers to each SMC request and describes how
arguments are passed and results are returned.
 ・Standard Service calls => 標準サービスの提供 ( PSCI )
 ・SiP Service calls => 各社独自サービス用
Standard Service calls
https://github.com/ARM-software/arm-trusted-firmware/blob/master/services/std_svc/std_svc_s
etup.c
/* Register Standard Service Calls as runtime service */
DECLARE_RT_SVC(
std_svc,
OEN_STD_START,
OEN_STD_END,
SMC_TYPE_FAST,
std_svc_setup,
std_svc_smc_handler
);
std_svc_smc_handler
https://github.com/ARM-software/arm-trusted-firmware/blob/master/services/std_svc/std_svc_s
etup.c
/* Top-level Standard Service SMC handler. This handler will in turn dispatch calls to PSCI SMC handler */
uint64_t std_svc_smc_handler(uint32_t smc_fid, uint64_t x1, uint64_t x2, uint64_t x3, uint64_t x4,
void *cookie, void *handle, uint64_t flags)
{
/* Dispatch PSCI calls to PSCI SMC handler and return its return value */
if (is_psci_fid(smc_fid)) {
return psci_smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle, flags);
}
psci_smc_handler
https://github.com/ARM-software/arm-trusted-firmware/blob/master/services/std_svc/psci/psci
_main.c
uint64_t psci_smc_handler(uint32_t smc_fid, uint64_t x1, uint64_t x2, uint64_t x3, uint64_t x4,
void *cookie, void *handle, uint64_t flags)
switch (smc_fid) {
case PSCI_CPU_SUSPEND_AARCH64: SMC_RET1(handle, psci_cpu_suspend(x1, x2, x3));
case PSCI_CPU_ON_AARCH64: SMC_RET1(handle, psci_cpu_on(x1, x2, x3));
case PSCI_AFFINITY_INFO_AARCH64: SMC_RET1(handle, psci_affinity_info(x1, x2));
case PSCI_MIG_AARCH64: SMC_RET1(handle, psci_migrate(x1));
case PSCI_MIG_INFO_UP_CPU_AARCH64:SMC_RET1(handle, psci_migrate_info_up_cpu());
case PSCI_SYSTEM_SUSPEND_AARCH64: SMC_RET1(handle, psci_system_suspend(x1, x2));
default:break;
}
Power Off / Reboot / System Suspend
User Landから
 ・Power Off
 ・Reboot
 ・System Suspend
を実行した場合、どのような関数を経由して、
PSCIにアクセスするのか?
System Halt (Power Off)
SYSCALL_DEFINE4(reboot, kernel/reboot.c
kernel_restart kernel/reboot.c
machine_restart arch/arm64/kernel/process.c
arm_pm_restart arch/arm64/kernel/process.c
psci_sys_reset drivers/firmware/psci.c
invoke_psci_fn drivers/firmware/psci.c
__invoke_psci_fn_smc drivers/firmware/psci.c
arm_smccc_smc include/linux/arm-smccc.h
System Reboot (System Reset)
SYSCALL_DEFINE4(reboot, kernel/reboot.c
kernel_power_off kernel/reboot.c
machine_power_off arch/arm64/kernel/process.c
pm_power_off arch/arm64/kernel/process.c
psci_sys_poweroff drivers/firmware/psci.c
invoke_psci_fn drivers/firmware/psci.c
__invoke_psci_fn_smc drivers/firmware/psci.c
arm_smccc_smc include/linux/arm-smccc.h
System Suspend
pm_suspend kernel/power/suspend.c
enter_state kernel/power/suspend.c
suspend_devices_and_enter kernel/power/suspend.c
suspend_enter kernel/power/suspend.c
psci_system_suspend_enter drivers/firmware/psci.c
psci_system_suspend drivers/firmware/psci.c
invoke_psci_fn drivers/firmware/psci.c
__invoke_psci_fn_smc drivers/firmware/psci.c
arm_smccc_smc include/linux/arm-smccc.h
おしまい

More Related Content

What's hot

U boot porting guide for SoC
U boot porting guide for SoCU boot porting guide for SoC
U boot porting guide for SoC
Macpaul Lin
 
OSC2011 Tokyo/Fall 濃いバナ(virtio)
OSC2011 Tokyo/Fall 濃いバナ(virtio)OSC2011 Tokyo/Fall 濃いバナ(virtio)
OSC2011 Tokyo/Fall 濃いバナ(virtio)
Takeshi HASEGAWA
 
Embedded_Linux_Booting
Embedded_Linux_BootingEmbedded_Linux_Booting
Embedded_Linux_Booting
Rashila Rr
 

What's hot (20)

Introduction to Modern U-Boot
Introduction to Modern U-BootIntroduction to Modern U-Boot
Introduction to Modern U-Boot
 
U boot porting guide for SoC
U boot porting guide for SoCU boot porting guide for SoC
U boot porting guide for SoC
 
BPF Internals (eBPF)
BPF Internals (eBPF)BPF Internals (eBPF)
BPF Internals (eBPF)
 
Reverse Mapping (rmap) in Linux Kernel
Reverse Mapping (rmap) in Linux KernelReverse Mapping (rmap) in Linux Kernel
Reverse Mapping (rmap) in Linux Kernel
 
Jagan Teki - U-boot from scratch
Jagan Teki - U-boot from scratchJagan Teki - U-boot from scratch
Jagan Teki - U-boot from scratch
 
U-Boot presentation 2013
U-Boot presentation  2013U-Boot presentation  2013
U-Boot presentation 2013
 
qemu + gdb: The efficient way to understand/debug Linux kernel code/data stru...
qemu + gdb: The efficient way to understand/debug Linux kernel code/data stru...qemu + gdb: The efficient way to understand/debug Linux kernel code/data stru...
qemu + gdb: The efficient way to understand/debug Linux kernel code/data stru...
 
Learn C Programming Language by Using GDB
Learn C Programming Language by Using GDBLearn C Programming Language by Using GDB
Learn C Programming Language by Using GDB
 
Static partitioning virtualization on RISC-V
Static partitioning virtualization on RISC-VStatic partitioning virtualization on RISC-V
Static partitioning virtualization on RISC-V
 
OSC2011 Tokyo/Fall 濃いバナ(virtio)
OSC2011 Tokyo/Fall 濃いバナ(virtio)OSC2011 Tokyo/Fall 濃いバナ(virtio)
OSC2011 Tokyo/Fall 濃いバナ(virtio)
 
QEMU - Binary Translation
QEMU - Binary Translation QEMU - Binary Translation
QEMU - Binary Translation
 
Zynq VIPを利用したテストベンチ
Zynq VIPを利用したテストベンチZynq VIPを利用したテストベンチ
Zynq VIPを利用したテストベンチ
 
ARM LinuxのMMUはわかりにくい
ARM LinuxのMMUはわかりにくいARM LinuxのMMUはわかりにくい
ARM LinuxのMMUはわかりにくい
 
Kernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven Rostedt
Kernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven RostedtKernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven Rostedt
Kernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven Rostedt
 
淺談探索 Linux 系統設計之道
淺談探索 Linux 系統設計之道 淺談探索 Linux 系統設計之道
淺談探索 Linux 系統設計之道
 
linux device driver
linux device driverlinux device driver
linux device driver
 
Embedded_Linux_Booting
Embedded_Linux_BootingEmbedded_Linux_Booting
Embedded_Linux_Booting
 
Linux Porting
Linux PortingLinux Porting
Linux Porting
 
initramfsについて
initramfsについてinitramfsについて
initramfsについて
 
Virtual Machine Constructions for Dummies
Virtual Machine Constructions for DummiesVirtual Machine Constructions for Dummies
Virtual Machine Constructions for Dummies
 

Similar to Linux : PSCI

HKG15-505: Power Management interactions with OP-TEE and Trusted Firmware
HKG15-505: Power Management interactions with OP-TEE and Trusted FirmwareHKG15-505: Power Management interactions with OP-TEE and Trusted Firmware
HKG15-505: Power Management interactions with OP-TEE and Trusted Firmware
Linaro
 
Unit 1
Unit 1Unit 1
Unit 1
siddr
 
Information Gathering 2
Information Gathering 2Information Gathering 2
Information Gathering 2
Aero Plane
 
Unit 2
Unit 2Unit 2
Unit 2
siddr
 

Similar to Linux : PSCI (20)

HKG15-505: Power Management interactions with OP-TEE and Trusted Firmware
HKG15-505: Power Management interactions with OP-TEE and Trusted FirmwareHKG15-505: Power Management interactions with OP-TEE and Trusted Firmware
HKG15-505: Power Management interactions with OP-TEE and Trusted Firmware
 
HKG15-505: Power Management interactions with OP-TEE and Trusted Firmware
HKG15-505: Power Management interactions with OP-TEE and Trusted FirmwareHKG15-505: Power Management interactions with OP-TEE and Trusted Firmware
HKG15-505: Power Management interactions with OP-TEE and Trusted Firmware
 
Unit 1
Unit 1Unit 1
Unit 1
 
Backtrack Manual Part6
Backtrack Manual Part6Backtrack Manual Part6
Backtrack Manual Part6
 
Information Gathering 2
Information Gathering 2Information Gathering 2
Information Gathering 2
 
LINUX Device Drivers
LINUX Device DriversLINUX Device Drivers
LINUX Device Drivers
 
LCA13: Power State Coordination Interface
LCA13: Power State Coordination InterfaceLCA13: Power State Coordination Interface
LCA13: Power State Coordination Interface
 
Raspberry Pi tutorial
Raspberry Pi tutorialRaspberry Pi tutorial
Raspberry Pi tutorial
 
Genode Compositions
Genode CompositionsGenode Compositions
Genode Compositions
 
Hunting Mac Malware with Memory Forensics
Hunting Mac Malware with Memory ForensicsHunting Mac Malware with Memory Forensics
Hunting Mac Malware with Memory Forensics
 
Hunting Mac Malware with Memory Forensics
Hunting Mac Malware with Memory ForensicsHunting Mac Malware with Memory Forensics
Hunting Mac Malware with Memory Forensics
 
CCA security answers chapter 2 test
CCA security answers chapter 2 testCCA security answers chapter 2 test
CCA security answers chapter 2 test
 
Unit 2
Unit 2Unit 2
Unit 2
 
Is your code ready for PHP 7 ?
Is your code ready for PHP 7 ?Is your code ready for PHP 7 ?
Is your code ready for PHP 7 ?
 
Developing a Windows CE OAL.ppt
Developing a Windows CE OAL.pptDeveloping a Windows CE OAL.ppt
Developing a Windows CE OAL.ppt
 
LCU13: An Introduction to ARM Trusted Firmware
LCU13: An Introduction to ARM Trusted FirmwareLCU13: An Introduction to ARM Trusted Firmware
LCU13: An Introduction to ARM Trusted Firmware
 
Efficient System Monitoring in Cloud Native Environments
Efficient System Monitoring in Cloud Native EnvironmentsEfficient System Monitoring in Cloud Native Environments
Efficient System Monitoring in Cloud Native Environments
 
LCA13: ARMv8 Status and Updates
LCA13: ARMv8 Status and UpdatesLCA13: ARMv8 Status and Updates
LCA13: ARMv8 Status and Updates
 
Code Red Security
Code Red SecurityCode Red Security
Code Red Security
 
PhD Slides
PhD SlidesPhD Slides
PhD Slides
 

More from Mr. Vengineer

More from Mr. Vengineer (20)

XilinxのxsimでSoftware Driven Verification.pdf
XilinxのxsimでSoftware  Driven Verification.pdfXilinxのxsimでSoftware  Driven Verification.pdf
XilinxのxsimでSoftware Driven Verification.pdf
 
VerilatorとSystemCでSoftware Driven Verification
VerilatorとSystemCでSoftware Driven VerificationVerilatorとSystemCでSoftware Driven Verification
VerilatorとSystemCでSoftware Driven Verification
 
VerilatorとSystemC
VerilatorとSystemCVerilatorとSystemC
VerilatorとSystemC
 
TVM VTA (TSIM)
TVM VTA (TSIM) TVM VTA (TSIM)
TVM VTA (TSIM)
 
Cloud TPU Driver API ソースコード解析
Cloud TPU Driver API ソースコード解析Cloud TPU Driver API ソースコード解析
Cloud TPU Driver API ソースコード解析
 
Cloud Deep Learning Chips Training & Inference
Cloud Deep Learning Chips Training & InferenceCloud Deep Learning Chips Training & Inference
Cloud Deep Learning Chips Training & Inference
 
TensorFlow Lite Delegateとは?
TensorFlow Lite Delegateとは?TensorFlow Lite Delegateとは?
TensorFlow Lite Delegateとは?
 
Pixel Visual Core device driver source code analysis
Pixel Visual Core device driver source code analysisPixel Visual Core device driver source code analysis
Pixel Visual Core device driver source code analysis
 
Google Edge TPUで TensorFlow Liteを使った時に 何をやっているのかを妄想してみる 2 「エッジAIモダン計測制御の世界」オ...
Google Edge TPUで TensorFlow Liteを使った時に 何をやっているのかを妄想してみる 2  「エッジAIモダン計測制御の世界」オ...Google Edge TPUで TensorFlow Liteを使った時に 何をやっているのかを妄想してみる 2  「エッジAIモダン計測制御の世界」オ...
Google Edge TPUで TensorFlow Liteを使った時に 何をやっているのかを妄想してみる 2 「エッジAIモダン計測制御の世界」オ...
 
TensorFlow XLA 「XLAとは、から、最近の利用事例について」
TensorFlow XLA 「XLAとは、から、最近の利用事例について」TensorFlow XLA 「XLAとは、から、最近の利用事例について」
TensorFlow XLA 「XLAとは、から、最近の利用事例について」
 
Facebook Glow Compiler のソースコードをグダグダ語る会
Facebook Glow Compiler のソースコードをグダグダ語る会Facebook Glow Compiler のソースコードをグダグダ語る会
Facebook Glow Compiler のソースコードをグダグダ語る会
 
Ultra96(UltraZed)実践勉強会
Ultra96(UltraZed)実践勉強会Ultra96(UltraZed)実践勉強会
Ultra96(UltraZed)実践勉強会
 
Bridge TensorFlow to run on Intel nGraph backends (v0.4)
Bridge TensorFlow to run on Intel nGraph backends (v0.4)Bridge TensorFlow to run on Intel nGraph backends (v0.4)
Bridge TensorFlow to run on Intel nGraph backends (v0.4)
 
Bridge TensorFlow to run on Intel nGraph backends (v0.5)
Bridge TensorFlow to run on Intel nGraph backends (v0.5)Bridge TensorFlow to run on Intel nGraph backends (v0.5)
Bridge TensorFlow to run on Intel nGraph backends (v0.5)
 
TensorFlow XLA RPC
TensorFlow XLA RPCTensorFlow XLA RPC
TensorFlow XLA RPC
 
TensorFlow local Python XLA client
TensorFlow local Python XLA clientTensorFlow local Python XLA client
TensorFlow local Python XLA client
 
Tiramisu をちょっと、味見してみました。
Tiramisu をちょっと、味見してみました。Tiramisu をちょっと、味見してみました。
Tiramisu をちょっと、味見してみました。
 
LeFlowを調べてみました
LeFlowを調べてみましたLeFlowを調べてみました
LeFlowを調べてみました
 
Tensorflow dynamically loadable XLA plugin ソースコード解析
Tensorflow  dynamically loadable XLA plugin ソースコード解析Tensorflow  dynamically loadable XLA plugin ソースコード解析
Tensorflow dynamically loadable XLA plugin ソースコード解析
 
Tiramisu概要
Tiramisu概要Tiramisu概要
Tiramisu概要
 

Recently uploaded

Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 

Recently uploaded (20)

%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 

Linux : PSCI

  • 2. PSCIとは PSCIは、POWER STATE COORDINATION INTERFACE の略 ARMv8(ARM64)では、多くのSoCがPSCIをサポートしている 参考資料 "Power State Coordination Interface System Software on ARM processors" http://infocenter.arm.com/help/topic/com.arm.doc.den0022c/ LinuxのDevice Tree Binding https://www.kernel.org/doc/Documentation/devicetree/bindings/arm/psci.txt
  • 3. cpuノードのenable-methodプロパティ http://lxr.free-electrons.com/source/Documentation/devicetree/bindings/arm/cpus.txt - enable-method Value type: <stringlist> Usage and definition depend on ARM architecture version. # On ARM v8 64-bit this property is required and must be one of: "psci" "spin-table" - cpu-release-addr Usage: required for systems that have an "enable-method" property value of "spin-table". Value type: <prop-encoded-array> Definition: # On ARM v8 64-bit systems must be a two cell property identifying a 64-bit zero-initialised memory location.
  • 4. psciの例 : Hisilicon 6220 (HiKey) http://lxr.free-electrons.com/source/arch/arm64/boot/dts/hisilicon/hi6220.dt si cpu0: cpu@0 { compatible = "arm,cortex-a53", "arm,armv8"; device_type = "cpu"; reg = <0x0 0x0>; enable-method = "psci";   }; 追記)、2016.11.19   DragonBoard 410cでも、Linaro Debian 16.09からPSCIをサポート
  • 5. spin-tableの例 : APM X-Gene SoC http://lxr.free-electrons.com/source/arch/arm64/boot/dts/apm/apm-shadowcat.d tsi cpu0: cpu@0 { compatible = apm,strega", "arm,armv8"; device_type = "cpu"; reg = <0x0 0x000>; enable-method = "spin-table"; cpu-release-addr = <0x1 0x0000fff8>; ext-level-cache = <&xgene_L2_0>; };
  • 6. spin-tableの例 : Raspberry Pi3 h追記)、2016.11.19   Raspberry Pi3は、Linux 4.8でサポートされたが ”spin-table” arch/arm64/boot/dts/broadcom/bcm2837.dtsi 参考資料)、  2016年11月号、第2章  なるほどそうやって動くのか!リセット直後から丸はだか!  完全理解! ラズベリー・パイの32/64ビットLinux起動シーケンス                           原山 みや  http://www.kumikomi.net/interface/sample/201611/if11_037.pdf
  • 7. enable-methodプロパティのチェック http://lxr.free-electrons.com/source/arch/arm64/kernel/cpu_ops.c static const char *__init cpu_read_enable_method(int cpu)  { struct device_node *dn = of_get_cpu_node(cpu, NULL); enable_method = of_get_property(dn, "enable-method", NULL); if (!enable_method) { /* The boot CPU may not have an enable method (e.g. * when spin-table is used for secondaries). * Don't warn spuriously. */ if (cpu != 0) pr_err("%s: missing enable-method propertyn", dn->full_name); } }
  • 8. psci http://lxr.free-electrons.com/source/arch/arm64/kernel/psci. c const struct cpu_operations cpu_psci_ops = { .name = "psci", #ifdef CONFIG_CPU_IDLE .cpu_init_idle = cpu_psci_cpu_init_idle, .cpu_suspend = cpu_psci_cpu_suspend, #endif .cpu_init = cpu_psci_cpu_init, .cpu_prepare = cpu_psci_cpu_prepare, .cpu_boot = cpu_psci_cpu_boot, #ifdef CONFIG_HOTPLUG_CPU .cpu_disable = cpu_psci_cpu_disable, .cpu_die = cpu_psci_cpu_die, .cpu_kill = cpu_psci_cpu_kill, #endif }; サスペンドをサポート ホットプラグをサポート
  • 9. spin_table http://lxr.free-electrons.com/source/arch/arm64/kernel/smp_spin_table.c const strucsmp_spin_table.ct cpu_operations smp_spin_table_ops = { .name = "spin-table", .cpu_init = smp_spin_table_cpu_init, .cpu_prepare = smp_spin_table_cpu_prepare, .cpu_boot = smp_spin_table_cpu_boot, }; サスペンドにも、ホットプラグもサポートしていない。 .cpu_init_idle = NULL, .cpu_suspend = NULL, .cpu_disable = NULL, .cpu_die = NULL, .cpu_kill = NULL,
  • 10. drivers/firmware/psci.c (Linux 4.3〜 static u32 psci_get_version(void) { return invoke_psci_fn(PSCI_0_2_FN_PSCI_VERSION, 0, 0, 0); }
  • 11. drivers/firmware/psci.c (Linux 4.3〜 static int psci_cpu_suspend(u32 state, unsigned long entry_point) { int err; u32 fn; fn = psci_function_id[PSCI_FN_CPU_SUSPEND]; err = invoke_psci_fn(fn, state, entry_point, 0); return psci_to_linux_errno(err); }
  • 12. drivers/firmware/psci.c (Linux 4.3〜 static void psci_sys_reset(enum reboot_mode reboot_mode, const char *cmd) { invoke_psci_fn(PSCI_0_2_FN_SYSTEM_RESET, 0, 0, 0); } static void psci_sys_poweroff(void)1 { invoke_psci_fn(PSCI_0_2_FN_SYSTEM_OFF, 0, 0, 0); }
  • 13. drivers/firmware/psci.c (Linux 4.3〜 static int psci_system_suspend(unsigned long unused) { return invoke_psci_fn( PSCI_FN_NATIVE(1_0, SYSTEM_SUSPEND), virt_to_phys(cpu_resume), 0, 0); } static int psci_system_suspend_enter(suspend_state_t state) { return cpu_suspend(0, psci_system_suspend); }
  • 14. drivers/firmware/psci.c (Linux 4.3〜 static int get_set_conduit_method(struct device_node *np) { if (of_property_read_string(np, "method", &method)) { pr_warn("missing "method" propertyn"); return -ENXIO; } if (!strcmp("hvc", method)) { invoke_psci_fn = __invoke_psci_fn_hvc; } else if (!strcmp("smc", method)) { invoke_psci_fn = __invoke_psci_fn_smc; }
  • 15. drivers/firmware/psci.c (Linux 4.3〜 static unsigned long __invoke_psci_fn_smc( unsigned long function_id, unsigned long arg0, unsigned long arg1, unsigned long arg2) { struct arm_smccc_res res; arm_smccc_smc(function_id, arg0, arg1, arg2, 0, 0, 0, 0, &res); return res.a0; }
  • 16. arch/arm64/kernel/smccc-call.S /* * void arm_smccc_smc(unsigned long a0, unsigned long a1,             unsigned long a2, unsigned long a3, unsigned long a4, unsigned long a5, unsigned long a6, unsigned long a7, struct arm_smccc_res *res) */ ENTRY(arm_smccc_smc) SMCCC smc ENDPROC(arm_smccc_smc)
  • 17. arch/arm64/kernel/smccc-call.S .macro SMCCC instr .cfi_startproc instr #0 ldr x4, [sp] stp x0, x1, [x4, #ARM_SMCCC_RES_X0_OFFS] stp x2, x3, [x4, #ARM_SMCCC_RES_X2_OFFS] ret .cfi_endproc .endm
  • 18. LinuxからATFへはどのように伝える? http://lxr.free-electrons.com/source/arch/arm64/kernel/smccc-call.S ・SMC (Secure Monitor Call) を使う  http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0204ij/Cjaeeged.html /* * void arm_smccc_smc(unsigned long a0, unsigned long a1, unsigned long a2, * unsigned long a3, unsigned long a4, unsigned long a5, * unsigned long a6, unsigned long a7, struct arm_smccc_res *res) */ ENTRY(arm_smccc_smc) SMCCC smc /* SMCCC は、このファイル(smccc-call.S内でマクロ定義されてい る)*/ ENDPROC(arm_smccc_smc)
  • 19. EL3 Runtime Service https://github.com/ARM-software/arm-trusted-firmware/blob/master/docs/rt-svc-writers-guide. md Software executing in the normal world and in the trusted world at exception levels lower than EL3 will request runtime services using the Secure Monitor Call (SMC) instruction. These requests will follow the convention described in the SMC Calling Convention PDD (SMCCC). The SMCCC assigns function identifiers to each SMC request and describes how arguments are passed and results are returned.  ・Standard Service calls => 標準サービスの提供 ( PSCI )  ・SiP Service calls => 各社独自サービス用
  • 20. Standard Service calls https://github.com/ARM-software/arm-trusted-firmware/blob/master/services/std_svc/std_svc_s etup.c /* Register Standard Service Calls as runtime service */ DECLARE_RT_SVC( std_svc, OEN_STD_START, OEN_STD_END, SMC_TYPE_FAST, std_svc_setup, std_svc_smc_handler );
  • 21. std_svc_smc_handler https://github.com/ARM-software/arm-trusted-firmware/blob/master/services/std_svc/std_svc_s etup.c /* Top-level Standard Service SMC handler. This handler will in turn dispatch calls to PSCI SMC handler */ uint64_t std_svc_smc_handler(uint32_t smc_fid, uint64_t x1, uint64_t x2, uint64_t x3, uint64_t x4, void *cookie, void *handle, uint64_t flags) { /* Dispatch PSCI calls to PSCI SMC handler and return its return value */ if (is_psci_fid(smc_fid)) { return psci_smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle, flags); }
  • 22. psci_smc_handler https://github.com/ARM-software/arm-trusted-firmware/blob/master/services/std_svc/psci/psci _main.c uint64_t psci_smc_handler(uint32_t smc_fid, uint64_t x1, uint64_t x2, uint64_t x3, uint64_t x4, void *cookie, void *handle, uint64_t flags) switch (smc_fid) { case PSCI_CPU_SUSPEND_AARCH64: SMC_RET1(handle, psci_cpu_suspend(x1, x2, x3)); case PSCI_CPU_ON_AARCH64: SMC_RET1(handle, psci_cpu_on(x1, x2, x3)); case PSCI_AFFINITY_INFO_AARCH64: SMC_RET1(handle, psci_affinity_info(x1, x2)); case PSCI_MIG_AARCH64: SMC_RET1(handle, psci_migrate(x1)); case PSCI_MIG_INFO_UP_CPU_AARCH64:SMC_RET1(handle, psci_migrate_info_up_cpu()); case PSCI_SYSTEM_SUSPEND_AARCH64: SMC_RET1(handle, psci_system_suspend(x1, x2)); default:break; }
  • 23. Power Off / Reboot / System Suspend User Landから  ・Power Off  ・Reboot  ・System Suspend を実行した場合、どのような関数を経由して、 PSCIにアクセスするのか?
  • 24. System Halt (Power Off) SYSCALL_DEFINE4(reboot, kernel/reboot.c kernel_restart kernel/reboot.c machine_restart arch/arm64/kernel/process.c arm_pm_restart arch/arm64/kernel/process.c psci_sys_reset drivers/firmware/psci.c invoke_psci_fn drivers/firmware/psci.c __invoke_psci_fn_smc drivers/firmware/psci.c arm_smccc_smc include/linux/arm-smccc.h
  • 25. System Reboot (System Reset) SYSCALL_DEFINE4(reboot, kernel/reboot.c kernel_power_off kernel/reboot.c machine_power_off arch/arm64/kernel/process.c pm_power_off arch/arm64/kernel/process.c psci_sys_poweroff drivers/firmware/psci.c invoke_psci_fn drivers/firmware/psci.c __invoke_psci_fn_smc drivers/firmware/psci.c arm_smccc_smc include/linux/arm-smccc.h
  • 26. System Suspend pm_suspend kernel/power/suspend.c enter_state kernel/power/suspend.c suspend_devices_and_enter kernel/power/suspend.c suspend_enter kernel/power/suspend.c psci_system_suspend_enter drivers/firmware/psci.c psci_system_suspend drivers/firmware/psci.c invoke_psci_fn drivers/firmware/psci.c __invoke_psci_fn_smc drivers/firmware/psci.c arm_smccc_smc include/linux/arm-smccc.h