Re: [Intel-gfx] [PATCH] drm/i915/tgl: Fix REVID macros for TGL to fetch correct stepping

2020-11-24 Thread kernel test robot
Hi Aditya,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on drm-intel/for-linux-next]
[also build test WARNING on drm-tip/drm-tip v5.10-rc5 next-20201124]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:
https://github.com/0day-ci/linux/commits/Aditya-Swarup/drm-i915-tgl-Fix-REVID-macros-for-TGL-to-fetch-correct-stepping/20201125-083215
base:   git://anongit.freedesktop.org/drm-intel for-linux-next
config: i386-randconfig-a004-20201125 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
reproduce (this is a W=1 build):
# 
https://github.com/0day-ci/linux/commit/ce4e72969ddaa07dd8426d230d04ed91382e2fd9
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review 
Aditya-Swarup/drm-i915-tgl-Fix-REVID-macros-for-TGL-to-fetch-correct-stepping/20201125-083215
git checkout ce4e72969ddaa07dd8426d230d04ed91382e2fd9
# save the attached .config to linux build tree
make W=1 ARCH=i386 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot 

All warnings (new ones prefixed by >>):

   In file included from include/drm/drm_mm.h:49,
from include/drm/drm_vma_manager.h:26,
from include/drm/drm_gem.h:40,
from drivers/gpu/drm/i915/i915_drv.h:55,
from drivers/gpu/drm/i915/gt/intel_workarounds.c:7:
   drivers/gpu/drm/i915/i915_drv.h: In function 'tgl_revids_get':
>> drivers/gpu/drm/i915/i915_drv.h:1594:9: warning: format '%lu' expects 
>> argument of type 'long unsigned int', but argument 5 has type 'unsigned int' 
>> [-Wformat=]
1594 | "Unsupported SOC stepping found %u, using %lu instead\n",
 | ^~~~
   include/drm/drm_print.h:450:38: note: in definition of macro 'drm_dbg_kms'
 450 |  drm_dev_dbg((drm)->dev, DRM_UT_KMS, fmt, ##__VA_ARGS__)
 |  ^~~
   In file included from drivers/gpu/drm/i915/gt/intel_workarounds.c:7:
   drivers/gpu/drm/i915/i915_drv.h:1594:53: note: format string is defined here
1594 | "Unsupported SOC stepping found %u, using %lu instead\n",
 |   ~~^
 | |
 | long unsigned int
 |   %u
   In file included from include/drm/drm_mm.h:49,
from include/drm/drm_vma_manager.h:26,
from include/drm/drm_gem.h:40,
from drivers/gpu/drm/i915/i915_drv.h:55,
from drivers/gpu/drm/i915/gt/intel_workarounds.c:7:
   drivers/gpu/drm/i915/i915_drv.h:1602:8: warning: format '%lu' expects 
argument of type 'long unsigned int', but argument 5 has type 'unsigned int' 
[-Wformat=]
1602 |"Unsupported SOC stepping found %u, using %lu instead\n",
 |^~~~
   include/drm/drm_print.h:450:38: note: in definition of macro 'drm_dbg_kms'
 450 |  drm_dev_dbg((drm)->dev, DRM_UT_KMS, fmt, ##__VA_ARGS__)
 |  ^~~
   In file included from drivers/gpu/drm/i915/gt/intel_workarounds.c:7:
   drivers/gpu/drm/i915/i915_drv.h:1602:52: note: format string is defined here
1602 |"Unsupported SOC stepping found %u, using %lu instead\n",
 |  ~~^
 ||
 |long unsigned int
 |  %u

vim +1594 drivers/gpu/drm/i915/i915_drv.h

  1577  
  1578  #define TGL_UY_REVID_RANGE(revid) \
  1579  ((revid) < ARRAY_SIZE(tgl_uy_revids))
  1580  
  1581  #define TGL_REVID_RANGE(revid) \
  1582  ((revid) < ARRAY_SIZE(tgl_revids))
  1583  
  1584  static inline const struct i915_rev_steppings *
  1585  tgl_revids_get(struct drm_i915_private *dev_priv)
  1586  {
  1587  const u8 revid = INTEL_REVID(dev_priv);
  1588  
  1589  if (IS_TGL_U(dev_priv) || IS_TGL_Y(dev_priv)) {
  1590  if (TGL_UY_REVID_RANGE(revid)) {
  1591  return tgl_uy_revids + revid;
  1592  } else {
  1593  drm_dbg_kms(&dev_priv->drm,
> 1594  "Unsupported SOC stepping found %u, 
> using %lu instead\n",
  1595  revid, ARRAY_SIZE(tgl_uy_revids) - 
1);
  1596  return tgl_uy_revids + 
(ARRAY_SIZE(tgl_uy_revids) - 1);
  1597  

Re: [Intel-gfx] [PATCH] drm/i915/tgl: Fix REVID macros for TGL to fetch correct stepping

2020-11-24 Thread kernel test robot
Hi Aditya,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on drm-intel/for-linux-next]
[also build test WARNING on drm-tip/drm-tip v5.10-rc5 next-20201124]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:
https://github.com/0day-ci/linux/commits/Aditya-Swarup/drm-i915-tgl-Fix-REVID-macros-for-TGL-to-fetch-correct-stepping/20201125-083215
base:   git://anongit.freedesktop.org/drm-intel for-linux-next
config: i386-randconfig-a005-20201125 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
reproduce (this is a W=1 build):
# 
https://github.com/0day-ci/linux/commit/ce4e72969ddaa07dd8426d230d04ed91382e2fd9
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review 
Aditya-Swarup/drm-i915-tgl-Fix-REVID-macros-for-TGL-to-fetch-correct-stepping/20201125-083215
git checkout ce4e72969ddaa07dd8426d230d04ed91382e2fd9
# save the attached .config to linux build tree
make W=1 ARCH=i386 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot 

All warnings (new ones prefixed by >>):

   In file included from include/drm/drm_mm.h:49,
from drivers/gpu/drm/i915/i915_vma.h:31,
from drivers/gpu/drm/i915/gt/uc/intel_guc.h:17,
from drivers/gpu/drm/i915/gt/uc/intel_uc.h:9,
from drivers/gpu/drm/i915/gt/intel_gt_types.h:16,
from drivers/gpu/drm/i915/gt/intel_gt.h:10,
from drivers/gpu/drm/i915/selftests/igt_reset.c:10:
   drivers/gpu/drm/i915/selftests/../i915_drv.h: In function 'tgl_revids_get':
>> drivers/gpu/drm/i915/selftests/../i915_drv.h:1594:9: warning: format '%lu' 
>> expects argument of type 'long unsigned int', but argument 5 has type 
>> 'unsigned int' [-Wformat=]
1594 | "Unsupported SOC stepping found %u, using %lu instead\n",
 | ^~~~
   include/drm/drm_print.h:450:38: note: in definition of macro 'drm_dbg_kms'
 450 |  drm_dev_dbg((drm)->dev, DRM_UT_KMS, fmt, ##__VA_ARGS__)
 |  ^~~
   In file included from drivers/gpu/drm/i915/selftests/igt_reset.c:12:
   drivers/gpu/drm/i915/selftests/../i915_drv.h:1594:53: note: format string is 
defined here
1594 | "Unsupported SOC stepping found %u, using %lu instead\n",
 |   ~~^
 | |
 | long unsigned int
 |   %u
   In file included from include/drm/drm_mm.h:49,
from drivers/gpu/drm/i915/i915_vma.h:31,
from drivers/gpu/drm/i915/gt/uc/intel_guc.h:17,
from drivers/gpu/drm/i915/gt/uc/intel_uc.h:9,
from drivers/gpu/drm/i915/gt/intel_gt_types.h:16,
from drivers/gpu/drm/i915/gt/intel_gt.h:10,
from drivers/gpu/drm/i915/selftests/igt_reset.c:10:
   drivers/gpu/drm/i915/selftests/../i915_drv.h:1602:8: warning: format '%lu' 
expects argument of type 'long unsigned int', but argument 5 has type 'unsigned 
int' [-Wformat=]
1602 |"Unsupported SOC stepping found %u, using %lu instead\n",
 |^~~~
   include/drm/drm_print.h:450:38: note: in definition of macro 'drm_dbg_kms'
 450 |  drm_dev_dbg((drm)->dev, DRM_UT_KMS, fmt, ##__VA_ARGS__)
 |  ^~~
   In file included from drivers/gpu/drm/i915/selftests/igt_reset.c:12:
   drivers/gpu/drm/i915/selftests/../i915_drv.h:1602:52: note: format string is 
defined here
1602 |"Unsupported SOC stepping found %u, using %lu instead\n",
 |  ~~^
 ||
 |long unsigned int
 |  %u

vim +1594 drivers/gpu/drm/i915/selftests/../i915_drv.h

  1577  
  1578  #define TGL_UY_REVID_RANGE(revid) \
  1579  ((revid) < ARRAY_SIZE(tgl_uy_revids))
  1580  
  1581  #define TGL_REVID_RANGE(revid) \
  1582  ((revid) < ARRAY_SIZE(tgl_revids))
  1583  
  1584  static inline const struct i915_rev_steppings *
  1585  tgl_revids_get(struct drm_i915_private *dev_priv)
  1586  {
  1587  const u8 revid = INTEL_REVID(dev_priv);
  1588  
  1589  if (IS_TGL_U(dev_priv) || IS_TGL_Y(dev_priv)) {
  1590  if (TGL_UY_REVID_RANGE(revid)) {
  1591  return tgl_uy

Re: [Intel-gfx] [PATCH] drm/i915/tgl: Fix REVID macros for TGL to fetch correct stepping

2020-11-25 Thread Jani Nikula
On Tue, 24 Nov 2020, Aditya Swarup  wrote:
> Fix TGL REVID macros to fetch correct display/gt stepping based
> on SOC rev id from INTEL_REVID() macro. Previously, we were just
> returning the first element of the revid array instead of using
> the correct index based on SOC rev id.
>
> Also, add array bound checks for TGL REV ID array. Since, there
> might be a possibility of using older kernels on latest platform
> revision, resulting in out of bounds access for rev ID array.
> In this scenario, print message for unsupported rev ID and apply
> settings for latest rev ID available.
>
> Fixes: ("drm/i915/tgl: Fix stepping WA matching")
> Cc: José Roberto de Souza 
> Cc: Matt Roper 
> Cc: Lucas De Marchi 
> Cc: Jani Nikula 
> Cc: Ville Syrjälä 
> Signed-off-by: Aditya Swarup 
> ---
>  drivers/gpu/drm/i915/i915_drv.h | 35 +++--
>  1 file changed, 29 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
> index 15be8debae54..29d55b7017be 100644
> --- a/drivers/gpu/drm/i915/i915_drv.h
> +++ b/drivers/gpu/drm/i915/i915_drv.h
> @@ -1572,16 +1572,37 @@ enum {
>   TGL_REVID_D0,
>  };
>  
> -extern const struct i915_rev_steppings tgl_uy_revids[];
> -extern const struct i915_rev_steppings tgl_revids[];
> +extern const struct i915_rev_steppings tgl_uy_revids[4];
> +extern const struct i915_rev_steppings tgl_revids[2];

Just a quick note, the compiler does not check that the size in the
extern declaration matches the size in the array definition. So you
might end up with a mismatch without noticing.

BR,
Jani.

> +
> +#define TGL_UY_REVID_RANGE(revid) \
> + ((revid) < ARRAY_SIZE(tgl_uy_revids))
> +
> +#define TGL_REVID_RANGE(revid) \
> + ((revid) < ARRAY_SIZE(tgl_revids))
>  
>  static inline const struct i915_rev_steppings *
>  tgl_revids_get(struct drm_i915_private *dev_priv)
>  {
> - if (IS_TGL_U(dev_priv) || IS_TGL_Y(dev_priv))
> - return tgl_uy_revids;
> - else
> - return tgl_revids;
> + const u8 revid = INTEL_REVID(dev_priv);
> +
> + if (IS_TGL_U(dev_priv) || IS_TGL_Y(dev_priv)) {
> + if (TGL_UY_REVID_RANGE(revid)) {
> + return tgl_uy_revids + revid;
> + } else {
> + drm_dbg_kms(&dev_priv->drm,
> + "Unsupported SOC stepping found %u, using 
> %lu instead\n",
> + revid, ARRAY_SIZE(tgl_uy_revids) - 1);
> + return tgl_uy_revids + (ARRAY_SIZE(tgl_uy_revids) - 1);
> + }
> + } else if (TGL_REVID_RANGE(revid)) {
> + return tgl_revids + revid;
> + } else  {
> + drm_dbg_kms(&dev_priv->drm,
> + "Unsupported SOC stepping found %u, using %lu 
> instead\n",
> + revid, ARRAY_SIZE(tgl_revids) - 1);
> + return tgl_uy_revids + (ARRAY_SIZE(tgl_revids) - 1);
> + }
>  }
>  
>  #define IS_TGL_DISP_REVID(p, since, until) \
> @@ -1591,12 +1612,14 @@ tgl_revids_get(struct drm_i915_private *dev_priv)
>  
>  #define IS_TGL_UY_GT_REVID(p, since, until) \
>   ((IS_TGL_U(p) || IS_TGL_Y(p)) && \
> +  TGL_UY_REVID_RANGE(INTEL_REVID(p)) && \
>tgl_uy_revids->gt_stepping >= (since) && \
>tgl_uy_revids->gt_stepping <= (until))
>  
>  #define IS_TGL_GT_REVID(p, since, until) \
>   (IS_TIGERLAKE(p) && \
>!(IS_TGL_U(p) || IS_TGL_Y(p)) && \
> +  TGL_REVID_RANGE(INTEL_REVID(p)) && \
>tgl_revids->gt_stepping >= (since) && \
>tgl_revids->gt_stepping <= (until))

-- 
Jani Nikula, Intel Open Source Graphics Center
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [PATCH] drm/i915/tgl: Fix REVID macros for TGL to fetch correct stepping

2020-11-25 Thread Souza, Jose
On Tue, 2020-11-24 at 16:31 -0800, Aditya Swarup wrote:
> Fix TGL REVID macros to fetch correct display/gt stepping based
> on SOC rev id from INTEL_REVID() macro. Previously, we were just
> returning the first element of the revid array instead of using
> the correct index based on SOC rev id.
> 
> Also, add array bound checks for TGL REV ID array. Since, there
> might be a possibility of using older kernels on latest platform
> revision, resulting in out of bounds access for rev ID array.
> In this scenario, print message for unsupported rev ID and apply
> settings for latest rev ID available.
> 
> Fixes: ("drm/i915/tgl: Fix stepping WA matching")
> Cc: José Roberto de Souza 
> Cc: Matt Roper 
> Cc: Lucas De Marchi 
> Cc: Jani Nikula 
> Cc: Ville Syrjälä 
> Signed-off-by: Aditya Swarup 
> ---
>  drivers/gpu/drm/i915/i915_drv.h | 35 +++--
>  1 file changed, 29 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
> index 15be8debae54..29d55b7017be 100644
> --- a/drivers/gpu/drm/i915/i915_drv.h
> +++ b/drivers/gpu/drm/i915/i915_drv.h
> @@ -1572,16 +1572,37 @@ enum {
>   TGL_REVID_D0,
>  };
>  
> 
> 
> 
> 
> 
> 
> 
> -extern const struct i915_rev_steppings tgl_uy_revids[];
> -extern const struct i915_rev_steppings tgl_revids[];
> +extern const struct i915_rev_steppings tgl_uy_revids[4];
> +extern const struct i915_rev_steppings tgl_revids[2];

Not sure if the above will work, saw a comment from Jani please check that.

> +
> +#define TGL_UY_REVID_RANGE(revid) \
> + ((revid) < ARRAY_SIZE(tgl_uy_revids))
> +
> +#define TGL_REVID_RANGE(revid) \
> + ((revid) < ARRAY_SIZE(tgl_revids))
>  
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
>  static inline const struct i915_rev_steppings *
>  tgl_revids_get(struct drm_i915_private *dev_priv)
>  {
> - if (IS_TGL_U(dev_priv) || IS_TGL_Y(dev_priv))
> - return tgl_uy_revids;
> - else
> - return tgl_revids;
> + const u8 revid = INTEL_REVID(dev_priv);
> +
> + if (IS_TGL_U(dev_priv) || IS_TGL_Y(dev_priv)) {
> + if (TGL_UY_REVID_RANGE(revid)) {
> + return tgl_uy_revids + revid;

Why not help readers and go simple? tgl_uy_revids[revid]

> + } else {
> + drm_dbg_kms(&dev_priv->drm,
> + "Unsupported SOC stepping found %u, using 
> %lu instead\n",
> + revid, ARRAY_SIZE(tgl_uy_revids) - 1);
> + return tgl_uy_revids + (ARRAY_SIZE(tgl_uy_revids) - 1);
> + }
> + } else if (TGL_REVID_RANGE(revid)) {
> + return tgl_revids + revid;
> + } else  {
> + drm_dbg_kms(&dev_priv->drm,
> + "Unsupported SOC stepping found %u, using %lu 
> instead\n",
> + revid, ARRAY_SIZE(tgl_revids) - 1);
> + return tgl_uy_revids + (ARRAY_SIZE(tgl_revids) - 1);
> + }

I bet you can re arrange it and end up with one drm_dbg_kms() call.


>  }
>  
> 
> 
> 
> 
> 
> 
> 
>  #define IS_TGL_DISP_REVID(p, since, until) \
> @@ -1591,12 +1612,14 @@ tgl_revids_get(struct drm_i915_private *dev_priv)
>  
> 
> 
> 
> 
> 
> 
> 
>  #define IS_TGL_UY_GT_REVID(p, since, until) \
>   ((IS_TGL_U(p) || IS_TGL_Y(p)) && \
> +  TGL_UY_REVID_RANGE(INTEL_REVID(p)) && \
>    tgl_uy_revids->gt_stepping >= (since) && \
>    tgl_uy_revids->gt_stepping <= (until))
>  
> 
> 
> 
> 
> 
> 
> 
>  #define IS_TGL_GT_REVID(p, since, until) \
>   (IS_TIGERLAKE(p) && \
>    !(IS_TGL_U(p) || IS_TGL_Y(p)) && \
> +  TGL_REVID_RANGE(INTEL_REVID(p)) && \
>    tgl_revids->gt_stepping >= (since) && \
>    tgl_revids->gt_stepping <= (until))
>  
> 
> 
> 
> 
> 
> 

You did not fixed the issue for GT.

> 
> 
> 
> 
> 

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [PATCH] drm/i915/tgl: Fix REVID macros for TGL to fetch correct stepping

2020-11-25 Thread Chris Wilson
Quoting Jani Nikula (2020-11-25 11:45:56)
> On Tue, 24 Nov 2020, Aditya Swarup  wrote:
> > Fix TGL REVID macros to fetch correct display/gt stepping based
> > on SOC rev id from INTEL_REVID() macro. Previously, we were just
> > returning the first element of the revid array instead of using
> > the correct index based on SOC rev id.
> >
> > Also, add array bound checks for TGL REV ID array. Since, there
> > might be a possibility of using older kernels on latest platform
> > revision, resulting in out of bounds access for rev ID array.
> > In this scenario, print message for unsupported rev ID and apply
> > settings for latest rev ID available.
> >
> > Fixes: ("drm/i915/tgl: Fix stepping WA matching")
> > Cc: José Roberto de Souza 
> > Cc: Matt Roper 
> > Cc: Lucas De Marchi 
> > Cc: Jani Nikula 
> > Cc: Ville Syrjälä 
> > Signed-off-by: Aditya Swarup 
> > ---
> >  drivers/gpu/drm/i915/i915_drv.h | 35 +++--
> >  1 file changed, 29 insertions(+), 6 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/i915/i915_drv.h 
> > b/drivers/gpu/drm/i915/i915_drv.h
> > index 15be8debae54..29d55b7017be 100644
> > --- a/drivers/gpu/drm/i915/i915_drv.h
> > +++ b/drivers/gpu/drm/i915/i915_drv.h
> > @@ -1572,16 +1572,37 @@ enum {
> >   TGL_REVID_D0,
> >  };
> >  
> > -extern const struct i915_rev_steppings tgl_uy_revids[];
> > -extern const struct i915_rev_steppings tgl_revids[];
> > +extern const struct i915_rev_steppings tgl_uy_revids[4];
> > +extern const struct i915_rev_steppings tgl_revids[2];
> 
> Just a quick note, the compiler does not check that the size in the
> extern declaration matches the size in the array definition. So you
> might end up with a mismatch without noticing.

What surprised me is that this defeated the __must_be_array() check.
I thought these were just pointers to C

> > +#define TGL_UY_REVID_RANGE(revid) \
> > + ((revid) < ARRAY_SIZE(tgl_uy_revids))
> > +
> > +#define TGL_REVID_RANGE(revid) \
> > + ((revid) < ARRAY_SIZE(tgl_revids))
> >  
> >  static inline const struct i915_rev_steppings *
> >  tgl_revids_get(struct drm_i915_private *dev_priv)
> >  {
> > - if (IS_TGL_U(dev_priv) || IS_TGL_Y(dev_priv))
> > - return tgl_uy_revids;
> > - else
> > - return tgl_revids;
> > + const u8 revid = INTEL_REVID(dev_priv);
> > +
> > + if (IS_TGL_U(dev_priv) || IS_TGL_Y(dev_priv)) {
> > + if (TGL_UY_REVID_RANGE(revid)) {
> > + return tgl_uy_revids + revid;
> > + } else {
> > + drm_dbg_kms(&dev_priv->drm,
> > + "Unsupported SOC stepping found %u, using 
> > %lu instead\n",
> > + revid, ARRAY_SIZE(tgl_uy_revids) - 1);

Also please don't have a dbg for every single IS_TGL_*_REVID
invocation. And this is not _kms, but driver; better yet, don't bother
with a drm_dbg_kms here at all.

If you want to actually check, add something like
intel_detect_preproduction_hw() and warn about unknown future revids.
Or include the info when we print the revid in the caps.
-Chris
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [PATCH] drm/i915/tgl: Fix REVID macros for TGL to fetch correct stepping

2020-11-25 Thread Aditya Swarup
On 11/25/20 7:33 AM, Chris Wilson wrote:
> Quoting Jani Nikula (2020-11-25 11:45:56)
>> On Tue, 24 Nov 2020, Aditya Swarup  wrote:
>>> Fix TGL REVID macros to fetch correct display/gt stepping based
>>> on SOC rev id from INTEL_REVID() macro. Previously, we were just
>>> returning the first element of the revid array instead of using
>>> the correct index based on SOC rev id.
>>>
>>> Also, add array bound checks for TGL REV ID array. Since, there
>>> might be a possibility of using older kernels on latest platform
>>> revision, resulting in out of bounds access for rev ID array.
>>> In this scenario, print message for unsupported rev ID and apply
>>> settings for latest rev ID available.
>>>
>>> Fixes: ("drm/i915/tgl: Fix stepping WA matching")
>>> Cc: José Roberto de Souza 
>>> Cc: Matt Roper 
>>> Cc: Lucas De Marchi 
>>> Cc: Jani Nikula 
>>> Cc: Ville Syrjälä 
>>> Signed-off-by: Aditya Swarup 
>>> ---
>>>  drivers/gpu/drm/i915/i915_drv.h | 35 +++--
>>>  1 file changed, 29 insertions(+), 6 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/i915/i915_drv.h 
>>> b/drivers/gpu/drm/i915/i915_drv.h
>>> index 15be8debae54..29d55b7017be 100644
>>> --- a/drivers/gpu/drm/i915/i915_drv.h
>>> +++ b/drivers/gpu/drm/i915/i915_drv.h
>>> @@ -1572,16 +1572,37 @@ enum {
>>>   TGL_REVID_D0,
>>>  };
>>>  
>>> -extern const struct i915_rev_steppings tgl_uy_revids[];
>>> -extern const struct i915_rev_steppings tgl_revids[];
>>> +extern const struct i915_rev_steppings tgl_uy_revids[4];
>>> +extern const struct i915_rev_steppings tgl_revids[2];
>>
>> Just a quick note, the compiler does not check that the size in the
>> extern declaration matches the size in the array definition. So you
>> might end up with a mismatch without noticing.

Yes.. We will have to take care of it if we are adding rev id to array 
table(which mostly
should remain a const once we decide to go upstream). Without this declaration, 
I cannot
use ARRAY_SIZE() macro with revid arrays as the sizeof() operator complains 
about not
knowing the size of the array in question as it is an extern declaration. 

So, I don't know what other approach you want to suggest? If we move all the 
array tables to i915_drv.h(which
I feel would be a better approach rather than having it in 
intel_workarounds.c), Matt
Roper's KBL patch says that compiler complains about unused variables.

We are anyhow going to correct the whole thing with your stepping series 
anyway. This is supposed
to be a stop gap fix. Revids shouldn't be changing for TGL anymore.

> 
> What surprised me is that this defeated the __must_be_array() check.
> I thought these were just pointers to C
> 
>>> +#define TGL_UY_REVID_RANGE(revid) \
>>> + ((revid) < ARRAY_SIZE(tgl_uy_revids))
>>> +
>>> +#define TGL_REVID_RANGE(revid) \
>>> + ((revid) < ARRAY_SIZE(tgl_revids))
>>>  
>>>  static inline const struct i915_rev_steppings *
>>>  tgl_revids_get(struct drm_i915_private *dev_priv)
>>>  {
>>> - if (IS_TGL_U(dev_priv) || IS_TGL_Y(dev_priv))
>>> - return tgl_uy_revids;
>>> - else
>>> - return tgl_revids;
>>> + const u8 revid = INTEL_REVID(dev_priv);
>>> +
>>> + if (IS_TGL_U(dev_priv) || IS_TGL_Y(dev_priv)) {
>>> + if (TGL_UY_REVID_RANGE(revid)) {
>>> + return tgl_uy_revids + revid;
>>> + } else {
>>> + drm_dbg_kms(&dev_priv->drm,
>>> + "Unsupported SOC stepping found %u, using 
>>> %lu instead\n",
>>> + revid, ARRAY_SIZE(tgl_uy_revids) - 1);
> 
> Also please don't have a dbg for every single IS_TGL_*_REVID
> invocation. And this is not _kms, but driver; better yet, don't bother
> with a drm_dbg_kms here at all.
> 
> If you want to actually check, add something like
> intel_detect_preproduction_hw() and warn about unknown future revids.
> Or include the info when we print the revid in the caps.

So, what you are suggesting is add an info print in that function 
intel_detect_preproduction_hw() right?
Or something else?

> -Chris
> 

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [PATCH] drm/i915/tgl: Fix REVID macros for TGL to fetch correct stepping

2020-11-25 Thread Aditya Swarup
On 11/25/20 5:21 AM, Souza, Jose wrote:
> On Tue, 2020-11-24 at 16:31 -0800, Aditya Swarup wrote:
>> Fix TGL REVID macros to fetch correct display/gt stepping based
>> on SOC rev id from INTEL_REVID() macro. Previously, we were just
>> returning the first element of the revid array instead of using
>> the correct index based on SOC rev id.
>>
>> Also, add array bound checks for TGL REV ID array. Since, there
>> might be a possibility of using older kernels on latest platform
>> revision, resulting in out of bounds access for rev ID array.
>> In this scenario, print message for unsupported rev ID and apply
>> settings for latest rev ID available.
>>
>> Fixes: ("drm/i915/tgl: Fix stepping WA matching")
>> Cc: José Roberto de Souza 
>> Cc: Matt Roper 
>> Cc: Lucas De Marchi 
>> Cc: Jani Nikula 
>> Cc: Ville Syrjälä 
>> Signed-off-by: Aditya Swarup 
>> ---
>>  drivers/gpu/drm/i915/i915_drv.h | 35 +++--
>>  1 file changed, 29 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/i915/i915_drv.h 
>> b/drivers/gpu/drm/i915/i915_drv.h
>> index 15be8debae54..29d55b7017be 100644
>> --- a/drivers/gpu/drm/i915/i915_drv.h
>> +++ b/drivers/gpu/drm/i915/i915_drv.h
>> @@ -1572,16 +1572,37 @@ enum {
>>  TGL_REVID_D0,
>>  };
>>  
>>
>>
>>
>>
>>
>>
>>
>> -extern const struct i915_rev_steppings tgl_uy_revids[];
>> -extern const struct i915_rev_steppings tgl_revids[];
>> +extern const struct i915_rev_steppings tgl_uy_revids[4];
>> +extern const struct i915_rev_steppings tgl_revids[2];
> 
> Not sure if the above will work, saw a comment from Jani please check that.

This works otherwise I can't use ARRAY_SIZE() macro as it is just an extern 
declaration,
so the sizeof() doesn't have clue about the size. The only way I can think of 
working 
around this is by moving tables here but Matt's KBL REVID patch suggests unused 
variables errors
but my compiler didn't complain.

> 
>> +
>> +#define TGL_UY_REVID_RANGE(revid) \
>> +((revid) < ARRAY_SIZE(tgl_uy_revids))
>> +
>> +#define TGL_REVID_RANGE(revid) \
>> +((revid) < ARRAY_SIZE(tgl_revids))
>>  
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>  static inline const struct i915_rev_steppings *
>>  tgl_revids_get(struct drm_i915_private *dev_priv)
>>  {
>> -if (IS_TGL_U(dev_priv) || IS_TGL_Y(dev_priv))
>> -return tgl_uy_revids;
>> -else
>> -return tgl_revids;
>> +const u8 revid = INTEL_REVID(dev_priv);
>> +
>> +if (IS_TGL_U(dev_priv) || IS_TGL_Y(dev_priv)) {
>> +if (TGL_UY_REVID_RANGE(revid)) {
>> +return tgl_uy_revids + revid;
> 
> Why not help readers and go simple? tgl_uy_revids[revid]

Hmm I will have to change the return type then, as you were returning a pointer 
and introduces
compiler error. I will change the return type.

> 
>> +} else {
>> +drm_dbg_kms(&dev_priv->drm,
>> +"Unsupported SOC stepping found %u, using 
>> %lu instead\n",
>> +revid, ARRAY_SIZE(tgl_uy_revids) - 1);
>> +return tgl_uy_revids + (ARRAY_SIZE(tgl_uy_revids) - 1);
>> +}
>> +} else if (TGL_REVID_RANGE(revid)) {
>> +return tgl_revids + revid;
>> +} else  {
>> +drm_dbg_kms(&dev_priv->drm,
>> +"Unsupported SOC stepping found %u, using %lu 
>> instead\n",
>> +revid, ARRAY_SIZE(tgl_revids) - 1);
>> +return tgl_uy_revids + (ARRAY_SIZE(tgl_revids) - 1);
>> +}
> 
> I bet you can re arrange it and end up with one drm_dbg_kms() call.

I can but that will involve more macros as we are dealing with two different 
array tables and each one
with a different range. I will use just one print to say what SOC rev id we get 
from pci dev and what
we will be using. 

> 
> 
>>  }
>>  
>>
>>
>>
>>
>>
>>
>>
>>  #define IS_TGL_DISP_REVID(p, since, until) \
>> @@ -1591,12 +1612,14 @@ tgl_revids_get(struct drm_i915_private *dev_priv)
>>  
>>
>>
>>
>>
>>
>>
>>
>>  #define IS_TGL_UY_GT_REVID(p, since, until) \
>>  ((IS_TGL_U(p) || IS_TGL_Y(p)) && \
>> + TGL_UY_REVID_RANGE(INTEL_REVID(p)) && \
>>   tgl_uy_revids->gt_stepping >= (since) && \
>>   tgl_uy_revids->gt_stepping <= (until))
>>  
>>
>>
>>
>>
>>
>>
>>
>>  #define IS_TGL_GT_REVID(p, since, until) \
>>  (IS_TIGERLAKE(p) && \
>>   !(IS_TGL_U(p) || IS_TGL_Y(p)) && \
>> + TGL_REVID_RANGE(INTEL_REVID(p)) && \
>>   tgl_revids->gt_stepping >= (since) && \
>>   tgl_revids->gt_stepping <= (until))
>>  
>>
>>
>>
>>
>>
>>
> 
> You did not fixed the issue for GT.

Yes.. I didn't notice that.. Will change in the next revision.

Aditya

> 
>>
>>
>>
>>
>>
> 

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [PATCH] drm/i915/tgl: Fix REVID macros for TGL to fetch correct stepping

2020-11-25 Thread Souza, Jose
On Wed, 2020-11-25 at 10:03 -0800, Aditya Swarup wrote:
> On 11/25/20 5:21 AM, Souza, Jose wrote:
> > On Tue, 2020-11-24 at 16:31 -0800, Aditya Swarup wrote:
> > > Fix TGL REVID macros to fetch correct display/gt stepping based
> > > on SOC rev id from INTEL_REVID() macro. Previously, we were just
> > > returning the first element of the revid array instead of using
> > > the correct index based on SOC rev id.
> > > 
> > > Also, add array bound checks for TGL REV ID array. Since, there
> > > might be a possibility of using older kernels on latest platform
> > > revision, resulting in out of bounds access for rev ID array.
> > > In this scenario, print message for unsupported rev ID and apply
> > > settings for latest rev ID available.
> > > 
> > > Fixes: ("drm/i915/tgl: Fix stepping WA matching")
> > > Cc: José Roberto de Souza 
> > > Cc: Matt Roper 
> > > Cc: Lucas De Marchi 
> > > Cc: Jani Nikula 
> > > Cc: Ville Syrjälä 
> > > Signed-off-by: Aditya Swarup 
> > > ---
> > >  drivers/gpu/drm/i915/i915_drv.h | 35 +++--
> > >  1 file changed, 29 insertions(+), 6 deletions(-)
> > > 
> > > diff --git a/drivers/gpu/drm/i915/i915_drv.h 
> > > b/drivers/gpu/drm/i915/i915_drv.h
> > > index 15be8debae54..29d55b7017be 100644
> > > --- a/drivers/gpu/drm/i915/i915_drv.h
> > > +++ b/drivers/gpu/drm/i915/i915_drv.h
> > > @@ -1572,16 +1572,37 @@ enum {
> > >   TGL_REVID_D0,
> > >  };
> > >  
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > > -extern const struct i915_rev_steppings tgl_uy_revids[];
> > > -extern const struct i915_rev_steppings tgl_revids[];
> > > +extern const struct i915_rev_steppings tgl_uy_revids[4];
> > > +extern const struct i915_rev_steppings tgl_revids[2];
> > 
> > Not sure if the above will work, saw a comment from Jani please check that.
> 
> This works otherwise I can't use ARRAY_SIZE() macro as it is just an extern 
> declaration,
> so the sizeof() doesn't have clue about the size. The only way I can think of 
> working 
> around this is by moving tables here but Matt's KBL REVID patch suggests 
> unused variables errors
> but my compiler didn't complain.
> 
> > 
> > > +
> > > +#define TGL_UY_REVID_RANGE(revid) \
> > > + ((revid) < ARRAY_SIZE(tgl_uy_revids))
> > > +
> > > +#define TGL_REVID_RANGE(revid) \
> > > + ((revid) < ARRAY_SIZE(tgl_revids))
> > >  
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > >  static inline const struct i915_rev_steppings *
> > >  tgl_revids_get(struct drm_i915_private *dev_priv)
> > >  {
> > > - if (IS_TGL_U(dev_priv) || IS_TGL_Y(dev_priv))
> > > - return tgl_uy_revids;
> > > - else
> > > - return tgl_revids;
> > > + const u8 revid = INTEL_REVID(dev_priv);
> > > +
> > > + if (IS_TGL_U(dev_priv) || IS_TGL_Y(dev_priv)) {
> > > + if (TGL_UY_REVID_RANGE(revid)) {
> > > + return tgl_uy_revids + revid;
> > 
> > Why not help readers and go simple? tgl_uy_revids[revid]
> 
> Hmm I will have to change the return type then, as you were returning a 
> pointer and introduces
> compiler error. I will change the return type.

No need to change the return type. &tgl_uy_revids[revid]



> 
> > 
> > > + } else {
> > > + drm_dbg_kms(&dev_priv->drm,
> > > + "Unsupported SOC stepping found %u, using 
> > > %lu instead\n",
> > > + revid, ARRAY_SIZE(tgl_uy_revids) - 1);
> > > + return tgl_uy_revids + (ARRAY_SIZE(tgl_uy_revids) - 1);
> > > + }
> > > + } else if (TGL_REVID_RANGE(revid)) {
> > > + return tgl_revids + revid;
> > > + } else  {
> > > + drm_dbg_kms(&dev_priv->drm,
> > > + "Unsupported SOC stepping found %u, using %lu 
> > > instead\n",
> > > + revid, ARRAY_SIZE(tgl_revids) - 1);
> > > + return tgl_uy_revids + (ARRAY_SIZE(tgl_revids) - 1);
> > > + }
> > 
> > I bet you can re arrange it and end up with one drm_dbg_kms() call.
> 
> I can but that will involve more macros as we are dealing with two different 
> array tables and each one
> with a different range. I will use just one print to say what SOC rev id we 
> get from pci dev and what
> we will be using. 
> 
> > 
> > 
> > >  }
> > >  
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > >  #define IS_TGL_DISP_REVID(p, since, until) \
> > > @@ -1591,12 +1612,14 @@ tgl_revids_get(struct drm_i915_private *dev_priv)
> > >  
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > >  #define IS_TGL_UY_GT_REVID(p, since, until) \
> > >   ((IS_TGL_U(p) || IS_TGL_Y(p)) && \
> > > +  TGL_UY_REVID_RANGE(INTEL_REVID(p)) && \
> > >    tgl_uy_revids->gt_stepping >= (since) && \
> > >    tgl_uy_revids->gt_stepping <= (until))
> > >  
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > >  #define IS_TGL_GT_REVID(p, since, until) \
> > >   (IS_TIGERLAKE(p) && \
> > >    !(IS_TGL_U(p) || IS_TGL_Y(p)) && \
> > > +  TGL_REVID_RANGE(INTEL_REVID(p)) && 

Re: [Intel-gfx] [PATCH] drm/i915/tgl: Fix REVID macros for TGL to fetch correct stepping

2020-11-25 Thread Ville Syrjälä
On Wed, Nov 25, 2020 at 09:51:04AM -0800, Aditya Swarup wrote:
> On 11/25/20 7:33 AM, Chris Wilson wrote:
> > Quoting Jani Nikula (2020-11-25 11:45:56)
> >> On Tue, 24 Nov 2020, Aditya Swarup  wrote:
> >>> Fix TGL REVID macros to fetch correct display/gt stepping based
> >>> on SOC rev id from INTEL_REVID() macro. Previously, we were just
> >>> returning the first element of the revid array instead of using
> >>> the correct index based on SOC rev id.
> >>>
> >>> Also, add array bound checks for TGL REV ID array. Since, there
> >>> might be a possibility of using older kernels on latest platform
> >>> revision, resulting in out of bounds access for rev ID array.
> >>> In this scenario, print message for unsupported rev ID and apply
> >>> settings for latest rev ID available.
> >>>
> >>> Fixes: ("drm/i915/tgl: Fix stepping WA matching")
> >>> Cc: José Roberto de Souza 
> >>> Cc: Matt Roper 
> >>> Cc: Lucas De Marchi 
> >>> Cc: Jani Nikula 
> >>> Cc: Ville Syrjälä 
> >>> Signed-off-by: Aditya Swarup 
> >>> ---
> >>>  drivers/gpu/drm/i915/i915_drv.h | 35 +++--
> >>>  1 file changed, 29 insertions(+), 6 deletions(-)
> >>>
> >>> diff --git a/drivers/gpu/drm/i915/i915_drv.h 
> >>> b/drivers/gpu/drm/i915/i915_drv.h
> >>> index 15be8debae54..29d55b7017be 100644
> >>> --- a/drivers/gpu/drm/i915/i915_drv.h
> >>> +++ b/drivers/gpu/drm/i915/i915_drv.h
> >>> @@ -1572,16 +1572,37 @@ enum {
> >>>   TGL_REVID_D0,
> >>>  };
> >>>  
> >>> -extern const struct i915_rev_steppings tgl_uy_revids[];
> >>> -extern const struct i915_rev_steppings tgl_revids[];
> >>> +extern const struct i915_rev_steppings tgl_uy_revids[4];
> >>> +extern const struct i915_rev_steppings tgl_revids[2];
> >>
> >> Just a quick note, the compiler does not check that the size in the
> >> extern declaration matches the size in the array definition. So you
> >> might end up with a mismatch without noticing.
> 
> Yes.. We will have to take care of it if we are adding rev id to array 
> table(which mostly
> should remain a const once we decide to go upstream). Without this 
> declaration, I cannot
> use ARRAY_SIZE() macro with revid arrays as the sizeof() operator complains 
> about not
> knowing the size of the array in question as it is an extern declaration. 

Can't you replace the ARRAY_SIZE() with a sentinel? I guess
Making it a struct with a size member would be another option.

-- 
Ville Syrjälä
Intel
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [PATCH] drm/i915/tgl: Fix REVID macros for TGL to fetch correct stepping

2020-11-25 Thread Lucas De Marchi

On Wed, Nov 25, 2020 at 03:33:23PM +, Chris Wilson wrote:

Quoting Jani Nikula (2020-11-25 11:45:56)

On Tue, 24 Nov 2020, Aditya Swarup  wrote:
> Fix TGL REVID macros to fetch correct display/gt stepping based
> on SOC rev id from INTEL_REVID() macro. Previously, we were just
> returning the first element of the revid array instead of using
> the correct index based on SOC rev id.
>
> Also, add array bound checks for TGL REV ID array. Since, there
> might be a possibility of using older kernels on latest platform
> revision, resulting in out of bounds access for rev ID array.
> In this scenario, print message for unsupported rev ID and apply
> settings for latest rev ID available.
>
> Fixes: ("drm/i915/tgl: Fix stepping WA matching")
> Cc: José Roberto de Souza 
> Cc: Matt Roper 
> Cc: Lucas De Marchi 
> Cc: Jani Nikula 
> Cc: Ville Syrjälä 
> Signed-off-by: Aditya Swarup 
> ---
>  drivers/gpu/drm/i915/i915_drv.h | 35 +++--
>  1 file changed, 29 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
> index 15be8debae54..29d55b7017be 100644
> --- a/drivers/gpu/drm/i915/i915_drv.h
> +++ b/drivers/gpu/drm/i915/i915_drv.h
> @@ -1572,16 +1572,37 @@ enum {
>   TGL_REVID_D0,
>  };
>
> -extern const struct i915_rev_steppings tgl_uy_revids[];
> -extern const struct i915_rev_steppings tgl_revids[];
> +extern const struct i915_rev_steppings tgl_uy_revids[4];
> +extern const struct i915_rev_steppings tgl_revids[2];

Just a quick note, the compiler does not check that the size in the
extern declaration matches the size in the array definition. So you
might end up with a mismatch without noticing.


What surprised me is that this defeated the __must_be_array() check.
I thought these were just pointers to C


it doesn't complain because it actually works. The extern is declaring
that amount of storage size... I think people here are confusing with
accepting an array as a parameter, in which case it decays to a
pointer.

Since this is all obscure semantics of C, for the quick fix here maybe
better to just define the size and reuse it both in header and .c?

and then work in the refactor that will actually remove all of this.

Lucas De Marchi




> +#define TGL_UY_REVID_RANGE(revid) \
> + ((revid) < ARRAY_SIZE(tgl_uy_revids))
> +
> +#define TGL_REVID_RANGE(revid) \
> + ((revid) < ARRAY_SIZE(tgl_revids))
>
>  static inline const struct i915_rev_steppings *
>  tgl_revids_get(struct drm_i915_private *dev_priv)
>  {
> - if (IS_TGL_U(dev_priv) || IS_TGL_Y(dev_priv))
> - return tgl_uy_revids;
> - else
> - return tgl_revids;
> + const u8 revid = INTEL_REVID(dev_priv);
> +
> + if (IS_TGL_U(dev_priv) || IS_TGL_Y(dev_priv)) {
> + if (TGL_UY_REVID_RANGE(revid)) {
> + return tgl_uy_revids + revid;
> + } else {
> + drm_dbg_kms(&dev_priv->drm,
> + "Unsupported SOC stepping found %u, using %lu 
instead\n",
> + revid, ARRAY_SIZE(tgl_uy_revids) - 1);


Also please don't have a dbg for every single IS_TGL_*_REVID
invocation. And this is not _kms, but driver; better yet, don't bother
with a drm_dbg_kms here at all.

If you want to actually check, add something like
intel_detect_preproduction_hw() and warn about unknown future revids.
Or include the info when we print the revid in the caps.
-Chris

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [PATCH] drm/i915/tgl: Fix REVID macros for TGL to fetch correct stepping

2020-11-25 Thread Lucas De Marchi

On Wed, Nov 25, 2020 at 09:51:04AM -0800, Aditya Swarup wrote:

On 11/25/20 7:33 AM, Chris Wilson wrote:

Quoting Jani Nikula (2020-11-25 11:45:56)

On Tue, 24 Nov 2020, Aditya Swarup  wrote:

Fix TGL REVID macros to fetch correct display/gt stepping based
on SOC rev id from INTEL_REVID() macro. Previously, we were just
returning the first element of the revid array instead of using
the correct index based on SOC rev id.

Also, add array bound checks for TGL REV ID array. Since, there
might be a possibility of using older kernels on latest platform
revision, resulting in out of bounds access for rev ID array.
In this scenario, print message for unsupported rev ID and apply
settings for latest rev ID available.

Fixes: ("drm/i915/tgl: Fix stepping WA matching")
Cc: José Roberto de Souza 
Cc: Matt Roper 
Cc: Lucas De Marchi 
Cc: Jani Nikula 
Cc: Ville Syrjälä 
Signed-off-by: Aditya Swarup 
---
 drivers/gpu/drm/i915/i915_drv.h | 35 +++--
 1 file changed, 29 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 15be8debae54..29d55b7017be 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -1572,16 +1572,37 @@ enum {
  TGL_REVID_D0,
 };

-extern const struct i915_rev_steppings tgl_uy_revids[];
-extern const struct i915_rev_steppings tgl_revids[];
+extern const struct i915_rev_steppings tgl_uy_revids[4];
+extern const struct i915_rev_steppings tgl_revids[2];


Just a quick note, the compiler does not check that the size in the
extern declaration matches the size in the array definition. So you
might end up with a mismatch without noticing.


Yes.. We will have to take care of it if we are adding rev id to array 
table(which mostly
should remain a const once we decide to go upstream). Without this declaration, 
I cannot
use ARRAY_SIZE() macro with revid arrays as the sizeof() operator complains 
about not
knowing the size of the array in question as it is an extern declaration.

So, I don't know what other approach you want to suggest? If we move all the 
array tables to i915_drv.h(which
I feel would be a better approach rather than having it in 
intel_workarounds.c), Matt
Roper's KBL patch says that compiler complains about unused variables.


adding the table in the header means that each compilation unit (.o)
will get a copy of the table when it includes the header (it will end up
being trimmed out if not used though). This is not what you want.

As I said in the other reply, sizeof does actually work here:

$ cat /tmp/a.c
#include 

#include "b.h"

int main(int argc, const char *argv[])
{
printf("%zu", sizeof(tgl_uy_revids));
return 0;
}

$ cat /tmp/b.h
#pragma once

struct i915_rev_steppings { int a; };
extern const struct i915_rev_steppings tgl_uy_revids[4];

$ cat /tmp/b.c
#include "b.h"

const struct i915_rev_steppings tgl_uy_revids[] = {
{ 10 },
{ 20 },
{ 30 },
{ 40 },
};

And compiler also warns if in the *definition* of tgl_uy_revids it goes
over the amount of space of the declaration. For clarity, you may
however want to add a define to tell the size:


-extern const struct i915_rev_steppings tgl_uy_revids[4];
+#define TGL_UY_REVIDS_SIZE 4
+extern const struct i915_rev_steppings tgl_uy_revids[TGL_UY_REVIDS_SIZE];

and do the same in the .c



We are anyhow going to correct the whole thing with your stepping series 
anyway. This is supposed
to be a stop gap fix. Revids shouldn't be changing for TGL anymore.



What surprised me is that this defeated the __must_be_array() check.
I thought these were just pointers to C


+#define TGL_UY_REVID_RANGE(revid) \
+ ((revid) < ARRAY_SIZE(tgl_uy_revids))
+
+#define TGL_REVID_RANGE(revid) \
+ ((revid) < ARRAY_SIZE(tgl_revids))

 static inline const struct i915_rev_steppings *
 tgl_revids_get(struct drm_i915_private *dev_priv)
 {
- if (IS_TGL_U(dev_priv) || IS_TGL_Y(dev_priv))
- return tgl_uy_revids;
- else
- return tgl_revids;
+ const u8 revid = INTEL_REVID(dev_priv);
+
+ if (IS_TGL_U(dev_priv) || IS_TGL_Y(dev_priv)) {
+ if (TGL_UY_REVID_RANGE(revid)) {
+ return tgl_uy_revids + revid;
+ } else {
+ drm_dbg_kms(&dev_priv->drm,
+ "Unsupported SOC stepping found %u, using %lu 
instead\n",
+ revid, ARRAY_SIZE(tgl_uy_revids) - 1);


Also please don't have a dbg for every single IS_TGL_*_REVID
invocation. And this is not _kms, but driver; better yet, don't bother
with a drm_dbg_kms here at all.

If you want to actually check, add something like
intel_detect_preproduction_hw() and warn about unknown future revids.
Or include the info when we print the revid in the cap

Re: [Intel-gfx] [PATCH] drm/i915/tgl: Fix REVID macros for TGL to fetch correct stepping

2020-11-25 Thread Lucas De Marchi

On Wed, Nov 25, 2020 at 09:51:04AM -0800, Aditya Swarup wrote:

On 11/25/20 7:33 AM, Chris Wilson wrote:

Quoting Jani Nikula (2020-11-25 11:45:56)

On Tue, 24 Nov 2020, Aditya Swarup  wrote:

+ if (IS_TGL_U(dev_priv) || IS_TGL_Y(dev_priv)) {
+ if (TGL_UY_REVID_RANGE(revid)) {
+ return tgl_uy_revids + revid;
+ } else {
+ drm_dbg_kms(&dev_priv->drm,
+ "Unsupported SOC stepping found %u, using %lu 
instead\n",
+ revid, ARRAY_SIZE(tgl_uy_revids) - 1);


Also please don't have a dbg for every single IS_TGL_*_REVID
invocation. And this is not _kms, but driver; better yet, don't bother
with a drm_dbg_kms here at all.

If you want to actually check, add something like
intel_detect_preproduction_hw() and warn about unknown future revids.
Or include the info when we print the revid in the caps.


So, what you are suggesting is add an info print in that function 
intel_detect_preproduction_hw() right?
Or something else?


since this is all going away soon, just removing the dbg would be ok

And in that case, just doing something like below would be shorter and
clearer IMO (untested):

if (IS_TGL_U(dev_priv) || IS_TGL_Y(dev_priv)) {
arr = tgl_uy_revids;
size = ARRAY_SIZE(tgl_uy_revids);
} else {
arr = tgl_revids;
size = ARRAY_SIZE(tgl_revids);
}

revid = min(revid, size - 1);

return &arr[revid];

That may also be 2 patches:  one adding the revid so we actually apply
the correct workarounds (this needs the "Fixes" tag) and the other to
add the bounds check.

Lucas De Marchi




-Chris




___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [PATCH] drm/i915/tgl: Fix REVID macros for TGL to fetch correct stepping

2020-11-25 Thread Aditya Swarup
On 11/25/20 11:18 AM, Lucas De Marchi wrote:
> On Wed, Nov 25, 2020 at 09:51:04AM -0800, Aditya Swarup wrote:
>> On 11/25/20 7:33 AM, Chris Wilson wrote:
>>> Quoting Jani Nikula (2020-11-25 11:45:56)
 On Tue, 24 Nov 2020, Aditya Swarup  wrote:
> Fix TGL REVID macros to fetch correct display/gt stepping based
> on SOC rev id from INTEL_REVID() macro. Previously, we were just
> returning the first element of the revid array instead of using
> the correct index based on SOC rev id.
>
> Also, add array bound checks for TGL REV ID array. Since, there
> might be a possibility of using older kernels on latest platform
> revision, resulting in out of bounds access for rev ID array.
> In this scenario, print message for unsupported rev ID and apply
> settings for latest rev ID available.
>
> Fixes: ("drm/i915/tgl: Fix stepping WA matching")
> Cc: José Roberto de Souza 
> Cc: Matt Roper 
> Cc: Lucas De Marchi 
> Cc: Jani Nikula 
> Cc: Ville Syrjälä 
> Signed-off-by: Aditya Swarup 
> ---
>  drivers/gpu/drm/i915/i915_drv.h | 35 +++--
>  1 file changed, 29 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_drv.h 
> b/drivers/gpu/drm/i915/i915_drv.h
> index 15be8debae54..29d55b7017be 100644
> --- a/drivers/gpu/drm/i915/i915_drv.h
> +++ b/drivers/gpu/drm/i915/i915_drv.h
> @@ -1572,16 +1572,37 @@ enum {
>   TGL_REVID_D0,
>  };
>
> -extern const struct i915_rev_steppings tgl_uy_revids[];
> -extern const struct i915_rev_steppings tgl_revids[];
> +extern const struct i915_rev_steppings tgl_uy_revids[4];
> +extern const struct i915_rev_steppings tgl_revids[2];

 Just a quick note, the compiler does not check that the size in the
 extern declaration matches the size in the array definition. So you
 might end up with a mismatch without noticing.
>>
>> Yes.. We will have to take care of it if we are adding rev id to array 
>> table(which mostly
>> should remain a const once we decide to go upstream). Without this 
>> declaration, I cannot
>> use ARRAY_SIZE() macro with revid arrays as the sizeof() operator complains 
>> about not
>> knowing the size of the array in question as it is an extern declaration.
>>
>> So, I don't know what other approach you want to suggest? If we move all the 
>> array tables to i915_drv.h(which
>> I feel would be a better approach rather than having it in 
>> intel_workarounds.c), Matt
>> Roper's KBL patch says that compiler complains about unused variables.
> 
> adding the table in the header means that each compilation unit (.o)
> will get a copy of the table when it includes the header (it will end up
> being trimmed out if not used though). This is not what you want.
> 
> As I said in the other reply, sizeof does actually work here:

The question is not about sizeof() not working but rather the usage of 
ARRAY_SIZE()
macro in i915_drv.h with just extern declaration without size specified.

> 
> $ cat /tmp/a.c
> #include 
> 
> #include "b.h"
> 
> int main(int argc, const char *argv[])
> {
>     printf("%zu", sizeof(tgl_uy_revids));
>     return 0;
> }
> 
> $ cat /tmp/b.h
> #pragma once
> 
> struct i915_rev_steppings { int a; };
> extern const struct i915_rev_steppings tgl_uy_revids[4];

You are specifying the size in the extern declaration which will make the 
ARRAY_SIZE()
macro work if used in the header else it will complain.

> 
> $ cat /tmp/b.c
> #include "b.h"
> 
> const struct i915_rev_steppings tgl_uy_revids[] = {
>     { 10 },
>     { 20 },
>     { 30 },
>     { 40 },
> };
> 
> And compiler also warns if in the *definition* of tgl_uy_revids it goes
> over the amount of space of the declaration. For clarity, you may
> however want to add a define to tell the size:
> 
> 
> -extern const struct i915_rev_steppings tgl_uy_revids[4];
> +#define TGL_UY_REVIDS_SIZE 4
> +extern const struct i915_rev_steppings tgl_uy_revids[TGL_UY_REVIDS_SIZE];
> 
> and do the same in the .c

I will go ahead with this approach.

Aditya 

> 
>>
>> We are anyhow going to correct the whole thing with your stepping series 
>> anyway. This is supposed
>> to be a stop gap fix. Revids shouldn't be changing for TGL anymore.
>>
>>>
>>> What surprised me is that this defeated the __must_be_array() check.
>>> I thought these were just pointers to C
>>>
> +#define TGL_UY_REVID_RANGE(revid) \
> + ((revid) < ARRAY_SIZE(tgl_uy_revids))
> +
> +#define TGL_REVID_RANGE(revid) \
> + ((revid) < ARRAY_SIZE(tgl_revids))
>
>  static inline const struct i915_rev_steppings *
>  tgl_revids_get(struct drm_i915_private *dev_priv)
>  {
> - if (IS_TGL_U(dev_priv) || IS_TGL_Y(dev_priv))
> - return tgl_uy_revids;
> - else
> - return tgl_revids;
> + const u8 rev

Re: [Intel-gfx] [PATCH] drm/i915/tgl: Fix REVID macros for TGL to fetch correct stepping

2020-11-25 Thread Aditya Swarup
On 11/25/20 11:29 AM, Lucas De Marchi wrote:
> On Wed, Nov 25, 2020 at 09:51:04AM -0800, Aditya Swarup wrote:
>> On 11/25/20 7:33 AM, Chris Wilson wrote:
>>> Quoting Jani Nikula (2020-11-25 11:45:56)
 On Tue, 24 Nov 2020, Aditya Swarup  wrote:
> + if (IS_TGL_U(dev_priv) || IS_TGL_Y(dev_priv)) {
> + if (TGL_UY_REVID_RANGE(revid)) {
> + return tgl_uy_revids + revid;
> + } else {
> + drm_dbg_kms(&dev_priv->drm,
> + "Unsupported SOC stepping found %u, 
> using %lu instead\n",
> + revid, ARRAY_SIZE(tgl_uy_revids) - 1);
>>>
>>> Also please don't have a dbg for every single IS_TGL_*_REVID
>>> invocation. And this is not _kms, but driver; better yet, don't bother
>>> with a drm_dbg_kms here at all.
>>>
>>> If you want to actually check, add something like
>>> intel_detect_preproduction_hw() and warn about unknown future revids.
>>> Or include the info when we print the revid in the caps.
>>
>> So, what you are suggesting is add an info print in that function 
>> intel_detect_preproduction_hw() right?
>> Or something else?
> 
> since this is all going away soon, just removing the dbg would be ok
> 
> And in that case, just doing something like below would be shorter and
> clearer IMO (untested):
> 
> if (IS_TGL_U(dev_priv) || IS_TGL_Y(dev_priv)) {
>     arr = tgl_uy_revids;
>     size = ARRAY_SIZE(tgl_uy_revids);
> } else {
>     arr = tgl_revids;
>     size = ARRAY_SIZE(tgl_revids);
> }
>    
> revid = min(revid, size - 1);
> 
> return &arr[revid];
> 
> That may also be 2 patches:  one adding the revid so we actually apply
> the correct workarounds (this needs the "Fixes" tag) and the other to
> add the bounds check.

Thanks for the suggestion. I will implement it this way.

Aditya

> 
> Lucas De Marchi
> 
>>
>>> -Chris
>>>
>>

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [PATCH] drm/i915/tgl: Fix REVID macros for TGL to fetch correct stepping

2020-11-25 Thread Lucas De Marchi

On Wed, Nov 25, 2020 at 11:30:44AM -0800, Aditya Swarup wrote:

As I said in the other reply, sizeof does actually work here:


The question is not about sizeof() not working but rather the usage of 
ARRAY_SIZE()
macro in i915_drv.h with just extern declaration without size specified.


ARRAY_SIZE() is just sizeof(arr)/sizeof(*arr) with additional
shenanigans to check for misuse: when used with a pointer rather than an
array:

int b[0];
int *a = b;

or

void foo(int a[10])

In these cases  ARRAY_SIZE(a) will not do what you expect and the macro
warns about it, because sizeof(a) will be sizeof(int *) instead of the
array size.






$ cat /tmp/a.c
#include 

#include "b.h"

int main(int argc, const char *argv[])
{
    printf("%zu", sizeof(tgl_uy_revids));
    return 0;
}

$ cat /tmp/b.h
#pragma once

struct i915_rev_steppings { int a; };
extern const struct i915_rev_steppings tgl_uy_revids[4];


You are specifying the size in the extern declaration which will make the 
ARRAY_SIZE()
macro work if used in the header else it will complain.


as it should

Lucas De Marchi
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


Re: [Intel-gfx] [PATCH] drm/i915/tgl: Fix REVID macros for TGL to fetch correct stepping

2020-11-25 Thread Chris Wilson
Quoting Aditya Swarup (2020-11-25 17:51:04)
> On 11/25/20 7:33 AM, Chris Wilson wrote:
> > Quoting Jani Nikula (2020-11-25 11:45:56)
> >> On Tue, 24 Nov 2020, Aditya Swarup  wrote:
> >>>  static inline const struct i915_rev_steppings *
> >>>  tgl_revids_get(struct drm_i915_private *dev_priv)
> >>>  {
> >>> - if (IS_TGL_U(dev_priv) || IS_TGL_Y(dev_priv))
> >>> - return tgl_uy_revids;
> >>> - else
> >>> - return tgl_revids;
> >>> + const u8 revid = INTEL_REVID(dev_priv);
> >>> +
> >>> + if (IS_TGL_U(dev_priv) || IS_TGL_Y(dev_priv)) {
> >>> + if (TGL_UY_REVID_RANGE(revid)) {
> >>> + return tgl_uy_revids + revid;
> >>> + } else {
> >>> + drm_dbg_kms(&dev_priv->drm,
> >>> + "Unsupported SOC stepping found %u, 
> >>> using %lu instead\n",
> >>> + revid, ARRAY_SIZE(tgl_uy_revids) - 1);
> > 
> > Also please don't have a dbg for every single IS_TGL_*_REVID
> > invocation. And this is not _kms, but driver; better yet, don't bother
> > with a drm_dbg_kms here at all.
> > 
> > If you want to actually check, add something like
> > intel_detect_preproduction_hw() and warn about unknown future revids.
> > Or include the info when we print the revid in the caps.
> 
> So, what you are suggesting is add an info print in that function 
> intel_detect_preproduction_hw() right?
> Or something else?

I wouldn't put it in detect_preproduction, just using that as an example
of when we do probes for unexpected revids. E.g.,

diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
index ca16ea541ecc..f1ff5509c23a 100644
--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -273,6 +273,21 @@ static void intel_detect_preproduction_hw(struct 
drm_i915_private *dev_priv)
}
 }

+/*
+ * HW that is more recent than the kernel runs the risk of us applying
+ * stale and disruptive w/a. Leave a debug tell-tale just in case.
+ */
+static void intel_detect_unknown_hw(struct drm_i915_private *dev_priv)
+{
+   bool post = false;
+
+   if (post) {
+   drm_dbg(&dev_priv->drm,
+   "This machine is more recent than the w/a database!\n");
+   add_taint(TAINT_MACHINE_CHECK, LOCKDEP_STILL_OK);
+   }
+}
+
 static void sanitize_gpu(struct drm_i915_private *i915)
 {
if (!INTEL_INFO(i915)->gpu_reset_clobbers_display)
@@ -343,6 +358,7 @@ static int i915_driver_early_probe(struct drm_i915_private 
*dev_priv)
intel_init_audio_hooks(dev_priv);

intel_detect_preproduction_hw(dev_priv);
+   intel_detect_unknown_hw(dev_priv);

return 0;


The taint is probably not justified in this case.
-Chris
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx