Add PowerPC simulator from Andrew Cagney <cagney@highland.com.au>
[deliverable/binutils-gdb.git] / sim / ppc / device_tree.h
1 /* This file is part of the program psim.
2
3 Copyright (C) 1994-1995, 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
7 the Free Software Foundation; either version 2 of the License, or
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
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.
18
19 */
20
21
22 #ifndef _DEVICE_TREE_H_
23 #define _DEVICE_TREE_H_
24
25 #ifndef INLINE_DEVICE_TREE
26 #define INLINE_DEVICE_TREE
27 #endif
28
29
30 /* forward declaration of types */
31
32 typedef struct _device_node device_node;
33 typedef struct _device_address device_address;
34 typedef struct _device_callbacks device_callbacks;
35
36
37 /* Device callbacks: */
38
39
40 /* Memory operations: transfer data to/from a processor.
41
42 These callbacks pass/return data in *host* byte order.
43
44 Should a memory read/write operation cause an interrupt (external
45 exception) then a device would typically pass an interrupt message
46 to the devices parent. Hopefully that is an interrupt controler
47 and will know what to do with it.
48
49 Devices normally never either restart a processor or issue an
50 interrupt directly. The only exception I've thought of could be
51 machine check type event. */
52
53 typedef unsigned64 (device_reader_callback)
54 (device_node *device,
55 unsigned_word base,
56 unsigned nr_bytes,
57 cpu *processor,
58 unsigned_word cia);
59
60 typedef void (device_writer_callback)
61 (device_node *device,
62 unsigned_word base,
63 unsigned nr_bytes,
64 unsigned64 val,
65 cpu *processor,
66 unsigned_word cia);
67
68 /* Interrupts:
69
70 A child device uses the below to pass on to its parent changes in
71 the state of a child devices interrupt lines.
72
73 Typically, the parent being an interrupt control device, would, in
74 responce, schedule an event at the start of the next clock cycle.
75 On this event, the state of any cpu could be changed. Other
76 devices could either ignore or pass on the interrupt message */
77
78 typedef void (device_interrupt_callback)
79 (device_node *me,
80 int interrupt_status,
81 device_node *device,
82 cpu *processor,
83 unsigned_word cia);
84
85 /* Create:
86
87 DEVICE_CREATOR is called once, as part of building the device tree.
88 This function gives the device the chance to attach any additional
89 data to this particular device instance.
90
91 DEVICE_INIT_CALLBACK is (re)called when ever the system is
92 (re)initialised. */
93
94 typedef device_node *(device_creator)
95 (device_node *parent,
96 char *name);
97
98 typedef void (device_init_callback)
99 (device_node *device);
100
101
102
103 /* constructs to describe the hardware's tree of devices */
104
105 typedef enum _device_type {
106 /* default */
107 unknown_device,
108 /* typical devices */
109 memory_device,
110 sequential_device,
111 block_device,
112 bus_device,
113 other_device,
114 /* atypical devices, these are for data being loaded into ram/rom */
115 data_device,
116 options_device,
117 /* types of primative nodes containing just data */
118 boolean_type_device,
119 integer_type_device,
120 string_type_device,
121 byte_type_device,
122 } device_type;
123
124 typedef enum _device_access {
125 device_is_readable = 1,
126 device_is_writeable = 2,
127 device_is_read_write = 3,
128 device_is_executable = 4,
129 device_is_read_exec = 5,
130 device_is_write_exec = 6,
131 device_is_read_write_exec = 7,
132 } device_access;
133
134 struct _device_address {
135 unsigned_word lower_bound;
136 unsigned_word upper_bound;
137 unsigned size; /* host limited */
138 void *init; /* initial data */
139 device_access access;
140 device_address *next_address;
141 };
142
143 struct _device_callbacks {
144 device_reader_callback *read_callback;
145 device_writer_callback *write_callback;
146 device_interrupt_callback *interrupt_callback;
147 /* device_init_callback *init_callback; */
148 /* device_init_hander *post_init_handler; */
149 };
150
151 struct _device_node {
152 /* where i am */
153 device_node *parent;
154 device_node *children;
155 device_node *sibling;
156 /* what I am */
157 char *name; /* eg rom@0x1234,0x40 */
158 device_type type;
159 device_callbacks *callbacks;
160 device_address *addresses;
161 void *data;
162 };
163
164
165 /* given the image to run, return its device tree */
166
167 INLINE_DEVICE_TREE device_node *device_tree_create
168 (const char *hardware_description);
169
170
171 /* traverse the tree eiter pre or post fix */
172
173 typedef void (device_tree_traverse_function)
174 (device_node *device,
175 void *data);
176
177 INLINE_DEVICE_TREE void device_tree_traverse
178 (device_node *root,
179 device_tree_traverse_function *prefix,
180 device_tree_traverse_function *postfix,
181 void *data);
182
183
184 /* query the device tree */
185
186 INLINE_DEVICE_TREE device_node *device_tree_find_node
187 (device_node *root,
188 const char *path);
189
190 INLINE_DEVICE_TREE device_node *device_tree_find_next_node
191 (device_node *root,
192 const char *path,
193 device_node *last);
194
195 INLINE_DEVICE_TREE signed_word device_tree_find_int
196 (device_node *root,
197 const char *path);
198
199 INLINE_DEVICE_TREE const char *device_tree_find_string
200 (device_node *root,
201 const char *path);
202
203 INLINE_DEVICE_TREE int device_tree_find_boolean
204 (device_node *root,
205 const char *path);
206
207 INLINE_DEVICE_TREE void *device_tree_find_bytes
208 (device_node *root,
209 const char *path);
210
211 /* add to the device tree */
212
213 INLINE_DEVICE_TREE device_node *device_node_create
214 (device_node *parent,
215 char *name,
216 device_type type,
217 device_callbacks *callbacks,
218 void *data);
219
220 INLINE_DEVICE_TREE void device_node_add_address
221 (device_node *node,
222 unsigned_word lower_bound,
223 unsigned size,
224 device_access access,
225 void *init);
226
227 /* dump a node, pass this to the device_tree_traverse() function to
228 dump the tree */
229
230 INLINE_DEVICE_TREE void device_tree_dump
231 (device_node *device,
232 void *ignore_data_argument);
233
234 #endif /* _DEVICE_TREE_H_ */
This page took 0.035274 seconds and 4 git commands to generate.