device_table.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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 _DEVICE_TABLE_H_
  15. #define _DEVICE_TABLE_H_
  16. #include "basics.h"
  17. #include "device.h"
  18. #include "tree.h"
  19. #include <string.h>
  20. typedef struct _device_callbacks device_callbacks;
  21. /* The creator, returns a pointer to any data that should be allocated
  22. once during (multiple) simulation runs */
  23. typedef void *(device_creator)
  24. (const char *name,
  25. const device_unit *unit_address,
  26. const char *args);
  27. /* two stages of initialization */
  28. typedef void (device_init_callback)
  29. (device *me);
  30. typedef struct _device_init_callbacks {
  31. device_init_callback *address; /* NULL - ignore */
  32. device_init_callback *data; /* NULL - ignore */
  33. } device_init_callbacks;
  34. /* attaching/detaching a devices address space to its parent */
  35. typedef void (device_address_callback)
  36. (device *me,
  37. attach_type attach,
  38. int space,
  39. unsigned_word addr,
  40. unsigned nr_bytes,
  41. access_type access,
  42. device *client); /*callback/default*/
  43. typedef struct _device_address_callbacks {
  44. device_address_callback *attach;
  45. device_address_callback *detach;
  46. } device_address_callbacks;
  47. /* I/O operations - from parent */
  48. typedef unsigned (device_io_read_buffer_callback)
  49. (device *me,
  50. void *dest,
  51. int space,
  52. unsigned_word addr,
  53. unsigned nr_bytes,
  54. cpu *processor,
  55. unsigned_word cia);
  56. typedef unsigned (device_io_write_buffer_callback)
  57. (device *me,
  58. const void *source,
  59. int space,
  60. unsigned_word addr,
  61. unsigned nr_bytes,
  62. cpu *processor,
  63. unsigned_word cia);
  64. typedef struct _device_io_callbacks { /* NULL - error */
  65. device_io_read_buffer_callback *read_buffer;
  66. device_io_write_buffer_callback *write_buffer;
  67. } device_io_callbacks;
  68. /* DMA transfers by a device via its parent */
  69. typedef unsigned (device_dma_read_buffer_callback)
  70. (device *me,
  71. void *dest,
  72. int space,
  73. unsigned_word addr,
  74. unsigned nr_bytes);
  75. typedef unsigned (device_dma_write_buffer_callback)
  76. (device *me,
  77. const void *source,
  78. int space,
  79. unsigned_word addr,
  80. unsigned nr_bytes,
  81. int violate_read_only_section);
  82. typedef struct _device_dma_callbacks { /* NULL - error */
  83. device_dma_read_buffer_callback *read_buffer;
  84. device_dma_write_buffer_callback *write_buffer;
  85. } device_dma_callbacks;
  86. /* Interrupts */
  87. typedef void (device_interrupt_event_callback)
  88. (device *me,
  89. int my_port,
  90. device *source,
  91. int source_port,
  92. int level,
  93. cpu *processor,
  94. unsigned_word cia);
  95. typedef void (device_child_interrupt_event_callback)
  96. (device *me,
  97. device *parent,
  98. device *source,
  99. int source_port,
  100. int level,
  101. cpu *processor,
  102. unsigned_word cia);
  103. typedef struct _device_interrupt_port_descriptor {
  104. const char *name;
  105. int number;
  106. int nr_ports;
  107. port_direction direction;
  108. } device_interrupt_port_descriptor;
  109. typedef struct _device_interrupt_callbacks {
  110. device_interrupt_event_callback *event;
  111. device_child_interrupt_event_callback *child_event;
  112. const device_interrupt_port_descriptor *ports;
  113. } device_interrupt_callbacks;
  114. /* symbolic value decoding */
  115. typedef int (device_unit_decode_callback)
  116. (device *bus,
  117. const char *unit,
  118. device_unit *address);
  119. typedef int (device_unit_encode_callback)
  120. (device *bus,
  121. const device_unit *unit_address,
  122. char *buf,
  123. int sizeof_buf);
  124. typedef int (device_address_to_attach_address_callback)
  125. (device *bus,
  126. const device_unit *address,
  127. int *attach_space,
  128. unsigned_word *attach_address,
  129. device *client);
  130. typedef int (device_size_to_attach_size_callback)
  131. (device *bus,
  132. const device_unit *size,
  133. unsigned *nr_bytes,
  134. device *client);
  135. typedef struct _device_convert_callbacks {
  136. device_unit_decode_callback *decode_unit;
  137. device_unit_encode_callback *encode_unit;
  138. device_address_to_attach_address_callback *address_to_attach_address;
  139. device_size_to_attach_size_callback *size_to_attach_size;
  140. } device_convert_callbacks;
  141. /* instances */
  142. typedef void (device_instance_delete_callback)
  143. (device_instance *instance);
  144. typedef int (device_instance_read_callback)
  145. (device_instance *instance,
  146. void *buf,
  147. unsigned_word len);
  148. typedef int (device_instance_write_callback)
  149. (device_instance *instance,
  150. const void *buf,
  151. unsigned_word len);
  152. typedef int (device_instance_seek_callback)
  153. (device_instance *instance,
  154. unsigned_word pos_hi,
  155. unsigned_word pos_lo);
  156. typedef int (device_instance_method)
  157. (device_instance *instance,
  158. int n_stack_args,
  159. unsigned_cell stack_args[/*n_stack_args*/],
  160. int n_stack_returns,
  161. unsigned_cell stack_returns[/*n_stack_returns*/]);
  162. typedef struct _device_instance_methods {
  163. const char *name;
  164. device_instance_method *method;
  165. } device_instance_methods;
  166. struct _device_instance_callbacks { /* NULL - error */
  167. device_instance_delete_callback *delete;
  168. device_instance_read_callback *read;
  169. device_instance_write_callback *write;
  170. device_instance_seek_callback *seek;
  171. const device_instance_methods *methods;
  172. };
  173. typedef device_instance *(device_create_instance_callback)
  174. (device *me,
  175. const char *full_path,
  176. const char *args);
  177. typedef device_instance *(package_create_instance_callback)
  178. (device_instance *parent,
  179. const char *args);
  180. /* all else fails */
  181. typedef int (device_ioctl_callback)
  182. (device *me,
  183. cpu *processor,
  184. unsigned_word cia,
  185. device_ioctl_request request,
  186. va_list ap);
  187. typedef void (device_usage_callback)
  188. (int verbose);
  189. /* the callbacks */
  190. struct _device_callbacks {
  191. /* initialization */
  192. device_init_callbacks init;
  193. /* address/data config - from child */
  194. device_address_callbacks address;
  195. /* address/data transfer - from parent */
  196. device_io_callbacks io;
  197. /* address/data transfer - from child */
  198. device_dma_callbacks dma;
  199. /* interrupt signalling */
  200. device_interrupt_callbacks interrupt;
  201. /* bus address decoding */
  202. device_convert_callbacks convert;
  203. /* instances */
  204. device_create_instance_callback *instance_create;
  205. /* back door to anything we've forgot */
  206. device_ioctl_callback *ioctl;
  207. device_usage_callback *usage;
  208. };
  209. /* Table of all the devices and a function to lookup/create a device
  210. from its name */
  211. typedef struct _device_descriptor device_descriptor;
  212. struct _device_descriptor {
  213. const char *name;
  214. device_creator *creator;
  215. const device_callbacks *callbacks;
  216. };
  217. extern const device_descriptor *const device_table[];
  218. #include "hw.h"
  219. /* Pass through, ignore and generic callback functions. A call going
  220. towards the root device are passed on up, local calls are ignored
  221. and call downs abort */
  222. extern device_address_callback passthrough_device_address_attach;
  223. extern device_address_callback passthrough_device_address_detach;
  224. extern device_dma_read_buffer_callback passthrough_device_dma_read_buffer;
  225. extern device_dma_write_buffer_callback passthrough_device_dma_write_buffer;
  226. extern device_unit_decode_callback ignore_device_unit_decode;
  227. extern device_init_callback generic_device_init_address;
  228. extern device_unit_decode_callback generic_device_unit_decode;
  229. extern device_unit_encode_callback generic_device_unit_encode;
  230. extern device_address_to_attach_address_callback generic_device_address_to_attach_address;
  231. extern device_size_to_attach_size_callback generic_device_size_to_attach_size;
  232. extern const device_callbacks passthrough_device_callbacks;
  233. #endif /* _DEVICE_TABLE_H_ */