2 * StrongARM SA-1100/SA-1110 emulation
4 * Copyright (C) 2011 Dmitry Eremin-Solenikov
6 * Largely based on StrongARM emulation:
7 * Copyright (c) 2006 Openedhand Ltd.
8 * Written by Andrzej Zaborowski <balrog@zabor.org>
10 * UART code based on QEMU 16550A UART emulation
11 * Copyright (c) 2003-2004 Fabrice Bellard
12 * Copyright (c) 2008 Citrix Systems, Inc.
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License version 2 as
16 * published by the Free Software Foundation.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, see <http://www.gnu.org/licenses/>.
26 * Contributions after 2012-01-13 are licensed under the terms of the
27 * GNU GPL, version 2 or (at your option) any later version.
30 #include "qemu/osdep.h"
31 #include "qemu-common.h"
33 #include "hw/boards.h"
35 #include "hw/qdev-properties.h"
36 #include "hw/sysbus.h"
37 #include "migration/vmstate.h"
38 #include "strongarm.h"
39 #include "qemu/error-report.h"
40 #include "hw/arm/boot.h"
41 #include "chardev/char-fe.h"
42 #include "chardev/char-serial.h"
43 #include "sysemu/sysemu.h"
44 #include "hw/ssi/ssi.h"
45 #include "qapi/error.h"
46 #include "qemu/cutils.h"
53 - Implement cp15, c14 ?
54 - Implement cp15, c15 !!! (idle used in L)
55 - Implement idle mode handling/DIM
56 - Implement sleep mode/Wake sources
57 - Implement reset control
58 - Implement memory control regs
60 - Maybe support MBGNT/MBREQ
65 - Enhance UART with modem signals
69 # define DPRINTF(format, ...) printf(format , ## __VA_ARGS__)
71 # define DPRINTF(format, ...) do { } while (0)
78 { 0x80010000, SA_PIC_UART1
},
79 { 0x80030000, SA_PIC_UART2
},
80 { 0x80050000, SA_PIC_UART3
},
84 /* Interrupt Controller */
86 #define TYPE_STRONGARM_PIC "strongarm_pic"
87 #define STRONGARM_PIC(obj) \
88 OBJECT_CHECK(StrongARMPICState, (obj), TYPE_STRONGARM_PIC)
90 typedef struct StrongARMPICState
{
91 SysBusDevice parent_obj
;
110 #define SA_PIC_SRCS 32
113 static void strongarm_pic_update(void *opaque
)
115 StrongARMPICState
*s
= opaque
;
117 /* FIXME: reflect DIM */
118 qemu_set_irq(s
->fiq
, s
->pending
& s
->enabled
& s
->is_fiq
);
119 qemu_set_irq(s
->irq
, s
->pending
& s
->enabled
& ~s
->is_fiq
);
122 static void strongarm_pic_set_irq(void *opaque
, int irq
, int level
)
124 StrongARMPICState
*s
= opaque
;
127 s
->pending
|= 1 << irq
;
129 s
->pending
&= ~(1 << irq
);
132 strongarm_pic_update(s
);
135 static uint64_t strongarm_pic_mem_read(void *opaque
, hwaddr offset
,
138 StrongARMPICState
*s
= opaque
;
142 return s
->pending
& ~s
->is_fiq
& s
->enabled
;
148 return s
->int_idle
== 0;
150 return s
->pending
& s
->is_fiq
& s
->enabled
;
154 printf("%s: Bad register offset 0x" TARGET_FMT_plx
"\n",
160 static void strongarm_pic_mem_write(void *opaque
, hwaddr offset
,
161 uint64_t value
, unsigned size
)
163 StrongARMPICState
*s
= opaque
;
173 s
->int_idle
= (value
& 1) ? 0 : ~0;
176 printf("%s: Bad register offset 0x" TARGET_FMT_plx
"\n",
180 strongarm_pic_update(s
);
183 static const MemoryRegionOps strongarm_pic_ops
= {
184 .read
= strongarm_pic_mem_read
,
185 .write
= strongarm_pic_mem_write
,
186 .endianness
= DEVICE_NATIVE_ENDIAN
,
189 static void strongarm_pic_initfn(Object
*obj
)
191 DeviceState
*dev
= DEVICE(obj
);
192 StrongARMPICState
*s
= STRONGARM_PIC(obj
);
193 SysBusDevice
*sbd
= SYS_BUS_DEVICE(obj
);
195 qdev_init_gpio_in(dev
, strongarm_pic_set_irq
, SA_PIC_SRCS
);
196 memory_region_init_io(&s
->iomem
, obj
, &strongarm_pic_ops
, s
,
198 sysbus_init_mmio(sbd
, &s
->iomem
);
199 sysbus_init_irq(sbd
, &s
->irq
);
200 sysbus_init_irq(sbd
, &s
->fiq
);
203 static int strongarm_pic_post_load(void *opaque
, int version_id
)
205 strongarm_pic_update(opaque
);
209 static VMStateDescription vmstate_strongarm_pic_regs
= {
210 .name
= "strongarm_pic",
212 .minimum_version_id
= 0,
213 .post_load
= strongarm_pic_post_load
,
214 .fields
= (VMStateField
[]) {
215 VMSTATE_UINT32(pending
, StrongARMPICState
),
216 VMSTATE_UINT32(enabled
, StrongARMPICState
),
217 VMSTATE_UINT32(is_fiq
, StrongARMPICState
),
218 VMSTATE_UINT32(int_idle
, StrongARMPICState
),
219 VMSTATE_END_OF_LIST(),
223 static void strongarm_pic_class_init(ObjectClass
*klass
, void *data
)
225 DeviceClass
*dc
= DEVICE_CLASS(klass
);
227 dc
->desc
= "StrongARM PIC";
228 dc
->vmsd
= &vmstate_strongarm_pic_regs
;
231 static const TypeInfo strongarm_pic_info
= {
232 .name
= TYPE_STRONGARM_PIC
,
233 .parent
= TYPE_SYS_BUS_DEVICE
,
234 .instance_size
= sizeof(StrongARMPICState
),
235 .instance_init
= strongarm_pic_initfn
,
236 .class_init
= strongarm_pic_class_init
,
239 /* Real-Time Clock */
240 #define RTAR 0x00 /* RTC Alarm register */
241 #define RCNR 0x04 /* RTC Counter register */
242 #define RTTR 0x08 /* RTC Timer Trim register */
243 #define RTSR 0x10 /* RTC Status register */
245 #define RTSR_AL (1 << 0) /* RTC Alarm detected */
246 #define RTSR_HZ (1 << 1) /* RTC 1Hz detected */
247 #define RTSR_ALE (1 << 2) /* RTC Alarm enable */
248 #define RTSR_HZE (1 << 3) /* RTC 1Hz enable */
250 /* 16 LSB of RTTR are clockdiv for internal trim logic,
251 * trim delete isn't emulated, so
252 * f = 32 768 / (RTTR_trim + 1) */
254 #define TYPE_STRONGARM_RTC "strongarm-rtc"
255 #define STRONGARM_RTC(obj) \
256 OBJECT_CHECK(StrongARMRTCState, (obj), TYPE_STRONGARM_RTC)
258 typedef struct StrongARMRTCState
{
259 SysBusDevice parent_obj
;
267 QEMUTimer
*rtc_alarm
;
273 static inline void strongarm_rtc_int_update(StrongARMRTCState
*s
)
275 qemu_set_irq(s
->rtc_irq
, s
->rtsr
& RTSR_AL
);
276 qemu_set_irq(s
->rtc_hz_irq
, s
->rtsr
& RTSR_HZ
);
279 static void strongarm_rtc_hzupdate(StrongARMRTCState
*s
)
281 int64_t rt
= qemu_clock_get_ms(rtc_clock
);
282 s
->last_rcnr
+= ((rt
- s
->last_hz
) << 15) /
283 (1000 * ((s
->rttr
& 0xffff) + 1));
287 static inline void strongarm_rtc_timer_update(StrongARMRTCState
*s
)
289 if ((s
->rtsr
& RTSR_HZE
) && !(s
->rtsr
& RTSR_HZ
)) {
290 timer_mod(s
->rtc_hz
, s
->last_hz
+ 1000);
292 timer_del(s
->rtc_hz
);
295 if ((s
->rtsr
& RTSR_ALE
) && !(s
->rtsr
& RTSR_AL
)) {
296 timer_mod(s
->rtc_alarm
, s
->last_hz
+
297 (((s
->rtar
- s
->last_rcnr
) * 1000 *
298 ((s
->rttr
& 0xffff) + 1)) >> 15));
300 timer_del(s
->rtc_alarm
);
304 static inline void strongarm_rtc_alarm_tick(void *opaque
)
306 StrongARMRTCState
*s
= opaque
;
308 strongarm_rtc_timer_update(s
);
309 strongarm_rtc_int_update(s
);
312 static inline void strongarm_rtc_hz_tick(void *opaque
)
314 StrongARMRTCState
*s
= opaque
;
316 strongarm_rtc_timer_update(s
);
317 strongarm_rtc_int_update(s
);
320 static uint64_t strongarm_rtc_read(void *opaque
, hwaddr addr
,
323 StrongARMRTCState
*s
= opaque
;
333 return s
->last_rcnr
+
334 ((qemu_clock_get_ms(rtc_clock
) - s
->last_hz
) << 15) /
335 (1000 * ((s
->rttr
& 0xffff) + 1));
337 printf("%s: Bad register 0x" TARGET_FMT_plx
"\n", __func__
, addr
);
342 static void strongarm_rtc_write(void *opaque
, hwaddr addr
,
343 uint64_t value
, unsigned size
)
345 StrongARMRTCState
*s
= opaque
;
350 strongarm_rtc_hzupdate(s
);
352 strongarm_rtc_timer_update(s
);
357 s
->rtsr
= (value
& (RTSR_ALE
| RTSR_HZE
)) |
358 (s
->rtsr
& ~(value
& (RTSR_AL
| RTSR_HZ
)));
360 if (s
->rtsr
!= old_rtsr
) {
361 strongarm_rtc_timer_update(s
);
364 strongarm_rtc_int_update(s
);
369 strongarm_rtc_timer_update(s
);
373 strongarm_rtc_hzupdate(s
);
374 s
->last_rcnr
= value
;
375 strongarm_rtc_timer_update(s
);
379 printf("%s: Bad register 0x" TARGET_FMT_plx
"\n", __func__
, addr
);
383 static const MemoryRegionOps strongarm_rtc_ops
= {
384 .read
= strongarm_rtc_read
,
385 .write
= strongarm_rtc_write
,
386 .endianness
= DEVICE_NATIVE_ENDIAN
,
389 static void strongarm_rtc_init(Object
*obj
)
391 StrongARMRTCState
*s
= STRONGARM_RTC(obj
);
392 SysBusDevice
*dev
= SYS_BUS_DEVICE(obj
);
398 qemu_get_timedate(&tm
, 0);
400 s
->last_rcnr
= (uint32_t) mktimegm(&tm
);
401 s
->last_hz
= qemu_clock_get_ms(rtc_clock
);
403 sysbus_init_irq(dev
, &s
->rtc_irq
);
404 sysbus_init_irq(dev
, &s
->rtc_hz_irq
);
406 memory_region_init_io(&s
->iomem
, obj
, &strongarm_rtc_ops
, s
,
408 sysbus_init_mmio(dev
, &s
->iomem
);
411 static void strongarm_rtc_realize(DeviceState
*dev
, Error
**errp
)
413 StrongARMRTCState
*s
= STRONGARM_RTC(dev
);
414 s
->rtc_alarm
= timer_new_ms(rtc_clock
, strongarm_rtc_alarm_tick
, s
);
415 s
->rtc_hz
= timer_new_ms(rtc_clock
, strongarm_rtc_hz_tick
, s
);
418 static int strongarm_rtc_pre_save(void *opaque
)
420 StrongARMRTCState
*s
= opaque
;
422 strongarm_rtc_hzupdate(s
);
427 static int strongarm_rtc_post_load(void *opaque
, int version_id
)
429 StrongARMRTCState
*s
= opaque
;
431 strongarm_rtc_timer_update(s
);
432 strongarm_rtc_int_update(s
);
437 static const VMStateDescription vmstate_strongarm_rtc_regs
= {
438 .name
= "strongarm-rtc",
440 .minimum_version_id
= 0,
441 .pre_save
= strongarm_rtc_pre_save
,
442 .post_load
= strongarm_rtc_post_load
,
443 .fields
= (VMStateField
[]) {
444 VMSTATE_UINT32(rttr
, StrongARMRTCState
),
445 VMSTATE_UINT32(rtsr
, StrongARMRTCState
),
446 VMSTATE_UINT32(rtar
, StrongARMRTCState
),
447 VMSTATE_UINT32(last_rcnr
, StrongARMRTCState
),
448 VMSTATE_INT64(last_hz
, StrongARMRTCState
),
449 VMSTATE_END_OF_LIST(),
453 static void strongarm_rtc_sysbus_class_init(ObjectClass
*klass
, void *data
)
455 DeviceClass
*dc
= DEVICE_CLASS(klass
);
457 dc
->desc
= "StrongARM RTC Controller";
458 dc
->vmsd
= &vmstate_strongarm_rtc_regs
;
459 dc
->realize
= strongarm_rtc_realize
;
462 static const TypeInfo strongarm_rtc_sysbus_info
= {
463 .name
= TYPE_STRONGARM_RTC
,
464 .parent
= TYPE_SYS_BUS_DEVICE
,
465 .instance_size
= sizeof(StrongARMRTCState
),
466 .instance_init
= strongarm_rtc_init
,
467 .class_init
= strongarm_rtc_sysbus_class_init
,
480 #define TYPE_STRONGARM_GPIO "strongarm-gpio"
481 #define STRONGARM_GPIO(obj) \
482 OBJECT_CHECK(StrongARMGPIOInfo, (obj), TYPE_STRONGARM_GPIO)
484 typedef struct StrongARMGPIOInfo StrongARMGPIOInfo
;
485 struct StrongARMGPIOInfo
{
488 qemu_irq handler
[28];
504 static void strongarm_gpio_irq_update(StrongARMGPIOInfo
*s
)
507 for (i
= 0; i
< 11; i
++) {
508 qemu_set_irq(s
->irqs
[i
], s
->status
& (1 << i
));
511 qemu_set_irq(s
->irqX
, (s
->status
& ~0x7ff));
514 static void strongarm_gpio_set(void *opaque
, int line
, int level
)
516 StrongARMGPIOInfo
*s
= opaque
;
522 s
->status
|= s
->rising
& mask
&
523 ~s
->ilevel
& ~s
->dir
;
526 s
->status
|= s
->falling
& mask
&
531 if (s
->status
& mask
) {
532 strongarm_gpio_irq_update(s
);
536 static void strongarm_gpio_handler_update(StrongARMGPIOInfo
*s
)
538 uint32_t level
, diff
;
541 level
= s
->olevel
& s
->dir
;
543 for (diff
= s
->prev_level
^ level
; diff
; diff
^= 1 << bit
) {
545 qemu_set_irq(s
->handler
[bit
], (level
>> bit
) & 1);
548 s
->prev_level
= level
;
551 static uint64_t strongarm_gpio_read(void *opaque
, hwaddr offset
,
554 StrongARMGPIOInfo
*s
= opaque
;
557 case GPDR
: /* GPIO Pin-Direction registers */
560 case GPSR
: /* GPIO Pin-Output Set registers */
561 qemu_log_mask(LOG_GUEST_ERROR
,
562 "strongarm GPIO: read from write only register GPSR\n");
565 case GPCR
: /* GPIO Pin-Output Clear registers */
566 qemu_log_mask(LOG_GUEST_ERROR
,
567 "strongarm GPIO: read from write only register GPCR\n");
570 case GRER
: /* GPIO Rising-Edge Detect Enable registers */
573 case GFER
: /* GPIO Falling-Edge Detect Enable registers */
576 case GAFR
: /* GPIO Alternate Function registers */
579 case GPLR
: /* GPIO Pin-Level registers */
580 return (s
->olevel
& s
->dir
) |
581 (s
->ilevel
& ~s
->dir
);
583 case GEDR
: /* GPIO Edge Detect Status registers */
587 printf("%s: Bad offset 0x" TARGET_FMT_plx
"\n", __func__
, offset
);
593 static void strongarm_gpio_write(void *opaque
, hwaddr offset
,
594 uint64_t value
, unsigned size
)
596 StrongARMGPIOInfo
*s
= opaque
;
599 case GPDR
: /* GPIO Pin-Direction registers */
600 s
->dir
= value
& 0x0fffffff;
601 strongarm_gpio_handler_update(s
);
604 case GPSR
: /* GPIO Pin-Output Set registers */
605 s
->olevel
|= value
& 0x0fffffff;
606 strongarm_gpio_handler_update(s
);
609 case GPCR
: /* GPIO Pin-Output Clear registers */
611 strongarm_gpio_handler_update(s
);
614 case GRER
: /* GPIO Rising-Edge Detect Enable registers */
618 case GFER
: /* GPIO Falling-Edge Detect Enable registers */
622 case GAFR
: /* GPIO Alternate Function registers */
626 case GEDR
: /* GPIO Edge Detect Status registers */
628 strongarm_gpio_irq_update(s
);
632 printf("%s: Bad offset 0x" TARGET_FMT_plx
"\n", __func__
, offset
);
636 static const MemoryRegionOps strongarm_gpio_ops
= {
637 .read
= strongarm_gpio_read
,
638 .write
= strongarm_gpio_write
,
639 .endianness
= DEVICE_NATIVE_ENDIAN
,
642 static DeviceState
*strongarm_gpio_init(hwaddr base
,
648 dev
= qdev_new(TYPE_STRONGARM_GPIO
);
649 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev
), &error_fatal
);
651 sysbus_mmio_map(SYS_BUS_DEVICE(dev
), 0, base
);
652 for (i
= 0; i
< 12; i
++)
653 sysbus_connect_irq(SYS_BUS_DEVICE(dev
), i
,
654 qdev_get_gpio_in(pic
, SA_PIC_GPIO0_EDGE
+ i
));
659 static void strongarm_gpio_initfn(Object
*obj
)
661 DeviceState
*dev
= DEVICE(obj
);
662 StrongARMGPIOInfo
*s
= STRONGARM_GPIO(obj
);
663 SysBusDevice
*sbd
= SYS_BUS_DEVICE(obj
);
666 qdev_init_gpio_in(dev
, strongarm_gpio_set
, 28);
667 qdev_init_gpio_out(dev
, s
->handler
, 28);
669 memory_region_init_io(&s
->iomem
, obj
, &strongarm_gpio_ops
, s
,
672 sysbus_init_mmio(sbd
, &s
->iomem
);
673 for (i
= 0; i
< 11; i
++) {
674 sysbus_init_irq(sbd
, &s
->irqs
[i
]);
676 sysbus_init_irq(sbd
, &s
->irqX
);
679 static const VMStateDescription vmstate_strongarm_gpio_regs
= {
680 .name
= "strongarm-gpio",
682 .minimum_version_id
= 0,
683 .fields
= (VMStateField
[]) {
684 VMSTATE_UINT32(ilevel
, StrongARMGPIOInfo
),
685 VMSTATE_UINT32(olevel
, StrongARMGPIOInfo
),
686 VMSTATE_UINT32(dir
, StrongARMGPIOInfo
),
687 VMSTATE_UINT32(rising
, StrongARMGPIOInfo
),
688 VMSTATE_UINT32(falling
, StrongARMGPIOInfo
),
689 VMSTATE_UINT32(status
, StrongARMGPIOInfo
),
690 VMSTATE_UINT32(gafr
, StrongARMGPIOInfo
),
691 VMSTATE_UINT32(prev_level
, StrongARMGPIOInfo
),
692 VMSTATE_END_OF_LIST(),
696 static void strongarm_gpio_class_init(ObjectClass
*klass
, void *data
)
698 DeviceClass
*dc
= DEVICE_CLASS(klass
);
700 dc
->desc
= "StrongARM GPIO controller";
701 dc
->vmsd
= &vmstate_strongarm_gpio_regs
;
704 static const TypeInfo strongarm_gpio_info
= {
705 .name
= TYPE_STRONGARM_GPIO
,
706 .parent
= TYPE_SYS_BUS_DEVICE
,
707 .instance_size
= sizeof(StrongARMGPIOInfo
),
708 .instance_init
= strongarm_gpio_initfn
,
709 .class_init
= strongarm_gpio_class_init
,
712 /* Peripheral Pin Controller */
719 #define TYPE_STRONGARM_PPC "strongarm-ppc"
720 #define STRONGARM_PPC(obj) \
721 OBJECT_CHECK(StrongARMPPCInfo, (obj), TYPE_STRONGARM_PPC)
723 typedef struct StrongARMPPCInfo StrongARMPPCInfo
;
724 struct StrongARMPPCInfo
{
725 SysBusDevice parent_obj
;
728 qemu_irq handler
[28];
740 static void strongarm_ppc_set(void *opaque
, int line
, int level
)
742 StrongARMPPCInfo
*s
= opaque
;
745 s
->ilevel
|= 1 << line
;
747 s
->ilevel
&= ~(1 << line
);
751 static void strongarm_ppc_handler_update(StrongARMPPCInfo
*s
)
753 uint32_t level
, diff
;
756 level
= s
->olevel
& s
->dir
;
758 for (diff
= s
->prev_level
^ level
; diff
; diff
^= 1 << bit
) {
760 qemu_set_irq(s
->handler
[bit
], (level
>> bit
) & 1);
763 s
->prev_level
= level
;
766 static uint64_t strongarm_ppc_read(void *opaque
, hwaddr offset
,
769 StrongARMPPCInfo
*s
= opaque
;
772 case PPDR
: /* PPC Pin Direction registers */
773 return s
->dir
| ~0x3fffff;
775 case PPSR
: /* PPC Pin State registers */
776 return (s
->olevel
& s
->dir
) |
777 (s
->ilevel
& ~s
->dir
) |
781 return s
->ppar
| ~0x41000;
787 return s
->ppfr
| ~0x7f001;
790 printf("%s: Bad offset 0x" TARGET_FMT_plx
"\n", __func__
, offset
);
796 static void strongarm_ppc_write(void *opaque
, hwaddr offset
,
797 uint64_t value
, unsigned size
)
799 StrongARMPPCInfo
*s
= opaque
;
802 case PPDR
: /* PPC Pin Direction registers */
803 s
->dir
= value
& 0x3fffff;
804 strongarm_ppc_handler_update(s
);
807 case PPSR
: /* PPC Pin State registers */
808 s
->olevel
= value
& s
->dir
& 0x3fffff;
809 strongarm_ppc_handler_update(s
);
813 s
->ppar
= value
& 0x41000;
817 s
->psdr
= value
& 0x3fffff;
821 s
->ppfr
= value
& 0x7f001;
825 printf("%s: Bad offset 0x" TARGET_FMT_plx
"\n", __func__
, offset
);
829 static const MemoryRegionOps strongarm_ppc_ops
= {
830 .read
= strongarm_ppc_read
,
831 .write
= strongarm_ppc_write
,
832 .endianness
= DEVICE_NATIVE_ENDIAN
,
835 static void strongarm_ppc_init(Object
*obj
)
837 DeviceState
*dev
= DEVICE(obj
);
838 StrongARMPPCInfo
*s
= STRONGARM_PPC(obj
);
839 SysBusDevice
*sbd
= SYS_BUS_DEVICE(obj
);
841 qdev_init_gpio_in(dev
, strongarm_ppc_set
, 22);
842 qdev_init_gpio_out(dev
, s
->handler
, 22);
844 memory_region_init_io(&s
->iomem
, obj
, &strongarm_ppc_ops
, s
,
847 sysbus_init_mmio(sbd
, &s
->iomem
);
850 static const VMStateDescription vmstate_strongarm_ppc_regs
= {
851 .name
= "strongarm-ppc",
853 .minimum_version_id
= 0,
854 .fields
= (VMStateField
[]) {
855 VMSTATE_UINT32(ilevel
, StrongARMPPCInfo
),
856 VMSTATE_UINT32(olevel
, StrongARMPPCInfo
),
857 VMSTATE_UINT32(dir
, StrongARMPPCInfo
),
858 VMSTATE_UINT32(ppar
, StrongARMPPCInfo
),
859 VMSTATE_UINT32(psdr
, StrongARMPPCInfo
),
860 VMSTATE_UINT32(ppfr
, StrongARMPPCInfo
),
861 VMSTATE_UINT32(prev_level
, StrongARMPPCInfo
),
862 VMSTATE_END_OF_LIST(),
866 static void strongarm_ppc_class_init(ObjectClass
*klass
, void *data
)
868 DeviceClass
*dc
= DEVICE_CLASS(klass
);
870 dc
->desc
= "StrongARM PPC controller";
871 dc
->vmsd
= &vmstate_strongarm_ppc_regs
;
874 static const TypeInfo strongarm_ppc_info
= {
875 .name
= TYPE_STRONGARM_PPC
,
876 .parent
= TYPE_SYS_BUS_DEVICE
,
877 .instance_size
= sizeof(StrongARMPPCInfo
),
878 .instance_init
= strongarm_ppc_init
,
879 .class_init
= strongarm_ppc_class_init
,
891 #define UTCR0_PE (1 << 0) /* Parity enable */
892 #define UTCR0_OES (1 << 1) /* Even parity */
893 #define UTCR0_SBS (1 << 2) /* 2 stop bits */
894 #define UTCR0_DSS (1 << 3) /* 8-bit data */
896 #define UTCR3_RXE (1 << 0) /* Rx enable */
897 #define UTCR3_TXE (1 << 1) /* Tx enable */
898 #define UTCR3_BRK (1 << 2) /* Force Break */
899 #define UTCR3_RIE (1 << 3) /* Rx int enable */
900 #define UTCR3_TIE (1 << 4) /* Tx int enable */
901 #define UTCR3_LBM (1 << 5) /* Loopback */
903 #define UTSR0_TFS (1 << 0) /* Tx FIFO nearly empty */
904 #define UTSR0_RFS (1 << 1) /* Rx FIFO nearly full */
905 #define UTSR0_RID (1 << 2) /* Receiver Idle */
906 #define UTSR0_RBB (1 << 3) /* Receiver begin break */
907 #define UTSR0_REB (1 << 4) /* Receiver end break */
908 #define UTSR0_EIF (1 << 5) /* Error in FIFO */
910 #define UTSR1_RNE (1 << 1) /* Receive FIFO not empty */
911 #define UTSR1_TNF (1 << 2) /* Transmit FIFO not full */
912 #define UTSR1_PRE (1 << 3) /* Parity error */
913 #define UTSR1_FRE (1 << 4) /* Frame error */
914 #define UTSR1_ROR (1 << 5) /* Receive Over Run */
916 #define RX_FIFO_PRE (1 << 8)
917 #define RX_FIFO_FRE (1 << 9)
918 #define RX_FIFO_ROR (1 << 10)
920 #define TYPE_STRONGARM_UART "strongarm-uart"
921 #define STRONGARM_UART(obj) \
922 OBJECT_CHECK(StrongARMUARTState, (obj), TYPE_STRONGARM_UART)
924 typedef struct StrongARMUARTState
{
925 SysBusDevice parent_obj
;
940 uint16_t rx_fifo
[12]; /* value + error flags in high bits */
944 uint64_t char_transmit_time
; /* time to transmit a char in ticks*/
946 QEMUTimer
*rx_timeout_timer
;
948 } StrongARMUARTState
;
950 static void strongarm_uart_update_status(StrongARMUARTState
*s
)
954 if (s
->tx_len
!= 8) {
958 if (s
->rx_len
!= 0) {
959 uint16_t ent
= s
->rx_fifo
[s
->rx_start
];
962 if (ent
& RX_FIFO_PRE
) {
963 s
->utsr1
|= UTSR1_PRE
;
965 if (ent
& RX_FIFO_FRE
) {
966 s
->utsr1
|= UTSR1_FRE
;
968 if (ent
& RX_FIFO_ROR
) {
969 s
->utsr1
|= UTSR1_ROR
;
976 static void strongarm_uart_update_int_status(StrongARMUARTState
*s
)
978 uint16_t utsr0
= s
->utsr0
&
979 (UTSR0_REB
| UTSR0_RBB
| UTSR0_RID
);
982 if ((s
->utcr3
& UTCR3_TXE
) &&
983 (s
->utcr3
& UTCR3_TIE
) &&
988 if ((s
->utcr3
& UTCR3_RXE
) &&
989 (s
->utcr3
& UTCR3_RIE
) &&
994 for (i
= 0; i
< s
->rx_len
&& i
< 4; i
++)
995 if (s
->rx_fifo
[(s
->rx_start
+ i
) % 12] & ~0xff) {
1001 qemu_set_irq(s
->irq
, utsr0
);
1004 static void strongarm_uart_update_parameters(StrongARMUARTState
*s
)
1006 int speed
, parity
, data_bits
, stop_bits
, frame_size
;
1007 QEMUSerialSetParams ssp
;
1011 if (s
->utcr0
& UTCR0_PE
) {
1014 if (s
->utcr0
& UTCR0_OES
) {
1022 if (s
->utcr0
& UTCR0_SBS
) {
1028 data_bits
= (s
->utcr0
& UTCR0_DSS
) ? 8 : 7;
1029 frame_size
+= data_bits
+ stop_bits
;
1030 speed
= 3686400 / 16 / (s
->brd
+ 1);
1032 ssp
.parity
= parity
;
1033 ssp
.data_bits
= data_bits
;
1034 ssp
.stop_bits
= stop_bits
;
1035 s
->char_transmit_time
= (NANOSECONDS_PER_SECOND
/ speed
) * frame_size
;
1036 qemu_chr_fe_ioctl(&s
->chr
, CHR_IOCTL_SERIAL_SET_PARAMS
, &ssp
);
1038 DPRINTF(stderr
, "%s speed=%d parity=%c data=%d stop=%d\n", s
->chr
->label
,
1039 speed
, parity
, data_bits
, stop_bits
);
1042 static void strongarm_uart_rx_to(void *opaque
)
1044 StrongARMUARTState
*s
= opaque
;
1047 s
->utsr0
|= UTSR0_RID
;
1048 strongarm_uart_update_int_status(s
);
1052 static void strongarm_uart_rx_push(StrongARMUARTState
*s
, uint16_t c
)
1054 if ((s
->utcr3
& UTCR3_RXE
) == 0) {
1059 if (s
->wait_break_end
) {
1060 s
->utsr0
|= UTSR0_REB
;
1061 s
->wait_break_end
= false;
1064 if (s
->rx_len
< 12) {
1065 s
->rx_fifo
[(s
->rx_start
+ s
->rx_len
) % 12] = c
;
1068 s
->rx_fifo
[(s
->rx_start
+ 11) % 12] |= RX_FIFO_ROR
;
1071 static int strongarm_uart_can_receive(void *opaque
)
1073 StrongARMUARTState
*s
= opaque
;
1075 if (s
->rx_len
== 12) {
1078 /* It's best not to get more than 2/3 of RX FIFO, so advertise that much */
1079 if (s
->rx_len
< 8) {
1080 return 8 - s
->rx_len
;
1085 static void strongarm_uart_receive(void *opaque
, const uint8_t *buf
, int size
)
1087 StrongARMUARTState
*s
= opaque
;
1090 for (i
= 0; i
< size
; i
++) {
1091 strongarm_uart_rx_push(s
, buf
[i
]);
1094 /* call the timeout receive callback in 3 char transmit time */
1095 timer_mod(s
->rx_timeout_timer
,
1096 qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
) + s
->char_transmit_time
* 3);
1098 strongarm_uart_update_status(s
);
1099 strongarm_uart_update_int_status(s
);
1102 static void strongarm_uart_event(void *opaque
, QEMUChrEvent event
)
1104 StrongARMUARTState
*s
= opaque
;
1105 if (event
== CHR_EVENT_BREAK
) {
1106 s
->utsr0
|= UTSR0_RBB
;
1107 strongarm_uart_rx_push(s
, RX_FIFO_FRE
);
1108 s
->wait_break_end
= true;
1109 strongarm_uart_update_status(s
);
1110 strongarm_uart_update_int_status(s
);
1114 static void strongarm_uart_tx(void *opaque
)
1116 StrongARMUARTState
*s
= opaque
;
1117 uint64_t new_xmit_ts
= qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
);
1119 if (s
->utcr3
& UTCR3_LBM
) /* loopback */ {
1120 strongarm_uart_receive(s
, &s
->tx_fifo
[s
->tx_start
], 1);
1121 } else if (qemu_chr_fe_backend_connected(&s
->chr
)) {
1122 /* XXX this blocks entire thread. Rewrite to use
1123 * qemu_chr_fe_write and background I/O callbacks */
1124 qemu_chr_fe_write_all(&s
->chr
, &s
->tx_fifo
[s
->tx_start
], 1);
1127 s
->tx_start
= (s
->tx_start
+ 1) % 8;
1130 timer_mod(s
->tx_timer
, new_xmit_ts
+ s
->char_transmit_time
);
1132 strongarm_uart_update_status(s
);
1133 strongarm_uart_update_int_status(s
);
1136 static uint64_t strongarm_uart_read(void *opaque
, hwaddr addr
,
1139 StrongARMUARTState
*s
= opaque
;
1150 return s
->brd
& 0xff;
1156 if (s
->rx_len
!= 0) {
1157 ret
= s
->rx_fifo
[s
->rx_start
];
1158 s
->rx_start
= (s
->rx_start
+ 1) % 12;
1160 strongarm_uart_update_status(s
);
1161 strongarm_uart_update_int_status(s
);
1173 printf("%s: Bad register 0x" TARGET_FMT_plx
"\n", __func__
, addr
);
1178 static void strongarm_uart_write(void *opaque
, hwaddr addr
,
1179 uint64_t value
, unsigned size
)
1181 StrongARMUARTState
*s
= opaque
;
1185 s
->utcr0
= value
& 0x7f;
1186 strongarm_uart_update_parameters(s
);
1190 s
->brd
= (s
->brd
& 0xff) | ((value
& 0xf) << 8);
1191 strongarm_uart_update_parameters(s
);
1195 s
->brd
= (s
->brd
& 0xf00) | (value
& 0xff);
1196 strongarm_uart_update_parameters(s
);
1200 s
->utcr3
= value
& 0x3f;
1201 if ((s
->utcr3
& UTCR3_RXE
) == 0) {
1204 if ((s
->utcr3
& UTCR3_TXE
) == 0) {
1207 strongarm_uart_update_status(s
);
1208 strongarm_uart_update_int_status(s
);
1212 if ((s
->utcr3
& UTCR3_TXE
) && s
->tx_len
!= 8) {
1213 s
->tx_fifo
[(s
->tx_start
+ s
->tx_len
) % 8] = value
;
1215 strongarm_uart_update_status(s
);
1216 strongarm_uart_update_int_status(s
);
1217 if (s
->tx_len
== 1) {
1218 strongarm_uart_tx(s
);
1224 s
->utsr0
= s
->utsr0
& ~(value
&
1225 (UTSR0_REB
| UTSR0_RBB
| UTSR0_RID
));
1226 strongarm_uart_update_int_status(s
);
1230 printf("%s: Bad register 0x" TARGET_FMT_plx
"\n", __func__
, addr
);
1234 static const MemoryRegionOps strongarm_uart_ops
= {
1235 .read
= strongarm_uart_read
,
1236 .write
= strongarm_uart_write
,
1237 .endianness
= DEVICE_NATIVE_ENDIAN
,
1240 static void strongarm_uart_init(Object
*obj
)
1242 StrongARMUARTState
*s
= STRONGARM_UART(obj
);
1243 SysBusDevice
*dev
= SYS_BUS_DEVICE(obj
);
1245 memory_region_init_io(&s
->iomem
, obj
, &strongarm_uart_ops
, s
,
1247 sysbus_init_mmio(dev
, &s
->iomem
);
1248 sysbus_init_irq(dev
, &s
->irq
);
1251 static void strongarm_uart_realize(DeviceState
*dev
, Error
**errp
)
1253 StrongARMUARTState
*s
= STRONGARM_UART(dev
);
1255 s
->rx_timeout_timer
= timer_new_ns(QEMU_CLOCK_VIRTUAL
,
1256 strongarm_uart_rx_to
,
1258 s
->tx_timer
= timer_new_ns(QEMU_CLOCK_VIRTUAL
, strongarm_uart_tx
, s
);
1259 qemu_chr_fe_set_handlers(&s
->chr
,
1260 strongarm_uart_can_receive
,
1261 strongarm_uart_receive
,
1262 strongarm_uart_event
,
1263 NULL
, s
, NULL
, true);
1266 static void strongarm_uart_reset(DeviceState
*dev
)
1268 StrongARMUARTState
*s
= STRONGARM_UART(dev
);
1270 s
->utcr0
= UTCR0_DSS
; /* 8 data, no parity */
1271 s
->brd
= 23; /* 9600 */
1272 /* enable send & recv - this actually violates spec */
1273 s
->utcr3
= UTCR3_TXE
| UTCR3_RXE
;
1275 s
->rx_len
= s
->tx_len
= 0;
1277 strongarm_uart_update_parameters(s
);
1278 strongarm_uart_update_status(s
);
1279 strongarm_uart_update_int_status(s
);
1282 static int strongarm_uart_post_load(void *opaque
, int version_id
)
1284 StrongARMUARTState
*s
= opaque
;
1286 strongarm_uart_update_parameters(s
);
1287 strongarm_uart_update_status(s
);
1288 strongarm_uart_update_int_status(s
);
1290 /* tx and restart timer */
1292 strongarm_uart_tx(s
);
1295 /* restart rx timeout timer */
1297 timer_mod(s
->rx_timeout_timer
,
1298 qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL
) + s
->char_transmit_time
* 3);
1304 static const VMStateDescription vmstate_strongarm_uart_regs
= {
1305 .name
= "strongarm-uart",
1307 .minimum_version_id
= 0,
1308 .post_load
= strongarm_uart_post_load
,
1309 .fields
= (VMStateField
[]) {
1310 VMSTATE_UINT8(utcr0
, StrongARMUARTState
),
1311 VMSTATE_UINT16(brd
, StrongARMUARTState
),
1312 VMSTATE_UINT8(utcr3
, StrongARMUARTState
),
1313 VMSTATE_UINT8(utsr0
, StrongARMUARTState
),
1314 VMSTATE_UINT8_ARRAY(tx_fifo
, StrongARMUARTState
, 8),
1315 VMSTATE_UINT8(tx_start
, StrongARMUARTState
),
1316 VMSTATE_UINT8(tx_len
, StrongARMUARTState
),
1317 VMSTATE_UINT16_ARRAY(rx_fifo
, StrongARMUARTState
, 12),
1318 VMSTATE_UINT8(rx_start
, StrongARMUARTState
),
1319 VMSTATE_UINT8(rx_len
, StrongARMUARTState
),
1320 VMSTATE_BOOL(wait_break_end
, StrongARMUARTState
),
1321 VMSTATE_END_OF_LIST(),
1325 static Property strongarm_uart_properties
[] = {
1326 DEFINE_PROP_CHR("chardev", StrongARMUARTState
, chr
),
1327 DEFINE_PROP_END_OF_LIST(),
1330 static void strongarm_uart_class_init(ObjectClass
*klass
, void *data
)
1332 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1334 dc
->desc
= "StrongARM UART controller";
1335 dc
->reset
= strongarm_uart_reset
;
1336 dc
->vmsd
= &vmstate_strongarm_uart_regs
;
1337 device_class_set_props(dc
, strongarm_uart_properties
);
1338 dc
->realize
= strongarm_uart_realize
;
1341 static const TypeInfo strongarm_uart_info
= {
1342 .name
= TYPE_STRONGARM_UART
,
1343 .parent
= TYPE_SYS_BUS_DEVICE
,
1344 .instance_size
= sizeof(StrongARMUARTState
),
1345 .instance_init
= strongarm_uart_init
,
1346 .class_init
= strongarm_uart_class_init
,
1349 /* Synchronous Serial Ports */
1351 #define TYPE_STRONGARM_SSP "strongarm-ssp"
1352 #define STRONGARM_SSP(obj) \
1353 OBJECT_CHECK(StrongARMSSPState, (obj), TYPE_STRONGARM_SSP)
1355 typedef struct StrongARMSSPState
{
1356 SysBusDevice parent_obj
;
1365 uint16_t rx_fifo
[8];
1368 } StrongARMSSPState
;
1370 #define SSCR0 0x60 /* SSP Control register 0 */
1371 #define SSCR1 0x64 /* SSP Control register 1 */
1372 #define SSDR 0x6c /* SSP Data register */
1373 #define SSSR 0x74 /* SSP Status register */
1375 /* Bitfields for above registers */
1376 #define SSCR0_SPI(x) (((x) & 0x30) == 0x00)
1377 #define SSCR0_SSP(x) (((x) & 0x30) == 0x10)
1378 #define SSCR0_UWIRE(x) (((x) & 0x30) == 0x20)
1379 #define SSCR0_PSP(x) (((x) & 0x30) == 0x30)
1380 #define SSCR0_SSE (1 << 7)
1381 #define SSCR0_DSS(x) (((x) & 0xf) + 1)
1382 #define SSCR1_RIE (1 << 0)
1383 #define SSCR1_TIE (1 << 1)
1384 #define SSCR1_LBM (1 << 2)
1385 #define SSSR_TNF (1 << 2)
1386 #define SSSR_RNE (1 << 3)
1387 #define SSSR_TFS (1 << 5)
1388 #define SSSR_RFS (1 << 6)
1389 #define SSSR_ROR (1 << 7)
1390 #define SSSR_RW 0x0080
1392 static void strongarm_ssp_int_update(StrongARMSSPState
*s
)
1396 level
|= (s
->sssr
& SSSR_ROR
);
1397 level
|= (s
->sssr
& SSSR_RFS
) && (s
->sscr
[1] & SSCR1_RIE
);
1398 level
|= (s
->sssr
& SSSR_TFS
) && (s
->sscr
[1] & SSCR1_TIE
);
1399 qemu_set_irq(s
->irq
, level
);
1402 static void strongarm_ssp_fifo_update(StrongARMSSPState
*s
)
1404 s
->sssr
&= ~SSSR_TFS
;
1405 s
->sssr
&= ~SSSR_TNF
;
1406 if (s
->sscr
[0] & SSCR0_SSE
) {
1407 if (s
->rx_level
>= 4) {
1408 s
->sssr
|= SSSR_RFS
;
1410 s
->sssr
&= ~SSSR_RFS
;
1413 s
->sssr
|= SSSR_RNE
;
1415 s
->sssr
&= ~SSSR_RNE
;
1417 /* TX FIFO is never filled, so it is always in underrun
1418 condition if SSP is enabled */
1419 s
->sssr
|= SSSR_TFS
;
1420 s
->sssr
|= SSSR_TNF
;
1423 strongarm_ssp_int_update(s
);
1426 static uint64_t strongarm_ssp_read(void *opaque
, hwaddr addr
,
1429 StrongARMSSPState
*s
= opaque
;
1440 if (~s
->sscr
[0] & SSCR0_SSE
) {
1443 if (s
->rx_level
< 1) {
1444 printf("%s: SSP Rx Underrun\n", __func__
);
1448 retval
= s
->rx_fifo
[s
->rx_start
++];
1450 strongarm_ssp_fifo_update(s
);
1453 printf("%s: Bad register 0x" TARGET_FMT_plx
"\n", __func__
, addr
);
1459 static void strongarm_ssp_write(void *opaque
, hwaddr addr
,
1460 uint64_t value
, unsigned size
)
1462 StrongARMSSPState
*s
= opaque
;
1466 s
->sscr
[0] = value
& 0xffbf;
1467 if ((s
->sscr
[0] & SSCR0_SSE
) && SSCR0_DSS(value
) < 4) {
1468 printf("%s: Wrong data size: %i bits\n", __func__
,
1469 (int)SSCR0_DSS(value
));
1471 if (!(value
& SSCR0_SSE
)) {
1475 strongarm_ssp_fifo_update(s
);
1479 s
->sscr
[1] = value
& 0x2f;
1480 if (value
& SSCR1_LBM
) {
1481 printf("%s: Attempt to use SSP LBM mode\n", __func__
);
1483 strongarm_ssp_fifo_update(s
);
1487 s
->sssr
&= ~(value
& SSSR_RW
);
1488 strongarm_ssp_int_update(s
);
1492 if (SSCR0_UWIRE(s
->sscr
[0])) {
1495 /* Note how 32bits overflow does no harm here */
1496 value
&= (1 << SSCR0_DSS(s
->sscr
[0])) - 1;
1498 /* Data goes from here to the Tx FIFO and is shifted out from
1499 * there directly to the slave, no need to buffer it.
1501 if (s
->sscr
[0] & SSCR0_SSE
) {
1503 if (s
->sscr
[1] & SSCR1_LBM
) {
1506 readval
= ssi_transfer(s
->bus
, value
);
1509 if (s
->rx_level
< 0x08) {
1510 s
->rx_fifo
[(s
->rx_start
+ s
->rx_level
++) & 0x7] = readval
;
1512 s
->sssr
|= SSSR_ROR
;
1515 strongarm_ssp_fifo_update(s
);
1519 printf("%s: Bad register 0x" TARGET_FMT_plx
"\n", __func__
, addr
);
1524 static const MemoryRegionOps strongarm_ssp_ops
= {
1525 .read
= strongarm_ssp_read
,
1526 .write
= strongarm_ssp_write
,
1527 .endianness
= DEVICE_NATIVE_ENDIAN
,
1530 static int strongarm_ssp_post_load(void *opaque
, int version_id
)
1532 StrongARMSSPState
*s
= opaque
;
1534 strongarm_ssp_fifo_update(s
);
1539 static void strongarm_ssp_init(Object
*obj
)
1541 SysBusDevice
*sbd
= SYS_BUS_DEVICE(obj
);
1542 DeviceState
*dev
= DEVICE(sbd
);
1543 StrongARMSSPState
*s
= STRONGARM_SSP(dev
);
1545 sysbus_init_irq(sbd
, &s
->irq
);
1547 memory_region_init_io(&s
->iomem
, obj
, &strongarm_ssp_ops
, s
,
1549 sysbus_init_mmio(sbd
, &s
->iomem
);
1551 s
->bus
= ssi_create_bus(dev
, "ssi");
1554 static void strongarm_ssp_reset(DeviceState
*dev
)
1556 StrongARMSSPState
*s
= STRONGARM_SSP(dev
);
1558 s
->sssr
= 0x03; /* 3 bit data, SPI, disabled */
1563 static const VMStateDescription vmstate_strongarm_ssp_regs
= {
1564 .name
= "strongarm-ssp",
1566 .minimum_version_id
= 0,
1567 .post_load
= strongarm_ssp_post_load
,
1568 .fields
= (VMStateField
[]) {
1569 VMSTATE_UINT16_ARRAY(sscr
, StrongARMSSPState
, 2),
1570 VMSTATE_UINT16(sssr
, StrongARMSSPState
),
1571 VMSTATE_UINT16_ARRAY(rx_fifo
, StrongARMSSPState
, 8),
1572 VMSTATE_UINT8(rx_start
, StrongARMSSPState
),
1573 VMSTATE_UINT8(rx_level
, StrongARMSSPState
),
1574 VMSTATE_END_OF_LIST(),
1578 static void strongarm_ssp_class_init(ObjectClass
*klass
, void *data
)
1580 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1582 dc
->desc
= "StrongARM SSP controller";
1583 dc
->reset
= strongarm_ssp_reset
;
1584 dc
->vmsd
= &vmstate_strongarm_ssp_regs
;
1587 static const TypeInfo strongarm_ssp_info
= {
1588 .name
= TYPE_STRONGARM_SSP
,
1589 .parent
= TYPE_SYS_BUS_DEVICE
,
1590 .instance_size
= sizeof(StrongARMSSPState
),
1591 .instance_init
= strongarm_ssp_init
,
1592 .class_init
= strongarm_ssp_class_init
,
1595 /* Main CPU functions */
1596 StrongARMState
*sa1110_init(const char *cpu_type
)
1601 s
= g_new0(StrongARMState
, 1);
1603 if (strncmp(cpu_type
, "sa1110", 6)) {
1604 error_report("Machine requires a SA1110 processor.");
1608 s
->cpu
= ARM_CPU(cpu_create(cpu_type
));
1610 s
->pic
= sysbus_create_varargs("strongarm_pic", 0x90050000,
1611 qdev_get_gpio_in(DEVICE(s
->cpu
), ARM_CPU_IRQ
),
1612 qdev_get_gpio_in(DEVICE(s
->cpu
), ARM_CPU_FIQ
),
1615 sysbus_create_varargs("pxa25x-timer", 0x90000000,
1616 qdev_get_gpio_in(s
->pic
, SA_PIC_OSTC0
),
1617 qdev_get_gpio_in(s
->pic
, SA_PIC_OSTC1
),
1618 qdev_get_gpio_in(s
->pic
, SA_PIC_OSTC2
),
1619 qdev_get_gpio_in(s
->pic
, SA_PIC_OSTC3
),
1622 sysbus_create_simple(TYPE_STRONGARM_RTC
, 0x90010000,
1623 qdev_get_gpio_in(s
->pic
, SA_PIC_RTC_ALARM
));
1625 s
->gpio
= strongarm_gpio_init(0x90040000, s
->pic
);
1627 s
->ppc
= sysbus_create_varargs(TYPE_STRONGARM_PPC
, 0x90060000, NULL
);
1629 for (i
= 0; sa_serial
[i
].io_base
; i
++) {
1630 DeviceState
*dev
= qdev_new(TYPE_STRONGARM_UART
);
1631 qdev_prop_set_chr(dev
, "chardev", serial_hd(i
));
1632 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev
), &error_fatal
);
1633 sysbus_mmio_map(SYS_BUS_DEVICE(dev
), 0,
1634 sa_serial
[i
].io_base
);
1635 sysbus_connect_irq(SYS_BUS_DEVICE(dev
), 0,
1636 qdev_get_gpio_in(s
->pic
, sa_serial
[i
].irq
));
1639 s
->ssp
= sysbus_create_varargs(TYPE_STRONGARM_SSP
, 0x80070000,
1640 qdev_get_gpio_in(s
->pic
, SA_PIC_SSP
), NULL
);
1641 s
->ssp_bus
= (SSIBus
*)qdev_get_child_bus(s
->ssp
, "ssi");
1646 static void strongarm_register_types(void)
1648 type_register_static(&strongarm_pic_info
);
1649 type_register_static(&strongarm_rtc_sysbus_info
);
1650 type_register_static(&strongarm_gpio_info
);
1651 type_register_static(&strongarm_ppc_info
);
1652 type_register_static(&strongarm_uart_info
);
1653 type_register_static(&strongarm_ssp_info
);
1656 type_init(strongarm_register_types
)