1af69d88dSmrg#ifndef __NOUVEAU_VIDEO_H__
2af69d88dSmrg#define __NOUVEAU_VIDEO_H__
3af69d88dSmrg
4af69d88dSmrg#include "nv17_mpeg.xml.h"
5af69d88dSmrg#include "nv31_mpeg.xml.h"
6af69d88dSmrg#include "nv_object.xml.h"
7af69d88dSmrg
8af69d88dSmrg#include "nouveau_winsys.h"
9af69d88dSmrg
10af69d88dSmrgstruct nouveau_video_buffer {
11af69d88dSmrg   struct pipe_video_buffer base;
12af69d88dSmrg   unsigned num_planes;
13af69d88dSmrg   struct pipe_resource     *resources[VL_NUM_COMPONENTS];
14af69d88dSmrg   struct pipe_sampler_view *sampler_view_planes[VL_NUM_COMPONENTS];
15af69d88dSmrg   struct pipe_sampler_view *sampler_view_components[VL_NUM_COMPONENTS];
16af69d88dSmrg   struct pipe_surface      *surfaces[VL_NUM_COMPONENTS * 2];
17af69d88dSmrg};
18af69d88dSmrg
19af69d88dSmrgstruct nouveau_decoder {
20af69d88dSmrg   struct pipe_video_codec base;
21af69d88dSmrg   struct nouveau_screen *screen;
22af69d88dSmrg   struct nouveau_pushbuf *push;
23af69d88dSmrg   struct nouveau_object *chan;
24af69d88dSmrg   struct nouveau_client *client;
25af69d88dSmrg   struct nouveau_bufctx *bufctx;
26af69d88dSmrg   struct nouveau_object *mpeg;
27af69d88dSmrg   struct nouveau_bo *cmd_bo, *data_bo, *fence_bo;
28af69d88dSmrg
29af69d88dSmrg   unsigned *fence_map;
30af69d88dSmrg   unsigned fence_seq;
31af69d88dSmrg
32af69d88dSmrg   unsigned ofs;
33af69d88dSmrg   unsigned *cmds;
34af69d88dSmrg
35af69d88dSmrg   unsigned *data;
36af69d88dSmrg   unsigned data_pos;
37af69d88dSmrg   unsigned picture_structure;
38af69d88dSmrg
39af69d88dSmrg   unsigned past, future, current;
40af69d88dSmrg   unsigned num_surfaces;
41af69d88dSmrg   struct nouveau_video_buffer *surfaces[8];
42af69d88dSmrg};
43af69d88dSmrg
44af69d88dSmrg#define NV31_VIDEO_BIND_IMG(i)  i
45af69d88dSmrg#define NV31_VIDEO_BIND_CMD     NV31_MPEG_IMAGE_Y_OFFSET__LEN
46af69d88dSmrg#define NV31_VIDEO_BIND_COUNT  (NV31_MPEG_IMAGE_Y_OFFSET__LEN + 1)
47af69d88dSmrg
4801e04c3fSmrgstatic inline void
49af69d88dSmrgnouveau_vpe_write(struct nouveau_decoder *dec, unsigned data) {
50af69d88dSmrg   dec->cmds[dec->ofs++] = data;
51af69d88dSmrg}
52af69d88dSmrg
53af69d88dSmrg#define SUBC_MPEG(mthd) 1, mthd
54af69d88dSmrg#define NV31_MPEG(mthd) SUBC_MPEG(NV31_MPEG_##mthd)
55af69d88dSmrg#define NV84_MPEG(mthd) SUBC_MPEG(NV84_MPEG_##mthd)
56af69d88dSmrg
5701e04c3fSmrgstatic inline uint32_t
58af69d88dSmrgNV04_FIFO_PKHDR(int subc, int mthd, unsigned size)
59af69d88dSmrg{
60af69d88dSmrg   return 0x00000000 | (size << 18) | (subc << 13) | mthd;
61af69d88dSmrg}
62af69d88dSmrg
6301e04c3fSmrgstatic inline uint32_t
64af69d88dSmrgNV04_FIFO_PKHDR_NI(int subc, int mthd, unsigned size)
65af69d88dSmrg{
66af69d88dSmrg   return 0x40000000 | (size << 18) | (subc << 13) | mthd;
67af69d88dSmrg}
68af69d88dSmrg
6901e04c3fSmrgstatic inline void
70af69d88dSmrgBEGIN_NV04(struct nouveau_pushbuf *push, int subc, int mthd, unsigned size)
71af69d88dSmrg{
72af69d88dSmrg   PUSH_SPACE(push, size + 1);
73af69d88dSmrg   PUSH_DATA (push, NV04_FIFO_PKHDR(subc, mthd, size));
74af69d88dSmrg}
75af69d88dSmrg
7601e04c3fSmrgstatic inline void
77af69d88dSmrgBEGIN_NI04(struct nouveau_pushbuf *push, int subc, int mthd, unsigned size)
78af69d88dSmrg{
79af69d88dSmrg   PUSH_SPACE(push, size + 1);
80af69d88dSmrg   PUSH_DATA (push, NV04_FIFO_PKHDR_NI(subc, mthd, size));
81af69d88dSmrg}
82af69d88dSmrg
8301e04c3fSmrgstatic inline void
84af69d88dSmrgPUSH_MTHDl(struct nouveau_pushbuf *push, int subc, int mthd,
85af69d88dSmrg           struct nouveau_bo *bo, uint32_t offset,
8601e04c3fSmrg           struct nouveau_bufctx *ctx, int bin, uint32_t rw)
87af69d88dSmrg{
88af69d88dSmrg   nouveau_bufctx_mthd(ctx, bin, NV04_FIFO_PKHDR(subc, mthd, 1),
89af69d88dSmrg                       bo, offset,
90af69d88dSmrg                       NOUVEAU_BO_LOW | (bo->flags & NOUVEAU_BO_APER) | rw,
91af69d88dSmrg                       0, 0);
92af69d88dSmrg
93af69d88dSmrg   PUSH_DATA(push, bo->offset + offset);
94af69d88dSmrg}
95af69d88dSmrg
96af69d88dSmrg#endif
97