From patchwork Wed Feb 15 17:43:49 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: 13142007 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F5A5C636D4 for ; Wed, 15 Feb 2023 17:44:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229561AbjBORoE (ORCPT ); Wed, 15 Feb 2023 12:44:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229640AbjBORoD (ORCPT ); Wed, 15 Feb 2023 12:44:03 -0500 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74D733A85E for ; Wed, 15 Feb 2023 09:44:02 -0800 (PST) Received: by mail-wr1-x436.google.com with SMTP id h16so19952563wrz.12 for ; Wed, 15 Feb 2023 09:44:02 -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=heFm5UqUphDjJpVI7Qv+ZKuvoLHrfHy/aAGqW6xSVEo=; b=w8OC715+aOMsi5OmhZ3/3915Wpmr4UaBPw/l9+UT6ZztgIO7uB/Cf1zJS51Erm39On M37AHEy0UPw6phGdnh8GuDzIiBqrVEvTrzrvJ31eX/0EcYLw39AR7GePTiNRgC4nVqZz Ng7qjUBYwlDO1Am7qbCjsaOJ9pYi5LOqB3rRz9qn0/72BR5PzypZRWcWZcjoZO4/wF8E j9ZrUM1nah63GXuse1P2N+h5+F39qljWEglEOYEu6L0t59OJH5G/7LW7XYJpLtNcLuTh R8N0vw6iS3jHRMrkxypkswbcI41eSWwNLObPQ+p+e8DMd1pwiuICQ+VyZ3jea78dtV0R Pp+A== 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=heFm5UqUphDjJpVI7Qv+ZKuvoLHrfHy/aAGqW6xSVEo=; b=FNh7DRMHEvLlrL7Ffqqe9UQ02hfoUtYyRChmoQvA6OoZnd7N/W/IFKdZ8BxTvBXCl5 mR94jK7jC9iv+KeP6AFD7avG9bhMqbyz6cEcpgAeAm6Wd23+geABS7EmlRZ/IMu+qGnb l5ZfbKukhAEVvKAIw9QPCbtsXyyhclT7HsUmEXtewvrkv89eMFk/VCIH6/SRz7aE1/xz QSIscMbUxDecAud1Un8G4B92gbmzoKVtWCPkhcLxMaIRHJiLeUeKZRX/m2nubCwj7ILi VgiJNQ/nsLbydMQzh4WdX1vG6t+QW3kgth86Xqj/S26mOq7g+zDPN+CUa1CNiAxztlGJ 17qg== X-Gm-Message-State: AO0yUKWtrWSK4ksw8Td+gkuTbdU1oumfygDN67w7lV4sxZ2Y0hT5+SOQ tsy8pXQbGqR2HDGQmsXUzV03Mg== X-Google-Smtp-Source: AK7set9QBzatX+iyzVMoe6/2+9iCbBIcnZ+Nl4ZdjUTu/yelgqHueAFwPIoLUgQyYvb7peWPRbfvPg== X-Received: by 2002:adf:ce02:0:b0:2c5:50f2:fcbc with SMTP id p2-20020adfce02000000b002c550f2fcbcmr2514670wrn.21.1676483040963; Wed, 15 Feb 2023 09:44:00 -0800 (PST) Received: from localhost.localdomain ([81.0.6.76]) by smtp.gmail.com with ESMTPSA id u13-20020a5d468d000000b002c54c92e125sm12669586wrq.46.2023.02.15.09.43.59 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 15 Feb 2023 09:44:00 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Marcelo Tosatti , Sergio Lopez , Paolo Bonzini , Richard Henderson , kvm@vger.kernel.org, "Michael S. Tsirkin" , Eduardo Habkost , qemu-ppc@nongnu.org, Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH 1/5] hw/timer/hpet: Include missing 'hw/qdev-properties.h' header Date: Wed, 15 Feb 2023 18:43:49 +0100 Message-Id: <20230215174353.37097-2-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230215174353.37097-1-philmd@linaro.org> References: <20230215174353.37097-1-philmd@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Avoid when refactoring unrelated headers: hw/timer/hpet.c:776:39: error: array has incomplete element type 'Property' (aka 'struct Property') static Property hpet_device_properties[] = { ^ hw/timer/hpet.c:777:5: error: implicit declaration of function 'DEFINE_PROP_UINT8' is invalid in C99 [-Werror,-Wimplicit-function-declaration] DEFINE_PROP_UINT8("timers", HPETState, num_timers, HPET_MIN_TIMERS), ^ Signed-off-by: Philippe Mathieu-Daudé Acked-by: Richard Henderson --- hw/timer/hpet.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/timer/hpet.c b/hw/timer/hpet.c index 9520471be2..214d6a0501 100644 --- a/hw/timer/hpet.c +++ b/hw/timer/hpet.c @@ -30,6 +30,7 @@ #include "qapi/error.h" #include "qemu/error-report.h" #include "qemu/timer.h" +#include "hw/qdev-properties.h" #include "hw/timer/hpet.h" #include "hw/sysbus.h" #include "hw/rtc/mc146818rtc.h" From patchwork Wed Feb 15 17:43:50 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: 13142008 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE0AEC636D4 for ; Wed, 15 Feb 2023 17:44:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229889AbjBORoL (ORCPT ); Wed, 15 Feb 2023 12:44:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229815AbjBORoK (ORCPT ); Wed, 15 Feb 2023 12:44:10 -0500 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 846D83C297 for ; Wed, 15 Feb 2023 09:44:08 -0800 (PST) Received: by mail-wm1-x32e.google.com with SMTP id hg24-20020a05600c539800b003e1f5f2a29cso2154806wmb.4 for ; Wed, 15 Feb 2023 09:44:08 -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=4xWeqx5C/Xjzaw1eQA4/F7uZTIcR+NwJk/0kJcEYTAY=; b=IUZDYPUxoTz64E5CsADb59dPUZIMb31X/tgySvrGmDuEdvmFEsEv6OOqEoawQhASpG Y0xqT/osOWB55zfb8IVlEB3g1aB1GWTupU2lQyzgeNtSNKaamuxhw3iYy0SkzEe+R46g LprJCLeEklZ/81t+bixRziYVDcy8+TFCsuLS68X/58n36lUeUl4xu/x2G4XKQUl8fqVY yNKqf6iZbq4hyHOBsdePvt3k/ANFx5oTSnBcPRL/EC69r53YA1fJkxV7+LKweyPxFsGg WeiA/cxycScza3jopc7RZxjZuDuqUm4iRm95y714NBpoKGuOhQM+TjlWakSBXG9WHd9x P6Nw== 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=4xWeqx5C/Xjzaw1eQA4/F7uZTIcR+NwJk/0kJcEYTAY=; b=QQY7CnW5TjQfmcTZtPP1lfZmP3Ldx7BaxuFha6MB//Uf97peWP/PdDWSjpw4pgXkXw UxjQEbBwmDjxaiYSBsgeetKOsCnRx0mXPSZGU3kaRm7MvNDtQfI1l2iBZ66mpSC9cwc0 VI/J/gTx1vyaJ7ct+ric2whpKael+3lkR3Xw9DvlIt9YrJqgOHcnV9H3DPa2TMpp3sfE y14D0GKQxzH8Hi4+y42TvPbbYSn+TZS0aWvNM2UT4LZH6avYxzPDsZ3IZE2yMfOR8eKZ u13IMWVBy6klvMV2KLy3PgdniV1zsZAlS1enYP2jyH+8YCC1AUohC33oOph9QKXk9f+i ca9Q== X-Gm-Message-State: AO0yUKX0sNncl/F6vD+iTESoyIPOAjZ5muD6pv+KqPyAtv8UAC4VTUhT vGdJ3GuNu/Qs5YQvJRa7d5YisQ== X-Google-Smtp-Source: AK7set/7lvshecTiyDKvaOH/yA+UWKADLvy67Z5P7A4WG491XE/W3jOetrh7ZzUU8Z/Vc4P2Um29/A== X-Received: by 2002:a05:600c:46c6:b0:3e0:14a:697a with SMTP id q6-20020a05600c46c600b003e0014a697amr2921374wmo.6.1676483046880; Wed, 15 Feb 2023 09:44:06 -0800 (PST) Received: from localhost.localdomain ([81.0.6.76]) by smtp.gmail.com with ESMTPSA id p17-20020a05600c469100b003dd1b00bd9asm3004147wmo.32.2023.02.15.09.44.05 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 15 Feb 2023 09:44:06 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Marcelo Tosatti , Sergio Lopez , Paolo Bonzini , Richard Henderson , kvm@vger.kernel.org, "Michael S. Tsirkin" , Eduardo Habkost , qemu-ppc@nongnu.org, Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH 2/5] hw/timer/i8254: Factor i8254_pit_create() out and document Date: Wed, 15 Feb 2023 18:43:50 +0100 Message-Id: <20230215174353.37097-3-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230215174353.37097-1-philmd@linaro.org> References: <20230215174353.37097-1-philmd@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson --- hw/timer/i8254.c | 16 ++++++++++++++++ include/hw/timer/i8254.h | 24 +++++++++++++----------- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/hw/timer/i8254.c b/hw/timer/i8254.c index c8388ea432..9b6932ab08 100644 --- a/hw/timer/i8254.c +++ b/hw/timer/i8254.c @@ -26,9 +26,11 @@ #include "hw/irq.h" #include "qemu/module.h" #include "qemu/timer.h" +#include "hw/qdev-properties.h" #include "hw/timer/i8254.h" #include "hw/timer/i8254_internal.h" #include "qom/object.h" +#include "qapi/error.h" //#define DEBUG_PIT @@ -47,6 +49,20 @@ struct PITClass { DeviceRealize parent_realize; }; +ISADevice *i8254_pit_create(ISABus *bus, int iobase, qemu_irq irq_in) +{ + DeviceState *dev; + ISADevice *d; + + d = isa_new(TYPE_I8254); + dev = DEVICE(d); + qdev_prop_set_uint32(dev, "iobase", iobase); + isa_realize_and_unref(d, bus, &error_fatal); + qdev_connect_gpio_out(dev, 0, irq_in); + + return d; +} + static void pit_irq_timer_update(PITChannelState *s, int64_t current_time); static int pit_get_count(PITChannelState *s) diff --git a/include/hw/timer/i8254.h b/include/hw/timer/i8254.h index 8402caad30..a0843cae07 100644 --- a/include/hw/timer/i8254.h +++ b/include/hw/timer/i8254.h @@ -45,21 +45,23 @@ OBJECT_DECLARE_TYPE(PITCommonState, PITCommonClass, PIT_COMMON) #define TYPE_I8254 "isa-pit" #define TYPE_KVM_I8254 "kvm-pit" +/** + * Create and realize a I8254 PIT device on the heap. + * @bus: the #ISABus to put it on. + * @iobase: the base I/O port. + * @irq_in: qemu_irq to connect the PIT output IRQ to. + * + * Create the device state structure, initialize it, put it on the + * specified ISA @bus, and drop the reference to it (the device is realized). + */ +ISADevice *i8254_pit_create(ISABus *bus, int iobase, qemu_irq irq_in); + static inline ISADevice *i8254_pit_init(ISABus *bus, int base, int isa_irq, qemu_irq alt_irq) { - DeviceState *dev; - ISADevice *d; - - d = isa_new(TYPE_I8254); - dev = DEVICE(d); - qdev_prop_set_uint32(dev, "iobase", base); - isa_realize_and_unref(d, bus, &error_fatal); - qdev_connect_gpio_out(dev, 0, - isa_irq >= 0 ? isa_bus_get_irq(bus, isa_irq) + return i8254_pit_create(bus, base, isa_irq >= 0 + ? isa_bus_get_irq(bus, isa_irq) : alt_irq); - - return d; } static inline ISADevice *kvm_pit_init(ISABus *bus, int base) From patchwork Wed Feb 15 17:43:51 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: 13142009 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2AE5BC636CC for ; Wed, 15 Feb 2023 17:44:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229903AbjBORoP (ORCPT ); Wed, 15 Feb 2023 12:44:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229620AbjBORoO (ORCPT ); Wed, 15 Feb 2023 12:44:14 -0500 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7AB6237F15 for ; Wed, 15 Feb 2023 09:44:13 -0800 (PST) Received: by mail-wr1-x436.google.com with SMTP id l2so3343035wry.0 for ; Wed, 15 Feb 2023 09:44:13 -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=vz35UX4luoMUaqbzTcDDIbvcjgeBkxbh135cUjhEHMo=; b=yowuVGL7oMXH61gQZvS6cQqkgZm8BocUdDiMLffKX5wVEPHygVvBzk8k0YGLyjZ0NI bQlOVBLDdtlQRPbUP5QQAT6ldo1lLIHrMbFA3uT5qVxOGCeLADLn/cxXLDqql2CVYdmJ FqVGuQLxjAbAKvb4wAKxWcTCv31Ivp+ASPsR3Z0HZTzUuF+OjeJbg66Gy79h8HSaYVKx wfQd/3YIxgXU6DMsp08+5QEJt5IWOgJLjS8+dFXzRMLwidPwif6Ax+A3QSC+6r8ejNxP RpoklAoNBnE4Lq3buUfJgPxJ9K4fB9XUfaEY9jqjb3lAo06ZFQ9gtaOvd3Qk/ryDqYdw 5Fow== 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=vz35UX4luoMUaqbzTcDDIbvcjgeBkxbh135cUjhEHMo=; b=NG1p1y4NTKzKAGMEakwdC3InE1oHD2jX+4e6VW8jTcr7GRgfg7ZoLuh1f+5LovtUFj JBfs5UcptilMDRfrg3P2qvoosCtfjDYj8FIjESkd9Idd/dvv7ik6hnEuWKuC7EFRNnwH gT6jg1T51NHF+5D9jHAIknZw2LMY5zsCBIzxnS8w9UlMePb022sMY7809IiulRXbWNtJ lWLOx3jVbNHLvUz1Ym3D39tzLaNVfxq7+HV7ufhbNENng2/JKyKzqCAxkYV7px0VSDoq fw31EmzrqKytNN6j6xaNS5a7loy2ClY6t4Yti3Ca/n6Qsah7s5SscFi5seTnzTNQqNpQ 6etQ== X-Gm-Message-State: AO0yUKV1zindZ4zXu5T0C4Mf5vqkbPILqYFLfC/iEs/QKTGNis+ngTV1 QOHzYsQUwY8aibqPQLRHhAduVbW3f39K+pk2 X-Google-Smtp-Source: AK7set/xn5Ccsu5wveg0hA8LklsQ+9ymklxMsebESI86/qV1Z+xqiOKNeIuLLMvRjwl0dPZDKqPv8Q== X-Received: by 2002:a5d:4b06:0:b0:2c5:4b93:ee44 with SMTP id v6-20020a5d4b06000000b002c54b93ee44mr2256030wrq.60.1676483052008; Wed, 15 Feb 2023 09:44:12 -0800 (PST) Received: from localhost.localdomain ([81.0.6.76]) by smtp.gmail.com with ESMTPSA id s9-20020a5d4ec9000000b002c567881dbcsm4363915wrv.48.2023.02.15.09.44.10 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 15 Feb 2023 09:44:11 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Marcelo Tosatti , Sergio Lopez , Paolo Bonzini , Richard Henderson , kvm@vger.kernel.org, "Michael S. Tsirkin" , Eduardo Habkost , qemu-ppc@nongnu.org, Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH 3/5] hw/i386/pc: Un-inline i8254_pit_init() Date: Wed, 15 Feb 2023 18:43:51 +0100 Message-Id: <20230215174353.37097-4-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230215174353.37097-1-philmd@linaro.org> References: <20230215174353.37097-1-philmd@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org pc_basic_device_init() is the single caller of i8254_pit_init() with a non-NULL 'alt_irq' argument. Open-code i8254_pit_init() by direclty calling i8254_pit_create(). To confirm all other callers pass a NULL 'alt_irq', add an assertion in i8254_pit_init(). Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson --- hw/i386/pc.c | 10 +++++----- include/hw/timer/i8254.h | 5 ++--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 79297a6ecd..fe95f6e9f2 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1258,8 +1258,7 @@ void pc_basic_device_init(struct PCMachineState *pcms, { int i; DeviceState *hpet = NULL; - int pit_isa_irq = 0; - qemu_irq pit_alt_irq = NULL; + qemu_irq pit_irq; qemu_irq rtc_irq = NULL; ISADevice *pit = NULL; MemoryRegion *ioport80_io = g_new(MemoryRegion, 1); @@ -1301,9 +1300,10 @@ void pc_basic_device_init(struct PCMachineState *pcms, for (i = 0; i < GSI_NUM_PINS; i++) { sysbus_connect_irq(SYS_BUS_DEVICE(hpet), i, gsi[i]); } - pit_isa_irq = -1; - pit_alt_irq = qdev_get_gpio_in(hpet, HPET_LEGACY_PIT_INT); + pit_irq = qdev_get_gpio_in(hpet, HPET_LEGACY_PIT_INT); rtc_irq = qdev_get_gpio_in(hpet, HPET_LEGACY_RTC_INT); + } else { + pit_irq = isa_bus_get_irq(isa_bus, 0); } *rtc_state = mc146818_rtc_init(isa_bus, 2000, rtc_irq); @@ -1314,7 +1314,7 @@ void pc_basic_device_init(struct PCMachineState *pcms, if (kvm_pit_in_kernel()) { pit = kvm_pit_init(isa_bus, 0x40); } else { - pit = i8254_pit_init(isa_bus, 0x40, pit_isa_irq, pit_alt_irq); + pit = i8254_pit_create(isa_bus, 0x40, pit_irq); } if (hpet) { /* connect PIT to output control line of the HPET */ diff --git a/include/hw/timer/i8254.h b/include/hw/timer/i8254.h index a0843cae07..0d837f3f41 100644 --- a/include/hw/timer/i8254.h +++ b/include/hw/timer/i8254.h @@ -59,9 +59,8 @@ ISADevice *i8254_pit_create(ISABus *bus, int iobase, qemu_irq irq_in); static inline ISADevice *i8254_pit_init(ISABus *bus, int base, int isa_irq, qemu_irq alt_irq) { - return i8254_pit_create(bus, base, isa_irq >= 0 - ? isa_bus_get_irq(bus, isa_irq) - : alt_irq); + assert(isa_irq == 0 && alt_irq == NULL); + return i8254_pit_create(bus, base, isa_bus_get_irq(bus, 0)); } static inline ISADevice *kvm_pit_init(ISABus *bus, int base) From patchwork Wed Feb 15 17:43:52 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: 13142024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 60B74C636CC for ; Wed, 15 Feb 2023 17:44:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229909AbjBORoX (ORCPT ); Wed, 15 Feb 2023 12:44:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229897AbjBORoW (ORCPT ); Wed, 15 Feb 2023 12:44:22 -0500 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E14B3C294 for ; Wed, 15 Feb 2023 09:44:19 -0800 (PST) Received: by mail-wm1-x32d.google.com with SMTP id az4-20020a05600c600400b003dff767a1f1so2132875wmb.2 for ; Wed, 15 Feb 2023 09:44:19 -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=zRiYpacq2buGtsbzdt2U4edvI0iODkUmTaRGtL8ovas=; b=jDsZJRQLERfeLQ490jpStffMhiCHc+0Rwb7tmTYaJq0Kw6f+YIzHKeqnuJALZNPbAJ URQiKJ1Jgt4qncCRdljh3VUryyaUxWLFWFTt21xdoaz80sQlE1IArzmcK6mpuxHwqhDb ZOBcfs8MLY0rzQPRd9oHW2MVOm10HmIgfQ5tVRi9Qm1nHOWniVqlMJzjPEfq0GqVFEiD XmB7L3HDZoWo46KvkoyBicrBZ+xPsjAnYdi3OQiKxuvZKTlI4+3sZp+MN+LjvG98sSpB iuzEddUN4npG0E5L37O6WRfVOt3789FjxMaTxqx4YekzlaHL5ebxC6mC/eHo6c0ENmVn BH3g== 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=zRiYpacq2buGtsbzdt2U4edvI0iODkUmTaRGtL8ovas=; b=6plklb3Mlu48oOnj/rj/kTEt2sHH7Lt/VOHpjw6u2QSmFG9ITIPBvmqQMuo3Gtawn6 wvBhgavqtYCHkhxyb8WLD/P6Tp5M/uR1j0mGdtZS50RrpXui0fyt8bCussUPP0DPOfwZ ++lx5z5LOd0D3CGH42k3UvD8lb8ObbblbHTcpY/TRKS+ly/9nrW5e6/RtPIgt8X1Zmi8 n1Kujmb2ulfrB4SUpa59hI7yVoUGZIfiU/6F+kaVQM8qlJDPsPPugac+9Yme+aOnvH39 XewN2qrtcd5toA2+HFNu+JW00XgNvWC2nfj1MPjUsctZV5S2oQ//QzxRSa/XfEBIHmCu jM7w== X-Gm-Message-State: AO0yUKXXrNI5lXLyLgN7xJISOzDPg9EEtNenrFAF2Rz4J9Qa4smc5pnk Rg8dst7jwW4JrhQYkTD5Z6gsXQ== X-Google-Smtp-Source: AK7set8jnVvjneWIxfxH9Bn5U/pjoZeBdZs+qd4MTX4M47EdU+EutDCEiNwQ6TNvB3qvIVBBMpJe7w== X-Received: by 2002:a05:600c:318a:b0:3db:5f1:53a5 with SMTP id s10-20020a05600c318a00b003db05f153a5mr2757152wmp.20.1676483058010; Wed, 15 Feb 2023 09:44:18 -0800 (PST) Received: from localhost.localdomain ([81.0.6.76]) by smtp.gmail.com with ESMTPSA id 21-20020a05600c021500b003e209186c07sm414427wmi.19.2023.02.15.09.44.16 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 15 Feb 2023 09:44:17 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Marcelo Tosatti , Sergio Lopez , Paolo Bonzini , Richard Henderson , kvm@vger.kernel.org, "Michael S. Tsirkin" , Eduardo Habkost , qemu-ppc@nongnu.org, Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Herv?= =?utf-8?q?=C3=A9_Poussineau?= , Aurelien Jarno , Huacai Chen , Jiaxun Yang , Aleksandar Rikalo Subject: [PATCH 4/5] hw/timer/i8254: Really inline i8254_pit_init() Date: Wed, 15 Feb 2023 18:43:52 +0100 Message-Id: <20230215174353.37097-5-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230215174353.37097-1-philmd@linaro.org> References: <20230215174353.37097-1-philmd@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org In-line the one-line i8254_pit_create() call. Signed-off-by: Philippe Mathieu-Daudé --- hw/i386/microvm.c | 2 +- hw/isa/i82378.c | 2 +- hw/isa/piix4.c | 4 ++-- hw/isa/vt82c686.c | 2 +- hw/mips/jazz.c | 2 +- include/hw/timer/i8254.h | 7 ------- 6 files changed, 6 insertions(+), 13 deletions(-) diff --git a/hw/i386/microvm.c b/hw/i386/microvm.c index 29f30dd6d3..9204bb4ff2 100644 --- a/hw/i386/microvm.c +++ b/hw/i386/microvm.c @@ -261,7 +261,7 @@ static void microvm_devices_init(MicrovmMachineState *mms) if (kvm_pit_in_kernel()) { kvm_pit_init(isa_bus, 0x40); } else { - i8254_pit_init(isa_bus, 0x40, 0, NULL); + i8254_pit_create(isa_bus, 0x40, isa_bus_get_irq(isa_bus, 0)); } } diff --git a/hw/isa/i82378.c b/hw/isa/i82378.c index e3322e03bf..f75f5a23ba 100644 --- a/hw/isa/i82378.c +++ b/hw/isa/i82378.c @@ -99,7 +99,7 @@ static void i82378_realize(PCIDevice *pci, Error **errp) isa_bus_irqs(isabus, s->i8259); /* 1 82C54 (pit) */ - pit = i8254_pit_init(isabus, 0x40, 0, NULL); + pit = i8254_pit_create(isabus, 0x40, isa_bus_get_irq(isabus, 0)); /* speaker */ pcspk_init(isa_new(TYPE_PC_SPEAKER), isabus, pit); diff --git a/hw/isa/piix4.c b/hw/isa/piix4.c index 94e5dc7825..8ff118445f 100644 --- a/hw/isa/piix4.c +++ b/hw/isa/piix4.c @@ -214,8 +214,8 @@ static void piix4_realize(PCIDevice *dev, Error **errp) /* initialize ISA irqs */ isa_bus_irqs(isa_bus, s->isa); - /* initialize pit */ - i8254_pit_init(isa_bus, 0x40, 0, NULL); + /* PIT */ + i8254_pit_create(isa_bus, 0x40, isa_bus_get_irq(isa_bus, 0)); /* DMA */ i8257_dma_init(isa_bus, 0); diff --git a/hw/isa/vt82c686.c b/hw/isa/vt82c686.c index 3f9bd0c04d..297bcda420 100644 --- a/hw/isa/vt82c686.c +++ b/hw/isa/vt82c686.c @@ -624,7 +624,7 @@ static void via_isa_realize(PCIDevice *d, Error **errp) s->isa_irqs = i8259_init(isa_bus, *isa_irq); isa_bus_irqs(isa_bus, s->isa_irqs); - i8254_pit_init(isa_bus, 0x40, 0, NULL); + i8254_pit_create(isa_bus, 0x40, isa_bus_get_irq(isa_bus, 0)); i8257_dma_init(isa_bus, 0); /* RTC */ diff --git a/hw/mips/jazz.c b/hw/mips/jazz.c index 6aefe9a61b..856acfe2a7 100644 --- a/hw/mips/jazz.c +++ b/hw/mips/jazz.c @@ -251,7 +251,7 @@ static void mips_jazz_init(MachineState *machine, i8259 = i8259_init(isa_bus, env->irq[4]); isa_bus_irqs(isa_bus, i8259); i8257_dma_init(isa_bus, 0); - pit = i8254_pit_init(isa_bus, 0x40, 0, NULL); + pit = i8254_pit_create(isa_bus, 0x40, isa_bus_get_irq(isa_bus, 0)); pcspk_init(isa_new(TYPE_PC_SPEAKER), isa_bus, pit); /* Video card */ diff --git a/include/hw/timer/i8254.h b/include/hw/timer/i8254.h index 0d837f3f41..aa48c44d39 100644 --- a/include/hw/timer/i8254.h +++ b/include/hw/timer/i8254.h @@ -56,13 +56,6 @@ OBJECT_DECLARE_TYPE(PITCommonState, PITCommonClass, PIT_COMMON) */ ISADevice *i8254_pit_create(ISABus *bus, int iobase, qemu_irq irq_in); -static inline ISADevice *i8254_pit_init(ISABus *bus, int base, int isa_irq, - qemu_irq alt_irq) -{ - assert(isa_irq == 0 && alt_irq == NULL); - return i8254_pit_create(bus, base, isa_bus_get_irq(bus, 0)); -} - static inline ISADevice *kvm_pit_init(ISABus *bus, int base) { DeviceState *dev; From patchwork Wed Feb 15 17:43:53 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: 13142025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 43C42C636CC for ; Wed, 15 Feb 2023 17:44:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229914AbjBORoa (ORCPT ); Wed, 15 Feb 2023 12:44:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229924AbjBORo3 (ORCPT ); Wed, 15 Feb 2023 12:44:29 -0500 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DE9B3C2B9 for ; Wed, 15 Feb 2023 09:44:25 -0800 (PST) Received: by mail-wr1-x42b.google.com with SMTP id bk16so19956131wrb.11 for ; Wed, 15 Feb 2023 09:44:25 -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=IWNxqquWLNXTTocLvUxsoGH+JCmIcd1Q1kcJ09WY8/Y=; b=sFTIywSyT5+Gm4JtVTiPy8pocwC8NLizi+OnGXa0F8gxS+pw88AJbAHk8HZ7sMb/FI 96175WS+payrqFe8IfpT4VJY+oPZRbvrGyBnOF8Uqmsn6iQhZzPnmM8IIAY9peP0Rvb3 KmGaMCMDxADFPMYBVs414xcyLurQUmdISGtc2hXzlzGGjaWuKPBxBCbVpt1qA1Ey6/7d GrXiarGGH9FGWJ+Z/diMir38jMpVosC8m/8Bc1owB+ohPRD7/4E6z6f8dQ3O7wGgPp7J wmJ2lUOCWMb98RpgxN+xQiLQl2T/CmNOhPQrbsRtwqGuL+pmikV9vmZVVYh/tKAU8uc+ u1Vg== 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=IWNxqquWLNXTTocLvUxsoGH+JCmIcd1Q1kcJ09WY8/Y=; b=oZD/L+RcD3Grk9uBozkXCmlqB8bg0iEgLdRjftd00EYN7mxxOEYLZ1mGN7+O3fT/bn L/CmvFNtEmAedNOqnPP4UMDUslTbMfcXvVLkLXYZ0aAAjq7GHbv8ngfX60I/NOELGCz7 o/D6aBMNp8d53lJOoYuC9oMX2ALxkJwvMWArywXFp+/FedvnhPDJBMVtw9krmyrv0R72 z8ENoKUZZp+UkudNJniw8bSOT6NJRUpAsYGWZ3GYr/BqKVsiA5Zr9r+hXVpRCbTCEgS8 rkr5DWRD/4iCFq8wHidNtQab4fPi+RV+SSncbFRJz63/nVt7T5e59Du5ncBtry9vxDUi jg3w== X-Gm-Message-State: AO0yUKWdRqnMKSzx+K9JlvmEpFVJTZhRWPhxqZLkwPh0RvFBjpsbRld4 cN8TMjcSE/920uanTqAW6m/BoA== X-Google-Smtp-Source: AK7set/dBoQ8bwhtu/KAQyOrlfuHEmIHSM2Ph1ygizmQiCsBZ4rAct1OR5ti0L9UZGbe4LmrE3eiEQ== X-Received: by 2002:a05:6000:3c7:b0:2c5:4c07:9593 with SMTP id b7-20020a05600003c700b002c54c079593mr135627wrg.16.1676483063919; Wed, 15 Feb 2023 09:44:23 -0800 (PST) Received: from localhost.localdomain ([81.0.6.76]) by smtp.gmail.com with ESMTPSA id f15-20020adff98f000000b002c5583ab017sm8580863wrr.15.2023.02.15.09.44.22 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 15 Feb 2023 09:44:23 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Marcelo Tosatti , Sergio Lopez , Paolo Bonzini , Richard Henderson , kvm@vger.kernel.org, "Michael S. Tsirkin" , Eduardo Habkost , qemu-ppc@nongnu.org, Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH 5/5] hw/i386/kvm: Factor i8254_pit_create_try_kvm() out Date: Wed, 15 Feb 2023 18:43:53 +0100 Message-Id: <20230215174353.37097-6-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230215174353.37097-1-philmd@linaro.org> References: <20230215174353.37097-1-philmd@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Factor a new i8254_pit_create_try_kvm() helper out of the following patter: if (kvm_pit_in_kernel()) { kvm_pit_init(...); } else } i8254_pit_create(...); } (adding a stub for non-KVM builds). Since kvm_pit_init() is only used once, un-inline it and remove the now unused headers from "hw/timer/i8254.h". Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson --- hw/i386/kvm/i8254.c | 18 ++++++++++++++++++ hw/i386/microvm.c | 6 +----- hw/i386/pc.c | 7 ++----- include/hw/timer/i8254.h | 22 ++++++---------------- target/i386/kvm/kvm-stub.c | 6 ++++++ 5 files changed, 33 insertions(+), 26 deletions(-) diff --git a/hw/i386/kvm/i8254.c b/hw/i386/kvm/i8254.c index 191a26fa57..9520c98c76 100644 --- a/hw/i386/kvm/i8254.c +++ b/hw/i386/kvm/i8254.c @@ -35,6 +35,7 @@ #include "hw/qdev-properties-system.h" #include "sysemu/kvm.h" #include "qom/object.h" +#include "kvm/kvm_i386.h" #define KVM_PIT_REINJECT_BIT 0 @@ -59,6 +60,23 @@ struct KVMPITClass { DeviceRealize parent_realize; }; +ISADevice *i8254_pit_create_try_kvm(ISABus *bus, int iobase, qemu_irq irq_in) +{ + DeviceState *dev; + ISADevice *d; + + if (!kvm_pit_in_kernel()) { + return i8254_pit_create(bus, iobase, irq_in); + } + + d = isa_new(TYPE_KVM_I8254); + dev = DEVICE(d); + qdev_prop_set_uint32(dev, "iobase", iobase); + isa_realize_and_unref(d, bus, &error_fatal); + + return d; +} + static void kvm_pit_update_clock_offset(KVMPITState *s) { int64_t offset, clock_offset; diff --git a/hw/i386/microvm.c b/hw/i386/microvm.c index 9204bb4ff2..d93dc8a263 100644 --- a/hw/i386/microvm.c +++ b/hw/i386/microvm.c @@ -258,11 +258,7 @@ static void microvm_devices_init(MicrovmMachineState *mms) } if (x86ms->pit == ON_OFF_AUTO_ON || x86ms->pit == ON_OFF_AUTO_AUTO) { - if (kvm_pit_in_kernel()) { - kvm_pit_init(isa_bus, 0x40); - } else { - i8254_pit_create(isa_bus, 0x40, isa_bus_get_irq(isa_bus, 0)); - } + i8254_pit_create_try_kvm(isa_bus, 0x40, isa_bus_get_irq(isa_bus, 0)); } if (mms->rtc == ON_OFF_AUTO_ON || diff --git a/hw/i386/pc.c b/hw/i386/pc.c index fe95f6e9f2..7d9f57c695 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1311,11 +1311,8 @@ void pc_basic_device_init(struct PCMachineState *pcms, if (!xen_enabled() && (x86ms->pit == ON_OFF_AUTO_AUTO || x86ms->pit == ON_OFF_AUTO_ON)) { - if (kvm_pit_in_kernel()) { - pit = kvm_pit_init(isa_bus, 0x40); - } else { - pit = i8254_pit_create(isa_bus, 0x40, pit_irq); - } + pit = i8254_pit_create_try_kvm(isa_bus, 0x40, pit_irq); + if (hpet) { /* connect PIT to output control line of the HPET */ qdev_connect_gpio_out(hpet, 0, qdev_get_gpio_in(DEVICE(pit), 0)); diff --git a/include/hw/timer/i8254.h b/include/hw/timer/i8254.h index aa48c44d39..9fb18c4ff4 100644 --- a/include/hw/timer/i8254.h +++ b/include/hw/timer/i8254.h @@ -25,9 +25,6 @@ #ifndef HW_I8254_H #define HW_I8254_H -#include "hw/qdev-properties.h" -#include "hw/isa/isa.h" -#include "qapi/error.h" #include "qom/object.h" #define PIT_FREQ 1193182 @@ -55,19 +52,12 @@ OBJECT_DECLARE_TYPE(PITCommonState, PITCommonClass, PIT_COMMON) * specified ISA @bus, and drop the reference to it (the device is realized). */ ISADevice *i8254_pit_create(ISABus *bus, int iobase, qemu_irq irq_in); - -static inline ISADevice *kvm_pit_init(ISABus *bus, int base) -{ - DeviceState *dev; - ISADevice *d; - - d = isa_new(TYPE_KVM_I8254); - dev = DEVICE(d); - qdev_prop_set_uint32(dev, "iobase", base); - isa_realize_and_unref(d, bus, &error_fatal); - - return d; -} +/** + * Try to create and realize a in-kernel I8254 PIT device on the heap. + * If KVM is not available or doesn't have in-kernel PIT support, a + * emulated PIT is used. See i8254_pit_create. + */ +ISADevice *i8254_pit_create_try_kvm(ISABus *bus, int iobase, qemu_irq irq_in); void pit_set_gate(ISADevice *dev, int channel, int val); void pit_get_channel_info(ISADevice *dev, int channel, PITChannelInfo *info); diff --git a/target/i386/kvm/kvm-stub.c b/target/i386/kvm/kvm-stub.c index e052f1c7b0..396da89f55 100644 --- a/target/i386/kvm/kvm-stub.c +++ b/target/i386/kvm/kvm-stub.c @@ -10,6 +10,7 @@ * */ #include "qemu/osdep.h" +#include "hw/timer/i8254.h" #include "cpu.h" #include "kvm_i386.h" @@ -49,3 +50,8 @@ void kvm_set_max_apic_id(uint32_t max_apic_id) { return; } + +ISADevice *i8254_pit_create_try_kvm(ISABus *bus, int iobase, qemu_irq irq_in) +{ + return i8254_pit_create(bus, iobase, irq_in); +}