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: 1743004 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=IUZDYPUx; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PH57z0QXFz23y8 for ; Thu, 16 Feb 2023 04:45:17 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSLpD-0000en-JQ; Wed, 15 Feb 2023 12:44:11 -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 1pSLpC-0000eD-9t for qemu-devel@nongnu.org; Wed, 15 Feb 2023 12:44:10 -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 1pSLpA-0008DY-OX for qemu-devel@nongnu.org; Wed, 15 Feb 2023 12:44:10 -0500 Received: by mail-wm1-x32e.google.com with SMTP id k8-20020a05600c1c8800b003dc57ea0dfeso2223587wms.0 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=CdnMLCWh5EmtHRFeBmN1ENa9NADNcyvvaHOeUTk6Yeq22OpZi595+YgaetbMW0/Gd1 UMulCmp3ps7YIgR2oKa4ndC9jamfeXp2xLL0pISVIlyUpE0CuShoISrtL5n89vgWA7RI PNDkzR1yjF386owBgbHMwx+VeIQPR1gDjYgmpopkpwWMpe27960jYW2jP41D/WvhqGNA 7Ip+nL/8z/PHY1YrqmNx5WOUdMBKf2Fhz3VyqpGCA0nhr13FbE8ig3fJ/l9JPdSaUTyE mqQCUH5izw/4v6qCeVHLngBVsd2lHLolz7/qngHoqBkHIKj/JZ3eIVwoi9QKN+Rg2Jq0 dNww== X-Gm-Message-State: AO0yUKUkf0t3d7smhvM1LDY9ZBVMyvplCPawy/rl44dP3ubYRdgrdKSZ P4x4g0cY1tzRwII22avKmN06j0jYVPDRaQSh 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 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=unavailable 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.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)