Browse Source

Include version information in all API descriptions

Suren A. Chilingaryan 9 years ago
parent
commit
5387063faa
15 changed files with 65 additions and 8 deletions
  1. 1 0
      .bzrignore
  2. 8 0
      CMakeLists.txt
  3. 12 0
      cmake/version.cmake
  4. 2 0
      dma/ipe.h
  5. 2 0
      dma/nwl.h
  6. 2 2
      pcilib/CMakeLists.txt
  7. 2 0
      pcilib/bank.h
  8. 2 0
      pcilib/dma.h
  9. 4 1
      pcilib/event.h
  10. 2 1
      pcilib/model.h
  11. 2 0
      pcilib/pcilib.h
  12. 1 1
      pcilib/plugin.c
  13. 15 0
      pcilib/version.h.in
  14. 8 2
      pcitool/cli.c
  15. 2 1
      protocols/default.h

+ 1 - 0
.bzrignore

@@ -28,3 +28,4 @@ apps/lorenzo_ipedma_test
 pcitool.pc
 config.h
 pcitool/pci
+version.h

+ 8 - 0
CMakeLists.txt

@@ -7,6 +7,7 @@ cmake_minimum_required(VERSION 2.6)
 
 set(DISABLE_PCITOOL FALSE CACHE BOOL "Build only the library") 
 
+#list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
 
 find_package(PkgConfig REQUIRED)
 find_package(Threads REQUIRED)
@@ -19,6 +20,10 @@ endif (NOT DISABLE_PCITOOL)
 add_definitions("-fPIC --std=c99 -Wall -O2 -gdwarf-2 -g3")
 #add_definitions("-fPIC --std=c99 -Wall -O2")
 
+include(cmake/version.cmake)
+VERSION_TO_VARS(${PCILIB_VERSION} PCILIB_VERSION_MAJOR PCILIB_VERSION_MINOR PCILIB_VERSION_MICRO)
+
+
 add_subdirectory(dma)
 add_subdirectory(protocols)
 add_subdirectory(pcilib)
@@ -64,8 +69,11 @@ set(PCILIB_DEBUG_DIR "." CACHE PATH "Directory to write debug information")
 
 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/pcitool.pc.in ${CMAKE_CURRENT_BINARY_DIR}/pcitool.pc)
 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/pcilib/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/pcilib/config.h)
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/pcilib/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/pcilib/version.h)
 
 install(FILES 
     ${CMAKE_CURRENT_BINARY_DIR}/pcitool.pc 
     DESTINATION ${LIB_INSTALL_DIR}/pkgconfig
 )
+
+message("-- Configured pcitool ${PCILIB_VERSION_MAJOR}.${PCILIB_VERSION_MINOR}.${PCILIB_VERSION_MICRO} with public ABI ${PCILIB_ABI_VERSION}")

+ 12 - 0
cmake/version.cmake

@@ -0,0 +1,12 @@
+SET(VERSION_REGEX "[0-9]+\\.[0-9]+\\.[0-9]+")
+
+MACRO(VERSION_TO_VARS version major minor patch)
+  IF(${version} MATCHES ${VERSION_REGEX})
+    STRING(REGEX REPLACE "^([0-9]+)\\.[0-9]+\\.[0-9]+" "\\1" ${major} "${version}")
+    STRING(REGEX REPLACE "^[0-9]+\\.([0-9])+\\.[0-9]+" "\\1" ${minor} "${version}")
+    STRING(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+)" "\\1" ${patch} "${version}")
+  ELSE(${version} MATCHES ${VERSION_REGEX})
+    MESSAGE("MACRO(VERSION_TO_VARS ${version} ${major} ${minor} ${patch}")
+    MESSAGE(FATAL_ERROR "Problem parsing version string, I can't parse it properly.")
+  ENDIF(${version} MATCHES ${VERSION_REGEX})
+ENDMACRO(VERSION_TO_VARS)

+ 2 - 0
dma/ipe.h

@@ -3,6 +3,7 @@
 
 #include <stdio.h>
 #include "pcilib.h"
+#include "version.h"
 
 //#define PCILIB_NWL_MODIFICATION_IPECAMERA 0x100
 
@@ -19,6 +20,7 @@ double dma_ipe_benchmark(pcilib_dma_context_t *vctx, pcilib_dma_engine_addr_t dm
 
 #ifdef _PCILIB_EXPORT_C
 static const pcilib_dma_api_description_t ipe_dma_api = {
+    PCILIB_VERSION,
     dma_ipe_init,
     dma_ipe_free,
     dma_ipe_get_status,

+ 2 - 0
dma/nwl.h

@@ -3,6 +3,7 @@
 
 #include <stdio.h>
 #include "pcilib.h"
+#include "version.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);
@@ -22,6 +23,7 @@ double dma_nwl_benchmark(pcilib_dma_context_t *vctx, pcilib_dma_engine_addr_t dm
 
 #ifdef _PCILIB_EXPORT_C
 static const pcilib_dma_api_description_t nwl_dma_api = {
+    PCILIB_VERSION,
     dma_nwl_init,
     dma_nwl_free,
     dma_nwl_get_status,

+ 2 - 2
pcilib/CMakeLists.txt

@@ -3,7 +3,7 @@ include_directories(
     ${CMAKE_SOURCE_DIR}/pcilib
 )
 
-set(HEADERS pcilib.h pci.h export.h model.h bank.h register.h kmem.h irq.h dma.h event.h plugin.h tools.h error.h debug.h config.h)
+set(HEADERS pcilib.h pci.h export.h model.h bank.h register.h kmem.h irq.h dma.h event.h plugin.h tools.h error.h debug.h version.h config.h)
 add_library(pcilib SHARED pci.c export.c model.c bank.c register.c kmem.c irq.c dma.c event.c plugin.c tools.c error.c debug.c)
 target_link_libraries(pcilib dma protocols ${CMAKE_THREAD_LIBS_INIT} ${UFODECODE_LIBRARIES} ${CMAKE_DL_LIBS})
 add_dependencies(pcilib dma protocols)
@@ -16,6 +16,6 @@ install(FILES pcilib.h
     DESTINATION include
 )
 
-install(FILES bank.h register.h dma.h event.h model.h error.h debug.h tools.h export.h
+install(FILES bank.h register.h dma.h event.h model.h error.h debug.h tools.h export.h version.h
     DESTINATION include/pcilib
 )

+ 2 - 0
pcilib/bank.h

@@ -25,6 +25,8 @@ typedef uint8_t pcilib_register_protocol_addr_t;				/**< Type holding the protoc
 typedef struct pcilib_register_bank_context_s pcilib_register_bank_context_t;
 
 typedef struct {
+    pcilib_version_t version;
+
     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 */

+ 2 - 0
pcilib/dma.h

@@ -49,6 +49,8 @@ typedef struct {
 } pcilib_dma_context_t;
 
 typedef struct {
+    pcilib_version_t version;
+
     pcilib_dma_context_t *(*init)(pcilib_t *ctx, const char *model, const void *arg);
     void (*free)(pcilib_dma_context_t *ctx);
     

+ 4 - 1
pcilib/event.h

@@ -2,9 +2,10 @@
 #define _PCILIB_EVENT_H
 
 #include <pcilib.h>
+#include <pcilib/version.h>
 #include <pcilib/dma.h>
 
-#define PCILIB_EVENT_INTERFACE_VERSION 0
+#define PCILIB_EVENT_INTERFACE_VERSION PCILIB_VERSION
 
 typedef struct {
     size_t max_events;
@@ -68,6 +69,8 @@ typedef enum {
  */
 
 typedef struct {
+    pcilib_version_t version;
+
     pcilib_context_t *(*init)(pcilib_t *ctx);
     void (*free)(pcilib_context_t *ctx);
 

+ 2 - 1
pcilib/model.h

@@ -7,8 +7,9 @@
 #include <pcilib/event.h>
 #include <pcilib/export.h>
 
+
 typedef struct {
-    const unsigned int interface_version;
+    const pcilib_version_t interface_version;
 
     const pcilib_event_api_description_t *api;
     const pcilib_dma_description_t *dma;

+ 2 - 0
pcilib/pcilib.h

@@ -9,6 +9,8 @@
 typedef struct pcilib_s pcilib_t;
 typedef struct pcilib_event_context_s pcilib_context_t;
 
+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 uint32_t pcilib_register_addr_t;	/**< Type holding the register address within address-space of BARs */

+ 1 - 1
pcilib/plugin.c

@@ -53,7 +53,7 @@ const pcilib_model_description_t *pcilib_get_plugin_model(pcilib_t *pcilib, void
     model_info = ((const pcilib_model_description_t *(*)(pcilib_t *pcilib, unsigned short vendor_id, unsigned short device_id, const char *model))get_model)(pcilib, vendor_id, device_id, model);
     if (!model_info) return model_info;
 
-    if (model_info->interface_version != PCILIB_EVENT_INTERFACE_VERSION) {
+    if ((PCILIB_VERSION_GET_MAJOR(model_info->interface_version) != PCILIB_VERSION_MAJOR)||(PCILIB_VERSION_GET_MINOR(model_info->interface_version) != PCILIB_VERSION_MINOR)) {
 	pcilib_warning("Plugin %s exposes outdated interface version (%lu), pcitool supports (%lu)", model_info->name, model_info->interface_version, PCILIB_EVENT_INTERFACE_VERSION);
 	return NULL;
     }

+ 15 - 0
pcilib/version.h.in

@@ -0,0 +1,15 @@
+#ifndef _PCILIB_VERSION_H
+#define _PCILIB_VERSION_H
+
+#define PCILIB_VERSION_MAJOR ${PCILIB_VERSION_MAJOR}
+#define PCILIB_VERSION_MINOR ${PCILIB_VERSION_MINOR}
+#define PCILIB_VERSION_MICRO ${PCILIB_VERSION_MICRO}
+
+#define PCILIB_MAKE_VERSION(major, minor, micro) ((major<<16)|(minor<<8)|(micro))
+#define PCILIB_VERSION_GET_MAJOR(version) ((version>>16)&&0xFF)
+#define PCILIB_VERSION_GET_MINOR(version) ((version>>8)&&0xFF)
+#define PCILIB_VERSION_GET_MICRO(version) ((version)&&0xFF)
+
+#define PCILIB_VERSION PCILIB_MAKE_VERSION(PCILIB_VERSION_MAJOR, PCILIB_VERSION_MINOR, PCILIB_VERSION_MICRO)
+
+#endif /* _PCILIB_VERSION_H */

+ 8 - 2
pcitool/cli.c

@@ -550,8 +550,14 @@ void Info(pcilib_t *handle, const pcilib_model_description_t *model_info) {
 		info = pcilib_get_plugin_model(handle, plugin, 0, 0, NULL);
 		if (info) {
 		    printf(" %s\n", entry->d_name);
-		    for (j = 0; info[j].name; j++)
-			printf("   %-12s - %s\n", info[j].name, info[j].description?info[j].description:"");
+		    for (j = 0; info[j].name; j++) {
+			pcilib_version_t version = info[j].api->version;
+			printf("   %-12s %u.%u.%u - %s\n", info[j].name, 
+				PCILIB_VERSION_GET_MAJOR(version), 
+				PCILIB_VERSION_GET_MINOR(version),
+				PCILIB_VERSION_GET_MICRO(version),
+				info[j].description?info[j].description:"");
+		    }
 		}
 		pcilib_plugin_close(plugin);
 	    } else {

+ 2 - 1
protocols/default.h

@@ -2,6 +2,7 @@
 #define _PCILIB_DEFAULT_H
 
 #include "pcilib.h"
+#include "version.h"
 #include "model.h"
 
 int pcilib_default_read(pcilib_t *ctx, pcilib_register_bank_context_t *bank, pcilib_register_addr_t addr, pcilib_register_value_t *value);
@@ -9,7 +10,7 @@ int pcilib_default_write(pcilib_t *ctx, pcilib_register_bank_context_t *bank, pc
 
 #ifdef _PCILIB_EXPORT_C
 const pcilib_register_protocol_api_description_t pcilib_default_protocol_api =
-    { NULL, NULL, pcilib_default_read, pcilib_default_write };
+    { PCILIB_VERSION, NULL, NULL, pcilib_default_read, pcilib_default_write };
 #endif /* _PCILIB_EXPORT_C */
 
 #endif /* _PCILIB_DEFAULT_H */