Re: [PATCH v8 1/2] drm/i915: preparation for using PAT index

2023-06-27 Thread Yang, Fei
> On 27/06/2023 14:28, Jani Nikula wrote:
>> On Tue, 09 May 2023, fei.y...@intel.com wrote:
>>> From: Fei Yang 
>>>
>>> This patch is a preparation for replacing enum i915_cache_level with
>>> PAT index. Caching policy for buffer objects is set through the PAT
>>> index in PTE, the old i915_cache_level is not sufficient to represent
>>> all caching modes supported by the hardware.
>>>
>>> Preparing the transition by adding some platform dependent data
>>> structures and helper functions to translate the cache_level to pat_index.
>>>
>>> cachelevel_to_pat: a platform dependent array mapping cache_level to
>>> pat_index.
>>>
>>> max_pat_index: the maximum PAT index recommended in hardware specification
>>> Needed for validating the PAT index passed in from user
>>> space.
>>>
>>> i915_gem_get_pat_index: function to convert cache_level to PAT index.
>>>
>>> obj_to_i915(obj): macro moved to header file for wider usage.
>>>
>>> I915_MAX_CACHE_LEVEL: upper bound of i915_cache_level for the
>>>convenience of coding.
>>>
>>> Cc: Chris Wilson 
>>> Cc: Matt Roper 
>>> Signed-off-by: Fei Yang 
>>> Reviewed-by: Andi Shyti 
>>> Reviewed-by: Andrzej Hajda 
>>
>> [snip]
>>
>>> diff --git a/drivers/gpu/drm/i915/selftests/mock_gem_device.c
>>> b/drivers/gpu/drm/i915/selftests/mock_gem_device.c
>>> index f6a7c0bd2955..0eda8b4ee17f 100644
>>> --- a/drivers/gpu/drm/i915/selftests/mock_gem_device.c
>>> +++ b/drivers/gpu/drm/i915/selftests/mock_gem_device.c
>>> @@ -123,7 +123,9 @@ struct drm_i915_private *mock_gem_device(void)
>>> static struct dev_iommu fake_iommu = { .priv = (void *)-1 };
>>>   #endif
>>> struct drm_i915_private *i915;
>>> +   struct intel_device_info *i915_info;
>>> struct pci_dev *pdev;
>>> +   unsigned int i;
>>> int ret;
>>>
>>> pdev = kzalloc(sizeof(*pdev), GFP_KERNEL); @@ -180,6 +182,13 @@
>>> struct drm_i915_private *mock_gem_device(void)
>>> I915_GTT_PAGE_SIZE_2M;
>>>
>>> RUNTIME_INFO(i915)->memory_regions = REGION_SMEM;
>>> +
>>> +   /* simply use legacy cache level for mock device */
>>> +   i915_info = (struct intel_device_info *)INTEL_INFO(i915);
>>
>> This is not okay. It's not okay to modify device info at runtime. This
>> is why we've separated runtime info from device info. This is why
>> we've made device info const, and localized the modifications to a
>> couple of places.
>>
>> If you need to modify it, it belongs in runtime info. Even if it's
>> only ever modified for mock devices.
>>
>> We were at the brink of being able to finally convert INTEL_INFO()
>> into a pointer to const rodata [1], where you are unable to modify it,
>> but this having been merged as commit 5e352e32aec2 ("drm/i915:
>> preparation for using PAT index") sets us back. (With [1] this oopses
>> trying to modify read-only data.)
>>
>> This has been posted to the public list 20+ times, and nobody noticed
>> or pointed this out?!
>>
>> Throwing away const should be a huge red flag to any developer or
>> reviewer. Hell, *any* cast should be.
>>
>> I've got a patch ready moving cachelevel_to_pat and max_pat_index to
>> runtime info. It's not great, since we'd be doing it only for the mock
>> device. Better ideas? I'm not waiting long.
>>
>>
>> BR,
>> Jani.
>>
>>
>> [1]
>> https://patchwork.freedesktop.org/patch/msgid/0badc36ce6dd6b030507bdfd
>> 8a42ab984fb38d12.1686236840.git.jani.nik...@intel.com
>>
>>
>>> +   i915_info->max_pat_index = 3;
>>> +   for (i = 0; i < I915_MAX_CACHE_LEVEL; i++)
>>> +   i915_info->cachelevel_to_pat[i] = i;
>>> +
>
> I'd simply suggest having a local static const table for the mock device.
> It should be trivial once i915->__info becomes a pointer so in that series
> I guess.
>
> While I am here - Fei - any plans to work on the promised cleanup?
> Abstracting the caching modes with a hw agnostic sw/driver representation,
> if you remember what we discussed.

Yes, I'm still working on that as a side task. Hopefully I would be able to
post something to the mailing list after the July 4th holiday.

> Regards,
>
> Tvrtko



Re: [PATCH v8 1/2] drm/i915: preparation for using PAT index

2023-06-27 Thread Yang, Fei
> Hi Jani and Tvrtko,
>
 This patch is a preparation for replacing enum i915_cache_level with PAT
 index. Caching policy for buffer objects is set through the PAT index in
 PTE, the old i915_cache_level is not sufficient to represent all caching
 modes supported by the hardware.

 Preparing the transition by adding some platform dependent data structures
 and helper functions to translate the cache_level to pat_index.

 cachelevel_to_pat: a platform dependent array mapping cache_level to
 pat_index.

 max_pat_index: the maximum PAT index recommended in hardware specification
 Needed for validating the PAT index passed in from user
 space.

 i915_gem_get_pat_index: function to convert cache_level to PAT index.

 obj_to_i915(obj): macro moved to header file for wider usage.

 I915_MAX_CACHE_LEVEL: upper bound of i915_cache_level for the
convenience of coding.

 Cc: Chris Wilson 
 Cc: Matt Roper 
 Signed-off-by: Fei Yang 
 Reviewed-by: Andi Shyti 
 Reviewed-by: Andrzej Hajda 
>>>
>>> [snip]
>>>
 diff --git a/drivers/gpu/drm/i915/selftests/mock_gem_device.c 
 b/drivers/gpu/drm/i915/selftests/mock_gem_device.c
 index f6a7c0bd2955..0eda8b4ee17f 100644
 --- a/drivers/gpu/drm/i915/selftests/mock_gem_device.c
 +++ b/drivers/gpu/drm/i915/selftests/mock_gem_device.c
 @@ -123,7 +123,9 @@ struct drm_i915_private *mock_gem_device(void)
static struct dev_iommu fake_iommu = { .priv = (void *)-1 };
   #endif
struct drm_i915_private *i915;
 + struct intel_device_info *i915_info;
struct pci_dev *pdev;
 + unsigned int i;
int ret;
pdev = kzalloc(sizeof(*pdev), GFP_KERNEL);
 @@ -180,6 +182,13 @@ struct drm_i915_private *mock_gem_device(void)
I915_GTT_PAGE_SIZE_2M;
RUNTIME_INFO(i915)->memory_regions = REGION_SMEM;
 +
 + /* simply use legacy cache level for mock device */
 + i915_info = (struct intel_device_info *)INTEL_INFO(i915);
>>>
>>> This is not okay. It's not okay to modify device info at runtime. This
>>> is why we've separated runtime info from device info. This is why we've
>>> made device info const, and localized the modifications to a couple of
>>> places.
>>>
>>> If you need to modify it, it belongs in runtime info. Even if it's only
>>> ever modified for mock devices.
>>>
>>> We were at the brink of being able to finally convert INTEL_INFO() into
>>> a pointer to const rodata [1], where you are unable to modify it, but
>>> this having been merged as commit 5e352e32aec2 ("drm/i915: preparation
>>> for using PAT index") sets us back. (With [1] this oopses trying to
>>> modify read-only data.)
>>>
>>> This has been posted to the public list 20+ times, and nobody noticed or
>>> pointed this out?!
>
> That's not cool, indeed.
>
>>> Throwing away const should be a huge red flag to any developer or
>>> reviewer. Hell, *any* cast should be.
>>>
>>> I've got a patch ready moving cachelevel_to_pat and max_pat_index to
>>> runtime info. It's not great, since we'd be doing it only for the mock
>>> device. Better ideas? I'm not waiting long.
>>>
>>>
>>> BR,
>>> Jani.
>>>
>>>
>>> [1] 
>>> https://patchwork.freedesktop.org/patch/msgid/0badc36ce6dd6b030507bdfd8a42ab984fb38d12.1686236840.git.jani.nik...@intel.com
>>>
>>>
 + i915_info->max_pat_index = 3;
 + for (i = 0; i < I915_MAX_CACHE_LEVEL; i++)
 + i915_info->cachelevel_to_pat[i] = i;
 +
>>
>> I'd simply suggest having a local static const table for the mock device. It
>> should be trivial once i915->__info becomes a pointer so in that series I
>> guess.
>
> Fei... do you have bandwidth to look into this or do you want me
> to try Tvrtko's suggestion out?

Please go ahead Andi if you have time to help on this.

> Thank you Jani for reporting it and thank you Tvrtko for
> proposing the fix.

Sorry for the trouble here.

> Andi



Re: [PATCH v8 1/2] drm/i915: preparation for using PAT index

2023-06-27 Thread Jani Nikula
On Tue, 27 Jun 2023, Andi Shyti  wrote:
> Tvrtko wrote:
>> I'd simply suggest having a local static const table for the mock device. It
>> should be trivial once i915->__info becomes a pointer so in that series I
>> guess.

That's a great idea, thanks!

> Fei... do you have bandwidth to look into this or do you want me
> to try Tvrtko's suggestion out?

https://patchwork.freedesktop.org/patch/msgid/b0db62045a96a3fd4cf123685da88cc777f9b485.1687878757.git.jani.nik...@intel.com


BR,
Jani.

-- 
Jani Nikula, Intel Open Source Graphics Center


Re: [PATCH v8 1/2] drm/i915: preparation for using PAT index

2023-06-27 Thread Andi Shyti
Hi Jani and Tvrtko,

> > > This patch is a preparation for replacing enum i915_cache_level with PAT
> > > index. Caching policy for buffer objects is set through the PAT index in
> > > PTE, the old i915_cache_level is not sufficient to represent all caching
> > > modes supported by the hardware.
> > > 
> > > Preparing the transition by adding some platform dependent data structures
> > > and helper functions to translate the cache_level to pat_index.
> > > 
> > > cachelevel_to_pat: a platform dependent array mapping cache_level to
> > > pat_index.
> > > 
> > > max_pat_index: the maximum PAT index recommended in hardware specification
> > > Needed for validating the PAT index passed in from user
> > > space.
> > > 
> > > i915_gem_get_pat_index: function to convert cache_level to PAT index.
> > > 
> > > obj_to_i915(obj): macro moved to header file for wider usage.
> > > 
> > > I915_MAX_CACHE_LEVEL: upper bound of i915_cache_level for the
> > >convenience of coding.
> > > 
> > > Cc: Chris Wilson 
> > > Cc: Matt Roper 
> > > Signed-off-by: Fei Yang 
> > > Reviewed-by: Andi Shyti 
> > > Reviewed-by: Andrzej Hajda 
> > 
> > [snip]
> > 
> > > diff --git a/drivers/gpu/drm/i915/selftests/mock_gem_device.c 
> > > b/drivers/gpu/drm/i915/selftests/mock_gem_device.c
> > > index f6a7c0bd2955..0eda8b4ee17f 100644
> > > --- a/drivers/gpu/drm/i915/selftests/mock_gem_device.c
> > > +++ b/drivers/gpu/drm/i915/selftests/mock_gem_device.c
> > > @@ -123,7 +123,9 @@ struct drm_i915_private *mock_gem_device(void)
> > >   static struct dev_iommu fake_iommu = { .priv = (void *)-1 };
> > >   #endif
> > >   struct drm_i915_private *i915;
> > > + struct intel_device_info *i915_info;
> > >   struct pci_dev *pdev;
> > > + unsigned int i;
> > >   int ret;
> > >   pdev = kzalloc(sizeof(*pdev), GFP_KERNEL);
> > > @@ -180,6 +182,13 @@ struct drm_i915_private *mock_gem_device(void)
> > >   I915_GTT_PAGE_SIZE_2M;
> > >   RUNTIME_INFO(i915)->memory_regions = REGION_SMEM;
> > > +
> > > + /* simply use legacy cache level for mock device */
> > > + i915_info = (struct intel_device_info *)INTEL_INFO(i915);
> > 
> > This is not okay. It's not okay to modify device info at runtime. This
> > is why we've separated runtime info from device info. This is why we've
> > made device info const, and localized the modifications to a couple of
> > places.
> > 
> > If you need to modify it, it belongs in runtime info. Even if it's only
> > ever modified for mock devices.
> > 
> > We were at the brink of being able to finally convert INTEL_INFO() into
> > a pointer to const rodata [1], where you are unable to modify it, but
> > this having been merged as commit 5e352e32aec2 ("drm/i915: preparation
> > for using PAT index") sets us back. (With [1] this oopses trying to
> > modify read-only data.)
> > 
> > This has been posted to the public list 20+ times, and nobody noticed or
> > pointed this out?!

That's not cool, indeed.

> > Throwing away const should be a huge red flag to any developer or
> > reviewer. Hell, *any* cast should be.
> > 
> > I've got a patch ready moving cachelevel_to_pat and max_pat_index to
> > runtime info. It's not great, since we'd be doing it only for the mock
> > device. Better ideas? I'm not waiting long.
> > 
> > 
> > BR,
> > Jani.
> > 
> > 
> > [1] 
> > https://patchwork.freedesktop.org/patch/msgid/0badc36ce6dd6b030507bdfd8a42ab984fb38d12.1686236840.git.jani.nik...@intel.com
> > 
> > 
> > > + i915_info->max_pat_index = 3;
> > > + for (i = 0; i < I915_MAX_CACHE_LEVEL; i++)
> > > + i915_info->cachelevel_to_pat[i] = i;
> > > +
> 
> I'd simply suggest having a local static const table for the mock device. It
> should be trivial once i915->__info becomes a pointer so in that series I
> guess.

Fei... do you have bandwidth to look into this or do you want me
to try Tvrtko's suggestion out?

Thank you Jani for reporting it and thank you Tvrtko for
proposing the fix.

Andi


Re: [PATCH v8 1/2] drm/i915: preparation for using PAT index

2023-06-27 Thread Tvrtko Ursulin



On 27/06/2023 14:28, Jani Nikula wrote:

On Tue, 09 May 2023, fei.y...@intel.com wrote:

From: Fei Yang 

This patch is a preparation for replacing enum i915_cache_level with PAT
index. Caching policy for buffer objects is set through the PAT index in
PTE, the old i915_cache_level is not sufficient to represent all caching
modes supported by the hardware.

Preparing the transition by adding some platform dependent data structures
and helper functions to translate the cache_level to pat_index.

cachelevel_to_pat: a platform dependent array mapping cache_level to
pat_index.

max_pat_index: the maximum PAT index recommended in hardware specification
Needed for validating the PAT index passed in from user
space.

i915_gem_get_pat_index: function to convert cache_level to PAT index.

obj_to_i915(obj): macro moved to header file for wider usage.

I915_MAX_CACHE_LEVEL: upper bound of i915_cache_level for the
   convenience of coding.

Cc: Chris Wilson 
Cc: Matt Roper 
Signed-off-by: Fei Yang 
Reviewed-by: Andi Shyti 
Reviewed-by: Andrzej Hajda 


[snip]


diff --git a/drivers/gpu/drm/i915/selftests/mock_gem_device.c 
b/drivers/gpu/drm/i915/selftests/mock_gem_device.c
index f6a7c0bd2955..0eda8b4ee17f 100644
--- a/drivers/gpu/drm/i915/selftests/mock_gem_device.c
+++ b/drivers/gpu/drm/i915/selftests/mock_gem_device.c
@@ -123,7 +123,9 @@ struct drm_i915_private *mock_gem_device(void)
static struct dev_iommu fake_iommu = { .priv = (void *)-1 };
  #endif
struct drm_i915_private *i915;
+   struct intel_device_info *i915_info;
struct pci_dev *pdev;
+   unsigned int i;
int ret;
  
  	pdev = kzalloc(sizeof(*pdev), GFP_KERNEL);

@@ -180,6 +182,13 @@ struct drm_i915_private *mock_gem_device(void)
I915_GTT_PAGE_SIZE_2M;
  
  	RUNTIME_INFO(i915)->memory_regions = REGION_SMEM;

+
+   /* simply use legacy cache level for mock device */
+   i915_info = (struct intel_device_info *)INTEL_INFO(i915);


This is not okay. It's not okay to modify device info at runtime. This
is why we've separated runtime info from device info. This is why we've
made device info const, and localized the modifications to a couple of
places.

If you need to modify it, it belongs in runtime info. Even if it's only
ever modified for mock devices.

We were at the brink of being able to finally convert INTEL_INFO() into
a pointer to const rodata [1], where you are unable to modify it, but
this having been merged as commit 5e352e32aec2 ("drm/i915: preparation
for using PAT index") sets us back. (With [1] this oopses trying to
modify read-only data.)

This has been posted to the public list 20+ times, and nobody noticed or
pointed this out?!

Throwing away const should be a huge red flag to any developer or
reviewer. Hell, *any* cast should be.

I've got a patch ready moving cachelevel_to_pat and max_pat_index to
runtime info. It's not great, since we'd be doing it only for the mock
device. Better ideas? I'm not waiting long.


BR,
Jani.


[1] 
https://patchwork.freedesktop.org/patch/msgid/0badc36ce6dd6b030507bdfd8a42ab984fb38d12.1686236840.git.jani.nik...@intel.com



+   i915_info->max_pat_index = 3;
+   for (i = 0; i < I915_MAX_CACHE_LEVEL; i++)
+   i915_info->cachelevel_to_pat[i] = i;
+


I'd simply suggest having a local static const table for the mock 
device. It should be trivial once i915->__info becomes a pointer so in 
that series I guess.


While I am here - Fei - any plans to work on the promised cleanup? 
Abstracting the caching modes with a hw agnostic sw/driver 
representation, if you remember what we discussed.


Regards,

Tvrtko


Re: [PATCH v8 1/2] drm/i915: preparation for using PAT index

2023-06-27 Thread Jani Nikula
On Tue, 09 May 2023, fei.y...@intel.com wrote:
> From: Fei Yang 
>
> This patch is a preparation for replacing enum i915_cache_level with PAT
> index. Caching policy for buffer objects is set through the PAT index in
> PTE, the old i915_cache_level is not sufficient to represent all caching
> modes supported by the hardware.
>
> Preparing the transition by adding some platform dependent data structures
> and helper functions to translate the cache_level to pat_index.
>
> cachelevel_to_pat: a platform dependent array mapping cache_level to
>pat_index.
>
> max_pat_index: the maximum PAT index recommended in hardware specification
>Needed for validating the PAT index passed in from user
>space.
>
> i915_gem_get_pat_index: function to convert cache_level to PAT index.
>
> obj_to_i915(obj): macro moved to header file for wider usage.
>
> I915_MAX_CACHE_LEVEL: upper bound of i915_cache_level for the
>   convenience of coding.
>
> Cc: Chris Wilson 
> Cc: Matt Roper 
> Signed-off-by: Fei Yang 
> Reviewed-by: Andi Shyti 
> Reviewed-by: Andrzej Hajda 

[snip]

> diff --git a/drivers/gpu/drm/i915/selftests/mock_gem_device.c 
> b/drivers/gpu/drm/i915/selftests/mock_gem_device.c
> index f6a7c0bd2955..0eda8b4ee17f 100644
> --- a/drivers/gpu/drm/i915/selftests/mock_gem_device.c
> +++ b/drivers/gpu/drm/i915/selftests/mock_gem_device.c
> @@ -123,7 +123,9 @@ struct drm_i915_private *mock_gem_device(void)
>   static struct dev_iommu fake_iommu = { .priv = (void *)-1 };
>  #endif
>   struct drm_i915_private *i915;
> + struct intel_device_info *i915_info;
>   struct pci_dev *pdev;
> + unsigned int i;
>   int ret;
>  
>   pdev = kzalloc(sizeof(*pdev), GFP_KERNEL);
> @@ -180,6 +182,13 @@ struct drm_i915_private *mock_gem_device(void)
>   I915_GTT_PAGE_SIZE_2M;
>  
>   RUNTIME_INFO(i915)->memory_regions = REGION_SMEM;
> +
> + /* simply use legacy cache level for mock device */
> + i915_info = (struct intel_device_info *)INTEL_INFO(i915);

This is not okay. It's not okay to modify device info at runtime. This
is why we've separated runtime info from device info. This is why we've
made device info const, and localized the modifications to a couple of
places.

If you need to modify it, it belongs in runtime info. Even if it's only
ever modified for mock devices.

We were at the brink of being able to finally convert INTEL_INFO() into
a pointer to const rodata [1], where you are unable to modify it, but
this having been merged as commit 5e352e32aec2 ("drm/i915: preparation
for using PAT index") sets us back. (With [1] this oopses trying to
modify read-only data.)

This has been posted to the public list 20+ times, and nobody noticed or
pointed this out?!

Throwing away const should be a huge red flag to any developer or
reviewer. Hell, *any* cast should be.

I've got a patch ready moving cachelevel_to_pat and max_pat_index to
runtime info. It's not great, since we'd be doing it only for the mock
device. Better ideas? I'm not waiting long.


BR,
Jani.


[1] 
https://patchwork.freedesktop.org/patch/msgid/0badc36ce6dd6b030507bdfd8a42ab984fb38d12.1686236840.git.jani.nik...@intel.com


> + i915_info->max_pat_index = 3;
> + for (i = 0; i < I915_MAX_CACHE_LEVEL; i++)
> + i915_info->cachelevel_to_pat[i] = i;
> +
>   intel_memory_regions_hw_probe(i915);
>  
>   spin_lock_init(>gpu_error.lock);

-- 
Jani Nikula, Intel Open Source Graphics Center


[PATCH v8 1/2] drm/i915: preparation for using PAT index

2023-05-09 Thread fei . yang
From: Fei Yang 

This patch is a preparation for replacing enum i915_cache_level with PAT
index. Caching policy for buffer objects is set through the PAT index in
PTE, the old i915_cache_level is not sufficient to represent all caching
modes supported by the hardware.

Preparing the transition by adding some platform dependent data structures
and helper functions to translate the cache_level to pat_index.

cachelevel_to_pat: a platform dependent array mapping cache_level to
   pat_index.

max_pat_index: the maximum PAT index recommended in hardware specification
   Needed for validating the PAT index passed in from user
   space.

i915_gem_get_pat_index: function to convert cache_level to PAT index.

obj_to_i915(obj): macro moved to header file for wider usage.

I915_MAX_CACHE_LEVEL: upper bound of i915_cache_level for the
  convenience of coding.

Cc: Chris Wilson 
Cc: Matt Roper 
Signed-off-by: Fei Yang 
Reviewed-by: Andi Shyti 
Reviewed-by: Andrzej Hajda 
---
 drivers/gpu/drm/i915/gem/i915_gem_object.c|  9 +++
 drivers/gpu/drm/i915/gem/i915_gem_object.h|  4 +
 .../gpu/drm/i915/gem/i915_gem_object_types.h  |  7 ++
 drivers/gpu/drm/i915/gem/i915_gem_shrinker.c  |  2 -
 drivers/gpu/drm/i915/gt/gen8_ppgtt.c  |  6 ++
 drivers/gpu/drm/i915/gt/intel_ggtt.c  |  6 ++
 drivers/gpu/drm/i915/i915_pci.c   | 79 ---
 drivers/gpu/drm/i915/intel_device_info.h  |  5 ++
 .../gpu/drm/i915/selftests/mock_gem_device.c  |  9 +++
 9 files changed, 116 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/i915/gem/i915_gem_object.c 
b/drivers/gpu/drm/i915/gem/i915_gem_object.c
index 4666bb82f312..8c70a0ec7d2f 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_object.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_object.c
@@ -45,6 +45,15 @@ static struct kmem_cache *slab_objects;
 
 static const struct drm_gem_object_funcs i915_gem_object_funcs;
 
+unsigned int i915_gem_get_pat_index(struct drm_i915_private *i915,
+   enum i915_cache_level level)
+{
+   if (drm_WARN_ON(>drm, level >= I915_MAX_CACHE_LEVEL))
+   return 0;
+
+   return INTEL_INFO(i915)->cachelevel_to_pat[level];
+}
+
 struct drm_i915_gem_object *i915_gem_object_alloc(void)
 {
struct drm_i915_gem_object *obj;
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_object.h 
b/drivers/gpu/drm/i915/gem/i915_gem_object.h
index bc1291887d4f..284e1aa396cd 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_object.h
+++ b/drivers/gpu/drm/i915/gem/i915_gem_object.h
@@ -20,6 +20,8 @@
 
 enum intel_region_id;
 
+#define obj_to_i915(obj__) to_i915((obj__)->base.dev)
+
 static inline bool i915_gem_object_size_2big(u64 size)
 {
struct drm_i915_gem_object *obj;
@@ -30,6 +32,8 @@ static inline bool i915_gem_object_size_2big(u64 size)
return false;
 }
 
+unsigned int i915_gem_get_pat_index(struct drm_i915_private *i915,
+   enum i915_cache_level level);
 void i915_gem_init__objects(struct drm_i915_private *i915);
 
 void i915_objects_module_exit(void);
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_object_types.h 
b/drivers/gpu/drm/i915/gem/i915_gem_object_types.h
index 830c11431ee8..bf0bd8e11355 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_object_types.h
+++ b/drivers/gpu/drm/i915/gem/i915_gem_object_types.h
@@ -194,6 +194,13 @@ enum i915_cache_level {
 * engine.
 */
I915_CACHE_WT,
+   /**
+* @I915_MAX_CACHE_LEVEL:
+*
+* Mark the last entry in the enum. Used for defining cachelevel_to_pat
+* array for cache_level to pat translation table.
+*/
+   I915_MAX_CACHE_LEVEL,
 };
 
 enum i915_map_type {
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_shrinker.c 
b/drivers/gpu/drm/i915/gem/i915_gem_shrinker.c
index b1672e054b21..214763942aa2 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_shrinker.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_shrinker.c
@@ -460,8 +460,6 @@ void i915_gem_shrinker_taints_mutex(struct drm_i915_private 
*i915,
fs_reclaim_release(GFP_KERNEL);
 }
 
-#define obj_to_i915(obj__) to_i915((obj__)->base.dev)
-
 /**
  * i915_gem_object_make_unshrinkable - Hide the object from the shrinker. By
  * default all object types that support shrinking(see IS_SHRINKABLE), will 
also
diff --git a/drivers/gpu/drm/i915/gt/gen8_ppgtt.c 
b/drivers/gpu/drm/i915/gt/gen8_ppgtt.c
index 22ec1566d2a7..bb6998d67133 100644
--- a/drivers/gpu/drm/i915/gt/gen8_ppgtt.c
+++ b/drivers/gpu/drm/i915/gt/gen8_ppgtt.c
@@ -78,6 +78,12 @@ static u64 mtl_pte_encode(dma_addr_t addr,
case I915_CACHE_WT:
pte |= GEN12_PPGTT_PTE_PAT0;
break;
+   default:
+   /* This should never happen. Added to deal with the compile
+* error due to the addition of I915_MAX_CACHE_LEVEL. Will
+* be removed by the pat_index patch.
+*/
+