Skip to contentSkip to conversation

reset: Add a managed API

PATCH New Jean-Jacques Hiblot 4 participants 12 messages Sep 30, 2019 – May 31, 2020 Reset controller framework

lore
Share & tools
lore
#0 lore raw

cover reset: Add a managed API

This is the 3rd of a few series, the goal of which is to facilitate porting drivers from the linux kernel. Most of the series will be about adding managed API to existing infrastructure (GPIO, reset, phy,...)

This particular series is about reset controllers. It adds a managed API, close to that of linux. The main difference is that bulk and reset_ctl are handled with different functions.

Jean-Jacques Hiblot (3):
drivers: reset: Handle gracefully NULL pointers
drivers: reset: Add a managed API to get reset controllers from the DT
test: reset: Add tests for the managed API

 arch/sandbox/include/asm/reset.h   |   1 +
 drivers/reset/reset-uclass.c       | 146 +++++++++++++++++++++++++----
 drivers/reset/sandbox-reset-test.c |  50 ++++++++--
 drivers/reset/sandbox-reset.c      |  19 ++++
 include/reset.h                    | 135 +++++++++++++++++++++++++-
 test/dm/reset.c                    |  59 ++++++++++++
 6 files changed, 387 insertions(+), 23 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/3 drivers: reset: Handle gracefully NULL pointers

Prepare the way for a managed reset API by handling NULL pointers without crashing nor failing.

---

 drivers/reset/reset-uclass.c | 30 +++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)
drivers/reset/reset-uclass.c +17 -13
index ee1a423ffb..1cfcc8b367 100644
@@ -9,9 +9,12 @@
 #include <reset.h>
 #include <reset-uclass.h>
 
-static inline struct reset_ops *reset_dev_ops(struct udevice *dev)
+struct reset_ops nop_reset_ops = {
+};
+
+static inline struct reset_ops *reset_dev_ops(struct reset_ctl *r)
 {
-	return (struct reset_ops *)dev->driver->ops;
+	return r ? (struct reset_ops *)r->dev->driver->ops : &nop_reset_ops;
 }
 
 static int reset_of_xlate_default(struct reset_ctl *reset_ctl,
@@ -50,9 +53,10 @@ static int reset_get_by_index_tail(int ret, ofnode node,
 		debug("%s %d\n", ofnode_get_name(args->node), args->args[0]);
 		return ret;
 	}
-	ops = reset_dev_ops(dev_reset);
 
 	reset_ctl->dev = dev_reset;
+	ops = reset_dev_ops(reset_ctl);
+
 	if (ops->of_xlate)
 		ret = ops->of_xlate(reset_ctl, args);
 	else
@@ -151,29 +155,29 @@ int reset_get_by_name(struct udevice *dev, const char *name,
 
 int reset_request(struct reset_ctl *reset_ctl)
 {
-	struct reset_ops *ops = reset_dev_ops(reset_ctl->dev);
+	struct reset_ops *ops = reset_dev_ops(reset_ctl);
 
 	debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
 
-	return ops->request(reset_ctl);
+	return ops->request ? ops->request(reset_ctl) : 0;
 }
 
 int reset_free(struct reset_ctl *reset_ctl)
 {
-	struct reset_ops *ops = reset_dev_ops(reset_ctl->dev);
+	struct reset_ops *ops = reset_dev_ops(reset_ctl);
 
 	debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
 
-	return ops->free(reset_ctl);
+	return ops->free ? ops->free(reset_ctl) : 0;
 }
 
 int reset_assert(struct reset_ctl *reset_ctl)
 {
-	struct reset_ops *ops = reset_dev_ops(reset_ctl->dev);
+	struct reset_ops *ops = reset_dev_ops(reset_ctl);
 
 	debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
 
-	return ops->rst_assert(reset_ctl);
+	return ops->rst_assert ? ops->rst_assert(reset_ctl) : 0;
 }
 
 int reset_assert_bulk(struct reset_ctl_bulk *bulk)
@@ -191,11 +195,11 @@ int reset_assert_bulk(struct reset_ctl_bulk *bulk)
 
 int reset_deassert(struct reset_ctl *reset_ctl)
 {
-	struct reset_ops *ops = reset_dev_ops(reset_ctl->dev);
+	struct reset_ops *ops = reset_dev_ops(reset_ctl);
 
 	debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
 
-	return ops->rst_deassert(reset_ctl);
+	return ops->rst_deassert ? ops->rst_deassert(reset_ctl) : 0;
 }
 
 int reset_deassert_bulk(struct reset_ctl_bulk *bulk)
@@ -213,11 +217,11 @@ int reset_deassert_bulk(struct reset_ctl_bulk *bulk)
 
 int reset_status(struct reset_ctl *reset_ctl)
 {
-	struct reset_ops *ops = reset_dev_ops(reset_ctl->dev);
+	struct reset_ops *ops = reset_dev_ops(reset_ctl);
 
 	debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
 
-	return ops->rst_status(reset_ctl);
+	return ops->rst_status ? ops->rst_status(reset_ctl) : 0;
 }
 
 int reset_release_all(struct reset_ctl *reset_ctl, int count)
Signature · 1 line
2.17.1
#2 lore raw

PATCH 1/3 drivers: reset: Handle gracefully NULL pointers

Hi Jean-Jacques,

Quoted 9 lines · Jean-Jacques Hiblot

Prepare the way for a managed reset API by handling NULL pointers without crashing nor failing.

---

 drivers/reset/reset-uclass.c | 30 +++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)

Same comment here about code size / Kconfig option.

Regards,
Simon

#3 lore raw

PATCH 1/3 drivers: reset: Handle gracefully NULL pointers

Hi Simon,

Quoted 7 lines · Simon Glass

Hi Jean-Jacques,

Quoted 4 lines · Jean-Jacques Hiblot

Prepare the way for a managed reset API by handling NULL pointers without crashing nor failing.

Quoted 7 lines
Quoted 5 lines

---

 drivers/reset/reset-uclass.c | 30 +++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)

Same comment here about code size / Kconfig option.

A lot of the changes below are ternary operators. I'm not sure how to put them behind a Kconfig option to reduce code size. Do you want me to change the NULL check to a separate if() block to put behind an #ifdef?

One way of doing this is like in this patch [0]. The other would be to wrap individual if statements in #ifdef, which tends to hurt readability.

[0] https://patchwork.ozlabs.org/project/uboot/patch/20191001115130.18886-2-jjhiblot at ti.com/

Quoted 95 lines
drivers/reset/reset-uclass.c +17 -13
index ee1a423ffb..1cfcc8b367 100644
@@ -9,9 +9,12 @@ 
 #include <reset.h>
 #include <reset-uclass.h>
 
-static inline struct reset_ops *reset_dev_ops(struct udevice *dev)
+struct reset_ops nop_reset_ops = {
+};
+
+static inline struct reset_ops *reset_dev_ops(struct reset_ctl *r)
 {
-	return (struct reset_ops *)dev->driver->ops;
+	return r ? (struct reset_ops *)r->dev->driver->ops : &nop_reset_ops;
 }
 
 static int reset_of_xlate_default(struct reset_ctl *reset_ctl,
@@ -50,9 +53,10 @@  static int reset_get_by_index_tail(int ret, ofnode node,
 		debug("%s %d\n", ofnode_get_name(args->node), args->args[0]);
 		return ret;
 	}
-	ops = reset_dev_ops(dev_reset);
 
 	reset_ctl->dev = dev_reset;
+	ops = reset_dev_ops(reset_ctl);
+
 	if (ops->of_xlate)
 		ret = ops->of_xlate(reset_ctl, args);
 	else
@@ -151,29 +155,29 @@  int reset_get_by_name(struct udevice *dev, const char *name,
 
 int reset_request(struct reset_ctl *reset_ctl)
 {
-	struct reset_ops *ops = reset_dev_ops(reset_ctl->dev);
+	struct reset_ops *ops = reset_dev_ops(reset_ctl);
 
 	debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
 
-	return ops->request(reset_ctl);
+	return ops->request ? ops->request(reset_ctl) : 0;
 }
 
 int reset_free(struct reset_ctl *reset_ctl)
 {
-	struct reset_ops *ops = reset_dev_ops(reset_ctl->dev);
+	struct reset_ops *ops = reset_dev_ops(reset_ctl);
 
 	debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
 
-	return ops->free(reset_ctl);
+	return ops->free ? ops->free(reset_ctl) : 0;
 }
 
 int reset_assert(struct reset_ctl *reset_ctl)
 {
-	struct reset_ops *ops = reset_dev_ops(reset_ctl->dev);
+	struct reset_ops *ops = reset_dev_ops(reset_ctl);
 
 	debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
 
-	return ops->rst_assert(reset_ctl);
+	return ops->rst_assert ? ops->rst_assert(reset_ctl) : 0;
 }
 
 int reset_assert_bulk(struct reset_ctl_bulk *bulk)
@@ -191,11 +195,11 @@  int reset_assert_bulk(struct reset_ctl_bulk *bulk)
 
 int reset_deassert(struct reset_ctl *reset_ctl)
 {
-	struct reset_ops *ops = reset_dev_ops(reset_ctl->dev);
+	struct reset_ops *ops = reset_dev_ops(reset_ctl);
 
 	debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
 
-	return ops->rst_deassert(reset_ctl);
+	return ops->rst_deassert ? ops->rst_deassert(reset_ctl) : 0;
 }
 
 int reset_deassert_bulk(struct reset_ctl_bulk *bulk)
@@ -213,11 +217,11 @@  int reset_deassert_bulk(struct reset_ctl_bulk *bulk)
 
 int reset_status(struct reset_ctl *reset_ctl)
 {
-	struct reset_ops *ops = reset_dev_ops(reset_ctl->dev);
+	struct reset_ops *ops = reset_dev_ops(reset_ctl);
 
 	debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
 
-	return ops->rst_status(reset_ctl);
+	return ops->rst_status ? ops->rst_status(reset_ctl) : 0;
 }
 
 int reset_release_all(struct reset_ctl *reset_ctl, int count)
Signature · 3 lines
Regards,
Pratyush Yadav
Texas Instruments India
#4 lore raw

PATCH 1/3 drivers: reset: Handle gracefully NULL pointers

Hi Pratyush,

Quoted 19 lines · Pratyush Yadav

Hi Simon,

Quoted 7 lines · Simon Glass

Hi Jean-Jacques,

Quoted 4 lines · Jean-Jacques Hiblot

Prepare the way for a managed reset API by handling NULL pointers without crashing nor failing.

Quoted 7 lines
Quoted 5 lines

---

 drivers/reset/reset-uclass.c | 30 +++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)

Same comment here about code size / Kconfig option.

Quoted 7 lines

A lot of the changes below are ternary operators. I'm not sure how to put them behind a Kconfig option to reduce code size. Do you want me to change the NULL check to a separate if() block to put behind an #ifdef?

One way of doing this is like in this patch [0]. The other would be to wrap individual if statements in #ifdef, which tends to hurt readability.

Well for this I would really favour:

  int reset_request(struct reset_ctl *reset_ctl)
  {
     struct reset_ops *ops;

if (!result_ctl)

    return 0;

ops = reset_dev_ops(reset_ctl->dev);

But why allow result_ctl to be NULL? You should explain that in your commit message.

Quoted 11 lines

drivers/reset/reset-uclass.c int reset_get_by_name(struct udevice *dev, const char *name, · line 163

Quoted 9 lines
drivers/reset/reset-uclass.c +2 -2
-     struct reset_ops *ops = reset_dev_ops(reset_ctl->dev);
+     struct reset_ops *ops = reset_dev_ops(reset_ctl);
 
      debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
 
-     return ops->request(reset_ctl);
+     return ops->request ? ops->request(reset_ctl) : 0;
 }

[0] https://patchwork.ozlabs.org/project/uboot/patch/20191001115130.18886-2-jjhiblot at ti.com/

[..]

Regards,
Simon

#5 lore raw

PATCH 2/3 drivers: reset: Add a managed API to get reset controllers from the DT

In reply to Jean-Jacques Hiblot

Add managed functions to get a reset_ctl from the device-tree, based on a name or an index.
Also add a managed functions to get a reset_ctl_bulk (array of reset_ctl) from the device-tree.

When the device is unbound, the reset controllers are automatically released and the data structure is freed.

---

 drivers/reset/reset-uclass.c | 116 +++++++++++++++++++++++++++++-
 include/reset.h              | 135 ++++++++++++++++++++++++++++++++++-
 2 files changed, 247 insertions(+), 4 deletions(-)
drivers/reset/reset-uclass.c +113 -3
index 1cfcc8b367..ae8395a5e9 100644
@@ -8,6 +8,7 @@
 #include <fdtdec.h>
 #include <reset.h>
 #include <reset-uclass.h>
+#include <dm/lists.h>
 
 struct reset_ops nop_reset_ops = {
 };
@@ -101,13 +102,14 @@ int reset_get_by_index_nodev(ofnode node, int index,
 				       index > 0, reset_ctl);
 }
 
-int reset_get_bulk(struct udevice *dev, struct reset_ctl_bulk *bulk)
+static int __reset_get_bulk(struct udevice *dev, ofnode node,
+			    struct reset_ctl_bulk *bulk)
 {
 	int i, ret, err, count;
 	
 	bulk->count = 0;
 
-	count = dev_count_phandle_with_args(dev, "resets", "#reset-cells");
+	count = ofnode_count_phandle_with_args(node, "resets", "#reset-cells");
 	if (count < 1)
 		return count;
 
@@ -117,7 +119,7 @@ int reset_get_bulk(struct udevice *dev, struct reset_ctl_bulk *bulk)
 		return -ENOMEM;
 
 	for (i = 0; i < count; i++) {
-		ret = reset_get_by_index(dev, i, &bulk->resets[i]);
+		ret = reset_get_by_index_nodev(node, i, &bulk->resets[i]);
 		if (ret < 0)
 			goto bulk_get_err;
 
@@ -135,6 +137,11 @@ bulk_get_err:
 	return ret;
 }
 
+int reset_get_bulk(struct udevice *dev, struct reset_ctl_bulk *bulk)
+{
+	return __reset_get_bulk(dev, dev_ofnode(dev), bulk);
+}
+
 int reset_get_by_name(struct udevice *dev, const char *name,
 		     struct reset_ctl *reset_ctl)
 {
@@ -247,6 +254,109 @@ int reset_release_all(struct reset_ctl *reset_ctl, int count)
 	return 0;
 }
 
+static void devm_reset_release(struct udevice *dev, void *res)
+{
+	reset_free(res);
+}
+
+struct reset_ctl *devm_reset_control_get_by_index(struct udevice *dev,
+						  int index)
+{
+	int rc;
+	struct reset_ctl *reset_ctl;
+
+	reset_ctl = devres_alloc(devm_reset_release, sizeof(struct reset_ctl),
+				 __GFP_ZERO);
+	if (unlikely(!reset_ctl))
+		return ERR_PTR(-ENOMEM);
+
+	rc = reset_get_by_index(dev, index, reset_ctl);
+	if (rc)
+		return ERR_PTR(rc);
+
+	devres_add(dev, reset_ctl);
+	return reset_ctl;
+}
+
+struct reset_ctl *devm_reset_control_get(struct udevice *dev, const char *id)
+{
+	int rc;
+	struct reset_ctl *reset_ctl;
+
+	reset_ctl = devres_alloc(devm_reset_release, sizeof(struct reset_ctl),
+				 __GFP_ZERO);
+	if (unlikely(!reset_ctl))
+		return ERR_PTR(-ENOMEM);
+
+	rc = reset_get_by_name(dev, id, reset_ctl);
+	if (rc)
+		return ERR_PTR(rc);
+
+	devres_add(dev, reset_ctl);
+	return reset_ctl;
+}
+
+struct reset_ctl *devm_reset_control_get_optional(struct udevice *dev,
+						  const char *id)
+{
+	struct reset_ctl *r = devm_reset_control_get(dev, id);
+
+	if (IS_ERR(r))
+		return NULL;
+
+	return r;
+}
+
+static void devm_reset_bulk_release(struct udevice *dev, void *res)
+{
+	struct reset_ctl_bulk *bulk = res;
+
+	reset_release_all(bulk->resets, bulk->count);
+}
+
+struct reset_ctl_bulk *devm_reset_bulk_get_by_node(struct udevice *dev,
+						   ofnode node)
+{
+	int rc;
+	struct reset_ctl_bulk *bulk;
+
+	bulk = devres_alloc(devm_reset_bulk_release,
+			    sizeof(struct reset_ctl_bulk),
+			    __GFP_ZERO);
+	if (unlikely(!bulk))
+		return ERR_PTR(-ENOMEM);
+
+	rc = __reset_get_bulk(dev, node, bulk);
+	if (rc)
+		return ERR_PTR(rc);
+
+	devres_add(dev, bulk);
+	return bulk;
+}
+
+struct reset_ctl_bulk *devm_reset_bulk_get_optional_by_node(struct udevice *dev,
+							    ofnode node)
+{
+	struct reset_ctl_bulk *bulk;
+
+	bulk = devm_reset_bulk_get_by_node(dev, node);
+
+	if (IS_ERR(bulk))
+		return NULL;
+
+	return bulk;
+}
+
+struct reset_ctl_bulk *devm_reset_bulk_get(struct udevice *dev)
+{
+	return devm_reset_bulk_get_by_node(dev, dev_ofnode(dev));
+}
+
+struct reset_ctl_bulk *devm_reset_bulk_get_optional(struct udevice *dev)
+{
+	return devm_reset_bulk_get_optional_by_node(dev, dev_ofnode(dev));
+}
+
 UCLASS_DRIVER(reset) = {
 	.id		= UCLASS_RESET,
 	.name		= "reset",
include/reset.h +134 -1

154 lines not on this page · raw message

Signature · 1 line
2.17.1
#6 lore raw

PATCH 2/3 drivers: reset: Add a managed API to get reset controllers from the DT

Quoted 9 lines · Jean-Jacques Hiblot

Add managed functions to get a reset_ctl from the device-tree, based on a name or an index.
Also add a managed functions to get a reset_ctl_bulk (array of reset_ctl) from the device-tree.

When the device is unbound, the reset controllers are automatically released and the data structure is freed.

Quoted 6 lines

---

 drivers/reset/reset-uclass.c | 116 +++++++++++++++++++++++++++++-
 include/reset.h              | 135 ++++++++++++++++++++++++++++++++++-
 2 files changed, 247 insertions(+), 4 deletions(-)

I really don't like these ERR_PTR returns. I suppose they make the code easier to port, and we can be sure that pointers will not be in the last 4KB of address space?

Regards,
Simon

#7 lore raw

PATCH 2/3 drivers: reset: Add a managed API to get reset controllers from the DT

Quoted 12 lines · Simon Glass
Quoted 11 lines · Jean-Jacques Hiblot

Add managed functions to get a reset_ctl from the device-tree, based on a name or an index.
Also add a managed functions to get a reset_ctl_bulk (array of reset_ctl) from the device-tree.

When the device is unbound, the reset controllers are automatically released and the data structure is freed.

---

Quoted 8 lines
Quoted 3 lines
  drivers/reset/reset-uclass.c | 116 +++++++++++++++++++++++++++++-
  include/reset.h              | 135 ++++++++++++++++++++++++++++++++++-
  2 files changed, 247 insertions(+), 4 deletions(-)

I really don't like these ERR_PTR returns. I suppose they make the code easier to port, and we can be sure that pointers will not be in the last 4KB of address space?

It seems rather unlikely because the returned pointer points to actual RAM allocated from the heap. On most platforms I've worked with, the top of the address space is not dedicated to memory. If ever the need to fix this  arises it could done by tweaking the macros to use another unused address space.

JJ

Quoted 4 lines

Regards,
Simon

#8 lore raw

PATCH 2/3 drivers: reset: Add a managed API to get reset controllers from the DT

Hi Jean-Jacques,

Quoted 20 lines · Jean-Jacques Hiblot
Quoted 17 lines · Simon Glass
Quoted 8 lines · Jean-Jacques Hiblot

Add managed functions to get a reset_ctl from the device-tree, based on a name or an index.
Also add a managed functions to get a reset_ctl_bulk (array of reset_ctl) from the device-tree.

When the device is unbound, the reset controllers are automatically released and the data structure is freed.

Quoted 6 lines

---

  drivers/reset/reset-uclass.c | 116 +++++++++++++++++++++++++++++-
  include/reset.h              | 135 ++++++++++++++++++++++++++++++++++-
  2 files changed, 247 insertions(+), 4 deletions(-)
Quoted 7 lines
Quoted 3 lines

I really don't like these ERR_PTR returns. I suppose they make the code easier to port, and we can be sure that pointers will not be in the last 4KB of address space?

It seems rather unlikely because the returned pointer points to actual RAM allocated from the heap. On most platforms I've worked with, the top of the address space is not dedicated to memory.

Yes that's my comfort.

Quoted 3 lines

If ever the need to fix
this arises it could done by tweaking the macros to use another unused address space.

Not easily without doing something platform-specific, as someone else is currently pushing.

Regards,
Simon

#9 lore raw

PATCH 2/3 drivers: reset: Add a managed API to get reset controllers from the DT

Am 05.11.2019 um 17:33 schrieb Simon Glass:

Quoted 30 lines

Hi Jean-Jacques,

Quoted 27 lines · Jean-Jacques Hiblot
Quoted 12 lines · Simon Glass
Quoted 11 lines · Jean-Jacques Hiblot

Add managed functions to get a reset_ctl from the device-tree, based on a name or an index.
Also add a managed functions to get a reset_ctl_bulk (array of reset_ctl) from the device-tree.

When the device is unbound, the reset controllers are automatically released and the data structure is freed.

---

Quoted 8 lines
Quoted 3 lines
   drivers/reset/reset-uclass.c | 116 +++++++++++++++++++++++++++++-
   include/reset.h              | 135 ++++++++++++++++++++++++++++++++++-
   2 files changed, 247 insertions(+), 4 deletions(-)

I really don't like these ERR_PTR returns. I suppose they make the code easier to port, and we can be sure that pointers will not be in the last 4KB of address space?

It seems rather unlikely because the returned pointer points to actual RAM allocated from the heap. On most platforms I've worked with, the top of the address space is not dedicated to memory.

Most != all: on socfpga, the internal SRAM is at the end of the address spcae. In SPL, this means the last 4K cannot be used.

However, that shouldn't keep us from porting ERR_PTR returns from Linux code.

Quoted 9 lines

Yes that's my comfort.

Quoted 3 lines

If ever the need to fix
this arises it could done by tweaking the macros to use another unused address space.

Not easily without doing something platform-specific, as someone else is currently pushing.

That "someone else" would be me. Sadly, I did not get any response:

https://patchwork.ozlabs.org/project/uboot/list/?series=137880

Regards,
Simon

#10 lore raw

PATCH 2/3 drivers: reset: Add a managed API to get reset controllers from the DT

Quoted 51 lines · Simon Goldschmidt

Am 05.11.2019 um 17:33 schrieb Simon Glass:

Quoted 36 lines

Hi Jean-Jacques,

Quoted 32 lines · Jean-Jacques Hiblot
Quoted 19 lines · Simon Glass
Quoted 10 lines · Jean-Jacques Hiblot

Add managed functions to get a reset_ctl from the device-tree, based on a
name or an index.
Also add a managed functions to get a reset_ctl_bulk (array of reset_ctl)
from the device-tree.

When the device is unbound, the reset controllers are automatically released and the data structure is freed.

Quoted 7 lines

---

   drivers/reset/reset-uclass.c | 116 +++++++++++++++++++++++++++++- include/reset.h              | 135
++++++++++++++++++++++++++++++++++-

   2 files changed, 247 insertions(+), 4 deletions(-)
Quoted 5 lines

I really don't like these ERR_PTR returns. I suppose they make the code easier to port, and we can be sure that pointers will not be in the last 4KB of address space?

It seems rather unlikely because the returned pointer points to actual RAM allocated from the heap. On most platforms I've worked with, the top
of the address space is not dedicated to memory.

Most != all: on socfpga, the internal SRAM is at the end of the address spcae. In SPL, this means the last 4K cannot be used.

However, that shouldn't keep us from porting ERR_PTR returns from Linux code.

Quoted 7 lines

Yes that's my comfort.

Quoted 3 lines

If ever the need to fix
this  arises it could done by tweaking the macros to use another unused address space.

Quoted 6 lines
Quoted 2 lines

Not easily without doing something platform-specific, as someone else is currently pushing.

That "someone else" would be me. Sadly, I did not get any response:

https://patchwork.ozlabs.org/project/uboot/list/?series=137880

Alternatively we could use BIT(0) to flag an error since allocations are always aligned on 4 or more (sizeof(ulong) or 2*sizeof(size_t))

Quoted 5 lines

Regards,
Simon

#11 lore raw

PATCH 3/3 test: reset: Add tests for the managed API

In reply to Jean-Jacques Hiblot

The tests are basically the same as for the regular API. Except that the reset are initialized using the managed API, and no freed manually.

---

 arch/sandbox/include/asm/reset.h   |  1 +
 drivers/reset/sandbox-reset-test.c | 50 ++++++++++++++++++++++---
 drivers/reset/sandbox-reset.c      | 19 ++++++++++
 test/dm/reset.c                    | 59 ++++++++++++++++++++++++++++++
 4 files changed, 123 insertions(+), 6 deletions(-)
arch/sandbox/include/asm/reset.h +1 -0
index c4205eabef..a0065b96ad 100644
@@ -11,6 +11,7 @@
 struct udevice;
 
 int sandbox_reset_query(struct udevice *dev, unsigned long id);
+int sandbox_reset_is_requested(struct udevice *dev, unsigned long id);
 
 int sandbox_reset_test_get(struct udevice *dev);
 int sandbox_reset_test_get_bulk(struct udevice *dev);
drivers/reset/sandbox-reset-test.c +44 -6

106 lines not on this page · raw message

drivers/reset/sandbox-reset.c +19 -0
index 40f2654d8e..2b5ae88187 100644
@@ -13,6 +13,7 @@
 
 struct sandbox_reset_signal {
 	bool asserted;
+	bool requested;
 };
 
 struct sandbox_reset {
@@ -21,18 +22,24 @@ struct sandbox_reset {
 
 static int sandbox_reset_request(struct reset_ctl *reset_ctl)
 {
+	struct sandbox_reset *sbr = dev_get_priv(reset_ctl->dev);
+
 	debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
 
 	if (reset_ctl->id >= SANDBOX_RESET_SIGNALS)
 		return -EINVAL;
 
+	sbr->signals[reset_ctl->id].requested = true;
 	return 0;
 }
 
 static int sandbox_reset_free(struct reset_ctl *reset_ctl)
 {
+	struct sandbox_reset *sbr = dev_get_priv(reset_ctl->dev);
+
 	debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
 
+	sbr->signals[reset_ctl->id].requested = false;
 	return 0;
 }
 
@@ -105,3 +112,15 @@ int sandbox_reset_query(struct udevice *dev, unsigned long id)
 
 	return sbr->signals[id].asserted;
 }
+
+int sandbox_reset_is_requested(struct udevice *dev, unsigned long id)
+{
+	struct sandbox_reset *sbr = dev_get_priv(dev);
+
+	debug("%s(dev=%p, id=%ld)\n", __func__, dev, id);
+
+	if (id >= SANDBOX_RESET_SIGNALS)
+		return -EINVAL;
+
+	return sbr->signals[id].requested;
+}
test/dm/reset.c +59 -0

74 lines not on this page · raw message

Signature · 1 line
2.17.1