From nobody Thu Nov 14 17:26:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1708445299; cv=none; d=zohomail.com; s=zohoarc; b=QBPg9lwn1KTy6gLrBlwTCI2BweHrjpDEG2MBHJZxUsZgQqvUkZDw/+z74Kgux0cXXNNz19rX2neZjKasouvBNvY/VusoOOjequN6mBnYywGqvo30p4eX9OE0O64+rKHxc/dpJ88M7mSUk5eNrJ8nR2WiUnWWp2JNbbqntZ+n1gc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708445299; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=fbwlnbkTELmw0yuCS8YQeiT81oI84UQospsJeFLv0YU=; b=ezNjv1SRneYlgR5OZP3jze1szoB7HiqXA9XCa3HGuENj/S4nNRAnM6XZUEJcz9iyya1mlgZFtyq/rSmMUV7fk/RVEodjiO3n9erL9C+kgG3Xz+Z/BsgxSfPzwRq4YU/w9si0SjVz/1SXr1tPMqPvhtckodmyipDkX/ddNNpZk0E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1708445299083767.7748717902455; Tue, 20 Feb 2024 08:08:19 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rcSdb-00025r-Ik; Tue, 20 Feb 2024 11:06:31 -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 1rcSda-00024E-2B for qemu-devel@nongnu.org; Tue, 20 Feb 2024 11:06:30 -0500 Received: from mail-lj1-x22d.google.com ([2a00:1450:4864:20::22d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rcSdX-0005En-Ik for qemu-devel@nongnu.org; Tue, 20 Feb 2024 11:06:29 -0500 Received: by mail-lj1-x22d.google.com with SMTP id 38308e7fff4ca-2d23114b19dso31699451fa.3 for ; Tue, 20 Feb 2024 08:06:27 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id f8-20020a05600c4e8800b0040f0219c371sm15299927wmq.19.2024.02.20.08.06.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 08:06:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708445186; x=1709049986; darn=nongnu.org; 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=fbwlnbkTELmw0yuCS8YQeiT81oI84UQospsJeFLv0YU=; b=nJ4ap+3Scjx3YWWryHjsn/arO4mJ3aWqlLktScKPo8/4AFLhpmWDmimA32SiLgFOdz 8FyXCzBWaVLm9pw4JWrlLU4apu6vf0VYPwGUYSATnPCOBQroLaGPt8x25lz9yNRjdsYx brACJu/eoAdI6CHdKFXajFlmV7Ax3EGWOaBbnRV1iES8T9peOjqW0Iy6IPPoyOOlxtDr mHsaYp67vhp3ncd7AScEIGQLoofeRaIsTEPzw/lVD1B5nTqRqlAiqrU9/zhFy4bzRARb cjHFMDPqDBdUIdDTDSJYiDw/ZKaawYror9HcH5WLmhZ/IKyn4vNO8cZvKrggnkzxmLyR erKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708445186; x=1709049986; 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=fbwlnbkTELmw0yuCS8YQeiT81oI84UQospsJeFLv0YU=; b=L1uSzihshyLW/pyPs1oxj9bkVRySMpmxmXdU7fB/8wuyVlUO8clh+T6a5jYX0fxiRe 6Hlyby8CykgFjK0wAVWUIXoet5dSL4ybHIsoBUwvwgRG8c5DkCJafsl1SNfnPiM0qNzq GhUnNZuJKNcy9Gj7mLJCfGcPvN+3Ho+97aKNS0qjqhqwBYsR8HG9fCBUDy7MirHFZpO3 ZW2YSxglJuJ9UGvzbGzSUOESuAjwmN0JaGUQcuH/G6aLMsXrQCmKdznULjyNueGivtlL KAfoWVdg4f5OQjJvlVDiS2N/T/0RUVEk9J3hc1bmTsRxmQVdNpppxIESmeBGL+aIuq31 BbkA== X-Gm-Message-State: AOJu0Yw1Lq2gY5dVfe2nb/2vjrCD3rGrz+dEF7GrcZh1SMkK/uL5+CiQ pFg/bTxU8myJLoSjw/4qQphjXKZrD2Ki6St8LSGiwD2HrSj3KSpQ3FdHqEr9l3Bv2lSTwyXNJy2 9 X-Google-Smtp-Source: AGHT+IEqgrymnA16eKPoYPJ9nEqD5pDnpQUglY2tnRRJJJWx4Yf1pQRqyLbb9uQif3AzgEOtdzX8Iw== X-Received: by 2002:a2e:9446:0:b0:2d2:4c72:b24 with SMTP id o6-20020a2e9446000000b002d24c720b24mr1628879ljh.50.1708445185881; Tue, 20 Feb 2024 08:06:25 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , "Michael S. Tsirkin" , "Gonglei (Arei)" Subject: [PATCH 02/10] hw/i386/pc: Do pc_cmos_init_late() from pc_machine_done() Date: Tue, 20 Feb 2024 16:06:14 +0000 Message-Id: <20240220160622.114437-3-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240220160622.114437-1-peter.maydell@linaro.org> References: <20240220160622.114437-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::22d; envelope-from=peter.maydell@linaro.org; helo=mail-lj1-x22d.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, T_SCC_BODY_TEXT_LINE=-0.01 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1708445301147100003 Content-Type: text/plain; charset="utf-8" In the i386 PC machine, we want to run the pc_cmos_init_late() function only once the IDE and floppy drive devices have been set up. We currently do this using qemu_register_reset(), and then have the function call qemu_unregister_reset() on itself, so it runs exactly once. This was an expedient way to do it back in 2010 when we first added this (in commit c0897e0cb94e8), but now we have a more obvious point to do "machine initialization that has to happen after generic device init": the machine-init-done hook. Do the pc_cmos_init_late() work from our existing PC machine init done hook function, so we can drop the use of qemu_register_reset() and qemu_unregister_reset(). Because the pointers to the devices we need (the IDE buses and the RTC) are now all in the machine state, we don't need the pc_cmos_init_late_arg struct and can just pass the PCMachineState pointer. Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson Reviewed-by: Zhao Liu --- hw/i386/pc.c | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 8b0f54e284c..4c3cfe9fc35 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -465,11 +465,6 @@ static void pc_cmos_init_floppy(MC146818RtcState *rtc_= state, ISADevice *floppy) mc146818rtc_set_cmos_data(rtc_state, REG_EQUIPMENT_BYTE, val); } =20 -typedef struct pc_cmos_init_late_arg { - MC146818RtcState *rtc_state; - BusState *idebus[2]; -} pc_cmos_init_late_arg; - typedef struct check_fdc_state { ISADevice *floppy; bool multiple; @@ -530,23 +525,25 @@ static ISADevice *pc_find_fdc0(void) return state.floppy; } =20 -static void pc_cmos_init_late(void *opaque) +static void pc_cmos_init_late(PCMachineState *pcms) { - pc_cmos_init_late_arg *arg =3D opaque; - MC146818RtcState *s =3D arg->rtc_state; + X86MachineState *x86ms =3D X86_MACHINE(pcms); + MC146818RtcState *s =3D MC146818_RTC(x86ms->rtc); int16_t cylinders; int8_t heads, sectors; int val; int i, trans; =20 val =3D 0; - if (arg->idebus[0] && ide_get_geometry(arg->idebus[0], 0, - &cylinders, &heads, §ors) >= =3D 0) { + if (pcms->idebus[0] && + ide_get_geometry(pcms->idebus[0], 0, + &cylinders, &heads, §ors) >=3D 0) { cmos_init_hd(s, 0x19, 0x1b, cylinders, heads, sectors); val |=3D 0xf0; } - if (arg->idebus[0] && ide_get_geometry(arg->idebus[0], 1, - &cylinders, &heads, §ors) >= =3D 0) { + if (pcms->idebus[0] && + ide_get_geometry(pcms->idebus[0], 1, + &cylinders, &heads, §ors) >=3D 0) { cmos_init_hd(s, 0x1a, 0x24, cylinders, heads, sectors); val |=3D 0x0f; } @@ -558,10 +555,11 @@ static void pc_cmos_init_late(void *opaque) geometry. It is always such that: 1 <=3D sects <=3D 63, 1 <=3D heads <=3D 16, 1 <=3D cylinders <=3D 16383. The BIOS geometry can be different if a translation is done. */ - if (arg->idebus[i / 2] && - ide_get_geometry(arg->idebus[i / 2], i % 2, + BusState *idebus =3D pcms->idebus[i / 2]; + if (idebus && + ide_get_geometry(idebus, i % 2, &cylinders, &heads, §ors) >=3D 0) { - trans =3D ide_get_bios_chs_trans(arg->idebus[i / 2], i % 2) - = 1; + trans =3D ide_get_bios_chs_trans(idebus, i % 2) - 1; assert((trans & ~3) =3D=3D 0); val |=3D trans << (i * 2); } @@ -569,15 +567,12 @@ static void pc_cmos_init_late(void *opaque) mc146818rtc_set_cmos_data(s, 0x39, val); =20 pc_cmos_init_floppy(s, pc_find_fdc0()); - - qemu_unregister_reset(pc_cmos_init_late, opaque); } =20 void pc_cmos_init(PCMachineState *pcms, ISADevice *rtc) { int val; - static pc_cmos_init_late_arg arg; X86MachineState *x86ms =3D X86_MACHINE(pcms); MC146818RtcState *s =3D MC146818_RTC(rtc); =20 @@ -631,11 +626,7 @@ void pc_cmos_init(PCMachineState *pcms, val |=3D 0x04; /* PS/2 mouse installed */ mc146818rtc_set_cmos_data(s, REG_EQUIPMENT_BYTE, val); =20 - /* hard drives and FDC */ - arg.rtc_state =3D s; - arg.idebus[0] =3D pcms->idebus[0]; - arg.idebus[1] =3D pcms->idebus[1]; - qemu_register_reset(pc_cmos_init_late, &arg); + /* hard drives and FDC are handled by pc_cmos_init_late() */ } =20 static void handle_a20_line_change(void *opaque, int irq, int level) @@ -703,6 +694,8 @@ void pc_machine_done(Notifier *notifier, void *data) /* update FW_CFG_NB_CPUS to account for -device added CPUs */ fw_cfg_modify_i16(x86ms->fw_cfg, FW_CFG_NB_CPUS, x86ms->boot_cpus); } + + pc_cmos_init_late(pcms); } =20 void pc_guest_info_init(PCMachineState *pcms) --=20 2.34.1