HiFive Unmatched is a PC development board based on RISC-V processor, this development board created a new era of RISC-V Linux development. It has an SiFive processor called the SiFive FU740 SoC, a five-core processor consisting of four SiFive U74 cores and one SiFive S7 core, with enough performance to support graphical desktops.

On December 29, 2021, with the joint efforts of Youkylin community and Haihe Laboratory RESEARCH and development team, the 20.04 Pro version of Youkylin community, the first operating system supporting RISC-V architecture, was released. This version of system was deeply adapted to HiFive Unmatched. The system can not shut down the problem, in the EFFORTS of the RESEARCH and development team made a breakthrough, realized through the system shutdown power function.

1, Hifive Unmatched development board hardware support

PMIC is the abbreviation of Power Management IC, which is a power management integrated circuit. It is characterized by high integration and encapsulates the traditional multi-channel output power supply into a single chip, making the multi-power application scenario more efficient and smaller in size. The development board uses DA9063 chip as its PMIC to realize the power management module.

Hifive Unmatched development board hardware shutdown can be supported in two ways. One is that the pins of CPU related functions are directly connected to the open/shutdown button, and the corresponding pins can be shut down by pressing the buttons to produce high and low level changes. Users can shut down the hardware directly by pressing the buttons. The other is through the development board hardware power management module (namely DA9063) external on/off button to achieve on/off function.

2. Realized the shutdown process software of Youkylin system

In the Linux Kernel, both shutdown and restart are implemented through the “reboot” system call. For details, see Kernel /sys.c. Shutdown is also a special restart process. Reboot is broken down into the following ways:

This article focuses on the shutdown process, POWER_OFF, after which the system stops the operating system and removes all power. You can run the poweroff command in Youkirin to initiate the following process:

The user-space program enters the kernel space through the reboot system call. The implementation is in the following function in kernel/reboot.c:

Where there are multiple cases for CMD, poweroff and other shutdown commands actually call:

Kernel space provides a kernel_restart handler that responds to reboot requests from user space. Its processing process mainly includes:

  • The Notify event is sent to the process concerned about the reboot process.

  • Call the interface provided by the drivers core module to shut down all external devices;

  • Call the interface provided by the drivers syscore module to close system core;

  • Call architecture-specific handlers for subsequent processing;

  • The machine_power_off function is then executed.

As we can see in the machine_power_off function, if the pm_power_off function pointer is not null, then the system will be shut down by calling this function.

The pM_POWER_off function actually points to the gPIo_poweroff_do_poweroff function in gPIO-poweroff. c, where gPIO is actually manipulated.

The entire shutdown process will be called as follows:

-->kernel_power_off() -->kernel_shutdown_prepare -->migrate_to_reboot_cpu -->syscore_shutdown -->machine_power_off // This function according to the concrete platform, riscv platform in the arch/riscv/kernel/reset. The c fileCopy the code

SiFive FU740 chip in Hifive Unmatched development board uses GPIO2 port as shutdown, we only need to send low level pulse to GPIO2 to achieve shutdown, the specific process is as follows:

First of all, to change the corresponding development board in the kernel source code files in the device tree, in the kernel source/arch/riscv/boot/DTS/sifive/hifive – unmatched – a00:1450:8006. DTS file, shutdown device nodes are added to it:

gpio-poweroff {
    compatible = "gpio-poweroff";
    gpios = <&gpio 2 GPIO_ACTIVE_LOW>;
}
Copy the code

Second, you need to match the device tree node with the driver in the corresponding driver code in the kernel.

After matching the device node with the driver, when the user initiates the shutdown request, after the shutdown process, the hardware is finally controlled to complete the shutdown and power off operation.

The above is Hifive Unmatched development board of the overall shutdown process, interested partners, hurry to youkylin official website download experience.