dv-bfin_ebiu_sdc.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /* Blackfin External Bus Interface Unit (EBIU) SDRAM Controller (SDC) Model.
  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. #include "config.h"
  16. #include "sim-main.h"
  17. #include "devices.h"
  18. #include "dv-bfin_ebiu_sdc.h"
  19. struct bfin_ebiu_sdc
  20. {
  21. bu32 base;
  22. int type;
  23. bu32 reg_size, bank_size;
  24. /* Order after here is important -- matches hardware MMR layout. */
  25. bu32 sdgctl;
  26. bu32 sdbctl; /* 16bit on most parts ... */
  27. bu16 BFIN_MMR_16(sdrrc);
  28. bu16 BFIN_MMR_16(sdstat);
  29. };
  30. #define mmr_base() offsetof(struct bfin_ebiu_sdc, sdgctl)
  31. #define mmr_offset(mmr) (offsetof(struct bfin_ebiu_sdc, mmr) - mmr_base())
  32. static const char * const mmr_names[] =
  33. {
  34. "EBIU_SDGCTL", "EBIU_SDBCTL", "EBIU_SDRRC", "EBIU_SDSTAT",
  35. };
  36. #define mmr_name(off) mmr_names[(off) / 4]
  37. static unsigned
  38. bfin_ebiu_sdc_io_write_buffer (struct hw *me, const void *source,
  39. int space, address_word addr, unsigned nr_bytes)
  40. {
  41. struct bfin_ebiu_sdc *sdc = hw_data (me);
  42. bu32 mmr_off;
  43. bu32 value;
  44. bu16 *value16p;
  45. bu32 *value32p;
  46. void *valuep;
  47. if (nr_bytes == 4)
  48. value = dv_load_4 (source);
  49. else
  50. value = dv_load_2 (source);
  51. mmr_off = addr - sdc->base;
  52. valuep = (void *)((unsigned long)sdc + mmr_base() + mmr_off);
  53. value16p = valuep;
  54. value32p = valuep;
  55. HW_TRACE_WRITE ();
  56. switch (mmr_off)
  57. {
  58. case mmr_offset(sdgctl):
  59. /* XXX: SRFS should make external mem unreadable. */
  60. *value32p = value;
  61. break;
  62. case mmr_offset(sdbctl):
  63. if (sdc->type == 561)
  64. {
  65. dv_bfin_mmr_require_32 (me, addr, nr_bytes, true);
  66. *value32p = value;
  67. }
  68. else
  69. {
  70. dv_bfin_mmr_require_16 (me, addr, nr_bytes, true);
  71. *value16p = value;
  72. }
  73. break;
  74. case mmr_offset(sdrrc):
  75. dv_bfin_mmr_require_16 (me, addr, nr_bytes, true);
  76. *value16p = value;
  77. break;
  78. case mmr_offset(sdstat):
  79. dv_bfin_mmr_require_16 (me, addr, nr_bytes, true);
  80. /* XXX: Some bits are W1C ... */
  81. break;
  82. }
  83. return nr_bytes;
  84. }
  85. static unsigned
  86. bfin_ebiu_sdc_io_read_buffer (struct hw *me, void *dest,
  87. int space, address_word addr, unsigned nr_bytes)
  88. {
  89. struct bfin_ebiu_sdc *sdc = hw_data (me);
  90. bu32 mmr_off;
  91. bu32 *value32p;
  92. bu16 *value16p;
  93. void *valuep;
  94. mmr_off = addr - sdc->base;
  95. valuep = (void *)((unsigned long)sdc + mmr_base() + mmr_off);
  96. value16p = valuep;
  97. value32p = valuep;
  98. HW_TRACE_READ ();
  99. switch (mmr_off)
  100. {
  101. case mmr_offset(sdgctl):
  102. dv_store_4 (dest, *value32p);
  103. break;
  104. case mmr_offset(sdbctl):
  105. if (sdc->type == 561)
  106. {
  107. dv_bfin_mmr_require_32 (me, addr, nr_bytes, false);
  108. dv_store_4 (dest, *value32p);
  109. }
  110. else
  111. {
  112. dv_bfin_mmr_require_16 (me, addr, nr_bytes, false);
  113. dv_store_2 (dest, *value16p);
  114. }
  115. break;
  116. case mmr_offset(sdrrc):
  117. case mmr_offset(sdstat):
  118. dv_bfin_mmr_require_16 (me, addr, nr_bytes, false);
  119. dv_store_2 (dest, *value16p);
  120. break;
  121. }
  122. return nr_bytes;
  123. }
  124. static void
  125. attach_bfin_ebiu_sdc_regs (struct hw *me, struct bfin_ebiu_sdc *sdc)
  126. {
  127. address_word attach_address;
  128. int attach_space;
  129. unsigned attach_size;
  130. reg_property_spec reg;
  131. if (hw_find_property (me, "reg") == NULL)
  132. hw_abort (me, "Missing \"reg\" property");
  133. if (!hw_find_reg_array_property (me, "reg", 0, &reg))
  134. hw_abort (me, "\"reg\" property must contain three addr/size entries");
  135. hw_unit_address_to_attach_address (hw_parent (me),
  136. &reg.address,
  137. &attach_space, &attach_address, me);
  138. hw_unit_size_to_attach_size (hw_parent (me), &reg.size, &attach_size, me);
  139. if (attach_size != BFIN_MMR_EBIU_SDC_SIZE)
  140. hw_abort (me, "\"reg\" size must be %#x", BFIN_MMR_EBIU_SDC_SIZE);
  141. hw_attach_address (hw_parent (me),
  142. 0, attach_space, attach_address, attach_size, me);
  143. sdc->base = attach_address;
  144. }
  145. static void
  146. bfin_ebiu_sdc_finish (struct hw *me)
  147. {
  148. struct bfin_ebiu_sdc *sdc;
  149. sdc = HW_ZALLOC (me, struct bfin_ebiu_sdc);
  150. set_hw_data (me, sdc);
  151. set_hw_io_read_buffer (me, bfin_ebiu_sdc_io_read_buffer);
  152. set_hw_io_write_buffer (me, bfin_ebiu_sdc_io_write_buffer);
  153. attach_bfin_ebiu_sdc_regs (me, sdc);
  154. sdc->type = hw_find_integer_property (me, "type");
  155. /* Initialize the SDC. */
  156. sdc->sdgctl = 0xE0088849;
  157. sdc->sdbctl = 0x00000000;
  158. sdc->sdrrc = 0x081A;
  159. sdc->sdstat = 0x0008;
  160. /* XXX: We boot with 64M external memory by default ... */
  161. sdc->sdbctl |= EBE | EBSZ_64 | EBCAW_10;
  162. }
  163. const struct hw_descriptor dv_bfin_ebiu_sdc_descriptor[] =
  164. {
  165. {"bfin_ebiu_sdc", bfin_ebiu_sdc_finish,},
  166. {NULL, NULL},
  167. };