ra_common.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright (C) 2021 Alibaba Group Holding Limited
  3. * Author: LuChongzhi <chongzhi.lcz@alibaba-inc.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. */
  9. #ifndef __RA_COMMON_H__
  10. #define __RA_COMMON_H__
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <stdint.h>
  14. #include <unistd.h>
  15. #include <string.h>
  16. #define INVALID_MAGIC32 0xDEADBEEF
  17. #define LINE_PADDING_6TAB "\n\t\t\t\t\t\t "
  18. #define LINE_PADDING_9TAB "\n\t\t\t\t\t\t\t\t\t "
  19. typedef struct {
  20. char *reg_name; /* Register name, can be null if it exists above, should <=24 chars */
  21. char *reg_desc; /* Register description, can be null if not exists */
  22. uint32_t offset; /* Register offset address */
  23. uint32_t reset_value; /* Register reset value */
  24. uint32_t msb; /* MSB for this field [31..0] */
  25. uint32_t lsb; /* LSB for this field [31..0] */
  26. char *field_name; /* Register field name */
  27. char *field_desc; /* Field description */
  28. } reg_field_s;
  29. /*
  30. For example:
  31. static const reg_field_s demo_reg_desc[] = {
  32. {"Demo reg", 0x10, "Demo field1", 15, 0, "This is demo reg's demo field1"},
  33. {NULL, 0x10, "Demo field2", 31, 16, "This is demo reg's demo field2"},
  34. };
  35. */
  36. typedef struct {
  37. char *ip_name;
  38. uint64_t ip_phy_addr;
  39. } ip_phy_addr_s;
  40. typedef enum {
  41. RA_OP_INVALID = -1,
  42. RA_OP_SHOW_DUMP = 0,
  43. RA_OP_SHOW_REG_DEFINE,
  44. RA_OP_FIND_REG,
  45. } ra_op_e;
  46. typedef struct {
  47. char module_name[64];
  48. uint32_t reg_offset;
  49. uint32_t reg_value;
  50. char reg_name[128];
  51. char field_name[128];
  52. ra_op_e operate;
  53. } reg_analyzer_info_s;
  54. void _dump_ra_info(reg_analyzer_info_s *ra_info);
  55. int ra_dump_reg_fields(reg_analyzer_info_s *ra_info,
  56. const reg_field_s reg_field[], const uint32_t reg_field_count);
  57. int ra_dump_reg_define(reg_analyzer_info_s *ra_info,
  58. const reg_field_s reg_field[], const uint32_t reg_field_count);
  59. int ra_dump_reg_find(reg_analyzer_info_s *ra_info,
  60. const reg_field_s reg_field[], const uint32_t reg_field_count);
  61. ///////////////////////////////////////
  62. typedef int (*module_reg_dump)(reg_analyzer_info_s *ra_info);
  63. typedef int (*module_reg_define)(reg_analyzer_info_s *ra_info);
  64. typedef int (*module_reg_find)(reg_analyzer_info_s *ra_info);
  65. typedef struct {
  66. const char *module_name;
  67. module_reg_dump reg_dump;
  68. module_reg_define reg_define;
  69. module_reg_find reg_find;
  70. } module_instance_t;
  71. int ra_search_reg_by_offset(reg_analyzer_info_s *ra_info);
  72. int ra_search_reg_by_name(reg_analyzer_info_s *ra_info);
  73. //////////////////////////////////////
  74. char *strlwr(char *str);
  75. void str_replace(char * cp, int n, char * str);
  76. int stricmp(const char* p1, const char* p2);
  77. char* stristr(const char* haystack, const char* needle);
  78. #endif /* __RA_COMMON_H__ */