11465dc26a540e2b6f8a055cf0ab48f774a3775bfMaarten Lankhorst#ifndef __NOUVEAU_VIDEO_H__
26d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller#define __NOUVEAU_VIDEO_H__
31465dc26a540e2b6f8a055cf0ab48f774a3775bfMaarten Lankhorst
41465dc26a540e2b6f8a055cf0ab48f774a3775bfMaarten Lankhorst#include "nv17_mpeg.xml.h"
51465dc26a540e2b6f8a055cf0ab48f774a3775bfMaarten Lankhorst#include "nv31_mpeg.xml.h"
66d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller#include "nv_object.xml.h"
76d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller
86d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller#include "nouveau_winsys.h"
91465dc26a540e2b6f8a055cf0ab48f774a3775bfMaarten Lankhorst
101465dc26a540e2b6f8a055cf0ab48f774a3775bfMaarten Lankhorststruct nouveau_video_buffer {
111465dc26a540e2b6f8a055cf0ab48f774a3775bfMaarten Lankhorst   struct pipe_video_buffer base;
121465dc26a540e2b6f8a055cf0ab48f774a3775bfMaarten Lankhorst   unsigned num_planes;
13ebe7c687ceed4e5ca704b325aac6b91791d394b0Maarten Lankhorst   struct pipe_resource     *resources[3];
14ebe7c687ceed4e5ca704b325aac6b91791d394b0Maarten Lankhorst   struct pipe_sampler_view *sampler_view_planes[3];
151465dc26a540e2b6f8a055cf0ab48f774a3775bfMaarten Lankhorst   struct pipe_sampler_view *sampler_view_components[3];
16ebe7c687ceed4e5ca704b325aac6b91791d394b0Maarten Lankhorst   struct pipe_surface      *surfaces[3];
171465dc26a540e2b6f8a055cf0ab48f774a3775bfMaarten Lankhorst};
181465dc26a540e2b6f8a055cf0ab48f774a3775bfMaarten Lankhorst
191465dc26a540e2b6f8a055cf0ab48f774a3775bfMaarten Lankhorststruct nouveau_decoder {
201465dc26a540e2b6f8a055cf0ab48f774a3775bfMaarten Lankhorst   struct pipe_video_decoder base;
211465dc26a540e2b6f8a055cf0ab48f774a3775bfMaarten Lankhorst   struct nouveau_screen *screen;
226d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   struct nouveau_pushbuf *push;
236d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   struct nouveau_object *chan;
246d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   struct nouveau_client *client;
256d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   struct nouveau_bufctx *bufctx;
266d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   struct nouveau_object *mpeg;
271465dc26a540e2b6f8a055cf0ab48f774a3775bfMaarten Lankhorst   struct nouveau_bo *cmd_bo, *data_bo, *fence_bo;
281465dc26a540e2b6f8a055cf0ab48f774a3775bfMaarten Lankhorst
291465dc26a540e2b6f8a055cf0ab48f774a3775bfMaarten Lankhorst   unsigned *fence_map;
301465dc26a540e2b6f8a055cf0ab48f774a3775bfMaarten Lankhorst   unsigned fence_seq;
311465dc26a540e2b6f8a055cf0ab48f774a3775bfMaarten Lankhorst
321465dc26a540e2b6f8a055cf0ab48f774a3775bfMaarten Lankhorst   unsigned ofs;
331465dc26a540e2b6f8a055cf0ab48f774a3775bfMaarten Lankhorst   unsigned *cmds;
341465dc26a540e2b6f8a055cf0ab48f774a3775bfMaarten Lankhorst
351465dc26a540e2b6f8a055cf0ab48f774a3775bfMaarten Lankhorst   unsigned *data;
361465dc26a540e2b6f8a055cf0ab48f774a3775bfMaarten Lankhorst   unsigned data_pos;
371465dc26a540e2b6f8a055cf0ab48f774a3775bfMaarten Lankhorst   unsigned picture_structure;
381465dc26a540e2b6f8a055cf0ab48f774a3775bfMaarten Lankhorst
391465dc26a540e2b6f8a055cf0ab48f774a3775bfMaarten Lankhorst   unsigned past, future, current;
401465dc26a540e2b6f8a055cf0ab48f774a3775bfMaarten Lankhorst   unsigned num_surfaces;
411465dc26a540e2b6f8a055cf0ab48f774a3775bfMaarten Lankhorst   struct nouveau_video_buffer *surfaces[8];
421465dc26a540e2b6f8a055cf0ab48f774a3775bfMaarten Lankhorst};
431465dc26a540e2b6f8a055cf0ab48f774a3775bfMaarten Lankhorst
446d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller#define NV31_VIDEO_BIND_IMG(i)  i
456d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller#define NV31_VIDEO_BIND_CMD     NV31_MPEG_IMAGE_Y_OFFSET__LEN
466d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller#define NV31_VIDEO_BIND_COUNT  (NV31_MPEG_IMAGE_Y_OFFSET__LEN + 1)
476d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller
481465dc26a540e2b6f8a055cf0ab48f774a3775bfMaarten Lankhorststatic INLINE void
491465dc26a540e2b6f8a055cf0ab48f774a3775bfMaarten Lankhorstnouveau_vpe_write(struct nouveau_decoder *dec, unsigned data) {
501465dc26a540e2b6f8a055cf0ab48f774a3775bfMaarten Lankhorst   dec->cmds[dec->ofs++] = data;
511465dc26a540e2b6f8a055cf0ab48f774a3775bfMaarten Lankhorst}
521465dc26a540e2b6f8a055cf0ab48f774a3775bfMaarten Lankhorst
536d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller#define SUBC_MPEG(mthd) 1, mthd
546d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller#define NV31_MPEG(mthd) SUBC_MPEG(NV31_MPEG_##mthd)
556d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller#define NV84_MPEG(mthd) SUBC_MPEG(NV84_MPEG_##mthd)
566d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller
576d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumillerstatic INLINE uint32_t
586d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph BumillerNV04_FIFO_PKHDR(int subc, int mthd, unsigned size)
596d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller{
606d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   return 0x00000000 | (size << 18) | (subc << 13) | mthd;
616d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller}
626d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller
636d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumillerstatic INLINE uint32_t
646d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph BumillerNV04_FIFO_PKHDR_NI(int subc, int mthd, unsigned size)
656d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller{
666d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   return 0x40000000 | (size << 18) | (subc << 13) | mthd;
676d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller}
686d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller
696d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumillerstatic INLINE void
706d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph BumillerBEGIN_NV04(struct nouveau_pushbuf *push, int subc, int mthd, unsigned size)
716d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller{
726d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_SPACE(push, size + 1);
736d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, NV04_FIFO_PKHDR(subc, mthd, size));
746d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller}
756d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller
766d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumillerstatic INLINE void
776d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph BumillerBEGIN_NI04(struct nouveau_pushbuf *push, int subc, int mthd, unsigned size)
786d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller{
796d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_SPACE(push, size + 1);
806d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA (push, NV04_FIFO_PKHDR_NI(subc, mthd, size));
816d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller}
826d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller
836d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumillerstatic INLINE void
846d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph BumillerPUSH_MTHDl(struct nouveau_pushbuf *push, int subc, int mthd,
856d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller           struct nouveau_bo *bo, uint32_t offset,
866d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller	   struct nouveau_bufctx *ctx, int bin, uint32_t rw)
876d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller{
886d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   nouveau_bufctx_mthd(ctx, bin, NV04_FIFO_PKHDR(subc, mthd, 1),
896d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller                       bo, offset,
906d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller                       NOUVEAU_BO_LOW | (bo->flags & NOUVEAU_BO_APER) | rw,
916d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller                       0, 0);
926d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller
936d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller   PUSH_DATA(push, bo->offset + offset);
946d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller}
956d1cdec3ba151168bfc3aef222fba6265dfb41fbChristoph Bumiller
961465dc26a540e2b6f8a055cf0ab48f774a3775bfMaarten Lankhorst#endif
97