Skip to content

Commit ba61ab1

Browse files
committed
Merge tag 'zynqmp-soc-for-v4.20-v2' of https://github.com/Xilinx/linux-xlnx into next/drivers
arm64: zynqmp: SoC changes for v4.20 - Adding firmware API for SoC with debugfs interface Firmware driver communicates to Platform Management Unit (PMU) by using SMC instructions routed to Arm Trusted Firmware (ATF). Initial version adds support for base firmware driver with query and clock APIs. EEMI spec is available here: https://www.xilinx.com/support/documentation/user_guides/ug1200-eemi-api.pdf * tag 'zynqmp-soc-for-v4.20-v2' of https://github.com/Xilinx/linux-xlnx: firmware: xilinx: Add debugfs for query data API firmware: xilinx: Add debugfs interface firmware: xilinx: Add clock APIs firmware: xilinx: Add query data API firmware: xilinx: Add Zynqmp firmware driver dt-bindings: firmware: Add bindings for ZynqMP firmware Signed-off-by: Arnd Bergmann <arnd@arndb.de>
2 parents 1e25ee6 + e60f02d commit ba61ab1

10 files changed

Lines changed: 970 additions & 0 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
-----------------------------------------------------------------
2+
Device Tree Bindings for the Xilinx Zynq MPSoC Firmware Interface
3+
-----------------------------------------------------------------
4+
5+
The zynqmp-firmware node describes the interface to platform firmware.
6+
ZynqMP has an interface to communicate with secure firmware. Firmware
7+
driver provides an interface to firmware APIs. Interface APIs can be
8+
used by any driver to communicate to PMUFW(Platform Management Unit).
9+
These requests include clock management, pin control, device control,
10+
power management service, FPGA service and other platform management
11+
services.
12+
13+
Required properties:
14+
- compatible: Must contain: "xlnx,zynqmp-firmware"
15+
- method: The method of calling the PM-API firmware layer.
16+
Permitted values are:
17+
- "smc" : SMC #0, following the SMCCC
18+
- "hvc" : HVC #0, following the SMCCC
19+
20+
-------
21+
Example
22+
-------
23+
24+
firmware {
25+
zynqmp_firmware: zynqmp-firmware {
26+
compatible = "xlnx,zynqmp-firmware";
27+
method = "smc";
28+
};
29+
};

‎arch/arm64/Kconfig.platforms‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ config ARCH_ZX
301301

302302
config ARCH_ZYNQMP
303303
bool "Xilinx ZynqMP Family"
304+
select ZYNQMP_FIRMWARE
304305
help
305306
This enables support for Xilinx ZynqMP Family
306307

‎drivers/firmware/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,5 +291,6 @@ source "drivers/firmware/google/Kconfig"
291291
source "drivers/firmware/efi/Kconfig"
292292
source "drivers/firmware/meson/Kconfig"
293293
source "drivers/firmware/tegra/Kconfig"
294+
source "drivers/firmware/xilinx/Kconfig"
294295

295296
endmenu

‎drivers/firmware/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ obj-$(CONFIG_GOOGLE_FIRMWARE) += google/
3232
obj-$(CONFIG_EFI) += efi/
3333
obj-$(CONFIG_UEFI_CPER) += efi/
3434
obj-y += tegra/
35+
obj-y += xilinx/

‎drivers/firmware/xilinx/Kconfig‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
# Kconfig for Xilinx firmwares
3+
4+
menu "Zynq MPSoC Firmware Drivers"
5+
depends on ARCH_ZYNQMP
6+
7+
config ZYNQMP_FIRMWARE
8+
bool "Enable Xilinx Zynq MPSoC firmware interface"
9+
help
10+
Firmware interface driver is used by different
11+
drivers to communicate with the firmware for
12+
various platform management services.
13+
Say yes to enable ZynqMP firmware interface driver.
14+
If in doubt, say N.
15+
16+
config ZYNQMP_FIRMWARE_DEBUG
17+
bool "Enable Xilinx Zynq MPSoC firmware debug APIs"
18+
depends on ZYNQMP_FIRMWARE && DEBUG_FS
19+
help
20+
Say yes to enable ZynqMP firmware interface debug APIs.
21+
If in doubt, say N.
22+
23+
endmenu

‎drivers/firmware/xilinx/Makefile‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
# Makefile for Xilinx firmwares
3+
4+
obj-$(CONFIG_ZYNQMP_FIRMWARE) += zynqmp.o
5+
obj-$(CONFIG_ZYNQMP_FIRMWARE_DEBUG) += zynqmp-debug.o
Lines changed: 250 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Xilinx Zynq MPSoC Firmware layer for debugfs APIs
4+
*
5+
* Copyright (C) 2014-2018 Xilinx, Inc.
6+
*
7+
* Michal Simek <michal.simek@xilinx.com>
8+
* Davorin Mista <davorin.mista@aggios.com>
9+
* Jolly Shah <jollys@xilinx.com>
10+
* Rajan Vaja <rajanv@xilinx.com>
11+
*/
12+
13+
#include <linux/compiler.h>
14+
#include <linux/module.h>
15+
#include <linux/slab.h>
16+
#include <linux/debugfs.h>
17+
#include <linux/uaccess.h>
18+
19+
#include <linux/firmware/xlnx-zynqmp.h>
20+
#include "zynqmp-debug.h"
21+
22+
#define PM_API_NAME_LEN 50
23+
24+
struct pm_api_info {
25+
u32 api_id;
26+
char api_name[PM_API_NAME_LEN];
27+
char api_name_len;
28+
};
29+
30+
static char debugfs_buf[PAGE_SIZE];
31+
32+
#define PM_API(id) {id, #id, strlen(#id)}
33+
static struct pm_api_info pm_api_list[] = {
34+
PM_API(PM_GET_API_VERSION),
35+
PM_API(PM_QUERY_DATA),
36+
};
37+
38+
struct dentry *firmware_debugfs_root;
39+
40+
/**
41+
* zynqmp_pm_argument_value() - Extract argument value from a PM-API request
42+
* @arg: Entered PM-API argument in string format
43+
*
44+
* Return: Argument value in unsigned integer format on success
45+
* 0 otherwise
46+
*/
47+
static u64 zynqmp_pm_argument_value(char *arg)
48+
{
49+
u64 value;
50+
51+
if (!arg)
52+
return 0;
53+
54+
if (!kstrtou64(arg, 0, &value))
55+
return value;
56+
57+
return 0;
58+
}
59+
60+
/**
61+
* get_pm_api_id() - Extract API-ID from a PM-API request
62+
* @pm_api_req: Entered PM-API argument in string format
63+
* @pm_id: API-ID
64+
*
65+
* Return: 0 on success else error code
66+
*/
67+
static int get_pm_api_id(char *pm_api_req, u32 *pm_id)
68+
{
69+
int i;
70+
71+
for (i = 0; i < ARRAY_SIZE(pm_api_list) ; i++) {
72+
if (!strncasecmp(pm_api_req, pm_api_list[i].api_name,
73+
pm_api_list[i].api_name_len)) {
74+
*pm_id = pm_api_list[i].api_id;
75+
break;
76+
}
77+
}
78+
79+
/* If no name was entered look for PM-API ID instead */
80+
if (i == ARRAY_SIZE(pm_api_list) && kstrtouint(pm_api_req, 10, pm_id))
81+
return -EINVAL;
82+
83+
return 0;
84+
}
85+
86+
static int process_api_request(u32 pm_id, u64 *pm_api_arg, u32 *pm_api_ret)
87+
{
88+
const struct zynqmp_eemi_ops *eemi_ops = zynqmp_pm_get_eemi_ops();
89+
u32 pm_api_version;
90+
int ret;
91+
struct zynqmp_pm_query_data qdata = {0};
92+
93+
if (!eemi_ops)
94+
return -ENXIO;
95+
96+
switch (pm_id) {
97+
case PM_GET_API_VERSION:
98+
ret = eemi_ops->get_api_version(&pm_api_version);
99+
sprintf(debugfs_buf, "PM-API Version = %d.%d\n",
100+
pm_api_version >> 16, pm_api_version & 0xffff);
101+
break;
102+
case PM_QUERY_DATA:
103+
qdata.qid = pm_api_arg[0];
104+
qdata.arg1 = pm_api_arg[1];
105+
qdata.arg2 = pm_api_arg[2];
106+
qdata.arg3 = pm_api_arg[3];
107+
108+
ret = eemi_ops->query_data(qdata, pm_api_ret);
109+
if (ret)
110+
break;
111+
112+
switch (qdata.qid) {
113+
case PM_QID_CLOCK_GET_NAME:
114+
sprintf(debugfs_buf, "Clock name = %s\n",
115+
(char *)pm_api_ret);
116+
break;
117+
case PM_QID_CLOCK_GET_FIXEDFACTOR_PARAMS:
118+
sprintf(debugfs_buf, "Multiplier = %d, Divider = %d\n",
119+
pm_api_ret[1], pm_api_ret[2]);
120+
break;
121+
default:
122+
sprintf(debugfs_buf,
123+
"data[0] = 0x%08x\ndata[1] = 0x%08x\n data[2] = 0x%08x\ndata[3] = 0x%08x\n",
124+
pm_api_ret[0], pm_api_ret[1],
125+
pm_api_ret[2], pm_api_ret[3]);
126+
}
127+
break;
128+
default:
129+
sprintf(debugfs_buf, "Unsupported PM-API request\n");
130+
ret = -EINVAL;
131+
}
132+
133+
return ret;
134+
}
135+
136+
/**
137+
* zynqmp_pm_debugfs_api_write() - debugfs write function
138+
* @file: User file
139+
* @ptr: User entered PM-API string
140+
* @len: Length of the userspace buffer
141+
* @off: Offset within the file
142+
*
143+
* Used for triggering pm api functions by writing
144+
* echo <pm_api_id> > /sys/kernel/debug/zynqmp_pm/power or
145+
* echo <pm_api_name> > /sys/kernel/debug/zynqmp_pm/power
146+
*
147+
* Return: Number of bytes copied if PM-API request succeeds,
148+
* the corresponding error code otherwise
149+
*/
150+
static ssize_t zynqmp_pm_debugfs_api_write(struct file *file,
151+
const char __user *ptr, size_t len,
152+
loff_t *off)
153+
{
154+
char *kern_buff, *tmp_buff;
155+
char *pm_api_req;
156+
u32 pm_id = 0;
157+
u64 pm_api_arg[4] = {0, 0, 0, 0};
158+
/* Return values from PM APIs calls */
159+
u32 pm_api_ret[4] = {0, 0, 0, 0};
160+
161+
int ret;
162+
int i = 0;
163+
164+
strcpy(debugfs_buf, "");
165+
166+
if (*off != 0 || len == 0)
167+
return -EINVAL;
168+
169+
kern_buff = kzalloc(len, GFP_KERNEL);
170+
if (!kern_buff)
171+
return -ENOMEM;
172+
173+
tmp_buff = kern_buff;
174+
175+
ret = strncpy_from_user(kern_buff, ptr, len);
176+
if (ret < 0) {
177+
ret = -EFAULT;
178+
goto err;
179+
}
180+
181+
/* Read the API name from a user request */
182+
pm_api_req = strsep(&kern_buff, " ");
183+
184+
ret = get_pm_api_id(pm_api_req, &pm_id);
185+
if (ret < 0)
186+
goto err;
187+
188+
/* Read node_id and arguments from the PM-API request */
189+
pm_api_req = strsep(&kern_buff, " ");
190+
while ((i < ARRAY_SIZE(pm_api_arg)) && pm_api_req) {
191+
pm_api_arg[i++] = zynqmp_pm_argument_value(pm_api_req);
192+
pm_api_req = strsep(&kern_buff, " ");
193+
}
194+
195+
ret = process_api_request(pm_id, pm_api_arg, pm_api_ret);
196+
197+
err:
198+
kfree(tmp_buff);
199+
if (ret)
200+
return ret;
201+
202+
return len;
203+
}
204+
205+
/**
206+
* zynqmp_pm_debugfs_api_read() - debugfs read function
207+
* @file: User file
208+
* @ptr: Requested pm_api_version string
209+
* @len: Length of the userspace buffer
210+
* @off: Offset within the file
211+
*
212+
* Return: Length of the version string on success
213+
* else error code
214+
*/
215+
static ssize_t zynqmp_pm_debugfs_api_read(struct file *file, char __user *ptr,
216+
size_t len, loff_t *off)
217+
{
218+
return simple_read_from_buffer(ptr, len, off, debugfs_buf,
219+
strlen(debugfs_buf));
220+
}
221+
222+
/* Setup debugfs fops */
223+
static const struct file_operations fops_zynqmp_pm_dbgfs = {
224+
.owner = THIS_MODULE,
225+
.write = zynqmp_pm_debugfs_api_write,
226+
.read = zynqmp_pm_debugfs_api_read,
227+
};
228+
229+
/**
230+
* zynqmp_pm_api_debugfs_init - Initialize debugfs interface
231+
*
232+
* Return: None
233+
*/
234+
void zynqmp_pm_api_debugfs_init(void)
235+
{
236+
/* Initialize debugfs interface */
237+
firmware_debugfs_root = debugfs_create_dir("zynqmp-firmware", NULL);
238+
debugfs_create_file("pm", 0660, firmware_debugfs_root, NULL,
239+
&fops_zynqmp_pm_dbgfs);
240+
}
241+
242+
/**
243+
* zynqmp_pm_api_debugfs_exit - Remove debugfs interface
244+
*
245+
* Return: None
246+
*/
247+
void zynqmp_pm_api_debugfs_exit(void)
248+
{
249+
debugfs_remove_recursive(firmware_debugfs_root);
250+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/*
3+
* Xilinx Zynq MPSoC Firmware layer
4+
*
5+
* Copyright (C) 2014-2018 Xilinx
6+
*
7+
* Michal Simek <michal.simek@xilinx.com>
8+
* Davorin Mista <davorin.mista@aggios.com>
9+
* Jolly Shah <jollys@xilinx.com>
10+
* Rajan Vaja <rajanv@xilinx.com>
11+
*/
12+
13+
#ifndef __FIRMWARE_ZYNQMP_DEBUG_H__
14+
#define __FIRMWARE_ZYNQMP_DEBUG_H__
15+
16+
#if IS_REACHABLE(CONFIG_ZYNQMP_FIRMWARE_DEBUG)
17+
void zynqmp_pm_api_debugfs_init(void);
18+
void zynqmp_pm_api_debugfs_exit(void);
19+
#else
20+
static inline void zynqmp_pm_api_debugfs_init(void) { }
21+
static inline void zynqmp_pm_api_debugfs_exit(void) { }
22+
#endif
23+
24+
#endif /* __FIRMWARE_ZYNQMP_DEBUG_H__ */

0 commit comments

Comments
 (0)