1 // SPDX-License-Identifier: GPL-2.0
3 #include <linux/reboot.h>
4 #include <linux/serial_core.h>
5 #include <clocksource/timer-goldfish.h>
7 #include <asm/bootinfo.h>
8 #include <asm/bootinfo-virt.h>
9 #include <asm/byteorder.h>
10 #include <asm/machdep.h>
12 #include <asm/config.h>
14 struct virt_booter_data virt_bi_data
;
16 #define VIRT_CTRL_REG_FEATURES 0x00
17 #define VIRT_CTRL_REG_CMD 0x04
19 static struct resource ctrlres
;
28 static void virt_get_model(char *str
)
30 /* str is 80 characters long */
31 sprintf(str
, "QEMU Virtual M68K Machine (%u.%u.%u)",
32 (u8
)(virt_bi_data
.qemu_version
>> 24),
33 (u8
)(virt_bi_data
.qemu_version
>> 16),
34 (u8
)(virt_bi_data
.qemu_version
>> 8));
37 static void virt_halt(void)
39 void __iomem
*base
= (void __iomem
*)virt_bi_data
.ctrl
.mmio
;
41 iowrite32be(CMD_HALT
, base
+ VIRT_CTRL_REG_CMD
);
47 static void virt_reset(void)
49 void __iomem
*base
= (void __iomem
*)virt_bi_data
.ctrl
.mmio
;
51 iowrite32be(CMD_RESET
, base
+ VIRT_CTRL_REG_CMD
);
58 * Parse a virtual-m68k-specific record in the bootinfo
61 int __init
virt_parse_bootinfo(const struct bi_record
*record
)
64 const void *data
= record
->data
;
66 switch (be16_to_cpu(record
->tag
)) {
67 case BI_VIRT_QEMU_VERSION
:
68 virt_bi_data
.qemu_version
= be32_to_cpup(data
);
70 case BI_VIRT_GF_PIC_BASE
:
71 virt_bi_data
.pic
.mmio
= be32_to_cpup(data
);
73 virt_bi_data
.pic
.irq
= be32_to_cpup(data
);
75 case BI_VIRT_GF_RTC_BASE
:
76 virt_bi_data
.rtc
.mmio
= be32_to_cpup(data
);
78 virt_bi_data
.rtc
.irq
= be32_to_cpup(data
);
80 case BI_VIRT_GF_TTY_BASE
:
81 virt_bi_data
.tty
.mmio
= be32_to_cpup(data
);
83 virt_bi_data
.tty
.irq
= be32_to_cpup(data
);
85 case BI_VIRT_CTRL_BASE
:
86 virt_bi_data
.ctrl
.mmio
= be32_to_cpup(data
);
88 virt_bi_data
.ctrl
.irq
= be32_to_cpup(data
);
90 case BI_VIRT_VIRTIO_BASE
:
91 virt_bi_data
.virtio
.mmio
= be32_to_cpup(data
);
93 virt_bi_data
.virtio
.irq
= be32_to_cpup(data
);
102 static void __init
virt_sched_init(void)
104 goldfish_timer_init(virt_bi_data
.rtc
.irq
,
105 (void __iomem
*)virt_bi_data
.rtc
.mmio
);
108 void __init
config_virt(void)
112 snprintf(earlycon
, sizeof(earlycon
), "early_gf_tty,0x%08x",
113 virt_bi_data
.tty
.mmio
);
114 setup_earlycon(earlycon
);
116 ctrlres
= (struct resource
)
117 DEFINE_RES_MEM_NAMED(virt_bi_data
.ctrl
.mmio
, 0x100,
120 if (request_resource(&iomem_resource
, &ctrlres
)) {
121 pr_err("Cannot allocate virt controller resource\n");
125 mach_init_IRQ
= virt_init_IRQ
;
126 mach_sched_init
= virt_sched_init
;
127 mach_get_model
= virt_get_model
;
128 mach_reset
= virt_reset
;
129 mach_halt
= virt_halt
;
131 register_platform_power_off(virt_halt
);