summaryrefslogtreecommitdiffstats
path: root/pcilib
diff options
context:
space:
mode:
authorSuren A. Chilingaryan <csa@suren.me>2015-09-24 04:28:45 +0200
committerSuren A. Chilingaryan <csa@suren.me>2015-09-24 04:28:45 +0200
commit08a01723af9cd52c078d5ca6c38c34d375b39fa0 (patch)
tree6eadea9c67f4bb56a9e4ee09f4982efaf61deece /pcilib
parent924adedb2928f5657c6668f606dbb3294b3c45da (diff)
parentae7f83a7948d8c3760f8019899a45e6ec90c2c6a (diff)
downloadpcitool-08a01723af9cd52c078d5ca6c38c34d375b39fa0.tar.gz
pcitool-08a01723af9cd52c078d5ca6c38c34d375b39fa0.tar.bz2
pcitool-08a01723af9cd52c078d5ca6c38c34d375b39fa0.tar.xz
pcitool-08a01723af9cd52c078d5ca6c38c34d375b39fa0.zip
Finalyze XML support and provide initial support for views (only descriptions so far)
Diffstat (limited to 'pcilib')
-rw-r--r--pcilib/CMakeLists.txt12
-rw-r--r--pcilib/lock.c32
-rw-r--r--pcilib/lock.h79
-rw-r--r--pcilib/locking.c28
-rw-r--r--pcilib/locking.h58
-rw-r--r--pcilib/model.h3
-rw-r--r--pcilib/pci.c45
-rw-r--r--pcilib/pci.h31
-rw-r--r--pcilib/pcilib.h11
-rw-r--r--pcilib/register.h16
-rw-r--r--pcilib/unit.c49
-rw-r--r--pcilib/unit.h36
-rw-r--r--pcilib/view.c74
-rw-r--r--pcilib/view.h40
-rw-r--r--pcilib/xml.c885
15 files changed, 1064 insertions, 335 deletions
diff --git a/pcilib/CMakeLists.txt b/pcilib/CMakeLists.txt
index 8b11d60..beaa253 100644
--- a/pcilib/CMakeLists.txt
+++ b/pcilib/CMakeLists.txt
@@ -4,12 +4,14 @@ include_directories(
${CMAKE_SOURCE_DIR}/pcilib
${CMAKE_BINARY_DIR}/pcilib
${LIBXML2_INCLUDE_DIRS}
+ ${PYTHON_INCLUDE_DIRS}
+ ${UTHASH_INCLUDE_DIRS}
)
-set(HEADERS pcilib.h pci.h export.h bar.h fifo.h model.h bank.h register.h xml.h kmem.h irq.h locking.h lock.h dma.h event.h plugin.h tools.h error.h debug.h env.h version.h config.h)
-add_library(pcilib SHARED pci.c export.c bar.c fifo.c model.c bank.c register.c xml.c kmem.c irq.c locking.c lock.c dma.c event.c plugin.c tools.c error.c debug.c env.c )
-target_link_libraries(pcilib dma protocols ${CMAKE_THREAD_LIBS_INIT} ${UFODECODE_LIBRARIES} ${CMAKE_DL_LIBS} ${EXTRA_SYSTEM_LIBS} ${LIBXML2_LIBRARIES})
-add_dependencies(pcilib dma protocols)
+set(HEADERS pcilib.h pci.h export.h bar.h fifo.h model.h bank.h register.h view.h unit.h xml.h kmem.h irq.h locking.h lock.h dma.h event.h plugin.h tools.h error.h debug.h env.h version.h config.h)
+add_library(pcilib SHARED pci.c export.c bar.c fifo.c model.c bank.c register.c view.c unit.c xml.c kmem.c irq.c locking.c lock.c dma.c event.c plugin.c tools.c error.c debug.c env.c )
+target_link_libraries(pcilib dma protocols views ${CMAKE_THREAD_LIBS_INIT} ${UFODECODE_LIBRARIES} ${CMAKE_DL_LIBS} ${EXTRA_SYSTEM_LIBS} ${LIBXML2_LIBRARIES} ${PYTHON_LIBRARIES})
+add_dependencies(pcilib dma protocols views)
install(TARGETS pcilib
LIBRARY DESTINATION lib${LIB_SUFFIX}
@@ -19,6 +21,6 @@ install(FILES pcilib.h
DESTINATION include
)
-install(FILES bar.h kmem.h locking.h lock.h bank.h register.h xml.h dma.h event.h model.h error.h debug.h env.h tools.h export.h version.h
+install(FILES bar.h kmem.h locking.h lock.h bank.h register.h xml.h dma.h event.h model.h error.h debug.h env.h tools.h export.h version.h view.h unit.h
DESTINATION include/pcilib
)
diff --git a/pcilib/lock.c b/pcilib/lock.c
index 03a2377..9e7cda2 100644
--- a/pcilib/lock.c
+++ b/pcilib/lock.c
@@ -18,22 +18,21 @@
#include "lock.h"
#include "pci.h"
-
+/**
+ * structure to define a lock
+ */
struct pcilib_lock_s {
- pthread_mutex_t mutex;
- pcilib_lock_flags_t flags;
+ pthread_mutex_t mutex; /**< the pthread robust mutex */
+ pcilib_lock_flags_t flags; /**< flags to define the type of the mutex */
#ifdef HAVE_STDATOMIC_H
- volatile atomic_uint refs;
+ volatile atomic_uint refs; /**< approximate number of processes that hold the lock initialized, may desynchronize on crashes */
#else /* HAVE_STDATOMIC_H */
- volatile uint32_t refs;
+ volatile uint32_t refs; /**< approximate number of processes that hold the lock initialized, may desynchronize on crashes */
#endif /* HAVE_STDATOMIC_H */
- char name[];
+ char name[]; /**< lock identifier */
};
-/**
- * this function initialize a new semaphore in the kernel if it's not already initialized given the key that permits to differentiate semaphores, and then return the integer that points to the semaphore that have been initialized or to a previously already initialized semaphore
- */
int pcilib_init_lock(pcilib_lock_t *lock, pcilib_lock_flags_t flags, const char *lock_id) {
int err;
pthread_mutexattr_t attr;
@@ -53,11 +52,13 @@ int pcilib_init_lock(pcilib_lock_t *lock, pcilib_lock_flags_t flags, const char
return PCILIB_ERROR_FAILED;
}
+ /* we declare the mutex as possibly shared amongst different processes*/
if ((err = pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED))!=0) {
pcilib_error("Can't configure a shared mutex attribute, errno %i", errno);
return PCILIB_ERROR_FAILED;
}
+ /* we set the mutex as robust, so it would be automatically unlocked if the application crash*/
if ((flags&PCILIB_LOCK_FLAG_PERSISTENT)==0) {
if ((err = pthread_mutexattr_setrobust(&attr, PTHREAD_MUTEX_ROBUST))!=0) {
pcilib_error("Can't configure a robust mutex attribute, errno: %i", errno);
@@ -78,9 +79,6 @@ int pcilib_init_lock(pcilib_lock_t *lock, pcilib_lock_flags_t flags, const char
}
-/*
- * we uninitialize a mutex and set its name to 0 pointed by lock_ctx with this function. setting name to is the real destroying operation, but we need to unitialize the lock to initialize it again after
- */
void pcilib_free_lock(pcilib_lock_t *lock) {
int err;
@@ -134,9 +132,6 @@ const char *pcilib_lock_get_name(pcilib_lock_t *lock) {
return NULL;
}
-/*
- * this function will take the lock for the semaphore pointed by semId
- */
int pcilib_lock_custom(pcilib_lock_t *lock, pcilib_lock_flags_t flags, pcilib_timeout_t timeout) {
int err;
@@ -149,12 +144,15 @@ int pcilib_lock_custom(pcilib_lock_t *lock, pcilib_lock_flags_t flags, pcilib_ti
switch (timeout) {
case PCILIB_TIMEOUT_INFINITE:
+ /* the process will be hold till it can gain acquire the lock*/
err = pthread_mutex_lock(&lock->mutex);
break;
case PCILIB_TIMEOUT_IMMEDIATE:
+ /* the function returns immediatly if it can't acquire the lock*/
err = pthread_mutex_trylock(&lock->mutex);
break;
default:
+ /* the process will be hold till it can acquire the lock and timeout is not reached*/
clock_gettime(CLOCK_REALTIME, &tm);
tm.tv_nsec += 1000 * (timeout%1000000);
if (tm.tv_nsec < 1000000000)
@@ -171,6 +169,7 @@ int pcilib_lock_custom(pcilib_lock_t *lock, pcilib_lock_flags_t flags, pcilib_ti
switch (err) {
case EOWNERDEAD:
+ /*in the case an application with a lock acquired crashes, this lock becomes inconsistent. we have so to make it consistent again to use it again.*/
err = pthread_mutex_consistent(&lock->mutex);
if (err) {
pcilib_error("Failed to mark mutex as consistent, errno %i", err);
@@ -195,9 +194,6 @@ int pcilib_try_lock(pcilib_lock_t* lock) {
return pcilib_lock_custom(lock, PCILIB_LOCK_FLAGS_DEFAULT, PCILIB_TIMEOUT_IMMEDIATE);
}
-/**
- * this function will unlock the semaphore pointed by lock_ctx.
- */
void pcilib_unlock(pcilib_lock_t *lock) {
int err;
diff --git a/pcilib/lock.h b/pcilib/lock.h
index 9ffe4cf..e3a5b02 100644
--- a/pcilib/lock.h
+++ b/pcilib/lock.h
@@ -1,29 +1,31 @@
/**
* @file lock.h
- * @skip author zilio nicolas, nicolas.zilio@hotmail.fr
* @brief this file is the header file for the functions that implement a semaphore API for the pcitool program, using pthread robust mutexes.
- * @details the use of pthread robust mutexes was chosen due to the fact we privilege security over fastness, and that pthread mutexes permits to recover semaphores even with crash ,and that it does not require access to resources that can be easily accessible from extern usage as flock file locking mechanism. A possible other locking mechanism could be the sysv semaphores, but we have a problem of how determine a perfect hash for the init function, and more, benchmarks proves that sysv semaphore aren't that stable and that with more than 10 locks/unlocks, pthread is better in performance, so that should suits more to the final pcitool program.
+ * @details the use of pthread robust mutexes was chosen due to the fact we privilege security over fastness, and that pthread mutexes permits to recover semaphores even with crash ,and that it does not require access to resources that can be easily accessible from extern usage as flock file locking mechanism. A possible other locking mechanism could be the sysv semaphores, but we have a problem of how determine a perfect hash for the init function, and more, benchmarks proves that sysv semaphore aren't that stable. For pure locking/unlocking, pthread is better in performance than sysV, but it suffers from big initialization times. In this sense, a kernel memory space is used for saving the locks, and persistence permits to avoid initializations over uses.
+ *
* We considered that mutex implmentation is enough compared to a reader/writer implementation. If it should change, please go to sysv semaphore.
+ *
* Basic explanation on how semaphores here work: a semaphore here is a positive integer, thus that can't go below zero, which is initiated with a value. when a process want access to the critical resource, it asks to decrement the value of the semaphore, and when it has finished, it reincrements it.basically, when the semaphore is equal to zero, any process must have to wait for it to be reincremented before decrementing it again. Here are defined two types of access to the semaphore corresponding to the reader/writer problem : an exclusive lock, which means that no other process than the one who have the resource can access it; a shared lock, which means that other processes who want to access to the resource with a shared lock can have the access, but a concurrent process who want to access the semaphore with an exclusive lock won't be able to.
- * explanation on locks here : here locks are registered in kernel memory, where they are defined by a pthread_mutex_t and a name, which corresponds to a register or processus. The iterations like searching a lock are done on names.
+ * explanation on locks here : here locks are registered in kernel memory, where they are defined by a pthread_mutex_t and an identifier name, which corresponds most of the time to a mix of the register associated name and processus (but it's up to the user). The iterations like searching a lock are done on this id name.
*/
#ifndef _PCILIB_LOCK_H
#define _PCILIB_LOCK_H
-#define PCILIB_LOCK_SIZE 128 /**< size of one lock, determine so the size of the protocol_name in the way locks are registered. 40 bytes are necessary for the mutex structure, so we have a protocol name of length LOCK_SIZE-40*/
+#define PCILIB_LOCK_SIZE 128 /**< size of one lock. indeed, as we can't allocate easily on the fly memory in the kernel, fixed size have been chosen. determines so the size of the identifier name in the way locks are registered. 40 bytes are necessary for the mutex structure, so we have an id name of length LOCK_SIZE-40*/
#include <pcilib.h>
/**
- * type that defines possible flags when locking a lock by calling pcilib_lock
+ * type that defines possible flags for a lock, defining how a lock should be handled by the locking functions
*/
typedef enum {
PCILIB_LOCK_FLAGS_DEFAULT = 0, /**< Default flags */
- PCILIB_LOCK_FLAG_UNLOCKED = 1, /**< Perform operation unlocked (protected by global flock during initialization of locking subsystem) */
+ PCILIB_LOCK_FLAG_UNLOCKED = 1, /**< Perform operations unlocked, thus without taking care of the lock (protected by global flock during initialization of locking subsystem) */
PCILIB_LOCK_FLAG_PERSISTENT = 2 /**< Do not create robust mutexes, but preserve the lock across application launches */
} pcilib_lock_flags_t;
+/** structure defining a lock*/
typedef struct pcilib_lock_s pcilib_lock_t;
@@ -32,70 +34,87 @@ extern "C" {
#endif
/**
- * this function initialize a new semaphore in the kernel given a name that corresponds to a specific processus if the semaphore is not already initialized given the name that permits to differentiate semaphores, and then return the integer that points to the semaphore that have been initialized or to a previously already initialized semaphore.
- * @param[in] lock - pointer to lock to initialize
- * @param[in] flags - flags
+ *this function initializes a lock, by setting correctly its property given the flags associated.
+ * @param[in,out] lock - pointer to lock to initialize
+ * @param[in] flags - flags: if it's set to two, then not a robust mutex is created
* @param[in] lock_id - lock identificator
* @return error code or 0 on success
*/
int pcilib_init_lock(pcilib_lock_t *lock, pcilib_lock_flags_t flags, const char *lock_id);
/**
- * this function uninitialize a lock in kernel memory and set the corresponding name to 0
- * @param[in] lock_ctx the pointer that points to the lock.
+ * this function will unref the defined lock. Any subsequent tries to lock it without reinitializaing it will fail.
+ * @param[in,out] lock_ctx - the pointer that points to the lock.
*/
void pcilib_free_lock(pcilib_lock_t *lock_ctx);
-
+/**
+ * this function gives the identifier name associated to a lock in the kernel space
+ * @param[in] loc - pointer to the lock we want the name
+ * @return string corresponding to the name
+ */
const char *pcilib_lock_get_name(pcilib_lock_t *lock);
/**
- * Increment reference count. Not thread/process safe unless system supports stdatomic (gcc 4.9+).
- * In this case, the access should be synchronized by the caller
- * @param[in] lock - pointer to initialized lock
+ * Increment reference count(number of processes that may access the given lock).
+ * Not thread/process safe unless system supports stdatomic (gcc 4.9+). In this case, the access should be synchronized by the caller.
+ * @param[in,out] lock - pointer to initialized lock
*/
void pcilib_lock_ref(pcilib_lock_t *lock);
/**
- * Decrement reference count. Not thread/process safe unless system supports stdatomic (gcc 4.9+).
- * In this case, the access should be synchronized by the caller
- * @param[in] lock - pointer to initialized lock
+ * Decrement reference count(number of processes that may access the given lock).
+ * Not thread/process safe unless system supports stdatomic (gcc 4.9+). In this case, the access should be synchronized by the caller
+ * @param[in,out] lock - pointer to initialized lock
*/
void pcilib_lock_unref(pcilib_lock_t *lock);
/**
- * Return _approximate_ number of lock references. The crashed applications will may not unref.
- * @param[in] lock - pointer to initialized lock
+ * Return _approximate_ number of lock references as the crashed applications will may not unref.
+ * @param[in,out] lock - pointer to initialized lock
+ * @return the number of lock refs
*/
size_t pcilib_lock_get_refs(pcilib_lock_t *lock);
+/**
+ * gets the flags associated to the given lock
+ * @param[in] lock - the lock we want to know the flags
+ * @return value of the flag associated
+ */
pcilib_lock_flags_t pcilib_lock_get_flags(pcilib_lock_t *lock);
/**
- * this function will take a lock for the mutex pointed by lock
- * @param[in] lock the pointer to the mutex
- * @param[in] flags define the type of lock wanted
- * @param[in] timeout defines timeout
+ * this function will call different locking functions to acquire the given lock. Given the flags, it is thus possible to:
+ * 1) the process requesting the lock will be held till it can acquire it
+ * 2)the lock is tried to be acquired, if the lock can be acquired then it is, if not, then the function returns immediatly and the lock is not taken at all
+ * 3) same than previous, but it's possible to define a waiting time to acquire the lock before returning
+ *
+ * @param[in] lock - the pointer to the mutex
+ * @param[in] flags - define the type of lock wanted
+ * @param[in] timeout - the waiting time if asked, before the function returns without having obtained the lock, in micro seconds
+ * @return error code or 0 for correctness
*/
int pcilib_lock_custom(pcilib_lock_t* lock, pcilib_lock_flags_t flags, pcilib_timeout_t timeout);
/**
- * this function will take a lock for the mutex pointed by lock
- * @param[in] lock the pointer to the mutex
+ * function to acquire a lock, and wait till the lock can be acquire
+ * @param[in] lock - the pointer to the mutex
+ * @return error code or 0 for correctness
*/
int pcilib_lock(pcilib_lock_t* lock);
/**
- * this function will try to take a lock for the mutex pointed by lock
- * @param[in] lock the pointer to the mutex
+ * this function will try to take a lock for the mutex pointed by lockfunction to acquire a lock, but that returns immediatly if the lock can't be acquired on first try
+ * @param[in] lock - the pointer to the mutex
+ * @return error code or 0 for correctness
*/
int pcilib_try_lock(pcilib_lock_t* lock);
/**
- * this function will unlock the lock pointed by lock
- * @param[in] lock the integer that points to the semaphore
+ * this function unlocks the lock pointed by lock
+ * @param[in] lock - the integer that points to the semaphore
*/
void pcilib_unlock(pcilib_lock_t* lock);
diff --git a/pcilib/locking.c b/pcilib/locking.c
index f384ca4..71f204e 100644
--- a/pcilib/locking.c
+++ b/pcilib/locking.c
@@ -21,10 +21,12 @@ int pcilib_init_locking(pcilib_t* ctx) {
pcilib_kmem_reuse_state_t reused;
assert(PCILIB_LOCK_PAGES * PCILIB_KMEM_PAGE_SIZE >= PCILIB_MAX_LOCKS * PCILIB_LOCK_SIZE);
-
+
+ /*protection against multiple creations of kernel space*/
err = pcilib_lock_global(ctx);
if (err) return err;
+ /* by default, this kernel space is persistent and will be reused, in order to avoid the big initialization times for robust mutexes each time we run pcitool*/
ctx->locks.kmem = pcilib_alloc_kernel_memory(ctx, PCILIB_KMEM_TYPE_PAGE, PCILIB_LOCK_PAGES, PCILIB_KMEM_PAGE_SIZE, 0, PCILIB_KMEM_USE(PCILIB_KMEM_USE_LOCKS,0), PCILIB_KMEM_FLAG_REUSE|PCILIB_KMEM_FLAG_PERSISTENT);
if (!ctx->locks.kmem) {
pcilib_unlock_global(ctx);
@@ -46,6 +48,7 @@ int pcilib_init_locking(pcilib_t* ctx) {
}
}
+ /* the lock that has been used for the creation of kernel space is declared unlocked, has we shouldnot use it anymore*/
ctx->locks.locking = pcilib_get_lock(ctx, PCILIB_LOCK_FLAG_UNLOCKED, "locking");
pcilib_unlock_global(ctx);
@@ -59,7 +62,7 @@ int pcilib_init_locking(pcilib_t* ctx) {
}
/*
- * this functions destroy all locks and then free the kernel memory allocated for them
+ * this function free the kernel memory allocated for them and destroys locks by setting memory to 0
*/
void pcilib_free_locking(pcilib_t *ctx) {
if (ctx->locks.locking)
@@ -75,7 +78,7 @@ void pcilib_free_locking(pcilib_t *ctx) {
int pcilib_lock_global(pcilib_t *ctx) {
int err;
- /* we flock() to make sure to not have two initialization in the same time (possible long time to init) */
+ /* we flock() on the board's device file to make sure to not have two initialization in the same time (possible long time to init) */
if ((err = flock(ctx->handle, LOCK_EX))==-1) {
pcilib_error("Can't get flock on device file");
return PCILIB_ERROR_FAILED;
@@ -105,7 +108,7 @@ pcilib_lock_t *pcilib_get_lock(pcilib_t *ctx, pcilib_lock_flags_t flags, const c
pcilib_lock_t *lock;
char buffer[PCILIB_LOCK_SIZE];
-
+ /* we construct the complete lock_id given the parameters of the function*/
va_list pa;
va_start(pa, lock_id);
ret = vsnprintf(buffer, PCILIB_LOCK_SIZE, lock_id, pa);
@@ -115,7 +118,9 @@ pcilib_lock_t *pcilib_get_lock(pcilib_t *ctx, pcilib_lock_flags_t flags, const c
pcilib_error("Failed to construct the lock id, probably arguments does not match the format string (%s)...", lock_id);
return NULL;
}
-
+
+
+ /* we iterate through locks to see if there is one already with the same name*/
// Would be nice to have hash here
for (i = 0; i < PCILIB_MAX_LOCKS; i++) {
lock = pcilib_get_lock_by_id(ctx, i);
@@ -141,6 +146,7 @@ pcilib_lock_t *pcilib_get_lock(pcilib_t *ctx, pcilib_lock_flags_t flags, const c
}
}
#endif /* ! HAVE_STDATOMIC_H */
+ /* if yes, we increment its ref variable*/
pcilib_lock_ref(lock);
#ifndef HAVE_STDATOMIC_H
if ((flags&PCILIB_LOCK_FLAG_UNLOCKED)==0)
@@ -192,6 +198,7 @@ pcilib_lock_t *pcilib_get_lock(pcilib_t *ctx, pcilib_lock_flags_t flags, const c
return NULL;
}
+ /* if the lock did not exist before, then we create it*/
err = pcilib_init_lock(lock, flags, buffer);
if (err) {
@@ -229,11 +236,11 @@ void pcilib_return_lock(pcilib_t *ctx, pcilib_lock_flags_t flags, pcilib_lock_t
}
-/**
- * Destroy all existing locks. This is unsafe call as this and other running applications
- * will still have all initialized lock pointers. It is user responsibility to issue this
- * command when no other application is running.
- */
+/*
+ * Destroy all existing locks. This is unsafe call as this and other running applications
+ * will still have all initialized lock pointers. It is user responsibility to issue this
+ * command when no other application is running.
+ */
int pcilib_destroy_all_locks(pcilib_t *ctx, int force) {
int err;
pcilib_lock_id_t i;
@@ -269,6 +276,7 @@ int pcilib_destroy_all_locks(pcilib_t *ctx, int force) {
return 0;
}
+ /* if we run in non-forced case, then if it may be still processes that can have access to the locks, they are not destroyed*/
if (!force) {
for (i = 0; i < PCILIB_MAX_LOCKS; i++) {
pcilib_lock_t *lock = pcilib_get_lock_by_id(ctx, i);
diff --git a/pcilib/locking.h b/pcilib/locking.h
index ccacd63..5e4c6e9 100644
--- a/pcilib/locking.h
+++ b/pcilib/locking.h
@@ -1,5 +1,5 @@
/**
- * @file lock_global.h
+ * @file locking.h
* @brief this file is the header file for functions that touch all locks allocated for software registers.
* @details for more details about implementation choice, please read the file lock.h
*/
@@ -14,30 +14,78 @@
#include <pcilib/kmem.h>
#include <pcilib/lock.h>
-typedef uint32_t pcilib_lock_id_t;
+typedef uint32_t pcilib_lock_id_t; /**< type to represent the index of a lock in the table of locks in the kernel space*/
typedef struct pcilib_locking_s pcilib_locking_t;
+
+/**
+ * structure defining the kernel space used for locks
+ */
struct pcilib_locking_s {
- pcilib_kmem_handle_t *kmem; /**< kmem used to store mutexes */
- pcilib_lock_t *locking; /**< lock used while intializing other locks */
-// pcilib_lock_t *mmap; /**< lock used to protect mmap operation */
+ pcilib_kmem_handle_t *kmem; /**< kmem used to store mutexes */
+ pcilib_lock_t *locking; /**< lock used while intializing kernel space */
+// pcilib_lock_t *mmap; /**< lock used to protect mmap operation */
};
#ifdef __cplusplus
extern "C" {
#endif
+/**
+ *this function gets the kernel space for the locks : if this space have been already initialized, then the previous space is returned. If not, the space is created. this function has to be protected, in order to avoid the simultaneous creation of 2 kernel spaces. For that, we use pcilib_lock_global.
+ *@param[in,out] ctx - the pcilib_t structure running, getting filled with a ref to locks' kernel space
+ */
int pcilib_init_locking(pcilib_t *ctx);
+
+/**
+ *this function cleans the memory from all locks : the kernel space is freed, and locks references in pcilib_t are destroyed by setting memory to 0
+ *@param[in,out] ctx - the pcilib_t structure running
+ */
void pcilib_free_locking(pcilib_t *ctx);
+/**
+ * this function use flock locking mechanism on the ALPS platform device file, to make sure to not create two kernel spaces for locks
+ *@param[in,out] ctx - the pcilib_t structure running
+ */
int pcilib_lock_global(pcilib_t *ctx);
+
+/**
+ *function to remove the lock created by flock on the ALPS platform device file
+ *@param[in,out] ctx - the pcilib_t structure running
+ */
void pcilib_unlock_global(pcilib_t *ctx);
+/**
+ * this function returns the lock at the index in the kernel space equal to id
+ *@param[in] ctx - the pcilib_t structure running
+ *@param[in] id - the index of the lock
+ *@return the lock structure corresponding
+ */
pcilib_lock_t *pcilib_get_lock_by_id(pcilib_t *ctx, pcilib_lock_id_t id);
+/**
+ *this function verify if the lock requested exists in the kernel space. If yes, then nothing is done, else we create the lock in the kernel space. This function also gives the number of processes that may request the lock afterwards, including the one that just created it.
+ *@param[in] ctx - the pcilib_t structure running
+ *@param[in] flags - the flag defining the property of the lock
+ *@param[in@ lock_id - the identifier name for the lock
+ *@return the corresponding lock, or a new one if it did not exist before
+ */
pcilib_lock_t *pcilib_get_lock(pcilib_t *ctx, pcilib_lock_flags_t flags, const char *lock_id, ...);
+
+/**
+ *this function is to decrement the variable in a lock containing the number of processes that may access to this lock(refs)
+ *@param[in] ctx - the pcilib_t structure running
+ *@param[in] flags - the flag defining the property of the lock
+ *@param[in] lock - pointer to the lock we want to modify
+ */
void pcilib_return_lock(pcilib_t *ctx, pcilib_lock_flags_t flags, pcilib_lock_t *lock);
+/**
+ * this function destroy all the locks that have been created(unref the locks + set memory to 0), and so is used when we want to clean properly the kernel space. If force is set to 1, then we don't care about other processes that may request locks. If not, if there is locks that may be requested by other processes, then the operation is stopped. Of course, destroying locks that may be requested by other processes results in an undefined behaviour. Thus, it is user responsibility to issue this command with force set to 1
+ *@param[in,out] ctx - the pcilib_t structure running
+ *@param[in] force - should the operation be forced or not
+ * @return error code : 0 if everything was ok
+ */
int pcilib_destroy_all_locks(pcilib_t *ctx, int force);
diff --git a/pcilib/model.h b/pcilib/model.h
index 660c363..acb2217 100644
--- a/pcilib/model.h
+++ b/pcilib/model.h
@@ -6,6 +6,7 @@
#include <pcilib/dma.h>
#include <pcilib/event.h>
#include <pcilib/export.h>
+#include <pcilib/view.h>
typedef struct {
@@ -18,6 +19,8 @@ typedef struct {
const pcilib_register_bank_description_t *banks;
const pcilib_register_protocol_description_t *protocols;
const pcilib_register_range_t *ranges;
+ const pcilib_view_description_t **views;
+ const pcilib_unit_description_t *units;
const pcilib_event_description_t *events;
const pcilib_event_data_type_description_t *data_types;
diff --git a/pcilib/pci.c b/pcilib/pci.c
index b7dcbcd..5c25473 100644
--- a/pcilib/pci.c
+++ b/pcilib/pci.c
@@ -139,16 +139,23 @@ pcilib_t *pcilib_open(const char *device, const char *model) {
}
ctx->alloc_reg = PCILIB_DEFAULT_REGISTER_SPACE;
+ ctx->alloc_views = PCILIB_DEFAULT_VIEW_SPACE;
+ ctx->alloc_units = PCILIB_DEFAULT_UNIT_SPACE;
ctx->registers = (pcilib_register_description_t *)malloc(PCILIB_DEFAULT_REGISTER_SPACE * sizeof(pcilib_register_description_t));
ctx->register_ctx = (pcilib_register_context_t *)malloc(PCILIB_DEFAULT_REGISTER_SPACE * sizeof(pcilib_register_context_t));
+ ctx->views = (pcilib_view_description_t**)malloc(PCILIB_DEFAULT_VIEW_SPACE * sizeof(pcilib_view_description_t*));
+ ctx->units = (pcilib_unit_description_t*)malloc(PCILIB_DEFAULT_UNIT_SPACE * sizeof(pcilib_unit_description_t));
- if ((!ctx->registers)||(!ctx->register_ctx)) {
+ if ((!ctx->registers)||(!ctx->register_ctx)||(!ctx->views)||(!ctx->units)) {
pcilib_error("Error allocating memory for register model");
pcilib_close(ctx);
return NULL;
}
+
memset(ctx->registers, 0, sizeof(pcilib_register_description_t));
+ memset(ctx->units, 0, sizeof(pcilib_unit_t));
+ memset(ctx->views, 0, sizeof(pcilib_view_t));
memset(ctx->banks, 0, sizeof(pcilib_register_bank_description_t));
memset(ctx->ranges, 0, sizeof(pcilib_register_range_t));
@@ -191,6 +198,8 @@ pcilib_t *pcilib_open(const char *device, const char *model) {
ctx->model_info.banks = ctx->banks;
ctx->model_info.protocols = ctx->protocols;
ctx->model_info.ranges = ctx->ranges;
+ ctx->model_info.views = (const pcilib_view_description_t**)ctx->views;
+ ctx->model_info.units = ctx->units;
err = pcilib_init_register_banks(ctx);
if (err) {
@@ -350,7 +359,8 @@ char *pcilib_resolve_data_space(pcilib_t *ctx, uintptr_t addr, size_t *size) {
void pcilib_close(pcilib_t *ctx) {
- pcilib_bar_t i;
+ int i;
+ pcilib_bar_t bar;
if (ctx) {
pcilib_dma_engine_t dma;
@@ -370,10 +380,14 @@ void pcilib_close(pcilib_t *ctx) {
pcilib_free_register_banks(ctx);
- pcilib_free_xml(ctx);
-
- if (ctx->register_ctx)
+ if (ctx->register_ctx) {
+ pcilib_register_t reg;
+ for (reg = 0; reg < ctx->num_reg; reg++) {
+ if (ctx->register_ctx[reg].views)
+ free(ctx->register_ctx[reg].views);
+ }
free(ctx->register_ctx);
+ }
if (ctx->event_plugin)
pcilib_plugin_close(ctx->event_plugin);
@@ -389,23 +403,34 @@ void pcilib_close(pcilib_t *ctx) {
}
}
- for (i = 0; i < PCILIB_MAX_BARS; i++) {
- if (ctx->bar_space[i]) {
- char *ptr = ctx->bar_space[i];
- ctx->bar_space[i] = NULL;
- pcilib_unmap_bar(ctx, i, ptr);
+ for (bar = 0; bar < PCILIB_MAX_BARS; bar++) {
+ if (ctx->bar_space[bar]) {
+ char *ptr = ctx->bar_space[bar];
+ ctx->bar_space[bar] = NULL;
+ pcilib_unmap_bar(ctx, bar, ptr);
}
}
if (ctx->pci_cfg_space_fd >= 0)
close(ctx->pci_cfg_space_fd);
+ if (ctx->units);
+ free(ctx->units);
+
+ if (ctx->views) {
+ for (i = 0; ctx->views[i]; i++)
+ free(ctx->views[i]);
+ free(ctx->views);
+ }
+
if (ctx->registers)
free(ctx->registers);
if (ctx->model)
free(ctx->model);
+ pcilib_free_xml(ctx);
+
if (ctx->handle >= 0)
close(ctx->handle);
diff --git a/pcilib/pci.h b/pcilib/pci.h
index 00528e1..ab80101 100644
--- a/pcilib/pci.h
+++ b/pcilib/pci.h
@@ -8,11 +8,15 @@
#define PCILIB_DMA_SKIP_TIMEOUT 1000000 /**< us */
#define PCILIB_MAX_BARS 6 /**< this is defined by PCI specification */
#define PCILIB_DEFAULT_REGISTER_SPACE 1024 /**< number of registers to allocate on init */
+#define PCILIB_DEFAULT_VIEW_SPACE 128 /**< number of views to allocate on init */
+#define PCILIB_DEFAULT_UNIT_SPACE 128 /**< number of units to allocate on init */
#define PCILIB_MAX_REGISTER_BANKS 32 /**< maximum number of register banks to allocate space for */
#define PCILIB_MAX_REGISTER_RANGES 32 /**< maximum number of register ranges to allocate space for */
#define PCILIB_MAX_REGISTER_PROTOCOLS 32 /**< maximum number of register protocols to support */
#define PCILIB_MAX_DMA_ENGINES 32 /**< maximum number of supported DMA engines */
+#include <uthash.h>
+
#include "linux-3.10.h"
#include "driver/pciDriver.h"
@@ -26,6 +30,7 @@
#include "export.h"
#include "locking.h"
#include "xml.h"
+#include "view.h"
typedef struct {
uint8_t max_link_speed, link_speed;
@@ -33,6 +38,26 @@ typedef struct {
uint8_t max_payload, payload;
} pcilib_pcie_link_info_t;
+struct pcilib_view_context_s {
+ UT_hash_handle hh;
+ pcilib_view_t view;
+ pcilib_view_api_description_t *api;
+ pcilib_view_description_t desc; /**< We will allocate more memory and store actual description instance here, so it should be the last member */
+};
+
+struct pcilib_unit_context_s {
+ UT_hash_handle hh;
+ pcilib_unit_t unit;
+ pcilib_unit_description_t desc;
+};
+
+typedef struct {
+ pcilib_register_bank_t bank; /**< Reference to bank containing the register */
+ pcilib_register_value_t min, max; /**< Minimum & maximum allowed values */
+ pcilib_xml_node_t *xml; /**< Additional XML properties */
+ pcilib_view_reference_t *views; /**< For non-static list of views, this vairables holds a copy of a NULL-terminated list from model (if present, memory should be de-allocated) */
+} pcilib_register_context_t;
+
struct pcilib_s {
int handle; /**< file handle of device */
@@ -62,7 +87,6 @@ struct pcilib_s {
size_t num_banks, num_protocols, num_ranges; /**< Number of registered banks, protocols, and register ranges */
size_t num_engines; /**< Number of configured DMA engines */
size_t dyn_banks; /**< Number of configured dynamic banks */
-
pcilib_register_description_t *registers; /**< List of currently defined registers (from all sources) */
pcilib_register_bank_description_t banks[PCILIB_MAX_REGISTER_BANKS + 1]; /**< List of currently defined register banks (from all sources) */
pcilib_register_range_t ranges[PCILIB_MAX_REGISTER_RANGES + 1]; /**< List of currently defined register ranges (from all sources) */
@@ -75,6 +99,11 @@ struct pcilib_s {
pcilib_dma_context_t *dma_ctx; /**< DMA context */
pcilib_context_t *event_ctx; /**< Implmentation context */
+ size_t num_views, alloc_views; /**< Number of configured and allocated views*/
+ size_t num_units, alloc_units; /**< Number of configured and allocated units*/
+ pcilib_view_description_t **views; /**< list of currently defined views */
+ pcilib_unit_description_t *units; /**< list of currently defined units */
+
pcilib_lock_t *dma_rlock[PCILIB_MAX_DMA_ENGINES]; /**< Per-engine locks to serialize streaming and read operations */
pcilib_lock_t *dma_wlock[PCILIB_MAX_DMA_ENGINES]; /**< Per-engine locks to serialize write operations */
diff --git a/pcilib/pcilib.h b/pcilib/pcilib.h
index 6bb018d..8e55d00 100644
--- a/pcilib/pcilib.h
+++ b/pcilib/pcilib.h
@@ -13,6 +13,8 @@ typedef uint32_t pcilib_version_t;
typedef uint8_t pcilib_bar_t; /**< Type holding the PCI Bar number */
typedef uint16_t pcilib_register_t; /**< Type holding the register position within the field listing registers in the model */
+typedef uint16_t pcilib_view_t; /**< Type holding the register view position within view listing in the model */
+typedef uint16_t pcilib_unit_t; /**< Type holding the value unit position within unit listing in the model */
typedef uint32_t pcilib_register_addr_t; /**< Type holding the register address within address-space of BARs */
typedef uint8_t pcilib_register_size_t; /**< Type holding the size in bits of the register */
typedef uint32_t pcilib_register_value_t; /**< Type holding the register value */
@@ -39,6 +41,12 @@ typedef enum {
} pcilib_endianess_t;
typedef enum {
+ PCILIB_TYPE_STRING = 0, /**< char* */
+ PCILIB_TYPE_DOUBLE = 1, /**< double */
+ PCILIB_TYPE_LONG = 2
+} pcilib_data_type_t;
+
+typedef enum {
PCILIB_DMA_IRQ = 1,
PCILIB_EVENT_IRQ = 2
} pcilib_irq_type_t;
@@ -192,6 +200,9 @@ int pcilib_write_register_by_id(pcilib_t *ctx, pcilib_register_t reg, pcilib_reg
int pcilib_read_register(pcilib_t *ctx, const char *bank, const char *regname, pcilib_register_value_t *value);
int pcilib_write_register(pcilib_t *ctx, const char *bank, const char *regname, pcilib_register_value_t value);
+int pcilib_read_register_view(pcilib_t *ctx, const char *bank, const char *regname, const char *unit, pcilib_data_type_t value_type, size_t value_size, void *value);
+int pcilib_write_register_view(pcilib_t *ctx, const char *bank, const char *regname, const char *unit, pcilib_data_type_t value_type, size_t value_size, void *value);
+
int pcilib_reset(pcilib_t *ctx);
int pcilib_trigger(pcilib_t *ctx, pcilib_event_t event, size_t trigger_size, void *trigger_data);
diff --git a/pcilib/register.h b/pcilib/register.h
index e7cbae9..74eeb12 100644
--- a/pcilib/register.h
+++ b/pcilib/register.h
@@ -24,6 +24,11 @@ typedef enum {
} pcilib_register_type_t;
typedef struct {
+ const char *name;
+ const char *view;
+} pcilib_view_reference_t;
+
+typedef struct {
pcilib_register_addr_t addr; /**< Register address in the bank */
pcilib_register_size_t offset; /**< Register offset in the byte (in bits) */
pcilib_register_size_t bits; /**< Register size in bits */
@@ -37,17 +42,12 @@ typedef struct {
are on in the value are cleared/inverted). For information only, no preprocessing on bits is performed. */
pcilib_register_type_t type; /**< Defines type of register is it standard register, subregister for bit fields or view, fifo */
pcilib_register_bank_addr_t bank; /**< Specified the address of the bank this register belongs to */
-
+
const char *name; /**< The access name of the register */
const char *description; /**< Brief description of the register */
-} pcilib_register_description_t;
-
-typedef struct {
- pcilib_register_bank_t bank; /**< Reference to bank containing the register */
- pcilib_register_value_t min, max; /**< Minimum & maximum allowed values */
- pcilib_xml_node_t *xml; /**< Additional XML properties */
-} pcilib_register_context_t;
+ pcilib_view_reference_t *views; /**< List of supported views for this register */
+} pcilib_register_description_t;
#ifdef __cplusplus
diff --git a/pcilib/unit.c b/pcilib/unit.c
new file mode 100644
index 0000000..2dd7113
--- /dev/null
+++ b/pcilib/unit.c
@@ -0,0 +1,49 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+
+#include "pci.h"
+#include "pcilib.h"
+#include "unit.h"
+#include "error.h"
+
+
+pcilib_unit_t pcilib_find_unit_by_name(pcilib_t *ctx, const char *unit) {
+ pcilib_unit_t i;
+
+ for(i = 0; ctx->units[i].name; i++) {
+ if (!strcasecmp(ctx->units[i].name, unit))
+ return i;
+ }
+ return PCILIB_UNIT_INVALID;
+}
+
+
+int pcilib_add_units(pcilib_t *ctx, size_t n, const pcilib_unit_description_t *desc) {
+ if (!n) {
+ for (n = 0; desc[n].name; n++);
+ }
+
+ if ((ctx->num_units + n + 1) > ctx->alloc_units) {
+ size_t size;
+ pcilib_unit_description_t *units;
+
+ for (size = ctx->alloc_units; size < 2 * (n + ctx->num_units + 1); size <<= 1);
+
+ units = (pcilib_unit_description_t*)realloc(ctx->units, size * sizeof(pcilib_unit_description_t));
+ if (!units) return PCILIB_ERROR_MEMORY;
+
+ ctx->units = units;
+ ctx->alloc_units = size;
+
+ ctx->model_info.units = units;
+ }
+
+ memcpy(ctx->units + ctx->num_units, desc, n * sizeof(pcilib_unit_description_t));
+ memset(ctx->units + ctx->num_units + n, 0, sizeof(pcilib_unit_description_t));
+
+ ctx->num_units += n;
+
+ return 0;
+}
diff --git a/pcilib/unit.h b/pcilib/unit.h
new file mode 100644
index 0000000..9c62ff3
--- /dev/null
+++ b/pcilib/unit.h
@@ -0,0 +1,36 @@
+#ifndef _PCILIB_UNIT_H
+#define _PCILIB_UNIT_H
+
+#include <pcilib.h>
+
+#define PCILIB_UNIT_INVALID ((pcilib_unit_t)-1)
+#define PCILIB_MAX_TRANSFORMS_PER_UNIT 16 /**< Limits number of supported transforms per unit */
+
+typedef struct pcilib_unit_context_s *pcilib_unit_context_t;
+
+/**
+ * unit transformation routines
+ */
+typedef struct {
+ char *unit; /**< Name of the resulting unit */
+ char *transform; /**< String, similar to view formula, explaining transform to this unit */
+} pcilib_unit_transform_t;
+
+typedef struct {
+ char *name; /**< Unit name */
+ pcilib_unit_transform_t transforms[PCILIB_MAX_TRANSFORMS_PER_UNIT + 1]; /**< Transforms to other units */
+} pcilib_unit_description_t;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int pcilib_add_units(pcilib_t *ctx, size_t n, const pcilib_unit_description_t *desc);
+pcilib_unit_t pcilib_find_unit_by_name(pcilib_t *ctx, const char *unit);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* _PCILIB_UNIT_H */
diff --git a/pcilib/view.c b/pcilib/view.c
new file mode 100644
index 0000000..1179808
--- /dev/null
+++ b/pcilib/view.c
@@ -0,0 +1,74 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+
+#include "pci.h"
+#include "pcilib.h"
+#include "view.h"
+#include "error.h"
+
+
+pcilib_view_t pcilib_find_view_by_name(pcilib_t *ctx, const char *view) {
+ pcilib_view_t i;
+
+ for(i = 0; ctx->views[i]; i++) {
+ if (!strcasecmp(ctx->views[i]->name, view))
+ return i;
+ }
+
+ return PCILIB_VIEW_INVALID;
+}
+
+
+
+int pcilib_add_views(pcilib_t *ctx, size_t n, const pcilib_view_description_t *desc) {
+ size_t i;
+ void *ptr;
+
+ if (!n) {
+ // No padding between array elements
+ ptr = (void*)desc;
+ while (1) {
+ const pcilib_view_description_t *v = (const pcilib_view_description_t*)ptr;
+ if (v->name) n++;
+ else break;
+ ptr += v->api->description_size;
+ }
+ }
+
+ if ((ctx->num_views + n + 1) > ctx->alloc_views) {
+ size_t size;
+ pcilib_view_description_t **views;
+ for (size = ctx->alloc_views; size < 2 * (n + ctx->num_views + 1); size<<=1);
+
+ views = (pcilib_view_description_t**)realloc(ctx->views, size * sizeof(pcilib_view_description_t*));
+ if (!views) return PCILIB_ERROR_MEMORY;
+
+ ctx->views = views;
+ ctx->alloc_views = size;
+
+ ctx->model_info.views = (const pcilib_view_description_t**)views;
+ }
+
+ // No padding between array elements
+ ptr = (void*)desc;
+ for (i = 0; i < n; i++) {
+ const pcilib_view_description_t *v = (const pcilib_view_description_t*)ptr;
+ ctx->views[ctx->num_views + i] = (pcilib_view_description_t*)malloc(v->api->description_size);
+ if (!ctx->views[ctx->num_views + i]) {
+ size_t j;
+ for (j = 0; j < i; j++)
+ free(ctx->views[ctx->num_views + j]);
+ ctx->views[ctx->num_views] = NULL;
+ pcilib_error("Error allocating %zu bytes of memory for the view description", v->api->description_size);
+ return PCILIB_ERROR_MEMORY;
+ }
+ memcpy(ctx->views[ctx->num_views + i], v, v->api->description_size);
+ ptr += v->api->description_size;
+ }
+ ctx->views[ctx->num_views + i] = NULL;
+ ctx->num_views += n;
+
+ return 0;
+}
diff --git a/pcilib/view.h b/pcilib/view.h
new file mode 100644
index 0000000..7a78a1d
--- /dev/null
+++ b/pcilib/view.h
@@ -0,0 +1,40 @@
+#ifndef _PCILIB_VIEW_H
+#define _PCILIB_VIEW_H
+
+#include <pcilib.h>
+#include <pcilib/unit.h>
+
+#define PCILIB_VIEW_INVALID ((pcilib_view_t)-1)
+
+//typedef void *pcilib_view_context_t;
+typedef struct pcilib_view_context_s *pcilib_view_context_t;
+
+typedef struct {
+ pcilib_version_t version;
+ size_t description_size;
+ pcilib_view_context_t (*init)(pcilib_t *ctx);
+ void (*free)(pcilib_t *ctx, pcilib_view_context_t *view);
+ int (*read_from_reg)(pcilib_t *ctx, pcilib_view_context_t *view, const pcilib_register_value_t *regval, pcilib_data_type_t viewval_type, size_t viewval_size, void *viewval);
+ int (*write_to_reg)(pcilib_t *ctx, pcilib_view_context_t *view, pcilib_register_value_t *regval, pcilib_data_type_t viewval_type, size_t viewval_size, const void *viewval);
+} pcilib_view_api_description_t;
+
+typedef struct {
+ const pcilib_view_api_description_t *api;
+ pcilib_data_type_t type; /**< The default data type returned by operation, PCILIB_VIEW_TYPE_STRING is supported by all operations */
+ const char *unit; /**< Returned unit (if any) */
+ const char *name; /**< Name of the view */
+ const char *description; /**< Short description */
+} pcilib_view_description_t;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int pcilib_add_views(pcilib_t *ctx, size_t n, const pcilib_view_description_t *desc);
+pcilib_view_t pcilib_find_view_by_name(pcilib_t *ctx, const char *view);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* PCILIB_VIEW_H */
diff --git a/pcilib/xml.c b/pcilib/xml.c
index 73a3deb..c431b73 100644
--- a/pcilib/xml.c
+++ b/pcilib/xml.c
@@ -39,14 +39,25 @@
#include "register.h"
#include "xml.h"
#include "error.h"
+#include "view.h"
+#include "views/enum.h"
+#include "views/transform.h"
-#define BANKS_PATH ((xmlChar*)"/model/banks/bank/bank_description") /**< path to complete nodes of banks.*/
-//#define REGISTERS_PATH ((xmlChar*)"/model/banks/bank/registers/register") /**< all standard registers nodes.*/
-//#define BIT_REGISTERS_PATH ((xmlChar*)"/model/banks/bank/registers/register/registers_bits/register_bits") /**< all bits registers nodes.*/
-#define REGISTERS_PATH ((xmlChar*)"../registers/register") /**< all standard registers nodes.*/
-#define BIT_REGISTERS_PATH ((xmlChar*)"./registers_bits/register_bits") /**< all bits registers nodes.*/
-static char *pcilib_xml_bank_default_format = "0x%lx";
+#define BANKS_PATH ((xmlChar*)"/model/bank") /**< path to complete nodes of banks */
+#define REGISTERS_PATH ((xmlChar*)"./register") /**< all standard registers nodes */
+#define BIT_REGISTERS_PATH ((xmlChar*)"./field") /**< all bits registers nodes */
+#define REGISTER_VIEWS_PATH ((xmlChar*)"./view") /**< supported register & field views */
+#define TRANSFORM_VIEWS_PATH ((xmlChar*)"/model/transform") /**< path to complete nodes of views */
+#define ENUM_VIEWS_PATH ((xmlChar*)"/model/enum") /**< path to complete nodes of views */
+#define ENUM_ELEMENTS_PATH ((xmlChar*)"./name") /**< all elements in the enum */
+#define UNITS_PATH ((xmlChar*)"/model/unit") /**< path to complete nodes of units */
+#define UNIT_TRANSFORMS_PATH ((xmlChar*)"./transform") /**< all transforms of the unit */
+
+
+
+static const char *pcilib_xml_bank_default_format = "0x%lx";
+static const char *pcilib_xml_enum_view_unit = "name";
typedef struct {
pcilib_register_description_t base;
@@ -59,7 +70,7 @@ static xmlNodePtr pcilib_xml_get_parent_bank_node(xmlDocPtr doc, xmlNodePtr node
bank_node = node->parent->parent;
// bank_description is always a first node according to the XSD schema
return xmlFirstElementChild(bank_node);
-
+
}
static xmlNodePtr pcilib_xml_get_parent_register_node(xmlDocPtr doc, xmlNodePtr node) {
@@ -67,76 +78,105 @@ static xmlNodePtr pcilib_xml_get_parent_register_node(xmlDocPtr doc, xmlNodePtr
}
*/
-static int pcilib_xml_parse_register(pcilib_t *ctx, pcilib_xml_register_description_t *xml_desc, xmlDocPtr doc, xmlNodePtr node, pcilib_register_bank_description_t *bdesc) {
+static int pcilib_xml_parse_view_reference(pcilib_t *ctx, xmlDocPtr doc, xmlNodePtr node, pcilib_view_reference_t *desc) {
+ xmlAttr *cur;
+ char *value, *name;
+
+ for (cur = node->properties; cur != NULL; cur = cur->next) {
+ if(!cur->children) continue;
+ if(!xmlNodeIsText(cur->children)) continue;
+
+ name = (char*)cur->name;
+ value = (char*)cur->children->content;
+
+ if (!strcasecmp(name, "name")) {
+ desc->name = value;
+ } else if (!strcasecmp(name, "view")) {
+ desc->view = value;
+ }
+ }
+
+ if (!desc->name)
+ desc->name = desc->view;
+
+ return 0;
+}
+
+static int pcilib_xml_parse_register(pcilib_t *ctx, pcilib_xml_register_description_t *xml_desc, xmlXPathContextPtr xpath, xmlDocPtr doc, xmlNodePtr node, pcilib_register_bank_description_t *bdesc) {
+ int err;
pcilib_register_description_t *desc = (pcilib_register_description_t*)xml_desc;
- xmlNodePtr cur;
+ xmlXPathObjectPtr nodes;
+ xmlNodeSetPtr nodeset;
+
+ xmlAttrPtr cur;
char *value, *name;
char *endptr;
- for (cur = node->children; cur != NULL; cur = cur->next) {
- if (!cur->children) continue;
- if (!xmlNodeIsText(cur->children)) continue;
-
- name = (char*)cur->name;
+
+ for (cur = node->properties; cur != NULL; cur = cur->next) {
+ if (!cur->children) continue;
+ if (!xmlNodeIsText(cur->children)) continue;
+
+ name = (char*)cur->name;
value = (char*)cur->children->content;
if (!value) continue;
-
+
if (!strcasecmp((char*)name, "address")) {
- uintptr_t addr = strtol(value, &endptr, 0);
- if ((strlen(endptr) > 0)) {
- pcilib_error("Invalid address (%s) is specified in the XML register description", value);
- return PCILIB_ERROR_INVALID_DATA;
- }
+ uintptr_t addr = strtol(value, &endptr, 0);
+ if ((strlen(endptr) > 0)) {
+ pcilib_error("Invalid address (%s) is specified in the XML register description", value);
+ return PCILIB_ERROR_INVALID_DATA;
+ }
desc->addr = addr;
} else if(!strcasecmp(name, "offset")) {
- int offset = strtol(value, &endptr, 0);
- if ((strlen(endptr) > 0)||(offset < 0)||(offset > (8 * sizeof(pcilib_register_value_t)))) {
- pcilib_error("Invalid offset (%s) is specified in the XML register description", value);
- return PCILIB_ERROR_INVALID_DATA;
- }
+ int offset = strtol(value, &endptr, 0);
+ if ((strlen(endptr) > 0)||(offset < 0)||(offset > (8 * sizeof(pcilib_register_value_t)))) {
+ pcilib_error("Invalid offset (%s) is specified in the XML register description", value);
+ return PCILIB_ERROR_INVALID_DATA;
+ }
desc->offset = (pcilib_register_size_t)offset;
} else if (!strcasecmp(name,"size")) {
- int size = strtol(value, &endptr, 0);
- if ((strlen(endptr) > 0)||(size <= 0)||(size > (8 * sizeof(pcilib_register_value_t)))) {
- pcilib_error("Invalid size (%s) is specified in the XML register description", value);
- return PCILIB_ERROR_INVALID_DATA;
- }
+ int size = strtol(value, &endptr, 0);
+ if ((strlen(endptr) > 0)||(size <= 0)||(size > (8 * sizeof(pcilib_register_value_t)))) {
+ pcilib_error("Invalid size (%s) is specified in the XML register description", value);
+ return PCILIB_ERROR_INVALID_DATA;
+ }
desc->bits = (pcilib_register_size_t)size;
} else if (!strcasecmp(name, "default")) {
- pcilib_register_value_t val = strtol(value, &endptr, 0);
- if ((strlen(endptr) > 0)) {
- pcilib_error("Invalid default value (%s) is specified in the XML register description", value);
- return PCILIB_ERROR_INVALID_DATA;
- }
+ pcilib_register_value_t val = strtol(value, &endptr, 0);
+ if ((strlen(endptr) > 0)) {
+ pcilib_error("Invalid default value (%s) is specified in the XML register description", value);
+ return PCILIB_ERROR_INVALID_DATA;
+ }
desc->defvalue = val;
} else if (!strcasecmp(name,"min")) {
- pcilib_register_value_t min = strtol(value, &endptr, 0);
- if ((strlen(endptr) > 0)) {
- pcilib_error("Invalid minimum value (%s) is specified in the XML register description", value);
- return PCILIB_ERROR_INVALID_DATA;
- }
- xml_desc->min = min;
+ pcilib_register_value_t min = strtol(value, &endptr, 0);
+ if ((strlen(endptr) > 0)) {
+ pcilib_error("Invalid minimum value (%s) is specified in the XML register description", value);
+ return PCILIB_ERROR_INVALID_DATA;
+ }
+ xml_desc->min = min;
} else if (!strcasecmp(name, "max")) {
- pcilib_register_value_t max = strtol(value, &endptr, 0);
- if ((strlen(endptr) > 0)) {
- pcilib_error("Invalid minimum value (%s) is specified in the XML register description", value);
- return PCILIB_ERROR_INVALID_DATA;
- }
- xml_desc->max = max;
+ pcilib_register_value_t max = strtol(value, &endptr, 0);
+ if ((strlen(endptr) > 0)) {
+ pcilib_error("Invalid minimum value (%s) is specified in the XML register description", value);
+ return PCILIB_ERROR_INVALID_DATA;
+ }
+ xml_desc->max = max;
} else if (!strcasecmp((char*)name,"rwmask")) {
if (!strcasecmp(value, "all")) {
desc->rwmask = PCILIB_REGISTER_ALL_BITS;
} else if (!strcasecmp(value, "none")) {
desc->rwmask = 0;
} else {
- uintptr_t mask = strtol(value, &endptr, 0);
- if ((strlen(endptr) > 0)) {
- pcilib_error("Invalid mask (%s) is specified in the XML register description", value);
- return PCILIB_ERROR_INVALID_DATA;
- }
- desc->rwmask = mask;
- }
+ uintptr_t mask = strtol(value, &endptr, 0);
+ if ((strlen(endptr) > 0)) {
+ pcilib_error("Invalid mask (%s) is specified in the XML register description", value);
+ return PCILIB_ERROR_INVALID_DATA;
+ }
+ desc->rwmask = mask;
+ }
} else if (!strcasecmp(name, "mode")) {
if (!strcasecmp(value, "R")) {
desc->mode = PCILIB_REGISTER_R;
@@ -151,15 +191,15 @@ static int pcilib_xml_parse_register(pcilib_t *ctx, pcilib_xml_register_descript
} else if (!strcasecmp(value, "W1C")) {
desc->mode = PCILIB_REGISTER_W1C;
} else {
- pcilib_error("Invalid access mode (%s) is specified in the XML register description", value);
- return PCILIB_ERROR_INVALID_DATA;
+ pcilib_error("Invalid access mode (%s) is specified in the XML register description", value);
+ return PCILIB_ERROR_INVALID_DATA;
}
} else if (!strcasecmp(name, "type")) {
if (!strcasecmp(value, "fifo")) {
desc->type = PCILIB_REGISTER_FIFO;
} else {
- pcilib_error("Invalid register type (%s) is specified in the XML register description", value);
- return PCILIB_ERROR_INVALID_DATA;
+ pcilib_error("Invalid register type (%s) is specified in the XML register description", value);
+ return PCILIB_ERROR_INVALID_DATA;
}
} else if (!strcasecmp(name,"name")) {
desc->name = value;
@@ -168,82 +208,121 @@ static int pcilib_xml_parse_register(pcilib_t *ctx, pcilib_xml_register_descript
}
}
+ xpath->node = node;
+ nodes = xmlXPathEvalExpression(REGISTER_VIEWS_PATH, xpath);
+ xpath->node = NULL;
+
+ if (!nodes) {
+ xmlErrorPtr xmlerr = xmlGetLastError();
+
+ if (xmlerr) pcilib_error("Failed to parse XPath expression %s, xmlXPathEvalExpression reported error %d - %s", REGISTER_VIEWS_PATH, xmlerr->code, xmlerr->message);
+ else pcilib_error("Failed to parse XPath expression %s", REGISTER_VIEWS_PATH);
+ return PCILIB_ERROR_FAILED;
+ }
+
+
+ nodeset = nodes->nodesetval;
+ if (!xmlXPathNodeSetIsEmpty(nodeset)) {
+ int i;
+
+ desc->views = (pcilib_view_reference_t*)malloc((nodeset->nodeNr + 1) * sizeof(pcilib_view_reference_t));
+ if (!desc->views) {
+ xmlXPathFreeObject(nodes);
+ pcilib_error("Failed to allocate %zu bytes of memory to store supported register views", (nodeset->nodeNr + 1) * sizeof(char*));
+ return PCILIB_ERROR_MEMORY;
+ }
+
+ memset(desc->views, 0, (nodeset->nodeNr + 1) * sizeof(pcilib_view_reference_t));
+ for (i = 0; i < nodeset->nodeNr; i++) {
+ err = pcilib_xml_parse_view_reference(ctx, doc, nodeset->nodeTab[i], &desc->views[i]);
+ if (err) {
+ xmlXPathFreeObject(nodes);
+ return err;
+ }
+ }
+ }
+ xmlXPathFreeObject(nodes);
+
return 0;
}
static int pcilib_xml_create_register(pcilib_t *ctx, pcilib_register_bank_t bank, xmlXPathContextPtr xpath, xmlDocPtr doc, xmlNodePtr node) {
int err;
-
xmlXPathObjectPtr nodes;
xmlNodeSetPtr nodeset;
pcilib_xml_register_description_t desc = {{0}};
pcilib_xml_register_description_t fdesc;
-
+
pcilib_register_t reg;
-
+
desc.base.bank = ctx->banks[bank].addr;
desc.base.rwmask = PCILIB_REGISTER_ALL_BITS;
desc.base.mode = PCILIB_REGISTER_R;
desc.base.type = PCILIB_REGISTER_STANDARD;
-
- err = pcilib_xml_parse_register(ctx, &desc, doc, node, &ctx->banks[bank]);
+
+ err = pcilib_xml_parse_register(ctx, &desc, xpath, doc, node, &ctx->banks[bank]);
if (err) {
- pcilib_error("Error (%i) parsing an XML register", err);
- return err;
+ pcilib_error("Error (%i) parsing an XML register", err);
+ return err;
}
-
+
err = pcilib_add_registers(ctx, PCILIB_MODEL_MODIFICATION_FLAG_OVERRIDE, 1, &desc.base, &reg);
if (err) {
- pcilib_error("Error (%i) adding a new XML register (%s) to the model", err, desc.base.name);
- return err;
+ if (desc.base.views) free(desc.base.views);
+ pcilib_error("Error (%i) adding a new XML register (%s) to the model", err, desc.base.name);
+ return err;
}
- ctx->register_ctx[reg].xml = node;
+ ctx->register_ctx[reg].xml = node;
ctx->register_ctx[reg].min = desc.min;
ctx->register_ctx[reg].max = desc.max;
+ ctx->register_ctx[reg].views = desc.base.views;
+
xpath->node = node;
nodes = xmlXPathEvalExpression(BIT_REGISTERS_PATH, xpath);
xpath->node = NULL;
-
+
if (!nodes) {
- xmlErrorPtr xmlerr = xmlGetLastError();
+ xmlErrorPtr xmlerr = xmlGetLastError();
- if (xmlerr) pcilib_error("Failed to parse XPath expression %s, xmlXPathEvalExpression reported error %d - %s", BIT_REGISTERS_PATH, xmlerr->code, xmlerr->message);
- else pcilib_error("Failed to parse XPath expression %s", BIT_REGISTERS_PATH);
- return PCILIB_ERROR_FAILED;
+ if (xmlerr) pcilib_error("Failed to parse XPath expression %s, xmlXPathEvalExpression reported error %d - %s", BIT_REGISTERS_PATH, xmlerr->code, xmlerr->message);
+ else pcilib_error("Failed to parse XPath expression %s", BIT_REGISTERS_PATH);
+ return PCILIB_ERROR_FAILED;
}
nodeset = nodes->nodesetval;
if (!xmlXPathNodeSetIsEmpty(nodeset)) {
- int i;
-
- for (i = 0; i < nodeset->nodeNr; i++) {
- memset(&fdesc, 0, sizeof(pcilib_xml_register_description_t));
-
- fdesc.base.bank = desc.base.bank;
- fdesc.base.addr = desc.base.addr;
- fdesc.base.mode = desc.base.mode;
- fdesc.base.rwmask = desc.base.rwmask;
- fdesc.base.type = PCILIB_REGISTER_BITS;
-
- err = pcilib_xml_parse_register(ctx, &fdesc, doc, nodeset->nodeTab[i], &ctx->banks[bank]);
- if (err) {
- pcilib_error("Error parsing field in the XML register %s", desc.base.name);
- continue;
- }
-
- err = pcilib_add_registers(ctx, PCILIB_MODEL_MODIFICATION_FLAG_OVERRIDE, 1, &fdesc.base, &reg);
- if (err) {
- pcilib_error("Error (%i) adding a new XML register (%s) to the model", err, fdesc.base.name);
- continue;
- }
-
- ctx->register_ctx[reg].xml = nodeset->nodeTab[i];
- ctx->register_ctx[reg].min = fdesc.min;
- ctx->register_ctx[reg].max = fdesc.max;
- }
+ int i;
+
+ for (i = 0; i < nodeset->nodeNr; i++) {
+ memset(&fdesc, 0, sizeof(pcilib_xml_register_description_t));
+
+ fdesc.base.bank = desc.base.bank;
+ fdesc.base.addr = desc.base.addr;
+ fdesc.base.mode = desc.base.mode;
+ fdesc.base.rwmask = desc.base.rwmask;
+ fdesc.base.type = PCILIB_REGISTER_BITS;
+
+ err = pcilib_xml_parse_register(ctx, &fdesc, xpath, doc, nodeset->nodeTab[i], &ctx->banks[bank]);
+ if (err) {
+ pcilib_error("Error parsing field in the XML register %s", desc.base.name);
+ continue;
+ }
+
+ err = pcilib_add_registers(ctx, PCILIB_MODEL_MODIFICATION_FLAG_OVERRIDE, 1, &fdesc.base, &reg);
+ if (err) {
+ if (fdesc.base.views) free(fdesc.base.views);
+ pcilib_error("Error (%i) adding a new XML register (%s) to the model", err, fdesc.base.name);
+ continue;
+ }
+
+ ctx->register_ctx[reg].xml = nodeset->nodeTab[i];
+ ctx->register_ctx[reg].min = fdesc.min;
+ ctx->register_ctx[reg].max = fdesc.max;
+ ctx->register_ctx[reg].views = fdesc.base.views;
+ }
}
xmlXPathFreeObject(nodes);
@@ -252,11 +331,11 @@ static int pcilib_xml_create_register(pcilib_t *ctx, pcilib_register_bank_t bank
static int pcilib_xml_create_bank(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDocPtr doc, xmlNodePtr node) {
int err;
-
+
int override = 0;
pcilib_register_bank_description_t desc = {0};
pcilib_register_bank_t bank;
- xmlNodePtr cur;
+ xmlAttrPtr cur;
char *value, *name;
char *endptr;
@@ -273,70 +352,70 @@ static int pcilib_xml_create_bank(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDo
desc.endianess = PCILIB_HOST_ENDIAN;
desc.raw_endianess = PCILIB_HOST_ENDIAN;
- // iterate through all children, representing bank properties, to fill the structure
- for (cur = node->children; cur != NULL; cur = cur->next) {
- if (!cur->children) continue;
- if (!xmlNodeIsText(cur->children)) continue;
-
- name = (char*)cur->name;
+ // iterate through all children, representing bank properties, to fill the structure
+ for (cur = node->properties; cur != NULL; cur = cur->next) {
+ if (!cur->children) continue;
+ if (!xmlNodeIsText(cur->children)) continue;
+
+ name = (char*)cur->name;
value = (char*)cur->children->content;
if (!value) continue;
-
+
if (!strcasecmp(name, "bar")) {
- char bar = value[0]-'0';
- if ((strlen(value) != 1)||(bar < 0)||(bar > 5)) {
- pcilib_error("Invalid BAR (%s) is specified in the XML bank description", value);
- return PCILIB_ERROR_INVALID_DATA;
- }
+ char bar = value[0]-'0';
+ if ((strlen(value) != 1)||(bar < 0)||(bar > 5)) {
+ pcilib_error("Invalid BAR (%s) is specified in the XML bank description", value);
+ return PCILIB_ERROR_INVALID_DATA;
+ }
desc.bar = (pcilib_bar_t)bar;
override = 1;
} else if (!strcasecmp(name,"size")) {
- long size = strtol(value, &endptr, 0);
- if ((strlen(endptr) > 0)||(size<=0)) {
- pcilib_error("Invalid bank size (%s) is specified in the XML bank description", value);
- return PCILIB_ERROR_INVALID_DATA;
- }
+ long size = strtol(value, &endptr, 0);
+ if ((strlen(endptr) > 0)||(size<=0)) {
+ pcilib_error("Invalid bank size (%s) is specified in the XML bank description", value);
+ return PCILIB_ERROR_INVALID_DATA;
+ }
desc.size = (size_t)size;
override = 1;
} else if (!strcasecmp(name,"protocol")) {
- pcilib_register_protocol_t protocol = pcilib_find_register_protocol_by_name(ctx, value);
- if (protocol == PCILIB_REGISTER_PROTOCOL_INVALID) {
- pcilib_error("Unsupported protocol (%s) is specified in the XML bank description", value);
- return PCILIB_ERROR_NOTSUPPORTED;
- }
- desc.protocol = ctx->protocols[protocol].addr;
+ pcilib_register_protocol_t protocol = pcilib_find_register_protocol_by_name(ctx, value);
+ if (protocol == PCILIB_REGISTER_PROTOCOL_INVALID) {
+ pcilib_error("Unsupported protocol (%s) is specified in the XML bank description", value);
+ return PCILIB_ERROR_NOTSUPPORTED;
+ }
+ desc.protocol = ctx->protocols[protocol].addr;
override = 1;
} else if (!strcasecmp(name,"address")) {
- uintptr_t addr = strtol(value, &endptr, 0);
- if ((strlen(endptr) > 0)) {
- pcilib_error("Invalid address (%s) is specified in the XML bank description", value);
- return PCILIB_ERROR_INVALID_DATA;
- }
+ uintptr_t addr = strtol(value, &endptr, 0);
+ if ((strlen(endptr) > 0)) {
+ pcilib_error("Invalid address (%s) is specified in the XML bank description", value);
+ return PCILIB_ERROR_INVALID_DATA;
+ }
desc.read_addr = addr;
desc.write_addr = addr;
override = 1;
} else if (!strcasecmp(name,"read_address")) {
- uintptr_t addr = strtol(value, &endptr, 0);
- if ((strlen(endptr) > 0)) {
- pcilib_error("Invalid address (%s) is specified in the XML bank description", value);
- return PCILIB_ERROR_INVALID_DATA;
- }
+ uintptr_t addr = strtol(value, &endptr, 0);
+ if ((strlen(endptr) > 0)) {
+ pcilib_error("Invalid address (%s) is specified in the XML bank description", value);
+ return PCILIB_ERROR_INVALID_DATA;
+ }
desc.read_addr = addr;
override = 1;
} else if (!strcasecmp(name,"write_address")) {
- uintptr_t addr = strtol(value, &endptr, 0);
- if ((strlen(endptr) > 0)) {
- pcilib_error("Invalid address (%s) is specified in the XML bank description", value);
- return PCILIB_ERROR_INVALID_DATA;
- }
+ uintptr_t addr = strtol(value, &endptr, 0);
+ if ((strlen(endptr) > 0)) {
+ pcilib_error("Invalid address (%s) is specified in the XML bank description", value);
+ return PCILIB_ERROR_INVALID_DATA;
+ }
desc.write_addr = addr;
override = 1;
} else if(strcasecmp((char*)name,"word_size")==0) {
- int access = strtol(value, &endptr, 0);
- if ((strlen(endptr) > 0)||(access%8)||(access<=0)||(access>(8 * sizeof(pcilib_register_value_t)))) {
- pcilib_error("Invalid word size (%s) is specified in the XML bank description", value);
- return PCILIB_ERROR_INVALID_DATA;
- }
+ int access = strtol(value, &endptr, 0);
+ if ((strlen(endptr) > 0)||(access%8)||(access<=0)||(access>(8 * sizeof(pcilib_register_value_t)))) {
+ pcilib_error("Invalid word size (%s) is specified in the XML bank description", value);
+ return PCILIB_ERROR_INVALID_DATA;
+ }
desc.access = access;
override = 1;
} else if (!strcasecmp(name,"endianess")) {
@@ -344,8 +423,8 @@ static int pcilib_xml_create_bank(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDo
else if (!strcasecmp(value,"big")) desc.endianess = PCILIB_BIG_ENDIAN;
else if (!strcasecmp(value,"host")) desc.endianess = PCILIB_HOST_ENDIAN;
else {
- pcilib_error("Invalid endianess (%s) is specified in the XML bank description", value);
- return PCILIB_ERROR_INVALID_DATA;
+ pcilib_error("Invalid endianess (%s) is specified in the XML bank description", value);
+ return PCILIB_ERROR_INVALID_DATA;
}
override = 1;
} else if (!strcasecmp(name,"format")) {
@@ -357,7 +436,7 @@ static int pcilib_xml_create_bank(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDo
desc.description = value;
override = 1;
} else if (!strcasecmp((char*)name,"override")) {
- override = 1;
+ override = 1;
}
}
@@ -369,31 +448,302 @@ static int pcilib_xml_create_bank(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDo
ctx->xml.bank_nodes[bank] = node;
if (ctx->bank_ctx[bank]) {
- ctx->bank_ctx[bank]->xml = node;
+ ctx->bank_ctx[bank]->xml = node;
}
xpath->node = node;
nodes = xmlXPathEvalExpression(REGISTERS_PATH, xpath);
xpath->node = NULL;
+
+ if (!nodes) {
+ xmlErrorPtr xmlerr = xmlGetLastError();
+ if (xmlerr) pcilib_error("Failed to parse XPath expression %s, xmlXPathEvalExpression reported error %d - %s", REGISTERS_PATH, xmlerr->code, xmlerr->message);
+ else pcilib_error("Failed to parse XPath expression %s", REGISTERS_PATH);
+ return PCILIB_ERROR_FAILED;
+ }
+
+ nodeset = nodes->nodesetval;
+ if (!xmlXPathNodeSetIsEmpty(nodeset)) {
+ int i;
+ for (i = 0; i < nodeset->nodeNr; i++) {
+ err = pcilib_xml_create_register(ctx, bank, xpath, doc, nodeset->nodeTab[i]);
+ if (err) pcilib_error("Error creating XML registers for bank %s", desc.name);
+ }
+ }
+ xmlXPathFreeObject(nodes);
+
+ return 0;
+}
+
+static int pcilib_xml_parse_view(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDocPtr doc, xmlNodePtr node, pcilib_view_description_t *desc) {
+ xmlAttrPtr cur;
+ const char *value, *name;
+
+ desc->type = PCILIB_TYPE_STRING;
+
+ for (cur = node->properties; cur != NULL; cur = cur->next) {
+ if (!cur->children) continue;
+ if (!xmlNodeIsText(cur->children)) continue;
+
+ name = (char*)cur->name;
+ value = (char*)cur->children->content;
+ if (!value) continue;
+
+ if (!strcasecmp(name, "name")) {
+ desc->name = value;
+ } else if (!strcasecmp((char*)name, "description")) {
+ desc->description = value;
+ } else if (!strcasecmp((char*)name, "unit")) {
+ desc->unit = value;
+ } else if (!strcasecmp((char*)name, "type")) {
+ if (!strcasecmp(value, "string")) desc->type = PCILIB_TYPE_STRING;
+ else if (!strcasecmp(value, "float")) desc->type = PCILIB_TYPE_DOUBLE;
+ else if (!strcasecmp(value, "int")) desc->type = PCILIB_TYPE_LONG;
+ else {
+ pcilib_error("Invalid type (%s) of register view is specified in the XML bank description", value);
+ return PCILIB_ERROR_INVALID_DATA;
+ }
+ }
+ }
+
+ return 0;
+}
+
+static int pcilib_xml_create_transform_view(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDocPtr doc, xmlNodePtr node) {
+ int err;
+ xmlAttrPtr cur;
+ const char *value, *name;
+
+ pcilib_transform_view_description_t desc = {0};
+
+ desc.base.api = &pcilib_enum_view_xml_api;
+
+ err = pcilib_xml_parse_view(ctx, xpath, doc, node, (pcilib_view_description_t*)&desc);
+ if (err) return err;
+
+ for (cur = node->properties; cur != NULL; cur = cur->next) {
+ if (!cur->children) continue;
+ if (!xmlNodeIsText(cur->children)) continue;
+
+ name = (char*)cur->name;
+ value = (char*)cur->children->content;
+ if (!value) continue;
+
+ if (!strcasecmp(name, "read_from_register")) {
+ desc.read_from_reg = value;
+ } else if (!strcasecmp(name, "write_to_register")) {
+ desc.write_to_reg = value;
+ }
+ }
+
+
+ return pcilib_add_views(ctx, 1, (pcilib_view_description_t*)&desc);
+}
+
+
+static int pcilib_xml_parse_value_name(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDocPtr doc, xmlNodePtr node, pcilib_value_name_t *desc) {
+ xmlAttr *cur;
+ char *value, *name;
+ char *endptr;
+
+ int min_set = 0, max_set = 0;
+ pcilib_register_value_t val;
+ for (cur = node->properties; cur != NULL; cur = cur->next) {
+ if(!cur->children) continue;
+ if(!xmlNodeIsText(cur->children)) continue;
+
+ name = (char*)cur->name;
+ value = (char*)cur->children->content;
+
+ if (!strcasecmp(name, "name")) {
+ desc->name = value;
+ } else if (!strcasecmp(name, "value")) {
+ val = strtol(value, &endptr, 0);
+ if ((strlen(endptr) > 0)) {
+ pcilib_error("Invalid enum value (%s) is specified in the XML enum node", value);
+ return PCILIB_ERROR_INVALID_DATA;
+ }
+ desc->value = val;
+ } else if (!strcasecmp(name, "min")) {
+ val = strtol(value, &endptr, 0);
+ if ((strlen(endptr) > 0)) {
+ pcilib_error("Invalid enum min-value (%s) is specified in the XML enum node", value);
+ return PCILIB_ERROR_INVALID_DATA;
+ }
+ desc->min = val;
+ min_set = 1;
+ } else if (!strcasecmp(name, "max")) {
+ val = strtol(value, &endptr, 0);
+ if ((strlen(endptr) > 0)) {
+ pcilib_error("Invalid enum max-value (%s) is specified in the XML enum node", value);
+ return PCILIB_ERROR_INVALID_DATA;
+ }
+ desc->max = val;
+ max_set = 1;
+ }
+ }
+
+ if ((!min_set)&&(!max_set)) {
+ desc->min = desc->value;
+ desc->max = desc->value;
+ } else if (max_set) {
+ desc->min = 0;
+ } else if (min_set) {
+ desc->max = (pcilib_register_value_t)-1;
+ }
+
+ if ((desc->min > desc->max)||(desc->value < desc->min)||(desc->value > desc->max)) {
+ pcilib_error("Invalid enum configuration (min: %lu, max: %lu, value: %lu)", desc->min, desc->max, desc->value);
+ return PCILIB_ERROR_INVALID_DATA;
+ }
+
+ return 0;
+}
+
+static int pcilib_xml_create_enum_view(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDocPtr doc, xmlNodePtr node) {
+ int i;
+ int err;
+
+ xmlXPathObjectPtr nodes;
+ xmlNodeSetPtr nodeset;
+
+ pcilib_enum_view_description_t desc = {0};
+
+ desc.base.unit = pcilib_xml_enum_view_unit;
+ desc.base.api = &pcilib_enum_view_xml_api;
+
+ err = pcilib_xml_parse_view(ctx, xpath, doc, node, (pcilib_view_description_t*)&desc);
+ if (err) return err;
+
+
+ xpath->node = node;
+ nodes = xmlXPathEvalExpression(ENUM_ELEMENTS_PATH, xpath);
+ xpath->node = NULL;
+
+ if (!nodes) {
+ xmlErrorPtr xmlerr = xmlGetLastError();
+ if (xmlerr) pcilib_error("Failed to parse XPath expression %s, xmlXPathEvalExpression reported error %d - %s", ENUM_ELEMENTS_PATH, xmlerr->code, xmlerr->message);
+ else pcilib_error("Failed to parse XPath expression %s", ENUM_ELEMENTS_PATH);
+ return PCILIB_ERROR_FAILED;
+ }
+
+ nodeset = nodes->nodesetval;
+ if (xmlXPathNodeSetIsEmpty(nodeset)) {
+ xmlXPathFreeObject(nodes);
+ pcilib_error("No names is defined for enum view (%s)", desc.base.name);
+ return PCILIB_ERROR_INVALID_DATA;
+ }
+
+ desc.names = (pcilib_value_name_t*)malloc((nodeset->nodeNr + 1) * sizeof(pcilib_value_name_t));
+ if (!desc.names) {
+ xmlXPathFreeObject(nodes);
+ pcilib_error("No names is defined for enum view (%s)", desc.base.name);
+ return PCILIB_ERROR_INVALID_DATA;
+ }
+
+
+ for (i = 0; i < nodeset->nodeNr; i++) {
+ err = pcilib_xml_parse_value_name(ctx, xpath, doc, nodeset->nodeTab[i], &desc.names[i]);
+ if (err) {
+ xmlXPathFreeObject(nodes);
+ free(desc.names);
+ return err;
+ }
+ }
+ memset(&desc.names[nodeset->nodeNr], 0, sizeof(pcilib_value_name_t));
+
+ xmlXPathFreeObject(nodes);
+
+
+ err = pcilib_add_views(ctx, 1, (pcilib_view_description_t*)&desc);
+ if (err) free(desc.names);
+ return err;
+}
+
+static int pcilib_xml_parse_unit_transform(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDocPtr doc, xmlNodePtr node, pcilib_unit_transform_t *desc) {
+ xmlAttrPtr cur;
+ char *value, *name;
+
+ for (cur = node->properties; cur != NULL; cur = cur->next) {
+ if (!cur->children) continue;
+ if (!xmlNodeIsText(cur->children)) continue;
+
+ name = (char*)cur->name;
+ value = (char*)cur->children->content;
+
+ if (!strcasecmp(name, "unit")) {
+ desc->unit = value;
+ } else if (!strcasecmp(name, "transform")) {
+ desc->transform = value;
+ }
+ }
+
+ return 0;
+}
+
+/**
+ * function to create a unit from a unit xml node, then populating ctx with it
+ *@param[in,out] ctx - the pcilib_t running
+ *@param[in] xpath - the xpath context of the unis xml file
+ *@param[in] doc - the AST of the unit xml file
+ *@param[in] node - the node representing the unit
+ *@return an error code: 0 if evrythinh is ok
+ */
+static int pcilib_xml_create_unit(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDocPtr doc, xmlNodePtr node) {
+ int err;
+
+ pcilib_unit_description_t desc = {0};
+
+ xmlXPathObjectPtr nodes;
+ xmlNodeSetPtr nodeset;
+
+ xmlAttrPtr cur;
+ char *value, *name;
+
+ for (cur = node->properties; cur != NULL; cur = cur->next) {
+ if (!cur->children) continue;
+ if (!xmlNodeIsText(cur->children)) continue;
+
+ name = (char*)cur->name;
+ value = (char*)cur->children->content;
+ if (!strcasecmp(name, "name")) {
+ desc.name = value;
+ }
+ }
+
+ xpath->node = node;
+ nodes = xmlXPathEvalExpression(UNIT_TRANSFORMS_PATH, xpath);
+ xpath->node = NULL;
+
if (!nodes) {
- xmlErrorPtr xmlerr = xmlGetLastError();
- if (xmlerr) pcilib_error("Failed to parse XPath expression %s, xmlXPathEvalExpression reported error %d - %s", REGISTERS_PATH, xmlerr->code, xmlerr->message);
- else pcilib_error("Failed to parse XPath expression %s", REGISTERS_PATH);
- return PCILIB_ERROR_FAILED;
+ xmlErrorPtr xmlerr = xmlGetLastError();
+ if (xmlerr) pcilib_error("Failed to parse XPath expression %s, xmlXPathEvalExpression reported error %d - %s", UNIT_TRANSFORMS_PATH, xmlerr->code, xmlerr->message);
+ else pcilib_error("Failed to parse XPath expression %s", UNIT_TRANSFORMS_PATH);
+ return PCILIB_ERROR_FAILED;
}
nodeset = nodes->nodesetval;
if (!xmlXPathNodeSetIsEmpty(nodeset)) {
int i;
+
+ if (nodeset->nodeNr > PCILIB_MAX_TRANSFORMS_PER_UNIT) {
+ xmlXPathFreeObject(nodes);
+ pcilib_error("Too many transforms for unit %s are defined, only %lu are supported", desc.name, PCILIB_MAX_TRANSFORMS_PER_UNIT);
+ return PCILIB_ERROR_INVALID_DATA;
+ }
+
for (i = 0; i < nodeset->nodeNr; i++) {
- err = pcilib_xml_create_register(ctx, bank, xpath, doc, nodeset->nodeTab[i]);
- if (err) pcilib_error("Error creating XML registers for bank %s", desc.name);
+ err = pcilib_xml_parse_unit_transform(ctx, xpath, doc, nodeset->nodeTab[i], &desc.transforms[i]);
+ if (err) {
+ xmlXPathFreeObject(nodes);
+ return err;
+ }
}
}
xmlXPathFreeObject(nodes);
- return 0;
+ return pcilib_add_units(ctx, 1, &desc);
}
@@ -405,69 +755,108 @@ static int pcilib_xml_create_bank(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDo
* @param[in] pci the pcilib_t running, which will be filled
*/
static int pcilib_xml_process_document(pcilib_t *ctx, xmlDocPtr doc, xmlXPathContextPtr xpath) {
- xmlXPathObjectPtr bank_nodes;
+ int err;
+ xmlXPathObjectPtr bank_nodes = NULL, transform_nodes = NULL, enum_nodes = NULL, unit_nodes = NULL;
xmlNodeSetPtr nodeset;
+ int i;
- bank_nodes = xmlXPathEvalExpression(BANKS_PATH, xpath);
- if (!bank_nodes) {
- xmlErrorPtr xmlerr = xmlGetLastError();
- if (xmlerr) pcilib_error("Failed to parse XPath expression %s, xmlXPathEvalExpression reported error %d - %s", BANKS_PATH, xmlerr->code, xmlerr->message);
- else pcilib_error("Failed to parse XPath expression %s", BANKS_PATH);
- return PCILIB_ERROR_FAILED;
+ bank_nodes = xmlXPathEvalExpression(BANKS_PATH, xpath);
+ if (bank_nodes) transform_nodes = xmlXPathEvalExpression(TRANSFORM_VIEWS_PATH, xpath);
+ if (transform_nodes) enum_nodes = xmlXPathEvalExpression(ENUM_VIEWS_PATH, xpath);
+ if (enum_nodes) unit_nodes = xmlXPathEvalExpression(UNITS_PATH, xpath);
+
+ if (!unit_nodes) {
+ const unsigned char *expr = (enum_nodes?UNITS_PATH:(transform_nodes?ENUM_VIEWS_PATH:(bank_nodes?TRANSFORM_VIEWS_PATH:BANKS_PATH)));
+
+ if (enum_nodes) xmlXPathFreeObject(enum_nodes);
+ if (transform_nodes) xmlXPathFreeObject(transform_nodes);
+ if (bank_nodes) xmlXPathFreeObject(bank_nodes);
+ xmlErrorPtr xmlerr = xmlGetLastError();
+ if (xmlerr) pcilib_error("Failed to parse XPath expression %s, xmlXPathEvalExpression reported error %d - %s", expr, xmlerr->code, xmlerr->message);
+ else pcilib_error("Failed to parse XPath expression %s", expr);
+ return PCILIB_ERROR_FAILED;
}
+ nodeset = unit_nodes->nodesetval;
+ if(!xmlXPathNodeSetIsEmpty(nodeset)) {
+ for(i=0; i < nodeset->nodeNr; i++) {
+ err = pcilib_xml_create_unit(ctx, xpath, doc, nodeset->nodeTab[i]);
+ if (err) pcilib_error("Error (%i) creating unit", err);
+ }
+ }
+
+ nodeset = transform_nodes->nodesetval;
+ if (!xmlXPathNodeSetIsEmpty(nodeset)) {
+ for(i=0; i < nodeset->nodeNr; i++) {
+ err = pcilib_xml_create_transform_view(ctx, xpath, doc, nodeset->nodeTab[i]);
+ if (err) pcilib_error("Error (%i) creating register transform", err);
+ }
+ }
+
+ nodeset = enum_nodes->nodesetval;
+ if (!xmlXPathNodeSetIsEmpty(nodeset)) {
+ for(i=0; i < nodeset->nodeNr; i++) {
+ err = pcilib_xml_create_enum_view(ctx, xpath, doc, nodeset->nodeTab[i]);
+ if (err) pcilib_error("Error (%i) creating register enum", err);
+ }
+ }
nodeset = bank_nodes->nodesetval;
if (!xmlXPathNodeSetIsEmpty(nodeset)) {
- int i;
- for (i = 0; i < nodeset->nodeNr; i++) {
- pcilib_xml_create_bank(ctx, xpath, doc, nodeset->nodeTab[i]);
- }
+ for (i = 0; i < nodeset->nodeNr; i++) {
+ err = pcilib_xml_create_bank(ctx, xpath, doc, nodeset->nodeTab[i]);
+ if (err) pcilib_error("Error (%i) creating bank", err);
+ }
}
+
+
+ xmlXPathFreeObject(unit_nodes);
+ xmlXPathFreeObject(enum_nodes);
+ xmlXPathFreeObject(transform_nodes);
xmlXPathFreeObject(bank_nodes);
-
+
return 0;
}
static int pcilib_xml_load_xsd(pcilib_t *ctx, char *xsd_filename) {
int err;
-
+
xmlSchemaParserCtxtPtr ctxt;
/** we first parse the xsd file for AST with validation*/
ctxt = xmlSchemaNewParserCtxt(xsd_filename);
if (!ctxt) {
- xmlErrorPtr xmlerr = xmlGetLastError();
- if (xmlerr) pcilib_error("xmlSchemaNewParserCtxt reported error %d - %s", xmlerr->code, xmlerr->message);
- else pcilib_error("Failed to create a parser for XML schemas");
- return PCILIB_ERROR_FAILED;
+ xmlErrorPtr xmlerr = xmlGetLastError();
+ if (xmlerr) pcilib_error("xmlSchemaNewParserCtxt reported error %d - %s", xmlerr->code, xmlerr->message);
+ else pcilib_error("Failed to create a parser for XML schemas");
+ return PCILIB_ERROR_FAILED;
}
-
+
ctx->xml.schema = xmlSchemaParse(ctxt);
if (!ctx->xml.schema) {
- xmlErrorPtr xmlerr = xmlGetLastError();
- xmlSchemaFreeParserCtxt(ctxt);
- if (xmlerr) pcilib_error("Failed to parse XML schema, xmlSchemaParse reported error %d - %s", xmlerr->code, xmlerr->message);
- else pcilib_error("Failed to parse XML schema");
- return PCILIB_ERROR_INVALID_DATA;
+ xmlErrorPtr xmlerr = xmlGetLastError();
+ xmlSchemaFreeParserCtxt(ctxt);
+ if (xmlerr) pcilib_error("Failed to parse XML schema, xmlSchemaParse reported error %d - %s", xmlerr->code, xmlerr->message);
+ else pcilib_error("Failed to parse XML schema");
+ return PCILIB_ERROR_INVALID_DATA;
}
-
+
xmlSchemaFreeParserCtxt(ctxt);
ctx->xml.validator = xmlSchemaNewValidCtxt(ctx->xml.schema);
if (!ctx->xml.validator) {
- xmlErrorPtr xmlerr = xmlGetLastError();
- if (xmlerr) pcilib_error("xmlSchemaNewValidCtxt reported error %d - %s", xmlerr->code, xmlerr->message);
- else pcilib_error("Failed to create a validation context");
- return PCILIB_ERROR_FAILED;
+ xmlErrorPtr xmlerr = xmlGetLastError();
+ if (xmlerr) pcilib_error("xmlSchemaNewValidCtxt reported error %d - %s", xmlerr->code, xmlerr->message);
+ else pcilib_error("Failed to create a validation context");
+ return PCILIB_ERROR_FAILED;
}
-
+
err = xmlSchemaSetValidOptions(ctx->xml.validator, XML_SCHEMA_VAL_VC_I_CREATE);
if (err) {
- xmlErrorPtr xmlerr = xmlGetLastError();
- if (xmlerr) pcilib_error("xmlSchemaSetValidOptions reported error %d - %s", xmlerr->code, xmlerr->message);
- else pcilib_error("Failed to configure the validation context to populate default attributes");
- return PCILIB_ERROR_FAILED;
+ xmlErrorPtr xmlerr = xmlGetLastError();
+ if (xmlerr) pcilib_error("xmlSchemaSetValidOptions reported error %d - %s", xmlerr->code, xmlerr->message);
+ else pcilib_error("Failed to configure the validation context to populate default attributes");
+ return PCILIB_ERROR_FAILED;
}
return 0;
@@ -481,46 +870,46 @@ static int pcilib_xml_load_file(pcilib_t *ctx, const char *path, const char *nam
full_name = (char*)alloca(strlen(path) + strlen(name) + 2);
if (!name) {
- pcilib_error("Error allocating %zu bytes of memory in stack to create a file name", strlen(path) + strlen(name) + 2);
- return PCILIB_ERROR_MEMORY;
+ pcilib_error("Error allocating %zu bytes of memory in stack to create a file name", strlen(path) + strlen(name) + 2);
+ return PCILIB_ERROR_MEMORY;
}
sprintf(full_name, "%s/%s", path, name);
doc = xmlCtxtReadFile(ctx->xml.parser, full_name, NULL, 0);
if (!doc) {
- xmlErrorPtr xmlerr = xmlCtxtGetLastError(ctx->xml.parser);
- if (xmlerr) pcilib_error("Error parsing %s, xmlCtxtReadFile reported error %d - %s", full_name, xmlerr->code, xmlerr->message);
- else pcilib_error("Error parsing %s", full_name);
- return PCILIB_ERROR_INVALID_DATA;
+ xmlErrorPtr xmlerr = xmlCtxtGetLastError(ctx->xml.parser);
+ if (xmlerr) pcilib_error("Error parsing %s, xmlCtxtReadFile reported error %d - %s", full_name, xmlerr->code, xmlerr->message);
+ else pcilib_error("Error parsing %s", full_name);
+ return PCILIB_ERROR_INVALID_DATA;
}
err = xmlSchemaValidateDoc(ctx->xml.validator, doc);
if (err) {
- xmlErrorPtr xmlerr = xmlCtxtGetLastError(ctx->xml.parser);
- xmlFreeDoc(doc);
- if (xmlerr) pcilib_error("Error validating %s, xmlSchemaValidateDoc reported error %d - %s", full_name, xmlerr->code, xmlerr->message);
- else pcilib_error("Error validating %s", full_name);
- return PCILIB_ERROR_VERIFY;
+ xmlErrorPtr xmlerr = xmlCtxtGetLastError(ctx->xml.parser);
+ xmlFreeDoc(doc);
+ if (xmlerr) pcilib_error("Error validating %s, xmlSchemaValidateDoc reported error %d - %s", full_name, xmlerr->code, xmlerr->message);
+ else pcilib_error("Error validating %s", full_name);
+ return PCILIB_ERROR_VERIFY;
}
xpath = xmlXPathNewContext(doc);
if (!xpath) {
- xmlErrorPtr xmlerr = xmlGetLastError();
- xmlFreeDoc(doc);
- if (xmlerr) pcilib_error("Document %s: xmlXpathNewContext reported error %d - %s for document %s", full_name, xmlerr->code, xmlerr->message);
- else pcilib_error("Error creating XPath context for %s", full_name);
- return PCILIB_ERROR_FAILED;
+ xmlErrorPtr xmlerr = xmlGetLastError();
+ xmlFreeDoc(doc);
+ if (xmlerr) pcilib_error("Document %s: xmlXpathNewContext reported error %d - %s for document %s", full_name, xmlerr->code, xmlerr->message);
+ else pcilib_error("Error creating XPath context for %s", full_name);
+ return PCILIB_ERROR_FAILED;
}
- // This can only partially fail... Therefore we need to keep XML and just return the error...
+ // This can only partially fail... Therefore we need to keep XML and just return the error...
err = pcilib_xml_process_document(ctx, doc, xpath);
if (ctx->xml.num_files == PCILIB_MAX_MODEL_FILES) {
- xmlFreeDoc(doc);
+ xmlFreeDoc(doc);
xmlXPathFreeContext(xpath);
- pcilib_error("Too many XML files for a model, only up to %zu are supported", PCILIB_MAX_MODEL_FILES);
- return PCILIB_ERROR_TOOBIG;
+ pcilib_error("Too many XML files for a model, only up to %zu are supported", PCILIB_MAX_MODEL_FILES);
+ return PCILIB_ERROR_TOOBIG;
}
ctx->xml.docs[ctx->xml.num_files] = doc;
@@ -550,12 +939,12 @@ int pcilib_process_xml(pcilib_t *ctx, const char *location) {
if (!rep) return PCILIB_ERROR_NOTFOUND;
while ((file = readdir(rep)) != NULL) {
- size_t len = strlen(file->d_name);
- if ((len < 4)||(strcasecmp(file->d_name + len - 4, ".xml"))) continue;
- if (file->d_type != DT_REG) continue;
-
- err = pcilib_xml_load_file(ctx, model_path, file->d_name);
- if (err) pcilib_error("Error processing XML file %s", file->d_name);
+ size_t len = strlen(file->d_name);
+ if ((len < 4)||(strcasecmp(file->d_name + len - 4, ".xml"))) continue;
+ if (file->d_type != DT_REG) continue;
+
+ err = pcilib_xml_load_file(ctx, model_path, file->d_name);
+ if (err) pcilib_error("Error processing XML file %s", file->d_name);
}
closedir(rep);
@@ -586,16 +975,16 @@ int pcilib_init_xml(pcilib_t *ctx, const char *model) {
sprintf(xsd_path, "%s/model.xsd", model_dir);
if (stat(xsd_path, &st)) {
- pcilib_info("XML models are not present");
- return PCILIB_ERROR_NOTFOUND;
+ pcilib_info("XML models are not present");
+ return PCILIB_ERROR_NOTFOUND;
}
ctx->xml.parser = xmlNewParserCtxt();
if (!ctx->xml.parser) {
- xmlErrorPtr xmlerr = xmlGetLastError();
- if (xmlerr) pcilib_error("xmlNewParserCtxt reported error %d (%s)", xmlerr->code, xmlerr->message);
- else pcilib_error("Failed to create an XML parser context");
- return PCILIB_ERROR_FAILED;
+ xmlErrorPtr xmlerr = xmlGetLastError();
+ if (xmlerr) pcilib_error("xmlNewParserCtxt reported error %d (%s)", xmlerr->code, xmlerr->message);
+ else pcilib_error("Failed to create an XML parser context");
+ return PCILIB_ERROR_FAILED;
}
err = pcilib_xml_load_xsd(ctx, xsd_path);
@@ -613,44 +1002,44 @@ void pcilib_free_xml(pcilib_t *ctx) {
memset(ctx->xml.bank_nodes, 0, sizeof(ctx->xml.bank_nodes));
for (i = 0; i < ctx->num_banks; i++) {
- if (ctx->bank_ctx[i])
- ctx->bank_ctx[i]->xml = NULL;
+ if (ctx->bank_ctx[i])
+ ctx->bank_ctx[i]->xml = NULL;
}
-
+
for (i = 0; i < ctx->num_reg; i++) {
- ctx->register_ctx[i].xml = NULL;
+ ctx->register_ctx[i].xml = NULL;
}
-
+
for (i = 0; i < ctx->xml.num_files; i++) {
- if (ctx->xml.docs[i]) {
- xmlFreeDoc(ctx->xml.docs[i]);
- ctx->xml.docs[i] = NULL;
- }
- if (ctx->xml.xpath[i]) {
- xmlXPathFreeContext(ctx->xml.xpath[i]);
- ctx->xml.xpath[i] = NULL;
- }
+ if (ctx->xml.docs[i]) {
+ xmlFreeDoc(ctx->xml.docs[i]);
+ ctx->xml.docs[i] = NULL;
+ }
+ if (ctx->xml.xpath[i]) {
+ xmlXPathFreeContext(ctx->xml.xpath[i]);
+ ctx->xml.xpath[i] = NULL;
+ }
}
ctx->xml.num_files = 0;
if (ctx->xml.validator) {
- xmlSchemaFreeValidCtxt(ctx->xml.validator);
- ctx->xml.validator = NULL;
+ xmlSchemaFreeValidCtxt(ctx->xml.validator);
+ ctx->xml.validator = NULL;
}
-
+
if (ctx->xml.schema) {
- xmlSchemaFree(ctx->xml.schema);
- ctx->xml.schema = NULL;
-
+ xmlSchemaFree(ctx->xml.schema);
+ ctx->xml.schema = NULL;
+
}
if (ctx->xml.parser) {
- xmlFreeParserCtxt(ctx->xml.parser);
- ctx->xml.parser = NULL;
+ xmlFreeParserCtxt(ctx->xml.parser);
+ ctx->xml.parser = NULL;
}
-/*
- xmlSchemaCleanupTypes();
- xmlCleanupParser();
- xmlMemoryDump();
-*/
+ /*
+ xmlSchemaCleanupTypes();
+ xmlCleanupParser();
+ xmlMemoryDump();
+ */
}