From 90aeab9dee07a63e4bac6d92646dfd80e65d2edd Mon Sep 17 00:00:00 2001 From: Deepak Nibade Date: Fri, 10 Nov 2017 05:02:37 -0800 Subject: gpu: nvgpu: define preemption modes in common code We use linux specific graphics/compute preemption modes defined in uapi header (and of below form) in all over common code NVGPU_GRAPHICS_PREEMPTION_MODE_* NVGPU_COMPUTE_PREEMPTION_MODE_* Since common code should be independent of linux specific code, define new modes of the form in common code and used them everywhere NVGPU_PREEMPTION_MODE_GRAPHICS_* NVGPU_PREEMPTION_MODE_COMPUTE_* Add required parser functions to convert both the modes into each other For linux IOCTL NVGPU_IOCTL_CHANNEL_SET_PREEMPTION_MODE, we need to convert linux specific modes into common modes first before passing them to common code And to pass gpu characteristics to user space we need to first convert common modes into linux specific modes and then pass them to user space Jira NVGPU-392 Change-Id: I8c62c6859bdc1baa5b44eb31c7020e42d2462c8c Signed-off-by: Deepak Nibade Reviewed-on: https://git-master.nvidia.com/r/1596930 Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/common/linux/ioctl_channel.c | 148 ++++++++++++++++++++++--- 1 file changed, 130 insertions(+), 18 deletions(-) (limited to 'drivers/gpu/nvgpu/common/linux/ioctl_channel.c') diff --git a/drivers/gpu/nvgpu/common/linux/ioctl_channel.c b/drivers/gpu/nvgpu/common/linux/ioctl_channel.c index f5947828..6feb6fb7 100644 --- a/drivers/gpu/nvgpu/common/linux/ioctl_channel.c +++ b/drivers/gpu/nvgpu/common/linux/ioctl_channel.c @@ -45,7 +45,7 @@ static const char *gr_gk20a_graphics_preempt_mode_name(u32 graphics_preempt_mode) { switch (graphics_preempt_mode) { - case NVGPU_GRAPHICS_PREEMPTION_MODE_WFI: + case NVGPU_PREEMPTION_MODE_GRAPHICS_WFI: return "WFI"; default: return "?"; @@ -55,9 +55,9 @@ static const char *gr_gk20a_graphics_preempt_mode_name(u32 graphics_preempt_mode static const char *gr_gk20a_compute_preempt_mode_name(u32 compute_preempt_mode) { switch (compute_preempt_mode) { - case NVGPU_COMPUTE_PREEMPTION_MODE_WFI: + case NVGPU_PREEMPTION_MODE_COMPUTE_WFI: return "WFI"; - case NVGPU_COMPUTE_PREEMPTION_MODE_CTA: + case NVGPU_PREEMPTION_MODE_COMPUTE_CTA: return "CTA"; default: return "?"; @@ -991,6 +991,130 @@ static int nvgpu_ioctl_channel_alloc_obj_ctx(struct channel_gk20a *ch, nvgpu_obj_ctx_user_flags_to_common_flags(user_flags)); } +/* + * Convert common preemption mode flags of the form NVGPU_PREEMPTION_MODE_GRAPHICS_* + * into linux preemption mode flags of the form NVGPU_GRAPHICS_PREEMPTION_MODE_* + */ +u32 nvgpu_get_ioctl_graphics_preempt_mode_flags(u32 graphics_preempt_mode_flags) +{ + u32 flags = 0; + + if (graphics_preempt_mode_flags & NVGPU_PREEMPTION_MODE_GRAPHICS_WFI) + flags |= NVGPU_GRAPHICS_PREEMPTION_MODE_WFI; + if (graphics_preempt_mode_flags & NVGPU_PREEMPTION_MODE_GRAPHICS_GFXP) + flags |= NVGPU_GRAPHICS_PREEMPTION_MODE_GFXP; + + return flags; +} + +/* + * Convert common preemption mode flags of the form NVGPU_PREEMPTION_MODE_COMPUTE_* + * into linux preemption mode flags of the form NVGPU_COMPUTE_PREEMPTION_MODE_* + */ +u32 nvgpu_get_ioctl_compute_preempt_mode_flags(u32 compute_preempt_mode_flags) +{ + u32 flags = 0; + + if (compute_preempt_mode_flags & NVGPU_PREEMPTION_MODE_COMPUTE_WFI) + flags |= NVGPU_COMPUTE_PREEMPTION_MODE_WFI; + if (compute_preempt_mode_flags & NVGPU_PREEMPTION_MODE_COMPUTE_CTA) + flags |= NVGPU_COMPUTE_PREEMPTION_MODE_CTA; + if (compute_preempt_mode_flags & NVGPU_PREEMPTION_MODE_COMPUTE_CILP) + flags |= NVGPU_COMPUTE_PREEMPTION_MODE_CILP; + + return flags; +} + +/* + * Convert common preemption modes of the form NVGPU_PREEMPTION_MODE_GRAPHICS_* + * into linux preemption modes of the form NVGPU_GRAPHICS_PREEMPTION_MODE_* + */ +u32 nvgpu_get_ioctl_graphics_preempt_mode(u32 graphics_preempt_mode) +{ + switch (graphics_preempt_mode) { + case NVGPU_PREEMPTION_MODE_GRAPHICS_WFI: + return NVGPU_GRAPHICS_PREEMPTION_MODE_WFI; + case NVGPU_PREEMPTION_MODE_GRAPHICS_GFXP: + return NVGPU_GRAPHICS_PREEMPTION_MODE_GFXP; + } + + return graphics_preempt_mode; +} + +/* + * Convert common preemption modes of the form NVGPU_PREEMPTION_MODE_COMPUTE_* + * into linux preemption modes of the form NVGPU_COMPUTE_PREEMPTION_MODE_* + */ +u32 nvgpu_get_ioctl_compute_preempt_mode(u32 compute_preempt_mode) +{ + switch (compute_preempt_mode) { + case NVGPU_PREEMPTION_MODE_COMPUTE_WFI: + return NVGPU_COMPUTE_PREEMPTION_MODE_WFI; + case NVGPU_PREEMPTION_MODE_COMPUTE_CTA: + return NVGPU_COMPUTE_PREEMPTION_MODE_CTA; + case NVGPU_PREEMPTION_MODE_COMPUTE_CILP: + return NVGPU_COMPUTE_PREEMPTION_MODE_CILP; + } + + return compute_preempt_mode; +} + +/* + * Convert linux preemption modes of the form NVGPU_GRAPHICS_PREEMPTION_MODE_* + * into common preemption modes of the form NVGPU_PREEMPTION_MODE_GRAPHICS_* + */ +static u32 nvgpu_get_common_graphics_preempt_mode(u32 graphics_preempt_mode) +{ + switch (graphics_preempt_mode) { + case NVGPU_GRAPHICS_PREEMPTION_MODE_WFI: + return NVGPU_PREEMPTION_MODE_GRAPHICS_WFI; + case NVGPU_GRAPHICS_PREEMPTION_MODE_GFXP: + return NVGPU_PREEMPTION_MODE_GRAPHICS_GFXP; + } + + return graphics_preempt_mode; +} + +/* + * Convert linux preemption modes of the form NVGPU_COMPUTE_PREEMPTION_MODE_* + * into common preemption modes of the form NVGPU_PREEMPTION_MODE_COMPUTE_* + */ +static u32 nvgpu_get_common_compute_preempt_mode(u32 compute_preempt_mode) +{ + switch (compute_preempt_mode) { + case NVGPU_COMPUTE_PREEMPTION_MODE_WFI: + return NVGPU_PREEMPTION_MODE_COMPUTE_WFI; + case NVGPU_COMPUTE_PREEMPTION_MODE_CTA: + return NVGPU_PREEMPTION_MODE_COMPUTE_CTA; + case NVGPU_COMPUTE_PREEMPTION_MODE_CILP: + return NVGPU_PREEMPTION_MODE_COMPUTE_CILP; + } + + return compute_preempt_mode; +} + +static int nvgpu_ioctl_channel_set_preemption_mode(struct channel_gk20a *ch, + u32 graphics_preempt_mode, u32 compute_preempt_mode) +{ + int err; + + if (ch->g->ops.gr.set_preemption_mode) { + err = gk20a_busy(ch->g); + if (err) { + nvgpu_err(ch->g, "failed to power on, %d", err); + return err; + } + err = ch->g->ops.gr.set_preemption_mode(ch, + nvgpu_get_common_graphics_preempt_mode(graphics_preempt_mode), + nvgpu_get_common_compute_preempt_mode(compute_preempt_mode)); + gk20a_idle(ch->g); + } else { + err = -EINVAL; + } + + return err; +} + long gk20a_channel_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) { @@ -1302,21 +1426,9 @@ long gk20a_channel_ioctl(struct file *filp, gk20a_channel_get_timeslice(ch); break; case NVGPU_IOCTL_CHANNEL_SET_PREEMPTION_MODE: - if (ch->g->ops.gr.set_preemption_mode) { - err = gk20a_busy(ch->g); - if (err) { - dev_err(dev, - "%s: failed to host gk20a for ioctl cmd: 0x%x", - __func__, cmd); - break; - } - err = ch->g->ops.gr.set_preemption_mode(ch, - ((struct nvgpu_preemption_mode_args *)buf)->graphics_preempt_mode, - ((struct nvgpu_preemption_mode_args *)buf)->compute_preempt_mode); - gk20a_idle(ch->g); - } else { - err = -EINVAL; - } + err = nvgpu_ioctl_channel_set_preemption_mode(ch, + ((struct nvgpu_preemption_mode_args *)buf)->graphics_preempt_mode, + ((struct nvgpu_preemption_mode_args *)buf)->compute_preempt_mode); break; case NVGPU_IOCTL_CHANNEL_SET_BOOSTED_CTX: if (ch->g->ops.gr.set_boosted_ctx) { -- cgit v1.2.2