From nobody Sun Apr 6 04:27:01 2025 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1737712089; cv=none; d=zohomail.com; s=zohoarc; b=EGRgPIGSJs9ycd+F5b9JKctEYiOkKcGsn7Gntr2YDBCwiZY40htbT5wXh1o50aUqPkZRtuP0AEuBbk30gVNLlztLNCIe27vW8vybcdrYgIy00kWAg37VY4yhr5SrWevap/P+OTo5GeA1LnieUR2CZ9VqcXgm6Oy7N/ulg0m72Bw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1737712089; h=Content-Transfer-Encoding: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:Cc; bh=Oie+UgyG+xo4wp2azixL6WeEjPRPNC/oLryPAGhcuZA=; b=VtsW6LiQ6YPAMs+7xPThRBaQSwD1hrMTV4Bc9j4jjTQBaxvnAm3NDk/EFoU2nd0NZEba/rciUMQz+l349JZQOnIrsI9TuICb7yPcAEwf/hg0jkc83bnpK7Kp8U+V8UdfpLuE5VNZIqndsAjwoQiYjROnMCvSuOM240RQBXZQOuU= 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 173771208931952.345809414698124; Fri, 24 Jan 2025 01:48:09 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tbGHz-000476-Qb; Fri, 24 Jan 2025 04:47:48 -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 1tbGGT-0007rM-71 for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:46:20 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tbGGO-0003zM-UU for qemu-devel@nongnu.org; Fri, 24 Jan 2025 04:46:10 -0500 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-531-xrsaROcOOp-VKvJlBmBg5w-1; Fri, 24 Jan 2025 04:46:05 -0500 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4362b9c15d8so8753975e9.3 for ; Fri, 24 Jan 2025 01:46:05 -0800 (PST) Received: from [192.168.10.48] ([151.95.59.125]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438bd4c75c0sm20280095e9.31.2025.01.24.01.46.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 01:46:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737711967; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Oie+UgyG+xo4wp2azixL6WeEjPRPNC/oLryPAGhcuZA=; b=FuON5gzawoCkYokvCGEO8nj9htrkxink5ev13xtzkZjbofUL9PpsVuscpJwRnK7zJF4Hdk geHhbRic0ZMzONj3YcOYxVsCqgoK3490ieCXHbjBLGw5OHjETeBXZlDl4HiPaTsiUBufki hKAuHGHL/nh9htTJweo7kKwZUnKp1fk= X-MC-Unique: xrsaROcOOp-VKvJlBmBg5w-1 X-Mimecast-MFC-AGG-ID: xrsaROcOOp-VKvJlBmBg5w X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737711964; x=1738316764; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Oie+UgyG+xo4wp2azixL6WeEjPRPNC/oLryPAGhcuZA=; b=rmOyZcYEuZBXGa1MDGmEoV6Zff2KGHArlzOac4zuzDxj97s4OmqQQbIvc2khdlMuo3 N6vJ3fFtKL0DrIrV/BwIDZGPn9e7IXPkuu73xIqxiP4f+Y7fHCOOScufEDOWXcn7OD99 zATBmm3TF3B9pyCq8Consm/d9wbjkWY8N+Xycp8604rvsrwzHOVQyd8fDe8CXgemC06G dT2Upm7a0qn9Ji/9y93VGMSkMGEOkd6iClo/LLryj+sLUXKbmPgr5x0EuOJE3tmCjvRj TZqpeFZTEwj34I3/x1HgW1ZaPH9gt3tpsaZ6CBoNjSfmr95MGcC/AJvjQL7OrATYgC2A htvg== X-Gm-Message-State: AOJu0YzkVY28ShN8NjJVpwh/+nL6GGF5lXyK6HoLeXM7re+vjlluhZ2y rT2RVvrQ+Ci78qDC1cZ2/VbguuExuM3DaArLq6nt3QOvPqW8oNMkq7LPX27QM6GCPX2sjGVq2lh bPsUREzaq+e5/6jqSMfmakPJw1CZYr18pUHOnUXj86lwLEZA9Z4tCebHe3NXjOBqOuOf5qgTsrU G/XLwdGEbj9FFx7AAl8shHKcm8hJdsNshUaIwFZmM= X-Gm-Gg: ASbGncsRYaifxKz+6Z0EJb8CIwFdk/lDHDnvCXiLNIkIHg4s+NB3sDDruNyxT48Rxqp lsRtVfvYRVOUEAuS+/E9niIy3STfCevssxvh3ulFSWj9rbnMWRsyJvWMCirFkd0W87bl6iicesc zeN1KBsK4GgOJM/JZrNliS81rBfPitXEMTvviQW70C7UMSxJ0sT9zj1nSQ/CFw4YDxf2bD9tVnf QUNC8xNn9dLWfy4syyFwOcj12PnR/7Mup7oRG80VwPPGVxW3ZS+zJPxSoorrGgfe3NHtzjfqA== X-Received: by 2002:a05:600c:5486:b0:434:f1e9:afae with SMTP id 5b1f17b1804b1-438913bfa0fmr242509635e9.1.1737711963919; Fri, 24 Jan 2025 01:46:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IHUHi8PqY8wgEb9kJyjfU7CyySml8jiZHKdXoA4+DZ7ZbBcNysjR55/L/bjNVmCrfIQSaRfWQ== X-Received: by 2002:a05:600c:5486:b0:434:f1e9:afae with SMTP id 5b1f17b1804b1-438913bfa0fmr242509215e9.1.1737711963273; Fri, 24 Jan 2025 01:46:03 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 40/48] rust: pl011: pull interrupt updates out of read/write ops Date: Fri, 24 Jan 2025 10:44:34 +0100 Message-ID: <20250124094442.13207-41-pbonzini@redhat.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250124094442.13207-1-pbonzini@redhat.com> References: <20250124094442.13207-1-pbonzini@redhat.com> 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=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.996, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1737712091707019100 Content-Type: text/plain; charset="utf-8" qemu_irqs are not part of the vmstate, therefore they will remain in PL011State. Update them if needed after regs_read()/regs_write(). Apply #[must_use] to functions that return whether the interrupt state could have changed, so that it's harder to forget the call to update(). Reviewed-by: Zhao Liu Signed-off-by: Paolo Bonzini --- rust/hw/char/pl011/src/device.rs | 84 ++++++++++++++++++-------------- 1 file changed, 48 insertions(+), 36 deletions(-) diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/devi= ce.rs index de5110038a5..9cac9d352a2 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -242,7 +242,6 @@ fn regs_read(&mut self, offset: RegisterOffset) -> Cont= rolFlow { } // Update error bits. self.receive_status_error_clear.set_from_data(c); - self.update(); // Must call qemu_chr_fe_accept_input, so return Continue: return ControlFlow::Continue(u32::from(c)); } @@ -266,7 +265,7 @@ fn regs_read(&mut self, offset: RegisterOffset) -> Cont= rolFlow { }) } =20 - fn regs_write(&mut self, offset: RegisterOffset, value: u32) { + fn regs_write(&mut self, offset: RegisterOffset, value: u32) -> bool { // eprintln!("write offset {offset} value {value}"); use RegisterOffset::*; match offset { @@ -281,9 +280,10 @@ fn regs_write(&mut self, offset: RegisterOffset, value= : u32) { unsafe { qemu_chr_fe_write_all(addr_of_mut!(self.char_backend),= &ch, 1); } - self.loopback_tx(value); + // interrupts always checked + let _ =3D self.loopback_tx(value); self.int_level |=3D registers::INT_TX; - self.update(); + return true; } RSR =3D> { self.receive_status_error_clear =3D 0.into(); @@ -307,7 +307,7 @@ fn regs_write(&mut self, offset: RegisterOffset, value:= u32) { self.reset_rx_fifo(); self.reset_tx_fifo(); } - if self.line_control.send_break() ^ new_val.send_break() { + let update =3D (self.line_control.send_break() !=3D new_va= l.send_break()) && { let mut break_enable: c_int =3D new_val.send_break().i= nto(); // SAFETY: self.char_backend is a valid CharBackend in= stance after it's been // initialized in realize(). @@ -318,15 +318,16 @@ fn regs_write(&mut self, offset: RegisterOffset, valu= e: u32) { addr_of_mut!(break_enable).cast::(), ); } - self.loopback_break(break_enable > 0); - } + self.loopback_break(break_enable > 0) + }; self.line_control =3D new_val; self.set_read_trigger(); + return update; } CR =3D> { // ??? Need to implement the enable bit. self.control =3D value.into(); - self.loopback_mdmctrl(); + return self.loopback_mdmctrl(); } FLS =3D> { self.ifl =3D value; @@ -334,13 +335,13 @@ fn regs_write(&mut self, offset: RegisterOffset, valu= e: u32) { } IMSC =3D> { self.int_enabled =3D value; - self.update(); + return true; } RIS =3D> {} MIS =3D> {} ICR =3D> { self.int_level &=3D !value; - self.update(); + return true; } DMACR =3D> { self.dmacr =3D value; @@ -350,14 +351,12 @@ fn regs_write(&mut self, offset: RegisterOffset, valu= e: u32) { } } } + false } =20 #[inline] - fn loopback_tx(&mut self, value: u32) { - if !self.loopback_enabled() { - return; - } - + #[must_use] + fn loopback_tx(&mut self, value: u32) -> bool { // Caveat: // // In real hardware, TX loopback happens at the serial-bit level @@ -375,12 +374,13 @@ fn loopback_tx(&mut self, value: u32) { // hardware flow-control is enabled. // // For simplicity, the above described is not emulated. - self.put_fifo(value); + self.loopback_enabled() && self.put_fifo(value) } =20 - fn loopback_mdmctrl(&mut self) { + #[must_use] + fn loopback_mdmctrl(&mut self) -> bool { if !self.loopback_enabled() { - return; + return false; } =20 /* @@ -421,13 +421,11 @@ fn loopback_mdmctrl(&mut self) { il |=3D Interrupt::RI as u32; } self.int_level =3D il; - self.update(); + true } =20 - fn loopback_break(&mut self, enable: bool) { - if enable { - self.loopback_tx(registers::Data::BREAK.into()); - } + fn loopback_break(&mut self, enable: bool) -> bool { + enable && self.loopback_tx(registers::Data::BREAK.into()) } =20 fn set_read_trigger(&mut self) { @@ -489,14 +487,17 @@ pub fn can_receive(&self) -> bool { } =20 pub fn receive(&mut self, ch: u32) { - if !self.loopback_enabled() { - self.put_fifo(ch) + if !self.loopback_enabled() && self.put_fifo(ch) { + self.update(); } } =20 pub fn event(&mut self, event: QEMUChrEvent) { if event =3D=3D QEMUChrEvent::CHR_EVENT_BREAK && !self.loopback_en= abled() { - self.put_fifo(registers::Data::BREAK.into()); + let update =3D self.put_fifo(registers::Data::BREAK.into()); + if update { + self.update(); + } } } =20 @@ -519,7 +520,8 @@ pub fn fifo_depth(&self) -> u32 { 1 } =20 - pub fn put_fifo(&mut self, value: u32) { + #[must_use] + pub fn put_fifo(&mut self, value: u32) -> bool { let depth =3D self.fifo_depth(); assert!(depth > 0); let slot =3D (self.read_pos + self.read_count) & (depth - 1); @@ -532,8 +534,9 @@ pub fn put_fifo(&mut self, value: u32) { =20 if self.read_count =3D=3D self.read_trigger { self.int_level |=3D registers::INT_RX; - self.update(); + return true; } + false } =20 pub fn update(&self) { @@ -565,7 +568,8 @@ pub fn post_load(&mut self, _version_id: u32) -> Result= <(), ()> { } =20 pub fn read(&mut self, offset: hwaddr, _size: u32) -> ControlFlow { - match RegisterOffset::try_from(offset) { + let mut update_irq =3D false; + let result =3D match RegisterOffset::try_from(offset) { Err(v) if (0x3f8..0x400).contains(&(v >> 2)) =3D> { let device_id =3D self.get_class().device_id; ControlFlow::Break(u64::from(device_id[(offset - 0xfe0) >>= 2])) @@ -574,22 +578,30 @@ pub fn read(&mut self, offset: hwaddr, _size: u32) ->= ControlFlow { // qemu_log_mask(LOG_GUEST_ERROR, "pl011_read: Bad offset = 0x%x\n", (int)offset); ControlFlow::Break(0) } - Ok(field) =3D> { - let result =3D self.regs_read(field); - match result { - ControlFlow::Break(value) =3D> ControlFlow::Break(valu= e.into()), - ControlFlow::Continue(value) =3D> ControlFlow::Continu= e(value.into()), + Ok(field) =3D> match self.regs_read(field) { + ControlFlow::Break(value) =3D> ControlFlow::Break(value.in= to()), + ControlFlow::Continue(value) =3D> { + update_irq =3D true; + ControlFlow::Continue(value.into()) } - } + }, + }; + if update_irq { + self.update(); } + result } =20 pub fn write(&mut self, offset: hwaddr, value: u64) { + let mut update_irq =3D false; if let Ok(field) =3D RegisterOffset::try_from(offset) { - self.regs_write(field, value as u32); + update_irq =3D self.regs_write(field, value as u32); } else { eprintln!("write bad offset {offset} value {value}"); } + if update_irq { + self.update(); + } } } =20 --=20 2.48.1