devices.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /* Common Blackfin device stuff.
  2. Copyright (C) 2010-2015 Free Software Foundation, Inc.
  3. Contributed by Analog Devices, Inc.
  4. This file is part of simulators.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  15. #ifndef DEVICES_H
  16. #define DEVICES_H
  17. #include "hw-base.h"
  18. #include "hw-main.h"
  19. #include "hw-device.h"
  20. #include "hw-tree.h"
  21. /* We keep the same inital structure layout with DMA enabled devices. */
  22. struct dv_bfin {
  23. bu32 base;
  24. struct hw *dma_master;
  25. bool acked;
  26. };
  27. #define BFIN_MMR_16(mmr) mmr, __pad_##mmr
  28. /* Most peripherals have either one interrupt or these three. */
  29. #define DV_PORT_TX 0
  30. #define DV_PORT_RX 1
  31. #define DV_PORT_STAT 2
  32. unsigned int dv_get_bus_num (struct hw *);
  33. static inline bu8 dv_load_1 (const void *ptr)
  34. {
  35. const unsigned char *c = ptr;
  36. return c[0];
  37. }
  38. static inline void dv_store_1 (void *ptr, bu8 val)
  39. {
  40. unsigned char *c = ptr;
  41. c[0] = val;
  42. }
  43. static inline bu16 dv_load_2 (const void *ptr)
  44. {
  45. const unsigned char *c = ptr;
  46. return (c[1] << 8) | dv_load_1 (ptr);
  47. }
  48. static inline void dv_store_2 (void *ptr, bu16 val)
  49. {
  50. unsigned char *c = ptr;
  51. c[1] = val >> 8;
  52. dv_store_1 (ptr, val);
  53. }
  54. static inline bu32 dv_load_4 (const void *ptr)
  55. {
  56. const unsigned char *c = ptr;
  57. return (c[3] << 24) | (c[2] << 16) | dv_load_2 (ptr);
  58. }
  59. static inline void dv_store_4 (void *ptr, bu32 val)
  60. {
  61. unsigned char *c = ptr;
  62. c[3] = val >> 24;
  63. c[2] = val >> 16;
  64. dv_store_2 (ptr, val);
  65. }
  66. /* Helpers for MMRs where only the specified bits are W1C. The
  67. rest are left unmodified. */
  68. #define dv_w1c(ptr, val, bits) (*(ptr) &= ~((val) & (bits)))
  69. static inline void dv_w1c_2 (bu16 *ptr, bu16 val, bu16 bits)
  70. {
  71. dv_w1c (ptr, val, bits);
  72. }
  73. static inline void dv_w1c_4 (bu32 *ptr, bu32 val, bu32 bits)
  74. {
  75. dv_w1c (ptr, val, bits);
  76. }
  77. /* Helpers for MMRs where all bits are RW except for the specified
  78. bits -- those ones are W1C. */
  79. #define dv_w1c_partial(ptr, val, bits) \
  80. (*(ptr) = ((val) | (*(ptr) & (bits))) & ~((val) & (bits)))
  81. static inline void dv_w1c_2_partial (bu16 *ptr, bu16 val, bu16 bits)
  82. {
  83. dv_w1c_partial (ptr, val, bits);
  84. }
  85. static inline void dv_w1c_4_partial (bu32 *ptr, bu32 val, bu32 bits)
  86. {
  87. dv_w1c_partial (ptr, val, bits);
  88. }
  89. /* XXX: Grubbing around in device internals is probably wrong, but
  90. until someone shows me what's right ... */
  91. static inline struct hw *
  92. dv_get_device (SIM_CPU *cpu, const char *device_name)
  93. {
  94. SIM_DESC sd = CPU_STATE (cpu);
  95. void *root = STATE_HW (sd);
  96. return hw_tree_find_device (root, device_name);
  97. }
  98. static inline void *
  99. dv_get_state (SIM_CPU *cpu, const char *device_name)
  100. {
  101. return hw_data (dv_get_device (cpu, device_name));
  102. }
  103. #define DV_STATE(cpu, dv) dv_get_state (cpu, "/core/bfin_"#dv)
  104. #define DV_STATE_CACHED(cpu, dv) \
  105. ({ \
  106. struct bfin_##dv *__##dv = BFIN_CPU_STATE.dv##_cache; \
  107. if (!__##dv) \
  108. BFIN_CPU_STATE.dv##_cache = __##dv = dv_get_state (cpu, "/core/bfin_"#dv); \
  109. __##dv; \
  110. })
  111. void dv_bfin_mmr_invalid (struct hw *, address_word, unsigned nr_bytes, bool write);
  112. void dv_bfin_mmr_require (struct hw *, address_word, unsigned nr_bytes, unsigned size, bool write);
  113. bool dv_bfin_mmr_check (struct hw *, address_word, unsigned nr_bytes, bool write);
  114. #define dv_bfin_mmr_require_16(hw, addr, nr_bytes, write) dv_bfin_mmr_require (hw, addr, nr_bytes, 2, write)
  115. #define dv_bfin_mmr_require_32(hw, addr, nr_bytes, write) dv_bfin_mmr_require (hw, addr, nr_bytes, 4, write)
  116. #define HW_TRACE_WRITE() \
  117. HW_TRACE ((me, "write 0x%08lx (%s) length %u with 0x%x", \
  118. (unsigned long) addr, mmr_name (mmr_off), nr_bytes, value))
  119. #define HW_TRACE_READ() \
  120. HW_TRACE ((me, "read 0x%08lx (%s) length %u", \
  121. (unsigned long) addr, mmr_name (mmr_off), nr_bytes))
  122. #define HW_TRACE_DMA_WRITE() \
  123. HW_TRACE ((me, "dma write 0x%08lx length %u", \
  124. (unsigned long) addr, nr_bytes))
  125. #define HW_TRACE_DMA_READ() \
  126. HW_TRACE ((me, "dma read 0x%08lx length %u", \
  127. (unsigned long) addr, nr_bytes))
  128. #endif