From nobody Thu Nov 14 07:04:05 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1705580707; cv=none; d=zohomail.com; s=zohoarc; b=Ij8gabtCKLrufEq5gwE7TB3O/KGM8Xnvcf8j1P1zNghg8517hI32EDYRaGemzAbr4eROh4fQpd8jJfl59D1kb9GFwTdg7o6butCkmuU0xRa69luf2UVYjk2EUyd66vugSwo0KxPApQFFOHBHcJvzr+CdgO4mQ+lotefFT+SE2kQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705580707; h=Content-Type: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=egeyUdc9pjO+1xQmlTrMlEire79rsJCnWzWZGPWX2jo=; b=PG795SoDxyCivKy/Fr+513yW9J+eQr9HZYmU0R0EX+46TQSPTK1lZiLjOARaBRMeyrwPuBtk99HsA9JEhPHz8MAiKfXcAlrdlhXvjF0/z3x7BImJl1IFMvheLKSe7rlgAicgD+XLtqh8AIY90gBSFI2uqgnBt4d9BGwzSUqWrjk= 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 1705580707019109.74958496771046; Thu, 18 Jan 2024 04:25:07 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rQRRk-0003O7-DN; Thu, 18 Jan 2024 07:24:36 -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 1rQRRe-0003De-Mx for qemu-devel@nongnu.org; Thu, 18 Jan 2024 07:24:31 -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 1rQRRY-0005d3-Mz for qemu-devel@nongnu.org; Thu, 18 Jan 2024 07:24:26 -0500 Received: from mail-lj1-f197.google.com (mail-lj1-f197.google.com [209.85.208.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-561-6IqNE1gnO3WWOitupWJLdA-1; Thu, 18 Jan 2024 07:24:21 -0500 Received: by mail-lj1-f197.google.com with SMTP id 38308e7fff4ca-2ccbfa17001so99729851fa.2 for ; Thu, 18 Jan 2024 04:24:21 -0800 (PST) Received: from [192.168.10.118] ([2001:b07:6468:f312:4783:a68:c1ee:15c5]) by smtp.gmail.com with ESMTPSA id x9-20020aa7cd89000000b00558e0481b2fsm8024551edv.47.2024.01.18.04.24.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 04:24:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705580663; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=egeyUdc9pjO+1xQmlTrMlEire79rsJCnWzWZGPWX2jo=; b=JzEYXRfn814THtvnhICpMtjtiixEJ3HzLgU5r7P5Zj02k4M0VW421F3qq6C/5q8l0zlCQ4 dZ7d2BuCaV7qJGfb0ULBD5mf6J0lnh8Q/F/RQrBidH/Lenjx0PWtzlrep5+CCOk/0nBZIu EnGd27skV1khXZ+XnKfaGm4fMBQcG7w= X-MC-Unique: 6IqNE1gnO3WWOitupWJLdA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705580660; x=1706185460; 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=egeyUdc9pjO+1xQmlTrMlEire79rsJCnWzWZGPWX2jo=; b=Fyyew9Oa02JPNTYNidNFM9DJbHSBu+Md5G+WVkLJXPsKzcX30KcKVJNm9KD9AxVhJl fv/tVk1dNVe6qfW8Cv6ANYqTJs3+BppBSZbFYZMr+h4UmuIg3xY4G2qdCO8OiJK3fRBA i6QNfF0fPXyI1rLMVovmP51thndNx5hPsiVTpfuIDbvMy9+vTEl+WQuWuZRp7BaueZuV jm3hRpIYt9kUyQKxv8QyiAjJ7kOgFt42ZNhgYKC06DzR6BTq0GGRRm2/Xpp94PZsHc7s jhfZwQXgALqNwLsQpgXMdsId7AcM0WuT809fa5TQw1qh8dNzItTQ2bQAjXlpGDkfa/wG 9V8w== X-Gm-Message-State: AOJu0YwLptew9FPSldX/NIgu2owJZwz53aN1+7tFicCfOXk20Cqs1CzV CSuUSfwmAnRvv29MtirgwL70vW2ieIP8fzKj2AtAqosIiO8hy3X9EGdnpduuhPuv4aH3poSAY5s mYVBjsbYazE9L2yrpYlyJFMhtO1pOcHanEsNgCnDjH36WNe1UpHigpIU7UiyjgpZMyjLnJ/INw+ g2o2u+obGoE7PvYLXHq8gl6Z8/LVwMIRZCgVcL X-Received: by 2002:a2e:9b0a:0:b0:2cd:63eb:e7b5 with SMTP id u10-20020a2e9b0a000000b002cd63ebe7b5mr453094lji.80.1705580660098; Thu, 18 Jan 2024 04:24:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IEiZkl1225h5ISC4H0jHyRfk62Jm81yjW/iQ5KQlUJ0Vm9dMc8o8ZX8uVwx8gsUki/B3kUMyQ== X-Received: by 2002:a2e:9b0a:0:b0:2cd:63eb:e7b5 with SMTP id u10-20020a2e9b0a000000b002cd63ebe7b5mr453088lji.80.1705580659692; Thu, 18 Jan 2024 04:24:19 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 01/16] vga: use common endian swap macros Date: Thu, 18 Jan 2024 13:24:01 +0100 Message-ID: <20240118122416.9209-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240118122416.9209-1-pbonzini@redhat.com> References: <20240118122416.9209-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: -38 X-Spam_score: -3.9 X-Spam_bar: --- X-Spam_report: (-3.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.806, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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 @redhat.com) X-ZM-MESSAGEID: 1705580707805100003 Content-Type: text/plain; charset="utf-8" The constant-expression bswap is provided by const_le32(), and GET_PLANE() can also be implemented using cpu_to_le32(). Remove the custom macros in vga.c. Signed-off-by: Paolo Bonzini --- hw/display/vga.c | 65 +++++++++++++----------------------------------- 1 file changed, 17 insertions(+), 48 deletions(-) diff --git a/hw/display/vga.c b/hw/display/vga.c index 886a4020e5d..a8b5830a30a 100644 --- a/hw/display/vga.c +++ b/hw/display/vga.c @@ -90,58 +90,27 @@ const uint8_t gr_mask[16] =3D { 0x00, /* 0x0f */ }; =20 -#define cbswap_32(__x) \ -((uint32_t)( \ - (((uint32_t)(__x) & (uint32_t)0x000000ffUL) << 24) | \ - (((uint32_t)(__x) & (uint32_t)0x0000ff00UL) << 8) | \ - (((uint32_t)(__x) & (uint32_t)0x00ff0000UL) >> 8) | \ - (((uint32_t)(__x) & (uint32_t)0xff000000UL) >> 24) )) - -#if HOST_BIG_ENDIAN -#define PAT(x) cbswap_32(x) -#else -#define PAT(x) (x) -#endif - -#if HOST_BIG_ENDIAN -#define BIG 1 -#else -#define BIG 0 -#endif - -#if HOST_BIG_ENDIAN -#define GET_PLANE(data, p) (((data) >> (24 - (p) * 8)) & 0xff) -#else -#define GET_PLANE(data, p) (((data) >> ((p) * 8)) & 0xff) -#endif +#define GET_PLANE(data, p) ((cpu_to_le32(data) >> ((p) * 8)) & 0xff) =20 static const uint32_t mask16[16] =3D { - PAT(0x00000000), - PAT(0x000000ff), - PAT(0x0000ff00), - PAT(0x0000ffff), - PAT(0x00ff0000), - PAT(0x00ff00ff), - PAT(0x00ffff00), - PAT(0x00ffffff), - PAT(0xff000000), - PAT(0xff0000ff), - PAT(0xff00ff00), - PAT(0xff00ffff), - PAT(0xffff0000), - PAT(0xffff00ff), - PAT(0xffffff00), - PAT(0xffffffff), + const_le32(0x00000000), + const_le32(0x000000ff), + const_le32(0x0000ff00), + const_le32(0x0000ffff), + const_le32(0x00ff0000), + const_le32(0x00ff00ff), + const_le32(0x00ffff00), + const_le32(0x00ffffff), + const_le32(0xff000000), + const_le32(0xff0000ff), + const_le32(0xff00ff00), + const_le32(0xff00ffff), + const_le32(0xffff0000), + const_le32(0xffff00ff), + const_le32(0xffffff00), + const_le32(0xffffffff), }; =20 -#undef PAT - -#if HOST_BIG_ENDIAN -#define PAT(x) (x) -#else -#define PAT(x) cbswap_32(x) -#endif - static uint32_t expand4[256]; static uint16_t expand2[256]; static uint8_t expand4to8[16]; --=20 2.43.0 From nobody Thu Nov 14 07:04:05 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1705580849; cv=none; d=zohomail.com; s=zohoarc; b=PKGZ6WRtHEMRIpyEHYBDFNsX2n7joEP/YFc1pRpiAdIsMaEG+zV6XoP+BhxxFy3MwgZFx5WilybwuWFft0c5tGtrhzkvkSwR87ccQlOHCSxL32GvU5JEi6YJXfijVw7Srbqduem8kPPhZ9LiAUGAIrJBjEBkMnCI1WQfpCUIGGY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705580849; h=Content-Type: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=p9TuRa1z7PtEWzSZQLB3Vva6UD0LuAqQd7e6FQ+xvQ8=; b=aS029+N6xw0FYDMuKgsIjwgztYGB7MYtBOtuvdL7XfTxDoDTy6qc6aVhVI7akGec5rsm6ZRrLFpMLEtR4BBaDrtKtguSeSpdDX/YfxJZAbpNg90I+U0IDVykmW/wyksZnOFe/4iyUxO1bmMm+zCClQxvv9Ht1oO4yjocL0qfVUQ= 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 1705580849288669.6794761263271; Thu, 18 Jan 2024 04:27:29 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rQRRl-0003Qa-FQ; Thu, 18 Jan 2024 07:24:37 -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 1rQRRh-0003Ko-72 for qemu-devel@nongnu.org; Thu, 18 Jan 2024 07:24:33 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rQRRc-0005lH-07 for qemu-devel@nongnu.org; Thu, 18 Jan 2024 07:24:32 -0500 Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-368-tPuL0C6WNNW3nEaCAMlOlg-1; Thu, 18 Jan 2024 07:24:24 -0500 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-a2eace36abdso84186966b.3 for ; Thu, 18 Jan 2024 04:24:23 -0800 (PST) Received: from [192.168.10.118] ([2001:b07:6468:f312:4783:a68:c1ee:15c5]) by smtp.gmail.com with ESMTPSA id un5-20020a170907cb8500b00a2ceaf80bcbsm7470302ejc.204.2024.01.18.04.24.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 04:24:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705580666; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=p9TuRa1z7PtEWzSZQLB3Vva6UD0LuAqQd7e6FQ+xvQ8=; b=I48CfGVlRGah44QsVy0hmhUa9Kh+Z81h8kpLkWfEgdFetvXN4r+sXMP/CmWms26C6yLkoK 0k9p2SLFDejYp9JmkaLuEzsOA3vyR4/anz/Urp+k4KJ1ZIfw9J5WHkzpxirEufuB0HNJHq Qguj73lQz0yT6a9P4aqw4iIeIYHMUqw= X-MC-Unique: tPuL0C6WNNW3nEaCAMlOlg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705580662; x=1706185462; 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=p9TuRa1z7PtEWzSZQLB3Vva6UD0LuAqQd7e6FQ+xvQ8=; b=MLxi9uElB1WBfgVkgO0xm9U01+vT1KpkdOIcnYon65HBAt5l8nShG2UNb4wbP774kS 9bUsE7ZEi/2pHajM5McJYjOzIDP9o144Gi5m6kAF0QLJLaEqpJgcYSW+YE+vVKeWYbWq yGMBodx17791qea3k68SIT8DBrJxTdM91of97pYkG/XojOjCez9awqFcHQIcBXDXXVr2 3uMKceAOlsbuAvtdJmRIq1rlUH5I+RL7EGxrACgk/9ht0aaWTblCEkbaPIQ6WvWpggnf AaIjxSW70ucCRljkU/DmZipQ6K81NBpsfH0RppL3IMlgnfgkY7tTvX1LLPNyL5MG6sW0 SF2w== X-Gm-Message-State: AOJu0YyvqWAJ/k9m4/FvVe9geK8ztuRno9/oGU+k33zpmo23mD2IzGUG aDqlbjp6NuoDeSPvRNnp47ci2Jv0rNUXa9NlNGwaknGw8QCTEH6dCdL08NhEKqhKuqvibjpj11C z7mG34vWANEheBEAtj6KD0yPztYZJNy3xd+YCVIk64JI9KO1KMHT/gsSTJSfDqfqfqE8dWcP5AL PBbLLex65CJfCD0AYR3QhsA0Lg/cm0ExZLcA7s X-Received: by 2002:a17:906:5946:b0:a27:a34e:bcd with SMTP id g6-20020a170906594600b00a27a34e0bcdmr222629ejr.157.1705580662097; Thu, 18 Jan 2024 04:24:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IEK3tbsZ54ZcDthhusSUtdfUxmTPt9Evpg/pjG6EsCObic3jYjyscfJAjXWM3NOEE+aU7i0fQ== X-Received: by 2002:a17:906:5946:b0:a27:a34e:bcd with SMTP id g6-20020a170906594600b00a27a34e0bcdmr222623ejr.157.1705580661487; Thu, 18 Jan 2024 04:24:21 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 02/16] vga: introduce VGADisplayParams Date: Thu, 18 Jan 2024 13:24:02 +0100 Message-ID: <20240118122416.9209-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240118122416.9209-1-pbonzini@redhat.com> References: <20240118122416.9209-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.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -38 X-Spam_score: -3.9 X-Spam_bar: --- X-Spam_report: (-3.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.806, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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 @redhat.com) X-ZM-MESSAGEID: 1705580850332100016 Content-Type: text/plain; charset="utf-8" The next patches will introduce more parameters that cause a full refresh. Instead of adding arguments to get_offsets and lines to update_basic_params, do everything through a struct. Signed-off-by: Paolo Bonzini --- hw/display/vga_int.h | 15 ++++---- hw/display/cirrus_vga.c | 24 +++++------- hw/display/vga.c | 82 +++++++++++++++++------------------------ 3 files changed, 52 insertions(+), 69 deletions(-) diff --git a/hw/display/vga_int.h b/hw/display/vga_int.h index 7cf0d11201a..6be61e04284 100644 --- a/hw/display/vga_int.h +++ b/hw/display/vga_int.h @@ -56,6 +56,12 @@ struct VGACommonState; typedef uint8_t (* vga_retrace_fn)(struct VGACommonState *s); typedef void (* vga_update_retrace_info_fn)(struct VGACommonState *s); =20 +typedef struct VGADisplayParams { + uint32_t line_offset; + uint32_t start_addr; + uint32_t line_compare; +} VGADisplayParams; + typedef struct VGACommonState { MemoryRegion *legacy_address_space; uint8_t *vram_ptr; @@ -90,10 +96,7 @@ typedef struct VGACommonState { uint8_t palette[768]; int32_t bank_offset; int (*get_bpp)(struct VGACommonState *s); - void (*get_offsets)(struct VGACommonState *s, - uint32_t *pline_offset, - uint32_t *pstart_addr, - uint32_t *pline_compare); + void (*get_params)(struct VGACommonState *s, VGADisplayParams *params); void (*get_resolution)(struct VGACommonState *s, int *pwidth, int *pheight); @@ -111,9 +114,7 @@ typedef struct VGACommonState { int graphic_mode; uint8_t shift_control; uint8_t double_scan; - uint32_t line_offset; - uint32_t line_compare; - uint32_t start_addr; + VGADisplayParams params; uint32_t plane_updated; uint32_t last_line_offset; uint8_t last_cw, last_ch; diff --git a/hw/display/cirrus_vga.c b/hw/display/cirrus_vga.c index 5dd5136a0cd..e637e5a816e 100644 --- a/hw/display/cirrus_vga.c +++ b/hw/display/cirrus_vga.c @@ -798,9 +798,9 @@ static int cirrus_bitblt_videotovideo_copy(CirrusVGASta= te * s) if (blit_is_unsafe(s, false)) return 0; =20 - return cirrus_do_copy(s, s->cirrus_blt_dstaddr - s->vga.start_addr, - s->cirrus_blt_srcaddr - s->vga.start_addr, - s->cirrus_blt_width, s->cirrus_blt_height); + return cirrus_do_copy(s, s->cirrus_blt_dstaddr - s->vga.params.start_a= ddr, + s->cirrus_blt_srcaddr - s->vga.params.start_addr, + s->cirrus_blt_width, s->cirrus_blt_height); } =20 /*************************************** @@ -1101,30 +1101,26 @@ static void cirrus_write_bitblt(CirrusVGAState * s,= unsigned reg_value) * ***************************************/ =20 -static void cirrus_get_offsets(VGACommonState *s1, - uint32_t *pline_offset, - uint32_t *pstart_addr, - uint32_t *pline_compare) +static void cirrus_get_params(VGACommonState *s1, + VGADisplayParams *params) { CirrusVGAState * s =3D container_of(s1, CirrusVGAState, vga); - uint32_t start_addr, line_offset, line_compare; + uint32_t line_offset; =20 line_offset =3D s->vga.cr[0x13] | ((s->vga.cr[0x1b] & 0x10) << 4); line_offset <<=3D 3; - *pline_offset =3D line_offset; + params->line_offset =3D line_offset; =20 - start_addr =3D (s->vga.cr[0x0c] << 8) + params->start_addr =3D (s->vga.cr[0x0c] << 8) | s->vga.cr[0x0d] | ((s->vga.cr[0x1b] & 0x01) << 16) | ((s->vga.cr[0x1b] & 0x0c) << 15) | ((s->vga.cr[0x1d] & 0x80) << 12); - *pstart_addr =3D start_addr; =20 - line_compare =3D s->vga.cr[0x18] | + params->line_compare =3D s->vga.cr[0x18] | ((s->vga.cr[0x07] & 0x10) << 4) | ((s->vga.cr[0x09] & 0x40) << 3); - *pline_compare =3D line_compare; } =20 static uint32_t cirrus_get_bpp16_depth(CirrusVGAState * s) @@ -2925,7 +2921,7 @@ void cirrus_init_common(CirrusVGAState *s, Object *ow= ner, s->linear_mmio_mask =3D s->real_vram_size - 256; =20 s->vga.get_bpp =3D cirrus_get_bpp; - s->vga.get_offsets =3D cirrus_get_offsets; + s->vga.get_params =3D cirrus_get_params; s->vga.get_resolution =3D cirrus_get_resolution; s->vga.cursor_invalidate =3D cirrus_cursor_invalidate; s->vga.cursor_draw_line =3D cirrus_cursor_draw_line; diff --git a/hw/display/vga.c b/hw/display/vga.c index a8b5830a30a..fea26f91232 100644 --- a/hw/display/vga.c +++ b/hw/display/vga.c @@ -1042,52 +1042,40 @@ static int update_palette256(VGACommonState *s) return full_update; } =20 -static void vga_get_offsets(VGACommonState *s, - uint32_t *pline_offset, - uint32_t *pstart_addr, - uint32_t *pline_compare) +static void vga_get_params(VGACommonState *s, + VGADisplayParams *params) { - uint32_t start_addr, line_offset, line_compare; - if (vbe_enabled(s)) { - line_offset =3D s->vbe_line_offset; - start_addr =3D s->vbe_start_addr; - line_compare =3D 65535; + params->line_offset =3D s->vbe_line_offset; + params->start_addr =3D s->vbe_start_addr; + params->line_compare =3D 65535; } else { /* compute line_offset in bytes */ - line_offset =3D s->cr[VGA_CRTC_OFFSET]; - line_offset <<=3D 3; + params->line_offset =3D s->cr[VGA_CRTC_OFFSET] << 3; =20 /* starting address */ - start_addr =3D s->cr[VGA_CRTC_START_LO] | + params->start_addr =3D s->cr[VGA_CRTC_START_LO] | (s->cr[VGA_CRTC_START_HI] << 8); =20 /* line compare */ - line_compare =3D s->cr[VGA_CRTC_LINE_COMPARE] | + params->line_compare =3D s->cr[VGA_CRTC_LINE_COMPARE] | ((s->cr[VGA_CRTC_OVERFLOW] & 0x10) << 4) | ((s->cr[VGA_CRTC_MAX_SCAN] & 0x40) << 3); } - *pline_offset =3D line_offset; - *pstart_addr =3D start_addr; - *pline_compare =3D line_compare; } =20 /* update start_addr and line_offset. Return TRUE if modified */ static int update_basic_params(VGACommonState *s) { int full_update; - uint32_t start_addr, line_offset, line_compare; + VGADisplayParams current; =20 full_update =3D 0; =20 - s->get_offsets(s, &line_offset, &start_addr, &line_compare); + s->get_params(s, ¤t); =20 - if (line_offset !=3D s->line_offset || - start_addr !=3D s->start_addr || - line_compare !=3D s->line_compare) { - s->line_offset =3D line_offset; - s->start_addr =3D start_addr; - s->line_compare =3D line_compare; + if (memcmp(¤t, &s->params, sizeof(current))) { + s->params =3D current; full_update =3D 1; } return full_update; @@ -1188,7 +1176,7 @@ static void vga_draw_text(VGACommonState *s, int full= _update) } full_update |=3D update_basic_params(s); =20 - line_offset =3D s->line_offset; + line_offset =3D s->params.line_offset; =20 vga_get_text_resolution(s, &width, &height, &cw, &cheight); if ((height * width) <=3D 1) { @@ -1227,7 +1215,7 @@ static void vga_draw_text(VGACommonState *s, int full= _update) } =20 cursor_offset =3D ((s->cr[VGA_CRTC_CURSOR_HI] << 8) | - s->cr[VGA_CRTC_CURSOR_LO]) - s->start_addr; + s->cr[VGA_CRTC_CURSOR_LO]) - s->params.start_addr; if (cursor_offset !=3D s->cursor_offset || s->cr[VGA_CRTC_CURSOR_START] !=3D s->cursor_start || s->cr[VGA_CRTC_CURSOR_END] !=3D s->cursor_end) { @@ -1241,7 +1229,7 @@ static void vga_draw_text(VGACommonState *s, int full= _update) s->cursor_start =3D s->cr[VGA_CRTC_CURSOR_START]; s->cursor_end =3D s->cr[VGA_CRTC_CURSOR_END]; } - cursor_ptr =3D s->vram_ptr + (s->start_addr + cursor_offset) * 4; + cursor_ptr =3D s->vram_ptr + (s->params.start_addr + cursor_offset) * = 4; if (now >=3D s->cursor_blink_time) { s->cursor_blink_time =3D now + VGA_TEXT_CURSOR_PERIOD_MS / 2; s->cursor_visible_phase =3D !s->cursor_visible_phase; @@ -1251,7 +1239,7 @@ static void vga_draw_text(VGACommonState *s, int full= _update) linesize =3D surface_stride(surface); ch_attr_ptr =3D s->last_ch_attr; line =3D 0; - offset =3D s->start_addr * 4; + offset =3D s->params.start_addr * 4; for(cy =3D 0; cy < height; cy++) { d1 =3D dest; src =3D s->vram_ptr + offset; @@ -1331,7 +1319,7 @@ static void vga_draw_text(VGACommonState *s, int full= _update) dest +=3D linesize * cheight; line1 =3D line + cheight; offset +=3D line_offset; - if (line < s->line_compare && line1 >=3D s->line_compare) { + if (line < s->params.line_compare && line1 >=3D s->params.line_com= pare) { offset =3D 0; } line =3D line1; @@ -1461,10 +1449,10 @@ static void vga_draw_graphic(VGACommonState *s, int= full_update) disp_width =3D width; depth =3D s->get_bpp(s); =20 - region_start =3D (s->start_addr * 4); - region_end =3D region_start + (ram_addr_t)s->line_offset * height; + region_start =3D (s->params.start_addr * 4); + region_end =3D region_start + (ram_addr_t)s->params.line_offset * heig= ht; region_end +=3D width * depth / 8; /* scanline length */ - region_end -=3D s->line_offset; + region_end -=3D s->params.line_offset; if (region_end > s->vbe_size || depth =3D=3D 0 || depth =3D=3D 15) { /* * We land here on: @@ -1529,7 +1517,7 @@ static void vga_draw_graphic(VGACommonState *s, int f= ull_update) share_surface =3D false; } =20 - if (s->line_offset !=3D s->last_line_offset || + if (s->params.line_offset !=3D s->last_line_offset || disp_width !=3D s->last_width || height !=3D s->last_height || s->last_depth !=3D depth || @@ -1540,12 +1528,12 @@ static void vga_draw_graphic(VGACommonState *s, int= full_update) s->last_scr_height =3D height; s->last_width =3D disp_width; s->last_height =3D height; - s->last_line_offset =3D s->line_offset; + s->last_line_offset =3D s->params.line_offset; s->last_depth =3D depth; s->last_byteswap =3D byteswap; full_update =3D 1; } - if (surface_data(surface) !=3D s->vram_ptr + (s->start_addr * 4) + if (surface_data(surface) !=3D s->vram_ptr + (s->params.start_addr * 4) && is_buffer_shared(surface)) { /* base address changed (page flip) -> shared display surfaces * must be updated with the new base address */ @@ -1555,8 +1543,8 @@ static void vga_draw_graphic(VGACommonState *s, int f= ull_update) if (full_update) { if (share_surface) { surface =3D qemu_create_displaysurface_from(disp_width, - height, format, s->line_offset, - s->vram_ptr + (s->start_addr * 4)); + height, format, s->params.line_offset, + s->vram_ptr + (s->params.start_addr * 4)); dpy_gfx_replace_surface(s->con, surface); } else { qemu_console_resize(s->con, disp_width, height); @@ -1620,9 +1608,9 @@ static void vga_draw_graphic(VGACommonState *s, int f= ull_update) #if 0 printf("w=3D%d h=3D%d v=3D%d line_offset=3D%d cr[0x09]=3D0x%02x cr[0x1= 7]=3D0x%02x linecmp=3D%d sr[0x01]=3D0x%02x\n", width, height, v, line_offset, s->cr[9], s->cr[VGA_CRTC_MODE], - s->line_compare, sr(s, VGA_SEQ_CLOCK_MODE)); + s->params.line_compare, sr(s, VGA_SEQ_CLOCK_MODE)); #endif - addr1 =3D (s->start_addr * 4); + addr1 =3D (s->params.start_addr * 4); bwidth =3D DIV_ROUND_UP(width * bits, 8); y_start =3D -1; d =3D surface_data(surface); @@ -1630,7 +1618,7 @@ static void vga_draw_graphic(VGACommonState *s, int f= ull_update) y1 =3D 0; =20 if (!full_update) { - if (s->line_compare < height) { + if (s->params.line_compare < height) { /* split screen mode */ region_start =3D 0; } @@ -1686,14 +1674,14 @@ static void vga_draw_graphic(VGACommonState *s, int= full_update) if (!multi_run) { mask =3D (s->cr[VGA_CRTC_MODE] & 3) ^ 3; if ((y1 & mask) =3D=3D mask) - addr1 +=3D s->line_offset; + addr1 +=3D s->params.line_offset; y1++; multi_run =3D multi_scan; } else { multi_run--; } /* line compare acts on the displayed lines */ - if (y =3D=3D s->line_compare) + if (y =3D=3D s->params.line_compare) addr1 =3D 0; d +=3D linesize; } @@ -1810,9 +1798,7 @@ void vga_common_reset(VGACommonState *s) s->graphic_mode =3D -1; /* force full update */ s->shift_control =3D 0; s->double_scan =3D 0; - s->line_offset =3D 0; - s->line_compare =3D 0; - s->start_addr =3D 0; + memset(&s->params, '\0', sizeof(s->params)); s->plane_updated =3D 0; s->last_cw =3D 0; s->last_ch =3D 0; @@ -1934,7 +1920,7 @@ static void vga_update_text(void *opaque, console_ch_= t *chardata) =20 /* Update "hardware" cursor */ cursor_offset =3D ((s->cr[VGA_CRTC_CURSOR_HI] << 8) | - s->cr[VGA_CRTC_CURSOR_LO]) - s->start_addr; + s->cr[VGA_CRTC_CURSOR_LO]) - s->params.start_addr; if (cursor_offset !=3D s->cursor_offset || s->cr[VGA_CRTC_CURSOR_START] !=3D s->cursor_start || s->cr[VGA_CRTC_CURSOR_END] !=3D s->cursor_end || full_update) { @@ -1950,7 +1936,7 @@ static void vga_update_text(void *opaque, console_ch_= t *chardata) s->cursor_end =3D s->cr[VGA_CRTC_CURSOR_END]; } =20 - src =3D (uint32_t *) s->vram_ptr + s->start_addr; + src =3D (uint32_t *) s->vram_ptr + s->params.start_addr; dst =3D chardata; =20 if (full_update) { @@ -2195,7 +2181,7 @@ bool vga_common_init(VGACommonState *s, Object *obj, = Error **errp) xen_register_framebuffer(&s->vram); s->vram_ptr =3D memory_region_get_ram_ptr(&s->vram); s->get_bpp =3D vga_get_bpp; - s->get_offsets =3D vga_get_offsets; + s->get_params =3D vga_get_params; s->get_resolution =3D vga_get_resolution; s->hw_ops =3D &vga_ops; switch (vga_retrace_method) { --=20 2.43.0 From nobody Thu Nov 14 07:04:05 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1705580849; cv=none; d=zohomail.com; s=zohoarc; b=KTwf+R6wiaOtgbK2agA8JVsVOR5OLX7cGBnSWB8OhaV3aWnDH/k8nKfoBL8HoX7HL9jQ2j838kiwHALidXithqUZyx00X5W1cyBLyRedFaMs0+J0/bB8Hdpwq0lGKZzsGnJHR9R0T9kkO8MLRi3uLXFb8vOMPoD5tGMEKXZn6xo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705580849; h=Content-Type: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=eBO1lrsnPEtJ2wirtQ5cQNGuGOk+ezHaN3UBTfhCnlg=; b=ZTaBDawZXCKdveOc5I1KYOtcC13VQI60Ez0o4y4cVVfrmmLpkQxTeORALZIIEO3rYPmmT925u34JUSDDQE+mwWuRMFVVW8SVZ34J4iJGyd9jbTeBgIhFJwdtOp14stdqB1NQ3cj1XmfezJepujkkd9DyIAExXchj7euELDuh4Mk= 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 1705580848824854.2276142424563; Thu, 18 Jan 2024 04:27:28 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rQRRl-0003Qd-Ei; Thu, 18 Jan 2024 07:24:37 -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 1rQRRg-0003Ho-4N for qemu-devel@nongnu.org; Thu, 18 Jan 2024 07:24:32 -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 1rQRRe-0005n7-FV for qemu-devel@nongnu.org; Thu, 18 Jan 2024 07:24:31 -0500 Received: from mail-lf1-f72.google.com (mail-lf1-f72.google.com [209.85.167.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-73-3W9szgaRP2ieVvZDgRDCDw-1; Thu, 18 Jan 2024 07:24:25 -0500 Received: by mail-lf1-f72.google.com with SMTP id 2adb3069b0e04-50e55470b49so9819323e87.0 for ; Thu, 18 Jan 2024 04:24:24 -0800 (PST) Received: from [192.168.10.118] ([2001:b07:6468:f312:4783:a68:c1ee:15c5]) by smtp.gmail.com with ESMTPSA id q8-20020a170906360800b00a2bd52d2a84sm9012442ejb.200.2024.01.18.04.24.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 04:24:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705580666; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eBO1lrsnPEtJ2wirtQ5cQNGuGOk+ezHaN3UBTfhCnlg=; b=WrcgY6rAxCGZ52IGI33BmtyUDa2Zuw9D6T+60Qv5TqapbLUmr5n11jJBs5IjrwmKn0/fGv xrW5QylRTBWjobnbQKe6pgZeuNL8mI8hzrrS/u9ieBuZsp9pXMkzbGIR1rfkfpKQtxZ0e1 FBMLNmvdJ0pZUNGZI8Hf2FPz1a25G+0= X-MC-Unique: 3W9szgaRP2ieVvZDgRDCDw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705580663; x=1706185463; 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=eBO1lrsnPEtJ2wirtQ5cQNGuGOk+ezHaN3UBTfhCnlg=; b=s1EysoATDYcIIVYwIawF/BeHnq+HCCqCmREqPkJCQKhmBId9ARjn7ru5yEya5aAk1L WBTuL6OAzMpICuHUwdyRh4o/yenF7K1ssoNHRStGrMieauwewLEfKgI6lauQOY1oz7mj onWC2Z+nTzEiSorQUGzUbFNO6FsJIue/5xtVghlWLtGbmvLQuF5psBz4s36NwlWwmWoq hHXPF0czMarSZUbaV6Q4rzWQpbYFtjr4JUzG9Xk+gfoRP0ZZySnhuzFRPMRqsWdHn7mo gHbGSx0I2Nrmqyo0d2uo2Rk+ksuhNUOPE4GwMUlNR8SHQscqLMoFd687HBFt30kZk/x2 mBbw== X-Gm-Message-State: AOJu0YxDwIIxzOJMN5VLipfXA4NiB8JsK8HZdVs4TMF9Jr8dXSwQJT58 IfqJdChneY3MAwwiBqOJ2hVvx7YaSmVW/EjvJXoXiPF0FJSypkeSL03EKc9DluVfCqsECQgb4wO rZpOZq9Fg+uzQDEyet2mHpJijM3I311kvsy5eu6Gyl8F26V0bdDQ//8k26igYGNDjwbjM90r/vR AtRfQlWY6rniprK3mgGkz1TO3jIlOLuDqtFtGt X-Received: by 2002:a05:6512:48c6:b0:50f:98d:35df with SMTP id er6-20020a05651248c600b0050f098d35dfmr356165lfb.5.1705580663116; Thu, 18 Jan 2024 04:24:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IE9IXMytBtaQqrKnADivLdmKrcRnL7TSizJOpYSQgIOmOo7MtwHlSuZ9t1usTXjEwrj47J1Wg== X-Received: by 2002:a05:6512:48c6:b0:50f:98d:35df with SMTP id er6-20020a05651248c600b0050f098d35dfmr356160lfb.5.1705580662767; Thu, 18 Jan 2024 04:24:22 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 03/16] vga: mask addresses in non-VESA modes to 256k Date: Thu, 18 Jan 2024 13:24:03 +0100 Message-ID: <20240118122416.9209-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240118122416.9209-1-pbonzini@redhat.com> References: <20240118122416.9209-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: -38 X-Spam_score: -3.9 X-Spam_bar: --- X-Spam_report: (-3.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.806, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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 @redhat.com) X-ZM-MESSAGEID: 1705580850276100013 Content-Type: text/plain; charset="utf-8" This allows setting the start address to a high value, and reading the bottom of the screen from the beginning of VRAM. Commander Keen 4 ("Goodbye, Galaxy!") relies on this behavior. Signed-off-by: Paolo Bonzini --- hw/display/vga-helpers.h | 9 +++++---- hw/display/vga.c | 3 +++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/hw/display/vga-helpers.h b/hw/display/vga-helpers.h index 10e9cfd40a0..83b9a15604a 100644 --- a/hw/display/vga-helpers.h +++ b/hw/display/vga-helpers.h @@ -108,7 +108,7 @@ static void vga_draw_line2(VGACommonState *vga, uint8_t= *d, plane_mask =3D mask16[vga->ar[VGA_ATC_PLANE_ENABLE] & 0xf]; width >>=3D 3; for(x =3D 0; x < width; x++) { - data =3D vga_read_dword_le(vga, addr); + data =3D vga_read_dword_le(vga, addr & (VGA_VRAM_SIZE - 1)); data &=3D plane_mask; v =3D expand2[GET_PLANE(data, 0)]; v |=3D expand2[GET_PLANE(data, 2)] << 2; @@ -144,7 +144,7 @@ static void vga_draw_line2d2(VGACommonState *vga, uint8= _t *d, plane_mask =3D mask16[vga->ar[VGA_ATC_PLANE_ENABLE] & 0xf]; width >>=3D 3; for(x =3D 0; x < width; x++) { - data =3D vga_read_dword_le(vga, addr); + data =3D vga_read_dword_le(vga, addr & (VGA_VRAM_SIZE - 1)); data &=3D plane_mask; v =3D expand2[GET_PLANE(data, 0)]; v |=3D expand2[GET_PLANE(data, 2)] << 2; @@ -177,7 +177,7 @@ static void vga_draw_line4(VGACommonState *vga, uint8_t= *d, plane_mask =3D mask16[vga->ar[VGA_ATC_PLANE_ENABLE] & 0xf]; width >>=3D 3; for(x =3D 0; x < width; x++) { - data =3D vga_read_dword_le(vga, addr); + data =3D vga_read_dword_le(vga, addr & (VGA_VRAM_SIZE - 1)); data &=3D plane_mask; v =3D expand4[GET_PLANE(data, 0)]; v |=3D expand4[GET_PLANE(data, 1)] << 1; @@ -209,7 +209,7 @@ static void vga_draw_line4d2(VGACommonState *vga, uint8= _t *d, plane_mask =3D mask16[vga->ar[VGA_ATC_PLANE_ENABLE] & 0xf]; width >>=3D 3; for(x =3D 0; x < width; x++) { - data =3D vga_read_dword_le(vga, addr); + data =3D vga_read_dword_le(vga, addr & (VGA_VRAM_SIZE - 1)); data &=3D plane_mask; v =3D expand4[GET_PLANE(data, 0)]; v |=3D expand4[GET_PLANE(data, 1)] << 1; @@ -242,6 +242,7 @@ static void vga_draw_line8d2(VGACommonState *vga, uint8= _t *d, palette =3D vga->last_palette; width >>=3D 3; for(x =3D 0; x < width; x++) { + addr &=3D VGA_VRAM_SIZE - 1; PUT_PIXEL2(d, 0, palette[vga_read_byte(vga, addr + 0)]); PUT_PIXEL2(d, 1, palette[vga_read_byte(vga, addr + 1)]); PUT_PIXEL2(d, 2, palette[vga_read_byte(vga, addr + 2)]); diff --git a/hw/display/vga.c b/hw/display/vga.c index fea26f91232..5bf4d14f342 100644 --- a/hw/display/vga.c +++ b/hw/display/vga.c @@ -47,6 +47,9 @@ bool have_vga =3D true; /* 16 state changes per vertical frame @60 Hz */ #define VGA_TEXT_CURSOR_PERIOD_MS (1000 * 2 * 16 / 60) =20 +/* Address mask for non-VESA modes. */ +#define VGA_VRAM_SIZE (256 * KiB) + /* * Video Graphics Array (VGA) * --=20 2.43.0 From nobody Thu Nov 14 07:04:05 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1705580790; cv=none; d=zohomail.com; s=zohoarc; b=cOEtsbamefFqxUEHy9gmuCoP1gxyOX0OMsraen/kmY67vsB0XQGxPo39NfHu5ArR729AYoRHxihYz6HDib2TgTaIU3LFM20DNsCmwWE0K8YCN+1UU4hFKt67yfhre29JG5siSTU4XKxCB0jG50Vd84Rnj6D1be76JLoGnSZKlbE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705580790; h=Content-Type: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=lHKtWY2aIb/G0jxcyX7kG5jqfnNfNv6gtD29X1mXs9k=; b=L81rfHLxr7aA4PSDkUXmHsNcxQGpJWSJ9Oqq+t/uoVnD9pPVhJlaMm12fFI2aF6lCx8AvWq5ywLqkO0JU12fSiH1F0PAv4fqKHPM+OIP0898cz+jSjz9ZTnqsZAmqHDzTmY8sl9O1/SqQvcCqyCM5/RWWpdoZ4DCMQy76bpAzEY= 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 170558079050973.15166510723543; Thu, 18 Jan 2024 04:26:30 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rQRSG-0004rp-Sq; Thu, 18 Jan 2024 07:25:08 -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 1rQRSB-0004nF-5W for qemu-devel@nongnu.org; Thu, 18 Jan 2024 07:25:03 -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 1rQRS7-0006UI-Vg for qemu-devel@nongnu.org; Thu, 18 Jan 2024 07:25:02 -0500 Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-653--9yV4l_7NM21vmqjRPQRrA-1; Thu, 18 Jan 2024 07:24:29 -0500 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-a2ea2b5e8b9so103512666b.3 for ; Thu, 18 Jan 2024 04:24:27 -0800 (PST) Received: from [192.168.10.118] ([2001:b07:6468:f312:4783:a68:c1ee:15c5]) by smtp.gmail.com with ESMTPSA id e4-20020a170906c00400b00a298adde5a1sm9025147ejz.189.2024.01.18.04.24.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 04:24:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705580687; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lHKtWY2aIb/G0jxcyX7kG5jqfnNfNv6gtD29X1mXs9k=; b=IX8PrzDf121Ebus5dfBeiwftlR1cD+h944a0RB4c5vTvYNsagxAKMzZLOGB3umxn1JvWS1 UxTVdxTwToxTaZXtzbJcSugE37EmuZ7zX7XAgIygWBomN9M2uqWApS1HDSlPFPjHbTFTw6 DOMSpBNf4iFq4V99qN+IsZg/B51O9us= X-MC-Unique: -9yV4l_7NM21vmqjRPQRrA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705580666; x=1706185466; 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=lHKtWY2aIb/G0jxcyX7kG5jqfnNfNv6gtD29X1mXs9k=; b=j6WNwWVMs54G8nnlxteiSfxFcRuoaPoreAqbUY+2DpFFRzIpFPJIF8sBd86/flz+Rc 9NLVIDqf3movJo/cp2DJZYK3bUmckOUtWy9aDyatimnFwDiH4xeXBGg0bc3q3Zyvc9Oz JbtCK8S/XC+U8xeUQ/9UU7AJQr4t1N59WZBIQsNOmzURwJj5r8jY3/B3rbv7cMJe7AWd isHdKYlXsE5+3HYLYt2AGwCAaWBv8nv5CornWZ6eBS8RF29h/sViAns+fR2KNwE2dtr8 VqvokI4/L3FBgaHuD4IIjzKXz4JxcEFL/nMJ/XMzunb70Jh8Kfr4SNrmqTNU6ZHlFSug fhgA== X-Gm-Message-State: AOJu0YxriB8kB5v+R4Di1rV/anmLdVtIGO/NnYT2/NJGbmJCYP7+DMd+ e3UNAUlF7+LWmQVQkiaJRjAUQjR1gpD7z3xVLylJdPbDjdOCrS+9qRYc94dtecGWtLcrth885wl ziUatGlre6zuq3C3Ap5qwT3xO1cH2pbCqm9AHlIukcRHBXyvPDbG4iDguis6zYFGHYUHFmBFENv UdA7lUZDuZysF3Nh9M/S02yVa6OpPpGMBE1vmo X-Received: by 2002:a17:906:29cd:b0:a2b:9a38:dcf5 with SMTP id y13-20020a17090629cd00b00a2b9a38dcf5mr405455eje.62.1705580665598; Thu, 18 Jan 2024 04:24:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IGInhRhFddKeLEFZdB6+/clF5/z/sBBwWBCc9kpX7dJqnAoj7IglpcYy4CBMx63CEzCmWEiRg== X-Received: by 2002:a17:906:29cd:b0:a2b:9a38:dcf5 with SMTP id y13-20020a17090629cd00b00a2b9a38dcf5mr405447eje.62.1705580664981; Thu, 18 Jan 2024 04:24:24 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 04/16] vga: implement horizontal pel panning in graphics modes Date: Thu, 18 Jan 2024 13:24:04 +0100 Message-ID: <20240118122416.9209-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240118122416.9209-1-pbonzini@redhat.com> References: <20240118122416.9209-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: -38 X-Spam_score: -3.9 X-Spam_bar: --- X-Spam_report: (-3.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.806, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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 @redhat.com) X-ZM-MESSAGEID: 1705580792201100003 Content-Type: text/plain; charset="utf-8" This implements smooth scrolling, as used for example by Commander Keen and Second Reality. Unfortunately, this is not enough to avoid tearing in Commander Keen, because sometimes the wrong start address is used for a frame. On real EGA, the panning register is sampled on every line, while the display start is latched for the next frame at the start of the vertical retrace. On real VGA, the panning register is also latched, but at the end of the vertical retrace. It looks like Keen exploits this by only waiting for horizontal retrace when setting the display start, but implementing it breaks the 256-color Keen games... Signed-off-by: Paolo Bonzini --- hw/display/vga-helpers.h | 100 ++++++++++++++++++++++++++++----------- hw/display/vga_int.h | 3 ++ hw/display/cirrus_vga.c | 4 ++ hw/display/vga.c | 36 ++++++++++++-- 4 files changed, 111 insertions(+), 32 deletions(-) diff --git a/hw/display/vga-helpers.h b/hw/display/vga-helpers.h index 83b9a15604a..29933562c45 100644 --- a/hw/display/vga-helpers.h +++ b/hw/display/vga-helpers.h @@ -98,14 +98,19 @@ static void vga_draw_glyph9(uint8_t *d, int linesize, /* * 4 color mode */ -static void vga_draw_line2(VGACommonState *vga, uint8_t *d, - uint32_t addr, int width) +static void *vga_draw_line2(VGACommonState *vga, uint8_t *d, + uint32_t addr, int width, int hpel) { uint32_t plane_mask, *palette, data, v; int x; =20 palette =3D vga->last_palette; plane_mask =3D mask16[vga->ar[VGA_ATC_PLANE_ENABLE] & 0xf]; + hpel &=3D 7; + if (hpel) { + width +=3D 8; + d =3D vga->panning_buf; + } width >>=3D 3; for(x =3D 0; x < width; x++) { data =3D vga_read_dword_le(vga, addr & (VGA_VRAM_SIZE - 1)); @@ -126,6 +131,7 @@ static void vga_draw_line2(VGACommonState *vga, uint8_t= *d, d +=3D 32; addr +=3D 4; } + return hpel ? vga->panning_buf + 4 * hpel : NULL; } =20 #define PUT_PIXEL2(d, n, v) \ @@ -134,14 +140,19 @@ static void vga_draw_line2(VGACommonState *vga, uint8= _t *d, /* * 4 color mode, dup2 horizontal */ -static void vga_draw_line2d2(VGACommonState *vga, uint8_t *d, - uint32_t addr, int width) +static void *vga_draw_line2d2(VGACommonState *vga, uint8_t *d, + uint32_t addr, int width, int hpel) { uint32_t plane_mask, *palette, data, v; int x; =20 palette =3D vga->last_palette; plane_mask =3D mask16[vga->ar[VGA_ATC_PLANE_ENABLE] & 0xf]; + hpel &=3D 7; + if (hpel) { + width +=3D 8; + d =3D vga->panning_buf; + } width >>=3D 3; for(x =3D 0; x < width; x++) { data =3D vga_read_dword_le(vga, addr & (VGA_VRAM_SIZE - 1)); @@ -162,19 +173,25 @@ static void vga_draw_line2d2(VGACommonState *vga, uin= t8_t *d, d +=3D 64; addr +=3D 4; } + return hpel ? vga->panning_buf + 8 * hpel : NULL; } =20 /* * 16 color mode */ -static void vga_draw_line4(VGACommonState *vga, uint8_t *d, - uint32_t addr, int width) +static void *vga_draw_line4(VGACommonState *vga, uint8_t *d, + uint32_t addr, int width, int hpel) { uint32_t plane_mask, data, v, *palette; int x; =20 palette =3D vga->last_palette; plane_mask =3D mask16[vga->ar[VGA_ATC_PLANE_ENABLE] & 0xf]; + hpel &=3D 7; + if (hpel) { + width +=3D 8; + d =3D vga->panning_buf; + } width >>=3D 3; for(x =3D 0; x < width; x++) { data =3D vga_read_dword_le(vga, addr & (VGA_VRAM_SIZE - 1)); @@ -194,19 +211,25 @@ static void vga_draw_line4(VGACommonState *vga, uint8= _t *d, d +=3D 32; addr +=3D 4; } + return hpel ? vga->panning_buf + 4 * hpel : NULL; } =20 /* * 16 color mode, dup2 horizontal */ -static void vga_draw_line4d2(VGACommonState *vga, uint8_t *d, - uint32_t addr, int width) +static void *vga_draw_line4d2(VGACommonState *vga, uint8_t *d, + uint32_t addr, int width, int hpel) { uint32_t plane_mask, data, v, *palette; int x; =20 palette =3D vga->last_palette; plane_mask =3D mask16[vga->ar[VGA_ATC_PLANE_ENABLE] & 0xf]; + hpel &=3D 7; + if (hpel) { + width +=3D 8; + d =3D vga->panning_buf; + } width >>=3D 3; for(x =3D 0; x < width; x++) { data =3D vga_read_dword_le(vga, addr & (VGA_VRAM_SIZE - 1)); @@ -226,6 +249,7 @@ static void vga_draw_line4d2(VGACommonState *vga, uint8= _t *d, d +=3D 64; addr +=3D 4; } + return hpel ? vga->panning_buf + 8 * hpel : NULL; } =20 /* @@ -233,13 +257,18 @@ static void vga_draw_line4d2(VGACommonState *vga, uin= t8_t *d, * * XXX: add plane_mask support (never used in standard VGA modes) */ -static void vga_draw_line8d2(VGACommonState *vga, uint8_t *d, - uint32_t addr, int width) +static void *vga_draw_line8d2(VGACommonState *vga, uint8_t *d, + uint32_t addr, int width, int hpel) { uint32_t *palette; int x; =20 palette =3D vga->last_palette; + hpel =3D (hpel >> 1) & 3; + if (hpel) { + width +=3D 8; + d =3D vga->panning_buf; + } width >>=3D 3; for(x =3D 0; x < width; x++) { addr &=3D VGA_VRAM_SIZE - 1; @@ -250,6 +279,7 @@ static void vga_draw_line8d2(VGACommonState *vga, uint8= _t *d, d +=3D 32; addr +=3D 4; } + return hpel ? vga->panning_buf + 8 * hpel : NULL; } =20 /* @@ -257,13 +287,18 @@ static void vga_draw_line8d2(VGACommonState *vga, uin= t8_t *d, * * XXX: add plane_mask support (never used in standard VGA modes) */ -static void vga_draw_line8(VGACommonState *vga, uint8_t *d, - uint32_t addr, int width) +static void *vga_draw_line8(VGACommonState *vga, uint8_t *d, + uint32_t addr, int width, int hpel) { uint32_t *palette; int x; =20 palette =3D vga->last_palette; + hpel =3D (hpel >> 1) & 3; + if (hpel) { + width +=3D 8; + d =3D vga->panning_buf; + } width >>=3D 3; for(x =3D 0; x < width; x++) { ((uint32_t *)d)[0] =3D palette[vga_read_byte(vga, addr + 0)]; @@ -277,13 +312,14 @@ static void vga_draw_line8(VGACommonState *vga, uint8= _t *d, d +=3D 32; addr +=3D 8; } + return hpel ? vga->panning_buf + 4 * hpel : NULL; } =20 /* * 15 bit color */ -static void vga_draw_line15_le(VGACommonState *vga, uint8_t *d, - uint32_t addr, int width) +static void *vga_draw_line15_le(VGACommonState *vga, uint8_t *d, + uint32_t addr, int width, int hpel) { int w; uint32_t v, r, g, b; @@ -298,10 +334,11 @@ static void vga_draw_line15_le(VGACommonState *vga, u= int8_t *d, addr +=3D 2; d +=3D 4; } while (--w !=3D 0); + return NULL; } =20 -static void vga_draw_line15_be(VGACommonState *vga, uint8_t *d, - uint32_t addr, int width) +static void *vga_draw_line15_be(VGACommonState *vga, uint8_t *d, + uint32_t addr, int width, int hpel) { int w; uint32_t v, r, g, b; @@ -316,13 +353,14 @@ static void vga_draw_line15_be(VGACommonState *vga, u= int8_t *d, addr +=3D 2; d +=3D 4; } while (--w !=3D 0); + return NULL; } =20 /* * 16 bit color */ -static void vga_draw_line16_le(VGACommonState *vga, uint8_t *d, - uint32_t addr, int width) +static void *vga_draw_line16_le(VGACommonState *vga, uint8_t *d, + uint32_t addr, int width, int hpel) { int w; uint32_t v, r, g, b; @@ -337,10 +375,11 @@ static void vga_draw_line16_le(VGACommonState *vga, u= int8_t *d, addr +=3D 2; d +=3D 4; } while (--w !=3D 0); + return NULL; } =20 -static void vga_draw_line16_be(VGACommonState *vga, uint8_t *d, - uint32_t addr, int width) +static void *vga_draw_line16_be(VGACommonState *vga, uint8_t *d, + uint32_t addr, int width, int hpel) { int w; uint32_t v, r, g, b; @@ -355,13 +394,14 @@ static void vga_draw_line16_be(VGACommonState *vga, u= int8_t *d, addr +=3D 2; d +=3D 4; } while (--w !=3D 0); + return NULL; } =20 /* * 24 bit color */ -static void vga_draw_line24_le(VGACommonState *vga, uint8_t *d, - uint32_t addr, int width) +static void *vga_draw_line24_le(VGACommonState *vga, uint8_t *d, + uint32_t addr, int width, int hpel) { int w; uint32_t r, g, b; @@ -375,10 +415,11 @@ static void vga_draw_line24_le(VGACommonState *vga, u= int8_t *d, addr +=3D 3; d +=3D 4; } while (--w !=3D 0); + return NULL; } =20 -static void vga_draw_line24_be(VGACommonState *vga, uint8_t *d, - uint32_t addr, int width) +static void *vga_draw_line24_be(VGACommonState *vga, uint8_t *d, + uint32_t addr, int width, int hpel) { int w; uint32_t r, g, b; @@ -392,13 +433,14 @@ static void vga_draw_line24_be(VGACommonState *vga, u= int8_t *d, addr +=3D 3; d +=3D 4; } while (--w !=3D 0); + return NULL; } =20 /* * 32 bit color */ -static void vga_draw_line32_le(VGACommonState *vga, uint8_t *d, - uint32_t addr, int width) +static void *vga_draw_line32_le(VGACommonState *vga, uint8_t *d, + uint32_t addr, int width, int hpel) { int w; uint32_t r, g, b; @@ -412,10 +454,11 @@ static void vga_draw_line32_le(VGACommonState *vga, u= int8_t *d, addr +=3D 4; d +=3D 4; } while (--w !=3D 0); + return NULL; } =20 -static void vga_draw_line32_be(VGACommonState *vga, uint8_t *d, - uint32_t addr, int width) +static void *vga_draw_line32_be(VGACommonState *vga, uint8_t *d, + uint32_t addr, int width, int hpel) { int w; uint32_t r, g, b; @@ -429,4 +472,5 @@ static void vga_draw_line32_be(VGACommonState *vga, uin= t8_t *d, addr +=3D 4; d +=3D 4; } while (--w !=3D 0); + return NULL; } diff --git a/hw/display/vga_int.h b/hw/display/vga_int.h index 6be61e04284..876a1d3697b 100644 --- a/hw/display/vga_int.h +++ b/hw/display/vga_int.h @@ -60,6 +60,8 @@ typedef struct VGADisplayParams { uint32_t line_offset; uint32_t start_addr; uint32_t line_compare; + uint8_t hpel; + bool hpel_split; } VGADisplayParams; =20 typedef struct VGACommonState { @@ -111,6 +113,7 @@ typedef struct VGACommonState { /* display refresh support */ QemuConsole *con; uint32_t font_offsets[2]; + uint8_t *panning_buf; int graphic_mode; uint8_t shift_control; uint8_t double_scan; diff --git a/hw/display/cirrus_vga.c b/hw/display/cirrus_vga.c index e637e5a816e..150883a9716 100644 --- a/hw/display/cirrus_vga.c +++ b/hw/display/cirrus_vga.c @@ -43,6 +43,7 @@ #include "hw/qdev-properties.h" #include "migration/vmstate.h" #include "ui/pixel_ops.h" +#include "vga_regs.h" #include "cirrus_vga_internal.h" #include "qom/object.h" #include "ui/console.h" @@ -1121,6 +1122,9 @@ static void cirrus_get_params(VGACommonState *s1, params->line_compare =3D s->vga.cr[0x18] | ((s->vga.cr[0x07] & 0x10) << 4) | ((s->vga.cr[0x09] & 0x40) << 3); + + params->hpel =3D s->vga.ar[VGA_ATC_PEL]; + params->hpel_split =3D s->vga.ar[VGA_ATC_MODE] & 0x20; } =20 static uint32_t cirrus_get_bpp16_depth(CirrusVGAState * s) diff --git a/hw/display/vga.c b/hw/display/vga.c index 5bf4d14f342..a39f802ab7e 100644 --- a/hw/display/vga.c +++ b/hw/display/vga.c @@ -50,6 +50,13 @@ bool have_vga =3D true; /* Address mask for non-VESA modes. */ #define VGA_VRAM_SIZE (256 * KiB) =20 +/* This value corresponds to a shift of zero pixels + * in 9-dot text mode. In other modes, bit 3 is undefined; + * we just ignore it, so that 8 corresponds to zero pixels + * in all modes. + */ +#define VGA_HPEL_NEUTRAL 8 + /* * Video Graphics Array (VGA) * @@ -984,8 +991,8 @@ void vga_mem_writeb(VGACommonState *s, hwaddr addr, uin= t32_t val) } } =20 -typedef void vga_draw_line_func(VGACommonState *s1, uint8_t *d, - uint32_t srcaddr, int width); +typedef void *vga_draw_line_func(VGACommonState *s1, uint8_t *d, + uint32_t srcaddr, int width, int hpel); =20 #include "vga-access.h" #include "vga-helpers.h" @@ -1052,6 +1059,8 @@ static void vga_get_params(VGACommonState *s, params->line_offset =3D s->vbe_line_offset; params->start_addr =3D s->vbe_start_addr; params->line_compare =3D 65535; + params->hpel =3D VGA_HPEL_NEUTRAL; + params->hpel_split =3D false; } else { /* compute line_offset in bytes */ params->line_offset =3D s->cr[VGA_CRTC_OFFSET] << 3; @@ -1064,6 +1073,9 @@ static void vga_get_params(VGACommonState *s, params->line_compare =3D s->cr[VGA_CRTC_LINE_COMPARE] | ((s->cr[VGA_CRTC_OVERFLOW] & 0x10) << 4) | ((s->cr[VGA_CRTC_MAX_SCAN] & 0x40) << 3); + + params->hpel =3D s->ar[VGA_ATC_PEL]; + params->hpel_split =3D s->ar[VGA_ATC_MODE] & 0x20; } } =20 @@ -1435,6 +1447,7 @@ static void vga_draw_graphic(VGACommonState *s, int f= ull_update) ram_addr_t page0, page1, region_start, region_end; DirtyBitmapSnapshot *snap =3D NULL; int disp_width, multi_scan, multi_run; + int hpel; uint8_t *d; uint32_t v, addr1, addr; vga_draw_line_func *vga_draw_line =3D NULL; @@ -1534,6 +1547,9 @@ static void vga_draw_graphic(VGACommonState *s, int f= ull_update) s->last_line_offset =3D s->params.line_offset; s->last_depth =3D depth; s->last_byteswap =3D byteswap; + /* 16 extra pixels are needed for double-width planar modes. */ + s->panning_buf =3D g_realloc(s->panning_buf, + (disp_width + 16) * sizeof(uint32_t)); full_update =3D 1; } if (surface_data(surface) !=3D s->vram_ptr + (s->params.start_addr * 4) @@ -1613,8 +1629,12 @@ static void vga_draw_graphic(VGACommonState *s, int = full_update) width, height, v, line_offset, s->cr[9], s->cr[VGA_CRTC_MODE], s->params.line_compare, sr(s, VGA_SEQ_CLOCK_MODE)); #endif + hpel =3D bits <=3D 8 ? s->params.hpel : 0; addr1 =3D (s->params.start_addr * 4); bwidth =3D DIV_ROUND_UP(width * bits, 8); + if (hpel) { + bwidth +=3D 4; + } y_start =3D -1; d =3D surface_data(surface); linesize =3D surface_stride(surface); @@ -1662,7 +1682,11 @@ static void vga_draw_graphic(VGACommonState *s, int = full_update) if (y_start < 0) y_start =3D y; if (!(is_buffer_shared(surface))) { - vga_draw_line(s, d, addr, width); + uint8_t *p; + p =3D vga_draw_line(s, d, addr, width, hpel); + if (p) { + memcpy(d, p, disp_width * sizeof(uint32_t)); + } if (s->cursor_draw_line) s->cursor_draw_line(s, d, y); } @@ -1684,8 +1708,12 @@ static void vga_draw_graphic(VGACommonState *s, int = full_update) multi_run--; } /* line compare acts on the displayed lines */ - if (y =3D=3D s->params.line_compare) + if (y =3D=3D s->params.line_compare) { + if (s->params.hpel_split) { + hpel =3D VGA_HPEL_NEUTRAL; + } addr1 =3D 0; + } d +=3D linesize; } if (y_start >=3D 0) { --=20 2.43.0 From nobody Thu Nov 14 07:04:05 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1705580782; cv=none; d=zohomail.com; s=zohoarc; b=QeCdLj3RjIk5ugRHI6iOQtrq3bk/ebTqim7iegKcqbBMlU5eXFkSOSYYoAVLZPM8yIBZc679HBCWWXnHncmHDfWRYJVmHaYsUH3AJkxWLjLY+ako6gyzoSV0UG7Mog5ibfGbsaGJaeEiHVulvd1fdbdkGArf7B/e6i1OIR8KBAo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705580782; h=Content-Type: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=/VVeA71Dmkqh48AQEKSvnskR8Cu+XOI6j0l+YjpNLD4=; b=m56Bk//R6r9PgvMvQqoFl0EAZ5/SHBPGs4VXU1CcGMBZjbReV2H+sWqMfN+rvbaS8cN+ierfn8ijlbtIOxMB2DKcCuDtpI0erk6UwunneWOQEG/JwxHOlrWzfOJ0V9ykAhHo3yNw05JKVj9opsWiiVl27vsP6Jh2esd52uvTaWA= 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 1705580782176207.57416852583992; Thu, 18 Jan 2024 04:26:22 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rQRRr-0003W4-Jk; Thu, 18 Jan 2024 07:24:45 -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 1rQRRi-0003L0-8K for qemu-devel@nongnu.org; Thu, 18 Jan 2024 07:24:34 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rQRRe-0005qA-Ic for qemu-devel@nongnu.org; Thu, 18 Jan 2024 07:24:33 -0500 Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-670-FXTfme9gODq7MQbyn3LHRg-1; Thu, 18 Jan 2024 07:24:27 -0500 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-a2b762cfdafso470818366b.1 for ; Thu, 18 Jan 2024 04:24:27 -0800 (PST) Received: from [192.168.10.118] ([2001:b07:6468:f312:4783:a68:c1ee:15c5]) by smtp.gmail.com with ESMTPSA id 23-20020a170906311700b00a269b4692a9sm6728146ejx.84.2024.01.18.04.24.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 04:24:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705580669; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/VVeA71Dmkqh48AQEKSvnskR8Cu+XOI6j0l+YjpNLD4=; b=b1XJhRnwkiOCwr3IuAMWH4SLJ/EsBM1g1NSCVadgqCq0FVrzY0OKmPF+oALkvKtzOLm+1/ W0teXIBPjWyWAPU5qMnGMs/TEUyM8uGpXGuDQc6pxr5yFsVCdGO2iIGSfufs7KzgONCUHH INHgMfEpDdVNu14hwUbLDxazOvI/yjo= X-MC-Unique: FXTfme9gODq7MQbyn3LHRg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705580666; x=1706185466; 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=/VVeA71Dmkqh48AQEKSvnskR8Cu+XOI6j0l+YjpNLD4=; b=QsFer2ILD4yarb4CYRYvaqqL4LZFCGJUCmUJSvExdwQmBO4eoBc1MC2Y9KuBgqk6ox WV1dVN5dJNVOUC4q7W+2ssIJVbt8q/m0vFy3r3hxTBvpx4PoD1gZfYdqzCx5gkhCDu29 kXRZEG2TMucH/bfDE//9ALRf1SlHSvHbLW6BC6ty92f4tQXKE2kUlwMiljjFKADlknV9 wyuZNB94YcjXQ1EuDafn8BdpT9MFfQD51dL7gMGt1gZO8R64jKjnVvm78eJ9MI3ghWpB Y+dTL85jj3KyIolu4YMb4UsKNjvmOTZTNstUdGl7HZSpv+kTKYnMJPm2TKZSBwrpc4RI ykrA== X-Gm-Message-State: AOJu0YyrVY5bZRIU8EharrpX1ulS5aUlSiP6aLCQqEBUxhxmnrJ9Qh7e WVLZAYd3n/JYBkl874QAYPRdf69DZgIZmfNk/9hCl9dnFakeyJyXQQZc/ctT0ehKD9a+xb0+pTl LkLgCo+x3gmn7UW4aNtzFxu5+6wjiAqyYI7EZceh9TljRh8FKzvru2bfQvv3bzwqbWTWa2TSENf Cbs7w/zvx7TwbxhOf24J7XzirTKMdlswOPgQVm X-Received: by 2002:a17:906:bc57:b0:a27:6615:15ed with SMTP id s23-20020a170906bc5700b00a27661515edmr519813ejv.42.1705580666387; Thu, 18 Jan 2024 04:24:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IGzeMDwNlGqKPtAovH20EgugCMLpSj8Wi9ikIifjhFSicZGbIm3Xknr6VJYHA4mTAhOeKmBrQ== X-Received: by 2002:a17:906:bc57:b0:a27:6615:15ed with SMTP id s23-20020a170906bc5700b00a27661515edmr519807ejv.42.1705580666130; Thu, 18 Jan 2024 04:24:26 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 05/16] vga: optimize horizontal pel panning in 256-color modes Date: Thu, 18 Jan 2024 13:24:05 +0100 Message-ID: <20240118122416.9209-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240118122416.9209-1-pbonzini@redhat.com> References: <20240118122416.9209-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.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -38 X-Spam_score: -3.9 X-Spam_bar: --- X-Spam_report: (-3.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.806, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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 @redhat.com) X-ZM-MESSAGEID: 1705580784131100003 Content-Type: text/plain; charset="utf-8" Do not go through the panning buffer unless the address wraps in the middle of the line. Signed-off-by: Paolo Bonzini --- hw/display/vga-helpers.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/hw/display/vga-helpers.h b/hw/display/vga-helpers.h index 29933562c45..2029b61791b 100644 --- a/hw/display/vga-helpers.h +++ b/hw/display/vga-helpers.h @@ -265,6 +265,18 @@ static void *vga_draw_line8d2(VGACommonState *vga, uin= t8_t *d, =20 palette =3D vga->last_palette; hpel =3D (hpel >> 1) & 3; + + /* For 256 color modes, we can adjust the source address and write dir= ectly + * to the destination, even if horizontal pel panning is active. Howe= ver, + * the loop below assumes that the address does not wrap in the middle= of a + * plane. If that happens... + */ + if (addr + (width >> 3) * 4 < VGA_VRAM_SIZE) { + addr +=3D hpel * 4; + hpel =3D 0; + } + + /* ... use the panning buffer as in planar modes. */ if (hpel) { width +=3D 8; d =3D vga->panning_buf; --=20 2.43.0 From nobody Thu Nov 14 07:04:05 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1705580736; cv=none; d=zohomail.com; s=zohoarc; b=Pxit60ld4tLy7kClv1Cz1d0PNvXBtj6jKodAkpC95nXUdZdjbky3NTyoC7B8LZ+bmQWoZC/RgMMxq6JNClBJ7lM32mnoKMsHV4HJhmnGSZv6ezlU7fqkUifubwEGQPV5Pm02U/NxkJXUa6NoZq7p1w/mtlwFVLLnmov8r7LF95Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705580736; h=Content-Type: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=U+rShe1zzqsjwl4vUlHMrqQonvixWh+vpAlDDZieUAE=; b=GHn1tio47w7lEHlrLBxYG1WNAkcboKcHaNOleboZANIezN3aucuFtvoAD+hsHxRpV5/H1UcgkZJ8Heyug1OulR8TsuvtZD/d/D9NkcPDhK5IMm8ZocOoQUJ2KlA8+Sw0uzXqdOqIhGs76tg7UR4jzEl0oNuBiLzlPPJlvJdmG6Y= 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 1705580736134913.1501765363392; Thu, 18 Jan 2024 04:25:36 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rQRRp-0003U9-6i; Thu, 18 Jan 2024 07:24:41 -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 1rQRRi-0003LU-DU for qemu-devel@nongnu.org; Thu, 18 Jan 2024 07:24:34 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rQRRf-0005uZ-P9 for qemu-devel@nongnu.org; Thu, 18 Jan 2024 07:24:33 -0500 Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-70-y1obnYEjOAas01cinbpoqw-1; Thu, 18 Jan 2024 07:24:29 -0500 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a2d4d231f77so173903166b.0 for ; Thu, 18 Jan 2024 04:24:29 -0800 (PST) Received: from [192.168.10.118] ([2001:b07:6468:f312:4783:a68:c1ee:15c5]) by smtp.gmail.com with ESMTPSA id vk6-20020a170907cbc600b00a2dbc664e2asm5257179ejc.89.2024.01.18.04.24.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 04:24:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705580671; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=U+rShe1zzqsjwl4vUlHMrqQonvixWh+vpAlDDZieUAE=; b=TtuWOR6xUUKStGHtlaD0VOiIX6cktrCZkto/UqdOaUpvuz9oYfrbhu8DdMww1Z7Su/9Jk8 DkGciHPpsL9t4Hur8c2TunL21m21QWCLMmz7DfwUkpwgrQZH4RcrTLXpGNOudTj8YEtWnx EXZ+tCq9IGbrQZ0kySt7rqAmVTVAcnU= X-MC-Unique: y1obnYEjOAas01cinbpoqw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705580668; x=1706185468; 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=U+rShe1zzqsjwl4vUlHMrqQonvixWh+vpAlDDZieUAE=; b=U9gTNdWNhH+oMCE9aWxmF1ta3CkdCS678l3SQaApPPO1tpy76Az6J2CifjHm09h/GY LzyuRk6QV/zuCfYwG0gkhUqG21Ykju0T7yo9GsOv/yC86uxRHudUJfpJn6eLVGgD/0tg oNWupIrRKOlbWSHB7msrELWzYsG4u3ybc48lfkIVE2Cdd6eRINL5NDFcPlDKF9SV++nu 6D2sdxWGtu3HV/cQMUWtfVcRlvrr0Rlrn3ZFAD7NqqfDD6byKWBlANv4ROsYOwEMSqk3 YFa1xnwgxl24aLRoPLLxrp2f5HeaJGs0RvcjyxRNMGK5rRrZPfmPDf/VLhyB7DcT4MMB vLcg== X-Gm-Message-State: AOJu0YwtLyfnSCgB94ZCWJff9uZMU3FtN6ra0zCO0YgmCigU9ZOWhaZg e4zd5IeopFqQFEefvKico6t6BU2cp5YtJCegxXl7K3EOgmzmp8Vr4LtpiTEcVdIFBbt7NTfYL2p n3J4ppjYDxY77yL9dNFXycdfWwkPMvuy1PubbChDJhcujQzVVoAAd6RIMz0Y0Oiqw5lmyba5Hf2 RBL7dHMrVftWe1eG2DvhX5aSFfTABg1nFJBeEK X-Received: by 2002:a17:906:f2da:b0:a27:d1c5:906 with SMTP id gz26-20020a170906f2da00b00a27d1c50906mr452923ejb.60.1705580667755; Thu, 18 Jan 2024 04:24:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IETBLaeSi7ChbA14wSSDLSgU0Y8P4P1COwhIZFAPrMbqG6m+OS2QdGkkrj1y95iWwjpVRNF1w== X-Received: by 2002:a17:906:f2da:b0:a27:d1c5:906 with SMTP id gz26-20020a170906f2da00b00a27d1c50906mr452919ejb.60.1705580667410; Thu, 18 Jan 2024 04:24:27 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 06/16] vga: reindent memory access code Date: Thu, 18 Jan 2024 13:24:06 +0100 Message-ID: <20240118122416.9209-7-pbonzini@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240118122416.9209-1-pbonzini@redhat.com> References: <20240118122416.9209-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.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -38 X-Spam_score: -3.9 X-Spam_bar: --- X-Spam_report: (-3.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.806, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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 @redhat.com) X-ZM-MESSAGEID: 1705580737921100007 Content-Type: text/plain; charset="utf-8" The next patch will reuse latched memory access in text modes. Start with a patch that moves the latched access code out of the "if". Best reviewed with "git diff -b". Signed-off-by: Paolo Bonzini --- hw/display/vga.c | 211 ++++++++++++++++++++++++----------------------- 1 file changed, 110 insertions(+), 101 deletions(-) diff --git a/hw/display/vga.c b/hw/display/vga.c index a39f802ab7e..f89409f8f2f 100644 --- a/hw/display/vga.c +++ b/hw/display/vga.c @@ -815,37 +815,41 @@ uint32_t vga_mem_readb(VGACommonState *s, hwaddr addr) } =20 if (sr(s, VGA_SEQ_MEMORY_MODE) & VGA_SR04_CHN_4M) { - /* chain 4 mode : simplest access */ + /* chain 4 mode : simplest access (but it should use the same + * algorithms as below; see e.g. vga_mem_writeb's plane mask check= ). + */ assert(addr < s->vram_size); - ret =3D s->vram_ptr[addr]; - } else if (s->gr[VGA_GFX_MODE] & 0x10) { + return s->vram_ptr[addr]; + } + + if (s->gr[VGA_GFX_MODE] & 0x10) { /* odd/even mode (aka text mode mapping) */ plane =3D (s->gr[VGA_GFX_PLANE_READ] & 2) | (addr & 1); addr =3D ((addr & ~1) << 1) | plane; if (addr >=3D s->vram_size) { return 0xff; } - ret =3D s->vram_ptr[addr]; - } else { - /* standard VGA latched access */ - if (addr * sizeof(uint32_t) >=3D s->vram_size) { - return 0xff; - } - s->latch =3D ((uint32_t *)s->vram_ptr)[addr]; - - if (!(s->gr[VGA_GFX_MODE] & 0x08)) { - /* read mode 0 */ - plane =3D s->gr[VGA_GFX_PLANE_READ]; - ret =3D GET_PLANE(s->latch, plane); - } else { - /* read mode 1 */ - ret =3D (s->latch ^ mask16[s->gr[VGA_GFX_COMPARE_VALUE]]) & - mask16[s->gr[VGA_GFX_COMPARE_MASK]]; - ret |=3D ret >> 16; - ret |=3D ret >> 8; - ret =3D (~ret) & 0xff; - } + return s->vram_ptr[addr]; } + + /* standard VGA latched access */ + plane =3D s->gr[VGA_GFX_PLANE_READ]; + if (addr * sizeof(uint32_t) >=3D s->vram_size) { + return 0xff; + } + s->latch =3D ((uint32_t *)s->vram_ptr)[addr]; + if (!(s->gr[VGA_GFX_MODE] & 0x08)) { + /* read mode 0 */ + ret =3D GET_PLANE(s->latch, plane); + } else { + /* read mode 1 */ + ret =3D (s->latch ^ mask16[s->gr[VGA_GFX_COMPARE_VALUE]]) & + mask16[s->gr[VGA_GFX_COMPARE_MASK]]; + ret |=3D ret >> 16; + ret |=3D ret >> 8; + ret =3D (~ret) & 0xff; + } + return ret; } =20 @@ -895,7 +899,10 @@ void vga_mem_writeb(VGACommonState *s, hwaddr addr, ui= nt32_t val) s->plane_updated |=3D mask; /* only used to detect font change= */ memory_region_set_dirty(&s->vram, addr, 1); } - } else if (s->gr[VGA_GFX_MODE] & 0x10) { + return; + } + + if (s->gr[VGA_GFX_MODE] & 0x10) { /* odd/even mode (aka text mode mapping) */ plane =3D (s->gr[VGA_GFX_PLANE_READ] & 2) | (addr & 1); mask =3D (1 << plane); @@ -911,84 +918,86 @@ void vga_mem_writeb(VGACommonState *s, hwaddr addr, u= int32_t val) s->plane_updated |=3D mask; /* only used to detect font change= */ memory_region_set_dirty(&s->vram, addr, 1); } - } else { - /* standard VGA latched access */ - write_mode =3D s->gr[VGA_GFX_MODE] & 3; - switch(write_mode) { - default: - case 0: - /* rotate */ - b =3D s->gr[VGA_GFX_DATA_ROTATE] & 7; - val =3D ((val >> b) | (val << (8 - b))) & 0xff; - val |=3D val << 8; - val |=3D val << 16; - - /* apply set/reset mask */ - set_mask =3D mask16[s->gr[VGA_GFX_SR_ENABLE]]; - val =3D (val & ~set_mask) | - (mask16[s->gr[VGA_GFX_SR_VALUE]] & set_mask); - bit_mask =3D s->gr[VGA_GFX_BIT_MASK]; - break; - case 1: - val =3D s->latch; - goto do_write; - case 2: - val =3D mask16[val & 0x0f]; - bit_mask =3D s->gr[VGA_GFX_BIT_MASK]; - break; - case 3: - /* rotate */ - b =3D s->gr[VGA_GFX_DATA_ROTATE] & 7; - val =3D (val >> b) | (val << (8 - b)); - - bit_mask =3D s->gr[VGA_GFX_BIT_MASK] & val; - val =3D mask16[s->gr[VGA_GFX_SR_VALUE]]; - break; - } - - /* apply logical operation */ - func_select =3D s->gr[VGA_GFX_DATA_ROTATE] >> 3; - switch(func_select) { - case 0: - default: - /* nothing to do */ - break; - case 1: - /* and */ - val &=3D s->latch; - break; - case 2: - /* or */ - val |=3D s->latch; - break; - case 3: - /* xor */ - val ^=3D s->latch; - break; - } - - /* apply bit mask */ - bit_mask |=3D bit_mask << 8; - bit_mask |=3D bit_mask << 16; - val =3D (val & bit_mask) | (s->latch & ~bit_mask); - - do_write: - /* mask data according to sr[2] */ - mask =3D sr(s, VGA_SEQ_PLANE_WRITE); - s->plane_updated |=3D mask; /* only used to detect font change */ - write_mask =3D mask16[mask]; - if (addr * sizeof(uint32_t) >=3D s->vram_size) { - return; - } - ((uint32_t *)s->vram_ptr)[addr] =3D - (((uint32_t *)s->vram_ptr)[addr] & ~write_mask) | - (val & write_mask); -#ifdef DEBUG_VGA_MEM - printf("vga: latch: [0x" HWADDR_FMT_plx "] mask=3D0x%08x val=3D0x%= 08x\n", - addr * 4, write_mask, val); -#endif - memory_region_set_dirty(&s->vram, addr << 2, sizeof(uint32_t)); + return; } + + mask =3D sr(s, VGA_SEQ_PLANE_WRITE); + + /* standard VGA latched access */ + write_mode =3D s->gr[VGA_GFX_MODE] & 3; + switch(write_mode) { + default: + case 0: + /* rotate */ + b =3D s->gr[VGA_GFX_DATA_ROTATE] & 7; + val =3D ((val >> b) | (val << (8 - b))) & 0xff; + val |=3D val << 8; + val |=3D val << 16; + + /* apply set/reset mask */ + set_mask =3D mask16[s->gr[VGA_GFX_SR_ENABLE]]; + val =3D (val & ~set_mask) | + (mask16[s->gr[VGA_GFX_SR_VALUE]] & set_mask); + bit_mask =3D s->gr[VGA_GFX_BIT_MASK]; + break; + case 1: + val =3D s->latch; + goto do_write; + case 2: + val =3D mask16[val & 0x0f]; + bit_mask =3D s->gr[VGA_GFX_BIT_MASK]; + break; + case 3: + /* rotate */ + b =3D s->gr[VGA_GFX_DATA_ROTATE] & 7; + val =3D (val >> b) | (val << (8 - b)); + + bit_mask =3D s->gr[VGA_GFX_BIT_MASK] & val; + val =3D mask16[s->gr[VGA_GFX_SR_VALUE]]; + break; + } + + /* apply logical operation */ + func_select =3D s->gr[VGA_GFX_DATA_ROTATE] >> 3; + switch(func_select) { + case 0: + default: + /* nothing to do */ + break; + case 1: + /* and */ + val &=3D s->latch; + break; + case 2: + /* or */ + val |=3D s->latch; + break; + case 3: + /* xor */ + val ^=3D s->latch; + break; + } + + /* apply bit mask */ + bit_mask |=3D bit_mask << 8; + bit_mask |=3D bit_mask << 16; + val =3D (val & bit_mask) | (s->latch & ~bit_mask); + +do_write: + /* mask data according to sr[2] */ + s->plane_updated |=3D mask; /* only used to detect font change */ + write_mask =3D mask16[mask]; + if (addr * sizeof(uint32_t) >=3D s->vram_size) { + return; + } + ((uint32_t *)s->vram_ptr)[addr] =3D + (((uint32_t *)s->vram_ptr)[addr] & ~write_mask) | + (val & write_mask); +#ifdef DEBUG_VGA_MEM + printf("vga: latch: [0x" HWADDR_FMT_plx "] mask=3D0x%08x val=3D0x%08x\= n", + addr * 4, write_mask, val); +#endif + memory_region_set_dirty(&s->vram, addr << 2, sizeof(uint32_t)); } =20 typedef void *vga_draw_line_func(VGACommonState *s1, uint8_t *d, --=20 2.43.0 From nobody Thu Nov 14 07:04:05 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1705580846; cv=none; d=zohomail.com; s=zohoarc; b=bBo+uYz9VSMPH6uzm+9o1tVLLdl1iuUzKMnvbEWSHZArvqTkRBNLmUfJRwutkhA9JIzDXau9n8BJB/heFEHSL7H3KGSYI3WLL6RMP/9n2/CA1kaeQY3JaSQ4bV8xFC5V6tHDjbuLajwOCxpy8EDMEUJ8vPUHJ+rtV5HGRdkW8PY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705580846; h=Content-Type: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=tswCvkz9OCIPGTjTnPUEmwbWgBnUuSxUc5oQe3+SP2Q=; b=Uk3qoWLZtEPPd2LRkWTOZ/gtU7BhqEYFN9r01Ndv6JOhWIam9GFRm3UJw4+XWXxZAR00sxE/5+3vlujgBhtvubUjnYha7A0tRvqVh5+Ty8D871IWkdWjJE5eDBQga2jx+uCHwZ6GnshZx3aZ/cjABjp0ZRI9pmZIC4e6NiGXPoM= 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 1705580846943930.1064658407018; Thu, 18 Jan 2024 04:27:26 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rQRRl-0003RU-OJ; Thu, 18 Jan 2024 07:24:38 -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 1rQRRj-0003ON-Sq for qemu-devel@nongnu.org; Thu, 18 Jan 2024 07:24:36 -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 1rQRRh-00063I-W7 for qemu-devel@nongnu.org; Thu, 18 Jan 2024 07:24:35 -0500 Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-587-1jNWoqbNNkOuG_yhJIbmFw-1; Thu, 18 Jan 2024 07:24:31 -0500 Received: by mail-ed1-f70.google.com with SMTP id 4fb4d7f45d1cf-5591ff1072fso2853424a12.3 for ; Thu, 18 Jan 2024 04:24:31 -0800 (PST) Received: from [192.168.10.118] ([2001:b07:6468:f312:4783:a68:c1ee:15c5]) by smtp.gmail.com with ESMTPSA id h16-20020a170906399000b00a28a66028bcsm9072364eje.91.2024.01.18.04.24.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 04:24:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705580673; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tswCvkz9OCIPGTjTnPUEmwbWgBnUuSxUc5oQe3+SP2Q=; b=gTfgibzWox37ZtAueeBLcECnVaMMbo2L45XT2Lx5JG4SOUD8mDbCYd6bZEDLH27Z5OokK9 ogonCvIYIy/cTrr1cPT8W2x+CUS0NKYvL+bGhIsmTLpVpJv6kUeSccqLHG8PmxHB0m3zsO AJz9/O5CYsqxnVlu3gc22x/mHhIy/vk= X-MC-Unique: 1jNWoqbNNkOuG_yhJIbmFw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705580670; x=1706185470; 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=tswCvkz9OCIPGTjTnPUEmwbWgBnUuSxUc5oQe3+SP2Q=; b=mxNM28QCG2fqd0zy7r4uKgN55vC+mIxnKgP0ZC6HKvnM2zYU+7CP8x0cT+rWIHdZbb cMQq+Zfbii63vmoN3o8+MQL5Spm2i0BfTS7+9ZBMNcyFNiNKfRnfTMF4iFrpPIvhUb4F BomlnALhgEiRaSxqW/grw6kETFgcGGoxyXqM60fHx7X24QFW4Z0WcsoCuI8FayEuBPrR 6NN88pguL+xD+iy93vz9PGoAtnMEkLJOeuP0Xg1eBbp0Wh5NFa5TOTswIejNM4c80Rat OnFcZnFs4D6KLWEanxGEc/5rYYjEQf1OQbZMKz9q+AdpY5XUFn0M/atqkoL5zkqhm6cI c6aw== X-Gm-Message-State: AOJu0YxEjg4zfVabfxDdrHBV/UrWWgaH+0oXsbaX1YDwJYafbJWg1RHs 9pq1IbMxiKiGFiw25k27GfKmt2Gx9kbErNbYyy5nc+9YZ6hvhjD5Mtkg5Nrbq3u2ccHmUqyXIvN /g7g5ZQ10lIU925146t8QrevsVBpTpTXxdwjBAo2XZhiAjRMqJ67aQnhCHRLGr+2w/90kSUxWfV aHbWNw4cHmlQgB2+wOk9KKR+C932kKi0ynnJ6B X-Received: by 2002:a17:906:841a:b0:a2f:1d0c:32f6 with SMTP id n26-20020a170906841a00b00a2f1d0c32f6mr189329ejx.171.1705580670104; Thu, 18 Jan 2024 04:24:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IHyJencOmRQiO0L169oxOZ8GiKI96bdJB3OoXpujPkFZmILS6ZHYkooaF7TjiBSuaMcpQliqg== X-Received: by 2002:a17:906:841a:b0:a2f:1d0c:32f6 with SMTP id n26-20020a170906841a00b00a2f1d0c32f6mr189324ejx.171.1705580669706; Thu, 18 Jan 2024 04:24:29 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 07/16] vga: use latches in odd/even mode too Date: Thu, 18 Jan 2024 13:24:07 +0100 Message-ID: <20240118122416.9209-8-pbonzini@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240118122416.9209-1-pbonzini@redhat.com> References: <20240118122416.9209-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: -38 X-Spam_score: -3.9 X-Spam_bar: --- X-Spam_report: (-3.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.806, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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 @redhat.com) X-ZM-MESSAGEID: 1705580848295100003 Content-Type: text/plain; charset="utf-8" Jazz Jackrabbit uses odd/even mode with 256-color graphics. This is probably so that it can do very fast blitting with a decent resolution (two pixels, compared to four pixels for "regular" mode X). Accesses still use all planes (reads go to the latches and the game uses read mode 1 so that the CPU always gets 0xFF; writes use the plane mask register because the game sets bit 2 of the sequencer's memory mode register). For this to work, QEMU needs to use the code for latched memory accesses in odd/even mode. The only difference between odd/even mode and "regular" planar mode is how the plane is computed in read mode 0, and how the planes are masked if the aforementioned bit 2 is reset. It is almost enough to fix the game. You also need to honor byte/word mode selection, which is done in the next patch. Signed-off-by: Paolo Bonzini --- hw/display/vga.c | 40 +++++++++++++--------------------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/hw/display/vga.c b/hw/display/vga.c index f89409f8f2f..d1ef716642f 100644 --- a/hw/display/vga.c +++ b/hw/display/vga.c @@ -825,15 +825,12 @@ uint32_t vga_mem_readb(VGACommonState *s, hwaddr addr) if (s->gr[VGA_GFX_MODE] & 0x10) { /* odd/even mode (aka text mode mapping) */ plane =3D (s->gr[VGA_GFX_PLANE_READ] & 2) | (addr & 1); - addr =3D ((addr & ~1) << 1) | plane; - if (addr >=3D s->vram_size) { - return 0xff; - } - return s->vram_ptr[addr]; + addr >>=3D 1; + } else { + /* standard VGA latched access */ + plane =3D s->gr[VGA_GFX_PLANE_READ]; } =20 - /* standard VGA latched access */ - plane =3D s->gr[VGA_GFX_PLANE_READ]; if (addr * sizeof(uint32_t) >=3D s->vram_size) { return 0xff; } @@ -886,11 +883,12 @@ void vga_mem_writeb(VGACommonState *s, hwaddr addr, u= int32_t val) break; } =20 + mask =3D sr(s, VGA_SEQ_PLANE_WRITE); if (sr(s, VGA_SEQ_MEMORY_MODE) & VGA_SR04_CHN_4M) { /* chain 4 mode : simplest access */ plane =3D addr & 3; - mask =3D (1 << plane); - if (sr(s, VGA_SEQ_PLANE_WRITE) & mask) { + mask &=3D (1 << plane); + if (mask) { assert(addr < s->vram_size); s->vram_ptr[addr] =3D val; #ifdef DEBUG_VGA_MEM @@ -902,26 +900,14 @@ void vga_mem_writeb(VGACommonState *s, hwaddr addr, u= int32_t val) return; } =20 - if (s->gr[VGA_GFX_MODE] & 0x10) { - /* odd/even mode (aka text mode mapping) */ - plane =3D (s->gr[VGA_GFX_PLANE_READ] & 2) | (addr & 1); - mask =3D (1 << plane); - if (sr(s, VGA_SEQ_PLANE_WRITE) & mask) { - addr =3D ((addr & ~1) << 1) | plane; - if (addr >=3D s->vram_size) { - return; - } - s->vram_ptr[addr] =3D val; -#ifdef DEBUG_VGA_MEM - printf("vga: odd/even: [0x" HWADDR_FMT_plx "]\n", addr); -#endif - s->plane_updated |=3D mask; /* only used to detect font change= */ - memory_region_set_dirty(&s->vram, addr, 1); - } - return; + if ((sr(s, VGA_SEQ_MEMORY_MODE) & VGA_SR04_SEQ_MODE) =3D=3D 0) { + mask &=3D (addr & 1) ? 0x0a : 0x05; } =20 - mask =3D sr(s, VGA_SEQ_PLANE_WRITE); + if (s->gr[VGA_GFX_MODE] & 0x10) { + /* odd/even mode (aka text mode mapping) */ + addr >>=3D 1; + } =20 /* standard VGA latched access */ write_mode =3D s->gr[VGA_GFX_MODE] & 3; --=20 2.43.0 From nobody Thu Nov 14 07:04:05 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1705580849; cv=none; d=zohomail.com; s=zohoarc; b=cxThqAK4afFiBt+VqKUn9Pw7ahSD6nLwxHq16lCgnopAO7hyZDrtR/8LTF1x3dzO+zbfp+yZxe3xe6Hcl0suEeCa6BaIfeVEPKEjsVJb7ESbNghVP8OE8dpB43mJ2ubu90o/hfW4tP5GTXvvH3fKd3qobsw8pUyApOqgT6PWmTg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705580849; h=Content-Type: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=6iYFJ1omtBZXJlFu5GK/KyeFIiu1spB8a/9O+0pfZj4=; b=cxWRb7i7pUbcaFrGzD3PR5YSyxKS7CNX9yuP9QXiD5PzjUdPgJ3JZlGzft02Nj80OsaLaWs0rsmSOdNpYsOAn76/SScC8YYas4xg/Txyrri2gtRp1mMQtj+6mBuEG2VfSVvSWM9cAIavTypnLO16a6i8h/ZmuChAOpiuI9kjRR8= 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 17055808493621010.0795586856917; Thu, 18 Jan 2024 04:27:29 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rQRS2-00044Q-4x; Thu, 18 Jan 2024 07:24:54 -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 1rQRRm-0003Rl-MG for qemu-devel@nongnu.org; Thu, 18 Jan 2024 07:24:38 -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 1rQRRk-00069Y-K9 for qemu-devel@nongnu.org; Thu, 18 Jan 2024 07:24:38 -0500 Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-613-FveHs_0CPPi30045ZaAiNA-1; Thu, 18 Jan 2024 07:24:34 -0500 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-a2b6c2a5fddso471079466b.1 for ; Thu, 18 Jan 2024 04:24:34 -0800 (PST) Received: from [192.168.10.118] ([2001:b07:6468:f312:4783:a68:c1ee:15c5]) by smtp.gmail.com with ESMTPSA id cw1-20020a170907160100b00a2dae4e408bsm5509381ejd.15.2024.01.18.04.24.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 04:24:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705580675; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6iYFJ1omtBZXJlFu5GK/KyeFIiu1spB8a/9O+0pfZj4=; b=eb1oba14neaAoCmkO4kmxCvI95ghdfZLQjVFlJhXNl7H17U/FDbpC2Ih+BdVIPIlWPrp3C 8+hSKt9fdUTGv9nLSw1mkKrEophvReEbEupGvN45j5Gm8DXP6uAeZv39u10MolADtX32VQ MhNYIjp/N/MHvSgIGCpCF51EcaErHuM= X-MC-Unique: FveHs_0CPPi30045ZaAiNA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705580672; x=1706185472; 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=6iYFJ1omtBZXJlFu5GK/KyeFIiu1spB8a/9O+0pfZj4=; b=XjO9g8VOsv0h9H2ZMMfEiPDoPz3ucdJ9U1UdqKxmhUeVwELI6QxnOlumkVvpFYwesg d20HyE9ozNJyxQC1yuL8gzau4ERNs1oR9LSmgvEaCP2ROzFcAsPNw/TA0mOZAU4X3ySV TJz3DMECP8joDaZIDgTtnZP/DRCzbqoQ5d+VWGCgFDEuEZTzIVp8SieMe3Da78DdTCQU V7TUiM6s+ZJRrjbkjESj0KywINj495gFU+nASzrhczlFeVsNn235k0oygBtHqOhBELND g3KZ89LdFSsyWZRM3D9ZBBPwGvKp9cG1xHoyuwSbG+gjjvCZZvXJ55M8pcXWcrfEw7mi sblA== X-Gm-Message-State: AOJu0Yzp2968V+v2KBR6NK9Zz4jrxTfqiEeq3uMvWcT+SOarg1CUEh+T 2vaA993OocMeuBPp5kyAdxKW2hJsE0RkKuXbp72DmvnBKxRXp4d0EBZh7xfJXeFWjV9M//sB8LW UaI7U0Gn9rchjKH30i3NQrhhjlHqouvZXKq8hwhaqshPxvAhzLo2b1fMzP8jfPKA9MFe1URycHu BP69jEvnAsayOpSszJy61l1jkfgnIwA3kUL3un X-Received: by 2002:a17:906:c147:b0:a2a:98d:d9ae with SMTP id dp7-20020a170906c14700b00a2a098dd9aemr587524ejc.84.1705580671995; Thu, 18 Jan 2024 04:24:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IE3/tEtDNX9n/Eq/tbAS6ABeB9CBA8bgDMdwbnvGayArBJq7WPoRRT6MCJYODyabbkzSk99IQ== X-Received: by 2002:a17:906:c147:b0:a2a:98d:d9ae with SMTP id dp7-20020a170906c14700b00a2a098dd9aemr587513ejc.84.1705580671567; Thu, 18 Jan 2024 04:24:31 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 08/16] vga: sort-of implement word and double-word access modes Date: Thu, 18 Jan 2024 13:24:08 +0100 Message-ID: <20240118122416.9209-9-pbonzini@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240118122416.9209-1-pbonzini@redhat.com> References: <20240118122416.9209-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: -38 X-Spam_score: -3.9 X-Spam_bar: --- X-Spam_report: (-3.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.806, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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 @redhat.com) X-ZM-MESSAGEID: 1705580850307100014 Content-Type: text/plain; charset="utf-8" Jazz Jackrabbit has a very unusual VGA setup, where it uses odd/even mode with 256-color graphics. Probably, it wants to use fast VRAM-to-VRAM copies without having to store 4 copies of the sprites as needed in mode X, one for each mod-4 alignment; odd/even mode simplifies the code a lot if it's okay to place on a 160-pixels horizontal grid. At the same time, because it wants to use double buffering (a la "mode X") it uses byte mode, not word mode as is the case in text modes. In order to implement the combination of odd/even mode (plane number comes from bit 0 of the address) and byte mode (use all bytes of VRAM, whereas word mode only uses bytes 0, 2, 4,... on each of the four planes), we need to separate the effect on the plane number from the effect on the address. Implementing the modes properly is a mess in QEMU, because it would change the layout of VRAM and break migration. As an approximation, shift right when the CPU accesses memory instead of shifting left when the CRT controller reads it. A hack is needed in order to write font data properly (see comment in the code), but it works well enough for the game. Because doubleword and chain4 modes are now independent, chain4 does not assert anymore that the address is in range. Instead it just returns all ones and discards writes, like other modes. Signed-off-by: Paolo Bonzini --- hw/display/vga_regs.h | 4 ++ hw/display/vga.c | 89 +++++++++++++++++++++++++++++++------------ 2 files changed, 69 insertions(+), 24 deletions(-) diff --git a/hw/display/vga_regs.h b/hw/display/vga_regs.h index 7fdba34b9b1..40e673f164d 100644 --- a/hw/display/vga_regs.h +++ b/hw/display/vga_regs.h @@ -100,7 +100,9 @@ =20 /* VGA CRT controller bit masks */ #define VGA_CR11_LOCK_CR0_CR7 0x80 /* lock writes to CR0 - CR7 */ +#define VGA_CR14_DW 0x40 #define VGA_CR17_H_V_SIGNALS_ENABLED 0x80 +#define VGA_CR17_WORD_BYTE 0x40 =20 /* VGA attribute controller register indices */ #define VGA_ATC_PALETTE0 0x00 @@ -154,6 +156,8 @@ #define VGA_GFX_BIT_MASK 0x08 =20 /* VGA graphics controller bit masks */ +#define VGA_GR05_HOST_ODD_EVEN 0x10 #define VGA_GR06_GRAPHICS_MODE 0x01 +#define VGA_GR06_CHAIN_ODD_EVEN 0x02 =20 #endif /* HW_VGA_REGS_H */ diff --git a/hw/display/vga.c b/hw/display/vga.c index d1ef716642f..bc5b83421bf 100644 --- a/hw/display/vga.c +++ b/hw/display/vga.c @@ -815,25 +815,40 @@ uint32_t vga_mem_readb(VGACommonState *s, hwaddr addr) } =20 if (sr(s, VGA_SEQ_MEMORY_MODE) & VGA_SR04_CHN_4M) { - /* chain 4 mode : simplest access (but it should use the same - * algorithms as below; see e.g. vga_mem_writeb's plane mask check= ). - */ - assert(addr < s->vram_size); - return s->vram_ptr[addr]; - } - - if (s->gr[VGA_GFX_MODE] & 0x10) { + /* chain4 mode */ + plane =3D addr & 3; + addr &=3D ~3; + } else if (s->gr[VGA_GFX_MODE] & VGA_GR05_HOST_ODD_EVEN) { /* odd/even mode (aka text mode mapping) */ plane =3D (s->gr[VGA_GFX_PLANE_READ] & 2) | (addr & 1); - addr >>=3D 1; } else { /* standard VGA latched access */ plane =3D s->gr[VGA_GFX_PLANE_READ]; } =20 + if (s->gr[VGA_GFX_MISC] & VGA_GR06_CHAIN_ODD_EVEN) { + addr &=3D ~1; + } + + /* Doubleword/word mode. See comment in vga_mem_writeb */ + if (s->cr[VGA_CRTC_UNDERLINE] & VGA_CR14_DW) { + addr >>=3D 2; + } else if ((s->gr[VGA_GFX_MODE] & VGA_GR05_HOST_ODD_EVEN) && + (s->cr[VGA_CRTC_MODE] & VGA_CR17_WORD_BYTE) =3D=3D 0) { + addr >>=3D 1; + } + if (addr * sizeof(uint32_t) >=3D s->vram_size) { return 0xff; } + + if (s->sr[VGA_SEQ_MEMORY_MODE] & VGA_SR04_CHN_4M) { + /* chain 4 mode: simplified access (but it should use the same + * algorithms as below, see e.g. vga_mem_writeb's plane mask check= ). + */ + return s->vram_ptr[(addr << 2) | plane]; + } + s->latch =3D ((uint32_t *)s->vram_ptr)[addr]; if (!(s->gr[VGA_GFX_MODE] & 0x08)) { /* read mode 0 */ @@ -853,8 +868,9 @@ uint32_t vga_mem_readb(VGACommonState *s, hwaddr addr) /* called for accesses between 0xa0000 and 0xc0000 */ void vga_mem_writeb(VGACommonState *s, hwaddr addr, uint32_t val) { - int memory_map_mode, plane, write_mode, b, func_select, mask; + int memory_map_mode, write_mode, b, func_select, mask; uint32_t write_mask, bit_mask, set_mask; + int plane =3D 0; =20 #ifdef DEBUG_VGA_MEM printf("vga: [0x" HWADDR_FMT_plx "] =3D 0x%02x\n", addr, val); @@ -888,9 +904,46 @@ void vga_mem_writeb(VGACommonState *s, hwaddr addr, ui= nt32_t val) /* chain 4 mode : simplest access */ plane =3D addr & 3; mask &=3D (1 << plane); + addr &=3D ~3; + } else { + if ((sr(s, VGA_SEQ_MEMORY_MODE) & VGA_SR04_SEQ_MODE) =3D=3D 0) { + mask &=3D (addr & 1) ? 0x0a : 0x05; + } + if (s->gr[VGA_GFX_MISC] & VGA_GR06_CHAIN_ODD_EVEN) { + addr &=3D ~1; + } + } + + /* Doubleword/word mode. These should be honored when displaying, + * not when reading/writing to memory! For example, chain4 modes + * use double-word mode and, on real hardware, would fetch bytes + * 0,1,2,3, 16,17,18,19, 32,33,34,35, etc. Text modes use word + * mode and, on real hardware, would fetch bytes 0,1, 8,9, etc. + * + * QEMU instead shifted addresses on memory accesses because it + * allows more optimizations (e.g. chain4_alias) and simplifies + * the draw_line handlers. Unfortunately, there is one case where + * the difference shows. When fetching font data, accesses are + * always in consecutive bytes, even if the text/attribute pairs + * are done in word mode. Hence, doing a right shift when operating + * on font data is wrong. So check the odd/even mode bits together wi= th + * word mode bit. The odd/even read bit is 0 when reading font data, + * and the odd/even write bit is 1 when writing it. + */ + if (s->cr[VGA_CRTC_UNDERLINE] & VGA_CR14_DW) { + addr >>=3D 2; + } else if ((sr(s, VGA_SEQ_MEMORY_MODE) & VGA_SR04_SEQ_MODE) =3D=3D 0 && + (s->cr[VGA_CRTC_MODE] & VGA_CR17_WORD_BYTE) =3D=3D 0) { + addr >>=3D 1; + } + + if (addr * sizeof(uint32_t) >=3D s->vram_size) { + return; + } + + if (sr(s, VGA_SEQ_MEMORY_MODE) & VGA_SR04_CHN_4M) { if (mask) { - assert(addr < s->vram_size); - s->vram_ptr[addr] =3D val; + s->vram_ptr[(addr << 2) | plane] =3D val; #ifdef DEBUG_VGA_MEM printf("vga: chain4: [0x" HWADDR_FMT_plx "]\n", addr); #endif @@ -900,15 +953,6 @@ void vga_mem_writeb(VGACommonState *s, hwaddr addr, ui= nt32_t val) return; } =20 - if ((sr(s, VGA_SEQ_MEMORY_MODE) & VGA_SR04_SEQ_MODE) =3D=3D 0) { - mask &=3D (addr & 1) ? 0x0a : 0x05; - } - - if (s->gr[VGA_GFX_MODE] & 0x10) { - /* odd/even mode (aka text mode mapping) */ - addr >>=3D 1; - } - /* standard VGA latched access */ write_mode =3D s->gr[VGA_GFX_MODE] & 3; switch(write_mode) { @@ -973,9 +1017,6 @@ do_write: /* mask data according to sr[2] */ s->plane_updated |=3D mask; /* only used to detect font change */ write_mask =3D mask16[mask]; - if (addr * sizeof(uint32_t) >=3D s->vram_size) { - return; - } ((uint32_t *)s->vram_ptr)[addr] =3D (((uint32_t *)s->vram_ptr)[addr] & ~write_mask) | (val & write_mask); --=20 2.43.0 From nobody Thu Nov 14 07:04:05 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1705580869; cv=none; d=zohomail.com; s=zohoarc; b=erOFFzLA1YNxX7SJy204pA37Pr5HsNfZLXBWeiWgoC0c6gOl8f+cTtiSKJl7g5++jWt5Ak8U8z7qDyprfvruw0BXqcE2sB/+7rd2kB+jjdkhaapgex+10ylkhen5JGniinRiDr6Ra3tavoUZI6cspULj9JQ/QOnAvsFWWU703nQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705580869; h=Content-Type: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=3zwo8gv+Nfm+lDqFRavE7UEJZC+0js1OM/QRX97Z4do=; b=iUQUazuhYJqvM08w/yydXw0b4Fmu93i+V/0h0ZH3OrsfNmPnx6a1GQ9tKA0WBtfLEb2aiVe9dSBvxdZ/hv9Oql/sZlj5fAUiC/BW+bCJBlikJPCchS8Jd2lzF1NuXFXT4d86uOA52Fcj67mXE3D2gw4cWFXGOk53/e2BhwfEtrQ= 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 1705580869597346.5927562776253; Thu, 18 Jan 2024 04:27:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rQRRx-0003bK-7L; Thu, 18 Jan 2024 07:24:49 -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 1rQRRn-0003Tt-LM for qemu-devel@nongnu.org; Thu, 18 Jan 2024 07:24:40 -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 1rQRRl-00069e-CP for qemu-devel@nongnu.org; Thu, 18 Jan 2024 07:24:39 -0500 Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-695-0VHBUsyNPGeyA-XbOB-NBw-1; Thu, 18 Jan 2024 07:24:35 -0500 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-a2b8bd6c6a3so810332466b.0 for ; Thu, 18 Jan 2024 04:24:35 -0800 (PST) Received: from [192.168.10.118] ([2001:b07:6468:f312:4783:a68:c1ee:15c5]) by smtp.gmail.com with ESMTPSA id k7-20020a17090627c700b00a19b7362dcfsm9062109ejc.139.2024.01.18.04.24.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 04:24:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705580676; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3zwo8gv+Nfm+lDqFRavE7UEJZC+0js1OM/QRX97Z4do=; b=csDfVfq5FTroNvSUqDQ4SvO50Js0PhZ4uJ0VMPklLPfNTNZCPu0+Hh+uHfDEYXnobBWd9u mh91dta4af5a9wNPtrmsfOaTMbl4NNS+ho7Iq66V/DdkDIXzjlTMU0bNfMWpuxXT0JDGcD /cSo1dGB4JVtAAUMS+EhwzxRYTb2804= X-MC-Unique: 0VHBUsyNPGeyA-XbOB-NBw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705580673; x=1706185473; 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=3zwo8gv+Nfm+lDqFRavE7UEJZC+0js1OM/QRX97Z4do=; b=xKF5dWE9vRKAbgvqGwaUSNncy5VOPsRDq9mud169OhMXaOlegPHgTB/qm0zMG4hOpU 9ZFM0Rhayp20fMt5GWrVQ6GBu1Lzzh5QjA5yNr0yMNSlfs9A81M6jI/NQFn3ARCahk2m lsf09mzZrCPOlhmka6Ibd/JUFRSFsZHZby+potNonDnmKH+tChciBUutY67Nfst1/4eI Bpr2FkfWm/pLT3dn/vkoH+AZlSNr4b/H4jEE/3tMalIMsEEHp5OWgAhAXpjhCY3DgVni BP8UAq4tWk6soyLXXCqFkHD/siW48MvIdMO6kJylAS2Z50+1Fz/l4APMk6qt2NvKmoi9 9mDA== X-Gm-Message-State: AOJu0Yz+pIOCjdvDE4PDF7Y3XPpHiWmnoQtLI3HS9LZICORyD+XGLRuC TdbUkvLDG2GrZSjD3OIHOY5E9cWJSyXWPx0CU7Fny5xWpDa0Fu1xmpcIuDrpqpsjDMVV/wWsYDh nSVp/d15x60NZ5oyZtzJclc4sHJvFA00uH4zVMSuTD0jDwGoUdic+KaeESeyEtFfY0JNaYUxhda kE+riskN36dSpJg3eZe7Ata5gJfyCEBUKr3u2R X-Received: by 2002:a17:906:8c7:b0:a28:7fe8:8b29 with SMTP id o7-20020a17090608c700b00a287fe88b29mr459514eje.68.1705580673124; Thu, 18 Jan 2024 04:24:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IG6m3/sfGr3z/AEDtkz2sC24fPJQmAf9W+8Nm/ZFCfG0eLWjdljqnw/K5ZFSXxOWnMzpjio3Q== X-Received: by 2002:a17:906:8c7:b0:a28:7fe8:8b29 with SMTP id o7-20020a17090608c700b00a287fe88b29mr459505eje.68.1705580672803; Thu, 18 Jan 2024 04:24:32 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Daan De Meyer Subject: [PULL 09/16] Add class property to configure KVM device node to use Date: Thu, 18 Jan 2024 13:24:09 +0100 Message-ID: <20240118122416.9209-10-pbonzini@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240118122416.9209-1-pbonzini@redhat.com> References: <20240118122416.9209-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: -38 X-Spam_score: -3.9 X-Spam_bar: --- X-Spam_report: (-3.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.806, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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 @redhat.com) X-ZM-MESSAGEID: 1705580870367100015 Content-Type: text/plain; charset="utf-8" From: Daan De Meyer This allows passing the KVM device node to use as a file descriptor via /dev/fdset/XX. Passing the device node to use as a file descriptor allows running qemu unprivileged even when the user running qemu is not in the kvm group on distributions where access to /dev/kvm is gated behind membership of the kvm group (as long as the process invoking qemu is able to open /dev/kvm and passes the file descriptor to qemu). Signed-off-by: Daan De Meyer Message-ID: <20231021134015.1119597-1-daan.j.demeyer@gmail.com> Signed-off-by: Paolo Bonzini --- include/sysemu/kvm_int.h | 1 + accel/kvm/kvm-all.c | 25 ++++++++++++++++++++++++- qemu-options.hx | 8 +++++++- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/include/sysemu/kvm_int.h b/include/sysemu/kvm_int.h index fd846394be1..882e37e12c5 100644 --- a/include/sysemu/kvm_int.h +++ b/include/sysemu/kvm_int.h @@ -120,6 +120,7 @@ struct KVMState uint32_t xen_caps; uint16_t xen_gnttab_max_frames; uint16_t xen_evtchn_max_pirq; + char *device; }; =20 void kvm_memory_listener_register(KVMState *s, KVMMemoryListener *kml, diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index bbc60146d15..49e755ec4ad 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -2349,7 +2349,7 @@ static int kvm_init(MachineState *ms) QTAILQ_INIT(&s->kvm_sw_breakpoints); #endif QLIST_INIT(&s->kvm_parked_vcpus); - s->fd =3D qemu_open_old("/dev/kvm", O_RDWR); + s->fd =3D qemu_open_old(s->device ?: "/dev/kvm", O_RDWR); if (s->fd =3D=3D -1) { fprintf(stderr, "Could not access KVM kernel module: %m\n"); ret =3D -errno; @@ -3585,6 +3585,24 @@ static void kvm_set_dirty_ring_size(Object *obj, Vis= itor *v, s->kvm_dirty_ring_size =3D value; } =20 +static char *kvm_get_device(Object *obj, + Error **errp G_GNUC_UNUSED) +{ + KVMState *s =3D KVM_STATE(obj); + + return g_strdup(s->device); +} + +static void kvm_set_device(Object *obj, + const char *value, + Error **errp G_GNUC_UNUSED) +{ + KVMState *s =3D KVM_STATE(obj); + + g_free(s->device); + s->device =3D g_strdup(value); +} + static void kvm_accel_instance_init(Object *obj) { KVMState *s =3D KVM_STATE(obj); @@ -3603,6 +3621,7 @@ static void kvm_accel_instance_init(Object *obj) s->xen_version =3D 0; s->xen_gnttab_max_frames =3D 64; s->xen_evtchn_max_pirq =3D 256; + s->device =3D NULL; } =20 /** @@ -3643,6 +3662,10 @@ static void kvm_accel_class_init(ObjectClass *oc, vo= id *data) object_class_property_set_description(oc, "dirty-ring-size", "Size of KVM dirty page ring buffer (default: 0, i.e. use bitmap)"= ); =20 + object_class_property_add_str(oc, "device", kvm_get_device, kvm_set_de= vice); + object_class_property_set_description(oc, "device", + "Path to the device node to use (default: /dev/kvm)"); + kvm_arch_accel_class_init(oc); } =20 diff --git a/qemu-options.hx b/qemu-options.hx index b66570ae006..2ae51005c12 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -188,7 +188,8 @@ DEF("accel", HAS_ARG, QEMU_OPTION_accel, " dirty-ring-size=3Dn (KVM dirty ring GFN count, defaul= t 0)\n" " eager-split-size=3Dn (KVM Eager Page Split chunk size= , default 0, disabled. ARM only)\n" " notify-vmexit=3Drun|internal-error|disable,notify-win= dow=3Dn (enable notify VM exit and set notify window, x86 only)\n" - " thread=3Dsingle|multi (enable multi-threaded TCG)\n",= QEMU_ARCH_ALL) + " thread=3Dsingle|multi (enable multi-threaded TCG)\n" + " device=3Dpath (KVM device path, default /dev/kvm)\n",= QEMU_ARCH_ALL) SRST ``-accel name[,prop=3Dvalue[,...]]`` This is used to enable an accelerator. Depending on the target @@ -269,6 +270,11 @@ SRST open up for a specified of time (i.e. notify-window). Default: notify-vmexit=3Drun,notify-window=3D0. =20 + ``device=3Dpath`` + Sets the path to the KVM device node. Defaults to ``/dev/kvm``. Th= is + option can be used to pass the KVM device to use via a file descri= ptor + by setting the value to ``/dev/fdset/NN``. + ERST =20 DEF("smp", HAS_ARG, QEMU_OPTION_smp, --=20 2.43.0 From nobody Thu Nov 14 07:04:05 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1705580822; cv=none; d=zohomail.com; s=zohoarc; b=jzKmOnbEXhLoF1OiwUiRTPScyu7P19OpNxFEnawrNfzCmIYJe/mtekebQig4LdVW1TXDjVdlbf1BSGjy15sw3d70wTuOqpHmHtojnFvOmK84BSm/jeyjEwWkvCuJGR8PSP3FXa5oeKtCAqGsSFmpmQCSplb5FkMctoKbn7emrL4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705580822; h=Content-Type: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=AgR/sVi8gSL0IDF14DxKGC6MRJw27EltXky4KfMrUso=; b=Z5c26xUNLUIbF4vy1CpVsGjYRol4EPpPWP9hRQKzl6vLlg+EbUuQitOZI6pdux8wPNiNZWTsH9tFu9ji7g+KdvEBvpy8HC3xmhnNReEN3FbiTOZSwlDStGOfeomuy8aXg/3ML0acgP0/SBI04YJKsofXhuOq/R6DlQ/nnToBKq8= 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 1705580822905331.6052720594296; Thu, 18 Jan 2024 04:27:02 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rQRRw-0003aH-VT; Thu, 18 Jan 2024 07:24: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 1rQRRp-0003VF-HI for qemu-devel@nongnu.org; Thu, 18 Jan 2024 07:24:43 -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 1rQRRn-0006A3-EU for qemu-devel@nongnu.org; Thu, 18 Jan 2024 07:24:40 -0500 Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-647-wDTHMuk6MAa-arCcXWgcKg-1; Thu, 18 Jan 2024 07:24:37 -0500 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-a2bc65005feso460739066b.0 for ; Thu, 18 Jan 2024 04:24:36 -0800 (PST) Received: from [192.168.10.118] ([2001:b07:6468:f312:4783:a68:c1ee:15c5]) by smtp.gmail.com with ESMTPSA id ti14-20020a170907c20e00b00a2cea055d92sm7581694ejc.176.2024.01.18.04.24.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 04:24:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705580678; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AgR/sVi8gSL0IDF14DxKGC6MRJw27EltXky4KfMrUso=; b=iKbHf96apBsT980rEtIdo7oMsnIlUVwMdWXumYZjeQvAlXmg2gJh6CatYLx5EgwsyRNd5C 9auQRrHI3KCu27mVwsNgZnNrz1bD3fzltHLGVW/ocZaEtKOhP83sgza0h3fvti9F5uj6sf JbxNsiURYY/g5JOACw3FyAxxzUTb7jE= X-MC-Unique: wDTHMuk6MAa-arCcXWgcKg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705580675; x=1706185475; 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=AgR/sVi8gSL0IDF14DxKGC6MRJw27EltXky4KfMrUso=; b=R8/eQgqD6KnTUx4I1JLoWUrQhOs93Yt1pWAayG6HETkkRB6gn1RiFCqPUfTIgdP+tu VczQpIBnj5xo9TCoFiqoqmgskNhu8WDxgE++YYzUOx9dTVCOhI4Ywbvlhhv65Q8ZwzIC pGhduTzknBfxqEM//WUvzTWMj8D4yYOMnNn4TnOGCYvF0QPGvl8nsEZGOlK+h47F/G+b 2zv/uMO0h/UfOGCpyTvN6WLcTh4mdoyX+5tfej2Ult8CGj/tbBNj2vD0DXdaDF5FzGjk c2eiH+gMPSl4G9fhg1ogX34FZvQ5CQFipzdcmPEOiAJ9LV3Kwg9pKUldLSElRp2Dm0fe lGHQ== X-Gm-Message-State: AOJu0YySmFlivjaesRw3vz/CJlsxmv8et+UE2DM8T9pEI1eZZLu5st+X j0i04TIgq3+AZUyFsg/w764743tO2LMmeYulrgXiDnTuxf9rJB+LA5rknQ34PTfYlvV9UnW3XPj 1kHowMPnzSoRaunjngPPuS6caHB65ergUkejxLXmK68U7N/R2nwbO7yTbYHnfYoS9VdAEzB241o 0kj5jjCZiBCTCxZ8eFbNwLcVTxqoU0/KP3I+bF X-Received: by 2002:a17:906:11d4:b0:a2a:23b6:fb2a with SMTP id o20-20020a17090611d400b00a2a23b6fb2amr427635eja.106.1705580675736; Thu, 18 Jan 2024 04:24:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IFuLKRVjVh0LOnf1GoA6ivykt5ksPS+ad40GYklsdntVv+OjF4HC3q/FR7sOY6yGdwM7kdCUA== X-Received: by 2002:a17:906:11d4:b0:a2a:23b6:fb2a with SMTP id o20-20020a17090611d400b00a2a23b6fb2amr427631eja.106.1705580675446; Thu, 18 Jan 2024 04:24:35 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 10/16] io_uring: move LuringState typedef to block/aio.h Date: Thu, 18 Jan 2024 13:24:10 +0100 Message-ID: <20240118122416.9209-11-pbonzini@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240118122416.9209-1-pbonzini@redhat.com> References: <20240118122416.9209-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: -38 X-Spam_score: -3.9 X-Spam_bar: --- X-Spam_report: (-3.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.806, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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 @redhat.com) X-ZM-MESSAGEID: 1705580824211100003 Content-Type: text/plain; charset="utf-8" The LuringState typedef is defined twice, in include/block/raw-aio.h and block/io_uring.c. Move it in include/block/aio.h, which is included everywhere the typedef is needed, since include/block/aio.h already has to define the forward reference to the struct. Signed-off-by: Paolo Bonzini --- include/block/aio.h | 8 ++++---- include/block/raw-aio.h | 1 - block/io_uring.c | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/include/block/aio.h b/include/block/aio.h index c802a392e5e..5d0a1149881 100644 --- a/include/block/aio.h +++ b/include/block/aio.h @@ -55,7 +55,7 @@ typedef void IOHandler(void *opaque); =20 struct ThreadPool; struct LinuxAioState; -struct LuringState; +typedef struct LuringState LuringState; =20 /* Is polling disabled? */ bool aio_poll_disabled(AioContext *ctx); @@ -212,7 +212,7 @@ struct AioContext { struct LinuxAioState *linux_aio; #endif #ifdef CONFIG_LINUX_IO_URING - struct LuringState *linux_io_uring; + LuringState *linux_io_uring; =20 /* State for file descriptor monitoring using Linux io_uring */ struct io_uring fdmon_io_uring; @@ -504,10 +504,10 @@ struct LinuxAioState *aio_setup_linux_aio(AioContext = *ctx, Error **errp); struct LinuxAioState *aio_get_linux_aio(AioContext *ctx); =20 /* Setup the LuringState bound to this AioContext */ -struct LuringState *aio_setup_linux_io_uring(AioContext *ctx, Error **errp= ); +LuringState *aio_setup_linux_io_uring(AioContext *ctx, Error **errp); =20 /* Return the LuringState bound to this AioContext */ -struct LuringState *aio_get_linux_io_uring(AioContext *ctx); +LuringState *aio_get_linux_io_uring(AioContext *ctx); /** * aio_timer_new_with_attrs: * @ctx: the aio context diff --git a/include/block/raw-aio.h b/include/block/raw-aio.h index 0f63c2800ce..20e000b8ef8 100644 --- a/include/block/raw-aio.h +++ b/include/block/raw-aio.h @@ -65,7 +65,6 @@ void laio_attach_aio_context(LinuxAioState *s, AioContext= *new_context); #endif /* io_uring.c - Linux io_uring implementation */ #ifdef CONFIG_LINUX_IO_URING -typedef struct LuringState LuringState; LuringState *luring_init(Error **errp); void luring_cleanup(LuringState *s); =20 diff --git a/block/io_uring.c b/block/io_uring.c index 7cdd00e9f16..1e5886c30be 100644 --- a/block/io_uring.c +++ b/block/io_uring.c @@ -49,7 +49,7 @@ typedef struct LuringQueue { QSIMPLEQ_HEAD(, LuringAIOCB) submit_queue; } LuringQueue; =20 -typedef struct LuringState { +struct LuringState { AioContext *aio_context; =20 struct io_uring ring; @@ -58,7 +58,7 @@ typedef struct LuringState { LuringQueue io_q; =20 QEMUBH *completion_bh; -} LuringState; +}; =20 /** * luring_resubmit: --=20 2.43.0 From nobody Thu Nov 14 07:04:05 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1705580735; cv=none; d=zohomail.com; s=zohoarc; b=noxOhbJkREj6LprEEbdzzb/CCUP8zODgJIOqtvEtSxMUqJv8OqIyCLNdt3xbsLd2Q0zfxg89rDYEu3oi43QKpa3wxAURzZmad1YQ2d+sUCdqW/2SFnkvMXgqL8ytWEw4ncSs8KVBEtCNklgpQUNDPLxINKJDSsy9+05YmJ4+Ud0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705580735; h=Content-Type: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=vUUEQ1/9ptoeMV67o4glnytwMPNSBdclswY2AvsVL1c=; b=R2Mb7/m5kBYSn51uon4SuwlJSx1dJ88D6LutdhV9fdEzQMhKFfSUyTWQs7YdQ5hnnV2/OWw9XTh/dDkfZ9cIlav3cM6gIHNV+kX0KIc8Q3qH8MCSuQKWqN+o3wUjAm2G0AxolS3jgodD1ttioeBq0TuKhywpt0EcJefue6CmlYQ= 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 1705580735159666.3098840083086; Thu, 18 Jan 2024 04:25:35 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rQRRz-0003j8-C4; Thu, 18 Jan 2024 07:24:51 -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 1rQRRr-0003VO-9b for qemu-devel@nongnu.org; Thu, 18 Jan 2024 07:24:43 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rQRRp-0006Ak-9S for qemu-devel@nongnu.org; Thu, 18 Jan 2024 07:24:42 -0500 Received: from mail-lf1-f69.google.com (mail-lf1-f69.google.com [209.85.167.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-538-69ETQF5bNNWh3vQwyhqXTg-1; Thu, 18 Jan 2024 07:24:39 -0500 Received: by mail-lf1-f69.google.com with SMTP id 2adb3069b0e04-50edf4f4767so5030338e87.0 for ; Thu, 18 Jan 2024 04:24:39 -0800 (PST) Received: from [192.168.10.118] ([2001:b07:6468:f312:4783:a68:c1ee:15c5]) by smtp.gmail.com with ESMTPSA id ss3-20020a170907c00300b00a2eb3d16fa9sm2376505ejc.144.2024.01.18.04.24.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 04:24:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705580680; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vUUEQ1/9ptoeMV67o4glnytwMPNSBdclswY2AvsVL1c=; b=jT74PaWcX5mzc+JJscpmqoNBNFespvR5Kw/lOOuLm0M00ohKQpr22I3v+LbXhI1skVX0WJ /tq8/8kHssYJbLFWhewbTJpxCqZTs9GhYsFsRcfXzs4xK+/kXiuxNXIcCR9KcfK7AVJOis 4Hr1oZ7v0JW5IU1/PVxBJuGXCjJUOVI= X-MC-Unique: 69ETQF5bNNWh3vQwyhqXTg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705580677; x=1706185477; 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=vUUEQ1/9ptoeMV67o4glnytwMPNSBdclswY2AvsVL1c=; b=ZsW3f2f99FzEpzlyc0M0w0FISIEt82dLRAfuAN2x5RHDt4Xn8ike8jpu97CW60xDpp tfw4EhCt8XZCq8az3p0oIVcPQDId2ML6okerS6ZUpVfY4/fkxQa4TJau1Rj6OCFrP27X uuDvCTtNoPcQv5fyVOdYxMBuwLQM6d3hKUZMVEWVZPTHLYXgZiCUDfJugMF1B8v8dS3V RecDSaIddTKnjBORm8/0EFQ35bjpj0I50pqXu46tEkJEaidXlS8Sz9TDfep4xSmc6K0q gO0+WXnZGxuN4rESXcujEupxCN7XHzJFzmhKTocr/YnlCNwUfQ9k2HkrCh4TgIHTZ/pm Jtyg== X-Gm-Message-State: AOJu0YzXDVYwHw19d7jW4jNj4iSPNXBcSkFGQH8EAj2THqrE9HvzxC3A 9KfqcjBZ5qv9DPkQAjYaYV72vZET++sdrJ+EFARKoKvF24xOuBgieBIJTUNfkjR08LWAZvpoy6A 27Blree0zkE6I5fWFrfK/tD3pDiSEkIn8PTAw+/CfNiTpEqFDG+y9jXpnLnRmODSK/XDPUChNSL Vu6E6h2Gsci7iewfD/min/53YhsnlDmcVat0Ct X-Received: by 2002:a05:6512:491:b0:50e:62b1:f67b with SMTP id v17-20020a056512049100b0050e62b1f67bmr185980lfq.134.1705580677075; Thu, 18 Jan 2024 04:24:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IESFeK504yxarmh08xTFAV3Lyci60HkJtiogSq0c8jZS+IXwuNHeDZleJU3A+k5v4Twyp2VNw== X-Received: by 2002:a05:6512:491:b0:50e:62b1:f67b with SMTP id v17-20020a056512049100b0050e62b1f67bmr185973lfq.134.1705580676816; Thu, 18 Jan 2024 04:24:36 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Richard Henderson , qemu-stable@nongnu.org, Michael Tokarev Subject: [PULL 11/16] target/i386: Do not re-compute new pc with CF_PCREL Date: Thu, 18 Jan 2024 13:24:11 +0100 Message-ID: <20240118122416.9209-12-pbonzini@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240118122416.9209-1-pbonzini@redhat.com> References: <20240118122416.9209-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.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -38 X-Spam_score: -3.9 X-Spam_bar: --- X-Spam_report: (-3.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.806, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1705580735909100003 Content-Type: text/plain; charset="utf-8" From: Richard Henderson With PCREL, we have a page-relative view of EIP, and an approximation of PC =3D EIP+CSBASE that is good enough to detect page crossings. If we try to recompute PC after masking EIP, we will mess up that approximation and write a corrupt value to EIP. We already handled masking properly for PCREL, so the fix in b5e0d5d2 was only needed for the !PCREL path. Cc: qemu-stable@nongnu.org Fixes: b5e0d5d22fbf ("target/i386: Fix 32-bit wrapping of pc/eip computatio= n") Reported-by: Michael Tokarev Signed-off-by: Richard Henderson Message-ID: <20240101230617.129349-1-richard.henderson@linaro.org> Signed-off-by: Paolo Bonzini --- target/i386/tcg/translate.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index e1eb82a5c68..d4d7e904adb 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -2866,10 +2866,6 @@ static void gen_jmp_rel(DisasContext *s, MemOp ot, i= nt diff, int tb_num) } } new_eip &=3D mask; - new_pc =3D new_eip + s->cs_base; - if (!CODE64(s)) { - new_pc =3D (uint32_t)new_pc; - } =20 gen_update_cc_op(s); set_cc_op(s, CC_OP_DYNAMIC); @@ -2885,6 +2881,8 @@ static void gen_jmp_rel(DisasContext *s, MemOp ot, in= t diff, int tb_num) tcg_gen_andi_tl(cpu_eip, cpu_eip, mask); use_goto_tb =3D false; } + } else if (!CODE64(s)) { + new_pc =3D (uint32_t)(new_eip + s->cs_base); } =20 if (use_goto_tb && translator_use_goto_tb(&s->base, new_pc)) { --=20 2.43.0 From nobody Thu Nov 14 07:04:05 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1705580866; cv=none; d=zohomail.com; s=zohoarc; b=lEQ1BCZdJRhy696VxvvTXl90pMQX3vtCqMGmovgDjvP2bHjOMOMep+Dc7zOkEIwoc6XhfgxBk5cANL6ZpQe6Wu+sbPx3uIckd64UdhUpTL8794J4+1DI+cJotkiymHUSdt2RHnEjCO81/1gSDTsItYEi2m08q1J3iEvKG+VH6kQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705580866; h=Content-Type: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=IxvX/wxNBwVtKGkT3vFrlSLqiMV2FttRmJQLp4ASRQ0=; b=kBla1y7yOHlaHZXq2jiPJ/Ebg3MyJOafYkrdB+7jD/uU7wGEC7uC8m/sE1/PaDJOcctc2OfevAaGiK3rogRDHkLUtG3prXAntWSbZ8CRMYYenQEiTXmJf08LPN8/DBP9YrlKsUIuiFaN7Twce3UsrBG3M/KflAHjgkYpHLt734E= 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 1705580866953242.50313398322714; Thu, 18 Jan 2024 04:27:46 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rQRS3-0004BZ-R3; Thu, 18 Jan 2024 07:24:55 -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 1rQRRs-0003WR-Rp for qemu-devel@nongnu.org; Thu, 18 Jan 2024 07:24:45 -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 1rQRRr-0006Gf-7j for qemu-devel@nongnu.org; Thu, 18 Jan 2024 07:24:44 -0500 Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-633-5zakvBx-PaCj0SfF05ElkQ-1; Thu, 18 Jan 2024 07:24:40 -0500 Received: by mail-ed1-f70.google.com with SMTP id 4fb4d7f45d1cf-55926d2bbe2so1467413a12.1 for ; Thu, 18 Jan 2024 04:24:40 -0800 (PST) Received: from [192.168.10.118] ([2001:b07:6468:f312:4783:a68:c1ee:15c5]) by smtp.gmail.com with ESMTPSA id c10-20020a056402100a00b0055974156563sm4142191edu.26.2024.01.18.04.24.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 04:24:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705580682; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IxvX/wxNBwVtKGkT3vFrlSLqiMV2FttRmJQLp4ASRQ0=; b=Qci2nQQiXymBQSgHGbhlfBijLqmrqXmm8DG9FMREY5kcWlHBSOysBYrvJZnTqD80Pb2Cjv GwuinVL7GlpwhEMLw00yjaEvkt2igpKLWaLbWkTZR4SBX1JoTZHRyNnjUgpQc2/8lIPCdW NLJ3h69DrrfzZ+ad0XLbioHmXfAfih8= X-MC-Unique: 5zakvBx-PaCj0SfF05ElkQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705580679; x=1706185479; 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=IxvX/wxNBwVtKGkT3vFrlSLqiMV2FttRmJQLp4ASRQ0=; b=KCKcJyV6nBSrYARdn9vB0GWCS/+hb1ut4dKoLYlHTFeNceY6BNK63IgA+nPxEZFwa5 wVkMj/mVhmrU3uUpQCbnsM52/MAiFHDyfA5zvxowYTxP5lTQEpjjenrFx8+Pz8WiP+FS 9vyBIhnsx+oOIukcKAVtseofZ4Vbgs5kdum3VODTh+JLSRHsJyXSFj+WwackMB7wmAHi CKSmr8cxhd0gbRAP8pOwmjuEN0W7KeQPAQhROv7EzaFIluADPvc8R8r2UKNAwxkUBagx DtUKh4ICw4xIDUtvBTbbHn2dsVcEXgXlSkCt/sCyXXADWxXYi2m2xkp4zazTqih/6pmD xmYg== X-Gm-Message-State: AOJu0YxBbipcijzLPJHt3WNq3M9ryPsrCd4l4Bp+DEZSid66bd07Xttz vIa+c77mIMFmctVcDLZTsxKKAdSgH0v8Zc46ZVQL3vFDtUEhuUywhKALOeGmaAySvrYtQaOFAIe EVeT605vPAKPmskoEmJIKZU1OMJVz4J6nHamBy/A3aM0+tR7hMFVbLfczsfuF7ZZycTY5B++s+F V6sGr2vZXzkMP8oeZjTi8PnpyPJu7Y7Tgi7lfH X-Received: by 2002:a50:9ea4:0:b0:559:b943:c067 with SMTP id a33-20020a509ea4000000b00559b943c067mr529664edf.79.1705580679117; Thu, 18 Jan 2024 04:24:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IGOuLJK78kHdR+iTZkutVu8nI+QN9+sP2yyWn+jd3CgVlwW1NGYJdKEsOpFab4LFVgIhsHD4g== X-Received: by 2002:a50:9ea4:0:b0:559:b943:c067 with SMTP id a33-20020a509ea4000000b00559b943c067mr529659edf.79.1705580678911; Thu, 18 Jan 2024 04:24:38 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: guoguangyao , qemu-stable@nongnu.org, Richard Henderson Subject: [PULL 12/16] target/i386: fix incorrect EIP in PC-relative translation blocks Date: Thu, 18 Jan 2024 13:24:12 +0100 Message-ID: <20240118122416.9209-13-pbonzini@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240118122416.9209-1-pbonzini@redhat.com> References: <20240118122416.9209-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: -38 X-Spam_score: -3.9 X-Spam_bar: --- X-Spam_report: (-3.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.806, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1705580868866100011 Content-Type: text/plain; charset="utf-8" From: guoguangyao The PCREL patches introduced a bug when updating EIP in the !CF_PCREL case. Using s->pc in func gen_update_eip_next() solves the problem. Cc: qemu-stable@nongnu.org Fixes: b5e0d5d22fbf ("target/i386: Fix 32-bit wrapping of pc/eip computatio= n") Signed-off-by: guoguangyao Reviewed-by: Richard Henderson Message-ID: <20240115020804.30272-1-guoguangyao18@mails.ucas.ac.cn> Signed-off-by: Paolo Bonzini --- target/i386/tcg/translate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index d4d7e904adb..cadf13bce43 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -567,9 +567,9 @@ static void gen_update_eip_next(DisasContext *s) if (tb_cflags(s->base.tb) & CF_PCREL) { tcg_gen_addi_tl(cpu_eip, cpu_eip, s->pc - s->pc_save); } else if (CODE64(s)) { - tcg_gen_movi_tl(cpu_eip, s->base.pc_next); + tcg_gen_movi_tl(cpu_eip, s->pc); } else { - tcg_gen_movi_tl(cpu_eip, (uint32_t)(s->base.pc_next - s->cs_base)); + tcg_gen_movi_tl(cpu_eip, (uint32_t)(s->pc - s->cs_base)); } s->pc_save =3D s->pc; } --=20 2.43.0 From nobody Thu Nov 14 07:04:05 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1705580783; cv=none; d=zohomail.com; s=zohoarc; b=k+i29UJyNG49707F2mS1/JM3cCTmjP5SzdMUezI4KZAiMwWVYqK1VmYyNyndb/h/TM1PyJr2fREkwz2wwcrmR5TL4J660lJjzZJcEv2eKR6DRv6zRSZ9gT+bBF94p63CDU7hkXYqCfe/GeO2A1FuJsiYHTa+qOEk6jk8PKxsJM8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705580783; h=Content-Type: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=+Eq3T2KCwKLxa+Xmtmtqemqra8k7zrccF6GSVgdJGXI=; b=SYKLvc8wtiXcc88ItH1eX6a4UCbiYXsmUA7SiyqLDZfUND/Rnw4Au6Vzb7Eb7f5M5QolXqJ5NyLroETT0BuMOdL4mHWDW3umPQaW94x3I+yO5MqkKJN59pWiu/sOcW6BfLxk3NIMFftQhxrObKaJyzn5cQ0vpT62gT1AuBNCJuQ= 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 1705580783927814.285122088697; Thu, 18 Jan 2024 04:26:23 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rQRS0-0003oK-5a; Thu, 18 Jan 2024 07:24:52 -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 1rQRRu-0003Wb-SL for qemu-devel@nongnu.org; Thu, 18 Jan 2024 07:24:47 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rQRRt-0006Mv-2A for qemu-devel@nongnu.org; Thu, 18 Jan 2024 07:24:46 -0500 Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-548-Lxn8m6QRPaGKdAOTN3yaFw-1; Thu, 18 Jan 2024 07:24:43 -0500 Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-558b04cb660so3692577a12.3 for ; Thu, 18 Jan 2024 04:24:42 -0800 (PST) Received: from [192.168.10.118] ([2001:b07:6468:f312:4783:a68:c1ee:15c5]) by smtp.gmail.com with ESMTPSA id t19-20020a1709067c1300b00a2ca9d38654sm8124997ejo.85.2024.01.18.04.24.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 04:24:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705580684; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+Eq3T2KCwKLxa+Xmtmtqemqra8k7zrccF6GSVgdJGXI=; b=JF0dDk9X6SBQCLGaLEDCeaelh/+GV8ct1ZF3jv6jsqO11L/csp5N1Vu2+aSNSlcpyKBAkH hByjl+R6RAZ3Z9Vy8J1OAkUAwQQNEVgaLdeSbTNy/WVM5yX2bG9LEpLn8N9rVOu6DO4XzX K6fPCpHtoe0IwoTQQmsVWML+fJYIuYU= X-MC-Unique: Lxn8m6QRPaGKdAOTN3yaFw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705580681; x=1706185481; 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=+Eq3T2KCwKLxa+Xmtmtqemqra8k7zrccF6GSVgdJGXI=; b=TrbDQa2md7KB+O1pTQmD3o3vsEFL2hZTOWqK2X6dDXi8lSV5NTBli6eNX0aQMxrQFH NvmbVY93/MwI2l1FhmgCL75fM8wz9euJTe+Ypm3hcp+l6tepuQp9Yjc2AQb4Kn+erDim XVztidDNjDqHE5xaVb+4YNm88cxPaG2wT2HNGgwChomuu4ZKmcG8vlqhgU1ONOiYlQT1 UvK5fUeAUj7hc19gD8fzj8tOlUrcgCY9ikdmZTdgr0AW4htOmv02HgmViciMD+dXD9Eg Lyfvmx5N+PKyHeu7vG7e6d23kQcAyiQR2OkTfIxGur0I7yeqr+ICzm3XS4qD1JAjtLBL J2lA== X-Gm-Message-State: AOJu0Yxo4BpENWObnahfhT6ULkwQ0hmYfagX3Maq+xuHo1sUxizyrazK aomWWF7Zi/fsDNGAyN6BSkUyH32jAjSISBQvopxg0MsVCOTTKpp3zT0aj6vx2/3WKeDd7dHiw70 jpwbfFc3yruRbelJL4ZC3oXj55GaqfaanIuOXNN1dHXHDcnIv2er6d1J0oF8Z2fjwQ7Pj7AVYiA ahIOkbwEYe1Aw663v8U0xNWjaxIpdf+xQnMoyp X-Received: by 2002:a17:906:3bca:b0:a26:c83d:e086 with SMTP id v10-20020a1709063bca00b00a26c83de086mr403641ejf.103.1705580681306; Thu, 18 Jan 2024 04:24:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IEAYUjmVnRPiCWYlEtYFqK8Ms59knADhjJIQe8rQA0b4h9DkIZfFuXiTPR+JjPd88inL1rvoA== X-Received: by 2002:a17:906:3bca:b0:a26:c83d:e086 with SMTP id v10-20020a1709063bca00b00a26c83de086mr403629ejf.103.1705580680929; Thu, 18 Jan 2024 04:24:40 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Mark Cave-Ayland , Richard Henderson Subject: [PULL 13/16] target/i386: pcrel: store low bits of physical address in data[0] Date: Thu, 18 Jan 2024 13:24:13 +0100 Message-ID: <20240118122416.9209-14-pbonzini@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240118122416.9209-1-pbonzini@redhat.com> References: <20240118122416.9209-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.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -38 X-Spam_score: -3.9 X-Spam_bar: --- X-Spam_report: (-3.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.806, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1705580786144100007 Content-Type: text/plain; charset="utf-8" For PC-relative translation blocks, env->eip changes during the execution of a translation block, Therefore, QEMU must be able to recover an instruction's PC just from the TranslationBlock struct and the instruction data with. Because a TB will not span two pages, QEMU stores all the low bits of EIP in the instruction data and replaces them in x86_restore_state_to_opc. Bits 12 and higher (which may vary between executions of a PCREL TB, since these only use the physical address in the hash key) are kept unmodified from env->eip. The assumption is that these bits of EIP, unlike bits 0-11, will not change as the translation block executes. Unfortunately, this is incorrect when the CS base is not aligned to a page. Then the linear address of the instructions (i.e. the one with the CS base addred) indeed will never span two pages, but bits 12+ of EIP can actually change. For example, if CS base is 0x80262200 and EIP =3D 0x6FF4, the first instruction in the translation block will be at linear address 0x802691F4. Even a very small TB will cross to EIP =3D 0x7xxx, while the linear addresses will remain comfortably within a single page. The fix is simply to use the low bits of the linear address for data[0], since those don't change. Then x86_restore_state_to_opc uses tb->cs_base to compute a temporary linear address (referring to some unknown instruction in the TB, but with the correct values of bits 12 and higher); the low bits are replaced with data[0], and EIP is obtained by subtracting again the CS base. Huge thanks to Mark Cave-Ayland for the image and initial debugging, and to Gitlab user @kjliew for help with bisecting another occurrence of (hopefully!) the same bug. It should be relatively easy to write a testcase that performs MMIO on an EIP with different bits 12+ than the first instruction of the translation block; any help is welcome. Fixes: e3a79e0e878 ("target/i386: Enable TARGET_TB_PCREL", 2022-10-11) Cc: qemu-stable@nongnu.org Cc: Mark Cave-Ayland Cc: Richard Henderson Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1759 Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1964 Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2012 Signed-off-by: Paolo Bonzini --- target/i386/tcg/tcg-cpu.c | 20 ++++++++++++++++---- target/i386/tcg/translate.c | 1 - 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/target/i386/tcg/tcg-cpu.c b/target/i386/tcg/tcg-cpu.c index 6e881e9e276..1d54164bdfa 100644 --- a/target/i386/tcg/tcg-cpu.c +++ b/target/i386/tcg/tcg-cpu.c @@ -68,14 +68,26 @@ static void x86_restore_state_to_opc(CPUState *cs, X86CPU *cpu =3D X86_CPU(cs); CPUX86State *env =3D &cpu->env; int cc_op =3D data[1]; + uint64_t new_pc; =20 if (tb_cflags(tb) & CF_PCREL) { - env->eip =3D (env->eip & TARGET_PAGE_MASK) | data[0]; - } else if (tb->flags & HF_CS64_MASK) { - env->eip =3D data[0]; + /* + * data[0] in PC-relative TBs is also a linear address, i.e. an ad= dress with + * the CS base added, because it is not guaranteed that EIP bits 1= 2 and higher + * stay the same across the translation block. Add the CS base ba= ck before + * replacing the low bits, and subtract it below just like for !CF= _PCREL. + */ + uint64_t pc =3D env->eip + tb->cs_base; + new_pc =3D (pc & TARGET_PAGE_MASK) | data[0]; } else { - env->eip =3D (uint32_t)(data[0] - tb->cs_base); + new_pc =3D data[0]; } + if (tb->flags & HF_CS64_MASK) { + env->eip =3D new_pc; + } else { + env->eip =3D (uint32_t)(new_pc - tb->cs_base); + } + if (cc_op !=3D CC_OP_DYNAMIC) { env->cc_op =3D cc_op; } diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index cadf13bce43..e193c74472b 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -6996,7 +6996,6 @@ static void i386_tr_insn_start(DisasContextBase *dcba= se, CPUState *cpu) =20 dc->prev_insn_end =3D tcg_last_op(); if (tb_cflags(dcbase->tb) & CF_PCREL) { - pc_arg -=3D dc->cs_base; pc_arg &=3D ~TARGET_PAGE_MASK; } tcg_gen_insn_start(pc_arg, dc->cc_op); --=20 2.43.0 From nobody Thu Nov 14 07:04:05 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1705580864; cv=none; d=zohomail.com; s=zohoarc; b=ZwiasTuh33peSY6ytd0JuBJnIte6qN0qetSr3A4eRKPS4UAbrTrCqJsaP/v2g7BrYZriRNMubCRj5xoPlZJRfA4NWHDJpn1uU/chlVtyyevUPuPY8lP9IhSdWragzIfGinUFyYPqh54mwxoo1kO0wTCQMnuY4w1MaogqSRBvKGQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705580864; h=Content-Type: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=hDmH0xb0KJF83JwWFiZmZr7xbAbQMZGA9xbRqzRDHkU=; b=Zy4ncue0AHhe7abBd0sl/nC5XT7eI1VV1vT2trmIJJPVwpbXaNEww4toQbxZa8EqwFRIXXIFImbXX7hEKhOvPhoD5LmOejYyxFBZJwPs9iu4/M8z0vqH79YFuPYFrhzGFZayG0nPfUP6XpjCSGov5r0MaQIGlipk/53c/oV6IDE= 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 1705580864702924.0660230598984; Thu, 18 Jan 2024 04:27:44 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rQRS3-0004C9-SV; Thu, 18 Jan 2024 07:24:55 -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 1rQRRy-0003hk-6p for qemu-devel@nongnu.org; Thu, 18 Jan 2024 07:24:50 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rQRRw-0006QY-AP for qemu-devel@nongnu.org; Thu, 18 Jan 2024 07:24:49 -0500 Received: from mail-lf1-f69.google.com (mail-lf1-f69.google.com [209.85.167.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-554-4SFreF_UORqOoeLVxV-uJg-1; Thu, 18 Jan 2024 07:24:45 -0500 Received: by mail-lf1-f69.google.com with SMTP id 2adb3069b0e04-50e5aa11579so10481342e87.1 for ; Thu, 18 Jan 2024 04:24:45 -0800 (PST) Received: from [192.168.10.118] ([2001:b07:6468:f312:4783:a68:c1ee:15c5]) by smtp.gmail.com with ESMTPSA id g16-20020a17090670d000b00a28f51adc39sm8999556ejk.61.2024.01.18.04.24.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 04:24:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705580687; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hDmH0xb0KJF83JwWFiZmZr7xbAbQMZGA9xbRqzRDHkU=; b=N0HYJU5VDoRrpJpjT2vKf/0v/oF/+J/YtdwXmf0EdQFmXUDOQpJi/kE7JEslc1RNKwGtnC 8scpT6k0xcgpyNxjN1spgW7ROxnHf+igzBM5UVjaZHTdGoQs72tuq8cVCW0qO6tukTiJp9 VEfDx3FVY0QwYY/6ibC4ZSJuDm6wRuU= X-MC-Unique: 4SFreF_UORqOoeLVxV-uJg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705580683; x=1706185483; 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=hDmH0xb0KJF83JwWFiZmZr7xbAbQMZGA9xbRqzRDHkU=; b=t7xzmLTCO90UaQtOaI+mUhdqSJZgi+o8tlzgESeSkdl9zHjem4Mib8kgnjO4EN6Swh qaUfMBPVY4p0Ex/mpFaQX2/jNS1k7Fdb/3kkwg17DWSSilFsd6h6a11olhgvLJgt2nfq Ryu1fIaez74l0Ceutm/rn3Qx4+wTuzGyui83cRSTDy8kAqsUpE4uSgn8ZXOv6wVZR06O 5KxERLVfk4+lA0YZk1Z94a1dkh7LQ7g3WDwy1WUaaWCSDJqyYLOwycZ7zX0DyEQf63vY FL9dmC8TGBEuUyZnuQQIhGEVpSj47FGh12HPbvytgh6II3UKT1NwU4NZWh5aqBIt0oVm 0dWw== X-Gm-Message-State: AOJu0YxkY67wHgaK6+nZJU7GRwd7ACJ05YK++T9IagjJ6GGvohtMIj+D +x2Q2NvovW/A5T5Ei96TZ9QkAR644Q73775VpGPA8aGHvnPEcN6HzwOToq5YO5iF5tTgjV8xPcf Og4LEWyqOM/oo3lUjQcqfi9rqapmBDSF/O+a1IrCQ7EQRaidGTRXAlqqP2/028imF2uNDKBu5xH DjPLzfhwgmYGzYTAO7rFJ2CWirgu+LNXnpuzsV X-Received: by 2002:ac2:5184:0:b0:50f:5e2:d50 with SMTP id u4-20020ac25184000000b0050f05e20d50mr360302lfi.51.1705580683529; Thu, 18 Jan 2024 04:24:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IH/xUDldOgfmRW0Kh3OnJlfRkyf61+sFNEht8bXaYgz9UIa8vi6ryuOk+QZ2N9LEASX5fTW7Q== X-Received: by 2002:ac2:5184:0:b0:50f:5e2:d50 with SMTP id u4-20020ac25184000000b0050f05e20d50mr360300lfi.51.1705580683234; Thu, 18 Jan 2024 04:24:43 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 14/16] remove unnecessary casts from uintptr_t Date: Thu, 18 Jan 2024 13:24:14 +0100 Message-ID: <20240118122416.9209-15-pbonzini@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240118122416.9209-1-pbonzini@redhat.com> References: <20240118122416.9209-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.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -38 X-Spam_score: -3.9 X-Spam_bar: --- X-Spam_report: (-3.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.806, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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 @redhat.com) X-ZM-MESSAGEID: 1705580866377100005 Content-Type: text/plain; charset="utf-8" uintptr_t, or unsigned long which is equivalent on Linux I32LP64 systems, is an unsigned type and there is no need to further cast to __u64 which is another unsigned integer type; widening casts from unsigned integers zero-extend the value. Signed-off-by: Paolo Bonzini --- block/io_uring.c | 2 +- hw/vfio/common.c | 4 ++-- target/i386/sev.c | 8 ++++---- util/fdmon-io_uring.c | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/block/io_uring.c b/block/io_uring.c index 1e5886c30be..d77ae55745a 100644 --- a/block/io_uring.c +++ b/block/io_uring.c @@ -102,7 +102,7 @@ static void luring_resubmit_short_read(LuringState *s, = LuringAIOCB *luringcb, =20 /* Update sqe */ luringcb->sqeq.off +=3D nread; - luringcb->sqeq.addr =3D (__u64)(uintptr_t)luringcb->resubmit_qiov.iov; + luringcb->sqeq.addr =3D (uintptr_t)luringcb->resubmit_qiov.iov; luringcb->sqeq.len =3D luringcb->resubmit_qiov.niov; =20 luring_resubmit(s, luringcb); diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 0b3352f2a9d..4aa86f563c6 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -1000,7 +1000,7 @@ vfio_device_feature_dma_logging_start_create(VFIOCont= ainerBase *bcontainer, return NULL; } =20 - control->ranges =3D (__u64)(uintptr_t)ranges; + control->ranges =3D (uintptr_t)ranges; if (tracking->max32) { ranges->iova =3D tracking->min32; ranges->length =3D (tracking->max32 - tracking->min32) + 1; @@ -1126,7 +1126,7 @@ static int vfio_device_dma_logging_report(VFIODevice = *vbasedev, hwaddr iova, report->iova =3D iova; report->length =3D size; report->page_size =3D qemu_real_host_page_size(); - report->bitmap =3D (__u64)(uintptr_t)bitmap; + report->bitmap =3D (uintptr_t)bitmap; =20 feature->argsz =3D sizeof(buf); feature->flags =3D VFIO_DEVICE_FEATURE_GET | diff --git a/target/i386/sev.c b/target/i386/sev.c index 9a712466825..173de91afe7 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -167,7 +167,7 @@ sev_ioctl(int fd, int cmd, void *data, int *error) =20 input.id =3D cmd; input.sev_fd =3D fd; - input.data =3D (__u64)(unsigned long)data; + input.data =3D (uintptr_t)data; =20 r =3D kvm_vm_ioctl(kvm_state, KVM_MEMORY_ENCRYPT_OP, &input); =20 @@ -240,7 +240,7 @@ sev_ram_block_added(RAMBlockNotifier *n, void *host, si= ze_t size, return; } =20 - range.addr =3D (__u64)(unsigned long)host; + range.addr =3D (uintptr_t)host; range.size =3D max_size; =20 trace_kvm_memcrypt_register_region(host, max_size); @@ -270,7 +270,7 @@ sev_ram_block_removed(RAMBlockNotifier *n, void *host, = size_t size, return; } =20 - range.addr =3D (__u64)(unsigned long)host; + range.addr =3D (uintptr_t)host; range.size =3D max_size; =20 trace_kvm_memcrypt_unregister_region(host, max_size); @@ -767,7 +767,7 @@ sev_launch_update_data(SevGuestState *sev, uint8_t *add= r, uint64_t len) return 1; } =20 - update.uaddr =3D (__u64)(unsigned long)addr; + update.uaddr =3D (uintptr_t)addr; update.len =3D len; trace_kvm_sev_launch_update_data(addr, len); ret =3D sev_ioctl(sev->sev_fd, KVM_SEV_LAUNCH_UPDATE_DATA, diff --git a/util/fdmon-io_uring.c b/util/fdmon-io_uring.c index 16054c5ede3..b0d68bdc44d 100644 --- a/util/fdmon-io_uring.c +++ b/util/fdmon-io_uring.c @@ -180,7 +180,7 @@ static void add_poll_remove_sqe(AioContext *ctx, AioHan= dler *node) struct io_uring_sqe *sqe =3D get_sqe(ctx); =20 #ifdef LIBURING_HAVE_DATA64 - io_uring_prep_poll_remove(sqe, (__u64)(uintptr_t)node); + io_uring_prep_poll_remove(sqe, (uintptr_t)node); #else io_uring_prep_poll_remove(sqe, node); #endif --=20 2.43.0 From nobody Thu Nov 14 07:04:05 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1705580849; cv=none; d=zohomail.com; s=zohoarc; b=cE/I5daGXz/3VtN5E6CgdzOKoLVvmlVSXCc4/KgLFsGgDj27XOO/OfzLOi5+0wW3hmuvQfR5J3CI7A/22uVmzmX+Q+qHTKMedkbTFAfotTj8UZLoPkqBSgWtpE8hINS4poIlzEHANlbrQWWGsDY+2z0v4wwAu9a5oDJ5UOqiQno= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705580849; h=Content-Type: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=5sh/MzaGjWxLlgh2MspMlqhV3rmhSqr08po1WDn+uqs=; b=MNEf8+AzQy3eEW6LAcguMHu8H5B41no/v+v4HktcOCFcOfO+t9ERoroO8euTkO7WpsgTCdspmr8vjGQST3OtEehgcTwtGTHVTJt8qvr9xENeV5yXi+aPAmEoJv/y8JBmtwqZJn3vegMXhTHp53RwlBwzbcsvUku+atAjWvY6VIk= 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 1705580848821581.1920341736463; Thu, 18 Jan 2024 04:27:28 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rQRS5-0004Jt-Ig; Thu, 18 Jan 2024 07:24:57 -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 1rQRRy-0003hj-6o for qemu-devel@nongnu.org; Thu, 18 Jan 2024 07:24:50 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rQRRw-0006Qa-EP for qemu-devel@nongnu.org; Thu, 18 Jan 2024 07:24:49 -0500 Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-558-UwLlthGaN4qE9EVq-vLRiA-1; Thu, 18 Jan 2024 07:24:46 -0500 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-a2bc65005feso460746666b.0 for ; Thu, 18 Jan 2024 04:24:46 -0800 (PST) Received: from [192.168.10.118] ([2001:b07:6468:f312:4783:a68:c1ee:15c5]) by smtp.gmail.com with ESMTPSA id cw8-20020a170907160800b00a2cd72af9cesm7871793ejd.146.2024.01.18.04.24.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 04:24:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705580687; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5sh/MzaGjWxLlgh2MspMlqhV3rmhSqr08po1WDn+uqs=; b=Js6ZDjaHNCjDSA24y4RssyJx2fxHK68Hk2MVr5S76MzG4CkCTudiToHL06+hAGj3hNYhK9 G9lByT3RsSFjk9P8YP5NE9sMqzEr95XJdC370g9257A0Ano/rueplTUvyrzncIKlmg5ycp h1ZCrz/isF360H6JHMFauxCiig3nVNY= X-MC-Unique: UwLlthGaN4qE9EVq-vLRiA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705580685; x=1706185485; 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=5sh/MzaGjWxLlgh2MspMlqhV3rmhSqr08po1WDn+uqs=; b=eeRQ3m6kHA8h/C3aYDr0KMEtpJfqAQUvoFZ8W/+HJx0QDkyudXA461cB0fR+jAhrqw sV9z9E0baJ0JRFblxLpi42gq+qCbMx1VkJzFDRH/xiIhiNaW/hFYWyrkAI1Q5BKWwTgl MwKUlzEtaMsZ7YaPIlMp/NraRXZOIm6yZ8gKSXRFEPAcBqPII3xB1DXxS3MqVpTo3nec ujTkelGujef3bTd0unSyY2dGTIvhpIIY2b5oKtHLwOp0icRI31ND9xhUbjuICjwvbnNS Kjh5EZrfIV2Wze94qrYsmgYRAft2FzAClWH7GTF+b4+y4qDPChXGIvqriLfVHLGrqi1d jeXA== X-Gm-Message-State: AOJu0YwOwybVFG0XZH96ucH+m2ZfdRe1l6rmkmeuAGD1oVCy2Qd1jQIE O0ogkcnxwC3k7ZaXueB9i5unPlQ1GUla6HvOOHT2pNwEfu6+jUVlDBvEbzPaq+596QRDSIODCII lkcNo8YAZmMVmPes1ZzMSMBEfRdu86JmNWDGr+EWlUtRhr2lh0U0/zTCQdVast7mm23RcAMIsDg r9Kbh0I8SKR8Qf2aPfSclq7T3m1A4ccQSwpTjc X-Received: by 2002:a17:906:c34c:b0:a2d:4383:78c7 with SMTP id ci12-20020a170906c34c00b00a2d438378c7mr430536ejb.132.1705580684925; Thu, 18 Jan 2024 04:24:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IGJ/CAdaZhHz1QduMdvvFbH6q52VUqfQ36AfUfQMRsvOqjc+iedr1UzAMzAD8bzdfdygtGytQ== X-Received: by 2002:a17:906:c34c:b0:a2d:4383:78c7 with SMTP id ci12-20020a170906c34c00b00a2d438378c7mr430530ejb.132.1705580684541; Thu, 18 Jan 2024 04:24:44 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Bibo Mao Subject: [PULL 15/16] qemu/osdep: Add huge page aligned support on LoongArch platform Date: Thu, 18 Jan 2024 13:24:15 +0100 Message-ID: <20240118122416.9209-16-pbonzini@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240118122416.9209-1-pbonzini@redhat.com> References: <20240118122416.9209-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.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -38 X-Spam_score: -3.9 X-Spam_bar: --- X-Spam_report: (-3.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.806, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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 @redhat.com) X-ZM-MESSAGEID: 1705580850484100019 Content-Type: text/plain; charset="utf-8" From: Bibo Mao On LoongArch kvm mode if transparent huge page wants to be enabled, base address and size of memslot from both HVA and GPA view. And LoongArch supports both 4K and 16K page size with Linux kernel, so transparent huge page size is calculated from real page size rather than hardcoded size. Signed-off-by: Bibo Mao Message-ID: <20240115073244.174155-1-maobibo@loongson.cn> Signed-off-by: Paolo Bonzini --- include/qemu/osdep.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index 9a405bed893..c9692cc3142 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -547,6 +547,14 @@ int madvise(char *, size_t, int); # define QEMU_VMALLOC_ALIGN (256 * 4096) #elif defined(__linux__) && defined(__sparc__) # define QEMU_VMALLOC_ALIGN MAX(qemu_real_host_page_size(), SHMLBA) +#elif defined(__linux__) && defined(__loongarch__) + /* + * For transparent hugepage optimization, it has better be huge page + * aligned. LoongArch host system supports two kinds of pagesize: 4K + * and 16K, here calculate huge page size from host page size + */ +# define QEMU_VMALLOC_ALIGN (qemu_real_host_page_size() * \ + qemu_real_host_page_size() / sizeof(long)) #else # define QEMU_VMALLOC_ALIGN qemu_real_host_page_size() #endif --=20 2.43.0 From nobody Thu Nov 14 07:04:05 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1705580864; cv=none; d=zohomail.com; s=zohoarc; b=Py9ih/VgmEY8r+I1vrRxcDsJ1KFkJfqPYahqddHJN8jAYzJh95wT25E01w+xULgkyAMYtTezoQfiBWEys2G7I/uzQC5Z5S7tuRLQYDBIl+mbxHQ5ZUrA2Yz2bN7eMpcT5QAYjPK9U9gfDU05uEPWdfHlRtAHqhoC283jAsaSr6Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705580864; h=Content-Type: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=VNAly1Va9uOmD/aqKC3qQhN78zjE+pQNvRpWao8WKWA=; b=VNg965tgQWi+6kZmQS9PZi8N1xZ+xiDsrs03sXsIT7yIi0EdnJdT75i+KMdrnBPlFHwM20Nh/Z4DwMuXPgYguynNTxEzW8y8NTGLXXp3qpnzw9X/74qYUDPXURo70zTS/pmXi99JGUfH9H2IADnulqYAoV4DdddbIYOnbwHwAJw= 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 1705580864710222.1022774894999; Thu, 18 Jan 2024 04:27:44 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rQRS3-0004BW-QT; Thu, 18 Jan 2024 07:24:55 -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 1rQRS1-0003zI-60 for qemu-devel@nongnu.org; Thu, 18 Jan 2024 07:24:53 -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 1rQRRy-0006XV-Vg for qemu-devel@nongnu.org; Thu, 18 Jan 2024 07:24:52 -0500 Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-151-8r1f-T6hPEy7qoDn1AIP6A-1; Thu, 18 Jan 2024 07:24:48 -0500 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-a2eace36abdso84192066b.3 for ; Thu, 18 Jan 2024 04:24:48 -0800 (PST) Received: from [192.168.10.118] ([2001:b07:6468:f312:4783:a68:c1ee:15c5]) by smtp.gmail.com with ESMTPSA id x27-20020a170906299b00b00a2c0fec4240sm9091833eje.158.2024.01.18.04.24.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 04:24:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705580690; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VNAly1Va9uOmD/aqKC3qQhN78zjE+pQNvRpWao8WKWA=; b=ihlIBBzvclCpYUnF2WYD6/RV/EovF3qou2FG3dFyibgs2VmMQvEm6LU2NJNjY7gOLYi+lf CsT2l0AszQub0/vA+WNdskjMN0d5b4yrbDUwh6TuiOP32zRPglaZRGncFoelAbog8gIfuJ q/xdp/F/JTP/qJGX2zTfdPWZK9jQ2YE= X-MC-Unique: 8r1f-T6hPEy7qoDn1AIP6A-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705580687; x=1706185487; 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=VNAly1Va9uOmD/aqKC3qQhN78zjE+pQNvRpWao8WKWA=; b=jVI24DgAunKYyIZXaTYsdf13Z1SWg5VhcF5KryaLhjq5XFCmMVgJtsaFhvLGfD+EzL W9m9tMHnupNNovh+y2VlRD4gR3Q8Fvn+QKJJ4kiU5nFx1nVH7jdA4EVUeYA+2VQhRZ0g SfUMUUvdrByxytn9SGMDD1Of148RTJS1FquhtlyrbdU8yUF1+fbTN2t5eI0wy1J4CFZ9 rqrLBCob5RO4U/8wpL6QBqYAI1fH9ePbSEiU69IITi1+w/4e29PE/j+X38zigxWWsEiz 83/t9PJ5U5isgu8w8LErlgwXnoa7RrPpK1Vp8mwTzeZFPnM//oQKfldHpc5+t/x+E7hU kvxQ== X-Gm-Message-State: AOJu0YyQmBomTc0c1mJP6xuF6v9QRucDjItI9y8aaQ3ULsQ0piNoS8aP WmWOyYvkBrcp6gqt+HxhCwyQkTSpQMSC9MYd/0Ax7RSQYmdSJz5pb5Kak0xPxZSTa09HotCdmh9 HAqXX5T9vi32GFwCCK6Es64pNTnioFD0k1TLw+kI+lYr27hPFYSA3VzsiDac8x6I9yscAL1KhnE wMuQ9AAzKDzjIp4Eh3Yey2kks3FiAHuqU3508C X-Received: by 2002:a17:906:81c8:b0:a28:ac5b:5814 with SMTP id e8-20020a17090681c800b00a28ac5b5814mr242678ejx.185.1705580687201; Thu, 18 Jan 2024 04:24:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IEALDULHaUhl5dvug/meiFhbXGn7QXpJ5MBYQ1zGM/KqHz3OIeWvopMDCUEkgYIml6f6mBPyw== X-Received: by 2002:a17:906:81c8:b0:a28:ac5b:5814 with SMTP id e8-20020a17090681c800b00a28ac5b5814mr242673ejx.185.1705580686895; Thu, 18 Jan 2024 04:24:46 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Ilya Leoshkevich Subject: [PULL 16/16] tests/tcg: Don't #include in aarch64/system/vtimer.c Date: Thu, 18 Jan 2024 13:24:16 +0100 Message-ID: <20240118122416.9209-17-pbonzini@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240118122416.9209-1-pbonzini@redhat.com> References: <20240118122416.9209-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: -38 X-Spam_score: -3.9 X-Spam_bar: --- X-Spam_report: (-3.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.806, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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 @redhat.com) X-ZM-MESSAGEID: 1705580866395100006 Content-Type: text/plain; charset="utf-8" From: Ilya Leoshkevich make check-tcg fails on Fedora with: vtimer.c:9:10: fatal error: inttypes.h: No such file or directory Fedora has a minimal aarch64 cross-compiler, which satisfies the configure checks, so it's chosen instead of the dockerized one. There is no cross-version of inttypes.h, however. Fix by using stdint.h instead. The test does not require anything from inttypes.h anyway. Signed-off-by: Ilya Leoshkevich Message-ID: <20240108125030.58569-1-iii@linux.ibm.com> Signed-off-by: Paolo Bonzini --- tests/tcg/aarch64/system/vtimer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tcg/aarch64/system/vtimer.c b/tests/tcg/aarch64/system/v= timer.c index 42f2f7796c7..7d725eced34 100644 --- a/tests/tcg/aarch64/system/vtimer.c +++ b/tests/tcg/aarch64/system/vtimer.c @@ -6,7 +6,7 @@ * SPDX-License-Identifier: GPL-2.0-or-later */ =20 -#include +#include #include =20 /* grabbed from Linux */ --=20 2.43.0