From nobody Mon Feb 9 23:04:05 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1593354496; cv=none; d=zohomail.com; s=zohoarc; b=A88CBd2FftYEwSBeBb9nlkF83EZODI7vK8Tnto+/7ScQvVqb/R9bfxqhGUjxWvQDs1cW2RBR1YpUzYNTAvDY/WEw45RxK2vmtwRM/CqwO2fDkTxVpXw6M1Nd9VlSKe0Q5ScNyfZdy0JNliIvijKRaAFVdDDE4boT04X4kcv3NrI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593354496; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=lUUWbbu7Y8pmzdSQjUCbPf/b5nShrOK6vJIrYmJ3aOc=; b=GNem5zxLbmaxvV6GfCpyDlqQT/hyD3IaumHmPQXtSw7PoTneeh3jChcHMGfi0i5f6JGc8G93sRlHheKDb9tWcK8EOBL8n/hEXVeJDiwzOGEPR3W8NJFPSFUhMur+EFsWhiIFQPvI4PRfgiFfa4d4jkKmui+WSQAulKYO7QlsonU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1593354496854309.8077466093064; Sun, 28 Jun 2020 07:28:16 -0700 (PDT) Received: from localhost ([::1]:55750 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jpYI3-00037I-Jq for importer@patchew.org; Sun, 28 Jun 2020 10:28:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38138) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jpYEY-0005ty-7U for qemu-devel@nongnu.org; Sun, 28 Jun 2020 10:24:38 -0400 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:37588) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jpYEW-0004eC-4Y for qemu-devel@nongnu.org; Sun, 28 Jun 2020 10:24:37 -0400 Received: by mail-wm1-x343.google.com with SMTP id o2so13694605wmh.2 for ; Sun, 28 Jun 2020 07:24:35 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id h13sm5321555wml.42.2020.06.28.07.24.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jun 2020 07:24:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lUUWbbu7Y8pmzdSQjUCbPf/b5nShrOK6vJIrYmJ3aOc=; b=ZZzEqCiyHqW66MeLyTjP6vdAo8NAw9KQQfwr1KQOVSrSa+5K6iYED4zAnbSheORO5y UJbIO2Sb99u42fB1TFBVBHOxla60EOQJKIpffcza/HNDpV3lqUpQWwz7AsVSGh1x8vQM kjlBzoFu+vk7HWyae5joXbZ6X2pvtLW5pcsniIxdbO94lqIhL9VGFMwCnLCp93cnDM4I XXtuiMMFvwOQVvfLlIOWKMod7sf/pXTTjvtxYxZGtBNRg0bYec4qLMO6av1kM+Vdyua/ x6hB4j+nVvJEACLjUhpsEcjtlGBjG3XZcYn3sGZShrs+LqTtf7NLUXB/majZfmmQZKfI A/Uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lUUWbbu7Y8pmzdSQjUCbPf/b5nShrOK6vJIrYmJ3aOc=; b=UZiuDMdTsWAtbaGdQ32S7EkFuQGgJgD+6QD2URjcdArDi8AhmyfAYt580bXwH/VkEZ GhPWJtPS/1gfxzBVJ7DcAMHxfEbDVQx1JkjZv22WBUCBq2nTJ0GiKr+TOmkulEJ5D9fb VHtcrU3vM6ulr/nNtdZNeRLONhqkSVKVgORyBfL87NhPi2yuXZuSW+ZeJHTA+/OYkHpB thbetpddxbhNbe/560Bd09u92xTxtc1CNNTEIpINgvzJPeWWKlMSVhV886o5HwZunAFC GL0aL/4YPDCczbtLtJoGd6kD78JsZ1oTvuSsigU6uaLnhqlHIugkTAB7TQi+KyIhDWQB g+Qg== X-Gm-Message-State: AOAM533jRud4ow4fOVJv4i3BWAaeGJNExRp3N4eqS8fSnNRQDvDaObM0 FnjmdwipZ1Fmn1KyggqXan03vg== X-Google-Smtp-Source: ABdhPJxbIZq9HZYzidiT57oheozoEkK4LR301DY4sN0NLaCJ49wfKAtw9KvrnUyCX8QCIu0Q3f0yDw== X-Received: by 2002:a1c:99c2:: with SMTP id b185mr13520572wme.52.1593354274670; Sun, 28 Jun 2020 07:24:34 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH 02/17] hw/arm/spitz: Create SpitzMachineClass abstract base class Date: Sun, 28 Jun 2020 15:24:14 +0100 Message-Id: <20200628142429.17111-3-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200628142429.17111-1-peter.maydell@linaro.org> References: <20200628142429.17111-1-peter.maydell@linaro.org> 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=2a00:1450:4864:20::343; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x343.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Alistair Francis Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" For the four Spitz-family machines (akita, borzoi, spitz, terrier) create a proper abstract class SpitzMachineClass which encapsulates the common behaviour, rather than having them all derive directly from TYPE_MACHINE: * instead of each machine class setting mc->init to a wrapper function which calls spitz_common_init() with parameters, put that data in the SpitzMachineClass and make spitz_common_init the SpitzMachineClass machine-init function * move the settings of mc->block_default_type and mc->ignore_memory_transaction_failures into the SpitzMachineClass class init rather than repeating them in each machine's class init (The motivation is that we're going to want to keep some state in the SpitzMachineState so we can connect GPIOs between devices created in one sub-function of the machine init to devices created in a different sub-function.) Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/arm/spitz.c | 91 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 55 insertions(+), 36 deletions(-) diff --git a/hw/arm/spitz.c b/hw/arm/spitz.c index 9eaedab79b5..c70e912a33d 100644 --- a/hw/arm/spitz.c +++ b/hw/arm/spitz.c @@ -33,6 +33,26 @@ #include "exec/address-spaces.h" #include "cpu.h" =20 +enum spitz_model_e { spitz, akita, borzoi, terrier }; + +typedef struct { + MachineClass parent; + enum spitz_model_e model; + int arm_id; +} SpitzMachineClass; + +typedef struct { + MachineState parent; +} SpitzMachineState; + +#define TYPE_SPITZ_MACHINE "spitz-common" +#define SPITZ_MACHINE(obj) \ + OBJECT_CHECK(SpitzMachineState, obj, TYPE_SPITZ_MACHINE) +#define SPITZ_MACHINE_GET_CLASS(obj) \ + OBJECT_GET_CLASS(SpitzMachineClass, obj, TYPE_SPITZ_MACHINE) +#define SPITZ_MACHINE_CLASS(klass) \ + OBJECT_CLASS_CHECK(SpitzMachineClass, klass, TYPE_SPITZ_MACHINE) + #undef REG_FMT #define REG_FMT "0x%02lx" =20 @@ -905,8 +925,6 @@ static void spitz_gpio_setup(PXA2xxState *cpu, int slot= s) } =20 /* Board init. */ -enum spitz_model_e { spitz, akita, borzoi, terrier }; - #define SPITZ_RAM 0x04000000 #define SPITZ_ROM 0x00800000 =20 @@ -915,9 +933,10 @@ static struct arm_boot_info spitz_binfo =3D { .ram_size =3D 0x04000000, }; =20 -static void spitz_common_init(MachineState *machine, - enum spitz_model_e model, int arm_id) +static void spitz_common_init(MachineState *machine) { + SpitzMachineClass *smc =3D SPITZ_MACHINE_GET_CLASS(machine); + enum spitz_model_e model =3D smc->model; PXA2xxState *mpu; DeviceState *scp0, *scp1 =3D NULL; MemoryRegion *address_space_mem =3D get_system_memory(); @@ -958,100 +977,100 @@ static void spitz_common_init(MachineState *machine, /* A 4.0 GB microdrive is permanently sitting in CF slot 0. */ spitz_microdrive_attach(mpu, 0); =20 - spitz_binfo.board_id =3D arm_id; + spitz_binfo.board_id =3D smc->arm_id; arm_load_kernel(mpu->cpu, machine, &spitz_binfo); sl_bootparam_write(SL_PXA_PARAM_BASE); } =20 -static void spitz_init(MachineState *machine) +static void spitz_common_class_init(ObjectClass *oc, void *data) { - spitz_common_init(machine, spitz, 0x2c9); + MachineClass *mc =3D MACHINE_CLASS(oc); + + mc->block_default_type =3D IF_IDE; + mc->ignore_memory_transaction_failures =3D true; + mc->init =3D spitz_common_init; } =20 -static void borzoi_init(MachineState *machine) -{ - spitz_common_init(machine, borzoi, 0x33f); -} - -static void akita_init(MachineState *machine) -{ - spitz_common_init(machine, akita, 0x2e8); -} - -static void terrier_init(MachineState *machine) -{ - spitz_common_init(machine, terrier, 0x33f); -} +static const TypeInfo spitz_common_info =3D { + .name =3D TYPE_SPITZ_MACHINE, + .parent =3D TYPE_MACHINE, + .abstract =3D true, + .instance_size =3D sizeof(SpitzMachineState), + .class_size =3D sizeof(SpitzMachineClass), + .class_init =3D spitz_common_class_init, +}; =20 static void akitapda_class_init(ObjectClass *oc, void *data) { MachineClass *mc =3D MACHINE_CLASS(oc); + SpitzMachineClass *smc =3D SPITZ_MACHINE_CLASS(oc); =20 mc->desc =3D "Sharp SL-C1000 (Akita) PDA (PXA270)"; - mc->init =3D akita_init; - mc->ignore_memory_transaction_failures =3D true; mc->default_cpu_type =3D ARM_CPU_TYPE_NAME("pxa270-c0"); + smc->model =3D akita; + smc->arm_id =3D 0x2e8; } =20 static const TypeInfo akitapda_type =3D { .name =3D MACHINE_TYPE_NAME("akita"), - .parent =3D TYPE_MACHINE, + .parent =3D TYPE_SPITZ_MACHINE, .class_init =3D akitapda_class_init, }; =20 static void spitzpda_class_init(ObjectClass *oc, void *data) { MachineClass *mc =3D MACHINE_CLASS(oc); + SpitzMachineClass *smc =3D SPITZ_MACHINE_CLASS(oc); =20 mc->desc =3D "Sharp SL-C3000 (Spitz) PDA (PXA270)"; - mc->init =3D spitz_init; - mc->block_default_type =3D IF_IDE; - mc->ignore_memory_transaction_failures =3D true; mc->default_cpu_type =3D ARM_CPU_TYPE_NAME("pxa270-c0"); + smc->model =3D spitz; + smc->arm_id =3D 0x2c9; } =20 static const TypeInfo spitzpda_type =3D { .name =3D MACHINE_TYPE_NAME("spitz"), - .parent =3D TYPE_MACHINE, + .parent =3D TYPE_SPITZ_MACHINE, .class_init =3D spitzpda_class_init, }; =20 static void borzoipda_class_init(ObjectClass *oc, void *data) { MachineClass *mc =3D MACHINE_CLASS(oc); + SpitzMachineClass *smc =3D SPITZ_MACHINE_CLASS(oc); =20 mc->desc =3D "Sharp SL-C3100 (Borzoi) PDA (PXA270)"; - mc->init =3D borzoi_init; - mc->block_default_type =3D IF_IDE; - mc->ignore_memory_transaction_failures =3D true; mc->default_cpu_type =3D ARM_CPU_TYPE_NAME("pxa270-c0"); + smc->model =3D borzoi; + smc->arm_id =3D 0x33f; } =20 static const TypeInfo borzoipda_type =3D { .name =3D MACHINE_TYPE_NAME("borzoi"), - .parent =3D TYPE_MACHINE, + .parent =3D TYPE_SPITZ_MACHINE, .class_init =3D borzoipda_class_init, }; =20 static void terrierpda_class_init(ObjectClass *oc, void *data) { MachineClass *mc =3D MACHINE_CLASS(oc); + SpitzMachineClass *smc =3D SPITZ_MACHINE_CLASS(oc); =20 mc->desc =3D "Sharp SL-C3200 (Terrier) PDA (PXA270)"; - mc->init =3D terrier_init; - mc->block_default_type =3D IF_IDE; - mc->ignore_memory_transaction_failures =3D true; mc->default_cpu_type =3D ARM_CPU_TYPE_NAME("pxa270-c5"); + smc->model =3D terrier; + smc->arm_id =3D 0x33f; } =20 static const TypeInfo terrierpda_type =3D { .name =3D MACHINE_TYPE_NAME("terrier"), - .parent =3D TYPE_MACHINE, + .parent =3D TYPE_SPITZ_MACHINE, .class_init =3D terrierpda_class_init, }; =20 static void spitz_machine_init(void) { + type_register_static(&spitz_common_info); type_register_static(&akitapda_type); type_register_static(&spitzpda_type); type_register_static(&borzoipda_type); --=20 2.20.1