|
| 1 | +/** |
| 2 | + * enum drm_i915_gem_memory_class - Supported memory classes |
| 3 | + */ |
| 4 | +enum drm_i915_gem_memory_class { |
| 5 | + /** @I915_MEMORY_CLASS_SYSTEM: System memory */ |
| 6 | + I915_MEMORY_CLASS_SYSTEM = 0, |
| 7 | + /** @I915_MEMORY_CLASS_DEVICE: Device local-memory */ |
| 8 | + I915_MEMORY_CLASS_DEVICE, |
| 9 | +}; |
| 10 | + |
| 11 | +/** |
| 12 | + * struct drm_i915_gem_memory_class_instance - Identify particular memory region |
| 13 | + */ |
| 14 | +struct drm_i915_gem_memory_class_instance { |
| 15 | + /** @memory_class: See enum drm_i915_gem_memory_class */ |
| 16 | + __u16 memory_class; |
| 17 | + |
| 18 | + /** @memory_instance: Which instance */ |
| 19 | + __u16 memory_instance; |
| 20 | +}; |
| 21 | + |
| 22 | +/** |
| 23 | + * struct drm_i915_memory_region_info - Describes one region as known to the |
| 24 | + * driver. |
| 25 | + * |
| 26 | + * Note that we reserve some stuff here for potential future work. As an example |
| 27 | + * we might want expose the capabilities for a given region, which could include |
| 28 | + * things like if the region is CPU mappable/accessible, what are the supported |
| 29 | + * mapping types etc. |
| 30 | + * |
| 31 | + * Note that to extend struct drm_i915_memory_region_info and struct |
| 32 | + * drm_i915_query_memory_regions in the future the plan is to do the following: |
| 33 | + * |
| 34 | + * .. code-block:: C |
| 35 | + * |
| 36 | + * struct drm_i915_memory_region_info { |
| 37 | + * struct drm_i915_gem_memory_class_instance region; |
| 38 | + * union { |
| 39 | + * __u32 rsvd0; |
| 40 | + * __u32 new_thing1; |
| 41 | + * }; |
| 42 | + * ... |
| 43 | + * union { |
| 44 | + * __u64 rsvd1[8]; |
| 45 | + * struct { |
| 46 | + * __u64 new_thing2; |
| 47 | + * __u64 new_thing3; |
| 48 | + * ... |
| 49 | + * }; |
| 50 | + * }; |
| 51 | + * }; |
| 52 | + * |
| 53 | + * With this things should remain source compatible between versions for |
| 54 | + * userspace, even as we add new fields. |
| 55 | + * |
| 56 | + * Note this is using both struct drm_i915_query_item and struct drm_i915_query. |
| 57 | + * For this new query we are adding the new query id DRM_I915_QUERY_MEMORY_REGIONS |
| 58 | + * at &drm_i915_query_item.query_id. |
| 59 | + */ |
| 60 | +struct drm_i915_memory_region_info { |
| 61 | + /** @region: The class:instance pair encoding */ |
| 62 | + struct drm_i915_gem_memory_class_instance region; |
| 63 | + |
| 64 | + /** @rsvd0: MBZ */ |
| 65 | + __u32 rsvd0; |
| 66 | + |
| 67 | + /** @probed_size: Memory probed by the driver (-1 = unknown) */ |
| 68 | + __u64 probed_size; |
| 69 | + |
| 70 | + /** @unallocated_size: Estimate of memory remaining (-1 = unknown) */ |
| 71 | + __u64 unallocated_size; |
| 72 | + |
| 73 | + /** @rsvd1: MBZ */ |
| 74 | + __u64 rsvd1[8]; |
| 75 | +}; |
| 76 | + |
| 77 | +/** |
| 78 | + * struct drm_i915_query_memory_regions |
| 79 | + * |
| 80 | + * The region info query enumerates all regions known to the driver by filling |
| 81 | + * in an array of struct drm_i915_memory_region_info structures. |
| 82 | + * |
| 83 | + * Example for getting the list of supported regions: |
| 84 | + * |
| 85 | + * .. code-block:: C |
| 86 | + * |
| 87 | + * struct drm_i915_query_memory_regions *info; |
| 88 | + * struct drm_i915_query_item item = { |
| 89 | + * .query_id = DRM_I915_QUERY_MEMORY_REGIONS; |
| 90 | + * }; |
| 91 | + * struct drm_i915_query query = { |
| 92 | + * .num_items = 1, |
| 93 | + * .items_ptr = (uintptr_t)&item, |
| 94 | + * }; |
| 95 | + * int err, i; |
| 96 | + * |
| 97 | + * // First query the size of the blob we need, this needs to be large |
| 98 | + * // enough to hold our array of regions. The kernel will fill out the |
| 99 | + * // item.length for us, which is the number of bytes we need. |
| 100 | + * err = ioctl(fd, DRM_IOCTL_I915_QUERY, &query); |
| 101 | + * if (err) ... |
| 102 | + * |
| 103 | + * info = calloc(1, item.length); |
| 104 | + * // Now that we allocated the required number of bytes, we call the ioctl |
| 105 | + * // again, this time with the data_ptr pointing to our newly allocated |
| 106 | + * // blob, which the kernel can then populate with the all the region info. |
| 107 | + * item.data_ptr = (uintptr_t)&info, |
| 108 | + * |
| 109 | + * err = ioctl(fd, DRM_IOCTL_I915_QUERY, &query); |
| 110 | + * if (err) ... |
| 111 | + * |
| 112 | + * // We can now access each region in the array |
| 113 | + * for (i = 0; i < info->num_regions; i++) { |
| 114 | + * struct drm_i915_memory_region_info mr = info->regions[i]; |
| 115 | + * u16 class = mr.region.class; |
| 116 | + * u16 instance = mr.region.instance; |
| 117 | + * |
| 118 | + * .... |
| 119 | + * } |
| 120 | + * |
| 121 | + * free(info); |
| 122 | + */ |
| 123 | +struct drm_i915_query_memory_regions { |
| 124 | + /** @num_regions: Number of supported regions */ |
| 125 | + __u32 num_regions; |
| 126 | + |
| 127 | + /** @rsvd: MBZ */ |
| 128 | + __u32 rsvd[3]; |
| 129 | + |
| 130 | + /** @regions: Info about each supported region */ |
| 131 | + struct drm_i915_memory_region_info regions[]; |
| 132 | +}; |
| 133 | + |
| 134 | +#define DRM_I915_GEM_CREATE_EXT 0xdeadbeaf |
| 135 | +#define DRM_IOCTL_I915_GEM_CREATE_EXT DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_CREATE_EXT, struct drm_i915_gem_create_ext) |
| 136 | + |
| 137 | +/** |
| 138 | + * struct drm_i915_gem_create_ext - Existing gem_create behaviour, with added |
| 139 | + * extension support using struct i915_user_extension. |
| 140 | + * |
| 141 | + * Note that in the future we want to have our buffer flags here, at least for |
| 142 | + * the stuff that is immutable. Previously we would have two ioctls, one to |
| 143 | + * create the object with gem_create, and another to apply various parameters, |
| 144 | + * however this creates some ambiguity for the params which are considered |
| 145 | + * immutable. Also in general we're phasing out the various SET/GET ioctls. |
| 146 | + */ |
| 147 | +struct drm_i915_gem_create_ext { |
| 148 | + /** |
| 149 | + * @size: Requested size for the object. |
| 150 | + * |
| 151 | + * The (page-aligned) allocated size for the object will be returned. |
| 152 | + * |
| 153 | + * Note that for some devices we have might have further minimum |
| 154 | + * page-size restrictions(larger than 4K), like for device local-memory. |
| 155 | + * However in general the final size here should always reflect any |
| 156 | + * rounding up, if for example using the I915_GEM_CREATE_EXT_MEMORY_REGIONS |
| 157 | + * extension to place the object in device local-memory. |
| 158 | + */ |
| 159 | + __u64 size; |
| 160 | + /** |
| 161 | + * @handle: Returned handle for the object. |
| 162 | + * |
| 163 | + * Object handles are nonzero. |
| 164 | + */ |
| 165 | + __u32 handle; |
| 166 | + /** @flags: MBZ */ |
| 167 | + __u32 flags; |
| 168 | + /** |
| 169 | + * @extensions: The chain of extensions to apply to this object. |
| 170 | + * |
| 171 | + * This will be useful in the future when we need to support several |
| 172 | + * different extensions, and we need to apply more than one when |
| 173 | + * creating the object. See struct i915_user_extension. |
| 174 | + * |
| 175 | + * If we don't supply any extensions then we get the same old gem_create |
| 176 | + * behaviour. |
| 177 | + * |
| 178 | + * For I915_GEM_CREATE_EXT_MEMORY_REGIONS usage see |
| 179 | + * struct drm_i915_gem_create_ext_memory_regions. |
| 180 | + */ |
| 181 | +#define I915_GEM_CREATE_EXT_MEMORY_REGIONS 0 |
| 182 | + __u64 extensions; |
| 183 | +}; |
| 184 | + |
| 185 | +/** |
| 186 | + * struct drm_i915_gem_create_ext_memory_regions - The |
| 187 | + * I915_GEM_CREATE_EXT_MEMORY_REGIONS extension. |
| 188 | + * |
| 189 | + * Set the object with the desired set of placements/regions in priority |
| 190 | + * order. Each entry must be unique and supported by the device. |
| 191 | + * |
| 192 | + * This is provided as an array of struct drm_i915_gem_memory_class_instance, or |
| 193 | + * an equivalent layout of class:instance pair encodings. See struct |
| 194 | + * drm_i915_query_memory_regions and DRM_I915_QUERY_MEMORY_REGIONS for how to |
| 195 | + * query the supported regions for a device. |
| 196 | + * |
| 197 | + * As an example, on discrete devices, if we wish to set the placement as |
| 198 | + * device local-memory we can do something like: |
| 199 | + * |
| 200 | + * .. code-block:: C |
| 201 | + * |
| 202 | + * struct drm_i915_gem_memory_class_instance region_lmem = { |
| 203 | + * .memory_class = I915_MEMORY_CLASS_DEVICE, |
| 204 | + * .memory_instance = 0, |
| 205 | + * }; |
| 206 | + * struct drm_i915_gem_create_ext_memory_regions regions = { |
| 207 | + * .base = { .name = I915_GEM_CREATE_EXT_MEMORY_REGIONS }, |
| 208 | + * .regions = (uintptr_t)®ion_lmem, |
| 209 | + * .num_regions = 1, |
| 210 | + * }; |
| 211 | + * struct drm_i915_gem_create_ext create_ext = { |
| 212 | + * .size = 16 * PAGE_SIZE, |
| 213 | + * .extensions = (uintptr_t)®ions, |
| 214 | + * }; |
| 215 | + * |
| 216 | + * int err = ioctl(fd, DRM_IOCTL_I915_GEM_CREATE_EXT, &create_ext); |
| 217 | + * if (err) ... |
| 218 | + * |
| 219 | + * At which point we get the object handle in &drm_i915_gem_create_ext.handle, |
| 220 | + * along with the final object size in &drm_i915_gem_create_ext.size, which |
| 221 | + * should account for any rounding up, if required. |
| 222 | + */ |
| 223 | +struct drm_i915_gem_create_ext_memory_regions { |
| 224 | + /** @base: Extension link. See struct i915_user_extension. */ |
| 225 | + struct i915_user_extension base; |
| 226 | + |
| 227 | + /** @pad: MBZ */ |
| 228 | + __u32 pad; |
| 229 | + /** @num_regions: Number of elements in the @regions array. */ |
| 230 | + __u32 num_regions; |
| 231 | + /** |
| 232 | + * @regions: The regions/placements array. |
| 233 | + * |
| 234 | + * An array of struct drm_i915_gem_memory_class_instance. |
| 235 | + */ |
| 236 | + __u64 regions; |
| 237 | +}; |
0 commit comments