| 1 |
/* |
| 2 |
* Copyright 2011-2013 Maarten Lankhorst, Ilia Mirkin |
| 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 AUTHORS OR COPYRIGHT HOLDERS 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 |
|
| 23 |
#include "nv50/nv98_video.h" |
| 24 |
|
| 25 |
#if NOUVEAU_VP3_DEBUG_FENCE |
| 26 |
static void dump_comm_bsp(struct comm *comm) |
| 27 |
{ |
| 28 |
unsigned idx = comm->bsp_cur_index & 0xf; |
| 29 |
debug_printf("Cur seq: %x, bsp byte ofs: %x\n", comm->bsp_cur_index, comm->byte_ofs); |
| 30 |
debug_printf("Status: %08x, pos: %08x\n", comm->status[idx], comm->pos[idx]); |
| 31 |
} |
| 32 |
#endif |
| 33 |
|
| 34 |
unsigned |
| 35 |
nv98_decoder_bsp(struct nouveau_vp3_decoder *dec, union pipe_desc desc, |
| 36 |
struct nouveau_vp3_video_buffer *target, |
| 37 |
unsigned comm_seq, unsigned num_buffers, |
| 38 |
const void *const *data, const unsigned *num_bytes, |
| 39 |
unsigned *vp_caps, unsigned *is_ref, |
| 40 |
struct nouveau_vp3_video_buffer *refs[16]) |
| 41 |
{ |
| 42 |
struct nouveau_screen *screen = nouveau_screen(dec->base.context->screen); |
| 43 |
struct nouveau_pushbuf *push = dec->pushbuf[0]; |
| 44 |
enum pipe_video_format codec = u_reduce_video_profile(dec->base.profile); |
| 45 |
uint32_t bsp_addr, comm_addr, inter_addr; |
| 46 |
uint32_t slice_size, bucket_size, ring_size, bsp_size; |
| 47 |
uint32_t caps, i; |
| 48 |
int ret; |
| 49 |
struct nouveau_bo *bsp_bo = dec->bsp_bo[comm_seq % NOUVEAU_VP3_VIDEO_QDEPTH]; |
| 50 |
struct nouveau_bo *inter_bo = dec->inter_bo[comm_seq & 1]; |
| 51 |
struct nouveau_pushbuf_refn bo_refs[] = { |
| 52 |
{ bsp_bo, NOUVEAU_BO_RD | NOUVEAU_BO_VRAM }, |
| 53 |
{ inter_bo, NOUVEAU_BO_WR | NOUVEAU_BO_VRAM }, |
| 54 |
#if NOUVEAU_VP3_DEBUG_FENCE |
| 55 |
{ dec->fence_bo, NOUVEAU_BO_WR | NOUVEAU_BO_GART }, |
| 56 |
#endif |
| 57 |
{ dec->bitplane_bo, NOUVEAU_BO_RDWR | NOUVEAU_BO_VRAM }, |
| 58 |
}; |
| 59 |
int num_refs = ARRAY_SIZE(bo_refs); |
| 60 |
|
| 61 |
if (!dec->bitplane_bo) |
| 62 |
num_refs--; |
| 63 |
|
| 64 |
bsp_size = NOUVEAU_VP3_BSP_RESERVED_SIZE; |
| 65 |
for (i = 0; i < num_buffers; i++) |
| 66 |
bsp_size += num_bytes[i]; |
| 67 |
bsp_size += 256; /* the 4 end markers */ |
| 68 |
|
| 69 |
if (!bsp_bo || bsp_size > bsp_bo->size) { |
| 70 |
struct nouveau_bo *tmp_bo = NULL; |
| 71 |
|
| 72 |
/* round up to the nearest mb */ |
| 73 |
bsp_size += (1 << 20) - 1; |
| 74 |
bsp_size &= ~((1 << 20) - 1); |
| 75 |
|
| 76 |
ret = nouveau_bo_new(dec->client->device, NOUVEAU_BO_VRAM, 0, bsp_size, NULL, &tmp_bo); |
| 77 |
if (ret) { |
| 78 |
debug_printf("reallocating bsp %u -> %u failed with %i\n", |
| 79 |
bsp_bo ? (unsigned)bsp_bo->size : 0, bsp_size, ret); |
| 80 |
return -1; |
| 81 |
} |
| 82 |
nouveau_bo_ref(NULL, &bsp_bo); |
| 83 |
bo_refs[0].bo = dec->bsp_bo[comm_seq % NOUVEAU_VP3_VIDEO_QDEPTH] = bsp_bo = tmp_bo; |
| 84 |
} |
| 85 |
|
| 86 |
if (!inter_bo || bsp_bo->size * 4 > inter_bo->size) { |
| 87 |
struct nouveau_bo *tmp_bo = NULL; |
| 88 |
|
| 89 |
ret = nouveau_bo_new(dec->client->device, NOUVEAU_BO_VRAM, 0, bsp_bo->size * 4, NULL, &tmp_bo); |
| 90 |
if (ret) { |
| 91 |
debug_printf("reallocating inter %u -> %u failed with %i\n", |
| 92 |
inter_bo ? (unsigned)inter_bo->size : 0, (unsigned)bsp_bo->size * 4, ret); |
| 93 |
return -1; |
| 94 |
} |
| 95 |
nouveau_bo_ref(NULL, &inter_bo); |
| 96 |
bo_refs[1].bo = dec->inter_bo[comm_seq & 1] = inter_bo = tmp_bo; |
| 97 |
} |
| 98 |
|
| 99 |
ret = BO_MAP(screen, bsp_bo, NOUVEAU_BO_WR, dec->client); |
| 100 |
if (ret) { |
| 101 |
debug_printf("map failed: %i %s\n", ret, strerror(-ret)); |
| 102 |
return -1; |
| 103 |
} |
| 104 |
|
| 105 |
nouveau_vp3_bsp_begin(dec); |
| 106 |
nouveau_vp3_bsp_next(dec, num_buffers, data, num_bytes); |
| 107 |
caps = nouveau_vp3_bsp_end(dec, desc); |
| 108 |
|
| 109 |
nouveau_vp3_vp_caps(dec, desc, target, comm_seq, vp_caps, is_ref, refs); |
| 110 |
|
| 111 |
PUSH_SPACE_EX(push, 32, num_refs, 0); |
| 112 |
PUSH_REFN(push, bo_refs, num_refs); |
| 113 |
|
| 114 |
bsp_addr = bsp_bo->offset >> 8; |
| 115 |
inter_addr = inter_bo->offset >> 8; |
| 116 |
|
| 117 |
#if NOUVEAU_VP3_DEBUG_FENCE |
| 118 |
memset(dec->comm, 0, 0x200); |
| 119 |
comm_addr = (dec->fence_bo->offset + COMM_OFFSET) >> 8; |
| 120 |
#else |
| 121 |
comm_addr = bsp_addr + (COMM_OFFSET>>8); |
| 122 |
#endif |
| 123 |
|
| 124 |
BEGIN_NV04(push, SUBC_BSP(0x700), 5); |
| 125 |
PUSH_DATA (push, caps); // 700 cmd |
| 126 |
PUSH_DATA (push, bsp_addr + 1); // 704 strparm_bsp |
| 127 |
PUSH_DATA (push, bsp_addr + 7); // 708 str addr |
| 128 |
PUSH_DATA (push, comm_addr); // 70c comm |
| 129 |
PUSH_DATA (push, comm_seq); // 710 seq |
| 130 |
|
| 131 |
if (codec != PIPE_VIDEO_FORMAT_MPEG4_AVC) { |
| 132 |
u32 bitplane_addr; |
| 133 |
int mpeg12 = (codec == PIPE_VIDEO_FORMAT_MPEG12); |
| 134 |
|
| 135 |
bitplane_addr = dec->bitplane_bo->offset >> 8; |
| 136 |
|
| 137 |
nouveau_vp3_inter_sizes(dec, 1, &slice_size, &bucket_size, &ring_size); |
| 138 |
BEGIN_NV04(push, SUBC_BSP(0x400), mpeg12 ? 5 : 7); |
| 139 |
PUSH_DATA (push, bsp_addr); // 400 picparm addr |
| 140 |
PUSH_DATA (push, inter_addr); // 404 interparm addr |
| 141 |
PUSH_DATA (push, inter_addr + slice_size + bucket_size); // 408 interdata addr |
| 142 |
PUSH_DATA (push, ring_size << 8); // 40c interdata_size |
| 143 |
if (!mpeg12) { |
| 144 |
PUSH_DATA (push, bitplane_addr); // 410 BITPLANE_DATA |
| 145 |
PUSH_DATA (push, 0x400); // 414 BITPLANE_DATA_SIZE |
| 146 |
} |
| 147 |
PUSH_DATA (push, 0); // dma idx |
| 148 |
} else { |
| 149 |
nouveau_vp3_inter_sizes(dec, desc.h264->slice_count, &slice_size, &bucket_size, &ring_size); |
| 150 |
BEGIN_NV04(push, SUBC_BSP(0x400), 8); |
| 151 |
PUSH_DATA (push, bsp_addr); // 400 picparm addr |
| 152 |
PUSH_DATA (push, inter_addr); // 404 interparm addr |
| 153 |
PUSH_DATA (push, slice_size << 8); // 408 interparm size? |
| 154 |
PUSH_DATA (push, inter_addr + slice_size + bucket_size); // 40c interdata addr |
| 155 |
PUSH_DATA (push, ring_size << 8); // 410 interdata size |
| 156 |
PUSH_DATA (push, inter_addr + slice_size); // 414 bucket? |
| 157 |
PUSH_DATA (push, bucket_size << 8); // 418 bucket size? unshifted.. |
| 158 |
PUSH_DATA (push, 0); // 41c targets |
| 159 |
// TODO: Double check 414 / 418 with nvidia trace |
| 160 |
} |
| 161 |
|
| 162 |
#if NOUVEAU_VP3_DEBUG_FENCE |
| 163 |
BEGIN_NV04(push, SUBC_BSP(0x240), 3); |
| 164 |
PUSH_DATAh(push, dec->fence_bo->offset); |
| 165 |
PUSH_DATA (push, dec->fence_bo->offset); |
| 166 |
PUSH_DATA (push, dec->fence_seq); |
| 167 |
|
| 168 |
BEGIN_NV04(push, SUBC_BSP(0x300), 1); |
| 169 |
PUSH_DATA (push, 1); |
| 170 |
PUSH_KICK (push); |
| 171 |
|
| 172 |
{ |
| 173 |
unsigned spin = 0; |
| 174 |
do { |
| 175 |
usleep(100); |
| 176 |
if ((spin++ & 0xff) == 0xff) { |
| 177 |
debug_printf("b%u: %u\n", dec->fence_seq, dec->fence_map[0]); |
| 178 |
dump_comm_bsp(dec->comm); |
| 179 |
} |
| 180 |
} while (dec->fence_seq > dec->fence_map[0]); |
| 181 |
} |
| 182 |
|
| 183 |
dump_comm_bsp(dec->comm); |
| 184 |
return dec->comm->status[comm_seq & 0xf]; |
| 185 |
#else |
| 186 |
BEGIN_NV04(push, SUBC_BSP(0x300), 1); |
| 187 |
PUSH_DATA (push, 0); |
| 188 |
PUSH_KICK (push); |
| 189 |
return 2; |
| 190 |
#endif |
| 191 |
} |