register.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #ifndef _PCILIB_REGISTER_H
  2. #define _PCILIB_REGISTER_H
  3. #include <uthash.h>
  4. #include <pcilib.h>
  5. #include <pcilib/bank.h>
  6. #define PCILIB_REGISTER_NO_BITS 0
  7. #define PCILIB_REGISTER_ALL_BITS ((pcilib_register_value_t)-1)
  8. typedef enum {
  9. PCILIB_REGISTER_R = 1, /**< reading from register is allowed */
  10. PCILIB_REGISTER_W = 2, /**< normal writting to register is allowed */
  11. PCILIB_REGISTER_RW = 3,
  12. PCILIB_REGISTER_W1C = 4, /**< writting 1 resets the bit, writting 0 keeps the value */
  13. PCILIB_REGISTER_RW1C = 5,
  14. PCILIB_REGISTER_W1I = 8, /**< writting 1 inversts the bit, writting 0 keeps the value */
  15. PCILIB_REGISTER_RW1I = 9,
  16. } pcilib_register_mode_t;
  17. typedef enum {
  18. PCILIB_REGISTER_STANDARD = 0,
  19. PCILIB_REGISTER_FIFO,
  20. PCILIB_REGISTER_BITS
  21. } pcilib_register_type_t;
  22. typedef struct {
  23. const char *name;
  24. const char *view;
  25. } pcilib_view_reference_t;
  26. typedef struct {
  27. pcilib_register_addr_t addr; /**< Register address in the bank */
  28. pcilib_register_size_t offset; /**< Register offset in the byte (in bits) */
  29. pcilib_register_size_t bits; /**< Register size in bits */
  30. pcilib_register_value_t defvalue; /**< Default register value (some protocols, i.e. software registers, may set it during the initialization) */
  31. pcilib_register_value_t rwmask; /**< Used to define how external bits of PCILIB_REGISTER_BITS registers are treated.
  32. To keep bit value unchanged, we need to observe the following behavior depending on status of corresponding bit in this field:
  33. 1 - standard bit (i.e. if we want to keep the bit value we need to read it, and, the write back),
  34. 0 - non-standard bit which behavior is defined by mode (only partially implemented.
  35. so far only 1C/1I modes (zero should be written to preserve the value) are supported */
  36. pcilib_register_mode_t mode; /**< Register access (ro/wo/rw) and how writting to register works (if value just set as specified or, for instance, the bits which
  37. are on in the value are cleared/inverted). For information only, no preprocessing on bits is performed. */
  38. pcilib_register_type_t type; /**< Defines type of register is it standard register, subregister for bit fields or view, fifo */
  39. pcilib_register_bank_addr_t bank; /**< Specified the address of the bank this register belongs to */
  40. const char *name; /**< The access name of the register */
  41. const char *description; /**< Brief description of the register */
  42. pcilib_view_reference_t *views; /**< List of supported views for this register */
  43. } pcilib_register_description_t;
  44. typedef struct {
  45. const char *name; /**< Register name */
  46. pcilib_register_t reg; /**< Register index */
  47. pcilib_register_bank_t bank; /**< Reference to bank containing the register */
  48. pcilib_register_value_t min, max; /**< Minimum & maximum allowed values */
  49. pcilib_xml_node_t *xml; /**< Additional XML properties */
  50. 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) */
  51. UT_hash_handle hh;
  52. } pcilib_register_context_t;
  53. #ifdef __cplusplus
  54. extern "C" {
  55. #endif
  56. /**
  57. * Use this function to add new registers into the model. Currently, it is considered a error
  58. * to re-add already defined register. If it will turn out to be useful to redefine some registers
  59. * from the model, it may change in the future. However, we should think how to treat bit-registers
  60. * in this case. The function will copy the context of registers structure, but name,
  61. * description, and other strings in the structure are considered to have static duration
  62. * and will not be copied. On error no new registers are initalized.
  63. * @param[in,out] ctx - pcilib context
  64. * @param[in] flags - not used now, but in future may instruct if existing registers should be reported as error (default), overriden or ignored
  65. * @param[in] n - number of registers to initialize. It is OK to pass 0 if registers array is NULL terminated (last member of the array have all members set to 0)
  66. * @param[in] registers - register descriptions
  67. * @param[out] ids - if specified will contain the ids of the newly registered and overriden registers
  68. * @return - error or 0 on success
  69. */
  70. int pcilib_add_registers(pcilib_t *ctx, pcilib_model_modification_flags_t flags, size_t n, const pcilib_register_description_t *registers, pcilib_register_t *ids);
  71. /**
  72. * Destroys data associated with registers. This is an internal function and will
  73. * be called during clean-up.
  74. * @param[in,out] ctx - pcilib context
  75. * @param[in] start - specifies first register to clean (used to clean only part of the registers to keep the defined state if pcilib_add_registers has failed)
  76. */
  77. void pcilib_clean_registers(pcilib_t *ctx, pcilib_register_t start);
  78. #ifdef __cplusplus
  79. }
  80. #endif
  81. #endif /* _PCILIB_REGISTER_H */