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 /* The event queue abstraction (for devices) */
97 hw_event_handler
*handler
;
101 /* Pass the H/W event onto the real handler */
104 bounce_hw_event (SIM_DESC sd
,
107 hw_event event
= * (hw_event
*) data
;
109 event
.handler (event
.me
, event
.data
);
113 /* Map onto the event functions */
116 hw_event_queue_schedule (struct hw
*me
,
118 hw_event_handler
*handler
,
121 hw_event
*event
= ZALLOC (hw_event
);
123 event
->handler
= handler
;
125 event
->real
= sim_events_schedule (hw_system (me
),
133 hw_event_queue_deschedule (struct hw
*me
,
134 hw_event
*event_to_remove
)
136 sim_events_deschedule (hw_system (me
),
137 event_to_remove
->real
);
138 zfree (event_to_remove
);
142 hw_event_queue_time (struct hw
*me
)
144 return sim_events_time (hw_system (me
));
148 /* Mechanism for associating allocated memory regions to a device.
149 When a device is deleted any remaining memory regions are also
152 FIXME: Perhaphs this can be generalized, perhaphs it should not
155 struct hw_alloc_data
{
158 struct hw_alloc_data
*next
;
162 hw_zalloc (struct hw
*me
, unsigned long size
)
164 struct hw_alloc_data
*memory
= ZALLOC (struct hw_alloc_data
);
165 memory
->alloc
= zalloc (size
);
166 memory
->zalloc_p
= 1;
167 memory
->next
= me
->alloc_of_hw
;
168 me
->alloc_of_hw
= memory
;
169 return memory
->alloc
;
173 hw_malloc (struct hw
*me
, unsigned long size
)
175 struct hw_alloc_data
*memory
= ZALLOC (struct hw_alloc_data
);
176 memory
->alloc
= zalloc (size
);
177 memory
->zalloc_p
= 0;
178 memory
->next
= me
->alloc_of_hw
;
179 me
->alloc_of_hw
= memory
;
180 return memory
->alloc
;
184 hw_free (struct hw
*me
,
187 struct hw_alloc_data
**memory
;
188 for (memory
= &me
->alloc_of_hw
;
190 memory
= &(*memory
)->next
)
192 if ((*memory
)->alloc
== alloc
)
194 struct hw_alloc_data
*die
= (*memory
);
195 (*memory
) = die
->next
;
204 hw_abort (me
, "free of memory not belonging to a device");
208 hw_free_all (struct hw
*me
)
210 while (me
->alloc_of_hw
!= NULL
)
212 hw_free (me
, me
->alloc_of_hw
->alloc
);
This page took 0.03657 seconds and 5 git commands to generate.