summaryrefslogtreecommitdiffstats
path: root/dma
diff options
context:
space:
mode:
authorSuren A. Chilingaryan <csa@dside.dyndns.org>2011-12-12 05:45:35 +0100
committerSuren A. Chilingaryan <csa@dside.dyndns.org>2011-12-12 05:45:35 +0100
commit2e4e8a00b27182a155cb10f0a00e44977bfcd5cf (patch)
tree86afd1b7ceb834dbb3cedf8d55c3ac0734947333 /dma
parent7a4cfb9e546c496792d3fe0c61c822c66ad0128f (diff)
downloadpcitool-2e4e8a00b27182a155cb10f0a00e44977bfcd5cf.tar.gz
pcitool-2e4e8a00b27182a155cb10f0a00e44977bfcd5cf.tar.bz2
pcitool-2e4e8a00b27182a155cb10f0a00e44977bfcd5cf.tar.xz
pcitool-2e4e8a00b27182a155cb10f0a00e44977bfcd5cf.zip
multithread preprocessing of ipecamera frames and code reorganization
Diffstat (limited to 'dma')
-rw-r--r--dma/CMakeLists.txt9
-rw-r--r--dma/nwl.c4
-rw-r--r--dma/nwl_defines.h2
-rw-r--r--dma/nwl_engine.c5
-rw-r--r--dma/nwl_engine_buffers.h20
-rw-r--r--dma/nwl_loopback.c9
-rw-r--r--dma/nwl_register.c2
-rw-r--r--dma/nwl_register.h4
8 files changed, 29 insertions, 26 deletions
diff --git a/dma/CMakeLists.txt b/dma/CMakeLists.txt
new file mode 100644
index 0000000..3d4226a
--- /dev/null
+++ b/dma/CMakeLists.txt
@@ -0,0 +1,9 @@
+include_directories(
+ ${CMAKE_SOURCE_DIR}
+)
+
+
+set(HEADERS ${HEADERS} nwl.h nwl_dma.h nwl_engine.h nwl_irq.h nwl_loopback.h nwl_register.h)
+
+add_library(dma STATIC nwl.c nwl_engine.c nwl_irq.c nwl_loopback.c nwl_register.c)
+
diff --git a/dma/nwl.c b/dma/nwl.c
index cc03687..df5d0b8 100644
--- a/dma/nwl.c
+++ b/dma/nwl.c
@@ -77,7 +77,6 @@ int dma_nwl_stop(pcilib_dma_context_t *vctx, pcilib_dma_engine_t dma, pcilib_dma
pcilib_dma_context_t *dma_nwl_init(pcilib_t *pcilib, pcilib_dma_modification_t type, void *arg) {
int i;
int err;
- uint32_t val;
pcilib_dma_engine_t n_engines;
pcilib_model_description_t *model_info = pcilib_get_model_description(pcilib);
@@ -128,9 +127,6 @@ pcilib_dma_context_t *dma_nwl_init(pcilib_t *pcilib, pcilib_dma_modification_t t
}
void dma_nwl_free(pcilib_dma_context_t *vctx) {
- int err;
-
- pcilib_dma_engine_t i;
nwl_dma_t *ctx = (nwl_dma_t*)vctx;
if (ctx) {
diff --git a/dma/nwl_defines.h b/dma/nwl_defines.h
index c1ff2eb..ce3b686 100644
--- a/dma/nwl_defines.h
+++ b/dma/nwl_defines.h
@@ -33,7 +33,7 @@
-#define DMA_BD_MINIMUM_ALIGNMENT 0x40 /**< Minimum byte alignment
+#define DMA_BD_MINIMUM_ALIGNMENT 0x40 /**< Minimum byte alignment */
/* Common DMA registers */
#define REG_DMA_CTRL_STATUS 0x4000 /**< DMA Common Ctrl & Status */
diff --git a/dma/nwl_engine.c b/dma/nwl_engine.c
index ac87f08..fc07ccd 100644
--- a/dma/nwl_engine.c
+++ b/dma/nwl_engine.c
@@ -267,14 +267,13 @@ int dma_nwl_write_fragment(pcilib_dma_context_t *vctx, pcilib_dma_engine_t dma,
int dma_nwl_stream_read(pcilib_dma_context_t *vctx, pcilib_dma_engine_t dma, uintptr_t addr, size_t size, pcilib_dma_flags_t flags, pcilib_timeout_t timeout, pcilib_dma_callback_t cb, void *cbattr) {
int err, ret = PCILIB_STREAMING_REQ_PACKET;
+ pcilib_timeout_t wait = 0;
size_t res = 0;
size_t bufnum;
size_t bufsize;
- pcilib_timeout_t wait;
nwl_dma_t *ctx = (nwl_dma_t*)vctx;
- size_t buf_size;
int eop;
pcilib_nwl_engine_description_t *info = ctx->engines + dma;
@@ -286,7 +285,7 @@ int dma_nwl_stream_read(pcilib_dma_context_t *vctx, pcilib_dma_engine_t dma, uin
switch (ret&PCILIB_STREAMING_TIMEOUT_MASK) {
case PCILIB_STREAMING_CONTINUE: wait = PCILIB_DMA_TIMEOUT; break;
case PCILIB_STREAMING_WAIT: wait = timeout; break;
- case PCILIB_STREAMING_CHECK: wait = 0; break;
+// case PCILIB_STREAMING_CHECK: wait = 0; break;
}
bufnum = dma_nwl_wait_buffer(ctx, info, &bufsize, &eop, wait);
diff --git a/dma/nwl_engine_buffers.h b/dma/nwl_engine_buffers.h
index b97e469..191a2a6 100644
--- a/dma/nwl_engine_buffers.h
+++ b/dma/nwl_engine_buffers.h
@@ -3,7 +3,6 @@
#define NWL_RING_UPDATE(data, offset, mask, val) *(uint32_t*)(((char*)(data)) + (offset)) = ((*(uint32_t*)(((char*)(data)) + (offset)))&(mask))|(val)
static int dma_nwl_compute_read_s2c_pointers(nwl_dma_t *ctx, pcilib_nwl_engine_description_t *info, unsigned char *ring, uint32_t ring_pa) {
- size_t pos;
uint32_t val;
char *base = info->base_addr;
@@ -42,13 +41,10 @@ static int dma_nwl_compute_read_s2c_pointers(nwl_dma_t *ctx, pcilib_nwl_engine_d
}
static int dma_nwl_compute_read_c2s_pointers(nwl_dma_t *ctx, pcilib_nwl_engine_description_t *info, unsigned char *ring, uint32_t ring_pa) {
- size_t pos;
uint32_t val;
- size_t prev;
char *base = info->base_addr;
-
nwl_read_register(val, ctx, base, REG_SW_NEXT_BD);
if ((val < ring_pa)||((val - ring_pa) % PCILIB_NWL_DMA_DESCRIPTOR_SIZE)) {
if (val < ring_pa) pcilib_warning("Inconsistent C2S DMA Ring buffer is found (REG_SW_NEXT_BD register value (%lx) is below start of the ring [%lx,%lx])", val, ring_pa, PCILIB_NWL_DMA_DESCRIPTOR_SIZE);
@@ -112,8 +108,8 @@ static int dma_nwl_allocate_engine_buffers(nwl_dma_t *ctx, pcilib_nwl_engine_des
if (reuse_ring == reuse_pages) {
if (reuse_ring & PCILIB_KMEM_REUSE_PARTIAL) pcilib_warning("Inconsistent DMA buffers are found (only part of required buffers is available), reinitializing...");
else if (reuse_ring & PCILIB_KMEM_REUSE_REUSED) {
- if (reuse_ring & PCILIB_KMEM_REUSE_PERSISTENT == 0) pcilib_warning("Lost DMA buffers are found (non-persistent mode), reinitializing...");
- else if (reuse_ring & PCILIB_KMEM_REUSE_HARDWARE == 0) pcilib_warning("Lost DMA buffers are found (missing HW reference), reinitializing...");
+ if ((reuse_ring & PCILIB_KMEM_REUSE_PERSISTENT) == 0) pcilib_warning("Lost DMA buffers are found (non-persistent mode), reinitializing...");
+ else if ((reuse_ring & PCILIB_KMEM_REUSE_HARDWARE) == 0) pcilib_warning("Lost DMA buffers are found (missing HW reference), reinitializing...");
else {
nwl_read_register(val, ctx, info->base_addr, REG_DMA_ENG_CTRL_STATUS);
@@ -174,7 +170,7 @@ static int dma_nwl_allocate_engine_buffers(nwl_dma_t *ctx, pcilib_nwl_engine_des
static size_t dma_nwl_clean_buffers(nwl_dma_t * ctx, pcilib_nwl_engine_description_t *info) {
size_t res = 0;
- uint32_t status, control;
+ uint32_t status;
unsigned char *ring = pcilib_kmem_get_ua(ctx->pcilib, info->ring);
ring += info->tail * PCILIB_NWL_DMA_DESCRIPTOR_SIZE;
@@ -282,9 +278,8 @@ static int dma_nwl_push_buffer(nwl_dma_t *ctx, pcilib_nwl_engine_description_t *
static size_t dma_nwl_wait_buffer(nwl_dma_t *ctx, pcilib_nwl_engine_description_t *info, size_t *size, int *eop, pcilib_timeout_t timeout) {
- uint32_t val;
struct timeval start, cur;
- uint32_t status_size, status, control;
+ uint32_t status_size, status;
unsigned char *ring = pcilib_kmem_get_ua(ctx->pcilib, info->ring);
@@ -325,6 +320,8 @@ static size_t dma_nwl_wait_buffer(nwl_dma_t *ctx, pcilib_nwl_engine_description_
return (size_t)-1;
}
+/*
+ // This function is not used now, but we may need it in the future
static int dma_nwl_is_overflown(nwl_dma_t *ctx, pcilib_nwl_engine_description_t *info) {
uint32_t status;
unsigned char *ring = pcilib_kmem_get_ua(ctx->pcilib, info->ring);
@@ -334,6 +331,7 @@ static int dma_nwl_is_overflown(nwl_dma_t *ctx, pcilib_nwl_engine_description_t
status = NWL_RING_GET(ring, DMA_BD_BUFL_STATUS_OFFSET);
return status&DMA_BD_COMP_MASK?1:0;
}
+*/
static int dma_nwl_return_buffer(nwl_dma_t *ctx, pcilib_nwl_engine_description_t *info) {
uint32_t val;
@@ -357,6 +355,8 @@ static int dma_nwl_return_buffer(nwl_dma_t *ctx, pcilib_nwl_engine_description_t
info->tail++;
if (info->tail == info->ring_size) info->tail = 0;
+
+ return 0;
}
int dma_nwl_get_status(pcilib_dma_context_t *vctx, pcilib_dma_engine_t dma, pcilib_dma_engine_status_t *status, size_t n_buffers, pcilib_dma_buffer_status_t *buffers) {
@@ -375,7 +375,7 @@ int dma_nwl_get_status(pcilib_dma_context_t *vctx, pcilib_dma_engine_t dma, pcil
status->ring_tail = info->tail;
if (info->desc.direction == PCILIB_DMA_FROM_DEVICE) {
- size_t pos;
+ size_t pos = 0;
for (i = 0; i < info->ring_size; i++) {
pos = status->ring_tail + i;
if (pos >= info->ring_size) pos -= info->ring_size;
diff --git a/dma/nwl_loopback.c b/dma/nwl_loopback.c
index 11f7f34..ce0844f 100644
--- a/dma/nwl_loopback.c
+++ b/dma/nwl_loopback.c
@@ -66,13 +66,10 @@ int dma_nwl_stop_loopback(nwl_dma_t *ctx) {
double dma_nwl_benchmark(pcilib_dma_context_t *vctx, pcilib_dma_engine_addr_t dma, uintptr_t addr, size_t size, size_t iterations, pcilib_dma_direction_t direction) {
int iter, i;
- int res;
int err;
size_t bytes, rbytes;
- uint32_t val;
uint32_t *buf, *cmp;
const char *error = NULL;
- pcilib_register_value_t regval;
size_t packet_size, blocks;
size_t us = 0;
@@ -83,9 +80,6 @@ double dma_nwl_benchmark(pcilib_dma_context_t *vctx, pcilib_dma_engine_addr_t dm
pcilib_dma_engine_t readid = pcilib_find_dma_by_addr(ctx->pcilib, PCILIB_DMA_FROM_DEVICE, dma);
pcilib_dma_engine_t writeid = pcilib_find_dma_by_addr(ctx->pcilib, PCILIB_DMA_TO_DEVICE, dma);
- char *read_base = ctx->engines[readid].base_addr;
- char *write_base = ctx->engines[writeid].base_addr;
-
if (size%sizeof(uint32_t)) size = 1 + size / sizeof(uint32_t);
else size /= sizeof(uint32_t);
@@ -214,8 +208,7 @@ double dma_nwl_benchmark(pcilib_dma_context_t *vctx, pcilib_dma_engine_addr_t dm
#ifndef NWL_BUG_EXTRA_DATA
if (direction == PCILIB_DMA_BIDIRECTIONAL) {
- res = memcmp(buf, cmp, size * sizeof(uint32_t));
- if (res) {
+ if (memcmp(buf, cmp, size * sizeof(uint32_t))) {
for (i = 0; i < size; i++)
if (buf[i] != cmp[i]) break;
diff --git a/dma/nwl_register.c b/dma/nwl_register.c
index 95b981a..5f94e4d 100644
--- a/dma/nwl_register.c
+++ b/dma/nwl_register.c
@@ -1,3 +1,5 @@
+#define _PCILIB_NWL_REGISTER_C
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
diff --git a/dma/nwl_register.h b/dma/nwl_register.h
index 2f465bd..a71942b 100644
--- a/dma/nwl_register.h
+++ b/dma/nwl_register.h
@@ -1,6 +1,7 @@
#ifndef _PCILIB_NWL_REGISTERS_H
#define _PCILIB_NWL_REGISTERS_H
+#ifdef _PCILIB_NWL_REGISTER_C
// DMA
static pcilib_register_description_t nwl_dma_registers[] = {
{0x4000, 0, 32, 0, 0x00000011, PCILIB_REGISTER_RW , PCILIB_REGISTER_STANDARD, PCILIB_REGISTER_BANK_DMA, "dma_control_and_status", ""},
@@ -89,5 +90,8 @@ static pcilib_register_description_t nwl_xrawdata_registers[] = {
{0, 0, 0, 0, 0x00000000, 0, 0, 0, NULL, NULL}
};
+#endif /* _PCILIB_NWL_REGISTERS_C */
+
int nwl_add_registers(nwl_dma_t *ctx);
+
#endif /* _PCILIB_NWL_REGISTERS_H */