hw_core.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /* This file is part of the program psim.
  2. Copyright (C) 1994-1996, Andrew Cagney <cagney@highland.com.au>
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #ifndef _HW_CORE_C_
  15. #define _HW_CORE_C_
  16. #include "device_table.h"
  17. #include "corefile.h"
  18. /* DEVICE
  19. core - root of the device tree
  20. DESCRIPTION
  21. The core device positioned at the root of the device tree appears
  22. to its child devices as a normal device just like every other
  23. device in the tree.
  24. Internally it is implemented using a core object. Requests to
  25. attach (or detach) address spaces are passed to that core object.
  26. Requests to transfer (DMA) data are reflected back down the device
  27. tree using the core_map data transfer methods.
  28. PROPERTIES
  29. None.
  30. */
  31. static void
  32. hw_core_init_address_callback(device *me)
  33. {
  34. core *memory = (core*)device_data(me);
  35. core_init(memory);
  36. }
  37. static void
  38. hw_core_attach_address_callback(device *me,
  39. attach_type attach,
  40. int space,
  41. unsigned_word addr,
  42. unsigned nr_bytes,
  43. access_type access,
  44. device *client) /*callback/default*/
  45. {
  46. core *memory = (core*)device_data(me);
  47. if (space != 0)
  48. error("core_attach_address_callback() invalid address space\n");
  49. core_attach(memory,
  50. attach,
  51. space,
  52. access,
  53. addr,
  54. nr_bytes,
  55. client);
  56. }
  57. static unsigned
  58. hw_core_dma_read_buffer_callback(device *me,
  59. void *dest,
  60. int space,
  61. unsigned_word addr,
  62. unsigned nr_bytes)
  63. {
  64. core *memory = (core*)device_data(me);
  65. return core_map_read_buffer(core_readable(memory),
  66. dest,
  67. addr,
  68. nr_bytes);
  69. }
  70. static unsigned
  71. hw_core_dma_write_buffer_callback(device *me,
  72. const void *source,
  73. int space,
  74. unsigned_word addr,
  75. unsigned nr_bytes,
  76. int violate_read_only_section)
  77. {
  78. core *memory = (core*)device_data(me);
  79. core_map *map = (violate_read_only_section
  80. ? core_readable(memory)
  81. : core_writeable(memory));
  82. return core_map_write_buffer(map,
  83. source,
  84. addr,
  85. nr_bytes);
  86. }
  87. static device_callbacks const hw_core_callbacks = {
  88. { hw_core_init_address_callback, },
  89. { hw_core_attach_address_callback, },
  90. { NULL, }, /* IO */
  91. { hw_core_dma_read_buffer_callback,
  92. hw_core_dma_write_buffer_callback, },
  93. { NULL, }, /* interrupt */
  94. { generic_device_unit_decode,
  95. generic_device_unit_encode,
  96. generic_device_address_to_attach_address,
  97. generic_device_size_to_attach_size, },
  98. };
  99. static void *
  100. hw_core_create(const char *name,
  101. const device_unit *unit_address,
  102. const char *args)
  103. {
  104. core *memory = core_create();
  105. return memory;
  106. }
  107. const device_descriptor hw_core_device_descriptor[] = {
  108. { "core", hw_core_create, &hw_core_callbacks },
  109. { NULL },
  110. };
  111. #endif /* _HW_CORE_C_ */