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 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.
25 #ifndef STATIC_INLINE_HW_CPU
26 #define STATIC_INLINE_HW_CPU STATIC_INLINE
29 #include "device_table.h"
32 #include "interrupts.h"
39 cpu - Interface to a Processor
45 The CPU device provides the connection between the interrupt net
46 (linking the devices and the interrupt controller) and the
47 simulated model of each processor. This device contains interrupt
48 ports that correspond directly to the external interrupt stimulus
49 that can be sent to a given processor. Sending an interrupt to one
50 of the ports results in an interrupt being delivered to the
51 corresponding processor.
53 Typically, an interrupt controller would have its inputs connected
54 to device interrupt sources and its outputs (sreset, int, et.al.)
55 connected to this device.
61 cpu-nr = <integer> (required)
64 Specify the processor (1..N) that this cpu device node should
71 Connect an OpenPIC interrupt controller interrupt ports to
74 | -o '/phb/opic@0 > irq0 int /cpus/cpu@0' \
75 | -o '/phb/opic@0 > init hreset /cpus/cpu@0' \
80 typedef struct _hw_cpu_device {
85 static const device_interrupt_port_descriptor hw_cpu_interrupt_ports[] = {
86 { "hreset", hw_cpu_hard_reset },
87 { "sreset", hw_cpu_soft_reset },
88 { "int", hw_cpu_external_interrupt },
89 { "mci", hw_cpu_machine_check_interrupt },
90 { "smi", hw_cpu_system_management_interrupt },
96 hw_cpu_create(const char *name,
97 const device_unit *unit_address,
100 hw_cpu_device *hw_cpu = ZALLOC(hw_cpu_device);
105 /* during address initialization ensure that any missing cpu
106 properties are added to this devices node */
109 hw_cpu_init_address(device *me)
111 hw_cpu_device *hw_cpu = (hw_cpu_device*)device_data(me);
112 /* populate the node with properties */
114 memset(hw_cpu, 0x0, sizeof(hw_cpu_device));
115 hw_cpu->cpu_nr = device_find_integer_property(me, "cpu-nr");
116 hw_cpu->processor = psim_cpu(device_system(me), hw_cpu->cpu_nr);
120 /* Take the interrupt and synchronize its delivery with the clock. If
121 we've not yet scheduled an interrupt for the next clock tick, take
122 the oportunity to do it now */
125 hw_cpu_interrupt_event(device *me,
133 hw_cpu_device *hw_cpu = (hw_cpu_device*)device_data(me);
134 if (my_port < 0 || my_port >= hw_cpu_nr_interrupt_ports)
135 error("hw_cpu_interrupt_event_callback: interrupt port out of range %d\n",
138 /*case hw_cpu_hard_reset:*/
139 /*case hw_cpu_soft_reset:*/
140 case hw_cpu_external_interrupt:
141 external_interrupt(hw_cpu->processor, level);
143 /*case hw_cpu_machine_check_interrupt:*/
145 error("hw_cpu_deliver_interrupt: unimplemented interrupt port %d\n",
152 static device_callbacks const hw_cpu_callbacks = {
153 { hw_cpu_init_address, }, /* init */
154 { NULL, }, /* address */
157 { hw_cpu_interrupt_event, NULL, hw_cpu_interrupt_ports }, /* interrupts */
161 const device_descriptor hw_cpu_device_descriptor[] = {
162 { "hw-cpu", hw_cpu_create, &hw_cpu_callbacks },
163 { "cpu", hw_cpu_create, &hw_cpu_callbacks },
167 #endif /* _HW_CPU_C_ */