dv-bfin_evt.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /* Blackfin Event Vector Table (EVT) 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_cec.h"
  19. #include "dv-bfin_evt.h"
  20. struct bfin_evt
  21. {
  22. bu32 base;
  23. /* Order after here is important -- matches hardware MMR layout. */
  24. bu32 evt[16];
  25. };
  26. #define mmr_base() offsetof(struct bfin_evt, evt[0])
  27. #define mmr_offset(mmr) (offsetof(struct bfin_evt, mmr) - mmr_base())
  28. static const char * const mmr_names[] =
  29. {
  30. "EVT0", "EVT1", "EVT2", "EVT3", "EVT4", "EVT5", "EVT6", "EVT7", "EVT8",
  31. "EVT9", "EVT10", "EVT11", "EVT12", "EVT13", "EVT14", "EVT15",
  32. };
  33. #define mmr_name(off) mmr_names[(off) / 4]
  34. static unsigned
  35. bfin_evt_io_write_buffer (struct hw *me, const void *source,
  36. int space, address_word addr, unsigned nr_bytes)
  37. {
  38. struct bfin_evt *evt = hw_data (me);
  39. bu32 mmr_off;
  40. bu32 value;
  41. value = dv_load_4 (source);
  42. mmr_off = addr - evt->base;
  43. HW_TRACE_WRITE ();
  44. evt->evt[mmr_off / 4] = value;
  45. return nr_bytes;
  46. }
  47. static unsigned
  48. bfin_evt_io_read_buffer (struct hw *me, void *dest,
  49. int space, address_word addr, unsigned nr_bytes)
  50. {
  51. struct bfin_evt *evt = hw_data (me);
  52. bu32 mmr_off;
  53. bu32 value;
  54. mmr_off = addr - evt->base;
  55. HW_TRACE_READ ();
  56. value = evt->evt[mmr_off / 4];
  57. dv_store_4 (dest, value);
  58. return nr_bytes;
  59. }
  60. static void
  61. attach_bfin_evt_regs (struct hw *me, struct bfin_evt *evt)
  62. {
  63. address_word attach_address;
  64. int attach_space;
  65. unsigned attach_size;
  66. reg_property_spec reg;
  67. if (hw_find_property (me, "reg") == NULL)
  68. hw_abort (me, "Missing \"reg\" property");
  69. if (!hw_find_reg_array_property (me, "reg", 0, &reg))
  70. hw_abort (me, "\"reg\" property must contain three addr/size entries");
  71. hw_unit_address_to_attach_address (hw_parent (me),
  72. &reg.address,
  73. &attach_space, &attach_address, me);
  74. hw_unit_size_to_attach_size (hw_parent (me), &reg.size, &attach_size, me);
  75. if (attach_size != BFIN_COREMMR_EVT_SIZE)
  76. hw_abort (me, "\"reg\" size must be %#x", BFIN_COREMMR_EVT_SIZE);
  77. hw_attach_address (hw_parent (me),
  78. 0, attach_space, attach_address, attach_size, me);
  79. evt->base = attach_address;
  80. }
  81. static void
  82. bfin_evt_finish (struct hw *me)
  83. {
  84. struct bfin_evt *evt;
  85. evt = HW_ZALLOC (me, struct bfin_evt);
  86. set_hw_data (me, evt);
  87. set_hw_io_read_buffer (me, bfin_evt_io_read_buffer);
  88. set_hw_io_write_buffer (me, bfin_evt_io_write_buffer);
  89. attach_bfin_evt_regs (me, evt);
  90. }
  91. const struct hw_descriptor dv_bfin_evt_descriptor[] =
  92. {
  93. {"bfin_evt", bfin_evt_finish,},
  94. {NULL, NULL},
  95. };
  96. #define EVT_STATE(cpu) DV_STATE_CACHED (cpu, evt)
  97. void
  98. cec_set_evt (SIM_CPU *cpu, int ivg, bu32 handler_addr)
  99. {
  100. if (ivg > IVG15 || ivg < 0)
  101. sim_io_error (CPU_STATE (cpu), "%s: ivg %i out of range !", __func__, ivg);
  102. EVT_STATE (cpu)->evt[ivg] = handler_addr;
  103. }
  104. bu32
  105. cec_get_evt (SIM_CPU *cpu, int ivg)
  106. {
  107. if (ivg > IVG15 || ivg < 0)
  108. sim_io_error (CPU_STATE (cpu), "%s: ivg %i out of range !", __func__, ivg);
  109. return EVT_STATE (cpu)->evt[ivg];
  110. }
  111. bu32
  112. cec_get_reset_evt (SIM_CPU *cpu)
  113. {
  114. /* XXX: This should tail into the model to get via BMODE pins. */
  115. return 0xef000000;
  116. }