[Cbe-oss-dev] [PATCH 25/28]MARS/task: module add dma syscall

Yuji Mano yuji.mano at am.sony.com
Fri Feb 6 13:33:09 EST 2009


This patch adds task module syscalls to make its internal dma routines
available to the task library implementation in an attempt to keep task code
size to a minimum.

It also removes the dependency on the base library from the task MPU library.

Signed-off-by: Yuji Mano <yuji.mano at am.sony.com>
---
 task/src/mpu/lib/Makefile.am      |    2 
 task/src/mpu/lib/task_queue.c     |   23 ++++------
 task/src/mpu/module/Makefile.am   |    1 
 task/src/mpu/module/task_module.c |   87 +++++++++++++++++++++-----------------
 task/src/mpu/module/task_module.h |   25 ++++++++++
 5 files changed, 85 insertions(+), 53 deletions(-)

--- a/task/src/mpu/lib/Makefile.am
+++ b/task/src/mpu/lib/Makefile.am
@@ -106,5 +106,3 @@ libmars_task_la_SOURCES = \
 	task_queue.c \
 	task_semaphore.c \
 	task_signal.c
-
-libmars_task_la_LIBADD = -lmars_base
--- a/task/src/mpu/lib/task_queue.c
+++ b/task/src/mpu/lib/task_queue.c
@@ -40,7 +40,6 @@
 
 #include "config.h"
 
-#include <mars/dma.h>
 #include <mars/error.h>
 
 #include "mars/task_types.h"
@@ -152,7 +151,7 @@ static int push(uint64_t queue_ea, const
 		return MARS_ERROR_ALIGN;
 	if ((uintptr_t)data & MARS_TASK_QUEUE_ENTRY_ALIGN_MASK)
 		return MARS_ERROR_ALIGN;
-	if (tag > MARS_DMA_TAG_MAX)
+	if (tag > MARS_TASK_MODULE_DMA_TAG_MAX)
 		return MARS_ERROR_PARAMS;
 
 	/* get task context */
@@ -220,7 +219,7 @@ static int push(uint64_t queue_ea, const
 
 int mars_task_queue_push(uint64_t queue_ea, const void *data)
 {
-	return push(queue_ea, data, 0, 0, MARS_DMA_TAG);
+	return push(queue_ea, data, 0, 0, MARS_TASK_MODULE_DMA_TAG);
 }
 
 int mars_task_queue_push_begin(uint64_t queue_ea, const void *data,
@@ -236,7 +235,7 @@ int mars_task_queue_push_end(uint64_t qu
 		return MARS_ERROR_NULL;
 	if (queue_ea & MARS_TASK_QUEUE_ALIGN_MASK)
 		return MARS_ERROR_ALIGN;
-	if (tag > MARS_DMA_TAG_MAX)
+	if (tag > MARS_TASK_MODULE_DMA_TAG_MAX)
 		return MARS_ERROR_PARAMS;
 
 	/* wait for dma completion */
@@ -252,7 +251,7 @@ int mars_task_queue_push_end(uint64_t qu
 
 int mars_task_queue_try_push(uint64_t queue_ea, const void *data)
 {
-	return push(queue_ea, data, 1, 0, MARS_DMA_TAG);
+	return push(queue_ea, data, 1, 0, MARS_TASK_MODULE_DMA_TAG);
 }
 
 int mars_task_queue_try_push_begin(uint64_t queue_ea, const void *data,
@@ -305,7 +304,7 @@ static int pop(uint64_t queue_ea, void *
 		return MARS_ERROR_ALIGN;
 	if ((uintptr_t)data & MARS_TASK_QUEUE_ENTRY_ALIGN_MASK)
 		return MARS_ERROR_ALIGN;
-	if (tag > MARS_DMA_TAG_MAX)
+	if (tag > MARS_TASK_MODULE_DMA_TAG_MAX)
 		return MARS_ERROR_PARAMS;
 
 	/* get task context */
@@ -373,7 +372,7 @@ static int pop(uint64_t queue_ea, void *
 
 int mars_task_queue_pop(uint64_t queue_ea, void *data)
 {
-	return pop(queue_ea, data, 0, 0, 0, MARS_DMA_TAG);
+	return pop(queue_ea, data, 0, 0, 0, MARS_TASK_MODULE_DMA_TAG);
 }
 
 int mars_task_queue_pop_begin(uint64_t queue_ea, void *data, uint32_t tag)
@@ -388,7 +387,7 @@ int mars_task_queue_pop_end(uint64_t que
 		return MARS_ERROR_NULL;
 	if (queue_ea & MARS_TASK_QUEUE_ALIGN_MASK)
 		return MARS_ERROR_ALIGN;
-	if (tag > MARS_DMA_TAG_MAX)
+	if (tag > MARS_TASK_MODULE_DMA_TAG_MAX)
 		return MARS_ERROR_PARAMS;
 
 	/* wait for dma completion */
@@ -404,7 +403,7 @@ int mars_task_queue_pop_end(uint64_t que
 
 int mars_task_queue_try_pop(uint64_t queue_ea, void *data)
 {
-	return pop(queue_ea, data, 0, 1, 0, MARS_DMA_TAG);
+	return pop(queue_ea, data, 0, 1, 0, MARS_TASK_MODULE_DMA_TAG);
 }
 
 int mars_task_queue_try_pop_begin(uint64_t queue_ea, void *data, uint32_t tag)
@@ -414,7 +413,7 @@ int mars_task_queue_try_pop_begin(uint64
 
 int mars_task_queue_peek(uint64_t queue_ea, void *data)
 {
-	return pop(queue_ea, data, 1, 0, 0, MARS_DMA_TAG);
+	return pop(queue_ea, data, 1, 0, 0, MARS_TASK_MODULE_DMA_TAG);
 }
 
 int mars_task_queue_peek_begin(uint64_t queue_ea, void *data, uint32_t tag)
@@ -429,7 +428,7 @@ int mars_task_queue_peek_end(uint64_t qu
 		return MARS_ERROR_NULL;
 	if (queue_ea & MARS_TASK_QUEUE_ALIGN_MASK)
 		return MARS_ERROR_ALIGN;
-	if (tag > MARS_DMA_TAG_MAX)
+	if (tag > MARS_TASK_MODULE_DMA_TAG_MAX)
 		return MARS_ERROR_PARAMS;
 
 	/* wait for dma completion */
@@ -442,7 +441,7 @@ int mars_task_queue_peek_end(uint64_t qu
 
 int mars_task_queue_try_peek(uint64_t queue_ea, void *data)
 {
-	return pop(queue_ea, data, 1, 1, 0, MARS_DMA_TAG);
+	return pop(queue_ea, data, 1, 1, 0, MARS_TASK_MODULE_DMA_TAG);
 }
 
 int mars_task_queue_try_peek_begin(uint64_t queue_ea, void *data, uint32_t tag)
--- a/task/src/mpu/module/Makefile.am
+++ b/task/src/mpu/module/Makefile.am
@@ -65,7 +65,6 @@ AM_CPPFLAGS = \
 	-I$(srcdir)/../../../include/common \
 	-I$(srcdir)/../../../include/mpu \
 	-I$(srcdir)/../../../src/common \
-	-I$(srcdir)/../../../src/mpu/lib \
 	-I$(builddir)/../../../../base/include/mpu \
 	-I$(srcdir)/../../../../base/include/common \
 	-I$(srcdir)/../../../../base/include/mpu
--- a/task/src/mpu/module/task_module.c
+++ b/task/src/mpu/module/task_module.c
@@ -37,7 +37,6 @@
 
 #include <spu_mfcio.h>
 
-#include <mars/dma.h>
 #include <mars/error.h>
 #include <mars/module.h>
 
@@ -45,10 +44,9 @@
 
 #include "task_module.h"
 
-#define MARS_TASK_MODULE_DMA_TAG		31
 #define MARS_TASK_MODULE_DMA_SIZE_MAX		16384
-
 #define MARS_TASK_MODULE_DMA_SIZE_MASK		0x7f
+
 #define MARS_TASK_REGISTER_SAVE_AREA_SIZE 	(16 * (127 - 80 + 1))
 
 /* stack pointer storage */
@@ -62,34 +60,6 @@ static struct mars_task_context *task;
 typedef void (*mars_task_entry)(struct mars_task_args *args,
 	struct mars_task_module_syscalls *task_module_syscalls);
 
-static void dma_large(void *ls, uint64_t ea, uint32_t size, int put)
-{
-	while (size) {
-		unsigned int block_size;
-
-		block_size = (size < MARS_TASK_MODULE_DMA_SIZE_MAX) ?
-			      size : MARS_TASK_MODULE_DMA_SIZE_MAX;
-
-		if (put)
-			mfc_put((volatile void *)ls, ea, block_size,
-				MARS_TASK_MODULE_DMA_TAG, 0, 0);
-		else
-			mfc_get((volatile void *)ls, ea, block_size,
-				MARS_TASK_MODULE_DMA_TAG, 0, 0);
-
-		ls += block_size;
-		ea += block_size;
-		size -= block_size;
-	}
-}
-
-static void dma_wait(void)
-{
-	mfc_write_tag_mask(1 << MARS_TASK_MODULE_DMA_TAG);
-	mfc_write_tag_update_all();
-	mfc_read_tag_status();
-}
-
 static uint32_t get_ticks(void)
 {
 	return mars_module_get_ticks();
@@ -221,6 +191,33 @@ static void registers_restore(void)
 		: : [ptr] "r" (__task_stack));
 }
 
+static void dma_large(void *ls, uint64_t ea, uint32_t size, uint32_t tag,
+		      int put)
+{
+	while (size) {
+		unsigned int block_size;
+
+		block_size = (size < MARS_TASK_MODULE_DMA_SIZE_MAX) ?
+			      size : MARS_TASK_MODULE_DMA_SIZE_MAX;
+
+		if (put)
+			mfc_put((volatile void *)ls, ea, block_size, tag, 0, 0);
+		else
+			mfc_get((volatile void *)ls, ea, block_size, tag, 0, 0);
+
+		ls += block_size;
+		ea += block_size;
+		size -= block_size;
+	}
+}
+
+static void dma_wait(uint32_t tag)
+{
+	mfc_write_tag_mask(1 << tag);
+	mfc_write_tag_update_all();
+	mfc_read_tag_status();
+}
+
 static void dma_context(int save, void *task_heap)
 {
 	int offset = 0;
@@ -262,17 +259,17 @@ static void dma_context(int save, void *
 	/* save or restore text and heap (low address) */
 	dma_large((void *)MARS_TASK_BASE_ADDR,
 		  task->context_save_area_ea + offset,
-		  low_size, save);
+		  low_size, MARS_TASK_MODULE_DMA_TAG, save);
 	offset += low_size;
 
 	/* save or restore stack (high addres) */
 	dma_large((void *)(MARS_TASK_BASE_ADDR +
 			   MARS_TASK_CONTEXT_SAVE_SIZE_MAX - high_size),
 		  task->context_save_area_ea + offset,
-		  high_size, save);
+		  high_size, MARS_TASK_MODULE_DMA_TAG, save);
 	offset += high_size;
 
-	dma_wait();
+	dma_wait(MARS_TASK_MODULE_DMA_TAG);
 }
 
 static void __attribute__((noinline)) context_save(void *task_heap)
@@ -441,6 +438,16 @@ static int mutex_unlock_put(uint64_t mut
 	return mars_module_mutex_unlock_put(mutex_ea, mutex);
 }
 
+static void dma_get(void *ls, uint64_t ea, uint32_t size, uint32_t tag)
+{
+	dma_large(ls, ea, size, tag, 0);
+}
+
+static void dma_put(const void *ls, uint64_t ea, uint32_t size, uint32_t tag)
+{
+	dma_large((void *)ls, ea, size, tag, 1);
+}
+
 static struct mars_task_module_syscalls task_module_syscalls =
 {
 	get_ticks,
@@ -459,7 +466,11 @@ static struct mars_task_module_syscalls 
 	task_signal_try_wait,
 
 	mutex_lock_get,
-	mutex_unlock_put
+	mutex_unlock_put,
+
+	dma_get,
+	dma_put,
+	dma_wait
 };
 
 static void context_start(void)
@@ -476,9 +487,9 @@ static void context_start(void)
 		*bss_ptr++ = spu_splats((unsigned char)0);
 
 	/* dma the text and data section */
-	dma_large((void *)MARS_TASK_BASE_ADDR,
-		  task->exec_ea, task->exec_size, 0);
-	dma_wait();
+	dma_large((void *)MARS_TASK_BASE_ADDR, task->exec_ea, task->exec_size,
+		  MARS_TASK_MODULE_DMA_TAG, 0);
+	dma_wait(MARS_TASK_MODULE_DMA_TAG);
 
 	/* sync before executing loaded code */
 	spu_sync();
--- a/task/src/mpu/module/task_module.h
+++ b/task/src/mpu/module/task_module.h
@@ -46,6 +46,9 @@
 
 #include "task_internal_types.h"
 
+#define MARS_TASK_MODULE_DMA_TAG	31
+#define MARS_TASK_MODULE_DMA_TAG_MAX	31
+
 /* mars task module syscalls */
 struct mars_task_module_syscalls {
 	uint32_t			(*get_ticks)(void);
@@ -69,6 +72,11 @@ struct mars_task_module_syscalls {
 				  struct mars_mutex *mutex);
 	int	(*mutex_unlock_put)(uint64_t mutex_ea,
 				    struct mars_mutex *mutex);
+
+	void	(*dma_get)(void *ls, uint64_t ea, uint32_t size, uint32_t tag);
+	void	(*dma_put)(const void *ls, uint64_t ea, uint32_t size,
+			   uint32_t tag);
+	void	(*dma_wait)(uint32_t tag);
 };
 
 #if defined(__cplusplus)
@@ -163,6 +171,23 @@ static inline int mars_mutex_unlock_put(
 	return (*mars_task_module_syscalls->mutex_unlock_put)(mutex_ea, mutex);
 }
 
+static inline void mars_dma_get(void *ls, uint64_t ea, uint32_t size,
+				uint32_t tag)
+{
+	(*mars_task_module_syscalls->dma_get)(ls, ea, size, tag);
+}
+
+static inline void mars_dma_put(const void *ls, uint64_t ea, uint32_t size,
+				uint32_t tag)
+{
+	(*mars_task_module_syscalls->dma_put)(ls, ea, size, tag);
+}
+
+static inline void mars_dma_wait(uint32_t tag)
+{
+	(*mars_task_module_syscalls->dma_wait)(tag);
+}
+
 #if defined(__cplusplus)
 }
 #endif







More information about the cbe-oss-dev mailing list