intel/stub: Implement DRM_I915_QUERY_MEMORY_REGIONS

Borrowed from sim-drm.

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14132>
This commit is contained in:
Ian Romanick 2021-12-06 12:56:01 -08:00
parent 4c429b6be6
commit 832db9d900
1 changed files with 34 additions and 0 deletions

View File

@ -352,6 +352,40 @@ i915_ioctl_query(int fd, unsigned long request, void *arg)
item->length = -EINVAL;
break;
case DRM_I915_QUERY_MEMORY_REGIONS: {
uint32_t num_regions = i915.devinfo.has_local_mem ? 2 : 1;
struct drm_i915_query_memory_regions *info =
(struct drm_i915_query_memory_regions*)(uintptr_t)item->data_ptr;
size_t data_length = sizeof(struct drm_i915_query_memory_regions) +
num_regions * sizeof(struct drm_i915_memory_region_info);
if (item->length == 0) {
item->length = data_length;
return 0;
} else if (item->length < (int32_t)data_length) {
item->length = -EINVAL;
return -1;
} else {
memset(info, 0, data_length);
info->num_regions = num_regions;
info->regions[0].region.memory_class = I915_MEMORY_CLASS_SYSTEM;
info->regions[0].region.memory_instance = 0;
/* Report 4Gb even if it's not actually true, it looks more like a
* real device.
*/
info->regions[0].probed_size = 4ull * 1024 * 1024 * 1024;
info->regions[0].unallocated_size = -1ll;
if (i915.devinfo.has_local_mem) {
info->regions[1].region.memory_class = I915_MEMORY_CLASS_DEVICE;
info->regions[1].region.memory_instance = 0;
info->regions[1].probed_size = 4ull * 1024 * 1024 * 1024;
info->regions[1].unallocated_size = -1ll;
}
return 0;
}
break;
}
default:
fprintf(stderr, "Unknown drm_i915_query_item id=%lli\n", item->query_id);
item->length = -EINVAL;