dm: SMEM (Shared memory) uclass
authorRamon Fried <ramon.fried@gmail.com>
Sun, 1 Jul 2018 23:57:55 +0000 (02:57 +0300)
committerTom Rini <trini@konsulko.com>
Thu, 19 Jul 2018 20:31:37 +0000 (16:31 -0400)
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.

Signed-off-by: Ramon Fried <ramon.fried@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
drivers/Makefile
drivers/smem/Kconfig [new file with mode: 0644]
drivers/smem/Makefile [new file with mode: 0644]
drivers/smem/smem-uclass.c [new file with mode: 0644]
include/dm/uclass-id.h
include/smem.h [new file with mode: 0644]

index 66834c33e30d2cdc121a845cc90c089bc1d5c9e6..276e5ee4d7eedfd6c3be5d8f802b6a614d80771f 100644 (file)
@@ -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/
diff --git a/drivers/smem/Kconfig b/drivers/smem/Kconfig
new file mode 100644 (file)
index 0000000..64337a8
--- /dev/null
@@ -0,0 +1,2 @@
+menuconfig SMEM
+       bool  "SMEM (Shared Memory mamanger) support"
diff --git a/drivers/smem/Makefile b/drivers/smem/Makefile
new file mode 100644 (file)
index 0000000..ca55c45
--- /dev/null
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Makefile for the U-Boot SMEM interface drivers
+
+obj-$(CONFIG_SMEM) += smem-uclass.o
diff --git a/drivers/smem/smem-uclass.c b/drivers/smem/smem-uclass.c
new file mode 100644 (file)
index 0000000..ce7bf40
--- /dev/null
@@ -0,0 +1,45 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2018 Ramon Fried <ramon.fried@gmail.com>
+ */
+
+#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)
+{
+       struct smem_ops *ops = smem_get_ops(dev);
+
+       if (!ops->get_free_space)
+               return -ENOSYS;
+
+       return ops->get_free_space(host);
+}
+
+UCLASS_DRIVER(smem) = {
+       .id     = UCLASS_SMEM,
+       .name       = "smem",
+};
index d7f9df3583a308c737eb6354fcef151fac8981a5..a39643ec5eefdb2bde5b3493dbc8feefb93fbb22 100644 (file)
@@ -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 */
diff --git a/include/smem.h b/include/smem.h
new file mode 100644 (file)
index 0000000..598799d
--- /dev/null
@@ -0,0 +1,91 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * The shared memory system is an allocate-only heap structure that
+ * consists of one of more memory areas that can be accessed by the processors
+ * in the SoC.
+ *
+ * Allocation can be done globally for all processors or to an individual processor.
+ * This is controlled by the @host parameter.
+ *
+ * Allocation and management of heap can be implemented in various ways,
+ * The @item parameter should be used as an index/hash to the memory region.
+ *
+ * Copyright (c) 2018 Ramon Fried <ramon.fried@gmail.com>
+ */
+
+#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 for all processors.
+        * @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
+        *
+        * @host:       the remote processor, of -1 for all processors.
+        * @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() - Get free space in smem in bytes
+        *
+        * @host:   the remote processor identifying a partition, or -1
+        *                      for all processors.
+        * @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 for all processors.
+ * @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
+ *                     for all processors.
+ * @return     size in bytes, -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);
+
+#endif /* _smem_h_ */
+