From patchwork Mon Feb 13 10:10:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 653194 Delivered-To: patch@linaro.org Received: by 2002:adf:f90f:0:0:0:0:0 with SMTP id b15csp2325872wrr; Mon, 13 Feb 2023 02:12:13 -0800 (PST) X-Google-Smtp-Source: AK7set9WGFxHMakIDP/Jh6PypSFZ9SN/ScASxsM9Re8sioC3/rKOuJy3JIzVGHzu0kMzEfiwnvkI X-Received: by 2002:ac8:5856:0:b0:3b8:5199:f84a with SMTP id h22-20020ac85856000000b003b85199f84amr41921608qth.3.1676283133694; Mon, 13 Feb 2023 02:12:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676283133; cv=none; d=google.com; s=arc-20160816; b=h7DDo0YtUcVGRJ2eBQ0Hub3+CpA6rpTZB7/+0D+JQTJQ9zUZNV5ZW2FOCu7YxdLtJC 1YjuSCcXkkze1nkswQWzUvI73e7PV9mlfqOEM//K1iyZEuvdaquwosZIzxoN69XsPohP tLKcGea81245dArWODVYahFN7/ihZAkK16CF6VxeOUrVjDEpAYJB5NZOimW3ShHMyYef 6j6adQYNNAsSs5n0PjW4U/esFyb1/h0LW+3UNaFlfX/wWTcfHWmN8UULcukmFvXFr8O1 I09aYHoveWMx+Oi+fn8lD5uXA9ZL/HcjfcwR9oeKID4r67k+uA9Kms1HkpCE+7TaT/64 8X3g== 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=BZL+Bp8uavCHtbQrBbmxFnoeXirx45v+Dj9xYJzTDeg=; b=jQPkFHxuHRoxNqPl6Y8Pr9Rlmy84PoCSCuYTyYFU9o2J+CpFhD+Iio1pCYrxJDVuuS zxZoB97elKwDPJurEUx+PnVSR/uj2x9zdneuBv5c7chHDAashLQVZxUPnIMpw4TzuAzz XD83X7iQ2bA/VrEcnNAvign5ddyJPcY134Vpg08RE1v4tpBDMGutCntxQQJQiIr8bARs 6N2xvHvqZvKaMZ/uFkRvOAh/t5pLMrijz7JlBTSSDKHCE1QAvQ61Gr0Bssv2qMMAhqod odPc4975Bw0OkyD9x025UJQScoV3QeCEvF+WrNBzwmK9c3ZMtn2yiFgK5d0ANSkcl/hu 2Y4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mexQoVgw; 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=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id x20-20020a05622a001400b003ba35fdb9b4si9317560qtw.280.2023.02.13.02.12.13 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 13 Feb 2023 02:12:13 -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=@linaro.org header.s=google header.b=mexQoVgw; 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=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pRVnp-0005cW-K9; Mon, 13 Feb 2023 05:11:17 -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 1pRVnn-0005af-5g for qemu-devel@nongnu.org; Mon, 13 Feb 2023 05:11:16 -0500 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pRVnk-0003Uc-Ru for qemu-devel@nongnu.org; Mon, 13 Feb 2023 05:11:14 -0500 Received: by mail-wm1-x32e.google.com with SMTP id j29-20020a05600c1c1d00b003dc52fed235so8566769wms.1 for ; Mon, 13 Feb 2023 02:11:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; 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=BZL+Bp8uavCHtbQrBbmxFnoeXirx45v+Dj9xYJzTDeg=; b=mexQoVgwoSQuueyuYWZ4fjYZWsc91Qg1sjG5uSvGkq3+KUR12HiwOvKduID2Oe8lA7 okDW24Ysa2a06DouOdKw23Xmwi6LG8/LeYZKnjb/P0dkQjIQwyMCRt8UD3A8I6OCV9NB XUgkML/Qra3KpeuHfxHNxFW5MVI2s99hHVPWWDofyAVkxZuc5t28HykSPEIkSCeBiROQ 6ni6sW3D/amcNW49Fdzo8T1jiX1EdgECfXPbrNRp85jDtR42qE6p5Clm+9jWY9nUUsBq vGCMZOPRHe1Jr9pq3GiyHE9I63+zu3bezCeBTVgK+0N0bzTO19vYzBGq0jdQNgUyWRCM 5QQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=BZL+Bp8uavCHtbQrBbmxFnoeXirx45v+Dj9xYJzTDeg=; b=KII/UyX9/ceI6mOCsEzjVrtDxLnYMsjMTdRsUPgCyw9SEwRWE0Gx/+ytydDvkn1Nuu eSx+r47Xt71d/N1iYQty95cvweU24qpcFTWp52MJVQuYpnXK0/Axe8dbsr9fQP4Puh4U w4SHRhsCMNBMgE05xtm49cdyylcoX75tvTFkPN45l/5T37JsgNjFvDS7MkfnWygWq+3K 6lWeELSGE0yZhjoTsDC+EU75jOqU6WBHRkznrY3zRRCsZaLM8mevZGpzbMjSyWzTjiFW TGdu51jeWeMCx1EvGHIULu7f65yqxpI514juv6h7aEE0kPUXwDJBAJ+iFEdx7EfKFoN/ gsTw== X-Gm-Message-State: AO0yUKWNnERQzxRUNNxYtXa/nxN2SFVb/iuFA3ZChSB2z9Z+372shQls pV5w5BFY40bykvWrkeCHfr4Yuo3FNsOYluuJ X-Received: by 2002:a05:600c:43d3:b0:3da:1357:4ca2 with SMTP id f19-20020a05600c43d300b003da13574ca2mr20544534wmn.11.1676283070236; Mon, 13 Feb 2023 02:11:10 -0800 (PST) Received: from localhost.localdomain ([81.0.6.76]) by smtp.gmail.com with ESMTPSA id m18-20020a5d6252000000b002c3dc4131f5sm10248084wrv.18.2023.02.13.02.11.09 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 13 Feb 2023 02:11:09 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Eduardo Habkost Cc: Jason Wang , Thomas Huth , Igor Mammedov , Stefan Weil , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v2 4/7] hw/net/eepro100: Pass E100PCIDeviceInfo as class init data Date: Mon, 13 Feb 2023 11:10:45 +0100 Message-Id: <20230213101048.94519-5-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230213101048.94519-1-philmd@linaro.org> References: <20230213101048.94519-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=philmd@linaro.org; helo=mail-wm1-x32e.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, RCVD_IN_DNSWL_NONE=-0.0001, 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 QOM already provides the TypeInfo::class_data to set class-specific data. Use it instead of reinventing the wheel with eepro100_get_class_by_name(). This finishes the QDev conversion started 12 years ago in commit 40021f0888 ("pci: convert to QEMU Object Model"). Signed-off-by: Philippe Mathieu-Daudé --- hw/net/eepro100.c | 63 +++++++++++++++-------------------------------- 1 file changed, 20 insertions(+), 43 deletions(-) diff --git a/hw/net/eepro100.c b/hw/net/eepro100.c index 722fb55e4a..ab20558a18 100644 --- a/hw/net/eepro100.c +++ b/hw/net/eepro100.c @@ -242,6 +242,8 @@ struct EEPRO100Class { /*< private >*/ PCIDeviceClass parent_class; /*< public >*/ + + const E100PCIDeviceInfo *info; }; struct EEPRO100State { @@ -338,8 +340,6 @@ static const uint16_t eepro100_mdi_mask[] = { 0xffff, 0xffff, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, }; -static E100PCIDeviceInfo *eepro100_get_class(EEPRO100State *s); - /* Read a 16 bit control/status (CSR) register. */ static uint16_t e100_read_reg2(EEPRO100State *s, E100RegisterOffset addr) { @@ -489,8 +489,9 @@ static void eepro100_fcp_interrupt(EEPRO100State * s) static void e100_pci_reset(DeviceState *dev) { EEPRO100State *s = EEPRO100(dev); - E100PCIDeviceInfo *info = eepro100_get_class(s); - uint32_t device = s->device; + EEPRO100Class *ek = EEPRO100_GET_CLASS(s); + const E100PCIDeviceInfo *info = ek->info; + uint32_t device = info->device; uint8_t *pci_conf = s->dev.config; TRACE(OTHER, logout("%p\n", s)); @@ -1847,11 +1848,11 @@ static NetClientInfo net_eepro100_info = { static void e100_nic_realize(PCIDevice *pci_dev, Error **errp) { EEPRO100State *s = DO_UPCAST(EEPRO100State, dev, pci_dev); - E100PCIDeviceInfo *info = eepro100_get_class(s); + EEPRO100Class *ek = EEPRO100_GET_CLASS(s); TRACE(OTHER, logout("\n")); - s->device = info->device; + s->device = ek->info->device; /* Add 64 * 2 EEPROM. i82557 and i82558 support a 64 word EEPROM, * i82559 and later support 64 or 256 word EEPROM. */ @@ -2028,32 +2029,19 @@ static E100PCIDeviceInfo e100_devices[] = { } }; -static E100PCIDeviceInfo *eepro100_get_class_by_name(const char *typename) +static void eepro100_class_init(ObjectClass *klass, void *data) { - E100PCIDeviceInfo *info = NULL; - int i; + DeviceClass *dc = DEVICE_CLASS(klass); + PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); + EEPRO100Class *ek = EEPRO100_CLASS(klass); + const E100PCIDeviceInfo *info = data; - /* This is admittedly awkward but also temporary. QOM allows for - * parameterized typing and for subclassing both of which would suitable - * handle what's going on here. But class_data is already being used as - * a stop-gap hack to allow incremental qdev conversion so we cannot use it - * right now. Once we merge the final QOM series, we can come back here and - * do this in a much more elegant fashion. - */ - for (i = 0; i < ARRAY_SIZE(e100_devices); i++) { - if (strcmp(e100_devices[i].name, typename) == 0) { - info = &e100_devices[i]; - break; - } - } - assert(info != NULL); - - return info; -} - -static E100PCIDeviceInfo *eepro100_get_class(EEPRO100State *s) -{ - return eepro100_get_class_by_name(object_get_typename(OBJECT(s))); + 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; + ek->info = info; } static Property e100_properties[] = { @@ -2065,8 +2053,6 @@ static void eepro100_base_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); - E100PCIDeviceInfo *info; - set_bit(DEVICE_CATEGORY_NETWORK, dc->categories); device_class_set_props(dc, e100_properties); @@ -2076,17 +2062,6 @@ static void eepro100_base_class_init(ObjectClass *klass, void *data) 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 = { @@ -2111,6 +2086,8 @@ static void eepro100_register_types(void) TypeInfo type_info = { .name = e100_devices[i].name, .parent = TYPE_EEPRO100, + .class_init = eepro100_class_init, + .class_data = (void *)&e100_devices[i], }; type_register(&type_info);