device_table.h 8.3 KB

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