From patchwork Tue Mar 7 07:08:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 659729 Delivered-To: patch@linaro.org Received: by 2002:adf:a3c6:0:0:0:0:0 with SMTP id m6csp2246094wrb; Mon, 6 Mar 2023 23:15:41 -0800 (PST) X-Google-Smtp-Source: AK7set+XJXLR5JO1PvQW54nca/arnx6vrxpF8sbSqakufZKRuXR9NS5wX2WemjQ1YfXOmXdTYjYL X-Received: by 2002:ac8:5b53:0:b0:3b8:6ae9:b10d with SMTP id n19-20020ac85b53000000b003b86ae9b10dmr21325860qtw.2.1678173341721; Mon, 06 Mar 2023 23:15:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678173341; cv=none; d=google.com; s=arc-20160816; b=tuMf0UfqveqhmQWBexuNW/9+UCv13n7LsKRKXseuI5WAvUFGct4B+dSSr25v1C1bQ/ +VY1ZPb77ca6HfFwazjc5Is+EcGfmfFFOxxSHYtn2oVb0XqZebMMLmbs/Gl9EKVDfH9R WgOTsx9u/IN2jhDLpQYW6+WhDgsQCvbWE8chSjWjnPSChu+vNiZcyyVepDykZzEwaC97 myvMrjDRcCfxm62o5JuBFZK9TmAS0NSv3AcBzcoY+E0F2JAzEwXAaL3BMEbdci2FLOgg /wGx8b6P5xbPLKjb+LAslqosFZr4BlMVx2o3KXgZ3XuapbPZsT1+JTBwXyKEEc1zlwdG oVQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Cq5G3WEGJ/6Zz+rrPCWfk8i0GOn43bnChlWjtdUE1gc=; b=agNZNO1fVseIMoDEZZlm8ey+APHtbzohkfdjIYdiHr9MJvQnaBs4Z9AN6lRQJd2vKP K4lotIdfpnhgTis2suxusTdda3KH3NvgjBMboX7xQf1By9tomvOII15zIl6xVi7rXuY2 zZ9ptghUldktA5H/7/nf1L9mywR8inds5CJB6D7+jgK2hreL+tmqAcb72uTQuaHz2kRd eOwFF5uW+p9TGR6OA5YHmkhXfJimIWedwXmzeaZQR2WE1H7O/yaDsF7VybCepvmdKnhw aBM7kwlrnMEoCFz0n/iebsFYkq53jwKHVcXkLJDyR0keBfbBf+TyqiRNkPadxqHHlvQ3 rvnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DpcIdyLR; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id h9-20020a05620a400900b0073b45062385si10469770qko.588.2023.03.06.23.15.41 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 06 Mar 2023 23:15:41 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DpcIdyLR; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pZRUP-0006tG-HL; Tue, 07 Mar 2023 02:12:01 -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 1pZRTm-0005me-BN for qemu-devel@nongnu.org; Tue, 07 Mar 2023 02:11:24 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pZRTf-0005sG-HK for qemu-devel@nongnu.org; Tue, 07 Mar 2023 02:11:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678173075; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Cq5G3WEGJ/6Zz+rrPCWfk8i0GOn43bnChlWjtdUE1gc=; b=DpcIdyLRtA0sJ/7fU+AsEI9nmuc/4gUIKCtJLahTdrTuLyiILsgl5vSPMuguOs0HH3UfKO lyyFAxsRnEiuu1/nbn8tzOqCforzFosZxfw1OcbAD1DCB6YzKNkdcGDzc+xK70jpKSRlZZ kCR990l1WjG/GxZBT+jc2qmG3xk2oNg= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-231-AI6uAQhLMQSAWcmK7X_eAQ-1; Tue, 07 Mar 2023 02:11:09 -0500 X-MC-Unique: AI6uAQhLMQSAWcmK7X_eAQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8582F18A6461; Tue, 7 Mar 2023 07:11:09 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-78.pek2.redhat.com [10.72.12.78]) by smtp.corp.redhat.com (Postfix) with ESMTP id 96E84400F8FA; Tue, 7 Mar 2023 07:11:07 +0000 (UTC) From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Jason Wang Subject: [PULL 46/51] hw/net/eepro100: Introduce TYPE_EEPRO100 QOM abstract parent Date: Tue, 7 Mar 2023 15:08:11 +0800 Message-Id: <20230307070816.34833-47-jasowang@redhat.com> In-Reply-To: <20230307070816.34833-1-jasowang@redhat.com> References: <20230307070816.34833-1-jasowang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 Received-SPF: pass client-ip=170.10.129.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Philippe Mathieu-Daudé Have all the EEPRO100-based devices share a common (abstract) QOM parent. Signed-off-by: Philippe Mathieu-Daudé Signed-off-by: Jason Wang --- hw/net/eepro100.c | 60 ++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 18 deletions(-) diff --git a/hw/net/eepro100.c b/hw/net/eepro100.c index dce7503..4b5d455 100644 --- a/hw/net/eepro100.c +++ b/hw/net/eepro100.c @@ -235,8 +235,20 @@ typedef enum { ru_ready = 4 } ru_state_t; -typedef struct { +#define TYPE_EEPRO100 "eepro100" +OBJECT_DECLARE_TYPE(EEPRO100State, EEPRO100Class, EEPRO100) + +struct EEPRO100Class { + /*< private >*/ + PCIDeviceClass parent_class; + /*< public >*/ +}; + +struct EEPRO100State { + /*< private >*/ PCIDevice dev; + /*< public >*/ + /* Hash register (multicast mask array, multiple individual addresses). */ uint8_t mult[8]; MemoryRegion mmio_bar; @@ -279,7 +291,7 @@ typedef struct { /* Quasi static device properties (no need to save them). */ uint16_t stats_size; bool has_extended_tcb_support; -} EEPRO100State; +}; /* Word indices in EEPROM. */ typedef enum { @@ -2055,43 +2067,55 @@ static Property e100_properties[] = { DEFINE_PROP_END_OF_LIST(), }; -static void eepro100_class_init(ObjectClass *klass, void *data) +static void eepro100_base_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); E100PCIDeviceInfo *info; - info = eepro100_get_class_by_name(object_class_get_name(klass)); set_bit(DEVICE_CATEGORY_NETWORK, dc->categories); device_class_set_props(dc, e100_properties); - dc->desc = info->desc; k->vendor_id = PCI_VENDOR_ID_INTEL; k->class_id = PCI_CLASS_NETWORK_ETHERNET; k->romfile = "pxe-eepro100.rom"; k->realize = e100_nic_realize; k->exit = pci_nic_uninit; + + info = eepro100_get_class_by_name(object_class_get_name(klass)); + if (!info) { + /* base class */ + return; + } + dc->desc = info->desc; k->device_id = info->device_id; k->revision = info->revision; k->subsystem_vendor_id = info->subsystem_vendor_id; k->subsystem_id = info->subsystem_id; } +static const TypeInfo eepro100_base_info = { + .name = TYPE_EEPRO100, + .parent = TYPE_PCI_DEVICE, + .abstract = true, + .class_init = eepro100_base_class_init, + .class_size = sizeof(EEPRO100Class), + .instance_size = sizeof(EEPRO100State), + .instance_init = eepro100_instance_init, + .interfaces = (InterfaceInfo[]) { + { INTERFACE_CONVENTIONAL_PCI_DEVICE }, + { }, + }, +}; + static void eepro100_register_types(void) { - size_t i; - for (i = 0; i < ARRAY_SIZE(e100_devices); i++) { - TypeInfo type_info = {}; - E100PCIDeviceInfo *info = &e100_devices[i]; - - type_info.name = info->name; - type_info.parent = TYPE_PCI_DEVICE; - type_info.class_init = eepro100_class_init; - type_info.instance_size = sizeof(EEPRO100State); - type_info.instance_init = eepro100_instance_init; - type_info.interfaces = (InterfaceInfo[]) { - { INTERFACE_CONVENTIONAL_PCI_DEVICE }, - { }, + type_register_static(&eepro100_base_info); + + for (size_t i = 0; i < ARRAY_SIZE(e100_devices); i++) { + TypeInfo type_info = { + .name = e100_devices[i].name, + .parent = TYPE_EEPRO100, }; type_register(&type_info);