]>
Commit | Line | Data |
---|---|---|
c906108c SS |
1 | /* This file is part of the program psim. |
2 | ||
3 | Copyright (C) 1994-1996, Andrew Cagney <cagney@highland.com.au> | |
4 | ||
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 | |
3fd725ef | 7 | the Free Software Foundation; either version 3 of the License, or |
c906108c SS |
8 | (at your option) any later version. |
9 | ||
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. | |
14 | ||
15 | You should have received a copy of the GNU General Public License | |
51b318de | 16 | along with this program; if not, see <http://www.gnu.org/licenses/>. |
c906108c SS |
17 | |
18 | */ | |
19 | ||
20 | ||
21 | #ifndef _DEVICE_TABLE_H_ | |
22 | #define _DEVICE_TABLE_H_ | |
23 | ||
24 | #include "basics.h" | |
25 | #include "device.h" | |
26 | #include "tree.h" | |
27 | ||
c906108c | 28 | #include <string.h> |
c906108c SS |
29 | |
30 | ||
31 | typedef struct _device_callbacks device_callbacks; | |
32 | ||
33 | ||
34 | /* The creator, returns a pointer to any data that should be allocated | |
35 | once during (multiple) simulation runs */ | |
36 | ||
37 | typedef void *(device_creator) | |
38 | (const char *name, | |
39 | const device_unit *unit_address, | |
40 | const char *args); | |
41 | ||
42 | ||
43 | /* two stages of initialization */ | |
44 | ||
45 | typedef void (device_init_callback) | |
46 | (device *me); | |
47 | ||
48 | typedef struct _device_init_callbacks { | |
49 | device_init_callback *address; /* NULL - ignore */ | |
50 | device_init_callback *data; /* NULL - ignore */ | |
51 | } device_init_callbacks; | |
52 | ||
53 | ||
54 | /* attaching/detaching a devices address space to its parent */ | |
55 | ||
56 | typedef void (device_address_callback) | |
57 | (device *me, | |
58 | attach_type attach, | |
59 | int space, | |
60 | unsigned_word addr, | |
61 | unsigned nr_bytes, | |
62 | access_type access, | |
63 | device *client); /*callback/default*/ | |
64 | ||
65 | typedef struct _device_address_callbacks { | |
66 | device_address_callback *attach; | |
67 | device_address_callback *detach; | |
68 | } device_address_callbacks; | |
69 | ||
70 | ||
71 | /* I/O operations - from parent */ | |
72 | ||
73 | typedef unsigned (device_io_read_buffer_callback) | |
74 | (device *me, | |
75 | void *dest, | |
76 | int space, | |
77 | unsigned_word addr, | |
78 | unsigned nr_bytes, | |
79 | cpu *processor, | |
80 | unsigned_word cia); | |
81 | ||
82 | typedef unsigned (device_io_write_buffer_callback) | |
83 | (device *me, | |
84 | const void *source, | |
85 | int space, | |
86 | unsigned_word addr, | |
87 | unsigned nr_bytes, | |
88 | cpu *processor, | |
89 | unsigned_word cia); | |
90 | ||
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; | |
95 | ||
96 | ||
97 | /* DMA transfers by a device via its parent */ | |
98 | ||
99 | typedef unsigned (device_dma_read_buffer_callback) | |
100 | (device *me, | |
101 | void *dest, | |
102 | int space, | |
103 | unsigned_word addr, | |
104 | unsigned nr_bytes); | |
105 | ||
106 | typedef unsigned (device_dma_write_buffer_callback) | |
107 | (device *me, | |
108 | const void *source, | |
109 | int space, | |
110 | unsigned_word addr, | |
111 | unsigned nr_bytes, | |
112 | int violate_read_only_section); | |
113 | ||
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; | |
118 | ||
119 | ||
120 | /* Interrupts */ | |
121 | ||
122 | typedef void (device_interrupt_event_callback) | |
123 | (device *me, | |
124 | int my_port, | |
125 | device *source, | |
126 | int source_port, | |
127 | int level, | |
128 | cpu *processor, | |
129 | unsigned_word cia); | |
130 | ||
131 | typedef void (device_child_interrupt_event_callback) | |
132 | (device *me, | |
133 | device *parent, | |
134 | device *source, | |
135 | int source_port, | |
136 | int level, | |
137 | cpu *processor, | |
138 | unsigned_word cia); | |
139 | ||
140 | typedef struct _device_interrupt_port_descriptor { | |
141 | const char *name; | |
142 | int number; | |
143 | int nr_ports; | |
144 | port_direction direction; | |
145 | } device_interrupt_port_descriptor; | |
146 | ||
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; | |
152 | ||
153 | ||
154 | /* symbolic value decoding */ | |
155 | ||
156 | typedef int (device_unit_decode_callback) | |
157 | (device *bus, | |
158 | const char *unit, | |
159 | device_unit *address); | |
160 | ||
161 | typedef int (device_unit_encode_callback) | |
162 | (device *bus, | |
163 | const device_unit *unit_address, | |
164 | char *buf, | |
165 | int sizeof_buf); | |
166 | ||
167 | typedef int (device_address_to_attach_address_callback) | |
168 | (device *bus, | |
169 | const device_unit *address, | |
170 | int *attach_space, | |
171 | unsigned_word *attach_address, | |
172 | device *client); | |
173 | ||
174 | typedef int (device_size_to_attach_size_callback) | |
175 | (device *bus, | |
176 | const device_unit *size, | |
177 | unsigned *nr_bytes, | |
178 | device *client); | |
179 | ||
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; | |
186 | ||
187 | ||
188 | /* instances */ | |
189 | ||
190 | typedef void (device_instance_delete_callback) | |
191 | (device_instance *instance); | |
192 | ||
193 | typedef int (device_instance_read_callback) | |
194 | (device_instance *instance, | |
195 | void *buf, | |
196 | unsigned_word len); | |
197 | ||
198 | typedef int (device_instance_write_callback) | |
199 | (device_instance *instance, | |
200 | const void *buf, | |
201 | unsigned_word len); | |
202 | ||
203 | typedef int (device_instance_seek_callback) | |
204 | (device_instance *instance, | |
205 | unsigned_word pos_hi, | |
206 | unsigned_word pos_lo); | |
207 | ||
208 | typedef int (device_instance_method) | |
209 | (device_instance *instance, | |
210 | int n_stack_args, | |
211 | unsigned_cell stack_args[/*n_stack_args*/], | |
212 | int n_stack_returns, | |
213 | unsigned_cell stack_returns[/*n_stack_returns*/]); | |
214 | ||
215 | typedef struct _device_instance_methods { | |
216 | const char *name; | |
217 | device_instance_method *method; | |
218 | } device_instance_methods; | |
219 | ||
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; | |
226 | }; | |
227 | ||
228 | typedef device_instance *(device_create_instance_callback) | |
229 | (device *me, | |
230 | const char *full_path, | |
231 | const char *args); | |
232 | ||
233 | typedef device_instance *(package_create_instance_callback) | |
234 | (device_instance *parent, | |
235 | const char *args); | |
236 | ||
237 | ||
238 | /* all else fails */ | |
239 | ||
240 | typedef int (device_ioctl_callback) | |
241 | (device *me, | |
242 | cpu *processor, | |
243 | unsigned_word cia, | |
244 | device_ioctl_request request, | |
245 | va_list ap); | |
246 | ||
247 | typedef void (device_usage_callback) | |
248 | (int verbose); | |
249 | ||
250 | ||
251 | /* the callbacks */ | |
252 | ||
253 | struct _device_callbacks { | |
254 | ||
255 | /* initialization */ | |
256 | device_init_callbacks init; | |
257 | ||
258 | /* address/data config - from child */ | |
259 | device_address_callbacks address; | |
260 | ||
261 | /* address/data transfer - from parent */ | |
262 | device_io_callbacks io; | |
263 | ||
264 | /* address/data transfer - from child */ | |
265 | device_dma_callbacks dma; | |
266 | ||
267 | /* interrupt signalling */ | |
268 | device_interrupt_callbacks interrupt; | |
269 | ||
270 | /* bus address decoding */ | |
271 | device_convert_callbacks convert; | |
272 | ||
273 | /* instances */ | |
274 | device_create_instance_callback *instance_create; | |
275 | ||
276 | /* back door to anything we've forgot */ | |
277 | device_ioctl_callback *ioctl; | |
278 | device_usage_callback *usage; | |
279 | }; | |
280 | ||
281 | ||
282 | /* Table of all the devices and a function to lookup/create a device | |
283 | from its name */ | |
284 | ||
285 | typedef struct _device_descriptor device_descriptor; | |
286 | struct _device_descriptor { | |
287 | const char *name; | |
288 | device_creator *creator; | |
289 | const device_callbacks *callbacks; | |
290 | }; | |
291 | ||
292 | extern const device_descriptor *const device_table[]; | |
293 | #include "hw.h" | |
294 | ||
295 | ||
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 */ | |
299 | ||
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; | |
304 | ||
305 | extern device_unit_decode_callback ignore_device_unit_decode; | |
306 | ||
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; | |
312 | ||
313 | ||
314 | extern const device_callbacks passthrough_device_callbacks; | |
315 | ||
316 | #endif /* _DEVICE_TABLE_H_ */ |