From patchwork Mon Jul 25 19:41:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Piotr_Pi=C3=B3rkowski?= X-Patchwork-Id: 12928324 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 6A269C433EF for ; Mon, 25 Jul 2022 19:41:48 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 122E08F40C; Mon, 25 Jul 2022 19:41:37 +0000 (UTC) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by gabe.freedesktop.org (Postfix) with ESMTPS id A50D08F40C; Mon, 25 Jul 2022 19:41:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1658778095; x=1690314095; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=WzwyC+M3VtycZuhnc+cCib+YJ1adu0Z93k1Wj9FRR6E=; b=nSFA9oJPDQzVWE7+2C6V89BYR7h/fwZC1wpC6MycM2TRaI3coWahujiW Bnx5FvB+ZvS9LoBMMB2RVrfMMl8O74yPbctjgCRbIBoKvfI5mfANNwRug F2+WSdNy+Cln0GrSm6xe0EUbksX64MdJaljNnqkv75iuKAmrLPPgic3Bx 6nBWuzxrgV3wrRoAaKoMoPPBBaQINQtTDN35Jp4j4UwNQrIcIfApp5Ewf JsnumqjgVgiOWVu+5syL95b3hlRNiZEREj9Wn3MYHoILiTAb0kcC3SnvJ 0wlY1+l63roL83q/xWetehMq47Hix69V9lgNot8nakGHF9yYCyd68Vf/0 g==; X-IronPort-AV: E=McAfee;i="6400,9594,10419"; a="285330754" X-IronPort-AV: E=Sophos;i="5.93,193,1654585200"; d="scan'208";a="285330754" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jul 2022 12:41:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,193,1654585200"; d="scan'208";a="726277870" Received: from fmsmsx605.amr.corp.intel.com ([10.18.126.85]) by orsmga004.jf.intel.com with ESMTP; 25 Jul 2022 12:41:34 -0700 Received: from fmsmsx606.amr.corp.intel.com (10.18.126.86) by fmsmsx605.amr.corp.intel.com (10.18.126.85) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Mon, 25 Jul 2022 12:41:34 -0700 Received: from FMSEDG603.ED.cps.intel.com (10.1.192.133) by fmsmsx606.amr.corp.intel.com (10.18.126.86) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28 via Frontend Transport; Mon, 25 Jul 2022 12:41:34 -0700 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (104.47.57.173) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2375.28; Mon, 25 Jul 2022 12:41:33 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CuS+dB7AP4VCYisEMuTUht0r+BXoJs2bsC7GpieGjejdlcqHYMccDhkS/w/LFLszeQh6M/wnkJ1/aXsUz0IBgkU9EeN9CcUtbnqWeINxkhHkQ3Lp+5ACaQdY3c49ze5MgIZhfjBAc/j8FExUWzSYZpcgCm5lQ38G7mgzObXL7v5ONdkDcLttyHyOV1h7/KUJJnN4mwqCm8R2p1M8f2szn45CTVj0Enmhn7rYnrmlNRUCtN0u46tt2AFaut8NfiM/dy4tf+O+xaM0w3fyj6xnca9FYtxjnTW2mQLWgPDbh7cSEePFWbMdtPO5C+2L9TLbNggpKguLVgty7UrhOYWQoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=oY9YwvYxztQsFS3WwfuRZAmy7hNtvWJz4/fQr/uldxY=; b=btbOmmyOK7l3RIZiTxH+5mBd08nkFeeRxZuSgV0k3w2PtOci/VWyD3mV7KpcDuMmumlocKk43xO+NNEcvF49oZ+pQy54YKCQS5tImpCHOpOf4YHrh1wXlw8yowmkqFXgMblq2Fg+CzxtK84HYCJrRfzIkQbGmrTLbc8GiNPTVi29xx2zftXaiOLPS0pykZ51WQyBrD3TJmxI85cxyF14BIJ9u+iaCVq6luqCiusp5PdT7uHBWwxjyrdpVlwaUC2aTZul06EibuQwKXg+si6H1QkgjWvNx4bEnUFAlSFNKdhpsY7hUAy4hAJ84vR8qzAGJdhfOoAcSm6bemgXI9Filw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from DM5PR11MB1372.namprd11.prod.outlook.com (2603:10b6:3:11::14) by CO1PR11MB4851.namprd11.prod.outlook.com (2603:10b6:303:9b::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5458.19; Mon, 25 Jul 2022 19:41:32 +0000 Received: from DM5PR11MB1372.namprd11.prod.outlook.com ([fe80::bc9e:4951:a404:5507]) by DM5PR11MB1372.namprd11.prod.outlook.com ([fe80::bc9e:4951:a404:5507%3]) with mapi id 15.20.5458.024; Mon, 25 Jul 2022 19:41:31 +0000 From: "Piorkowski, Piotr" To: , Date: Mon, 25 Jul 2022 21:41:04 +0200 Message-ID: <20220725194105.4054734-2-piotr.piorkowski@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220725194105.4054734-1-piotr.piorkowski@intel.com> References: <20220725194105.4054734-1-piotr.piorkowski@intel.com> X-ClientProxiedBy: LO4P123CA0634.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:294::9) To DM5PR11MB1372.namprd11.prod.outlook.com (2603:10b6:3:11::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3b43f1ab-2649-4221-d412-08da6e75ac9a X-MS-TrafficTypeDiagnostic: CO1PR11MB4851:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: IUq45lEVQAybMT0Jyq/5HFOgOC1h4G7I0B4QsKx4+wHg/6CZWvEN+rspMKGKfZ5N2o/0xc09l64iw6QVOtxrw4kLoN5GoZXU242tV43vg6EDpLlFqQWbvg/8BxowiIU9eJqzc8Bg+OfE88US5TtGpfvyPvO96TN4Novgf7xE7GYeHtb06wW2tG/dWnNL716NtmQOF4xpbMIyhiqjTuMvHmeVnoZV17vv1r8QRee2Ru0K5wDsRHH3zbHs2RahhtLGyhyjrxE9r0P38QdUXVQY2eEQaJp62TsHiH2Mt1awu0IfKX5JRutS8RXQIRJHRzv4AAMjN2BlCpMsvTNdrtwWSJXXbXImFU+LWJauVd4/0AI/dVFOmTa4mY2wiB+ZbwkkT3DXr/szncUV1NBqmDZwSKBstmfmZFAqeqqYdwkt7a1eYBjflwDTt6XUot9+SPP9m8BBR7oibw2f6d44Yk82S/ySmZrVpAxXdmZyD2rKWRj7npyhsNHbnLdjPVpSml3Guw5C19pVebdtNQGNjkturuG5bYGKlU90XlXJRlCPlErtBOwdViQBbD9GwFeaSuX1jBQZlzMX5H6klAhsXnhKaKoDkcRUVrLokAersSmOB7EPEVUpn4ERcCBTpghnL/xenhxZqmD9nq6YoIcHPLabv4t9/rIzLbrzU/FuqVJovnFwI57pbCdp0EWzzedIMiN2p1sm4wnfxZxkbAGzdatnrKePOoHHLpdpm/l4HMN2Y88yVl5bfNqXW3q8VOnywsVd X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM5PR11MB1372.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(136003)(376002)(396003)(346002)(366004)(39860400002)(38100700002)(86362001)(6486002)(8936002)(82960400001)(478600001)(5660300002)(316002)(66946007)(66574015)(66476007)(4326008)(8676002)(66556008)(186003)(1076003)(2616005)(54906003)(83380400001)(41300700001)(36756003)(6666004)(2906002)(26005)(6506007)(6512007); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?efzHmo4o2BFx7LpH0ui4Xuo4ui3t?= =?utf-8?q?WMKDI6KUS1k86+1z4KmBtja23F3vhs4cRsK+cFFh0Gh3BKTp8octk+0CGpeERJAQl?= =?utf-8?q?fV7W5pjxNT4r94Jw3P+Yb/P3yNl+h08vQwNRJ00DG4gMVrr8OSoTM7CXrHEr878lg?= =?utf-8?q?t8bnQaO9x8obmnSW/l7m7AqmG/EmZkIzuVlnxhqnZhHRNHvUWnYR8B8i4BSuHHlv/?= =?utf-8?q?Vn2yNq5zoOrhjcHg6Txg6l8n3rGrV80JaYMKBh2px4Zftu81O81VCFRhTYDExCAH/?= =?utf-8?q?Yhgtf3sMKn26ia54uDgDcoWCICKs0KTqWHmxf19eEhcyuqwL1yhaPWmL8jv7i+PMJ?= =?utf-8?q?WKSMo8WMgoDj55RO7rb6x0vwFJWSTZL+uNS2Nmyj8DaBLAIMBIdAXRHgzqfvdZ2Fl?= =?utf-8?q?GVYUbpp2hjpXuYc9Td1CC6ff4Y+hWrAsHiTnY7X7Nt7QLsl8Ht/Qvzd7oJdu9TjSD?= =?utf-8?q?qZHcbcvgguk9G6WjLZ4IdfkvQyeBma8BOOZMlQV+lT7SFw5SKI1YJEUrps21zE0CF?= =?utf-8?q?g5m2FA3JcEFkgaSumcwba7EBEb8MPIxQZ47dXPP2sSwj15U1ZXyRCGVOBNlQx4Rf7?= =?utf-8?q?OLlEAQaicLrq0DtPFJn4uyrnad38ke9X4C5RI1SFdsm/3GqAzeGY9fPnKINHN/X7h?= =?utf-8?q?PkVI6o4hv28Copyf5KuMqCPg46c2nUmcSQuKLiJam2gampcjU4IthIe2Eo/KlAPo/?= =?utf-8?q?hh+y+vXpTOFdO7eLyassOcBWjiXAbFFDTMiCbeReCG0iQtgezPvzrVPFq78koWoVK?= =?utf-8?q?TaWekwwlGBvMzSXJB1QqcfTHZNQNOCGF77tmSbzVASnjd5fQ8PHU2PypXWOWS0qYV?= =?utf-8?q?PWC3HjhB9CejMhPQXBgffdSsupPqdJETQD1t4JvdeW64hkBPNp89IRQISb0yc99zd?= =?utf-8?q?sjj0xYg7dcYgbY3gDseGw+jjftPHeGlzAWtVDGu8OfbMHuDq5voWqNwIaDp03BVfb?= =?utf-8?q?qBuSvLS0ryTG71vWbeXdNMXueuHwlxpBJDSanJKEQQeb/MAYSOJ4ZAf3MSeCNSe8C?= =?utf-8?q?6dGTYWNKvCrwYyd2O5c0Ss9u0N572/+eOuL3Cp9hcAV+F29jKDT9tnjUKk1q2pIFS?= =?utf-8?q?vhlcloYSx2/91PH4o+F1da7izN11Xj96wc2NbGVvquVdy1+hRuDcsIL6EAkpjV55w?= =?utf-8?q?inZ6g8n0gKWhPaq3Dk5ef5se4f7KyMC8tCTVM5P2qUiOu74AG8cGtmehAz5+87z+v?= =?utf-8?q?nuNkj/k4a+zNdrxS/c3dVZCW0Nd9lrGGHLl/zRP271A4XrzfdVQzX1ZGwLlNJMxsP?= =?utf-8?q?OaCcifyay9f87bfT+KVSkVRW/wYMQaByqEVbs+4H5r7ZU8L3ZMo0y+jdpwasd4YEQ?= =?utf-8?q?8XmUqS+Bddt8k1+OFsKV+pFPu1Alxwr/865+HRv4mEOVopfMlnsGZmnxtfuWDxIfl?= =?utf-8?q?GDNopmCNiDGir2UyD3DYV+/nYT0dMVj1JsrOVoKtQIKbBfDIHr3vUbO3l1VWKMzxG?= =?utf-8?q?YC6/iID+9bH5oX78AlUiQeOQdQ1D0TupK3LeGiHfrEdAPyiBep+G5syEWHxJAtg+L?= =?utf-8?q?wC02Ek3eraFCTQf9ow3w/Y0rEbEIch5INg=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: 3b43f1ab-2649-4221-d412-08da6e75ac9a X-MS-Exchange-CrossTenant-AuthSource: DM5PR11MB1372.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jul 2022 19:41:31.4590 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: SyBiUyx/MWjOjqoh5Ig418YcW44BtGJJ8wQzBBxPvRKzKgeBrxp3+Up5R0fTtB8Hndgp1Ev/ttNPfZHKXUeeAOhcoUM3oAzE1G43Zv2809o= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR11MB4851 X-OriginatorOrg: intel.com Subject: [Intel-gfx] [PATCH 1/2] drm/i915: Use of BARs names instead of numbers X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lucas De Marchi Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" From: Piotr Piórkowski At the moment, when we refer to some PCI BAR we use the number of this BAR in the code. The meaning of BARs between different platforms may be different. Therefore, in order to organize the code, let's start using defined names instead of numbers. Signed-off-by: Piotr Piórkowski Cc: Jani Nikula Cc: Lucas De Marchi Cc: Matt Roper --- drivers/gpu/drm/i915/display/intel_lpe_audio.c | 5 +++-- drivers/gpu/drm/i915/gem/i915_gem_stolen.c | 7 ++++--- drivers/gpu/drm/i915/gt/intel_ggtt.c | 9 +++++---- drivers/gpu/drm/i915/gt/intel_gt.c | 3 ++- drivers/gpu/drm/i915/gt/intel_region_lmem.c | 13 ++++++------- drivers/gpu/drm/i915/gvt/cfg_space.c | 4 ++-- drivers/gpu/drm/i915/intel_pci_config.h | 7 +++++++ 7 files changed, 29 insertions(+), 19 deletions(-) diff --git a/drivers/gpu/drm/i915/display/intel_lpe_audio.c b/drivers/gpu/drm/i915/display/intel_lpe_audio.c index 4970bf146c4a..1e18696aaecf 100644 --- a/drivers/gpu/drm/i915/display/intel_lpe_audio.c +++ b/drivers/gpu/drm/i915/display/intel_lpe_audio.c @@ -73,6 +73,7 @@ #include "i915_drv.h" #include "intel_de.h" #include "intel_lpe_audio.h" +#include "intel_pci_config.h" #define HAS_LPE_AUDIO(dev_priv) ((dev_priv)->audio.lpe.platdev != NULL) @@ -100,9 +101,9 @@ lpe_audio_platdev_create(struct drm_i915_private *dev_priv) rsc[0].flags = IORESOURCE_IRQ; rsc[0].name = "hdmi-lpe-audio-irq"; - rsc[1].start = pci_resource_start(pdev, 0) + + rsc[1].start = pci_resource_start(pdev, GTTMMADR_BAR) + I915_HDMI_LPE_AUDIO_BASE; - rsc[1].end = pci_resource_start(pdev, 0) + + rsc[1].end = pci_resource_start(pdev, GTTMMADR_BAR) + I915_HDMI_LPE_AUDIO_BASE + I915_HDMI_LPE_AUDIO_SIZE - 1; rsc[1].flags = IORESOURCE_MEM; rsc[1].name = "hdmi-lpe-audio-mmio"; diff --git a/drivers/gpu/drm/i915/gem/i915_gem_stolen.c b/drivers/gpu/drm/i915/gem/i915_gem_stolen.c index 166d0a4b9e8c..c369cfd185bc 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_stolen.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_stolen.c @@ -22,6 +22,7 @@ #include "i915_utils.h" #include "i915_vgpu.h" #include "intel_mchbar_regs.h" +#include "intel_pci_config.h" /* * The BIOS typically reserves some of the system's memory for the exclusive @@ -830,7 +831,7 @@ i915_gem_stolen_lmem_setup(struct drm_i915_private *i915, u16 type, /* Use DSM base address instead for stolen memory */ dsm_base = intel_uncore_read64(uncore, GEN12_DSMBASE); if (IS_DG1(uncore->i915)) { - lmem_size = pci_resource_len(pdev, 2); + lmem_size = pci_resource_len(pdev, GEN12_LMEM_BAR); if (WARN_ON(lmem_size < dsm_base)) return ERR_PTR(-ENODEV); } else { @@ -842,11 +843,11 @@ i915_gem_stolen_lmem_setup(struct drm_i915_private *i915, u16 type, } dsm_size = lmem_size - dsm_base; - if (pci_resource_len(pdev, 2) < lmem_size) { + if (pci_resource_len(pdev, GEN12_LMEM_BAR) < lmem_size) { io_start = 0; io_size = 0; } else { - io_start = pci_resource_start(pdev, 2) + dsm_base; + io_start = pci_resource_start(pdev, GEN12_LMEM_BAR) + dsm_base; io_size = dsm_size; } diff --git a/drivers/gpu/drm/i915/gt/intel_ggtt.c b/drivers/gpu/drm/i915/gt/intel_ggtt.c index 15a915bb4088..8214e07a0f5b 100644 --- a/drivers/gpu/drm/i915/gt/intel_ggtt.c +++ b/drivers/gpu/drm/i915/gt/intel_ggtt.c @@ -16,6 +16,7 @@ #include "intel_ggtt_gmch.h" #include "intel_gt.h" #include "intel_gt_regs.h" +#include "intel_pci_config.h" #include "i915_drv.h" #include "i915_scatterlist.h" #include "i915_utils.h" @@ -869,8 +870,8 @@ static int ggtt_probe_common(struct i915_ggtt *ggtt, u64 size) u32 pte_flags; int ret; - GEM_WARN_ON(pci_resource_len(pdev, 0) != gen6_gttmmadr_size(i915)); - phys_addr = pci_resource_start(pdev, 0) + gen6_gttadr_offset(i915); + GEM_WARN_ON(pci_resource_len(pdev, GTTMMADR_BAR) != gen6_gttmmadr_size(i915)); + phys_addr = pci_resource_start(pdev, GTTMMADR_BAR) + gen6_gttadr_offset(i915); /* * On BXT+/ICL+ writes larger than 64 bit to the GTT pagetable range @@ -930,7 +931,7 @@ static int gen8_gmch_probe(struct i915_ggtt *ggtt) u16 snb_gmch_ctl; if (!HAS_LMEM(i915)) { - ggtt->gmadr = pci_resource(pdev, 2); + ggtt->gmadr = pci_resource(pdev, GTT_APERTURE_BAR); ggtt->mappable_end = resource_size(&ggtt->gmadr); } @@ -1084,7 +1085,7 @@ static int gen6_gmch_probe(struct i915_ggtt *ggtt) unsigned int size; u16 snb_gmch_ctl; - ggtt->gmadr = pci_resource(pdev, 2); + ggtt->gmadr = pci_resource(pdev, GTT_APERTURE_BAR); ggtt->mappable_end = resource_size(&ggtt->gmadr); /* diff --git a/drivers/gpu/drm/i915/gt/intel_gt.c b/drivers/gpu/drm/i915/gt/intel_gt.c index 68c2b0d8f187..7b059fdf8cbc 100644 --- a/drivers/gpu/drm/i915/gt/intel_gt.c +++ b/drivers/gpu/drm/i915/gt/intel_gt.c @@ -24,6 +24,7 @@ #include "intel_gt_requests.h" #include "intel_migrate.h" #include "intel_mocs.h" +#include "intel_pci_config.h" #include "intel_pm.h" #include "intel_rc6.h" #include "intel_renderstate.h" @@ -827,7 +828,7 @@ int intel_gt_probe_all(struct drm_i915_private *i915) unsigned int mmio_bar; int ret; - mmio_bar = GRAPHICS_VER(i915) == 2 ? 1 : 0; + mmio_bar = GRAPHICS_VER(i915) == 2 ? GEN2_GTTMMADR_BAR : GTTMMADR_BAR; phys_addr = pci_resource_start(pdev, mmio_bar); /* diff --git a/drivers/gpu/drm/i915/gt/intel_region_lmem.c b/drivers/gpu/drm/i915/gt/intel_region_lmem.c index 6e90032e12e9..0b78a5f3a996 100644 --- a/drivers/gpu/drm/i915/gt/intel_region_lmem.c +++ b/drivers/gpu/drm/i915/gt/intel_region_lmem.c @@ -6,6 +6,7 @@ #include "i915_drv.h" #include "i915_reg.h" #include "intel_memory_region.h" +#include "intel_pci_config.h" #include "intel_region_lmem.h" #include "intel_region_ttm.h" #include "gem/i915_gem_lmem.h" @@ -44,7 +45,6 @@ _resize_bar(struct drm_i915_private *i915, int resno, resource_size_t size) drm_info(&i915->drm, "BAR%d resized to %dM\n", resno, 1 << bar_size); } -#define LMEM_BAR_NUM 2 static void i915_resize_lmem_bar(struct drm_i915_private *i915, resource_size_t lmem_size) { struct pci_dev *pdev = to_pci_dev(i915->drm.dev); @@ -55,15 +55,14 @@ static void i915_resize_lmem_bar(struct drm_i915_private *i915, resource_size_t u32 pci_cmd; int i; - current_size = roundup_pow_of_two(pci_resource_len(pdev, LMEM_BAR_NUM)); + current_size = roundup_pow_of_two(pci_resource_len(pdev, GEN12_LMEM_BAR)); if (i915->params.lmem_bar_size) { u32 bar_sizes; rebar_size = i915->params.lmem_bar_size * (resource_size_t)SZ_1M; - bar_sizes = pci_rebar_get_possible_sizes(pdev, - LMEM_BAR_NUM); + bar_sizes = pci_rebar_get_possible_sizes(pdev, GEN12_LMEM_BAR); if (rebar_size == current_size) return; @@ -106,7 +105,7 @@ static void i915_resize_lmem_bar(struct drm_i915_private *i915, resource_size_t pci_write_config_dword(pdev, PCI_COMMAND, pci_cmd & ~PCI_COMMAND_MEMORY); - _resize_bar(i915, LMEM_BAR_NUM, rebar_size); + _resize_bar(i915, GEN12_LMEM_BAR, rebar_size); pci_assign_unassigned_bus_resources(pdev->bus); pci_write_config_dword(pdev, PCI_COMMAND, pci_cmd); @@ -232,8 +231,8 @@ static struct intel_memory_region *setup_lmem(struct intel_gt *gt) mul_u32_u32(i915->params.lmem_size, SZ_1M)); } - io_start = pci_resource_start(pdev, 2); - io_size = min(pci_resource_len(pdev, 2), lmem_size); + io_start = pci_resource_start(pdev, GEN12_LMEM_BAR); + io_size = min(pci_resource_len(pdev, GEN12_LMEM_BAR), lmem_size); if (!io_size) return ERR_PTR(-EIO); diff --git a/drivers/gpu/drm/i915/gvt/cfg_space.c b/drivers/gpu/drm/i915/gvt/cfg_space.c index dad3a6054335..c22d3a388aa5 100644 --- a/drivers/gpu/drm/i915/gvt/cfg_space.c +++ b/drivers/gpu/drm/i915/gvt/cfg_space.c @@ -353,9 +353,9 @@ void intel_vgpu_init_cfg_space(struct intel_vgpu *vgpu, memset(vgpu_cfg_space(vgpu) + INTEL_GVT_PCI_OPREGION, 0, 4); vgpu->cfg_space.bar[INTEL_GVT_PCI_BAR_GTTMMIO].size = - pci_resource_len(pdev, 0); + pci_resource_len(pdev, GTTMMADR_BAR); vgpu->cfg_space.bar[INTEL_GVT_PCI_BAR_APERTURE].size = - pci_resource_len(pdev, 2); + pci_resource_len(pdev, GTT_APERTURE_BAR); memset(vgpu_cfg_space(vgpu) + PCI_ROM_ADDRESS, 0, 4); diff --git a/drivers/gpu/drm/i915/intel_pci_config.h b/drivers/gpu/drm/i915/intel_pci_config.h index 12cd9d4f23de..4977a524ce6f 100644 --- a/drivers/gpu/drm/i915/intel_pci_config.h +++ b/drivers/gpu/drm/i915/intel_pci_config.h @@ -6,6 +6,13 @@ #ifndef __INTEL_PCI_CONFIG_H__ #define __INTEL_PCI_CONFIG_H__ +/* PCI BARs */ +#define GTTMMADR_BAR 0 +#define GEN2_GTTMMADR_BAR 1 +#define GFXMEM_BAR 2 +#define GTT_APERTURE_BAR GFXMEM_BAR +#define GEN12_LMEM_BAR GFXMEM_BAR + /* BSM in include/drm/i915_drm.h */ #define MCHBAR_I915 0x44 From patchwork Mon Jul 25 19:41:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Piotr_Pi=C3=B3rkowski?= X-Patchwork-Id: 12928325 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 D47D7C43334 for ; Mon, 25 Jul 2022 19:42:07 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2092B11BE71; Mon, 25 Jul 2022 19:41:57 +0000 (UTC) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by gabe.freedesktop.org (Postfix) with ESMTPS id 011A614AFB6; Mon, 25 Jul 2022 19:41:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1658778098; x=1690314098; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=h9b/JiXLgXkhA3nZdvNS2izSFOoQqV9JDyJ0MUKnaxw=; b=ByRXV4ILBVCBVAHZwULqUQo8Ww+5kvspSaGDu+P1EGifWyKZGvgZ81+s 5nGYlI7aO0m086x2hOxQWtonk/MGMyyi12Hm1Px2Sy01zwNnDXSGgFV7h wXlrn/W+tvvcfMp3rqUso+JPRfkTMw/FN1+QinaciXReWB2UCavkRYpg2 WxBe2jfucDooooKSfKEy5624UMKvtYlPC+vBEcuurbAwKDZr6gS4dCuWk O8qAwXISvcQqpnOVX1qMpcAkTN+2azc13ciFy7AMG8iTkwmHJjiYZEKjm SsC2zehJJePs0lmI9cGqsvnPMPOkmEG3DIs2ERvXLSb8DqR1bRSSRGRpo Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10419"; a="313536899" X-IronPort-AV: E=Sophos;i="5.93,193,1654585200"; d="scan'208";a="313536899" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jul 2022 12:41:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,193,1654585200"; d="scan'208";a="627589969" Received: from fmsmsx601.amr.corp.intel.com ([10.18.126.81]) by orsmga008.jf.intel.com with ESMTP; 25 Jul 2022 12:41:37 -0700 Received: from fmsmsx612.amr.corp.intel.com (10.18.126.92) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Mon, 25 Jul 2022 12:41:37 -0700 Received: from fmsmsx604.amr.corp.intel.com (10.18.126.84) by fmsmsx612.amr.corp.intel.com (10.18.126.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Mon, 25 Jul 2022 12:41:37 -0700 Received: from FMSEDG603.ED.cps.intel.com (10.1.192.133) by fmsmsx604.amr.corp.intel.com (10.18.126.84) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28 via Frontend Transport; Mon, 25 Jul 2022 12:41:37 -0700 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (104.47.57.176) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2375.28; Mon, 25 Jul 2022 12:41:36 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HqRwMWaJK3yhyOnqTy7Ke+Km8QN6nMUP5vZzqJTP4uEEMn8VBJFykbsX/SNFML+LQ6ccPx3V8RBs6xRHhZRbkRNRCisKWYitXYgjIoIHgI3E8vVRS4m9DxpOGaeibLszbFOrXKBibXOtQUIVBiooTItNSo6EQ1mddLlp/GMFm7Q2Zx3GvbABhBuokfgSshA8bAnN7+22uyUKSjvUbThlLKAucBCU46X1Anp+T58MzqnUcVVEK1YqMv+TIVlKdg4Kuhp/LHlNuc27yNEKKavlYipfAN+peiEu3gFiqz55imtpEAOVA0aNG9A1QZ1iyalg8pnosenzvurKWfcDiUluLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=fPvd+f9gOQad9iLMy6G1lHNHmdTV/DuoRvf+i1gIaVU=; b=brKbevh+QxG9Qnekgvq36dcCDZWgNzvUj1M1Oq5LO1lcz5fGU5ST/iKt9auiuRXTl3HMNN8DVG6Wopwk1MpXl87ppi0tv8QuXHyRZXHzJ/VAz2l0DQpjv4mClxd2JvMuXZ7vP+gbAIaFO6X8Q2HnRR+aKs7BzwP7Be1DO3vTnq7e8OeMeyxjW3YOlldJ4np26rrCCrLmRvUS6PjFhjHaf90MWUd7EA+SYZ15bPUKd5Bc7p6QxxkNGP30li1RiajACpL+1VTESyn3MR9/LuPAM/RSHXEbI2EIdOxVjvWQ269NCJuaMtWPEin/xU2ivhws5Q6lfGW+wyQCyrXF0JCP+Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from DM5PR11MB1372.namprd11.prod.outlook.com (2603:10b6:3:11::14) by CO1PR11MB4851.namprd11.prod.outlook.com (2603:10b6:303:9b::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5458.19; Mon, 25 Jul 2022 19:41:35 +0000 Received: from DM5PR11MB1372.namprd11.prod.outlook.com ([fe80::bc9e:4951:a404:5507]) by DM5PR11MB1372.namprd11.prod.outlook.com ([fe80::bc9e:4951:a404:5507%3]) with mapi id 15.20.5458.024; Mon, 25 Jul 2022 19:41:35 +0000 From: "Piorkowski, Piotr" To: , Date: Mon, 25 Jul 2022 21:41:05 +0200 Message-ID: <20220725194105.4054734-3-piotr.piorkowski@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220725194105.4054734-1-piotr.piorkowski@intel.com> References: <20220725194105.4054734-1-piotr.piorkowski@intel.com> X-ClientProxiedBy: LO2P123CA0009.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:a6::21) To DM5PR11MB1372.namprd11.prod.outlook.com (2603:10b6:3:11::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7b703608-8412-482e-fe2a-08da6e75aed6 X-MS-TrafficTypeDiagnostic: CO1PR11MB4851:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gx/PgK5Cmwo2kkNn7z7JBZLoWZcwfvsBJafUxHiZnyGLVuGpnWtKisY9nGXcNDrK/dWxHIpqOyFE1zqW8groYkfx1Gvc6w5ZO+E9FFJJLxZSzCUllaYOlAz2gbkgEBHQnIGv3AvTl5yghiSmIPzsJWT0t/1e0QaCSjLDUmYoN/SUIIcE5foUSbQtTT54M7uuyXNwDcZhOgWP4YZ6b9lj1Z7boVcVvNSWqj70vfdCEB/f+smQOeZetayj2BB0CGqVLCAissVT5fEaswEniZj95rG5t2yPXRU+ANt4CnT9FCrnZIwwcYNYpU3qxCGCEJph25kkdVq2DQs1LJInENCaDmkfWq/WNstYZd++NO/rH1Hwn7d35xByb7GGq8/Xwesj/GGQJ78X1xikOUBPv525sjJCDglxeQw0sBDkYPTlIqe65ItuIRy6P5xPPlObHEezsc1fBRpQ+NxJ1MdF/Ut9JT+wvffPZ3sY7f1G49BhfzPOGfxminLB2Yx9GoIA9WL4qn6LqxWpK4a6ymN0ssJcpN4ezz+rfvGtMp/MM8/w+C2JoMArn6Jj2Tak58JhnOaArX/3rLOFNe5z3+EAokh4brrxnx6gYb8SU8V4RhRUtE2YKaSIb+XvwxghylZ04HkylFfVMmjAwWheQGEfGwkdrJN6C7Irrd8bMJlnkKzAeScE80ihHweExAfN37cL0EL9kPxjpml9JQparWCAYRervNOwCsxUHhWO6XwNDQg+zP8rNVX4ct7Z/TeS8DsYtqIt X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM5PR11MB1372.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(136003)(376002)(396003)(346002)(366004)(39860400002)(38100700002)(86362001)(6486002)(8936002)(82960400001)(478600001)(5660300002)(316002)(66946007)(66574015)(66476007)(4326008)(8676002)(66556008)(186003)(1076003)(2616005)(54906003)(83380400001)(41300700001)(36756003)(6666004)(2906002)(26005)(6506007)(6512007); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?fmOgNKmOWMJS0uG8BjJIdYd9Y7Me?= =?utf-8?q?tbxS90zLQ3Q+DG2psUsq5x+6r8U7qQzM092ReAKg3dE60QiYUkP3Knil1pJ4wvxyf?= =?utf-8?q?it55lOUOtR5V2pJSAUWrQLPbGh5wOsZgGbLdhNQoV/WKG/w/64LfmD9L9y0oq4Db5?= =?utf-8?q?97lbgZwzaaMBQbSTxNqo+O3terOlHUr9xtFcFvHsT1l8xU9EVtA5FtjoEixgGuH+V?= =?utf-8?q?JkU9aF2mqNVCYx6KiVMzvcySBFCDG5UvS/msyFO66BJ5X+MuFFH3cAMsWpgC+fGTy?= =?utf-8?q?CBH1cVjgJySvduJgw1Xh9iGkrBGkTKM3cGjw5z80tsW5nSwxLk+MhpxSt9nqusf7V?= =?utf-8?q?9fCqzmFOzIISDPrVruFU0Ocqtndb/Kzzah61bQURL1gv/Lig9h884JQ+I3DPmZuex?= =?utf-8?q?44H6muM2eR+vcDJJHJYgNHcOWcEFnqnKnfxv1+3AuNrHwndCTcQ1dH97FXIusAq7y?= =?utf-8?q?GOePPb2lrWp9CahDSC7LXIUpp7/O9ZDeho+WhJMSEEdh+KHXMdcPb1KzTE2w/U3If?= =?utf-8?q?6jcOcbt59m84w+h+0t0nZJ792tIuMZ7aYysjXPxoj/zTfCrXjkSkqMRU4jnDYKSao?= =?utf-8?q?VAHceku8pGSmv92cBzzbknvM21HPix2fftOTzDI/gUjlfIpb6Gv7O8tnaoUK+IMou?= =?utf-8?q?ZVppQv47lSsX0tDk0v3B0LA9FJ/UvxMw6N3T9Q60tOls2C8HCLeQiNWXLVKYiAB3x?= =?utf-8?q?g8wjakgWxQCGwNyLn1W8En+tMda76BayJyIGWz3rwqOBK1ukqt2PzBi24nksAR/Do?= =?utf-8?q?ImN8qrEupXOsM6b+scvuhi+P21lfPmY/QV5v09LA1ggY5T0W9PB+EAE7zqSmZo+Qm?= =?utf-8?q?OAMDZZu2FyfRpP8wczJYphkz8aTPg8/x66NXYaD/D4WKKcMW2b6NVWR9ydUyxC47Z?= =?utf-8?q?PgaFFI/37byPWO8acdkxCNwdrnRMJG/W5s/lbynCXFOJNXL7hxlkc4cCB60vDlrDD?= =?utf-8?q?aOifWInD3pYLc47LJ3dFoeZuZ9xRmyGW31dkR31GVPNyRgnX48Uq4IbVJqFispXn0?= =?utf-8?q?SXK18YpeyxFcaq6elN7c1NHlzEoPQuVp5EushIj50W090bkobGlnLgM+M4lAWtMUo?= =?utf-8?q?p5kH3rMh4wchS6lDRx3uqWQVBlrOWKIlDoegJ3UonQjeCFMprx3C2c9C1ScC5N8Ak?= =?utf-8?q?j/Eb4r33Mjv9PY/fq30ZpLJt22cumcmhMV1mqtQsAIilq+5jS/2bxj00e60Q65+DE?= =?utf-8?q?MwfbqM3JkTl15+X+7IEnG5gBi60WWYef95u6UAaCFWtGhtc6kAWHkSwjc/1+CbnEI?= =?utf-8?q?p5Ph5M+LkhgXZZEiD98qhc21rf6J1pW1VlDgdb4SNWtNS2COYJT1ss6kh4MOinaBV?= =?utf-8?q?MmiHrRA6zRuXhLyhYPWzTh6djvnSLcLDQabYgt4k5uw6IxwlX7A/8p2sCHdiP34nt?= =?utf-8?q?Zd95dbWOtOA9Qj3bfjDYERicb+wNymqBJ8kx3HWmjSzX2cMKs8FejAYXA2uHTUbqF?= =?utf-8?q?oXa71zvOGAZRt0+HHOxQLYHL4I73Wme//8ZVFYhBlsaJiHl9a1S1Fc8xQeOvkmKtE?= =?utf-8?q?SSzHHr2BciaMjLWxtbi8w7cuFUD3VWgHJw=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: 7b703608-8412-482e-fe2a-08da6e75aed6 X-MS-Exchange-CrossTenant-AuthSource: DM5PR11MB1372.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jul 2022 19:41:35.1619 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 6Kza4S+lx4DiWp/3H6HaUa/rf8Dshhp2Jk1F+0vbU9RXZPfN6QLowe7PxXsm4nVVRZkhSNPxhcSTAuFq6pOGIqjcFAy12mxre0ldEt/nRD4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR11MB4851 X-OriginatorOrg: intel.com Subject: [Intel-gfx] [PATCH 2/2] drm/i915: Sanitycheck PCI BARs X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lucas De Marchi Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" From: Piotr Piórkowski For proper operation of i915 we need usable PCI GTTMMADDR BAR 0 (1 for GEN2). In most cases we also need usable PCI GFXMEM BAR 2. Let's add functions to check if BARs are set, and that it have a size greater than 0. In case GTTMMADDR BAR, let's validate at the beginning of i915 initialization. For other BARs, let's validate before first use. Signed-off-by: Piotr Piórkowski Cc: Jani Nikula Cc: Lucas De Marchi Cc: Matt Roper --- drivers/gpu/drm/i915/gem/i915_gem_stolen.c | 4 ++++ drivers/gpu/drm/i915/gt/intel_ggtt.c | 7 ++++++ drivers/gpu/drm/i915/gt/intel_region_lmem.c | 4 ++++ drivers/gpu/drm/i915/i915_pci.c | 25 +++++++++++++++++++++ drivers/gpu/drm/i915/i915_pci.h | 4 ++++ 5 files changed, 44 insertions(+) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_stolen.c b/drivers/gpu/drm/i915/gem/i915_gem_stolen.c index c369cfd185bc..4f4c9461a23b 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_stolen.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_stolen.c @@ -18,6 +18,7 @@ #include "gt/intel_region_lmem.h" #include "i915_drv.h" #include "i915_gem_stolen.h" +#include "i915_pci.h" #include "i915_reg.h" #include "i915_utils.h" #include "i915_vgpu.h" @@ -828,6 +829,9 @@ i915_gem_stolen_lmem_setup(struct drm_i915_private *i915, u16 type, if (WARN_ON_ONCE(instance)) return ERR_PTR(-ENODEV); + if (!i915_pci_resource_valid(pdev, GEN12_LMEM_BAR)) + return ERR_PTR(-ENXIO); + /* Use DSM base address instead for stolen memory */ dsm_base = intel_uncore_read64(uncore, GEN12_DSMBASE); if (IS_DG1(uncore->i915)) { diff --git a/drivers/gpu/drm/i915/gt/intel_ggtt.c b/drivers/gpu/drm/i915/gt/intel_ggtt.c index 8214e07a0f5b..30cf5c3369d9 100644 --- a/drivers/gpu/drm/i915/gt/intel_ggtt.c +++ b/drivers/gpu/drm/i915/gt/intel_ggtt.c @@ -18,6 +18,7 @@ #include "intel_gt_regs.h" #include "intel_pci_config.h" #include "i915_drv.h" +#include "i915_pci.h" #include "i915_scatterlist.h" #include "i915_utils.h" #include "i915_vgpu.h" @@ -931,6 +932,9 @@ static int gen8_gmch_probe(struct i915_ggtt *ggtt) u16 snb_gmch_ctl; if (!HAS_LMEM(i915)) { + if (!i915_pci_resource_valid(pdev, GTT_APERTURE_BAR)) + return -ENXIO; + ggtt->gmadr = pci_resource(pdev, GTT_APERTURE_BAR); ggtt->mappable_end = resource_size(&ggtt->gmadr); } @@ -1085,6 +1089,9 @@ static int gen6_gmch_probe(struct i915_ggtt *ggtt) unsigned int size; u16 snb_gmch_ctl; + if (!i915_pci_resource_valid(pdev, GTT_APERTURE_BAR)) + return -ENXIO; + ggtt->gmadr = pci_resource(pdev, GTT_APERTURE_BAR); ggtt->mappable_end = resource_size(&ggtt->gmadr); diff --git a/drivers/gpu/drm/i915/gt/intel_region_lmem.c b/drivers/gpu/drm/i915/gt/intel_region_lmem.c index 0b78a5f3a996..360b11fd57bb 100644 --- a/drivers/gpu/drm/i915/gt/intel_region_lmem.c +++ b/drivers/gpu/drm/i915/gt/intel_region_lmem.c @@ -4,6 +4,7 @@ */ #include "i915_drv.h" +#include "i915_pci.h" #include "i915_reg.h" #include "intel_memory_region.h" #include "intel_pci_config.h" @@ -197,6 +198,9 @@ static struct intel_memory_region *setup_lmem(struct intel_gt *gt) if (!IS_DGFX(i915)) return ERR_PTR(-ENODEV); + if (!i915_pci_resource_valid(pdev, GEN12_LMEM_BAR)) + return ERR_PTR(-ENXIO); + if (HAS_FLAT_CCS(i915)) { resource_size_t lmem_range; u64 tile_stolen, flat_ccs_base; diff --git a/drivers/gpu/drm/i915/i915_pci.c b/drivers/gpu/drm/i915/i915_pci.c index aacc10f2e73f..9fd788e147a3 100644 --- a/drivers/gpu/drm/i915/i915_pci.c +++ b/drivers/gpu/drm/i915/i915_pci.c @@ -30,6 +30,7 @@ #include "i915_drv.h" #include "i915_pci.h" #include "i915_reg.h" +#include "intel_pci_config.h" #define PLATFORM(x) .platform = (x) #define GEN(x) \ @@ -1262,6 +1263,27 @@ static bool force_probe(u16 device_id, const char *devices) return ret; } +bool i915_pci_resource_valid(struct pci_dev *pdev, int bar) +{ + if (!pci_resource_flags(pdev, bar)) + return false; + + if (pci_resource_flags(pdev, bar) & IORESOURCE_UNSET) + return false; + + if (!pci_resource_len(pdev, bar)) + return false; + + return true; +} + +static bool intel_mmio_bar_valid(struct pci_dev *pdev, struct intel_device_info *intel_info) +{ + int gttmmaddr_bar = intel_info->graphics.ver == 2 ? GEN2_GTTMMADR_BAR : GTTMMADR_BAR; + + return i915_pci_resource_valid(pdev, gttmmaddr_bar); +} + static int i915_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) { struct intel_device_info *intel_info = @@ -1287,6 +1309,9 @@ static int i915_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) if (PCI_FUNC(pdev->devfn)) return -ENODEV; + if (!intel_mmio_bar_valid(pdev, intel_info)) + return -ENXIO; + /* Detect if we need to wait for other drivers early on */ if (intel_modeset_probe_defer(pdev)) return -EPROBE_DEFER; diff --git a/drivers/gpu/drm/i915/i915_pci.h b/drivers/gpu/drm/i915/i915_pci.h index ee048c238174..c0bda6aae806 100644 --- a/drivers/gpu/drm/i915/i915_pci.h +++ b/drivers/gpu/drm/i915/i915_pci.h @@ -6,7 +6,11 @@ #ifndef __I915_PCI_H__ #define __I915_PCI_H__ +#include + int i915_pci_register_driver(void); void i915_pci_unregister_driver(void); +bool i915_pci_resource_valid(struct pci_dev *pdev, int bar); + #endif /* __I915_PCI_H__ */