1 /* This file is part of the program psim.
3 Copyright (C) 1994-1998, 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.
24 #include "hw-device.h"
25 #include "hw-properties.h"
35 hw_unit_address (struct hw *me)
37 return &me->unit_address_of_hw;
45 hw_ioctl (struct hw *me,
48 hw_ioctl_request request,
53 va_start(ap, request);
54 status = me->to_ioctl (me, processor, cia, request, ap);
62 hw_abort (struct hw *me,
70 /* find a system to abort through */
71 if (me == NULL || hw_system (me) == NULL)
75 /* find an identity */
76 if (me != NULL && hw_path (me) != NULL && hw_path (me) [0] != '\0')
78 else if (me != NULL && hw_name (me) != NULL && hw_name (me)[0] != '\0')
80 else if (me != NULL && hw_family (me) != NULL && hw_family (me)[0] != '\0')
81 name = hw_family (me);
84 /* report the problem */
85 sim_io_eprintf (sd, "%s: ", name);
86 sim_io_evprintf (sd, fmt, ap);
87 sim_io_error (sd, "%s", "");
91 hw_trace (struct hw *me,
95 if (hw_trace_p (me)) /* to be sure, to be sure */
99 sim_io_eprintf (hw_system (me), "%s: ", hw_path (me));
100 sim_io_evprintf (hw_system (me), fmt, ap);
101 sim_io_eprintf (hw_system (me), "\n");
107 /* The event queue abstraction (for devices) */
113 hw_event_handler *handler;
117 /* Pass the H/W event onto the real handler */
120 bounce_hw_event (SIM_DESC sd,
123 hw_event event = * (hw_event*) data;
125 event.handler (event.me, event.data);
129 /* Map onto the event functions */
132 hw_event_queue_schedule (struct hw *me,
134 hw_event_handler *handler,
137 hw_event *event = ZALLOC (hw_event);
139 event->handler = handler;
141 event->real = sim_events_schedule (hw_system (me),
149 hw_event_queue_deschedule (struct hw *me,
150 hw_event *event_to_remove)
152 sim_events_deschedule (hw_system (me),
153 event_to_remove->real);
154 zfree (event_to_remove);
158 hw_event_queue_time (struct hw *me)
160 return sim_events_time (hw_system (me));
164 /* Mechanism for associating allocated memory regions to a device.
165 When a device is deleted any remaining memory regions are also
168 FIXME: Perhaphs this can be generalized, perhaphs it should not
171 struct hw_alloc_data {
174 struct hw_alloc_data *next;
178 hw_zalloc (struct hw *me, unsigned long size)
180 struct hw_alloc_data *memory = ZALLOC (struct hw_alloc_data);
181 memory->alloc = zalloc (size);
182 memory->zalloc_p = 1;
183 memory->next = me->alloc_of_hw;
184 me->alloc_of_hw = memory;
185 return memory->alloc;
189 hw_malloc (struct hw *me, unsigned long size)
191 struct hw_alloc_data *memory = ZALLOC (struct hw_alloc_data);
192 memory->alloc = zalloc (size);
193 memory->zalloc_p = 0;
194 memory->next = me->alloc_of_hw;
195 me->alloc_of_hw = memory;
196 return memory->alloc;
200 hw_free (struct hw *me,
203 struct hw_alloc_data **memory;
204 for (memory = &me->alloc_of_hw;
206 memory = &(*memory)->next)
208 if ((*memory)->alloc == alloc)
210 struct hw_alloc_data *die = (*memory);
211 (*memory) = die->next;
220 hw_abort (me, "free of memory not belonging to a device");
224 hw_free_all (struct hw *me)
226 while (me->alloc_of_hw != NULL)
228 hw_free (me, me->alloc_of_hw->alloc);