From patchwork Fri Jan 10 17:57:07 2025 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: 856275 Delivered-To: patch@linaro.org Received: by 2002:a5d:525c:0:b0:385:e875:8a9e with SMTP id k28csp355287wrc; Fri, 10 Jan 2025 09:57:58 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUalpChkcCDBIpJW1JzO/t+t/eRsuYidYKzOIxyeXi0b4jJUivPeyy4P8SmT3HE46mPrOFs/Q==@linaro.org X-Google-Smtp-Source: AGHT+IFFA2zOUYIKGpNAgdWmPm2eYNC7qNoJy9faR4JyhFoLbj0UO6sUEmUrNflGPgBrge/BaqAy X-Received: by 2002:ad4:5d67:0:b0:6d8:99cf:d2db with SMTP id 6a1803df08f44-6df9b2ddc47mr205896136d6.38.1736531878592; Fri, 10 Jan 2025 09:57:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1736531878; cv=none; d=google.com; s=arc-20240605; b=WHwEWYbz5lU4bDd52XZ7DxS0rKJcgsonbD14KbwPJ41TZnpwEEchf6o/q6xpp4SD9W QNojtNakXjF3MbGfjxx5YRc9bdYSHoPmlLwG4v9Qp7X3Xrdwlng5UktxyJm+3PJvJzxw Jsgm2WtPEiTVAb6V1dS4pO04/OVMYB9CT4HvXm9EIagr/J8yjYHAajM0zo1UlQ1wgUOR o2di3cON8jWd2D5hbm32+c2tQKSZFC5SeTGVPyTGaKjuoGP7kfqj9A8T3VpvgN1bKMus YxWYFvdIU6ECs3fZXpRDcBsZg9CVVF0NK8QcBdenbGLjxcp+eRm9rikSEXKZCH5qFc9L j97A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=p5ISWojPgo9WK3ygV/aJcl6uT1BqiAXPMA4HtQhz2so=; fh=z1i+5ard1V1LFzRYbE1rKrMX/nD2EZkkqMYv1OBroa4=; b=ALNSeF5q99ea70RtSGd7BTzx1arSW1AoOkqyz2hmRU+3H5wn5NUZ25nG2JQ+lUMkdM 85JssuLe/VelPF2eD/PvXO69anuhsJc6Vg/YFY4lfwOu8msyRX/TEa2IL+KFDn9JOTwm hOqxYq9eM03MqfQpeBZI6Mzo532Wm1UwlaBMk/RHUFsHRjrcEtk1MKzaIbNio+SI55Oa hQuF2B8PUEEfEb/j4M2iOHBkO0sBz8dpk+xJNOtuLysp+IoUKpIMaLXpz5l8+5p7E4oA l1gSr3mtLnGbxG1w7ljH7dnIlWq1pALYX+xLZ1G2zRQxrEgpSqdUt3CYS/jnWZj9GrTf uN6Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IA8MOQax; 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; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 6a1803df08f44-6dfad9aab9bsi27845826d6.80.2025.01.10.09.57.58 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 10 Jan 2025 09:57:58 -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=IA8MOQax; 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; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tWJFz-00028x-Ua; Fri, 10 Jan 2025 12:57:16 -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 1tWJFw-00028j-U9 for qemu-devel@nongnu.org; Fri, 10 Jan 2025 12:57:12 -0500 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tWJFv-0003Cn-7F for qemu-devel@nongnu.org; Fri, 10 Jan 2025 12:57:12 -0500 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-385e0e224cbso1307485f8f.2 for ; Fri, 10 Jan 2025 09:57:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1736531829; x=1737136629; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=p5ISWojPgo9WK3ygV/aJcl6uT1BqiAXPMA4HtQhz2so=; b=IA8MOQaxLDhqPMtjzY6NbABPvmRVkHI4IG4l7+Dsr8yPy0D0dI3e/GwP2DkAu5kmiB ohrZhCVlMIp+Z8zy3pabhVkL8UkWy9jJgEGcpuvOH9Ybst7sLBsbXhngkHb/vkU7qTKS sOntR8XKvGLGb+EvWwVnHcxWh3B8ikgO/PpgeZr0SxFItsC1R7n9vE+whmYMZvN+2zai BYVvNuOTJpCnwyeKiFJQtl+vKFvvq5ulBkR/MZ6l8G0wXUkQSwQL5r9PqYjBB5h4ZIw6 XQQ8pJ9D4mJ8FXbY6sFf8++zkRQ5NlstMqB+pl8zom1tXLol3PpNU6pt0x7JkljB29co T24Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736531829; x=1737136629; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=p5ISWojPgo9WK3ygV/aJcl6uT1BqiAXPMA4HtQhz2so=; b=YLIsOM8YUtNFiABvrb9UrG1PdollKgZNmKiZPHs+JdfdM0zIiMM5GuBBdeQ+6l17Ya L9IR8ZO2jaBhD1+S3gNIIfvu98fOkfnGFkiVW6J2+zlT7uHenKSF0sCJ87rEtinHPIsF CjH5uUAMsy9Rl3skyVOASw/SD6PDcITU9DCeJpw7v+jKEBuuobyzZpBO+C7szxbmSNnK ZDw0uyw+2LFF1kBa7+5zUs4OxhBilOb4CSwGjOukDtboKCr1zcg2hxTDV4JX9F5Vhp5B gWJ6UNExt2B7VNvQ9EoDGzDMFG3uFDn8ZsJ7qWh9SnbSW8T/kv+PmY2wtTOwsKSeUHw8 LmuQ== X-Gm-Message-State: AOJu0YxrMIrgOUCWF/TB2dIb6nhwRbNDBF9cdQO8kN5c0ygXgbYHUDZG y92vAyVru2MDzGJ7fNVPNFW6GYbMX1T8VzDbg2NSoA1PYCmDucwgY/ELkprPQvUPUeQlkwl/y42 6rnQ= X-Gm-Gg: ASbGncvy56QgcG49kmkb5V4uYIiZf8m2zEFK+vP9X0NJVXwV2jp9sjZV5LU/sssbnBS DjkJWjkiYhzp7YgHHT+tfdQXl1ge/KMd/chCqqdaf4hPX8ekcXduwZhj9sZ1+NxLTi5RIulAkw3 w2+Io2Jc5S6TAu6A1TVlVW42Sac8v5+xO83RJyyUjMqNIu/tsSuqeKW6s+NkbjwGSHnR5GMK8u4 T1DtRVpgPWc9Y9NgOGWnXjMVv+62ESCmrk/HEG/l9173Ro5p7IrgsGcWo9fNDRS24uWgB9fbvNV MN0GK5QoEumfp5tJ6L7hiNmeidVIRqE= X-Received: by 2002:a05:6000:712:b0:385:f3fb:46aa with SMTP id ffacd0b85a97d-38a87308c15mr11721227f8f.43.1736531828837; Fri, 10 Jan 2025 09:57:08 -0800 (PST) Received: from localhost.localdomain (88-187-86-199.subs.proxad.net. [88.187.86.199]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38a8e37d111sm5234556f8f.18.2025.01.10.09.57.07 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 10 Jan 2025 09:57:08 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: "Michael S. Tsirkin" , Paolo Bonzini , Peter Maydell , Mark Cave-Ayland , =?utf-8?q?Marc-Andr=C3=A9?= =?utf-8?q?_Lureau?= , =?utf-8?q?Alex_Benn?= =?utf-8?q?=C3=A9e?= , =?utf-8?q?Philippe_Mathieu-Da?= =?utf-8?q?ud=C3=A9?= Subject: [PATCH] hw/char/serial: Convert to three-phase reset Date: Fri, 10 Jan 2025 18:57:07 +0100 Message-ID: <20250110175707.82097-1-philmd@linaro.org> X-Mailer: git-send-email 2.47.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=philmd@linaro.org; helo=mail-wr1-x432.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 Convert the TYPE_SERIAL (16550A UART) to three-phase reset. Local states are reset in the ResetHold handler. Move the IRQ lowering to ResetExit, since it an external object is accessed. Note, this fixes a bug where serial_realize() was calling serial_reset() -> qemu_irq_lower() while the IRQ was not yet created. Signed-off-by: Philippe Mathieu-Daudé --- That said, externally creating IRQ like that is odd, see: serial_pci_realize() { SerialState *s = &pci->state; qdev_realize(DEVICE(s), NULL, ...); s->irq = pci_allocate_irq(&pci->dev); But too much cleanup for now, one step at a time. --- hw/char/serial.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/hw/char/serial.c b/hw/char/serial.c index 70044e14a0f..0dab5fba176 100644 --- a/hw/char/serial.c +++ b/hw/char/serial.c @@ -851,9 +851,9 @@ const VMStateDescription vmstate_serial = { } }; -static void serial_reset(void *opaque) +static void serial_reset_hold(Object *obj, ResetType type) { - SerialState *s = opaque; + SerialState *s = (SerialState *)obj; if (s->watch_tag > 0) { g_source_remove(s->watch_tag); @@ -885,12 +885,18 @@ static void serial_reset(void *opaque) s->thr_ipending = 0; s->last_break_enable = 0; - qemu_irq_lower(s->irq); serial_update_msl(s); s->msr &= ~UART_MSR_ANY_DELTA; } +static void serial_reset_exit(Object *obj, ResetType type) +{ + SerialState *s = (SerialState *)obj; + + qemu_irq_lower(s->irq); +} + static int serial_be_change(void *opaque) { SerialState *s = opaque; @@ -926,13 +932,11 @@ static void serial_realize(DeviceState *dev, Error **errp) s->modem_status_poll = timer_new_ns(QEMU_CLOCK_VIRTUAL, (QEMUTimerCB *) serial_update_msl, s); s->fifo_timeout_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, (QEMUTimerCB *) fifo_timeout_int, s); - qemu_register_reset(serial_reset, s); qemu_chr_fe_set_handlers(&s->chr, serial_can_receive1, serial_receive1, serial_event, serial_be_change, s, NULL, true); fifo8_create(&s->recv_fifo, UART_FIFO_LENGTH); fifo8_create(&s->xmit_fifo, UART_FIFO_LENGTH); - serial_reset(s); } static void serial_unrealize(DeviceState *dev) @@ -947,8 +951,6 @@ static void serial_unrealize(DeviceState *dev) fifo8_destroy(&s->recv_fifo); fifo8_destroy(&s->xmit_fifo); - - qemu_unregister_reset(serial_reset, s); } const MemoryRegionOps serial_io_ops = { @@ -973,12 +975,15 @@ static const Property serial_properties[] = { static void serial_class_init(ObjectClass *klass, void* data) { DeviceClass *dc = DEVICE_CLASS(klass); + ResettableClass *rc = RESETTABLE_CLASS(klass); /* internal device for serialio/serialmm, not user-creatable */ dc->user_creatable = false; dc->realize = serial_realize; dc->unrealize = serial_unrealize; device_class_set_props(dc, serial_properties); + rc->phases.hold = serial_reset_hold; + rc->phases.exit = serial_reset_exit; } static const TypeInfo serial_info = {