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_C_
22 #define _DEVICE_TABLE_C_
24 #include "device_table.h"
30 /* Helper functions */
33 /* Go through the devices various reg properties for those that
34 specify attach addresses */
38 generic_device_init_address(device
*me
)
40 static const char *(reg_property_names
[]) = {
47 const char **reg_property_name
;
48 int nr_valid_reg_properties
= 0;
49 for (reg_property_name
= reg_property_names
;
50 *reg_property_name
!= NULL
;
51 reg_property_name
++) {
52 if (device_find_property(me
, *reg_property_name
) != NULL
) {
53 reg_property_spec reg
;
56 device_find_reg_array_property(me
, *reg_property_name
, reg_entry
,
59 unsigned_word attach_address
;
62 if (!device_address_to_attach_address(device_parent(me
),
64 &attach_space
, &attach_address
,
67 if (!device_size_to_attach_size(device_parent(me
),
71 device_attach_address(device_parent(me
),
73 attach_space
, attach_address
, attach_size
,
74 access_read_write_exec
,
76 nr_valid_reg_properties
++;
78 /* if first option matches don't try for any others */
79 if (reg_property_name
== reg_property_names
)
86 generic_device_unit_decode(device
*bus
,
90 memset(phys
, 0, sizeof(device_unit
));
95 const int max_nr_cells
= device_nr_address_cells(bus
);
99 val
= strtoul(unit
, &end
, 0);
103 /* two many cells? */
104 if (nr_cells
>= max_nr_cells
)
107 phys
->cells
[nr_cells
] = val
;
110 /* more to follow? */
111 if (isspace(*unit
) || *unit
== '\0')
117 if (nr_cells
< max_nr_cells
) {
118 /* shift everything to correct position */
120 for (i
= 1; i
<= nr_cells
; i
++)
121 phys
->cells
[max_nr_cells
- i
] = phys
->cells
[nr_cells
- i
];
122 for (i
= 0; i
< (max_nr_cells
- nr_cells
); i
++)
125 phys
->nr_cells
= max_nr_cells
;
131 generic_device_unit_encode(device
*bus
,
132 const device_unit
*phys
,
139 /* skip leading zero's */
140 for (i
= 0; i
< phys
->nr_cells
; i
++) {
141 if (phys
->cells
[i
] != 0)
144 /* don't output anything if empty */
145 if (phys
->nr_cells
== 0) {
149 else if (i
== phys
->nr_cells
) {
155 for (; i
< phys
->nr_cells
; i
++) {
158 pos
= strchr(pos
, '\0');
160 if (phys
->cells
[i
] < 10)
161 sprintf(pos
, "%ld", (unsigned long)phys
->cells
[i
]);
163 sprintf(pos
, "0x%lx", (unsigned long)phys
->cells
[i
]);
164 pos
= strchr(pos
, '\0');
168 if (len
>= sizeof_buf
)
169 error("generic_unit_encode - buffer overflow\n");
174 generic_device_address_to_attach_address(device
*me
,
175 const device_unit
*address
,
177 unsigned_word
*attach_address
,
181 for (i
= 0; i
< address
->nr_cells
- 2; i
++) {
182 if (address
->cells
[i
] != 0)
183 device_error(me
, "Only 32bit addresses supported");
185 if (address
->nr_cells
>= 2)
186 *attach_space
= address
->cells
[address
->nr_cells
- 2];
189 *attach_address
= address
->cells
[address
->nr_cells
- 1];
194 generic_device_size_to_attach_size(device
*me
,
195 const device_unit
*size
,
200 for (i
= 0; i
< size
->nr_cells
- 1; i
++) {
201 if (size
->cells
[i
] != 0)
202 device_error(me
, "Only 32bit sizes supported");
204 *nr_bytes
= size
->cells
[0];
209 /* ignore/passthrough versions of each function */
212 passthrough_device_address_attach(device
*me
,
218 device
*client
) /*callback/default*/
220 device_attach_address(device_parent(me
), attach
,
221 space
, addr
, nr_bytes
,
227 passthrough_device_address_detach(device
*me
,
233 device
*client
) /*callback/default*/
235 device_detach_address(device_parent(me
), attach
,
236 space
, addr
, nr_bytes
, access
,
241 passthrough_device_dma_read_buffer(device
*me
,
247 return device_dma_read_buffer(device_parent(me
), dest
,
248 space
, addr
, nr_bytes
);
252 passthrough_device_dma_write_buffer(device
*me
,
257 int violate_read_only_section
)
259 return device_dma_write_buffer(device_parent(me
), source
,
262 violate_read_only_section
);
266 ignore_device_unit_decode(device
*me
,
270 memset(phys
, 0, sizeof(device_unit
));
275 static const device_callbacks passthrough_callbacks
= {
276 { NULL
, }, /* init */
277 { passthrough_device_address_attach
,
278 passthrough_device_address_detach
, },
280 { passthrough_device_dma_read_buffer
, passthrough_device_dma_write_buffer
, },
281 { NULL
, }, /* interrupt */
282 { generic_device_unit_decode
,
283 generic_device_unit_encode
, },
287 static const device_descriptor ob_device_table
[] = {
288 /* standard OpenBoot devices */
289 { "aliases", NULL
, &passthrough_callbacks
},
290 { "options", NULL
, &passthrough_callbacks
},
291 { "chosen", NULL
, &passthrough_callbacks
},
292 { "packages", NULL
, &passthrough_callbacks
},
293 { "cpus", NULL
, &passthrough_callbacks
},
294 { "openprom", NULL
, &passthrough_callbacks
},
295 { "init", NULL
, &passthrough_callbacks
},
299 const device_descriptor
*const device_table
[] = {
306 #endif /* _DEVICE_TABLE_C_ */