[Cbe-oss-dev] [PATCH 10/22]MARS/base: Add dma implementation
Yuji Mano
yuji.mano at am.sony.com
Wed Jan 21 11:28:45 EST 2009
This adds dma.c for dma implementation that were previously inline functions
provided in dma.h. This is to reduce code size and also because implementation
may vary depending on platform.
Signed-off-by: Yuji Mano <yuji.mano at am.sony.com>
---
base/include/mpu/mars/dma.h | 77 +++------------------------------
base/src/mpu/lib/Makefile.am | 1
base/src/mpu/lib/dma.c | 98 +++++++++++++++++++++++++++++++++++++++++++
3 files changed, 107 insertions(+), 69 deletions(-)
--- a/base/include/mpu/mars/dma.h
+++ b/base/include/mpu/mars/dma.h
@@ -44,17 +44,12 @@
* \brief <b>[MPU]</b> MARS DMA API
*/
-#include <assert.h>
-#include <spu_mfcio.h>
+#include <stdint.h>
/** dma tag reserved for MARS */
#define MARS_DMA_TAG 31
/** dma tag 0~31 */
#define MARS_DMA_TAG_MAX 31
-/** dma 16 byte alignment mask */
-#define MARS_DMA_ALIGN_MASK 0xf
-/** dma 16 byte size mask */
-#define MARS_DMA_SIZE_MASK 0xf
/** dma single tranfer size max 16KB */
#define MARS_DMA_SIZE_MAX 16384
@@ -73,14 +68,7 @@ extern "C" {
* \return
* none
*/
-static inline void mars_dma_wait(uint32_t tag)
-{
- assert(tag <= MARS_DMA_TAG_MAX);
-
- mfc_write_tag_mask(1 << tag);
- mfc_write_tag_update_all();
- mfc_read_tag_status();
-}
+void mars_dma_wait(uint32_t tag);
/**
* \ingroup group_mars_core
@@ -93,12 +81,7 @@ static inline void mars_dma_wait(uint32_
* \return
* none
*/
-static inline void mars_dma_sync(uint32_t tag)
-{
- assert(tag <= MARS_DMA_TAG_MAX);
-
- mfc_sync(tag);
-}
+void mars_dma_sync(uint32_t tag);
/**
* \ingroup group_mars_core
@@ -114,29 +97,7 @@ static inline void mars_dma_sync(uint32_
* \return
* none
*/
-static inline void mars_dma_get(void *ls, uint64_t ea,
- uint32_t size, uint32_t tag)
-{
- assert((size == 1 || size == 2 || size == 4 || size == 8 ||
- (size & MARS_DMA_SIZE_MASK) == 0) &&
- ((uintptr_t)ls & MARS_DMA_ALIGN_MASK) ==
- ((uintptr_t)ea & MARS_DMA_ALIGN_MASK) &&
- ((uintptr_t)ea & (size - 1) & MARS_DMA_ALIGN_MASK) == 0);
- assert(tag <= MARS_DMA_TAG_MAX);
-
- while (size) {
- unsigned int block_size;
-
- block_size = (size < MARS_DMA_SIZE_MAX) ?
- size : MARS_DMA_SIZE_MAX;
-
- mfc_get((volatile void *)ls, ea, block_size, tag, 0, 0);
-
- ls += block_size;
- ea += block_size;
- size -= block_size;
- }
-}
+void mars_dma_get(void *ls, uint64_t ea, uint32_t size, uint32_t tag);
/**
* \ingroup group_mars_core
@@ -150,7 +111,7 @@ static inline void mars_dma_get(void *ls
* none
*/
static inline void mars_dma_get_and_wait(void *ls, uint64_t ea,
- uint32_t size, uint32_t tag)
+ uint32_t size, uint32_t tag)
{
mars_dma_get(ls, ea, size, tag);
mars_dma_wait(tag);
@@ -170,29 +131,7 @@ static inline void mars_dma_get_and_wait
* \return
* none
*/
-static inline void mars_dma_put(const void *ls, uint64_t ea,
- uint32_t size, uint32_t tag)
-{
- assert((size == 1 || size == 2 || size == 4 || size == 8 ||
- (size & MARS_DMA_SIZE_MASK) == 0) &&
- ((uintptr_t)ls & MARS_DMA_ALIGN_MASK) ==
- ((uintptr_t)ea & MARS_DMA_ALIGN_MASK) &&
- ((uintptr_t)ea & (size - 1) & MARS_DMA_ALIGN_MASK) == 0);
- assert(tag <= MARS_DMA_TAG_MAX);
-
- while (size) {
- unsigned int block_size;
-
- block_size = (size < MARS_DMA_SIZE_MAX) ?
- size : MARS_DMA_SIZE_MAX;
-
- mfc_put((volatile void *)ls, ea, block_size, tag, 0, 0);
-
- ls += block_size;
- ea += block_size;
- size -= block_size;
- }
-}
+void mars_dma_put(const void *ls, uint64_t ea, uint32_t size, uint32_t tag);
/**
* \ingroup group_mars_core
@@ -206,9 +145,9 @@ static inline void mars_dma_put(const vo
* none
*/
static inline void mars_dma_put_and_wait(const void *ls, uint64_t ea,
- uint32_t size, uint32_t tag)
+ uint32_t size, uint32_t tag)
{
- mars_dma_put(ls, ea, size, tag);
+ mars_dma_put((void *)ls, ea, size, tag);
mars_dma_wait(tag);
}
--- a/base/src/mpu/lib/Makefile.am
+++ b/base/src/mpu/lib/Makefile.am
@@ -91,5 +91,6 @@ lib_LTLIBRARIES = libmars_base.la
libmars_base_la_SOURCES = \
$(srcdir)/../../../src/common/*.h \
+ dma.c \
module.c \
mutex.c
--- /dev/null
+++ b/base/src/mpu/lib/dma.c
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2008 Sony Corporation of America
+ *
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this Library and associated documentation files (the
+ * "Library"), to deal in the Library without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Library, and to
+ * permit persons to whom the Library is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Library.
+ *
+ * If you modify the Library, you may copy and distribute your modified
+ * version of the Library in object code or as an executable provided
+ * that you also do one of the following:
+ *
+ * Accompany the modified version of the Library with the complete
+ * corresponding machine-readable source code for the modified version
+ * of the Library; or,
+ *
+ * Accompany the modified version of the Library with a written offer
+ * for a complete machine-readable copy of the corresponding source
+ * code of the modified version of the Library.
+ *
+ *
+ * THE LIBRARY IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * LIBRARY OR THE USE OR OTHER DEALINGS IN THE LIBRARY.
+ */
+
+#include <assert.h>
+#include <spu_mfcio.h>
+
+#include "mars/dma.h"
+
+/** dma 16 byte alignment mask */
+#define MARS_DMA_ALIGN_MASK 0xf
+/** dma 16 byte size mask */
+#define MARS_DMA_SIZE_MASK 0xf
+
+void mars_dma_wait(uint32_t tag)
+{
+ assert(tag <= MARS_DMA_TAG_MAX);
+
+ mfc_write_tag_mask(1 << tag);
+ mfc_write_tag_update_all();
+ mfc_read_tag_status();
+}
+
+void mars_dma_sync(uint32_t tag)
+{
+ assert(tag <= MARS_DMA_TAG_MAX);
+
+ mfc_sync(tag);
+}
+
+static void dma(void *ls, uint64_t ea, uint32_t size, uint32_t tag, int get)
+{
+ assert((size == 1 || size == 2 || size == 4 || size == 8 ||
+ (size & MARS_DMA_SIZE_MASK) == 0) &&
+ ((uintptr_t)ls & MARS_DMA_ALIGN_MASK) ==
+ ((uintptr_t)ea & MARS_DMA_ALIGN_MASK) &&
+ ((uintptr_t)ea & (size - 1) & MARS_DMA_ALIGN_MASK) == 0);
+ assert(tag <= MARS_DMA_TAG_MAX);
+
+ while (size) {
+ unsigned int block_size;
+
+ block_size = (size < MARS_DMA_SIZE_MAX) ?
+ size : MARS_DMA_SIZE_MAX;
+
+ if (get)
+ mfc_get((volatile void *)ls, ea, block_size, tag, 0, 0);
+ else
+ mfc_put((volatile void *)ls, ea, block_size, tag, 0, 0);
+
+ ls += block_size;
+ ea += block_size;
+ size -= block_size;
+ }
+}
+
+void mars_dma_get(void *ls, uint64_t ea, uint32_t size, uint32_t tag)
+{
+ dma(ls, ea, size, tag, 1);
+}
+
+void mars_dma_put(const void *ls, uint64_t ea, uint32_t size, uint32_t tag)
+{
+ dma((void *)ls, ea, size, tag, 0);
+}
More information about the cbe-oss-dev
mailing list