/* SPDX-License-Identifier: MIT */1/*2* Copyright (C) The Asahi Linux Contributors3* Copyright (C) 2018-2023 Collabora Ltd.4* Copyright (C) 2014-2018 Broadcom5*/6#ifndef _ASAHI_DRM_H_7#define _ASAHI_DRM_H_89#include "drm.h"1011#if defined(__cplusplus)12extern "C" {13#endif1415/**16* DOC: Introduction to the Asahi UAPI17*18* This documentation describes the Asahi IOCTLs.19*20* Just a few generic rules about the data passed to the Asahi IOCTLs (cribbed21* from Panthor):22*23* - Structures must be aligned on 64-bit/8-byte. If the object is not24* naturally aligned, a padding field must be added.25* - Fields must be explicitly aligned to their natural type alignment with26* pad[0..N] fields.27* - All padding fields will be checked by the driver to make sure they are28* zeroed.29* - Flags can be added, but not removed/replaced.30* - New fields can be added to the main structures (the structures31* directly passed to the ioctl). Those fields can be added at the end of32* the structure, or replace existing padding fields. Any new field being33* added must preserve the behavior that existed before those fields were34* added when a value of zero is passed.35* - New fields can be added to indirect objects (objects pointed by the36* main structure), iff those objects are passed a size to reflect the37* size known by the userspace driver (see38* drm_asahi_cmd_header::size).39* - If the kernel driver is too old to know some fields, those will be40* ignored if zero, and otherwise rejected (and so will be zero on output).41* - If userspace is too old to know some fields, those will be zeroed42* (input) before the structure is parsed by the kernel driver.43* - Each new flag/field addition must come with a driver version update so44* the userspace driver doesn't have to guess which flags are supported.45* - Structures should not contain unions, as this would defeat the46* extensibility of such structures.47* - IOCTLs can't be removed or replaced. New IOCTL IDs should be placed48* at the end of the drm_asahi_ioctl_id enum.49*/5051/**52* enum drm_asahi_ioctl_id - IOCTL IDs53*54* Place new ioctls at the end, don't re-order, don't replace or remove entries.55*56* These IDs are not meant to be used directly. Use the DRM_IOCTL_ASAHI_xxx57* definitions instead.58*/59enum drm_asahi_ioctl_id {60/** @DRM_ASAHI_GET_PARAMS: Query device properties. */61DRM_ASAHI_GET_PARAMS = 0,6263/** @DRM_ASAHI_GET_TIME: Query device time. */64DRM_ASAHI_GET_TIME,6566/** @DRM_ASAHI_VM_CREATE: Create a GPU VM address space. */67DRM_ASAHI_VM_CREATE,6869/** @DRM_ASAHI_VM_DESTROY: Destroy a VM. */70DRM_ASAHI_VM_DESTROY,7172/** @DRM_ASAHI_VM_BIND: Bind/unbind memory to a VM. */73DRM_ASAHI_VM_BIND,7475/** @DRM_ASAHI_GEM_CREATE: Create a buffer object. */76DRM_ASAHI_GEM_CREATE,7778/**79* @DRM_ASAHI_GEM_MMAP_OFFSET: Get offset to pass to mmap() to map a80* given GEM handle.81*/82DRM_ASAHI_GEM_MMAP_OFFSET,8384/** @DRM_ASAHI_GEM_BIND_OBJECT: Bind memory as a special object */85DRM_ASAHI_GEM_BIND_OBJECT,8687/** @DRM_ASAHI_QUEUE_CREATE: Create a scheduling queue. */88DRM_ASAHI_QUEUE_CREATE,8990/** @DRM_ASAHI_QUEUE_DESTROY: Destroy a scheduling queue. */91DRM_ASAHI_QUEUE_DESTROY,9293/** @DRM_ASAHI_SUBMIT: Submit commands to a queue. */94DRM_ASAHI_SUBMIT,95};9697#define DRM_ASAHI_MAX_CLUSTERS 649899/**100* struct drm_asahi_params_global - Global parameters.101*102* This struct may be queried by drm_asahi_get_params.103*/104struct drm_asahi_params_global {105/** @features: Feature bits from drm_asahi_feature */106__u64 features;107108/** @gpu_generation: GPU generation, e.g. 13 for G13G */109__u32 gpu_generation;110111/** @gpu_variant: GPU variant as a character, e.g. 'C' for G13C */112__u32 gpu_variant;113114/**115* @gpu_revision: GPU revision in BCD, e.g. 0x00 for 'A0' or116* 0x21 for 'C1'117*/118__u32 gpu_revision;119120/** @chip_id: Chip ID in BCD, e.g. 0x8103 for T8103 */121__u32 chip_id;122123/** @num_dies: Number of dies in the SoC */124__u32 num_dies;125126/** @num_clusters_total: Number of GPU clusters (across all dies) */127__u32 num_clusters_total;128129/**130* @num_cores_per_cluster: Number of logical cores per cluster131* (including inactive/nonexistent)132*/133__u32 num_cores_per_cluster;134135/** @max_frequency_khz: Maximum GPU core clock frequency */136__u32 max_frequency_khz;137138/** @core_masks: Bitmask of present/enabled cores per cluster */139__u64 core_masks[DRM_ASAHI_MAX_CLUSTERS];140141/**142* @vm_start: VM range start VMA. Together with @vm_end, this defines143* the window of valid GPU VAs. Userspace is expected to subdivide VAs144* out of this window.145*146* This window contains all virtual addresses that userspace needs to147* know about. There may be kernel-internal GPU VAs outside this range,148* but that detail is not relevant here.149*/150__u64 vm_start;151152/** @vm_end: VM range end VMA */153__u64 vm_end;154155/**156* @vm_kernel_min_size: Minimum kernel VMA window size.157*158* When creating a VM, userspace is required to carve out a section of159* virtual addresses (within the range given by @vm_start and160* @vm_end). The kernel will allocate various internal structures161* within the specified VA range.162*163* Allowing userspace to choose the VA range for the kernel, rather than164* the kernel reserving VAs and requiring userspace to cope, can assist165* in implementing SVM.166*/167__u64 vm_kernel_min_size;168169/**170* @max_commands_per_submission: Maximum number of supported commands171* per submission. This mirrors firmware limits. Userspace must split up172* larger command buffers, which may require inserting additional173* synchronization.174*/175__u32 max_commands_per_submission;176177/**178* @max_attachments: Maximum number of drm_asahi_attachment's per179* command180*/181__u32 max_attachments;182183/**184* @command_timestamp_frequency_hz: Timebase frequency for timestamps185* written during command execution, specified via drm_asahi_timestamp186* structures. As this rate is controlled by the firmware, it is a187* queryable parameter.188*189* Userspace must divide by this frequency to convert timestamps to190* seconds, rather than hardcoding a particular firmware's rate.191*/192__u64 command_timestamp_frequency_hz;193};194195/**196* enum drm_asahi_feature - Feature bits197*198* This covers only features that userspace cannot infer from the architecture199* version. Most features don't need to be here.200*/201enum drm_asahi_feature {202/**203* @DRM_ASAHI_FEATURE_SOFT_FAULTS: GPU has "soft fault" enabled. Shader204* loads of unmapped memory will return zero. Shader stores to unmapped205* memory will be silently discarded. Note that only shader load/store206* is affected. Other hardware units are not affected, notably including207* texture sampling.208*209* Soft fault is set when initializing the GPU and cannot be runtime210* toggled. Therefore, it is exposed as a feature bit and not a211* userspace-settable flag on the VM. When soft fault is enabled,212* userspace can speculate memory accesses more aggressively.213*/214DRM_ASAHI_FEATURE_SOFT_FAULTS = (1UL) << 0,215};216217/**218* struct drm_asahi_get_params - Arguments passed to DRM_IOCTL_ASAHI_GET_PARAMS219*/220struct drm_asahi_get_params {221/** @param_group: Parameter group to fetch (MBZ) */222__u32 param_group;223224/** @pad: MBZ */225__u32 pad;226227/** @pointer: User pointer to write parameter struct */228__u64 pointer;229230/**231* @size: Size of the user buffer. In case of older userspace, this may232* be less than sizeof(struct drm_asahi_params_global). The kernel will233* not write past the length specified here, allowing extensibility.234*/235__u64 size;236};237238/**239* struct drm_asahi_vm_create - Arguments passed to DRM_IOCTL_ASAHI_VM_CREATE240*/241struct drm_asahi_vm_create {242/**243* @kernel_start: Start of the kernel-reserved address range. See244* drm_asahi_params_global::vm_kernel_min_size.245*246* Both @kernel_start and @kernel_end must be within the range of247* valid VAs given by drm_asahi_params_global::vm_start and248* drm_asahi_params_global::vm_end. The size of the kernel range249* (@kernel_end - @kernel_start) must be at least250* drm_asahi_params_global::vm_kernel_min_size.251*252* Userspace must not bind any memory on this VM into this reserved253* range, it is for kernel use only.254*/255__u64 kernel_start;256257/**258* @kernel_end: End of the kernel-reserved address range. See259* @kernel_start.260*/261__u64 kernel_end;262263/** @vm_id: Returned VM ID */264__u32 vm_id;265266/** @pad: MBZ */267__u32 pad;268};269270/**271* struct drm_asahi_vm_destroy - Arguments passed to DRM_IOCTL_ASAHI_VM_DESTROY272*/273struct drm_asahi_vm_destroy {274/** @vm_id: VM ID to be destroyed */275__u32 vm_id;276277/** @pad: MBZ */278__u32 pad;279};280281/**282* enum drm_asahi_gem_flags - Flags for GEM creation283*/284enum drm_asahi_gem_flags {285/**286* @DRM_ASAHI_GEM_WRITEBACK: BO should be CPU-mapped as writeback.287*288* Map as writeback instead of write-combine. This optimizes for CPU289* reads.290*/291DRM_ASAHI_GEM_WRITEBACK = (1L << 0),292293/**294* @DRM_ASAHI_GEM_VM_PRIVATE: BO is private to this GPU VM (no exports).295*/296DRM_ASAHI_GEM_VM_PRIVATE = (1L << 1),297};298299/**300* struct drm_asahi_gem_create - Arguments passed to DRM_IOCTL_ASAHI_GEM_CREATE301*/302struct drm_asahi_gem_create {303/** @size: Size of the BO */304__u64 size;305306/** @flags: Combination of drm_asahi_gem_flags flags. */307__u32 flags;308309/**310* @vm_id: VM ID to assign to the BO, if DRM_ASAHI_GEM_VM_PRIVATE is set311*/312__u32 vm_id;313314/** @handle: Returned GEM handle for the BO */315__u32 handle;316317/** @pad: MBZ */318__u32 pad;319};320321/**322* struct drm_asahi_gem_mmap_offset - Arguments passed to323* DRM_IOCTL_ASAHI_GEM_MMAP_OFFSET324*/325struct drm_asahi_gem_mmap_offset {326/** @handle: Handle for the object being mapped. */327__u32 handle;328329/** @flags: Must be zero */330__u32 flags;331332/** @offset: The fake offset to use for subsequent mmap call */333__u64 offset;334};335336/**337* enum drm_asahi_bind_flags - Flags for GEM binding338*/339enum drm_asahi_bind_flags {340/**341* @DRM_ASAHI_BIND_UNBIND: Instead of binding a GEM object to the range,342* simply unbind the GPU VMA range.343*/344DRM_ASAHI_BIND_UNBIND = (1L << 0),345346/** @DRM_ASAHI_BIND_READ: Map BO with GPU read permission */347DRM_ASAHI_BIND_READ = (1L << 1),348349/** @DRM_ASAHI_BIND_WRITE: Map BO with GPU write permission */350DRM_ASAHI_BIND_WRITE = (1L << 2),351352/**353* @DRM_ASAHI_BIND_SINGLE_PAGE: Map a single page of the BO repeatedly354* across the VA range.355*356* This is useful to fill a VA range with scratch pages or zero pages.357* It is intended as a mechanism to accelerate sparse.358*/359DRM_ASAHI_BIND_SINGLE_PAGE = (1L << 3),360};361362/**363* struct drm_asahi_gem_bind_op - Description of a single GEM bind operation.364*/365struct drm_asahi_gem_bind_op {366/** @flags: Combination of drm_asahi_bind_flags flags. */367__u32 flags;368369/** @handle: GEM object to bind (except for UNBIND) */370__u32 handle;371372/**373* @offset: Offset into the object (except for UNBIND).374*375* For a regular bind, this is the beginning of the region of the GEM376* object to bind.377*378* For a single-page bind, this is the offset to the single page that379* will be repeatedly bound.380*381* Must be page-size aligned.382*/383__u64 offset;384385/**386* @range: Number of bytes to bind/unbind to @addr.387*388* Must be page-size aligned.389*/390__u64 range;391392/**393* @addr: Address to bind to.394*395* Must be page-size aligned.396*/397__u64 addr;398};399400/**401* struct drm_asahi_vm_bind - Arguments passed to402* DRM_IOCTL_ASAHI_VM_BIND403*/404struct drm_asahi_vm_bind {405/** @vm_id: The ID of the VM to bind to */406__u32 vm_id;407408/** @num_binds: number of binds in this IOCTL. */409__u32 num_binds;410411/**412* @stride: Stride in bytes between consecutive binds. This allows413* extensibility of drm_asahi_gem_bind_op.414*/415__u32 stride;416417/** @pad: MBZ */418__u32 pad;419420/**421* @userptr: User pointer to an array of @num_binds structures of type422* @drm_asahi_gem_bind_op and size @stride bytes.423*/424__u64 userptr;425};426427/**428* enum drm_asahi_bind_object_op - Special object bind operation429*/430enum drm_asahi_bind_object_op {431/** @DRM_ASAHI_BIND_OBJECT_OP_BIND: Bind a BO as a special GPU object */432DRM_ASAHI_BIND_OBJECT_OP_BIND = 0,433434/** @DRM_ASAHI_BIND_OBJECT_OP_UNBIND: Unbind a special GPU object */435DRM_ASAHI_BIND_OBJECT_OP_UNBIND = 1,436};437438/**439* enum drm_asahi_bind_object_flags - Special object bind flags440*/441enum drm_asahi_bind_object_flags {442/**443* @DRM_ASAHI_BIND_OBJECT_USAGE_TIMESTAMPS: Map a BO as a timestamp444* buffer.445*/446DRM_ASAHI_BIND_OBJECT_USAGE_TIMESTAMPS = (1L << 0),447};448449/**450* struct drm_asahi_gem_bind_object - Arguments passed to451* DRM_IOCTL_ASAHI_GEM_BIND_OBJECT452*/453struct drm_asahi_gem_bind_object {454/** @op: Bind operation (enum drm_asahi_bind_object_op) */455__u32 op;456457/** @flags: Combination of drm_asahi_bind_object_flags flags. */458__u32 flags;459460/** @handle: GEM object to bind/unbind (BIND) */461__u32 handle;462463/** @vm_id: The ID of the VM to operate on (MBZ currently) */464__u32 vm_id;465466/** @offset: Offset into the object (BIND only) */467__u64 offset;468469/** @range: Number of bytes to bind/unbind (BIND only) */470__u64 range;471472/** @object_handle: Object handle (out for BIND, in for UNBIND) */473__u32 object_handle;474475/** @pad: MBZ */476__u32 pad;477};478479/**480* enum drm_asahi_cmd_type - Command type481*/482enum drm_asahi_cmd_type {483/**484* @DRM_ASAHI_CMD_RENDER: Render command, executing on the render485* subqueue. Combined vertex and fragment operation.486*487* Followed by a @drm_asahi_cmd_render payload.488*/489DRM_ASAHI_CMD_RENDER = 0,490491/**492* @DRM_ASAHI_CMD_COMPUTE: Compute command on the compute subqueue.493*494* Followed by a @drm_asahi_cmd_compute payload.495*/496DRM_ASAHI_CMD_COMPUTE = 1,497498/**499* @DRM_ASAHI_SET_VERTEX_ATTACHMENTS: Software command to set500* attachments for subsequent vertex shaders in the same submit.501*502* Followed by (possibly multiple) @drm_asahi_attachment payloads.503*/504DRM_ASAHI_SET_VERTEX_ATTACHMENTS = 2,505506/**507* @DRM_ASAHI_SET_FRAGMENT_ATTACHMENTS: Software command to set508* attachments for subsequent fragment shaders in the same submit.509*510* Followed by (possibly multiple) @drm_asahi_attachment payloads.511*/512DRM_ASAHI_SET_FRAGMENT_ATTACHMENTS = 3,513514/**515* @DRM_ASAHI_SET_COMPUTE_ATTACHMENTS: Software command to set516* attachments for subsequent compute shaders in the same submit.517*518* Followed by (possibly multiple) @drm_asahi_attachment payloads.519*/520DRM_ASAHI_SET_COMPUTE_ATTACHMENTS = 4,521};522523/**524* enum drm_asahi_priority - Scheduling queue priority.525*526* These priorities are forwarded to the firmware to influence firmware527* scheduling. The exact policy is ultimately decided by firmware, but528* these enums allow userspace to communicate the intentions.529*/530enum drm_asahi_priority {531/** @DRM_ASAHI_PRIORITY_LOW: Low priority queue. */532DRM_ASAHI_PRIORITY_LOW = 0,533534/** @DRM_ASAHI_PRIORITY_MEDIUM: Medium priority queue. */535DRM_ASAHI_PRIORITY_MEDIUM = 1,536537/**538* @DRM_ASAHI_PRIORITY_HIGH: High priority queue.539*540* Reserved for future extension.541*/542DRM_ASAHI_PRIORITY_HIGH = 2,543544/**545* @DRM_ASAHI_PRIORITY_REALTIME: Real-time priority queue.546*547* Reserved for future extension.548*/549DRM_ASAHI_PRIORITY_REALTIME = 3,550};551552/**553* struct drm_asahi_queue_create - Arguments passed to554* DRM_IOCTL_ASAHI_QUEUE_CREATE555*/556struct drm_asahi_queue_create {557/** @flags: MBZ */558__u32 flags;559560/** @vm_id: The ID of the VM this queue is bound to */561__u32 vm_id;562563/** @priority: One of drm_asahi_priority */564__u32 priority;565566/** @queue_id: The returned queue ID */567__u32 queue_id;568569/**570* @usc_exec_base: GPU base address for all USC binaries (shaders) on571* this queue. USC addresses are 32-bit relative to this 64-bit base.572*573* This sets the following registers on all queue commands:574*575* USC_EXEC_BASE_TA (vertex)576* USC_EXEC_BASE_ISP (fragment)577* USC_EXEC_BASE_CP (compute)578*579* While the hardware lets us configure these independently per command,580* we do not have a use case for this. Instead, we expect userspace to581* fix a 4GiB VA carveout for USC memory and pass its base address here.582*/583__u64 usc_exec_base;584};585586/**587* struct drm_asahi_queue_destroy - Arguments passed to588* DRM_IOCTL_ASAHI_QUEUE_DESTROY589*/590struct drm_asahi_queue_destroy {591/** @queue_id: The queue ID to be destroyed */592__u32 queue_id;593594/** @pad: MBZ */595__u32 pad;596};597598/**599* enum drm_asahi_sync_type - Sync item type600*/601enum drm_asahi_sync_type {602/** @DRM_ASAHI_SYNC_SYNCOBJ: Binary sync object */603DRM_ASAHI_SYNC_SYNCOBJ = 0,604605/** @DRM_ASAHI_SYNC_TIMELINE_SYNCOBJ: Timeline sync object */606DRM_ASAHI_SYNC_TIMELINE_SYNCOBJ = 1,607};608609/**610* struct drm_asahi_sync - Sync item611*/612struct drm_asahi_sync {613/** @sync_type: One of drm_asahi_sync_type */614__u32 sync_type;615616/** @handle: The sync object handle */617__u32 handle;618619/** @timeline_value: Timeline value for timeline sync objects */620__u64 timeline_value;621};622623/**624* define DRM_ASAHI_BARRIER_NONE - Command index for no barrier625*626* This special value may be passed in to drm_asahi_command::vdm_barrier or627* drm_asahi_command::cdm_barrier to indicate that the respective subqueue628* should not wait on any previous work.629*/630#define DRM_ASAHI_BARRIER_NONE (0xFFFFu)631632/**633* struct drm_asahi_cmd_header - Top level command structure634*635* This struct is core to the command buffer definition and therefore is not636* extensible.637*/638struct drm_asahi_cmd_header {639/** @cmd_type: One of drm_asahi_cmd_type */640__u16 cmd_type;641642/**643* @size: Size of this command, not including this header.644*645* For hardware commands, this enables extensibility of commands without646* requiring extra command types. Passing a command that is shorter647* than expected is explicitly allowed for backwards-compatibility.648* Truncated fields will be zeroed.649*650* For the synthetic attachment setting commands, this implicitly651* encodes the number of attachments. These commands take multiple652* fixed-size @drm_asahi_attachment structures as their payload, so size653* equals number of attachments * sizeof(struct drm_asahi_attachment).654*/655__u16 size;656657/**658* @vdm_barrier: VDM (render) command index to wait on.659*660* Barriers are indices relative to the beginning of a given submit. A661* barrier of 0 waits on commands submitted to the respective subqueue662* in previous submit ioctls. A barrier of N waits on N previous663* commands on the subqueue within the current submit ioctl. As a664* special case, passing @DRM_ASAHI_BARRIER_NONE avoids waiting on any665* commands in the subqueue.666*667* Examples:668*669* 0: This waits on all previous work.670*671* NONE: This does not wait for anything on this subqueue.672*673* 1: This waits on the first render command in the submit.674* This is valid only if there are multiple render commands in the675* same submit.676*677* Barriers are valid only for hardware commands. Synthetic software678* commands to set attachments must pass NONE here.679*/680__u16 vdm_barrier;681682/**683* @cdm_barrier: CDM (compute) command index to wait on.684*685* See @vdm_barrier, and replace VDM/render with CDM/compute.686*/687__u16 cdm_barrier;688};689690/**691* struct drm_asahi_submit - Arguments passed to DRM_IOCTL_ASAHI_SUBMIT692*/693struct drm_asahi_submit {694/**695* @syncs: An optional pointer to an array of drm_asahi_sync. The first696* @in_sync_count elements are in-syncs, then the remaining697* @out_sync_count elements are out-syncs. Using a single array with698* explicit partitioning simplifies handling.699*/700__u64 syncs;701702/**703* @cmdbuf: Pointer to the command buffer to submit.704*705* This is a flat command buffer. By design, it contains no CPU706* pointers, which makes it suitable for a virtgpu wire protocol without707* requiring any serializing/deserializing step.708*709* It consists of a series of commands. Each command begins with a710* fixed-size @drm_asahi_cmd_header header and is followed by a711* variable-length payload according to the type and size in the header.712*713* The combined count of "real" hardware commands must be nonzero and at714* most drm_asahi_params_global::max_commands_per_submission.715*/716__u64 cmdbuf;717718/** @flags: Flags for command submission (MBZ) */719__u32 flags;720721/** @queue_id: The queue ID to be submitted to */722__u32 queue_id;723724/**725* @in_sync_count: Number of sync objects to wait on before starting726* this job.727*/728__u32 in_sync_count;729730/**731* @out_sync_count: Number of sync objects to signal upon completion of732* this job.733*/734__u32 out_sync_count;735736/** @cmdbuf_size: Command buffer size in bytes */737__u32 cmdbuf_size;738739/** @pad: MBZ */740__u32 pad;741};742743/**744* struct drm_asahi_attachment - Describe an "attachment".745*746* Attachments are any memory written by shaders, notably including render747* target attachments written by the end-of-tile program. This is purely a hint748* about the accessed memory regions. It is optional to specify, which is749* fortunate as it cannot be specified precisely with bindless access anyway.750* But where possible, it's probably a good idea for userspace to include these751* hints, forwarded to the firmware.752*753* This struct is implicitly sized and therefore is not extensible.754*/755struct drm_asahi_attachment {756/** @pointer: Base address of the attachment */757__u64 pointer;758759/** @size: Size of the attachment in bytes */760__u64 size;761762/** @pad: MBZ */763__u32 pad;764765/** @flags: MBZ */766__u32 flags;767};768769enum drm_asahi_render_flags {770/**771* @DRM_ASAHI_RENDER_VERTEX_SCRATCH: A vertex stage shader uses scratch772* memory.773*/774DRM_ASAHI_RENDER_VERTEX_SCRATCH = (1U << 0),775776/**777* @DRM_ASAHI_RENDER_PROCESS_EMPTY_TILES: Process even empty tiles.778* This must be set when clearing render targets.779*/780DRM_ASAHI_RENDER_PROCESS_EMPTY_TILES = (1U << 1),781782/**783* @DRM_ASAHI_RENDER_NO_VERTEX_CLUSTERING: Run vertex stage on a single784* cluster (on multi-cluster GPUs)785*786* This harms performance but can workaround certain sync/coherency787* bugs, and therefore is useful for debugging.788*/789DRM_ASAHI_RENDER_NO_VERTEX_CLUSTERING = (1U << 2),790791/**792* @DRM_ASAHI_RENDER_DBIAS_IS_INT: Use integer depth bias formula.793*794* Graphics specifications contain two alternate formulas for depth795* bias, a float formula used with floating-point depth buffers and an796* integer formula using with unorm depth buffers. This flag specifies797* that the integer formula should be used. If omitted, the float798* formula is used instead.799*800* This corresponds to bit 18 of the relevant hardware control register,801* so we match that here for efficiency.802*/803DRM_ASAHI_RENDER_DBIAS_IS_INT = (1U << 18),804};805806/**807* struct drm_asahi_zls_buffer - Describe a depth or stencil buffer.808*809* These fields correspond to hardware registers in the ZLS (Z Load/Store) unit.810* There are three hardware registers for each field respectively for loads,811* stores, and partial renders. In practice, it makes sense to set all to the812* same values, except in exceptional cases not yet implemented in userspace, so813* we do not duplicate here for simplicity/efficiency.814*815* This struct is embedded in other structs and therefore is not extensible.816*/817struct drm_asahi_zls_buffer {818/** @base: Base address of the buffer */819__u64 base;820821/**822* @comp_base: If the load buffer is compressed, address of the823* compression metadata section.824*/825__u64 comp_base;826827/**828* @stride: If layered rendering is enabled, the number of bytes829* between each layer of the buffer.830*/831__u32 stride;832833/**834* @comp_stride: If layered rendering is enabled, the number of bytes835* between each layer of the compression metadata.836*/837__u32 comp_stride;838};839840/**841* struct drm_asahi_timestamp - Describe a timestamp write.842*843* The firmware can optionally write the GPU timestamp at render pass844* granularities, but it needs to be mapped specially via845* DRM_IOCTL_ASAHI_GEM_BIND_OBJECT. This structure therefore describes where to846* write as a handle-offset pair, rather than a GPU address like normal.847*848* This struct is embedded in other structs and therefore is not extensible.849*/850struct drm_asahi_timestamp {851/**852* @handle: Handle of the timestamp buffer, or 0 to skip this853* timestamp. If nonzero, this must equal the value returned in854* drm_asahi_gem_bind_object::object_handle.855*/856__u32 handle;857858/** @offset: Offset to write into the timestamp buffer */859__u32 offset;860};861862/**863* struct drm_asahi_timestamps - Describe timestamp writes.864*865* Each operation that can be timestamped, can be timestamped at the start and866* end. Therefore, drm_asahi_timestamp structs always come in pairs, bundled867* together into drm_asahi_timestamps.868*869* This struct is embedded in other structs and therefore is not extensible.870*/871struct drm_asahi_timestamps {872/** @start: Timestamp recorded at the start of the operation */873struct drm_asahi_timestamp start;874875/** @end: Timestamp recorded at the end of the operation */876struct drm_asahi_timestamp end;877};878879/**880* struct drm_asahi_helper_program - Describe helper program configuration.881*882* The helper program is a compute-like kernel required for various hardware883* functionality. Its most important role is dynamically allocating884* scratch/stack memory for individual subgroups, by partitioning a static885* allocation shared for the whole device. It is supplied by userspace via886* drm_asahi_helper_program and internally dispatched by the hardware as needed.887*888* This struct is embedded in other structs and therefore is not extensible.889*/890struct drm_asahi_helper_program {891/**892* @binary: USC address to the helper program binary. This is a tagged893* pointer with configuration in the bottom bits.894*/895__u32 binary;896897/** @cfg: Additional configuration bits for the helper program. */898__u32 cfg;899900/**901* @data: Data passed to the helper program. This value is not902* interpreted by the kernel, firmware, or hardware in any way. It is903* simply a sideband for userspace, set with the submit ioctl and read904* via special registers inside the helper program.905*906* In practice, userspace will pass a 64-bit GPU VA here pointing to the907* actual arguments, which presumably don't fit in 64-bits.908*/909__u64 data;910};911912/**913* struct drm_asahi_bg_eot - Describe a background or end-of-tile program.914*915* The background and end-of-tile programs are dispatched by the hardware at the916* beginning and end of rendering. As the hardware "tilebuffer" is simply local917* memory, these programs are necessary to implement API-level render targets.918* The fragment-like background program is responsible for loading either the919* clear colour or the existing render target contents, while the compute-like920* end-of-tile program stores the tilebuffer contents to memory.921*922* This struct is embedded in other structs and therefore is not extensible.923*/924struct drm_asahi_bg_eot {925/**926* @usc: USC address of the hardware USC words binding resources927* (including images and uniforms) and the program itself. Note this is928* an additional layer of indirection compared to the helper program,929* avoiding the need for a sideband for data. This is a tagged pointer930* with additional configuration in the bottom bits.931*/932__u32 usc;933934/**935* @rsrc_spec: Resource specifier for the program. This is a packed936* hardware data structure describing the required number of registers,937* uniforms, bound textures, and bound samplers.938*/939__u32 rsrc_spec;940};941942/**943* struct drm_asahi_cmd_render - Command to submit 3D944*945* This command submits a single render pass. The hardware control stream may946* include many draws and subpasses, but within the command, the framebuffer947* dimensions and attachments are fixed.948*949* The hardware requires the firmware to set a large number of Control Registers950* setting up state at render pass granularity before each command rendering 3D.951* The firmware bundles this state into data structures. Unfortunately, we952* cannot expose either any of that directly to userspace, because the953* kernel-firmware ABI is not stable. Although we can guarantee the firmware954* updates in tandem with the kernel, we cannot break old userspace when955* upgrading the firmware and kernel. Therefore, we need to abstract well the956* data structures to avoid tying our hands with future firmwares.957*958* The bulk of drm_asahi_cmd_render therefore consists of values of hardware959* control registers, marshalled via the firmware interface.960*961* The framebuffer/tilebuffer dimensions are also specified here. In addition to962* being passed to the firmware/hardware, the kernel requires these dimensions963* to calculate various essential tiling-related data structures. It is964* unfortunate that our submits are heavier than on vendors with saner965* hardware-software interfaces. The upshot is all of this information is966* readily available to userspace with all current APIs.967*968* It looks odd - but it's not overly burdensome and it ensures we can remain969* compatible with old userspace.970*/971struct drm_asahi_cmd_render {972/** @flags: Combination of drm_asahi_render_flags flags. */973__u32 flags;974975/**976* @isp_zls_pixels: ISP_ZLS_PIXELS register value. This contains the977* depth/stencil width/height, which may differ from the framebuffer978* width/height.979*/980__u32 isp_zls_pixels;981982/**983* @vdm_ctrl_stream_base: VDM_CTRL_STREAM_BASE register value. GPU984* address to the beginning of the VDM control stream.985*/986__u64 vdm_ctrl_stream_base;987988/** @vertex_helper: Helper program used for the vertex shader */989struct drm_asahi_helper_program vertex_helper;990991/** @fragment_helper: Helper program used for the fragment shader */992struct drm_asahi_helper_program fragment_helper;993994/**995* @isp_scissor_base: ISP_SCISSOR_BASE register value. GPU address of an996* array of scissor descriptors indexed in the render pass.997*/998__u64 isp_scissor_base;9991000/**1001* @isp_dbias_base: ISP_DBIAS_BASE register value. GPU address of an1002* array of depth bias values indexed in the render pass.1003*/1004__u64 isp_dbias_base;10051006/**1007* @isp_oclqry_base: ISP_OCLQRY_BASE register value. GPU address of an1008* array of occlusion query results written by the render pass.1009*/1010__u64 isp_oclqry_base;10111012/** @depth: Depth buffer */1013struct drm_asahi_zls_buffer depth;10141015/** @stencil: Stencil buffer */1016struct drm_asahi_zls_buffer stencil;10171018/** @zls_ctrl: ZLS_CTRL register value */1019__u64 zls_ctrl;10201021/** @ppp_multisamplectl: PPP_MULTISAMPLECTL register value */1022__u64 ppp_multisamplectl;10231024/**1025* @sampler_heap: Base address of the sampler heap. This heap is used1026* for both vertex shaders and fragment shaders. The registers are1027* per-stage, but there is no known use case for separate heaps.1028*/1029__u64 sampler_heap;10301031/** @ppp_ctrl: PPP_CTRL register value */1032__u32 ppp_ctrl;10331034/** @width_px: Framebuffer width in pixels */1035__u16 width_px;10361037/** @height_px: Framebuffer height in pixels */1038__u16 height_px;10391040/** @layers: Number of layers in the framebuffer */1041__u16 layers;10421043/** @sampler_count: Number of samplers in the sampler heap. */1044__u16 sampler_count;10451046/** @utile_width_px: Width of a logical tilebuffer tile in pixels */1047__u8 utile_width_px;10481049/** @utile_height_px: Height of a logical tilebuffer tile in pixels */1050__u8 utile_height_px;10511052/** @samples: # of samples in the framebuffer. Must be 1, 2, or 4. */1053__u8 samples;10541055/** @sample_size_B: # of bytes in the tilebuffer required per sample. */1056__u8 sample_size_B;10571058/**1059* @isp_merge_upper_x: 32-bit float used in the hardware triangle1060* merging. Calculate as: tan(60 deg) * width.1061*1062* Making these values UAPI avoids requiring floating-point calculations1063* in the kernel in the hot path.1064*/1065__u32 isp_merge_upper_x;10661067/**1068* @isp_merge_upper_y: 32-bit float. Calculate as: tan(60 deg) * height.1069* See @isp_merge_upper_x.1070*/1071__u32 isp_merge_upper_y;10721073/** @bg: Background program run for each tile at the start */1074struct drm_asahi_bg_eot bg;10751076/** @eot: End-of-tile program ran for each tile at the end */1077struct drm_asahi_bg_eot eot;10781079/**1080* @partial_bg: Background program ran at the start of each tile when1081* resuming the render pass during a partial render.1082*/1083struct drm_asahi_bg_eot partial_bg;10841085/**1086* @partial_eot: End-of-tile program ran at the end of each tile when1087* pausing the render pass during a partial render.1088*/1089struct drm_asahi_bg_eot partial_eot;10901091/**1092* @isp_bgobjdepth: ISP_BGOBJDEPTH register value. This is the depth1093* buffer clear value, encoded in the depth buffer's format: either a1094* 32-bit float or a 16-bit unorm (with upper bits zeroed).1095*/1096__u32 isp_bgobjdepth;10971098/**1099* @isp_bgobjvals: ISP_BGOBJVALS register value. The bottom 8-bits1100* contain the stencil buffer clear value.1101*/1102__u32 isp_bgobjvals;11031104/** @ts_vtx: Timestamps for the vertex portion of the render */1105struct drm_asahi_timestamps ts_vtx;11061107/** @ts_frag: Timestamps for the fragment portion of the render */1108struct drm_asahi_timestamps ts_frag;1109};11101111/**1112* struct drm_asahi_cmd_compute - Command to submit compute1113*1114* This command submits a control stream consisting of compute dispatches. There1115* is essentially no limit on how many compute dispatches may be included in a1116* single compute command, although timestamps are at command granularity.1117*/1118struct drm_asahi_cmd_compute {1119/** @flags: MBZ */1120__u32 flags;11211122/** @sampler_count: Number of samplers in the sampler heap. */1123__u32 sampler_count;11241125/**1126* @cdm_ctrl_stream_base: CDM_CTRL_STREAM_BASE register value. GPU1127* address to the beginning of the CDM control stream.1128*/1129__u64 cdm_ctrl_stream_base;11301131/**1132* @cdm_ctrl_stream_end: GPU base address to the end of the hardware1133* control stream. Note this only considers the first contiguous segment1134* of the control stream, as the stream might jump elsewhere.1135*/1136__u64 cdm_ctrl_stream_end;11371138/** @sampler_heap: Base address of the sampler heap. */1139__u64 sampler_heap;11401141/** @helper: Helper program used for this compute command */1142struct drm_asahi_helper_program helper;11431144/** @ts: Timestamps for the compute command */1145struct drm_asahi_timestamps ts;1146};11471148/**1149* struct drm_asahi_get_time - Arguments passed to DRM_IOCTL_ASAHI_GET_TIME1150*/1151struct drm_asahi_get_time {1152/** @flags: MBZ. */1153__u64 flags;11541155/** @gpu_timestamp: On return, the GPU timestamp in nanoseconds. */1156__u64 gpu_timestamp;1157};11581159/**1160* DRM_IOCTL_ASAHI() - Build an Asahi IOCTL number1161* @__access: Access type. Must be R, W or RW.1162* @__id: One of the DRM_ASAHI_xxx id.1163* @__type: Suffix of the type being passed to the IOCTL.1164*1165* Don't use this macro directly, use the DRM_IOCTL_ASAHI_xxx1166* values instead.1167*1168* Return: An IOCTL number to be passed to ioctl() from userspace.1169*/1170#define DRM_IOCTL_ASAHI(__access, __id, __type) \1171DRM_IO ## __access(DRM_COMMAND_BASE + DRM_ASAHI_ ## __id, \1172struct drm_asahi_ ## __type)11731174/* Note: this is an enum so that it can be resolved by Rust bindgen. */1175enum {1176DRM_IOCTL_ASAHI_GET_PARAMS = DRM_IOCTL_ASAHI(W, GET_PARAMS, get_params),1177DRM_IOCTL_ASAHI_GET_TIME = DRM_IOCTL_ASAHI(WR, GET_TIME, get_time),1178DRM_IOCTL_ASAHI_VM_CREATE = DRM_IOCTL_ASAHI(WR, VM_CREATE, vm_create),1179DRM_IOCTL_ASAHI_VM_DESTROY = DRM_IOCTL_ASAHI(W, VM_DESTROY, vm_destroy),1180DRM_IOCTL_ASAHI_VM_BIND = DRM_IOCTL_ASAHI(W, VM_BIND, vm_bind),1181DRM_IOCTL_ASAHI_GEM_CREATE = DRM_IOCTL_ASAHI(WR, GEM_CREATE, gem_create),1182DRM_IOCTL_ASAHI_GEM_MMAP_OFFSET = DRM_IOCTL_ASAHI(WR, GEM_MMAP_OFFSET, gem_mmap_offset),1183DRM_IOCTL_ASAHI_GEM_BIND_OBJECT = DRM_IOCTL_ASAHI(WR, GEM_BIND_OBJECT, gem_bind_object),1184DRM_IOCTL_ASAHI_QUEUE_CREATE = DRM_IOCTL_ASAHI(WR, QUEUE_CREATE, queue_create),1185DRM_IOCTL_ASAHI_QUEUE_DESTROY = DRM_IOCTL_ASAHI(W, QUEUE_DESTROY, queue_destroy),1186DRM_IOCTL_ASAHI_SUBMIT = DRM_IOCTL_ASAHI(W, SUBMIT, submit),1187};11881189#if defined(__cplusplus)1190}1191#endif11921193#endif /* _ASAHI_DRM_H_ */119411951196