summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.bzrignore1
-rw-r--r--CMakeLists.txt48
-rw-r--r--apps/CMakeLists.txt5
-rw-r--r--bank.h97
-rw-r--r--config.h30
-rw-r--r--dma.h86
-rw-r--r--dma/CMakeLists.txt2
-rw-r--r--dma/ipe.h4
-rw-r--r--dma/nwl.h4
-rw-r--r--pcilib/CMakeLists.txt21
-rw-r--r--pcilib/bank.c (renamed from bank.c)9
-rw-r--r--pcilib/bank.h102
-rw-r--r--pcilib/config.c (renamed from config.c)17
-rw-r--r--pcilib/config.h17
-rw-r--r--pcilib/dma.c (renamed from dma.c)86
-rw-r--r--pcilib/dma.h85
-rw-r--r--pcilib/error.c (renamed from error.c)0
-rw-r--r--pcilib/error.h (renamed from error.h)0
-rw-r--r--pcilib/event.c (renamed from event.c)1
-rw-r--r--pcilib/event.h (renamed from event.h)2
-rw-r--r--pcilib/irq.c (renamed from irq.c)0
-rw-r--r--pcilib/irq.h (renamed from irq.h)0
-rw-r--r--pcilib/kmem.c (renamed from kmem.c)0
-rw-r--r--pcilib/kmem.h (renamed from kmem.h)0
-rw-r--r--pcilib/linux-3.10.h (renamed from linux-3.10.h)0
-rw-r--r--pcilib/model.c (renamed from model.c)0
-rw-r--r--pcilib/model.h (renamed from model.h)16
-rw-r--r--pcilib/pci.c (renamed from pci.c)4
-rw-r--r--pcilib/pci.h (renamed from pci.h)0
-rw-r--r--pcilib/pcilib.h (renamed from pcilib.h)0
-rw-r--r--pcilib/register.c (renamed from register.c)0
-rw-r--r--pcilib/register.h (renamed from register.h)2
-rw-r--r--pcilib/tools.c (renamed from tools.c)0
-rw-r--r--pcilib/tools.h (renamed from tools.h)0
-rw-r--r--pcitool/CMakeLists.txt28
-rw-r--r--pcitool/cli.c (renamed from cli.c)10
-rw-r--r--protocols/CMakeLists.txt2
-rw-r--r--protocols/default.h2
-rwxr-xr-xtests/grab.sh4
-rwxr-xr-xtests/ipedma/ipecamera-frame.sh2
-rwxr-xr-xtests/ipedma/ipecamera-test.sh2
-rwxr-xr-xtests/ipedma/test.sh2
-rwxr-xr-xtests/nwldma/bench.sh4
-rwxr-xr-xtests/nwldma/cleanup.sh4
-rwxr-xr-xtests/test-iommu.sh5
-rwxr-xr-xtests/xilinxdma/xilinx_dma.sh4
-rwxr-xr-xtests/xilinxdma/xilinx_dma_static_mem.sh2
47 files changed, 352 insertions, 358 deletions
diff --git a/.bzrignore b/.bzrignore
index 6fe7019..a4a8059 100644
--- a/.bzrignore
+++ b/.bzrignore
@@ -25,3 +25,4 @@ apps/heb_strip_bad_values
*.out
apps/check_counter
apps/lorenzo_ipedma_test
+pci
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6eb4c26..faed5aa 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -16,66 +16,20 @@ if (NOT DISABLE_PCITOOL)
pkg_check_modules(FASTWRITER fastwriter REQUIRED)
endif (NOT DISABLE_PCITOOL)
-set(HEADERS pcilib.h pci.h config.h model.h bank.h register.h kmem.h irq.h dma.h event.h tools.h error.h)
add_definitions("-fPIC --std=c99 -Wall -O2 -gdwarf-2 -g3")
#add_definitions("-fPIC --std=c99 -Wall -O2")
add_subdirectory(dma)
add_subdirectory(protocols)
+add_subdirectory(pcilib)
add_subdirectory(pcitool)
add_subdirectory(apps)
-include_directories(
- .
- ${FASTWRITER_INCLUDE_DIRS}
-)
-
-link_directories(
- ${FASTWRITER_LIBRARY_DIRS}
- ${UFODECODE_LIBRARY_DIRS}
-)
-
-add_library(pcilib SHARED pci.c config.c model.c bank.c register.c kmem.c irq.c dma.c event.c tools.c error.c)
-target_link_libraries(pcilib dma protocols ${CMAKE_THREAD_LIBS_INIT} ${UFODECODE_LIBRARIES} )
-add_dependencies(pcilib dma protocols pcitool)
-
set_target_properties(pcilib PROPERTIES
VERSION ${PCILIB_VERSION}
SOVERSION ${PCILIB_ABI_VERSION}
)
-if (NOT DISABLE_PCITOOL)
- add_executable(pci cli.c)
- add_dependencies(pci pcitool)
- target_link_libraries(pci pcilib pcitool ${FASTWRITER_LIBRARIES})
- set_target_properties(pci PROPERTIES
- LINK_FLAGS ${CMAKE_THREAD_LIBS_INIT}
- )
-endif (NOT DISABLE_PCITOOL)
-
-#set_target_properties(pci PROPERTIES
-# LINK_FLAGS "-Wl,pcitool/libpcitool.a"
-#)
-if(NOT DEFINED BIN_INSTALL_DIR)
- set(BIN_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/bin")
-endif(NOT DEFINED BIN_INSTALL_DIR)
-install(TARGETS pcilib
- LIBRARY DESTINATION lib${LIB_SUFFIX}
-)
-
-if (NOT DISABLE_PCITOOL)
- install(TARGETS pci
- DESTINATION ${BIN_INSTALL_DIR}
- )
-endif (NOT DISABLE_PCITOOL)
-
-install(FILES pcilib.h
- DESTINATION include
-)
-
-install(FILES bank.h register.h dma.h event.h model.h error.h tools.h
- DESTINATION include/pcilib
-)
diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt
index de652b5..32aac62 100644
--- a/apps/CMakeLists.txt
+++ b/apps/CMakeLists.txt
@@ -1,8 +1,11 @@
include_directories(
${CMAKE_SOURCE_DIR}
+ ${CMAKE_SOURCE_DIR}/pcilib
)
-link_directories(${UFODECODE_LIBRARY_DIRS})
+link_directories(
+ ${CMAKE_SOURCE_DIR}/pcilib
+)
add_executable(xilinx xilinx.c)
target_link_libraries(xilinx pcilib rt)
diff --git a/bank.h b/bank.h
deleted file mode 100644
index 2a0b0b3..0000000
--- a/bank.h
+++ /dev/null
@@ -1,97 +0,0 @@
-#ifndef _PCILIB_BANK_H
-#define _PCILIB_BANK_H
-
-#include <pcilib.h>
-
-#define PCILIB_REGISTER_BANK_INVALID ((pcilib_register_bank_t)-1)
-#define PCILIB_REGISTER_BANK0 0 /**< First BANK to be used in the event engine */
-#define PCILIB_REGISTER_BANK1 1
-#define PCILIB_REGISTER_BANK2 2
-#define PCILIB_REGISTER_BANK3 3
-#define PCILIB_REGISTER_BANK_DMA 64 /**< First BANK address to be used by DMA engines */
-#define PCILIB_REGISTER_BANK_DYNAMIC 128 /**< First BANK address to map dynamic XML configuration */
-#define PCILIB_REGISTER_PROTOCOL_INVALID ((pcilib_register_protocol_t)-1)
-#define PCILIB_REGISTER_PROTOCOL0 0 /**< First PROTOCOL address to be used in the event engine */
-#define PCILIB_REGISTER_PROTOCOL_DEFAULT 64 /**< Default memmap based protocol */
-#define PCILIB_REGISTER_PROTOCOL_DMA 96 /**< First PROTOCOL address to be used by DMA engines */
-#define PCILIB_REGISTER_PROTOCOL_DYNAMIC 128 /**< First PROTOCOL address to be used by plugins */
-
-#define PCILIB_REGISTER_NO_BITS 0
-#define PCILIB_REGISTER_ALL_BITS ((pcilib_register_value_t)-1)
-
-typedef uint8_t pcilib_register_bank_t; /**< Type holding the bank position within the field listing register banks in the model */
-typedef uint8_t pcilib_register_bank_addr_t; /**< Type holding the bank address number */
-typedef uint8_t pcilib_register_protocol_t; /**< Type holding the protocol position within the field listing register protocols in the model */
-typedef uint8_t pcilib_register_protocol_addr_t; /**< Type holding the protocol address */
-
-
-typedef struct pcilib_register_bank_context_s pcilib_register_bank_context_t;
-
-typedef struct {
- pcilib_register_bank_context_t *(*init)(pcilib_t *ctx, pcilib_register_bank_t bank, const char *model, const void *args);
- void (*free)(pcilib_register_bank_context_t *ctx);
- int (*read)(pcilib_t *pcilib, pcilib_register_bank_context_t *ctx, pcilib_register_addr_t addr, pcilib_register_value_t *value);
- int (*write)(pcilib_t *pcilib, pcilib_register_bank_context_t *ctx, pcilib_register_addr_t addr, pcilib_register_value_t value);
-} pcilib_register_protocol_api_description_t;
-
-typedef struct {
- pcilib_register_protocol_addr_t addr;
- const pcilib_register_protocol_api_description_t *api;
- const char *model;
- const void *args;
- const char *name;
- const char *description;
-} pcilib_register_protocol_description_t;
-
-typedef struct {
- pcilib_register_bank_addr_t addr;
-
- pcilib_bar_t bar; // optional
- size_t size;
-
- pcilib_register_protocol_addr_t protocol;
-
- uintptr_t read_addr; // or offset if bar specified
- uintptr_t write_addr; // or offset if bar specified
- pcilib_endianess_t raw_endianess;
-
- uint8_t access;
- pcilib_endianess_t endianess;
-
- const char *format;
- const char *name;
- const char *description;
-} pcilib_register_bank_description_t;
-
-/**
- * Default mappings
- */
-typedef struct {
- uintptr_t start;
- uintptr_t end;
- pcilib_register_bank_addr_t bank;
- long addr_shift;
-} pcilib_register_range_t;
-
-
-
-struct pcilib_register_bank_context_s {
- const pcilib_register_bank_description_t *bank;
- const pcilib_register_protocol_api_description_t *api;
-};
-
-
- // we don't copy strings, they should be statically allocated
-int pcilib_init_register_banks(pcilib_t *ctx);
-void pcilib_free_register_banks(pcilib_t *ctx);
-int pcilib_add_register_banks(pcilib_t *ctx, size_t n, const pcilib_register_bank_description_t *banks);
-
-pcilib_register_bank_t pcilib_find_register_bank_by_addr(pcilib_t *ctx, pcilib_register_bank_addr_t bank);
-pcilib_register_bank_t pcilib_find_register_bank_by_name(pcilib_t *ctx, const char *bankname);
-pcilib_register_bank_t pcilib_find_register_bank(pcilib_t *ctx, const char *bank);
-
-pcilib_register_protocol_t pcilib_find_register_protocol_by_addr(pcilib_t *ctx, pcilib_register_protocol_addr_t protocol);
-pcilib_register_protocol_t pcilib_find_register_protocol_by_name(pcilib_t *ctx, const char *name);
-pcilib_register_protocol_t pcilib_find_register_protocol(pcilib_t *ctx, const char *name);
-
-#endif /* _PCILIB_BANK_H */
diff --git a/config.h b/config.h
deleted file mode 100644
index 3ba92ee..0000000
--- a/config.h
+++ /dev/null
@@ -1,30 +0,0 @@
-#ifndef _PCILIB_CONFIG_H
-#define _PCILIB_CONFIG_H
-
-
-#include "register.h"
-#include "dma.h"
-
-/*
-typedef struct {
- const char *alias;
- pcilib_register_protocol_description_t *protocol;
-} pcilib_register_protocol_alias_t;
-
-
-typedef struct {
- const char *alias;
- pcilib_dma_description_t dma;
-} pcilib_dma_alias_t;
-
-extern pcilib_register_protocol_alias_t pcilib_protocols[];
-extern pcilib_dma_alias_t pcilib_dma[];
-*/
-
-extern const pcilib_register_protocol_description_t pcilib_protocols[];
-extern const pcilib_dma_description_t pcilib_dma[];
-
-
-//extern const pcilib_register_protocol_description_t *pcilib_protocol_default;
-
-#endif /* _PCILIB_CONFIG_H */
diff --git a/dma.h b/dma.h
deleted file mode 100644
index 2ed850d..0000000
--- a/dma.h
+++ /dev/null
@@ -1,86 +0,0 @@
-#ifndef _PCILIB_DMA_H
-#define _PCILIB_DMA_H
-
-#define PCILIB_DMA_BUFFER_INVALID ((size_t)-1)
-
-
-typedef struct {
- int started;
- size_t ring_size, buffer_size;
- size_t ring_head, ring_tail;
-} pcilib_dma_engine_status_t;
-
-typedef enum {
- PCILIB_DMA_TYPE_BLOCK,
- PCILIB_DMA_TYPE_PACKET,
- PCILIB_DMA_TYPE_UNKNOWN
-} pcilib_dma_engine_type_t;
-
-typedef struct {
- pcilib_dma_engine_addr_t addr;
- pcilib_dma_engine_type_t type;
- pcilib_dma_direction_t direction;
- size_t addr_bits;
-
- const char *name;
- const char *description;
-} pcilib_dma_engine_description_t;
-
-typedef struct {
- int used;
- int error;
- int first;
- int last;
- size_t size;
-} pcilib_dma_buffer_status_t;
-
-/*
-typedef struct {
- int ignore_eop;
-} pcilib_dma_parameters_t;
-*/
-
-typedef struct {
-// pcilib_dma_parameters_t params;
- pcilib_t *pcilib;
-} pcilib_dma_context_t;
-
-typedef struct {
- pcilib_dma_context_t *(*init)(pcilib_t *ctx, const char *model, const void *arg);
- void (*free)(pcilib_dma_context_t *ctx);
-
- int (*status)(pcilib_dma_context_t *ctx, pcilib_dma_engine_t dma, pcilib_dma_engine_status_t *status, size_t n_buffers, pcilib_dma_buffer_status_t *buffers);
-
- int (*enable_irq)(pcilib_dma_context_t *ctx, pcilib_irq_type_t irq_type, pcilib_dma_flags_t flags);
- int (*disable_irq)(pcilib_dma_context_t *ctx, pcilib_dma_flags_t flags);
- int (*acknowledge_irq)(pcilib_dma_context_t *ctx, pcilib_irq_type_t irq_type, pcilib_irq_source_t irq_source);
-
- int (*start_dma)(pcilib_dma_context_t *ctx, pcilib_dma_engine_t dma, pcilib_dma_flags_t flags);
- int (*stop_dma)(pcilib_dma_context_t *ctx, pcilib_dma_engine_t dma, pcilib_dma_flags_t flags);
-
- int (*push)(pcilib_dma_context_t *ctx, pcilib_dma_engine_t dma, uintptr_t addr, size_t size, pcilib_dma_flags_t flags, pcilib_timeout_t timeout, void *buf, size_t *written);
- int (*stream)(pcilib_dma_context_t *ctx, 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);
-
- double (*benchmark)(pcilib_dma_context_t *ctx, pcilib_dma_engine_addr_t dma, uintptr_t addr, size_t size, size_t iterations, pcilib_dma_direction_t direction);
-} pcilib_dma_api_description_t;
-
-
-typedef struct {
- const pcilib_dma_api_description_t *api;
- const pcilib_register_bank_description_t *banks;
- const pcilib_register_description_t *registers;
- const pcilib_dma_engine_description_t *engines;
- const char *model;
- const void *args;
- const char *name;
- const char *description;
-} pcilib_dma_description_t;
-
-
-const pcilib_dma_description_t *pcilib_get_dma_info(pcilib_t *ctx);
-pcilib_dma_engine_t pcilib_add_dma_engine(pcilib_t *ctx, pcilib_dma_engine_description_t *desc);
-int pcilib_get_dma_status(pcilib_t *ctx, pcilib_dma_engine_t dma, pcilib_dma_engine_status_t *status, size_t n_buffers, pcilib_dma_buffer_status_t *buffers);
-int pcilib_init_dma(pcilib_t *ctx);
-
-
-#endif /* _PCILIB_DMA_H */
diff --git a/dma/CMakeLists.txt b/dma/CMakeLists.txt
index 9bbfacd..8a3a8e1 100644
--- a/dma/CMakeLists.txt
+++ b/dma/CMakeLists.txt
@@ -1,8 +1,8 @@
include_directories(
${CMAKE_SOURCE_DIR}
+ ${CMAKE_SOURCE_DIR}/pcilib
)
-
set(HEADERS ${HEADERS} nwl.h nwl_private.h nwl_engine.h nwl_irq.h nwl_loopback.h ipe.h ipe_private.h)
add_library(dma STATIC nwl.c nwl_engine.c nwl_irq.c nwl_loopback.c ipe.c)
diff --git a/dma/ipe.h b/dma/ipe.h
index 208911a..c647954 100644
--- a/dma/ipe.h
+++ b/dma/ipe.h
@@ -2,7 +2,7 @@
#define _PCILIB_DMA_IPE_H
#include <stdio.h>
-#include "../pcilib.h"
+#include "pcilib.h"
//#define PCILIB_NWL_MODIFICATION_IPECAMERA 0x100
@@ -38,7 +38,7 @@ static const pcilib_dma_engine_description_t ipe_dma_engines[] = {
};
static const pcilib_register_bank_description_t ipe_dma_banks[] = {
- { PCILIB_REGISTER_BANK_DMA, PCILIB_BAR0, 0xA000, PCILIB_REGISTER_PROTOCOL_DEFAULT, 0, 0, PCILIB_LITTLE_ENDIAN, 32, PCILIB_LITTLE_ENDIAN, "0x%lx", "dma", "DMA Registers"},
+ { PCILIB_REGISTER_BANK_DMA, PCILIB_REGISTER_PROTOCOL_DEFAULT, PCILIB_BAR0, 0, 0, 32, 0x0200, PCILIB_LITTLE_ENDIAN, PCILIB_LITTLE_ENDIAN, "0x%lx", "dma", "DMA Registers"},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
};
diff --git a/dma/nwl.h b/dma/nwl.h
index d4742fd..3d6e988 100644
--- a/dma/nwl.h
+++ b/dma/nwl.h
@@ -2,7 +2,7 @@
#define _PCILIB_DMA_NWL_H
#include <stdio.h>
-#include "../pcilib.h"
+#include "pcilib.h"
pcilib_dma_context_t *dma_nwl_init(pcilib_t *ctx, const char *model, const void *arg);
void dma_nwl_free(pcilib_dma_context_t *vctx);
@@ -36,7 +36,7 @@ static const pcilib_dma_api_description_t nwl_dma_api = {
};
static pcilib_register_bank_description_t nwl_dma_banks[] = {
- { PCILIB_REGISTER_BANK_DMA, PCILIB_BAR0, 0xA000, PCILIB_REGISTER_PROTOCOL_DEFAULT , 0, 0, PCILIB_LITTLE_ENDIAN, 32, PCILIB_LITTLE_ENDIAN, "0x%lx", "dma", "DMA Registers"},
+ { PCILIB_REGISTER_BANK_DMA, PCILIB_REGISTER_PROTOCOL_DEFAULT, PCILIB_BAR0, 0, 0, 32, 0xA000, PCILIB_LITTLE_ENDIAN, PCILIB_LITTLE_ENDIAN, "0x%lx", "dma", "DMA Registers"},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
};
diff --git a/pcilib/CMakeLists.txt b/pcilib/CMakeLists.txt
new file mode 100644
index 0000000..c5297ab
--- /dev/null
+++ b/pcilib/CMakeLists.txt
@@ -0,0 +1,21 @@
+include_directories(
+ ${CMAKE_SOURCE_DIR}
+ ${CMAKE_SOURCE_DIR}/pcilib
+)
+
+set(HEADERS pcilib.h pci.h config.h model.h bank.h register.h kmem.h irq.h dma.h event.h tools.h error.h)
+add_library(pcilib SHARED pci.c config.c model.c bank.c register.c kmem.c irq.c dma.c event.c tools.c error.c)
+target_link_libraries(pcilib dma protocols ${CMAKE_THREAD_LIBS_INIT} ${UFODECODE_LIBRARIES} )
+add_dependencies(pcilib dma protocols)
+
+install(TARGETS pcilib
+ LIBRARY DESTINATION lib${LIB_SUFFIX}
+)
+
+install(FILES pcilib.h
+ DESTINATION include
+)
+
+install(FILES bank.h register.h dma.h event.h model.h error.h tools.h config.h
+ DESTINATION include/pcilib
+)
diff --git a/bank.c b/pcilib/bank.c
index c601c57..91bd161 100644
--- a/bank.c
+++ b/pcilib/bank.c
@@ -38,9 +38,12 @@ int pcilib_init_register_banks(pcilib_t *ctx) {
bapi = ctx->protocols[protocol].api;
- if (bapi->init)
- bank_ctx = bapi->init(ctx, ctx->num_banks_init, ctx->protocols[protocol].model, ctx->protocols[protocol].args);
- else
+ if (bapi->init) {
+ const char *model = ctx->protocols[protocol].model;
+ if (!model) model = ctx->model;
+
+ bank_ctx = bapi->init(ctx, ctx->num_banks_init, model, ctx->protocols[protocol].args);
+ } else
bank_ctx = (pcilib_register_bank_context_t*)malloc(sizeof(pcilib_register_bank_context_t));
if (!bank_ctx)
diff --git a/pcilib/bank.h b/pcilib/bank.h
new file mode 100644
index 0000000..f673169
--- /dev/null
+++ b/pcilib/bank.h
@@ -0,0 +1,102 @@
+#ifndef _PCILIB_BANK_H
+#define _PCILIB_BANK_H
+
+#include <pcilib.h>
+
+#define PCILIB_REGISTER_BANK_INVALID ((pcilib_register_bank_t)-1)
+#define PCILIB_REGISTER_BANK0 0 /**< First BANK to be used in the event engine */
+#define PCILIB_REGISTER_BANK1 1
+#define PCILIB_REGISTER_BANK2 2
+#define PCILIB_REGISTER_BANK3 3
+#define PCILIB_REGISTER_BANK_DMA 64 /**< First BANK address to be used by DMA engines */
+#define PCILIB_REGISTER_BANK_DYNAMIC 128 /**< First BANK address to map dynamic XML configuration */
+#define PCILIB_REGISTER_PROTOCOL_INVALID ((pcilib_register_protocol_t)-1)
+#define PCILIB_REGISTER_PROTOCOL0 0 /**< First PROTOCOL address to be used in the event engine */
+#define PCILIB_REGISTER_PROTOCOL_DEFAULT 64 /**< Default memmap based protocol */
+#define PCILIB_REGISTER_PROTOCOL_DMA 96 /**< First PROTOCOL address to be used by DMA engines */
+#define PCILIB_REGISTER_PROTOCOL_DYNAMIC 128 /**< First PROTOCOL address to be used by plugins */
+
+#define PCILIB_REGISTER_NO_BITS 0
+#define PCILIB_REGISTER_ALL_BITS ((pcilib_register_value_t)-1)
+
+typedef uint8_t pcilib_register_bank_t; /**< Type holding the bank position within the field listing register banks in the model */
+typedef uint8_t pcilib_register_bank_addr_t; /**< Type holding the bank address number */
+typedef uint8_t pcilib_register_protocol_t; /**< Type holding the protocol position within the field listing register protocols in the model */
+typedef uint8_t pcilib_register_protocol_addr_t; /**< Type holding the protocol address */
+
+
+typedef struct pcilib_register_bank_context_s pcilib_register_bank_context_t;
+
+typedef struct {
+ pcilib_register_bank_context_t *(*init)(pcilib_t *ctx, pcilib_register_bank_t bank, const char *model, const void *args); /**< Optional API call to initialize bank context */
+ void (*free)(pcilib_register_bank_context_t *ctx); /**< Optional API call to cleanup bank context */
+ int (*read)(pcilib_t *pcilib, pcilib_register_bank_context_t *ctx, pcilib_register_addr_t addr, pcilib_register_value_t *value); /**< Read from register, mandatory for RO/RW registers */
+ int (*write)(pcilib_t *pcilib, pcilib_register_bank_context_t *ctx, pcilib_register_addr_t addr, pcilib_register_value_t value); /**< Write to register, mandatory for WO/RW registers */
+} pcilib_register_protocol_api_description_t;
+
+typedef struct {
+ pcilib_register_protocol_addr_t addr; /**< Protocol address used in model for addressing the described protocol */
+ const pcilib_register_protocol_api_description_t *api; /**< Defines all API functions for protocol */
+ const char *model; /**< If NULL, the actually used model is used instead */
+ const void *args; /**< Custom protocol-specific arguments. The actual structure may depend on the specified model */
+ const char *name; /**< Short protocol name */
+ const char *description; /**< A bit longer protocol description */
+} pcilib_register_protocol_description_t;
+
+typedef struct {
+ pcilib_register_bank_addr_t addr; /**< Bank address used in model for addressing the described register bank */
+
+ pcilib_register_protocol_addr_t protocol; /**< Defines a protocol to access registers */
+ pcilib_bar_t bar; /**< Specifies the PCI BAR through which an access to the registers is provided (autodetcted if PCILIB_BAR_DETECT is specified) */
+ uintptr_t read_addr; /**< protocol specific (normally offset in the BAR of the first address used to read registers) */
+ uintptr_t write_addr; /**< protocol specific (normally offset in the BAR of the first address used to write registers) */
+
+ uint8_t access; /**< Default register size in bits (or word-size in plain addressing mode) */
+ size_t size; /**< Number of register addresses (plain addressing) in the bank (more register names can be defined if bit-fields/views are used) */
+ pcilib_endianess_t raw_endianess; /**< Specifies endianess in the plain-addressing mode, PCILIB_HOST_ENDIAN have to be specified if no conversion desired.
+ Conversion applied after protocol. This value does not get into the account in register-access mode */
+ pcilib_endianess_t endianess; /**< Specifies endianess in the register-access mode, this may differ from raw_endianess if multi-word registers are used.
+ This is fully independent from raw_endianess. No double conversion is either performed */
+
+ const char *format; /**< printf format for the registers, either %lu for decimal output or 0x%lx for hexdecimal */
+ const char *name; /**< short bank name */
+ const char *description; /**< longer bank description */
+} pcilib_register_bank_description_t;
+
+/**
+ * Default mappings: defines virtual address to register mappings, i.e. how 0x9000 in the following command
+ * will be mapped to the actual register. By comparing with start and end-addresses, we find to which range
+ * 0x9000 belongs to and detect actual bank and offset in it.
+ * Simple example: pci -r 0x9000
+ * if we specify range { 0x9000, 0x9100, 10, -0x9000}, the example command we print the value of the first
+ * register in the bank 10.
+ */
+typedef struct {
+ uintptr_t start; /**< The first virtual address of the register range */
+ uintptr_t end; /**< The last virtual address of the register range */
+ pcilib_register_bank_addr_t bank; /**< The bank mapped to the specified range */
+ long addr_shift; /**< Address shift, i.e. how much we should add/substract to the virtual address to get address in the register bank */
+} pcilib_register_range_t;
+
+
+
+struct pcilib_register_bank_context_s {
+ const pcilib_register_bank_description_t *bank; /**< Corresponding bank description */
+ const pcilib_register_protocol_api_description_t *api; /**< API functions */
+};
+
+
+ // we don't copy strings, they should be statically allocated
+int pcilib_init_register_banks(pcilib_t *ctx);
+void pcilib_free_register_banks(pcilib_t *ctx);
+int pcilib_add_register_banks(pcilib_t *ctx, size_t n, const pcilib_register_bank_description_t *banks);
+
+pcilib_register_bank_t pcilib_find_register_bank_by_addr(pcilib_t *ctx, pcilib_register_bank_addr_t bank);
+pcilib_register_bank_t pcilib_find_register_bank_by_name(pcilib_t *ctx, const char *bankname);
+pcilib_register_bank_t pcilib_find_register_bank(pcilib_t *ctx, const char *bank);
+
+pcilib_register_protocol_t pcilib_find_register_protocol_by_addr(pcilib_t *ctx, pcilib_register_protocol_addr_t protocol);
+pcilib_register_protocol_t pcilib_find_register_protocol_by_name(pcilib_t *ctx, const char *name);
+pcilib_register_protocol_t pcilib_find_register_protocol(pcilib_t *ctx, const char *name);
+
+#endif /* _PCILIB_BANK_H */
diff --git a/config.c b/pcilib/config.c
index 642c505..21a0e53 100644
--- a/config.c
+++ b/pcilib/config.c
@@ -2,7 +2,6 @@
#include <stdio.h>
-#include "model.h"
#include "error.h"
#include "config.h"
@@ -18,23 +17,21 @@ const pcilib_register_protocol_description_t pcilib_protocols[] = {
{ 0 }
};
-//static const pcilib_register_protocol_description_t *pcilib_protocol_default = NULL;//{0};//&pcilib_protocols[0];
-
#include "dma/nwl.h"
#include "dma/ipe.h"
-/*
-pcilib_register_protocol_alias_t pcilib_protocols[] = {
- { "default", { &pcilib_default_protocol_api, PCILIB_REGISTER_PROTOCOL_MODIFICATION_DEFAULT, NULL } },
- { NULL, {0} }
-};
-*/
+const pcilib_dma_description_t pcilib_ipedma =
+ { &ipe_dma_api, ipe_dma_banks, ipe_dma_registers, ipe_dma_engines, NULL, NULL, "ipedma", "DMA engine developed by M. Caselle" };
+const pcilib_dma_description_t pcilib_nwldma =
+ { &nwl_dma_api, nwl_dma_banks, nwl_dma_registers, NULL, NULL, NULL, "nwldma", "North West Logic DMA Engine" };
-const pcilib_dma_description_t pcilib_dma[] = {
+const pcilib_dma_description_t pcilib_dma[] = {
{ &ipe_dma_api, ipe_dma_banks, ipe_dma_registers, ipe_dma_engines, NULL, NULL, "ipedma", "DMA engine developed by M. Caselle" },
{ &nwl_dma_api, nwl_dma_banks, nwl_dma_registers, NULL, NULL, NULL, "nwldma", "North West Logic DMA Engine" },
{ &nwl_dma_api, nwl_dma_banks, nwl_dma_registers, NULL, "ipecamera", NULL, "nwldma-ipe", "North West Logic DMA Engine" },
{ 0 }
};
+
+
diff --git a/pcilib/config.h b/pcilib/config.h
new file mode 100644
index 0000000..710bff8
--- /dev/null
+++ b/pcilib/config.h
@@ -0,0 +1,17 @@
+#ifndef _PCILIB_CONFIG_H
+#define _PCILIB_CONFIG_H
+
+
+#include <pcilib/register.h>
+#include <pcilib/bank.h>
+#include <pcilib/dma.h>
+
+extern const pcilib_register_protocol_description_t pcilib_protocols[];
+extern const pcilib_dma_description_t pcilib_dma[];
+
+extern const pcilib_register_protocol_api_description_t pcilib_default_protocol_api;
+
+extern const pcilib_dma_description_t pcilib_ipedma;
+extern const pcilib_dma_description_t pcilib_nwldma;
+
+#endif /* _PCILIB_CONFIG_H */
diff --git a/dma.c b/pcilib/dma.c
index ba99ba1..f6b8053 100644
--- a/dma.c
+++ b/pcilib/dma.c
@@ -18,7 +18,7 @@
#include "pci.h"
#include "dma.h"
-const pcilib_dma_description_t *pcilib_get_dma_info(pcilib_t *ctx) {
+const pcilib_dma_description_t *pcilib_get_dma_description(pcilib_t *ctx) {
int err;
err = pcilib_init_dma(ctx);
@@ -29,24 +29,24 @@ const pcilib_dma_description_t *pcilib_get_dma_info(pcilib_t *ctx) {
if (!ctx->dma_ctx) return NULL;
- return ctx->model_info.dma;
+ return &ctx->dma;
}
pcilib_dma_engine_t pcilib_find_dma_by_addr(pcilib_t *ctx, pcilib_dma_direction_t direction, pcilib_dma_engine_addr_t dma) {
pcilib_dma_engine_t i;
- const pcilib_dma_description_t *info = pcilib_get_dma_info(ctx);
- if (!info) {
+ const pcilib_dma_description_t *dma_info = pcilib_get_dma_description(ctx);
+ if (!dma_info) {
pcilib_error("DMA Engine is not configured in the current model");
return PCILIB_ERROR_NOTSUPPORTED;
}
- for (i = 0; info->engines[i].addr_bits; i++) {
- if ((info->engines[i].addr == dma)&&((info->engines[i].direction&direction)==direction)) break;
+ for (i = 0; dma_info->engines[i].addr_bits; i++) {
+ if ((dma_info->engines[i].addr == dma)&&((dma_info->engines[i].direction&direction)==direction)) break;
}
- if (info->engines[i].addr_bits) return i;
+ if (dma_info->engines[i].addr_bits) return i;
return PCILIB_DMA_ENGINE_INVALID;
}
@@ -75,16 +75,14 @@ int pcilib_init_dma(pcilib_t *ctx) {
}
dma_ctx = model_info->api->init_dma(ctx->event_ctx);
- } else if ((model_info->dma)&&(model_info->dma->api)&&(model_info->dma->api->init)) {
- const pcilib_dma_description_t *dma = model_info->dma;
-
+ } else if ((ctx->dma.api)&&(ctx->dma.api->init)) {
err = pcilib_init_register_banks(ctx);
if (err) {
pcilib_error("Error (%i) while initializing register banks", err);
return err;
}
- dma_ctx = dma->api->init(ctx, (dma->model?dma->model:ctx->model), dma->args);
+ dma_ctx = ctx->dma.api->init(ctx, (ctx->dma.model?ctx->dma.model:ctx->model), ctx->dma.args);
}
if (dma_ctx) {
@@ -97,66 +95,66 @@ int pcilib_init_dma(pcilib_t *ctx) {
}
int pcilib_start_dma(pcilib_t *ctx, pcilib_dma_engine_t dma, pcilib_dma_flags_t flags) {
- const pcilib_dma_description_t *info = pcilib_get_dma_info(ctx);
+ const pcilib_dma_description_t *info = pcilib_get_dma_description(ctx);
if (!info) {
pcilib_error("DMA is not supported by the device");
return PCILIB_ERROR_NOTSUPPORTED;
}
- if (!ctx->model_info.dma->api) {
+ if (!info->api) {
pcilib_error("DMA Engine is not configured in the current model");
return PCILIB_ERROR_NOTAVAILABLE;
}
- if (!ctx->model_info.dma->api->start_dma) {
+ if (!info->api->start_dma) {
return 0;
}
- return ctx->model_info.dma->api->start_dma(ctx->dma_ctx, dma, flags);
+ return info->api->start_dma(ctx->dma_ctx, dma, flags);
}
int pcilib_stop_dma(pcilib_t *ctx, pcilib_dma_engine_t dma, pcilib_dma_flags_t flags) {
- const pcilib_dma_description_t *info = pcilib_get_dma_info(ctx);
+ const pcilib_dma_description_t *info = pcilib_get_dma_description(ctx);
if (!info) {
pcilib_error("DMA is not supported by the device");
return PCILIB_ERROR_NOTSUPPORTED;
}
- if (!ctx->model_info.dma->api) {
+ if (!info->api) {
pcilib_error("DMA Engine is not configured in the current model");
return PCILIB_ERROR_NOTAVAILABLE;
}
- if (!ctx->model_info.dma->api->stop_dma) {
+ if (!info->api->stop_dma) {
return 0;
}
- return ctx->model_info.dma->api->stop_dma(ctx->dma_ctx, dma, flags);
+ return info->api->stop_dma(ctx->dma_ctx, dma, flags);
}
int pcilib_enable_irq(pcilib_t *ctx, pcilib_irq_type_t irq_type, pcilib_dma_flags_t flags) {
- const pcilib_dma_description_t *info = pcilib_get_dma_info(ctx);
+ const pcilib_dma_description_t *info = pcilib_get_dma_description(ctx);
- if ((!info)||(!ctx->model_info.dma->api)||(!ctx->model_info.dma->api->enable_irq)) return 0;
+ if ((!info)||(!info->api)||(!info->api->enable_irq)) return 0;
- return ctx->model_info.dma->api->enable_irq(ctx->dma_ctx, irq_type, flags);
+ return info->api->enable_irq(ctx->dma_ctx, irq_type, flags);
}
int pcilib_disable_irq(pcilib_t *ctx, pcilib_dma_flags_t flags) {
- const pcilib_dma_description_t *info = pcilib_get_dma_info(ctx);
+ const pcilib_dma_description_t *info = pcilib_get_dma_description(ctx);
- if ((!info)||(!ctx->model_info.dma->api)||(!ctx->model_info.dma->api->disable_irq)) return 0;
+ if ((!info)||(!info->api)||(!info->api->disable_irq)) return 0;
- return ctx->model_info.dma->api->disable_irq(ctx->dma_ctx, flags);
+ return info->api->disable_irq(ctx->dma_ctx, flags);
}
int pcilib_acknowledge_irq(pcilib_t *ctx, pcilib_irq_type_t irq_type, pcilib_irq_source_t irq_source) {
- const pcilib_dma_description_t *info = pcilib_get_dma_info(ctx);
+ const pcilib_dma_description_t *info = pcilib_get_dma_description(ctx);
- if ((!info)||(!ctx->model_info.dma->api)||(!ctx->model_info.dma->api->acknowledge_irq)) return 0;
+ if ((!info)||(!info->api)||(!info->api->acknowledge_irq)) return 0;
- return ctx->model_info.dma->api->acknowledge_irq(ctx->dma_ctx, irq_type, irq_source);
+ return info->api->acknowledge_irq(ctx->dma_ctx, irq_type, irq_source);
}
typedef struct {
@@ -203,18 +201,18 @@ static int pcilib_dma_skip_callback(void *arg, pcilib_dma_flags_t flags, size_t
}
int pcilib_stream_dma(pcilib_t *ctx, 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) {
- const pcilib_dma_description_t *info = pcilib_get_dma_info(ctx);
+ const pcilib_dma_description_t *info = pcilib_get_dma_description(ctx);
if (!info) {
pcilib_error("DMA is not supported by the device");
return PCILIB_ERROR_NOTSUPPORTED;
}
- if (!ctx->model_info.dma->api) {
+ if (!info->api) {
pcilib_error("DMA Engine is not configured in the current model");
return PCILIB_ERROR_NOTAVAILABLE;
}
- if (!ctx->model_info.dma->api->stream) {
+ if (!info->api->stream) {
pcilib_error("The DMA read is not supported by configured DMA engine");
return PCILIB_ERROR_NOTSUPPORTED;
}
@@ -230,7 +228,7 @@ int pcilib_stream_dma(pcilib_t *ctx, pcilib_dma_engine_t dma, uintptr_t addr, si
return PCILIB_ERROR_NOTSUPPORTED;
}
- return ctx->model_info.dma->api->stream(ctx->dma_ctx, dma, addr, size, flags, timeout, cb, cbattr);
+ return info->api->stream(ctx->dma_ctx, dma, addr, size, flags, timeout, cb, cbattr);
}
int pcilib_read_dma_custom(pcilib_t *ctx, pcilib_dma_engine_t dma, uintptr_t addr, size_t size, pcilib_dma_flags_t flags, pcilib_timeout_t timeout, void *buf, size_t *read_bytes) {
@@ -280,18 +278,18 @@ int pcilib_skip_dma(pcilib_t *ctx, pcilib_dma_engine_t dma) {
int pcilib_push_dma(pcilib_t *ctx, pcilib_dma_engine_t dma, uintptr_t addr, size_t size, pcilib_dma_flags_t flags, pcilib_timeout_t timeout, void *buf, size_t *written) {
- const pcilib_dma_description_t *info = pcilib_get_dma_info(ctx);
+ const pcilib_dma_description_t *info = pcilib_get_dma_description(ctx);
if (!info) {
pcilib_error("DMA is not supported by the device");
return PCILIB_ERROR_NOTSUPPORTED;
}
- if (!ctx->model_info.dma->api) {
+ if (!info->api) {
pcilib_error("DMA Engine is not configured in the current model");
return PCILIB_ERROR_NOTAVAILABLE;
}
- if (!ctx->model_info.dma->api->push) {
+ if (!info->api->push) {
pcilib_error("The DMA write is not supported by configured DMA engine");
return PCILIB_ERROR_NOTSUPPORTED;
}
@@ -307,7 +305,7 @@ int pcilib_push_dma(pcilib_t *ctx, pcilib_dma_engine_t dma, uintptr_t addr, size
return PCILIB_ERROR_NOTSUPPORTED;
}
- return ctx->model_info.dma->api->push(ctx->dma_ctx, dma, addr, size, flags, timeout, buf, written);
+ return info->api->push(ctx->dma_ctx, dma, addr, size, flags, timeout, buf, written);
}
@@ -316,38 +314,38 @@ int pcilib_write_dma(pcilib_t *ctx, pcilib_dma_engine_t dma, uintptr_t addr, siz
}
double pcilib_benchmark_dma(pcilib_t *ctx, pcilib_dma_engine_addr_t dma, uintptr_t addr, size_t size, size_t iterations, pcilib_dma_direction_t direction) {
- const pcilib_dma_description_t *info = pcilib_get_dma_info(ctx);
+ const pcilib_dma_description_t *info = pcilib_get_dma_description(ctx);
if (!info) {
pcilib_error("DMA is not supported by the device");
return 0;
}
- if (!ctx->model_info.dma->api) {
+ if (!info->api) {
pcilib_error("DMA Engine is not configured in the current model");
return -1;
}
- if (!ctx->model_info.dma->api->benchmark) {
+ if (!info->api->benchmark) {
pcilib_error("The DMA benchmark is not supported by configured DMA engine");
return -1;
}
- return ctx->model_info.dma->api->benchmark(ctx->dma_ctx, dma, addr, size, iterations, direction);
+ return info->api->benchmark(ctx->dma_ctx, dma, addr, size, iterations, direction);
}
int pcilib_get_dma_status(pcilib_t *ctx, pcilib_dma_engine_t dma, pcilib_dma_engine_status_t *status, size_t n_buffers, pcilib_dma_buffer_status_t *buffers) {
- const pcilib_dma_description_t *info = pcilib_get_dma_info(ctx);
+ const pcilib_dma_description_t *info = pcilib_get_dma_description(ctx);
if (!info) {
pcilib_error("DMA is not supported by the device");
return 0;
}
- if (!ctx->model_info.dma->api) {
+ if (!info->api) {
pcilib_error("DMA Engine is not configured in the current model");
return -1;
}
- if (!ctx->model_info.dma->api->status) {
+ if (!info->api->status) {
memset(status, 0, sizeof(pcilib_dma_engine_status_t));
return -1;
}
@@ -358,5 +356,5 @@ int pcilib_get_dma_status(pcilib_t *ctx, pcilib_dma_engine_t dma, pcilib_dma_eng
return -1;
}
- return ctx->model_info.dma->api->status(ctx->dma_ctx, dma, status, n_buffers, buffers);
+ return info->api->status(ctx->dma_ctx, dma, status, n_buffers, buffers);
}
diff --git a/pcilib/dma.h b/pcilib/dma.h
new file mode 100644
index 0000000..83bc0fd
--- /dev/null
+++ b/pcilib/dma.h
@@ -0,0 +1,85 @@
+#ifndef _PCILIB_DMA_H
+#define _PCILIB_DMA_H
+
+#define PCILIB_DMA_BUFFER_INVALID ((size_t)-1)
+
+typedef struct {
+ int used; /**< Indicates if buffer has unread data or empty and ready for DMA */
+ int error; /**< Indicates if data is complete and correctly transfered or some error occured during the DMA transfer */
+ int first; /**< Indicates the first buffer of the packet */
+ int last; /**< Indicates the last buffer of the packet */
+ size_t size; /**< Indicates number of bytes actually written to the buffer */
+} pcilib_dma_buffer_status_t;
+
+typedef struct {
+ int started; /**< Informs if the engine is currently started or not */
+ size_t ring_size, buffer_size; /**< The number of allocated DMA buffers and size of each buffer in bytes */
+ size_t ring_head, ring_tail; /**< The first and the last buffer containing the data */
+} pcilib_dma_engine_status_t;
+
+typedef enum {
+ PCILIB_DMA_TYPE_BLOCK, /**< Simple DMA engine */
+ PCILIB_DMA_TYPE_PACKET, /**< Streaming (scatter-gather) DMA engine */
+ PCILIB_DMA_TYPE_UNKNOWN
+} pcilib_dma_engine_type_t;
+
+typedef struct {
+ pcilib_dma_engine_addr_t addr; /**< Address of DMA engine (from 0) */
+ pcilib_dma_engine_type_t type; /**< Type of DMA engine */
+ pcilib_dma_direction_t direction; /**< Defines which kind of transfer does engine support: C2S, S2C, or both */
+ size_t addr_bits; /**< Number of addressable bits in the system memory (we currently work with 32-bits only) */
+
+ const char *name; /**< Defines a short name of engine (its main use, i.e. main, auxilliary, etc.) */
+ const char *description; /**< Defines a longer description of the engine */
+} pcilib_dma_engine_description_t;
+
+/*
+typedef struct {
+ int ignore_eop;
+} pcilib_dma_parameters_t;
+*/
+
+typedef struct {
+// pcilib_dma_parameters_t params;
+ pcilib_t *pcilib; /**< Reference to the pcilib context */
+} pcilib_dma_context_t;
+
+typedef struct {
+ pcilib_dma_context_t *(*init)(pcilib_t *ctx, const char *model, const void *arg);
+ void (*free)(pcilib_dma_context_t *ctx);
+
+ int (*status)(pcilib_dma_context_t *ctx, pcilib_dma_engine_t dma, pcilib_dma_engine_status_t *status, size_t n_buffers, pcilib_dma_buffer_status_t *buffers);
+
+ int (*enable_irq)(pcilib_dma_context_t *ctx, pcilib_irq_type_t irq_type, pcilib_dma_flags_t flags);
+ int (*disable_irq)(pcilib_dma_context_t *ctx, pcilib_dma_flags_t flags);
+ int (*acknowledge_irq)(pcilib_dma_context_t *ctx, pcilib_irq_type_t irq_type, pcilib_irq_source_t irq_source);
+
+ int (*start_dma)(pcilib_dma_context_t *ctx, pcilib_dma_engine_t dma, pcilib_dma_flags_t flags);
+ int (*stop_dma)(pcilib_dma_context_t *ctx, pcilib_dma_engine_t dma, pcilib_dma_flags_t flags);
+
+ int (*push)(pcilib_dma_context_t *ctx, pcilib_dma_engine_t dma, uintptr_t addr, size_t size, pcilib_dma_flags_t flags, pcilib_timeout_t timeout, void *buf, size_t *written);
+ int (*stream)(pcilib_dma_context_t *ctx, 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);
+
+ double (*benchmark)(pcilib_dma_context_t *ctx, pcilib_dma_engine_addr_t dma, uintptr_t addr, size_t size, size_t iterations, pcilib_dma_direction_t direction);
+} pcilib_dma_api_description_t;
+
+
+typedef struct {
+ const pcilib_dma_api_description_t *api; /**< Defines all API functions for DMA operation */
+ const pcilib_register_bank_description_t *banks; /**< Pre-defined register banks exposed by DMA interface, additional banks can be defined during DMA initialization */
+ const pcilib_register_description_t *registers; /**< Pre-defined registers exposed by DMA interface, additional registers can be defined during DMA initialization */
+ const pcilib_dma_engine_description_t *engines; /**< List of DMA engines exposed by DMA interface, alternatively engines can be added during DMA initialization */
+ const char *model; /**< If NULL, the actually used event model is used instead */
+ const void *args; /**< Custom DMA-specific arguments. The actual structure may depend on the specified model */
+ const char *name; /**< Short name of DMA interface */
+ const char *description; /**< A bit longer description of DMA interface */
+} pcilib_dma_description_t;
+
+
+const pcilib_dma_description_t *pcilib_get_dma_description(pcilib_t *ctx);
+pcilib_dma_engine_t pcilib_add_dma_engine(pcilib_t *ctx, pcilib_dma_engine_description_t *desc);
+int pcilib_get_dma_status(pcilib_t *ctx, pcilib_dma_engine_t dma, pcilib_dma_engine_status_t *status, size_t n_buffers, pcilib_dma_buffer_status_t *buffers);
+int pcilib_init_dma(pcilib_t *ctx);
+
+
+#endif /* _PCILIB_DMA_H */
diff --git a/error.c b/pcilib/error.c
index f242209..f242209 100644
--- a/error.c
+++ b/pcilib/error.c
diff --git a/error.h b/pcilib/error.h
index d923d3f..d923d3f 100644
--- a/error.h
+++ b/pcilib/error.h
diff --git a/event.c b/pcilib/event.c
index fc07fd0..43bbf01 100644
--- a/event.c
+++ b/pcilib/event.c
@@ -59,7 +59,6 @@ int pcilib_init_event_engine(pcilib_t *ctx) {
api = model_info->api;
-// api = pcilib_model[model].api;
if ((api)&&(api->init)) {
ctx->event_ctx = api->init(ctx);
if (ctx->event_ctx) {
diff --git a/event.h b/pcilib/event.h
index a71d761..93f659c 100644
--- a/event.h
+++ b/pcilib/event.h
@@ -1,7 +1,7 @@
#ifndef _PCILIB_EVENT_H
#define _PCILIB_EVENT_H
-#include "pcilib.h"
+#include <pcilib.h>
typedef struct {
size_t max_events;
diff --git a/irq.c b/pcilib/irq.c
index 3d387bb..3d387bb 100644
--- a/irq.c
+++ b/pcilib/irq.c
diff --git a/irq.h b/pcilib/irq.h
index 441e0e5..441e0e5 100644
--- a/irq.h
+++ b/pcilib/irq.h
diff --git a/kmem.c b/pcilib/kmem.c
index 8560eae..8560eae 100644
--- a/kmem.c
+++ b/pcilib/kmem.c
diff --git a/kmem.h b/pcilib/kmem.h
index 8302b6a..8302b6a 100644
--- a/kmem.h
+++ b/pcilib/kmem.h
diff --git a/linux-3.10.h b/pcilib/linux-3.10.h
index 161d2aa..161d2aa 100644
--- a/linux-3.10.h
+++ b/pcilib/linux-3.10.h
diff --git a/model.c b/pcilib/model.c
index 65f96aa..65f96aa 100644
--- a/model.c
+++ b/pcilib/model.c
diff --git a/model.h b/pcilib/model.h
index 2d8d6b7..0b18c59 100644
--- a/model.h
+++ b/pcilib/model.h
@@ -1,14 +1,15 @@
#ifndef _PCILIB_MODEL_H
#define _PCILIB_MODEL_H
-#include <bank.h>
-#include <register.h>
-#include <dma.h>
-#include <event.h>
+#include <pcilib/bank.h>
+#include <pcilib/register.h>
+#include <pcilib/dma.h>
+#include <pcilib/event.h>
+#include <pcilib/config.h>
typedef struct {
- uint8_t access;
- pcilib_endianess_t endianess;
+ const pcilib_event_api_description_t *api;
+ const pcilib_dma_description_t *dma;
const pcilib_register_description_t *registers;
const pcilib_register_bank_description_t *banks;
@@ -18,9 +19,6 @@ typedef struct {
const pcilib_event_description_t *events;
const pcilib_event_data_type_description_t *data_types;
- const pcilib_dma_description_t *dma;
- const pcilib_event_api_description_t *api;
-
const char *name;
const char *description;
} pcilib_model_description_t;
diff --git a/pci.c b/pcilib/pci.c
index 61571fc..426ae91 100644
--- a/pci.c
+++ b/pcilib/pci.c
@@ -444,10 +444,8 @@ void pcilib_close(pcilib_t *ctx) {
if (ctx) {
const pcilib_model_description_t *model_info = pcilib_get_model_description(ctx);
const pcilib_event_api_description_t *eapi = model_info->api;
- const pcilib_dma_api_description_t *dapi = NULL;
+ const pcilib_dma_api_description_t *dapi = ctx->dma.api;
- if (model_info->dma) dapi = model_info->dma->api;
-
if ((eapi)&&(eapi->free)) eapi->free(ctx->event_ctx);
if ((dapi)&&(dapi->free)) dapi->free(ctx->dma_ctx);
diff --git a/pci.h b/pcilib/pci.h
index fe2ff8a..fe2ff8a 100644
--- a/pci.h
+++ b/pcilib/pci.h
diff --git a/pcilib.h b/pcilib/pcilib.h
index 3518f75..3518f75 100644
--- a/pcilib.h
+++ b/pcilib/pcilib.h
diff --git a/register.c b/pcilib/register.c
index 8d138b8..8d138b8 100644
--- a/register.c
+++ b/pcilib/register.c
diff --git a/register.h b/pcilib/register.h
index cd13522..89673ec 100644
--- a/register.h
+++ b/pcilib/register.h
@@ -2,7 +2,7 @@
#define _PCILIB_REGISTER_H
#include <pcilib.h>
-#include <bank.h>
+#include <pcilib/bank.h>
typedef enum {
PCILIB_REGISTER_R = 1, /**< reading from register is allowed */
diff --git a/tools.c b/pcilib/tools.c
index 352127d..352127d 100644
--- a/tools.c
+++ b/pcilib/tools.c
diff --git a/tools.h b/pcilib/tools.h
index 41dc071..41dc071 100644
--- a/tools.h
+++ b/pcilib/tools.h
diff --git a/pcitool/CMakeLists.txt b/pcitool/CMakeLists.txt
index 6dc7942..1b21041 100644
--- a/pcitool/CMakeLists.txt
+++ b/pcitool/CMakeLists.txt
@@ -1,8 +1,32 @@
include_directories(
${CMAKE_SOURCE_DIR}
+ ${CMAKE_SOURCE_DIR}/pcilib
+ ${FASTWRITER_INCLUDE_DIRS}
)
-set(HEADERS ${HEADERS} sysinfo.h formaters.h)
+link_directories(
+ ${FASTWRITER_LIBRARY_DIRS}
+ ${CMAKE_SOURCE_DIR}/pcilib
+)
+
+if (NOT DISABLE_PCITOOL)
+ add_executable(pci cli.c sysinfo.c formaters.c)
+ set(HEADERS ${HEADERS} sysinfo.h formaters.h)
+ add_dependencies(pci pcitool)
+ target_link_libraries(pci pcilib ${FASTWRITER_LIBRARIES})
+ set_target_properties(pci PROPERTIES
+ LINK_FLAGS ${CMAKE_THREAD_LIBS_INIT}
+ )
+
+#set_target_properties(pci PROPERTIES
+# LINK_FLAGS "-Wl,pcitool/libpcitool.a"
+#)
-add_library(pcitool STATIC sysinfo.c formaters.c)
+ if(NOT DEFINED BIN_INSTALL_DIR)
+ set(BIN_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/bin")
+ endif(NOT DEFINED BIN_INSTALL_DIR)
+ install(TARGETS pci
+ DESTINATION ${BIN_INSTALL_DIR}
+ )
+endif (NOT DISABLE_PCITOOL)
diff --git a/cli.c b/pcitool/cli.c
index 616e9ad..a5c4290 100644
--- a/cli.c
+++ b/pcitool/cli.c
@@ -362,7 +362,7 @@ void List(pcilib_t *handle, const pcilib_model_description_t *model_info, const
const pcilib_event_data_type_description_t *types;
const pcilib_board_info_t *board_info = pcilib_get_board_info(handle);
- const pcilib_dma_description_t *dma_info = pcilib_get_dma_info(handle);
+ const pcilib_dma_description_t *dma_info = pcilib_get_dma_description(handle);
for (i = 0; i < PCILIB_MAX_BARS; i++) {
if (board_info->bar_length[i] > 0) {
@@ -922,7 +922,7 @@ int ReadRegister(pcilib_t *handle, const pcilib_model_description_t *model_info,
}
} else {
// Adding DMA registers
- pcilib_get_dma_info(handle);
+ pcilib_get_dma_description(handle);
if (model_info->registers) {
if (bank) {
@@ -1762,7 +1762,7 @@ int StartStopDMA(pcilib_t *handle, const pcilib_model_description_t *model_info
pcilib_dma_engine_t dmaid;
if (dma == PCILIB_DMA_ENGINE_ADDR_INVALID) {
- const pcilib_dma_description_t *dma_info = pcilib_get_dma_info(handle);
+ const pcilib_dma_description_t *dma_info = pcilib_get_dma_description(handle);
if (start) Error("DMA engine should be specified");
@@ -2370,6 +2370,7 @@ int main(int argc, char **argv) {
const char *model = NULL;
const pcilib_model_description_t *model_info;
+ const pcilib_dma_description_t *dma_info;
MODE mode = MODE_INVALID;
GRAB_MODE grab_mode = 0;
size_t trigger_time = 0;
@@ -2847,6 +2848,7 @@ int main(int argc, char **argv) {
if (handle < 0) Error("Failed to open FPGA device: %s", fpga_device);
model_info = pcilib_get_model_description(handle);
+ dma_info = pcilib_get_dma_description(handle);
switch (mode) {
case MODE_WRITE:
@@ -2873,7 +2875,7 @@ int main(int argc, char **argv) {
else Usage(argc, argv, "The %i data values is specified, but %i required", argc - optind, size);
case MODE_READ:
if (!addr) {
- if (((!model_info->dma)||(!model_info->dma->api))&&(!model_info->api)) {
+ if (((!dma_info)||(!dma_info->api))&&(!model_info->api)) {
// if (model == PCILIB_MODEL_PCI) {
if ((amode != ACCESS_DMA)&&(amode != ACCESS_CONFIG))
Usage(argc, argv, "The address is not specified");
diff --git a/protocols/CMakeLists.txt b/protocols/CMakeLists.txt
index 5f64a43..3c1d75b 100644
--- a/protocols/CMakeLists.txt
+++ b/protocols/CMakeLists.txt
@@ -1,8 +1,8 @@
include_directories(
${CMAKE_SOURCE_DIR}
+ ${CMAKE_SOURCE_DIR}/pcilib
)
-
set(HEADERS ${HEADERS} default.h)
add_library(protocols STATIC default.c)
diff --git a/protocols/default.h b/protocols/default.h
index f8685f1..f535550 100644
--- a/protocols/default.h
+++ b/protocols/default.h
@@ -8,7 +8,7 @@ int pcilib_default_read(pcilib_t *ctx, pcilib_register_bank_context_t *bank, pci
int pcilib_default_write(pcilib_t *ctx, pcilib_register_bank_context_t *bank, pcilib_register_addr_t addr, pcilib_register_value_t value);
#ifdef _PCILIB_CONFIG_C
-static pcilib_register_protocol_api_description_t pcilib_default_protocol_api =
+const pcilib_register_protocol_api_description_t pcilib_default_protocol_api =
{ NULL, NULL, pcilib_default_read, pcilib_default_write };
#endif /* _PCILIB_CONFIG_C */
diff --git a/tests/grab.sh b/tests/grab.sh
index daf142e..daa08c1 100755
--- a/tests/grab.sh
+++ b/tests/grab.sh
@@ -1,8 +1,8 @@
#! /bin/bash
function pci {
- PCILIB_PATH="/root/pcitool"
- LD_LIBRARY_PATH="$PCILIB_PATH" $PCILIB_PATH/pci $*
+ PCILIB_PATH=".."
+ LD_LIBRARY_PATH="$PCILIB_PATH/pcilib" $PCILIB_PATH/pcitool/pci $*
}
rm -f images.raw
diff --git a/tests/ipedma/ipecamera-frame.sh b/tests/ipedma/ipecamera-frame.sh
index 9862432..5e72c6c 100755
--- a/tests/ipedma/ipecamera-frame.sh
+++ b/tests/ipedma/ipecamera-frame.sh
@@ -5,7 +5,7 @@ TESTS_PATH="`( cd \"$TESTS_PATH\" && pwd )`"
function pci {
PCILIB_PATH=$TESTS_PATH/../..
- LD_LIBRARY_PATH="$PCILIB_PATH" $PCILIB_PATH/pci -m ipedma $*
+ LD_LIBRARY_PATH="$PCILIB_PATH/pcilib" $PCILIB_PATH/pcitool/pci -m ipedma $*
}
diff --git a/tests/ipedma/ipecamera-test.sh b/tests/ipedma/ipecamera-test.sh
index 3984c82..cd21391 100755
--- a/tests/ipedma/ipecamera-test.sh
+++ b/tests/ipedma/ipecamera-test.sh
@@ -4,7 +4,7 @@ size=65536
function pci {
PCILIB_PATH=`pwd`/../..
- LD_LIBRARY_PATH="$PCILIB_PATH" $PCILIB_PATH/pci -m ipedma $*
+ LD_LIBRARY_PATH="$PCILIB_PATH/pcilib" $PCILIB_PATH/pcitool/pci -m ipedma $*
}
diff --git a/tests/ipedma/test.sh b/tests/ipedma/test.sh
index 4054f8a..62c391a 100755
--- a/tests/ipedma/test.sh
+++ b/tests/ipedma/test.sh
@@ -4,7 +4,7 @@ size=65536
function pci {
PCILIB_PATH=`pwd`/../..
- LD_LIBRARY_PATH="$PCILIB_PATH" $PCILIB_PATH/pci -m ipedma $*
+ LD_LIBRARY_PATH="$PCILIB_PATH/pcilib" $PCILIB_PATH/pcitool/pci -m ipedma $*
}
diff --git a/tests/nwldma/bench.sh b/tests/nwldma/bench.sh
index b36c251..d0bf323 100755
--- a/tests/nwldma/bench.sh
+++ b/tests/nwldma/bench.sh
@@ -1,8 +1,8 @@
#!/bin/bash
function pci {
- PCILIB_PATH="/root/pcitool"
- LD_LIBRARY_PATH="$PCILIB_PATH" $PCILIB_PATH/pci $*
+ PCILIB_PATH="../.."
+ LD_LIBRARY_PATH="$PCILIB_PATH/pcilib" $PCILIB_PATH/pcitool/pci $*
}
size=16
diff --git a/tests/nwldma/cleanup.sh b/tests/nwldma/cleanup.sh
index 5ef568e..87e1517 100755
--- a/tests/nwldma/cleanup.sh
+++ b/tests/nwldma/cleanup.sh
@@ -1,8 +1,8 @@
#!/bin/bash
function pci {
- PCILIB_PATH="/root/pcitool"
- LD_LIBRARY_PATH="$PCILIB_PATH" $PCILIB_PATH/pci $*
+ PCILIB_PATH="../.."
+ LD_LIBRARY_PATH="$PCILIB_PATH/pcilib" $PCILIB_PATH/pcitool/pci $*
}
pci --start-dma dma1r
diff --git a/tests/test-iommu.sh b/tests/test-iommu.sh
index 74e3ece..5a5924b 100755
--- a/tests/test-iommu.sh
+++ b/tests/test-iommu.sh
@@ -1,5 +1,10 @@
#! /bin/bash
+function pci {
+ PCILIB_PATH=".."
+ LD_LIBRARY_PATH="$PCILIB_PATH/pcilib" $PCILIB_PATH/pcitool/pci $*
+}
+
i=1
while [ 1 ]; do
pci --start-dma dma1r
diff --git a/tests/xilinxdma/xilinx_dma.sh b/tests/xilinxdma/xilinx_dma.sh
index 6aada8b..4fedac3 100755
--- a/tests/xilinxdma/xilinx_dma.sh
+++ b/tests/xilinxdma/xilinx_dma.sh
@@ -6,8 +6,8 @@ ITERATIONS=2
BUFFERS=16
function pci {
- PCILIB_PATH=`pwd`/..
- LD_LIBRARY_PATH="$PCILIB_PATH" $PCILIB_PATH/pci $*
+ PCILIB_PATH=`pwd`/../..
+ LD_LIBRARY_PATH="$PCILIB_PATH/pcilib" $PCILIB_PATH/pcitool/pci $*
}
diff --git a/tests/xilinxdma/xilinx_dma_static_mem.sh b/tests/xilinxdma/xilinx_dma_static_mem.sh
index e3ba0f5..23ee5c9 100755
--- a/tests/xilinxdma/xilinx_dma_static_mem.sh
+++ b/tests/xilinxdma/xilinx_dma_static_mem.sh
@@ -8,7 +8,7 @@ BUFFER_SIZE=8
function pci {
PCILIB_PATH=`pwd`/..
- LD_LIBRARY_PATH="$PCILIB_PATH" $PCILIB_PATH/pci $*
+ LD_LIBRARY_PATH="$PCILIB_PATH/pcilib" $PCILIB_PATH/pcitool/pci $*
}