76
ZynqMPのブートとパワーマネージメント @Vengineer ZynqMP勉強会資料 (2016/2/20) 追記) 2016.05.08 P.44に、公式ARM Trusted Firmwareのサイトに、Zynq UltraScale+ MPSoCの実装が追加されていること

ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

Embed Size (px)

Citation preview

Page 1: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

ZynqMPのブートとパワーマネージメント

@Vengineer

ZynqMP勉強会資料 (2016/2/20)

追記) 2016.05.08P.44に、公式ARM Trusted Firmwareのサイトに、Zynq UltraScale+ MPSoCの実装が追加されていること

Page 2: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

自己紹介

Twitter ID :@Vengineer 2009年〜

Blog   :@Vengineerの戯言 2007年〜

http://blogs.yahoo.co.jp/verification_engineer

:昭和の時代(1987年)〜 C++を書いているプログラマ

AT&T C++ Translator => Zortech C++ … GCC/Intel/LLVM

:「SystemVerilog設計スタートアップ(2008年)」の中の人のひとり

http://www.cqpub.co.jp/hanbai/books/36/36191.htm

Page 3: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

ZynqMP:参考資料

1)、Zynq UltraScale+ MPSoC Technical Reference Manual,

  UG1085 (v1.0) November 24, 2015

2)、Zynq UltraScale+ MPSoC Software Developers Guide,

  UG1137 (v1.0) November 18, 2015

3)、Xilinx Github : https://github.com/xilinx

4)、Xilinx Wiki : http://www.wiki.xilinx.com/

5)、QEMU User Guide, UG1169 (v1.0) November 18, 2015

Page 4: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

ZynqMPの特徴

参考文献1)、P.11

• Scalable PS with scaling for power and performance• Low-power running mode and sleep mode• Flexible user-programmable power and performance scaling• Advanced configure system with device and user-security support• Extended connectivity support including PCIe®, SATA, and USB 3.0• Advanced user interface(s) with GPU and DisplayPort in the PS• Increased DRAM and PS-PL bandwidth• Improved memory traffic QoS• Improved safety and reliability

Page 5: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

XilinxのZynqMPの公式コース

・Zynq UltraScale+MPSoC-System Architecthttp://www.fastertechnology.com/training/training-courses/xilinx-fpga-training-zynq-ultrascale-mpsoc-system-architect/

・Zynq UltraScale+MPSoC-Software Designer

http://www.fastertechnology.com/training/training-courses/xilinx-fpga-training-zynq-ultrascale-mpsoc-system-architect-copy-1/

ともに、2日コース。お一人様、1200ドル。

Page 6: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

コンピュータとしてのZynqMP

Page 7: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

一般的なARMv8なコンピュータ

CCI-400

DRAMC

128b128b

bigx4

128b

128bACE128b

128b

PCIe

SATA

LITTLEx4

ACE128b

GPU

128b

Page 8: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

ARMv8コンピュータとしてのZynqMP

128b 128b

ACE128b

128b

GPU

PCIe

SATA

CentralSwitch

CCI-400

DDRC

128b

A53x4

Page 9: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

ヘテロなコンピュータとしてのZynqMP

CCI-400

DDRC

128bLPS

Low Power Switch128b

128b

A53x4

128b

ACE128b

128b

GPU

PCIe

SATA

R5 R5

CentralSwitch

64b

Page 10: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

FPGAとしてのZynqMP

参考文献2)、P.139

CCI-400

DDRC

128bLPS

Low Power Switch128b

128b

64b

A53x4

128b

128b

ACE128b

PL

ACE128b

128b

GPU

PCIe

SATA

PL

ACE HPC HPC

HP

R5 R5

CentralSwitch

Page 11: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

ブート

Page 12: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

おさらい : ZynqでのLinuxブートシーケンス

・A9で内部ROMが起動

・内部ROMがストレージからFSBLをロードし、A9でFSBLを起動

・FSBLがストレージからU-BootをDRAMにロードし、A9でU-Bootを起動

・U-BootがストレージからLinuxをDRAMにロードし、A9でLinuxを起動

すべてのプログラムは、ARM Cortex-A9が実行する

Page 13: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

Zynqについて、詳しく知りたい人は

@marsee101さんのブログ、

FPGAの部屋の以下のまとめを!

Zynq : http://marsee101.web.fc2.com/zynq.html

Zedboard : http://marsee101.web.fc2.com/zedboard.html

Zybo : http://marsee101.web.fc2.com/zybo.html

Page 14: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

ZynqMPでのLinuxブートシーケンス

・内部ROMが起動、

・内部ROMがストレージからFSBLをロードし、FSBLを起動

・FSBLがストレージからATF(bl31)をDRAMにロードし、ATF(bl31)を起動

・FSBLがストレージからU-BootをDRAMにロードし、U-Bootを起動

・U-BootがストレージからLinuxをDRAMにロードし、Linuxを起動

各プログラムは、どのコアが実行する?

Page 15: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

内部ROMはどのコアが実行する?

・CPU: ARM Cortex-A53x4

・CPU: ARM Cortex-R5

・GPU: ARM Mali-T400MP2

Page 16: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

PMU : Platform Management Unit

参考文献1)、Chapter 6

The platform management unit (PMU) controls the power-up, reset, and monitoring of resources within the entire system. Earlier power management mechanisms were implemented using hardware state machines. Modern MPSoCs include a dedicated centralized and user-programmable processor for power management to reduce risk and increase scalability. The Zynq® UltraScale+™ MPSoC PMU performs the following set of tasks.

  • Initialization of the system during boot.  • Management of power gating.

Page 17: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

PMUはどこに居る?

参考文献2)、P.139

CCI-400

DDRC

128bLPS

Low Power Switch128b

128b

64b

A53x4

128b

128b

ACE128b

PL

ACE128b

128b

GPU

PCIe

SATA

PL

ACE HPC HPC

HP

R5 R5

PMU

Page 18: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

PMUって何だ?

参考文献1)、PMU System-level View, Page.89-90, Figure 6-1

  • Dedicated, fault-tolerant triple-redundant processor.

  • ROM to hold PMU ROM code that includes the PMU startup sequence, routines to handle power-up or down requests, and interrupts.

 • 128 KB RAM with ECC used as the storage for data and also the optional user/firmware code.

どうやら、PMU Processorというものがある。

Page 19: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

PMU Processorの実態は?

参考資料3)、embeddedsw/tree/master/lib/sw_apps/zynqmp_pmufw/data/zynqmp_pmufw.tcl

proc swapp_is_supported_hw {} {if {($proc_type != "psu_microblaze")} {

error "This application is supported only for PMU Microblaze processor (psu_microblaze).";

}}

   どうやら、Microblazeのようだ!

Page 20: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

で、ブートシーケンスは?

参考文献2)、Chapter 7、Page.73、Detailed Boot Flow

1. Determines the boot mode by reading the boot mode register, which captures the boot-mode pin strapping at the POR. 2. Initializes the OCM. 3. Reads the boot header.  <= ブートデバイスにアクセスする4. If the FSBL in the boot image is authenticated, the SHA engine checks for its authentication. If the FSBL passes the authentication test, the configuration unit checks if the FSBL is encrypted. In case the FSBL is encrypted, AES-GCM engine decrypts the FSBL and configuration unit loads it into the OCM of either APU or RPU and FSBL handoff to APU/RPU software.

Page 21: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

ブートできるデバイスは?

参考文献2)、Chapter 7、System Boot and Configuration

 ・JTAG

 ・QSPI flash

 ・NAND flash drive

 ・SD card (SD/eMMC) <= U-Boot/Linuxはここ!

Mode Pins(4ピン)によって指定できる

Page 22: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

FSBLは何をする?

参考文献2)、Chapter 7、Page.73、Detailed Boot Flow

・Load FSBL to OCM

・FSBL configures the PS・FSBL configures the PL with the bitstream

・FSBL loads the RPU software・FSBL loads ths AP software

・FSBL handoff to AP software

Page 23: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

FSBL

参考文献3)、embeddedsw/lib/sw_apps/zynqmp_fsbl/ data/zynqmp_fsbl.tcl

proc swapp_get_description {} { return "First Stage Bootloader (FSBL) for Zynq Ultrascale+ MPSoC. The FSBL configures the FPGA with HW bit stream (if it exists) \

and loads the Operating System (OS) Image or Standalone (SA) Image or 2nd Stage Boot Loader image from the \non-volatile memory (NAND/SD/QSPI) to RAM (DDR) and takes A53/R5 out of reset. It supports multiple partitions, \and each partition can be a code image or a bit stream.";

}

proc swapp_get_supported_processors {} {

return "psu_cortexa53 psu_cortexr5";}

# based on the CPU (A53 64-bit, A53 32-bit or R5),

Page 24: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

Boot Image Creation

参考資料2)、P.68、 Boot Image Creation

下記のプログラム等をboot image format (BIF) fileに記述し、

Bootgen tool を使って、 boot.bin を生成する

 ・FSBL ELF

 ・Cortex-R5 and/or Cortex-A53 application ELF <= U-Bootはここに!

 ・Authentication and encryption key (Option)

なお、Kernel Image/Device Tree Blob/RootFSは、Petalinux SDKにて生成する

Page 25: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

MPSoC Non Secure Boot

参考文献4)、MPSoC+Non+Secure+Boot

The purpose of this page is to describe booting of QEMU in Non-Secure mode using the following boot devices:

- QSPI24- NAND- SD

各種デバイスに対するブートイメージを作成し、QEMUで動作確認しています。

Secure Bootに関しては、まだ書かれていないようです。

Page 26: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

ZynqMPでのLinuxブートシーケンス

参考資料2)、P.71、 Boot Image Creation、SD Mode

・PMUの内部ROMが起動、

・内部ROMがストレージからFSBLをロードし、A53でFSBLを起動

・FSBLがストレージからATF(bl31)をDRAMにロードし、A53でATF(bl31)を起動

・FSBLがストレージからU-BootをDRAMにロードし、A53でU-Bootを起動

・U-BootがストレージからLinuxをDRAMにロードし、A53でLinuxを起動

SDカードのFAT32に、boot.bin/Kernel Image/Device Tree Blobを

EXT3 file systemに、RootFSをストアしておく。

Page 27: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

Arm64のLinuxのブートプロセス

参考資料)3、linux-xlnx/tree/master/Documentation/arm64/booting.txt

 Linux/arm64のブートプロセスについてのメモ

 http://qiita.com/peo3@github/items/45063ab7ca27af69668b

arch/arm64/boot/以下にはx86_64のようなソースコード(head_64.S等)が存在しない。ブートローダがハードウェ

アの最低限の初期化をして、解凍された生のカーネルイメージ(ELFではない)を配置、エントリポイントにジャン

プしてやらないといけない。カーネルに実行を移すときの要件も、booting.txtに書かれている。

Page 28: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

booting.txtに何が書いてあるのか?

参考資料)3、linux-xlnx/tree/master/Documentation/arm64/booting.txt

ブートローダーのお仕事

 1. Setup and initialise the RAM 2. Setup the device tree 3. Decompress the kernel image 4. Call the kernel image

ZynqMPでは、1〜4までをU-Bootが行っているみたい。

カーネルにジャンプする前に、満たさないといけない条件も書いてある。

Page 29: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

Linuxには、Device Treeが必要

参考資料)3、linux-xlnx/tree/master/arch/arm64/boot/dts/xilinx/zynqmp.dtsi

cpus {#address-cells = <1>;#size-cells = <0>;cpu@0 {

compatible = "arm,cortex-a53", "arm,armv8";device_type = "cpu";enable-method = "psci";reg = <0x0>;

};cpu@1 {

Page 30: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

各種IP : Zynqと同じで、Cadence IP

参考資料)3、linux-xlnx/tree/master/arch/arm64/boot/dts/xilinx/zynqmp.dtsi

 ・GbEコントローラ(cdns,gem) ・I2Cコントローラ(cdns,i2c-r1p10) ・SDHCコントローラ(arasan,sdhci-8.9a) ・SPIコントローラ(cdns,spi-r1p6) ・Timer(cdns,ttc) ・UART(cdns,uart-r1p12) ・Watch Dog Timer(cdns,wdt-r1p2)

Page 31: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

各種IP:新規

参考資料)3、linux-xlnx/tree/master/arch/arm64/boot/dts/xilinx/zynqmp.dtsi 

 ・NANDコントローラ(arasan,nfc-v3p10)は、Arasan IP

 ・PCIeコントローラ(xlnx,nwl-pcie-2.11)は、Northwest Logic IP

 ・SATAコントローラ(ceva,ahci-1v84)は、Ceva IP

 ・USB Hostコントローラ(snps,dwc3)は、Synopsys IP

Page 32: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

GPU : Mali-400MP2も

参考資料)3、linux-xlnx/tree/master/arch/arm64/boot/dts/xilinx/zynqmp.dtsi

gpu: gpu@fd4b0000 {status = "disabled";compatible = "arm,mali-400", "arm,mali-utgard";reg = <0x0 0xfd4b0000 0x30000>;interrupt-parent = <&gic>;interrupts = <0 132 4>, <0 132 4>, <0 132 4>, <0 132 4>, <0 132 4>, <0 132 4>;interrupt-names = "IRQGP", "IRQGPMMU", "IRQPP0", "IRQPPMMU0", "IRQPP1", "IRQPPMMU1";

};

Page 33: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

Linux:arch/arm64

参考資料)3、linux-xlnx/tree/master/arch/arm64/

 

 boot configs crypto include kernel kvm lib mm net xen

 Kconfig Kconfig.debug Makefile

arch/armに比べて、すっきり!

Linus Torvalds氏、ARM用コードに噛み付く

http://srad.jp/story/11/06/22/0911201/

Page 34: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

PetaLinux

参考資料)4、PetaLinux、MPSoC+Petalinux+Software+Development

PetaLinux Tools Documentation Reference GuideUG1144 (v2015.4) December 7, 2015http://www.xilinx.com/support/documentation/sw_manuals/petalinux2015_4/ug1144-petalinux-tools-reference-guide.pdf

PetaLinux 2015.4ダウンロードサイトhttp://www.xilinx.com/support/download/index.html/content/xilinx/en/downloadNav/embedded-design-tools/2015-4.html

Zynqようですが、Petalinux 2015.4をUbuntu 14.04LTSでビルドした人

http://engineernote.hatenablog.com/entry/2016/01/31/012227

Page 35: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

Yoctoもサポート

参考資料)4、Yocto+for+zynqmp

参考資料)3、meta-xilinx

 Yocto 2015-02-23 Mainline Releases <build directory>/poky/meta \

<build directory>/poky/meta-yocto \

<build directory>/poky/meta-yocto-bsp \

<build directory>/meta-xilinx \

MACHINE ??= "qemux86"

MACHINE = "ep108-zynqmp"

Page 36: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

ZynqMPがないのにどうやって確かめる?

参考文献4)、http://www.wiki.xilinx.com/QEMU+-+ZynqMP、参考文献5)

QEMU上で、

 ・PMU :Firmware

 ・A53 :Linux + ATF(bl31)

を起動して、確かめられる

http://www.wiki.xilinx.com/MPSoC+Power+Management では、PMU firmwareの確認もできる

Page 37: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

ZynqのQEMUなら4年前に調べていた

Zynqのqemu (その0 〜 その11) 

http://blogs.yahoo.co.jp/verification_engineer/MYBLOG/yblog.html?sk=0&sv=Zynq%A4%CEqemu&m=l

ZynqMPのQEMU + PCのPCIeに接続したFPGAを使って、

擬似Zynq MPSoC

が作れるよ。

Page 38: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

でも実機がほしい?

96boards : Hikey

http://www.96boards.org/products/ce/hikey/

・Hisilicon Kirin 620

 CPUコア:ARM [email protected] + [email protected]

 GPUコア:ARM Mali-T450MP4、HDMI 1.3 1080p

・1GB/2GBメモリ(LPDDR3-800)、8GB eMMC

・802.11b/g/n WiFi, Bluetooth 4.0 LE

・79ドル(1GB)、99ドル(2GB)

・ACアダプタは別売り

Page 39: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

もっと安いの出ました

HardKernel : ODROID-C2、40ドル

http://forum.odroid.com/viewtopic.php?f=135&t=18683

 ・Amlogic S905 (Cortex-A53x4@ 2Ghz) ・2Gbyte DDR3 SDRAM ・ARM Mali™-450 MP3 GPU、HDMI 2.0 4K/60Hz display ・H.265 4K/60FPS and H.264 4K/30FPS capable VPU ・Gigabit Ethernet ・eMMC5.0 HS400 Flash Storage slot(eMMCは付いていない) ・UHS-1 SDR50 MicroSD slot ・USB 2.0 Host x 4, USB 2.0 OTG x 1 (USB給電可能) ・Ubuntu 16.04 and Android 5.1 Lollipop

Page 40: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

Hikeyの中身はこんな感じ?

CCI-400

DRAMC

128b

A53x4

128b

128bACE128b

128b

A53x4

ACE128b

GPU

128b

DRAMは32ビットLPDDR3-800

Page 41: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

Hikeyのソフトウェア

・ATF (ARM trusted firmware)

・UEFI (Unified Extensible Firmware Interface)・EDK2

  ATFのbl33として実行(ZymqMPでは、FSBLが実行)

U-bootもサポートできているみたい

  http://lists.denx.de/pipermail/u-boot/2015-July/221190.html

・Linux

・File System (Debian)、ARM Mali-450MP4はOpenGL ES v2サポート

Page 42: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

パワーマネージメント

Page 43: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

ARM64のパワーマネージメント

Linux Kernel Power Management Framework for ARM 64-bit ProcessorsL.Pieralisi、21/8/2014 - LinuxCon North America 2014

http://events.linuxfoundation.org/sites/events/files/slides/lp-linuxcon14.pdf

HKG15-404: Standardizing Linux Kernel Power Management on ARM 32/64-bit

https://www.youtube.com/watch?v=YB7W-v1At4o

PSCI (Power State Coordination Interface)

Page 44: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

ATF(ARM Trusted Firmware)

参考資料)3、arm-trusted-firmware/blob/master/docs/firmware-design.md

● Boot Loader stage 1 (BL1) AP Trusted ROM● Boot Loader stage 2 (BL2) Trusted Boot Firmware● Boot Loader stage 3-1 (BL31) EL3 Runtime Firmware● Boot Loader stage 3-2 (BL32) Secure-EL1 Payload (optional)● Boot Loader stage 3-3 (BL33) Non-trusted Firmware

PSCIは、BL31に実装されている

追記) 2016.05.08公式ARM Trusted Firmwareのサイトに、Zynq UltraScale+ MPSoCの実装が追加されているhttps://github.com/ARM-software/arm-trusted-firmware/blob/master/docs/plat/xilinx-zynqmp.mdhttps://github.com/ARM-software/arm-trusted-firmware/tree/master/plat/xilinx/zynqmp

Page 45: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

ZynqMPで使用するATF

参考資料)3、arm-trusted-firmware/blob/master/docs/plat/xilinx-zynqmp.md

・ZynqMPでは、ATFはBL31(EL3 Runtime Firmware)のみを利用

  ・BL1(AP Trusted ROM)に相当するものは、内部ROM(PMUが実行)

  ・BL2(Trusted Boot Firmware)に相当するものは、FSBL(A53が実行)

・通常はOCMにロード(DRAMも可能:Makefile内で指定)

・Build

% make DEBUG=1 RESET_TO_BL31=1 CROSS_COMPILE=aarch64-none-elf- PLAT=zynqmp bl31

Page 46: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

EL3 Runtime Service

参考資料)3、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 => Xilinx独自サービスの提供

Page 47: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

Standard Service calls : PSCI

参考資料)、http://infocenter.arm.com/help/topic/com.arm.doc.den0022c/DEN0022C_Power_State_Coordination_Interface.pdf

・POWER STATE COORDINATION INTERFACE の略

  

  このドキュメントを読めばいいよ!

Page 48: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

Linuxのdtsで指定する

参考資料)3、linux-xlnx/blob/master/arch/arm64/boot/dts/xilinx/zynqmp.dtsi

cpu@0 {compatible = "arm,cortex-a53", "arm,armv8";device_type = "cpu";enable-method = "psci";reg = <0x0>;

}; psci {compatible = "arm,psci-0.2";method = "smc";

};

パワーマネージメント無しの時は、enable-method = “spin-lock”;または、何もしていしないとき

Page 49: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

PSCIは、Linux Kernel内で処理される

参考資料)3、linux-xlnx/blob/master/arch/arm64/kernel/psci.c

   const struct cpu_operations cpu_psci_ops = {

      .name = "psci",

     .cpu_init_idle = cpu_psci_cpu_init_idle,     .cpu_suspend = cpu_psci_cpu_suspend,

     .cpu_init = cpu_psci_cpu_init,        .cpu_prepare = cpu_psci_cpu_prepare,     .cpu_boot = cpu_psci_cpu_boot,   };

const struct 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,};

ここにパワーマネージメント関連の関数が設定されていない

altera/exynos/cavium/mediatek/xilinx/hisilicon/rockchip/spreadtrum

apm/freescale/broadcom/qualcomm

Page 50: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

LinuxからATFへはどのように伝える?

参考資料)3、linux-xlnx/blob/master/arch/arm64/kernel/psci_call.S

・SMC (Secure Monitor Call) を使う

  http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0204ij/Cjaeeged.html

  

  /* int __invoke_psci_fn_smc(u64 function_id, u64 arg0, u64 arg1, u64 arg2) */  ENTRY(__invoke_psci_fn_smc)

  smc #0  ret

  ENDPROC(__invoke_psci_fn_smc)

          zynqmp.dts

psci {compatible = "arm,psci-0.2";

method = "smc";};

Page 51: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

Sip Service calls:PM-API (Xilinx独自)

参考資料)3、linux-xlnx/blob/master/Documentation/devicetree/bindings/soc/xilinx/zynq_mpsoc.txt

Zynq MPSoC based systems rely on the "psci" node to detect the presence of PMUfirmware as well as to determine the calling method (either "smc" or "hvc")to the PM-API firmware layer.

                 zynqmp.dtifirmware {

compatible = "xlnx,zynqmp-pm";method = "smc";

};

Page 52: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

PM-APIは、Linux Driver内で処理される

参考資料)3、linux-xlnx/tree/master/drivers/soc/xilinx/zynqmp/pm.c参考資料)4、http://www.wiki.xilinx.com/MPSoC+Power+Management

/sys/kernel/debug/zynqmp_pm/power

に対して、以下のコマンドをライトする  REQUEST_SUSPEND, SELF_SUSPEND, FORCE_POWERDOWN, ABORT_SUSPEND, REQUEST_WAKEUP, SET_WAKEUP_SOURCE, SYSTEM_SHUTDOWN, REQUEST_NODE, RELEASE_NONE, SET_REQUIREMENT, SET_MAX_LATENCY, GET_API_VERSION, SET_CONFIGURATION, GET_NODE_STATUS, GET_OPERATING_CHARACTERISTIC, RQGISTER_NOTIFIER, RESET_ASSERT, RESET_GET_STATUS, MMIO_READ, MMIO_WRITE

Page 53: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

LinuxからATFへはどのように伝える?

参考資料)3、linux-xlnx/blob/master/drivers/soc/xilinx/zynqmp/pm.c

static int invoke_pm_fn(u32 pm_api_id, u32 arg0, u32 arg1, u32 arg2, u32 arg3, u32 *ret_payload)

* Invoke power management function for SMC or HVC call, depending on configuration* Following SMC Calling Convention (SMCCC) for SMC64:

* Pm Function Identifier,* PM_SIP_SVC + PM_API_ID * PM_SIP_SVC - Registered ZynqMP SIP Service Call* PM_API_ID - Power Management API ID

Page 54: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

LinuxからATFへはどのように伝える?

参考資料)3、linux-xlnx/blob/master/drivers/soc/xilinx/zynqmp/pm.c

・SMC (Secure Monitor Call) を使う

static noinline int do_fw_call_smc(u64 arg0, u64 arg1, u64 arg2, u32 *ret_payload) { asm volatile( __asmeq("%0", "x0")

__asmeq("%1", "x1") __asmeq("%2", "x2") "smc #0\n" : "+r" (arg0), "+r" (arg1), "+r" (arg2) : /* no input only */ : "x3", "x4", "x5", "x6", "x7", "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15", "x16", "x17" );

                 zynqmp.dtifirmware {

compatible = "xlnx,zynqmp-pm";method = "smc";

};

Page 55: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

Linux

Standard Service callsとSiP Service calls

PSCI zynqmp-pm

ATF ( BL31 )

Std Service SiP Service

Page 56: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

Standard Service calls

参考資料)3、arm-trusted-firmware/tree/master/services/std_svc_setup.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

);

Page 57: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

std_svc_smc_handler

参考資料)3、arm-trusted-firmware/tree/master/services/std_svc_setup.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);}

Page 58: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

psci_smc_handler

参考資料)3、arm-trusted-firmware/tree/master/services/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;

}

Page 59: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

Sip Service calls

参考資料)3、arm-trusted-firmware/tree/master/plat/xilinx/zynqmp/sip_svc_setup.c

/* Register PM Service Calls as runtime service */DECLARE_RT_SVC(

sip_svc,

OEN_SIP_START,OEN_SIP_END,SMC_TYPE_FAST,

sip_svc_setup,sip_svc_smc_handler

;

Page 60: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

sip_svc_smc_handler

参考資料)3、arm-trusted-firmware/tree/master/plat/xilinx/zynqmp/sip_svc_setup.c

/* sip_svc_smc_handler() - Top-level SiP Service SMC handler* Handler for all SiP SMC calls. Handles standard SIP requests and calls PM SMC handler if the call is for a PM-API function. */

uint64_t sip_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){

/* Let PM SMC handler deal with PM-related requests */if (is_pm_fid(smc_fid)) {

return pm_smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle, flags);

}

Page 61: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

Linux

ZynqMP PM Service

PSCI zynqmp-pm

ATF ( BL31 )

Std Service SiP Service

ZynqMP PM Service

Page 62: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

pm_api_sys

参考資料)3、arm-trusted-firmware/blob/master/plat/xilinx/zynqmp/pm_service/pm_api_sys.c

pm_req_suspend pm_self_suspendpm_force_powerdown pm_abort_suspendpm_req_wakeup pm_set_wakeup_sourcepm_system_shutdown pm_init_suspend_cbpm_req_node pm_release_nodepm_set_requirement pm_set_max_latencypm_get_api_version pm_set_configurationpm_get_node_status pm_register_notifierpm_get_op_characteristic pm_acknowledge_cbpm_notify_cb pm_reset_assert pm_reset_get_statuspm_mmio_write pm_mmio_read

Page 63: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

pm_self_suspend

参考資料)3、arm-trusted-firmware/blob/master/plat/xilinx/zynqmp/pm_service/pm_api_sys.c

enum pm_ret_status pm_self_suspend(const enum pm_node_id nid, const uint32_t latency, const uint8_t state, const uint64_t address)

{uint32_t payload[PAYLOAD_ARG_CNT];unsigned int cpuid = plat_my_core_pos();const struct pm_proc *proc = pm_get_proc(cpuid);pm_client_suspend(proc);

/* Send request to the PMU */PM_PACK_PAYLOAD6(payload, PM_SELF_SUSPEND, proc->node_id, latency,

state, address, (address >> 32));return pm_ipi_send_sync(proc, payload, NULL);

}

Page 64: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

Linux

最後は、PMU FW

PSCI zynqmp-pm

ATF ( BL31 )

Std Service SiP Service

PMU FW

ZynqMP PM Service

Page 65: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

再び、PMUのお仕事

参考文献1)、Chapter 6

The platform management unit (PMU) controls the power-up, reset, and monitoring of resources within the entire system. Earlier power management mechanisms were implemented using hardware state machines. Modern MPSoCs include a dedicated centralized and user-programmable processor for power management to reduce risk and increase scalability. The Zynq® UltraScale+™ MPSoC PMU performs the following set of tasks.

  • Initialization of the system during boot.

  • Management of power gating.

Page 66: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

IPI : Inter-Processor Interrupt (ATF側)

参考資料)1、P.189参考資料)3、arm-trusted-firmware/blob/master/plat/xilinx/zynqmp/pm_service/pm_ipi.c

pm_ipi_init() - Initialize IPI peripheral for communication with PMUpm_ipi_send_sync() - Sends IPI request to the PMUpm_ipi_send() - Sends IPI request to the PMUpm_ipi_send_common() - Sends IPI request to the PMUpm_ipi_buff_read() - Reads IPI response after PMU has handled interruptpm_ipi_wait() - wait for pmu to handle requestipi_fiq_handler() - IPI Handler for PM-API callbacks

Page 67: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

IPI : Inter-Processor Interrupt (PMUFW側)

参考資料)3、embeddedsw/tree/master/lib/sw_apps/zynqmp_pmufw/src/xpfw_user_startup.c

static void PmIpiHandler(const XPfw_Module_t *ModPtr, u32 IpiNum, u32 SrcMask)

{switch (IpiNum) {case 0:

isrVal = XPfw_Read32(IPI_PMU_0_ISR);ipiStatus = XPfw_PmCheckIpiRequest(isrVal, &apiId);if (XPFW_PM_IPI_IS_PM_CALL == ipiStatus) {

/* Power management API processing */

status = XPfw_PmIpiHandler(isrVal, apiId, &isrClr);

if (XST_SUCCESS == status) XPfw_Write32(IPI_PMU_0_ISR, isrClr);

Page 68: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

XPfw_PmIpiHandler

参考資料)3、embeddedsw/tree/master/lib/sw_apps/zynqmp_pmufw/src/pm_binding.c

int XPfw_PmIpiHandler(const u32 isrMask, const u32 apiId, u32* const isrClr)

{const PmMaster* master = PmGetMasterByIpiMask(isrMask);payload[0] = apiId;bufferBase = master->buffer + IPI_BUFFER_REQ_OFFSET;for (i = 1U; i < PAYLOAD_ELEM_CNT; i++) {

offset += PAYLOAD_ELEM_SIZE;payload[i] = XPfw_Read32(bufferBase + offset);

}

PmProcessRequest(master, payload);

Page 69: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

PmProcessRequest

参考資料)3、embeddedsw/tree/master/lib/sw_apps/zynqmp_pmufw/src/pm_core.c

void PmProcessRequest(const PmMaster *const master, const u32 pload[PAYLOAD_ELEM_CNT])

{PmPayloadStatus status = PmCheckPayload(pload);

if (PM_PAYLOAD_OK == status) {

PmProcessApiCall(master, pload);

}

Page 70: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

PmProcessApiCall

参考資料)3、embeddedsw/tree/master/lib/sw_apps/zynqmp_pmufw/src/pm_core.c

void PmProcessApiCall(const PmMaster *const master, const u32 pload[PAYLOAD_ELEM_CNT])

{switch (pload[0]) {case PM_SELF_SUSPEND: PmSelfSuspend(master, pload[1], pload[2], pload[3]);case PM_REQUEST_SUSPEND: PmRequestSuspend(master, pload[1], pload[2], pload[3], case PM_FORCE_POWERDOWN: PmForcePowerdown(master, pload[1], pload[2]);case PM_ABORT_SUSPEND: PmAbortSuspend(master, pload[1], pload[2]);case PM_REQUEST_WAKEUP: PmRequestWakeup(master, pload[1], pload[2]);…..

Page 71: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

PmSelfSuspend

参考資料)3、embeddedsw/tree/master/lib/sw_apps/zynqmp_pmufw/src/pm_core.c

static void PmSelfSuspend(const PmMaster *const master, const u32 node, const u32 latency, const u32

{int status;

/* the node ID must refer to a processor belonging to this master */

PmProc* proc = PmGetProcOfThisMaster(master, node);

status = PmProcFsm(proc, PM_PROC_EVENT_SELF_SUSPEND);

XPfw_Write32(master->buffer + IPI_BUFFER_RESP_OFFSET, status);}

Page 72: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

PmProcFsm

参考資料)3、embeddedsw/tree/master/lib/sw_apps/zynqmp_pmufw/src/pm_proc.c

int PmProcFsm(PmProc* const proc, const PmProcEvent event)

{int status = XST_PM_INTERNAL;PmStateId currState = proc->node.currState;

switch (event) {case PM_PROC_EVENT_SELF_SUSPEND:

if (PM_PROC_STATE_ACTIVE == currState) {

status = PmProcTrActiveToSuspend(proc);

}break;

Page 73: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

PmProcTrActiveToSuspend

参考資料)1、P.97(PMU GPI2 : GPI2 monitors power control requests)参考資料)3、embeddedsw/tree/master/lib/sw_apps/zynqmp_pmufw/src/pm_proc.c

static int PmProcTrActiveToSuspend(PmProc* const proc)

{PmDbg("ACTIVE->SUSPENDING %s\n", PmStrNode(proc->node.nodeId));

/* Enable/disable macros for processor's wfi event in GPI2 register */#define ENABLE_WFI(mask) XPfw_RMW32(PMU_LOCAL_GPI2_ENABLE, mask, mask);

ENABLE_WFI(proc->wfiEnableMask);proc->node.currState = PM_PROC_STATE_SUSPENDING;

return XST_SUCCESS;}

Page 74: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

WFI

ARM® Compiler armasm User Guide, Version 6.3http://infocenter.arm.com/help/topic/com.arm.doc.dui0801d/pge1427897721360.htmllib/sw_apps/zynqmp_pmufw/src/pm_proc.c

Wait For Interrupt is a hint instruction that permits the PE to enter a low-power state until one of a number of asynchronous event occurs.

● Traps to EL1 of EL0 execution of WFE and WFI instructions.● Traps to EL2 of Non-secure EL0 and EL1 execution of WFE and WFI instructions.● Traps to EL3 of EL2, EL1, and EL0 execution of WFE and WFI instructions.

Page 75: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

Linux

PMU FWは、ZynqMPの重要な機能

PSCI zynqmp-pm

ATF ( BL31 )

Std Service SiP Service

PMU FW

ZynqMP PM Service

Page 76: ZynqMPのブートとパワーマネージメント : (ZynqMP Boot and Power Management)

おしまい