From patchwork Fri Jun 29 17:22:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 10497111 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BBAFD60230 for ; Fri, 29 Jun 2018 17:24:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A755929010 for ; Fri, 29 Jun 2018 17:24:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9B4A329164; Fri, 29 Jun 2018 17:24:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D3CAD29010 for ; Fri, 29 Jun 2018 17:24:06 +0000 (UTC) Received: from localhost ([::1]:43666 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYx7u-00054l-2X for patchwork-qemu-devel@patchwork.kernel.org; Fri, 29 Jun 2018 13:24:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42154) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYx6R-00044y-LT for qemu-devel@nongnu.org; Fri, 29 Jun 2018 13:22:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYx6N-0003Kr-LS for qemu-devel@nongnu.org; Fri, 29 Jun 2018 13:22:35 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:54503) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1fYx6N-0003Hx-6j for qemu-devel@nongnu.org; Fri, 29 Jun 2018 13:22:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1530292951; x=1561828951; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=QWL4sg+r8fWzmU9vqIsxhgM+Zr3dXrL5AYq6SnOvmdg=; b=ltfHac/FOj3VfaisgXAbL7eo0VARFXookVA1Q9FDoCNdXfsBCBwGhnAE /ixpfP7txBBYx46o76ORAO2TtZ00q3ljXx3R/oq00HoFUDslhr2uid7sL uDge4DQ8kn7P7tCD1GcRopMW7633o7VQTv6yiLpmfp4HjWMX3uNGE8jNi Vy47ytz4xo74Kbk3lHo7ICqOY1ACbpjdWvbIrRDERhT4/FV57SQSa17CH fofDrV+NdHnxbMM0v5vJ5yDZ3p6EBEk2WsAslCBNwfw0wCvnb0ujKDUic qoKrCPUS5HmMQDF3x5ryyWEbRU8AF6FA0syrRDFTB2QjybfLLCkIVr1vg A==; X-IronPort-AV: E=Sophos;i="5.51,286,1526313600"; d="scan'208";a="82461894" Received: from mail-co1nam04lp0055.outbound.protection.outlook.com (HELO NAM04-CO1-obe.outbound.protection.outlook.com) ([216.32.181.55]) by ob1.hgst.iphmx.com with ESMTP; 30 Jun 2018 01:22:28 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector1-wdc-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iugC6atpqNXUgJ3fkZK/Wb6KKkWCQNtCqQ1n8ExRzaY=; b=RxHbFB+aNdbDD7tKyZ2s6Ou72mcjkS4HDRakywlSZ1q25jyAUp7mVoOeL3u3EqBGn8Gs0xXXJEkXEvNqrkzJ1RPZszQJFGjYpucLaZ7QZg67wEYLU0pJ4NSKm3bP2XdGKktQNxCJqYQko+f8mWl/xEWuNNQiqhaxKMsk1/ktDiI= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Alistair.Francis@wdc.com; Received: from risc6-mainframe.int.fusionio.com (199.255.44.171) by CY4PR04MB0391.namprd04.prod.outlook.com (2603:10b6:903:b1::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.906.20; Fri, 29 Jun 2018 17:22:26 +0000 From: Alistair Francis To: qemu-devel@nongnu.org, peter.maydell@linaro.org, mjc@sifive.com Date: Fri, 29 Jun 2018 10:22:09 -0700 Message-Id: <20180629172215.29475-2-alistair.francis@wdc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180629172215.29475-1-alistair.francis@wdc.com> References: <20180629172215.29475-1-alistair.francis@wdc.com> MIME-Version: 1.0 X-Originating-IP: [199.255.44.171] X-ClientProxiedBy: BYAPR03CA0029.namprd03.prod.outlook.com (2603:10b6:a02:a8::42) To CY4PR04MB0391.namprd04.prod.outlook.com (2603:10b6:903:b1::16) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 634cf80d-f74e-4af8-4b5a-08d5dde4e2e1 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989117)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600026)(711020)(48565401081)(2017052603328)(7153060)(7193020); SRVR:CY4PR04MB0391; X-Microsoft-Exchange-Diagnostics: 1; CY4PR04MB0391; 3:lcn5gR3cVhva5qryFEEOnunLIPQ9WI4x5EB5HMut7OUR2b2VVmLBbOM2CRqbkUw4oRTAisCz1Z6ag6XJKP2NyoSyBVvMofc5xa/HSuLqIuojqzh1uLEqu9EJ+C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wukwmebhpAgpVynktx7EDvw/tXOy+G//5Woav2FSYDI0cMBGn7X9GtdRK/XktrhFEPUp0iSF3S8UrxvOleCu3x3Ylv7VYkMHYeFkJn1Mh/8xvtm/DH943ttO2V+/NR748n/29C2lK0bTnloIkZIzW7Bwto3cZ6Bl1OBPJ4bGQUqAGX+m3y4JK0cT2foJRCnkenwfn4hrJeZ/baCPJXajXbRdjlPOO/N1REbZLFqermgP7QH5IZAGnuu0289c/U; 4:VO2HoUOtvqAz6uFWn25QJUowah5MhbQJd40RXACcC/Fukf33mbwCmQ9N2F35Biz3faSA1Fz5SQD/J2fAovxpgs1HomuPfA+/ILQfaAR6opH6I6e4OBpOBLNvpWOYp/YE8cOg4+36sweu6uxUY/NPUJXwOwkomoxtZ/re5p5oA6Q6GF0xm7wO5q3GjDbyuibAo4P20b7H7kwyndUdUusjVUOqPG0F6b2EofXrghozYW5sVeCzJajXVrJwYmpdw2BgR2qVWaV/2pKqftkrlLYp/A== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(5005006)(8121501046)(3231254)(944501410)(52105095)(93006095)(93001095)(10201501046)(3002001)(6055026)(149027)(150027)(6041310)(20161123562045)(20161123558120)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(6072148)(201708071742011)(7699016); SRVR:CY4PR04MB0391; BCL:0; PCL:0; RULEID:; SRVR:CY4PR04MB0391; X-Forefront-PRVS: 0718908305 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6029001)(136003)(39860400002)(366004)(346002)(396003)(376002)(199004)(189003)(446003)(16526019)(186003)(956004)(11346002)(26005)(2616005)(36756003)(39060400002)(72206003)(50226002)(316002)(4326008)(25786009)(44832011)(486006)(476003)(8936002)(48376002)(3846002)(6116002)(50466002)(68736007)(2906002)(105586002)(106356001)(478600001)(66066001)(53936002)(51416003)(52116002)(76176011)(305945005)(97736004)(6486002)(16586007)(386003)(47776003)(6506007)(1076002)(5660300001)(6512007)(6666003)(81156014)(8676002)(81166006)(86362001)(7736002); DIR:OUT; SFP:1102; SCL:1; SRVR:CY4PR04MB0391; H:risc6-mainframe.int.fusionio.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY4PR04MB0391; 23:UdQ53rqXfHrKUnhUV2shC6hjU6IJRH5M8I8eyWckG?= =?us-ascii?Q?2z1quNAdCya1MB2OdFFISJ7g0/MQXCDlz4NmMNgiBMX9wkm7/e0og6y7DD+i?= =?us-ascii?Q?9K4GzIc1V0sI7t11xpdIrlgFzSzrvn6PvOtU1sL14GqrHO6Qo+v9pQnHGdOZ?= =?us-ascii?Q?9gdBC/CGoR8HpxRi8tS8hr8R8eenKqknCc08qkZdE4HoHLM1qYU5K+oypiyw?= =?us-ascii?Q?9IfUp8noBi6uFIMQyyWyDrCHXQAU5u4hNs9sfxwwyOY7XYyoqI5dqMdMfCO8?= =?us-ascii?Q?/S760paYw3q7JS/7ngoRlZHr9Aun2cT6jKTv7ePRZlLL2P8DLFqeDGJbOT9o?= =?us-ascii?Q?0noXCcbW/6f3hcWhl4AwXH3Y7dN/8NrNfnJ/tUIPlvATLM8AC3HMOltHEaGQ?= =?us-ascii?Q?Ob7qsAaXf2juAoR16z2RGdBrWuFAFf9G6lR2duh3l4WJfp9raynhC/K4VhJy?= =?us-ascii?Q?hJOQAHb2uBAKaPmj9WB3h8pIrXRtpYO/utefvWWRpC9B8uB3adT97QZuPtW1?= =?us-ascii?Q?3qcB98+iK8+moiQgfiu42WqlBxyGczXkscZ1I/4+FB4SuFO3j4zQkx4zsWPt?= =?us-ascii?Q?9LTriT7clhjd9l5INRMGgV1dzcE7DyMjyOkpZJF8EpxZe3Bg/Ut2YyVh4J2T?= =?us-ascii?Q?58InJlV76dNOkMVQQ8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tWiUp9fG+A7o6s7uvypuCKg4RjYkeTdX0oHDSdAdzwTTXGCIQYUeoLLW9+MRDHsqrFoB/zWWDD83oynU+MiteM/RshvaL4ON/iav2MnC8Qiz; 20:2yHQOMk1cqYkkBT8sCeCJIZUYFnY7IY+BIwVFMevg2WKe/rpLqDw0dFwvcB1AIzZn+aGyEbT3ybPakXQleOV4lHPBurRZrKLuiB887ceLFc3UReZ4QgJTOljZTKVIEgsD0VhImtcV7KbeJCgUe1jhq1AVZRtRyeatJtMY+rc3OA= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jun 2018 17:22:26.8718 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 634cf80d-f74e-4af8-4b5a-08d5dde4e2e1 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR04MB0391 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 216.71.154.42 Subject: [Qemu-devel] [PULL v2 1/7] hw/riscv/sifive_u: Create a SiFive U SoC object X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alistair23@gmail.com, Alistair Francis , f4bug@amsat.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Create a SiFive Unleashed U54 SoC and use that in the sifive_u machine. We leave the SoC, RAM, device tree and reset/fdt loading as part of the machine. All the other device creation has been moved to the SoC. Signed-off-by: Alistair Francis Reviewed-by: Michael Clark --- hw/riscv/sifive_u.c | 90 ++++++++++++++++++++++++++++--------- include/hw/riscv/sifive_u.h | 16 ++++++- 2 files changed, 82 insertions(+), 24 deletions(-) diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c index c05dcbba95..45b6aeb36b 100644 --- a/hw/riscv/sifive_u.c +++ b/hw/riscv/sifive_u.c @@ -116,10 +116,10 @@ static void create_fdt(SiFiveUState *s, const struct MemmapEntry *memmap, qemu_fdt_setprop_cell(fdt, "/cpus", "#size-cells", 0x0); qemu_fdt_setprop_cell(fdt, "/cpus", "#address-cells", 0x1); - for (cpu = s->soc.num_harts - 1; cpu >= 0; cpu--) { + for (cpu = s->soc.cpus.num_harts - 1; cpu >= 0; cpu--) { nodename = g_strdup_printf("/cpus/cpu@%d", cpu); char *intc = g_strdup_printf("/cpus/cpu@%d/interrupt-controller", cpu); - char *isa = riscv_isa_string(&s->soc.harts[cpu]); + char *isa = riscv_isa_string(&s->soc.cpus.harts[cpu]); qemu_fdt_add_subnode(fdt, nodename); qemu_fdt_setprop_cell(fdt, nodename, "clock-frequency", SIFIVE_U_CLOCK_FREQ); @@ -140,8 +140,8 @@ static void create_fdt(SiFiveUState *s, const struct MemmapEntry *memmap, g_free(nodename); } - cells = g_new0(uint32_t, s->soc.num_harts * 4); - for (cpu = 0; cpu < s->soc.num_harts; cpu++) { + cells = g_new0(uint32_t, s->soc.cpus.num_harts * 4); + for (cpu = 0; cpu < s->soc.cpus.num_harts; cpu++) { nodename = g_strdup_printf("/cpus/cpu@%d/interrupt-controller", cpu); uint32_t intc_phandle = qemu_fdt_get_phandle(fdt, nodename); @@ -159,12 +159,12 @@ static void create_fdt(SiFiveUState *s, const struct MemmapEntry *memmap, 0x0, memmap[SIFIVE_U_CLINT].base, 0x0, memmap[SIFIVE_U_CLINT].size); qemu_fdt_setprop(fdt, nodename, "interrupts-extended", - cells, s->soc.num_harts * sizeof(uint32_t) * 4); + cells, s->soc.cpus.num_harts * sizeof(uint32_t) * 4); g_free(cells); g_free(nodename); - cells = g_new0(uint32_t, s->soc.num_harts * 4); - for (cpu = 0; cpu < s->soc.num_harts; cpu++) { + cells = g_new0(uint32_t, s->soc.cpus.num_harts * 4); + for (cpu = 0; cpu < s->soc.cpus.num_harts; cpu++) { nodename = g_strdup_printf("/cpus/cpu@%d/interrupt-controller", cpu); uint32_t intc_phandle = qemu_fdt_get_phandle(fdt, nodename); @@ -181,7 +181,7 @@ static void create_fdt(SiFiveUState *s, const struct MemmapEntry *memmap, qemu_fdt_setprop_string(fdt, nodename, "compatible", "riscv,plic0"); qemu_fdt_setprop(fdt, nodename, "interrupt-controller", NULL, 0); qemu_fdt_setprop(fdt, nodename, "interrupts-extended", - cells, s->soc.num_harts * sizeof(uint32_t) * 4); + cells, s->soc.cpus.num_harts * sizeof(uint32_t) * 4); qemu_fdt_setprop_cells(fdt, nodename, "reg", 0x0, memmap[SIFIVE_U_PLIC].base, 0x0, memmap[SIFIVE_U_PLIC].size); @@ -217,17 +217,12 @@ static void riscv_sifive_u_init(MachineState *machine) SiFiveUState *s = g_new0(SiFiveUState, 1); MemoryRegion *system_memory = get_system_memory(); MemoryRegion *main_mem = g_new(MemoryRegion, 1); - MemoryRegion *mask_rom = g_new(MemoryRegion, 1); int i; - /* Initialize SOC */ - object_initialize(&s->soc, sizeof(s->soc), TYPE_RISCV_HART_ARRAY); + /* Initialize SoC */ + object_initialize(&s->soc, sizeof(s->soc), TYPE_RISCV_U_SOC); object_property_add_child(OBJECT(machine), "soc", OBJECT(&s->soc), &error_abort); - object_property_set_str(OBJECT(&s->soc), SIFIVE_U_CPU, "cpu-type", - &error_abort); - object_property_set_int(OBJECT(&s->soc), smp_cpus, "num-harts", - &error_abort); object_property_set_bool(OBJECT(&s->soc), true, "realized", &error_abort); @@ -235,17 +230,11 @@ static void riscv_sifive_u_init(MachineState *machine) memory_region_init_ram(main_mem, NULL, "riscv.sifive.u.ram", machine->ram_size, &error_fatal); memory_region_add_subregion(system_memory, memmap[SIFIVE_U_DRAM].base, - main_mem); + main_mem); /* create device tree */ create_fdt(s, memmap, machine->ram_size, machine->kernel_cmdline); - /* boot rom */ - memory_region_init_rom(mask_rom, NULL, "riscv.sifive.u.mrom", - memmap[SIFIVE_U_MROM].size, &error_fatal); - memory_region_add_subregion(system_memory, memmap[SIFIVE_U_MROM].base, - mask_rom); - if (machine->kernel_filename) { load_kernel(machine->kernel_filename); } @@ -284,6 +273,39 @@ static void riscv_sifive_u_init(MachineState *machine) rom_add_blob_fixed_as("mrom.fdt", s->fdt, fdt_totalsize(s->fdt), memmap[SIFIVE_U_MROM].base + sizeof(reset_vec), &address_space_memory); +} + +static void riscv_sifive_u_soc_init(Object *obj) +{ + const struct MemmapEntry *memmap = sifive_u_memmap; + + SiFiveUSoCState *s = RISCV_U_SOC(obj); + MemoryRegion *system_memory = get_system_memory(); + MemoryRegion *mask_rom = g_new(MemoryRegion, 1); + + object_initialize(&s->cpus, sizeof(s->cpus), TYPE_RISCV_HART_ARRAY); + object_property_add_child(obj, "cpus", OBJECT(&s->cpus), + &error_abort); + object_property_set_str(OBJECT(&s->cpus), SIFIVE_U_CPU, "cpu-type", + &error_abort); + object_property_set_int(OBJECT(&s->cpus), smp_cpus, "num-harts", + &error_abort); + + /* boot rom */ + memory_region_init_rom(mask_rom, NULL, "riscv.sifive.u.mrom", + memmap[SIFIVE_U_MROM].size, &error_fatal); + memory_region_add_subregion(system_memory, memmap[SIFIVE_U_MROM].base, + mask_rom); +} + +static void riscv_sifive_u_soc_realize(DeviceState *dev, Error **errp) +{ + SiFiveUSoCState *s = RISCV_U_SOC(dev); + const struct MemmapEntry *memmap = sifive_u_memmap; + MemoryRegion *system_memory = get_system_memory(); + + object_property_set_bool(OBJECT(&s->cpus), true, "realized", + &error_abort); /* MMIO */ s->plic = sifive_plic_create(memmap[SIFIVE_U_PLIC].base, @@ -314,3 +336,27 @@ static void riscv_sifive_u_machine_init(MachineClass *mc) } DEFINE_MACHINE("sifive_u", riscv_sifive_u_machine_init) + +static void riscv_sifive_u_soc_class_init(ObjectClass *oc, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(oc); + + dc->realize = riscv_sifive_u_soc_realize; + /* Reason: Uses serial_hds in realize function, thus can't be used twice */ + dc->user_creatable = false; +} + +static const TypeInfo riscv_sifive_u_soc_type_info = { + .name = TYPE_RISCV_U_SOC, + .parent = TYPE_DEVICE, + .instance_size = sizeof(SiFiveUSoCState), + .instance_init = riscv_sifive_u_soc_init, + .class_init = riscv_sifive_u_soc_class_init, +}; + +static void riscv_sifive_u_soc_register_types(void) +{ + type_register_static(&riscv_sifive_u_soc_type_info); +} + +type_init(riscv_sifive_u_soc_register_types) diff --git a/include/hw/riscv/sifive_u.h b/include/hw/riscv/sifive_u.h index 94a390566e..49f1946539 100644 --- a/include/hw/riscv/sifive_u.h +++ b/include/hw/riscv/sifive_u.h @@ -19,13 +19,25 @@ #ifndef HW_SIFIVE_U_H #define HW_SIFIVE_U_H -typedef struct SiFiveUState { +#define TYPE_RISCV_U_SOC "riscv.sifive.u.soc" +#define RISCV_U_SOC(obj) \ + OBJECT_CHECK(SiFiveUSoCState, (obj), TYPE_RISCV_U_SOC) + +typedef struct SiFiveUSoCState { /*< private >*/ SysBusDevice parent_obj; /*< public >*/ - RISCVHartArrayState soc; + RISCVHartArrayState cpus; DeviceState *plic; +} SiFiveUSoCState; + +typedef struct SiFiveUState { + /*< private >*/ + SysBusDevice parent_obj; + + /*< public >*/ + SiFiveUSoCState soc; void *fdt; int fdt_size; } SiFiveUState;