view.h 5.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #ifndef _PCILIB_VIEW_H
  2. #define _PCILIB_VIEW_H
  3. #include <uthash.h>
  4. #include <pcilib.h>
  5. #include <pcilib/unit.h>
  6. #define PCILIB_VIEW_INVALID ((pcilib_view_t)-1)
  7. typedef struct pcilib_view_context_s pcilib_view_context_t;
  8. typedef struct pcilib_view_description_s pcilib_view_description_t;
  9. typedef enum {
  10. PCILIB_VIEW_FLAG_PROPERTY = 1, /**< Indicates that view does not depend on a value and is independent property */
  11. PCILIB_VIEW_FLAG_REGISTER = 2 /**< Indicates that view does not depend on a value and should be mapped to the register space */
  12. } pcilib_view_flags_t;
  13. typedef struct {
  14. pcilib_version_t version; /**< Version */
  15. size_t description_size; /**< The actual size of the description */
  16. pcilib_view_context_t *(*init)(pcilib_t *ctx, pcilib_view_t view); /**< Optional function which should allocated context used by read/write functions */
  17. void (*free)(pcilib_t *ctx, pcilib_view_context_t *view); /**< Optional function which should clean context */
  18. void (*free_description)(pcilib_t *ctx, pcilib_view_description_t *view); /**< Optional function which shoud clean required parts of the extended description if non-static memory was used to initialize it */
  19. int (*read_from_reg)(pcilib_t *ctx, pcilib_view_context_t *view, pcilib_register_value_t regval, pcilib_value_t *val); /**< Function which computes view value based on the passed the register value (view-based properties should not use register value) */
  20. int (*write_to_reg)(pcilib_t *ctx, pcilib_view_context_t *view, pcilib_register_value_t *regval, const pcilib_value_t *val); /**< Function which computes register value based on the passed value (view-based properties are not required to set the register value) */
  21. } pcilib_view_api_description_t;
  22. struct pcilib_view_description_s {
  23. const pcilib_view_api_description_t *api;
  24. pcilib_view_flags_t flags; /**< Flags specifying type of the view */
  25. pcilib_value_type_t type; /**< The default data type returned by operation, PCILIB_VIEW_TYPE_STRING is supported by all operations */
  26. pcilib_access_mode_t mode; /**< Specifies if the view is read/write-only */
  27. const char *unit; /**< Returned unit (if any) */
  28. const char *name; /**< Name of the view */
  29. const char *regname; /**< Specifies the register name if the view should be mapped to register space */
  30. const char *description; /**< Short description */
  31. };
  32. struct pcilib_view_context_s {
  33. const char *name;
  34. pcilib_view_t view;
  35. pcilib_xml_node_t *xml;
  36. UT_hash_handle hh;
  37. };
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /**
  42. * Use this function to add new view definitions into the model. It is error to re-register
  43. * already registered view. The function will copy the context of unit description, but name,
  44. * transform, and other strings in the structure are considered to have static duration
  45. * and will not be copied. On error no new views are initalized.
  46. * @param[in,out] ctx - pcilib context
  47. * @param[in] n - number of views to initialize. It is OK to pass 0 if protocols variable is NULL terminated (last member of protocols array have all members set to 0)
  48. * @param[in] desc - view descriptions
  49. * @return - error or 0 on success
  50. */
  51. int pcilib_add_views(pcilib_t *ctx, size_t n, const pcilib_view_description_t *desc);
  52. /**
  53. * Use this function to add new view definitions into the model. It is error to re-register
  54. * already registered view. The function will copy the context of unit description, but name,
  55. * transform, and other strings in the structure are considered to have static duration
  56. * and will not be copied. On error no new views are initalized.
  57. * @param[in,out] ctx - pcilib context
  58. * @param[in] n - number of views to initialize. It is OK to pass 0 if protocols variable is NULL terminated (last member of protocols array have all members set to 0)
  59. * @param[in] desc - view descriptions
  60. * @param[out] refs - fills allocated view contexts. On error context is undefined.
  61. * @return - error or 0 on success
  62. */
  63. int pcilib_add_views_custom(pcilib_t *ctx, size_t n, const pcilib_view_description_t *desc, pcilib_view_context_t **refs);
  64. /**
  65. * Destroys data associated with views. This is an internal function and will
  66. * be called during clean-up.
  67. * @param[in,out] ctx - pcilib context
  68. * @param[in] start - specifies first view to clean (used to clean only part of the views to keep the defined state if pcilib_add_views has failed)
  69. */
  70. void pcilib_clean_views(pcilib_t *ctx, pcilib_view_t start);
  71. pcilib_view_context_t *pcilib_find_view_context_by_name(pcilib_t *ctx, const char *view);
  72. pcilib_view_context_t *pcilib_find_register_view_context_by_name(pcilib_t *ctx, pcilib_register_t reg, const char *name);
  73. pcilib_view_context_t *pcilib_find_register_view_context(pcilib_t *ctx, pcilib_register_t reg, const char *name);
  74. pcilib_view_t pcilib_find_view_by_name(pcilib_t *ctx, const char *name);
  75. #ifdef __cplusplus
  76. }
  77. #endif
  78. #endif /* PCILIB_VIEW_H */