Re: [PATCH 5/5] firmware: xilinx: Add sysfs and IOCTL to set boot health status
From: Michal Simek
Date: Wed Dec 18 2019 - 09:28:34 EST
On 05. 12. 19 0:29, Jolly Shah wrote:
> From: Rajan Vaja <rajan.vaja@xxxxxxxxxx>
>
> Add sysfs interface to set boot health status from userspace.
> Add IOCTL ID used by this interface to communicate with firmware.
>
> If PMUFW is compiled with CHECK_HEALTHY_BOOT, it will check the
> healthy bit on FPD WDT expiration. If healthy bit is set by a user
> application running in Linux, PMUFW will do APU only restart. If
> healthy bit is not set during FPD WDT expiration, PMUFW will do
> system restart.
>
> Signed-off-by: Michal Simek <michal.simek@xxxxxxxxxx>
> Signed-off-by: Rajan Vaja <rajan.vaja@xxxxxxxxxx>
Rajan should be the first.
> Signed-off-by: Jolly Shah <jolly.shah@xxxxxxxxxx>
> ---
> Documentation/ABI/stable/sysfs-firmware-zynqmp | 21 +++++++++++++
> drivers/firmware/xilinx/zynqmp.c | 42 ++++++++++++++++++++++++++
> include/linux/firmware/xlnx-zynqmp.h | 2 ++
> 3 files changed, 65 insertions(+)
>
> diff --git a/Documentation/ABI/stable/sysfs-firmware-zynqmp b/Documentation/ABI/stable/sysfs-firmware-zynqmp
> index 13e4fd2..eeae291 100644
> --- a/Documentation/ABI/stable/sysfs-firmware-zynqmp
> +++ b/Documentation/ABI/stable/sysfs-firmware-zynqmp
> @@ -80,3 +80,24 @@ Description:
> # echo "subsystem" > /sys/firmware/zynqmp/shutdown_scope
>
> Users: Xilinx
> +
> +What: /sys/firmware/zynqmp/health_status
> +Date: April 2018
> +KernelVersion: 4.14.0
ditto
> +Contact: "Rajan Vaja" <rajanv@xxxxxxxxxx>
> +Description:
> + This sysfs interface allows to set the health status. If PMUFW
> + is compiled with CHECK_HEALTHY_BOOT, it will check the healthy
> + bit on FPD WDT expiration. If healthy bit is set by a user
> + application running in Linux, PMUFW will do APU only restart. If
> + healthy bit is not set during FPD WDT expiration, PMUFW will do
> + system restart.
> +
> + Usage:
> + Set healty bit
healthy
> + # echo 1 > /sys/firmware/zynqmp/health_status
> +
> + Unset healty bit
ditto.
> + # echo 0 > /sys/firmware/zynqmp/health_status
> +
> +Users: Xilinx
> diff --git a/drivers/firmware/xilinx/zynqmp.c b/drivers/firmware/xilinx/zynqmp.c
> index b23bda4..4e497a3 100644
> --- a/drivers/firmware/xilinx/zynqmp.c
> +++ b/drivers/firmware/xilinx/zynqmp.c
> @@ -479,6 +479,7 @@ static inline int zynqmp_is_valid_ioctl(u32 ioctl_id)
> case IOCTL_READ_GGS:
> case IOCTL_WRITE_PGGS:
> case IOCTL_READ_PGGS:
> + case IOCTL_SET_BOOT_HEALTH_STATUS:
> return 1;
> default:
> return 0;
> @@ -886,6 +887,46 @@ static struct kobj_attribute zynqmp_attr_shutdown_scope =
> __ATTR_RW(shutdown_scope);
>
> /**
> + * health_status_store - Store health_status sysfs attribute
> + * @kobj: Kobject structure
> + * @attr: Kobject attribute structure
> + * @buf: User entered health_status attribute string
> + * @count: Buffer size
> + *
> + * User-space interface for setting the boot health status.
> + * Usage: echo <value> > /sys/firmware/zynqmp/health_status
> + *
> + * Value:
> + * 1 - Set healthy bit to 1
> + * 0 - Unset healthy bit
> + *
> + * Return: count argument if request succeeds, the corresponding error
> + * code otherwise
> + */
> +static ssize_t health_status_store(struct kobject *kobj,
> + struct kobj_attribute *attr,
> + const char *buf, size_t count)
> +{
> + int ret;
> + unsigned int value;
> +
> + ret = kstrtouint(buf, 10, &value);
> + if (ret)
> + return ret;
> +
> + ret = zynqmp_pm_ioctl(0, IOCTL_SET_BOOT_HEALTH_STATUS, value, 0, NULL);
> + if (ret) {
> + pr_err("unable to set healthy bit value to %u\n", value);
> + return ret;
> + }
> +
> + return count;
> +}
> +
> +static struct kobj_attribute zynqmp_attr_health_status =
> + __ATTR_WO(health_status);
ditto.
> +
> +/**
> * config_reg_store - Write config_reg sysfs attribute
> * @kobj: Kobject structure
> * @attr: Kobject attribute structure
> @@ -1011,6 +1052,7 @@ static struct kobj_attribute zynqmp_attr_config_reg =
>
> static struct attribute *attrs[] = {
> &zynqmp_attr_shutdown_scope.attr,
> + &zynqmp_attr_health_status.attr,
> &zynqmp_attr_config_reg.attr,
> NULL,
> };
> diff --git a/include/linux/firmware/xlnx-zynqmp.h b/include/linux/firmware/xlnx-zynqmp.h
> index 54061de..c6f3c50 100644
> --- a/include/linux/firmware/xlnx-zynqmp.h
> +++ b/include/linux/firmware/xlnx-zynqmp.h
> @@ -107,6 +107,8 @@ enum pm_ioctl_id {
> IOCTL_READ_GGS,
> IOCTL_WRITE_PGGS,
> IOCTL_READ_PGGS,
> + /* Set healthy bit value*/
<space>*/
> + IOCTL_SET_BOOT_HEALTH_STATUS = 17,
> };
>
> enum pm_query_id {
>
M