From nobody Tue Feb 10 23:53:34 2026 Received: from smtpbg153.qq.com (smtpbg153.qq.com [13.245.218.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 35B2C179AA for ; Mon, 22 Apr 2024 05:27:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.245.218.24 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713763642; cv=none; b=VMNdPhQbur8uoKl62+tq/1BIO2WgsCd/8Qs6yBoGpUEES7L9K/T1lANdJPnAbnfrhDG8qNMYZy0NNF8X8iWV1RHhJGxUMbw5NTV5YPGAXaJEtPk6KXx5zaovY/hfeN85oJwUflYvOnASUpREFi9i/DVlz8xmKVw7k76fIgHV4GU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713763642; c=relaxed/simple; bh=+DIJOjcAO+wpSqnfsIPcGEzwnny61DbFMPbZYgFD+tU=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=RcrUIroozo52/fD5uX8hJrZw4wQjIANLBFKO1VN79BPl6KJPHXOd9Pio/Aq1X/I58AVtlJDNZ2tCag2jUDEvg4rzxyo0jYt+It2EvT7iE67Sdp1qLyoneYjlE3wEJuoraLQdV30FdWrDa1E5X76cs6E8tj8qPeQJKUXnDDq5IDs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=uniontech.com; spf=pass smtp.mailfrom=uniontech.com; arc=none smtp.client-ip=13.245.218.24 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=uniontech.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=uniontech.com X-QQ-mid: bizesmtp83t1713763605tapnhxvm X-QQ-Originating-IP: IlITxjeKZMItJ6L/mAP+PlOCOE5Up/4g6uFI5ptulAM= Received: from localhost.localdomain ( [123.114.60.34]) by bizesmtp.qq.com (ESMTP) with id ; Mon, 22 Apr 2024 13:26:43 +0800 (CST) X-QQ-SSF: 01400000000000E0L000000A0000000 X-QQ-FEAT: 3M0okmaRx3jJF+U+0sbRbMtRZ+cqdB72lcfAEiXlzzlf5ijaRGDqdQi0oLasc OKrVIjRsrdJAYl+DnzY3uCPY3LJ2NG8Kdu/uojBPeNPib2ltLG1+VHvWe+cQH5Xov4uExIk e/XYRDWzd5eFgdHrB427tEwBAk4yZMMKOL8UG3gGwXDVzQzcuFSnLaWjcWKsqd/fXxUffNQ V0+38LRNd9JX0o6bqq1fjLyn+vierbhBeBswBy0J2xzF+y3Qy24M7WDHbsEYTdTAxg0omI4 9agGSmCz4ON0XFpA4tHHSttXd6bB3YqdvWuLsQndl6+obQXYbp+JU49gzc3Lh720rd94eLD C+EvQxJd4EUXK3DmqcHl4hXerj1ZpYubr2ZAIT3G7W7UK3euzb24+vEjbOcb4TUPLvq5Nod X-QQ-GoodBg: 1 X-BIZMAIL-ID: 1870312449968284138 From: Qiang Ma To: alexander.deucher@amd.com, christian.koenig@amd.com, Xinhui.Pan@amd.com, airlied@gmail.com, daniel@ffwll.ch, srinivasan.shanmugam@amd.com, Arunpravin.PaneerSelvam@amd.com, maqianga@uniontech.com, le.ma@amd.com, Felix.Kuehling@amd.com, mukul.joshi@amd.com Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH] drm/amdgpu: Fixup bad vram size on gmc v6 and v7 Date: Mon, 22 Apr 2024 13:26:08 +0800 Message-Id: <20240422052608.5297-1-maqianga@uniontech.com> X-Mailer: git-send-email 2.20.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:uniontech.com:qybglogicsvrsz:qybglogicsvrsz4a-0 Content-Type: text/plain; charset="utf-8" Some boards(like Oland PRO: 0x1002:0x6613) seem to have garbage in the upper 16 bits of the vram size register, kern log as follows: [ 6.000000] [drm] Detected VRAM RAM=3D2256537600M, BAR=3D256M [ 6.007812] [drm] RAM width 64bits GDDR5 [ 6.031250] [drm] amdgpu: 2256537600M of VRAM memory ready This is obviously not true, check for this and clamp the size properly. Fixes boards reporting bogus amounts of vram, kern log as follows: [ 2.789062] [drm] Probable bad vram size: 0x86800800 [ 2.789062] [drm] Detected VRAM RAM=3D2048M, BAR=3D256M [ 2.789062] [drm] RAM width 64bits GDDR5 [ 2.789062] [drm] amdgpu: 2048M of VRAM memory ready Signed-off-by: Qiang Ma --- drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c | 11 +++++++++-- drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c | 13 ++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c b/drivers/gpu/drm/amd/am= dgpu/gmc_v6_0.c index 23b478639921..3703695f7789 100644 --- a/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c @@ -309,8 +309,15 @@ static int gmc_v6_0_mc_init(struct amdgpu_device *adev) } adev->gmc.vram_width =3D numchan * chansize; /* size in MB on si */ - adev->gmc.mc_vram_size =3D RREG32(mmCONFIG_MEMSIZE) * 1024ULL * 1024ULL; - adev->gmc.real_vram_size =3D RREG32(mmCONFIG_MEMSIZE) * 1024ULL * 1024ULL; + tmp =3D RREG32(mmCONFIG_MEMSIZE); + /* some boards may have garbage in the upper 16 bits */ + if (tmp & 0xffff0000) { + DRM_INFO("Probable bad vram size: 0x%08x\n", tmp); + if (tmp & 0xffff) + tmp &=3D 0xffff; + } + adev->gmc.mc_vram_size =3D tmp * 1024ULL * 1024ULL; + adev->gmc.real_vram_size =3D adev->gmc.mc_vram_size; =20 if (!(adev->flags & AMD_IS_APU)) { r =3D amdgpu_device_resize_fb_bar(adev); diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c b/drivers/gpu/drm/amd/am= dgpu/gmc_v7_0.c index 3da7b6a2b00d..1df1fc578ff6 100644 --- a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c @@ -316,10 +316,10 @@ static void gmc_v7_0_mc_program(struct amdgpu_device = *adev) static int gmc_v7_0_mc_init(struct amdgpu_device *adev) { int r; + u32 tmp; =20 adev->gmc.vram_width =3D amdgpu_atombios_get_vram_width(adev); if (!adev->gmc.vram_width) { - u32 tmp; int chansize, numchan; =20 /* Get VRAM informations */ @@ -363,8 +363,15 @@ static int gmc_v7_0_mc_init(struct amdgpu_device *adev) adev->gmc.vram_width =3D numchan * chansize; } /* size in MB on si */ - adev->gmc.mc_vram_size =3D RREG32(mmCONFIG_MEMSIZE) * 1024ULL * 1024ULL; - adev->gmc.real_vram_size =3D RREG32(mmCONFIG_MEMSIZE) * 1024ULL * 1024ULL; + tmp =3D RREG32(mmCONFIG_MEMSIZE); + /* some boards may have garbage in the upper 16 bits */ + if (tmp & 0xffff0000) { + DRM_INFO("Probable bad vram size: 0x%08x\n", tmp); + if (tmp & 0xffff) + tmp &=3D 0xffff; + } + adev->gmc.mc_vram_size =3D tmp * 1024ULL * 1024ULL; + adev->gmc.real_vram_size =3D adev->gmc.mc_vram_size; =20 if (!(adev->flags & AMD_IS_APU)) { r =3D amdgpu_device_resize_fb_bar(adev); --=20 2.20.1