Sanitycheck PCI BARs
Subsystems (4)
v2 cover Sanitycheck PCI BARs
From: Piotr Piórkowski <[email protected]>
When initializing the i915, we want to be sure that the PCI BARs have been properly initialized.
As part of this series, I have prepared two patches,
one that introduces BARs names to use in code instead of numbers, and another that adds function to validate BARs before use. This is an evolution of the concept I presented in the patch:
https://patchwork.freedesktop.org/patch/470184/?series=99094
The main difference between the original patch and what I have prepared here is that previously I checked all BARs at the beginning of i915 initialization, and now I only check BAR 0 at beginning. This is due to the fact that I have noticed that it can happen that only BAR 0 is available (I have observed this in the case of virtualization, on some platforms).
Therefore, at the beginning, let's verify only BAR 0, and the others only before the first use.
v2: Fix build
Piotr Piórkowski (2):
drm/i915: Use of BARs names instead of numbers
drm/i915: Sanitycheck PCI BARs
.../gpu/drm/i915/display/intel_lpe_audio.c | 5 ++-- drivers/gpu/drm/i915/gem/i915_gem_stolen.c | 11 +++++--- drivers/gpu/drm/i915/gt/intel_ggtt.c | 16 +++++++++--- drivers/gpu/drm/i915/gt/intel_gt.c | 3 ++- drivers/gpu/drm/i915/gt/intel_region_lmem.c | 17 +++++++------ drivers/gpu/drm/i915/gvt/cfg_space.c | 5 ++-- drivers/gpu/drm/i915/i915_pci.c | 25 +++++++++++++++++++ drivers/gpu/drm/i915/i915_pci.h | 4 +++ drivers/gpu/drm/i915/intel_pci_config.h | 7 ++++++ 9 files changed, 74 insertions(+), 19 deletions(-)
Signature · 1 line
2.25.1
PATCH v2 1/2 drm/i915: Use of BARs names instead of numbers
From: Piotr Piórkowski <[email protected]>
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.
v2: Add lost header in cfg_space.c
--- 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 | 5 +++-- drivers/gpu/drm/i915/intel_pci_config.h | 7 +++++++ 7 files changed, 30 insertions(+), 19 deletions(-)
drivers/gpu/drm/i915/display/intel_lpe_audio.c +3 -2
@@ -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" ;
drivers/gpu/drm/i915/gem/i915_gem_stolen.c +4 -3
@@ -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; }
drivers/gpu/drm/i915/gt/intel_ggtt.c +5 -4
@@ -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);/*
drivers/gpu/drm/i915/gt/intel_gt.c +2 -1
@@ -26,6 +26,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"
@@ -830,7 +831,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);/*
drivers/gpu/drm/i915/gt/intel_region_lmem.c +6 -7
@@ -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"
@@ -45,7 +46,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 2static 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);
@@ -56,15 +56,14 @@ static void i915_resize_lmem_bar(struct drm_i915_private *i915, resource_size_tu32 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 ;
@@ -107,7 +106,7 @@ static void i915_resize_lmem_bar(struct drm_i915_private *i915, resource_size_tpci_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);
@@ -236,8 +235,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 );
drivers/gpu/drm/i915/gvt/cfg_space.c +3 -2
@@ -33,6 +33,7 @@#include "i915_drv.h" #include "gvt.h" +#include "intel_pci_config.h" enum {INTEL_GVT_PCI_BAR_GTTMMIO =0 ,
@@ -353,9 +354,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 );
drivers/gpu/drm/i915/intel_pci_config.h +7 -0
@@ -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
Signature · 1 line
2.25.1
Re: [PATCH v2 1/2] drm/i915: Use of BARs names instead of numbers
Quoted 8 lines · Piotr
From: Piotr Piórkowski <[email protected]>
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.
v2: Add lost header in
cfg_space.c
I could bikeshed the macro names for bars, but meh. This is an improvement.
Quoted 236 lines
Signed-off-by Piotr Piórkowski <[email protected]>Cc Jani Nikula <[email protected]>Cc Lucas De Marchi <[email protected]>Cc Matt Roper <[email protected]>--- 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 | 5 +++-- drivers/gpu/drm/i915/intel_pci_config.h | 7 +++++++ 7 files changed, 30 insertions(+), 19 deletions(-)drivers/gpu/drm/i915/display/intel_lpe_audio.c +3
-2@@ -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" ;drivers/gpu/drm/i915/gem/i915_gem_stolen.c +4
-3@@ -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; }drivers/gpu/drm/i915/gt/intel_ggtt.c +5
-4@@ -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);/* drivers/gpu/drm/i915/gt/intel_gt.c +2
-1@@ -26,6 +26,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" @@ -830,7 +831,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);/* drivers/gpu/drm/i915/gt/intel_region_lmem.c +6
-7@@ -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" @@ -45,7 +46,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 2static 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);@@ -56,15 +56,14 @@ static void i915_resize_lmem_bar(struct drm_i915_private *i915, resource_size_tu32 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 ;@@ -107,7 +106,7 @@ static void i915_resize_lmem_bar(struct drm_i915_private *i915, resource_size_tpci_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);@@ -236,8 +235,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 );drivers/gpu/drm/i915/gvt/cfg_space.c +3
-2@@ -33,6 +33,7 @@#include "i915_drv.h" #include "gvt.h" +#include "intel_pci_config.h" enum {INTEL_GVT_PCI_BAR_GTTMMIO =0 ,@@ -353,9 +354,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 );drivers/gpu/drm/i915/intel_pci_config.h +7
-0@@ -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
Signature · 1 line
Jani Nikula, Intel Open Source Graphics Center
PATCH v2 2/2 drm/i915: Sanitycheck PCI BARs
In reply to Piorkowski, PiotrFrom: Piotr Piórkowski <[email protected]>
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.
--- 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(+)
drivers/gpu/drm/i915/gem/i915_gem_stolen.c +4 -0
@@ -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)) {
drivers/gpu/drm/i915/gt/intel_ggtt.c +7 -0
@@ -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);
drivers/gpu/drm/i915/gt/intel_region_lmem.c +4 -0
@@ -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"
@@ -201,6 +202,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;
drivers/gpu/drm/i915/i915_pci.c +25 -0
@@ -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 ;
drivers/gpu/drm/i915/i915_pci.h +4 -0
@@ -6,7 +6,11 @@#ifndef __I915_PCI_H__#define __I915_PCI_H__ +#include <linux/pci.h> +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__ */
Signature · 1 line
2.25.1
Re: [PATCH v2 2/2] drm/i915: Sanitycheck PCI BARs
Quoted 153 lines · Piotr
From: Piotr Piórkowski <[email protected]>
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 <[email protected]>Cc Jani Nikula <[email protected]>Cc Lucas De Marchi <[email protected]>Cc Matt Roper <[email protected]>--- 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(+)drivers/gpu/drm/i915/gem/i915_gem_stolen.c +4
-0@@ -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)) {drivers/gpu/drm/i915/gt/intel_ggtt.c +7
-0@@ -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);drivers/gpu/drm/i915/gt/intel_region_lmem.c +4
-0@@ -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" @@ -201,6 +202,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;drivers/gpu/drm/i915/i915_pci.c +25
-0@@ -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 ;drivers/gpu/drm/i915/i915_pci.h +0
-0
drivers/gpu/drm/i915/i915_pci.h line 10
Quoted 5 lines
drivers/gpu/drm/i915/i915_pci.h +2
-0@@ -6,7 +6,11 @@#ifndef __I915_PCI_H__#define __I915_PCI_H__ +#include <linux/pci.h> +
Please replace this with a forward declaration for struct pci_dev.
With that, seems good,
Quoted 6 lines
drivers/gpu/drm/i915/i915_pci.h +2
-0int 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__ */
Signature · 1 line
Jani Nikula, Intel Open Source Graphics Center
Patchwork
CI[Intel-gfx] ✗ Fi.CI.SPARSE: warning for Sanitycheck PCI BARs
In reply to Piorkowski, Piotr== Series Details ==
== Series Details ==
Series: Sanitycheck PCI BARs
URL : https://patchwork.freedesktop.org/series/106927/
State : warning
== Summary ==
Error: dim sparse failed
Sparse version: v0.6.2
Fast mode used, each commit won't be checked separately.
-+drivers/gpu/drm/i915/gt/intel_gt.h:106:16: warning: trying to copy expression type 31 +drivers/gpu/drm/i915/gt/intel_reset.c:1410:5: warning: context imbalance in 'intel_gt_reset_trylock' - different lock contexts for basic block
Patchwork
CI[Intel-gfx] ✗ Fi.CI.BAT: failure for Sanitycheck PCI BARs
In reply to Piorkowski, Piotr== Series Details ==
== Series Details ==
Series: Sanitycheck PCI BARs
URL : https://patchwork.freedesktop.org/series/106927/
State : failure
== Summary ==
CI Bug Log - changes from CI_DRM_11964 -> Patchwork_106927v1
====================================================
Summary
-------
**FAILURE**
Serious unknown changes coming with Patchwork_106927v1 absolutely need to be verified manually.
If you think the reported changes have nothing to do with the changes introduced in Patchwork_106927v1, please notify your bug team to allow them to document this new failure mode, which will reduce false positives in CI.
External URL: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_106927v1/index.html
Participating hosts (45 -> 41)
------------------------------
Additional (2): bat-rpls-1 bat-dg1-5
Missing (6): fi-hsw-4200u fi-bdw-gvtdvm fi-ctg-p8600 fi-kbl-x1275 fi-cfl-8109u fi-bdw-samus
Possible new issues
-------------------
Here are the unknown changes that may have been introduced in Patchwork_106927v1:
### IGT changes ###
#### Possible regressions ####
* igt@i915_selftest@live@migrate:
- fi-apl-guc: [PASS][1] -> [INCOMPLETE][2]
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11964/fi-apl-guc/igt@i915_selftest@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_106927v1/fi-apl-guc/igt@i915_selftest@[email protected]
Known issues
------------
Here are the changes found in Patchwork_106927v1 that come from known issues:
### IGT changes ###
#### Issues hit ####
* igt@fbdev@nullptr:
- bat-dg1-5: NOTRUN -> [SKIP][3] ([i915#2582]) +4 similar issues
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_106927v1/bat-dg1-5/igt@[email protected]
* igt@gem_mmap@basic:
- bat-dg1-5: NOTRUN -> [SKIP][4] ([i915#4083])
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_106927v1/bat-dg1-5/igt@[email protected]
* igt@gem_tiled_blits@basic:
- bat-dg1-5: NOTRUN -> [SKIP][5] ([i915#4077]) +2 similar issues
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_106927v1/bat-dg1-5/igt@[email protected]
* igt@gem_tiled_pread_basic:
- bat-dg1-5: NOTRUN -> [SKIP][6] ([i915#4079]) +1 similar issue
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_106927v1/bat-dg1-5/igt@gem_tiled_pread_basic.html
* igt@i915_pm_backlight@basic-brightness:
- bat-dg1-5: NOTRUN -> [SKIP][7] ([i915#1155])
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_106927v1/bat-dg1-5/igt@[email protected]
* igt@i915_selftest@live@gt_engines:
- bat-dg1-5: NOTRUN -> [INCOMPLETE][8] ([i915#4418])
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_106927v1/bat-dg1-5/igt@i915_selftest@live@gt_engines.html
* igt@kms_addfb_basic@basic-x-tiled-legacy:
- bat-dg1-5: NOTRUN -> [SKIP][9] ([i915#4212]) +7 similar issues
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_106927v1/bat-dg1-5/igt@[email protected]
* igt@kms_addfb_basic@basic-y-tiled-legacy:
- bat-dg1-5: NOTRUN -> [SKIP][10] ([i915#4215])
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_106927v1/bat-dg1-5/igt@[email protected]
* igt@kms_busy@basic:
- bat-dg1-5: NOTRUN -> [SKIP][11] ([i915#1845] / [i915#4303])
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_106927v1/bat-dg1-5/igt@[email protected]
* igt@kms_chamelium@dp-crc-fast:
- bat-dg1-5: NOTRUN -> [SKIP][12] ([fdo#111827]) +7 similar issues
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_106927v1/bat-dg1-5/igt@[email protected]
* igt@kms_cursor_legacy@basic-busy-flip-before-cursor@atomic-transitions:
- fi-bsw-kefka: [PASS][13] -> [FAIL][14] ([i915#6298])
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11964/fi-bsw-kefka/igt@kms_cursor_legacy@[email protected]
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_106927v1/fi-bsw-kefka/igt@kms_cursor_legacy@[email protected]
* igt@kms_force_connector_basic@force-load-detect:
- bat-dg1-5: NOTRUN -> [SKIP][15] ([fdo#109285])
[15]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_106927v1/bat-dg1-5/igt@[email protected]
* igt@kms_pipe_crc_basic@nonblocking-crc:
- bat-dg1-5: NOTRUN -> [SKIP][16] ([i915#4078]) +13 similar issues
[16]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_106927v1/bat-dg1-5/igt@[email protected]
* igt@kms_psr@primary_page_flip:
- bat-dg1-5: NOTRUN -> [SKIP][17] ([i915#1072] / [i915#4078]) +3 similar issues
[17]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_106927v1/bat-dg1-5/igt@kms_psr@primary_page_flip.html
* igt@kms_setmode@basic-clone-single-crtc:
- bat-dg1-5: NOTRUN -> [SKIP][18] ([i915#3555])
[18]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_106927v1/bat-dg1-5/igt@[email protected]
* igt@prime_vgem@basic-fence-flip:
- bat-dg1-5: NOTRUN -> [SKIP][19] ([i915#1845] / [i915#3708])
[19]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_106927v1/bat-dg1-5/igt@[email protected]
* igt@prime_vgem@basic-fence-read:
- bat-dg1-5: NOTRUN -> [SKIP][20] ([i915#3708]) +2 similar issues
[20]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_106927v1/bat-dg1-5/igt@[email protected]
* igt@prime_vgem@basic-gtt:
- bat-dg1-5: NOTRUN -> [SKIP][21] ([i915#3708] / [i915#4077]) +1 similar issue
[21]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_106927v1/bat-dg1-5/igt@[email protected]
* igt@prime_vgem@basic-userptr:
- bat-dg1-5: NOTRUN -> [SKIP][22] ([i915#3708] / [i915#4873])
[22]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_106927v1/bat-dg1-5/igt@[email protected]
* igt@runner@aborted:
- bat-dg1-5: NOTRUN -> [FAIL][23] ([i915#4312] / [i915#5257])
[23]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_106927v1/bat-dg1-5/igt@[email protected]
#### Possible fixes ####
* igt@gem_ringfill@basic-all:
- {bat-dg2-8}: [FAIL][24] ([i915#5886]) -> [PASS][25]
[24]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11964/bat-dg2-8/igt@[email protected]
[25]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_106927v1/bat-dg2-8/igt@[email protected]
* igt@i915_selftest@live@hugepages:
- {bat-adlm-1}: [DMESG-WARN][26] -> [PASS][27]
[26]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_11964/bat-adlm-1/igt@i915_selftest@[email protected]
[27]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_106927v1/bat-adlm-1/igt@i915_selftest@[email protected]
{name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).
[fdo#109285]: https://bugs.freedesktop.org/show_bug.cgi?id=109285
[fdo#109295]: https://bugs.freedesktop.org/show_bug.cgi?id=109295
[fdo#111827]: https://bugs.freedesktop.org/show_bug.cgi?id=111827
[i915#1072]: https://gitlab.freedesktop.org/drm/intel/issues/1072
[i915#1155]: https://gitlab.freedesktop.org/drm/intel/issues/1155
[i915#1845]: https://gitlab.freedesktop.org/drm/intel/issues/1845
[i915#1849]: https://gitlab.freedesktop.org/drm/intel/issues/1849
[i915#2582]: https://gitlab.freedesktop.org/drm/intel/issues/2582
[i915#3282]: https://gitlab.freedesktop.org/drm/intel/issues/3282
[i915#3555]: https://gitlab.freedesktop.org/drm/intel/issues/3555
[i915#3637]: https://gitlab.freedesktop.org/drm/intel/issues/3637
[i915#3708]: https://gitlab.freedesktop.org/drm/intel/issues/3708
[i915#4077]: https://gitlab.freedesktop.org/drm/intel/issues/4077
[i915#4078]: https://gitlab.freedesktop.org/drm/intel/issues/4078
[i915#4079]: https://gitlab.freedesktop.org/drm/intel/issues/4079
[i915#4083]: https://gitlab.freedesktop.org/drm/intel/issues/4083
[i915#4103]: https://gitlab.freedesktop.org/drm/intel/issues/4103
[i915#4212]: https://gitlab.freedesktop.org/drm/intel/issues/4212
[i915#4213]: https://gitlab.freedesktop.org/drm/intel/issues/4213
[i915#4215]: https://gitlab.freedesktop.org/drm/intel/issues/4215
[i915#4303]: https://gitlab.freedesktop.org/drm/intel/issues/4303
[i915#4312]: https://gitlab.freedesktop.org/drm/intel/issues/4312
[i915#4418]: https://gitlab.freedesktop.org/drm/intel/issues/4418
[i915#4613]: https://gitlab.freedesktop.org/drm/intel/issues/4613
[i915#4873]: https://gitlab.freedesktop.org/drm/intel/issues/4873
[i915#5257]: https://gitlab.freedesktop.org/drm/intel/issues/5257
[i915#5354]: https://gitlab.freedesktop.org/drm/intel/issues/5354
[i915#5886]: https://gitlab.freedesktop.org/drm/intel/issues/5886
[i915#6298]: https://gitlab.freedesktop.org/drm/intel/issues/6298
Build changes
-------------
* Linux: CI_DRM_11964 -> Patchwork_106927v1
CI-20190529: 20190529
CI_DRM_11964: 856e330c2d6aa43e94bfca2d1b09369575f8f498 @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_6610: c93f93dfe91a77e6a884f826d61f927106988b5f @ https://gitlab.freedesktop.org/drm/igt-gpu-tools.git
Patchwork_106927v1: 856e330c2d6aa43e94bfca2d1b09369575f8f498 @ git://anongit.freedesktop.org/gfx-ci/linux
### Linux commits
0bd30161f761 drm/i915: Sanitycheck PCI BARs 2c213d6d9a9a drm/i915: Use of BARs names instead of numbers
== Logs ==
For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_106927v1/index.html