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_
31 typedef struct _device_callbacks device_callbacks
;
34 /* The creator, returns a pointer to any data that should be allocated
35 once during (multiple) simulation runs */
37 typedef void *(device_creator
)
39 const device_unit
*unit_address
,
43 /* two stages of initialization */
45 typedef void (device_init_callback
)
48 typedef struct _device_init_callbacks
{
49 device_init_callback
*address
; /* NULL - ignore */
50 device_init_callback
*data
; /* NULL - ignore */
51 } device_init_callbacks
;
54 /* attaching/detaching a devices address space to its parent */
56 typedef void (device_address_callback
)
63 device
*client
); /*callback/default*/
65 typedef struct _device_address_callbacks
{
66 device_address_callback
*attach
;
67 device_address_callback
*detach
;
68 } device_address_callbacks
;
71 /* I/O operations - from parent */
73 typedef unsigned (device_io_read_buffer_callback
)
82 typedef unsigned (device_io_write_buffer_callback
)
91 typedef struct _device_io_callbacks
{ /* NULL - error */
92 device_io_read_buffer_callback
*read_buffer
;
93 device_io_write_buffer_callback
*write_buffer
;
94 } device_io_callbacks
;
97 /* DMA transfers by a device via its parent */
99 typedef unsigned (device_dma_read_buffer_callback
)
106 typedef unsigned (device_dma_write_buffer_callback
)
112 int violate_read_only_section
);
114 typedef struct _device_dma_callbacks
{ /* NULL - error */
115 device_dma_read_buffer_callback
*read_buffer
;
116 device_dma_write_buffer_callback
*write_buffer
;
117 } device_dma_callbacks
;
122 typedef void (device_interrupt_event_callback
)
131 typedef void (device_child_interrupt_event_callback
)
140 typedef struct _device_interrupt_port_descriptor
{
144 port_direction direction
;
145 } device_interrupt_port_descriptor
;
147 typedef struct _device_interrupt_callbacks
{
148 device_interrupt_event_callback
*event
;
149 device_child_interrupt_event_callback
*child_event
;
150 const device_interrupt_port_descriptor
*ports
;
151 } device_interrupt_callbacks
;
154 /* symbolic value decoding */
156 typedef int (device_unit_decode_callback
)
159 device_unit
*address
);
161 typedef int (device_unit_encode_callback
)
163 const device_unit
*unit_address
,
167 typedef int (device_address_to_attach_address_callback
)
169 const device_unit
*address
,
171 unsigned_word
*attach_address
,
174 typedef int (device_size_to_attach_size_callback
)
176 const device_unit
*size
,
180 typedef struct _device_convert_callbacks
{
181 device_unit_decode_callback
*decode_unit
;
182 device_unit_encode_callback
*encode_unit
;
183 device_address_to_attach_address_callback
*address_to_attach_address
;
184 device_size_to_attach_size_callback
*size_to_attach_size
;
185 } device_convert_callbacks
;
190 typedef void (device_instance_delete_callback
)
191 (device_instance
*instance
);
193 typedef int (device_instance_read_callback
)
194 (device_instance
*instance
,
198 typedef int (device_instance_write_callback
)
199 (device_instance
*instance
,
203 typedef int (device_instance_seek_callback
)
204 (device_instance
*instance
,
205 unsigned_word pos_hi
,
206 unsigned_word pos_lo
);
208 typedef int (device_instance_method
)
209 (device_instance
*instance
,
211 unsigned_cell stack_args
[/*n_stack_args*/],
213 unsigned_cell stack_returns
[/*n_stack_returns*/]);
215 typedef struct _device_instance_methods
{
217 device_instance_method
*method
;
218 } device_instance_methods
;
220 struct _device_instance_callbacks
{ /* NULL - error */
221 device_instance_delete_callback
*delete;
222 device_instance_read_callback
*read
;
223 device_instance_write_callback
*write
;
224 device_instance_seek_callback
*seek
;
225 const device_instance_methods
*methods
;
228 typedef device_instance
*(device_create_instance_callback
)
230 const char *full_path
,
233 typedef device_instance
*(package_create_instance_callback
)
234 (device_instance
*parent
,
240 typedef int (device_ioctl_callback
)
244 device_ioctl_request request
,
247 typedef void (device_usage_callback
)
253 struct _device_callbacks
{
256 device_init_callbacks init
;
258 /* address/data config - from child */
259 device_address_callbacks address
;
261 /* address/data transfer - from parent */
262 device_io_callbacks io
;
264 /* address/data transfer - from child */
265 device_dma_callbacks dma
;
267 /* interrupt signalling */
268 device_interrupt_callbacks interrupt
;
270 /* bus address decoding */
271 device_convert_callbacks convert
;
274 device_create_instance_callback
*instance_create
;
276 /* back door to anything we've forgot */
277 device_ioctl_callback
*ioctl
;
278 device_usage_callback
*usage
;
282 /* Table of all the devices and a function to lookup/create a device
285 typedef struct _device_descriptor device_descriptor
;
286 struct _device_descriptor
{
288 device_creator
*creator
;
289 const device_callbacks
*callbacks
;
292 extern const device_descriptor
*const device_table
[];
296 /* Pass through, ignore and generic callback functions. A call going
297 towards the root device are passed on up, local calls are ignored
298 and call downs abort */
300 extern device_address_callback passthrough_device_address_attach
;
301 extern device_address_callback passthrough_device_address_detach
;
302 extern device_dma_read_buffer_callback passthrough_device_dma_read_buffer
;
303 extern device_dma_write_buffer_callback passthrough_device_dma_write_buffer
;
305 extern device_unit_decode_callback ignore_device_unit_decode
;
307 extern device_init_callback generic_device_init_address
;
308 extern device_unit_decode_callback generic_device_unit_decode
;
309 extern device_unit_encode_callback generic_device_unit_encode
;
310 extern device_address_to_attach_address_callback generic_device_address_to_attach_address
;
311 extern device_size_to_attach_size_callback generic_device_size_to_attach_size
;
314 extern const device_callbacks passthrough_device_callbacks
;
316 #endif /* _DEVICE_TABLE_H_ */