Skip to content

Commit 782b726

Browse files
committed
Merge tag 'zynqmp-soc2-for-6.11' of https://github.com/Xilinx/linux-xlnx into soc/drivers
arm64: Xilinx SoC changes for 6.11 Timer - Fix u32 overflow issue in 32-bit width PWM mode. Event manager: - rename cpu_number1 to dummy_cpu_number Power: - Add cb event for subsystem restart - check return status of get_api_version() Firmware: - Move FIRMWARE_VERSION_MASK to xlnx-zynqmp.h * tag 'zynqmp-soc2-for-6.11' of https://github.com/Xilinx/linux-xlnx: drivers: soc: xilinx: check return status of get_api_version() firmware: xilinx: Move FIRMWARE_VERSION_MASK to xlnx-zynqmp.h soc: xilinx: Add cb event for subsystem restart soc: xilinx: rename cpu_number1 to dummy_cpu_number pwm: xilinx: Fix u32 overflow issue in 32-bit width PWM mode. Link: https://lore.kernel.org/r/CAHTX3dKMtqgNpkEvrw0p2w+SPN83Ai1_kzhefUGOO5rMkPaH_w@mail.gmail.com Signed-off-by: Arnd Bergmann <[email protected]>
2 parents dc3c836 + 9b003e1 commit 782b726

File tree

6 files changed

+152
-37
lines changed

6 files changed

+152
-37
lines changed

drivers/firmware/xilinx/zynqmp.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@
4141
/* IOCTL/QUERY feature payload size */
4242
#define FEATURE_PAYLOAD_SIZE 2
4343

44-
/* Firmware feature check version mask */
45-
#define FIRMWARE_VERSION_MASK GENMASK(15, 0)
46-
4744
static bool feature_check_enabled;
4845
static DEFINE_HASHTABLE(pm_api_features_map, PM_API_FEATURE_CHECK_MAX_ORDER);
4946
static u32 ioctl_features[FEATURE_PAYLOAD_SIZE];

drivers/soc/xilinx/xlnx_event_manager.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Xilinx Event Management Driver
44
*
55
* Copyright (C) 2021 Xilinx, Inc.
6+
* Copyright (C) 2024 Advanced Micro Devices, Inc.
67
*
78
* Abhyuday Godhasara <[email protected]>
89
*/
@@ -19,7 +20,7 @@
1920
#include <linux/platform_device.h>
2021
#include <linux/slab.h>
2122

22-
static DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number1);
23+
static DEFINE_PER_CPU_READ_MOSTLY(int, dummy_cpu_number);
2324

2425
static int virq_sgi;
2526
static int event_manager_availability = -EACCES;
@@ -35,7 +36,6 @@ static int event_manager_availability = -EACCES;
3536

3637
#define MAX_BITS (32U) /* Number of bits available for error mask */
3738

38-
#define FIRMWARE_VERSION_MASK (0xFFFFU)
3939
#define REGISTER_NOTIFIER_FIRMWARE_VERSION (2U)
4040

4141
static DEFINE_HASHTABLE(reg_driver_map, REGISTERED_DRIVER_MAX_ORDER);
@@ -570,7 +570,6 @@ static void xlnx_disable_percpu_irq(void *data)
570570
static int xlnx_event_init_sgi(struct platform_device *pdev)
571571
{
572572
int ret = 0;
573-
int cpu;
574573
/*
575574
* IRQ related structures are used for the following:
576575
* for each SGI interrupt ensure its mapped by GIC IRQ domain
@@ -607,11 +606,8 @@ static int xlnx_event_init_sgi(struct platform_device *pdev)
607606
sgi_fwspec.param[0] = sgi_num;
608607
virq_sgi = irq_create_fwspec_mapping(&sgi_fwspec);
609608

610-
cpu = get_cpu();
611-
per_cpu(cpu_number1, cpu) = cpu;
612609
ret = request_percpu_irq(virq_sgi, xlnx_event_handler, "xlnx_event_mgmt",
613-
&cpu_number1);
614-
put_cpu();
610+
&dummy_cpu_number);
615611

616612
WARN_ON(ret);
617613
if (ret) {
@@ -627,16 +623,12 @@ static int xlnx_event_init_sgi(struct platform_device *pdev)
627623

628624
static void xlnx_event_cleanup_sgi(struct platform_device *pdev)
629625
{
630-
int cpu = smp_processor_id();
631-
632-
per_cpu(cpu_number1, cpu) = cpu;
633-
634626
cpuhp_remove_state(CPUHP_AP_ONLINE_DYN);
635627

636628
on_each_cpu(xlnx_disable_percpu_irq, NULL, 1);
637629

638630
irq_clear_status_flags(virq_sgi, IRQ_PER_CPU);
639-
free_percpu_irq(virq_sgi, &cpu_number1);
631+
free_percpu_irq(virq_sgi, &dummy_cpu_number);
640632
irq_dispose_mapping(virq_sgi);
641633
}
642634

drivers/soc/xilinx/zynqmp_power.c

Lines changed: 134 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,27 @@ struct zynqmp_pm_work_struct {
3030
u32 args[CB_ARG_CNT];
3131
};
3232

33-
static struct zynqmp_pm_work_struct *zynqmp_pm_init_suspend_work;
33+
/**
34+
* struct zynqmp_pm_event_info - event related information
35+
* @cb_fun: Function pointer to store the callback function.
36+
* @cb_type: Type of callback from pm_api_cb_id,
37+
* PM_NOTIFY_CB - for Error Events,
38+
* PM_INIT_SUSPEND_CB - for suspend callback.
39+
* @node_id: Node-Id related to event.
40+
* @event: Event Mask for the Error Event.
41+
* @wake: Flag specifying whether the subsystem should be woken upon
42+
* event notification.
43+
*/
44+
struct zynqmp_pm_event_info {
45+
event_cb_func_t cb_fun;
46+
enum pm_api_cb_id cb_type;
47+
u32 node_id;
48+
u32 event;
49+
bool wake;
50+
};
51+
52+
static struct zynqmp_pm_work_struct *zynqmp_pm_init_suspend_work, *zynqmp_pm_init_restart_work;
3453
static struct mbox_chan *rx_chan;
35-
static bool event_registered;
3654

3755
enum pm_suspend_mode {
3856
PM_SUSPEND_MODE_FIRST = 0,
@@ -54,6 +72,19 @@ static void zynqmp_pm_get_callback_data(u32 *buf)
5472
zynqmp_pm_invoke_fn(GET_CALLBACK_DATA, buf, 0);
5573
}
5674

75+
static void subsystem_restart_event_callback(const u32 *payload, void *data)
76+
{
77+
/* First element is callback API ID, others are callback arguments */
78+
if (work_pending(&zynqmp_pm_init_restart_work->callback_work))
79+
return;
80+
81+
/* Copy callback arguments into work's structure */
82+
memcpy(zynqmp_pm_init_restart_work->args, &payload[0],
83+
sizeof(zynqmp_pm_init_restart_work->args));
84+
85+
queue_work(system_unbound_wq, &zynqmp_pm_init_restart_work->callback_work);
86+
}
87+
5788
static void suspend_event_callback(const u32 *payload, void *data)
5889
{
5990
/* First element is callback API ID, others are callback arguments */
@@ -119,6 +150,37 @@ static void ipi_receive_callback(struct mbox_client *cl, void *data)
119150
}
120151
}
121152

153+
/**
154+
* zynqmp_pm_subsystem_restart_work_fn - Initiate Subsystem restart
155+
* @work: Pointer to work_struct
156+
*
157+
* Bottom-half of PM callback IRQ handler.
158+
*/
159+
static void zynqmp_pm_subsystem_restart_work_fn(struct work_struct *work)
160+
{
161+
int ret;
162+
struct zynqmp_pm_work_struct *pm_work = container_of(work, struct zynqmp_pm_work_struct,
163+
callback_work);
164+
165+
/* First element is callback API ID, others are callback arguments */
166+
if (pm_work->args[0] == PM_NOTIFY_CB) {
167+
if (pm_work->args[2] == EVENT_SUBSYSTEM_RESTART) {
168+
ret = zynqmp_pm_system_shutdown(ZYNQMP_PM_SHUTDOWN_TYPE_SETSCOPE_ONLY,
169+
ZYNQMP_PM_SHUTDOWN_SUBTYPE_SUBSYSTEM);
170+
if (ret) {
171+
pr_err("unable to set shutdown scope\n");
172+
return;
173+
}
174+
175+
kernel_restart(NULL);
176+
} else {
177+
pr_err("%s Unsupported Event - %d\n", __func__, pm_work->args[2]);
178+
}
179+
} else {
180+
pr_err("%s() Unsupported Callback %d\n", __func__, pm_work->args[0]);
181+
}
182+
}
183+
122184
/**
123185
* zynqmp_pm_init_suspend_work_fn - Initialize suspend
124186
* @work: Pointer to work_struct
@@ -184,13 +246,51 @@ static ssize_t suspend_mode_store(struct device *dev,
184246

185247
static DEVICE_ATTR_RW(suspend_mode);
186248

249+
static void unregister_event(struct device *dev, void *res)
250+
{
251+
struct zynqmp_pm_event_info *event_info = res;
252+
253+
xlnx_unregister_event(event_info->cb_type, event_info->node_id,
254+
event_info->event, event_info->cb_fun, NULL);
255+
}
256+
257+
static int register_event(struct device *dev, const enum pm_api_cb_id cb_type, const u32 node_id,
258+
const u32 event, const bool wake, event_cb_func_t cb_fun)
259+
{
260+
int ret;
261+
struct zynqmp_pm_event_info *event_info;
262+
263+
event_info = devres_alloc(unregister_event, sizeof(struct zynqmp_pm_event_info),
264+
GFP_KERNEL);
265+
if (!event_info)
266+
return -ENOMEM;
267+
268+
event_info->cb_type = cb_type;
269+
event_info->node_id = node_id;
270+
event_info->event = event;
271+
event_info->wake = wake;
272+
event_info->cb_fun = cb_fun;
273+
274+
ret = xlnx_register_event(event_info->cb_type, event_info->node_id,
275+
event_info->event, event_info->wake, event_info->cb_fun, NULL);
276+
if (ret) {
277+
devres_free(event_info);
278+
return ret;
279+
}
280+
281+
devres_add(dev, event_info);
282+
return 0;
283+
}
284+
187285
static int zynqmp_pm_probe(struct platform_device *pdev)
188286
{
189287
int ret, irq;
190-
u32 pm_api_version;
288+
u32 pm_api_version, pm_family_code, pm_sub_family_code, node_id;
191289
struct mbox_client *client;
192290

193-
zynqmp_pm_get_api_version(&pm_api_version);
291+
ret = zynqmp_pm_get_api_version(&pm_api_version);
292+
if (ret)
293+
return ret;
194294

195295
/* Check PM API version number */
196296
if (pm_api_version < ZYNQMP_PM_VERSION)
@@ -203,21 +303,43 @@ static int zynqmp_pm_probe(struct platform_device *pdev)
203303
* is not available to use) or -ENODEV(Xilinx Event Manager not compiled),
204304
* then use ipi-mailbox or interrupt method.
205305
*/
206-
ret = xlnx_register_event(PM_INIT_SUSPEND_CB, 0, 0, false,
207-
suspend_event_callback, NULL);
306+
ret = register_event(&pdev->dev, PM_INIT_SUSPEND_CB, 0, 0, false,
307+
suspend_event_callback);
208308
if (!ret) {
209309
zynqmp_pm_init_suspend_work = devm_kzalloc(&pdev->dev,
210310
sizeof(struct zynqmp_pm_work_struct),
211311
GFP_KERNEL);
212-
if (!zynqmp_pm_init_suspend_work) {
213-
xlnx_unregister_event(PM_INIT_SUSPEND_CB, 0, 0,
214-
suspend_event_callback, NULL);
312+
if (!zynqmp_pm_init_suspend_work)
215313
return -ENOMEM;
216-
}
217-
event_registered = true;
218314

219315
INIT_WORK(&zynqmp_pm_init_suspend_work->callback_work,
220316
zynqmp_pm_init_suspend_work_fn);
317+
318+
ret = zynqmp_pm_get_family_info(&pm_family_code, &pm_sub_family_code);
319+
if (ret < 0)
320+
return ret;
321+
322+
if (pm_sub_family_code == VERSALNET_SUB_FAMILY_CODE)
323+
node_id = PM_DEV_ACPU_0_0;
324+
else
325+
node_id = PM_DEV_ACPU_0;
326+
327+
ret = register_event(&pdev->dev, PM_NOTIFY_CB, node_id, EVENT_SUBSYSTEM_RESTART,
328+
false, subsystem_restart_event_callback);
329+
if (ret) {
330+
dev_err(&pdev->dev, "Failed to Register with Xilinx Event manager %d\n",
331+
ret);
332+
return ret;
333+
}
334+
335+
zynqmp_pm_init_restart_work = devm_kzalloc(&pdev->dev,
336+
sizeof(struct zynqmp_pm_work_struct),
337+
GFP_KERNEL);
338+
if (!zynqmp_pm_init_restart_work)
339+
return -ENOMEM;
340+
341+
INIT_WORK(&zynqmp_pm_init_restart_work->callback_work,
342+
zynqmp_pm_subsystem_restart_work_fn);
221343
} else if (ret != -EACCES && ret != -ENODEV) {
222344
dev_err(&pdev->dev, "Failed to Register with Xilinx Event manager %d\n", ret);
223345
return ret;
@@ -264,24 +386,15 @@ static int zynqmp_pm_probe(struct platform_device *pdev)
264386
}
265387

266388
ret = sysfs_create_file(&pdev->dev.kobj, &dev_attr_suspend_mode.attr);
267-
if (ret) {
268-
if (event_registered) {
269-
xlnx_unregister_event(PM_INIT_SUSPEND_CB, 0, 0, suspend_event_callback,
270-
NULL);
271-
event_registered = false;
272-
}
273-
dev_err(&pdev->dev, "unable to create sysfs interface\n");
389+
if (ret)
274390
return ret;
275-
}
276391

277392
return 0;
278393
}
279394

280395
static void zynqmp_pm_remove(struct platform_device *pdev)
281396
{
282397
sysfs_remove_file(&pdev->dev.kobj, &dev_attr_suspend_mode.attr);
283-
if (event_registered)
284-
xlnx_unregister_event(PM_INIT_SUSPEND_CB, 0, 0, suspend_event_callback, NULL);
285398

286399
if (!rx_chan)
287400
mbox_free_channel(rx_chan);

include/clocksource/timer-xilinx.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct regmap;
4141
struct xilinx_timer_priv {
4242
struct regmap *map;
4343
struct clk *clk;
44-
u32 max;
44+
u64 max;
4545
};
4646

4747
/**

include/linux/firmware/xlnx-event-manager.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
/* SPDX-License-Identifier: GPL-2.0 */
2+
/*
3+
* Xilinx Event Management Driver
4+
*
5+
* Copyright (C) 2024, Advanced Micro Devices, Inc.
6+
*/
27

38
#ifndef _FIRMWARE_XLNX_EVENT_MANAGER_H_
49
#define _FIRMWARE_XLNX_EVENT_MANAGER_H_
@@ -7,6 +12,11 @@
712

813
#define CB_MAX_PAYLOAD_SIZE (4U) /*In payload maximum 32bytes */
914

15+
#define EVENT_SUBSYSTEM_RESTART (4U)
16+
17+
#define PM_DEV_ACPU_0_0 (0x1810c0afU)
18+
#define PM_DEV_ACPU_0 (0x1810c003U)
19+
1020
/************************** Exported Function *****************************/
1121

1222
typedef void (*event_cb_func_t)(const u32 *payload, void *data);

include/linux/firmware/xlnx-zynqmp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
#define API_ID_MASK GENMASK(7, 0)
5353
#define MODULE_ID_MASK GENMASK(11, 8)
5454

55+
/* Firmware feature check version mask */
56+
#define FIRMWARE_VERSION_MASK 0xFFFFU
57+
5558
/* ATF only commands */
5659
#define TF_A_PM_REGISTER_SGI 0xa04
5760
#define PM_GET_TRUSTZONE_VERSION 0xa03

0 commit comments

Comments
 (0)