Skip to contentSkip to conversation

dm: SMEM (Shared memory) uclass

PATCH Superseded Ramon Fried 3 participants 18 messages Jun 22, 2018 – Jun 28, 2018 1 message not in the archive Arm (32-bit)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH v2 1/6 dm: SMEM (Shared memory) uclass

This is a uclass for Shared memory manager drivers.

A Shared Memory Manager driver implements an interface for allocating and accessing items in the memory area shared among all of the processors.

---

Changes in v2:
(As suggested by Simon Glass)
- Introduced a new dm class (CLASS_SMEM) instead of CLASS_SOC.
- Added sandbox driver
- Added testing for DM class.

 drivers/Makefile           |  1 +
 drivers/smem/Kconfig       |  2 +
 drivers/smem/Makefile      |  5 +++
 drivers/smem/smem-uclass.c | 53 ++++++++++++++++++++++++
 include/dm/uclass-id.h     |  1 +
 include/smem.h             | 84 ++++++++++++++++++++++++++++++++++++++
 6 files changed, 146 insertions(+)
 create mode 100644 drivers/smem/Kconfig
 create mode 100644 drivers/smem/Makefile
 create mode 100644 drivers/smem/smem-uclass.c
 create mode 100644 include/smem.h
drivers/Makefile +1 -0
index a213ea9671..ba4a561358 100644
@@ -98,6 +98,7 @@ obj-y += pwm/
 obj-y += reset/
 obj-y += input/
 # SOC specific infrastructure drivers.
+obj-y += smem/
 obj-y += soc/
 obj-$(CONFIG_REMOTEPROC) += remoteproc/
 obj-y += thermal/
drivers/smem/Kconfig new file +2 -0
new file mode 100644
index 0000000000..64337a8b8e
@@ -0,0 +1,2 @@
+menuconfig SMEM
+	bool  "SMEM (Shared Memory mamanger) support"
drivers/smem/Makefile new file +5 -0
new file mode 100644
index 0000000000..ca55c4512d
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Makefile for the U-Boot SMEM interface drivers
+
+obj-$(CONFIG_SMEM) += smem-uclass.o
drivers/smem/smem-uclass.c new file +53 -0

53 lines not on this page · raw message

include/dm/uclass-id.h +1 -0
index d7f9df3583..a39643ec5e 100644
@@ -74,6 +74,7 @@ enum uclass_id {
 	UCLASS_RTC,		/* Real time clock device */
 	UCLASS_SCSI,		/* SCSI device */
 	UCLASS_SERIAL,		/* Serial UART */
+	UCLASS_SMEM,		/* Shared memory interface */
 	UCLASS_SPI,		/* SPI bus */
 	UCLASS_SPMI,		/* System Power Management Interface bus */
 	UCLASS_SPI_FLASH,	/* SPI flash */
include/smem.h new file +84 -0

84 lines not on this page · raw message

Signature · 1 line
2.17.1
#2 lore raw

PATCH v2 1/6 dm: SMEM (Shared memory) uclass

Hi Ramon,

Quoted 16 lines · Ramon Fried

This is a uclass for Shared memory manager drivers.

A Shared Memory Manager driver implements an interface for allocating and accessing items in the memory area shared among all of the processors.

---

Changes in v2:
(As suggested by Simon Glass)
- Introduced a new dm class (CLASS_SMEM) instead of CLASS_SOC.
- Added sandbox driver
- Added testing for DM class.

Quoted 12 lines
 drivers/Makefile           |  1 +
 drivers/smem/Kconfig       |  2 +
 drivers/smem/Makefile      |  5 +++
 drivers/smem/smem-uclass.c | 53 ++++++++++++++++++++++++
 include/dm/uclass-id.h     |  1 +
 include/smem.h             | 84 ++++++++++++++++++++++++++++++++++++++
 6 files changed, 146 insertions(+)
 create mode 100644 drivers/smem/Kconfig
 create mode 100644 drivers/smem/Makefile
 create mode 100644 drivers/smem/smem-uclass.c
 create mode 100644 include/smem.h

A few nits below.

Quoted 72 lines
drivers/Makefile +1 -0
index a213ea9671..ba4a561358 100644
@@ -98,6 +98,7 @@ obj-y += pwm/
 obj-y += reset/
 obj-y += input/
 # SOC specific infrastructure drivers.
+obj-y += smem/
 obj-y += soc/
 obj-$(CONFIG_REMOTEPROC) += remoteproc/
 obj-y += thermal/
drivers/smem/Kconfig new file +2 -0
new file mode 100644
index 0000000000..64337a8b8e
@@ -0,0 +1,2 @@
+menuconfig SMEM
+       bool  "SMEM (Shared Memory mamanger) support"
drivers/smem/Makefile new file +5 -0
new file mode 100644
index 0000000000..ca55c4512d
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Makefile for the U-Boot SMEM interface drivers
+
+obj-$(CONFIG_SMEM) += smem-uclass.o
drivers/smem/smem-uclass.c new file +35 -0
new file mode 100644
index 0000000000..07ed1a92d8
@@ -0,0 +1,53 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2018 Ramon Fried <[email protected]>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <smem.h>
+
+int smem_alloc(struct udevice *dev, unsigned int host,
+               unsigned int item, size_t size)
+{
+       struct smem_ops *ops = smem_get_ops(dev);
+
+       if (!ops->alloc)
+               return -ENOSYS;
+
+       return ops->alloc(host, item, size);
+}
+
+void *smem_get(struct udevice *dev, unsigned int host,
+               unsigned int item, size_t *size)
+{
+       struct smem_ops *ops = smem_get_ops(dev);
+
+       if (!ops->get)
+               return NULL;
+
+       return ops->get(host, item, size);
+}
+
+int smem_get_free_space(struct udevice *dev, unsigned int host, size_t *free)
+{
+       struct smem_ops *ops = smem_get_ops(dev);
+

drivers/smem/smem-uclass.c line 45

Quoted 10 lines
drivers/smem/smem-uclass.c new file +10 -0
+       int ret;
+
+       if (!ops->get_free_space)
+               return -ENOSYS;
+
+       ret = ops->get_free_space(host);
+       if (ret > 0)
+               *free = ret;
+       else
+               return ret;

It seems odd that get_free_space() has a different return value than smem_get_free_space(). Can you make the latter return the amount of free space? If not, change the op to return it in a param. You can use long as the return value if that helps.

Quoted 26 lines
drivers/smem/smem-uclass.c new file +8 -0
+
+       return 0;
+}
+
+UCLASS_DRIVER(smem) = {
+       .id     = UCLASS_SMEM,
+       .name       = "smem",
+};
include/dm/uclass-id.h +1 -0
index d7f9df3583..a39643ec5e 100644
@@ -74,6 +74,7 @@ enum uclass_id {
        UCLASS_RTC,             /* Real time clock device */
        UCLASS_SCSI,            /* SCSI device */
        UCLASS_SERIAL,          /* Serial UART */
+       UCLASS_SMEM,            /* Shared memory interface */
        UCLASS_SPI,             /* SPI bus */
        UCLASS_SPMI,            /* System Power Management Interface bus */
        UCLASS_SPI_FLASH,       /* SPI flash */
include/smem.h new file +0 -0
new file mode 100644
index 0000000000..201960232c

include/smem.h line 3

Quoted 3 lines
include/smem.h new file +3 -0
@@ -0,0 +1,84 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * header file for smem driver.

If you have a README somewhere please point to it here.

include/smem.h line 16

Quoted 13 lines
include/smem.h new file +13 -0
+ *
+ * Copyright (c) 2018 Ramon Fried <[email protected]>
+ */
+
+#ifndef _smemh_
+#define _smemh_
+
+/* struct smem_ops: Operations for the SMEM uclass */
+struct smem_ops {
+       /**
+        * alloc() - allocate space for a smem item
+        *
+        * @host:       remote processor id, or -1

What does -1 mean? Please expand commment

include/smem.h line 17

Quoted 1 line
include/smem.h new file +1 -0
+        * @item:       smem item handle

How does one choose this? What does it mean? Can you expand this comment a bit?

include/smem.h line 22

Quoted 5 lines
include/smem.h new file +5 -0
+        * @size:       number of bytes to be allocated
+        * @return 0 if OK, -ve on error
+        */
+       int (*alloc)(unsigned int host,
+               unsigned int item, size_t size);

Fits on one line?

include/smem.h line 33

Quoted 11 lines
include/smem.h new file +11 -0
+
+       /**
+        * get() - Resolve ptr of size of a smem item
+        *
+        * @host:       the remote processor, of -1
+        * @item:       smem item handle
+        * @size:       pointer to be filled out with the size of the item
+        * @return      pointer on success, NULL on error
+        */
+       void *(*get)(unsigned int host,
+               unsigned int item, size_t *size);

Fits on one line?

include/smem.h line 39

Quoted 6 lines
include/smem.h new file +6 -0
+
+       /**
+        * get_free_space() - Set the PWM invert
+        *
+        * @host:   the remote processor identifying a partition, or -1
+        * @return      free space, -ve on error

free space in bytes ?

Quoted 46 lines
include/smem.h new file +45 -1
+        */
+       int (*get_free_space)(unsigned int host);
+};
+
+#define smem_get_ops(dev)      ((struct smem_ops *)(dev)->driver->ops)
+
+/**
+ * smem_alloc() - allocate space for a smem item
+ * @host:      remote processor id, or -1
+ * @item:      smem item handle
+ * @size:      number of bytes to be allocated
+ * @return 0 if OK, -ve on error
+ *
+ * Allocate space for a given smem item of size @size, given that the item is
+ * not yet allocated.
+ */
+int smem_alloc(struct udevice *dev, unsigned int host,
+               unsigned int item, size_t size);
+
+/**
+ * smem_get() - resolve ptr of size of a smem item
+ * @host:      the remote processor, or -1
+ * @item:      smem item handle
+ * @size:      pointer to be filled out with size of the item
+ * @return     pointer on success, NULL on error
+ *
+ * Looks up smem item and returns pointer to it. Size of smem
+ * item is returned in @size.
+ */
+void *smem_get(struct udevice *dev, unsigned int host,
+               unsigned int item, size_t *size);
+
+/**
+ * smem_get_free_space() - retrieve amount of free space in a partition
+ * @host:      the remote processor identifying a partition, or -1
+ * @free_space:        pointer to be filled out with free space
+ * @return     0 if OK, -ve on error
+ *
+ * To be used by smem clients as a quick way to determine if any new
+ * allocations has been made.
+ */
+int smem_get_free_space(struct udevice *dev, unsigned int host, size_t *free_space);
+
+#endif /* _smem_h_ */
+
--
Quoted 2 lines

2.17.1

Regards,
Simon

#3 lore raw

PATCH v2 1/6 dm: SMEM (Shared memory) uclass

Hi Simon

Quoted 116 lines · Simon Glass

Hi Ramon,

Quoted 16 lines · Ramon Fried

This is a uclass for Shared memory manager drivers.

A Shared Memory Manager driver implements an interface for allocating and accessing items in the memory area shared among all of the processors.

---

Changes in v2:
(As suggested by Simon Glass)
- Introduced a new dm class (CLASS_SMEM) instead of CLASS_SOC.
- Added sandbox driver
- Added testing for DM class.

Quoted 12 lines
 drivers/Makefile           |  1 +
 drivers/smem/Kconfig       |  2 +
 drivers/smem/Makefile      |  5 +++
 drivers/smem/smem-uclass.c | 53 ++++++++++++++++++++++++
 include/dm/uclass-id.h     |  1 +
 include/smem.h             | 84 ++++++++++++++++++++++++++++++++++++++
 6 files changed, 146 insertions(+)
 create mode 100644 drivers/smem/Kconfig
 create mode 100644 drivers/smem/Makefile
 create mode 100644 drivers/smem/smem-uclass.c
 create mode 100644 include/smem.h

A few nits below.

Quoted 59 lines
drivers/Makefile +1 -0
index a213ea9671..ba4a561358 100644
@@ -98,6 +98,7 @@ obj-y += pwm/
 obj-y += reset/
 obj-y += input/
 # SOC specific infrastructure drivers.
+obj-y += smem/
 obj-y += soc/
 obj-$(CONFIG_REMOTEPROC) += remoteproc/
 obj-y += thermal/
drivers/smem/Kconfig new file +2 -0
new file mode 100644
index 0000000000..64337a8b8e
@@ -0,0 +1,2 @@
+menuconfig SMEM
+       bool  "SMEM (Shared Memory mamanger) support"
drivers/smem/Makefile new file +5 -0
new file mode 100644
index 0000000000..ca55c4512d
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Makefile for the U-Boot SMEM interface drivers
+
+obj-$(CONFIG_SMEM) += smem-uclass.o
drivers/smem/smem-uclass.c new file +22 -0
new file mode 100644
index 0000000000..07ed1a92d8
@@ -0,0 +1,53 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2018 Ramon Fried <[email protected]>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <smem.h>
+
+int smem_alloc(struct udevice *dev, unsigned int host,
+               unsigned int item, size_t size)
+{
+       struct smem_ops *ops = smem_get_ops(dev);
+
+       if (!ops->alloc)
+               return -ENOSYS;
+
+       return ops->alloc(host, item, size);
+}
+
+void *smem_get(struct udevice *dev, unsigned int host,
+               unsigned int item, size_t *size)

drivers/smem/smem-uclass.c line 32

Quoted 10 lines
drivers/smem/smem-uclass.c new file +10 -0
+{
+       struct smem_ops *ops = smem_get_ops(dev);
+
+       if (!ops->get)
+               return NULL;
+
+       return ops->get(host, item, size);
+}
+
+int smem_get_free_space(struct udevice *dev, unsigned int host, size_t

*free)

Quoted 10 lines
drivers/smem/smem-uclass.c new file +10 -0
+{
+       struct smem_ops *ops = smem_get_ops(dev);
+
+       int ret;
+
+       if (!ops->get_free_space)
+               return -ENOSYS;
+
+       ret = ops->get_free_space(host);
+       if (ret > 0)
Quoted 9 lines

drivers/smem/smem-uclass.c line 45

Quoted 3 lines
drivers/smem/smem-uclass.c new file +3 -0
+               *free = ret;
+       else
+               return ret;

It seems odd that get_free_space() has a different return value than smem_get_free_space(). Can you make the latter return the amount of free space? If not, change the op to return it in a param. You can use long as the return value if that helps.

I fixed smem_get_free_space() to look the same as get_free_space().

Quoted 33 lines
Quoted 13 lines
drivers/smem/smem-uclass.c new file +8 -0
+
+       return 0;
+}
+
+UCLASS_DRIVER(smem) = {
+       .id     = UCLASS_SMEM,
+       .name       = "smem",
+};
include/dm/uclass-id.h +0 -0
index d7f9df3583..a39643ec5e 100644

include/dm/uclass-id.h enum uclass_id { · line 79

Quoted 6 lines
include/dm/uclass-id.h +1 -0
@@ -74,6 +74,7 @@ enum uclass_id {
        UCLASS_RTC,             /* Real time clock device */
        UCLASS_SCSI,            /* SCSI device */
        UCLASS_SERIAL,          /* Serial UART */
+       UCLASS_SMEM,            /* Shared memory interface */
        UCLASS_SPI,             /* SPI bus */
        UCLASS_SPMI,            /* System Power Management Interface bus

*/

include/smem.h line 3

Quoted 10 lines
include/dm/uclass-id.h +0 -0
        UCLASS_SPI_FLASH,       /* SPI flash */
include/smem.h new file +3 -0
new file mode 100644
index 0000000000..201960232c
@@ -0,0 +1,84 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * header file for smem driver.

If you have a README somewhere please point to it here.

Quoted 16 lines

include/smem.h line 16

Quoted 13 lines
include/smem.h new file +13 -0
+ *
+ * Copyright (c) 2018 Ramon Fried <[email protected]>
+ */
+
+#ifndef _smemh_
+#define _smemh_
+
+/* struct smem_ops: Operations for the SMEM uclass */
+struct smem_ops {
+       /**
+        * alloc() - allocate space for a smem item
+        *
+        * @host:       remote processor id, or -1

What does -1 mean? Please expand commment

Done.

Quoted 6 lines

include/smem.h line 17

Quoted 2 lines
include/smem.h new file +1 -0
+        * @item:       smem item handle

How does one choose this? What does it mean? Can you expand this comment a bit?

Quoted 8 lines

include/smem.h line 22

Quoted 5 lines
include/smem.h new file +5 -0
+        * @size:       number of bytes to be allocated
+        * @return 0 if OK, -ve on error
+        */
+       int (*alloc)(unsigned int host,
+               unsigned int item, size_t size);

Fits on one line?

Checkpatch complained, but I agree, this should be one line.

Quoted 15 lines

include/smem.h

Quoted 7 lines
include/smem.h new file +7 -0
+
+       /**
+        * get() - Resolve ptr of size of a smem item
+        *
+        * @host:       the remote processor, of -1
+        * @item:       smem item handle
+        * @size:       pointer to be filled out with the size of the

item

include/smem.h line 33

Quoted 4 lines
include/smem.h new file +4 -0
+        * @return      pointer on success, NULL on error
+        */
+       void *(*get)(unsigned int host,
+               unsigned int item, size_t *size);

Fits on one line?

Quoted 9 lines

include/smem.h line 39

Quoted 6 lines
include/smem.h new file +6 -0
+
+       /**
+        * get_free_space() - Set the PWM invert
+        *
+        * @host:   the remote processor identifying a partition, or -1
+        * @return      free space, -ve on error

free space in bytes ?

Yes. Fixed.

Quoted 45 lines
Quoted 5 lines
include/smem.h new file +4 -0
+        */
+       int (*get_free_space)(unsigned int host);
+};
+

include/smem.h

Quoted 10 lines
include/smem.h new file +10 -0
+#define smem_get_ops(dev)      ((struct smem_ops *)(dev)->driver->ops)
+
+/**
+ * smem_alloc() - allocate space for a smem item
+ * @host:      remote processor id, or -1
+ * @item:      smem item handle
+ * @size:      number of bytes to be allocated
+ * @return 0 if OK, -ve on error
+ *
+ * Allocate space for a given smem item of size @size, given that the

item is

Quoted 18 lines
include/smem.h new file +18 -0
+ * not yet allocated.
+ */
+int smem_alloc(struct udevice *dev, unsigned int host,
+               unsigned int item, size_t size);
+
+/**
+ * smem_get() - resolve ptr of size of a smem item
+ * @host:      the remote processor, or -1
+ * @item:      smem item handle
+ * @size:      pointer to be filled out with size of the item
+ * @return     pointer on success, NULL on error
+ *
+ * Looks up smem item and returns pointer to it. Size of smem
+ * item is returned in @size.
+ */
+void *smem_get(struct udevice *dev, unsigned int host,
+               unsigned int item, size_t *size);
+

include/smem.h

Quoted 10 lines
include/smem.h new file +10 -0
+/**
+ * smem_get_free_space() - retrieve amount of free space in a partition
+ * @host:      the remote processor identifying a partition, or -1
+ * @free_space:        pointer to be filled out with free space
+ * @return     0 if OK, -ve on error
+ *
+ * To be used by smem clients as a quick way to determine if any new
+ * allocations has been made.
+ */
+int smem_get_free_space(struct udevice *dev, unsigned int host, size_t

*free_space);

Quoted 7 lines
Quoted 6 lines
include/smem.h new file +3 -1
+
+#endif /* _smem_h_ */
+
--

2.17.1

Thanks,
Ramon.

Quoted 4 lines

Regards,
Simon

#4 lore raw

PATCH v2 1/6 dm: SMEM (Shared memory) uclass

In reply to Simon Glass
Quoted 174 lines · Simon Glass

Hi Ramon,

Quoted 16 lines · Ramon Fried

This is a uclass for Shared memory manager drivers.

A Shared Memory Manager driver implements an interface for allocating and accessing items in the memory area shared among all of the processors.

---

Changes in v2:
(As suggested by Simon Glass)
- Introduced a new dm class (CLASS_SMEM) instead of CLASS_SOC.
- Added sandbox driver
- Added testing for DM class.

Quoted 12 lines
 drivers/Makefile           |  1 +
 drivers/smem/Kconfig       |  2 +
 drivers/smem/Makefile      |  5 +++
 drivers/smem/smem-uclass.c | 53 ++++++++++++++++++++++++
 include/dm/uclass-id.h     |  1 +
 include/smem.h             | 84 ++++++++++++++++++++++++++++++++++++++
 6 files changed, 146 insertions(+)
 create mode 100644 drivers/smem/Kconfig
 create mode 100644 drivers/smem/Makefile
 create mode 100644 drivers/smem/smem-uclass.c
 create mode 100644 include/smem.h

A few nits below.

Quoted 59 lines
drivers/Makefile +1 -0
index a213ea9671..ba4a561358 100644
@@ -98,6 +98,7 @@ obj-y += pwm/
 obj-y += reset/
 obj-y += input/
 # SOC specific infrastructure drivers.
+obj-y += smem/
 obj-y += soc/
 obj-$(CONFIG_REMOTEPROC) += remoteproc/
 obj-y += thermal/
drivers/smem/Kconfig new file +2 -0
new file mode 100644
index 0000000000..64337a8b8e
@@ -0,0 +1,2 @@
+menuconfig SMEM
+       bool  "SMEM (Shared Memory mamanger) support"
drivers/smem/Makefile new file +5 -0
new file mode 100644
index 0000000000..ca55c4512d
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Makefile for the U-Boot SMEM interface drivers
+
+obj-$(CONFIG_SMEM) += smem-uclass.o
drivers/smem/smem-uclass.c new file +22 -0
new file mode 100644
index 0000000000..07ed1a92d8
@@ -0,0 +1,53 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2018 Ramon Fried <[email protected]>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <smem.h>
+
+int smem_alloc(struct udevice *dev, unsigned int host,
+               unsigned int item, size_t size)
+{
+       struct smem_ops *ops = smem_get_ops(dev);
+
+       if (!ops->alloc)
+               return -ENOSYS;
+
+       return ops->alloc(host, item, size);
+}
+
+void *smem_get(struct udevice *dev, unsigned int host,
+               unsigned int item, size_t *size)

drivers/smem/smem-uclass.c line 32

Quoted 10 lines
drivers/smem/smem-uclass.c new file +10 -0
+{
+       struct smem_ops *ops = smem_get_ops(dev);
+
+       if (!ops->get)
+               return NULL;
+
+       return ops->get(host, item, size);
+}
+
+int smem_get_free_space(struct udevice *dev, unsigned int host, size_t

*free)

drivers/smem/smem-uclass.c line 45

Quoted 13 lines
drivers/smem/smem-uclass.c new file +13 -0
+{
+       struct smem_ops *ops = smem_get_ops(dev);
+
+       int ret;
+
+       if (!ops->get_free_space)
+               return -ENOSYS;
+
+       ret = ops->get_free_space(host);
+       if (ret > 0)
+               *free = ret;
+       else
+               return ret;

It seems odd that get_free_space() has a different return value than smem_get_free_space(). Can you make the latter return the amount of free space? If not, change the op to return it in a param. You can use long as the return value if that helps.

Quoted 13 lines
drivers/smem/smem-uclass.c new file +8 -0
+
+       return 0;
+}
+
+UCLASS_DRIVER(smem) = {
+       .id     = UCLASS_SMEM,
+       .name       = "smem",
+};
include/dm/uclass-id.h +0 -0
index d7f9df3583..a39643ec5e 100644

include/dm/uclass-id.h enum uclass_id { · line 79

Quoted 6 lines
include/dm/uclass-id.h +1 -0
@@ -74,6 +74,7 @@ enum uclass_id {
        UCLASS_RTC,             /* Real time clock device */
        UCLASS_SCSI,            /* SCSI device */
        UCLASS_SERIAL,          /* Serial UART */
+       UCLASS_SMEM,            /* Shared memory interface */
        UCLASS_SPI,             /* SPI bus */
        UCLASS_SPMI,            /* System Power Management Interface bus

*/

include/smem.h line 3

Quoted 10 lines
include/dm/uclass-id.h +0 -0
        UCLASS_SPI_FLASH,       /* SPI flash */
include/smem.h new file +3 -0
new file mode 100644
index 0000000000..201960232c
@@ -0,0 +1,84 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * header file for smem driver.

If you have a README somewhere please point to it here.

include/smem.h line 16

Quoted 13 lines
include/smem.h new file +13 -0
+ *
+ * Copyright (c) 2018 Ramon Fried <[email protected]>
+ */
+
+#ifndef _smemh_
+#define _smemh_
+
+/* struct smem_ops: Operations for the SMEM uclass */
+struct smem_ops {
+       /**
+        * alloc() - allocate space for a smem item
+        *
+        * @host:       remote processor id, or -1

What does -1 mean? Please expand commment

Quoted 5 lines

include/smem.h line 17

Quoted 1 line
include/smem.h new file +1 -0
+        * @item:       smem item handle

How does one choose this? What does it mean? Can you expand this comment a bit?

It can be an index (like in QCOM implementation) but honestly, it can be a hash as well. it's up to the implementation
to decide how to access the items.

Quoted 86 lines

include/smem.h line 22

Quoted 6 lines
include/smem.h new file +5 -0
+        * @size:       number of bytes to be allocated
+        * @return 0 if OK, -ve on error
+        */
+       int (*alloc)(unsigned int host,
+               unsigned int item, size_t size);

Fits on one line?

include/smem.h

Quoted 7 lines
include/smem.h new file +7 -0
+
+       /**
+        * get() - Resolve ptr of size of a smem item
+        *
+        * @host:       the remote processor, of -1
+        * @item:       smem item handle
+        * @size:       pointer to be filled out with the size of the

item

include/smem.h line 33

Quoted 4 lines
include/smem.h new file +4 -0
+        * @return      pointer on success, NULL on error
+        */
+       void *(*get)(unsigned int host,
+               unsigned int item, size_t *size);

Fits on one line?

include/smem.h line 39

Quoted 6 lines
include/smem.h new file +6 -0
+
+       /**
+        * get_free_space() - Set the PWM invert
+        *
+        * @host:   the remote processor identifying a partition, or -1
+        * @return      free space, -ve on error

free space in bytes ?

Quoted 4 lines
include/smem.h new file +4 -0
+        */
+       int (*get_free_space)(unsigned int host);
+};
+

include/smem.h

Quoted 10 lines
include/smem.h new file +10 -0
+#define smem_get_ops(dev)      ((struct smem_ops *)(dev)->driver->ops)
+
+/**
+ * smem_alloc() - allocate space for a smem item
+ * @host:      remote processor id, or -1
+ * @item:      smem item handle
+ * @size:      number of bytes to be allocated
+ * @return 0 if OK, -ve on error
+ *
+ * Allocate space for a given smem item of size @size, given that the

item is

Quoted 18 lines
include/smem.h new file +18 -0
+ * not yet allocated.
+ */
+int smem_alloc(struct udevice *dev, unsigned int host,
+               unsigned int item, size_t size);
+
+/**
+ * smem_get() - resolve ptr of size of a smem item
+ * @host:      the remote processor, or -1
+ * @item:      smem item handle
+ * @size:      pointer to be filled out with size of the item
+ * @return     pointer on success, NULL on error
+ *
+ * Looks up smem item and returns pointer to it. Size of smem
+ * item is returned in @size.
+ */
+void *smem_get(struct udevice *dev, unsigned int host,
+               unsigned int item, size_t *size);
+

include/smem.h

Quoted 10 lines
include/smem.h new file +10 -0
+/**
+ * smem_get_free_space() - retrieve amount of free space in a partition
+ * @host:      the remote processor identifying a partition, or -1
+ * @free_space:        pointer to be filled out with free space
+ * @return     0 if OK, -ve on error
+ *
+ * To be used by smem clients as a quick way to determine if any new
+ * allocations has been made.
+ */
+int smem_get_free_space(struct udevice *dev, unsigned int host, size_t

*free_space);

Quoted 6 lines
include/smem.h new file +3 -1
+
+#endif /* _smem_h_ */
+
--

2.17.1

Regards,
Simon

#5 lore raw

PATCH v2 1/6 dm: SMEM (Shared memory) uclass

HI Ramon,

Quoted 40 lines · Ramon Fried
Quoted 37 lines · Simon Glass

Hi Ramon,

Quoted 16 lines · Ramon Fried

This is a uclass for Shared memory manager drivers.

A Shared Memory Manager driver implements an interface for allocating and accessing items in the memory area shared among all of the processors.

---

Changes in v2:
(As suggested by Simon Glass)
- Introduced a new dm class (CLASS_SMEM) instead of CLASS_SOC.
- Added sandbox driver
- Added testing for DM class.

Quoted 12 lines
 drivers/Makefile           |  1 +
 drivers/smem/Kconfig       |  2 +
 drivers/smem/Makefile      |  5 +++
 drivers/smem/smem-uclass.c | 53 ++++++++++++++++++++++++
 include/dm/uclass-id.h     |  1 +
 include/smem.h             | 84 ++++++++++++++++++++++++++++++++++++++
 6 files changed, 146 insertions(+)
 create mode 100644 drivers/smem/Kconfig
 create mode 100644 drivers/smem/Makefile
 create mode 100644 drivers/smem/smem-uclass.c
 create mode 100644 include/smem.h

A few nits below.

[..]

Quoted 9 lines
Quoted 9 lines

include/smem.h line 16

Quoted 6 lines
include/smem.h new file +6 -0
+/* struct smem_ops: Operations for the SMEM uclass */
+struct smem_ops {
+       /**
+        * alloc() - allocate space for a smem item
+        *
+        * @host:       remote processor id, or -1

What does -1 mean? Please expand commment

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

+ * @item: smem item handle

How does one choose this? What does it mean? Can you expand this comment a bit?

It can be an index (like in QCOM implementation) but honestly, it can be a hash as well. it's up to the implementation
to decide how to access the items.

OK that's fine. The key thing is to document this. Your API at present is pretty vague which is why I am asking for more comments showing what is going on. Even a comment at the top of your header file with an example of usage would be useful.

I just saw your latest v3 patch and it still seems to me that it needs more details. I had to read the qualcomm driver to try to understand how the uclass API is supposed to work.

Regards,
Simon

#6 lore raw

PATCH v2 1/6 dm: SMEM (Shared memory) uclass

Quoted 71 lines · Simon Glass

HI Ramon,

Quoted 23 lines · Ramon Fried
Quoted 20 lines · Simon Glass

Hi Ramon,

Quoted 16 lines · Ramon Fried

This is a uclass for Shared memory manager drivers.

A Shared Memory Manager driver implements an interface for allocating and accessing items in the memory area shared among all of the processors.

---

Changes in v2:
(As suggested by Simon Glass)
- Introduced a new dm class (CLASS_SMEM) instead of CLASS_SOC.
- Added sandbox driver
- Added testing for DM class.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
 drivers/Makefile           |  1 +
 drivers/smem/Kconfig       |  2 +
 drivers/smem/Makefile      |  5 +++
 drivers/smem/smem-uclass.c | 53 ++++++++++++++++++++++++
 include/dm/uclass-id.h     |  1 +
 include/smem.h             | 84

++++++++++++++++++++++++++++++++++++++

Quoted 11 lines
Quoted 11 lines
Quoted 6 lines
 6 files changed, 146 insertions(+)
 create mode 100644 drivers/smem/Kconfig
 create mode 100644 drivers/smem/Makefile
 create mode 100644 drivers/smem/smem-uclass.c
 create mode 100644 include/smem.h

A few nits below.

[..]

Quoted 9 lines
Quoted 9 lines

include/smem.h line 16

Quoted 6 lines
include/smem.h new file +6 -0
+/* struct smem_ops: Operations for the SMEM uclass */
+struct smem_ops {
+       /**
+        * alloc() - allocate space for a smem item
+        *
+        * @host:       remote processor id, or -1

What does -1 mean? Please expand commment

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

+ * @item: smem item handle

How does one choose this? What does it mean? Can you expand this

comment a

Quoted 3 lines
Quoted 1 line

bit?

It can be an index (like in QCOM implementation) but honestly, it can be

a

Quoted 2 lines

hash as well. it's up to the implementation
to decide how to access the items.

OK that's fine. The key thing is to document this. Your API at present is pretty vague which is why I am asking for more comments showing what is going on. Even a comment at the top of your header file with an example of usage would be useful.

Quoted 5 lines

I just saw your latest v3 patch and it still seems to me that it needs more details. I had to read the qualcomm driver to try to understand how the uclass API is supposed to work.

Thanks for the feedback. I'll look in to it soon.

Thanks,
Ramon.

Quoted 3 lines

Regards,
Simon

#7 lore raw

PATCH v2 1/6 dm: SMEM (Shared memory) uclass

In reply to Ramon Fried
Quoted 10 lines · Ramon Fried

This is a uclass for Shared memory manager drivers.

A Shared Memory Manager driver implements an interface for allocating and accessing items in the memory area shared among all of the processors.

See below for a requested correction.

Quoted 155 lines

---

Changes in v2:
(As suggested by Simon Glass)
- Introduced a new dm class (CLASS_SMEM) instead of CLASS_SOC.
- Added sandbox driver
- Added testing for DM class.

drivers/Makefile           |  1 +
drivers/smem/Kconfig       |  2 +
drivers/smem/Makefile      |  5 +++
drivers/smem/smem-uclass.c | 53 ++++++++++++++++++++++++
include/dm/uclass-id.h     |  1 +
include/smem.h             | 84 ++++++++++++++++++++++++++++++++++++++
6 files changed, 146 insertions(+)

create mode 100644 drivers/smem/Kconfig
create mode 100644 drivers/smem/Makefile
create mode 100644 drivers/smem/smem-uclass.c
create mode 100644 include/smem.h

drivers/Makefile +0 -0
index a213ea9671..ba4a561358 100644
@@ -98,6 +98,7 @@ obj-y += pwm/

obj-y += reset/
obj-y += input/
# SOC specific infrastructure drivers.
+obj-y += smem/
obj-y += soc/
obj-$(CONFIG_REMOTEPROC) += remoteproc/
obj-y += thermal/

drivers/smem/Kconfig new file +2 -0
new file mode 100644
index 0000000000..64337a8b8e
@@ -0,0 +1,2 @@
+menuconfig SMEM
+	bool  "SMEM (Shared Memory mamanger) support"
drivers/smem/Makefile new file +5 -0
new file mode 100644
index 0000000000..ca55c4512d
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Makefile for the U-Boot SMEM interface drivers
+
+obj-$(CONFIG_SMEM) += smem-uclass.o
drivers/smem/smem-uclass.c new file +53 -0
new file mode 100644
index 0000000000..07ed1a92d8
@@ -0,0 +1,53 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2018 Ramon Fried <[email protected]>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <smem.h>
+
+int smem_alloc(struct udevice *dev, unsigned int host,
+		unsigned int item, size_t size)
+{
+	struct smem_ops *ops = smem_get_ops(dev);
+
+	if (!ops->alloc)
+		return -ENOSYS;
+
+	return ops->alloc(host, item, size);
+}
+
+void *smem_get(struct udevice *dev, unsigned int host,
+		unsigned int item, size_t *size)
+{
+	struct smem_ops *ops = smem_get_ops(dev);
+
+	if (!ops->get)
+		return NULL;
+
+	return ops->get(host, item, size);
+}
+
+int smem_get_free_space(struct udevice *dev, unsigned int host, size_t *free)
+{
+	struct smem_ops *ops = smem_get_ops(dev);
+
+	int ret;
+
+	if (!ops->get_free_space)
+		return -ENOSYS;
+
+	ret = ops->get_free_space(host);
+	if (ret > 0)
+		*free = ret;
+	else
+		return ret;
+
+	return 0;
+}
+
+UCLASS_DRIVER(smem) = {
+	.id     = UCLASS_SMEM,
+	.name       = "smem",
+};
include/dm/uclass-id.h +1 -0
index d7f9df3583..a39643ec5e 100644
@@ -74,6 +74,7 @@ enum uclass_id {
 	UCLASS_RTC,		/* Real time clock device */
 	UCLASS_SCSI,		/* SCSI device */
 	UCLASS_SERIAL,		/* Serial UART */
+	UCLASS_SMEM,		/* Shared memory interface */
 	UCLASS_SPI,		/* SPI bus */
 	UCLASS_SPMI,		/* System Power Management Interface bus */
 	UCLASS_SPI_FLASH,	/* SPI flash */
include/smem.h new file +26 -0
new file mode 100644
index 0000000000..201960232c
@@ -0,0 +1,84 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * header file for smem driver.
+ *
+ * Copyright (c) 2018 Ramon Fried <[email protected]>
+ */
+
+#ifndef _smemh_
+#define _smemh_
+
+/* struct smem_ops: Operations for the SMEM uclass */
+struct smem_ops {
+	/**
+	 * alloc() - allocate space for a smem item
+	 *
+	 * @host:	remote processor id, or -1
+	 * @item:	smem item handle
+	 * @size:	number of bytes to be allocated
+	 * @return 0 if OK, -ve on error
+	 */
+	int (*alloc)(unsigned int host,
+		unsigned int item, size_t size);
+
+	/**
+	 * get() - Resolve ptr of size of a smem item
+	 *

include/smem.h line 36

Quoted 10 lines
include/smem.h new file +10 -0
+	 * @host:	the remote processor, of -1
+	 * @item:	smem item handle
+	 * @size:	pointer to be filled out with the size of the item
+	 * @return	pointer on success, NULL on error
+	 */
+	void *(*get)(unsigned int host,
+		unsigned int item, size_t *size);
+
+	/**
+	 * get_free_space() - Set the PWM invert

The “Set the PWM invert” part seems like a mistake here...

Quoted 49 lines
include/smem.h new file +48 -1
+	 *
+	 * @host:   the remote processor identifying a partition, or -1
+	 * @return	free space, -ve on error
+	 */
+	int (*get_free_space)(unsigned int host);
+};
+
+#define smem_get_ops(dev)	((struct smem_ops *)(dev)->driver->ops)
+
+/**
+ * smem_alloc() - allocate space for a smem item
+ * @host:	remote processor id, or -1
+ * @item:	smem item handle
+ * @size:	number of bytes to be allocated
+ * @return 0 if OK, -ve on error
+ *
+ * Allocate space for a given smem item of size @size, given that the item is
+ * not yet allocated.
+ */
+int smem_alloc(struct udevice *dev, unsigned int host,
+		unsigned int item, size_t size);
+
+/**
+ * smem_get() - resolve ptr of size of a smem item
+ * @host:	the remote processor, or -1
+ * @item:	smem item handle
+ * @size:	pointer to be filled out with size of the item
+ * @return	pointer on success, NULL on error
+ *
+ * Looks up smem item and returns pointer to it. Size of smem
+ * item is returned in @size.
+ */
+void *smem_get(struct udevice *dev, unsigned int host,
+		unsigned int item, size_t *size);
+
+/**
+ * smem_get_free_space() - retrieve amount of free space in a partition
+ * @host:	the remote processor identifying a partition, or -1
+ * @free_space:	pointer to be filled out with free space
+ * @return	0 if OK, -ve on error
+ *
+ * To be used by smem clients as a quick way to determine if any new
+ * allocations has been made.
+ */
+int smem_get_free_space(struct udevice *dev, unsigned int host, size_t *free_space);
+
+#endif /* _smem_h_ */
+
--
Quoted 2 lines

2.17.1

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 529 bytes
Desc: Message signed with OpenPGP
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180626/ea06cd95/attachment.sig>

#8 lore raw

PATCH v2 1/6 dm: SMEM (Shared memory) uclass

Quoted 9 lines · Dr. Philipp Tomsich
Quoted 9 lines · Ramon Fried

This is a uclass for Shared memory manager drivers.

A Shared Memory Manager driver implements an interface for allocating and accessing items in the memory area shared among all of the processors.

Quoted 7 lines
Quoted 1 line

See below for a requested correction.

Quoted 1 line

Thanks. Nice catch...

Quoted 223 lines
Quoted 8 lines

---

Changes in v2:
(As suggested by Simon Glass)
- Introduced a new dm class (CLASS_SMEM) instead of CLASS_SOC.
- Added sandbox driver
- Added testing for DM class.

Quoted 6 lines
drivers/Makefile           |  1 +
drivers/smem/Kconfig       |  2 +
drivers/smem/Makefile      |  5 +++
drivers/smem/smem-uclass.c | 53 ++++++++++++++++++++++++
include/dm/uclass-id.h     |  1 +
include/smem.h             | 84

++++++++++++++++++++++++++++++++++++++

Quoted 65 lines
6 files changed, 146 insertions(+)

create mode 100644 drivers/smem/Kconfig
create mode 100644 drivers/smem/Makefile
create mode 100644 drivers/smem/smem-uclass.c
create mode 100644 include/smem.h

drivers/Makefile +0 -0
index a213ea9671..ba4a561358 100644
@@ -98,6 +98,7 @@ obj-y += pwm/

obj-y += reset/
obj-y += input/
# SOC specific infrastructure drivers.
+obj-y += smem/
obj-y += soc/
obj-$(CONFIG_REMOTEPROC) += remoteproc/
obj-y += thermal/

drivers/smem/Kconfig new file +2 -0
new file mode 100644
index 0000000000..64337a8b8e
@@ -0,0 +1,2 @@
+menuconfig SMEM
+	bool  "SMEM (Shared Memory mamanger) support"
drivers/smem/Makefile new file +5 -0
new file mode 100644
index 0000000000..ca55c4512d
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Makefile for the U-Boot SMEM interface drivers
+
+obj-$(CONFIG_SMEM) += smem-uclass.o
drivers/smem/smem-uclass.c new file +22 -0
new file mode 100644
index 0000000000..07ed1a92d8
@@ -0,0 +1,53 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2018 Ramon Fried <[email protected]>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <smem.h>
+
+int smem_alloc(struct udevice *dev, unsigned int host,
+		unsigned int item, size_t size)
+{
+	struct smem_ops *ops = smem_get_ops(dev);
+
+	if (!ops->alloc)
+		return -ENOSYS;
+
+	return ops->alloc(host, item, size);
+}
+
+void *smem_get(struct udevice *dev, unsigned int host,
+		unsigned int item, size_t *size)

drivers/smem/smem-uclass.c line 32

Quoted 10 lines
drivers/smem/smem-uclass.c new file +10 -0
+{
+	struct smem_ops *ops = smem_get_ops(dev);
+
+	if (!ops->get)
+		return NULL;
+
+	return ops->get(host, item, size);
+}
+
+int smem_get_free_space(struct udevice *dev, unsigned int host,

size_t *free)

Quoted 65 lines
drivers/smem/smem-uclass.c new file +21 -0
+{
+	struct smem_ops *ops = smem_get_ops(dev);
+
+	int ret;
+
+	if (!ops->get_free_space)
+		return -ENOSYS;
+
+	ret = ops->get_free_space(host);
+	if (ret > 0)
+		*free = ret;
+	else
+		return ret;
+
+	return 0;
+}
+
+UCLASS_DRIVER(smem) = {
+	.id     = UCLASS_SMEM,
+	.name       = "smem",
+};
include/dm/uclass-id.h +1 -0
index d7f9df3583..a39643ec5e 100644
@@ -74,6 +74,7 @@ enum uclass_id {
 	UCLASS_RTC,		/* Real time clock device */
 	UCLASS_SCSI,		/* SCSI device */
 	UCLASS_SERIAL,		/* Serial UART */
+	UCLASS_SMEM,		/* Shared memory interface */
 	UCLASS_SPI,		/* SPI bus */
 	UCLASS_SPMI,		/* System Power Management Interface bus */
 	UCLASS_SPI_FLASH,	/* SPI flash */
include/smem.h new file +26 -0
new file mode 100644
index 0000000000..201960232c
@@ -0,0 +1,84 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * header file for smem driver.
+ *
+ * Copyright (c) 2018 Ramon Fried <[email protected]>
+ */
+
+#ifndef _smemh_
+#define _smemh_
+
+/* struct smem_ops: Operations for the SMEM uclass */
+struct smem_ops {
+	/**
+	 * alloc() - allocate space for a smem item
+	 *
+	 * @host:	remote processor id, or -1
+	 * @item:	smem item handle
+	 * @size:	number of bytes to be allocated
+	 * @return 0 if OK, -ve on error
+	 */
+	int (*alloc)(unsigned int host,
+		unsigned int item, size_t size);
+
+	/**
+	 * get() - Resolve ptr of size of a smem item
+	 *

include/smem.h line 36

Quoted 10 lines
include/smem.h new file +10 -0
+	 * @host:	the remote processor, of -1
+	 * @item:	smem item handle
+	 * @size:	pointer to be filled out with the size of the item
+	 * @return	pointer on success, NULL on error
+	 */
+	void *(*get)(unsigned int host,
+		unsigned int item, size_t *size);
+
+	/**
+	 * get_free_space() - Set the PWM invert

The “Set the PWM invert” part seems like a mistake here...

Quoted 7 lines
include/smem.h new file +7 -0
+	 *
+	 * @host:   the remote processor identifying a partition, or -1
+	 * @return	free space, -ve on error
+	 */
+	int (*get_free_space)(unsigned int host);
+};
+

include/smem.h

Quoted 10 lines
include/smem.h new file +10 -0
+#define smem_get_ops(dev)	((struct smem_ops *)(dev)->driver->ops)
+
+/**
+ * smem_alloc() - allocate space for a smem item
+ * @host:	remote processor id, or -1
+ * @item:	smem item handle
+ * @size:	number of bytes to be allocated
+ * @return 0 if OK, -ve on error
+ *
+ * Allocate space for a given smem item of size @size, given that

the item is

Quoted 10 lines
include/smem.h new file +10 -0
+ * not yet allocated.
+ */
+int smem_alloc(struct udevice *dev, unsigned int host,
+		unsigned int item, size_t size);
+
+/**
+ * smem_get() - resolve ptr of size of a smem item
+ * @host:	the remote processor, or -1
+ * @item:	smem item handle
+ * @size:	pointer to be filled out with size of the item

include/smem.h

Quoted 10 lines
include/smem.h new file +10 -0
+ * @return	pointer on success, NULL on error
+ *
+ * Looks up smem item and returns pointer to it. Size of smem
+ * item is returned in @size.
+ */
+void *smem_get(struct udevice *dev, unsigned int host,
+		unsigned int item, size_t *size);
+
+/**
+ * smem_get_free_space() - retrieve amount of free space in a

partition

include/smem.h

Quoted 8 lines
include/smem.h new file +8 -0
+ * @host:	the remote processor identifying a partition, or -1
+ * @free_space:	pointer to be filled out with free space
+ * @return	0 if OK, -ve on error
+ *
+ * To be used by smem clients as a quick way to determine if any new
+ * allocations has been made.
+ */
+int smem_get_free_space(struct udevice *dev, unsigned int host,

size_t *free_space);

Quoted 6 lines
include/smem.h new file +3 -1
+
+#endif /* _smem_h_ */
+
--

2.17.1

Signature · 1 line
Sent from my Android device with K-9 Mail. Please excuse my brevity.
#9 lore raw

PATCH v2 2/6 soc: qualcomm: Add Shared Memory Manager driver

In reply to a message not in the archive

The Shared Memory Manager driver implements an interface for allocating and accessing items in the memory area shared among all of the processors in a Qualcomm platform.

Adapted from the Linux driver (4.17)

Changes from the original Linux driver:
* Removed HW spinlock mechanism, which is irrelevant
in U-boot particualar use case, which is just reading from the smem.
* adaptaion from Linux driver model to U-boot's.

Cc Bjorn Andersson <[email protected]>

---

Changes in v2:
- Applied checkpatch fixes (also sent these to Linux upstream)
- Changed UCLASS_SOC to UCLASS_SMEM
- Removed function exports and registered functionality through .ops

 MAINTAINERS             |   1 +
 arch/arm/Kconfig        |   2 +
 drivers/Kconfig         |   2 +
 drivers/smem/Kconfig    |  13 +
 drivers/smem/Makefile   |   1 +
 drivers/smem/msm_smem.c | 941 ++++++++++++++++++++++++++++++++++++++++
 6 files changed, 960 insertions(+)
 create mode 100644 drivers/smem/msm_smem.c
MAINTAINERS +1 -0
index b2c9717cb7..b691bae13c 100644
@@ -187,6 +187,7 @@ ARM SNAPDRAGON
 M:	Ramon Fried <[email protected]>
 S:	Maintained
 F:	arch/arm/mach-snapdragon/
+F:	drivers/smem/msm_smem.c
 
 ARM STI
 M:	Patrice Chotard <[email protected]>
arch/arm/Kconfig +2 -0
index 22234cde2a..badf4cacb8 100644
@@ -728,6 +728,8 @@ config ARCH_SNAPDRAGON
 	select SPMI
 	select OF_CONTROL
 	select OF_SEPARATE
+	select SMEM
+	select MSM_SMEM
 
 config ARCH_SOCFPGA
 	bool "Altera SOCFPGA family"
drivers/Kconfig +2 -0
index 9e21b28750..c72abf8932 100644
@@ -84,6 +84,8 @@ source "drivers/scsi/Kconfig"
 
 source "drivers/serial/Kconfig"
 
+source "drivers/smem/Kconfig"
+
 source "drivers/sound/Kconfig"
 
 source "drivers/spi/Kconfig"
drivers/smem/Kconfig +13 -0
index 64337a8b8e..77ad02e236 100644
@@ -1,2 +1,15 @@
 menuconfig SMEM
 	bool  "SMEM (Shared Memory mamanger) support"
+
+if SMEM
+
+config MSM_SMEM
+    bool "Qualcomm Shared Memory Manager (SMEM)"
+    depends on DM
+    depends on ARCH_SNAPDRAGON
+    help
+      enable support for the Qualcomm Shared Memory Manager.
+      The driver provides an interface to items in a heap shared among all
+      processors in a Qualcomm platform.
+
+endif # menu "SMEM Support"
drivers/smem/Makefile +1 -0
index ca55c4512d..605b8fc290 100644
@@ -3,3 +3,4 @@
 # Makefile for the U-Boot SMEM interface drivers
 
 obj-$(CONFIG_SMEM) += smem-uclass.o
+obj-$(CONFIG_MSM_SMEM) += msm_smem.o
drivers/smem/msm_smem.c new file +941 -0

941 lines not on this page · raw message

Signature · 1 line
2.17.1
#10 lore raw

PATCH v2 2/6 soc: qualcomm: Add Shared Memory Manager driver

Hi Ramon,

Quoted 9 lines · Ramon Fried

The Shared Memory Manager driver implements an interface for allocating and accessing items in the memory area shared among all of the processors in a Qualcomm platform.

Adapted from the Linux driver (4.17)

Changes from the original Linux driver:
* Removed HW spinlock mechanism, which is irrelevant
in U-boot particualar use case, which is just reading from the smem.

U-Boot

Quoted 1 line

* adaptaion from Linux driver model to U-boot's.

Adapted (I think)

Quoted 11 lines
Cc Bjorn Andersson <[email protected]>

---

Changes in v2:
- Applied checkpatch fixes (also sent these to Linux upstream)
- Changed UCLASS_SOC to UCLASS_SMEM
- Removed function exports and registered functionality through .ops

Quoted 9 lines
 MAINTAINERS             |   1 +
 arch/arm/Kconfig        |   2 +
 drivers/Kconfig         |   2 +
 drivers/smem/Kconfig    |  13 +
 drivers/smem/Makefile   |   1 +
 drivers/smem/msm_smem.c | 941 ++++++++++++++++++++++++++++++++++++++++
 6 files changed, 960 insertions(+)
 create mode 100644 drivers/smem/msm_smem.c

with nits as noted.

Quoted 43 lines
MAINTAINERS +1 -0
index b2c9717cb7..b691bae13c 100644
@@ -187,6 +187,7 @@ ARM SNAPDRAGON
 M:     Ramon Fried <[email protected]>
 S:     Maintained
 F:     arch/arm/mach-snapdragon/
+F:     drivers/smem/msm_smem.c
 
 ARM STI
 M:     Patrice Chotard <[email protected]>
arch/arm/Kconfig +2 -0
index 22234cde2a..badf4cacb8 100644
@@ -728,6 +728,8 @@ config ARCH_SNAPDRAGON
        select SPMI
        select OF_CONTROL
        select OF_SEPARATE
+       select SMEM
+       select MSM_SMEM
 
 config ARCH_SOCFPGA
        bool "Altera SOCFPGA family"
drivers/Kconfig +2 -0
index 9e21b28750..c72abf8932 100644
@@ -84,6 +84,8 @@ source "drivers/scsi/Kconfig"
 
 source "drivers/serial/Kconfig"
 
+source "drivers/smem/Kconfig"
+
 source "drivers/sound/Kconfig"
 
 source "drivers/spi/Kconfig"
drivers/smem/Kconfig +0 -0
index 64337a8b8e..77ad02e236 100644

drivers/smem/Kconfig line 2

Quoted 2 lines
drivers/smem/Kconfig +0 -0
@@ -1,2 +1,15 @@
 menuconfig SMEM
        bool  "SMEM (Shared Memory mamanger) support"

manager

drivers/smem/Kconfig line 11

Quoted 9 lines
drivers/smem/Kconfig +9 -0
+
+if SMEM
+
+config MSM_SMEM
+    bool "Qualcomm Shared Memory Manager (SMEM)"
+    depends on DM
+    depends on ARCH_SNAPDRAGON
+    help
+      enable support for the Qualcomm Shared Memory Manager.

Enable

Quoted 23 lines
drivers/smem/Kconfig +4 -0
+      The driver provides an interface to items in a heap shared among all
+      processors in a Qualcomm platform.
+
+endif # menu "SMEM Support"
drivers/smem/Makefile +1 -0
index ca55c4512d..605b8fc290 100644
@@ -3,3 +3,4 @@
 # Makefile for the U-Boot SMEM interface drivers
 
 obj-$(CONFIG_SMEM) += smem-uclass.o
+obj-$(CONFIG_MSM_SMEM) += msm_smem.o
drivers/smem/msm_smem.c new file +4 -0
new file mode 100644
index 0000000000..183ab7b54b
@@ -0,0 +1,941 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2015, Sony Mobile Communications AB.
+ * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.

drivers/smem/msm_smem.c line 14

Quoted 10 lines
drivers/smem/msm_smem.c new file +10 -0
+ * Copyright (c) 2018, Ramon Fried <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.

Can you drop the license? The SPDX should be enough.

Quoted 6 lines
drivers/smem/msm_smem.c new file +6 -0
+ */
+
+#include <common.h>
+#include <errno.h>
+#include <dm.h>
+#include <dm/of_access.h>

drivers/smem/msm_smem.c line 30

Quoted 10 lines
drivers/smem/msm_smem.c new file +10 -0
+#include <dm/of_addr.h>
+#include <asm/io.h>
+#include <linux/ioport.h>
+#include <linux/io.h>
+#include <smem.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+/*
+ * The Qualcomm shared memory system is an allocate only heap structure that

allocate-only

drivers/smem/msm_smem.c line 43

Quoted 13 lines
drivers/smem/msm_smem.c new file +13 -0
+ * consists of one of more memory areas that can be accessed by the processors
+ * in the SoC.
+ *
+ * All systems contains a global heap, accessible by all processors in the SoC,
+ * with a table of contents data structure (@smem_header) at the beginning of
+ * the main shared memory block.
+ *
+ * The global header contains meta data for allocations as well as a fixed list
+ * of 512 entries (@smem_global_entry) that can be initialized to reference
+ * parts of the shared memory space.
+ *
+ *
+ * In addition to this global heap a set of "private" heaps can be set up at

heap, a

Quoted 16 lines
drivers/smem/msm_smem.c new file +16 -0
+ * boot time with access restrictions so that only certain processor pairs can
+ * access the data.
+ *
+ * These partitions are referenced from an optional partition table
+ * (@smem_ptable), that is found 4kB from the end of the main smem region. The
+ * partition table entries (@smem_ptable_entry) lists the involved processors
+ * (or hosts) and their location in the main shared memory region.
+ *
+ * Each partition starts with a header (@smem_partition_header) that identifies
+ * the partition and holds properties for the two internal memory regions. The
+ * two regions are cached and non-cached memory respectively. Each region
+ * contain a link list of allocation headers (@smem_private_entry) followed by
+ * their data.
+ *
+ * Items in the non-cached region are allocated from the start of the partition
+ * while items in the cached region are allocated from the end. The free area

drivers/smem/msm_smem.c line 69

Quoted 10 lines
drivers/smem/msm_smem.c new file +10 -0
+ * is hence the region between the cached and non-cached offsets. The header of
+ * cached items comes after the data.
+ *
+ * Version 12 (SMEM_GLOBAL_PART_VERSION) changes the item alloc/get procedure
+ * for the global heap. A new global partition is created from the global heap
+ * region with partition type (SMEM_GLOBAL_HOST) and the max smem item count is
+ * set by the bootloader.
+ *
+ */
+

[...]

Regards,
Simon

#11 lore raw

PATCH v2 3/6 dts: db410c: added smem nodes

In reply to a message not in the archive

Added necessary nodes for Qualcomm smem driver.

---

Changes in v2: None

 arch/arm/dts/dragonboard410c-uboot.dtsi |  5 +++++
 arch/arm/dts/dragonboard410c.dts        | 16 ++++++++++++++++
 2 files changed, 21 insertions(+)
arch/arm/dts/dragonboard410c-uboot.dtsi +5 -0
index 50ac2e6584..773439ab93 100644
@@ -6,6 +6,11 @@
  */
 
 / {
+
+	smem {
+		u-boot,dm-pre-reloc;
+	};
+
 	soc {
 		u-boot,dm-pre-reloc;
 
arch/arm/dts/dragonboard410c.dts +16 -0
index 182a865b0a..f4f7c350ec 100644
@@ -27,18 +27,34 @@
 		#address-cells = <2>;
 		#size-cells = <2>;
 		ranges;
+
+		smem_mem: smem_region at 86300000 {
+			reg = <0x0 0x86300000 0x0 0x100000>;
+			no-map;
+		};
 	};
 
 	chosen {
 		stdout-path = "/soc/serial at 78b0000";
 	};
 
+	smem {
+		compatible = "qcom,smem";
+		memory-region = <&smem_mem>;
+		qcom,rpm-msg-ram = <&rpm_msg_ram>;
+	};
+
 	soc {
 		#address-cells = <0x1>;
 		#size-cells = <0x1>;
 		ranges = <0x0 0x0 0x0 0xffffffff>;
 		compatible = "simple-bus";
 
+		rpm_msg_ram: memory at 60000 {
+			compatible = "qcom,rpm-msg-ram";
+			reg = <0x60000 0x8000>;
+		};
+
 		pinctrl: qcom,tlmm at 1000000 {
 			compatible = "qcom,tlmm-apq8016";
 			reg = <0x1000000 0x400000>;
Signature · 1 line
2.17.1
#13 lore raw

PATCH v2 4/6 dts: db820c: added smem nodes

In reply to a message not in the archive

Added necessary nodes for Qualcomm smem driver.

---

Changes in v2: None

 arch/arm/dts/dragonboard820c-uboot.dtsi |  4 ++++
 arch/arm/dts/dragonboard820c.dts        | 16 ++++++++++++++++
 2 files changed, 20 insertions(+)
arch/arm/dts/dragonboard820c-uboot.dtsi +4 -0
index 97394cc5b0..d60aa04494 100644
@@ -6,6 +6,10 @@
  */
 
 / {
+	smem {
+		u-boot,dm-pre-reloc;
+	};
+
 	soc {
 		u-boot,dm-pre-reloc;
 
arch/arm/dts/dragonboard820c.dts +16 -0
index 7457d7b7e3..ffad8e0e0a 100644
@@ -28,11 +28,27 @@
 		reg = <0 0x80000000 0 0xc0000000>;
 	};
 
+	reserved-memory {
+		#address-cells = <2>;
+		#size-cells = <2>;
+		ranges;
+
+		smem_mem: smem_region at 86300000 {
+			reg = <0x0 0x86300000 0x0 0x200000>;
+			no-map;
+		};
+	};
+
 	psci {
 		compatible = "arm,psci-1.0";
 		method = "smc";
 	};
 
+	smem {
+		compatible = "qcom,smem";
+		memory-region = <&smem_mem>;
+	};
+
 	soc: soc {
 		#address-cells = <1>;
 		#size-cells = <1>;
Signature · 1 line
2.17.1
#15 lore raw

PATCH v2 5/6 drivers: smem: sandbox

In reply to a message not in the archive

Add Sandbox driver for SMEM. mostly stub operations.

---

Changes in v2: None

 arch/sandbox/dts/test.dts   |  4 ++++
 configs/sandbox64_defconfig |  2 ++
 configs/sandbox_defconfig   |  2 ++
 drivers/smem/Kconfig        |  9 ++++++++
 drivers/smem/Makefile       |  1 +
 drivers/smem/sandbox_smem.c | 45 +++++++++++++++++++++++++++++++++++++
 6 files changed, 63 insertions(+)
 create mode 100644 drivers/smem/sandbox_smem.c
arch/sandbox/dts/test.dts +4 -0
index 5752bf547e..01e6bc0367 100644
@@ -382,6 +382,10 @@
 		remoteproc-name = "remoteproc-test-dev2";
 	};
 
+	smem at 0 {
+		compatible = "sandbox,smem";
+	};
+
 	spi at 0 {
 		#address-cells = <1>;
 		#size-cells = <0>;
configs/sandbox64_defconfig +2 -0
index 20a2ab3ffb..1fa85a819c 100644
@@ -199,3 +199,5 @@ CONFIG_UT_TIME=y
 CONFIG_UT_DM=y
 CONFIG_UT_ENV=y
 CONFIG_UT_OVERLAY=y
+CONFIG_SMEM=y
+CONFIG_SANDBOX_SMEM=y
configs/sandbox_defconfig +2 -0
index 2fc84a16c9..47f6bfd87f 100644
@@ -200,3 +200,5 @@ CONFIG_UT_TIME=y
 CONFIG_UT_DM=y
 CONFIG_UT_ENV=y
 CONFIG_UT_OVERLAY=y
+CONFIG_SMEM=y
+CONFIG_SANDBOX_SMEM=y
drivers/smem/Kconfig +9 -0
index 77ad02e236..3aa32a6c13 100644
@@ -3,6 +3,15 @@ menuconfig SMEM
 
 if SMEM
 
+config SANDBOX_SMEM
+    bool "Sandbox Shared Memory Manager (SMEM)"
+    depends on SANDBOX && DM
+    help
+      enable SMEM support for sandbox. This is an emulation of a real SMEM
+      manager.
+      The sandbox driver allocates a shared memory from the heap and
+      initialzies it on start.
+
 config MSM_SMEM
     bool "Qualcomm Shared Memory Manager (SMEM)"
     depends on DM
drivers/smem/Makefile +1 -0
index 605b8fc290..af3e9b5088 100644
@@ -2,5 +2,6 @@
 #
 # Makefile for the U-Boot SMEM interface drivers
 
+obj-$(CONFIG_SANDBOX_SMEM) += sandbox_smem.o
 obj-$(CONFIG_SMEM) += smem-uclass.o
 obj-$(CONFIG_MSM_SMEM) += msm_smem.o
drivers/smem/sandbox_smem.c new file +45 -0

45 lines not on this page · raw message

Signature · 1 line
2.17.1
#16 lore raw

PATCH v2 5/6 drivers: smem: sandbox

Quoted 7 lines · Ramon Fried

Add Sandbox driver for SMEM. mostly stub operations.

---

Changes in v2: None

Quoted 8 lines
 arch/sandbox/dts/test.dts   |  4 ++++
 configs/sandbox64_defconfig |  2 ++
 configs/sandbox_defconfig   |  2 ++
 drivers/smem/Kconfig        |  9 ++++++++
 drivers/smem/Makefile       |  1 +
 drivers/smem/sandbox_smem.c | 45 +++++++++++++++++++++++++++++++++++++
 6 files changed, 63 insertions(+)
 create mode 100644 drivers/smem/sandbox_smem.c
#17 lore raw

PATCH v2 6/6 test: smem: add basic smem test

In reply to a message not in the archive

Add basic smem sandbox testing.

---
Tom, this patch depends on https://patchwork.ozlabs.org/patch/932965/

Changes in v2: None

 test/dm/Makefile |  1 +
 test/dm/smem.c   | 29 +++++++++++++++++++++++++++++
 2 files changed, 30 insertions(+)
 create mode 100644 test/dm/smem.c
test/dm/Makefile +1 -0
index 5511a85700..d2ed96c615 100644
@@ -33,6 +33,7 @@ obj-$(CONFIG_DM_RESET) += reset.o
 obj-$(CONFIG_SYSRESET) += sysreset.o
 obj-$(CONFIG_DM_RTC) += rtc.o
 obj-$(CONFIG_DM_SPI_FLASH) += sf.o
+obj-$(CONFIG_SMEM) += smem.o
 obj-$(CONFIG_DM_SPI) += spi.o
 obj-y += syscon.o
 obj-$(CONFIG_DM_USB) += usb.o
test/dm/smem.c new file +29 -0
new file mode 100644
index 0000000000..4d94ddbe5b
@@ -0,0 +1,29 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2018 Ramon Fried <[email protected]>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <smem.h>
+#include <dm/test.h>
+#include <test/ut.h>
+
+/* Basic test of the smem uclass */
+static int dm_test_smem_base(struct unit_test_state *uts)
+{
+	struct udevice *dev;
+	size_t size;
+
+	ut_assertok(uclass_get_device(UCLASS_SMEM, 0, &dev));
+	ut_assertnonnull(dev);
+	ut_assertok(smem_alloc(dev, -1, 0, 16));
+	ut_assertok(smem_get_free_space(dev, -1, &size);
+	ut_assertnonnull(smem_get(dev, -1, 0, &size));
+	/* Try getting of bound item */
+	ut_assertnnull(smem_get(dev, -1, 70, &size));
+
+	return 0;
+}
+DM_TEST(dm_test_smem_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
Signature · 1 line
2.17.1