Source
x
/*
* Copyright 2007 Nouveau Project
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
static int
nouveau_pushbuf_space(struct nouveau_channel *chan, unsigned min)
{
struct nouveau_channel_priv *nvchan = nouveau_channel(chan);
struct nouveau_pushbuf_priv *nvpb = &nvchan->pb;
struct nouveau_bo *bo;
int ret;
if (min < PB_MIN_USER_DWORDS)
min = PB_MIN_USER_DWORDS;
nvpb->current_offset = chan->cur - nvpb->pushbuf;
if (chan->cur + min + 2 <= chan->end)
return 0;
nvpb->current++;
if (nvpb->current == CALPB_BUFFERS)
nvpb->current = 0;
bo = nvpb->buffer[nvpb->current];
ret = nouveau_bo_map(bo, NOUVEAU_BO_WR);
if (ret)
return ret;
nvpb->size = (bo->size - 8) / 4;
nvpb->pushbuf = bo->map;
nvpb->current_offset = 0;
chan->cur = nvpb->pushbuf;
chan->end = nvpb->pushbuf + nvpb->size;
nouveau_bo_unmap(bo);
return 0;
}
static void
nouveau_pushbuf_fini_call(struct nouveau_channel *chan)
{
struct nouveau_channel_priv *nvchan = nouveau_channel(chan);
struct nouveau_pushbuf_priv *nvpb = &nvchan->pb;
int i;
for (i = 0; i < CALPB_BUFFERS; i++)
nouveau_bo_ref(NULL, &nvpb->buffer[i]);
nvpb->pushbuf = NULL;
}
static int
nouveau_pushbuf_init_call(struct nouveau_channel *chan, int buf_size)
{
struct drm_nouveau_gem_pushbuf req;
struct nouveau_channel_priv *nvchan = nouveau_channel(chan);
struct nouveau_pushbuf_priv *nvpb = &nvchan->pb;
struct nouveau_device *dev = chan->device;
uint32_t flags = 0;
int i, ret;
if (nvchan->drm.pushbuf_domains & NOUVEAU_GEM_DOMAIN_GART)
flags |= NOUVEAU_BO_GART;
else