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 2 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, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #ifndef _DEVICE_TABLE_H_
23 #define _DEVICE_TABLE_H_
38 typedef struct _device_callbacks device_callbacks
;
41 /* The creator, returns a pointer to any data that should be allocated
42 once during (multiple) simulation runs */
44 typedef void *(device_creator
)
46 const device_unit
*unit_address
,
50 /* two stages of initialization */
52 typedef void (device_init_callback
)
55 typedef struct _device_init_callbacks
{
56 device_init_callback
*address
; /* NULL - ignore */
57 device_init_callback
*data
; /* NULL - ignore */
58 } device_init_callbacks
;
61 /* attaching/detaching a devices address space to its parent */
63 typedef void (device_address_callback
)
70 device
*client
); /*callback/default*/
72 typedef struct _device_address_callbacks
{
73 device_address_callback
*attach
;
74 device_address_callback
*detach
;
75 } device_address_callbacks
;
78 /* I/O operations - from parent */
80 typedef unsigned (device_io_read_buffer_callback
)
89 typedef unsigned (device_io_write_buffer_callback
)
98 typedef struct _device_io_callbacks
{ /* NULL - error */
99 device_io_read_buffer_callback
*read_buffer
;
100 device_io_write_buffer_callback
*write_buffer
;
101 } device_io_callbacks
;
104 /* DMA transfers by a device via its parent */
106 typedef unsigned (device_dma_read_buffer_callback
)
113 typedef unsigned (device_dma_write_buffer_callback
)
119 int violate_read_only_section
);
121 typedef struct _device_dma_callbacks
{ /* NULL - error */
122 device_dma_read_buffer_callback
*read_buffer
;
123 device_dma_write_buffer_callback
*write_buffer
;
124 } device_dma_callbacks
;
129 typedef void (device_interrupt_event_callback
)
138 typedef void (device_child_interrupt_event_callback
)
147 typedef struct _device_interrupt_port_descriptor
{
151 port_direction direction
;
152 } device_interrupt_port_descriptor
;
154 typedef struct _device_interrupt_callbacks
{
155 device_interrupt_event_callback
*event
;
156 device_child_interrupt_event_callback
*child_event
;
157 const device_interrupt_port_descriptor
*ports
;
158 } device_interrupt_callbacks
;
161 /* symbolic value decoding */
163 typedef int (device_unit_decode_callback
)
166 device_unit
*address
);
168 typedef int (device_unit_encode_callback
)
170 const device_unit
*unit_address
,
174 typedef int (device_address_to_attach_address_callback
)
176 const device_unit
*address
,
178 unsigned_word
*attach_address
,
181 typedef int (device_size_to_attach_size_callback
)
183 const device_unit
*size
,
187 typedef struct _device_convert_callbacks
{
188 device_unit_decode_callback
*decode_unit
;
189 device_unit_encode_callback
*encode_unit
;
190 device_address_to_attach_address_callback
*address_to_attach_address
;
191 device_size_to_attach_size_callback
*size_to_attach_size
;
192 } device_convert_callbacks
;
197 typedef void (device_instance_delete_callback
)
198 (device_instance
*instance
);
200 typedef int (device_instance_read_callback
)
201 (device_instance
*instance
,
205 typedef int (device_instance_write_callback
)
206 (device_instance
*instance
,
210 typedef int (device_instance_seek_callback
)
211 (device_instance
*instance
,
212 unsigned_word pos_hi
,
213 unsigned_word pos_lo
);
215 typedef int (device_instance_method
)
216 (device_instance
*instance
,
218 unsigned_cell stack_args
[/*n_stack_args*/],
220 unsigned_cell stack_returns
[/*n_stack_returns*/]);
222 typedef struct _device_instance_methods
{
224 device_instance_method
*method
;
225 } device_instance_methods
;
227 struct _device_instance_callbacks
{ /* NULL - error */
228 device_instance_delete_callback
*delete;
229 device_instance_read_callback
*read
;
230 device_instance_write_callback
*write
;
231 device_instance_seek_callback
*seek
;
232 const device_instance_methods
*methods
;
235 typedef device_instance
*(device_create_instance_callback
)
237 const char *full_path
,
240 typedef device_instance
*(package_create_instance_callback
)
241 (device_instance
*parent
,
247 typedef int (device_ioctl_callback
)
251 device_ioctl_request request
,
254 typedef void (device_usage_callback
)
260 struct _device_callbacks
{
263 device_init_callbacks init
;
265 /* address/data config - from child */
266 device_address_callbacks address
;
268 /* address/data transfer - from parent */
269 device_io_callbacks io
;
271 /* address/data transfer - from child */
272 device_dma_callbacks dma
;
274 /* interrupt signalling */
275 device_interrupt_callbacks interrupt
;
277 /* bus address decoding */
278 device_convert_callbacks convert
;
281 device_create_instance_callback
*instance_create
;
283 /* back door to anything we've forgot */
284 device_ioctl_callback
*ioctl
;
285 device_usage_callback
*usage
;
289 /* Table of all the devices and a function to lookup/create a device
292 typedef struct _device_descriptor device_descriptor
;
293 struct _device_descriptor
{
295 device_creator
*creator
;
296 const device_callbacks
*callbacks
;
299 extern const device_descriptor
*const device_table
[];
303 /* Pass through, ignore and generic callback functions. A call going
304 towards the root device are passed on up, local calls are ignored
305 and call downs abort */
307 extern device_address_callback passthrough_device_address_attach
;
308 extern device_address_callback passthrough_device_address_detach
;
309 extern device_dma_read_buffer_callback passthrough_device_dma_read_buffer
;
310 extern device_dma_write_buffer_callback passthrough_device_dma_write_buffer
;
312 extern device_unit_decode_callback ignore_device_unit_decode
;
314 extern device_init_callback generic_device_init_address
;
315 extern device_unit_decode_callback generic_device_unit_decode
;
316 extern device_unit_encode_callback generic_device_unit_encode
;
317 extern device_address_to_attach_address_callback generic_device_address_to_attach_address
;
318 extern device_size_to_attach_size_callback generic_device_size_to_attach_size
;
321 extern const device_callbacks passthrough_device_callbacks
;
323 #endif /* _DEVICE_TABLE_H_ */