From patchwork Thu Dec 5 10:55:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tomita Moeko X-Patchwork-Id: 13895003 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7024EE7716C for ; Thu, 5 Dec 2024 10:56:11 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tJ9WT-0005Qn-T0; Thu, 05 Dec 2024 05:55:53 -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 1tJ9WR-0005Qb-V4 for qemu-devel@nongnu.org; Thu, 05 Dec 2024 05:55:51 -0500 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tJ9WQ-00030H-D9 for qemu-devel@nongnu.org; Thu, 05 Dec 2024 05:55:51 -0500 Received: by mail-pf1-x444.google.com with SMTP id d2e1a72fcca58-7251abe0e69so785397b3a.0 for ; Thu, 05 Dec 2024 02:55:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733396148; x=1734000948; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9tMqvex4RuMXL27s3iBwmhMpuv9eZ7sBnrBfQ8TBDz4=; b=iu0DCLzotKD9gLy/bhkZG9kRZ1Ae6pS0JTqbzf8S25CgJ/Olh40DO0kYjc010pd2oc DdSwXL3aLkP8CLe33uE9Qsb67Z9P8wXauqYbrunjwyPiw7QF4HW4xgwKuG/uzE7KppbB nOokg5bhkdTTuFyS8ymHQnMecbr5pewnFW9LkVHDHViDMT3jxy/lHJRngmhr3Ck/fVbt tPPojh6wnbFyicfos+XUijZALem568hkNOqdTZBNcmlVcohxGLg57IkBljhZpTraf8W9 3kz55MYRg0HLSbhdPg4LPyPd+XsgnkZFbnG47WARZbY3++9PTfnsxwn+2u7orhwbL56Y Gjaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733396148; x=1734000948; 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=9tMqvex4RuMXL27s3iBwmhMpuv9eZ7sBnrBfQ8TBDz4=; b=cewu6Xv+3IgHXPy2FxubB3TQnEe77wXhrvfkPIlVkYrdrB9LaLKplk2TPLDOUNBEX0 3agou5vemE9271ElTkxJmZftrvU0oDJayKjGqcLWYLxYpq/+tZTNnSqTEHF/oGn57ZgK hZzcO8n/qci+m0AOPrMJrVrUYr8rBclP2UD0+Hu8qSqVjxGyONsokVBuTDnMsx8Gl52w vil+/shNY2uyc6QmBx5/gew6ttZecvgQFzi+0+NaDIKQT0OR3XqKm4gCLNzv+sqFU+TP f9wMqlOrdPra/qlr0hG/QEvbzdhK/D1S/LHSiqxYPoNqF8VUm3yWTGrPfSArmEGh7sor 8GNg== X-Gm-Message-State: AOJu0YzgwmJRkGoAIC/scdr0z50taSXK2IB/avg3htG3cTrfkQ0TkaO3 +dWI1PdHri1AhjoSJxhLHIGctljYV1/6h8+sM2pLV/c3d1mRq1bHmPL5vjhUIQ== X-Gm-Gg: ASbGnctU9qGrSFzQArMZbWMpdVJWHtyVCkiTHiqJ16CQFIIJzpxdIMETWu8ADMmLdgg lFCFuovdW0J6rAmo4vogY4d8oZL06JcnX5qBwz6Pu88+2c6m1C2Ldebiy5G7xIL2cjDj/1Bw4DS 1NqcSntXBN+UQsxO/2aGkEkJlUihyR9cxhRI0Q8dar9NASV1hbwvZ776o7CwjLgxjytV7vkyKSG afcGK7EngDSk8kXDa7gxsPxEwmkVhNIaDY1xOZG4NoXSKYmLDcaDYDVcA== X-Google-Smtp-Source: AGHT+IGuBl5B3xYJCKb26/PT8A5rK7R/EKMrmjFbYf2cLJe6zSsF+2i2sxeAwY8T+RQW7k9qrhufKg== X-Received: by 2002:a05:6a00:21c4:b0:71e:76ac:4fc4 with SMTP id d2e1a72fcca58-7257fcc65d4mr13594675b3a.21.1733396148531; Thu, 05 Dec 2024 02:55:48 -0800 (PST) Received: from kotori-desktop.lan ([58.38.120.33]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-725a2ca6747sm1010905b3a.149.2024.12.05.02.55.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Dec 2024 02:55:48 -0800 (PST) From: Tomita Moeko To: qemu-devel@nongnu.org Cc: Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , =?utf-8?q?Corvin_K=C3=B6hne?= , Tomita Moeko Subject: [PATCH v3 01/10] vfio/igd: remove unsupported device ids Date: Thu, 5 Dec 2024 18:55:26 +0800 Message-ID: <20241205105535.30498-2-tomitamoeko@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241205105535.30498-1-tomitamoeko@gmail.com> References: <20241205105535.30498-1-tomitamoeko@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::444; envelope-from=tomitamoeko@gmail.com; helo=mail-pf1-x444.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Since e433f208973f ("vfio/igd: return an invalid generation for unknown devices"), the default return of igd_gen() was changed to unsupported. There is no need to filter out those unsupported devices. Reviewed-by: Alex Williamson Reviewed-by: Corvin Köhne Signed-off-by: Tomita Moeko --- hw/vfio/igd.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c index 4047f4f071..6ba3045bf3 100644 --- a/hw/vfio/igd.c +++ b/hw/vfio/igd.c @@ -64,16 +64,6 @@ static int igd_gen(VFIOPCIDevice *vdev) } switch (vdev->device_id & 0xff00) { - /* Old, untested, unavailable, unknown */ - case 0x0000: - case 0x2500: - case 0x2700: - case 0x2900: - case 0x2a00: - case 0x2e00: - case 0x3500: - case 0xa000: - return -1; /* SandyBridge, IvyBridge, ValleyView, Haswell */ case 0x0100: case 0x0400: From patchwork Thu Dec 5 10:55:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tomita Moeko X-Patchwork-Id: 13895011 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 22BDDE7716C for ; Thu, 5 Dec 2024 10:57:20 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tJ9WX-0005RY-GB; Thu, 05 Dec 2024 05:55: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 1tJ9WV-0005RA-D6 for qemu-devel@nongnu.org; Thu, 05 Dec 2024 05:55:55 -0500 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tJ9WT-0003Fc-OH for qemu-devel@nongnu.org; Thu, 05 Dec 2024 05:55:55 -0500 Received: by mail-pf1-x441.google.com with SMTP id d2e1a72fcca58-7251331e756so819544b3a.3 for ; Thu, 05 Dec 2024 02:55:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733396151; x=1734000951; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+lpaVTclhDlpFRzEmZQaeUmvCBh3nRuKyRkZZ569Nr4=; b=LR991K0jeW+5v17sSR9NPUcXMJC+UADlj4gTwZVW6OWWd7hQEWixhwDLXG7sKNn1+e ZIDLXnpJu8VbN1sMkq9TUSXkak84m97DDPWyOKpLnI0EF3t2ykE2DswtUbogspqbNhU8 8nLJeYBv964Gm2vMdh0z0gJkPiz3dXnl1nwhrTqt9pySd3V09fkgAyV6Y1Cji9KQeroR ADwSobgZBa00uM3pS2KnyeWHIRYXQdIZQvEqUWpJKQYRFgNKVPztxPoR6cb5BfanCni8 3mgi/hLd/T6pWTe4ElblcJI1OKRr+evStJk8Mw2yJt9Dy7BQ3VwUcnQsPoW/G07igAxF yqPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733396151; x=1734000951; 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=+lpaVTclhDlpFRzEmZQaeUmvCBh3nRuKyRkZZ569Nr4=; b=wn+EuvE8D+sF047Aeu8jUybc9llNlBzoQ4TIOE2fMFrGyIZlmrf2PWHCYL9evjK5On knZ2S8ev0Gg0rIFRsZfL9gJTJsvCpm5hiz7LP/rl+A2Aiydq9k4dw/Y04WhOdCsIi0Xd 8kt0hgEw/DMpPxftLFEHwEPa2KAQ+tbeFQVQze7cJv3fJCgS0tHXdeYVD786QtEpG6d2 Ok3KMd+5WROtFCdwkgzr0YLwaMIl1TJlpjPW4nkczkswrd23uTKLjK8NJWPoAY128WtH qOYKQPAuBTg60nAE0ybK4n8faDr21c0/FafEuZxvlf3LMuBkQqP3fQBEWdPKJwGQTvZu srKw== X-Gm-Message-State: AOJu0Yzh3Sj0BgCarArieFybiaDk2KgU0CmhIMsiOPyXmK6GCSMSHks7 tKfcb6DOz7ukrLut6gC/R1py/Nch30EkdXvuX7yy66fysn3H7fWj7T7EFJoTkg== X-Gm-Gg: ASbGncvKcmy8D8ANMcAvAuAQQYBADOxlZ5Itj8qtIjaM0vB5+PXQhNwEuSjKb+e8P/f ds5N898vbVQkYSd7Tr0+/Xpvgqb/fMTxwS7WFDdCMxWkQqw5T4fqJbiDV9vW3Ir+R0t7qrKljdH bVzGO2ZzleasT9IAr25VTQZiJthZUnzpoyFHq9UOQk7n1HF3yHcF0uLHFeCQ61IStc38Fjb91Ct 4YwKmYc9FaFsblTywCREbQEFh0t+IjQHmQExjflXPGvcQB7KyJ2kXIa4A== X-Google-Smtp-Source: AGHT+IEzM4jt/xlvppyVT22xK0FgBiDw6jv1SwVcjLLLpSg8xSYPf8z09jebU1nSOeQgS2VnxceIMQ== X-Received: by 2002:a05:6a00:3a16:b0:724:eac3:576a with SMTP id d2e1a72fcca58-7257fcca19fmr13553419b3a.25.1733396151340; Thu, 05 Dec 2024 02:55:51 -0800 (PST) Received: from kotori-desktop.lan ([58.38.120.33]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-725a2ca6747sm1010905b3a.149.2024.12.05.02.55.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Dec 2024 02:55:51 -0800 (PST) From: Tomita Moeko To: qemu-devel@nongnu.org Cc: Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , =?utf-8?q?Corvin_K=C3=B6hne?= , Tomita Moeko Subject: [PATCH v3 02/10] vfio/igd: align generation with i915 kernel driver Date: Thu, 5 Dec 2024 18:55:27 +0800 Message-ID: <20241205105535.30498-3-tomitamoeko@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241205105535.30498-1-tomitamoeko@gmail.com> References: <20241205105535.30498-1-tomitamoeko@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::441; envelope-from=tomitamoeko@gmail.com; helo=mail-pf1-x441.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Define the igd device generations according to i915 kernel driver to avoid confusion, and adjust comment placement to clearly reflect the relationship between ids and devices. The condition of how GTT stolen memory size is calculated is changed accordingly as GGMS is in multiple of 2 starting from gen 8. Reviewed-by: Corvin Köhne Signed-off-by: Tomita Moeko --- hw/vfio/igd.c | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c index 6ba3045bf3..18d179bc83 100644 --- a/hw/vfio/igd.c +++ b/hw/vfio/igd.c @@ -59,33 +59,34 @@ */ static int igd_gen(VFIOPCIDevice *vdev) { - if ((vdev->device_id & 0xfff) == 0xa84) { - return 8; /* Broxton */ + /* + * Device IDs for Broxton/Apollo Lake are 0x0a84, 0x1a84, 0x1a85, 0x5a84 + * and 0x5a85, match bit 11:1 here + * Prefix 0x0a is taken by Haswell, this rule should be matched first. + */ + if ((vdev->device_id & 0xffe) == 0xa84) { + return 9; } switch (vdev->device_id & 0xff00) { - /* SandyBridge, IvyBridge, ValleyView, Haswell */ - case 0x0100: - case 0x0400: - case 0x0a00: - case 0x0c00: - case 0x0d00: - case 0x0f00: + case 0x0100: /* SandyBridge, IvyBridge */ return 6; - /* BroadWell, CherryView, SkyLake, KabyLake */ - case 0x1600: - case 0x1900: - case 0x2200: - case 0x5900: + case 0x0400: /* Haswell */ + case 0x0a00: /* Haswell */ + case 0x0c00: /* Haswell */ + case 0x0d00: /* Haswell */ + case 0x0f00: /* Valleyview/Bay Trail */ + return 7; + case 0x1600: /* Broadwell */ + case 0x2200: /* Cherryview */ return 8; - /* CoffeeLake */ - case 0x3e00: + case 0x1900: /* Skylake */ + case 0x5900: /* Kaby Lake */ + case 0x3e00: /* Coffee Lake */ return 9; - /* ElkhartLake */ - case 0x4500: + case 0x4500: /* Elkhart Lake */ return 11; - /* TigerLake */ - case 0x9A00: + case 0x9A00: /* Tiger Lake */ return 12; } @@ -258,7 +259,7 @@ static int vfio_igd_gtt_max(VFIOPCIDevice *vdev) gmch = vfio_pci_read_config(&vdev->pdev, IGD_GMCH, sizeof(gmch)); ggms = (gmch >> (gen < 8 ? 8 : 6)) & 0x3; - if (gen > 6) { + if (gen >= 8) { ggms = 1 << ggms; } @@ -668,7 +669,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) /* Determine the size of stolen memory needed for GTT */ ggms_mb = (gmch >> (gen < 8 ? 8 : 6)) & 0x3; - if (gen > 6) { + if (gen >= 8) { ggms_mb = 1 << ggms_mb; } From patchwork Thu Dec 5 10:55:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomita Moeko X-Patchwork-Id: 13895007 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 75B03E7716C for ; Thu, 5 Dec 2024 10:56:45 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tJ9WZ-0005V3-Tx; Thu, 05 Dec 2024 05:56:00 -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 1tJ9WY-0005Rd-2k for qemu-devel@nongnu.org; Thu, 05 Dec 2024 05:55:58 -0500 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tJ9WW-0003Wa-El for qemu-devel@nongnu.org; Thu, 05 Dec 2024 05:55:57 -0500 Received: by mail-pf1-x441.google.com with SMTP id d2e1a72fcca58-72577d3b026so757481b3a.3 for ; Thu, 05 Dec 2024 02:55:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733396155; x=1734000955; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ghEpwFv0jtfaUZx94fv8Kp850KMtaEVl4DsECiLC2bQ=; b=OmrfDtcgdMuKuSvjHSApC61x4JGlGT5VyLZI9Wb8GhfV5d37gcVdZmZi3JLJ0m3u0k NgHrEVAbvH6OWmHHAjC6WYYA9HD7eDoKsNcni6QaemjY9fGLSC+22aCihv4NCazdAc// blmlodX8e/MpWnDtrhXg9ZUj1mM3aFPA+T8R1MDyoHUSWScjQ5Ni2+dnWJXLtWB/Cb+U 25xsNDf935dQTPPyeoV5/ova4elJxrESg9AYpEhRlgdmWg6AoJYEEWY/b8VUCzd8wJif 8lE0XHoheIsDU7tUlNjvWPl703PIhEiqWFuoiMjEOf1TQM7yWxFW+3EyABIhx+20x1cw y/Qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733396155; x=1734000955; 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=ghEpwFv0jtfaUZx94fv8Kp850KMtaEVl4DsECiLC2bQ=; b=BuIC7po4ttbbw7ze2UsMzXGi+smVfBQr/pEsde3O0NOETzudzdV3riasIFpdB0Fn5b yVDHwlAvaF7fGA315HsdCsyYi6THFWNdal+99t9Ca+GIr28n0/65TWCCYrGZan6xCoeZ DFIIMMQ6ARJzCmSRalOMxgKU1P63EIBD8jH5qPX9Qrp16f60aXjjSQ5Ewbrgou0oOiC8 8mZS9lpAgp1qACXkhoh3fHGO8ybeRpOoUhDY6HRni0FKhk7y42Tu/CximOVrYT7CypSM 8R0VLWQmxN4ky22C856eJ+PWgJVWdmyYo5aeHUO5fMp2QEQOyXcI8Bd3Z9YiaHGD5LMh Y4og== X-Gm-Message-State: AOJu0Yy0BvKOvaBRStSM66uaH/it6k+FCsTVBCL6uNGmbfe6SR9ejeb9 nt4giQWwNm73DmuqFjKZLwOu6dQjG05ps44iMp5cOyDxKA4gp9glpQeYr7T1zg== X-Gm-Gg: ASbGncuHq2Ah1lTOu4AlRnF6pULDyEsQBphvmIlrzu/excOqkpceNizD2dTE/q88niY nQwJg799hXkCuN80KMKcSKO9n+rPgTuvT2v6h+DHsxKER7qymyhZjxX85hrKm6GmqmCeGL0+jsV 1GvhRUJyjj7Qcvfi0pj30HB0Tqn7yFnnNjrzqw8eaHJ8e3e9P12nF+ybRVvst23XXmh5n2BZGGR SdMOpA9dEB+HZBvGBdpA9k3BgsS7aqZcSl9tM8xDgniR+sxcCqwls6vDA== X-Google-Smtp-Source: AGHT+IFuyEe8INiWEufKz4O5JZ3qooFvS1rePLxsDNcAOHeM9T634/dg2GJOhDtNR/JSieRjcaVJcg== X-Received: by 2002:a05:6a00:3cd5:b0:725:9ec3:7ed9 with SMTP id d2e1a72fcca58-7259ec3812bmr2472414b3a.21.1733396154832; Thu, 05 Dec 2024 02:55:54 -0800 (PST) Received: from kotori-desktop.lan ([58.38.120.33]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-725a2ca6747sm1010905b3a.149.2024.12.05.02.55.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Dec 2024 02:55:54 -0800 (PST) From: Tomita Moeko To: qemu-devel@nongnu.org Cc: Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , =?utf-8?q?Corvin_K=C3=B6hne?= , Tomita Moeko Subject: [PATCH v3 03/10] vfio/igd: fix GTT stolen memory size calculation for gen 8+ Date: Thu, 5 Dec 2024 18:55:28 +0800 Message-ID: <20241205105535.30498-4-tomitamoeko@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241205105535.30498-1-tomitamoeko@gmail.com> References: <20241205105535.30498-1-tomitamoeko@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::441; envelope-from=tomitamoeko@gmail.com; helo=mail-pf1-x441.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org On gen 8 and later devices, the GTT stolen memory size when GGMS equals 0 is 0 (no preallocated memory) rather than 1MB [1]. [1] 3.1.13, 5th Generation Intel Core Processor Family Datasheet Vol. 2 https://www.intel.com/content/www/us/en/content-details/330835 Reported-By: Alex Williamson Signed-off-by: Tomita Moeko --- hw/vfio/igd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c index 18d179bc83..09bd4e5383 100644 --- a/hw/vfio/igd.c +++ b/hw/vfio/igd.c @@ -259,7 +259,7 @@ static int vfio_igd_gtt_max(VFIOPCIDevice *vdev) gmch = vfio_pci_read_config(&vdev->pdev, IGD_GMCH, sizeof(gmch)); ggms = (gmch >> (gen < 8 ? 8 : 6)) & 0x3; - if (gen >= 8) { + if (gen >= 8 && ggms != 0) { ggms = 1 << ggms; } @@ -669,7 +669,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) /* Determine the size of stolen memory needed for GTT */ ggms_mb = (gmch >> (gen < 8 ? 8 : 6)) & 0x3; - if (gen >= 8) { + if (gen >= 8 && ggms_mb != 0) { ggms_mb = 1 << ggms_mb; } From patchwork Thu Dec 5 10:55:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomita Moeko X-Patchwork-Id: 13895005 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 870F5E77170 for ; Thu, 5 Dec 2024 10:56:35 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tJ9We-0005bL-8G; Thu, 05 Dec 2024 05:56:04 -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 1tJ9Wb-0005Z6-Oj for qemu-devel@nongnu.org; Thu, 05 Dec 2024 05:56:02 -0500 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tJ9Wa-0003bo-11 for qemu-devel@nongnu.org; Thu, 05 Dec 2024 05:56:01 -0500 Received: by mail-pf1-x441.google.com with SMTP id d2e1a72fcca58-725ad59ad72so141360b3a.2 for ; Thu, 05 Dec 2024 02:55:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733396158; x=1734000958; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Lx7mWSlMFt3UwBpDPHAXwsNgtKvBMAr06837vMU0kv4=; b=aM36dsgJAeF+LK5wTosMhRPXzRE1YDbwfn7XepLOB08umTlU34doMoPMD2kMMApPDz sHaVe7RWr29CSPwX2FfkoxdoYcSzx2Yjvkoy/TZucHm7Ax5OPXm4DipDSmYwyA5gw95v Ap6pTwRclPteuOZn0zNzl+9Y2Ve5bWGUc0aUS4qBAhhpBJkL5Xg2FYqBG+GP+vdWmOqk 0RdJCWeJfm1LAIT4D/CxmUwoho1T7sx9XPM4cEZ4CL+VyGBYUtu0kWpk2H9kYOK1Lak3 uWz7bRAg1OVxO59+3BOzRJONx0A3othU6b0848XJPqvwULYBIzdgQ7vvrCd2a/t5Ja4G YmEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733396158; x=1734000958; 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=Lx7mWSlMFt3UwBpDPHAXwsNgtKvBMAr06837vMU0kv4=; b=wkQp8zxTGve19zVkdUQKrGYur+krqLt0uUL+XymLz0RgEhQHogmVS5rO5tQR3g0MXF u+/SETpWHtvNz4MWAe/tFERLnags4MEOMQNwdrp/Cyi/dmp0zFYLHf1IkhChTfoqvBpq tC9ft6nDWVq+Is7OE1HioWPl5mpTfDtR32d8fCpwnwOt4f3qFtocZNAIzS/AobZNmR/h 5gn3+ZnZ9POcVUIBSpgSUVghoCG+tq3BNwm2+XqcqIx834Fp3McvtziovhFrPgGcofBM HCieRnfAF9HcRbNEnHfsVdcQuOc6O3LJYZ1qqaOGzBsLcOC7sVV3MmQiLfC09TvI4jIt 2/GQ== X-Gm-Message-State: AOJu0YxxL4CgyaFxILaVigUR+Nen7FBbEco4X2l/JkMrvNZomPzUg8bf Ht6XjUYAWeipzO9rrVHGizHCVXnVZI0IhsZS4FYDanP91dtJpSHyoCa/bUFnmw== X-Gm-Gg: ASbGncuxs9v7MQg9ezQNnQ6eZmuFSTIm8mB4x4HBwEXwTWnFNqMjul7TFodpp+Yj7ee TDriNmGvuotyLHOy9D/00v+iTm76XuhWBf9NARa0m7JlKmDVG7Xss1s6nAtkOOATZ8DAZDGu5ug qXjQLFaR2VvJp6Z0aZ+jyePFLK+1c2d/vR5EXRV/95yt8FLzZIqJccOSps9Gy/Q65sSddGEP38w 7/RfdKIQTm1F6Ozce6NdDVPLrJ/m0mPNwqfyTDdufeXKoGEoWt1UtroAg== X-Google-Smtp-Source: AGHT+IElHDMBurudKcGoWRWi6fyKYNok/8W+f8PLeyH9+kbUvgGCXItmMlhbbPN4nuo67Kwykyfniw== X-Received: by 2002:a05:6a00:a95:b0:71e:587d:f268 with SMTP id d2e1a72fcca58-72587ee644dmr11995990b3a.4.1733396158378; Thu, 05 Dec 2024 02:55:58 -0800 (PST) Received: from kotori-desktop.lan ([58.38.120.33]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-725a2ca6747sm1010905b3a.149.2024.12.05.02.55.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Dec 2024 02:55:58 -0800 (PST) From: Tomita Moeko To: qemu-devel@nongnu.org Cc: Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , =?utf-8?q?Corvin_K=C3=B6hne?= , Tomita Moeko Subject: [PATCH v3 04/10] vfio/igd: canonicalize memory size calculations Date: Thu, 5 Dec 2024 18:55:29 +0800 Message-ID: <20241205105535.30498-5-tomitamoeko@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241205105535.30498-1-tomitamoeko@gmail.com> References: <20241205105535.30498-1-tomitamoeko@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::441; envelope-from=tomitamoeko@gmail.com; helo=mail-pf1-x441.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Add helper functions igd_gtt_memory_size() and igd_stolen_size() for calculating GTT stolen memory and Data stolen memory size in bytes, and use macros to replace the hardware-related magic numbers for better readability. Signed-off-by: Tomita Moeko --- hw/vfio/igd.c | 101 ++++++++++++++++++++++++++++---------------------- 1 file changed, 57 insertions(+), 44 deletions(-) diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c index 09bd4e5383..e231865d72 100644 --- a/hw/vfio/igd.c +++ b/hw/vfio/igd.c @@ -107,6 +107,53 @@ typedef struct VFIOIGDQuirk { #define IGD_BDSM 0x5c /* Base Data of Stolen Memory */ #define IGD_BDSM_GEN11 0xc0 /* Base Data of Stolen Memory of gen 11 and later */ +#define IGD_GMCH_GEN6_GMS_SHIFT 3 /* SNB_GMCH in i915 */ +#define IGD_GMCH_GEN6_GMS_MASK 0x1f +#define IGD_GMCH_GEN6_GGMS_SHIFT 8 +#define IGD_GMCH_GEN6_GGMS_MASK 0x3 +#define IGD_GMCH_GEN8_GMS_SHIFT 8 /* BDW_GMCH in i915 */ +#define IGD_GMCH_GEN8_GMS_MASK 0xff +#define IGD_GMCH_GEN8_GGMS_SHIFT 6 +#define IGD_GMCH_GEN8_GGMS_MASK 0x3 + +static uint64_t igd_gtt_memory_size(int gen, uint16_t gmch) +{ + uint64_t ggms; + + if (gen < 8) { + ggms = (gmch >> IGD_GMCH_GEN6_GGMS_SHIFT) & IGD_GMCH_GEN6_GGMS_MASK; + } else { + ggms = (gmch >> IGD_GMCH_GEN8_GGMS_SHIFT) & IGD_GMCH_GEN8_GGMS_MASK; + if (ggms != 0) { + ggms = 1 << ggms; + } + } + + return ggms * MiB; +} + +static uint64_t igd_stolen_memory_size(int gen, uint32_t gmch) +{ + uint64_t gms; + + if (gen < 8) { + gms = (gmch >> IGD_GMCH_GEN6_GMS_SHIFT) & IGD_GMCH_GEN6_GMS_MASK; + } else { + gms = (gmch >> IGD_GMCH_GEN8_GMS_SHIFT) & IGD_GMCH_GEN8_GMS_MASK; + } + + if (gen < 9) { + return gms * 32 * MiB; + } else { + if (gms < 0xf0) { + return gms * 32 * MiB; + } else { + return (gms - 0xf0 + 1) * 4 * MiB; + } + } + + return 0; +} /* * The rather short list of registers that we copy from the host devices. @@ -255,17 +302,10 @@ static int vfio_pci_igd_lpc_init(VFIOPCIDevice *vdev, static int vfio_igd_gtt_max(VFIOPCIDevice *vdev) { uint32_t gmch = vfio_pci_read_config(&vdev->pdev, IGD_GMCH, sizeof(gmch)); - int ggms, gen = igd_gen(vdev); - - gmch = vfio_pci_read_config(&vdev->pdev, IGD_GMCH, sizeof(gmch)); - ggms = (gmch >> (gen < 8 ? 8 : 6)) & 0x3; - if (gen >= 8 && ggms != 0) { - ggms = 1 << ggms; - } - - ggms *= MiB; + int gen = igd_gen(vdev); + uint64_t ggms_size = igd_gtt_memory_size(gen, gmch); - return (ggms / (4 * KiB)) * (gen < 8 ? 4 : 8); + return (ggms_size / (4 * KiB)) * (gen < 8 ? 4 : 8); } /* @@ -472,30 +512,6 @@ void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, int nr) QLIST_INSERT_HEAD(&vdev->bars[nr].quirks, quirk, next); } -static int igd_get_stolen_mb(int gen, uint32_t gmch) -{ - int gms; - - if (gen < 8) { - gms = (gmch >> 3) & 0x1f; - } else { - gms = (gmch >> 8) & 0xff; - } - - if (gen < 9) { - if (gms > 0x10) { - error_report("Unsupported IGD GMS value 0x%x", gms); - return 0; - } - return gms * 32; - } else { - if (gms < 0xf0) - return gms * 32; - else - return (gms - 0xf0) * 4 + 4; - } -} - void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) { g_autofree struct vfio_region_info *rom = NULL; @@ -505,7 +521,8 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) VFIOQuirk *quirk; VFIOIGDQuirk *igd; PCIDevice *lpc_bridge; - int i, ret, ggms_mb, gms_mb = 0, gen; + int i, ret, gen; + uint64_t ggms_size, gms_size; uint64_t *bdsm_size; uint32_t gmch; uint16_t cmd_orig, cmd; @@ -667,13 +684,8 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) QLIST_INSERT_HEAD(&vdev->bars[nr].quirks, quirk, next); - /* Determine the size of stolen memory needed for GTT */ - ggms_mb = (gmch >> (gen < 8 ? 8 : 6)) & 0x3; - if (gen >= 8 && ggms_mb != 0) { - ggms_mb = 1 << ggms_mb; - } - - gms_mb = igd_get_stolen_mb(gen, gmch); + ggms_size = igd_gtt_memory_size(gen, gmch); + gms_size = igd_stolen_memory_size(gen, gmch); /* * Request reserved memory for stolen memory via fw_cfg. VM firmware @@ -684,7 +696,7 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) * config offset 0x5C. */ bdsm_size = g_malloc(sizeof(*bdsm_size)); - *bdsm_size = cpu_to_le64((ggms_mb + gms_mb) * MiB); + *bdsm_size = cpu_to_le64(ggms_size + gms_size); fw_cfg_add_file(fw_cfg_find(), "etc/igd-bdsm-size", bdsm_size, sizeof(*bdsm_size)); @@ -735,5 +747,6 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) vdev->vbasedev.name); } - trace_vfio_pci_igd_bdsm_enabled(vdev->vbasedev.name, ggms_mb + gms_mb); + trace_vfio_pci_igd_bdsm_enabled(vdev->vbasedev.name, + (ggms_size + gms_size) / MiB); } From patchwork Thu Dec 5 10:55:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tomita Moeko X-Patchwork-Id: 13895008 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 84AA8E7716C for ; Thu, 5 Dec 2024 10:56:48 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tJ9Wg-0005bk-CX; Thu, 05 Dec 2024 05:56:06 -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 1tJ9We-0005bK-75 for qemu-devel@nongnu.org; Thu, 05 Dec 2024 05:56:04 -0500 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tJ9Wc-0003cj-Su for qemu-devel@nongnu.org; Thu, 05 Dec 2024 05:56:03 -0500 Received: by mail-pf1-x442.google.com with SMTP id d2e1a72fcca58-7259a26ad10so596199b3a.1 for ; Thu, 05 Dec 2024 02:56:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733396161; x=1734000961; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DxafhFvYtf9jVszuSh+7ZDIex2hyUu5Kz37u7+ddEIU=; b=QEWn2cGDg/kUk9L2twWzJW6XeZ3f9WNhFNGQwxemsK8jHlqBS/Dq+xcKFj6Oe1zRLT LIZDCj1UyYQNjINn9g5+OaWpEj7d/hUGXVFgK5eRlF2+1YB+iLu9rHPw5oKYDps/PED8 LxJJmHMatw1pH5/8lzcgpMRGeN8KXu2kYOHQi9b8WoW34nXoq+iy+qkUCgcQVDCkzvPc D/Ye6DX1JR+X7qLOIHedJuvhEHDNCv4VQpg27X5MsEseS+S9OYl2vfK/QPbwpgxc+bqp 25b/ch2GAh+8uFQ2YU/wkkdoT0P8B69T4wtf2WyBhGJ8t4jb+rwhztxwYh53ZJI5nA9Q TWoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733396161; x=1734000961; 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=DxafhFvYtf9jVszuSh+7ZDIex2hyUu5Kz37u7+ddEIU=; b=tFZDH5TAjdbLn/RhsprCMsi8L3mt04W1dOQklE1gDQaxQFyiIszbSS46gFk3MjvRDv GSJxiLqSngC/rznuVek9Bp5N20g7cp0VDtz1jOCpLndazGWL2hz+CBiN9l8USUWaVodW CyEbVP20pylrqIb+wN7NDvQwM+JvyutWNfJZQBkvLmOG4ZgtSRpw0bSuZJGqrFXGA+TO S/YHAgDL3yQYj8u3EFyRVU0AKxqFaMiYRCQWXNF76HSsTRVXekLRdF2qFFv78yig1BSw g0GZESzN6MRtWfUK8dN1QA09Q60zjpE/5FU4LnY30Ss/rf7RUpgxiyg1DgJSAnkbptgp qjDg== X-Gm-Message-State: AOJu0Yx21NebEQx51jdO1vys1UNYozqiFPO4TuWTXvESuQcOv8Ct957t LW9K1l3ToTf7a85Qz1IgpEp5YYogVgsic8TGdXQmsz9lP5BJfnWLhsRQGKyMMQ== X-Gm-Gg: ASbGncvH+x48rgb+H3p5NnFzniHL0/cJVbh+MCC8u1oYTlbiD/kXR1fLvDeCy2AlVpv i8mPrIQbtDUpLu/XUV6rvoEhSFJFAUCwMHTakJz9roCG7jth847WeJkeR/InG06q1ExZudPQKCj /GcnWmqGjK+TqQ3sAaTMaSqIhvCnWZ0TwAgWB5lMQR8B3Pqe9SUVd0T8zbcQSvHXblLKcTKiyId CGvXlMncPcqmKb5MzDjoUvz/O+RAU6wLL3y4SQueYMUjh81FdV/BWM0rw== X-Google-Smtp-Source: AGHT+IEkD3tQsDEgh2ZuXMRKWxdFb2cm2O7aRW4deG44fcNagjy9437lUqcQScd76khla5M+mZ7FVw== X-Received: by 2002:a05:6a00:c86:b0:725:8edc:948a with SMTP id d2e1a72fcca58-7259d634437mr4087780b3a.8.1733396161245; Thu, 05 Dec 2024 02:56:01 -0800 (PST) Received: from kotori-desktop.lan ([58.38.120.33]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-725a2ca6747sm1010905b3a.149.2024.12.05.02.55.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Dec 2024 02:56:00 -0800 (PST) From: Tomita Moeko To: qemu-devel@nongnu.org Cc: Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , =?utf-8?q?Corvin_K=C3=B6hne?= , Tomita Moeko Subject: [PATCH v3 05/10] vfio/igd: add Gemini Lake and Comet Lake device ids Date: Thu, 5 Dec 2024 18:55:30 +0800 Message-ID: <20241205105535.30498-6-tomitamoeko@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241205105535.30498-1-tomitamoeko@gmail.com> References: <20241205105535.30498-1-tomitamoeko@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::442; envelope-from=tomitamoeko@gmail.com; helo=mail-pf1-x442.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Both Gemini Lake and Comet Lake are gen 9 devices. Many user reports on internet shows legacy mode of igd passthrough works as qemu treats them as gen 8 devices by default before e433f208973f ("vfio/igd: return an invalid generation for unknown devices"). Reviewed-by: Corvin Köhne Signed-off-by: Tomita Moeko --- hw/vfio/igd.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c index e231865d72..ed236f443a 100644 --- a/hw/vfio/igd.c +++ b/hw/vfio/igd.c @@ -81,8 +81,10 @@ static int igd_gen(VFIOPCIDevice *vdev) case 0x2200: /* Cherryview */ return 8; case 0x1900: /* Skylake */ + case 0x3100: /* Gemini Lake */ case 0x5900: /* Kaby Lake */ case 0x3e00: /* Coffee Lake */ + case 0x9B00: /* Comet Lake */ return 9; case 0x4500: /* Elkhart Lake */ return 11; From patchwork Thu Dec 5 10:55:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tomita Moeko X-Patchwork-Id: 13895013 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D5E34E77170 for ; Thu, 5 Dec 2024 10:57:36 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tJ9Wl-0005n0-Fd; Thu, 05 Dec 2024 05:56:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tJ9Wi-0005gl-4j for qemu-devel@nongnu.org; Thu, 05 Dec 2024 05:56:08 -0500 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tJ9Wg-0003dK-IV for qemu-devel@nongnu.org; Thu, 05 Dec 2024 05:56:07 -0500 Received: by mail-pf1-x442.google.com with SMTP id d2e1a72fcca58-7258bce5289so591971b3a.0 for ; Thu, 05 Dec 2024 02:56:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733396164; x=1734000964; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=u6IjMTOhbbtnbKyiu9odYQrXzvjL175+vD8tdZJb7kU=; b=T1xquenMk0ZKS0Upc2mBNxF2qG0CemI5770FCwVx3lxCDVTE6GjAiv2iUtVwkxQ+6n yN+iqqI09f55mo7NNuyakq0s+mOX5kiVIJZdVSf3RpNuMq/1sxDUL7HNjPAi77aQFaSl uLwY9rc7YaoSwqUjWMzeeQVuLEZQBr7HH5rrhMjY9tK0GqIS8B09iF0ttqJExLHQptP+ dIjFSrPa1BI0mT6EePOp/6OcgihBapRoaFwvGIoHhWHXai79J4jcLWwTSeh0pb8cE5H1 Zj6ctg5sI6cTg1Euu4qWsEkRcoXeGumsN8lU8PS0DAng5TbXcHaoOI9xOdDY26ZL2qbW pKYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733396164; x=1734000964; 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=u6IjMTOhbbtnbKyiu9odYQrXzvjL175+vD8tdZJb7kU=; b=HfjQAoihUIMWM/cuqhwk3EAwOt97p5w0HjRWxLBZJfnCEPVzQJqQVjW6xOQVsBLYlY cZk2JP3J3eXayPZp3VE7dnUvZrzqKNOoQmFA1yeJOn2zcs0IwHUnnPioF1v9XWM89gZL /jFHYhZg2OC2xRru4qhkNjUKtUZDp/xx5DWGTzicAJiOcRApKGlS9ifXazy58Rj9iABu pptNeKPHSpsoYAUpzoHSvimdTVcNe5A57GkLNYLPd5iRd/5Txt5KhQAbNhN6lNYwnFXN X4oQA5Z5R64bQkGGTEJClwd4t0FIw5HT15TdKEQ93oWVuLnSbj2O9/i1xVwc1AhOiov4 s+8w== X-Gm-Message-State: AOJu0YydXJzj5v9N/Ig9KuSm8YCXzJuiPh0jcxEqX4SiQcyZfVpZn188 UUOEDCXQuKgPCcHAdmkBzP+xNHU0MmG1BwDmRGqxtZ697HGc+W4WPhCcPii6vA== X-Gm-Gg: ASbGncsyBRBjeuFqGWcEy3ZBIC4WLtY9tT+5jywdK97k6fpXKKQNMWWugETGSAxEDsA l/WSNCHVgaph0qz6QeMgKjE+nG/dH/X2SLGCCuXIPft7yLjsH0q9Z0/kSdC1lme3rdmMSfy4U1J JJmnFGiq46X0xQKSG6kJDDAr2j2I3yf0jPXovd4pyJkspy6EJGK19Vjf6Nm7xNsVl7wfHzPgpne jUami/JMzFB7K6MRL9T+R99K29w3ov9rCIZaNOGAW9knKoev+3uqCHG3A== X-Google-Smtp-Source: AGHT+IEcXfPZNQpfUQWRyo13uSou100geH0MS+nU6Dr2t3NxXBPLbmhsbKoWJ5BEx4RpDEjSVrtrhg== X-Received: by 2002:a05:6a00:2d29:b0:71e:755c:6dad with SMTP id d2e1a72fcca58-72587ee6365mr13408932b3a.5.1733396164621; Thu, 05 Dec 2024 02:56:04 -0800 (PST) Received: from kotori-desktop.lan ([58.38.120.33]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-725a2ca6747sm1010905b3a.149.2024.12.05.02.56.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Dec 2024 02:56:04 -0800 (PST) From: Tomita Moeko To: qemu-devel@nongnu.org Cc: Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , =?utf-8?q?Corvin_K=C3=B6hne?= , Tomita Moeko Subject: [PATCH v3 06/10] vfio/igd: add Alder/Raptor/Rocket/Ice/Jasper Lake device ids Date: Thu, 5 Dec 2024 18:55:31 +0800 Message-ID: <20241205105535.30498-7-tomitamoeko@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241205105535.30498-1-tomitamoeko@gmail.com> References: <20241205105535.30498-1-tomitamoeko@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::442; envelope-from=tomitamoeko@gmail.com; helo=mail-pf1-x442.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org All gen 11 and 12 igd devices have 64 bit BDSM register at 0xC0 in its config space, add them to the list to support igd passthrough on Alder/ Raptor/Rocket/Ice/Jasper Lake platforms. Tested legacy mode of igd passthrough works properly on both linux and windows guests with AlderLake-S GT1 (8086:4680). Reviewed-by: Corvin Köhne Signed-off-by: Tomita Moeko --- hw/vfio/igd.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c index ed236f443a..49b6547776 100644 --- a/hw/vfio/igd.c +++ b/hw/vfio/igd.c @@ -86,9 +86,14 @@ static int igd_gen(VFIOPCIDevice *vdev) case 0x3e00: /* Coffee Lake */ case 0x9B00: /* Comet Lake */ return 9; + case 0x8A00: /* Ice Lake */ case 0x4500: /* Elkhart Lake */ + case 0x4E00: /* Jasper Lake */ return 11; case 0x9A00: /* Tiger Lake */ + case 0x4C00: /* Rocket Lake */ + case 0x4600: /* Alder Lake */ + case 0xA700: /* Raptor Lake */ return 12; } From patchwork Thu Dec 5 10:55:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomita Moeko X-Patchwork-Id: 13895006 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5064CE7716C for ; Thu, 5 Dec 2024 10:56:40 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tJ9Wo-0005yP-Pc; Thu, 05 Dec 2024 05:56:15 -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 1tJ9Wm-0005pe-6W for qemu-devel@nongnu.org; Thu, 05 Dec 2024 05:56:12 -0500 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tJ9Wk-0003dn-Iu for qemu-devel@nongnu.org; Thu, 05 Dec 2024 05:56:11 -0500 Received: by mail-pg1-x541.google.com with SMTP id 41be03b00d2f7-7fc22a88bcbso621892a12.2 for ; Thu, 05 Dec 2024 02:56:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733396168; x=1734000968; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DbyhL467kLFoNyl59lj+CqWMKUpCY5M1py2Usy4VavY=; b=QKFPVOzwsz1cJL6QUY7vasd1JfKzjHEKKsyOXzLP0DYKPxTMP41Utxrn7Oh+nbrNr2 yEi7hGfKfVxAZfebwNg/g+wDZZkzq9yZZarrX6lc8c4tYO8tqBT9sahOwj54nFTAOKKK qJQQ2IOFjsxiUvJWTzc6QKH+XSGTa5Y9j/a3lxjZRi4ab5iZ/xQvXOc8f7LkELMGhKIE CNuMge4sDSjhF71fsiOVTqBpAxm0rWWyAgx6wRibaANp68lTUi77+M5tMUcZopTrGjE6 DDKek43oK+pNMr7Htn5ml9yDhVeLs8WU3JSbfCUeohlSdI3JEH7PbIZ0PaiSI+YMpv24 JfPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733396168; x=1734000968; 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=DbyhL467kLFoNyl59lj+CqWMKUpCY5M1py2Usy4VavY=; b=khkaW+FxPQyocq/RrX5lfnOcmVwLsiWBzW911Bdj8+uE5J+RZ8CQeAyhnYh9of9DT/ GF8Eye6fmg3TTHyEwm/nAjthvnF/2fKtVn+HBUBLsH4DIkECV5CJm8mE2YDYaWJQP5d4 RAAUBATqkWNP6Tfi1z9+dz0qnKfs69dutgCSO1odCM+CV+/diijETAIb2py72upeQEUy H7bA6Du8TsakEFMXoaOih88XweTPin6ttMEfHIRyQo/FeZYMwSmFf8nQxFyasEmegx0A JWocWHW3SYqCIwVO8exU3TGbd261qSZ4e5x8ErnYa6UTQabWHwJU7WhgeMeBQzROcv3u jInQ== X-Gm-Message-State: AOJu0YyQUUwmz6ANSstYyV7s7lSizF4GIy2eDLh2UKzAw+v9ide2kNvS mI0KHwyi900pBB3zB0HMrQ5tHv5ivnihrveUQLqbJsEvyL94veQlXhm4EV7+5Q== X-Gm-Gg: ASbGncsPqeiu3QQgllQ34Z/3TPwEdBJDhqBA+lIq0yd8Ghrh0Ki8qYtRogCRjulTqxm AsD1GQh4uW/JRpbD6vTeq0jFxoLcXfKRTCC8BPTfXDlvEUtdYKxInthfT2Nv63FjYsed4XP1JIo gsAfcqlZkBuqYHbw5foraU67fTW9Kf+qOHFXEYBkLnbgPJlDymbV4nPoMThkn5zWjUjBAGwvk4C NXMwynrqYwh7mA7LyFuRUZ4raMlNPZzcAuOf7u7+17Sbcs/qHa19qtPqA== X-Google-Smtp-Source: AGHT+IG47WGTWjdqjMTm9Njiqcark6Mz6UkfHmV3El3oV95OeATOQQ1ZWGxpvGKi+pdlX5DAiitt6w== X-Received: by 2002:a05:6a21:99a0:b0:1d9:780a:4311 with SMTP id adf61e73a8af0-1e1653b9e35mr14590656637.18.1733396168246; Thu, 05 Dec 2024 02:56:08 -0800 (PST) Received: from kotori-desktop.lan ([58.38.120.33]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-725a2ca6747sm1010905b3a.149.2024.12.05.02.56.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Dec 2024 02:56:07 -0800 (PST) From: Tomita Moeko To: qemu-devel@nongnu.org Cc: Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , =?utf-8?q?Corvin_K=C3=B6hne?= , Tomita Moeko Subject: [PATCH v3 07/10] vfio/igd: add macro for declaring mirrored registers Date: Thu, 5 Dec 2024 18:55:32 +0800 Message-ID: <20241205105535.30498-8-tomitamoeko@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241205105535.30498-1-tomitamoeko@gmail.com> References: <20241205105535.30498-1-tomitamoeko@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::541; envelope-from=tomitamoeko@gmail.com; helo=mail-pg1-x541.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org igd devices have multipe registers mirroring mmio address and pci config space, more than a single BDSM register. To support this, the read/write functions are made common and a macro is defined to simplify the declaration of MemoryRegionOps. Signed-off-by: Tomita Moeko --- hw/vfio/igd.c | 60 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c index 49b6547776..18d159aa8e 100644 --- a/hw/vfio/igd.c +++ b/hw/vfio/igd.c @@ -421,16 +421,9 @@ static const MemoryRegionOps vfio_igd_index_quirk = { .endianness = DEVICE_LITTLE_ENDIAN, }; -#define IGD_BDSM_MMIO_OFFSET 0x1080C0 - -static uint64_t vfio_igd_quirk_bdsm_read(void *opaque, - hwaddr addr, unsigned size) +static uint64_t vfio_igd_pci_config_read(VFIOPCIDevice *vdev, uint64_t offset, + unsigned size) { - VFIOPCIDevice *vdev = opaque; - uint64_t offset; - - offset = IGD_BDSM_GEN11 + addr; - switch (size) { case 1: return pci_get_byte(vdev->pdev.config + offset); @@ -441,21 +434,17 @@ static uint64_t vfio_igd_quirk_bdsm_read(void *opaque, case 8: return pci_get_quad(vdev->pdev.config + offset); default: - hw_error("igd: unsupported read size, %u bytes", size); + hw_error("igd: unsupported pci config read at %lx, size %u", + offset, size); break; } return 0; } -static void vfio_igd_quirk_bdsm_write(void *opaque, hwaddr addr, - uint64_t data, unsigned size) +static void vfio_igd_pci_config_write(VFIOPCIDevice *vdev, uint64_t offset, + uint64_t data, unsigned size) { - VFIOPCIDevice *vdev = opaque; - uint64_t offset; - - offset = IGD_BDSM_GEN11 + addr; - switch (size) { case 1: pci_set_byte(vdev->pdev.config + offset, data); @@ -470,17 +459,39 @@ static void vfio_igd_quirk_bdsm_write(void *opaque, hwaddr addr, pci_set_quad(vdev->pdev.config + offset, data); break; default: - hw_error("igd: unsupported read size, %u bytes", size); + hw_error("igd: unsupported pci config write at %lx, size %u", + offset, size); break; } } -static const MemoryRegionOps vfio_igd_bdsm_quirk = { - .read = vfio_igd_quirk_bdsm_read, - .write = vfio_igd_quirk_bdsm_write, - .endianness = DEVICE_LITTLE_ENDIAN, +#define VFIO_IGD_QUIRK_MIRROR_REG(reg, name) \ +static uint64_t vfio_igd_quirk_read_##name(void *opaque, \ + hwaddr addr, unsigned size) \ +{ \ + VFIOPCIDevice *vdev = opaque; \ + \ + return vfio_igd_pci_config_read(vdev, reg + addr, size); \ +} \ + \ +static void vfio_igd_quirk_write_##name(void *opaque, hwaddr addr, \ + uint64_t data, unsigned size) \ +{ \ + VFIOPCIDevice *vdev = opaque; \ + \ + vfio_igd_pci_config_write(vdev, reg + addr, data, size); \ +} \ + \ +static const MemoryRegionOps vfio_igd_quirk_mirror_##name = { \ + .read = vfio_igd_quirk_read_##name, \ + .write = vfio_igd_quirk_write_##name, \ + .endianness = DEVICE_LITTLE_ENDIAN, \ }; +VFIO_IGD_QUIRK_MIRROR_REG(IGD_BDSM_GEN11, bdsm) + +#define IGD_BDSM_MMIO_OFFSET 0x1080C0 + void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, int nr) { VFIOQuirk *quirk; @@ -510,8 +521,9 @@ void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, int nr) quirk = vfio_quirk_alloc(1); quirk->data = vdev; - memory_region_init_io(&quirk->mem[0], OBJECT(vdev), &vfio_igd_bdsm_quirk, - vdev, "vfio-igd-bdsm-quirk", 8); + memory_region_init_io(&quirk->mem[0], OBJECT(vdev), + &vfio_igd_quirk_mirror_bdsm, vdev, + "vfio-igd-bdsm-quirk", 8); memory_region_add_subregion_overlap(vdev->bars[0].region.mem, IGD_BDSM_MMIO_OFFSET, &quirk->mem[0], 1); From patchwork Thu Dec 5 10:55:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomita Moeko X-Patchwork-Id: 13895009 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3A6D6E7716C for ; Thu, 5 Dec 2024 10:57:00 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tJ9X0-0006JC-Ho; Thu, 05 Dec 2024 05:56:26 -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 1tJ9Ww-00066q-SO for qemu-devel@nongnu.org; Thu, 05 Dec 2024 05:56:22 -0500 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tJ9Wn-0003em-HJ for qemu-devel@nongnu.org; Thu, 05 Dec 2024 05:56:14 -0500 Received: by mail-pl1-x642.google.com with SMTP id d9443c01a7336-215909152c5so7928545ad.3 for ; Thu, 05 Dec 2024 02:56:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733396171; x=1734000971; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Afev6en4kR+CrZleuto4wB3x+yzqkCFox++dU9LzUsA=; b=bEi+aJEzgzpOmdJaaHAfB/Pzu3/e0fSJTLniRkiQMD4aqkOwQSQDgYm+7Duv4ZoyGg m6uSikOcWR9sgHfMzAIFXJwuc31trgqOLYg4INN+HqltFUzi+3zXf8DyeY237xXwJco1 hw++QIQ06FRiPQJ+CZLIRPkuJm42bgj1FsE9wCNY3T73Z2poA6dX9A4Q4gu+YxV+ORR/ NpM76gQKwxdd39Q5oSG/pi+FHSqCE79zPo/a1tNwAs4yaOFxqYwlVAQZygchqScrKaY9 de0WAUddOYYu786y7wI+OlvFcLYqkhy+r+7+IAWtOyq72hzLXON8mYPr4/on6q/bsypB JkHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733396171; x=1734000971; 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=Afev6en4kR+CrZleuto4wB3x+yzqkCFox++dU9LzUsA=; b=XzJafLUbQfaddCNzwYKr3D+HTS0T5GggMSDNSFTnAE55R883jA+12ize+vpNtT/rn0 hnxiYOf+OIL9HM0hpyUi3UTDyc3hOeHlCFQsjkukmFOnE1JvQFqJWg8yw4rui+xdTPFI D1s12PYzkxZLXsyiOJ+3LoXQVQJNngU1RhgYkn+FCNzEo70K8bvFszJlyWZt8ggxxrnl t/q9zSsFdHbd72oz9WzIWybzUMd+x0qrRnchw2ARJeBTEe0dEsVigoiLg3sbCHAr0++P /wFlkn8YVKU2V0DWYMI+apEWXZLtgTP6Pz/ZUglRvY1kF1mdz9laCLTe37yw5hisYZcw l2Mg== X-Gm-Message-State: AOJu0YzcXcW+PUnF19LSpRfyg/sDw4+LE/25e9IKLpXQRnE+CUZ8D9vr jxeQcc7dCOnTOZ6vbZoeUCqN+7f3peS3WMyTAXKWTRt2jmzITBd03myEQmIlaA== X-Gm-Gg: ASbGncuwQGz3J2QtsFPWMWDaZLHM4Aru4SmyktbJyKEgAK8L/h0Kdr+aZ2XJgGlHOti xMjDJroGucgbUVmJ6T7p+3KIFFCD3IISTX24TbCbinDeH03WI/zmnQIzymkOdNWh3jLmSk35eS0 52g3aoV0+1XuzTG10hpE+II3+IMEu7HGwUFF3Bw5RQrnhsI7HOX8RRaJfADFKRY4HPC2kV8bRx9 tStt9doh/qncNE+glyfpLIqf8Tg43YH6rGmvP5o18LYFeYLP3ALiYhHAw== X-Google-Smtp-Source: AGHT+IGPKdydCue07Ns3c9gmXsFN8oeu7yRBTNG/TIcycFfDBLY2MvLM5p5xvGg9I8J3AkSNq2ZsxQ== X-Received: by 2002:a17:902:dacb:b0:215:a60d:bcd9 with SMTP id d9443c01a7336-215bd24ba1bmr97962255ad.45.1733396170947; Thu, 05 Dec 2024 02:56:10 -0800 (PST) Received: from kotori-desktop.lan ([58.38.120.33]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-725a2ca6747sm1010905b3a.149.2024.12.05.02.56.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Dec 2024 02:56:10 -0800 (PST) From: Tomita Moeko To: qemu-devel@nongnu.org Cc: Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , =?utf-8?q?Corvin_K=C3=B6hne?= , Tomita Moeko Subject: [PATCH v3 08/10] vfio/igd: emulate GGC register in mmio bar0 Date: Thu, 5 Dec 2024 18:55:33 +0800 Message-ID: <20241205105535.30498-9-tomitamoeko@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241205105535.30498-1-tomitamoeko@gmail.com> References: <20241205105535.30498-1-tomitamoeko@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::642; envelope-from=tomitamoeko@gmail.com; helo=mail-pl1-x642.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The GGC register at 0x50 of pci config space is a mirror of the same register at 0x108040 of mmio bar0 [1]. i915 driver also reads that register from mmio bar0 instead of config space. As GGC is programmed and emulated by qemu, the mmio address should also be emulated, in the same way of BDSM register. [1] 4.1.28, 12th Generation Intel Core Processors Datasheet Volume 2 https://www.intel.com/content/www/us/en/content-details/655259 Signed-off-by: Tomita Moeko --- hw/vfio/igd.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c index 18d159aa8e..12e0553e83 100644 --- a/hw/vfio/igd.c +++ b/hw/vfio/igd.c @@ -488,8 +488,10 @@ static const MemoryRegionOps vfio_igd_quirk_mirror_##name = { \ .endianness = DEVICE_LITTLE_ENDIAN, \ }; +VFIO_IGD_QUIRK_MIRROR_REG(IGD_GMCH, ggc) VFIO_IGD_QUIRK_MIRROR_REG(IGD_BDSM_GEN11, bdsm) +#define IGD_GGC_MMIO_OFFSET 0x108040 #define IGD_BDSM_MMIO_OFFSET 0x1080C0 void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, int nr) @@ -518,14 +520,21 @@ void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, int nr) return; } - quirk = vfio_quirk_alloc(1); + quirk = vfio_quirk_alloc(2); quirk->data = vdev; memory_region_init_io(&quirk->mem[0], OBJECT(vdev), + &vfio_igd_quirk_mirror_ggc, vdev, + "vfio-igd-ggc-quirk", 2); + memory_region_add_subregion_overlap(vdev->bars[0].region.mem, + IGD_GGC_MMIO_OFFSET, &quirk->mem[0], + 1); + + memory_region_init_io(&quirk->mem[1], OBJECT(vdev), &vfio_igd_quirk_mirror_bdsm, vdev, "vfio-igd-bdsm-quirk", 8); memory_region_add_subregion_overlap(vdev->bars[0].region.mem, - IGD_BDSM_MMIO_OFFSET, &quirk->mem[0], + IGD_BDSM_MMIO_OFFSET, &quirk->mem[1], 1); QLIST_INSERT_HEAD(&vdev->bars[nr].quirks, quirk, next); From patchwork Thu Dec 5 10:55:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tomita Moeko X-Patchwork-Id: 13895010 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1606EE7716C for ; Thu, 5 Dec 2024 10:57:15 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tJ9X2-0006OQ-I1; Thu, 05 Dec 2024 05:56:28 -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 1tJ9Wy-0006Fm-A2 for qemu-devel@nongnu.org; Thu, 05 Dec 2024 05:56:24 -0500 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tJ9Wu-0003f0-UU for qemu-devel@nongnu.org; Thu, 05 Dec 2024 05:56:24 -0500 Received: by mail-pg1-x541.google.com with SMTP id 41be03b00d2f7-7fc41b4c78bso498577a12.3 for ; Thu, 05 Dec 2024 02:56:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733396173; x=1734000973; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=pJksUVkEtwEudvlxsC5f5lHQl1QlNlGKcBR7V40Y6N8=; b=V9rkKx3xiAibnCwx1xUph9HbznuIkZxgtB6NDGz+ZY4qCYIzafqJ8uT++lOacU9TBj eMzaPU/PL1WLxDxHrWdm1S+gI/JraxaCvPqdO3S1NczPnYZ16AlyuuAfCCuhyD5jwKiP m2bcJeq3jnZOa6tsgNoJB40/wdw1vw4TSMoJu3bTcphT/YI7TcblQ3yRqIvp/xAVeYKu oxdRMwd3oEsh9aW7g/ybT4cWD1uhy2iwnO0eI+nhY5Wh9VFzPUfgEuOzYtaMkZsEZxvY +98B/tEz9MCQtR0lkZNBl9qD4vCve4XGT6ae6ATwxeE7F96U7KDR0FSX34TsZoOGfHAp XDSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733396173; x=1734000973; 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=pJksUVkEtwEudvlxsC5f5lHQl1QlNlGKcBR7V40Y6N8=; b=Toa8ioKlwsY9Fr4UvWFMlD2ncXW0w14o2YnqErY8NYD2j/VoLF5zpbellX2/qSNsQn XZ/nTwwWUs6N3paABWthEEPQAb8X9HzNYTJIMdyNf/+fKsfYjD28zyC5SdLnmOJ0nTTm n4GZ4nXZAfmgfaNoF4ZCj2XhISpRh0l5CwLJ9V6QUs9W41GS21LHzq1bwDYfJ/fQBjNa B8JJ77krRxQIW71xTgIGc5C730Aob7YRRzHA+wCzxb7wVrJIChcvnIG3B6posGTbyCUa k47BgWjAFjRzg903aiqjdfiApnwAEnJMpQHrQk7Naaw6EIdIPCQbBURmDXwIQyG0THkt g6Qw== X-Gm-Message-State: AOJu0YyBNx0NhdWjWMkPgkDXpPBknADF6190ux1Ij3OBbAJ2qFLGRWeX 0hqdyaooIYl1jptn6Ow/hgYeSa3DDcMrhcG7D3aAjKKsAZeyzLqmBi6YJIVIKw== X-Gm-Gg: ASbGnctxENx95g9bSbRhPJ6qUepdjOu2jifQCxPTjIXCUJcycFRPOu0h/eE6b3TC12/ VUSa3kfre9Jm1ViH90JS2I4yQKn8Atnr/jsY/6MhAC4H4zJqgNNvIgAP6WsLMU80knOb0xiszui 7sO0qH6XQPtM4ogVp8dy4XTKGfHg0WfbrHIfGZJcatyHwNUVzqIUrXD0HkmDCdOW1QTNVOy9Mul BycwtG2IwzeKRYZ2S22yoS+1KxIdwoR+8+RFy05SwxO6CEqq2PctkE4JA== X-Google-Smtp-Source: AGHT+IFQl82deMWUZdn5mNFsgF9nRsCUuJtg0zW87nzUeU/pa0DnAetKJw8HCiguehQo6CRRBoxulg== X-Received: by 2002:a05:6a20:8410:b0:1e0:c247:21d2 with SMTP id adf61e73a8af0-1e1653c8294mr16251506637.23.1733396173649; Thu, 05 Dec 2024 02:56:13 -0800 (PST) Received: from kotori-desktop.lan ([58.38.120.33]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-725a2ca6747sm1010905b3a.149.2024.12.05.02.56.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Dec 2024 02:56:13 -0800 (PST) From: Tomita Moeko To: qemu-devel@nongnu.org Cc: Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , =?utf-8?q?Corvin_K=C3=B6hne?= , Tomita Moeko Subject: [PATCH v3 09/10] vfio/igd: emulate BDSM in mmio bar0 for gen 6-10 devices Date: Thu, 5 Dec 2024 18:55:34 +0800 Message-ID: <20241205105535.30498-10-tomitamoeko@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241205105535.30498-1-tomitamoeko@gmail.com> References: <20241205105535.30498-1-tomitamoeko@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::541; envelope-from=tomitamoeko@gmail.com; helo=mail-pg1-x541.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org A recent commit in i915 driver [1] claims the BDSM register at 0x1080c0 of mmio bar0 has been there since gen 6. Mirror this register to the 32 bit BDSM register at 0x5c in pci config space for gen6-10 devices. [1] https://patchwork.freedesktop.org/patch/msgid/20240202224340.30647-7-ville.syrjala@linux.intel.com Reviewed-by: Corvin Köhne Signed-off-by: Tomita Moeko --- hw/vfio/igd.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c index 12e0553e83..73c06bbf64 100644 --- a/hw/vfio/igd.c +++ b/hw/vfio/igd.c @@ -489,7 +489,8 @@ static const MemoryRegionOps vfio_igd_quirk_mirror_##name = { \ }; VFIO_IGD_QUIRK_MIRROR_REG(IGD_GMCH, ggc) -VFIO_IGD_QUIRK_MIRROR_REG(IGD_BDSM_GEN11, bdsm) +VFIO_IGD_QUIRK_MIRROR_REG(IGD_BDSM, bdsm) +VFIO_IGD_QUIRK_MIRROR_REG(IGD_BDSM_GEN11, bdsm64) #define IGD_GGC_MMIO_OFFSET 0x108040 #define IGD_BDSM_MMIO_OFFSET 0x1080C0 @@ -516,7 +517,7 @@ void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, int nr) * into MMIO space and read from MMIO space by the Windows driver. */ gen = igd_gen(vdev); - if (gen < 11) { + if (gen < 6) { return; } @@ -530,12 +531,21 @@ void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, int nr) IGD_GGC_MMIO_OFFSET, &quirk->mem[0], 1); - memory_region_init_io(&quirk->mem[1], OBJECT(vdev), - &vfio_igd_quirk_mirror_bdsm, vdev, - "vfio-igd-bdsm-quirk", 8); - memory_region_add_subregion_overlap(vdev->bars[0].region.mem, - IGD_BDSM_MMIO_OFFSET, &quirk->mem[1], - 1); + if (gen < 11) { + memory_region_init_io(&quirk->mem[1], OBJECT(vdev), + &vfio_igd_quirk_mirror_bdsm, vdev, + "vfio-igd-bdsm-quirk", 4); + memory_region_add_subregion_overlap(vdev->bars[0].region.mem, + IGD_BDSM_MMIO_OFFSET, + &quirk->mem[1], 1); + } else { + memory_region_init_io(&quirk->mem[1], OBJECT(vdev), + &vfio_igd_quirk_mirror_bdsm64, vdev, + "vfio-igd-bdsm-quirk", 8); + memory_region_add_subregion_overlap(vdev->bars[0].region.mem, + IGD_BDSM_MMIO_OFFSET, + &quirk->mem[1], 1); + } QLIST_INSERT_HEAD(&vdev->bars[nr].quirks, quirk, next); } From patchwork Thu Dec 5 10:55:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomita Moeko X-Patchwork-Id: 13895012 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8B8C4E77173 for ; Thu, 5 Dec 2024 10:57:20 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tJ9X2-0006Np-Dr; Thu, 05 Dec 2024 05:56:28 -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 1tJ9Wy-0006Fi-9H for qemu-devel@nongnu.org; Thu, 05 Dec 2024 05:56:24 -0500 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tJ9Ww-0003fR-Ki for qemu-devel@nongnu.org; Thu, 05 Dec 2024 05:56:24 -0500 Received: by mail-pf1-x442.google.com with SMTP id d2e1a72fcca58-7258cf297d4so739433b3a.2 for ; Thu, 05 Dec 2024 02:56:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733396177; x=1734000977; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DMVtNuBqtIXXm2C24hwxrJtPRQT47P73SaeeHd2lWK4=; b=faMLOlNFe0C6rRNRxTFR3FC4p5fBNFq+EPRJcwpoTEChQsxAqeaQa16ahXG6z1BZtL e8t2oCXsfMwPkM5ccP/fOk0sNyvhvRqHjsjEo279xJpfv7PFl5RN8BBk0JEEMPEsU0Oi gARwZPOtX1KZE6/CfxHLwOHF3W4aZ0VUKyE+B1SN0vHbWbgTwIklSmM0/Zq7AS6Fstkd ImFTNsKQDawrPHBXqS84CUdCY/5QXL5PutjXK8ED4Nz4Sq0kWAp9MoG+2kKVGfgblQr6 P7OJS8Vx0oBWXCbhBxavX0sy9N9p78wuXQgBie0VwpGqXYEiNigIZj2F9OuiEL63prN3 8ZFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733396177; x=1734000977; 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=DMVtNuBqtIXXm2C24hwxrJtPRQT47P73SaeeHd2lWK4=; b=rNmQBI0belaEVijB3mq1j4R5KGqGiZml1BSKv+PDatGl5111fhURKqr7m7TTElpceP KS2RH/Ko32rJfyLZnRptQqBkOqLWghqB5neMaMKFvAp8Td4VSdM4jWYxojtOZJ8bVN6G x49KT2e3B23WixAeS2EVeSqGiDId/LlvqxPJcZClznmp+Cu4hYFY7MyWTSbZuVmv1ph2 VjBoJk1UEa0eAc08HPcZobMvUFW3bMW9ZzJWM8MPFBF5Tx7CBzZjDYUuvdhYPEtjoFf8 uNWw6Phv5EgTSVK5ENU/rEDLNTT1ShZKyi5/nDUV46qmP/+uIcfm2L2JZMfvQdShcMDu yiSw== X-Gm-Message-State: AOJu0Yzn2BWU9rHdVb0200pzlHrCtDZ3n65v3cZmV7nLzCdy92UbFcz8 EFWao+LRkpgVRuw9l135bAAem3+2KPTpQDIkGk5RlokNZd+OKYc/Cg4GEd+Mbw== X-Gm-Gg: ASbGncvzNxHnnYkUTWv+SEJkbaIRtno32zVKt2k5XcKXe76+FQdIiW/5AjkeiTjeWYT 5/6An4qNntsx6n9l0+FJtlBqEMkWIQzHSkMJirzAKHD/Px0S/+tI4cbLCCAemft8N2WpWO5BN2M 1EcGFOw2byvJEhaFWL8kY2Zh6Q9BNwM0ieYU7hNzz2qxO7JwISQrY2AxmSQBqK5JNvW2fBGh4xM 3Tkrx2jDwnCOfESTPstm1OsC0zF74YBj4dtrxb9fq7O67y2q1n9VIKD8A== X-Google-Smtp-Source: AGHT+IHuIdpgw/LuC72t6bmxi6VEw3WoD084zBzgUlsYBXDyKYexlvZXexLMVRNNov4+TTxrK/SE+A== X-Received: by 2002:a05:6a00:1d1c:b0:724:dba1:61ef with SMTP id d2e1a72fcca58-7257fcca10cmr14326435b3a.24.1733396177131; Thu, 05 Dec 2024 02:56:17 -0800 (PST) Received: from kotori-desktop.lan ([58.38.120.33]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-725a2ca6747sm1010905b3a.149.2024.12.05.02.56.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Dec 2024 02:56:16 -0800 (PST) From: Tomita Moeko To: qemu-devel@nongnu.org Cc: Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_G?= =?utf-8?q?oater?= , =?utf-8?q?Corvin_K=C3=B6hne?= , Tomita Moeko Subject: [PATCH v3 10/10] vfio/igd: add x-igd-gms option back to set DSM region size for guest Date: Thu, 5 Dec 2024 18:55:35 +0800 Message-ID: <20241205105535.30498-11-tomitamoeko@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241205105535.30498-1-tomitamoeko@gmail.com> References: <20241205105535.30498-1-tomitamoeko@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::442; envelope-from=tomitamoeko@gmail.com; helo=mail-pf1-x442.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org DSM region is likely to store framebuffer in Windows, a small DSM region may cause display issues (e.g. half of the screen is black). Since 971ca22f041b ("vfio/igd: don't set stolen memory size to zero"), the x-igd-gms option was functionally removed, QEMU uses host's original value, which is determined by DVMT Pre-Allocated option in Intel FSP of host bios. However, some vendors do not expose this config item to users. In such cases, x-igd-gms option can be used to manually set the data stolen memory size for guest. So this commit brings this option back, keeping its old behavior. When it is not specified, QEMU uses host's value. When DVMT Pre-Allocated option is available in host BIOS, user should set DSM region size there instead of using x-igd-gms option. Signed-off-by: Tomita Moeko --- hw/vfio/igd.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c index 73c06bbf64..b0fef90240 100644 --- a/hw/vfio/igd.c +++ b/hw/vfio/igd.c @@ -14,6 +14,7 @@ #include "qemu/units.h" #include "qemu/error-report.h" #include "qapi/error.h" +#include "qapi/qmp/qerror.h" #include "hw/hw.h" #include "hw/nvram/fw_cfg.h" #include "pci.h" @@ -722,6 +723,31 @@ void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) QLIST_INSERT_HEAD(&vdev->bars[nr].quirks, quirk, next); + /* + * Allow user to override dsm size using x-igd-gms option, in multiples of + * 32MiB. This option should only be used when the desired size cannot be + * set from DVMT Pre-Allocated option in host BIOS. + */ + if (vdev->igd_gms) { + if (gen < 8) { + if (vdev->igd_gms <= 0x10) { + gmch &= ~(IGD_GMCH_GEN6_GMS_MASK << IGD_GMCH_GEN6_GMS_SHIFT); + gmch |= vdev->igd_gms << IGD_GMCH_GEN6_GMS_SHIFT; + } else { + error_report(QERR_INVALID_PARAMETER_VALUE, + "x-igd-gms", "0~0x10"); + } + } else { + if (vdev->igd_gms <= 0x40) { + gmch &= ~(IGD_GMCH_GEN8_GMS_MASK << IGD_GMCH_GEN8_GMS_SHIFT); + gmch |= vdev->igd_gms << IGD_GMCH_GEN8_GMS_SHIFT; + } else { + error_report(QERR_INVALID_PARAMETER_VALUE, + "x-igd-gms", "0~0x40"); + } + } + } + ggms_size = igd_gtt_memory_size(gen, gmch); gms_size = igd_stolen_memory_size(gen, gmch);