linux/drivers/gpu/drm/nouveau/dispnv50/ovly507e.c
<<
>>
Prefs
   1/*
   2 * Copyright 2018 Red Hat Inc.
   3 *
   4 * Permission is hereby granted, free of charge, to any person obtaining a
   5 * copy of this software and associated documentation files (the "Software"),
   6 * to deal in the Software without restriction, including without limitation
   7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
   8 * and/or sell copies of the Software, and to permit persons to whom the
   9 * Software is furnished to do so, subject to the following conditions:
  10 *
  11 * The above copyright notice and this permission notice shall be included in
  12 * all copies or substantial portions of the Software.
  13 *
  14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20 * OTHER DEALINGS IN THE SOFTWARE.
  21 */
  22#include "ovly.h"
  23#include "atom.h"
  24
  25#include <drm/drm_atomic_helper.h>
  26#include <drm/drm_fourcc.h>
  27#include <drm/drm_plane_helper.h>
  28
  29#include <nvif/cl507e.h>
  30#include <nvif/event.h>
  31
  32void
  33ovly507e_update(struct nv50_wndw *wndw, u32 *interlock)
  34{
  35        u32 *push;
  36        if ((push = evo_wait(&wndw->wndw, 2))) {
  37                evo_mthd(push, 0x0080, 1);
  38                evo_data(push, interlock[NV50_DISP_INTERLOCK_CORE]);
  39                evo_kick(push, &wndw->wndw);
  40        }
  41}
  42
  43void
  44ovly507e_scale_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
  45{
  46        u32 *push;
  47        if ((push = evo_wait(&wndw->wndw, 4))) {
  48                evo_mthd(push, 0x00e0, 3);
  49                evo_data(push, asyw->scale.sy << 16 | asyw->scale.sx);
  50                evo_data(push, asyw->scale.sh << 16 | asyw->scale.sw);
  51                evo_data(push, asyw->scale.dw);
  52                evo_kick(push, &wndw->wndw);
  53        }
  54}
  55
  56void
  57ovly507e_image_clr(struct nv50_wndw *wndw)
  58{
  59        u32 *push;
  60        if ((push = evo_wait(&wndw->wndw, 4))) {
  61                evo_mthd(push, 0x0084, 1);
  62                evo_data(push, 0x00000000);
  63                evo_mthd(push, 0x00c0, 1);
  64                evo_data(push, 0x00000000);
  65                evo_kick(push, &wndw->wndw);
  66        }
  67}
  68
  69static void
  70ovly507e_image_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
  71{
  72        u32 *push;
  73        if ((push = evo_wait(&wndw->wndw, 12))) {
  74                evo_mthd(push, 0x0084, 1);
  75                evo_data(push, asyw->image.interval << 4);
  76                evo_mthd(push, 0x00c0, 1);
  77                evo_data(push, asyw->image.handle[0]);
  78                evo_mthd(push, 0x0100, 1);
  79                evo_data(push, 0x00000002);
  80                evo_mthd(push, 0x0800, 1);
  81                evo_data(push, asyw->image.offset[0] >> 8);
  82                evo_mthd(push, 0x0808, 3);
  83                evo_data(push, asyw->image.h << 16 | asyw->image.w);
  84                evo_data(push, asyw->image.layout << 20 |
  85                               (asyw->image.pitch[0] >> 8) << 8 |
  86                               asyw->image.blocks[0] << 8 |
  87                               asyw->image.blockh);
  88                evo_data(push, asyw->image.kind << 16 |
  89                               asyw->image.format << 8 |
  90                               asyw->image.colorspace);
  91                evo_kick(push, &wndw->wndw);
  92        }
  93}
  94
  95void
  96ovly507e_ntfy_clr(struct nv50_wndw *wndw)
  97{
  98        u32 *push;
  99        if ((push = evo_wait(&wndw->wndw, 2))) {
 100                evo_mthd(push, 0x00a4, 1);
 101                evo_data(push, 0x00000000);
 102                evo_kick(push, &wndw->wndw);
 103        }
 104}
 105
 106void
 107ovly507e_ntfy_set(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw)
 108{
 109        u32 *push;
 110        if ((push = evo_wait(&wndw->wndw, 3))) {
 111                evo_mthd(push, 0x00a0, 2);
 112                evo_data(push, asyw->ntfy.awaken << 30 | asyw->ntfy.offset);
 113                evo_data(push, asyw->ntfy.handle);
 114                evo_kick(push, &wndw->wndw);
 115        }
 116}
 117
 118void
 119ovly507e_release(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw,
 120                 struct nv50_head_atom *asyh)
 121{
 122        asyh->ovly.cpp = 0;
 123}
 124
 125int
 126ovly507e_acquire(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw,
 127                 struct nv50_head_atom *asyh)
 128{
 129        const struct drm_framebuffer *fb = asyw->state.fb;
 130        int ret;
 131
 132        ret = drm_atomic_helper_check_plane_state(&asyw->state, &asyh->state,
 133                                                  DRM_PLANE_HELPER_NO_SCALING,
 134                                                  DRM_PLANE_HELPER_NO_SCALING,
 135                                                  true, true);
 136        if (ret)
 137                return ret;
 138
 139        asyh->ovly.cpp = fb->format->cpp[0];
 140        return 0;
 141}
 142
 143#include "nouveau_bo.h"
 144
 145static const struct nv50_wndw_func
 146ovly507e = {
 147        .acquire = ovly507e_acquire,
 148        .release = ovly507e_release,
 149        .ntfy_set = ovly507e_ntfy_set,
 150        .ntfy_clr = ovly507e_ntfy_clr,
 151        .ntfy_reset = base507c_ntfy_reset,
 152        .ntfy_wait_begun = base507c_ntfy_wait_begun,
 153        .image_set = ovly507e_image_set,
 154        .image_clr = ovly507e_image_clr,
 155        .scale_set = ovly507e_scale_set,
 156        .update = ovly507e_update,
 157};
 158
 159static const u32
 160ovly507e_format[] = {
 161        DRM_FORMAT_YUYV,
 162        DRM_FORMAT_UYVY,
 163        DRM_FORMAT_XRGB8888,
 164        DRM_FORMAT_XRGB1555,
 165        0
 166};
 167
 168int
 169ovly507e_new_(const struct nv50_wndw_func *func, const u32 *format,
 170              struct nouveau_drm *drm, int head, s32 oclass, u32 interlock_data,
 171              struct nv50_wndw **pwndw)
 172{
 173        struct nv50_disp_overlay_channel_dma_v0 args = {
 174                .head = head,
 175        };
 176        struct nv50_disp *disp = nv50_disp(drm->dev);
 177        struct nv50_wndw *wndw;
 178        int ret;
 179
 180        ret = nv50_wndw_new_(func, drm->dev, DRM_PLANE_TYPE_OVERLAY,
 181                             "ovly", head, format, BIT(head),
 182                             NV50_DISP_INTERLOCK_OVLY, interlock_data,
 183                             &wndw);
 184        if (*pwndw = wndw, ret)
 185                return ret;
 186
 187        ret = nv50_dmac_create(&drm->client.device, &disp->disp->object,
 188                               &oclass, 0, &args, sizeof(args),
 189                               disp->sync->bo.offset, &wndw->wndw);
 190        if (ret) {
 191                NV_ERROR(drm, "ovly%04x allocation failed: %d\n", oclass, ret);
 192                return ret;
 193        }
 194
 195        ret = nvif_notify_init(&wndw->wndw.base.user, wndw->notify.func, false,
 196                               NV50_DISP_OVERLAY_CHANNEL_DMA_V0_NTFY_UEVENT,
 197                               &(struct nvif_notify_uevent_req) {},
 198                               sizeof(struct nvif_notify_uevent_req),
 199                               sizeof(struct nvif_notify_uevent_rep),
 200                               &wndw->notify);
 201        if (ret)
 202                return ret;
 203
 204        wndw->ntfy = NV50_DISP_OVLY_NTFY(wndw->id);
 205        wndw->sema = NV50_DISP_OVLY_SEM0(wndw->id);
 206        wndw->data = 0x00000000;
 207        return 0;
 208}
 209
 210int
 211ovly507e_new(struct nouveau_drm *drm, int head, s32 oclass,
 212             struct nv50_wndw **pwndw)
 213{
 214        return ovly507e_new_(&ovly507e, ovly507e_format, drm, head, oclass,
 215                             0x00000004 << (head * 8), pwndw);
 216}
 217