1 /* This file is part of the program psim.
3 Copyright (C) 1994-1995, 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_TREE_H_
23 #define _DEVICE_TREE_H_
31 /* declared in basics.h, this object is used everywhere */
32 /* typedef struct _device device; */
39 All the devices in this model live in a tree. The following allow
40 the location/manipulation of this tree */
42 device INLINE_DEVICE
*device_parent
45 const char INLINE_DEVICE
*device_name
48 void INLINE_DEVICE
*device_data
52 /* Grow the device tree adding either a specific device or
53 alternativly a device found in the device table */
55 device INLINE_DEVICE
*device_tree_add_device
58 device
*new_sub_tree
);
60 device INLINE_DEVICE
*device_tree_add_found
65 device INLINE_DEVICE
*device_tree_add_found_c
71 device INLINE_DEVICE
*device_tree_add_found_c_uw
78 device INLINE_DEVICE
*device_tree_add_found_uw_u
85 device INLINE_DEVICE
*device_tree_add_found_uw_u_u
93 device INLINE_DEVICE
*device_tree_add_found_uw_u_u_c
102 device INLINE_DEVICE
*device_tree_add_found_uw_uw_u_u_c
112 device INLINE_DEVICE
*device_tree_add_found_uw_uw_u_u_u
123 /* Query the device tree, null is returned if the specified device is
126 device INLINE_DEVICE
*device_tree_find_device
131 /* traverse the device tree visiting all notes (either pre or post
134 typedef void (device_tree_traverse_function
)
138 void INLINE_DEVICE device_tree_traverse
140 device_tree_traverse_function
*prefix
,
141 device_tree_traverse_function
*postfix
,
145 /* dump a node, this can be passed to the device_tree_traverse()
146 function to dump out the entire device tree */
148 void INLINE_DEVICE device_tree_dump
150 void *ignore_data_argument
);
155 /* Device Properties:
157 Attached to a device (typically by open boot firmware) are
158 properties that profile the devices features. The below allow the
159 manipulation of device properties */
161 /* Each device can have associated properties. Internal to
162 psim those properties are strictly typed. Within the simulation,
163 no such control exists */
171 } device_property_type
;
173 typedef struct _device_property device_property
;
174 struct _device_property
{
176 device_property_type type
;
177 unsigned sizeof_array
;
182 /* Basic operations used by software */
184 const char INLINE_DEVICE
*device_find_next_property
186 const char *previous
);
188 /* INLINE_DEVICE void device_add_property
189 No such external function, all properties, when added are explictly
192 void INLINE_DEVICE device_add_array_property
194 const char *property
,
198 void INLINE_DEVICE device_add_integer_property
200 const char *property
,
201 signed_word integer
);
203 void INLINE_DEVICE device_add_boolean_property
205 const char *property
,
208 void INLINE_DEVICE device_add_null_property
210 const char *property
);
212 void INLINE_DEVICE device_add_string_property
214 const char *property
,
218 /* Locate a property returning its description. Return NULL if the
219 named property is not found */
221 const device_property INLINE_DEVICE
*device_find_property
223 const char *property
);
226 /* Process all properties attached to the named device */
228 typedef void (device_traverse_property_function
)
233 void INLINE_DEVICE device_traverse_properties
235 device_traverse_property_function
*traverse
,
239 /* Similar to above except that the property *must* be in the device
240 tree and *must* be of the specified type. */
242 const device_property INLINE_DEVICE
*device_find_array_property
244 const char *property
);
246 signed_word INLINE_DEVICE device_find_integer_property
248 const char *property
);
250 const char INLINE_DEVICE
*device_find_string_property
252 const char *property
);
254 int INLINE_DEVICE device_find_boolean_property
256 const char *property
);
262 A device principaly is modeling real hardware that a processor can
263 directly interact with via load/stores dma's and interrupts. The
264 interface below is used by the hardware side of the device
267 /* Address access attributes that can be attached to a devices address
269 typedef enum _access_type
{
273 access_read_write
= 3,
275 access_read_exec
= 5,
276 access_write_exec
= 6,
277 access_read_write_exec
= 7,
281 /* Address attachement types */
282 typedef enum _attach_type
{
292 A device is made fully functional in two stages.
294 1. It is created. A device is created _before_ it is entered into
295 the device tree. During creation any permenant structures needed
296 by the device should be created/initialized.
298 2. It is initialized. Before a simulation run, each device in the
299 device tree is initialized in prefix order. As part of this
300 initialization, a device should (re)attach its self to its parent
305 device INLINE_DEVICE
*device_create
309 /* some external functions want to create things */
310 typedef struct _device_callbacks device_callbacks
;
312 device INLINE_DEVICE
*device_create_from
315 const device_callbacks
*callbacks
,
318 void INLINE_DEVICE device_init
322 /* initialize the entire tree */
324 void INLINE_DEVICE device_tree_init
331 A device may permit the reading/writing (IO) of its registers in
332 one or more address spaces. For instance, a PCI device may have
333 config registers in its config space and control registers in both
334 the io and memory spaces of a PCI bus.
336 Similarly, a device may initiate a data transfer (DMA) by passing
337 such a request up to its parent.
341 As part of its initialization (not creation) and possibly also as a
342 consequence of IO a device may attach its self to one or more of
343 the address spaces of its parent device.
345 For instance, a PCI device, during initialization would attach its
346 config registers (space=0?, base=0, nr_bytes=64) to its parent PCI
347 bridge. Later, due to a write to this config space, the same
348 device may in turn find it necessary to also attach its self to
349 it's parent's `memory' or `io' space.
351 To perform these operations, a device will call upon its parent
352 using either device_attach_address or device_detach_address.
354 * Any address specified is according to what the device expects to
357 * Any detach operation must exactly match a previous attach.
359 * included with the attach or detach is the devices name, the
360 parent may use this as part of determining how to map map between a
361 child's address + space and its own.
363 * at any time, at most one device can have a default mapping
369 A device receives requests to perform reads/writes to its registers
370 or memory either A. from a processor or B. from a parent device.
372 The device may then in turn either A. resolve the IO request
373 locally by processing the data or trigering an exception or
374 B. re-mapping the access onto one of its local address spaces and
375 then in turn passing that on to one of its children.
377 * Any address passed is relative to the local device. Eg for PCI
378 config registers, the address would (normally) be in the range of 0
381 * Any exception situtation triggered by an IO operation (processor
382 != NULL) is handled in one of the following ways: 1. Machine check
383 (and similar): issued immediatly by restarting the cpu; 2. External
384 exception: issue delayed (using events.h) until the current
385 instruction execution cycle is completed; 3. Slave device (and
386 similar): the need for the interrupt is passed on to the devices
387 parent (which being an interrupt control unit will in turn take one
388 of the actions described here); 4. Forget it.
390 * Any exception situtation trigered by a non IO operation
391 (processor == NULL) is handled buy returning 0.
393 * Transfers of size <= 8 and of a power of 2 *must* be correctly
394 aligned and should be treated as a `single cycle' transfer.
398 A device initiates a DMA transfer by calling its parent with the
399 request. At the top level (if not done earlier) this is reflected
400 back down the tree as io read/writes to the target device.
402 This function is subject to change ...
406 void INLINE_DEVICE device_attach_address
414 device
*who
); /*callback/default*/
416 void INLINE_DEVICE device_detach_address
424 device
*who
); /*callback/default*/
426 unsigned INLINE_DEVICE device_io_read_buffer
435 unsigned INLINE_DEVICE device_io_write_buffer
444 unsigned INLINE_DEVICE device_dma_read_buffer
451 unsigned INLINE_DEVICE device_dma_write_buffer
457 int violate_read_only_section
);
462 As mentioned above. Instead of handling an interrupt directly, a
463 device may instead pass the need to interrupt on to its parent.
467 Before passing interrupts up to is parent, a device must first
468 attach its interrupt lines to the parent device. To do this, the
469 device uses the parents attach/detach calls.
473 A child notifies a parent of a change in an interrupt lines status
474 using the interrupt call. Similarly, a parent may notify a child
475 of any `interrupt ack' sequence using the interrupt_ack call.
479 void INLINE_DEVICE device_attach_interrupt
485 void INLINE_DEVICE device_detach_interrupt
491 void INLINE_DEVICE device_interrupt
495 int interrupt_status
,
499 void INLINE_DEVICE device_interrupt_ack
502 int interrupt_status
);
507 Very simply, a catch all for any thing that turns up that until now
508 either hasn't been thought of or doesn't justify an extra function. */
510 void EXTERN_DEVICE device_ioctl
519 /* Device software - the instance
523 In addition to the processor directly manipulating a device via
524 read/write operations. A program may manipulate a device
525 indirectly via OpenBoot calls. The following provide a higher
526 level software interface to the devices */
529 device_instance INLINE_DEVICE
*device_instance_open
531 const char *device_specifier
);
533 void INLINE_DEVICE device_instance_close
534 (device_instance
*instance
);
536 int INLINE_DEVICE device_instance_read
537 (device_instance
*instance
,
541 int INLINE_DEVICE device_instance_write
542 (device_instance
*instance
,
546 int INLINE_DEVICE device_instance_seek
547 (device_instance
*instance
,
548 unsigned_word pos_hi
,
549 unsigned_word pos_lo
);
551 device INLINE_DEVICE
*device_instance_device
552 (device_instance
*instance
);
554 const char INLINE_DEVICE
*device_instance_name
555 (device_instance
*instance
);
561 /* Device dregs... */
563 /* Parse a device name */
565 void INLINE_DEVICE device_tree_parse_name
567 const char **driver_name
,
568 const char **unit_address
,
569 const char **device_arguments
,
573 /* Parse a device name, various formats:
579 int INLINE_DEVICE scand_c
584 int INLINE_DEVICE scand_c_uw_u
591 int INLINE_DEVICE scand_uw
595 int INLINE_DEVICE scand_uw_c
601 int INLINE_DEVICE scand_uw_u
606 int INLINE_DEVICE scand_uw_u_u
612 int INLINE_DEVICE scand_uw_u_u_c
620 int INLINE_DEVICE scand_uw_uw
625 int INLINE_DEVICE scand_uw_uw_u
631 int INLINE_DEVICE scand_uw_uw_u_u_c
640 int INLINE_DEVICE scand_uw_uw_u_u_u
648 #endif /* _DEVICE_TREE_H_ */