1
#define _PCILIB_DMA_NWL_C
14
#include "nwl_private.h"
16
#include "nwl_defines.h"
18
int dma_nwl_start(pcilib_dma_context_t *vctx, pcilib_dma_engine_t dma, pcilib_dma_flags_t flags) {
20
nwl_dma_t *ctx = (nwl_dma_t*)vctx;
23
// global initialization, should we do anything?
27
if (dma == PCILIB_DMA_ENGINE_INVALID) return 0;
28
else if (dma > ctx->n_engines) return PCILIB_ERROR_INVALID_BANK;
30
if (flags&PCILIB_DMA_FLAG_PERSISTENT) ctx->engines[dma].preserve = 1;
32
err = dma_nwl_start_engine(ctx, dma);
37
int dma_nwl_stop(pcilib_dma_context_t *vctx, pcilib_dma_engine_t dma, pcilib_dma_flags_t flags) {
41
nwl_dma_t *ctx = (nwl_dma_t*)vctx;
43
if (!ctx->started) return 0;
46
if (dma == PCILIB_DMA_ENGINE_INVALID) {
47
for (dma = 0; dma < ctx->n_engines; dma++) {
48
if (flags&PCILIB_DMA_FLAG_PERSISTENT) {
49
ctx->engines[dma].preserve = 0;
52
if (ctx->engines[dma].preserve) preserving = 1;
54
err = dma_nwl_stop_engine(ctx, dma);
58
// global cleanup, should we do anything?
66
if (dma > ctx->n_engines) return PCILIB_ERROR_INVALID_BANK;
68
// ignorign previous setting if flag specified
69
if (flags&PCILIB_DMA_FLAG_PERSISTENT) {
70
ctx->engines[dma].preserve = 0;
73
return dma_nwl_stop_engine(ctx, dma);
77
pcilib_dma_context_t *dma_nwl_init(pcilib_t *pcilib, pcilib_dma_modification_t type, void *arg) {
80
pcilib_dma_engine_t n_engines;
82
pcilib_model_description_t *model_info = pcilib_get_model_description(pcilib);
84
nwl_dma_t *ctx = malloc(sizeof(nwl_dma_t));
86
memset(ctx, 0, sizeof(nwl_dma_t));
90
if (type == PCILIB_NWL_MODIFICATION_IPECAMERA) {
91
ctx->dmactx.ignore_eop = 1;
94
pcilib_register_bank_t dma_bank = pcilib_find_bank_by_addr(pcilib, PCILIB_REGISTER_BANK_DMA);
95
if (dma_bank == PCILIB_REGISTER_BANK_INVALID) {
97
pcilib_error("DMA Register Bank could not be found");
101
ctx->dma_bank = model_info->banks + dma_bank;
102
ctx->base_addr = pcilib_resolve_register_address(pcilib, ctx->dma_bank->bar, ctx->dma_bank->read_addr);
104
for (i = 0, n_engines = 0; i < 2 * PCILIB_MAX_DMA_ENGINES; i++) {
105
char *addr = ctx->base_addr + DMA_OFFSET + i * DMA_ENGINE_PER_SIZE;
107
memset(ctx->engines + n_engines, 0, sizeof(pcilib_nwl_engine_description_t));
109
err = dma_nwl_read_engine_config(ctx, ctx->engines + n_engines, addr);
112
pcilib_set_dma_engine_description(pcilib, n_engines, (pcilib_dma_engine_description_t*)(ctx->engines + n_engines));
115
pcilib_set_dma_engine_description(pcilib, n_engines, NULL);
117
ctx->n_engines = n_engines;
119
err = nwl_add_registers(ctx);
122
pcilib_error("Failed to add DMA registers");
126
return (pcilib_dma_context_t*)ctx;
129
void dma_nwl_free(pcilib_dma_context_t *vctx) {
130
nwl_dma_t *ctx = (nwl_dma_t*)vctx;
133
if (ctx->type == PCILIB_DMA_MODIFICATION_DEFAULT) dma_nwl_stop_loopback(ctx);
134
dma_nwl_free_irq(ctx);
135
dma_nwl_stop(vctx, PCILIB_DMA_ENGINE_ALL, PCILIB_DMA_FLAGS_DEFAULT);