Skip to contentSkip to conversation

clk: keystone: sci-clk: Handle missing get_num_parents operation

PATCH In review Beleswar Padhi 3 participants 6 messages Sep 30 – Oct 1

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clk: keystone: sci-clk: Handle missing get_num_parents operation

The sci-clk driver unconditionally calls the get_num_parents TI-SCI operation while scanning clocks, both from DT and from firmware. This works for all cases today, but with future support for some System Controllers (e.g. PDM on TDA54), this may not be always right.

The PDM system controller on TI TDA54 SoC manages clock parents internally and does not support the clock parent related ops. Therefore, when scanning clocks from DT, treat the clock as having a single parent if get_num_parents is not provided. Such a clock is registered without parents, so the get_parent and set_parent operations are never invoked for it.

Scanning clocks from firmware relies on get_num_parents to discover the valid clock IDs, so return -EOPNOTSUPP in that case instead.

---
Testing Done:
- Boot test on all keystone and K3 platforms.
- Verified that the patch does not result in any warnings or errors

Logs:
https://gist.github.com/3V3RYONE/d821cea46f5dc1e70a759c97878fa487

Note:
This patch is independent and can be applied directly.

 drivers/clk/keystone/sci-clk.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)
drivers/clk/keystone/sci-clk.c +19 -4
index 9d2094bd48e3b..5bf615893a8c0 100644
@@ -468,6 +468,13 @@ static int ti_sci_scan_clocks_from_fw(struct sci_clk_provider *provider)
 	int gap_size = 0;
 	struct device *dev = provider->dev;
 
+	/*
+	 * Clocks are discovered by probing the firmware with get_num_parents,
+	 * which is not available with every system firmware (e.g. ABI5.0 PDM).
+	 */
+	if (!provider->ops->get_num_parents)
+		return -EOPNOTSUPP;
+
 	while (1) {
 		ret = provider->ops->get_num_parents(provider->sci, dev_id,
 						     clk_id,
@@ -589,10 +596,18 @@ static int ti_sci_scan_clocks_from_dt(struct sci_clk_provider *provider)
 				sci_clk->dev_id = args.args[0];
 				sci_clk->clk_id = args.args[1];
 				sci_clk->provider = provider;
-				provider->ops->get_num_parents(provider->sci,
-							       sci_clk->dev_id,
-							       sci_clk->clk_id,
-							       (void *)&sci_clk->num_parents);
+				/*
+				 * Firmware without get_num_parents (e.g. ABI5.0
+				 * PDM) manages clock parents internally, so
+				 * treat the clock as having a single parent.
+				 */
+				if (provider->ops->get_num_parents)
+					provider->ops->get_num_parents(provider->sci,
+								       sci_clk->dev_id,
+								       sci_clk->clk_id,
+								       &sci_clk->num_parents);
+				else
+					sci_clk->num_parents = 1;
 				list_add_tail(&sci_clk->node, &clks);
 
 				num_clks++;
Signature · 1 line
2.34.1
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] clk: keystone: dead code due to invalid get_num_parents capability check --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] clk: keystone: dead code due to invalid get_num_parents capability check --

commit 261ca89db50e7bf2199864fc566650d47bb2b916
Author: Beleswar Padhi <[email protected]>

clk: keystone: sci-clk: Handle missing get_num_parents operation

This commit updates the sci-clk driver to handle missing get_num_parents operations, specifically for system controllers like PDM on TDA54 that manage clock parents internally. It avoids invoking the parent operations by checking for the get_num_parents capability during DT and firmware scans.

Quoted 5 lines
drivers/clk/keystone/sci-clk.c +0 -0
index 9d2094bd48e3b..5bf615893a8c0 100644

drivers/clk/keystone/sci-clk.c static int ti_sci_scan_clocks_from_fw(struct sci_clk_provider *provider) · line 477

Quoted 10 lines
drivers/clk/keystone/sci-clk.c +7 -0
@@ -468,6 +468,13 @@ static int ti_sci_scan_clocks_from_fw(struct sci_clk_provider *provider)
 	int gap_size = 0;
 	struct device *dev = provider->dev;
 
+	/*
+	 * Clocks are discovered by probing the firmware with get_num_parents,
+	 * which is not available with every system firmware (e.g. ABI5.0 PDM).
+	 */
+	if (!provider->ops->get_num_parents)
+		return -EOPNOTSUPP;
+

[Severity: Medium]
Is this capability check effective? The TI SCI framework unconditionally populates the get_num_parents pointer during ti_sci_setup_ops(), so it seems this would never be NULL.

Does this mean this early return is dead code, and the driver will instead silently scan and register an empty clock provider when probed on a platform with firmware lacking this support (like TDA54)? Should this instead verify the capability by checking the return value of get_num_parents() for an error code (e.g., -ENODEV) instead of checking the pointer?

Quoted 2 lines
drivers/clk/keystone/sci-clk.c +0 -0
 	while (1) {
 		ret = provider->ops->get_num_parents(provider->sci, dev_id,

[ ... ]

Quoted 10 lines
drivers/clk/keystone/sci-clk.c +2 -4
@@ -589,10 +596,18 @@ static int ti_sci_scan_clocks_from_dt(struct sci_clk_provider *provider)
 				sci_clk->dev_id = args.args[0];
 				sci_clk->clk_id = args.args[1];
 				sci_clk->provider = provider;
-				provider->ops->get_num_parents(provider->sci,
-							       sci_clk->dev_id,
-							       sci_clk->clk_id,
-							       (void *)&sci_clk->num_parents);
+				/*
+				 * Firmware without get_num_parents (e.g. ABI5.0

drivers/clk/keystone/sci-clk.c static int ti_sci_scan_clocks_from_dt(struct sci_clk_provider *provider) · line 610

Quoted 10 lines
drivers/clk/keystone/sci-clk.c +10 -0
+				 * PDM) manages clock parents internally, so
+				 * treat the clock as having a single parent.
+				 */
+				if (provider->ops->get_num_parents)
+					provider->ops->get_num_parents(provider->sci,
+								       sci_clk->dev_id,
+								       sci_clk->clk_id,
+								       &sci_clk->num_parents);
+				else
+					sci_clk->num_parents = 1;

[Severity: Medium]
Since the function pointer is unconditionally assigned, is this else branch dead code? Should the capability be verified dynamically by evaluating the error code returned from the API call rather than checking the pointer?

Quoted 3 lines
drivers/clk/keystone/sci-clk.c +0 -0
 				list_add_tail(&sci_clk->node, &clks);
 
 				num_clks++;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
In reply to Beleswar Padhi
Quoted 58 lines · Beleswar Padhi

The sci-clk driver unconditionally calls the get_num_parents TI-SCI operation while scanning clocks, both from DT and from firmware. This works for all cases today, but with future support for some System Controllers (e.g. PDM on TDA54), this may not be always right.

The PDM system controller on TI TDA54 SoC manages clock parents internally and does not support the clock parent related ops. Therefore, when scanning clocks from DT, treat the clock as having a single parent if get_num_parents is not provided. Such a clock is registered without parents, so the get_parent and set_parent operations are never invoked for it.

Scanning clocks from firmware relies on get_num_parents to discover the valid clock IDs, so return -EOPNOTSUPP in that case instead.

---
Testing Done:
- Boot test on all keystone and K3 platforms.
- Verified that the patch does not result in any warnings or errors

Logs:
https://gist.github.com/3V3RYONE/d821cea46f5dc1e70a759c97878fa487

Note:
This patch is independent and can be applied directly.

  drivers/clk/keystone/sci-clk.c | 23 +++++++++++++++++++----
  1 file changed, 19 insertions(+), 4 deletions(-)
drivers/clk/keystone/sci-clk.c +9 -4
index 9d2094bd48e3b..5bf615893a8c0 100644
@@ -468,6 +468,13 @@ static int ti_sci_scan_clocks_from_fw(struct sci_clk_provider *provider)
  	int gap_size = 0;
  	struct device *dev = provider->dev;
 
+	/*
+	 * Clocks are discovered by probing the firmware with get_num_parents,
+	 * which is not available with every system firmware (e.g. ABI5.0 PDM).
+	 */
+	if (!provider->ops->get_num_parents)
+		return -EOPNOTSUPP;
+
  	while (1) {
  		ret = provider->ops->get_num_parents(provider->sci, dev_id,
  						     clk_id,
@@ -589,10 +596,18 @@ static int ti_sci_scan_clocks_from_dt(struct sci_clk_provider *provider)
  				sci_clk->dev_id = args.args[0];
  				sci_clk->clk_id = args.args[1];
  				sci_clk->provider = provider;
-				provider->ops->get_num_parents(provider->sci,
-							       sci_clk->dev_id,
-							       sci_clk->clk_id,
-							       (void *)&sci_clk->num_parents);
+				/*
+				 * Firmware without get_num_parents (e.g. ABI5.0

drivers/clk/keystone/sci-clk.c static int ti_sci_scan_clocks_from_dt(struct sci_clk_provider *provider) · line 610

Quoted 10 lines
drivers/clk/keystone/sci-clk.c +10 -0
+				 * PDM) manages clock parents internally, so
+				 * treat the clock as having a single parent.
+				 */
+				if (provider->ops->get_num_parents)
+					provider->ops->get_num_parents(provider->sci,
+								       sci_clk->dev_id,
+								       sci_clk->clk_id,
+								       &sci_clk->num_parents);
+				else
+					sci_clk->num_parents = 1;

Why 1 and not 0? Also, why not keep get_num_parents defined, but just have it return num_parents as 0? Haven't checked but if that works the same, but if it does then it saves us from having to make changes here and we can isolate firmware differences to only the firmware driver.

Andrew

Quoted 3 lines
drivers/clk/keystone/sci-clk.c +0 -0
  				list_add_tail(&sci_clk->node, &clks);
 
  				num_clks++;
#3 lore raw
Quoted 66 lines · Andrew Davis
Quoted 65 lines · Beleswar Padhi

The sci-clk driver unconditionally calls the get_num_parents TI-SCI operation while scanning clocks, both from DT and from firmware. This works for all cases today, but with future support for some System Controllers (e.g. PDM on TDA54), this may not be always right.

The PDM system controller on TI TDA54 SoC manages clock parents internally and does not support the clock parent related ops. Therefore, when scanning clocks from DT, treat the clock as having a single parent if get_num_parents is not provided. Such a clock is registered without parents, so the get_parent and set_parent operations are never invoked for it.

Scanning clocks from firmware relies on get_num_parents to discover the valid clock IDs, so return -EOPNOTSUPP in that case instead.

---
Testing Done:
  - Boot test on all keystone and K3 platforms.
  - Verified that the patch does not result in any warnings or errors

Logs:
https://gist.github.com/3V3RYONE/d821cea46f5dc1e70a759c97878fa487

Note:
This patch is independent and can be applied directly.

  drivers/clk/keystone/sci-clk.c | 23 +++++++++++++++++++----

  1 file changed, 19 insertions(+), 4 deletions(-)
drivers/clk/keystone/sci-clk.c +0 -0
index 9d2094bd48e3b..5bf615893a8c0 100644
@@ -468,6 +468,13 @@ static int ti_sci_scan_clocks_from_fw(struct 
 sci_clk_provider *provider)
       int gap_size = 0;
       struct device *dev = provider->dev;

  +    /*
+     * Clocks are discovered by probing the firmware with get_num_parents,
+     * which is not available with every system firmware (e.g. ABI5.0 PDM).
+     */
+    if (!provider->ops->get_num_parents)
+        return -EOPNOTSUPP;
+
      while (1) {
          ret = provider->ops->get_num_parents(provider->sci, dev_id, clk_id,

drivers/clk/keystone/sci-clk.c +6 -4
@@ -589,10 +596,18 @@ static int ti_sci_scan_clocks_from_dt(struct 
 sci_clk_provider *provider)
                   sci_clk->dev_id = args.args[0];
                   sci_clk->clk_id = args.args[1];
                   sci_clk->provider = provider;
- provider->ops->get_num_parents(provider->sci,
-                                   sci_clk->dev_id,
-                                   sci_clk->clk_id,
-                                   (void *)&sci_clk->num_parents);
+                /*
+                 * Firmware without get_num_parents (e.g. ABI5.0
+                 * PDM) manages clock parents internally, so
+                 * treat the clock as having a single parent.
+                 */
+                if (provider->ops->get_num_parents)
Quoted 8 lines

drivers/clk/keystone/sci-clk.c static int ti_sci_scan_clocks_from_dt(struct sci_clk_provider *provider) · line 610

Quoted 6 lines
drivers/clk/keystone/sci-clk.c +6 -0
+ provider->ops->get_num_parents(provider->sci,
+                                       sci_clk->dev_id,
+                                       sci_clk->clk_id,
+ &sci_clk->num_parents);
+                else
+                    sci_clk->num_parents = 1;

Why 1 and not 0?

Functionally, 1 and 0 are treated the same everywhere in the driver. Could pick either.

Quoted 4 lines

 Also, why not keep get_num_parents defined, but just have it return num_parents as 0? Haven't checked but if that works the same, but if it does then it saves us from having to make changes here and we can isolate firmware differences to only the firmware driver.

This works for the above branch where we are scanning clocks from device tree. But the code path where we scan clocks from System Firmware explicitly depends on a NAK against some clock to get out of the infinite loop. If we are writing a get_num_parents() which returns a NAK always and sets num_parents to 0, we are patching the protocol at this point. This does not give the correct view IMHO.

Thanks,
Beleswar

Quoted 6 lines

Andrew

Quoted 2 lines
drivers/clk/keystone/sci-clk.c +0 -0
 list_add_tail(&sci_clk->node, &clks);
                     num_clks++;
#4 lore raw
Quoted 74 lines · Beleswar
Quoted 62 lines · Andrew Davis
Quoted 61 lines · Beleswar Padhi

The sci-clk driver unconditionally calls the get_num_parents TI-SCI operation while scanning clocks, both from DT and from firmware. This works for all cases today, but with future support for some System Controllers (e.g. PDM on TDA54), this may not be always right.

The PDM system controller on TI TDA54 SoC manages clock parents internally and does not support the clock parent related ops. Therefore, when scanning clocks from DT, treat the clock as having a single parent if get_num_parents is not provided. Such a clock is registered without parents, so the get_parent and set_parent operations are never invoked for it.

Scanning clocks from firmware relies on get_num_parents to discover the valid clock IDs, so return -EOPNOTSUPP in that case instead.

---
Testing Done:
  - Boot test on all keystone and K3 platforms.
  - Verified that the patch does not result in any warnings or errors

Logs:
https://gist.github.com/3V3RYONE/d821cea46f5dc1e70a759c97878fa487

Note:
This patch is independent and can be applied directly.

  drivers/clk/keystone/sci-clk.c | 23 +++++++++++++++++++----

  1 file changed, 19 insertions(+), 4 deletions(-)
drivers/clk/keystone/sci-clk.c +0 -0
index 9d2094bd48e3b..5bf615893a8c0 100644
@@ -468,6 +468,13 @@ static int ti_sci_scan_clocks_from_fw(struct sci_clk_provider *provider)
       int gap_size = 0;
       struct device *dev = provider->dev;

  +    /*
+     * Clocks are discovered by probing the firmware with get_num_parents, +     * which is not available with every system firmware (e.g. ABI5.0 PDM). +     */
+    if (!provider->ops->get_num_parents)
+        return -EOPNOTSUPP;
+
      while (1) {
          ret = provider->ops->get_num_parents(provider->sci, dev_id, clk_id,

drivers/clk/keystone/sci-clk.c +6 -4
@@ -589,10 +596,18 @@ static int ti_sci_scan_clocks_from_dt(struct sci_clk_provider *provider)
                   sci_clk->dev_id = args.args[0];
                   sci_clk->clk_id = args.args[1];
                   sci_clk->provider = provider;
- provider->ops->get_num_parents(provider->sci,
-                                   sci_clk->dev_id,
-                                   sci_clk->clk_id,
-                                   (void *)&sci_clk->num_parents);
+                /*
+                 * Firmware without get_num_parents (e.g. ABI5.0
+                 * PDM) manages clock parents internally, so
+                 * treat the clock as having a single parent.
+                 */
+                if (provider->ops->get_num_parents)
Quoted 8 lines

drivers/clk/keystone/sci-clk.c static int ti_sci_scan_clocks_from_dt(struct sci_clk_provider *provider) · line 610

Quoted 6 lines
drivers/clk/keystone/sci-clk.c +6 -0
+ provider->ops->get_num_parents(provider->sci,
+                                       sci_clk->dev_id,
+                                       sci_clk->clk_id,
+ &sci_clk->num_parents);
+                else
+                    sci_clk->num_parents = 1;

Why 1 and not 0?

Quoted 3 lines

Functionally, 1 and 0 are treated the same everywhere in the driver. Could pick either.

Exactly what I was seeing, setting it to 0 just feels more correct. Might be some future case that checks on the "1" parent that doesn't exist, but "0" parents should always result in no parent check.

Quoted 6 lines
Quoted 4 lines

 Also, why not keep get_num_parents defined, but just have it return num_parents as 0? Haven't checked but if that works the same, but if it does then it saves us from having to make changes here and we can isolate firmware differences to only the firmware driver.

Quoted 6 lines

This works for the above branch where we are scanning clocks from device tree. But the code path where we scan clocks from System Firmware explicitly depends on a NAK against some clock to get out of the infinite loop. If we are writing a get_num_parents() which returns a NAK always and sets num_parents to 0, we are patching the protocol at this point. This does not give the correct view IMHO.

We wouldn't return NAK if the clock exists, we return success and set the num_parents to 0. Only for invalid clock IDs we return NAK. This should keep the TI_SCI_CLK_PROBE_FROM_FW path happy. But really that path has been disabled for many years now and I highly doubt it even functions at all anymore, it should probably just be removed.

Andrew

Quoted 10 lines

Thanks,
Beleswar

Quoted 6 lines

Andrew

Quoted 2 lines
drivers/clk/keystone/sci-clk.c +0 -0
 list_add_tail(&sci_clk->node, &clks);
                     num_clks++;
#5 lore raw
Quoted 79 lines · Andrew Davis
Quoted 78 lines · Beleswar
Quoted 74 lines · Andrew Davis
Quoted 61 lines · Beleswar Padhi

The sci-clk driver unconditionally calls the get_num_parents TI-SCI operation while scanning clocks, both from DT and from firmware. This works for all cases today, but with future support for some System Controllers (e.g. PDM on TDA54), this may not be always right.

The PDM system controller on TI TDA54 SoC manages clock parents internally and does not support the clock parent related ops. Therefore, when scanning clocks from DT, treat the clock as having a single parent if get_num_parents is not provided. Such a clock is registered without parents, so the get_parent and set_parent operations are never invoked for it.

Scanning clocks from firmware relies on get_num_parents to discover the valid clock IDs, so return -EOPNOTSUPP in that case instead.

---
Testing Done:
  - Boot test on all keystone and K3 platforms.
  - Verified that the patch does not result in any warnings or errors

Logs:
https://gist.github.com/3V3RYONE/d821cea46f5dc1e70a759c97878fa487

Note:
This patch is independent and can be applied directly.

  drivers/clk/keystone/sci-clk.c | 23 +++++++++++++++++++----

  1 file changed, 19 insertions(+), 4 deletions(-)
drivers/clk/keystone/sci-clk.c +0 -0
index 9d2094bd48e3b..5bf615893a8c0 100644
@@ -468,6 +468,13 @@ static int ti_sci_scan_clocks_from_fw(struct 
 sci_clk_provider *provider)
       int gap_size = 0;
       struct device *dev = provider->dev;

  +    /*
+     * Clocks are discovered by probing the firmware with get_num_parents,
+     * which is not available with every system firmware (e.g. ABI5.0 PDM).
+     */
+    if (!provider->ops->get_num_parents)
+        return -EOPNOTSUPP;
+
      while (1) {
          ret = provider->ops->get_num_parents(provider->sci, dev_id, clk_id,

drivers/clk/keystone/sci-clk.c +2 -4
@@ -589,10 +596,18 @@ static int ti_sci_scan_clocks_from_dt(struct 
 sci_clk_provider *provider)
                   sci_clk->dev_id = args.args[0];
                   sci_clk->clk_id = args.args[1];
                   sci_clk->provider = provider;
- provider->ops->get_num_parents(provider->sci,
-                                   sci_clk->dev_id,
-                                   sci_clk->clk_id,
-                                   (void *)&sci_clk->num_parents);
+                /*
+                 * Firmware without get_num_parents (e.g. ABI5.0

drivers/clk/keystone/sci-clk.c static int ti_sci_scan_clocks_from_dt(struct · line 611

Quoted 10 lines
drivers/clk/keystone/sci-clk.c +10 -0
+                 * PDM) manages clock parents internally, so
+                 * treat the clock as having a single parent.
+                 */
+                if (provider->ops->get_num_parents)
+ provider->ops->get_num_parents(provider->sci,
+                                       sci_clk->dev_id,
+                                       sci_clk->clk_id,
+ &sci_clk->num_parents);
+                else
+                    sci_clk->num_parents = 1;

Why 1 and not 0?

Quoted 7 lines
Quoted 3 lines

Functionally, 1 and 0 are treated the same everywhere in the driver. Could pick either.

Exactly what I was seeing, setting it to 0 just feels more correct. Might be some future case that checks on the "1" parent that doesn't exist, but "0" parents should always result in no parent check.

Sure, will do.

Quoted 14 lines
Quoted 7 lines
Quoted 5 lines

 Also, why not keep get_num_parents defined, but just have it return num_parents as 0? Haven't checked but if that works the same, but if it does then it saves us from having to make changes here and we can isolate firmware differences to only the firmware driver.

Quoted 6 lines

This works for the above branch where we are scanning clocks from device tree. But the code path where we scan clocks from System Firmware explicitly depends on a NAK against some clock to get out of the infinite loop. If we are writing a get_num_parents() which returns a NAK always and sets num_parents to 0, we are patching the protocol at this point. This does not give the correct view IMHO.

Quoted 3 lines

We wouldn't return NAK if the clock exists, we return success and set the num_parents to 0. Only for invalid clock IDs we return NAK. This should keep the TI_SCI_CLK_PROBE_FROM_FW path happy.

That should work. Although, I am thinking if it's alright for us to implement clock parent related ops when the ABI spec says that it's not supported. Let me know your preference, and accordingly I can send a revision for this or handle it in the TI-SCI ABI5.0 series whenever it's due for a revision:

https://lore.kernel.org/all/[email protected]

Thanks,
Beleswar

Quoted 17 lines

 But really
that path has been disabled for many years now and I highly doubt it even functions at all anymore, it should probably just be removed.

Andrew

Quoted 10 lines

Thanks,
Beleswar

Quoted 6 lines

Andrew

Quoted 2 lines
drivers/clk/keystone/sci-clk.c +0 -0
 list_add_tail(&sci_clk->node, &clks);
                     num_clks++;