1 /* This file is part of the program psim.
3 Copyright (C) 1994-1996, Andrew Cagney <cagney@highland.com.au>
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.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, see <http://www.gnu.org/licenses/>.
21 #ifndef _DEVICE_TABLE_H_
22 #define _DEVICE_TABLE_H_
37 typedef struct _device_callbacks device_callbacks;
40 /* The creator, returns a pointer to any data that should be allocated
41 once during (multiple) simulation runs */
43 typedef void *(device_creator)
45 const device_unit *unit_address,
49 /* two stages of initialization */
51 typedef void (device_init_callback)
54 typedef struct _device_init_callbacks {
55 device_init_callback *address; /* NULL - ignore */
56 device_init_callback *data; /* NULL - ignore */
57 } device_init_callbacks;
60 /* attaching/detaching a devices address space to its parent */
62 typedef void (device_address_callback)
69 device *client); /*callback/default*/
71 typedef struct _device_address_callbacks {
72 device_address_callback *attach;
73 device_address_callback *detach;
74 } device_address_callbacks;
77 /* I/O operations - from parent */
79 typedef unsigned (device_io_read_buffer_callback)
88 typedef unsigned (device_io_write_buffer_callback)
97 typedef struct _device_io_callbacks { /* NULL - error */
98 device_io_read_buffer_callback *read_buffer;
99 device_io_write_buffer_callback *write_buffer;
100 } device_io_callbacks;
103 /* DMA transfers by a device via its parent */
105 typedef unsigned (device_dma_read_buffer_callback)
112 typedef unsigned (device_dma_write_buffer_callback)
118 int violate_read_only_section);
120 typedef struct _device_dma_callbacks { /* NULL - error */
121 device_dma_read_buffer_callback *read_buffer;
122 device_dma_write_buffer_callback *write_buffer;
123 } device_dma_callbacks;
128 typedef void (device_interrupt_event_callback)
137 typedef void (device_child_interrupt_event_callback)
146 typedef struct _device_interrupt_port_descriptor {
150 port_direction direction;
151 } device_interrupt_port_descriptor;
153 typedef struct _device_interrupt_callbacks {
154 device_interrupt_event_callback *event;
155 device_child_interrupt_event_callback *child_event;
156 const device_interrupt_port_descriptor *ports;
157 } device_interrupt_callbacks;
160 /* symbolic value decoding */
162 typedef int (device_unit_decode_callback)
165 device_unit *address);
167 typedef int (device_unit_encode_callback)
169 const device_unit *unit_address,
173 typedef int (device_address_to_attach_address_callback)
175 const device_unit *address,
177 unsigned_word *attach_address,
180 typedef int (device_size_to_attach_size_callback)
182 const device_unit *size,
186 typedef struct _device_convert_callbacks {
187 device_unit_decode_callback *decode_unit;
188 device_unit_encode_callback *encode_unit;
189 device_address_to_attach_address_callback *address_to_attach_address;
190 device_size_to_attach_size_callback *size_to_attach_size;
191 } device_convert_callbacks;
196 typedef void (device_instance_delete_callback)
197 (device_instance *instance);
199 typedef int (device_instance_read_callback)
200 (device_instance *instance,
204 typedef int (device_instance_write_callback)
205 (device_instance *instance,
209 typedef int (device_instance_seek_callback)
210 (device_instance *instance,
211 unsigned_word pos_hi,
212 unsigned_word pos_lo);
214 typedef int (device_instance_method)
215 (device_instance *instance,
217 unsigned_cell stack_args[/*n_stack_args*/],
219 unsigned_cell stack_returns[/*n_stack_returns*/]);
221 typedef struct _device_instance_methods {
223 device_instance_method *method;
224 } device_instance_methods;
226 struct _device_instance_callbacks { /* NULL - error */
227 device_instance_delete_callback *delete;
228 device_instance_read_callback *read;
229 device_instance_write_callback *write;
230 device_instance_seek_callback *seek;
231 const device_instance_methods *methods;
234 typedef device_instance *(device_create_instance_callback)
236 const char *full_path,
239 typedef device_instance *(package_create_instance_callback)
240 (device_instance *parent,
246 typedef int (device_ioctl_callback)
250 device_ioctl_request request,
253 typedef void (device_usage_callback)
259 struct _device_callbacks {
262 device_init_callbacks init;
264 /* address/data config - from child */
265 device_address_callbacks address;
267 /* address/data transfer - from parent */
268 device_io_callbacks io;
270 /* address/data transfer - from child */
271 device_dma_callbacks dma;
273 /* interrupt signalling */
274 device_interrupt_callbacks interrupt;
276 /* bus address decoding */
277 device_convert_callbacks convert;
280 device_create_instance_callback *instance_create;
282 /* back door to anything we've forgot */
283 device_ioctl_callback *ioctl;
284 device_usage_callback *usage;
288 /* Table of all the devices and a function to lookup/create a device
291 typedef struct _device_descriptor device_descriptor;
292 struct _device_descriptor {
294 device_creator *creator;
295 const device_callbacks *callbacks;
298 extern const device_descriptor *const device_table[];
302 /* Pass through, ignore and generic callback functions. A call going
303 towards the root device are passed on up, local calls are ignored
304 and call downs abort */
306 extern device_address_callback passthrough_device_address_attach;
307 extern device_address_callback passthrough_device_address_detach;
308 extern device_dma_read_buffer_callback passthrough_device_dma_read_buffer;
309 extern device_dma_write_buffer_callback passthrough_device_dma_write_buffer;
311 extern device_unit_decode_callback ignore_device_unit_decode;
313 extern device_init_callback generic_device_init_address;
314 extern device_unit_decode_callback generic_device_unit_decode;
315 extern device_unit_encode_callback generic_device_unit_encode;
316 extern device_address_to_attach_address_callback generic_device_address_to_attach_address;
317 extern device_size_to_attach_size_callback generic_device_size_to_attach_size;
320 extern const device_callbacks passthrough_device_callbacks;
322 #endif /* _DEVICE_TABLE_H_ */