| 
									
										
										
										
											2016-09-29 14:46:45 +02:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * QEMU Sun4v/Niagara System Emulator | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright (c) 2016 Artyom Tarasenko | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Permission is hereby granted, free of charge, to any person obtaining a copy | 
					
						
							|  |  |  |  * of this software and associated documentation files (the "Software"), to deal | 
					
						
							|  |  |  |  * in the Software without restriction, including without limitation the rights | 
					
						
							|  |  |  |  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | 
					
						
							|  |  |  |  * copies of the Software, and to permit persons to whom the Software is | 
					
						
							|  |  |  |  * furnished to do so, subject to the following conditions: | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The above copyright notice and this permission notice shall be included in | 
					
						
							|  |  |  |  * all copies or substantial portions of the Software. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 
					
						
							|  |  |  |  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 
					
						
							|  |  |  |  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | 
					
						
							|  |  |  |  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 
					
						
							|  |  |  |  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 
					
						
							|  |  |  |  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | 
					
						
							|  |  |  |  * THE SOFTWARE. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "qemu/osdep.h"
 | 
					
						
							| 
									
										
										
										
											2018-06-25 09:42:10 -03:00
										 |  |  | #include "qemu/units.h"
 | 
					
						
							| 
									
										
										
										
											2016-09-29 14:46:45 +02:00
										 |  |  | #include "cpu.h"
 | 
					
						
							|  |  |  | #include "hw/boards.h"
 | 
					
						
							|  |  |  | #include "hw/char/serial.h"
 | 
					
						
							| 
									
										
										
										
											2018-10-02 23:25:18 +02:00
										 |  |  | #include "hw/misc/unimp.h"
 | 
					
						
							| 
									
										
										
										
											2016-09-29 14:46:45 +02:00
										 |  |  | #include "hw/loader.h"
 | 
					
						
							|  |  |  | #include "hw/sparc/sparc64.h"
 | 
					
						
							| 
									
										
										
										
											2019-10-04 01:03:56 +02:00
										 |  |  | #include "hw/rtc/sun4v-rtc.h"
 | 
					
						
							| 
									
										
										
										
											2016-09-29 14:46:45 +02:00
										 |  |  | #include "exec/address-spaces.h"
 | 
					
						
							|  |  |  | #include "sysemu/block-backend.h"
 | 
					
						
							| 
									
										
										
										
											2017-01-23 21:18:13 +01:00
										 |  |  | #include "qemu/error-report.h"
 | 
					
						
							|  |  |  | #include "sysemu/qtest.h"
 | 
					
						
							| 
									
										
										
										
											2019-08-12 07:23:57 +02:00
										 |  |  | #include "sysemu/sysemu.h"
 | 
					
						
							| 
									
										
										
										
											2019-10-08 07:33:16 -04:00
										 |  |  | #include "qapi/error.h"
 | 
					
						
							| 
									
										
										
										
											2016-09-29 14:46:45 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | typedef struct NiagaraBoardState { | 
					
						
							|  |  |  |     MemoryRegion hv_ram; | 
					
						
							|  |  |  |     MemoryRegion partition_ram; | 
					
						
							|  |  |  |     MemoryRegion nvram; | 
					
						
							|  |  |  |     MemoryRegion md_rom; | 
					
						
							|  |  |  |     MemoryRegion hv_rom; | 
					
						
							|  |  |  |     MemoryRegion vdisk_ram; | 
					
						
							|  |  |  |     MemoryRegion prom; | 
					
						
							|  |  |  | } NiagaraBoardState; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define NIAGARA_HV_RAM_BASE 0x100000ULL
 | 
					
						
							|  |  |  | #define NIAGARA_HV_RAM_SIZE 0x3f00000ULL /* 63 MiB */
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define NIAGARA_PARTITION_RAM_BASE 0x80000000ULL
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define NIAGARA_UART_BASE   0x1f10000000ULL
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define NIAGARA_NVRAM_BASE  0x1f11000000ULL
 | 
					
						
							|  |  |  | #define NIAGARA_NVRAM_SIZE  0x2000
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define NIAGARA_MD_ROM_BASE 0x1f12000000ULL
 | 
					
						
							|  |  |  | #define NIAGARA_MD_ROM_SIZE 0x2000
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define NIAGARA_HV_ROM_BASE 0x1f12080000ULL
 | 
					
						
							|  |  |  | #define NIAGARA_HV_ROM_SIZE 0x2000
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define NIAGARA_IOBBASE     0x9800000000ULL
 | 
					
						
							|  |  |  | #define NIAGARA_IOBSIZE     0x0100000000ULL
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define NIAGARA_VDISK_BASE  0x1f40000000ULL
 | 
					
						
							|  |  |  | #define NIAGARA_RTC_BASE    0xfff0c1fff8ULL
 | 
					
						
							|  |  |  | #define NIAGARA_UART_BASE   0x1f10000000ULL
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Firmware layout
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * |------------------| | 
					
						
							|  |  |  |  * |   openboot.bin   | | 
					
						
							|  |  |  |  * |------------------| PROM_ADDR + OBP_OFFSET | 
					
						
							|  |  |  |  * |      q.bin       | | 
					
						
							|  |  |  |  * |------------------| PROM_ADDR + Q_OFFSET | 
					
						
							|  |  |  |  * |     reset.bin    | | 
					
						
							|  |  |  |  * |------------------| PROM_ADDR | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | #define NIAGARA_PROM_BASE   0xfff0000000ULL
 | 
					
						
							|  |  |  | #define NIAGARA_Q_OFFSET    0x10000ULL
 | 
					
						
							|  |  |  | #define NIAGARA_OBP_OFFSET  0x80000ULL
 | 
					
						
							| 
									
										
										
										
											2018-06-25 09:42:10 -03:00
										 |  |  | #define PROM_SIZE_MAX       (4 * MiB)
 | 
					
						
							| 
									
										
										
										
											2016-09-29 14:46:45 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-23 21:18:13 +01:00
										 |  |  | static void add_rom_or_fail(const char *file, const hwaddr addr) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     /* XXX remove qtest_enabled() check once firmware files are
 | 
					
						
							|  |  |  |      * in the qemu tree | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     if (!qtest_enabled() && rom_add_file_fixed(file, addr, -1)) { | 
					
						
							|  |  |  |         error_report("Unable to load a firmware for -M niagara"); | 
					
						
							|  |  |  |         exit(1); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2016-09-29 14:46:45 +02:00
										 |  |  | /* Niagara hardware initialisation */ | 
					
						
							|  |  |  | static void niagara_init(MachineState *machine) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     NiagaraBoardState *s = g_new(NiagaraBoardState, 1); | 
					
						
							|  |  |  |     DriveInfo *dinfo = drive_get_next(IF_PFLASH); | 
					
						
							|  |  |  |     MemoryRegion *sysmem = get_system_memory(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* init CPUs */ | 
					
						
							| 
									
										
										
										
											2017-10-05 15:51:06 +02:00
										 |  |  |     sparc64_cpu_devinit(machine->cpu_type, NIAGARA_PROM_BASE); | 
					
						
							| 
									
										
										
										
											2016-09-29 14:46:45 +02:00
										 |  |  |     /* set up devices */ | 
					
						
							| 
									
										
										
										
											2019-10-08 07:33:16 -04:00
										 |  |  |     memory_region_init_ram(&s->hv_ram, NULL, "sun4v-hv.ram", | 
					
						
							|  |  |  |                            NIAGARA_HV_RAM_SIZE, &error_fatal); | 
					
						
							| 
									
										
										
										
											2016-09-29 14:46:45 +02:00
										 |  |  |     memory_region_add_subregion(sysmem, NIAGARA_HV_RAM_BASE, &s->hv_ram); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     memory_region_allocate_system_memory(&s->partition_ram, NULL, | 
					
						
							|  |  |  |                                          "sun4v-partition.ram", | 
					
						
							|  |  |  |                                          machine->ram_size); | 
					
						
							|  |  |  |     memory_region_add_subregion(sysmem, NIAGARA_PARTITION_RAM_BASE, | 
					
						
							|  |  |  |                                 &s->partition_ram); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-08 07:33:16 -04:00
										 |  |  |     memory_region_init_ram(&s->nvram, NULL, "sun4v.nvram", NIAGARA_NVRAM_SIZE, | 
					
						
							|  |  |  |                            &error_fatal); | 
					
						
							| 
									
										
										
										
											2016-09-29 14:46:45 +02:00
										 |  |  |     memory_region_add_subregion(sysmem, NIAGARA_NVRAM_BASE, &s->nvram); | 
					
						
							| 
									
										
										
										
											2019-10-08 07:33:16 -04:00
										 |  |  |     memory_region_init_ram(&s->md_rom, NULL, "sun4v-md.rom", | 
					
						
							|  |  |  |                            NIAGARA_MD_ROM_SIZE, &error_fatal); | 
					
						
							| 
									
										
										
										
											2016-09-29 14:46:45 +02:00
										 |  |  |     memory_region_add_subregion(sysmem, NIAGARA_MD_ROM_BASE, &s->md_rom); | 
					
						
							| 
									
										
										
										
											2019-10-08 07:33:16 -04:00
										 |  |  |     memory_region_init_ram(&s->hv_rom, NULL, "sun4v-hv.rom", | 
					
						
							|  |  |  |                            NIAGARA_HV_ROM_SIZE, &error_fatal); | 
					
						
							| 
									
										
										
										
											2016-09-29 14:46:45 +02:00
										 |  |  |     memory_region_add_subregion(sysmem, NIAGARA_HV_ROM_BASE, &s->hv_rom); | 
					
						
							| 
									
										
										
										
											2019-10-08 07:33:16 -04:00
										 |  |  |     memory_region_init_ram(&s->prom, NULL, "sun4v.prom", PROM_SIZE_MAX, | 
					
						
							|  |  |  |                            &error_fatal); | 
					
						
							| 
									
										
										
										
											2016-09-29 14:46:45 +02:00
										 |  |  |     memory_region_add_subregion(sysmem, NIAGARA_PROM_BASE, &s->prom); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-23 21:18:13 +01:00
										 |  |  |     add_rom_or_fail("nvram1", NIAGARA_NVRAM_BASE); | 
					
						
							|  |  |  |     add_rom_or_fail("1up-md.bin", NIAGARA_MD_ROM_BASE); | 
					
						
							|  |  |  |     add_rom_or_fail("1up-hv.bin", NIAGARA_HV_ROM_BASE); | 
					
						
							| 
									
										
										
										
											2016-09-29 14:46:45 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-23 21:18:13 +01:00
										 |  |  |     add_rom_or_fail("reset.bin", NIAGARA_PROM_BASE); | 
					
						
							|  |  |  |     add_rom_or_fail("q.bin", NIAGARA_PROM_BASE + NIAGARA_Q_OFFSET); | 
					
						
							|  |  |  |     add_rom_or_fail("openboot.bin", NIAGARA_PROM_BASE + NIAGARA_OBP_OFFSET); | 
					
						
							| 
									
										
										
										
											2016-09-29 14:46:45 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /* the virtual ramdisk is kind of initrd, but it resides
 | 
					
						
							|  |  |  |        outside of the partition RAM */ | 
					
						
							|  |  |  |     if (dinfo) { | 
					
						
							|  |  |  |         BlockBackend *blk = blk_by_legacy_dinfo(dinfo); | 
					
						
							|  |  |  |         int size = blk_getlength(blk); | 
					
						
							|  |  |  |         if (size > 0) { | 
					
						
							| 
									
										
										
										
											2019-10-08 07:33:16 -04:00
										 |  |  |             memory_region_init_ram(&s->vdisk_ram, NULL, "sun4v_vdisk.ram", size, | 
					
						
							|  |  |  |                                    &error_fatal); | 
					
						
							| 
									
										
										
										
											2016-09-29 14:46:45 +02:00
										 |  |  |             memory_region_add_subregion(get_system_memory(), | 
					
						
							|  |  |  |                                         NIAGARA_VDISK_BASE, &s->vdisk_ram); | 
					
						
							|  |  |  |             dinfo->is_default = 1; | 
					
						
							|  |  |  |             rom_add_file_fixed(blk_bs(blk)->filename, NIAGARA_VDISK_BASE, -1); | 
					
						
							|  |  |  |         } else { | 
					
						
							| 
									
										
											  
											
												hw/sparc*: Replace fprintf(stderr, "*\n" with error_report()
Replace a large number of the fprintf(stderr, "*\n" calls with
error_report(). The functions were renamed with these commands and then
compiler issues where manually fixed.
find ./* -type f -exec sed -i \
    'N;N;N;N;N;N;N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
    {} +
find ./* -type f -exec sed -i \
    'N;N;N;N;N;N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
    {} +
find ./* -type f -exec sed -i \
    'N;N;N;N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
    {} +
find ./* -type f -exec sed -i \
    'N;N;N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
    {} +
find ./* -type f -exec sed -i \
    'N;N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
    {} +
find ./* -type f -exec sed -i \
    'N;N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
    {} +
find ./* -type f -exec sed -i \
    'N;N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
    {} +
find ./* -type f -exec sed -i \
    'N;N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
    {} +
find ./* -type f -exec sed -i \
    'N;N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
    {} +
find ./* -type f -exec sed -i \
    'N;N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
    {} +
find ./* -type f -exec sed -i \
    'N; {s|fprintf(stderr, "\(.*\)\\n"\(.*\));|error_report("\1"\2);|Ig}' \
    {} +
Some lines where then manually tweaked to pass checkpatch.
Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
Cc: Fabien Chouteau <chouteau@adacore.com>
Cc: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Cc: Artyom Tarasenko <atar4qemu@gmail.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Acked-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Message-Id: <20180203084315.20497-12-armbru@redhat.com>
											
										 
											2018-02-03 09:43:12 +01:00
										 |  |  |             error_report("could not load ram disk '%s'", | 
					
						
							|  |  |  |                          blk_bs(blk)->filename); | 
					
						
							| 
									
										
										
										
											2016-09-29 14:46:45 +02:00
										 |  |  |             exit(1); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-04-20 15:52:43 +01:00
										 |  |  |     if (serial_hd(0)) { | 
					
						
							| 
									
										
										
										
											2017-01-23 22:08:59 +01:00
										 |  |  |         serial_mm_init(sysmem, NIAGARA_UART_BASE, 0, NULL, 115200, | 
					
						
							| 
									
										
										
										
											2018-04-20 15:52:43 +01:00
										 |  |  |                        serial_hd(0), DEVICE_BIG_ENDIAN); | 
					
						
							| 
									
										
										
										
											2017-01-23 22:08:59 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-10-02 23:25:18 +02:00
										 |  |  |     create_unimplemented_device("sun4v-iob", NIAGARA_IOBBASE, NIAGARA_IOBSIZE); | 
					
						
							| 
									
										
										
										
											2016-09-29 14:46:45 +02:00
										 |  |  |     sun4v_rtc_init(NIAGARA_RTC_BASE); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void niagara_class_init(ObjectClass *oc, void *data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     MachineClass *mc = MACHINE_CLASS(oc); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     mc->desc = "Sun4v platform, Niagara"; | 
					
						
							|  |  |  |     mc->init = niagara_init; | 
					
						
							|  |  |  |     mc->max_cpus = 1; /* XXX for now */ | 
					
						
							|  |  |  |     mc->default_boot_order = "c"; | 
					
						
							| 
									
										
										
										
											2017-10-05 15:51:06 +02:00
										 |  |  |     mc->default_cpu_type = SPARC_CPU_TYPE_NAME("Sun-UltraSparc-T1"); | 
					
						
							| 
									
										
										
										
											2016-09-29 14:46:45 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static const TypeInfo niagara_type = { | 
					
						
							|  |  |  |     .name = MACHINE_TYPE_NAME("niagara"), | 
					
						
							|  |  |  |     .parent = TYPE_MACHINE, | 
					
						
							|  |  |  |     .class_init = niagara_class_init, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void niagara_register_types(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     type_register_static(&niagara_type); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type_init(niagara_register_types) |