bank.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #ifndef _PCILIB_BANK_H
  2. #define _PCILIB_BANK_H
  3. #include <pcilib.h>
  4. #define PCILIB_REGISTER_BANK_INVALID ((pcilib_register_bank_t)-1)
  5. #define PCILIB_REGISTER_BANK0 0 /**< First BANK to be used in the event engine */
  6. #define PCILIB_REGISTER_BANK1 1
  7. #define PCILIB_REGISTER_BANK2 2
  8. #define PCILIB_REGISTER_BANK3 3
  9. #define PCILIB_REGISTER_BANK_DMA 64 /**< First BANK address to be used by DMA engines */
  10. #define PCILIB_REGISTER_BANK_DMACONF 65 /**< DMA configuration in the software registers */
  11. #define PCILIB_REGISTER_BANK_DYNAMIC 128 /**< First BANK address to map dynamic XML configuration */
  12. #define PCILIB_REGISTER_PROTOCOL_INVALID ((pcilib_register_protocol_t)-1)
  13. #define PCILIB_REGISTER_PROTOCOL0 0 /**< First PROTOCOL address to be used in the event engine */
  14. #define PCILIB_REGISTER_PROTOCOL_DEFAULT 64 /**< Default memmap based protocol */
  15. #define PCILIB_REGISTER_PROTOCOL_SOFTWARE 65 /**< Software registers */
  16. #define PCILIB_REGISTER_PROTOCOL_DMA 96 /**< First PROTOCOL address to be used by DMA engines */
  17. #define PCILIB_REGISTER_PROTOCOL_DYNAMIC 128 /**< First PROTOCOL address to be used by plugins */
  18. typedef uint8_t pcilib_register_bank_t; /**< Type holding the bank position within the field listing register banks in the model */
  19. typedef uint8_t pcilib_register_bank_addr_t; /**< Type holding the bank address number */
  20. typedef uint8_t pcilib_register_protocol_t; /**< Type holding the protocol position within the field listing register protocols in the model */
  21. typedef uint8_t pcilib_register_protocol_addr_t; /**< Type holding the protocol address */
  22. typedef struct pcilib_register_bank_context_s pcilib_register_bank_context_t;
  23. typedef struct {
  24. pcilib_version_t version;
  25. 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 */
  26. void (*free)(pcilib_t *pcilib, pcilib_register_bank_context_t *ctx); /**< Optional API call to cleanup bank context */
  27. 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 */
  28. int (*write)(pcilib_t *pcilib, pcilib_register_bank_context_t *ctx, pcilib_register_addr_t addr, pcilib_register_value_t value); /**< Write to register, mandatory for WO/RW registers */
  29. } pcilib_register_protocol_api_description_t;
  30. typedef struct {
  31. pcilib_register_protocol_addr_t addr; /**< Protocol address used in model for addressing the described protocol */
  32. const pcilib_register_protocol_api_description_t *api; /**< Defines all API functions for protocol */
  33. const char *model; /**< If NULL, the actually used model is used instead */
  34. const void *args; /**< Custom protocol-specific arguments. The actual structure may depend on the specified model */
  35. const char *name; /**< Short protocol name */
  36. const char *description; /**< A bit longer protocol description */
  37. } pcilib_register_protocol_description_t;
  38. typedef struct {
  39. pcilib_register_bank_addr_t addr; /**< Bank address used in model for addressing the described register bank */
  40. pcilib_register_protocol_addr_t protocol; /**< Defines a protocol to access registers */
  41. pcilib_bar_t bar; /**< Specifies the PCI BAR through which an access to the registers is provided (autodetcted if PCILIB_BAR_DETECT is specified) */
  42. uintptr_t read_addr; /**< protocol specific (normally offset in the BAR of the first address used to read registers) */
  43. uintptr_t write_addr; /**< protocol specific (normally offset in the BAR of the first address used to write registers) */
  44. uint8_t access; /**< Default register size in bits (or word-size in plain addressing mode) */
  45. size_t size; /**< Number of register addresses (plain addressing) in the bank (more register names can be defined if bit-fields/views are used) */
  46. pcilib_endianess_t raw_endianess; /**< Specifies endianess in the plain-addressing mode, PCILIB_HOST_ENDIAN have to be specified if no conversion desired.
  47. Conversion applied after protocol. This value does not get into the account in register-access mode */
  48. pcilib_endianess_t endianess; /**< Specifies endianess in the register-access mode, this may differ from raw_endianess if multi-word registers are used.
  49. This is fully independent from raw_endianess. No double conversion is either performed */
  50. const char *format; /**< printf format for the registers, either %lu for decimal output or 0x%lx for hexdecimal */
  51. const char *name; /**< short bank name */
  52. const char *description; /**< longer bank description */
  53. } pcilib_register_bank_description_t;
  54. /**
  55. * Default mappings: defines virtual address to register mappings, i.e. how 0x9000 in the following command
  56. * will be mapped to the actual register. By comparing with start and end-addresses, we find to which range
  57. * 0x9000 belongs to and detect actual bank and offset in it.
  58. * Simple example: pci -r 0x9000
  59. * if we specify range { 0x9000, 0x9100, 10, -0x9000}, the example command we print the value of the first
  60. * register in the bank 10.
  61. */
  62. typedef struct {
  63. uintptr_t start; /**< The first virtual address of the register range */
  64. uintptr_t end; /**< The last virtual address of the register range */
  65. pcilib_register_bank_addr_t bank; /**< The bank mapped to the specified range */
  66. long addr_shift; /**< Address shift, i.e. how much we should add/substract to the virtual address to get address in the register bank */
  67. } pcilib_register_range_t;
  68. struct pcilib_register_bank_context_s {
  69. const pcilib_register_bank_description_t *bank; /**< Corresponding bank description */
  70. const pcilib_register_protocol_api_description_t *api; /**< API functions */
  71. };
  72. #ifdef __cplusplus
  73. extern "C" {
  74. #endif
  75. // we don't copy strings, they should be statically allocated
  76. int pcilib_init_register_banks(pcilib_t *ctx);
  77. void pcilib_free_register_banks(pcilib_t *ctx);
  78. int pcilib_add_register_banks(pcilib_t *ctx, size_t n, const pcilib_register_bank_description_t *banks);
  79. int pcilib_add_register_protocols(pcilib_t *ctx, size_t n, const pcilib_register_protocol_description_t *protocols);
  80. int pcilib_add_register_ranges(pcilib_t *ctx, size_t n, const pcilib_register_range_t *ranges);
  81. pcilib_register_bank_t pcilib_find_register_bank_by_addr(pcilib_t *ctx, pcilib_register_bank_addr_t bank);
  82. pcilib_register_bank_t pcilib_find_register_bank_by_name(pcilib_t *ctx, const char *bankname);
  83. pcilib_register_bank_t pcilib_find_register_bank(pcilib_t *ctx, const char *bank);
  84. pcilib_register_protocol_t pcilib_find_register_protocol_by_addr(pcilib_t *ctx, pcilib_register_protocol_addr_t protocol);
  85. pcilib_register_protocol_t pcilib_find_register_protocol_by_name(pcilib_t *ctx, const char *name);
  86. pcilib_register_protocol_t pcilib_find_register_protocol(pcilib_t *ctx, const char *name);
  87. #ifdef __cplusplus
  88. }
  89. #endif
  90. #endif /* _PCILIB_BANK_H */