Skip to content

Commit ae5c961

Browse files
rajanv-xilinxgregkh
authored andcommitted
firmware: xilinx: Add sysfs interface
Add firmware-ggs sysfs interface which provides read/write interface to global storage registers. Signed-off-by: Rajan Vaja <rajan.vaja@xilinx.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-23-git-send-email-jolly.shah@xilinx.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 4f680b7 commit ae5c961

3 files changed

Lines changed: 218 additions & 1 deletion

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
What: /sys/devices/platform/firmware\:zynqmp-firmware/ggs*
2+
Date: March 2020
3+
KernelVersion: 5.6
4+
Contact: "Jolly Shah" <jollys@xilinx.com>
5+
Description:
6+
Read/Write PMU global general storage register value,
7+
GLOBAL_GEN_STORAGE{0:3}.
8+
Global general storage register that can be used
9+
by system to pass information between masters.
10+
11+
The register is reset during system or power-on
12+
resets. Three registers are used by the FSBL and
13+
other Xilinx software products: GLOBAL_GEN_STORAGE{4:6}.
14+
15+
Usage:
16+
# cat /sys/devices/platform/firmware\:zynqmp-firmware/ggs0
17+
# echo <value> > /sys/devices/platform/firmware\:zynqmp-firmware/ggs0
18+
19+
Example:
20+
# cat /sys/devices/platform/firmware\:zynqmp-firmware/ggs0
21+
# echo 0x1234ABCD > /sys/devices/platform/firmware\:zynqmp-firmware/ggs0
22+
23+
Users: Xilinx
24+
25+
What: /sys/devices/platform/firmware\:zynqmp-firmware/pggs*
26+
Date: March 2020
27+
KernelVersion: 5.6
28+
Contact: "Jolly Shah" <jollys@xilinx.com>
29+
Description:
30+
Read/Write PMU persistent global general storage register
31+
value, PERS_GLOB_GEN_STORAGE{0:3}.
32+
Persistent global general storage register that
33+
can be used by system to pass information between
34+
masters.
35+
36+
This register is only reset by the power-on reset
37+
and maintains its value through a system reset.
38+
Four registers are used by the FSBL and other Xilinx
39+
software products: PERS_GLOB_GEN_STORAGE{4:7}.
40+
Register is reset only by a POR reset.
41+
42+
Usage:
43+
# cat /sys/devices/platform/firmware\:zynqmp-firmware/pggs0
44+
# echo <value> > /sys/devices/platform/firmware\:zynqmp-firmware/pggs0
45+
46+
Example:
47+
# cat /sys/devices/platform/firmware\:zynqmp-firmware/pggs0
48+
# echo 0x1234ABCD > /sys/devices/platform/firmware\:zynqmp-firmware/pggs0
49+
50+
Users: Xilinx

‎drivers/firmware/xilinx/zynqmp.c‎

Lines changed: 166 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/*
33
* Xilinx Zynq MPSoC Firmware layer
44
*
5-
* Copyright (C) 2014-2018 Xilinx, Inc.
5+
* Copyright (C) 2014-2020 Xilinx, Inc.
66
*
77
* Michal Simek <michal.simek@xilinx.com>
88
* Davorin Mista <davorin.mista@aggios.com>
@@ -875,6 +875,170 @@ int zynqmp_pm_aes_engine(const u64 address, u32 *out)
875875
}
876876
EXPORT_SYMBOL_GPL(zynqmp_pm_aes_engine);
877877

878+
static ssize_t ggs_show(struct device *device,
879+
struct device_attribute *attr,
880+
char *buf,
881+
u32 reg)
882+
{
883+
int ret;
884+
u32 ret_payload[PAYLOAD_ARG_CNT];
885+
886+
ret = zynqmp_pm_read_ggs(reg, ret_payload);
887+
if (ret)
888+
return ret;
889+
890+
return sprintf(buf, "0x%x\n", ret_payload[1]);
891+
}
892+
893+
static ssize_t ggs_store(struct device *device,
894+
struct device_attribute *attr,
895+
const char *buf, size_t count,
896+
u32 reg)
897+
{
898+
long value;
899+
int ret;
900+
901+
if (reg >= GSS_NUM_REGS)
902+
return -EINVAL;
903+
904+
ret = kstrtol(buf, 16, &value);
905+
if (ret) {
906+
count = -EFAULT;
907+
goto err;
908+
}
909+
910+
ret = zynqmp_pm_write_ggs(reg, value);
911+
if (ret)
912+
count = -EFAULT;
913+
914+
err:
915+
return count;
916+
}
917+
918+
/* GGS register show functions */
919+
#define GGS0_SHOW(N) \
920+
ssize_t ggs##N##_show(struct device *device, \
921+
struct device_attribute *attr, \
922+
char *buf) \
923+
{ \
924+
return ggs_show(device, attr, buf, N); \
925+
}
926+
927+
static GGS0_SHOW(0);
928+
static GGS0_SHOW(1);
929+
static GGS0_SHOW(2);
930+
static GGS0_SHOW(3);
931+
932+
/* GGS register store function */
933+
#define GGS0_STORE(N) \
934+
ssize_t ggs##N##_store(struct device *device, \
935+
struct device_attribute *attr, \
936+
const char *buf, \
937+
size_t count) \
938+
{ \
939+
return ggs_store(device, attr, buf, count, N); \
940+
}
941+
942+
static GGS0_STORE(0);
943+
static GGS0_STORE(1);
944+
static GGS0_STORE(2);
945+
static GGS0_STORE(3);
946+
947+
static ssize_t pggs_show(struct device *device,
948+
struct device_attribute *attr,
949+
char *buf,
950+
u32 reg)
951+
{
952+
int ret;
953+
u32 ret_payload[PAYLOAD_ARG_CNT];
954+
955+
ret = zynqmp_pm_read_pggs(reg, ret_payload);
956+
if (ret)
957+
return ret;
958+
959+
return sprintf(buf, "0x%x\n", ret_payload[1]);
960+
}
961+
962+
static ssize_t pggs_store(struct device *device,
963+
struct device_attribute *attr,
964+
const char *buf, size_t count,
965+
u32 reg)
966+
{
967+
long value;
968+
int ret;
969+
970+
if (reg >= GSS_NUM_REGS)
971+
return -EINVAL;
972+
973+
ret = kstrtol(buf, 16, &value);
974+
if (ret) {
975+
count = -EFAULT;
976+
goto err;
977+
}
978+
979+
ret = zynqmp_pm_write_pggs(reg, value);
980+
if (ret)
981+
count = -EFAULT;
982+
983+
err:
984+
return count;
985+
}
986+
987+
#define PGGS0_SHOW(N) \
988+
ssize_t pggs##N##_show(struct device *device, \
989+
struct device_attribute *attr, \
990+
char *buf) \
991+
{ \
992+
return pggs_show(device, attr, buf, N); \
993+
}
994+
995+
#define PGGS0_STORE(N) \
996+
ssize_t pggs##N##_store(struct device *device, \
997+
struct device_attribute *attr, \
998+
const char *buf, \
999+
size_t count) \
1000+
{ \
1001+
return pggs_store(device, attr, buf, count, N); \
1002+
}
1003+
1004+
/* PGGS register show functions */
1005+
static PGGS0_SHOW(0);
1006+
static PGGS0_SHOW(1);
1007+
static PGGS0_SHOW(2);
1008+
static PGGS0_SHOW(3);
1009+
1010+
/* PGGS register store functions */
1011+
static PGGS0_STORE(0);
1012+
static PGGS0_STORE(1);
1013+
static PGGS0_STORE(2);
1014+
static PGGS0_STORE(3);
1015+
1016+
/* GGS register attributes */
1017+
static DEVICE_ATTR_RW(ggs0);
1018+
static DEVICE_ATTR_RW(ggs1);
1019+
static DEVICE_ATTR_RW(ggs2);
1020+
static DEVICE_ATTR_RW(ggs3);
1021+
1022+
/* PGGS register attributes */
1023+
static DEVICE_ATTR_RW(pggs0);
1024+
static DEVICE_ATTR_RW(pggs1);
1025+
static DEVICE_ATTR_RW(pggs2);
1026+
static DEVICE_ATTR_RW(pggs3);
1027+
1028+
static struct attribute *zynqmp_firmware_attrs[] = {
1029+
&dev_attr_ggs0.attr,
1030+
&dev_attr_ggs1.attr,
1031+
&dev_attr_ggs2.attr,
1032+
&dev_attr_ggs3.attr,
1033+
&dev_attr_pggs0.attr,
1034+
&dev_attr_pggs1.attr,
1035+
&dev_attr_pggs2.attr,
1036+
&dev_attr_pggs3.attr,
1037+
NULL,
1038+
};
1039+
1040+
ATTRIBUTE_GROUPS(zynqmp_firmware);
1041+
8781042
static int zynqmp_firmware_probe(struct platform_device *pdev)
8791043
{
8801044
struct device *dev = &pdev->dev;
@@ -952,6 +1116,7 @@ static struct platform_driver zynqmp_firmware_driver = {
9521116
.driver = {
9531117
.name = "zynqmp_firmware",
9541118
.of_match_table = zynqmp_firmware_of_match,
1119+
.dev_groups = zynqmp_firmware_groups,
9551120
},
9561121
.probe = zynqmp_firmware_probe,
9571122
.remove = zynqmp_firmware_remove,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242

4343
#define ZYNQMP_PM_MAX_QOS 100U
4444

45+
#define GSS_NUM_REGS (4)
46+
4547
/* Node capabilities */
4648
#define ZYNQMP_PM_CAPABILITY_ACCESS 0x1U
4749
#define ZYNQMP_PM_CAPABILITY_CONTEXT 0x2U

0 commit comments

Comments
 (0)