devices.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* Blackfin device support.
  2. Copyright (C) 2010-2022 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. /* This must come before any other includes. */
  16. #include "defs.h"
  17. #include "sim-main.h"
  18. #include "sim-hw.h"
  19. #include "hw-device.h"
  20. #include "devices.h"
  21. #include "dv-bfin_cec.h"
  22. #include "dv-bfin_mmu.h"
  23. static void
  24. bfin_mmr_invalid (struct hw *me, address_word addr,
  25. unsigned nr_bytes, bool write, bool missing)
  26. {
  27. SIM_CPU *cpu = hw_system_cpu (me);
  28. const char *rw = write ? "write" : "read";
  29. const char *reason =
  30. missing ? "no such register" :
  31. (addr & 3) ? "must be 32-bit aligned" : "invalid length";
  32. /* Only throw a fit if the cpu is doing the access. DMA/GDB simply
  33. go unnoticed. Not exactly hardware behavior, but close enough. */
  34. if (!cpu)
  35. {
  36. sim_io_eprintf (hw_system (me),
  37. "%s: invalid MMR %s at %#x length %u: %s\n",
  38. hw_path (me), rw, addr, nr_bytes, reason);
  39. return;
  40. }
  41. HW_TRACE ((me, "invalid MMR %s at %#x length %u: %s",
  42. rw, addr, nr_bytes, reason));
  43. /* XXX: is this what hardware does ? What about priority of unaligned vs
  44. wrong length vs missing register ? What about system-vs-core ? */
  45. /* XXX: We should move this addr check to a model property so we get the
  46. same behavior regardless of where we map the model. */
  47. if (addr >= BFIN_CORE_MMR_BASE)
  48. /* XXX: This should be setting up CPLB fault addrs ? */
  49. mmu_process_fault (cpu, addr, write, false, false, true);
  50. else
  51. /* XXX: Newer parts set up an interrupt from EBIU and program
  52. EBIU_ERRADDR with the address. */
  53. cec_hwerr (cpu, HWERR_SYSTEM_MMR);
  54. }
  55. void
  56. dv_bfin_mmr_invalid (struct hw *me, address_word addr, unsigned nr_bytes,
  57. bool write)
  58. {
  59. bfin_mmr_invalid (me, addr, nr_bytes, write, true);
  60. }
  61. bool
  62. dv_bfin_mmr_require (struct hw *me, address_word addr, unsigned nr_bytes,
  63. unsigned size, bool write)
  64. {
  65. if ((addr & 0x3) == 0 && nr_bytes == size)
  66. return true;
  67. bfin_mmr_invalid (me, addr, nr_bytes, write, false);
  68. return false;
  69. }
  70. /* For 32-bit memory mapped registers that allow 16-bit or 32-bit access. */
  71. bool
  72. dv_bfin_mmr_require_16_32 (struct hw *me, address_word addr, unsigned nr_bytes,
  73. bool write)
  74. {
  75. if ((addr & 0x3) == 0 && (nr_bytes == 2 || nr_bytes == 4))
  76. return true;
  77. bfin_mmr_invalid (me, addr, nr_bytes, write, false);
  78. return false;
  79. }
  80. unsigned int dv_get_bus_num (struct hw *me)
  81. {
  82. const hw_unit *unit = hw_unit_address (me);
  83. return unit->cells[unit->nr_cells - 1];
  84. }