drm/nouveau: ZCULL support
Subsystems (3)
cover drm/nouveau: ZCULL support
These patches add kernel-side support for using the zcull hardware in nvidia gpus. Zcull aims to improve memory bandwidth by using an early approximate depth test, similar to hierarchical Z on an AMD card. These patches add two new ioctls on nouveau devices, which are currently only supported when using gsp firmware.
Corresponding userspace changes for NVK are available here:
https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33861
or, if gitlab is down, mirrored here:
https://codeberg.org/mhenning/mesa/commits/branch/zcull3
This series is also available in git:
https://gitlab.freedesktop.org/mhenning/linux/-/commits/zcull2?ref_type=heads
As these are my first kernel patches, I ask for your patience during the review process.
Mel Henning (2):
drm/nouveau: Add DRM_IOCTL_NOUVEAU_GET_ZCULL_INFO drm/nouveau: DRM_NOUVEAU_SET_ZCULL_CTXSW_BUFFER
drivers/gpu/drm/nouveau/include/nvif/if0020.h | 6 + .../drm/nouveau/include/nvkm/core/device.h | 6 + .../gpu/drm/nouveau/include/nvkm/engine/gr.h | 1 + .../sdk/nvidia/inc/ctrl/ctrl2080/ctrl2080gr.h | 122 ++++++++++++++++++ drivers/gpu/drm/nouveau/nouveau_abi16.c | 61 +++++++++ drivers/gpu/drm/nouveau/nouveau_abi16.h | 2 + drivers/gpu/drm/nouveau/nouveau_drm.c | 2 + .../gpu/drm/nouveau/nvkm/engine/fifo/chan.c | 8 ++ .../gpu/drm/nouveau/nvkm/engine/fifo/chan.h | 2 + .../gpu/drm/nouveau/nvkm/engine/fifo/r535.c | 26 ++++ .../gpu/drm/nouveau/nvkm/engine/fifo/uchan.c | 17 +++ drivers/gpu/drm/nouveau/nvkm/engine/gr/r535.c | 34 +++++ include/uapi/drm/nouveau_drm.h | 35 +++++ 13 files changed, 322 insertions(+)
Signature · 1 line
2.48.1
PATCH 1/2 drm/nouveau: Add DRM_IOCTL_NOUVEAU_GET_ZCULL_INFO
Userspace needs this information to set up zcull correctly.
--- .../drm/nouveau/include/nvkm/core/device.h | 6 ++ .../sdk/nvidia/inc/ctrl/ctrl2080/ctrl2080gr.h | 69 +++++++++++++++++++ drivers/gpu/drm/nouveau/nouveau_abi16.c | 15 ++++ drivers/gpu/drm/nouveau/nouveau_abi16.h | 1 + drivers/gpu/drm/nouveau/nouveau_drm.c | 1 + drivers/gpu/drm/nouveau/nvkm/engine/gr/r535.c | 34 +++++++++ include/uapi/drm/nouveau_drm.h | 19 +++++ 7 files changed, 145 insertions(+)
drivers/gpu/drm/nouveau/include/nvkm/core/device.h +6 -0
@@ -3,6 +3,9 @@#define __NVKM_DEVICE_H__#include <core/oclass.h> #include <core/intr.h> + +#include "uapi/drm/nouveau_drm.h" +enum nvkm_subdev_type ;enum nvkm_device_type {
@@ -72,6 +75,9 @@ struct nvkm_device {bool armed;bool legacy_done; } intr; + +bool has_zcull_info; +struct drm_nouveau_get_zcull_info zcull_info; };struct nvkm_subdev *nvkm_device_subdev (struct nvkm_device *,int type,int inst);
drivers/gpu/drm/nouveau/include/nvrm/535.113.01/common/sdk/nvidia/inc/ctrl/ctrl2080/ctrl2080gr.h +69 -0
75 lines not on this page · raw message
drivers/gpu/drm/nouveau/nouveau_abi16.c +15 -0
@@ -333,6 +333,21 @@ nouveau_abi16_ioctl_getparam(ABI16_IOCTL_ARGS)return 0 ; } +int +nouveau_abi16_ioctl_get_zcull_info (ABI16_IOCTL_ARGS ) +{ +struct nouveau_drm *drm =nouveau_drm (dev); +struct nvkm_device *device = drm->nvkm; +struct drm_nouveau_get_zcull_info *out = data; + +if (device->has_zcull_info) { + *out = device->zcull_info; +return 0 ; + }else { +return -ENODEV ; + } +} +int nouveau_abi16_ioctl_channel_alloc (ABI16_IOCTL_ARGS ) {
drivers/gpu/drm/nouveau/nouveau_abi16.h +1 -0
@@ -6,6 +6,7 @@ struct drm_device *dev, void *data, struct drm_file *file_privint nouveau_abi16_ioctl_getparam (ABI16_IOCTL_ARGS ); +int nouveau_abi16_ioctl_get_zcull_info (ABI16_IOCTL_ARGS );int nouveau_abi16_ioctl_channel_alloc (ABI16_IOCTL_ARGS );int nouveau_abi16_ioctl_channel_free (ABI16_IOCTL_ARGS );int nouveau_abi16_ioctl_grobj_alloc (ABI16_IOCTL_ARGS );
drivers/gpu/drm/nouveau/nouveau_drm.c +1 -0
@@ -1244,6 +1244,7 @@ nouveau_ioctls[] = {DRM_IOCTL_DEF_DRV (NOUVEAU_GROBJ_ALLOC , nouveau_abi16_ioctl_grobj_alloc,DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (NOUVEAU_NOTIFIEROBJ_ALLOC , nouveau_abi16_ioctl_notifierobj_alloc,DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (NOUVEAU_GPUOBJ_FREE , nouveau_abi16_ioctl_gpuobj_free,DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (NOUVEAU_GET_ZCULL_INFO , nouveau_abi16_ioctl_get_zcull_info,DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (NOUVEAU_SVM_INIT , nouveau_svmm_init,DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (NOUVEAU_SVM_BIND , nouveau_svmm_bind,DRM_RENDER_ALLOW ), DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_NEW, nouveau_gem_ioctl_new, DRM_RENDER_ALLOW),
drivers/gpu/drm/nouveau/nvkm/engine/gr/r535.c +34 -0
@@ -34,6 +34,7 @@#include <nvrm/535.113.01/common/sdk/nvidia/inc/alloc/alloc_channel.h> #include <nvrm/535.113.01/common/sdk/nvidia/inc/ctrl/ctrl0080/ctrl0080fifo.h> #include <nvrm/535.113.01/common/sdk/nvidia/inc/ctrl/ctrl2080/ctrl2080gpu.h> +#include <nvrm/535.113.01/common/sdk/nvidia/inc/ctrl/ctrl2080/ctrl2080gr.h> #include <nvrm/535.113.01/common/sdk/nvidia/inc/ctrl/ctrl2080/ctrl2080internal.h> #include <nvrm/535.113.01/nvidia/generated/g_kernel_channel_nvoc.h>
@@ -244,6 +245,8 @@ static int r535_gr_oneinit(struct nvkm_gr *base) {NV2080_CTRL_INTERNAL_STATIC_GR_GET_CONTEXT_BUFFERS_INFO_PARAMS *info; +NV2080_CTRL_GR_GET_ZCULL_INFO_PARAMS *zcull_info; +u32 zcull_ctxsw_size, zcull_ctxsw_align;struct r535_gr *gr =container_of (base,typeof (*gr), base);struct nvkm_subdev *subdev = &gr->base.engine.subdev;struct nvkm_device *device = subdev->device;
@@ -418,6 +421,11 @@ r535_gr_oneinit(struct nvkm_gr *base) } } + zcull_ctxsw_size = info->engineContextBuffersInfo[0 ] + .engine[NV0080_CTRL_FIFO_GET_ENGINE_CONTEXT_PROPERTIES_ENGINE_ID_GRAPHICS_ZCULL ].size; + zcull_ctxsw_align = info->engineContextBuffersInfo[0 ] + .engine[NV0080_CTRL_FIFO_GET_ENGINE_CONTEXT_PROPERTIES_ENGINE_ID_GRAPHICS_ZCULL ].alignment; +nvkm_gsp_rm_ctrl_done (&gsp->internal.device.subdevice, info);/* Promote golden context to RM. */
@@ -450,6 +458,32 @@ r535_gr_oneinit(struct nvkm_gr *base) } } + zcull_info =nvkm_gsp_rm_ctrl_rd (&gsp->internal.device.subdevice, +NV2080_CTRL_CMD_GR_GET_ZCULL_INFO , +sizeof (*zcull_info)); +if (WARN_ON (IS_ERR (zcull_info))) { + ret =PTR_ERR (zcull_info); + goto done; + } + + device->has_zcull_info = true; + + device->zcull_info.width_align_pixels = zcull_info->widthAlignPixels; + device->zcull_info.height_align_pixels = zcull_info->heightAlignPixels; + device->zcull_info.pixel_squares_by_aliquots = zcull_info->pixelSquaresByAliquots; + device->zcull_info.aliquot_total = zcull_info->aliquotTotal; + device->zcull_info.zcull_region_byte_multiplier = zcull_info->zcullRegionByteMultiplier; + device->zcull_info.zcull_region_header_size = zcull_info->zcullRegionHeaderSize; + device->zcull_info.zcull_subregion_header_size = zcull_info->zcullSubregionHeaderSize; + device->zcull_info.subregion_count = zcull_info->subregionCount; + device->zcull_info.subregion_width_align_pixels = zcull_info->subregionWidthAlignPixels; + device->zcull_info.subregion_height_align_pixels = zcull_info->subregionHeightAlignPixels; + + device->zcull_info.ctxsw_size = zcull_ctxsw_size; + device->zcull_info.ctxsw_align = zcull_ctxsw_align; + +nvkm_gsp_rm_ctrl_done (&gsp->internal.device.subdevice, zcull_info); + done:nvkm_gsp_rm_free (&golden.chan);for (int i = gr->ctxbuf_nr -1 ; i >=0 ; i--)
include/uapi/drm/nouveau_drm.h +19 -0
@@ -432,6 +432,22 @@ struct drm_nouveau_exec {__u64 push_ptr; }; +struct drm_nouveau_get_zcull_info { +__u32 width_align_pixels; +__u32 height_align_pixels; +__u32 pixel_squares_by_aliquots; +__u32 aliquot_total; +__u32 zcull_region_byte_multiplier; +__u32 zcull_region_header_size; +__u32 zcull_subregion_header_size; +__u32 subregion_count; +__u32 subregion_width_align_pixels; +__u32 subregion_height_align_pixels; + +__u32 ctxsw_size; +__u32 ctxsw_align; +}; +#define DRM_NOUVEAU_GETPARAM 0x00#define DRM_NOUVEAU_SETPARAM 0x01/* deprecated */ #define DRM_NOUVEAU_CHANNEL_ALLOC 0x02
@@ -445,6 +461,7 @@ struct drm_nouveau_exec {#define DRM_NOUVEAU_VM_INIT 0x10#define DRM_NOUVEAU_VM_BIND 0x11#define DRM_NOUVEAU_EXEC 0x12 +#define DRM_NOUVEAU_GET_ZCULL_INFO 0x13#define DRM_NOUVEAU_GEM_NEW 0x40#define DRM_NOUVEAU_GEM_PUSHBUF 0x41#define DRM_NOUVEAU_GEM_CPU_PREP 0x42
@@ -513,6 +530,8 @@ struct drm_nouveau_svm_bind {#define DRM_IOCTL_NOUVEAU_VM_INIT DRM_IOWR(DRM_COMMAND_BASE + DRM_NOUVEAU_VM_INIT, struct drm_nouveau_vm_init)#define DRM_IOCTL_NOUVEAU_VM_BIND DRM_IOWR(DRM_COMMAND_BASE + DRM_NOUVEAU_VM_BIND, struct drm_nouveau_vm_bind)#define DRM_IOCTL_NOUVEAU_EXEC DRM_IOWR(DRM_COMMAND_BASE + DRM_NOUVEAU_EXEC, struct drm_nouveau_exec) + +#define DRM_IOCTL_NOUVEAU_GET_ZCULL_INFO DRM_IOR (DRM_COMMAND_BASE + DRM_NOUVEAU_GET_ZCULL_INFO, struct drm_nouveau_get_zcull_info)#if defined(__cplusplus) }#endif
Signature · 1 line
2.48.1
Danilo Krummrich
maintainerRe: [PATCH 1/2] drm/nouveau: Add DRM_IOCTL_NOUVEAU_GET_ZCULL_INFO
Hi Mel,
Quoted 1 line · Mel Henning
Userspace needs this information to set up zcull correctly.
This is a very brief motivation for the commit, please also describe what the commit does using imperative form.
Quoted 27 lines
Signed-off-by Mel Henning <[email protected]>--- .../drm/nouveau/include/nvkm/core/device.h | 6 ++ .../sdk/nvidia/inc/ctrl/ctrl2080/ctrl2080gr.h | 69 +++++++++++++++++++ drivers/gpu/drm/nouveau/nouveau_abi16.c | 15 ++++ drivers/gpu/drm/nouveau/nouveau_abi16.h | 1 + drivers/gpu/drm/nouveau/nouveau_drm.c | 1 + drivers/gpu/drm/nouveau/nvkm/engine/gr/r535.c | 34 +++++++++ include/uapi/drm/nouveau_drm.h | 19 +++++ 7 files changed, 145 insertions(+)drivers/gpu/drm/nouveau/include/nvkm/core/device.h +3
-0@@ -3,6 +3,9 @@#define __NVKM_DEVICE_H__#include <core/oclass.h> #include <core/intr.h> + +#include "uapi/drm/nouveau_drm.h" +enum nvkm_subdev_type ;enum nvkm_device_type {
drivers/gpu/drm/nouveau/include/nvkm/core/device.h struct nvkm_device { · line 80
Quoted 6 lines
drivers/gpu/drm/nouveau/include/nvkm/core/device.h +3
-0@@ -72,6 +75,9 @@ struct nvkm_device {bool armed;bool legacy_done; } intr; + +bool has_zcull_info; +struct drm_nouveau_get_zcull_info zcull_info;
This is bypassing the nvif layer entirely. I think you should store the contents of struct NV2080_CTRL_GR_GET_ZCULL_INFO_PARAMS in struct r535_gr and have an nvif interface to access the data.
Quoted 90 lines
drivers/gpu/drm/nouveau/include/nvkm/core/device.h +0
-0};struct nvkm_subdev *nvkm_device_subdev (struct nvkm_device *,int type,int inst);drivers/gpu/drm/nouveau/include/nvrm/535.113.01/common/sdk/nvidia/inc/ctrl/ctrl2080/ctrl2080gr.h +69
-0@@ -26,6 +26,75 @@* DEALINGS IN THE SOFTWARE. */ +/** +* NV2080_CTRL_CMD_GR_GET_ZCULL_INFO +* +* This command is used to query the RM for zcull information that the +* driver will need to allocate and manage the zcull regions. +* +* widthAlignPixels +* This parameter returns the width alignment restrictions in pixels +* used to adjust a surface for proper aliquot coverage (typically +* #TPC's * 16). +* +* heightAlignPixels +* This parameter returns the height alignment restrictions in pixels +* used to adjust a surface for proper aliquot coverage (typically 32). +* +* pixelSquaresByAliquots +* This parameter returns the pixel area covered by an aliquot +* (typically #Zcull_banks * 16 * 16). +* +* aliquotTotal +* This parameter returns the total aliquot pool available in HW. +* +* zcullRegionByteMultiplier +* This parameter returns multiplier used to convert aliquots in a region +* to the number of bytes required to save/restore them. +* +* zcullRegionHeaderSize +* This parameter returns the region header size which is required to be +* allocated and accounted for in any save/restore operation on a region. +* +* zcullSubregionHeaderSize +* This parameter returns the subregion header size which is required to be +* allocated and accounted for in any save/restore operation on a region. +* +* subregionCount +* This parameter returns the subregion count. +* +* subregionWidthAlignPixels +* This parameter returns the subregion width alignment restrictions in +* pixels used to adjust a surface for proper aliquot coverage +* (typically #TPC's * 16). +* +* subregionHeightAlignPixels +* This parameter returns the subregion height alignment restrictions in +* pixels used to adjust a surface for proper aliquot coverage +* (typically 62). +* +* The callee should compute the size of a zcull region as follows. +* (numBytes = aliquots * zcullRegionByteMultiplier + +* zcullRegionHeaderSize + zcullSubregionHeaderSize) +*/ +#define NV2080_CTRL_CMD_GR_GET_ZCULL_INFO (0x20801206U)/* finn: Evaluated from "(FINN_NV20_SUBDEVICE_0_GR_INTERFACE_ID << 8) | NV2080_CTRL_GR_GET_ZCULL_INFO_PARAMS_MESSAGE_ID" */ + +#define NV2080_CTRL_GR_GET_ZCULL_INFO_PARAMS_SUBREGION_SUPPORTED +#define NV2080_CTRL_GR_GET_ZCULL_INFO_PARAMS_MESSAGE_ID (0x6U) + +typedef struct NV2080_CTRL_GR_GET_ZCULL_INFO_PARAMS { +NvU32 widthAlignPixels; +NvU32 heightAlignPixels; +NvU32 pixelSquaresByAliquots; +NvU32 aliquotTotal; +NvU32 zcullRegionByteMultiplier; +NvU32 zcullRegionHeaderSize; +NvU32 zcullSubregionHeaderSize; +NvU32 subregionCount; +NvU32 subregionWidthAlignPixels; +NvU32 subregionHeightAlignPixels; +}NV2080_CTRL_GR_GET_ZCULL_INFO_PARAMS ; + typedef enum NV2080_CTRL_CMD_GR_CTXSW_PREEMPTION_BIND_BUFFERS { NV2080_CTRL_CMD_GR_CTXSW_PREEMPTION_BIND_BUFFERS_MAIN = 0, NV2080_CTRL_CMD_GR_CTXSW_PREEMPTION_BIND_BUFFERS_SPILL = 1,drivers/gpu/drm/nouveau/nouveau_abi16.c +0
-0@@ -333,6 +333,21 @@ nouveau_abi16_ioctl_getparam(ABI16_IOCTL_ARGS)return 0 ; }
drivers/gpu/drm/nouveau/nouveau_abi16.c nouveau_abi16_ioctl_getparam(ABI16_IOCTL_ARGS) · line 344
Quoted 10 lines
drivers/gpu/drm/nouveau/nouveau_abi16.c +9
-0+int +nouveau_abi16_ioctl_get_zcull_info (ABI16_IOCTL_ARGS ) +{ +struct nouveau_drm *drm =nouveau_drm (dev); +struct nvkm_device *device = drm->nvkm; +struct drm_nouveau_get_zcull_info *out = data; + +if (device->has_zcull_info) { + *out = device->zcull_info;
This needs copy_to_user().
Quoted 85 lines
drivers/gpu/drm/nouveau/nouveau_abi16.c +6
-0+return 0 ; + }else { +return -ENODEV ; + } +} +int nouveau_abi16_ioctl_channel_alloc (ABI16_IOCTL_ARGS ) {drivers/gpu/drm/nouveau/nouveau_abi16.h +1
-0@@ -6,6 +6,7 @@ struct drm_device *dev, void *data, struct drm_file *file_privint nouveau_abi16_ioctl_getparam (ABI16_IOCTL_ARGS ); +int nouveau_abi16_ioctl_get_zcull_info (ABI16_IOCTL_ARGS );int nouveau_abi16_ioctl_channel_alloc (ABI16_IOCTL_ARGS );int nouveau_abi16_ioctl_channel_free (ABI16_IOCTL_ARGS );int nouveau_abi16_ioctl_grobj_alloc (ABI16_IOCTL_ARGS );drivers/gpu/drm/nouveau/nouveau_drm.c +1
-0@@ -1244,6 +1244,7 @@ nouveau_ioctls[] = {DRM_IOCTL_DEF_DRV (NOUVEAU_GROBJ_ALLOC , nouveau_abi16_ioctl_grobj_alloc,DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (NOUVEAU_NOTIFIEROBJ_ALLOC , nouveau_abi16_ioctl_notifierobj_alloc,DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (NOUVEAU_GPUOBJ_FREE , nouveau_abi16_ioctl_gpuobj_free,DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (NOUVEAU_GET_ZCULL_INFO , nouveau_abi16_ioctl_get_zcull_info,DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (NOUVEAU_SVM_INIT , nouveau_svmm_init,DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (NOUVEAU_SVM_BIND , nouveau_svmm_bind,DRM_RENDER_ALLOW ), DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_NEW, nouveau_gem_ioctl_new, DRM_RENDER_ALLOW),drivers/gpu/drm/nouveau/nvkm/engine/gr/r535.c +23
-0@@ -34,6 +34,7 @@#include <nvrm/535.113.01/common/sdk/nvidia/inc/alloc/alloc_channel.h> #include <nvrm/535.113.01/common/sdk/nvidia/inc/ctrl/ctrl0080/ctrl0080fifo.h> #include <nvrm/535.113.01/common/sdk/nvidia/inc/ctrl/ctrl2080/ctrl2080gpu.h> +#include <nvrm/535.113.01/common/sdk/nvidia/inc/ctrl/ctrl2080/ctrl2080gr.h> #include <nvrm/535.113.01/common/sdk/nvidia/inc/ctrl/ctrl2080/ctrl2080internal.h> #include <nvrm/535.113.01/nvidia/generated/g_kernel_channel_nvoc.h> @@ -244,6 +245,8 @@ static int r535_gr_oneinit(struct nvkm_gr *base) {NV2080_CTRL_INTERNAL_STATIC_GR_GET_CONTEXT_BUFFERS_INFO_PARAMS *info; +NV2080_CTRL_GR_GET_ZCULL_INFO_PARAMS *zcull_info; +u32 zcull_ctxsw_size, zcull_ctxsw_align;struct r535_gr *gr =container_of (base,typeof (*gr), base);struct nvkm_subdev *subdev = &gr->base.engine.subdev;struct nvkm_device *device = subdev->device;@@ -418,6 +421,11 @@ r535_gr_oneinit(struct nvkm_gr *base) } } + zcull_ctxsw_size = info->engineContextBuffersInfo[0 ] + .engine[NV0080_CTRL_FIFO_GET_ENGINE_CONTEXT_PROPERTIES_ENGINE_ID_GRAPHICS_ZCULL ].size; + zcull_ctxsw_align = info->engineContextBuffersInfo[0 ] + .engine[NV0080_CTRL_FIFO_GET_ENGINE_CONTEXT_PROPERTIES_ENGINE_ID_GRAPHICS_ZCULL ].alignment; +nvkm_gsp_rm_ctrl_done (&gsp->internal.device.subdevice, info);/* Promote golden context to RM. */ @@ -450,6 +458,32 @@ r535_gr_oneinit(struct nvkm_gr *base) } } + zcull_info =nvkm_gsp_rm_ctrl_rd (&gsp->internal.device.subdevice, +NV2080_CTRL_CMD_GR_GET_ZCULL_INFO , +sizeof (*zcull_info)); +if (WARN_ON (IS_ERR (zcull_info))) { + ret =PTR_ERR (zcull_info); + goto done; + } + + device->has_zcull_info = true; + + device->zcull_info.width_align_pixels = zcull_info->widthAlignPixels; + device->zcull_info.height_align_pixels = zcull_info->heightAlignPixels; + device->zcull_info.pixel_squares_by_aliquots = zcull_info->pixelSquaresByAliquots; + device->zcull_info.aliquot_total = zcull_info->aliquotTotal; + device->zcull_info.zcull_region_byte_multiplier = zcull_info->zcullRegionByteMultiplier;
drivers/gpu/drm/nouveau/nvkm/engine/gr/r535.c r535_gr_oneinit(struct nvkm_gr *base) · line 485
Quoted 10 lines
drivers/gpu/drm/nouveau/nvkm/engine/gr/r535.c +10
-0+ device->zcull_info.zcull_region_header_size = zcull_info->zcullRegionHeaderSize; + device->zcull_info.zcull_subregion_header_size = zcull_info->zcullSubregionHeaderSize; + device->zcull_info.subregion_count = zcull_info->subregionCount; + device->zcull_info.subregion_width_align_pixels = zcull_info->subregionWidthAlignPixels; + device->zcull_info.subregion_height_align_pixels = zcull_info->subregionHeightAlignPixels; + + device->zcull_info.ctxsw_size = zcull_ctxsw_size; + device->zcull_info.ctxsw_align = zcull_ctxsw_align; + +nvkm_gsp_rm_ctrl_done (&gsp->internal.device.subdevice, zcull_info);
Please move this to a separate function.
include/uapi/drm/nouveau_drm.h
Quoted 8 lines
drivers/gpu/drm/nouveau/nvkm/engine/gr/r535.c +1
-0+ done:nvkm_gsp_rm_free (&golden.chan);for (int i = gr->ctxbuf_nr -1 ; i >=0 ; i--)include/uapi/drm/nouveau_drm.h +0
-0
Please do the uAPI change in a separate commit.
include/uapi/drm/nouveau_drm.h struct drm_nouveau_exec { · line 435
Quoted 5 lines
include/uapi/drm/nouveau_drm.h +1
-0@@ -432,6 +432,22 @@ struct drm_nouveau_exec {__u64 push_ptr; }; +struct drm_nouveau_get_zcull_info {
Please add some documentation to this structure.
Quoted 4 lines
include/uapi/drm/nouveau_drm.h +4
-0+__u32 width_align_pixels; +__u32 height_align_pixels; +__u32 pixel_squares_by_aliquots; +__u32 aliquot_total;
include/uapi/drm/nouveau_drm.h struct drm_nouveau_exec { · line 449
Quoted 10 lines
include/uapi/drm/nouveau_drm.h +10
-0+__u32 zcull_region_byte_multiplier; +__u32 zcull_region_header_size; +__u32 zcull_subregion_header_size; +__u32 subregion_count; +__u32 subregion_width_align_pixels; +__u32 subregion_height_align_pixels; + +__u32 ctxsw_size; +__u32 ctxsw_align; +};
What if this ever changes between hardware revisions or firmware versions?
Quoted 24 lines
include/uapi/drm/nouveau_drm.h +4
-0+#define DRM_NOUVEAU_GETPARAM 0x00#define DRM_NOUVEAU_SETPARAM 0x01/* deprecated */ #define DRM_NOUVEAU_CHANNEL_ALLOC 0x02@@ -445,6 +461,7 @@ struct drm_nouveau_exec {#define DRM_NOUVEAU_VM_INIT 0x10#define DRM_NOUVEAU_VM_BIND 0x11#define DRM_NOUVEAU_EXEC 0x12 +#define DRM_NOUVEAU_GET_ZCULL_INFO 0x13#define DRM_NOUVEAU_GEM_NEW 0x40#define DRM_NOUVEAU_GEM_PUSHBUF 0x41#define DRM_NOUVEAU_GEM_CPU_PREP 0x42@@ -513,6 +530,8 @@ struct drm_nouveau_svm_bind {#define DRM_IOCTL_NOUVEAU_VM_INIT DRM_IOWR(DRM_COMMAND_BASE + DRM_NOUVEAU_VM_INIT, struct drm_nouveau_vm_init)#define DRM_IOCTL_NOUVEAU_VM_BIND DRM_IOWR(DRM_COMMAND_BASE + DRM_NOUVEAU_VM_BIND, struct drm_nouveau_vm_bind)#define DRM_IOCTL_NOUVEAU_EXEC DRM_IOWR(DRM_COMMAND_BASE + DRM_NOUVEAU_EXEC, struct drm_nouveau_exec) + +#define DRM_IOCTL_NOUVEAU_GET_ZCULL_INFO DRM_IOR (DRM_COMMAND_BASE + DRM_NOUVEAU_GET_ZCULL_INFO, struct drm_nouveau_get_zcull_info)#if defined(__cplusplus) }#endif Signature · 1 line
2.48.1
Danilo Krummrich
maintainerRe: [PATCH 1/2] drm/nouveau: Add DRM_IOCTL_NOUVEAU_GET_ZCULL_INFO
Quoted 14 lines · Danilo Krummrich
Hi Mel,
drivers/gpu/drm/nouveau/nouveau_abi16.c nouveau_abi16_ioctl_getparam(ABI16_IOCTL_ARGS) · line 344
Quoted 9 lines · Mel Henning
drivers/gpu/drm/nouveau/nouveau_abi16.c +9
-0+int +nouveau_abi16_ioctl_get_zcull_info (ABI16_IOCTL_ARGS ) +{ +struct nouveau_drm *drm =nouveau_drm (dev); +struct nvkm_device *device = drm->nvkm; +struct drm_nouveau_get_zcull_info *out = data; + +if (device->has_zcull_info) { + *out = device->zcull_info;This needs
copy_to_user().
Sorry, had the wrong context, drm_ioctl() should already take care of that.
Re: [PATCH 1/2] drm/nouveau: Add DRM_IOCTL_NOUVEAU_GET_ZCULL_INFO
In reply to Danilo KrummrichQuoted 31 lines · Danilo Krummrich
Hi Mel,
Quoted 1 line · Mel Henning
Userspace needs this information to set up zcull correctly.
This is a very brief motivation for the commit, please also describe what the commit does using imperative form.
Quoted 24 lines
Signed-off-by Mel Henning <[email protected]>--- .../drm/nouveau/include/nvkm/core/device.h | 6 ++ .../sdk/nvidia/inc/ctrl/ctrl2080/ctrl2080gr.h | 69 +++++++++++++++++++ drivers/gpu/drm/nouveau/nouveau_abi16.c | 15 ++++ drivers/gpu/drm/nouveau/nouveau_abi16.h | 1 + drivers/gpu/drm/nouveau/nouveau_drm.c | 1 + drivers/gpu/drm/nouveau/nvkm/engine/gr/r535.c | 34 +++++++++ include/uapi/drm/nouveau_drm.h | 19 +++++ 7 files changed, 145 insertions(+)drivers/gpu/drm/nouveau/include/nvkm/core/device.h +3
-0@@ -3,6 +3,9 @@#define __NVKM_DEVICE_H__#include <core/oclass.h> #include <core/intr.h> + +#include "uapi/drm/nouveau_drm.h" +enum nvkm_subdev_type ;
Quoted 11 lines
drivers/gpu/drm/nouveau/include/nvkm/core/device.h struct nvkm_device { · line 80
Quoted 8 lines
drivers/gpu/drm/nouveau/include/nvkm/core/device.h +3
-0enum nvkm_device_type {@@ -72,6 +75,9 @@ struct nvkm_device {bool armed;bool legacy_done; } intr; + +bool has_zcull_info; +struct drm_nouveau_get_zcull_info zcull_info;This is bypassing the nvif layer entirely. I think you should store the contents of struct
NV2080_CTRL_GR_GET_ZCULL_INFO_PARAMSin structr535_grand have an nvif interface to access the data.
I agree here, though nvkm_gr would be a better choice for a couple of reasons, not least that it's possible (and should be reasonably trivial) to support this on earlier GPUs - should someone desire to at a later point.
Ben.
Quoted 257 lines
Quoted 91 lines
drivers/gpu/drm/nouveau/include/nvkm/core/device.h +0
-0};struct nvkm_subdev *nvkm_device_subdev (struct nvkm_device *,int type,int inst);drivers/gpu/drm/nouveau/include/nvrm/535.113.01/common/sdk/nvidia/inc/ctrl/ctrl2080/ctrl2080gr.h +69
-0@@ -26,6 +26,75 @@* DEALINGS IN THE SOFTWARE. */ +/** +* NV2080_CTRL_CMD_GR_GET_ZCULL_INFO +* +* This command is used to query the RM for zcull information that the +* driver will need to allocate and manage the zcull regions. +* +* widthAlignPixels +* This parameter returns the width alignment restrictions in pixels +* used to adjust a surface for proper aliquot coverage (typically +* #TPC's * 16). +* +* heightAlignPixels +* This parameter returns the height alignment restrictions in pixels +* used to adjust a surface for proper aliquot coverage (typically 32). +* +* pixelSquaresByAliquots +* This parameter returns the pixel area covered by an aliquot +* (typically #Zcull_banks * 16 * 16). +* +* aliquotTotal +* This parameter returns the total aliquot pool available in HW. +* +* zcullRegionByteMultiplier +* This parameter returns multiplier used to convert aliquots in a region +* to the number of bytes required to save/restore them. +* +* zcullRegionHeaderSize +* This parameter returns the region header size which is required to be +* allocated and accounted for in any save/restore operation on a region. +* +* zcullSubregionHeaderSize +* This parameter returns the subregion header size which is required to be +* allocated and accounted for in any save/restore operation on a region. +* +* subregionCount +* This parameter returns the subregion count. +* +* subregionWidthAlignPixels +* This parameter returns the subregion width alignment restrictions in +* pixels used to adjust a surface for proper aliquot coverage +* (typically #TPC's * 16). +* +* subregionHeightAlignPixels +* This parameter returns the subregion height alignment restrictions in +* pixels used to adjust a surface for proper aliquot coverage +* (typically 62). +* +* The callee should compute the size of a zcull region as follows. +* (numBytes = aliquots * zcullRegionByteMultiplier + +* zcullRegionHeaderSize + zcullSubregionHeaderSize) +*/ +#define NV2080_CTRL_CMD_GR_GET_ZCULL_INFO (0x20801206U)/* finn: Evaluated from "(FINN_NV20_SUBDEVICE_0_GR_INTERFACE_ID << 8) | NV2080_CTRL_GR_GET_ZCULL_INFO_PARAMS_MESSAGE_ID" */ + +#define NV2080_CTRL_GR_GET_ZCULL_INFO_PARAMS_SUBREGION_SUPPORTED +#define NV2080_CTRL_GR_GET_ZCULL_INFO_PARAMS_MESSAGE_ID (0x6U) + +typedef struct NV2080_CTRL_GR_GET_ZCULL_INFO_PARAMS { +NvU32 widthAlignPixels; +NvU32 heightAlignPixels; +NvU32 pixelSquaresByAliquots; +NvU32 aliquotTotal; +NvU32 zcullRegionByteMultiplier; +NvU32 zcullRegionHeaderSize; +NvU32 zcullSubregionHeaderSize; +NvU32 subregionCount; +NvU32 subregionWidthAlignPixels; +NvU32 subregionHeightAlignPixels; +}NV2080_CTRL_GR_GET_ZCULL_INFO_PARAMS ; + typedef enum NV2080_CTRL_CMD_GR_CTXSW_PREEMPTION_BIND_BUFFERS { NV2080_CTRL_CMD_GR_CTXSW_PREEMPTION_BIND_BUFFERS_MAIN = 0, NV2080_CTRL_CMD_GR_CTXSW_PREEMPTION_BIND_BUFFERS_SPILL = 1,drivers/gpu/drm/nouveau/nouveau_abi16.c +0
-0@@ -333,6 +333,21 @@ nouveau_abi16_ioctl_getparam(ABI16_IOCTL_ARGS)return 0 ; }drivers/gpu/drm/nouveau/nouveau_abi16.c nouveau_abi16_ioctl_getparam(ABI16_IOCTL_ARGS) · line 344
Quoted 10 lines
drivers/gpu/drm/nouveau/nouveau_abi16.c +9
-0+int +nouveau_abi16_ioctl_get_zcull_info (ABI16_IOCTL_ARGS ) +{ +struct nouveau_drm *drm =nouveau_drm (dev); +struct nvkm_device *device = drm->nvkm; +struct drm_nouveau_get_zcull_info *out = data; + +if (device->has_zcull_info) { + *out = device->zcull_info;This needs
copy_to_user().Quoted 85 lines
drivers/gpu/drm/nouveau/nouveau_abi16.c +6
-0+return 0 ; + }else { +return -ENODEV ; + } +} +int nouveau_abi16_ioctl_channel_alloc (ABI16_IOCTL_ARGS ) {drivers/gpu/drm/nouveau/nouveau_abi16.h +1
-0@@ -6,6 +6,7 @@ struct drm_device *dev, void *data, struct drm_file *file_privint nouveau_abi16_ioctl_getparam (ABI16_IOCTL_ARGS ); +int nouveau_abi16_ioctl_get_zcull_info (ABI16_IOCTL_ARGS );int nouveau_abi16_ioctl_channel_alloc (ABI16_IOCTL_ARGS );int nouveau_abi16_ioctl_channel_free (ABI16_IOCTL_ARGS );int nouveau_abi16_ioctl_grobj_alloc (ABI16_IOCTL_ARGS );drivers/gpu/drm/nouveau/nouveau_drm.c +1
-0@@ -1244,6 +1244,7 @@ nouveau_ioctls[] = {DRM_IOCTL_DEF_DRV (NOUVEAU_GROBJ_ALLOC , nouveau_abi16_ioctl_grobj_alloc,DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (NOUVEAU_NOTIFIEROBJ_ALLOC , nouveau_abi16_ioctl_notifierobj_alloc,DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (NOUVEAU_GPUOBJ_FREE , nouveau_abi16_ioctl_gpuobj_free,DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (NOUVEAU_GET_ZCULL_INFO , nouveau_abi16_ioctl_get_zcull_info,DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (NOUVEAU_SVM_INIT , nouveau_svmm_init,DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (NOUVEAU_SVM_BIND , nouveau_svmm_bind,DRM_RENDER_ALLOW ), DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_NEW, nouveau_gem_ioctl_new, DRM_RENDER_ALLOW),drivers/gpu/drm/nouveau/nvkm/engine/gr/r535.c +23
-0@@ -34,6 +34,7 @@#include <nvrm/535.113.01/common/sdk/nvidia/inc/alloc/alloc_channel.h> #include <nvrm/535.113.01/common/sdk/nvidia/inc/ctrl/ctrl0080/ctrl0080fifo.h> #include <nvrm/535.113.01/common/sdk/nvidia/inc/ctrl/ctrl2080/ctrl2080gpu.h> +#include <nvrm/535.113.01/common/sdk/nvidia/inc/ctrl/ctrl2080/ctrl2080gr.h> #include <nvrm/535.113.01/common/sdk/nvidia/inc/ctrl/ctrl2080/ctrl2080internal.h> #include <nvrm/535.113.01/nvidia/generated/g_kernel_channel_nvoc.h> @@ -244,6 +245,8 @@ static int r535_gr_oneinit(struct nvkm_gr *base) {NV2080_CTRL_INTERNAL_STATIC_GR_GET_CONTEXT_BUFFERS_INFO_PARAMS *info; +NV2080_CTRL_GR_GET_ZCULL_INFO_PARAMS *zcull_info; +u32 zcull_ctxsw_size, zcull_ctxsw_align;struct r535_gr *gr =container_of (base,typeof (*gr), base);struct nvkm_subdev *subdev = &gr->base.engine.subdev;struct nvkm_device *device = subdev->device;@@ -418,6 +421,11 @@ r535_gr_oneinit(struct nvkm_gr *base) } } + zcull_ctxsw_size = info->engineContextBuffersInfo[0 ] + .engine[NV0080_CTRL_FIFO_GET_ENGINE_CONTEXT_PROPERTIES_ENGINE_ID_GRAPHICS_ZCULL ].size; + zcull_ctxsw_align = info->engineContextBuffersInfo[0 ] + .engine[NV0080_CTRL_FIFO_GET_ENGINE_CONTEXT_PROPERTIES_ENGINE_ID_GRAPHICS_ZCULL ].alignment; +nvkm_gsp_rm_ctrl_done (&gsp->internal.device.subdevice, info);/* Promote golden context to RM. */ @@ -450,6 +458,32 @@ r535_gr_oneinit(struct nvkm_gr *base) } } + zcull_info =nvkm_gsp_rm_ctrl_rd (&gsp->internal.device.subdevice, +NV2080_CTRL_CMD_GR_GET_ZCULL_INFO , +sizeof (*zcull_info)); +if (WARN_ON (IS_ERR (zcull_info))) { + ret =PTR_ERR (zcull_info); + goto done; + } + + device->has_zcull_info = true; + + device->zcull_info.width_align_pixels = zcull_info->widthAlignPixels; + device->zcull_info.height_align_pixels = zcull_info->heightAlignPixels; + device->zcull_info.pixel_squares_by_aliquots = zcull_info->pixelSquaresByAliquots; + device->zcull_info.aliquot_total = zcull_info->aliquotTotal; + device->zcull_info.zcull_region_byte_multiplier = zcull_info->zcullRegionByteMultiplier;drivers/gpu/drm/nouveau/nvkm/engine/gr/r535.c r535_gr_oneinit(struct nvkm_gr *base) · line 485
Quoted 10 lines
drivers/gpu/drm/nouveau/nvkm/engine/gr/r535.c +10
-0+ device->zcull_info.zcull_region_header_size = zcull_info->zcullRegionHeaderSize; + device->zcull_info.zcull_subregion_header_size = zcull_info->zcullSubregionHeaderSize; + device->zcull_info.subregion_count = zcull_info->subregionCount; + device->zcull_info.subregion_width_align_pixels = zcull_info->subregionWidthAlignPixels; + device->zcull_info.subregion_height_align_pixels = zcull_info->subregionHeightAlignPixels; + + device->zcull_info.ctxsw_size = zcull_ctxsw_size; + device->zcull_info.ctxsw_align = zcull_ctxsw_align; + +nvkm_gsp_rm_ctrl_done (&gsp->internal.device.subdevice, zcull_info);Please move this to a separate function.
include/uapi/drm/nouveau_drm.h
Quoted 8 lines
drivers/gpu/drm/nouveau/nvkm/engine/gr/r535.c +1
-0+ done:nvkm_gsp_rm_free (&golden.chan);for (int i = gr->ctxbuf_nr -1 ; i >=0 ; i--)include/uapi/drm/nouveau_drm.h +0
-0Please do the uAPI change in a separate commit.
include/uapi/drm/nouveau_drm.h struct drm_nouveau_exec { · line 435
Quoted 5 lines
include/uapi/drm/nouveau_drm.h +1
-0@@ -432,6 +432,22 @@ struct drm_nouveau_exec {__u64 push_ptr; }; +struct drm_nouveau_get_zcull_info {Please add some documentation to this structure.
Quoted 4 lines
include/uapi/drm/nouveau_drm.h +4
-0+__u32 width_align_pixels; +__u32 height_align_pixels; +__u32 pixel_squares_by_aliquots; +__u32 aliquot_total;include/uapi/drm/nouveau_drm.h struct drm_nouveau_exec { · line 449
Quoted 10 lines
include/uapi/drm/nouveau_drm.h +10
-0+__u32 zcull_region_byte_multiplier; +__u32 zcull_region_header_size; +__u32 zcull_subregion_header_size; +__u32 subregion_count; +__u32 subregion_width_align_pixels; +__u32 subregion_height_align_pixels; + +__u32 ctxsw_size; +__u32 ctxsw_align; +};What if this ever changes between hardware revisions or firmware versions?
Quoted 24 lines
include/uapi/drm/nouveau_drm.h +4
-0+#define DRM_NOUVEAU_GETPARAM 0x00#define DRM_NOUVEAU_SETPARAM 0x01/* deprecated */ #define DRM_NOUVEAU_CHANNEL_ALLOC 0x02@@ -445,6 +461,7 @@ struct drm_nouveau_exec {#define DRM_NOUVEAU_VM_INIT 0x10#define DRM_NOUVEAU_VM_BIND 0x11#define DRM_NOUVEAU_EXEC 0x12 +#define DRM_NOUVEAU_GET_ZCULL_INFO 0x13#define DRM_NOUVEAU_GEM_NEW 0x40#define DRM_NOUVEAU_GEM_PUSHBUF 0x41#define DRM_NOUVEAU_GEM_CPU_PREP 0x42@@ -513,6 +530,8 @@ struct drm_nouveau_svm_bind {#define DRM_IOCTL_NOUVEAU_VM_INIT DRM_IOWR(DRM_COMMAND_BASE + DRM_NOUVEAU_VM_INIT, struct drm_nouveau_vm_init)#define DRM_IOCTL_NOUVEAU_VM_BIND DRM_IOWR(DRM_COMMAND_BASE + DRM_NOUVEAU_VM_BIND, struct drm_nouveau_vm_bind)#define DRM_IOCTL_NOUVEAU_EXEC DRM_IOWR(DRM_COMMAND_BASE + DRM_NOUVEAU_EXEC, struct drm_nouveau_exec) + +#define DRM_IOCTL_NOUVEAU_GET_ZCULL_INFO DRM_IOR (DRM_COMMAND_BASE + DRM_NOUVEAU_GET_ZCULL_INFO, struct drm_nouveau_get_zcull_info)#if defined(__cplusplus) }#endif Signature · 1 line
2.48.1
Danilo Krummrich
maintainerRe: [PATCH 1/2] drm/nouveau: Add DRM_IOCTL_NOUVEAU_GET_ZCULL_INFO
Quoted 17 lines · Ben Skeggs
Quoted 4 lines · Danilo Krummrich
Hi Mel,
On Wed, Mar 12, 2025 at 05:36:14PM -0400, Mel Henning wrote:
Quoted 10 lines
drivers/gpu/drm/nouveau/include/nvkm/core/device.h struct nvkm_device { · line 80
Quoted 7 lines
drivers/gpu/drm/nouveau/include/nvkm/core/device.h +3
-0@@ -72,6 +75,9 @@ struct nvkm_device {bool armed;bool legacy_done; } intr; + +bool has_zcull_info; +struct drm_nouveau_get_zcull_info zcull_info;This is bypassing the nvif layer entirely. I think you should store the contents of struct
NV2080_CTRL_GR_GET_ZCULL_INFO_PARAMSin structr535_grand have an nvif interface to access the data.
Quoted 3 lines
I agree here, though
nvkm_grwould be a better choice for a couple of reasons, not least that it's possible (and should be reasonably trivial) to support this on earlier GPUs - should someone desire to at a later point.
I agree, if the interface is stable enough -- I don't know whether this is prone to change or not.
Re: [PATCH 1/2] drm/nouveau: Add DRM_IOCTL_NOUVEAU_GET_ZCULL_INFO
Okay, that sounds reasonable since I don't expect this to change very quickly.
Since I don't fully understand, is the suggestion here to:
1) add the interface as a function on nvkm_gr using the nvkm_gr_func vtable and store the actual data on r535_gr
or
2) add the interface to NVIF (which IF?) and store the actual data on nvkm_gr ?
(Sorry, I don't understand how these layers are intended to fit together.))
Quoted 25 lines · Danilo Krummrich
Quoted 17 lines · Ben Skeggs
Quoted 4 lines · Danilo Krummrich
Hi Mel,
On Wed, Mar 12, 2025 at 05:36:14PM -0400, Mel Henning wrote:
Quoted 10 lines
drivers/gpu/drm/nouveau/include/nvkm/core/device.h struct nvkm_device { · line 80
Quoted 7 lines
drivers/gpu/drm/nouveau/include/nvkm/core/device.h +3
-0@@ -72,6 +75,9 @@ struct nvkm_device {bool armed;bool legacy_done; } intr; + +bool has_zcull_info; +struct drm_nouveau_get_zcull_info zcull_info;This is bypassing the nvif layer entirely. I think you should store the contents of struct
NV2080_CTRL_GR_GET_ZCULL_INFO_PARAMSin structr535_grand have an nvif interface to access the data.Quoted 3 lines
I agree here, though
nvkm_grwould be a better choice for a couple of reasons, not least that it's possible (and should be reasonably trivial) to support this on earlier GPUs - should someone desire to at a later point.I agree, if the interface is stable enough -- I don't know whether this is prone to change or not.
Danilo Krummrich
maintainerRe: [PATCH 1/2] drm/nouveau: Add DRM_IOCTL_NOUVEAU_GET_ZCULL_INFO
Quoted 8 lines · M Henning
Okay, that sounds reasonable since I don't expect this to change very quickly.
Since I don't fully understand, is the suggestion here to:
1) add the interface as a function onnvkm_grusing thenvkm_gr_funcvtable and store the actual data onr535_gr
or
2) add the interface to NVIF (which IF?) and store the actual data onnvkm_gr?
I think we want both.
1) I think the suggestion was to store the data directly in nvkm_gr, however the structure is indeed specific to r535, so I think, unfortunately, we need the vtable and store that data in r535_gr.
2) Yes, this should be passed through nvif. Unfortunately, I think it would need to be a whole new one (similar to the fifo one).
Maybe Ben can provide you some additional pointers one this? Mayber he can suggest a shortcut, since he has patches queued to simplify the whole interface.
Quoted 29 lines
(Sorry, I don't understand how these layers are intended to fit together.))
Quoted 25 lines · Danilo Krummrich
Quoted 17 lines · Ben Skeggs
Quoted 4 lines · Danilo Krummrich
Hi Mel,
On Wed, Mar 12, 2025 at 05:36:14PM -0400, Mel Henning wrote:
Quoted 10 lines
drivers/gpu/drm/nouveau/include/nvkm/core/device.h struct nvkm_device { · line 80
Quoted 7 lines
drivers/gpu/drm/nouveau/include/nvkm/core/device.h +3
-0@@ -72,6 +75,9 @@ struct nvkm_device {bool armed;bool legacy_done; } intr; + +bool has_zcull_info; +struct drm_nouveau_get_zcull_info zcull_info;This is bypassing the nvif layer entirely. I think you should store the contents of struct
NV2080_CTRL_GR_GET_ZCULL_INFO_PARAMSin structr535_grand have an nvif interface to access the data.Quoted 3 lines
I agree here, though
nvkm_grwould be a better choice for a couple of reasons, not least that it's possible (and should be reasonably trivial) to support this on earlier GPUs - should someone desire to at a later point.I agree, if the interface is stable enough -- I don't know whether this is prone to change or not.
Re: [PATCH 1/2] drm/nouveau: Add DRM_IOCTL_NOUVEAU_GET_ZCULL_INFO
Quoted 11 lines · Danilo Krummrich
Quoted 8 lines · M Henning
Okay, that sounds reasonable since I don't expect this to change very quickly.
Since I don't fully understand, is the suggestion here to:
1) add the interface as a function onnvkm_grusing thenvkm_gr_funcvtable and store the actual data onr535_gr
or
2) add the interface to NVIF (which IF?) and store the actual data onnvkm_gr?
Quoted 5 lines
I think we want both.
1) I think the suggestion was to store the data directly in
nvkm_gr, however the structure is indeed specific to r535, so I think, unfortunately, we need the vtable and store that data inr535_gr.
Well, NV2080_CTRL_GR_GET_ZCULL_INFO_PARAMS is r535-specific, but we need to convert it into a common structure and combine it with info from NV0080_CTRL_FIFO_GET_ENGINE_CONTEXT_PROPERTIES at some point, so I think it makes sense to do that conversion+combination before storing it on any structure. In that case, maybe we store the structure on nvkm_gr directly during r535_gr_oneinit and then the call to get the info only goes through NVIF?
Quoted 35 lines
2) Yes, this should be passed through nvif. Unfortunately, I think it would need to be a whole new one (similar to the fifo one).
Maybe Ben can provide you some additional pointers one this? Mayber he can suggest a shortcut, since he has patches queued to simplify the whole interface.
Quoted 29 lines
(Sorry, I don't understand how these layers are intended to fit together.))
Quoted 25 lines · Danilo Krummrich
Quoted 17 lines · Ben Skeggs
Quoted 4 lines · Danilo Krummrich
Hi Mel,
On Wed, Mar 12, 2025 at 05:36:14PM -0400, Mel Henning wrote:
Quoted 10 lines
drivers/gpu/drm/nouveau/include/nvkm/core/device.h struct nvkm_device { · line 80
Quoted 7 lines
drivers/gpu/drm/nouveau/include/nvkm/core/device.h +3
-0@@ -72,6 +75,9 @@ struct nvkm_device {bool armed;bool legacy_done; } intr; + +bool has_zcull_info; +struct drm_nouveau_get_zcull_info zcull_info;This is bypassing the nvif layer entirely. I think you should store the contents of struct
NV2080_CTRL_GR_GET_ZCULL_INFO_PARAMSin structr535_grand have an nvif interface to access the data.Quoted 3 lines
I agree here, though
nvkm_grwould be a better choice for a couple of reasons, not least that it's possible (and should be reasonably trivial) to support this on earlier GPUs - should someone desire to at a later point.I agree, if the interface is stable enough -- I don't know whether this is prone to change or not.
Danilo Krummrich
maintainerRe: [PATCH 1/2] drm/nouveau: Add DRM_IOCTL_NOUVEAU_GET_ZCULL_INFO
Quoted 18 lines · M Henning
Quoted 11 lines · Danilo Krummrich
Quoted 8 lines · M Henning
Okay, that sounds reasonable since I don't expect this to change very quickly.
Since I don't fully understand, is the suggestion here to:
1) add the interface as a function onnvkm_grusing thenvkm_gr_funcvtable and store the actual data onr535_gr
or
2) add the interface to NVIF (which IF?) and store the actual data onnvkm_gr?Quoted 5 lines
I think we want both.
1) I think the suggestion was to store the data directly in
nvkm_gr, however the structure is indeed specific to r535, so I think, unfortunately, we need the vtable and store that data inr535_gr.
Quoted 7 lines
Well,
NV2080_CTRL_GR_GET_ZCULL_INFO_PARAMSis r535-specific, but we need to convert it into a common structure and combine it with info fromNV0080_CTRL_FIFO_GET_ENGINE_CONTEXT_PROPERTIESat some point, so I think it makes sense to do that conversion+combination before storing it on any structure. In that case, maybe we store the structure onnvkm_grdirectly duringr535_gr_oneinitand then the call to get the info only goes through NVIF?
Sounds good to me! It means you need an intermediate structure though, we should avoid using uAPI structures in NVKM code.
Dave Airlie
maintainerRe: [PATCH 1/2] drm/nouveau: Add DRM_IOCTL_NOUVEAU_GET_ZCULL_INFO
Quoted 28 lines · Danilo Krummrich
Quoted 18 lines · M Henning
Quoted 11 lines · Danilo Krummrich
Quoted 8 lines · M Henning
Okay, that sounds reasonable since I don't expect this to change very quickly.
Since I don't fully understand, is the suggestion here to:
1) add the interface as a function onnvkm_grusing thenvkm_gr_funcvtable and store the actual data onr535_gr
or
2) add the interface to NVIF (which IF?) and store the actual data onnvkm_gr?Quoted 5 lines
I think we want both.
1) I think the suggestion was to store the data directly in
nvkm_gr, however the structure is indeed specific to r535, so I think, unfortunately, we need the vtable and store that data inr535_gr.Quoted 7 lines
Well,
NV2080_CTRL_GR_GET_ZCULL_INFO_PARAMSis r535-specific, but we need to convert it into a common structure and combine it with info fromNV0080_CTRL_FIFO_GET_ENGINE_CONTEXT_PROPERTIESat some point, so I think it makes sense to do that conversion+combination before storing it on any structure. In that case, maybe we store the structure onnvkm_grdirectly duringr535_gr_oneinitand then the call to get the info only goes through NVIF?
Quoted 2 lines
Sounds good to me! It means you need an intermediate structure though, we should avoid using uAPI structures in NVKM code.
I don't think we need to go through NVIF, or at least we could do it, but there is no gr object exposed through it now and adding a whole load of gr code to nvif would be a nightmare, I'd rather we merged the kill nvif patches.
I think not using the uapi struct in nvkm is all we need to maintain, nvkm has it's structure, uapi has it's structure and we just pass between them. nvkm_gr_units already exists as an nvif bypass so I think it's probably fine.
Dave.
Danilo Krummrich
maintainerRe: [PATCH 1/2] drm/nouveau: Add DRM_IOCTL_NOUVEAU_GET_ZCULL_INFO
Quoted 3 lines · Dave Airlie
I don't think we need to go through NVIF, or at least we could do it, but there is no gr object exposed through it now and adding a whole load of gr code to nvif would be a nightmare,
I mean, we can bypass it, but it would be yet another inconsistency. Though, I do fully agree that there is not much value in adding the required code. And similar to the other thread, things have changed a bit and we may be able to afford being a bit more relaxed about those things.
Quoted 1 line
I'd rather we merged the kill nvif patches.
Maybe we should just do that?
Re: [PATCH 1/2] drm/nouveau: Add DRM_IOCTL_NOUVEAU_GET_ZCULL_INFO
In reply to Danilo KrummrichQuoted 2 lines · Danilo Krummrich
Hi Mel,
Hi, thanks for the review.
Quoted 5 lines · Mel Henning
Quoted 1 line
Userspace needs this information to set up zcull correctly.
This is a very brief motivation for the commit, please also describe what the commit does using imperative form.
Sure, I guess I'll move some of the motivation that I wrote in the intro email for this series into this commit message.
Quoted 25 lines
Quoted 25 lines
Signed-off-by Mel Henning <[email protected]>--- .../drm/nouveau/include/nvkm/core/device.h | 6 ++ .../sdk/nvidia/inc/ctrl/ctrl2080/ctrl2080gr.h | 69 +++++++++++++++++++ drivers/gpu/drm/nouveau/nouveau_abi16.c | 15 ++++ drivers/gpu/drm/nouveau/nouveau_abi16.h | 1 + drivers/gpu/drm/nouveau/nouveau_drm.c | 1 + drivers/gpu/drm/nouveau/nvkm/engine/gr/r535.c | 34 +++++++++ include/uapi/drm/nouveau_drm.h | 19 +++++ 7 files changed, 145 insertions(+)drivers/gpu/drm/nouveau/include/nvkm/core/device.h +3
-0@@ -3,6 +3,9 @@#define __NVKM_DEVICE_H__#include <core/oclass.h> #include <core/intr.h> + +#include "uapi/drm/nouveau_drm.h" +enum nvkm_subdev_type ;
Quoted 12 lines
drivers/gpu/drm/nouveau/include/nvkm/core/device.h struct nvkm_device { · line 80
Quoted 8 lines
drivers/gpu/drm/nouveau/include/nvkm/core/device.h +3
-0enum nvkm_device_type {@@ -72,6 +75,9 @@ struct nvkm_device {bool armed;bool legacy_done; } intr; + +bool has_zcull_info; +struct drm_nouveau_get_zcull_info zcull_info;This is bypassing the nvif layer entirely. I think you should store the contents of struct
NV2080_CTRL_GR_GET_ZCULL_INFO_PARAMSin structr535_grand have an nvif interface to access the data.
Sure. I think my main tripping point here is: do we re-declare the struct another time? It feels annoying to re-define it for each layer, and I don't suppose we can expose the CTRL2080 or drm structures directly in the NVIF layer.
Quoted 212 lines
Quoted 90 lines
drivers/gpu/drm/nouveau/include/nvkm/core/device.h +0
-0};struct nvkm_subdev *nvkm_device_subdev (struct nvkm_device *,int type,int inst);drivers/gpu/drm/nouveau/include/nvrm/535.113.01/common/sdk/nvidia/inc/ctrl/ctrl2080/ctrl2080gr.h +69
-0@@ -26,6 +26,75 @@* DEALINGS IN THE SOFTWARE. */ +/** +* NV2080_CTRL_CMD_GR_GET_ZCULL_INFO +* +* This command is used to query the RM for zcull information that the +* driver will need to allocate and manage the zcull regions. +* +* widthAlignPixels +* This parameter returns the width alignment restrictions in pixels +* used to adjust a surface for proper aliquot coverage (typically +* #TPC's * 16). +* +* heightAlignPixels +* This parameter returns the height alignment restrictions in pixels +* used to adjust a surface for proper aliquot coverage (typically 32). +* +* pixelSquaresByAliquots +* This parameter returns the pixel area covered by an aliquot +* (typically #Zcull_banks * 16 * 16). +* +* aliquotTotal +* This parameter returns the total aliquot pool available in HW. +* +* zcullRegionByteMultiplier +* This parameter returns multiplier used to convert aliquots in a region +* to the number of bytes required to save/restore them. +* +* zcullRegionHeaderSize +* This parameter returns the region header size which is required to be +* allocated and accounted for in any save/restore operation on a region. +* +* zcullSubregionHeaderSize +* This parameter returns the subregion header size which is required to be +* allocated and accounted for in any save/restore operation on a region. +* +* subregionCount +* This parameter returns the subregion count. +* +* subregionWidthAlignPixels +* This parameter returns the subregion width alignment restrictions in +* pixels used to adjust a surface for proper aliquot coverage +* (typically #TPC's * 16). +* +* subregionHeightAlignPixels +* This parameter returns the subregion height alignment restrictions in +* pixels used to adjust a surface for proper aliquot coverage +* (typically 62). +* +* The callee should compute the size of a zcull region as follows. +* (numBytes = aliquots * zcullRegionByteMultiplier + +* zcullRegionHeaderSize + zcullSubregionHeaderSize) +*/ +#define NV2080_CTRL_CMD_GR_GET_ZCULL_INFO (0x20801206U)/* finn: Evaluated from "(FINN_NV20_SUBDEVICE_0_GR_INTERFACE_ID << 8) | NV2080_CTRL_GR_GET_ZCULL_INFO_PARAMS_MESSAGE_ID" */ + +#define NV2080_CTRL_GR_GET_ZCULL_INFO_PARAMS_SUBREGION_SUPPORTED +#define NV2080_CTRL_GR_GET_ZCULL_INFO_PARAMS_MESSAGE_ID (0x6U) + +typedef struct NV2080_CTRL_GR_GET_ZCULL_INFO_PARAMS { +NvU32 widthAlignPixels; +NvU32 heightAlignPixels; +NvU32 pixelSquaresByAliquots; +NvU32 aliquotTotal; +NvU32 zcullRegionByteMultiplier; +NvU32 zcullRegionHeaderSize; +NvU32 zcullSubregionHeaderSize; +NvU32 subregionCount; +NvU32 subregionWidthAlignPixels; +NvU32 subregionHeightAlignPixels; +}NV2080_CTRL_GR_GET_ZCULL_INFO_PARAMS ; + typedef enum NV2080_CTRL_CMD_GR_CTXSW_PREEMPTION_BIND_BUFFERS { NV2080_CTRL_CMD_GR_CTXSW_PREEMPTION_BIND_BUFFERS_MAIN = 0, NV2080_CTRL_CMD_GR_CTXSW_PREEMPTION_BIND_BUFFERS_SPILL = 1,drivers/gpu/drm/nouveau/nouveau_abi16.c +0
-0@@ -333,6 +333,21 @@ nouveau_abi16_ioctl_getparam(ABI16_IOCTL_ARGS)return 0 ; }drivers/gpu/drm/nouveau/nouveau_abi16.c nouveau_abi16_ioctl_getparam(ABI16_IOCTL_ARGS) · line 344
Quoted 10 lines
drivers/gpu/drm/nouveau/nouveau_abi16.c +9
-0+int +nouveau_abi16_ioctl_get_zcull_info (ABI16_IOCTL_ARGS ) +{ +struct nouveau_drm *drm =nouveau_drm (dev); +struct nvkm_device *device = drm->nvkm; +struct drm_nouveau_get_zcull_info *out = data; + +if (device->has_zcull_info) { + *out = device->zcull_info;This needs
copy_to_user().Quoted 85 lines
drivers/gpu/drm/nouveau/nouveau_abi16.c +6
-0+return 0 ; + }else { +return -ENODEV ; + } +} +int nouveau_abi16_ioctl_channel_alloc (ABI16_IOCTL_ARGS ) {drivers/gpu/drm/nouveau/nouveau_abi16.h +1
-0@@ -6,6 +6,7 @@ struct drm_device *dev, void *data, struct drm_file *file_privint nouveau_abi16_ioctl_getparam (ABI16_IOCTL_ARGS ); +int nouveau_abi16_ioctl_get_zcull_info (ABI16_IOCTL_ARGS );int nouveau_abi16_ioctl_channel_alloc (ABI16_IOCTL_ARGS );int nouveau_abi16_ioctl_channel_free (ABI16_IOCTL_ARGS );int nouveau_abi16_ioctl_grobj_alloc (ABI16_IOCTL_ARGS );drivers/gpu/drm/nouveau/nouveau_drm.c +1
-0@@ -1244,6 +1244,7 @@ nouveau_ioctls[] = {DRM_IOCTL_DEF_DRV (NOUVEAU_GROBJ_ALLOC , nouveau_abi16_ioctl_grobj_alloc,DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (NOUVEAU_NOTIFIEROBJ_ALLOC , nouveau_abi16_ioctl_notifierobj_alloc,DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (NOUVEAU_GPUOBJ_FREE , nouveau_abi16_ioctl_gpuobj_free,DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (NOUVEAU_GET_ZCULL_INFO , nouveau_abi16_ioctl_get_zcull_info,DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (NOUVEAU_SVM_INIT , nouveau_svmm_init,DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (NOUVEAU_SVM_BIND , nouveau_svmm_bind,DRM_RENDER_ALLOW ), DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_NEW, nouveau_gem_ioctl_new, DRM_RENDER_ALLOW),drivers/gpu/drm/nouveau/nvkm/engine/gr/r535.c +23
-0@@ -34,6 +34,7 @@#include <nvrm/535.113.01/common/sdk/nvidia/inc/alloc/alloc_channel.h> #include <nvrm/535.113.01/common/sdk/nvidia/inc/ctrl/ctrl0080/ctrl0080fifo.h> #include <nvrm/535.113.01/common/sdk/nvidia/inc/ctrl/ctrl2080/ctrl2080gpu.h> +#include <nvrm/535.113.01/common/sdk/nvidia/inc/ctrl/ctrl2080/ctrl2080gr.h> #include <nvrm/535.113.01/common/sdk/nvidia/inc/ctrl/ctrl2080/ctrl2080internal.h> #include <nvrm/535.113.01/nvidia/generated/g_kernel_channel_nvoc.h> @@ -244,6 +245,8 @@ static int r535_gr_oneinit(struct nvkm_gr *base) {NV2080_CTRL_INTERNAL_STATIC_GR_GET_CONTEXT_BUFFERS_INFO_PARAMS *info; +NV2080_CTRL_GR_GET_ZCULL_INFO_PARAMS *zcull_info; +u32 zcull_ctxsw_size, zcull_ctxsw_align;struct r535_gr *gr =container_of (base,typeof (*gr), base);struct nvkm_subdev *subdev = &gr->base.engine.subdev;struct nvkm_device *device = subdev->device;@@ -418,6 +421,11 @@ r535_gr_oneinit(struct nvkm_gr *base) } } + zcull_ctxsw_size = info->engineContextBuffersInfo[0 ] + .engine[NV0080_CTRL_FIFO_GET_ENGINE_CONTEXT_PROPERTIES_ENGINE_ID_GRAPHICS_ZCULL ].size; + zcull_ctxsw_align = info->engineContextBuffersInfo[0 ] + .engine[NV0080_CTRL_FIFO_GET_ENGINE_CONTEXT_PROPERTIES_ENGINE_ID_GRAPHICS_ZCULL ].alignment; +nvkm_gsp_rm_ctrl_done (&gsp->internal.device.subdevice, info);/* Promote golden context to RM. */ @@ -450,6 +458,32 @@ r535_gr_oneinit(struct nvkm_gr *base) } } + zcull_info =nvkm_gsp_rm_ctrl_rd (&gsp->internal.device.subdevice, +NV2080_CTRL_CMD_GR_GET_ZCULL_INFO , +sizeof (*zcull_info)); +if (WARN_ON (IS_ERR (zcull_info))) { + ret =PTR_ERR (zcull_info); + goto done; + } + + device->has_zcull_info = true; + + device->zcull_info.width_align_pixels = zcull_info->widthAlignPixels; + device->zcull_info.height_align_pixels = zcull_info->heightAlignPixels; + device->zcull_info.pixel_squares_by_aliquots = zcull_info->pixelSquaresByAliquots; + device->zcull_info.aliquot_total = zcull_info->aliquotTotal; + device->zcull_info.zcull_region_byte_multiplier = zcull_info->zcullRegionByteMultiplier;drivers/gpu/drm/nouveau/nvkm/engine/gr/r535.c r535_gr_oneinit(struct nvkm_gr *base) · line 485
Quoted 10 lines
drivers/gpu/drm/nouveau/nvkm/engine/gr/r535.c +10
-0+ device->zcull_info.zcull_region_header_size = zcull_info->zcullRegionHeaderSize; + device->zcull_info.zcull_subregion_header_size = zcull_info->zcullSubregionHeaderSize; + device->zcull_info.subregion_count = zcull_info->subregionCount; + device->zcull_info.subregion_width_align_pixels = zcull_info->subregionWidthAlignPixels; + device->zcull_info.subregion_height_align_pixels = zcull_info->subregionHeightAlignPixels; + + device->zcull_info.ctxsw_size = zcull_ctxsw_size; + device->zcull_info.ctxsw_align = zcull_ctxsw_align; + +nvkm_gsp_rm_ctrl_done (&gsp->internal.device.subdevice, zcull_info);Please move this to a separate function.
include/uapi/drm/nouveau_drm.h
Quoted 8 lines
drivers/gpu/drm/nouveau/nvkm/engine/gr/r535.c +1
-0+ done:nvkm_gsp_rm_free (&golden.chan);for (int i = gr->ctxbuf_nr -1 ; i >=0 ; i--)include/uapi/drm/nouveau_drm.h +0
-0Please do the uAPI change in a separate commit.
Quoted 7 lines
include/uapi/drm/nouveau_drm.h struct drm_nouveau_exec { · line 435
Quoted 5 lines
include/uapi/drm/nouveau_drm.h +1
-0@@ -432,6 +432,22 @@ struct drm_nouveau_exec {__u64 push_ptr; }; +struct drm_nouveau_get_zcull_info {Please add some documentation to this structure.
Okay. I guess I'll mostly copy the docs from the CTRL2080 structure.
Quoted 8 lines
Quoted 8 lines
include/uapi/drm/nouveau_drm.h +8
-0+__u32 width_align_pixels; +__u32 height_align_pixels; +__u32 pixel_squares_by_aliquots; +__u32 aliquot_total; +__u32 zcull_region_byte_multiplier; +__u32 zcull_region_header_size; +__u32 zcull_subregion_header_size; +__u32 subregion_count;
Quoted 8 lines
include/uapi/drm/nouveau_drm.h struct drm_nouveau_exec { · line 449
Quoted 6 lines
include/uapi/drm/nouveau_drm.h +6
-0+__u32 subregion_width_align_pixels; +__u32 subregion_height_align_pixels; + +__u32 ctxsw_size; +__u32 ctxsw_align; +};What if this ever changes between hardware revisions or firmware versions?
There was some previous discussion of that here:
https://gitlab.freedesktop.org/mesa/mesa/-/issues/12596#note_2796853
From what I can tell, this structure hasn't really changed since FERMI_C (circa 2011), so I'm not too worried about it changing on us too quickly. When it does change, we have the option of appending more members to this struct in the usual way, or if the change is more fundamental we can return an error from this ioctl and add a new interface. Userspace needs to handle an error from this ioctl gracefully anyway since whether it works or not depends on the gpu generation and what firmware is loaded right now.
Quoted 24 lines
Quoted 24 lines
include/uapi/drm/nouveau_drm.h +4
-1+#define DRM_NOUVEAU_GETPARAM 0x00#define DRM_NOUVEAU_SETPARAM 0x01/* deprecated */ #define DRM_NOUVEAU_CHANNEL_ALLOC 0x02@@ -445,6 +461,7 @@ struct drm_nouveau_exec {#define DRM_NOUVEAU_VM_INIT 0x10#define DRM_NOUVEAU_VM_BIND 0x11#define DRM_NOUVEAU_EXEC 0x12 +#define DRM_NOUVEAU_GET_ZCULL_INFO 0x13#define DRM_NOUVEAU_GEM_NEW 0x40#define DRM_NOUVEAU_GEM_PUSHBUF 0x41#define DRM_NOUVEAU_GEM_CPU_PREP 0x42@@ -513,6 +530,8 @@ struct drm_nouveau_svm_bind {#define DRM_IOCTL_NOUVEAU_VM_INIT DRM_IOWR(DRM_COMMAND_BASE + DRM_NOUVEAU_VM_INIT, struct drm_nouveau_vm_init)#define DRM_IOCTL_NOUVEAU_VM_BIND DRM_IOWR(DRM_COMMAND_BASE + DRM_NOUVEAU_VM_BIND, struct drm_nouveau_vm_bind)#define DRM_IOCTL_NOUVEAU_EXEC DRM_IOWR(DRM_COMMAND_BASE + DRM_NOUVEAU_EXEC, struct drm_nouveau_exec) + +#define DRM_IOCTL_NOUVEAU_GET_ZCULL_INFO DRM_IOR (DRM_COMMAND_BASE + DRM_NOUVEAU_GET_ZCULL_INFO, struct drm_nouveau_get_zcull_info)#if defined(__cplusplus) }#endif --2.48.1
Danilo Krummrich
maintainerRe: [PATCH 1/2] drm/nouveau: Add DRM_IOCTL_NOUVEAU_GET_ZCULL_INFO
Quoted 22 lines · M Henning
Quoted 17 lines · Danilo Krummrich
Quoted 4 lines · Mel Henning
include/uapi/drm/nouveau_drm.h +4
-0+__u32 width_align_pixels; +__u32 height_align_pixels; +__u32 pixel_squares_by_aliquots; +__u32 aliquot_total;include/uapi/drm/nouveau_drm.h struct drm_nouveau_exec { · line 449
Quoted 10 lines
include/uapi/drm/nouveau_drm.h +10
-0+__u32 zcull_region_byte_multiplier; +__u32 zcull_region_header_size; +__u32 zcull_subregion_header_size; +__u32 subregion_count; +__u32 subregion_width_align_pixels; +__u32 subregion_height_align_pixels; + +__u32 ctxsw_size; +__u32 ctxsw_align; +};What if this ever changes between hardware revisions or firmware versions?
There was some previous discussion of that here:
https://gitlab.freedesktop.org/mesa/mesa/-/issues/12596#note_2796853
Quoted 8 lines
From what I can tell, this structure hasn't really changed since
FERMI_C(circa 2011), so I'm not too worried about it changing on us too quickly. When it does change, we have the option of appending more members to this struct in the usual way, or if the change is more fundamental we can return an error from this ioctl and add a new interface. Userspace needs to handle an error from this ioctl gracefully anyway since whether it works or not depends on the gpu generation and what firmware is loaded right now.
We could also define it as
struct drm_nouveau_get_zcull_info {
__u32 version;
__u32 _pad;
union {
struct drm_nouveau_get_zcull_info_v1 info;
}
}just to be safe.
Re: [PATCH 1/2] drm/nouveau: Add DRM_IOCTL_NOUVEAU_GET_ZCULL_INFO
Quoted 44 lines · Danilo Krummrich
Quoted 22 lines · M Henning
Quoted 17 lines · Danilo Krummrich
Quoted 4 lines · Mel Henning
include/uapi/drm/nouveau_drm.h +4
-0+__u32 width_align_pixels; +__u32 height_align_pixels; +__u32 pixel_squares_by_aliquots; +__u32 aliquot_total;include/uapi/drm/nouveau_drm.h struct drm_nouveau_exec { · line 449
Quoted 10 lines
include/uapi/drm/nouveau_drm.h +10
-0+__u32 zcull_region_byte_multiplier; +__u32 zcull_region_header_size; +__u32 zcull_subregion_header_size; +__u32 subregion_count; +__u32 subregion_width_align_pixels; +__u32 subregion_height_align_pixels; + +__u32 ctxsw_size; +__u32 ctxsw_align; +};What if this ever changes between hardware revisions or firmware versions?
There was some previous discussion of that here:
https://gitlab.freedesktop.org/mesa/mesa/-/issues/12596#note_2796853Quoted 8 lines
From what I can tell, this structure hasn't really changed since
FERMI_C(circa 2011), so I'm not too worried about it changing on us too quickly. When it does change, we have the option of appending more members to this struct in the usual way, or if the change is more fundamental we can return an error from this ioctl and add a new interface. Userspace needs to handle an error from this ioctl gracefully anyway since whether it works or not depends on the gpu generation and what firmware is loaded right now.We could also define it as
struct drm_nouveau_get_zcull_info { __u32 version; __u32 _pad; union { struct drm_nouveau_get_zcull_info_v1 info; } }
Quoted 1 line
just to be safe.
We can do that, although I don't see any other drm drivers using a similar pattern anywhere.
Danilo Krummrich
maintainerRe: [PATCH 1/2] drm/nouveau: Add DRM_IOCTL_NOUVEAU_GET_ZCULL_INFO
(CC: Ben, John)
Quoted 45 lines · M Henning
Quoted 44 lines · Danilo Krummrich
Quoted 22 lines · M Henning
Quoted 17 lines · Danilo Krummrich
Quoted 4 lines · Mel Henning
include/uapi/drm/nouveau_drm.h +4
-0+__u32 width_align_pixels; +__u32 height_align_pixels; +__u32 pixel_squares_by_aliquots; +__u32 aliquot_total;include/uapi/drm/nouveau_drm.h struct drm_nouveau_exec { · line 449
Quoted 10 lines
include/uapi/drm/nouveau_drm.h +10
-0+__u32 zcull_region_byte_multiplier; +__u32 zcull_region_header_size; +__u32 zcull_subregion_header_size; +__u32 subregion_count; +__u32 subregion_width_align_pixels; +__u32 subregion_height_align_pixels; + +__u32 ctxsw_size; +__u32 ctxsw_align; +};What if this ever changes between hardware revisions or firmware versions?
There was some previous discussion of that here:
https://gitlab.freedesktop.org/mesa/mesa/-/issues/12596#note_2796853Quoted 8 lines
From what I can tell, this structure hasn't really changed since
FERMI_C(circa 2011), so I'm not too worried about it changing on us too quickly. When it does change, we have the option of appending more members to this struct in the usual way, or if the change is more fundamental we can return an error from this ioctl and add a new interface. Userspace needs to handle an error from this ioctl gracefully anyway since whether it works or not depends on the gpu generation and what firmware is loaded right now.We could also define it as
struct drm_nouveau_get_zcull_info { __u32 version; __u32 _pad; union { struct drm_nouveau_get_zcull_info_v1 info; } }
Quoted 4 lines
Quoted 1 line
just to be safe.
We can do that, although I don't see any other drm drivers using a similar pattern anywhere.
I think it's a bit cleaner than adding new members, leave existing ones unset or add a new IOCTL in the worst case.
Maybe the NVIDIA folks can give us some hint on whether this is expected to change at some point?
Dave Airlie
maintainerRe: [PATCH 1/2] drm/nouveau: Add DRM_IOCTL_NOUVEAU_GET_ZCULL_INFO
Quoted 51 lines · Danilo Krummrich
(CC: Ben, John)
Quoted 47 lines · M Henning
Quoted 45 lines · Danilo Krummrich
Quoted 22 lines · M Henning
Quoted 17 lines · Danilo Krummrich
Quoted 4 lines · Mel Henning
include/uapi/drm/nouveau_drm.h +4
-0+__u32 width_align_pixels; +__u32 height_align_pixels; +__u32 pixel_squares_by_aliquots; +__u32 aliquot_total;include/uapi/drm/nouveau_drm.h struct drm_nouveau_exec { · line 449
Quoted 10 lines
include/uapi/drm/nouveau_drm.h +10
-0+__u32 zcull_region_byte_multiplier; +__u32 zcull_region_header_size; +__u32 zcull_subregion_header_size; +__u32 subregion_count; +__u32 subregion_width_align_pixels; +__u32 subregion_height_align_pixels; + +__u32 ctxsw_size; +__u32 ctxsw_align; +};What if this ever changes between hardware revisions or firmware versions?
There was some previous discussion of that here:
https://gitlab.freedesktop.org/mesa/mesa/-/issues/12596#note_2796853Quoted 8 lines
From what I can tell, this structure hasn't really changed since
FERMI_C(circa 2011), so I'm not too worried about it changing on us too quickly. When it does change, we have the option of appending more members to this struct in the usual way, or if the change is more fundamental we can return an error from this ioctl and add a new interface. Userspace needs to handle an error from this ioctl gracefully anyway since whether it works or not depends on the gpu generation and what firmware is loaded right now.We could also define it as
struct drm_nouveau_get_zcull_info { __u32 version; __u32 _pad; union { struct drm_nouveau_get_zcull_info_v1 info; } }just to be safe.
Quoted 8 lines
Quoted 2 lines
We can do that, although I don't see any other drm drivers using a similar pattern anywhere.
I think it's a bit cleaner than adding new members, leave existing ones unset or add a new IOCTL in the worst case.
Maybe the NVIDIA folks can give us some hint on whether this is expected to change at some point?
I think it's an ioctl, let's just leave out version/pad, adding a new ioctl isn't a major trouble if the world decides we need to do it.
Also you can extend ioctls with new fields at the end without problems, so if it's just extra info it'll likely be hw specific and be part of enabling a new GPU.
Dave.
Re: [PATCH 1/2] drm/nouveau: Add DRM_IOCTL_NOUVEAU_GET_ZCULL_INFO
Quoted 52 lines · Dave Airlie
Quoted 51 lines · Danilo Krummrich
(CC: Ben, John)
Quoted 47 lines · M Henning
Quoted 45 lines · Danilo Krummrich
Quoted 22 lines · M Henning
Quoted 17 lines · Danilo Krummrich
Quoted 4 lines · Mel Henning
(quoted diff) +4
-0+ __u32 width_align_pixels; + __u32 height_align_pixels; + __u32 pixel_squares_by_aliquots; + __u32 aliquot_total;Review
Quoted 10 lines
(quoted diff) +10
-0+ __u32 zcull_region_byte_multiplier; + __u32 zcull_region_header_size; + __u32 zcull_subregion_header_size; + __u32 subregion_count; + __u32 subregion_width_align_pixels; + __u32 subregion_height_align_pixels; + + __u32 ctxsw_size; + __u32 ctxsw_align; +};What if this ever changes between hardware revisions or firmware versions?
There was some previous discussion of that here:
https://gitlab.freedesktop.org/mesa/mesa/-/issues/12596#note_2796853Quoted 8 lines
From what I can tell, this structure hasn't really changed since
FERMI_C(circa 2011), so I'm not too worried about it changing on us too quickly. When it does change, we have the option of appending more members to this struct in the usual way, or if the change is more fundamental we can return an error from this ioctl and add a new interface. Userspace needs to handle an error from this ioctl gracefully anyway since whether it works or not depends on the gpu generation and what firmware is loaded right now.We could also define it as
struct drm_nouveau_get_zcull_info { __u32 version; __u32 _pad; union { struct drm_nouveau_get_zcull_info_v1 info; } }just to be safe.
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
We can do that, although I don't see any other drm drivers using a similar pattern anywhere.
I think it's a bit cleaner than adding new members, leave existing ones unset or add a new IOCTL in the worst case.
Maybe the NVIDIA folks can give us some hint on whether this is expected to change at some point?
"Predictions are hard, especially about the future." :)
Quoted 8 lines
I think it's an ioctl, let's just leave out version/pad, adding a new ioctl isn't a major trouble if the world decides we need to do it.
Also you can extend ioctls with new fields at the end without problems, so if it's just extra info it'll likely be hw specific and be part of enabling a new GPU.
That seems reasonable to me.
thanks,
Signature · 1 line
John Hubbard
Danilo Krummrich
maintainerRe: [PATCH 1/2] drm/nouveau: Add DRM_IOCTL_NOUVEAU_GET_ZCULL_INFO
In reply to Dave AirlieQuoted 61 lines · Dave Airlie
Quoted 51 lines · Danilo Krummrich
(CC: Ben, John)
Quoted 47 lines · M Henning
Quoted 45 lines · Danilo Krummrich
Quoted 22 lines · M Henning
Quoted 17 lines · Danilo Krummrich
Quoted 4 lines · Mel Henning
(quoted diff) +4
-0+ __u32 width_align_pixels; + __u32 height_align_pixels; + __u32 pixel_squares_by_aliquots; + __u32 aliquot_total;Review
Quoted 10 lines
(quoted diff) +10
-0+ __u32 zcull_region_byte_multiplier; + __u32 zcull_region_header_size; + __u32 zcull_subregion_header_size; + __u32 subregion_count; + __u32 subregion_width_align_pixels; + __u32 subregion_height_align_pixels; + + __u32 ctxsw_size; + __u32 ctxsw_align; +};What if this ever changes between hardware revisions or firmware versions?
There was some previous discussion of that here:
https://gitlab.freedesktop.org/mesa/mesa/-/issues/12596#note_2796853Quoted 8 lines
From what I can tell, this structure hasn't really changed since
FERMI_C(circa 2011), so I'm not too worried about it changing on us too quickly. When it does change, we have the option of appending more members to this struct in the usual way, or if the change is more fundamental we can return an error from this ioctl and add a new interface. Userspace needs to handle an error from this ioctl gracefully anyway since whether it works or not depends on the gpu generation and what firmware is loaded right now.We could also define it as
struct drm_nouveau_get_zcull_info { __u32 version; __u32 _pad; union { struct drm_nouveau_get_zcull_info_v1 info; } }just to be safe.
Quoted 8 lines
Quoted 2 lines
We can do that, although I don't see any other drm drivers using a similar pattern anywhere.
I think it's a bit cleaner than adding new members, leave existing ones unset or add a new IOCTL in the worst case.
Maybe the NVIDIA folks can give us some hint on whether this is expected to change at some point?
Quoted 6 lines
I think it's an ioctl, let's just leave out version/pad, adding a new ioctl isn't a major trouble if the world decides we need to do it.
Also you can extend ioctls with new fields at the end without problems, so if it's just extra info it'll likely be hw specific and be part of enabling a new GPU.
Yeah, that's why I said "it's a bit cleaner than adding new members, leave existing ones unset or add a new IOCTL in the worst case" above. :)
Anyways, this is quite a while ago and things have changed. I think we can afford to be a bit less future proof in terms of new GPU (and firmware) support. :)
PATCH 2/2 drm/nouveau: DRM_NOUVEAU_SET_ZCULL_CTXSW_BUFFER
In reply to Mel HenningWe add this ioctl to set up the zcull context switch buffer so userspace can manage it. This also includes support for unbinding the buffer, which helps simplify device teardown on the userspace side.
--- drivers/gpu/drm/nouveau/include/nvif/if0020.h | 6 +++ .../gpu/drm/nouveau/include/nvkm/engine/gr.h | 1 + .../sdk/nvidia/inc/ctrl/ctrl2080/ctrl2080gr.h | 53 +++++++++++++++++++ drivers/gpu/drm/nouveau/nouveau_abi16.c | 46 ++++++++++++++++ drivers/gpu/drm/nouveau/nouveau_abi16.h | 1 + drivers/gpu/drm/nouveau/nouveau_drm.c | 1 + .../gpu/drm/nouveau/nvkm/engine/fifo/chan.c | 8 +++ .../gpu/drm/nouveau/nvkm/engine/fifo/chan.h | 2 + .../gpu/drm/nouveau/nvkm/engine/fifo/r535.c | 26 +++++++++ .../gpu/drm/nouveau/nvkm/engine/fifo/uchan.c | 17 ++++++ include/uapi/drm/nouveau_drm.h | 16 ++++++ 11 files changed, 177 insertions(+)
drivers/gpu/drm/nouveau/include/nvif/if0020.h +6 -0
@@ -42,4 +42,10 @@ union nvif_chan_event_args { __u8 type; } v0; }; + +#define NVIF_CHAN_MTHD_SET_ZCULL_CTXSW_BUFFER 0x00000000 + +struct nvif_chan_mthd_set_zcull_ctxsw_buffer { +u64 addr; +};#endif
drivers/gpu/drm/nouveau/include/nvkm/engine/gr.h +1 -0
@@ -9,6 +9,7 @@ struct nvkm_gr { };u64 nvkm_gr_units (struct nvkm_gr *); +int nvkm_gr_set_zcull_ctxsw_buffer (struct nvkm_gr *gr,struct nvkm_chan *chan,u64 addr);int nvkm_gr_tlb_flush (struct nvkm_gr *);int nvkm_gr_ctxsw_pause (struct nvkm_device *);int nvkm_gr_ctxsw_resume (struct nvkm_device *);
drivers/gpu/drm/nouveau/include/nvrm/535.113.01/common/sdk/nvidia/inc/ctrl/ctrl2080/ctrl2080gr.h +53 -0
65 lines not on this page · raw message
drivers/gpu/drm/nouveau/nouveau_abi16.c +46 -0
58 lines not on this page · raw message
drivers/gpu/drm/nouveau/nouveau_abi16.h +1 -0
@@ -7,6 +7,7 @@int nouveau_abi16_ioctl_getparam (ABI16_IOCTL_ARGS );int nouveau_abi16_ioctl_get_zcull_info (ABI16_IOCTL_ARGS ); +int nouveau_abi16_ioctl_set_zcull_ctxsw_buffer (ABI16_IOCTL_ARGS );int nouveau_abi16_ioctl_channel_alloc (ABI16_IOCTL_ARGS );int nouveau_abi16_ioctl_channel_free (ABI16_IOCTL_ARGS );int nouveau_abi16_ioctl_grobj_alloc (ABI16_IOCTL_ARGS );
drivers/gpu/drm/nouveau/nouveau_drm.c +1 -0
@@ -1245,6 +1245,7 @@ nouveau_ioctls[] = {DRM_IOCTL_DEF_DRV (NOUVEAU_NOTIFIEROBJ_ALLOC , nouveau_abi16_ioctl_notifierobj_alloc,DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (NOUVEAU_GPUOBJ_FREE , nouveau_abi16_ioctl_gpuobj_free,DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (NOUVEAU_GET_ZCULL_INFO , nouveau_abi16_ioctl_get_zcull_info,DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (NOUVEAU_SET_ZCULL_CTXSW_BUFFER , nouveau_abi16_ioctl_set_zcull_ctxsw_buffer,DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (NOUVEAU_SVM_INIT , nouveau_svmm_init,DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (NOUVEAU_SVM_BIND , nouveau_svmm_bind,DRM_RENDER_ALLOW ), DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_NEW, nouveau_gem_ioctl_new, DRM_RENDER_ALLOW),
drivers/gpu/drm/nouveau/nvkm/engine/fifo/chan.c +8 -0
@@ -345,6 +345,14 @@ nvkm_chan_get_chid(struct nvkm_engine *engine, int id, unsigned long *pirqflags)return NULL ; } +int +nvkm_chan_set_zcull_ctxsw_buffer (struct nvkm_chan *chan,u64 addr) +{ +if (chan->func->set_zcull_ctxsw_buffer) +return chan->func->set_zcull_ctxsw_buffer (chan, addr); +return -ENODEV ; +} + int nvkm_chan_new_(const struct nvkm_chan_func *func, struct nvkm_runl *runl, int runq, struct nvkm_cgrp *cgrp, const char *name, bool priv, u32 devm, struct nvkm_vmm *vmm,
drivers/gpu/drm/nouveau/nvkm/engine/fifo/chan.h +2 -0
@@ -54,6 +54,7 @@ struct nvkm_chan_func {void (*stop)(struct nvkm_chan *);void (*preempt)(struct nvkm_chan *);u32 (*doorbell_handle)(struct nvkm_chan *); +int (*set_zcull_ctxsw_buffer)(struct nvkm_chan *,u64 addr); }; int nvkm_chan_new_(const struct nvkm_chan_func *, struct nvkm_runl *, int runq, struct nvkm_cgrp *,
@@ -73,6 +74,7 @@ int nvkm_chan_cctx_get(struct nvkm_chan *, struct nvkm_engn *, struct nvkm_cctx struct nvkm_client * /*TODO: remove need for this */); void nvkm_chan_cctx_put(struct nvkm_chan *, struct nvkm_cctx **);void nvkm_chan_cctx_bind (struct nvkm_chan *,struct nvkm_engn *,struct nvkm_cctx *); +int nvkm_chan_set_zcull_ctxsw_buffer (struct nvkm_chan *chan,u64 addr); #define CHAN_PRCLI(c,l,p,f,a...) CGRP_PRINT((c)->cgrp, l, p, "%04x:[%s]"f, (c)->id, (c)->name, ##a) #define CHAN_PRINT(c,l,p,f,a...) CGRP_PRINT((c)->cgrp, l, p, "%04x:"f, (c)->id, ##a)
drivers/gpu/drm/nouveau/nvkm/engine/fifo/r535.c +26 -0
@@ -39,6 +39,7 @@#include <nvrm/535.113.01/common/sdk/nvidia/inc/ctrl/ctrl2080/ctrl2080ce.h> #include <nvrm/535.113.01/common/sdk/nvidia/inc/ctrl/ctrl2080/ctrl2080fifo.h> #include <nvrm/535.113.01/common/sdk/nvidia/inc/ctrl/ctrl2080/ctrl2080gpu.h> +#include <nvrm/535.113.01/common/sdk/nvidia/inc/ctrl/ctrl2080/ctrl2080gr.h> #include <nvrm/535.113.01/common/sdk/nvidia/inc/ctrl/ctrl2080/ctrl2080internal.h> #include <nvrm/535.113.01/common/sdk/nvidia/inc/ctrl/ctrla06f/ctrla06fgpfifo.h> #include <nvrm/535.113.01/nvidia/generated/g_kernel_channel_nvoc.h>
@@ -328,6 +329,30 @@ r535_chan_id_get(struct nvkm_chan *chan, struct nvkm_memory *muserd, u64 ouserd)return ret; } +static int +r535_chan_set_zcull_ctxsw_buffer (struct nvkm_chan *chan,u64 addr) +{ +NV2080_CTRL_GR_CTXSW_ZCULL_BIND_PARAMS *ctrl; + + ctrl =nvkm_gsp_rm_ctrl_get (&chan->vmm->rm.device.subdevice, +NV2080_CTRL_CMD_GR_CTXSW_ZCULL_BIND ,sizeof (*ctrl)); + +if (WARN_ON (IS_ERR (ctrl))) +return PTR_ERR (ctrl); + + ctrl->hClient = chan->vmm->rm.client.object.handle; + ctrl->hChannel = chan->rm.object.handle; +if (addr) { + ctrl->vMemPtr = addr; + ctrl->zcullMode =NV2080_CTRL_CTXSW_ZCULL_MODE_SEPARATE_BUFFER ; + }else { + ctrl->vMemPtr =0 ; + ctrl->zcullMode =NV2080_CTRL_CTXSW_ZCULL_MODE_NO_CTXSW ; + } + +return nvkm_gsp_rm_ctrl_wr (&chan->vmm->rm.device.subdevice, ctrl); +} +static const struct nvkm_chan_func r535_chan = { .id_get = r535_chan_id_get,
@@ -338,6 +363,7 @@ r535_chan = { .start = r535_chan_start, .stop = r535_chan_stop, .doorbell_handle = r535_chan_doorbell_handle, + .set_zcull_ctxsw_buffer = r535_chan_set_zcull_ctxsw_buffer, }; static const struct nvkm_cgrp_func
drivers/gpu/drm/nouveau/nvkm/engine/fifo/uchan.c +17 -0
@@ -31,6 +31,7 @@#include <subdev/mmu.h> #include <engine/dma.h> +#include <nvkm/engine/gr.h> #include <nvif/if0020.h> struct nvkm_uchan {
@@ -268,6 +269,21 @@ nvkm_uchan_map(struct nvkm_object *object, void *argv, u32 argc,return 0 ; } +static int +nvkm_uchan_mthd (struct nvkm_object *object,u32 mthd,void *argv,u32 argc) +{ +struct nvkm_chan *chan =nvkm_uchan (object)->chan; +struct nvif_chan_mthd_set_zcull_ctxsw_buffer *args = argv; + +if (mthd !=NVIF_CHAN_MTHD_SET_ZCULL_CTXSW_BUFFER ) +return -ENOTTY ; + +if (argc <sizeof (*args)) +return -EINVAL ; + +return nvkm_chan_set_zcull_ctxsw_buffer (chan, args->addr); +} +static int nvkm_uchan_fini (struct nvkm_object *object,bool suspend) {
@@ -312,6 +328,7 @@ nvkm_uchan = { .dtor = nvkm_uchan_dtor, .init = nvkm_uchan_init, .fini = nvkm_uchan_fini, + .mthd = nvkm_uchan_mthd, .map = nvkm_uchan_map, .sclass = nvkm_uchan_sclass, .uevent = nvkm_uchan_uevent,
include/uapi/drm/nouveau_drm.h +16 -0
@@ -448,6 +448,20 @@ struct drm_nouveau_get_zcull_info {__u32 ctxsw_align; }; +struct drm_nouveau_set_zcull_ctxsw_buffer { +/** +* @ptr: The virtual address for the buffer, or null to bind nothing +*/ +__u64 addr; + +/** +* @channel: the channel to set the buffer on +*/ +__u32 channel; + +__u32 pad; +}; +#define DRM_NOUVEAU_GETPARAM 0x00#define DRM_NOUVEAU_SETPARAM 0x01/* deprecated */ #define DRM_NOUVEAU_CHANNEL_ALLOC 0x02
@@ -462,6 +476,7 @@ struct drm_nouveau_get_zcull_info {#define DRM_NOUVEAU_VM_BIND 0x11#define DRM_NOUVEAU_EXEC 0x12#define DRM_NOUVEAU_GET_ZCULL_INFO 0x13 +#define DRM_NOUVEAU_SET_ZCULL_CTXSW_BUFFER 0x14#define DRM_NOUVEAU_GEM_NEW 0x40#define DRM_NOUVEAU_GEM_PUSHBUF 0x41#define DRM_NOUVEAU_GEM_CPU_PREP 0x42
@@ -532,6 +547,7 @@ struct drm_nouveau_svm_bind {#define DRM_IOCTL_NOUVEAU_EXEC DRM_IOWR(DRM_COMMAND_BASE + DRM_NOUVEAU_EXEC, struct drm_nouveau_exec)#define DRM_IOCTL_NOUVEAU_GET_ZCULL_INFO DRM_IOR (DRM_COMMAND_BASE + DRM_NOUVEAU_GET_ZCULL_INFO, struct drm_nouveau_get_zcull_info) +#define DRM_IOCTL_NOUVEAU_SET_ZCULL_CTXSW_BUFFER DRM_IOW (DRM_COMMAND_BASE + DRM_NOUVEAU_SET_ZCULL_CTXSW_BUFFER, struct drm_nouveau_set_zcull_ctxsw_buffer)#if defined(__cplusplus) }#endif
Signature · 1 line
2.48.1
Danilo Krummrich
maintainerRe: [PATCH 2/2] drm/nouveau: DRM_NOUVEAU_SET_ZCULL_CTXSW_BUFFER
include/uapi/drm/nouveau_drm.h
Quoted 1 line · Mel Henning
include/uapi/drm/nouveau_drm.h +0
-0
Same here, please split the uAPI change in a separate commit.
include/uapi/drm/nouveau_drm.h struct drm_nouveau_get_zcull_info { · line 455
Quoted 12 lines
index
33361784eb4e..e9638f4dd7e6100644include/uapi/drm/nouveau_drm.h +5
-0@@ -448,6 +448,20 @@ struct drm_nouveau_get_zcull_info {__u32 ctxsw_align; }; +struct drm_nouveau_set_zcull_ctxsw_buffer { +/** +* @ptr: The virtual address for the buffer, or null to bind nothing +*/ +__u64 addr;
What is this buffer? Is this a GEM object backed buffer? How is it mapped?
Quoted 31 lines
include/uapi/drm/nouveau_drm.h +11
-0+ +/** +* @channel: the channel to set the buffer on +*/ +__u32 channel; + +__u32 pad; +}; +#define DRM_NOUVEAU_GETPARAM 0x00#define DRM_NOUVEAU_SETPARAM 0x01/* deprecated */ #define DRM_NOUVEAU_CHANNEL_ALLOC 0x02@@ -462,6 +476,7 @@ struct drm_nouveau_get_zcull_info {#define DRM_NOUVEAU_VM_BIND 0x11#define DRM_NOUVEAU_EXEC 0x12#define DRM_NOUVEAU_GET_ZCULL_INFO 0x13 +#define DRM_NOUVEAU_SET_ZCULL_CTXSW_BUFFER 0x14#define DRM_NOUVEAU_GEM_NEW 0x40#define DRM_NOUVEAU_GEM_PUSHBUF 0x41#define DRM_NOUVEAU_GEM_CPU_PREP 0x42@@ -532,6 +547,7 @@ struct drm_nouveau_svm_bind {#define DRM_IOCTL_NOUVEAU_EXEC DRM_IOWR(DRM_COMMAND_BASE + DRM_NOUVEAU_EXEC, struct drm_nouveau_exec)#define DRM_IOCTL_NOUVEAU_GET_ZCULL_INFO DRM_IOR (DRM_COMMAND_BASE + DRM_NOUVEAU_GET_ZCULL_INFO, struct drm_nouveau_get_zcull_info) +#define DRM_IOCTL_NOUVEAU_SET_ZCULL_CTXSW_BUFFER DRM_IOW (DRM_COMMAND_BASE + DRM_NOUVEAU_SET_ZCULL_CTXSW_BUFFER, struct drm_nouveau_set_zcull_ctxsw_buffer)#if defined(__cplusplus) }#endif Signature · 1 line
2.48.1
Re: [PATCH 2/2] drm/nouveau: DRM_NOUVEAU_SET_ZCULL_CTXSW_BUFFER
This is a pointer in the gpu's virtual address space. It must be aligned according to ctxsw_align and be at least ctxsw_size bytes (where those values come from the nouveau_abi16_ioctl_get_zcull_info structure). I'll change the description to say that much.
Yes, this is GEM-backed. I'm actually not entirely sure what the requirements are here, since this part is reverse-engineered. I think NOUVEAU_GEM_DOMAIN_VRAM and NOUVEAU_GEM_DOMAIN_GART are both okay. The proprietary driver allocates this buffer using NV_ESC_RM_VID_HEAP_CONTROL and sets attr = NVOS32_ATTR_LOCATION_ANY | NVOS32_ATTR_PAGE_SIZE_BIG | NVOS32_ATTR_PHYSICALITY_CONTIGUOUS, attr2 = NVOS32_ATTR2_GPU_CACHEABLE_YES | NVOS32_ATTR2_ZBC_PREFER_NO_ZBC.
Quoted 52 lines · Danilo Krummrich
include/uapi/drm/nouveau_drm.h
Quoted 1 line · Mel Henning
include/uapi/drm/nouveau_drm.h +0
-0Same here, please split the uAPI change in a separate commit.
include/uapi/drm/nouveau_drm.h struct drm_nouveau_get_zcull_info { · line 455
Quoted 12 lines
index
33361784eb4e..e9638f4dd7e6100644include/uapi/drm/nouveau_drm.h +5
-0@@ -448,6 +448,20 @@ struct drm_nouveau_get_zcull_info {__u32 ctxsw_align; }; +struct drm_nouveau_set_zcull_ctxsw_buffer { +/** +* @ptr: The virtual address for the buffer, or null to bind nothing +*/ +__u64 addr;What is this buffer? Is this a GEM object backed buffer? How is it mapped?
Quoted 31 lines
include/uapi/drm/nouveau_drm.h +11
-1+ +/** +* @channel: the channel to set the buffer on +*/ +__u32 channel; + +__u32 pad; +}; +#define DRM_NOUVEAU_GETPARAM 0x00#define DRM_NOUVEAU_SETPARAM 0x01/* deprecated */ #define DRM_NOUVEAU_CHANNEL_ALLOC 0x02@@ -462,6 +476,7 @@ struct drm_nouveau_get_zcull_info {#define DRM_NOUVEAU_VM_BIND 0x11#define DRM_NOUVEAU_EXEC 0x12#define DRM_NOUVEAU_GET_ZCULL_INFO 0x13 +#define DRM_NOUVEAU_SET_ZCULL_CTXSW_BUFFER 0x14#define DRM_NOUVEAU_GEM_NEW 0x40#define DRM_NOUVEAU_GEM_PUSHBUF 0x41#define DRM_NOUVEAU_GEM_CPU_PREP 0x42@@ -532,6 +547,7 @@ struct drm_nouveau_svm_bind {#define DRM_IOCTL_NOUVEAU_EXEC DRM_IOWR(DRM_COMMAND_BASE + DRM_NOUVEAU_EXEC, struct drm_nouveau_exec)#define DRM_IOCTL_NOUVEAU_GET_ZCULL_INFO DRM_IOR (DRM_COMMAND_BASE + DRM_NOUVEAU_GET_ZCULL_INFO, struct drm_nouveau_get_zcull_info) +#define DRM_IOCTL_NOUVEAU_SET_ZCULL_CTXSW_BUFFER DRM_IOW (DRM_COMMAND_BASE + DRM_NOUVEAU_SET_ZCULL_CTXSW_BUFFER, struct drm_nouveau_set_zcull_ctxsw_buffer)#if defined(__cplusplus) }#endif --2.48.1
Danilo Krummrich
maintainerRe: [PATCH 2/2] drm/nouveau: DRM_NOUVEAU_SET_ZCULL_CTXSW_BUFFER
Quoted 5 lines · M Henning
This is a pointer in the gpu's virtual address space. It must be aligned according to
ctxsw_alignand be at leastctxsw_sizebytes (where those values come from thenouveau_abi16_ioctl_get_zcull_infostructure). I'll change the description to say that much.
Quoted 7 lines
Yes, this is GEM-backed. I'm actually not entirely sure what the requirements are here, since this part is reverse-engineered. I think
NOUVEAU_GEM_DOMAIN_VRAMandNOUVEAU_GEM_DOMAIN_GARTare both okay. The proprietary driver allocates this buffer usingNV_ESC_RM_VID_HEAP_CONTROLand sets attr =NVOS32_ATTR_LOCATION_ANY|NVOS32_ATTR_PAGE_SIZE_BIG|NVOS32_ATTR_PHYSICALITY_CONTIGUOUS, attr2 =NVOS32_ATTR2_GPU_CACHEABLE_YES|NVOS32_ATTR2_ZBC_PREFER_NO_ZBC.
(Please do not top post.)
What I mean is how do you map the backing GEM into the GPU's virtual address space? Since it's bound to a channel, I assume that it must be ensured it's properly mapped when work is pushed to the channel. Is it mapped through VM_BIND?
Quoted 54 lines · Danilo Krummrich
Quoted 52 lines · Mel Henning
include/uapi/drm/nouveau_drm.h
Quoted 1 line
include/uapi/drm/nouveau_drm.h +0
-0Same here, please split the uAPI change in a separate commit.
include/uapi/drm/nouveau_drm.h struct drm_nouveau_get_zcull_info { · line 455
Quoted 12 lines
index
33361784eb4e..e9638f4dd7e6100644include/uapi/drm/nouveau_drm.h +5
-0@@ -448,6 +448,20 @@ struct drm_nouveau_get_zcull_info {__u32 ctxsw_align; }; +struct drm_nouveau_set_zcull_ctxsw_buffer { +/** +* @ptr: The virtual address for the buffer, or null to bind nothing +*/ +__u64 addr;What is this buffer? Is this a GEM object backed buffer? How is it mapped?
Quoted 31 lines
include/uapi/drm/nouveau_drm.h +11
-1+ +/** +* @channel: the channel to set the buffer on +*/ +__u32 channel; + +__u32 pad; +}; +#define DRM_NOUVEAU_GETPARAM 0x00#define DRM_NOUVEAU_SETPARAM 0x01/* deprecated */ #define DRM_NOUVEAU_CHANNEL_ALLOC 0x02@@ -462,6 +476,7 @@ struct drm_nouveau_get_zcull_info {#define DRM_NOUVEAU_VM_BIND 0x11#define DRM_NOUVEAU_EXEC 0x12#define DRM_NOUVEAU_GET_ZCULL_INFO 0x13 +#define DRM_NOUVEAU_SET_ZCULL_CTXSW_BUFFER 0x14#define DRM_NOUVEAU_GEM_NEW 0x40#define DRM_NOUVEAU_GEM_PUSHBUF 0x41#define DRM_NOUVEAU_GEM_CPU_PREP 0x42@@ -532,6 +547,7 @@ struct drm_nouveau_svm_bind {#define DRM_IOCTL_NOUVEAU_EXEC DRM_IOWR(DRM_COMMAND_BASE + DRM_NOUVEAU_EXEC, struct drm_nouveau_exec)#define DRM_IOCTL_NOUVEAU_GET_ZCULL_INFO DRM_IOR (DRM_COMMAND_BASE + DRM_NOUVEAU_GET_ZCULL_INFO, struct drm_nouveau_get_zcull_info) +#define DRM_IOCTL_NOUVEAU_SET_ZCULL_CTXSW_BUFFER DRM_IOW (DRM_COMMAND_BASE + DRM_NOUVEAU_SET_ZCULL_CTXSW_BUFFER, struct drm_nouveau_set_zcull_ctxsw_buffer)#if defined(__cplusplus) }#endif --2.48.1
Re: [PATCH 2/2] drm/nouveau: DRM_NOUVEAU_SET_ZCULL_CTXSW_BUFFER
Quoted 15 lines · Danilo Krummrich
Quoted 5 lines · M Henning
This is a pointer in the gpu's virtual address space. It must be aligned according to
ctxsw_alignand be at leastctxsw_sizebytes (where those values come from thenouveau_abi16_ioctl_get_zcull_infostructure). I'll change the description to say that much.Quoted 7 lines
Yes, this is GEM-backed. I'm actually not entirely sure what the requirements are here, since this part is reverse-engineered. I think
NOUVEAU_GEM_DOMAIN_VRAMandNOUVEAU_GEM_DOMAIN_GARTare both okay. The proprietary driver allocates this buffer usingNV_ESC_RM_VID_HEAP_CONTROLand sets attr =NVOS32_ATTR_LOCATION_ANY|NVOS32_ATTR_PAGE_SIZE_BIG|NVOS32_ATTR_PHYSICALITY_CONTIGUOUS, attr2 =NVOS32_ATTR2_GPU_CACHEABLE_YES|NVOS32_ATTR2_ZBC_PREFER_NO_ZBC.
Quoted 6 lines
(Please do not top post.)
What I mean is how do you map the backing GEM into the GPU's virtual address space? Since it's bound to a channel, I assume that it must be ensured it's properly mapped when work is pushed to the channel. Is it mapped through
VM_BIND?
Yes. The userspace code for this is here:
https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33861/diffs?commit_id=0c4baab863730f9fc8b417834ffcbb400f11d617
It calls into the usual function for driver internal allocations (nvkmd_dev_alloc_mem) which calls VM_BIND internally.
I don't understand: why is this line of questioning important?
Quoted 54 lines
Quoted 54 lines · Danilo Krummrich
Quoted 52 lines · Mel Henning
include/uapi/drm/nouveau_drm.h
Quoted 1 line
include/uapi/drm/nouveau_drm.h +0
-0Same here, please split the uAPI change in a separate commit.
include/uapi/drm/nouveau_drm.h struct drm_nouveau_get_zcull_info { · line 455
Quoted 12 lines
index
33361784eb4e..e9638f4dd7e6100644include/uapi/drm/nouveau_drm.h +5
-0@@ -448,6 +448,20 @@ struct drm_nouveau_get_zcull_info {__u32 ctxsw_align; }; +struct drm_nouveau_set_zcull_ctxsw_buffer { +/** +* @ptr: The virtual address for the buffer, or null to bind nothing +*/ +__u64 addr;What is this buffer? Is this a GEM object backed buffer? How is it mapped?
Quoted 31 lines
include/uapi/drm/nouveau_drm.h +11
-1+ +/** +* @channel: the channel to set the buffer on +*/ +__u32 channel; + +__u32 pad; +}; +#define DRM_NOUVEAU_GETPARAM 0x00#define DRM_NOUVEAU_SETPARAM 0x01/* deprecated */ #define DRM_NOUVEAU_CHANNEL_ALLOC 0x02@@ -462,6 +476,7 @@ struct drm_nouveau_get_zcull_info {#define DRM_NOUVEAU_VM_BIND 0x11#define DRM_NOUVEAU_EXEC 0x12#define DRM_NOUVEAU_GET_ZCULL_INFO 0x13 +#define DRM_NOUVEAU_SET_ZCULL_CTXSW_BUFFER 0x14#define DRM_NOUVEAU_GEM_NEW 0x40#define DRM_NOUVEAU_GEM_PUSHBUF 0x41#define DRM_NOUVEAU_GEM_CPU_PREP 0x42@@ -532,6 +547,7 @@ struct drm_nouveau_svm_bind {#define DRM_IOCTL_NOUVEAU_EXEC DRM_IOWR(DRM_COMMAND_BASE + DRM_NOUVEAU_EXEC, struct drm_nouveau_exec)#define DRM_IOCTL_NOUVEAU_GET_ZCULL_INFO DRM_IOR (DRM_COMMAND_BASE + DRM_NOUVEAU_GET_ZCULL_INFO, struct drm_nouveau_get_zcull_info) +#define DRM_IOCTL_NOUVEAU_SET_ZCULL_CTXSW_BUFFER DRM_IOW (DRM_COMMAND_BASE + DRM_NOUVEAU_SET_ZCULL_CTXSW_BUFFER, struct drm_nouveau_set_zcull_ctxsw_buffer)#if defined(__cplusplus) }#endif --2.48.1
Danilo Krummrich
maintainerRe: [PATCH 2/2] drm/nouveau: DRM_NOUVEAU_SET_ZCULL_CTXSW_BUFFER
Quoted 23 lines · M Henning
Quoted 15 lines · Danilo Krummrich
Quoted 5 lines · M Henning
This is a pointer in the gpu's virtual address space. It must be aligned according to
ctxsw_alignand be at leastctxsw_sizebytes (where those values come from thenouveau_abi16_ioctl_get_zcull_infostructure). I'll change the description to say that much.Quoted 7 lines
Yes, this is GEM-backed. I'm actually not entirely sure what the requirements are here, since this part is reverse-engineered. I think
NOUVEAU_GEM_DOMAIN_VRAMandNOUVEAU_GEM_DOMAIN_GARTare both okay. The proprietary driver allocates this buffer usingNV_ESC_RM_VID_HEAP_CONTROLand sets attr =NVOS32_ATTR_LOCATION_ANY|NVOS32_ATTR_PAGE_SIZE_BIG|NVOS32_ATTR_PHYSICALITY_CONTIGUOUS, attr2 =NVOS32_ATTR2_GPU_CACHEABLE_YES|NVOS32_ATTR2_ZBC_PREFER_NO_ZBC.Quoted 6 lines
(Please do not top post.)
What I mean is how do you map the backing GEM into the GPU's virtual address space? Since it's bound to a channel, I assume that it must be ensured it's properly mapped when work is pushed to the channel. Is it mapped through
VM_BIND?
Quoted 4 lines
Yes. The userspace code for this is here:
https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33861/diffs?commit_id=0c4baab863730f9fc8b417834ffcbb400f11d617
It calls into the usual function for driver internal allocations (nvkmd_dev_alloc_mem) which callsVM_BINDinternally.
BOs mapped through VM_BIND are prone to eviction, is this a problem here, or is it fine if it is only ensured that this mapping is valid for the duration of subsequent EXEC jobs?
Does the mapping need to be valid when DRM_NOUVEAU_SET_ZCULL_CTXSW_BUFFER is called? If so, how is this ensured?
Can DRM_NOUVEAU_SET_ZCULL_CTXSW_BUFFER be called in between multiple DRM_NOUVEAU_EXEC calls?
Does it maybe need an async mode, such as EXEC and VM_BIND? (To me it doesn't seem to be the case, but those questions still need an answer.)
I also think we should document those things.
Quoted 1 line
I don't understand: why is this line of questioning important?
By sending those patches you ask me as the maintainer of the project to take resposibility of your changes. In this case it even goes further. In fact, you ask me to take resposibility of a new interface, which, since it is a uAPI, can *never* be removed in the future after being released.
It is part of my job to act responsibly, which includes understanding what the interface does, how it is intended to be used, whether it is sufficient for its purpose or if it has any flaws.
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines · Danilo Krummrich
Quoted 20 lines · Mel Henning
include/uapi/drm/nouveau_drm.h
Quoted 1 line
include/uapi/drm/nouveau_drm.h +0
-0Same here, please split the uAPI change in a separate commit.
include/uapi/drm/nouveau_drm.h struct drm_nouveau_get_zcull_info { · line 455
Quoted 12 lines
index
33361784eb4e..e9638f4dd7e6100644include/uapi/drm/nouveau_drm.h +5
-0@@ -448,6 +448,20 @@ struct drm_nouveau_get_zcull_info {__u32 ctxsw_align; }; +struct drm_nouveau_set_zcull_ctxsw_buffer { +/** +* @ptr: The virtual address for the buffer, or null to bind nothing +*/ +__u64 addr;What is this buffer? Is this a GEM object backed buffer? How is it mapped?
Re: [PATCH 2/2] drm/nouveau: DRM_NOUVEAU_SET_ZCULL_CTXSW_BUFFER
Quoted 25 lines · Danilo Krummrich
Quoted 23 lines · M Henning
Quoted 21 lines · Danilo Krummrich
Quoted 5 lines · M Henning
This is a pointer in the gpu's virtual address space. It must be aligned according to
ctxsw_alignand be at leastctxsw_sizebytes (where those values come from thenouveau_abi16_ioctl_get_zcull_infostructure). I'll change the description to say that much.Quoted 7 lines
Yes, this is GEM-backed. I'm actually not entirely sure what the requirements are here, since this part is reverse-engineered. I think
NOUVEAU_GEM_DOMAIN_VRAMandNOUVEAU_GEM_DOMAIN_GARTare both okay. The proprietary driver allocates this buffer usingNV_ESC_RM_VID_HEAP_CONTROLand sets attr =NVOS32_ATTR_LOCATION_ANY|NVOS32_ATTR_PAGE_SIZE_BIG|NVOS32_ATTR_PHYSICALITY_CONTIGUOUS, attr2 =NVOS32_ATTR2_GPU_CACHEABLE_YES|NVOS32_ATTR2_ZBC_PREFER_NO_ZBC.(Please do not top post.)
What I mean is how do you map the backing GEM into the GPU's virtual address space? Since it's bound to a channel, I assume that it must be ensured it's properly mapped when work is pushed to the channel. Is it mapped through
VM_BIND?
Quoted 8 lines
Quoted 4 lines
Yes. The userspace code for this is here:
https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33861/diffs?commit_id=0c4baab863730f9fc8b417834ffcbb400f11d617
It calls into the usual function for driver internal allocations (nvkmd_dev_alloc_mem) which callsVM_BINDinternally.BOs mapped through
VM_BINDare prone to eviction, is this a problem here, or is it fine if it is only ensured that this mapping is valid for the duration of subsequent EXEC jobs?
I don't see the proprietary driver doing anything special related to eviction in traces, which is to say that I think it's fine for it to just be valid for subsequent EXEC jobs. That being said, I don't have the deepest understanding of how memory mapping works in open-gpu-kernel-modules so I might have missed something.
Is there a good way to test this code path? Can I eg. force the kernel to evict everything in order to test that the context switching still works?
Quoted 2 lines
Does the mapping need to be valid when
DRM_NOUVEAU_SET_ZCULL_CTXSW_BUFFERis called? If so, how is this ensured?
I don't think so. My understanding is that this call is just setting a pointer.
Quoted 2 lines
Can
DRM_NOUVEAU_SET_ZCULL_CTXSW_BUFFERbe called in between multipleDRM_NOUVEAU_EXECcalls?
Yes, there's nothing that requires a specific ordering - we can use the context normally before and after the DRM_NOUVEAU_SET_ZCULL_CTXSW_BUFFER call.
Quoted 2 lines
Does it maybe need an async mode, such as EXEC and
VM_BIND? (To me it doesn't seem to be the case, but those questions still need an answer.)
I don't think so. Userspace calls it twice per context right now (once for init, once for teardown), so I don't expect it to be especially perf critical.
Quoted 4 lines
I also think we should document those things.
Quoted 1 line
I don't understand: why is this line of questioning important?
Quoted 8 lines
By sending those patches you ask me as the maintainer of the project to take resposibility of your changes. In this case it even goes further. In fact, you ask me to take resposibility of a new interface, which, since it is a uAPI, can *never* be removed in the future after being released.
It is part of my job to act responsibly, which includes understanding what the interface does, how it is intended to be used, whether it is sufficient for its purpose or if it has any flaws.
Right, sorry about this - I didn't mean to question the purpose of you asking questions at all. You of course have every right to ask questions about a patch during code review. I was more just confused about why you were asking me specifically about VM_BIND, although I think that's a bit clearer to me now that you've asked questions about eviction.