2 * QEMU ETRAX Interrupt Controller.
4 * Copyright (c) 2008 Edgar E. Iglesias, Axis Communications AB.
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28 //#include "etraxfs.h"
34 #define R_R_MASKED_VECT 2
43 void *interrupt_vector
;
49 static void pic_update(struct etrax_pic
*fs
)
54 fs
->regs
[R_R_MASKED_VECT
] = fs
->regs
[R_R_VECT
] & fs
->regs
[R_RW_MASK
];
56 /* The ETRAX interrupt controller signals interrupts to the core
57 through an interrupt request wire and an irq vector bus. If
58 multiple interrupts are simultaneously active it chooses vector
59 0x30 and lets the sw choose the priorities. */
60 if (fs
->regs
[R_R_MASKED_VECT
]) {
61 uint32_t mv
= fs
->regs
[R_R_MASKED_VECT
];
62 for (i
= 0; i
< 31; i
++) {
65 /* Check for multiple interrupts. */
74 if (fs
->interrupt_vector
) {
75 /* hack alert: ptr property */
76 *(uint32_t*)(fs
->interrupt_vector
) = vector
;
78 qemu_set_irq(fs
->parent_irq
, !!vector
);
82 pic_read(void *opaque
, hwaddr addr
, unsigned int size
)
84 struct etrax_pic
*fs
= opaque
;
87 rval
= fs
->regs
[addr
>> 2];
88 D(printf("%s %x=%x\n", __func__
, addr
, rval
));
92 static void pic_write(void *opaque
, hwaddr addr
,
93 uint64_t value
, unsigned int size
)
95 struct etrax_pic
*fs
= opaque
;
96 D(printf("%s addr=%x val=%x\n", __func__
, addr
, value
));
98 if (addr
== R_RW_MASK
) {
99 fs
->regs
[R_RW_MASK
] = value
;
104 static const MemoryRegionOps pic_ops
= {
107 .endianness
= DEVICE_NATIVE_ENDIAN
,
109 .min_access_size
= 4,
114 static void nmi_handler(void *opaque
, int irq
, int level
)
116 struct etrax_pic
*fs
= (void *)opaque
;
121 fs
->regs
[R_R_NMI
] |= mask
;
123 fs
->regs
[R_R_NMI
] &= ~mask
;
125 qemu_set_irq(fs
->parent_nmi
, !!fs
->regs
[R_R_NMI
]);
128 static void irq_handler(void *opaque
, int irq
, int level
)
130 struct etrax_pic
*fs
= (void *)opaque
;
133 return nmi_handler(opaque
, irq
, level
);
136 fs
->regs
[R_R_VECT
] &= ~(1 << irq
);
137 fs
->regs
[R_R_VECT
] |= (!!level
<< irq
);
141 static int etraxfs_pic_init(SysBusDevice
*dev
)
143 struct etrax_pic
*s
= FROM_SYSBUS(typeof (*s
), dev
);
145 qdev_init_gpio_in(&dev
->qdev
, irq_handler
, 32);
146 sysbus_init_irq(dev
, &s
->parent_irq
);
147 sysbus_init_irq(dev
, &s
->parent_nmi
);
149 memory_region_init_io(&s
->mmio
, &pic_ops
, s
, "etraxfs-pic", R_MAX
* 4);
150 sysbus_init_mmio(dev
, &s
->mmio
);
154 static Property etraxfs_pic_properties
[] = {
155 DEFINE_PROP_PTR("interrupt_vector", struct etrax_pic
, interrupt_vector
),
156 DEFINE_PROP_END_OF_LIST(),
159 static void etraxfs_pic_class_init(ObjectClass
*klass
, void *data
)
161 DeviceClass
*dc
= DEVICE_CLASS(klass
);
162 SysBusDeviceClass
*k
= SYS_BUS_DEVICE_CLASS(klass
);
164 k
->init
= etraxfs_pic_init
;
165 dc
->props
= etraxfs_pic_properties
;
168 static const TypeInfo etraxfs_pic_info
= {
169 .name
= "etraxfs,pic",
170 .parent
= TYPE_SYS_BUS_DEVICE
,
171 .instance_size
= sizeof(struct etrax_pic
),
172 .class_init
= etraxfs_pic_class_init
,
175 static void etraxfs_pic_register_types(void)
177 type_register_static(&etraxfs_pic_info
);
180 type_init(etraxfs_pic_register_types
)