@@ -2230,6 +2230,7 @@ struct drm_i915_query_item {
2230
2230
#define DRM_I915_QUERY_TOPOLOGY_INFO 1
2231
2231
#define DRM_I915_QUERY_ENGINE_INFO 2
2232
2232
#define DRM_I915_QUERY_PERF_CONFIG 3
2233
+ #define DRM_I915_QUERY_MEMORY_REGIONS 4
2233
2234
/* Must be kept compact -- no holes and well documented */
2234
2235
2235
2236
/**
@@ -2464,6 +2465,139 @@ struct drm_i915_query_perf_config {
2464
2465
__u8 data [];
2465
2466
};
2466
2467
2468
+ /**
2469
+ * enum drm_i915_gem_memory_class - Supported memory classes
2470
+ */
2471
+ enum drm_i915_gem_memory_class {
2472
+ /** @I915_MEMORY_CLASS_SYSTEM: System memory */
2473
+ I915_MEMORY_CLASS_SYSTEM = 0 ,
2474
+ /** @I915_MEMORY_CLASS_DEVICE: Device local-memory */
2475
+ I915_MEMORY_CLASS_DEVICE ,
2476
+ };
2477
+
2478
+ /**
2479
+ * struct drm_i915_gem_memory_class_instance - Identify particular memory region
2480
+ */
2481
+ struct drm_i915_gem_memory_class_instance {
2482
+ /** @memory_class: See enum drm_i915_gem_memory_class */
2483
+ __u16 memory_class ;
2484
+
2485
+ /** @memory_instance: Which instance */
2486
+ __u16 memory_instance ;
2487
+ };
2488
+
2489
+ /**
2490
+ * struct drm_i915_memory_region_info - Describes one region as known to the
2491
+ * driver.
2492
+ *
2493
+ * Note that we reserve some stuff here for potential future work. As an example
2494
+ * we might want expose the capabilities for a given region, which could include
2495
+ * things like if the region is CPU mappable/accessible, what are the supported
2496
+ * mapping types etc.
2497
+ *
2498
+ * Note that to extend struct drm_i915_memory_region_info and struct
2499
+ * drm_i915_query_memory_regions in the future the plan is to do the following:
2500
+ *
2501
+ * .. code-block:: C
2502
+ *
2503
+ * struct drm_i915_memory_region_info {
2504
+ * struct drm_i915_gem_memory_class_instance region;
2505
+ * union {
2506
+ * __u32 rsvd0;
2507
+ * __u32 new_thing1;
2508
+ * };
2509
+ * ...
2510
+ * union {
2511
+ * __u64 rsvd1[8];
2512
+ * struct {
2513
+ * __u64 new_thing2;
2514
+ * __u64 new_thing3;
2515
+ * ...
2516
+ * };
2517
+ * };
2518
+ * };
2519
+ *
2520
+ * With this things should remain source compatible between versions for
2521
+ * userspace, even as we add new fields.
2522
+ *
2523
+ * Note this is using both struct drm_i915_query_item and struct drm_i915_query.
2524
+ * For this new query we are adding the new query id DRM_I915_QUERY_MEMORY_REGIONS
2525
+ * at &drm_i915_query_item.query_id.
2526
+ */
2527
+ struct drm_i915_memory_region_info {
2528
+ /** @region: The class:instance pair encoding */
2529
+ struct drm_i915_gem_memory_class_instance region ;
2530
+
2531
+ /** @rsvd0: MBZ */
2532
+ __u32 rsvd0 ;
2533
+
2534
+ /** @probed_size: Memory probed by the driver (-1 = unknown) */
2535
+ __u64 probed_size ;
2536
+
2537
+ /** @unallocated_size: Estimate of memory remaining (-1 = unknown) */
2538
+ __u64 unallocated_size ;
2539
+
2540
+ /** @rsvd1: MBZ */
2541
+ __u64 rsvd1 [8 ];
2542
+ };
2543
+
2544
+ /**
2545
+ * struct drm_i915_query_memory_regions
2546
+ *
2547
+ * The region info query enumerates all regions known to the driver by filling
2548
+ * in an array of struct drm_i915_memory_region_info structures.
2549
+ *
2550
+ * Example for getting the list of supported regions:
2551
+ *
2552
+ * .. code-block:: C
2553
+ *
2554
+ * struct drm_i915_query_memory_regions *info;
2555
+ * struct drm_i915_query_item item = {
2556
+ * .query_id = DRM_I915_QUERY_MEMORY_REGIONS;
2557
+ * };
2558
+ * struct drm_i915_query query = {
2559
+ * .num_items = 1,
2560
+ * .items_ptr = (uintptr_t)&item,
2561
+ * };
2562
+ * int err, i;
2563
+ *
2564
+ * // First query the size of the blob we need, this needs to be large
2565
+ * // enough to hold our array of regions. The kernel will fill out the
2566
+ * // item.length for us, which is the number of bytes we need.
2567
+ * err = ioctl(fd, DRM_IOCTL_I915_QUERY, &query);
2568
+ * if (err) ...
2569
+ *
2570
+ * info = calloc(1, item.length);
2571
+ * // Now that we allocated the required number of bytes, we call the ioctl
2572
+ * // again, this time with the data_ptr pointing to our newly allocated
2573
+ * // blob, which the kernel can then populate with the all the region info.
2574
+ * item.data_ptr = (uintptr_t)&info,
2575
+ *
2576
+ * err = ioctl(fd, DRM_IOCTL_I915_QUERY, &query);
2577
+ * if (err) ...
2578
+ *
2579
+ * // We can now access each region in the array
2580
+ * for (i = 0; i < info->num_regions; i++) {
2581
+ * struct drm_i915_memory_region_info mr = info->regions[i];
2582
+ * u16 class = mr.region.class;
2583
+ * u16 instance = mr.region.instance;
2584
+ *
2585
+ * ....
2586
+ * }
2587
+ *
2588
+ * free(info);
2589
+ */
2590
+ struct drm_i915_query_memory_regions {
2591
+ /** @num_regions: Number of supported regions */
2592
+ __u32 num_regions ;
2593
+
2594
+ /** @rsvd: MBZ */
2595
+ __u32 rsvd [3 ];
2596
+
2597
+ /** @regions: Info about each supported region */
2598
+ struct drm_i915_memory_region_info regions [];
2599
+ };
2600
+
2467
2601
#if defined(__cplusplus )
2468
2602
}
2469
2603
#endif
0 commit comments