Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp2044508lqt; Sun, 21 Apr 2024 22:27:29 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXe1YWgiWiLbGVERow171Lq9CJxuj+ta0ZGfptYO+pc6+kLxI1mvZt0U6SU9g9N8MR7LDnHKo0mOGMNEvSzvBOFsg637k+cSPjjXpGVvA== X-Google-Smtp-Source: AGHT+IGHXgpmyAz37HJ6+z9lQln29KYgJfz1ZaXyaph2scQaj9KxCs3SNyJlF2T55Tvih2ADKH92 X-Received: by 2002:a17:906:915:b0:a51:c964:3cb7 with SMTP id i21-20020a170906091500b00a51c9643cb7mr7894158ejd.61.1713763649120; Sun, 21 Apr 2024 22:27:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713763649; cv=pass; d=google.com; s=arc-20160816; b=YlyDaSffr6GcRNs7mc0uYRC27awsEovhSUippFeEjrzG8MJbZdHycn65Um8KLe64OE XJsqrEkQSvvdWVcL6VLrqMQnyttygbqWUbG9UE3Mt9frnUJr82Ca5eltiedD0D9LAsmG qeUmaYPJ23fBa9vV3fwGuYV2ZFC/9mtxm+UYYNzY+a0qxbiCms2FkOiPGMPrcYEHvQ6/ MfsN32Z4GZrjzL7S9srejO96XyR48Snl6o2GevM7Sb9dDUYJ9EHwAhDIbAM9/rr+uP1r 9IdZkr6j0GsjsCf8vu27uAbsMUxZ0hutr53S1PsuVSZ+fleVAm713jvp5+FPokcCxnSy ncFg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=feedback-id:content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=5dxqEsA1rZmUDrkDgnNEnqd15qtTLgGaXYctPgz+QY0=; fh=84WgsOntHIA8JlmWizGnc5MwKu3ztMWZEgkE5rm4lr4=; b=eE+4gOsK2NHeQTEYwcalARhACCmFxx4VT3b1tfLTA9EVfr9+f39UAiCnEMCpHLkX0g 0NsneU1Di2LNMix2F1J5TaiUhJXbxY7fJJaH7Y7YkuDmGOAbmo7XVsSBdOhyNvU8gRUi 2WZvpUphTweMVNhjq6P2CoGqU+5v8S3m0CmWuk9lBJx8p2SZjOXSDdgaJt8Q2MOKejtx E+uEchD1XyFvwsvBO6Zuge1xGaBkaU1I3jNRWslLD7Bo4we1D0n9RDEA6EqEjodOTifI ZZ+cZj4RKsOF3eor3NOKJiYlVz6ynslalWetQ9z8/pCx3sWx4LCYTgMomoFgKYDzbjTL xdng==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=uniontech.com); spf=pass (google.com: domain of linux-kernel+bounces-152740-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152740-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id sh11-20020a1709076e8b00b00a555520a9ddsi5797976ejc.670.2024.04.21.22.27.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Apr 2024 22:27:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-152740-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=uniontech.com); spf=pass (google.com: domain of linux-kernel+bounces-152740-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152740-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id D469A1F21FA4 for ; Mon, 22 Apr 2024 05:27:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 81BAC17C9E; Mon, 22 Apr 2024 05:27:22 +0000 (UTC) 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: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:uniontech.com:qybglogicsvrsz:qybglogicsvrsz4a-0 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=2256537600M, BAR=256M [ 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=2048M, BAR=256M [ 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/amdgpu/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 = numchan * chansize; /* size in MB on si */ - adev->gmc.mc_vram_size = RREG32(mmCONFIG_MEMSIZE) * 1024ULL * 1024ULL; - adev->gmc.real_vram_size = RREG32(mmCONFIG_MEMSIZE) * 1024ULL * 1024ULL; + tmp = 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 &= 0xffff; + } + adev->gmc.mc_vram_size = tmp * 1024ULL * 1024ULL; + adev->gmc.real_vram_size = adev->gmc.mc_vram_size; if (!(adev->flags & AMD_IS_APU)) { r = amdgpu_device_resize_fb_bar(adev); diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c b/drivers/gpu/drm/amd/amdgpu/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; adev->gmc.vram_width = amdgpu_atombios_get_vram_width(adev); if (!adev->gmc.vram_width) { - u32 tmp; int chansize, numchan; /* Get VRAM informations */ @@ -363,8 +363,15 @@ static int gmc_v7_0_mc_init(struct amdgpu_device *adev) adev->gmc.vram_width = numchan * chansize; } /* size in MB on si */ - adev->gmc.mc_vram_size = RREG32(mmCONFIG_MEMSIZE) * 1024ULL * 1024ULL; - adev->gmc.real_vram_size = RREG32(mmCONFIG_MEMSIZE) * 1024ULL * 1024ULL; + tmp = 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 &= 0xffff; + } + adev->gmc.mc_vram_size = tmp * 1024ULL * 1024ULL; + adev->gmc.real_vram_size = adev->gmc.mc_vram_size; if (!(adev->flags & AMD_IS_APU)) { r = amdgpu_device_resize_fb_bar(adev); -- 2.20.1