2023-08-07 13:11:30

by Peng Fan (OSS)

[permalink] [raw]
Subject: [PATCH V6 0/8] firmware: imx: scu/scu-irq: misc update

From: Peng Fan <[email protected]>

V6:
Typo fix
Update commit message
Drop Patch v5 3/9
code style and error path check in patch 8

V5:
Address sparse checking in patch 9
Add a new patch 5

V4:
Add static inline for irq get status when SCU not defined
Drop two patches wrongly included

V3:
Fix build error reported by kernel robot
Add patch subject-prefix

V2:
Fix build warning

Dong Aisheng (2):
firmware: imx: scu: change init level to subsys_initcall_sync
firmware: imx: scu: increase RPC timeout

Peng Fan (4):
firmware: imx: scu: use soc name for soc_id
firmware: imx: scu: use EOPNOTSUPP
firmware: imx: scu-irq: add imx_scu_irq_get_status
firmware: imx: scu-irq: enlarge the IMX_SC_IRQ_NUM_GROUP

Ranjani Vaidyanathan (1):
firmware: imx: scu-irq: support identifying SCU wakeup source from
sysfs

Robin Gong (1):
firmware: imx: scu-irq: fix RCU complaint after M4 partition reset

drivers/firmware/imx/imx-scu-irq.c | 118 ++++++++++++++++++++++++-----
drivers/firmware/imx/imx-scu-soc.c | 20 ++++-
drivers/firmware/imx/imx-scu.c | 9 ++-
include/linux/firmware/imx/sci.h | 16 ++--
4 files changed, 136 insertions(+), 27 deletions(-)

--
2.37.1



2023-08-07 13:12:05

by Peng Fan (OSS)

[permalink] [raw]
Subject: [PATCH V6 3/8] firmware: imx: scu: use soc name for soc_id

From: Peng Fan <[email protected]>

Same as soc-imx8m and soc-imx driver, use soc name for soc_id which is
user friendly.

Signed-off-by: Peng Fan <[email protected]>
---
drivers/firmware/imx/imx-scu-soc.c | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/drivers/firmware/imx/imx-scu-soc.c b/drivers/firmware/imx/imx-scu-soc.c
index 2f32353de2c9..497192320562 100644
--- a/drivers/firmware/imx/imx-scu-soc.c
+++ b/drivers/firmware/imx/imx-scu-soc.c
@@ -78,6 +78,22 @@ static int imx_scu_soc_id(void)
return msg.data.resp.id;
}

+static const char *imx_scu_soc_name(u32 id)
+{
+ switch (id) {
+ case 0x1:
+ return "i.MX8QM";
+ case 0x2:
+ return "i.MX8QXP";
+ case 0xe:
+ return "i.MX8DXL";
+ default:
+ break;
+ }
+
+ return "NULL";
+}
+
int imx_scu_soc_init(struct device *dev)
{
struct soc_device_attribute *soc_dev_attr;
@@ -113,9 +129,7 @@ int imx_scu_soc_init(struct device *dev)

/* format soc_id value passed from SCU firmware */
val = id & 0x1f;
- soc_dev_attr->soc_id = devm_kasprintf(dev, GFP_KERNEL, "0x%x", val);
- if (!soc_dev_attr->soc_id)
- return -ENOMEM;
+ soc_dev_attr->soc_id = imx_scu_soc_name(val);

/* format revision value passed from SCU firmware */
val = (id >> 5) & 0xf;
--
2.37.1


2023-08-07 13:22:47

by Peng Fan (OSS)

[permalink] [raw]
Subject: [PATCH V6 5/8] firmware: imx: scu-irq: fix RCU complaint after M4 partition reset

From: Robin Gong <[email protected]>

Use blocking_notifier_chain instead of atomic_notifier_chain, otherwise
there will be RCU complaint, because unregister/register_virtio_device()
will issue mbox message.

mbox_send_message() is blocking again after received M4 partition reset.

Actually, no need atomic notifier for scu irq notification since this
notifier is called in worker instead of interrupt handler.

[ 389.706645] i2c-rpmsg virtio0.rpmsg-i2c-channel.-1.2: i2c rpmsg driver is removed
[ 389.767362] Wait for remote ready timeout, use first_notify.
[ 389.774084] ------------[ cut here ]------------
[ 389.778729] WARNING: CPU: 0 PID: 397 at kernel/rcu/tree_plugin.h:293 rcu_note_context_switch+0x34/0x338
[ 389.788131] Modules linked in:
[ 389.791195] CPU: 0 PID: 397 Comm: kworker/0:13 Not tainted 5.4.0-rc5-02977-g08f78722f07b #26
[ 389.799633] Hardware name: Freescale i.MX8DXL MEK (DT)
[ 389.805481] Workqueue: events imx_scu_irq_work_handler

Signed-off-by: Robin Gong <[email protected]>
Reviewed-by: Dong Aisheng <[email protected]>
Signed-off-by: Peng Fan <[email protected]>
---
drivers/firmware/imx/imx-scu-irq.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/firmware/imx/imx-scu-irq.c b/drivers/firmware/imx/imx-scu-irq.c
index d9dcc20945c6..4408f150b3d5 100644
--- a/drivers/firmware/imx/imx-scu-irq.c
+++ b/drivers/firmware/imx/imx-scu-irq.c
@@ -42,25 +42,25 @@ struct imx_sc_msg_irq_enable {

static struct imx_sc_ipc *imx_sc_irq_ipc_handle;
static struct work_struct imx_sc_irq_work;
-static ATOMIC_NOTIFIER_HEAD(imx_scu_irq_notifier_chain);
+static BLOCKING_NOTIFIER_HEAD(imx_scu_irq_notifier_chain);

int imx_scu_irq_register_notifier(struct notifier_block *nb)
{
- return atomic_notifier_chain_register(
+ return blocking_notifier_chain_register(
&imx_scu_irq_notifier_chain, nb);
}
EXPORT_SYMBOL(imx_scu_irq_register_notifier);

int imx_scu_irq_unregister_notifier(struct notifier_block *nb)
{
- return atomic_notifier_chain_unregister(
+ return blocking_notifier_chain_unregister(
&imx_scu_irq_notifier_chain, nb);
}
EXPORT_SYMBOL(imx_scu_irq_unregister_notifier);

static int imx_scu_irq_notifier_call_chain(unsigned long status, u8 *group)
{
- return atomic_notifier_call_chain(&imx_scu_irq_notifier_chain,
+ return blocking_notifier_call_chain(&imx_scu_irq_notifier_chain,
status, (void *)group);
}

--
2.37.1


2023-08-07 13:54:38

by Peng Fan (OSS)

[permalink] [raw]
Subject: [PATCH V6 7/8] firmware: imx: scu-irq: enlarge the IMX_SC_IRQ_NUM_GROUP

From: Peng Fan <[email protected]>

Per SCFW update, update the IMX_SC_IRQ_NUM_GROUP to 9.

Signed-off-by: Peng Fan <[email protected]>
---
drivers/firmware/imx/imx-scu-irq.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/firmware/imx/imx-scu-irq.c b/drivers/firmware/imx/imx-scu-irq.c
index 6549f3792a0f..8d902db1daf2 100644
--- a/drivers/firmware/imx/imx-scu-irq.c
+++ b/drivers/firmware/imx/imx-scu-irq.c
@@ -14,7 +14,7 @@

#define IMX_SC_IRQ_FUNC_ENABLE 1
#define IMX_SC_IRQ_FUNC_STATUS 2
-#define IMX_SC_IRQ_NUM_GROUP 4
+#define IMX_SC_IRQ_NUM_GROUP 9

static u32 mu_resource_id;

--
2.37.1


2023-08-07 14:29:20

by Peng Fan (OSS)

[permalink] [raw]
Subject: [PATCH V6 8/8] firmware: imx: scu-irq: support identifying SCU wakeup source from sysfs

From: Ranjani Vaidyanathan <[email protected]>

Record SCU wakeup interrupt in /sys/power/pm_wakeup_irq
The user can further identify the exact wakeup source by using the
following interface:
cat /sys/firmware/scu_wakeup_source/wakeup_src

The above will print the wake groups and the irqs that could have
contributed to waking up the kernel. For example if ON/OFF button was the
wakeup source:
cat /sys/firmware/scu_wakeup_source/wakeup_src
Wakeup source group = 3, irq = 0x1

The user can refer to the SCFW API documentation to identify all the
wake groups and irqs.

Signed-off-by: Ranjani Vaidyanathan <[email protected]>
Signed-off-by: Peng Fan <[email protected]>
---
drivers/firmware/imx/imx-scu-irq.c | 70 ++++++++++++++++++++++++++++++
1 file changed, 70 insertions(+)

diff --git a/drivers/firmware/imx/imx-scu-irq.c b/drivers/firmware/imx/imx-scu-irq.c
index 8d902db1daf2..7cc0dec04587 100644
--- a/drivers/firmware/imx/imx-scu-irq.c
+++ b/drivers/firmware/imx/imx-scu-irq.c
@@ -9,8 +9,10 @@
#include <dt-bindings/firmware/imx/rsrc.h>
#include <linux/firmware/imx/ipc.h>
#include <linux/firmware/imx/sci.h>
+#include <linux/kobject.h>
#include <linux/mailbox_client.h>
#include <linux/suspend.h>
+#include <linux/sysfs.h>

#define IMX_SC_IRQ_FUNC_ENABLE 1
#define IMX_SC_IRQ_FUNC_STATUS 2
@@ -40,6 +42,20 @@ struct imx_sc_msg_irq_enable {
u8 enable;
} __packed;

+struct scu_wakeup {
+ u32 mask;
+ u32 wakeup_src;
+ bool valid;
+};
+
+/* Sysfs functions */
+static struct kobject *wakeup_obj;
+static ssize_t wakeup_source_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf);
+static struct kobj_attribute wakeup_source_attr =
+ __ATTR(wakeup_src, 0660, wakeup_source_show, NULL);
+
+static struct scu_wakeup scu_irq_wakeup[IMX_SC_IRQ_NUM_GROUP];
+
static struct imx_sc_ipc *imx_sc_irq_ipc_handle;
static struct work_struct imx_sc_irq_work;
static BLOCKING_NOTIFIER_HEAD(imx_scu_irq_notifier_chain);
@@ -71,6 +87,11 @@ static void imx_scu_irq_work_handler(struct work_struct *work)
u8 i;

for (i = 0; i < IMX_SC_IRQ_NUM_GROUP; i++) {
+ if (scu_irq_wakeup[i].mask) {
+ scu_irq_wakeup[i].valid = false;
+ scu_irq_wakeup[i].wakeup_src = 0;
+ }
+
ret = imx_scu_irq_get_status(i, &irq_status);
if (ret) {
pr_err("get irq group %d status failed, ret %d\n",
@@ -80,6 +101,12 @@ static void imx_scu_irq_work_handler(struct work_struct *work)

if (!irq_status)
continue;
+ if (scu_irq_wakeup[i].mask & irq_status) {
+ scu_irq_wakeup[i].valid = true;
+ scu_irq_wakeup[i].wakeup_src = irq_status & scu_irq_wakeup[i].mask;
+ } else {
+ scu_irq_wakeup[i].wakeup_src = irq_status;
+ }

pm_system_wakeup();
imx_scu_irq_notifier_call_chain(irq_status, &i);
@@ -135,6 +162,11 @@ int imx_scu_irq_group_enable(u8 group, u32 mask, u8 enable)
pr_err("enable irq failed, group %d, mask %d, ret %d\n",
group, mask, ret);

+ if (enable)
+ scu_irq_wakeup[group].mask |= mask;
+ else
+ scu_irq_wakeup[group].mask &= ~mask;
+
return ret;
}
EXPORT_SYMBOL(imx_scu_irq_group_enable);
@@ -144,6 +176,25 @@ static void imx_scu_irq_callback(struct mbox_client *c, void *msg)
schedule_work(&imx_sc_irq_work);
}

+static ssize_t wakeup_source_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
+{
+ int i;
+
+ for (i = 0; i < IMX_SC_IRQ_NUM_GROUP; i++) {
+ if (!scu_irq_wakeup[i].wakeup_src)
+ continue;
+
+ if (scu_irq_wakeup[i].valid)
+ sprintf(buf, "Wakeup source group = %d, irq = 0x%x\n",
+ i, scu_irq_wakeup[i].wakeup_src);
+ else
+ sprintf(buf, "Spurious SCU wakeup, group = %d, irq = 0x%x\n",
+ i, scu_irq_wakeup[i].wakeup_src);
+ }
+
+ return strlen(buf);
+}
+
int imx_scu_enable_general_irq_channel(struct device *dev)
{
struct of_phandle_args spec;
@@ -183,6 +234,25 @@ int imx_scu_enable_general_irq_channel(struct device *dev)

mu_resource_id = IMX_SC_R_MU_0A + i;

+ /* Create directory under /sysfs/firmware */
+ wakeup_obj = kobject_create_and_add("scu_wakeup_source", firmware_kobj);
+ if (!wakeup_obj) {
+ ret = -ENOMEM;
+ goto free_ch;
+ }
+
+ ret = sysfs_create_file(wakeup_obj, &wakeup_source_attr.attr);
+ if (ret) {
+ dev_err(dev, "Cannot create wakeup source src file......\n");
+ kobject_put(wakeup_obj);
+ goto free_ch;
+ }
+
+ return 0;
+
+free_ch:
+ mbox_free_channel(ch);
+
return ret;
}
EXPORT_SYMBOL(imx_scu_enable_general_irq_channel);
--
2.37.1


2023-08-07 15:23:56

by Peng Fan (OSS)

[permalink] [raw]
Subject: [PATCH V6 4/8] firmware: imx: scu: use EOPNOTSUPP

From: Peng Fan <[email protected]>

Per checkpatch.pl, "ENOTSUPP is not a SUSV4 error code, prefer EOPNOTSUPP"
So use EOPNOTSUPP to replace ENOTSUPP.

Signed-off-by: Peng Fan <[email protected]>
---
include/linux/firmware/imx/sci.h | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/include/linux/firmware/imx/sci.h b/include/linux/firmware/imx/sci.h
index 5cc63fe7e84d..7fa0f3b329b5 100644
--- a/include/linux/firmware/imx/sci.h
+++ b/include/linux/firmware/imx/sci.h
@@ -25,27 +25,27 @@ int imx_scu_soc_init(struct device *dev);
#else
static inline int imx_scu_soc_init(struct device *dev)
{
- return -ENOTSUPP;
+ return -EOPNOTSUPP;
}

static inline int imx_scu_enable_general_irq_channel(struct device *dev)
{
- return -ENOTSUPP;
+ return -EOPNOTSUPP;
}

static inline int imx_scu_irq_register_notifier(struct notifier_block *nb)
{
- return -ENOTSUPP;
+ return -EOPNOTSUPP;
}

static inline int imx_scu_irq_unregister_notifier(struct notifier_block *nb)
{
- return -ENOTSUPP;
+ return -EOPNOTSUPP;
}

static inline int imx_scu_irq_group_enable(u8 group, u32 mask, u8 enable)
{
- return -ENOTSUPP;
+ return -EOPNOTSUPP;
}
#endif
#endif /* _SC_SCI_H */
--
2.37.1


2023-08-09 08:47:45

by Daniel Baluta

[permalink] [raw]
Subject: Re: [PATCH V6 7/8] firmware: imx: scu-irq: enlarge the IMX_SC_IRQ_NUM_GROUP

On Mon, Aug 7, 2023 at 4:11 PM Peng Fan (OSS) <[email protected]> wrote:
>
> From: Peng Fan <[email protected]>
>
> Per SCFW update, update the IMX_SC_IRQ_NUM_GROUP to 9.
>
> Signed-off-by: Peng Fan <[email protected]>
> ---
> drivers/firmware/imx/imx-scu-irq.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/firmware/imx/imx-scu-irq.c b/drivers/firmware/imx/imx-scu-irq.c
> index 6549f3792a0f..8d902db1daf2 100644
> --- a/drivers/firmware/imx/imx-scu-irq.c
> +++ b/drivers/firmware/imx/imx-scu-irq.c
> @@ -14,7 +14,7 @@
>
> #define IMX_SC_IRQ_FUNC_ENABLE 1
> #define IMX_SC_IRQ_FUNC_STATUS 2
> -#define IMX_SC_IRQ_NUM_GROUP 4
> +#define IMX_SC_IRQ_NUM_GROUP 9

This is tricky. Shouldn't we have some sort of versioning so that the user knows
that kernel and scfw are not compatible anymore?

2023-08-09 09:45:12

by Peng Fan

[permalink] [raw]
Subject: RE: [PATCH V6 7/8] firmware: imx: scu-irq: enlarge the IMX_SC_IRQ_NUM_GROUP

> Subject: Re: [PATCH V6 7/8] firmware: imx: scu-irq: enlarge the
> IMX_SC_IRQ_NUM_GROUP
>
> On Mon, Aug 7, 2023 at 4:11 PM Peng Fan (OSS) <[email protected]>
> wrote:
> >
> > From: Peng Fan <[email protected]>
> >
> > Per SCFW update, update the IMX_SC_IRQ_NUM_GROUP to 9.
> >
> > Signed-off-by: Peng Fan <[email protected]>
> > ---
> > drivers/firmware/imx/imx-scu-irq.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/firmware/imx/imx-scu-irq.c
> > b/drivers/firmware/imx/imx-scu-irq.c
> > index 6549f3792a0f..8d902db1daf2 100644
> > --- a/drivers/firmware/imx/imx-scu-irq.c
> > +++ b/drivers/firmware/imx/imx-scu-irq.c
> > @@ -14,7 +14,7 @@
> >
> > #define IMX_SC_IRQ_FUNC_ENABLE 1
> > #define IMX_SC_IRQ_FUNC_STATUS 2
> > -#define IMX_SC_IRQ_NUM_GROUP 4
> > +#define IMX_SC_IRQ_NUM_GROUP 9
>
> This is tricky. Shouldn't we have some sort of versioning so that the user
> knows that kernel and scfw are not compatible anymore?

It would not hurt here for scu irq num group. Newer linux
could work with older scfw.

But you raised a good point, we could print scfw version when
probing scu firmware, and for un compatible case, version
check could be used.

Thanks,
Peng.

2023-08-11 14:26:27

by Shawn Guo

[permalink] [raw]
Subject: Re: [PATCH V6 0/8] firmware: imx: scu/scu-irq: misc update

On Mon, Aug 07, 2023 at 08:14:24PM +0800, Peng Fan (OSS) wrote:
> From: Peng Fan <[email protected]>
>
> V6:
> Typo fix
> Update commit message
> Drop Patch v5 3/9
> code style and error path check in patch 8
>
> V5:
> Address sparse checking in patch 9
> Add a new patch 5
>
> V4:
> Add static inline for irq get status when SCU not defined
> Drop two patches wrongly included
>
> V3:
> Fix build error reported by kernel robot
> Add patch subject-prefix
>
> V2:
> Fix build warning
>
> Dong Aisheng (2):
> firmware: imx: scu: change init level to subsys_initcall_sync
> firmware: imx: scu: increase RPC timeout
>
> Peng Fan (4):
> firmware: imx: scu: use soc name for soc_id
> firmware: imx: scu: use EOPNOTSUPP
> firmware: imx: scu-irq: add imx_scu_irq_get_status
> firmware: imx: scu-irq: enlarge the IMX_SC_IRQ_NUM_GROUP
>
> Ranjani Vaidyanathan (1):
> firmware: imx: scu-irq: support identifying SCU wakeup source from
> sysfs
>
> Robin Gong (1):
> firmware: imx: scu-irq: fix RCU complaint after M4 partition reset

Applied all, thanks!