<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof ContentPasted0 ContentPasted1">
> On 12/05/2023 18:51, fei.yang@intel.com wrote:
<div class="ContentPasted0">>> From: Fei Yang <fei.yang@intel.com></div>
<div class="ContentPasted0">>></div>
<div class="ContentPasted0">>> Gem_create uAPI has been extended with capability of setting PAT index.</div>
<div class="ContentPasted0">>> Add a test case to exercise this new extension.</div>
<div class="ContentPasted0">>></div>
<div class="ContentPasted0">>> Signed-off-by: Fei Yang <fei.yang@intel.com></div>
<div class="ContentPasted0">>> ---</div>
<div class="ContentPasted0">>> lib/i915/i915_drm_local.h | 34 ++++++++++++++++++++++++++++++</div>
<div class="ContentPasted0">>> tests/i915/gem_create.c | 44 +++++++++++++++++++++++++++++++++++++++</div>
<div class="ContentPasted0">>> 2 files changed, 78 insertions(+)</div>
<div class="ContentPasted0">>></div>
<div class="ContentPasted0">>> diff --git a/lib/i915/i915_drm_local.h b/lib/i915/i915_drm_local.h</div>
<div class="ContentPasted0">>> index af017650..35929a0c 100644</div>
<div class="ContentPasted0">>> --- a/lib/i915/i915_drm_local.h</div>
<div class="ContentPasted0">>> +++ b/lib/i915/i915_drm_local.h</div>
<div class="ContentPasted0">>> @@ -26,6 +26,40 @@ extern "C" {</div>
<div class="ContentPasted0">>> #define DRM_I915_PERF_PROP_OA_ENGINE_CLASS 9</div>
<div class="ContentPasted0">>> #define DRM_I915_PERF_PROP_OA_ENGINE_INSTANCE 10</div>
<div class="ContentPasted0">>></div>
<div class="ContentPasted0">>> +#define I915_GEM_CREATE_EXT_SET_PAT 2</div>
<div class="ContentPasted0">>> +</div>
<div class="ContentPasted0">>> +/**</div>
<div class="ContentPasted0">>> + * struct drm_i915_gem_create_ext_set_pat - The</div>
<div class="ContentPasted0">>> + * I915_GEM_CREATE_EXT_SET_PAT extension.</div>
<div class="ContentPasted0">>> + *</div>
<div class="ContentPasted0">>> + * If this extension is provided, the specified caching policy (PAT</div>
<div class="ContentPasted0">>> +index) is</div>
<div class="ContentPasted0">>> + * applied to the buffer object.</div>
<div class="ContentPasted0">>> + *</div>
<div class="ContentPasted0">>> + * Below is an example on how to create an object with specific caching policy:</div>
<div class="ContentPasted0">>> + *</div>
<div class="ContentPasted0">>> + * .. code-block:: C</div>
<div class="ContentPasted0">>> + *</div>
<div class="ContentPasted0">>> + * struct drm_i915_gem_create_ext_set_pat set_pat_ext = {</div>
<div class="ContentPasted0">>> + * .base = { .name = I915_GEM_CREATE_EXT_SET_PAT },</div>
<div class="ContentPasted0">>> + * .pat_index = 0,</div>
<div class="ContentPasted0">>> + * };</div>
<div class="ContentPasted0">>> + * struct drm_i915_gem_create_ext create_ext = {</div>
<div class="ContentPasted0">>> + * .size = PAGE_SIZE,</div>
<div class="ContentPasted0">>> + * .extensions = (uintptr_t)&set_pat_ext,</div>
>> + * };
<div class="ContentPasted1">>> + *</div>
<div class="ContentPasted1">>> + * int err = ioctl(fd, DRM_IOCTL_I915_GEM_CREATE_EXT, &create_ext);</div>
<div class="ContentPasted1">>> + * if (err) ...</div>
<div class="ContentPasted1">>> + */</div>
<div class="ContentPasted1">>> +struct drm_i915_gem_create_ext_set_pat {</div>
<div class="ContentPasted1">>> + /** @base: Extension link. See struct i915_user_extension. */</div>
<div class="ContentPasted1">>> + struct i915_user_extension base;</div>
<div class="ContentPasted1">>> + /** @pat_index: PAT index to be set */</div>
<div class="ContentPasted1">>> + __u32 pat_index;</div>
<div class="ContentPasted1">>> + /** @rsvd: reserved for future use */</div>
<div class="ContentPasted1">>> + __u32 rsvd;</div>
<div class="ContentPasted1">>> +};</div>
<div class="ContentPasted1">>> +</div>
<div class="ContentPasted1">>> #if defined(__cplusplus)</div>
<div class="ContentPasted1">>> }</div>
<div class="ContentPasted1">>> #endif</div>
<div class="ContentPasted1">>> diff --git a/tests/i915/gem_create.c b/tests/i915/gem_create.c index</div>
<div class="ContentPasted1">>> c719ab6c..20c71afb 100644</div>
<div class="ContentPasted1">>> --- a/tests/i915/gem_create.c</div>
<div class="ContentPasted1">>> +++ b/tests/i915/gem_create.c</div>
<div class="ContentPasted1">>> @@ -537,6 +537,45 @@ static void create_ext_placement_each(int fd)</div>
<div class="ContentPasted1">>> free(regions);</div>
<div class="ContentPasted1">>> }</div>
<div class="ContentPasted1">>></div>
<div class="ContentPasted1">>> +static void create_ext_set_pat(int fd) {</div>
<div class="ContentPasted1">>> + struct drm_i915_gem_create_ext_set_pat setparam_pat = {</div>
<div class="ContentPasted1">>> + .base = { .name = I915_GEM_CREATE_EXT_SET_PAT },</div>
<div class="ContentPasted1">>> + .pat_index = 0,</div>
<div class="ContentPasted1">>> + };</div>
<div class="ContentPasted1">>> + struct drm_i915_gem_create_ext_set_pat setparam_inv_pat = {</div>
<div class="ContentPasted1">>> + .base = { .name = I915_GEM_CREATE_EXT_SET_PAT },</div>
<div class="ContentPasted1">>> + .pat_index = 65,</div>
<div class="ContentPasted1">>> + };</div>
<div class="ContentPasted1">>> + struct drm_i915_gem_caching arg;</div>
<div class="ContentPasted1">>> + uint64_t size;</div>
<div class="ContentPasted1">>> + uint32_t handle;</div>
<div class="ContentPasted1">>> + int ret;</div>
<div class="ContentPasted1">>> +</div>
<div class="ContentPasted1">>> + size = PAGE_SIZE;</div>
<div class="ContentPasted1">>> +</div>
<div class="ContentPasted1 ContentPasted2 ContentPasted3">>> + ret = __gem_create_ext(fd, &size, 0, &handle, &setparam_pat.base);
<div class="ContentPasted2">>> +</div>
<div class="ContentPasted2">>> + /* Returning -EFAULT indicates set_pat extension is not supported */</div>
<div class="ContentPasted2">>> + if (ret == -EFAULT)</div>
<div class="ContentPasted2">>> + igt_info("I915_GEM_CREATE_EXT_SET_PAT is not supported\n");</div>
<div class="ContentPasted2">></div>
<div class="ContentPasted2">> Is this correct? EFAULT should be data access issues while unsupported extensions should be EINVAL.</div>
<div><br class="ContentPasted2">
</div>
<div class="ContentPasted2">Wil correct.</div>
<div><br class="ContentPasted2">
</div>
<div class="ContentPasted2">>> + igt_assert(ret == 0);</div>
<div class="ContentPasted2">></div>
<div class="ContentPasted2">> Extension not supported should be a skip I would say.</div>
<div><br class="ContentPasted2">
</div>
<div class="ContentPasted2">Will replace igt_info with igt_skip.</div>
<div><br class="ContentPasted2">
</div>
<div class="ContentPasted2">> EFAULT test is then something else, ie. hitting this path from the kernel ioctl handler:</div>
<div class="ContentPasted2">></div>
<div class="ContentPasted2">> ext_set_pat()</div>
<div class="ContentPasted2">> ...</div>
<div class="ContentPasted2">> + if (copy_from_user(&ext, base, sizeof(ext)))</div>
<div class="ContentPasted2">> + return -EFAULT;</div>
<div class="ContentPasted2">></div>
<div class="ContentPasted2">>> +</div>
<div class="ContentPasted2">>> + /* {set|get}_caching ioctl should fail for objects created with set_pat */</div>
<div class="ContentPasted2">>> + igt_assert(__gem_set_caching(fd, handle, 1) == -EOPNOTSUPP);</div>
<div class="ContentPasted2">></div>
<div class="ContentPasted2">> Easy to test get too as the comment suggests?</div>
<div><br class="ContentPasted2">
</div>
<div class="ContentPasted2">The ioctl right below is exercising get_caching ioctl.</div>
<div class="ContentPasted2">I couldn't use gem_get_caching() because it overwrites errno.</div>
<div><br class="ContentPasted2">
</div>
<div class="ContentPasted2">> Regards,</div>
<div class="ContentPasted2">></div>
<div class="ContentPasted2">> Tvrtko</div>
<div class="ContentPasted2">></div>
<div class="ContentPasted2">>> +</div>
<div class="ContentPasted2">>> + memset(&arg, 0, sizeof(arg));</div>
<div class="ContentPasted2">>> + arg.handle = handle;</div>
<div class="ContentPasted2">>> + igt_assert(ioctl(fd, DRM_IOCTL_I915_GEM_GET_CACHING, &arg) < 0 &&</div>
<div class="ContentPasted2">>> + errno == EOPNOTSUPP);</div>
<div class="ContentPasted2">>> +</div>
>> + /* gem_create should fail with -EINVAL if invalid pat index specified */
<div class="ContentPasted3">>> + igt_assert_eq(__gem_create_ext(fd, &size, 0, &handle, &setparam_inv_pat.base),</div>
<div class="ContentPasted3">>> + -EINVAL);</div>
<div class="ContentPasted3">>> +</div>
<div class="ContentPasted3">>> + gem_close(fd, handle);</div>
<div class="ContentPasted3">>> +}</div>
<div class="ContentPasted3">>> +</div>
<div class="ContentPasted3">>> static bool supports_needs_cpu_access(int fd)</div>
<div class="ContentPasted3">>> {</div>
<div class="ContentPasted3">>> struct drm_i915_gem_memory_class_instance regions[] = { @@ -897,6</div>
<div class="ContentPasted3">>> +936,11 @@ igt_main</div>
<div class="ContentPasted3">>> igt_subtest("create-ext-placement-all")</div>
<div class="ContentPasted3">>> create_ext_placement_all(fd);</div>
<div class="ContentPasted3">>></div>
<div class="ContentPasted3">>> + igt_describe("Create objects with specific cache setting"</div>
<div class="ContentPasted3">>> + " create-ext.");</div>
<div class="ContentPasted3">>> + igt_subtest("create-ext-set-pat")</div>
<div class="ContentPasted3">>> + create_ext_set_pat(fd);</div>
<div class="ContentPasted3">>> +</div>
<div class="ContentPasted3">>> igt_describe("Verify the basic functionally and expected ABI contract around I915_GEM_CREATE_EXT_FLAG_NEEDS_CPU_ACCESS");</div>
<div class="ContentPasted3">>> igt_subtest("create-ext-cpu-access-sanity-check") {</div>
<div class="ContentPasted3">>> igt_require(supports_needs_cpu_access(fd));</div>
</div>
</div>
</body>
</html>