2011-04-19 16:56:45 +02:00
|
|
|
/*
|
|
|
|
* StrongARM SA-1100/SA-1110 emulation
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011 Dmitry Eremin-Solenikov
|
|
|
|
*
|
|
|
|
* Largely based on StrongARM emulation:
|
|
|
|
* Copyright (c) 2006 Openedhand Ltd.
|
|
|
|
* Written by Andrzej Zaborowski <balrog@zabor.org>
|
|
|
|
*
|
|
|
|
* UART code based on QEMU 16550A UART emulation
|
|
|
|
* Copyright (c) 2003-2004 Fabrice Bellard
|
|
|
|
* Copyright (c) 2008 Citrix Systems, Inc.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, see <http://www.gnu.org/licenses/>.
|
2012-01-13 17:44:23 +01:00
|
|
|
*
|
|
|
|
* Contributions after 2012-01-13 are licensed under the terms of the
|
|
|
|
* GNU GPL, version 2 or (at your option) any later version.
|
2011-04-19 16:56:45 +02:00
|
|
|
*/
|
2015-04-04 14:24:38 +02:00
|
|
|
|
2015-12-07 17:23:45 +01:00
|
|
|
#include "qemu/osdep.h"
|
2016-01-19 21:51:44 +01:00
|
|
|
#include "cpu.h"
|
2019-08-12 07:23:42 +02:00
|
|
|
#include "hw/irq.h"
|
2019-08-12 07:23:51 +02:00
|
|
|
#include "hw/qdev-properties.h"
|
2020-12-11 23:05:12 +01:00
|
|
|
#include "hw/qdev-properties-system.h"
|
2013-02-04 15:40:22 +01:00
|
|
|
#include "hw/sysbus.h"
|
2019-08-12 07:23:45 +02:00
|
|
|
#include "migration/vmstate.h"
|
2013-03-18 17:36:02 +01:00
|
|
|
#include "strongarm.h"
|
2012-12-17 18:20:00 +01:00
|
|
|
#include "qemu/error-report.h"
|
2019-05-23 15:47:43 +02:00
|
|
|
#include "hw/arm/boot.h"
|
2017-01-26 15:26:44 +01:00
|
|
|
#include "chardev/char-fe.h"
|
2017-01-26 14:33:39 +01:00
|
|
|
#include "chardev/char-serial.h"
|
2012-12-17 18:20:04 +01:00
|
|
|
#include "sysemu/sysemu.h"
|
2021-11-29 21:55:05 +01:00
|
|
|
#include "sysemu/rtc.h"
|
2016-01-21 15:15:03 +01:00
|
|
|
#include "hw/ssi/ssi.h"
|
qdev: Convert uses of qdev_create() with Coccinelle
This is the transformation explained in the commit before previous.
Takes care of just one pattern that needs conversion. More to come in
this series.
Coccinelle script:
@ depends on !(file in "hw/arm/highbank.c")@
expression bus, type_name, dev, expr;
@@
- dev = qdev_create(bus, type_name);
+ dev = qdev_new(type_name);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, bus, &error_fatal);
@@
expression bus, type_name, dev, expr;
identifier DOWN;
@@
- dev = DOWN(qdev_create(bus, type_name));
+ dev = DOWN(qdev_new(type_name));
... when != dev = expr
- qdev_init_nofail(DEVICE(dev));
+ qdev_realize_and_unref(DEVICE(dev), bus, &error_fatal);
@@
expression bus, type_name, expr;
identifier dev;
@@
- DeviceState *dev = qdev_create(bus, type_name);
+ DeviceState *dev = qdev_new(type_name);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, bus, &error_fatal);
@@
expression bus, type_name, dev, expr, errp;
symbol true;
@@
- dev = qdev_create(bus, type_name);
+ dev = qdev_new(type_name);
... when != dev = expr
- object_property_set_bool(OBJECT(dev), true, "realized", errp);
+ qdev_realize_and_unref(dev, bus, errp);
@@
expression bus, type_name, expr, errp;
identifier dev;
symbol true;
@@
- DeviceState *dev = qdev_create(bus, type_name);
+ DeviceState *dev = qdev_new(type_name);
... when != dev = expr
- object_property_set_bool(OBJECT(dev), true, "realized", errp);
+ qdev_realize_and_unref(dev, bus, errp);
The first rule exempts hw/arm/highbank.c, because it matches along two
control flow paths there, with different @type_name. Covered by the
next commit's manual conversions.
Missing #include "qapi/error.h" added manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-10-armbru@redhat.com>
[Conflicts in hw/misc/empty_slot.c and hw/sparc/leon3.c resolved]
2020-06-10 07:31:58 +02:00
|
|
|
#include "qapi/error.h"
|
2016-03-20 18:16:19 +01:00
|
|
|
#include "qemu/cutils.h"
|
2015-12-15 13:16:16 +01:00
|
|
|
#include "qemu/log.h"
|
2020-09-03 22:43:22 +02:00
|
|
|
#include "qom/object.h"
|
2011-04-19 16:56:45 +02:00
|
|
|
|
|
|
|
//#define DEBUG
|
|
|
|
|
|
|
|
/*
|
|
|
|
TODO
|
|
|
|
- Implement cp15, c14 ?
|
|
|
|
- Implement cp15, c15 !!! (idle used in L)
|
|
|
|
- Implement idle mode handling/DIM
|
|
|
|
- Implement sleep mode/Wake sources
|
|
|
|
- Implement reset control
|
|
|
|
- Implement memory control regs
|
|
|
|
- PCMCIA handling
|
|
|
|
- Maybe support MBGNT/MBREQ
|
|
|
|
- DMA channels
|
|
|
|
- GPCLK
|
|
|
|
- IrDA
|
|
|
|
- MCP
|
|
|
|
- Enhance UART with modem signals
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
# define DPRINTF(format, ...) printf(format , ## __VA_ARGS__)
|
|
|
|
#else
|
|
|
|
# define DPRINTF(format, ...) do { } while (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static struct {
|
2012-10-23 12:30:10 +02:00
|
|
|
hwaddr io_base;
|
2011-04-19 16:56:45 +02:00
|
|
|
int irq;
|
|
|
|
} sa_serial[] = {
|
|
|
|
{ 0x80010000, SA_PIC_UART1 },
|
|
|
|
{ 0x80030000, SA_PIC_UART2 },
|
|
|
|
{ 0x80050000, SA_PIC_UART3 },
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Interrupt Controller */
|
2013-07-24 09:17:13 +02:00
|
|
|
|
|
|
|
#define TYPE_STRONGARM_PIC "strongarm_pic"
|
2020-09-16 20:25:19 +02:00
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(StrongARMPICState, STRONGARM_PIC)
|
2013-07-24 09:17:13 +02:00
|
|
|
|
2020-09-03 22:43:22 +02:00
|
|
|
struct StrongARMPICState {
|
2013-07-24 09:17:13 +02:00
|
|
|
SysBusDevice parent_obj;
|
|
|
|
|
2011-10-03 14:14:20 +02:00
|
|
|
MemoryRegion iomem;
|
2011-04-19 16:56:45 +02:00
|
|
|
qemu_irq irq;
|
|
|
|
qemu_irq fiq;
|
|
|
|
|
|
|
|
uint32_t pending;
|
|
|
|
uint32_t enabled;
|
|
|
|
uint32_t is_fiq;
|
|
|
|
uint32_t int_idle;
|
2020-09-03 22:43:22 +02:00
|
|
|
};
|
2011-04-19 16:56:45 +02:00
|
|
|
|
|
|
|
#define ICIP 0x00
|
|
|
|
#define ICMR 0x04
|
|
|
|
#define ICLR 0x08
|
|
|
|
#define ICFP 0x10
|
|
|
|
#define ICPR 0x20
|
|
|
|
#define ICCR 0x0c
|
|
|
|
|
|
|
|
#define SA_PIC_SRCS 32
|
|
|
|
|
|
|
|
|
|
|
|
static void strongarm_pic_update(void *opaque)
|
|
|
|
{
|
|
|
|
StrongARMPICState *s = opaque;
|
|
|
|
|
|
|
|
/* FIXME: reflect DIM */
|
|
|
|
qemu_set_irq(s->fiq, s->pending & s->enabled & s->is_fiq);
|
|
|
|
qemu_set_irq(s->irq, s->pending & s->enabled & ~s->is_fiq);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void strongarm_pic_set_irq(void *opaque, int irq, int level)
|
|
|
|
{
|
|
|
|
StrongARMPICState *s = opaque;
|
|
|
|
|
|
|
|
if (level) {
|
|
|
|
s->pending |= 1 << irq;
|
|
|
|
} else {
|
|
|
|
s->pending &= ~(1 << irq);
|
|
|
|
}
|
|
|
|
|
|
|
|
strongarm_pic_update(s);
|
|
|
|
}
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
static uint64_t strongarm_pic_mem_read(void *opaque, hwaddr offset,
|
2011-10-03 14:14:20 +02:00
|
|
|
unsigned size)
|
2011-04-19 16:56:45 +02:00
|
|
|
{
|
|
|
|
StrongARMPICState *s = opaque;
|
|
|
|
|
|
|
|
switch (offset) {
|
|
|
|
case ICIP:
|
|
|
|
return s->pending & ~s->is_fiq & s->enabled;
|
|
|
|
case ICMR:
|
|
|
|
return s->enabled;
|
|
|
|
case ICLR:
|
|
|
|
return s->is_fiq;
|
|
|
|
case ICCR:
|
|
|
|
return s->int_idle == 0;
|
|
|
|
case ICFP:
|
|
|
|
return s->pending & s->is_fiq & s->enabled;
|
|
|
|
case ICPR:
|
|
|
|
return s->pending;
|
|
|
|
default:
|
2023-01-10 22:29:47 +01:00
|
|
|
printf("%s: Bad register offset 0x" HWADDR_FMT_plx "\n",
|
2011-04-19 16:56:45 +02:00
|
|
|
__func__, offset);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
static void strongarm_pic_mem_write(void *opaque, hwaddr offset,
|
2011-10-03 14:14:20 +02:00
|
|
|
uint64_t value, unsigned size)
|
2011-04-19 16:56:45 +02:00
|
|
|
{
|
|
|
|
StrongARMPICState *s = opaque;
|
|
|
|
|
|
|
|
switch (offset) {
|
|
|
|
case ICMR:
|
|
|
|
s->enabled = value;
|
|
|
|
break;
|
|
|
|
case ICLR:
|
|
|
|
s->is_fiq = value;
|
|
|
|
break;
|
|
|
|
case ICCR:
|
|
|
|
s->int_idle = (value & 1) ? 0 : ~0;
|
|
|
|
break;
|
|
|
|
default:
|
2023-01-10 22:29:47 +01:00
|
|
|
printf("%s: Bad register offset 0x" HWADDR_FMT_plx "\n",
|
2011-04-19 16:56:45 +02:00
|
|
|
__func__, offset);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
strongarm_pic_update(s);
|
|
|
|
}
|
|
|
|
|
2011-10-03 14:14:20 +02:00
|
|
|
static const MemoryRegionOps strongarm_pic_ops = {
|
|
|
|
.read = strongarm_pic_mem_read,
|
|
|
|
.write = strongarm_pic_mem_write,
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
2011-04-19 16:56:45 +02:00
|
|
|
};
|
|
|
|
|
2016-03-07 08:05:49 +01:00
|
|
|
static void strongarm_pic_initfn(Object *obj)
|
2011-04-19 16:56:45 +02:00
|
|
|
{
|
2016-03-07 08:05:49 +01:00
|
|
|
DeviceState *dev = DEVICE(obj);
|
|
|
|
StrongARMPICState *s = STRONGARM_PIC(obj);
|
|
|
|
SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
|
2011-04-19 16:56:45 +02:00
|
|
|
|
2013-07-24 09:17:13 +02:00
|
|
|
qdev_init_gpio_in(dev, strongarm_pic_set_irq, SA_PIC_SRCS);
|
2016-03-07 08:05:49 +01:00
|
|
|
memory_region_init_io(&s->iomem, obj, &strongarm_pic_ops, s,
|
2013-06-07 03:25:08 +02:00
|
|
|
"pic", 0x1000);
|
2013-07-24 09:17:13 +02:00
|
|
|
sysbus_init_mmio(sbd, &s->iomem);
|
|
|
|
sysbus_init_irq(sbd, &s->irq);
|
|
|
|
sysbus_init_irq(sbd, &s->fiq);
|
2011-04-19 16:56:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int strongarm_pic_post_load(void *opaque, int version_id)
|
|
|
|
{
|
|
|
|
strongarm_pic_update(opaque);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-13 18:11:48 +01:00
|
|
|
static const VMStateDescription vmstate_strongarm_pic_regs = {
|
2011-04-19 16:56:45 +02:00
|
|
|
.name = "strongarm_pic",
|
|
|
|
.version_id = 0,
|
|
|
|
.minimum_version_id = 0,
|
|
|
|
.post_load = strongarm_pic_post_load,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_UINT32(pending, StrongARMPICState),
|
|
|
|
VMSTATE_UINT32(enabled, StrongARMPICState),
|
|
|
|
VMSTATE_UINT32(is_fiq, StrongARMPICState),
|
|
|
|
VMSTATE_UINT32(int_idle, StrongARMPICState),
|
|
|
|
VMSTATE_END_OF_LIST(),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2012-01-24 20:12:29 +01:00
|
|
|
static void strongarm_pic_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2012-01-24 20:12:29 +01:00
|
|
|
|
2011-12-08 04:34:16 +01:00
|
|
|
dc->desc = "StrongARM PIC";
|
|
|
|
dc->vmsd = &vmstate_strongarm_pic_regs;
|
2012-01-24 20:12:29 +01:00
|
|
|
}
|
|
|
|
|
2013-01-10 16:19:07 +01:00
|
|
|
static const TypeInfo strongarm_pic_info = {
|
2013-07-24 09:17:13 +02:00
|
|
|
.name = TYPE_STRONGARM_PIC,
|
2011-12-08 04:34:16 +01:00
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(StrongARMPICState),
|
2016-03-07 08:05:49 +01:00
|
|
|
.instance_init = strongarm_pic_initfn,
|
2011-12-08 04:34:16 +01:00
|
|
|
.class_init = strongarm_pic_class_init,
|
2011-04-19 16:56:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Real-Time Clock */
|
|
|
|
#define RTAR 0x00 /* RTC Alarm register */
|
|
|
|
#define RCNR 0x04 /* RTC Counter register */
|
|
|
|
#define RTTR 0x08 /* RTC Timer Trim register */
|
|
|
|
#define RTSR 0x10 /* RTC Status register */
|
|
|
|
|
|
|
|
#define RTSR_AL (1 << 0) /* RTC Alarm detected */
|
|
|
|
#define RTSR_HZ (1 << 1) /* RTC 1Hz detected */
|
|
|
|
#define RTSR_ALE (1 << 2) /* RTC Alarm enable */
|
|
|
|
#define RTSR_HZE (1 << 3) /* RTC 1Hz enable */
|
|
|
|
|
|
|
|
/* 16 LSB of RTTR are clockdiv for internal trim logic,
|
|
|
|
* trim delete isn't emulated, so
|
|
|
|
* f = 32 768 / (RTTR_trim + 1) */
|
|
|
|
|
2013-07-24 09:20:15 +02:00
|
|
|
#define TYPE_STRONGARM_RTC "strongarm-rtc"
|
2020-09-16 20:25:19 +02:00
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(StrongARMRTCState, STRONGARM_RTC)
|
2013-07-24 09:20:15 +02:00
|
|
|
|
2020-09-03 22:43:22 +02:00
|
|
|
struct StrongARMRTCState {
|
2013-07-24 09:20:15 +02:00
|
|
|
SysBusDevice parent_obj;
|
|
|
|
|
2011-10-03 14:14:20 +02:00
|
|
|
MemoryRegion iomem;
|
2011-04-19 16:56:45 +02:00
|
|
|
uint32_t rttr;
|
|
|
|
uint32_t rtsr;
|
|
|
|
uint32_t rtar;
|
|
|
|
uint32_t last_rcnr;
|
|
|
|
int64_t last_hz;
|
|
|
|
QEMUTimer *rtc_alarm;
|
|
|
|
QEMUTimer *rtc_hz;
|
|
|
|
qemu_irq rtc_irq;
|
|
|
|
qemu_irq rtc_hz_irq;
|
2020-09-03 22:43:22 +02:00
|
|
|
};
|
2011-04-19 16:56:45 +02:00
|
|
|
|
|
|
|
static inline void strongarm_rtc_int_update(StrongARMRTCState *s)
|
|
|
|
{
|
|
|
|
qemu_set_irq(s->rtc_irq, s->rtsr & RTSR_AL);
|
|
|
|
qemu_set_irq(s->rtc_hz_irq, s->rtsr & RTSR_HZ);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void strongarm_rtc_hzupdate(StrongARMRTCState *s)
|
|
|
|
{
|
2013-08-21 17:03:04 +02:00
|
|
|
int64_t rt = qemu_clock_get_ms(rtc_clock);
|
2011-04-19 16:56:45 +02:00
|
|
|
s->last_rcnr += ((rt - s->last_hz) << 15) /
|
|
|
|
(1000 * ((s->rttr & 0xffff) + 1));
|
|
|
|
s->last_hz = rt;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void strongarm_rtc_timer_update(StrongARMRTCState *s)
|
|
|
|
{
|
|
|
|
if ((s->rtsr & RTSR_HZE) && !(s->rtsr & RTSR_HZ)) {
|
2013-08-21 17:03:08 +02:00
|
|
|
timer_mod(s->rtc_hz, s->last_hz + 1000);
|
2011-04-19 16:56:45 +02:00
|
|
|
} else {
|
2013-08-21 17:03:08 +02:00
|
|
|
timer_del(s->rtc_hz);
|
2011-04-19 16:56:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((s->rtsr & RTSR_ALE) && !(s->rtsr & RTSR_AL)) {
|
2013-08-21 17:03:08 +02:00
|
|
|
timer_mod(s->rtc_alarm, s->last_hz +
|
2011-04-19 16:56:45 +02:00
|
|
|
(((s->rtar - s->last_rcnr) * 1000 *
|
|
|
|
((s->rttr & 0xffff) + 1)) >> 15));
|
|
|
|
} else {
|
2013-08-21 17:03:08 +02:00
|
|
|
timer_del(s->rtc_alarm);
|
2011-04-19 16:56:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void strongarm_rtc_alarm_tick(void *opaque)
|
|
|
|
{
|
|
|
|
StrongARMRTCState *s = opaque;
|
|
|
|
s->rtsr |= RTSR_AL;
|
|
|
|
strongarm_rtc_timer_update(s);
|
|
|
|
strongarm_rtc_int_update(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void strongarm_rtc_hz_tick(void *opaque)
|
|
|
|
{
|
|
|
|
StrongARMRTCState *s = opaque;
|
|
|
|
s->rtsr |= RTSR_HZ;
|
|
|
|
strongarm_rtc_timer_update(s);
|
|
|
|
strongarm_rtc_int_update(s);
|
|
|
|
}
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
static uint64_t strongarm_rtc_read(void *opaque, hwaddr addr,
|
2011-10-03 14:14:20 +02:00
|
|
|
unsigned size)
|
2011-04-19 16:56:45 +02:00
|
|
|
{
|
|
|
|
StrongARMRTCState *s = opaque;
|
|
|
|
|
|
|
|
switch (addr) {
|
|
|
|
case RTTR:
|
|
|
|
return s->rttr;
|
|
|
|
case RTSR:
|
|
|
|
return s->rtsr;
|
|
|
|
case RTAR:
|
|
|
|
return s->rtar;
|
|
|
|
case RCNR:
|
|
|
|
return s->last_rcnr +
|
2013-08-21 17:03:04 +02:00
|
|
|
((qemu_clock_get_ms(rtc_clock) - s->last_hz) << 15) /
|
2011-04-19 16:56:45 +02:00
|
|
|
(1000 * ((s->rttr & 0xffff) + 1));
|
|
|
|
default:
|
2023-01-10 22:29:47 +01:00
|
|
|
printf("%s: Bad register 0x" HWADDR_FMT_plx "\n", __func__, addr);
|
2011-04-19 16:56:45 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
static void strongarm_rtc_write(void *opaque, hwaddr addr,
|
2011-10-03 14:14:20 +02:00
|
|
|
uint64_t value, unsigned size)
|
2011-04-19 16:56:45 +02:00
|
|
|
{
|
|
|
|
StrongARMRTCState *s = opaque;
|
|
|
|
uint32_t old_rtsr;
|
|
|
|
|
|
|
|
switch (addr) {
|
|
|
|
case RTTR:
|
|
|
|
strongarm_rtc_hzupdate(s);
|
|
|
|
s->rttr = value;
|
|
|
|
strongarm_rtc_timer_update(s);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RTSR:
|
|
|
|
old_rtsr = s->rtsr;
|
|
|
|
s->rtsr = (value & (RTSR_ALE | RTSR_HZE)) |
|
|
|
|
(s->rtsr & ~(value & (RTSR_AL | RTSR_HZ)));
|
|
|
|
|
|
|
|
if (s->rtsr != old_rtsr) {
|
|
|
|
strongarm_rtc_timer_update(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
strongarm_rtc_int_update(s);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RTAR:
|
|
|
|
s->rtar = value;
|
|
|
|
strongarm_rtc_timer_update(s);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RCNR:
|
|
|
|
strongarm_rtc_hzupdate(s);
|
|
|
|
s->last_rcnr = value;
|
|
|
|
strongarm_rtc_timer_update(s);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2023-01-10 22:29:47 +01:00
|
|
|
printf("%s: Bad register 0x" HWADDR_FMT_plx "\n", __func__, addr);
|
2011-04-19 16:56:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-03 14:14:20 +02:00
|
|
|
static const MemoryRegionOps strongarm_rtc_ops = {
|
|
|
|
.read = strongarm_rtc_read,
|
|
|
|
.write = strongarm_rtc_write,
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
2011-04-19 16:56:45 +02:00
|
|
|
};
|
|
|
|
|
2016-03-07 08:05:49 +01:00
|
|
|
static void strongarm_rtc_init(Object *obj)
|
2011-04-19 16:56:45 +02:00
|
|
|
{
|
2016-03-07 08:05:49 +01:00
|
|
|
StrongARMRTCState *s = STRONGARM_RTC(obj);
|
|
|
|
SysBusDevice *dev = SYS_BUS_DEVICE(obj);
|
2011-04-19 16:56:45 +02:00
|
|
|
struct tm tm;
|
|
|
|
|
|
|
|
s->rttr = 0x0;
|
|
|
|
s->rtsr = 0;
|
|
|
|
|
|
|
|
qemu_get_timedate(&tm, 0);
|
|
|
|
|
|
|
|
s->last_rcnr = (uint32_t) mktimegm(&tm);
|
2013-08-21 17:03:04 +02:00
|
|
|
s->last_hz = qemu_clock_get_ms(rtc_clock);
|
2011-04-19 16:56:45 +02:00
|
|
|
|
|
|
|
sysbus_init_irq(dev, &s->rtc_irq);
|
|
|
|
sysbus_init_irq(dev, &s->rtc_hz_irq);
|
|
|
|
|
2016-03-07 08:05:49 +01:00
|
|
|
memory_region_init_io(&s->iomem, obj, &strongarm_rtc_ops, s,
|
2013-06-07 03:25:08 +02:00
|
|
|
"rtc", 0x10000);
|
2011-11-27 10:38:10 +01:00
|
|
|
sysbus_init_mmio(dev, &s->iomem);
|
2011-04-19 16:56:45 +02:00
|
|
|
}
|
|
|
|
|
2020-03-05 17:09:16 +01:00
|
|
|
static void strongarm_rtc_realize(DeviceState *dev, Error **errp)
|
|
|
|
{
|
|
|
|
StrongARMRTCState *s = STRONGARM_RTC(dev);
|
|
|
|
s->rtc_alarm = timer_new_ms(rtc_clock, strongarm_rtc_alarm_tick, s);
|
|
|
|
s->rtc_hz = timer_new_ms(rtc_clock, strongarm_rtc_hz_tick, s);
|
|
|
|
}
|
|
|
|
|
2017-09-25 13:29:12 +02:00
|
|
|
static int strongarm_rtc_pre_save(void *opaque)
|
2011-04-19 16:56:45 +02:00
|
|
|
{
|
|
|
|
StrongARMRTCState *s = opaque;
|
|
|
|
|
|
|
|
strongarm_rtc_hzupdate(s);
|
2017-09-25 13:29:12 +02:00
|
|
|
|
|
|
|
return 0;
|
2011-04-19 16:56:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int strongarm_rtc_post_load(void *opaque, int version_id)
|
|
|
|
{
|
|
|
|
StrongARMRTCState *s = opaque;
|
|
|
|
|
|
|
|
strongarm_rtc_timer_update(s);
|
|
|
|
strongarm_rtc_int_update(s);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_strongarm_rtc_regs = {
|
|
|
|
.name = "strongarm-rtc",
|
|
|
|
.version_id = 0,
|
|
|
|
.minimum_version_id = 0,
|
|
|
|
.pre_save = strongarm_rtc_pre_save,
|
|
|
|
.post_load = strongarm_rtc_post_load,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_UINT32(rttr, StrongARMRTCState),
|
|
|
|
VMSTATE_UINT32(rtsr, StrongARMRTCState),
|
|
|
|
VMSTATE_UINT32(rtar, StrongARMRTCState),
|
|
|
|
VMSTATE_UINT32(last_rcnr, StrongARMRTCState),
|
|
|
|
VMSTATE_INT64(last_hz, StrongARMRTCState),
|
|
|
|
VMSTATE_END_OF_LIST(),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2012-01-24 20:12:29 +01:00
|
|
|
static void strongarm_rtc_sysbus_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2012-01-24 20:12:29 +01:00
|
|
|
|
2011-12-08 04:34:16 +01:00
|
|
|
dc->desc = "StrongARM RTC Controller";
|
|
|
|
dc->vmsd = &vmstate_strongarm_rtc_regs;
|
2020-03-05 17:09:16 +01:00
|
|
|
dc->realize = strongarm_rtc_realize;
|
2012-01-24 20:12:29 +01:00
|
|
|
}
|
|
|
|
|
2013-01-10 16:19:07 +01:00
|
|
|
static const TypeInfo strongarm_rtc_sysbus_info = {
|
2013-07-24 09:20:15 +02:00
|
|
|
.name = TYPE_STRONGARM_RTC,
|
2011-12-08 04:34:16 +01:00
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(StrongARMRTCState),
|
2016-03-07 08:05:49 +01:00
|
|
|
.instance_init = strongarm_rtc_init,
|
2011-12-08 04:34:16 +01:00
|
|
|
.class_init = strongarm_rtc_sysbus_class_init,
|
2011-04-19 16:56:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* GPIO */
|
|
|
|
#define GPLR 0x00
|
|
|
|
#define GPDR 0x04
|
|
|
|
#define GPSR 0x08
|
|
|
|
#define GPCR 0x0c
|
|
|
|
#define GRER 0x10
|
|
|
|
#define GFER 0x14
|
|
|
|
#define GEDR 0x18
|
|
|
|
#define GAFR 0x1c
|
|
|
|
|
2013-07-24 09:23:14 +02:00
|
|
|
#define TYPE_STRONGARM_GPIO "strongarm-gpio"
|
2020-09-16 20:25:19 +02:00
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(StrongARMGPIOInfo, STRONGARM_GPIO)
|
2013-07-24 09:23:14 +02:00
|
|
|
|
2011-04-19 16:56:45 +02:00
|
|
|
struct StrongARMGPIOInfo {
|
|
|
|
SysBusDevice busdev;
|
2011-10-03 14:14:20 +02:00
|
|
|
MemoryRegion iomem;
|
2011-04-19 16:56:45 +02:00
|
|
|
qemu_irq handler[28];
|
|
|
|
qemu_irq irqs[11];
|
|
|
|
qemu_irq irqX;
|
|
|
|
|
|
|
|
uint32_t ilevel;
|
|
|
|
uint32_t olevel;
|
|
|
|
uint32_t dir;
|
|
|
|
uint32_t rising;
|
|
|
|
uint32_t falling;
|
|
|
|
uint32_t status;
|
|
|
|
uint32_t gafr;
|
|
|
|
|
|
|
|
uint32_t prev_level;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void strongarm_gpio_irq_update(StrongARMGPIOInfo *s)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < 11; i++) {
|
|
|
|
qemu_set_irq(s->irqs[i], s->status & (1 << i));
|
|
|
|
}
|
|
|
|
|
|
|
|
qemu_set_irq(s->irqX, (s->status & ~0x7ff));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void strongarm_gpio_set(void *opaque, int line, int level)
|
|
|
|
{
|
|
|
|
StrongARMGPIOInfo *s = opaque;
|
|
|
|
uint32_t mask;
|
|
|
|
|
|
|
|
mask = 1 << line;
|
|
|
|
|
|
|
|
if (level) {
|
|
|
|
s->status |= s->rising & mask &
|
|
|
|
~s->ilevel & ~s->dir;
|
|
|
|
s->ilevel |= mask;
|
|
|
|
} else {
|
|
|
|
s->status |= s->falling & mask &
|
|
|
|
s->ilevel & ~s->dir;
|
|
|
|
s->ilevel &= ~mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s->status & mask) {
|
|
|
|
strongarm_gpio_irq_update(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void strongarm_gpio_handler_update(StrongARMGPIOInfo *s)
|
|
|
|
{
|
|
|
|
uint32_t level, diff;
|
|
|
|
int bit;
|
|
|
|
|
|
|
|
level = s->olevel & s->dir;
|
|
|
|
|
|
|
|
for (diff = s->prev_level ^ level; diff; diff ^= 1 << bit) {
|
2015-03-23 16:29:26 +01:00
|
|
|
bit = ctz32(diff);
|
2011-04-19 16:56:45 +02:00
|
|
|
qemu_set_irq(s->handler[bit], (level >> bit) & 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
s->prev_level = level;
|
|
|
|
}
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
static uint64_t strongarm_gpio_read(void *opaque, hwaddr offset,
|
2011-10-03 14:14:20 +02:00
|
|
|
unsigned size)
|
2011-04-19 16:56:45 +02:00
|
|
|
{
|
|
|
|
StrongARMGPIOInfo *s = opaque;
|
|
|
|
|
|
|
|
switch (offset) {
|
|
|
|
case GPDR: /* GPIO Pin-Direction registers */
|
|
|
|
return s->dir;
|
|
|
|
|
|
|
|
case GPSR: /* GPIO Pin-Output Set registers */
|
2014-06-29 19:38:39 +02:00
|
|
|
qemu_log_mask(LOG_GUEST_ERROR,
|
|
|
|
"strongarm GPIO: read from write only register GPSR\n");
|
|
|
|
return 0;
|
2011-04-19 16:56:45 +02:00
|
|
|
|
|
|
|
case GPCR: /* GPIO Pin-Output Clear registers */
|
2014-06-29 19:38:39 +02:00
|
|
|
qemu_log_mask(LOG_GUEST_ERROR,
|
|
|
|
"strongarm GPIO: read from write only register GPCR\n");
|
|
|
|
return 0;
|
2011-04-19 16:56:45 +02:00
|
|
|
|
|
|
|
case GRER: /* GPIO Rising-Edge Detect Enable registers */
|
|
|
|
return s->rising;
|
|
|
|
|
|
|
|
case GFER: /* GPIO Falling-Edge Detect Enable registers */
|
|
|
|
return s->falling;
|
|
|
|
|
|
|
|
case GAFR: /* GPIO Alternate Function registers */
|
|
|
|
return s->gafr;
|
|
|
|
|
|
|
|
case GPLR: /* GPIO Pin-Level registers */
|
|
|
|
return (s->olevel & s->dir) |
|
|
|
|
(s->ilevel & ~s->dir);
|
|
|
|
|
|
|
|
case GEDR: /* GPIO Edge Detect Status registers */
|
|
|
|
return s->status;
|
|
|
|
|
|
|
|
default:
|
2023-01-10 22:29:47 +01:00
|
|
|
printf("%s: Bad offset 0x" HWADDR_FMT_plx "\n", __func__, offset);
|
2011-04-19 16:56:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
static void strongarm_gpio_write(void *opaque, hwaddr offset,
|
2011-10-03 14:14:20 +02:00
|
|
|
uint64_t value, unsigned size)
|
2011-04-19 16:56:45 +02:00
|
|
|
{
|
|
|
|
StrongARMGPIOInfo *s = opaque;
|
|
|
|
|
|
|
|
switch (offset) {
|
|
|
|
case GPDR: /* GPIO Pin-Direction registers */
|
2018-10-30 16:23:56 +01:00
|
|
|
s->dir = value & 0x0fffffff;
|
2011-04-19 16:56:45 +02:00
|
|
|
strongarm_gpio_handler_update(s);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GPSR: /* GPIO Pin-Output Set registers */
|
2018-10-30 16:23:56 +01:00
|
|
|
s->olevel |= value & 0x0fffffff;
|
2011-04-19 16:56:45 +02:00
|
|
|
strongarm_gpio_handler_update(s);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GPCR: /* GPIO Pin-Output Clear registers */
|
|
|
|
s->olevel &= ~value;
|
|
|
|
strongarm_gpio_handler_update(s);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GRER: /* GPIO Rising-Edge Detect Enable registers */
|
|
|
|
s->rising = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GFER: /* GPIO Falling-Edge Detect Enable registers */
|
|
|
|
s->falling = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GAFR: /* GPIO Alternate Function registers */
|
|
|
|
s->gafr = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GEDR: /* GPIO Edge Detect Status registers */
|
|
|
|
s->status &= ~value;
|
|
|
|
strongarm_gpio_irq_update(s);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2023-01-10 22:29:47 +01:00
|
|
|
printf("%s: Bad offset 0x" HWADDR_FMT_plx "\n", __func__, offset);
|
2011-04-19 16:56:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-03 14:14:20 +02:00
|
|
|
static const MemoryRegionOps strongarm_gpio_ops = {
|
|
|
|
.read = strongarm_gpio_read,
|
|
|
|
.write = strongarm_gpio_write,
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
2011-04-19 16:56:45 +02:00
|
|
|
};
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
static DeviceState *strongarm_gpio_init(hwaddr base,
|
2011-04-19 16:56:45 +02:00
|
|
|
DeviceState *pic)
|
|
|
|
{
|
|
|
|
DeviceState *dev;
|
|
|
|
int i;
|
|
|
|
|
qdev: Convert uses of qdev_create() with Coccinelle
This is the transformation explained in the commit before previous.
Takes care of just one pattern that needs conversion. More to come in
this series.
Coccinelle script:
@ depends on !(file in "hw/arm/highbank.c")@
expression bus, type_name, dev, expr;
@@
- dev = qdev_create(bus, type_name);
+ dev = qdev_new(type_name);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, bus, &error_fatal);
@@
expression bus, type_name, dev, expr;
identifier DOWN;
@@
- dev = DOWN(qdev_create(bus, type_name));
+ dev = DOWN(qdev_new(type_name));
... when != dev = expr
- qdev_init_nofail(DEVICE(dev));
+ qdev_realize_and_unref(DEVICE(dev), bus, &error_fatal);
@@
expression bus, type_name, expr;
identifier dev;
@@
- DeviceState *dev = qdev_create(bus, type_name);
+ DeviceState *dev = qdev_new(type_name);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, bus, &error_fatal);
@@
expression bus, type_name, dev, expr, errp;
symbol true;
@@
- dev = qdev_create(bus, type_name);
+ dev = qdev_new(type_name);
... when != dev = expr
- object_property_set_bool(OBJECT(dev), true, "realized", errp);
+ qdev_realize_and_unref(dev, bus, errp);
@@
expression bus, type_name, expr, errp;
identifier dev;
symbol true;
@@
- DeviceState *dev = qdev_create(bus, type_name);
+ DeviceState *dev = qdev_new(type_name);
... when != dev = expr
- object_property_set_bool(OBJECT(dev), true, "realized", errp);
+ qdev_realize_and_unref(dev, bus, errp);
The first rule exempts hw/arm/highbank.c, because it matches along two
control flow paths there, with different @type_name. Covered by the
next commit's manual conversions.
Missing #include "qapi/error.h" added manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-10-armbru@redhat.com>
[Conflicts in hw/misc/empty_slot.c and hw/sparc/leon3.c resolved]
2020-06-10 07:31:58 +02:00
|
|
|
dev = qdev_new(TYPE_STRONGARM_GPIO);
|
sysbus: Convert to sysbus_realize() etc. with Coccinelle
Convert from qdev_realize(), qdev_realize_and_unref() with null @bus
argument to sysbus_realize(), sysbus_realize_and_unref().
Coccinelle script:
@@
expression dev, errp;
@@
- qdev_realize(DEVICE(dev), NULL, errp);
+ sysbus_realize(SYS_BUS_DEVICE(dev), errp);
@@
expression sysbus_dev, dev, errp;
@@
+ sysbus_dev = SYS_BUS_DEVICE(dev);
- qdev_realize_and_unref(dev, NULL, errp);
+ sysbus_realize_and_unref(sysbus_dev, errp);
- sysbus_dev = SYS_BUS_DEVICE(dev);
@@
expression sysbus_dev, dev, errp;
expression expr;
@@
sysbus_dev = SYS_BUS_DEVICE(dev);
... when != dev = expr;
- qdev_realize_and_unref(dev, NULL, errp);
+ sysbus_realize_and_unref(sysbus_dev, errp);
@@
expression dev, errp;
@@
- qdev_realize_and_unref(DEVICE(dev), NULL, errp);
+ sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), errp);
@@
expression dev, errp;
@@
- qdev_realize_and_unref(dev, NULL, errp);
+ sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), errp);
Whitespace changes minimized manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Acked-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-46-armbru@redhat.com>
[Conflicts in hw/misc/empty_slot.c and hw/sparc/leon3.c resolved]
2020-06-10 07:32:34 +02:00
|
|
|
sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
|
2011-04-19 16:56:45 +02:00
|
|
|
|
2013-01-20 02:47:33 +01:00
|
|
|
sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
|
2011-04-19 16:56:45 +02:00
|
|
|
for (i = 0; i < 12; i++)
|
2013-01-20 02:47:33 +01:00
|
|
|
sysbus_connect_irq(SYS_BUS_DEVICE(dev), i,
|
2011-04-19 16:56:45 +02:00
|
|
|
qdev_get_gpio_in(pic, SA_PIC_GPIO0_EDGE + i));
|
|
|
|
|
|
|
|
return dev;
|
|
|
|
}
|
|
|
|
|
2016-03-07 08:05:49 +01:00
|
|
|
static void strongarm_gpio_initfn(Object *obj)
|
2011-04-19 16:56:45 +02:00
|
|
|
{
|
2016-03-07 08:05:49 +01:00
|
|
|
DeviceState *dev = DEVICE(obj);
|
|
|
|
StrongARMGPIOInfo *s = STRONGARM_GPIO(obj);
|
|
|
|
SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
|
2011-04-19 16:56:45 +02:00
|
|
|
int i;
|
|
|
|
|
2013-07-24 09:23:14 +02:00
|
|
|
qdev_init_gpio_in(dev, strongarm_gpio_set, 28);
|
|
|
|
qdev_init_gpio_out(dev, s->handler, 28);
|
2011-04-19 16:56:45 +02:00
|
|
|
|
2016-03-07 08:05:49 +01:00
|
|
|
memory_region_init_io(&s->iomem, obj, &strongarm_gpio_ops, s,
|
2013-06-07 03:25:08 +02:00
|
|
|
"gpio", 0x1000);
|
2011-04-19 16:56:45 +02:00
|
|
|
|
2013-07-24 09:23:14 +02:00
|
|
|
sysbus_init_mmio(sbd, &s->iomem);
|
2011-04-19 16:56:45 +02:00
|
|
|
for (i = 0; i < 11; i++) {
|
2013-07-24 09:23:14 +02:00
|
|
|
sysbus_init_irq(sbd, &s->irqs[i]);
|
2011-04-19 16:56:45 +02:00
|
|
|
}
|
2013-07-24 09:23:14 +02:00
|
|
|
sysbus_init_irq(sbd, &s->irqX);
|
2011-04-19 16:56:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_strongarm_gpio_regs = {
|
|
|
|
.name = "strongarm-gpio",
|
|
|
|
.version_id = 0,
|
|
|
|
.minimum_version_id = 0,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_UINT32(ilevel, StrongARMGPIOInfo),
|
|
|
|
VMSTATE_UINT32(olevel, StrongARMGPIOInfo),
|
|
|
|
VMSTATE_UINT32(dir, StrongARMGPIOInfo),
|
|
|
|
VMSTATE_UINT32(rising, StrongARMGPIOInfo),
|
|
|
|
VMSTATE_UINT32(falling, StrongARMGPIOInfo),
|
|
|
|
VMSTATE_UINT32(status, StrongARMGPIOInfo),
|
|
|
|
VMSTATE_UINT32(gafr, StrongARMGPIOInfo),
|
2014-06-29 19:38:39 +02:00
|
|
|
VMSTATE_UINT32(prev_level, StrongARMGPIOInfo),
|
2011-04-19 16:56:45 +02:00
|
|
|
VMSTATE_END_OF_LIST(),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2012-01-24 20:12:29 +01:00
|
|
|
static void strongarm_gpio_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2012-01-24 20:12:29 +01:00
|
|
|
|
2011-12-08 04:34:16 +01:00
|
|
|
dc->desc = "StrongARM GPIO controller";
|
2014-06-29 19:38:39 +02:00
|
|
|
dc->vmsd = &vmstate_strongarm_gpio_regs;
|
2012-01-24 20:12:29 +01:00
|
|
|
}
|
|
|
|
|
2013-01-10 16:19:07 +01:00
|
|
|
static const TypeInfo strongarm_gpio_info = {
|
2013-07-24 09:23:14 +02:00
|
|
|
.name = TYPE_STRONGARM_GPIO,
|
2011-12-08 04:34:16 +01:00
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(StrongARMGPIOInfo),
|
2016-03-07 08:05:49 +01:00
|
|
|
.instance_init = strongarm_gpio_initfn,
|
2011-12-08 04:34:16 +01:00
|
|
|
.class_init = strongarm_gpio_class_init,
|
2011-04-19 16:56:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Peripheral Pin Controller */
|
|
|
|
#define PPDR 0x00
|
|
|
|
#define PPSR 0x04
|
|
|
|
#define PPAR 0x08
|
|
|
|
#define PSDR 0x0c
|
|
|
|
#define PPFR 0x10
|
|
|
|
|
2013-07-24 09:26:04 +02:00
|
|
|
#define TYPE_STRONGARM_PPC "strongarm-ppc"
|
2020-09-16 20:25:19 +02:00
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(StrongARMPPCInfo, STRONGARM_PPC)
|
2013-07-24 09:26:04 +02:00
|
|
|
|
2011-04-19 16:56:45 +02:00
|
|
|
struct StrongARMPPCInfo {
|
2013-07-24 09:26:04 +02:00
|
|
|
SysBusDevice parent_obj;
|
|
|
|
|
2011-10-03 14:14:20 +02:00
|
|
|
MemoryRegion iomem;
|
2011-04-19 16:56:45 +02:00
|
|
|
qemu_irq handler[28];
|
|
|
|
|
|
|
|
uint32_t ilevel;
|
|
|
|
uint32_t olevel;
|
|
|
|
uint32_t dir;
|
|
|
|
uint32_t ppar;
|
|
|
|
uint32_t psdr;
|
|
|
|
uint32_t ppfr;
|
|
|
|
|
|
|
|
uint32_t prev_level;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void strongarm_ppc_set(void *opaque, int line, int level)
|
|
|
|
{
|
|
|
|
StrongARMPPCInfo *s = opaque;
|
|
|
|
|
|
|
|
if (level) {
|
|
|
|
s->ilevel |= 1 << line;
|
|
|
|
} else {
|
|
|
|
s->ilevel &= ~(1 << line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void strongarm_ppc_handler_update(StrongARMPPCInfo *s)
|
|
|
|
{
|
|
|
|
uint32_t level, diff;
|
|
|
|
int bit;
|
|
|
|
|
|
|
|
level = s->olevel & s->dir;
|
|
|
|
|
|
|
|
for (diff = s->prev_level ^ level; diff; diff ^= 1 << bit) {
|
2015-03-23 16:29:26 +01:00
|
|
|
bit = ctz32(diff);
|
2011-04-19 16:56:45 +02:00
|
|
|
qemu_set_irq(s->handler[bit], (level >> bit) & 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
s->prev_level = level;
|
|
|
|
}
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
static uint64_t strongarm_ppc_read(void *opaque, hwaddr offset,
|
2011-10-03 14:14:20 +02:00
|
|
|
unsigned size)
|
2011-04-19 16:56:45 +02:00
|
|
|
{
|
|
|
|
StrongARMPPCInfo *s = opaque;
|
|
|
|
|
|
|
|
switch (offset) {
|
|
|
|
case PPDR: /* PPC Pin Direction registers */
|
|
|
|
return s->dir | ~0x3fffff;
|
|
|
|
|
|
|
|
case PPSR: /* PPC Pin State registers */
|
|
|
|
return (s->olevel & s->dir) |
|
|
|
|
(s->ilevel & ~s->dir) |
|
|
|
|
~0x3fffff;
|
|
|
|
|
|
|
|
case PPAR:
|
|
|
|
return s->ppar | ~0x41000;
|
|
|
|
|
|
|
|
case PSDR:
|
|
|
|
return s->psdr;
|
|
|
|
|
|
|
|
case PPFR:
|
|
|
|
return s->ppfr | ~0x7f001;
|
|
|
|
|
|
|
|
default:
|
2023-01-10 22:29:47 +01:00
|
|
|
printf("%s: Bad offset 0x" HWADDR_FMT_plx "\n", __func__, offset);
|
2011-04-19 16:56:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
static void strongarm_ppc_write(void *opaque, hwaddr offset,
|
2011-10-03 14:14:20 +02:00
|
|
|
uint64_t value, unsigned size)
|
2011-04-19 16:56:45 +02:00
|
|
|
{
|
|
|
|
StrongARMPPCInfo *s = opaque;
|
|
|
|
|
|
|
|
switch (offset) {
|
|
|
|
case PPDR: /* PPC Pin Direction registers */
|
|
|
|
s->dir = value & 0x3fffff;
|
|
|
|
strongarm_ppc_handler_update(s);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PPSR: /* PPC Pin State registers */
|
|
|
|
s->olevel = value & s->dir & 0x3fffff;
|
|
|
|
strongarm_ppc_handler_update(s);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PPAR:
|
|
|
|
s->ppar = value & 0x41000;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PSDR:
|
|
|
|
s->psdr = value & 0x3fffff;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PPFR:
|
|
|
|
s->ppfr = value & 0x7f001;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2023-01-10 22:29:47 +01:00
|
|
|
printf("%s: Bad offset 0x" HWADDR_FMT_plx "\n", __func__, offset);
|
2011-04-19 16:56:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-03 14:14:20 +02:00
|
|
|
static const MemoryRegionOps strongarm_ppc_ops = {
|
|
|
|
.read = strongarm_ppc_read,
|
|
|
|
.write = strongarm_ppc_write,
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
2011-04-19 16:56:45 +02:00
|
|
|
};
|
|
|
|
|
2016-03-07 08:05:49 +01:00
|
|
|
static void strongarm_ppc_init(Object *obj)
|
2011-04-19 16:56:45 +02:00
|
|
|
{
|
2016-03-07 08:05:49 +01:00
|
|
|
DeviceState *dev = DEVICE(obj);
|
|
|
|
StrongARMPPCInfo *s = STRONGARM_PPC(obj);
|
|
|
|
SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
|
2011-04-19 16:56:45 +02:00
|
|
|
|
2013-07-24 09:26:04 +02:00
|
|
|
qdev_init_gpio_in(dev, strongarm_ppc_set, 22);
|
|
|
|
qdev_init_gpio_out(dev, s->handler, 22);
|
2011-04-19 16:56:45 +02:00
|
|
|
|
2016-03-07 08:05:49 +01:00
|
|
|
memory_region_init_io(&s->iomem, obj, &strongarm_ppc_ops, s,
|
2013-06-07 03:25:08 +02:00
|
|
|
"ppc", 0x1000);
|
2011-04-19 16:56:45 +02:00
|
|
|
|
2013-07-24 09:26:04 +02:00
|
|
|
sysbus_init_mmio(sbd, &s->iomem);
|
2011-04-19 16:56:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_strongarm_ppc_regs = {
|
|
|
|
.name = "strongarm-ppc",
|
|
|
|
.version_id = 0,
|
|
|
|
.minimum_version_id = 0,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_UINT32(ilevel, StrongARMPPCInfo),
|
|
|
|
VMSTATE_UINT32(olevel, StrongARMPPCInfo),
|
|
|
|
VMSTATE_UINT32(dir, StrongARMPPCInfo),
|
|
|
|
VMSTATE_UINT32(ppar, StrongARMPPCInfo),
|
|
|
|
VMSTATE_UINT32(psdr, StrongARMPPCInfo),
|
|
|
|
VMSTATE_UINT32(ppfr, StrongARMPPCInfo),
|
2014-06-29 19:38:39 +02:00
|
|
|
VMSTATE_UINT32(prev_level, StrongARMPPCInfo),
|
2011-04-19 16:56:45 +02:00
|
|
|
VMSTATE_END_OF_LIST(),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2012-01-24 20:12:29 +01:00
|
|
|
static void strongarm_ppc_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2012-01-24 20:12:29 +01:00
|
|
|
|
2011-12-08 04:34:16 +01:00
|
|
|
dc->desc = "StrongARM PPC controller";
|
2014-06-29 19:38:39 +02:00
|
|
|
dc->vmsd = &vmstate_strongarm_ppc_regs;
|
2012-01-24 20:12:29 +01:00
|
|
|
}
|
|
|
|
|
2013-01-10 16:19:07 +01:00
|
|
|
static const TypeInfo strongarm_ppc_info = {
|
2013-07-24 09:26:04 +02:00
|
|
|
.name = TYPE_STRONGARM_PPC,
|
2011-12-08 04:34:16 +01:00
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(StrongARMPPCInfo),
|
2016-03-07 08:05:49 +01:00
|
|
|
.instance_init = strongarm_ppc_init,
|
2011-12-08 04:34:16 +01:00
|
|
|
.class_init = strongarm_ppc_class_init,
|
2011-04-19 16:56:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* UART Ports */
|
|
|
|
#define UTCR0 0x00
|
|
|
|
#define UTCR1 0x04
|
|
|
|
#define UTCR2 0x08
|
|
|
|
#define UTCR3 0x0c
|
|
|
|
#define UTDR 0x14
|
|
|
|
#define UTSR0 0x1c
|
|
|
|
#define UTSR1 0x20
|
|
|
|
|
|
|
|
#define UTCR0_PE (1 << 0) /* Parity enable */
|
|
|
|
#define UTCR0_OES (1 << 1) /* Even parity */
|
|
|
|
#define UTCR0_SBS (1 << 2) /* 2 stop bits */
|
|
|
|
#define UTCR0_DSS (1 << 3) /* 8-bit data */
|
|
|
|
|
|
|
|
#define UTCR3_RXE (1 << 0) /* Rx enable */
|
|
|
|
#define UTCR3_TXE (1 << 1) /* Tx enable */
|
|
|
|
#define UTCR3_BRK (1 << 2) /* Force Break */
|
|
|
|
#define UTCR3_RIE (1 << 3) /* Rx int enable */
|
|
|
|
#define UTCR3_TIE (1 << 4) /* Tx int enable */
|
|
|
|
#define UTCR3_LBM (1 << 5) /* Loopback */
|
|
|
|
|
|
|
|
#define UTSR0_TFS (1 << 0) /* Tx FIFO nearly empty */
|
|
|
|
#define UTSR0_RFS (1 << 1) /* Rx FIFO nearly full */
|
|
|
|
#define UTSR0_RID (1 << 2) /* Receiver Idle */
|
|
|
|
#define UTSR0_RBB (1 << 3) /* Receiver begin break */
|
|
|
|
#define UTSR0_REB (1 << 4) /* Receiver end break */
|
|
|
|
#define UTSR0_EIF (1 << 5) /* Error in FIFO */
|
|
|
|
|
|
|
|
#define UTSR1_RNE (1 << 1) /* Receive FIFO not empty */
|
|
|
|
#define UTSR1_TNF (1 << 2) /* Transmit FIFO not full */
|
|
|
|
#define UTSR1_PRE (1 << 3) /* Parity error */
|
|
|
|
#define UTSR1_FRE (1 << 4) /* Frame error */
|
|
|
|
#define UTSR1_ROR (1 << 5) /* Receive Over Run */
|
|
|
|
|
|
|
|
#define RX_FIFO_PRE (1 << 8)
|
|
|
|
#define RX_FIFO_FRE (1 << 9)
|
|
|
|
#define RX_FIFO_ROR (1 << 10)
|
|
|
|
|
2013-07-24 09:29:14 +02:00
|
|
|
#define TYPE_STRONGARM_UART "strongarm-uart"
|
2020-09-16 20:25:19 +02:00
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(StrongARMUARTState, STRONGARM_UART)
|
2013-07-24 09:29:14 +02:00
|
|
|
|
2020-09-03 22:43:22 +02:00
|
|
|
struct StrongARMUARTState {
|
2013-07-24 09:29:14 +02:00
|
|
|
SysBusDevice parent_obj;
|
|
|
|
|
2011-10-03 14:14:20 +02:00
|
|
|
MemoryRegion iomem;
|
2016-10-22 11:52:51 +02:00
|
|
|
CharBackend chr;
|
2011-04-19 16:56:45 +02:00
|
|
|
qemu_irq irq;
|
|
|
|
|
|
|
|
uint8_t utcr0;
|
|
|
|
uint16_t brd;
|
|
|
|
uint8_t utcr3;
|
|
|
|
uint8_t utsr0;
|
|
|
|
uint8_t utsr1;
|
|
|
|
|
|
|
|
uint8_t tx_fifo[8];
|
|
|
|
uint8_t tx_start;
|
|
|
|
uint8_t tx_len;
|
|
|
|
uint16_t rx_fifo[12]; /* value + error flags in high bits */
|
|
|
|
uint8_t rx_start;
|
|
|
|
uint8_t rx_len;
|
|
|
|
|
2020-10-14 23:36:01 +02:00
|
|
|
uint64_t char_transmit_time; /* time to transmit a char in nanoseconds */
|
2011-04-19 16:56:45 +02:00
|
|
|
bool wait_break_end;
|
|
|
|
QEMUTimer *rx_timeout_timer;
|
|
|
|
QEMUTimer *tx_timer;
|
2020-09-03 22:43:22 +02:00
|
|
|
};
|
2011-04-19 16:56:45 +02:00
|
|
|
|
|
|
|
static void strongarm_uart_update_status(StrongARMUARTState *s)
|
|
|
|
{
|
|
|
|
uint16_t utsr1 = 0;
|
|
|
|
|
|
|
|
if (s->tx_len != 8) {
|
|
|
|
utsr1 |= UTSR1_TNF;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s->rx_len != 0) {
|
|
|
|
uint16_t ent = s->rx_fifo[s->rx_start];
|
|
|
|
|
|
|
|
utsr1 |= UTSR1_RNE;
|
|
|
|
if (ent & RX_FIFO_PRE) {
|
|
|
|
s->utsr1 |= UTSR1_PRE;
|
|
|
|
}
|
|
|
|
if (ent & RX_FIFO_FRE) {
|
|
|
|
s->utsr1 |= UTSR1_FRE;
|
|
|
|
}
|
|
|
|
if (ent & RX_FIFO_ROR) {
|
|
|
|
s->utsr1 |= UTSR1_ROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
s->utsr1 = utsr1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void strongarm_uart_update_int_status(StrongARMUARTState *s)
|
|
|
|
{
|
|
|
|
uint16_t utsr0 = s->utsr0 &
|
|
|
|
(UTSR0_REB | UTSR0_RBB | UTSR0_RID);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if ((s->utcr3 & UTCR3_TXE) &&
|
|
|
|
(s->utcr3 & UTCR3_TIE) &&
|
|
|
|
s->tx_len <= 4) {
|
|
|
|
utsr0 |= UTSR0_TFS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((s->utcr3 & UTCR3_RXE) &&
|
|
|
|
(s->utcr3 & UTCR3_RIE) &&
|
|
|
|
s->rx_len > 4) {
|
|
|
|
utsr0 |= UTSR0_RFS;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < s->rx_len && i < 4; i++)
|
|
|
|
if (s->rx_fifo[(s->rx_start + i) % 12] & ~0xff) {
|
|
|
|
utsr0 |= UTSR0_EIF;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
s->utsr0 = utsr0;
|
|
|
|
qemu_set_irq(s->irq, utsr0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void strongarm_uart_update_parameters(StrongARMUARTState *s)
|
|
|
|
{
|
|
|
|
int speed, parity, data_bits, stop_bits, frame_size;
|
|
|
|
QEMUSerialSetParams ssp;
|
|
|
|
|
|
|
|
/* Start bit. */
|
|
|
|
frame_size = 1;
|
|
|
|
if (s->utcr0 & UTCR0_PE) {
|
|
|
|
/* Parity bit. */
|
|
|
|
frame_size++;
|
|
|
|
if (s->utcr0 & UTCR0_OES) {
|
|
|
|
parity = 'E';
|
|
|
|
} else {
|
|
|
|
parity = 'O';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
parity = 'N';
|
|
|
|
}
|
|
|
|
if (s->utcr0 & UTCR0_SBS) {
|
|
|
|
stop_bits = 2;
|
|
|
|
} else {
|
|
|
|
stop_bits = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
data_bits = (s->utcr0 & UTCR0_DSS) ? 8 : 7;
|
|
|
|
frame_size += data_bits + stop_bits;
|
|
|
|
speed = 3686400 / 16 / (s->brd + 1);
|
|
|
|
ssp.speed = speed;
|
|
|
|
ssp.parity = parity;
|
|
|
|
ssp.data_bits = data_bits;
|
|
|
|
ssp.stop_bits = stop_bits;
|
2016-03-21 17:02:30 +01:00
|
|
|
s->char_transmit_time = (NANOSECONDS_PER_SECOND / speed) * frame_size;
|
2016-10-22 11:52:59 +02:00
|
|
|
qemu_chr_fe_ioctl(&s->chr, CHR_IOCTL_SERIAL_SET_PARAMS, &ssp);
|
2011-04-19 16:56:45 +02:00
|
|
|
|
|
|
|
DPRINTF(stderr, "%s speed=%d parity=%c data=%d stop=%d\n", s->chr->label,
|
|
|
|
speed, parity, data_bits, stop_bits);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void strongarm_uart_rx_to(void *opaque)
|
|
|
|
{
|
|
|
|
StrongARMUARTState *s = opaque;
|
|
|
|
|
|
|
|
if (s->rx_len) {
|
|
|
|
s->utsr0 |= UTSR0_RID;
|
|
|
|
strongarm_uart_update_int_status(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void strongarm_uart_rx_push(StrongARMUARTState *s, uint16_t c)
|
|
|
|
{
|
|
|
|
if ((s->utcr3 & UTCR3_RXE) == 0) {
|
|
|
|
/* rx disabled */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s->wait_break_end) {
|
|
|
|
s->utsr0 |= UTSR0_REB;
|
|
|
|
s->wait_break_end = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s->rx_len < 12) {
|
|
|
|
s->rx_fifo[(s->rx_start + s->rx_len) % 12] = c;
|
|
|
|
s->rx_len++;
|
|
|
|
} else
|
|
|
|
s->rx_fifo[(s->rx_start + 11) % 12] |= RX_FIFO_ROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int strongarm_uart_can_receive(void *opaque)
|
|
|
|
{
|
|
|
|
StrongARMUARTState *s = opaque;
|
|
|
|
|
|
|
|
if (s->rx_len == 12) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* It's best not to get more than 2/3 of RX FIFO, so advertise that much */
|
|
|
|
if (s->rx_len < 8) {
|
|
|
|
return 8 - s->rx_len;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void strongarm_uart_receive(void *opaque, const uint8_t *buf, int size)
|
|
|
|
{
|
|
|
|
StrongARMUARTState *s = opaque;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < size; i++) {
|
|
|
|
strongarm_uart_rx_push(s, buf[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* call the timeout receive callback in 3 char transmit time */
|
2013-08-21 17:03:08 +02:00
|
|
|
timer_mod(s->rx_timeout_timer,
|
|
|
|
qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + s->char_transmit_time * 3);
|
2011-04-19 16:56:45 +02:00
|
|
|
|
|
|
|
strongarm_uart_update_status(s);
|
|
|
|
strongarm_uart_update_int_status(s);
|
|
|
|
}
|
|
|
|
|
chardev: Use QEMUChrEvent enum in IOEventHandler typedef
The Chardev events are listed in the QEMUChrEvent enum.
By using the enum in the IOEventHandler typedef we:
- make the IOEventHandler type more explicit (this handler
process out-of-band information, while the IOReadHandler
is in-band),
- help static code analyzers.
This patch was produced with the following spatch script:
@match@
expression backend, opaque, context, set_open;
identifier fd_can_read, fd_read, fd_event, be_change;
@@
qemu_chr_fe_set_handlers(backend, fd_can_read, fd_read, fd_event,
be_change, opaque, context, set_open);
@depends on match@
identifier opaque, event;
identifier match.fd_event;
@@
static
-void fd_event(void *opaque, int event)
+void fd_event(void *opaque, QEMUChrEvent event)
{
...
}
Then the typedef was modified manually in
include/chardev/char-fe.h.
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Acked-by: Corey Minyard <cminyard@mvista.com>
Acked-by: Cornelia Huck <cohuck@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20191218172009.8868-15-philmd@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2019-12-18 18:20:09 +01:00
|
|
|
static void strongarm_uart_event(void *opaque, QEMUChrEvent event)
|
2011-04-19 16:56:45 +02:00
|
|
|
{
|
|
|
|
StrongARMUARTState *s = opaque;
|
|
|
|
if (event == CHR_EVENT_BREAK) {
|
|
|
|
s->utsr0 |= UTSR0_RBB;
|
|
|
|
strongarm_uart_rx_push(s, RX_FIFO_FRE);
|
|
|
|
s->wait_break_end = true;
|
|
|
|
strongarm_uart_update_status(s);
|
|
|
|
strongarm_uart_update_int_status(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void strongarm_uart_tx(void *opaque)
|
|
|
|
{
|
|
|
|
StrongARMUARTState *s = opaque;
|
2013-08-21 17:03:08 +02:00
|
|
|
uint64_t new_xmit_ts = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
|
2011-04-19 16:56:45 +02:00
|
|
|
|
|
|
|
if (s->utcr3 & UTCR3_LBM) /* loopback */ {
|
|
|
|
strongarm_uart_receive(s, &s->tx_fifo[s->tx_start], 1);
|
2017-07-06 14:08:52 +02:00
|
|
|
} else if (qemu_chr_fe_backend_connected(&s->chr)) {
|
2016-09-06 15:56:04 +02:00
|
|
|
/* XXX this blocks entire thread. Rewrite to use
|
|
|
|
* qemu_chr_fe_write and background I/O callbacks */
|
2016-10-22 11:52:55 +02:00
|
|
|
qemu_chr_fe_write_all(&s->chr, &s->tx_fifo[s->tx_start], 1);
|
2011-04-19 16:56:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
s->tx_start = (s->tx_start + 1) % 8;
|
|
|
|
s->tx_len--;
|
|
|
|
if (s->tx_len) {
|
2013-08-21 17:03:08 +02:00
|
|
|
timer_mod(s->tx_timer, new_xmit_ts + s->char_transmit_time);
|
2011-04-19 16:56:45 +02:00
|
|
|
}
|
|
|
|
strongarm_uart_update_status(s);
|
|
|
|
strongarm_uart_update_int_status(s);
|
|
|
|
}
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
static uint64_t strongarm_uart_read(void *opaque, hwaddr addr,
|
2011-10-03 14:14:20 +02:00
|
|
|
unsigned size)
|
2011-04-19 16:56:45 +02:00
|
|
|
{
|
|
|
|
StrongARMUARTState *s = opaque;
|
|
|
|
uint16_t ret;
|
|
|
|
|
|
|
|
switch (addr) {
|
|
|
|
case UTCR0:
|
|
|
|
return s->utcr0;
|
|
|
|
|
|
|
|
case UTCR1:
|
|
|
|
return s->brd >> 8;
|
|
|
|
|
|
|
|
case UTCR2:
|
|
|
|
return s->brd & 0xff;
|
|
|
|
|
|
|
|
case UTCR3:
|
|
|
|
return s->utcr3;
|
|
|
|
|
|
|
|
case UTDR:
|
|
|
|
if (s->rx_len != 0) {
|
|
|
|
ret = s->rx_fifo[s->rx_start];
|
|
|
|
s->rx_start = (s->rx_start + 1) % 12;
|
|
|
|
s->rx_len--;
|
|
|
|
strongarm_uart_update_status(s);
|
|
|
|
strongarm_uart_update_int_status(s);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case UTSR0:
|
|
|
|
return s->utsr0;
|
|
|
|
|
|
|
|
case UTSR1:
|
|
|
|
return s->utsr1;
|
|
|
|
|
|
|
|
default:
|
2023-01-10 22:29:47 +01:00
|
|
|
printf("%s: Bad register 0x" HWADDR_FMT_plx "\n", __func__, addr);
|
2011-04-19 16:56:45 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
static void strongarm_uart_write(void *opaque, hwaddr addr,
|
2011-10-03 14:14:20 +02:00
|
|
|
uint64_t value, unsigned size)
|
2011-04-19 16:56:45 +02:00
|
|
|
{
|
|
|
|
StrongARMUARTState *s = opaque;
|
|
|
|
|
|
|
|
switch (addr) {
|
|
|
|
case UTCR0:
|
|
|
|
s->utcr0 = value & 0x7f;
|
|
|
|
strongarm_uart_update_parameters(s);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UTCR1:
|
|
|
|
s->brd = (s->brd & 0xff) | ((value & 0xf) << 8);
|
|
|
|
strongarm_uart_update_parameters(s);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UTCR2:
|
|
|
|
s->brd = (s->brd & 0xf00) | (value & 0xff);
|
|
|
|
strongarm_uart_update_parameters(s);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UTCR3:
|
|
|
|
s->utcr3 = value & 0x3f;
|
|
|
|
if ((s->utcr3 & UTCR3_RXE) == 0) {
|
|
|
|
s->rx_len = 0;
|
|
|
|
}
|
|
|
|
if ((s->utcr3 & UTCR3_TXE) == 0) {
|
|
|
|
s->tx_len = 0;
|
|
|
|
}
|
|
|
|
strongarm_uart_update_status(s);
|
|
|
|
strongarm_uart_update_int_status(s);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UTDR:
|
|
|
|
if ((s->utcr3 & UTCR3_TXE) && s->tx_len != 8) {
|
|
|
|
s->tx_fifo[(s->tx_start + s->tx_len) % 8] = value;
|
|
|
|
s->tx_len++;
|
|
|
|
strongarm_uart_update_status(s);
|
|
|
|
strongarm_uart_update_int_status(s);
|
|
|
|
if (s->tx_len == 1) {
|
|
|
|
strongarm_uart_tx(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UTSR0:
|
|
|
|
s->utsr0 = s->utsr0 & ~(value &
|
|
|
|
(UTSR0_REB | UTSR0_RBB | UTSR0_RID));
|
|
|
|
strongarm_uart_update_int_status(s);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2023-01-10 22:29:47 +01:00
|
|
|
printf("%s: Bad register 0x" HWADDR_FMT_plx "\n", __func__, addr);
|
2011-04-19 16:56:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-03 14:14:20 +02:00
|
|
|
static const MemoryRegionOps strongarm_uart_ops = {
|
|
|
|
.read = strongarm_uart_read,
|
|
|
|
.write = strongarm_uart_write,
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
2011-04-19 16:56:45 +02:00
|
|
|
};
|
|
|
|
|
2016-03-07 08:05:49 +01:00
|
|
|
static void strongarm_uart_init(Object *obj)
|
2011-04-19 16:56:45 +02:00
|
|
|
{
|
2016-03-07 08:05:49 +01:00
|
|
|
StrongARMUARTState *s = STRONGARM_UART(obj);
|
|
|
|
SysBusDevice *dev = SYS_BUS_DEVICE(obj);
|
2011-04-19 16:56:45 +02:00
|
|
|
|
2016-03-07 08:05:49 +01:00
|
|
|
memory_region_init_io(&s->iomem, obj, &strongarm_uart_ops, s,
|
2013-06-07 03:25:08 +02:00
|
|
|
"uart", 0x10000);
|
2011-11-27 10:38:10 +01:00
|
|
|
sysbus_init_mmio(dev, &s->iomem);
|
2011-04-19 16:56:45 +02:00
|
|
|
sysbus_init_irq(dev, &s->irq);
|
2016-10-24 17:26:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void strongarm_uart_realize(DeviceState *dev, Error **errp)
|
|
|
|
{
|
|
|
|
StrongARMUARTState *s = STRONGARM_UART(dev);
|
2011-04-19 16:56:45 +02:00
|
|
|
|
2020-03-05 17:09:16 +01:00
|
|
|
s->rx_timeout_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,
|
|
|
|
strongarm_uart_rx_to,
|
|
|
|
s);
|
|
|
|
s->tx_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, strongarm_uart_tx, s);
|
2016-10-22 11:52:59 +02:00
|
|
|
qemu_chr_fe_set_handlers(&s->chr,
|
|
|
|
strongarm_uart_can_receive,
|
|
|
|
strongarm_uart_receive,
|
|
|
|
strongarm_uart_event,
|
2017-07-06 14:08:49 +02:00
|
|
|
NULL, s, NULL, true);
|
2011-04-19 16:56:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void strongarm_uart_reset(DeviceState *dev)
|
|
|
|
{
|
2013-07-24 09:29:14 +02:00
|
|
|
StrongARMUARTState *s = STRONGARM_UART(dev);
|
2011-04-19 16:56:45 +02:00
|
|
|
|
|
|
|
s->utcr0 = UTCR0_DSS; /* 8 data, no parity */
|
|
|
|
s->brd = 23; /* 9600 */
|
|
|
|
/* enable send & recv - this actually violates spec */
|
|
|
|
s->utcr3 = UTCR3_TXE | UTCR3_RXE;
|
|
|
|
|
|
|
|
s->rx_len = s->tx_len = 0;
|
|
|
|
|
|
|
|
strongarm_uart_update_parameters(s);
|
|
|
|
strongarm_uart_update_status(s);
|
|
|
|
strongarm_uart_update_int_status(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int strongarm_uart_post_load(void *opaque, int version_id)
|
|
|
|
{
|
|
|
|
StrongARMUARTState *s = opaque;
|
|
|
|
|
|
|
|
strongarm_uart_update_parameters(s);
|
|
|
|
strongarm_uart_update_status(s);
|
|
|
|
strongarm_uart_update_int_status(s);
|
|
|
|
|
|
|
|
/* tx and restart timer */
|
|
|
|
if (s->tx_len) {
|
|
|
|
strongarm_uart_tx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* restart rx timeout timer */
|
|
|
|
if (s->rx_len) {
|
2013-08-21 17:03:08 +02:00
|
|
|
timer_mod(s->rx_timeout_timer,
|
|
|
|
qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + s->char_transmit_time * 3);
|
2011-04-19 16:56:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_strongarm_uart_regs = {
|
|
|
|
.name = "strongarm-uart",
|
|
|
|
.version_id = 0,
|
|
|
|
.minimum_version_id = 0,
|
|
|
|
.post_load = strongarm_uart_post_load,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_UINT8(utcr0, StrongARMUARTState),
|
|
|
|
VMSTATE_UINT16(brd, StrongARMUARTState),
|
|
|
|
VMSTATE_UINT8(utcr3, StrongARMUARTState),
|
|
|
|
VMSTATE_UINT8(utsr0, StrongARMUARTState),
|
|
|
|
VMSTATE_UINT8_ARRAY(tx_fifo, StrongARMUARTState, 8),
|
|
|
|
VMSTATE_UINT8(tx_start, StrongARMUARTState),
|
|
|
|
VMSTATE_UINT8(tx_len, StrongARMUARTState),
|
|
|
|
VMSTATE_UINT16_ARRAY(rx_fifo, StrongARMUARTState, 12),
|
|
|
|
VMSTATE_UINT8(rx_start, StrongARMUARTState),
|
|
|
|
VMSTATE_UINT8(rx_len, StrongARMUARTState),
|
|
|
|
VMSTATE_BOOL(wait_break_end, StrongARMUARTState),
|
|
|
|
VMSTATE_END_OF_LIST(),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2012-01-24 20:12:29 +01:00
|
|
|
static Property strongarm_uart_properties[] = {
|
|
|
|
DEFINE_PROP_CHR("chardev", StrongARMUARTState, chr),
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
|
|
|
static void strongarm_uart_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2012-01-24 20:12:29 +01:00
|
|
|
|
2011-12-08 04:34:16 +01:00
|
|
|
dc->desc = "StrongARM UART controller";
|
|
|
|
dc->reset = strongarm_uart_reset;
|
|
|
|
dc->vmsd = &vmstate_strongarm_uart_regs;
|
2020-01-10 16:30:32 +01:00
|
|
|
device_class_set_props(dc, strongarm_uart_properties);
|
2016-10-24 17:26:56 +02:00
|
|
|
dc->realize = strongarm_uart_realize;
|
2012-01-24 20:12:29 +01:00
|
|
|
}
|
|
|
|
|
2013-01-10 16:19:07 +01:00
|
|
|
static const TypeInfo strongarm_uart_info = {
|
2013-07-24 09:29:14 +02:00
|
|
|
.name = TYPE_STRONGARM_UART,
|
2011-12-08 04:34:16 +01:00
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(StrongARMUARTState),
|
2016-03-07 08:05:49 +01:00
|
|
|
.instance_init = strongarm_uart_init,
|
2011-12-08 04:34:16 +01:00
|
|
|
.class_init = strongarm_uart_class_init,
|
2011-04-19 16:56:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Synchronous Serial Ports */
|
2013-07-24 09:32:06 +02:00
|
|
|
|
|
|
|
#define TYPE_STRONGARM_SSP "strongarm-ssp"
|
2020-09-16 20:25:19 +02:00
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(StrongARMSSPState, STRONGARM_SSP)
|
2013-07-24 09:32:06 +02:00
|
|
|
|
2020-09-03 22:43:22 +02:00
|
|
|
struct StrongARMSSPState {
|
2013-07-24 09:32:06 +02:00
|
|
|
SysBusDevice parent_obj;
|
|
|
|
|
2011-10-03 14:14:20 +02:00
|
|
|
MemoryRegion iomem;
|
2011-04-19 16:56:45 +02:00
|
|
|
qemu_irq irq;
|
|
|
|
SSIBus *bus;
|
|
|
|
|
|
|
|
uint16_t sscr[2];
|
|
|
|
uint16_t sssr;
|
|
|
|
|
|
|
|
uint16_t rx_fifo[8];
|
|
|
|
uint8_t rx_level;
|
|
|
|
uint8_t rx_start;
|
2020-09-03 22:43:22 +02:00
|
|
|
};
|
2011-04-19 16:56:45 +02:00
|
|
|
|
|
|
|
#define SSCR0 0x60 /* SSP Control register 0 */
|
|
|
|
#define SSCR1 0x64 /* SSP Control register 1 */
|
|
|
|
#define SSDR 0x6c /* SSP Data register */
|
|
|
|
#define SSSR 0x74 /* SSP Status register */
|
|
|
|
|
|
|
|
/* Bitfields for above registers */
|
|
|
|
#define SSCR0_SPI(x) (((x) & 0x30) == 0x00)
|
|
|
|
#define SSCR0_SSP(x) (((x) & 0x30) == 0x10)
|
|
|
|
#define SSCR0_UWIRE(x) (((x) & 0x30) == 0x20)
|
|
|
|
#define SSCR0_PSP(x) (((x) & 0x30) == 0x30)
|
|
|
|
#define SSCR0_SSE (1 << 7)
|
|
|
|
#define SSCR0_DSS(x) (((x) & 0xf) + 1)
|
|
|
|
#define SSCR1_RIE (1 << 0)
|
|
|
|
#define SSCR1_TIE (1 << 1)
|
|
|
|
#define SSCR1_LBM (1 << 2)
|
|
|
|
#define SSSR_TNF (1 << 2)
|
|
|
|
#define SSSR_RNE (1 << 3)
|
|
|
|
#define SSSR_TFS (1 << 5)
|
|
|
|
#define SSSR_RFS (1 << 6)
|
|
|
|
#define SSSR_ROR (1 << 7)
|
|
|
|
#define SSSR_RW 0x0080
|
|
|
|
|
|
|
|
static void strongarm_ssp_int_update(StrongARMSSPState *s)
|
|
|
|
{
|
|
|
|
int level = 0;
|
|
|
|
|
|
|
|
level |= (s->sssr & SSSR_ROR);
|
|
|
|
level |= (s->sssr & SSSR_RFS) && (s->sscr[1] & SSCR1_RIE);
|
|
|
|
level |= (s->sssr & SSSR_TFS) && (s->sscr[1] & SSCR1_TIE);
|
|
|
|
qemu_set_irq(s->irq, level);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void strongarm_ssp_fifo_update(StrongARMSSPState *s)
|
|
|
|
{
|
|
|
|
s->sssr &= ~SSSR_TFS;
|
|
|
|
s->sssr &= ~SSSR_TNF;
|
|
|
|
if (s->sscr[0] & SSCR0_SSE) {
|
|
|
|
if (s->rx_level >= 4) {
|
|
|
|
s->sssr |= SSSR_RFS;
|
|
|
|
} else {
|
|
|
|
s->sssr &= ~SSSR_RFS;
|
|
|
|
}
|
|
|
|
if (s->rx_level) {
|
|
|
|
s->sssr |= SSSR_RNE;
|
|
|
|
} else {
|
|
|
|
s->sssr &= ~SSSR_RNE;
|
|
|
|
}
|
|
|
|
/* TX FIFO is never filled, so it is always in underrun
|
|
|
|
condition if SSP is enabled */
|
|
|
|
s->sssr |= SSSR_TFS;
|
|
|
|
s->sssr |= SSSR_TNF;
|
|
|
|
}
|
|
|
|
|
|
|
|
strongarm_ssp_int_update(s);
|
|
|
|
}
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
static uint64_t strongarm_ssp_read(void *opaque, hwaddr addr,
|
2011-10-03 14:14:20 +02:00
|
|
|
unsigned size)
|
2011-04-19 16:56:45 +02:00
|
|
|
{
|
|
|
|
StrongARMSSPState *s = opaque;
|
|
|
|
uint32_t retval;
|
|
|
|
|
|
|
|
switch (addr) {
|
|
|
|
case SSCR0:
|
|
|
|
return s->sscr[0];
|
|
|
|
case SSCR1:
|
|
|
|
return s->sscr[1];
|
|
|
|
case SSSR:
|
|
|
|
return s->sssr;
|
|
|
|
case SSDR:
|
|
|
|
if (~s->sscr[0] & SSCR0_SSE) {
|
|
|
|
return 0xffffffff;
|
|
|
|
}
|
|
|
|
if (s->rx_level < 1) {
|
|
|
|
printf("%s: SSP Rx Underrun\n", __func__);
|
|
|
|
return 0xffffffff;
|
|
|
|
}
|
|
|
|
s->rx_level--;
|
|
|
|
retval = s->rx_fifo[s->rx_start++];
|
|
|
|
s->rx_start &= 0x7;
|
|
|
|
strongarm_ssp_fifo_update(s);
|
|
|
|
return retval;
|
|
|
|
default:
|
2023-01-10 22:29:47 +01:00
|
|
|
printf("%s: Bad register 0x" HWADDR_FMT_plx "\n", __func__, addr);
|
2011-04-19 16:56:45 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-23 12:30:10 +02:00
|
|
|
static void strongarm_ssp_write(void *opaque, hwaddr addr,
|
2011-10-03 14:14:20 +02:00
|
|
|
uint64_t value, unsigned size)
|
2011-04-19 16:56:45 +02:00
|
|
|
{
|
|
|
|
StrongARMSSPState *s = opaque;
|
|
|
|
|
|
|
|
switch (addr) {
|
|
|
|
case SSCR0:
|
|
|
|
s->sscr[0] = value & 0xffbf;
|
|
|
|
if ((s->sscr[0] & SSCR0_SSE) && SSCR0_DSS(value) < 4) {
|
|
|
|
printf("%s: Wrong data size: %i bits\n", __func__,
|
2011-10-03 14:14:20 +02:00
|
|
|
(int)SSCR0_DSS(value));
|
2011-04-19 16:56:45 +02:00
|
|
|
}
|
|
|
|
if (!(value & SSCR0_SSE)) {
|
|
|
|
s->sssr = 0;
|
|
|
|
s->rx_level = 0;
|
|
|
|
}
|
|
|
|
strongarm_ssp_fifo_update(s);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SSCR1:
|
|
|
|
s->sscr[1] = value & 0x2f;
|
|
|
|
if (value & SSCR1_LBM) {
|
|
|
|
printf("%s: Attempt to use SSP LBM mode\n", __func__);
|
|
|
|
}
|
|
|
|
strongarm_ssp_fifo_update(s);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SSSR:
|
|
|
|
s->sssr &= ~(value & SSSR_RW);
|
|
|
|
strongarm_ssp_int_update(s);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SSDR:
|
|
|
|
if (SSCR0_UWIRE(s->sscr[0])) {
|
|
|
|
value &= 0xff;
|
|
|
|
} else
|
|
|
|
/* Note how 32bits overflow does no harm here */
|
|
|
|
value &= (1 << SSCR0_DSS(s->sscr[0])) - 1;
|
|
|
|
|
|
|
|
/* Data goes from here to the Tx FIFO and is shifted out from
|
|
|
|
* there directly to the slave, no need to buffer it.
|
|
|
|
*/
|
|
|
|
if (s->sscr[0] & SSCR0_SSE) {
|
|
|
|
uint32_t readval;
|
|
|
|
if (s->sscr[1] & SSCR1_LBM) {
|
|
|
|
readval = value;
|
|
|
|
} else {
|
|
|
|
readval = ssi_transfer(s->bus, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s->rx_level < 0x08) {
|
|
|
|
s->rx_fifo[(s->rx_start + s->rx_level++) & 0x7] = readval;
|
|
|
|
} else {
|
|
|
|
s->sssr |= SSSR_ROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
strongarm_ssp_fifo_update(s);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2023-01-10 22:29:47 +01:00
|
|
|
printf("%s: Bad register 0x" HWADDR_FMT_plx "\n", __func__, addr);
|
2011-04-19 16:56:45 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-03 14:14:20 +02:00
|
|
|
static const MemoryRegionOps strongarm_ssp_ops = {
|
|
|
|
.read = strongarm_ssp_read,
|
|
|
|
.write = strongarm_ssp_write,
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
2011-04-19 16:56:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static int strongarm_ssp_post_load(void *opaque, int version_id)
|
|
|
|
{
|
|
|
|
StrongARMSSPState *s = opaque;
|
|
|
|
|
|
|
|
strongarm_ssp_fifo_update(s);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-10-24 17:26:56 +02:00
|
|
|
static void strongarm_ssp_init(Object *obj)
|
2011-04-19 16:56:45 +02:00
|
|
|
{
|
2016-10-24 17:26:56 +02:00
|
|
|
SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
|
2013-07-24 09:32:06 +02:00
|
|
|
DeviceState *dev = DEVICE(sbd);
|
|
|
|
StrongARMSSPState *s = STRONGARM_SSP(dev);
|
2011-04-19 16:56:45 +02:00
|
|
|
|
2013-07-24 09:32:06 +02:00
|
|
|
sysbus_init_irq(sbd, &s->irq);
|
2011-04-19 16:56:45 +02:00
|
|
|
|
2016-10-24 17:26:56 +02:00
|
|
|
memory_region_init_io(&s->iomem, obj, &strongarm_ssp_ops, s,
|
2013-06-07 03:25:08 +02:00
|
|
|
"ssp", 0x1000);
|
2013-07-24 09:32:06 +02:00
|
|
|
sysbus_init_mmio(sbd, &s->iomem);
|
2011-04-19 16:56:45 +02:00
|
|
|
|
2013-07-24 09:32:06 +02:00
|
|
|
s->bus = ssi_create_bus(dev, "ssi");
|
2011-04-19 16:56:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void strongarm_ssp_reset(DeviceState *dev)
|
|
|
|
{
|
2013-07-24 09:32:06 +02:00
|
|
|
StrongARMSSPState *s = STRONGARM_SSP(dev);
|
|
|
|
|
2011-04-19 16:56:45 +02:00
|
|
|
s->sssr = 0x03; /* 3 bit data, SPI, disabled */
|
|
|
|
s->rx_start = 0;
|
|
|
|
s->rx_level = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_strongarm_ssp_regs = {
|
|
|
|
.name = "strongarm-ssp",
|
|
|
|
.version_id = 0,
|
|
|
|
.minimum_version_id = 0,
|
|
|
|
.post_load = strongarm_ssp_post_load,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_UINT16_ARRAY(sscr, StrongARMSSPState, 2),
|
|
|
|
VMSTATE_UINT16(sssr, StrongARMSSPState),
|
|
|
|
VMSTATE_UINT16_ARRAY(rx_fifo, StrongARMSSPState, 8),
|
|
|
|
VMSTATE_UINT8(rx_start, StrongARMSSPState),
|
|
|
|
VMSTATE_UINT8(rx_level, StrongARMSSPState),
|
|
|
|
VMSTATE_END_OF_LIST(),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2012-01-24 20:12:29 +01:00
|
|
|
static void strongarm_ssp_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2012-01-24 20:12:29 +01:00
|
|
|
|
2011-12-08 04:34:16 +01:00
|
|
|
dc->desc = "StrongARM SSP controller";
|
|
|
|
dc->reset = strongarm_ssp_reset;
|
|
|
|
dc->vmsd = &vmstate_strongarm_ssp_regs;
|
2012-01-24 20:12:29 +01:00
|
|
|
}
|
|
|
|
|
2013-01-10 16:19:07 +01:00
|
|
|
static const TypeInfo strongarm_ssp_info = {
|
2013-07-24 09:32:06 +02:00
|
|
|
.name = TYPE_STRONGARM_SSP,
|
2011-12-08 04:34:16 +01:00
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(StrongARMSSPState),
|
2016-10-24 17:26:56 +02:00
|
|
|
.instance_init = strongarm_ssp_init,
|
2011-12-08 04:34:16 +01:00
|
|
|
.class_init = strongarm_ssp_class_init,
|
2011-04-19 16:56:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Main CPU functions */
|
2019-10-22 17:50:38 +02:00
|
|
|
StrongARMState *sa1110_init(const char *cpu_type)
|
2011-04-19 16:56:45 +02:00
|
|
|
{
|
|
|
|
StrongARMState *s;
|
|
|
|
int i;
|
|
|
|
|
arm: Use g_new() & friends where that makes obvious sense
g_new(T, n) is neater than g_malloc(sizeof(T) * n). It's also safer,
for two reasons. One, it catches multiplication overflowing size_t.
Two, it returns T * rather than void *, which lets the compiler catch
more type errors.
This commit only touches allocations with size arguments of the form
sizeof(T).
Coccinelle semantic patch:
@@
type T;
@@
-g_malloc(sizeof(T))
+g_new(T, 1)
@@
type T;
@@
-g_try_malloc(sizeof(T))
+g_try_new(T, 1)
@@
type T;
@@
-g_malloc0(sizeof(T))
+g_new0(T, 1)
@@
type T;
@@
-g_try_malloc0(sizeof(T))
+g_try_new0(T, 1)
@@
type T;
expression n;
@@
-g_malloc(sizeof(T) * (n))
+g_new(T, n)
@@
type T;
expression n;
@@
-g_try_malloc(sizeof(T) * (n))
+g_try_new(T, n)
@@
type T;
expression n;
@@
-g_malloc0(sizeof(T) * (n))
+g_new0(T, n)
@@
type T;
expression n;
@@
-g_try_malloc0(sizeof(T) * (n))
+g_try_new0(T, n)
@@
type T;
expression p, n;
@@
-g_realloc(p, sizeof(T) * (n))
+g_renew(T, p, n)
@@
type T;
expression p, n;
@@
-g_try_realloc(p, sizeof(T) * (n))
+g_try_renew(T, p, n)
@@
type T;
expression n;
@@
-(T *)g_new(T, n)
+g_new(T, n)
@@
type T;
expression n;
@@
-(T *)g_new0(T, n)
+g_new0(T, n)
@@
type T;
expression p, n;
@@
-(T *)g_renew(T, p, n)
+g_renew(T, p, n)
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-id: 1440524394-15640-1-git-send-email-armbru@redhat.com
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
2015-09-07 11:39:27 +02:00
|
|
|
s = g_new0(StrongARMState, 1);
|
2011-04-19 16:56:45 +02:00
|
|
|
|
2017-09-13 18:04:57 +02:00
|
|
|
if (strncmp(cpu_type, "sa1110", 6)) {
|
2011-06-22 14:03:54 +02:00
|
|
|
error_report("Machine requires a SA1110 processor.");
|
2011-04-19 16:56:45 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2017-09-13 18:04:57 +02:00
|
|
|
s->cpu = ARM_CPU(cpu_create(cpu_type));
|
2011-04-19 16:56:45 +02:00
|
|
|
|
|
|
|
s->pic = sysbus_create_varargs("strongarm_pic", 0x90050000,
|
2013-08-20 15:54:30 +02:00
|
|
|
qdev_get_gpio_in(DEVICE(s->cpu), ARM_CPU_IRQ),
|
|
|
|
qdev_get_gpio_in(DEVICE(s->cpu), ARM_CPU_FIQ),
|
|
|
|
NULL);
|
2011-04-19 16:56:45 +02:00
|
|
|
|
|
|
|
sysbus_create_varargs("pxa25x-timer", 0x90000000,
|
|
|
|
qdev_get_gpio_in(s->pic, SA_PIC_OSTC0),
|
|
|
|
qdev_get_gpio_in(s->pic, SA_PIC_OSTC1),
|
|
|
|
qdev_get_gpio_in(s->pic, SA_PIC_OSTC2),
|
|
|
|
qdev_get_gpio_in(s->pic, SA_PIC_OSTC3),
|
|
|
|
NULL);
|
|
|
|
|
2013-07-24 09:20:15 +02:00
|
|
|
sysbus_create_simple(TYPE_STRONGARM_RTC, 0x90010000,
|
2011-04-19 16:56:45 +02:00
|
|
|
qdev_get_gpio_in(s->pic, SA_PIC_RTC_ALARM));
|
|
|
|
|
|
|
|
s->gpio = strongarm_gpio_init(0x90040000, s->pic);
|
|
|
|
|
2013-07-24 09:26:04 +02:00
|
|
|
s->ppc = sysbus_create_varargs(TYPE_STRONGARM_PPC, 0x90060000, NULL);
|
2011-04-19 16:56:45 +02:00
|
|
|
|
|
|
|
for (i = 0; sa_serial[i].io_base; i++) {
|
qdev: Convert uses of qdev_create() with Coccinelle
This is the transformation explained in the commit before previous.
Takes care of just one pattern that needs conversion. More to come in
this series.
Coccinelle script:
@ depends on !(file in "hw/arm/highbank.c")@
expression bus, type_name, dev, expr;
@@
- dev = qdev_create(bus, type_name);
+ dev = qdev_new(type_name);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, bus, &error_fatal);
@@
expression bus, type_name, dev, expr;
identifier DOWN;
@@
- dev = DOWN(qdev_create(bus, type_name));
+ dev = DOWN(qdev_new(type_name));
... when != dev = expr
- qdev_init_nofail(DEVICE(dev));
+ qdev_realize_and_unref(DEVICE(dev), bus, &error_fatal);
@@
expression bus, type_name, expr;
identifier dev;
@@
- DeviceState *dev = qdev_create(bus, type_name);
+ DeviceState *dev = qdev_new(type_name);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, bus, &error_fatal);
@@
expression bus, type_name, dev, expr, errp;
symbol true;
@@
- dev = qdev_create(bus, type_name);
+ dev = qdev_new(type_name);
... when != dev = expr
- object_property_set_bool(OBJECT(dev), true, "realized", errp);
+ qdev_realize_and_unref(dev, bus, errp);
@@
expression bus, type_name, expr, errp;
identifier dev;
symbol true;
@@
- DeviceState *dev = qdev_create(bus, type_name);
+ DeviceState *dev = qdev_new(type_name);
... when != dev = expr
- object_property_set_bool(OBJECT(dev), true, "realized", errp);
+ qdev_realize_and_unref(dev, bus, errp);
The first rule exempts hw/arm/highbank.c, because it matches along two
control flow paths there, with different @type_name. Covered by the
next commit's manual conversions.
Missing #include "qapi/error.h" added manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-10-armbru@redhat.com>
[Conflicts in hw/misc/empty_slot.c and hw/sparc/leon3.c resolved]
2020-06-10 07:31:58 +02:00
|
|
|
DeviceState *dev = qdev_new(TYPE_STRONGARM_UART);
|
2018-04-20 16:52:43 +02:00
|
|
|
qdev_prop_set_chr(dev, "chardev", serial_hd(i));
|
sysbus: Convert to sysbus_realize() etc. with Coccinelle
Convert from qdev_realize(), qdev_realize_and_unref() with null @bus
argument to sysbus_realize(), sysbus_realize_and_unref().
Coccinelle script:
@@
expression dev, errp;
@@
- qdev_realize(DEVICE(dev), NULL, errp);
+ sysbus_realize(SYS_BUS_DEVICE(dev), errp);
@@
expression sysbus_dev, dev, errp;
@@
+ sysbus_dev = SYS_BUS_DEVICE(dev);
- qdev_realize_and_unref(dev, NULL, errp);
+ sysbus_realize_and_unref(sysbus_dev, errp);
- sysbus_dev = SYS_BUS_DEVICE(dev);
@@
expression sysbus_dev, dev, errp;
expression expr;
@@
sysbus_dev = SYS_BUS_DEVICE(dev);
... when != dev = expr;
- qdev_realize_and_unref(dev, NULL, errp);
+ sysbus_realize_and_unref(sysbus_dev, errp);
@@
expression dev, errp;
@@
- qdev_realize_and_unref(DEVICE(dev), NULL, errp);
+ sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), errp);
@@
expression dev, errp;
@@
- qdev_realize_and_unref(dev, NULL, errp);
+ sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), errp);
Whitespace changes minimized manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Acked-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-46-armbru@redhat.com>
[Conflicts in hw/misc/empty_slot.c and hw/sparc/leon3.c resolved]
2020-06-10 07:32:34 +02:00
|
|
|
sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
|
2013-01-20 02:47:33 +01:00
|
|
|
sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0,
|
2011-04-19 16:56:45 +02:00
|
|
|
sa_serial[i].io_base);
|
2013-01-20 02:47:33 +01:00
|
|
|
sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0,
|
2011-04-19 16:56:45 +02:00
|
|
|
qdev_get_gpio_in(s->pic, sa_serial[i].irq));
|
|
|
|
}
|
|
|
|
|
2013-07-24 09:32:06 +02:00
|
|
|
s->ssp = sysbus_create_varargs(TYPE_STRONGARM_SSP, 0x80070000,
|
2011-04-19 16:56:45 +02:00
|
|
|
qdev_get_gpio_in(s->pic, SA_PIC_SSP), NULL);
|
|
|
|
s->ssp_bus = (SSIBus *)qdev_get_child_bus(s->ssp, "ssi");
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2012-02-09 15:20:55 +01:00
|
|
|
static void strongarm_register_types(void)
|
2011-04-19 16:56:45 +02:00
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
type_register_static(&strongarm_pic_info);
|
|
|
|
type_register_static(&strongarm_rtc_sysbus_info);
|
|
|
|
type_register_static(&strongarm_gpio_info);
|
|
|
|
type_register_static(&strongarm_ppc_info);
|
|
|
|
type_register_static(&strongarm_uart_info);
|
|
|
|
type_register_static(&strongarm_ssp_info);
|
2011-04-19 16:56:45 +02:00
|
|
|
}
|
2012-02-09 15:20:55 +01:00
|
|
|
|
|
|
|
type_init(strongarm_register_types)
|