History

drm/xe/uapi: Add madvise interface

This commit introduces a new madvise interface to support driver-specific ioctl operations. The madvise interface allows for more efficient memory management by providing hints to the driver about the expected memory usage and pte update policy for gpuvma. v2 (Matthew/Thomas) - Drop num_ops support - Drop purgeable support - Add kernel-docs - IOWR/IOW v3 (Matthew/Thomas) - Reorder attributes - use __u16 for migration_policy - use __u64 for reserved in unions - Avoid usage of vma

Himal Prasad Ghimiray committed 1 year ago

Commit 231bb0e1 parent 9d527c41 file · +130 −0Browse files

Showing the changes to include/uapi (1 of 1 file). Show all

Unified · Split

include/uapi/drm/xe_drm.h+130−0
@@ -81,6 +81,7 @@ extern "C" { · 80 unmodified lines
8181 * - &DRM_IOCTL_XE_EXEC
8282 * - &DRM_IOCTL_XE_WAIT_USER_FENCE
8383 * - &DRM_IOCTL_XE_OBSERVATION
84+ * - &DRM_IOCTL_XE_MADVISE
8485 */
8586
8687 /*
@@ -102,6 +103,7 @@ extern "C" { · 15 unmodified lines
102103 #define DRM_XE_EXEC 0x09
103104 #define DRM_XE_WAIT_USER_FENCE 0x0a
104105 #define DRM_XE_OBSERVATION 0x0b
106+#define DRM_XE_MADVISE 0x0c
105107
106108 /* Must be kept compact -- no holes */
107109
@@ -117,6 +119,7 @@ extern "C" { · 9 unmodified lines
117119 #define DRM_IOCTL_XE_EXEC DRM_IOW(DRM_COMMAND_BASE + DRM_XE_EXEC, struct drm_xe_exec)
118120 #define DRM_IOCTL_XE_WAIT_USER_FENCE DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_WAIT_USER_FENCE, struct drm_xe_wait_user_fence)
119121 #define DRM_IOCTL_XE_OBSERVATION DRM_IOW(DRM_COMMAND_BASE + DRM_XE_OBSERVATION, struct drm_xe_observation_param)
122+#define DRM_IOCTL_XE_MADVISE DRM_IOW(DRM_COMMAND_BASE + DRM_XE_MADVISE, struct drm_xe_madvise)
120123
121124 /**
122125 * DOC: Xe IOCTL Extensions
@@ -1978,6 +1981,133 @@ struct drm_xe_query_eu_stall { · 1855 unmodified lines
19781981 __u64 sampling_rates[];
19791982 };
19801983
1984+/**
1985+ * struct drm_xe_madvise - Input of &DRM_IOCTL_XE_MADVISE
1986+ *
1987+ * This structure is used to set memory attributes for a virtual address range
1988+ * in a VM. The type of attribute is specified by @type, and the corresponding
1989+ * union member is used to provide additional parameters for @type.
1990+ *
1991+ * Supported attribute types:
1992+ * - DRM_XE_MEM_RANGE_ATTR_PREFERRED_LOC: Set preferred memory location.
1993+ * - DRM_XE_MEM_RANGE_ATTR_ATOMIC: Set atomic access policy.
1994+ * - DRM_XE_MEM_RANGE_ATTR_PAT: Set page attribute table index.
1995+ *
1996+ * Example:
1997+ *
1998+ * .. code-block:: C
1999+ *
2000+ * struct drm_xe_madvise madvise = {
2001+ *          .vm_id = vm_id,
2002+ *          .start = 0x100000,
2003+ *          .range = 0x2000,
2004+ *          .type = DRM_XE_MEM_RANGE_ATTR_ATOMIC,
2005+ *         .atomic_val = DRM_XE_ATOMIC_DEVICE,
2006+ * };
2007+ *
2008+ * ioctl(fd, DRM_IOCTL_XE_MADVISE, &madvise);
2009+ *
2010+ */
2011+struct drm_xe_madvise {
2012+ /** @extensions: Pointer to the first extension struct, if any */
2013+ __u64 extensions;
2014+
2015+ /** @start: start of the virtual address range */
2016+ __u64 start;
2017+
2018+ /** @range: size of the virtual address range */
2019+ __u64 range;
2020+
2021+ /** @vm_id: vm_id of the virtual range */
2022+ __u32 vm_id;
2023+
2024+#define DRM_XE_MEM_RANGE_ATTR_PREFERRED_LOC 0
2025+#define DRM_XE_MEM_RANGE_ATTR_ATOMIC 1
2026+#define DRM_XE_MEM_RANGE_ATTR_PAT 2
2027+ /** @type: type of attribute */
2028+ __u32 type;
2029+
2030+ union {
2031+ /**
2032+ * @preferred_mem_loc: preferred memory location
2033+ *
2034+ * Used when @type == DRM_XE_MEM_RANGE_ATTR_PREFERRED_LOC
2035+ *
2036+ * Supported values for @preferred_mem_loc.devmem_fd:
2037+ * - DRM_XE_PREFERRED_LOC_DEFAULT_DEVICE: set vram of faulting tile as preferred loc
2038+ * - DRM_XE_PREFERRED_LOC_DEFAULT_SYSTEM: set smem as preferred loc
2039+ *
2040+ * Supported values for @preferred_mem_loc.migration_policy:
2041+ * - DRM_XE_MIGRATE_ALL_PAGES
2042+ * - DRM_XE_MIGRATE_ONLY_SYSTEM_PAGES
2043+ */
2044+ struct {
2045+#define DRM_XE_PREFERRED_LOC_DEFAULT_DEVICE 0
2046+#define DRM_XE_PREFERRED_LOC_DEFAULT_SYSTEM -1
2047+ /** @preferred_mem_loc.devmem_fd: fd for preferred loc */
2048+ __u32 devmem_fd;
2049+
2050+#define DRM_XE_MIGRATE_ALL_PAGES 0
2051+#define DRM_XE_MIGRATE_ONLY_SYSTEM_PAGES 1
2052+ /** @preferred_mem_loc.migration_policy: Page migration policy */
2053+ __u16 migration_policy;
2054+
2055+ /** @preferred_mem_loc.pad : MBZ */
2056+ __u16 pad;
2057+
2058+ /** @preferred_mem_loc.reserved : Reserved */
2059+ __u64 reserved;
2060+ } preferred_mem_loc;
2061+
2062+ /**
2063+ * @atomic: Atomic access policy
2064+ *
2065+ * Used when @type == DRM_XE_MEM_RANGE_ATTR_ATOMIC.
2066+ *
2067+ * Supported values for @atomic.val:
2068+ * - DRM_XE_ATOMIC_UNDEFINED: Undefined or default behaviour
2069+ * Support both GPU and CPU atomic operations for system allocator
2070+ * Support GPU atomic operations for normal(bo) allocator
2071+ * - DRM_XE_ATOMIC_DEVICE: Support GPU atomic operations
2072+ * - DRM_XE_ATOMIC_GLOBAL: Support both GPU and CPU atomic operations
2073+ * - DRM_XE_ATOMIC_CPU: Support CPU atomic
2074+ */
2075+ struct {
2076+#define DRM_XE_ATOMIC_UNDEFINED 0
2077+#define DRM_XE_ATOMIC_DEVICE 1
2078+#define DRM_XE_ATOMIC_GLOBAL 2
2079+#define DRM_XE_ATOMIC_CPU 3
2080+ /** @atomic.val: value of atomic operation */
2081+ __u32 val;
2082+
2083+ /** @atomic.pad: MBZ */
2084+ __u32 pad;
2085+
2086+ /** @atomic.reserved: Reserved */
2087+ __u64 reserved;
2088+ } atomic;
2089+
2090+ /**
2091+ * @pat_index: Page attribute table index
2092+ *
2093+ * Used when @type == DRM_XE_MEM_RANGE_ATTR_PAT.
2094+ */
2095+ struct {
2096+ /** @pat_index.val: PAT index value */
2097+ __u32 val;
2098+
2099+ /** @pat_index.pad: MBZ */
2100+ __u32 pad;
2101+
2102+ /** @pat_index.reserved: Reserved */
2103+ __u64 reserved;
2104+ } pat_index;
2105+ };
2106+
2107+ /** @reserved: Reserved */
2108+ __u64 reserved[2];
2109+};
2110+
19812111 #if defined(__cplusplus)
19822112 }
19832113 #endif