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"
33 /* Helper functions */
36 /* Go through the devices various reg properties for those that
37 specify attach addresses */
41 generic_device_init_address(device *me)
43 static const char *(reg_property_names[]) = {
50 const char **reg_property_name;
51 int nr_valid_reg_properties = 0;
52 for (reg_property_name = reg_property_names;
53 *reg_property_name != NULL;
54 reg_property_name++) {
55 if (device_find_property(me, *reg_property_name) != NULL) {
56 reg_property_spec reg;
59 device_find_reg_array_property(me, *reg_property_name, reg_entry,
62 unsigned_word attach_address;
65 if (!device_address_to_attach_address(device_parent(me),
67 &attach_space, &attach_address,
70 if (!device_size_to_attach_size(device_parent(me),
74 device_attach_address(device_parent(me),
76 attach_space, attach_address, attach_size,
77 access_read_write_exec,
79 nr_valid_reg_properties++;
81 /* if first option matches don't try for any others */
82 if (reg_property_name == reg_property_names)
89 generic_device_unit_decode(device *bus,
93 memset(phys, 0, sizeof(device_unit));
98 const int max_nr_cells = device_nr_address_cells(bus);
102 val = strtoul(unit, &end, 0);
106 /* two many cells? */
107 if (nr_cells >= max_nr_cells)
110 phys->cells[nr_cells] = val;
113 /* more to follow? */
114 if (isspace(*unit) || *unit == '\0')
120 if (nr_cells < max_nr_cells) {
121 /* shift everything to correct position */
123 for (i = 1; i <= nr_cells; i++)
124 phys->cells[max_nr_cells - i] = phys->cells[nr_cells - i];
125 for (i = 0; i < (max_nr_cells - nr_cells); i++)
128 phys->nr_cells = max_nr_cells;
134 generic_device_unit_encode(device *bus,
135 const device_unit *phys,
142 /* skip leading zero's */
143 for (i = 0; i < phys->nr_cells; i++) {
144 if (phys->cells[i] != 0)
147 /* don't output anything if empty */
148 if (phys->nr_cells == 0) {
152 else if (i == phys->nr_cells) {
158 for (; i < phys->nr_cells; i++) {
161 pos = strchr(pos, '\0');
163 if (phys->cells[i] < 10)
164 sprintf(pos, "%ld", (unsigned long)phys->cells[i]);
166 sprintf(pos, "0x%lx", (unsigned long)phys->cells[i]);
167 pos = strchr(pos, '\0');
171 if (len >= sizeof_buf)
172 error("generic_unit_encode - buffer overflow\n");
177 generic_device_address_to_attach_address(device *me,
178 const device_unit *address,
180 unsigned_word *attach_address,
184 for (i = 0; i < address->nr_cells - 2; i++) {
185 if (address->cells[i] != 0)
186 device_error(me, "Only 32bit addresses supported");
188 if (address->nr_cells >= 2)
189 *attach_space = address->cells[address->nr_cells - 2];
192 *attach_address = address->cells[address->nr_cells - 1];
197 generic_device_size_to_attach_size(device *me,
198 const device_unit *size,
203 for (i = 0; i < size->nr_cells - 1; i++) {
204 if (size->cells[i] != 0)
205 device_error(me, "Only 32bit sizes supported");
207 *nr_bytes = size->cells[0];
212 /* ignore/passthrough versions of each function */
215 passthrough_device_address_attach(device *me,
221 device *client) /*callback/default*/
223 device_attach_address(device_parent(me), attach,
224 space, addr, nr_bytes,
230 passthrough_device_address_detach(device *me,
236 device *client) /*callback/default*/
238 device_detach_address(device_parent(me), attach,
239 space, addr, nr_bytes, access,
244 passthrough_device_dma_read_buffer(device *me,
250 return device_dma_read_buffer(device_parent(me), dest,
251 space, addr, nr_bytes);
255 passthrough_device_dma_write_buffer(device *me,
260 int violate_read_only_section)
262 return device_dma_write_buffer(device_parent(me), source,
265 violate_read_only_section);
269 ignore_device_unit_decode(device *me,
273 memset(phys, 0, sizeof(device_unit));
278 static const device_callbacks passthrough_callbacks = {
279 { NULL, }, /* init */
280 { passthrough_device_address_attach,
281 passthrough_device_address_detach, },
283 { passthrough_device_dma_read_buffer, passthrough_device_dma_write_buffer, },
284 { NULL, }, /* interrupt */
285 { generic_device_unit_decode,
286 generic_device_unit_encode, },
290 static const device_descriptor ob_device_table[] = {
291 /* standard OpenBoot devices */
292 { "aliases", NULL, &passthrough_callbacks },
293 { "options", NULL, &passthrough_callbacks },
294 { "chosen", NULL, &passthrough_callbacks },
295 { "packages", NULL, &passthrough_callbacks },
296 { "cpus", NULL, &passthrough_callbacks },
297 { "openprom", NULL, &passthrough_callbacks },
298 { "init", NULL, &passthrough_callbacks },
302 const device_descriptor *const device_table[] = {
309 #endif /* _DEVICE_TABLE_C_ */