Skip to content

Commit b3ae24c

Browse files
rajanv-xilinxgregkh
authored andcommitted
firmware: xilinx: Add sysfs to set shutdown scope
The Linux shutdown functionality implemented via PSCI system_off does not include an option to set a scope, i.e. which parts of the system to shut down. This patch creates sysfs that allows to set the shutdown scope for the next shutdown request. When the next shutdown is performed, the platform specific portion of PSCI-system_off can use the chosen shutdown scope. Signed-off-by: Rajan Vaja <rajan.vaja@xilinx.com> Signed-off-by: Stefan Krsmanovic <stefan.krsmanovic@aggios.com> Signed-off-by: Michal Simek <michal.simek@xilinx.com> Signed-off-by: Tejas Patel <tejas.patel@xilinx.com> Signed-off-by: Jolly Shah <jolly.shah@xilinx.com> Link: https://lore.kernel.org/r/1587761887-4279-25-git-send-email-jolly.shah@xilinx.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent fdd2ed8 commit b3ae24c

3 files changed

Lines changed: 141 additions & 1 deletion

File tree

‎Documentation/ABI/stable/sysfs-driver-firmware-zynqmp‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,35 @@ Description:
4848
# echo 0x1234ABCD > /sys/devices/platform/firmware\:zynqmp-firmware/pggs0
4949

5050
Users: Xilinx
51+
52+
What: /sys/devices/platform/firmware\:zynqmp-firmware/shutdown_scope
53+
Date: March 2020
54+
KernelVersion: 5.6
55+
Contact: "Jolly Shah" <jollys@xilinx.com>
56+
Description:
57+
This sysfs interface allows to set the shutdown scope for the
58+
next shutdown request. When the next shutdown is performed, the
59+
platform specific portion of PSCI-system_off can use the chosen
60+
shutdown scope.
61+
62+
Following are available shutdown scopes(subtypes):
63+
64+
subsystem: Only the APU along with all of its peripherals
65+
not used by other processing units will be
66+
shut down. This may result in the FPD power
67+
domain being shut down provided that no other
68+
processing unit uses FPD peripherals or DRAM.
69+
ps_only: The complete PS will be shut down, including the
70+
RPU, PMU, etc. Only the PL domain (FPGA)
71+
remains untouched.
72+
system: The complete system/device is shut down.
73+
74+
Usage:
75+
# cat /sys/devices/platform/firmware\:zynqmp-firmware/shutdown_scope
76+
# echo <scope> > /sys/devices/platform/firmware\:zynqmp-firmware/shutdown_scope
77+
78+
Example:
79+
# cat /sys/devices/platform/firmware\:zynqmp-firmware/shutdown_scope
80+
# echo "subsystem" > /sys/devices/platform/firmware\:zynqmp-firmware/shutdown_scope
81+
82+
Users: Xilinx

‎drivers/firmware/xilinx/zynqmp.c‎

Lines changed: 97 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,102 @@ int zynqmp_pm_system_shutdown(const u32 type, const u32 subtype)
888888
0, 0, NULL);
889889
}
890890

891+
/**
892+
* struct zynqmp_pm_shutdown_scope - Struct for shutdown scope
893+
* @subtype: Shutdown subtype
894+
* @name: Matching string for scope argument
895+
*
896+
* This struct encapsulates mapping between shutdown scope ID and string.
897+
*/
898+
struct zynqmp_pm_shutdown_scope {
899+
const enum zynqmp_pm_shutdown_subtype subtype;
900+
const char *name;
901+
};
902+
903+
static struct zynqmp_pm_shutdown_scope shutdown_scopes[] = {
904+
[ZYNQMP_PM_SHUTDOWN_SUBTYPE_SUBSYSTEM] = {
905+
.subtype = ZYNQMP_PM_SHUTDOWN_SUBTYPE_SUBSYSTEM,
906+
.name = "subsystem",
907+
},
908+
[ZYNQMP_PM_SHUTDOWN_SUBTYPE_PS_ONLY] = {
909+
.subtype = ZYNQMP_PM_SHUTDOWN_SUBTYPE_PS_ONLY,
910+
.name = "ps_only",
911+
},
912+
[ZYNQMP_PM_SHUTDOWN_SUBTYPE_SYSTEM] = {
913+
.subtype = ZYNQMP_PM_SHUTDOWN_SUBTYPE_SYSTEM,
914+
.name = "system",
915+
},
916+
};
917+
918+
static struct zynqmp_pm_shutdown_scope *selected_scope =
919+
&shutdown_scopes[ZYNQMP_PM_SHUTDOWN_SUBTYPE_SYSTEM];
920+
921+
/**
922+
* zynqmp_pm_is_shutdown_scope_valid - Check if shutdown scope string is valid
923+
* @scope_string: Shutdown scope string
924+
*
925+
* Return: Return pointer to matching shutdown scope struct from
926+
* array of available options in system if string is valid,
927+
* otherwise returns NULL.
928+
*/
929+
static struct zynqmp_pm_shutdown_scope*
930+
zynqmp_pm_is_shutdown_scope_valid(const char *scope_string)
931+
{
932+
int count;
933+
934+
for (count = 0; count < ARRAY_SIZE(shutdown_scopes); count++)
935+
if (sysfs_streq(scope_string, shutdown_scopes[count].name))
936+
return &shutdown_scopes[count];
937+
938+
return NULL;
939+
}
940+
941+
static ssize_t shutdown_scope_show(struct device *device,
942+
struct device_attribute *attr,
943+
char *buf)
944+
{
945+
int i;
946+
947+
for (i = 0; i < ARRAY_SIZE(shutdown_scopes); i++) {
948+
if (&shutdown_scopes[i] == selected_scope) {
949+
strcat(buf, "[");
950+
strcat(buf, shutdown_scopes[i].name);
951+
strcat(buf, "]");
952+
} else {
953+
strcat(buf, shutdown_scopes[i].name);
954+
}
955+
strcat(buf, " ");
956+
}
957+
strcat(buf, "\n");
958+
959+
return strlen(buf);
960+
}
961+
962+
static ssize_t shutdown_scope_store(struct device *device,
963+
struct device_attribute *attr,
964+
const char *buf, size_t count)
965+
{
966+
int ret;
967+
struct zynqmp_pm_shutdown_scope *scope;
968+
969+
scope = zynqmp_pm_is_shutdown_scope_valid(buf);
970+
if (!scope)
971+
return -EINVAL;
972+
973+
ret = zynqmp_pm_system_shutdown(ZYNQMP_PM_SHUTDOWN_TYPE_SETSCOPE_ONLY,
974+
scope->subtype);
975+
if (ret) {
976+
pr_err("unable to set shutdown scope %s\n", buf);
977+
return ret;
978+
}
979+
980+
selected_scope = scope;
981+
982+
return count;
983+
}
984+
985+
static DEVICE_ATTR_RW(shutdown_scope);
986+
891987
static ssize_t ggs_show(struct device *device,
892988
struct device_attribute *attr,
893989
char *buf,
@@ -923,7 +1019,6 @@ static ssize_t ggs_store(struct device *device,
9231019
ret = zynqmp_pm_write_ggs(reg, value);
9241020
if (ret)
9251021
count = -EFAULT;
926-
9271022
err:
9281023
return count;
9291024
}
@@ -1047,6 +1142,7 @@ static struct attribute *zynqmp_firmware_attrs[] = {
10471142
&dev_attr_pggs1.attr,
10481143
&dev_attr_pggs2.attr,
10491144
&dev_attr_pggs3.attr,
1145+
&dev_attr_shutdown_scope.attr,
10501146
NULL,
10511147
};
10521148

‎include/linux/firmware/xlnx-zynqmp.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,18 @@ enum dll_reset_type {
286286
PM_DLL_RESET_PULSE,
287287
};
288288

289+
enum zynqmp_pm_shutdown_type {
290+
ZYNQMP_PM_SHUTDOWN_TYPE_SHUTDOWN,
291+
ZYNQMP_PM_SHUTDOWN_TYPE_RESET,
292+
ZYNQMP_PM_SHUTDOWN_TYPE_SETSCOPE_ONLY,
293+
};
294+
295+
enum zynqmp_pm_shutdown_subtype {
296+
ZYNQMP_PM_SHUTDOWN_SUBTYPE_SUBSYSTEM,
297+
ZYNQMP_PM_SHUTDOWN_SUBTYPE_PS_ONLY,
298+
ZYNQMP_PM_SHUTDOWN_SUBTYPE_SYSTEM,
299+
};
300+
289301
/**
290302
* struct zynqmp_pm_query_data - PM query data
291303
* @qid: query ID

0 commit comments

Comments
 (0)