From nobody Wed Nov 27 04:46:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1701650089; cv=none; d=zohomail.com; s=zohoarc; b=ZQcVJusWPC2CV0JD0zUJyIswyqopbl60w8yi1A0yzY4ZRDuYxnZjPm0+m3cxfZFtQWbg24bi6INMqpgJqgRbANSlQEJJ6kWirWPaBDA4Cz1PXlZeI30Bda0vk/SYDZYB2xyVfRiIYdbKU9egwnvaimnnlVfrh5Q+CYDsqSFIMjg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701650089; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=7mb12SLyYKgE+GLLI/c9J/vANlZ3FBQt3OE84lYGKOg=; b=ZRWGDmIxk13tTptFAWBq2bQX3rzzIZ9egJfBeeLVQ0W21WpWHunEXC0ELm8JkLo6hnfyHdJ5HUPEqhaHMY0zpPZdo4J6OThdy99jbW1tu1/qWYlrTx3qx+dgnQhzVSK+2GhUkV6+13DM+fkQqQ7FPuLvI1yLGpRMUDH5olvQUdw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 170165008947037.67965644297033; Sun, 3 Dec 2023 16:34:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r9wnN-0004VG-3k; Sun, 03 Dec 2023 19:26:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r9wnC-0004Qm-8q; Sun, 03 Dec 2023 19:26:34 -0500 Received: from mail-yw1-x112e.google.com ([2607:f8b0:4864:20::112e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r9wn8-00005i-Nk; Sun, 03 Dec 2023 19:26:33 -0500 Received: by mail-yw1-x112e.google.com with SMTP id 00721157ae682-5d8d2b5d1b5so180167b3.0; Sun, 03 Dec 2023 16:26:29 -0800 (PST) Received: from localhost.localdomain ([201.206.180.22]) by smtp.gmail.com with ESMTPSA id l63-20020a0de242000000b005d3e6ce07e7sm2443187ywe.6.2023.12.03.16.26.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 16:26:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701649588; x=1702254388; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7mb12SLyYKgE+GLLI/c9J/vANlZ3FBQt3OE84lYGKOg=; b=F4X1ZIlUJA7tZX7qenq1nOuLacPKX+q8gR2+ZLz8C0su0MpPTolzY4cKt2IJPnpP6r j/re4B5qkKQNSPXtrjnPL5ldT1CE+xvcSfCLWPZTZ1Hd88tEhpwIlQiNXay0fwP7QsvP oZ99xq8/t7k5OANLN7Q03W+pi1AuyrKEpasTjzp9qaWM6veqnuKOo9lUZ5xk0jvh+qgY PpE27tnuslx/X6au4gOP8bUNe45Hq9m81zCnuJzsQiPnaWsCSlt63Y4JzS6GpWPJumq/ QKt8R2sqM8mxosSzE40kEYsSXkY9GAW+oQ7mupfiDQREZdHvAk7s0kNdvyeMXY56Hlbx ydGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701649588; x=1702254388; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7mb12SLyYKgE+GLLI/c9J/vANlZ3FBQt3OE84lYGKOg=; b=b8ZbsQfLx/QFamCkeqjRtoc7FKb9OzaBb8s9Ud0yT6H2j62kab1LikTt7Z9qMO4ZOi OYLQV+xWUtCXybjWhUgWm6ZvI/9NhWBKcweMHtBuemzKu5MH5GZrXpXikJQKwNG9owDo nqoI7JbWsJSW2ftDUKjAytM2pP0F+dmEeYEqBpKIQPAsJZoXwxmyUKz7HhtFO/viNINv OXiKSfHOoFob+OCxFm+XTvCr2Q8+GY2DnbUkeYpD3K9o2rxh7jhkl1XvkGWJijPr6nbx QXZc3CzfXDe3ygG3BVUsgDhcIay+yuDBqPmKnYTUlawTFKR9BPHc46WtTFKtDWPhOdUG LfGw== X-Gm-Message-State: AOJu0Yz4KGP/Q9iBBhWaze3+VMv+6VVmEp/e3ahaTAHS5/G9dlWhlgn0 57lAsLe7O9KJ4ihmlUxQY1Vq1SrHIx22Iw== X-Google-Smtp-Source: AGHT+IHIE3eMTMvFqh30BVDYvcYsuoajUdB014bTzSH1Nb/oOd044WME3NOrLjI4kITHD66SwSo3Uw== X-Received: by 2002:a81:ad14:0:b0:5ca:8f2c:28c5 with SMTP id l20-20020a81ad14000000b005ca8f2c28c5mr656171ywh.8.1701649588199; Sun, 03 Dec 2023 16:26:28 -0800 (PST) From: Sergey Kambalin X-Google-Original-From: Sergey Kambalin To: qemu-arm@nongnu.org Cc: qemu-devel@nongnu.org, Sergey Kambalin Subject: [PATCH v3 03/45] Split out raspi machine common part Date: Sun, 3 Dec 2023 18:25:37 -0600 Message-Id: <20231204002619.1367044-4-sergey.kambalin@auriga.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231204002619.1367044-1-sergey.kambalin@auriga.com> References: <20231204002619.1367044-1-sergey.kambalin@auriga.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::112e; envelope-from=serg.oker@gmail.com; helo=mail-yw1-x112e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1701651356348100001 Content-Type: text/plain; charset="utf-8" Pre-setup for raspberry pi 4 introduction Signed-off-by: Sergey Kambalin --- hw/arm/raspi.c | 112 ++++++++++++++++++-------------- include/hw/arm/raspi_platform.h | 21 ++++++ 2 files changed, 85 insertions(+), 48 deletions(-) diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c index af866ebce2..7d04734cd2 100644 --- a/hw/arm/raspi.c +++ b/hw/arm/raspi.c @@ -18,6 +18,7 @@ #include "qapi/error.h" #include "hw/arm/boot.h" #include "hw/arm/bcm2836.h" +#include "hw/arm/raspi_platform.h" #include "hw/registerfields.h" #include "qemu/error-report.h" #include "hw/boards.h" @@ -25,6 +26,9 @@ #include "hw/arm/boot.h" #include "qom/object.h" =20 +#define TYPE_RASPI_MACHINE MACHINE_TYPE_NAME("raspi-common") +OBJECT_DECLARE_SIMPLE_TYPE(RaspiMachineState, RASPI_MACHINE) + #define SMPBOOT_ADDR 0x300 /* this should leave enough space for ATAGS = */ #define MVBAR_ADDR 0x400 /* secure vectors */ #define BOARDSETUP_ADDR (MVBAR_ADDR + 0x20) /* board setup code */ @@ -37,25 +41,10 @@ =20 struct RaspiMachineState { /*< private >*/ - MachineState parent_obj; + RaspiBaseMachineState parent_obj; /*< public >*/ BCM283XState soc; - struct arm_boot_info binfo; -}; -typedef struct RaspiMachineState RaspiMachineState; - -struct RaspiMachineClass { - /*< private >*/ - MachineClass parent_obj; - /*< public >*/ - uint32_t board_rev; }; -typedef struct RaspiMachineClass RaspiMachineClass; - -#define TYPE_RASPI_MACHINE MACHINE_TYPE_NAME("raspi-common") -DECLARE_OBJ_CHECKERS(RaspiMachineState, RaspiMachineClass, - RASPI_MACHINE, TYPE_RASPI_MACHINE) - =20 /* * Board revision codes: @@ -83,6 +72,11 @@ static const struct { [PROCESSOR_ID_BCM2837] =3D {TYPE_BCM2837, BCM283X_NCPUS}, }; =20 +static void raspi_base_machine_init(MachineState *machine, + BCM283XBaseState *soc); +static void raspi_machine_class_common_init(MachineClass *mc, + uint32_t board_rev); + static uint64_t board_ram_size(uint32_t board_rev) { assert(FIELD_EX32(board_rev, REV_CODE, STYLE)); /* Only new style */ @@ -200,13 +194,12 @@ static void reset_secondary(ARMCPU *cpu, const struct= arm_boot_info *info) cpu_set_pc(cs, info->smp_loader_start); } =20 -static void setup_boot(MachineState *machine, RaspiProcessorId processor_i= d, - size_t ram_size) +static void setup_boot(MachineState *machine, ARMCPU *cpu, + RaspiProcessorId processor_id, size_t ram_size) { - RaspiMachineState *s =3D RASPI_MACHINE(machine); + RaspiBaseMachineState *s =3D RASPI_BASE_MACHINE(machine); int r; =20 - s->binfo.board_id =3D MACH_TYPE_BCM2708; s->binfo.ram_size =3D ram_size; =20 if (processor_id <=3D PROCESSOR_ID_BCM2836) { @@ -252,13 +245,13 @@ static void setup_boot(MachineState *machine, RaspiPr= ocessorId processor_id, s->binfo.firmware_loaded =3D true; } =20 - arm_load_kernel(&s->soc.parent_obj.cpu[0].core, machine, &s->binfo); + arm_load_kernel(cpu, machine, &s->binfo); } =20 -static void raspi_machine_init(MachineState *machine) +static void raspi_base_machine_init(MachineState *machine, + BCM283XBaseState *soc) { - RaspiMachineClass *mc =3D RASPI_MACHINE_GET_CLASS(machine); - RaspiMachineState *s =3D RASPI_MACHINE(machine); + RaspiBaseMachineClass *mc =3D RASPI_BASE_MACHINE_GET_CLASS(machine); uint32_t board_rev =3D mc->board_rev; uint64_t ram_size =3D board_ram_size(board_rev); uint32_t vcram_size; @@ -279,19 +272,17 @@ static void raspi_machine_init(MachineState *machine) machine->ram, 0); =20 /* Setup the SOC */ - object_initialize_child(OBJECT(machine), "soc", &s->soc, - board_soc_type(board_rev)); - object_property_add_const_link(OBJECT(&s->soc), "ram", OBJECT(machine-= >ram)); - object_property_set_int(OBJECT(&s->soc), "board-rev", board_rev, + object_property_add_const_link(OBJECT(soc), "ram", OBJECT(machine->ram= )); + object_property_set_int(OBJECT(soc), "board-rev", board_rev, &error_abort); - object_property_set_str(OBJECT(&s->soc), "command-line", + object_property_set_str(OBJECT(soc), "command-line", machine->kernel_cmdline, &error_abort); - qdev_realize(DEVICE(&s->soc), NULL, &error_fatal); + qdev_realize(DEVICE(soc), NULL, &error_fatal); =20 /* Create and plug in the SD cards */ di =3D drive_get(IF_SD, 0, 0); blk =3D di ? blk_by_legacy_dinfo(di) : NULL; - bus =3D qdev_get_child_bus(DEVICE(&s->soc), "sd-bus"); + bus =3D qdev_get_child_bus(DEVICE(soc), "sd-bus"); if (bus =3D=3D NULL) { error_report("No SD bus found in SOC object"); exit(1); @@ -300,19 +291,32 @@ static void raspi_machine_init(MachineState *machine) qdev_prop_set_drive_err(carddev, "drive", blk, &error_fatal); qdev_realize_and_unref(carddev, bus, &error_fatal); =20 - vcram_size =3D object_property_get_uint(OBJECT(&s->soc), "vcram-size", + vcram_size =3D object_property_get_uint(OBJECT(soc), "vcram-size", &error_abort); - setup_boot(machine, board_processor_id(mc->board_rev), + setup_boot(machine, &soc->cpu[0].core, board_processor_id(board_rev), machine->ram_size - vcram_size); } =20 -static void raspi_machine_class_common_init(MachineClass *mc, - uint32_t board_rev) +static void raspi_machine_init(MachineState *machine) +{ + RaspiMachineState *s =3D RASPI_MACHINE(machine); + RaspiBaseMachineState *s_base =3D RASPI_BASE_MACHINE(machine); + RaspiBaseMachineClass *mc =3D RASPI_BASE_MACHINE_GET_CLASS(machine); + BCM283XState *soc =3D &s->soc; + + s_base->binfo.board_id =3D MACH_TYPE_BCM2708; + + object_initialize_child(OBJECT(machine), "soc", soc, + board_soc_type(mc->board_rev)); + raspi_base_machine_init(machine, &soc->parent_obj); +} + +void raspi_machine_class_common_init(MachineClass *mc, + uint32_t board_rev) { mc->desc =3D g_strdup_printf("Raspberry Pi %s (revision 1.%u)", board_type(board_rev), FIELD_EX32(board_rev, REV_CODE, REVISION)); - mc->init =3D raspi_machine_init; mc->block_default_type =3D IF_SD; mc->no_parallel =3D 1; mc->no_floppy =3D 1; @@ -322,50 +326,57 @@ static void raspi_machine_class_common_init(MachineCl= ass *mc, mc->default_ram_id =3D "ram"; }; =20 +static void raspi_machine_class_init(MachineClass *mc, + uint32_t board_rev) +{ + raspi_machine_class_common_init(mc, board_rev); + mc->init =3D raspi_machine_init; +}; + static void raspi0_machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc =3D MACHINE_CLASS(oc); - RaspiMachineClass *rmc =3D RASPI_MACHINE_CLASS(oc); + RaspiBaseMachineClass *rmc =3D RASPI_BASE_MACHINE_CLASS(oc); =20 rmc->board_rev =3D 0x920092; /* Revision 1.2 */ - raspi_machine_class_common_init(mc, rmc->board_rev); + raspi_machine_class_init(mc, rmc->board_rev); }; =20 static void raspi1ap_machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc =3D MACHINE_CLASS(oc); - RaspiMachineClass *rmc =3D RASPI_MACHINE_CLASS(oc); + RaspiBaseMachineClass *rmc =3D RASPI_BASE_MACHINE_CLASS(oc); =20 rmc->board_rev =3D 0x900021; /* Revision 1.1 */ - raspi_machine_class_common_init(mc, rmc->board_rev); + raspi_machine_class_init(mc, rmc->board_rev); }; =20 static void raspi2b_machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc =3D MACHINE_CLASS(oc); - RaspiMachineClass *rmc =3D RASPI_MACHINE_CLASS(oc); + RaspiBaseMachineClass *rmc =3D RASPI_BASE_MACHINE_CLASS(oc); =20 rmc->board_rev =3D 0xa21041; - raspi_machine_class_common_init(mc, rmc->board_rev); + raspi_machine_class_init(mc, rmc->board_rev); }; =20 #ifdef TARGET_AARCH64 static void raspi3ap_machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc =3D MACHINE_CLASS(oc); - RaspiMachineClass *rmc =3D RASPI_MACHINE_CLASS(oc); + RaspiBaseMachineClass *rmc =3D RASPI_BASE_MACHINE_CLASS(oc); =20 rmc->board_rev =3D 0x9020e0; /* Revision 1.0 */ - raspi_machine_class_common_init(mc, rmc->board_rev); + raspi_machine_class_init(mc, rmc->board_rev); }; =20 static void raspi3b_machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc =3D MACHINE_CLASS(oc); - RaspiMachineClass *rmc =3D RASPI_MACHINE_CLASS(oc); + RaspiBaseMachineClass *rmc =3D RASPI_BASE_MACHINE_CLASS(oc); =20 rmc->board_rev =3D 0xa02082; - raspi_machine_class_common_init(mc, rmc->board_rev); + raspi_machine_class_init(mc, rmc->board_rev); }; #endif /* TARGET_AARCH64 */ =20 @@ -394,9 +405,14 @@ static const TypeInfo raspi_machine_types[] =3D { #endif }, { .name =3D TYPE_RASPI_MACHINE, - .parent =3D TYPE_MACHINE, + .parent =3D TYPE_RASPI_BASE_MACHINE, .instance_size =3D sizeof(RaspiMachineState), - .class_size =3D sizeof(RaspiMachineClass), + .abstract =3D true, + }, { + .name =3D TYPE_RASPI_BASE_MACHINE, + .parent =3D TYPE_MACHINE, + .instance_size =3D sizeof(RaspiBaseMachineState), + .class_size =3D sizeof(RaspiBaseMachineClass), .abstract =3D true, } }; diff --git a/include/hw/arm/raspi_platform.h b/include/hw/arm/raspi_platfor= m.h index ede98e63c3..3018e8fcf3 100644 --- a/include/hw/arm/raspi_platform.h +++ b/include/hw/arm/raspi_platform.h @@ -28,6 +28,27 @@ #ifndef HW_ARM_RASPI_PLATFORM_H #define HW_ARM_RASPI_PLATFORM_H =20 +#include "hw/boards.h" +#include "hw/arm/boot.h" + +#define TYPE_RASPI_BASE_MACHINE MACHINE_TYPE_NAME("raspi-base") +OBJECT_DECLARE_TYPE(RaspiBaseMachineState, RaspiBaseMachineClass, + RASPI_BASE_MACHINE) + +struct RaspiBaseMachineState { + /*< private >*/ + MachineState parent_obj; + /*< public >*/ + struct arm_boot_info binfo; +}; + +struct RaspiBaseMachineClass { + /*< private >*/ + MachineClass parent_obj; + /*< public >*/ + uint32_t board_rev; +}; + #define MSYNC_OFFSET 0x0000 /* Multicore Sync Block */ #define CCPT_OFFSET 0x1000 /* Compact Camera Port 2 TX */ #define INTE_OFFSET 0x2000 /* VC Interrupt controller */ --=20 2.34.1