view.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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_flags_t;
  12. typedef struct {
  13. pcilib_version_t version; /**< Version */
  14. size_t description_size; /**< The actual size of the description */
  15. pcilib_view_context_t *(*init)(pcilib_t *ctx); /**< Optional function which should allocated context used by read/write functions */
  16. void (*free)(pcilib_t *ctx, pcilib_view_context_t *view); /**< Optional function which should clean context */
  17. 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 */
  18. 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) */
  19. 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) */
  20. } pcilib_view_api_description_t;
  21. struct pcilib_view_description_s {
  22. const pcilib_view_api_description_t *api;
  23. pcilib_value_type_t type; /**< The default data type returned by operation, PCILIB_VIEW_TYPE_STRING is supported by all operations */
  24. pcilib_access_mode_t mode; /**< Specifies if the view is read/write-only */
  25. const char *unit; /**< Returned unit (if any) */
  26. const char *name; /**< Name of the view */
  27. const char *description; /**< Short description */
  28. };
  29. struct pcilib_view_context_s {
  30. const char *name;
  31. pcilib_view_t view;
  32. pcilib_view_flags_t flags; /**< Flags specifying type of the view */
  33. UT_hash_handle hh;
  34. };
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38. /**
  39. * Use this function to add new view definitions into the model. It is error to re-register
  40. * already registered view. The function will copy the context of unit description, but name,
  41. * transform, and other strings in the structure are considered to have static duration
  42. * and will not be copied. On error no new views are initalized.
  43. * @param[in,out] ctx - pcilib context
  44. * @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)
  45. * @param[in] desc - view descriptions
  46. * @return - error or 0 on success
  47. */
  48. int pcilib_add_views(pcilib_t *ctx, size_t n, const pcilib_view_description_t *desc);
  49. /**
  50. * Destroys data associated with views. This is an internal function and will
  51. * be called during clean-up.
  52. * @param[in,out] ctx - pcilib context
  53. * @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)
  54. */
  55. void pcilib_clean_views(pcilib_t *ctx, pcilib_view_t start);
  56. pcilib_view_context_t *pcilib_find_view_context_by_name(pcilib_t *ctx, const char *view);
  57. pcilib_view_context_t *pcilib_find_register_view_context_by_name(pcilib_t *ctx, pcilib_register_t reg, const char *name);
  58. pcilib_view_context_t *pcilib_find_register_view_context(pcilib_t *ctx, pcilib_register_t reg, const char *name);
  59. pcilib_view_t pcilib_find_view_by_name(pcilib_t *ctx, const char *name);
  60. #ifdef __cplusplus
  61. }
  62. #endif
  63. #endif /* PCILIB_VIEW_H */