2009-01-29 18:25:35 -07:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2009-06-03 16:59:53 -06:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
2009-01-29 18:25:35 -07:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include <sys/mman.h>
|
|
|
|
|
|
|
|
#include "nouveau_private.h"
|
|
|
|
|
|
|
|
int
|
|
|
|
nouveau_bo_init(struct nouveau_device *dev)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nouveau_bo_takedown(struct nouveau_device *dev)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-05-25 22:14:04 -06:00
|
|
|
static int
|
|
|
|
nouveau_bo_info(struct nouveau_bo_priv *nvbo, struct drm_nouveau_gem_info *arg)
|
|
|
|
{
|
|
|
|
nvbo->handle = nvbo->base.handle = arg->handle;
|
|
|
|
nvbo->domain = arg->domain;
|
2009-07-27 16:12:21 -06:00
|
|
|
nvbo->size = arg->size;
|
2009-05-25 22:14:04 -06:00
|
|
|
nvbo->offset = arg->offset;
|
|
|
|
nvbo->map_handle = arg->map_handle;
|
2009-06-02 21:54:43 -06:00
|
|
|
nvbo->base.tile_mode = arg->tile_mode;
|
2010-09-28 14:47:11 -06:00
|
|
|
/* XXX - flag inverted for backwards compatibility */
|
|
|
|
nvbo->base.tile_flags = arg->tile_flags ^ NOUVEAU_GEM_TILE_NONCONTIG;
|
2009-05-25 22:14:04 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-01-29 18:25:35 -07:00
|
|
|
static int
|
|
|
|
nouveau_bo_allocated(struct nouveau_bo_priv *nvbo)
|
|
|
|
{
|
2009-12-16 20:07:18 -07:00
|
|
|
if (nvbo->sysmem || nvbo->handle)
|
2009-01-29 18:25:35 -07:00
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nouveau_bo_ualloc(struct nouveau_bo_priv *nvbo)
|
|
|
|
{
|
|
|
|
if (nvbo->user || nvbo->sysmem) {
|
|
|
|
assert(nvbo->sysmem);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
nvbo->sysmem = malloc(nvbo->size);
|
|
|
|
if (!nvbo->sysmem)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nouveau_bo_ufree(struct nouveau_bo_priv *nvbo)
|
|
|
|
{
|
|
|
|
if (nvbo->sysmem) {
|
|
|
|
if (!nvbo->user)
|
|
|
|
free(nvbo->sysmem);
|
|
|
|
nvbo->sysmem = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nouveau_bo_kfree(struct nouveau_bo_priv *nvbo)
|
|
|
|
{
|
|
|
|
struct nouveau_device_priv *nvdev = nouveau_device(nvbo->base.device);
|
|
|
|
struct drm_gem_close req;
|
|
|
|
|
|
|
|
if (!nvbo->handle)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (nvbo->map) {
|
|
|
|
munmap(nvbo->map, nvbo->size);
|
|
|
|
nvbo->map = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
req.handle = nvbo->handle;
|
|
|
|
nvbo->handle = 0;
|
2009-12-08 21:50:15 -07:00
|
|
|
drmIoctl(nvdev->fd, DRM_IOCTL_GEM_CLOSE, &req);
|
2009-01-29 18:25:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nouveau_bo_kalloc(struct nouveau_bo_priv *nvbo, struct nouveau_channel *chan)
|
|
|
|
{
|
|
|
|
struct nouveau_device_priv *nvdev = nouveau_device(nvbo->base.device);
|
|
|
|
struct drm_nouveau_gem_new req;
|
2009-05-25 22:14:04 -06:00
|
|
|
struct drm_nouveau_gem_info *info = &req.info;
|
2009-01-29 18:25:35 -07:00
|
|
|
int ret;
|
|
|
|
|
2009-12-16 20:07:18 -07:00
|
|
|
if (nvbo->handle)
|
2009-01-29 18:25:35 -07:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
req.channel_hint = chan ? chan->id : 0;
|
|
|
|
req.align = nvbo->align;
|
|
|
|
|
|
|
|
|
2009-05-25 22:14:04 -06:00
|
|
|
info->size = nvbo->size;
|
|
|
|
info->domain = 0;
|
2009-01-29 18:25:35 -07:00
|
|
|
|
2009-05-25 22:14:04 -06:00
|
|
|
if (nvbo->flags & NOUVEAU_BO_VRAM)
|
|
|
|
info->domain |= NOUVEAU_GEM_DOMAIN_VRAM;
|
2009-01-29 18:25:35 -07:00
|
|
|
if (nvbo->flags & NOUVEAU_BO_GART)
|
2009-05-25 22:14:04 -06:00
|
|
|
info->domain |= NOUVEAU_GEM_DOMAIN_GART;
|
|
|
|
if (!info->domain) {
|
|
|
|
info->domain |= (NOUVEAU_GEM_DOMAIN_VRAM |
|
2009-06-02 21:54:43 -06:00
|
|
|
NOUVEAU_GEM_DOMAIN_GART);
|
2009-01-29 18:25:35 -07:00
|
|
|
}
|
|
|
|
|
2009-05-25 22:14:04 -06:00
|
|
|
if (nvbo->flags & NOUVEAU_BO_MAP)
|
|
|
|
info->domain |= NOUVEAU_GEM_DOMAIN_MAPPABLE;
|
2009-01-29 18:25:35 -07:00
|
|
|
|
2009-06-02 21:54:43 -06:00
|
|
|
info->tile_mode = nvbo->base.tile_mode;
|
|
|
|
info->tile_flags = nvbo->base.tile_flags;
|
2010-09-28 14:47:11 -06:00
|
|
|
/* XXX - flag inverted for backwards compatibility */
|
|
|
|
info->tile_flags ^= NOUVEAU_GEM_TILE_NONCONTIG;
|
|
|
|
if (!nvdev->has_bo_usage)
|
|
|
|
info->tile_flags &= NOUVEAU_GEM_TILE_LAYOUT_MASK;
|
2009-06-02 21:54:43 -06:00
|
|
|
|
2009-01-29 18:25:35 -07:00
|
|
|
ret = drmCommandWriteRead(nvdev->fd, DRM_NOUVEAU_GEM_NEW,
|
|
|
|
&req, sizeof(req));
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2009-05-25 22:14:04 -06:00
|
|
|
nouveau_bo_info(nvbo, &req.info);
|
2009-01-29 18:25:35 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nouveau_bo_kmap(struct nouveau_bo_priv *nvbo)
|
|
|
|
{
|
|
|
|
struct nouveau_device_priv *nvdev = nouveau_device(nvbo->base.device);
|
|
|
|
|
|
|
|
if (nvbo->map)
|
|
|
|
return 0;
|
|
|
|
|
2009-05-25 22:14:04 -06:00
|
|
|
if (!nvbo->map_handle)
|
2009-01-29 18:25:35 -07:00
|
|
|
return -EINVAL;
|
|
|
|
|
2009-05-25 22:14:04 -06:00
|
|
|
nvbo->map = mmap(0, nvbo->size, PROT_READ | PROT_WRITE,
|
|
|
|
MAP_SHARED, nvdev->fd, nvbo->map_handle);
|
|
|
|
if (nvbo->map == MAP_FAILED) {
|
|
|
|
nvbo->map = NULL;
|
|
|
|
return -errno;
|
|
|
|
}
|
2009-01-29 18:25:35 -07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-06-02 21:54:43 -06:00
|
|
|
nouveau_bo_new_tile(struct nouveau_device *dev, uint32_t flags, int align,
|
|
|
|
int size, uint32_t tile_mode, uint32_t tile_flags,
|
|
|
|
struct nouveau_bo **bo)
|
2009-01-29 18:25:35 -07:00
|
|
|
{
|
|
|
|
struct nouveau_bo_priv *nvbo;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!dev || !bo || *bo)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
nvbo = calloc(1, sizeof(struct nouveau_bo_priv));
|
|
|
|
if (!nvbo)
|
|
|
|
return -ENOMEM;
|
|
|
|
nvbo->base.device = dev;
|
|
|
|
nvbo->base.size = size;
|
2009-06-02 21:54:43 -06:00
|
|
|
nvbo->base.tile_mode = tile_mode;
|
|
|
|
nvbo->base.tile_flags = tile_flags;
|
2009-01-29 18:25:35 -07:00
|
|
|
|
|
|
|
nvbo->refcount = 1;
|
2009-12-16 20:07:18 -07:00
|
|
|
nvbo->flags = flags;
|
2009-01-29 18:25:35 -07:00
|
|
|
nvbo->size = size;
|
|
|
|
nvbo->align = align;
|
|
|
|
|
2009-12-16 20:07:18 -07:00
|
|
|
if (flags & (NOUVEAU_BO_VRAM | NOUVEAU_BO_GART)) {
|
|
|
|
ret = nouveau_bo_kalloc(nvbo, NULL);
|
2009-01-29 18:25:35 -07:00
|
|
|
if (ret) {
|
2010-03-18 18:17:19 -06:00
|
|
|
nouveau_bo_ref(NULL, (void *)&nvbo);
|
2009-01-29 18:25:35 -07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*bo = &nvbo->base;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-06-02 21:54:43 -06:00
|
|
|
int
|
|
|
|
nouveau_bo_new(struct nouveau_device *dev, uint32_t flags, int align,
|
|
|
|
int size, struct nouveau_bo **bo)
|
|
|
|
{
|
2010-01-29 01:53:24 -07:00
|
|
|
return nouveau_bo_new_tile(dev, flags, align, size, 0, 0, bo);
|
2009-06-02 21:54:43 -06:00
|
|
|
}
|
|
|
|
|
2009-01-29 18:25:35 -07:00
|
|
|
int
|
|
|
|
nouveau_bo_user(struct nouveau_device *dev, void *ptr, int size,
|
|
|
|
struct nouveau_bo **bo)
|
|
|
|
{
|
|
|
|
struct nouveau_bo_priv *nvbo;
|
|
|
|
int ret;
|
|
|
|
|
2009-07-27 15:46:20 -06:00
|
|
|
ret = nouveau_bo_new(dev, NOUVEAU_BO_MAP, 0, size, bo);
|
2009-01-29 18:25:35 -07:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
nvbo = nouveau_bo(*bo);
|
|
|
|
|
|
|
|
nvbo->sysmem = ptr;
|
|
|
|
nvbo->user = 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-05-25 22:14:04 -06:00
|
|
|
int
|
|
|
|
nouveau_bo_wrap(struct nouveau_device *dev, uint32_t handle,
|
|
|
|
struct nouveau_bo **bo)
|
|
|
|
{
|
|
|
|
struct nouveau_device_priv *nvdev = nouveau_device(dev);
|
|
|
|
struct drm_nouveau_gem_info req;
|
|
|
|
struct nouveau_bo_priv *nvbo;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = nouveau_bo_new(dev, 0, 0, 0, bo);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
nvbo = nouveau_bo(*bo);
|
|
|
|
|
|
|
|
req.handle = handle;
|
|
|
|
ret = drmCommandWriteRead(nvdev->fd, DRM_NOUVEAU_GEM_INFO,
|
|
|
|
&req, sizeof(req));
|
|
|
|
if (ret) {
|
|
|
|
nouveau_bo_ref(NULL, bo);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
nouveau_bo_info(nvbo, &req);
|
2009-07-27 16:12:21 -06:00
|
|
|
nvbo->base.size = nvbo->size;
|
2009-05-25 22:14:04 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-01-29 18:25:35 -07:00
|
|
|
int
|
|
|
|
nouveau_bo_handle_get(struct nouveau_bo *bo, uint32_t *handle)
|
|
|
|
{
|
|
|
|
struct nouveau_device_priv *nvdev = nouveau_device(bo->device);
|
|
|
|
struct nouveau_bo_priv *nvbo = nouveau_bo(bo);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!bo || !handle)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (!nvbo->global_handle) {
|
|
|
|
struct drm_gem_flink req;
|
|
|
|
|
|
|
|
ret = nouveau_bo_kalloc(nvbo, NULL);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2009-03-17 18:25:22 -06:00
|
|
|
|
2009-07-26 15:23:09 -06:00
|
|
|
req.handle = nvbo->handle;
|
2009-12-08 21:50:15 -07:00
|
|
|
ret = drmIoctl(nvdev->fd, DRM_IOCTL_GEM_FLINK, &req);
|
2009-07-26 15:23:09 -06:00
|
|
|
if (ret) {
|
|
|
|
nouveau_bo_kfree(nvbo);
|
|
|
|
return ret;
|
2009-01-29 18:25:35 -07:00
|
|
|
}
|
2009-07-26 15:23:09 -06:00
|
|
|
|
|
|
|
nvbo->global_handle = req.name;
|
2009-01-29 18:25:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
*handle = nvbo->global_handle;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nouveau_bo_handle_ref(struct nouveau_device *dev, uint32_t handle,
|
|
|
|
struct nouveau_bo **bo)
|
|
|
|
{
|
|
|
|
struct nouveau_device_priv *nvdev = nouveau_device(dev);
|
|
|
|
struct nouveau_bo_priv *nvbo;
|
|
|
|
struct drm_gem_open req;
|
|
|
|
int ret;
|
|
|
|
|
2009-07-26 15:23:09 -06:00
|
|
|
req.name = handle;
|
2009-12-08 21:50:15 -07:00
|
|
|
ret = drmIoctl(nvdev->fd, DRM_IOCTL_GEM_OPEN, &req);
|
2009-07-26 15:23:09 -06:00
|
|
|
if (ret) {
|
|
|
|
nouveau_bo_ref(NULL, bo);
|
|
|
|
return ret;
|
|
|
|
}
|
2009-05-25 22:14:04 -06:00
|
|
|
|
2009-07-26 15:23:09 -06:00
|
|
|
ret = nouveau_bo_wrap(dev, req.handle, bo);
|
|
|
|
if (ret) {
|
|
|
|
nouveau_bo_ref(NULL, bo);
|
|
|
|
return ret;
|
2009-01-29 18:25:35 -07:00
|
|
|
}
|
2009-04-14 20:44:21 -06:00
|
|
|
|
2009-07-26 15:23:09 -06:00
|
|
|
nvbo = nouveau_bo(*bo);
|
2009-04-14 20:44:21 -06:00
|
|
|
nvbo->base.handle = nvbo->handle;
|
2009-01-29 18:25:35 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nouveau_bo_del(struct nouveau_bo **bo)
|
|
|
|
{
|
|
|
|
struct nouveau_bo_priv *nvbo;
|
|
|
|
|
|
|
|
if (!bo || !*bo)
|
|
|
|
return;
|
|
|
|
nvbo = nouveau_bo(*bo);
|
|
|
|
*bo = NULL;
|
|
|
|
|
|
|
|
if (--nvbo->refcount)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (nvbo->pending) {
|
|
|
|
nvbo->pending = NULL;
|
|
|
|
nouveau_pushbuf_flush(nvbo->pending_channel, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
nouveau_bo_ufree(nvbo);
|
2009-07-26 15:23:09 -06:00
|
|
|
nouveau_bo_kfree(nvbo);
|
|
|
|
free(nvbo);
|
2009-01-29 18:25:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nouveau_bo_ref(struct nouveau_bo *ref, struct nouveau_bo **pbo)
|
|
|
|
{
|
|
|
|
if (!pbo)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (ref)
|
|
|
|
nouveau_bo(ref)->refcount++;
|
|
|
|
|
|
|
|
if (*pbo)
|
|
|
|
nouveau_bo_del(pbo);
|
|
|
|
|
|
|
|
*pbo = ref;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-07-26 15:23:09 -06:00
|
|
|
nouveau_bo_wait(struct nouveau_bo *bo, int cpu_write, int no_wait, int no_block)
|
2009-01-29 18:25:35 -07:00
|
|
|
{
|
|
|
|
struct nouveau_device_priv *nvdev = nouveau_device(bo->device);
|
|
|
|
struct nouveau_bo_priv *nvbo = nouveau_bo(bo);
|
|
|
|
struct drm_nouveau_gem_cpu_prep req;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!nvbo->global_handle && !nvbo->write_marker && !cpu_write)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (nvbo->pending &&
|
|
|
|
(nvbo->pending->write_domains || cpu_write)) {
|
|
|
|
nvbo->pending = NULL;
|
|
|
|
nouveau_pushbuf_flush(nvbo->pending_channel, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
req.handle = nvbo->handle;
|
2009-07-26 15:23:09 -06:00
|
|
|
req.flags = 0;
|
|
|
|
if (cpu_write)
|
|
|
|
req.flags |= NOUVEAU_GEM_CPU_PREP_WRITE;
|
|
|
|
if (no_wait)
|
|
|
|
req.flags |= NOUVEAU_GEM_CPU_PREP_NOWAIT;
|
|
|
|
if (no_block)
|
|
|
|
req.flags |= NOUVEAU_GEM_CPU_PREP_NOBLOCK;
|
|
|
|
|
2009-05-25 22:14:04 -06:00
|
|
|
do {
|
|
|
|
ret = drmCommandWrite(nvdev->fd, DRM_NOUVEAU_GEM_CPU_PREP,
|
|
|
|
&req, sizeof(req));
|
|
|
|
} while (ret == -EAGAIN);
|
2009-01-29 18:25:35 -07:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2009-05-25 22:14:04 -06:00
|
|
|
if (ret == 0)
|
|
|
|
nvbo->write_marker = 0;
|
2009-01-29 18:25:35 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-06-02 21:54:43 -06:00
|
|
|
nouveau_bo_map_range(struct nouveau_bo *bo, uint32_t delta, uint32_t size,
|
|
|
|
uint32_t flags)
|
2009-01-29 18:25:35 -07:00
|
|
|
{
|
|
|
|
struct nouveau_bo_priv *nvbo = nouveau_bo(bo);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!nvbo || bo->map)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (!nouveau_bo_allocated(nvbo)) {
|
|
|
|
if (nvbo->flags & (NOUVEAU_BO_VRAM | NOUVEAU_BO_GART)) {
|
|
|
|
ret = nouveau_bo_kalloc(nvbo, NULL);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!nouveau_bo_allocated(nvbo)) {
|
|
|
|
ret = nouveau_bo_ualloc(nvbo);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nvbo->sysmem) {
|
2009-06-02 21:54:43 -06:00
|
|
|
bo->map = (char *)nvbo->sysmem + delta;
|
2009-01-29 18:25:35 -07:00
|
|
|
} else {
|
|
|
|
ret = nouveau_bo_kmap(nvbo);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2009-06-02 21:54:43 -06:00
|
|
|
if (!(flags & NOUVEAU_BO_NOSYNC)) {
|
2009-07-26 15:23:09 -06:00
|
|
|
ret = nouveau_bo_wait(bo, (flags & NOUVEAU_BO_WR),
|
|
|
|
(flags & NOUVEAU_BO_NOWAIT), 0);
|
2009-06-02 21:54:43 -06:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2010-10-30 18:22:29 -06:00
|
|
|
|
|
|
|
nvbo->map_refcnt++;
|
2009-06-02 21:54:43 -06:00
|
|
|
}
|
2009-01-29 18:25:35 -07:00
|
|
|
|
2009-06-02 21:54:43 -06:00
|
|
|
bo->map = (char *)nvbo->map + delta;
|
2009-01-29 18:25:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-06-02 21:54:43 -06:00
|
|
|
void
|
|
|
|
nouveau_bo_map_flush(struct nouveau_bo *bo, uint32_t delta, uint32_t size)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nouveau_bo_map(struct nouveau_bo *bo, uint32_t flags)
|
|
|
|
{
|
|
|
|
return nouveau_bo_map_range(bo, 0, bo->size, flags);
|
|
|
|
}
|
|
|
|
|
2009-01-29 18:25:35 -07:00
|
|
|
void
|
|
|
|
nouveau_bo_unmap(struct nouveau_bo *bo)
|
|
|
|
{
|
|
|
|
struct nouveau_bo_priv *nvbo = nouveau_bo(bo);
|
|
|
|
|
2010-10-30 18:22:29 -06:00
|
|
|
if (bo->map && !nvbo->sysmem && nvbo->map_refcnt) {
|
2009-01-29 18:25:35 -07:00
|
|
|
struct nouveau_device_priv *nvdev = nouveau_device(bo->device);
|
|
|
|
struct drm_nouveau_gem_cpu_fini req;
|
|
|
|
|
|
|
|
req.handle = nvbo->handle;
|
|
|
|
drmCommandWrite(nvdev->fd, DRM_NOUVEAU_GEM_CPU_FINI,
|
|
|
|
&req, sizeof(req));
|
2010-10-30 18:22:29 -06:00
|
|
|
nvbo->map_refcnt--;
|
2009-01-29 18:25:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bo->map = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nouveau_bo_busy(struct nouveau_bo *bo, uint32_t access)
|
|
|
|
{
|
2009-07-26 15:23:09 -06:00
|
|
|
return nouveau_bo_wait(bo, (access & NOUVEAU_BO_WR), 1, 1);
|
2009-01-29 18:25:35 -07:00
|
|
|
}
|
|
|
|
|
2009-10-18 17:04:37 -06:00
|
|
|
uint32_t
|
|
|
|
nouveau_bo_pending(struct nouveau_bo *bo)
|
|
|
|
{
|
|
|
|
struct nouveau_bo_priv *nvbo = nouveau_bo(bo);
|
|
|
|
uint32_t flags;
|
|
|
|
|
|
|
|
if (!nvbo->pending)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
flags = 0;
|
|
|
|
if (nvbo->pending->read_domains)
|
|
|
|
flags |= NOUVEAU_BO_RD;
|
|
|
|
if (nvbo->pending->write_domains)
|
|
|
|
flags |= NOUVEAU_BO_WR;
|
|
|
|
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2009-01-29 18:25:35 -07:00
|
|
|
struct drm_nouveau_gem_pushbuf_bo *
|
|
|
|
nouveau_bo_emit_buffer(struct nouveau_channel *chan, struct nouveau_bo *bo)
|
|
|
|
{
|
2010-01-29 01:53:24 -07:00
|
|
|
struct nouveau_pushbuf_priv *nvpb = &nouveau_channel(chan)->pb;
|
2009-01-29 18:25:35 -07:00
|
|
|
struct nouveau_bo_priv *nvbo = nouveau_bo(bo);
|
|
|
|
struct drm_nouveau_gem_pushbuf_bo *pbbo;
|
|
|
|
struct nouveau_bo *ref = NULL;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (nvbo->pending)
|
|
|
|
return nvbo->pending;
|
|
|
|
|
|
|
|
if (!nvbo->handle) {
|
|
|
|
ret = nouveau_bo_kalloc(nvbo, chan);
|
|
|
|
if (ret)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (nvbo->sysmem) {
|
|
|
|
void *sysmem_tmp = nvbo->sysmem;
|
|
|
|
|
|
|
|
nvbo->sysmem = NULL;
|
|
|
|
ret = nouveau_bo_map(bo, NOUVEAU_BO_WR);
|
|
|
|
if (ret)
|
|
|
|
return NULL;
|
|
|
|
nvbo->sysmem = sysmem_tmp;
|
|
|
|
|
|
|
|
memcpy(bo->map, nvbo->sysmem, nvbo->base.size);
|
|
|
|
nouveau_bo_ufree(nvbo);
|
2009-07-27 11:24:13 -06:00
|
|
|
nouveau_bo_unmap(bo);
|
2009-01-29 18:25:35 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-26 15:23:09 -06:00
|
|
|
if (nvpb->nr_buffers >= NOUVEAU_GEM_MAX_BUFFERS)
|
2009-01-29 18:25:35 -07:00
|
|
|
return NULL;
|
|
|
|
pbbo = nvpb->buffers + nvpb->nr_buffers++;
|
|
|
|
nvbo->pending = pbbo;
|
|
|
|
nvbo->pending_channel = chan;
|
2009-10-26 22:32:40 -06:00
|
|
|
nvbo->pending_refcnt = 0;
|
2009-01-29 18:25:35 -07:00
|
|
|
|
|
|
|
nouveau_bo_ref(bo, &ref);
|
|
|
|
pbbo->user_priv = (uint64_t)(unsigned long)ref;
|
|
|
|
pbbo->handle = nvbo->handle;
|
|
|
|
pbbo->valid_domains = NOUVEAU_GEM_DOMAIN_VRAM | NOUVEAU_GEM_DOMAIN_GART;
|
|
|
|
pbbo->read_domains = 0;
|
|
|
|
pbbo->write_domains = 0;
|
2010-01-29 01:53:24 -07:00
|
|
|
pbbo->presumed.domain = nvbo->domain;
|
|
|
|
pbbo->presumed.offset = nvbo->offset;
|
|
|
|
pbbo->presumed.valid = 1;
|
2009-01-29 18:25:35 -07:00
|
|
|
return pbbo;
|
|
|
|
}
|