mirror of
https://gitlab.freedesktop.org/mesa/drm.git
synced 2025-12-20 03:30:22 +01:00
Update to latest libdrm.
This commit is contained in:
parent
875a6ae217
commit
f785d1a15e
31 changed files with 11628 additions and 27 deletions
19
configure.ac
19
configure.ac
|
|
@ -42,6 +42,10 @@ AC_ARG_ENABLE(udev, AS_HELP_STRING([--enable-udev],
|
|||
[Enable support for using udev instead of mknod (default: disabled)]),
|
||||
[UDEV=$enableval], [UDEV=no])
|
||||
|
||||
AC_ARG_ENABLE(nouveau-experimental-api,
|
||||
AS_HELP_STRING([--enable-nouveau-experimental-api],
|
||||
[Enable support for nouveau's experimental API (default: disabled)]),
|
||||
[NOUVEAU=$enableval], [NOUVEAU=no])
|
||||
|
||||
dnl ===========================================================================
|
||||
dnl check compiler flags
|
||||
|
|
@ -119,13 +123,28 @@ if test "x$UDEV" = xyes; then
|
|||
AC_DEFINE(UDEV, 1, [Have UDEV support])
|
||||
fi
|
||||
|
||||
if test "x$NOUVEAU" = xyes; then
|
||||
NOUVEAU_SUBDIR="nouveau"
|
||||
AC_SUBST(NOUVEAU_SUBDIR)
|
||||
fi
|
||||
|
||||
PKG_CHECK_MODULES(CAIRO, cairo, [HAVE_CAIRO=yes], [HAVE_CAIRO=no])
|
||||
if test "x$HAVE_CAIRO" = xyes; then
|
||||
AC_DEFINE(HAVE_CAIRO, 1, [Have cairo support])
|
||||
fi
|
||||
AM_CONDITIONAL(HAVE_CAIRO, [test "x$HAVE_CAIRO" = xyes])
|
||||
|
||||
|
||||
AC_SUBST(WARN_CFLAGS)
|
||||
AC_OUTPUT([
|
||||
Makefile
|
||||
libdrm/Makefile
|
||||
libdrm/intel/Makefile
|
||||
libdrm/nouveau/Makefile
|
||||
libdrm/nouveau/libdrm_nouveau.pc
|
||||
shared-core/Makefile
|
||||
tests/Makefile
|
||||
tests/modeprint/Makefile
|
||||
tests/modetest/Makefile
|
||||
linux-core/ttm/Makefile
|
||||
libdrm.pc])
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
# 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.
|
||||
|
||||
SUBDIRS = . intel
|
||||
SUBDIRS = . intel @NOUVEAU_SUBDIR@
|
||||
|
||||
libdrm_la_LTLIBRARIES = libdrm.la
|
||||
libdrm_ladir = $(libdir)
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ libdrm_intel_la_SOURCES = \
|
|||
intel_bufmgr_priv.h \
|
||||
intel_bufmgr_fake.c \
|
||||
intel_bufmgr_gem.c \
|
||||
intel_chipset.h \
|
||||
mm.c \
|
||||
mm.h
|
||||
|
||||
|
|
|
|||
|
|
@ -1070,6 +1070,7 @@ drm_intel_fake_kick_all_locked(drm_intel_bufmgr_fake *bufmgr_fake)
|
|||
if (!(bo_fake->flags & BM_NO_BACKING_STORE))
|
||||
bo_fake->dirty = 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@
|
|||
#include "errno.h"
|
||||
#include "intel_bufmgr.h"
|
||||
#include "intel_bufmgr_priv.h"
|
||||
#include "intel_chipset.h"
|
||||
#include "string.h"
|
||||
|
||||
#include "i915_drm.h"
|
||||
|
|
@ -99,6 +100,8 @@ typedef struct _drm_intel_bufmgr_gem {
|
|||
struct drm_intel_gem_bo_bucket cache_bucket[DRM_INTEL_GEM_BO_BUCKETS];
|
||||
|
||||
uint64_t gtt_size;
|
||||
int available_fences;
|
||||
int pci_device;
|
||||
} drm_intel_bufmgr_gem;
|
||||
|
||||
struct _drm_intel_bo_gem {
|
||||
|
|
@ -165,6 +168,11 @@ struct _drm_intel_bo_gem {
|
|||
* the common case.
|
||||
*/
|
||||
int reloc_tree_size;
|
||||
/**
|
||||
* Number of potential fence registers required by this buffer and its
|
||||
* relocations.
|
||||
*/
|
||||
int reloc_tree_fences;
|
||||
};
|
||||
|
||||
static void drm_intel_gem_bo_reference_locked(drm_intel_bo *bo);
|
||||
|
|
@ -347,6 +355,7 @@ drm_intel_gem_bo_alloc(drm_intel_bufmgr *bufmgr, const char *name,
|
|||
struct drm_i915_gem_busy busy;
|
||||
|
||||
bo_gem = bucket->head;
|
||||
memset(&busy, 0, sizeof(busy));
|
||||
busy.handle = bo_gem->gem_handle;
|
||||
|
||||
ret = ioctl(bufmgr_gem->fd, DRM_IOCTL_I915_GEM_BUSY, &busy);
|
||||
|
|
@ -386,6 +395,7 @@ drm_intel_gem_bo_alloc(drm_intel_bufmgr *bufmgr, const char *name,
|
|||
bo_gem->refcount = 1;
|
||||
bo_gem->validate_index = -1;
|
||||
bo_gem->reloc_tree_size = bo_gem->bo.size;
|
||||
bo_gem->reloc_tree_fences = 0;
|
||||
bo_gem->used_as_reloc_target = 0;
|
||||
bo_gem->tiling_mode = I915_TILING_NONE;
|
||||
bo_gem->swizzle_mode = I915_BIT_6_SWIZZLE_NONE;
|
||||
|
|
@ -435,6 +445,7 @@ drm_intel_bo_gem_create_from_name(drm_intel_bufmgr *bufmgr, const char *name,
|
|||
bo_gem->gem_handle = open_arg.handle;
|
||||
bo_gem->global_name = handle;
|
||||
|
||||
memset(&get_tiling, 0, sizeof(get_tiling));
|
||||
get_tiling.handle = bo_gem->gem_handle;
|
||||
ret = ioctl(bufmgr_gem->fd, DRM_IOCTL_I915_GEM_GET_TILING, &get_tiling);
|
||||
if (ret != 0) {
|
||||
|
|
@ -443,6 +454,10 @@ drm_intel_bo_gem_create_from_name(drm_intel_bufmgr *bufmgr, const char *name,
|
|||
}
|
||||
bo_gem->tiling_mode = get_tiling.tiling_mode;
|
||||
bo_gem->swizzle_mode = get_tiling.swizzle_mode;
|
||||
if (bo_gem->tiling_mode == I915_TILING_NONE)
|
||||
bo_gem->reloc_tree_fences = 0;
|
||||
else
|
||||
bo_gem->reloc_tree_fences = 1;
|
||||
|
||||
DBG("bo_create_from_handle: %d (%s)\n", handle, bo_gem->name);
|
||||
|
||||
|
|
@ -460,14 +475,6 @@ drm_intel_gem_bo_reference(drm_intel_bo *bo)
|
|||
pthread_mutex_unlock(&bufmgr_gem->lock);
|
||||
}
|
||||
|
||||
static void
|
||||
dri_gem_bo_reference_locked(dri_bo *bo)
|
||||
{
|
||||
drm_intel_bo_gem *bo_gem = (drm_intel_bo_gem *)bo;
|
||||
|
||||
bo_gem->refcount++;
|
||||
}
|
||||
|
||||
static void
|
||||
drm_intel_gem_bo_reference_locked(drm_intel_bo *bo)
|
||||
{
|
||||
|
|
@ -488,6 +495,7 @@ drm_intel_gem_bo_free(drm_intel_bo *bo)
|
|||
munmap (bo_gem->virtual, bo_gem->bo.size);
|
||||
|
||||
/* Close this object */
|
||||
memset(&close, 0, sizeof(close));
|
||||
close.handle = bo_gem->gem_handle;
|
||||
ret = ioctl(bufmgr_gem->fd, DRM_IOCTL_GEM_CLOSE, &close);
|
||||
if (ret != 0) {
|
||||
|
|
@ -868,6 +876,7 @@ drm_intel_gem_bo_emit_reloc(drm_intel_bo *bo, uint32_t offset,
|
|||
*/
|
||||
assert(!bo_gem->used_as_reloc_target);
|
||||
bo_gem->reloc_tree_size += target_bo_gem->reloc_tree_size;
|
||||
bo_gem->reloc_tree_fences += target_bo_gem->reloc_tree_fences;
|
||||
|
||||
/* Flag the target to disallow further relocations in it. */
|
||||
target_bo_gem->used_as_reloc_target = 1;
|
||||
|
|
@ -1004,6 +1013,7 @@ drm_intel_gem_bo_pin(drm_intel_bo *bo, uint32_t alignment)
|
|||
struct drm_i915_gem_pin pin;
|
||||
int ret;
|
||||
|
||||
memset(&pin, 0, sizeof(pin));
|
||||
pin.handle = bo_gem->gem_handle;
|
||||
pin.alignment = alignment;
|
||||
|
||||
|
|
@ -1026,6 +1036,7 @@ drm_intel_gem_bo_unpin(drm_intel_bo *bo)
|
|||
struct drm_i915_gem_unpin unpin;
|
||||
int ret;
|
||||
|
||||
memset(&unpin, 0, sizeof(unpin));
|
||||
unpin.handle = bo_gem->gem_handle;
|
||||
|
||||
ret = ioctl(bufmgr_gem->fd, DRM_IOCTL_I915_GEM_UNPIN, &unpin);
|
||||
|
|
@ -1047,6 +1058,11 @@ drm_intel_gem_bo_set_tiling(drm_intel_bo *bo, uint32_t *tiling_mode,
|
|||
if (bo_gem->global_name == 0 && *tiling_mode == bo_gem->tiling_mode)
|
||||
return 0;
|
||||
|
||||
/* If we're going from non-tiling to tiling, bump fence count */
|
||||
if (bo_gem->tiling_mode == I915_TILING_NONE)
|
||||
bo_gem->reloc_tree_fences++;
|
||||
|
||||
memset(&set_tiling, 0, sizeof(set_tiling));
|
||||
set_tiling.handle = bo_gem->gem_handle;
|
||||
set_tiling.tiling_mode = *tiling_mode;
|
||||
set_tiling.stride = stride;
|
||||
|
|
@ -1059,6 +1075,10 @@ drm_intel_gem_bo_set_tiling(drm_intel_bo *bo, uint32_t *tiling_mode,
|
|||
bo_gem->tiling_mode = set_tiling.tiling_mode;
|
||||
bo_gem->swizzle_mode = set_tiling.swizzle_mode;
|
||||
|
||||
/* If we're going from tiling to non-tiling, drop fence count */
|
||||
if (bo_gem->tiling_mode == I915_TILING_NONE)
|
||||
bo_gem->reloc_tree_fences--;
|
||||
|
||||
*tiling_mode = bo_gem->tiling_mode;
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1083,6 +1103,7 @@ drm_intel_gem_bo_flink(drm_intel_bo *bo, uint32_t *name)
|
|||
int ret;
|
||||
|
||||
if (!bo_gem->global_name) {
|
||||
memset(&flink, 0, sizeof(flink));
|
||||
flink.handle = bo_gem->gem_handle;
|
||||
|
||||
ret = ioctl(bufmgr_gem->fd, DRM_IOCTL_GEM_FLINK, &flink);
|
||||
|
|
@ -1136,6 +1157,31 @@ drm_intel_gem_bo_get_aperture_space(drm_intel_bo *bo)
|
|||
return total;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count the number of buffers in this list that need a fence reg
|
||||
*
|
||||
* If the count is greater than the number of available regs, we'll have
|
||||
* to ask the caller to resubmit a batch with fewer tiled buffers.
|
||||
*
|
||||
* This function over-counts if the same buffer is used multiple times.
|
||||
*/
|
||||
static unsigned int
|
||||
drm_intel_gem_total_fences(drm_intel_bo **bo_array, int count)
|
||||
{
|
||||
int i;
|
||||
unsigned int total = 0;
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
drm_intel_bo_gem *bo_gem = (drm_intel_bo_gem *)bo_array[i];
|
||||
|
||||
if (bo_gem == NULL)
|
||||
continue;
|
||||
|
||||
total += bo_gem->reloc_tree_fences;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the flag set by drm_intel_gem_bo_get_aperture_space() so we're ready
|
||||
* for the next drm_intel_bufmgr_check_aperture_space() call.
|
||||
|
|
@ -1214,9 +1260,17 @@ drm_intel_gem_check_aperture_space(drm_intel_bo **bo_array, int count)
|
|||
drm_intel_bufmgr_gem *bufmgr_gem = (drm_intel_bufmgr_gem *)bo_array[0]->bufmgr;
|
||||
unsigned int total = 0;
|
||||
unsigned int threshold = bufmgr_gem->gtt_size * 3 / 4;
|
||||
int total_fences;
|
||||
|
||||
/* Check for fence reg constraints if necessary */
|
||||
if (bufmgr_gem->available_fences) {
|
||||
total_fences = drm_intel_gem_total_fences(bo_array, count);
|
||||
if (total_fences > bufmgr_gem->available_fences)
|
||||
return -1;
|
||||
}
|
||||
|
||||
total = drm_intel_gem_estimate_batch_space(bo_array, count);
|
||||
|
||||
|
||||
if (total > threshold)
|
||||
total = drm_intel_gem_compute_batch_space(bo_array, count);
|
||||
|
||||
|
|
@ -1242,6 +1296,7 @@ drm_intel_bufmgr_gem_init(int fd, int batch_size)
|
|||
{
|
||||
drm_intel_bufmgr_gem *bufmgr_gem;
|
||||
struct drm_i915_gem_get_aperture aperture;
|
||||
drm_i915_getparam_t gp;
|
||||
int ret, i;
|
||||
|
||||
bufmgr_gem = calloc(1, sizeof(*bufmgr_gem));
|
||||
|
|
@ -1265,6 +1320,25 @@ drm_intel_bufmgr_gem_init(int fd, int batch_size)
|
|||
(int)bufmgr_gem->gtt_size / 1024);
|
||||
}
|
||||
|
||||
gp.param = I915_PARAM_CHIPSET_ID;
|
||||
gp.value = &bufmgr_gem->pci_device;
|
||||
ret = ioctl(bufmgr_gem->fd, DRM_IOCTL_I915_GETPARAM, &gp);
|
||||
if (ret) {
|
||||
fprintf(stderr, "get chip id failed: %d\n", ret);
|
||||
fprintf(stderr, "param: %d, val: %d\n", gp.param, *gp.value);
|
||||
}
|
||||
|
||||
if (!IS_I965G(bufmgr_gem)) {
|
||||
gp.param = I915_PARAM_NUM_FENCES_AVAIL;
|
||||
gp.value = &bufmgr_gem->available_fences;
|
||||
ret = ioctl(bufmgr_gem->fd, DRM_IOCTL_I915_GETPARAM, &gp);
|
||||
if (ret) {
|
||||
fprintf(stderr, "get fences failed: %d\n", ret);
|
||||
fprintf(stderr, "param: %d, val: %d\n", gp.param, *gp.value);
|
||||
bufmgr_gem->available_fences = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Let's go with one relocation per every 2 dwords (but round down a bit
|
||||
* since a power of two will mean an extra page allocation for the reloc
|
||||
* buffer).
|
||||
|
|
|
|||
71
libdrm/intel/intel_chipset.h
Normal file
71
libdrm/intel/intel_chipset.h
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
*
|
||||
* Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* 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, sub license, 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 (including the
|
||||
* next paragraph) 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 NON-INFRINGEMENT.
|
||||
* IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _INTEL_CHIPSET_H
|
||||
#define _INTEL_CHIPSET_H
|
||||
|
||||
#define IS_I830(dev) ((dev)->pci_device == 0x3577)
|
||||
#define IS_845G(dev) ((dev)->pci_device == 0x2562)
|
||||
#define IS_I85X(dev) ((dev)->pci_device == 0x3582)
|
||||
#define IS_I855(dev) ((dev)->pci_device == 0x3582)
|
||||
#define IS_I865G(dev) ((dev)->pci_device == 0x2572)
|
||||
|
||||
#define IS_I915G(dev) ((dev)->pci_device == 0x2582 || (dev)->pci_device == 0x258a)
|
||||
#define IS_I915GM(dev) ((dev)->pci_device == 0x2592)
|
||||
#define IS_I945G(dev) ((dev)->pci_device == 0x2772)
|
||||
#define IS_I945GM(dev) ((dev)->pci_device == 0x27A2 ||\
|
||||
(dev)->pci_device == 0x27AE)
|
||||
#define IS_I965G(dev) ((dev)->pci_device == 0x2972 || \
|
||||
(dev)->pci_device == 0x2982 || \
|
||||
(dev)->pci_device == 0x2992 || \
|
||||
(dev)->pci_device == 0x29A2 || \
|
||||
(dev)->pci_device == 0x2A02 || \
|
||||
(dev)->pci_device == 0x2A12 || \
|
||||
(dev)->pci_device == 0x2A42 || \
|
||||
(dev)->pci_device == 0x2E02 || \
|
||||
(dev)->pci_device == 0x2E12 || \
|
||||
(dev)->pci_device == 0x2E22)
|
||||
|
||||
#define IS_I965GM(dev) ((dev)->pci_device == 0x2A02)
|
||||
|
||||
#define IS_GM45(dev) ((dev)->pci_device == 0x2A42)
|
||||
|
||||
#define IS_G4X(dev) ((dev)->pci_device == 0x2E02 || \
|
||||
(dev)->pci_device == 0x2E12 || \
|
||||
(dev)->pci_device == 0x2E22)
|
||||
|
||||
#define IS_G33(dev) ((dev)->pci_device == 0x29C2 || \
|
||||
(dev)->pci_device == 0x29B2 || \
|
||||
(dev)->pci_device == 0x29D2)
|
||||
|
||||
#define IS_I9XX(dev) (IS_I915G(dev) || IS_I915GM(dev) || IS_I945G(dev) || \
|
||||
IS_I945GM(dev) || IS_I965G(dev) || IS_G33(dev))
|
||||
|
||||
#define IS_MOBILE(dev) (IS_I830(dev) || IS_I85X(dev) || IS_I915GM(dev) || \
|
||||
IS_I945GM(dev) || IS_I965GM(dev) || IS_GM45(dev))
|
||||
|
||||
#endif /* _INTEL_CHIPSET_H */
|
||||
40
libdrm/nouveau/Makefile.am
Normal file
40
libdrm/nouveau/Makefile.am
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
AM_CFLAGS = \
|
||||
$(WARN_CFLAGS) \
|
||||
-I$(top_srcdir)/libdrm \
|
||||
-I$(top_srcdir)/libdrm/nouveau \
|
||||
$(PTHREADSTUBS_CFLAGS) \
|
||||
-I$(top_srcdir)/shared-core
|
||||
|
||||
libdrm_nouveau_la_LTLIBRARIES = libdrm_nouveau.la
|
||||
libdrm_nouveau_ladir = $(libdir)
|
||||
libdrm_nouveau_la_LDFLAGS = -version-number 1:0:0 -no-undefined
|
||||
libdrm_nouveau_la_LIBADD = ../libdrm.la @PTHREADSTUBS_LIBS@
|
||||
|
||||
libdrm_nouveau_la_SOURCES = \
|
||||
nouveau_device.c \
|
||||
nouveau_channel.c \
|
||||
nouveau_pushbuf.c \
|
||||
nouveau_grobj.c \
|
||||
nouveau_notifier.c \
|
||||
nouveau_bo.c \
|
||||
nouveau_resource.c \
|
||||
nouveau_dma.c \
|
||||
nouveau_fence.c
|
||||
|
||||
libdrm_nouveaucommonincludedir = ${includedir}/nouveau
|
||||
libdrm_nouveaucommoninclude_HEADERS = \
|
||||
nouveau_device.h \
|
||||
nouveau_channel.h \
|
||||
nouveau_grobj.h \
|
||||
nouveau_notifier.h \
|
||||
nouveau_pushbuf.h \
|
||||
nouveau_bo.h \
|
||||
nouveau_resource.h \
|
||||
nouveau_class.h
|
||||
|
||||
libdrm_nouveauincludedir = ${includedir}/drm
|
||||
libdrm_nouveauinclude_HEADERS = \
|
||||
nouveau_drmif.h
|
||||
|
||||
pkgconfigdir = @pkgconfigdir@
|
||||
pkgconfig_DATA = libdrm_nouveau.pc
|
||||
10
libdrm/nouveau/libdrm_nouveau.pc.in
Normal file
10
libdrm/nouveau/libdrm_nouveau.pc.in
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
prefix=@prefix@
|
||||
exec_prefix=@exec_prefix@
|
||||
libdir=@libdir@
|
||||
includedir=@includedir@
|
||||
|
||||
Name: libdrm_nouveau
|
||||
Description: Userspace interface to nouveau kernel DRM services
|
||||
Version: 0.5
|
||||
Libs: -L${libdir} -ldrm_nouveau
|
||||
Cflags: -I${includedir} -I${includedir}/drm -I${includedir}/nouveau
|
||||
845
libdrm/nouveau/nouveau_bo.c
Normal file
845
libdrm/nouveau/nouveau_bo.c
Normal file
|
|
@ -0,0 +1,845 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <sys/mman.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include "nouveau_private.h"
|
||||
|
||||
int
|
||||
nouveau_bo_init(struct nouveau_device *dev)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
nouveau_bo_takedown(struct nouveau_device *dev)
|
||||
{
|
||||
}
|
||||
|
||||
static int
|
||||
nouveau_bo_allocated(struct nouveau_bo_priv *nvbo)
|
||||
{
|
||||
if (nvbo->sysmem || nvbo->handle || (nvbo->flags & NOUVEAU_BO_PIN))
|
||||
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_nomm(struct nouveau_bo_priv *nvbo)
|
||||
{
|
||||
struct nouveau_device_priv *nvdev = nouveau_device(nvbo->base.device);
|
||||
struct drm_nouveau_mem_free req;
|
||||
|
||||
if (nvbo->map) {
|
||||
drmUnmap(nvbo->map, nvbo->size);
|
||||
nvbo->map = NULL;
|
||||
}
|
||||
|
||||
req.offset = nvbo->offset;
|
||||
if (nvbo->domain & NOUVEAU_BO_GART)
|
||||
req.flags = NOUVEAU_MEM_AGP | NOUVEAU_MEM_PCI;
|
||||
else
|
||||
if (nvbo->domain & NOUVEAU_BO_VRAM)
|
||||
req.flags = NOUVEAU_MEM_FB;
|
||||
drmCommandWrite(nvdev->fd, DRM_NOUVEAU_MEM_FREE, &req, sizeof(req));
|
||||
|
||||
nvbo->handle = 0;
|
||||
}
|
||||
|
||||
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 (!nvdev->mm_enabled) {
|
||||
nouveau_bo_kfree_nomm(nvbo);
|
||||
return;
|
||||
}
|
||||
|
||||
if (nvbo->map) {
|
||||
munmap(nvbo->map, nvbo->size);
|
||||
nvbo->map = NULL;
|
||||
}
|
||||
|
||||
req.handle = nvbo->handle;
|
||||
nvbo->handle = 0;
|
||||
ioctl(nvdev->fd, DRM_IOCTL_GEM_CLOSE, &req);
|
||||
}
|
||||
|
||||
static int
|
||||
nouveau_bo_kalloc_nomm(struct nouveau_bo_priv *nvbo)
|
||||
{
|
||||
struct nouveau_device_priv *nvdev = nouveau_device(nvbo->base.device);
|
||||
struct drm_nouveau_mem_alloc req;
|
||||
int ret;
|
||||
|
||||
if (nvbo->handle)
|
||||
return 0;
|
||||
|
||||
if (!(nvbo->flags & (NOUVEAU_BO_VRAM|NOUVEAU_BO_GART)))
|
||||
nvbo->flags |= (NOUVEAU_BO_GART | NOUVEAU_BO_VRAM);
|
||||
|
||||
req.size = nvbo->size;
|
||||
req.alignment = nvbo->align;
|
||||
req.flags = 0;
|
||||
if (nvbo->flags & NOUVEAU_BO_VRAM)
|
||||
req.flags |= NOUVEAU_MEM_FB;
|
||||
if (nvbo->flags & NOUVEAU_BO_GART)
|
||||
req.flags |= (NOUVEAU_MEM_AGP | NOUVEAU_MEM_PCI);
|
||||
if (nvbo->flags & NOUVEAU_BO_TILED) {
|
||||
req.flags |= NOUVEAU_MEM_TILE;
|
||||
if (nvbo->flags & NOUVEAU_BO_ZTILE)
|
||||
req.flags |= NOUVEAU_MEM_TILE_ZETA;
|
||||
}
|
||||
req.flags |= NOUVEAU_MEM_MAPPED;
|
||||
|
||||
ret = drmCommandWriteRead(nvdev->fd, DRM_NOUVEAU_MEM_ALLOC,
|
||||
&req, sizeof(req));
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
nvbo->handle = req.map_handle;
|
||||
nvbo->size = req.size;
|
||||
nvbo->offset = req.offset;
|
||||
if (req.flags & (NOUVEAU_MEM_AGP | NOUVEAU_MEM_PCI))
|
||||
nvbo->domain = NOUVEAU_BO_GART;
|
||||
else
|
||||
if (req.flags & NOUVEAU_MEM_FB)
|
||||
nvbo->domain = NOUVEAU_BO_VRAM;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
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;
|
||||
int ret;
|
||||
|
||||
if (nvbo->handle || (nvbo->flags & NOUVEAU_BO_PIN))
|
||||
return 0;
|
||||
|
||||
if (!nvdev->mm_enabled)
|
||||
return nouveau_bo_kalloc_nomm(nvbo);
|
||||
|
||||
req.channel_hint = chan ? chan->id : 0;
|
||||
|
||||
req.size = nvbo->size;
|
||||
req.align = nvbo->align;
|
||||
|
||||
req.domain = 0;
|
||||
|
||||
if (nvbo->flags & NOUVEAU_BO_VRAM)
|
||||
req.domain |= NOUVEAU_GEM_DOMAIN_VRAM;
|
||||
|
||||
if (nvbo->flags & NOUVEAU_BO_GART)
|
||||
req.domain |= NOUVEAU_GEM_DOMAIN_GART;
|
||||
|
||||
if (nvbo->flags & NOUVEAU_BO_TILED) {
|
||||
req.domain |= NOUVEAU_GEM_DOMAIN_TILE;
|
||||
if (nvbo->flags & NOUVEAU_BO_ZTILE)
|
||||
req.domain |= NOUVEAU_GEM_DOMAIN_TILE_ZETA;
|
||||
}
|
||||
|
||||
if (!req.domain) {
|
||||
req.domain |= (NOUVEAU_GEM_DOMAIN_VRAM |
|
||||
NOUVEAU_GEM_DOMAIN_GART);
|
||||
}
|
||||
|
||||
ret = drmCommandWriteRead(nvdev->fd, DRM_NOUVEAU_GEM_NEW,
|
||||
&req, sizeof(req));
|
||||
if (ret)
|
||||
return ret;
|
||||
nvbo->handle = nvbo->base.handle = req.handle;
|
||||
nvbo->size = req.size;
|
||||
nvbo->domain = req.domain;
|
||||
nvbo->offset = req.offset;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
nouveau_bo_kmap_nomm(struct nouveau_bo_priv *nvbo)
|
||||
{
|
||||
struct nouveau_device_priv *nvdev = nouveau_device(nvbo->base.device);
|
||||
int ret;
|
||||
|
||||
ret = drmMap(nvdev->fd, nvbo->handle, nvbo->size, &nvbo->map);
|
||||
if (ret) {
|
||||
nvbo->map = NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
nouveau_bo_kmap(struct nouveau_bo_priv *nvbo)
|
||||
{
|
||||
struct nouveau_device_priv *nvdev = nouveau_device(nvbo->base.device);
|
||||
struct drm_nouveau_gem_mmap req;
|
||||
int ret;
|
||||
|
||||
if (nvbo->map)
|
||||
return 0;
|
||||
|
||||
if (!nvbo->handle)
|
||||
return -EINVAL;
|
||||
|
||||
if (!nvdev->mm_enabled)
|
||||
return nouveau_bo_kmap_nomm(nvbo);
|
||||
|
||||
req.handle = nvbo->handle;
|
||||
ret = drmCommandWriteRead(nvdev->fd, DRM_NOUVEAU_GEM_MMAP,
|
||||
&req, sizeof(req));
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
nvbo->map = (void *)(unsigned long)req.vaddr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
nouveau_bo_new(struct nouveau_device *dev, uint32_t flags, int align,
|
||||
int size, struct nouveau_bo **bo)
|
||||
{
|
||||
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;
|
||||
|
||||
nvbo->refcount = 1;
|
||||
/* Don't set NOUVEAU_BO_PIN here, or nouveau_bo_allocated() will
|
||||
* decided the buffer's already allocated when it's not. The
|
||||
* call to nouveau_bo_pin() later will set this flag.
|
||||
*/
|
||||
nvbo->flags = (flags & ~NOUVEAU_BO_PIN);
|
||||
nvbo->size = size;
|
||||
nvbo->align = align;
|
||||
|
||||
/*XXX: murder me violently */
|
||||
if (flags & NOUVEAU_BO_TILED) {
|
||||
nvbo->base.tiled = 1;
|
||||
if (flags & NOUVEAU_BO_ZTILE)
|
||||
nvbo->base.tiled |= 2;
|
||||
}
|
||||
|
||||
if (flags & NOUVEAU_BO_PIN) {
|
||||
ret = nouveau_bo_pin((void *)nvbo, nvbo->flags);
|
||||
if (ret) {
|
||||
nouveau_bo_ref(NULL, (void *)nvbo);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
*bo = &nvbo->base;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
nouveau_bo_user(struct nouveau_device *dev, void *ptr, int size,
|
||||
struct nouveau_bo **bo)
|
||||
{
|
||||
struct nouveau_bo_priv *nvbo;
|
||||
int ret;
|
||||
|
||||
ret = nouveau_bo_new(dev, 0, 0, size, bo);
|
||||
if (ret)
|
||||
return ret;
|
||||
nvbo = nouveau_bo(*bo);
|
||||
|
||||
nvbo->sysmem = ptr;
|
||||
nvbo->user = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
nouveau_bo_fake(struct nouveau_device *dev, uint64_t offset, uint32_t flags,
|
||||
uint32_t size, void *map, struct nouveau_bo **bo)
|
||||
{
|
||||
struct nouveau_bo_priv *nvbo;
|
||||
int ret;
|
||||
|
||||
ret = nouveau_bo_new(dev, flags & ~NOUVEAU_BO_PIN, 0, size, bo);
|
||||
if (ret)
|
||||
return ret;
|
||||
nvbo = nouveau_bo(*bo);
|
||||
|
||||
nvbo->flags = flags | NOUVEAU_BO_PIN;
|
||||
nvbo->domain = (flags & (NOUVEAU_BO_VRAM|NOUVEAU_BO_GART));
|
||||
nvbo->offset = offset;
|
||||
nvbo->size = nvbo->base.size = size;
|
||||
nvbo->map = map;
|
||||
nvbo->base.flags = nvbo->flags;
|
||||
nvbo->base.offset = nvbo->offset;
|
||||
return 0;
|
||||
}
|
||||
|
||||
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 (!nvdev->mm_enabled)
|
||||
return -ENODEV;
|
||||
|
||||
if (!nvbo->global_handle) {
|
||||
struct drm_gem_flink req;
|
||||
|
||||
ret = nouveau_bo_kalloc(nvbo, NULL);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
req.handle = nvbo->handle;
|
||||
ret = ioctl(nvdev->fd, DRM_IOCTL_GEM_FLINK, &req);
|
||||
if (ret) {
|
||||
nouveau_bo_kfree(nvbo);
|
||||
return ret;
|
||||
}
|
||||
|
||||
nvbo->global_handle = req.name;
|
||||
}
|
||||
|
||||
*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;
|
||||
|
||||
ret = nouveau_bo_new(dev, 0, 0, 0, bo);
|
||||
if (ret)
|
||||
return ret;
|
||||
nvbo = nouveau_bo(*bo);
|
||||
|
||||
if (!nvdev->mm_enabled) {
|
||||
nvbo->handle = 0;
|
||||
nvbo->offset = handle;
|
||||
nvbo->domain = NOUVEAU_BO_VRAM;
|
||||
nvbo->flags = NOUVEAU_BO_VRAM | NOUVEAU_BO_PIN;
|
||||
nvbo->base.offset = nvbo->offset;
|
||||
nvbo->base.flags = nvbo->flags;
|
||||
} else {
|
||||
req.name = handle;
|
||||
ret = ioctl(nvdev->fd, DRM_IOCTL_GEM_OPEN, &req);
|
||||
if (ret) {
|
||||
nouveau_bo_ref(NULL, bo);
|
||||
return ret;
|
||||
}
|
||||
|
||||
nvbo->size = req.size;
|
||||
nvbo->handle = req.handle;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
nouveau_bo_del_cb(void *priv)
|
||||
{
|
||||
struct nouveau_bo_priv *nvbo = priv;
|
||||
|
||||
nouveau_bo_kfree(nvbo);
|
||||
free(nvbo);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
if (!nouveau_device(nvbo->base.device)->mm_enabled && nvbo->fence) {
|
||||
nouveau_fence_flush(nvbo->fence->channel);
|
||||
if (nouveau_fence(nvbo->fence)->signalled) {
|
||||
nouveau_bo_del_cb(nvbo);
|
||||
} else {
|
||||
nouveau_fence_signal_cb(nvbo->fence,
|
||||
nouveau_bo_del_cb, nvbo);
|
||||
}
|
||||
} else {
|
||||
nouveau_bo_del_cb(nvbo);
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
nouveau_bo_wait_nomm(struct nouveau_bo *bo, int cpu_write)
|
||||
{
|
||||
struct nouveau_bo_priv *nvbo = nouveau_bo(bo);
|
||||
int ret = 0;
|
||||
|
||||
if (cpu_write)
|
||||
ret = nouveau_fence_wait(&nvbo->fence);
|
||||
else
|
||||
ret = nouveau_fence_wait(&nvbo->wr_fence);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
nvbo->write_marker = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
nouveau_bo_wait(struct nouveau_bo *bo, int cpu_write)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
if (!nvdev->mm_enabled)
|
||||
return nouveau_bo_wait_nomm(bo, cpu_write);
|
||||
|
||||
req.handle = nvbo->handle;
|
||||
ret = drmCommandWrite(nvdev->fd, DRM_NOUVEAU_GEM_CPU_PREP,
|
||||
&req, sizeof(req));
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
nvbo->write_marker = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
nouveau_bo_map(struct nouveau_bo *bo, uint32_t flags)
|
||||
{
|
||||
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) {
|
||||
bo->map = nvbo->sysmem;
|
||||
} else {
|
||||
ret = nouveau_bo_kmap(nvbo);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = nouveau_bo_wait(bo, (flags & NOUVEAU_BO_WR));
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
bo->map = nvbo->map;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
nouveau_bo_unmap(struct nouveau_bo *bo)
|
||||
{
|
||||
struct nouveau_device_priv *nvdev = nouveau_device(bo->device);
|
||||
struct nouveau_bo_priv *nvbo = nouveau_bo(bo);
|
||||
|
||||
if (nvdev->mm_enabled && bo->map && !nvbo->sysmem) {
|
||||
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));
|
||||
}
|
||||
|
||||
bo->map = NULL;
|
||||
}
|
||||
|
||||
int
|
||||
nouveau_bo_validate_nomm(struct nouveau_bo_priv *nvbo, uint32_t flags)
|
||||
{
|
||||
struct nouveau_bo *new = NULL;
|
||||
uint32_t t_handle, t_domain, t_offset, t_size;
|
||||
void *t_map;
|
||||
int ret;
|
||||
|
||||
if ((flags & NOUVEAU_BO_VRAM) && nvbo->domain == NOUVEAU_BO_VRAM)
|
||||
return 0;
|
||||
if ((flags & NOUVEAU_BO_GART) && nvbo->domain == NOUVEAU_BO_GART)
|
||||
return 0;
|
||||
assert(flags & (NOUVEAU_BO_VRAM|NOUVEAU_BO_GART));
|
||||
|
||||
/* Keep tiling info */
|
||||
flags |= (nvbo->flags & (NOUVEAU_BO_TILED|NOUVEAU_BO_ZTILE));
|
||||
|
||||
ret = nouveau_bo_new(nvbo->base.device, flags, 0, nvbo->size, &new);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = nouveau_bo_kalloc(nouveau_bo(new), NULL);
|
||||
if (ret) {
|
||||
nouveau_bo_ref(NULL, &new);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (nvbo->handle || nvbo->sysmem) {
|
||||
nouveau_bo_kmap(nouveau_bo(new));
|
||||
|
||||
if (!nvbo->base.map) {
|
||||
nouveau_bo_map(&nvbo->base, NOUVEAU_BO_RD);
|
||||
memcpy(nouveau_bo(new)->map, nvbo->base.map, nvbo->base.size);
|
||||
nouveau_bo_unmap(&nvbo->base);
|
||||
} else {
|
||||
memcpy(nouveau_bo(new)->map, nvbo->base.map, nvbo->base.size);
|
||||
}
|
||||
}
|
||||
|
||||
t_handle = nvbo->handle;
|
||||
t_domain = nvbo->domain;
|
||||
t_offset = nvbo->offset;
|
||||
t_size = nvbo->size;
|
||||
t_map = nvbo->map;
|
||||
|
||||
nvbo->handle = nouveau_bo(new)->handle;
|
||||
nvbo->domain = nouveau_bo(new)->domain;
|
||||
nvbo->offset = nouveau_bo(new)->offset;
|
||||
nvbo->size = nouveau_bo(new)->size;
|
||||
nvbo->map = nouveau_bo(new)->map;
|
||||
|
||||
nouveau_bo(new)->handle = t_handle;
|
||||
nouveau_bo(new)->domain = t_domain;
|
||||
nouveau_bo(new)->offset = t_offset;
|
||||
nouveau_bo(new)->size = t_size;
|
||||
nouveau_bo(new)->map = t_map;
|
||||
|
||||
nouveau_bo_ref(NULL, &new);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
nouveau_bo_pin_nomm(struct nouveau_bo *bo, uint32_t flags)
|
||||
{
|
||||
struct nouveau_bo_priv *nvbo = nouveau_bo(bo);
|
||||
int ret;
|
||||
|
||||
if (!nvbo->handle) {
|
||||
if (!(flags & (NOUVEAU_BO_VRAM | NOUVEAU_BO_GART)))
|
||||
return -EINVAL;
|
||||
|
||||
ret = nouveau_bo_validate_nomm(nvbo, flags & ~NOUVEAU_BO_PIN);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
|
||||
nvbo->pinned = 1;
|
||||
|
||||
/* Fill in public nouveau_bo members */
|
||||
bo->flags = nvbo->domain;
|
||||
bo->offset = nvbo->offset;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
nouveau_bo_pin(struct nouveau_bo *bo, uint32_t flags)
|
||||
{
|
||||
struct nouveau_device_priv *nvdev = nouveau_device(bo->device);
|
||||
struct nouveau_bo_priv *nvbo = nouveau_bo(bo);
|
||||
struct drm_nouveau_gem_pin req;
|
||||
int ret;
|
||||
|
||||
if (nvbo->pinned)
|
||||
return 0;
|
||||
|
||||
if (!nvdev->mm_enabled)
|
||||
return nouveau_bo_pin_nomm(bo, flags);
|
||||
|
||||
/* Ensure we have a kernel object... */
|
||||
if (!nvbo->handle) {
|
||||
if (!(flags & (NOUVEAU_BO_VRAM | NOUVEAU_BO_GART)))
|
||||
return -EINVAL;
|
||||
nvbo->flags = flags;
|
||||
|
||||
ret = nouveau_bo_kalloc(nvbo, NULL);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Now force it to stay put :) */
|
||||
req.handle = nvbo->handle;
|
||||
req.domain = 0;
|
||||
if (nvbo->flags & NOUVEAU_BO_VRAM)
|
||||
req.domain |= NOUVEAU_GEM_DOMAIN_VRAM;
|
||||
if (nvbo->flags & NOUVEAU_BO_GART)
|
||||
req.domain |= NOUVEAU_GEM_DOMAIN_GART;
|
||||
|
||||
ret = drmCommandWriteRead(nvdev->fd, DRM_NOUVEAU_GEM_PIN, &req,
|
||||
sizeof(struct drm_nouveau_gem_pin));
|
||||
if (ret)
|
||||
return ret;
|
||||
nvbo->offset = req.offset;
|
||||
nvbo->domain = req.domain;
|
||||
nvbo->pinned = 1;
|
||||
nvbo->flags |= NOUVEAU_BO_PIN;
|
||||
|
||||
/* Fill in public nouveau_bo members */
|
||||
if (nvbo->domain & NOUVEAU_GEM_DOMAIN_VRAM)
|
||||
bo->flags = NOUVEAU_BO_VRAM;
|
||||
if (nvbo->domain & NOUVEAU_GEM_DOMAIN_GART)
|
||||
bo->flags = NOUVEAU_BO_GART;
|
||||
bo->offset = nvbo->offset;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
nouveau_bo_unpin(struct nouveau_bo *bo)
|
||||
{
|
||||
struct nouveau_device_priv *nvdev = nouveau_device(bo->device);
|
||||
struct nouveau_bo_priv *nvbo = nouveau_bo(bo);
|
||||
struct drm_nouveau_gem_unpin req;
|
||||
|
||||
if (!nvbo->pinned)
|
||||
return;
|
||||
|
||||
if (nvdev->mm_enabled) {
|
||||
req.handle = nvbo->handle;
|
||||
drmCommandWrite(nvdev->fd, DRM_NOUVEAU_GEM_UNPIN,
|
||||
&req, sizeof(req));
|
||||
}
|
||||
|
||||
nvbo->pinned = bo->offset = bo->flags = 0;
|
||||
}
|
||||
|
||||
int
|
||||
nouveau_bo_tile(struct nouveau_bo *bo, uint32_t flags, uint32_t delta,
|
||||
uint32_t size)
|
||||
{
|
||||
struct nouveau_device_priv *nvdev = nouveau_device(bo->device);
|
||||
struct nouveau_bo_priv *nvbo = nouveau_bo(bo);
|
||||
uint32_t kern_flags = 0;
|
||||
int ret = 0;
|
||||
|
||||
if (flags & NOUVEAU_BO_TILED) {
|
||||
kern_flags |= NOUVEAU_MEM_TILE;
|
||||
if (flags & NOUVEAU_BO_ZTILE)
|
||||
kern_flags |= NOUVEAU_MEM_TILE_ZETA;
|
||||
}
|
||||
|
||||
if (nvdev->mm_enabled) {
|
||||
struct drm_nouveau_gem_tile req;
|
||||
|
||||
req.handle = nvbo->handle;
|
||||
req.delta = delta;
|
||||
req.size = size;
|
||||
req.flags = kern_flags;
|
||||
ret = drmCommandWrite(nvdev->fd, DRM_NOUVEAU_GEM_TILE,
|
||||
&req, sizeof(req));
|
||||
} else {
|
||||
struct drm_nouveau_mem_tile req;
|
||||
|
||||
req.offset = nvbo->offset;
|
||||
req.delta = delta;
|
||||
req.size = size;
|
||||
req.flags = kern_flags;
|
||||
|
||||
if (flags & NOUVEAU_BO_VRAM)
|
||||
req.flags |= NOUVEAU_MEM_FB;
|
||||
if (flags & NOUVEAU_BO_GART)
|
||||
req.flags |= NOUVEAU_MEM_AGP;
|
||||
|
||||
ret = drmCommandWrite(nvdev->fd, DRM_NOUVEAU_MEM_TILE,
|
||||
&req, sizeof(req));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
nouveau_bo_busy(struct nouveau_bo *bo, uint32_t access)
|
||||
{
|
||||
struct nouveau_device_priv *nvdev = nouveau_device(bo->device);
|
||||
struct nouveau_bo_priv *nvbo = nouveau_bo(bo);
|
||||
|
||||
if (!nvdev->mm_enabled) {
|
||||
struct nouveau_fence *fence;
|
||||
|
||||
if (nvbo->pending && (nvbo->pending->write_domains ||
|
||||
(access & NOUVEAU_BO_WR)))
|
||||
return 1;
|
||||
|
||||
if (access & NOUVEAU_BO_WR)
|
||||
fence = nvbo->fence;
|
||||
else
|
||||
fence = nvbo->wr_fence;
|
||||
return !nouveau_fence(fence)->signalled;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct drm_nouveau_gem_pushbuf_bo *
|
||||
nouveau_bo_emit_buffer(struct nouveau_channel *chan, struct nouveau_bo *bo)
|
||||
{
|
||||
struct nouveau_pushbuf_priv *nvpb = nouveau_pushbuf(chan->pushbuf);
|
||||
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_unmap(bo);
|
||||
nouveau_bo_ufree(nvbo);
|
||||
}
|
||||
}
|
||||
|
||||
if (nvpb->nr_buffers >= NOUVEAU_PUSHBUF_MAX_BUFFERS)
|
||||
return NULL;
|
||||
pbbo = nvpb->buffers + nvpb->nr_buffers++;
|
||||
nvbo->pending = pbbo;
|
||||
nvbo->pending_channel = chan;
|
||||
|
||||
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;
|
||||
pbbo->presumed_domain = nvbo->domain;
|
||||
pbbo->presumed_offset = nvbo->offset;
|
||||
pbbo->presumed_ok = 1;
|
||||
return pbbo;
|
||||
}
|
||||
97
libdrm/nouveau/nouveau_bo.h
Normal file
97
libdrm/nouveau/nouveau_bo.h
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef __NOUVEAU_BO_H__
|
||||
#define __NOUVEAU_BO_H__
|
||||
|
||||
/* Relocation/Buffer type flags */
|
||||
#define NOUVEAU_BO_VRAM (1 << 0)
|
||||
#define NOUVEAU_BO_GART (1 << 1)
|
||||
#define NOUVEAU_BO_RD (1 << 2)
|
||||
#define NOUVEAU_BO_WR (1 << 3)
|
||||
#define NOUVEAU_BO_RDWR (NOUVEAU_BO_RD | NOUVEAU_BO_WR)
|
||||
#define NOUVEAU_BO_MAP (1 << 4)
|
||||
#define NOUVEAU_BO_PIN (1 << 5)
|
||||
#define NOUVEAU_BO_LOW (1 << 6)
|
||||
#define NOUVEAU_BO_HIGH (1 << 7)
|
||||
#define NOUVEAU_BO_OR (1 << 8)
|
||||
#define NOUVEAU_BO_LOCAL (1 << 9)
|
||||
#define NOUVEAU_BO_TILED (1 << 10)
|
||||
#define NOUVEAU_BO_ZTILE (1 << 11)
|
||||
#define NOUVEAU_BO_DUMMY (1 << 31)
|
||||
|
||||
struct nouveau_bo {
|
||||
struct nouveau_device *device;
|
||||
uint32_t handle;
|
||||
|
||||
uint64_t size;
|
||||
void *map;
|
||||
|
||||
int tiled;
|
||||
|
||||
/* Available when buffer is pinned *only* */
|
||||
uint32_t flags;
|
||||
uint64_t offset;
|
||||
};
|
||||
|
||||
int
|
||||
nouveau_bo_new(struct nouveau_device *, uint32_t flags, int align, int size,
|
||||
struct nouveau_bo **);
|
||||
|
||||
int
|
||||
nouveau_bo_user(struct nouveau_device *, void *ptr, int size,
|
||||
struct nouveau_bo **);
|
||||
|
||||
int
|
||||
nouveau_bo_fake(struct nouveau_device *dev, uint64_t offset, uint32_t flags,
|
||||
uint32_t size, void *map, struct nouveau_bo **);
|
||||
|
||||
int
|
||||
nouveau_bo_handle_get(struct nouveau_bo *, uint32_t *);
|
||||
|
||||
int
|
||||
nouveau_bo_handle_ref(struct nouveau_device *, uint32_t handle,
|
||||
struct nouveau_bo **);
|
||||
|
||||
int
|
||||
nouveau_bo_ref(struct nouveau_bo *, struct nouveau_bo **);
|
||||
|
||||
int
|
||||
nouveau_bo_map(struct nouveau_bo *, uint32_t flags);
|
||||
|
||||
void
|
||||
nouveau_bo_unmap(struct nouveau_bo *);
|
||||
|
||||
int
|
||||
nouveau_bo_pin(struct nouveau_bo *, uint32_t flags);
|
||||
|
||||
void
|
||||
nouveau_bo_unpin(struct nouveau_bo *);
|
||||
|
||||
int
|
||||
nouveau_bo_tile(struct nouveau_bo *, uint32_t flags, uint32_t delta,
|
||||
uint32_t size);
|
||||
|
||||
int
|
||||
nouveau_bo_busy(struct nouveau_bo *, uint32_t access);
|
||||
|
||||
#endif
|
||||
178
libdrm/nouveau/nouveau_channel.c
Normal file
178
libdrm/nouveau/nouveau_channel.c
Normal file
|
|
@ -0,0 +1,178 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "nouveau_private.h"
|
||||
|
||||
int
|
||||
nouveau_channel_alloc(struct nouveau_device *dev, uint32_t fb_ctxdma,
|
||||
uint32_t tt_ctxdma, struct nouveau_channel **chan)
|
||||
{
|
||||
struct nouveau_device_priv *nvdev = nouveau_device(dev);
|
||||
struct nouveau_channel_priv *nvchan;
|
||||
unsigned i;
|
||||
int ret;
|
||||
|
||||
if (!nvdev || !chan || *chan)
|
||||
return -EINVAL;
|
||||
|
||||
nvchan = calloc(1, sizeof(struct nouveau_channel_priv));
|
||||
if (!nvchan)
|
||||
return -ENOMEM;
|
||||
nvchan->base.device = dev;
|
||||
|
||||
nvchan->drm.fb_ctxdma_handle = fb_ctxdma;
|
||||
nvchan->drm.tt_ctxdma_handle = tt_ctxdma;
|
||||
ret = drmCommandWriteRead(nvdev->fd, DRM_NOUVEAU_CHANNEL_ALLOC,
|
||||
&nvchan->drm, sizeof(nvchan->drm));
|
||||
if (ret) {
|
||||
free(nvchan);
|
||||
return ret;
|
||||
}
|
||||
|
||||
nvchan->base.id = nvchan->drm.channel;
|
||||
if (nouveau_grobj_ref(&nvchan->base, nvchan->drm.fb_ctxdma_handle,
|
||||
&nvchan->base.vram) ||
|
||||
nouveau_grobj_ref(&nvchan->base, nvchan->drm.tt_ctxdma_handle,
|
||||
&nvchan->base.gart)) {
|
||||
nouveau_channel_free((void *)&nvchan);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Mark all DRM-assigned subchannels as in-use */
|
||||
for (i = 0; i < nvchan->drm.nr_subchan; i++) {
|
||||
struct nouveau_grobj_priv *gr = calloc(1, sizeof(*gr));
|
||||
|
||||
gr->base.bound = NOUVEAU_GROBJ_BOUND_EXPLICIT;
|
||||
gr->base.subc = i;
|
||||
gr->base.handle = nvchan->drm.subchan[i].handle;
|
||||
gr->base.grclass = nvchan->drm.subchan[i].grclass;
|
||||
gr->base.channel = &nvchan->base;
|
||||
|
||||
nvchan->base.subc[i].gr = &gr->base;
|
||||
}
|
||||
|
||||
ret = drmMap(nvdev->fd, nvchan->drm.notifier, nvchan->drm.notifier_size,
|
||||
(drmAddressPtr)&nvchan->notifier_block);
|
||||
if (ret) {
|
||||
nouveau_channel_free((void *)&nvchan);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = nouveau_grobj_alloc(&nvchan->base, 0x00000000, 0x0030,
|
||||
&nvchan->base.nullobj);
|
||||
if (ret) {
|
||||
nouveau_channel_free((void *)&nvchan);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (!nvdev->mm_enabled) {
|
||||
ret = drmMap(nvdev->fd, nvchan->drm.ctrl, nvchan->drm.ctrl_size,
|
||||
(void*)&nvchan->user);
|
||||
if (ret) {
|
||||
nouveau_channel_free((void *)&nvchan);
|
||||
return ret;
|
||||
}
|
||||
nvchan->put = &nvchan->user[0x40/4];
|
||||
nvchan->get = &nvchan->user[0x44/4];
|
||||
nvchan->ref_cnt = &nvchan->user[0x48/4];
|
||||
|
||||
ret = drmMap(nvdev->fd, nvchan->drm.cmdbuf,
|
||||
nvchan->drm.cmdbuf_size, (void*)&nvchan->pushbuf);
|
||||
if (ret) {
|
||||
nouveau_channel_free((void *)&nvchan);
|
||||
return ret;
|
||||
}
|
||||
|
||||
nouveau_dma_channel_init(&nvchan->base);
|
||||
}
|
||||
|
||||
nouveau_pushbuf_init(&nvchan->base);
|
||||
|
||||
if (!nvdev->mm_enabled && dev->chipset < 0x10) {
|
||||
ret = nouveau_grobj_alloc(&nvchan->base, 0xbeef3904, 0x5039,
|
||||
&nvchan->fence_grobj);
|
||||
if (ret) {
|
||||
nouveau_channel_free((void *)&nvchan);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = nouveau_notifier_alloc(&nvchan->base, 0xbeef3905, 1,
|
||||
&nvchan->fence_ntfy);
|
||||
if (ret) {
|
||||
nouveau_channel_free((void *)&nvchan);
|
||||
return ret;
|
||||
}
|
||||
|
||||
BEGIN_RING(&nvchan->base, nvchan->fence_grobj, 0x0180, 1);
|
||||
OUT_RING (&nvchan->base, nvchan->fence_ntfy->handle);
|
||||
nvchan->fence_grobj->bound = NOUVEAU_GROBJ_BOUND_EXPLICIT;
|
||||
}
|
||||
|
||||
*chan = &nvchan->base;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
nouveau_channel_free(struct nouveau_channel **chan)
|
||||
{
|
||||
struct nouveau_channel_priv *nvchan;
|
||||
struct nouveau_device_priv *nvdev;
|
||||
struct drm_nouveau_channel_free cf;
|
||||
|
||||
if (!chan || !*chan)
|
||||
return;
|
||||
nvchan = nouveau_channel(*chan);
|
||||
*chan = NULL;
|
||||
nvdev = nouveau_device(nvchan->base.device);
|
||||
|
||||
FIRE_RING(&nvchan->base);
|
||||
|
||||
if (!nvdev->mm_enabled) {
|
||||
struct nouveau_fence *fence = NULL;
|
||||
|
||||
/* Make sure all buffer objects on delayed delete queue
|
||||
* actually get freed.
|
||||
*/
|
||||
nouveau_fence_new(&nvchan->base, &fence);
|
||||
nouveau_fence_emit(fence);
|
||||
nouveau_fence_wait(&fence);
|
||||
}
|
||||
|
||||
if (nvchan->notifier_block)
|
||||
drmUnmap(nvchan->notifier_block, nvchan->drm.notifier_size);
|
||||
|
||||
nouveau_grobj_free(&nvchan->base.vram);
|
||||
nouveau_grobj_free(&nvchan->base.gart);
|
||||
nouveau_grobj_free(&nvchan->base.nullobj);
|
||||
nouveau_grobj_free(&nvchan->fence_grobj);
|
||||
nouveau_notifier_free(&nvchan->fence_ntfy);
|
||||
|
||||
cf.channel = nvchan->drm.channel;
|
||||
drmCommandWrite(nvdev->fd, DRM_NOUVEAU_CHANNEL_FREE, &cf, sizeof(cf));
|
||||
free(nvchan);
|
||||
}
|
||||
|
||||
|
||||
56
libdrm/nouveau/nouveau_channel.h
Normal file
56
libdrm/nouveau/nouveau_channel.h
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef __NOUVEAU_CHANNEL_H__
|
||||
#define __NOUVEAU_CHANNEL_H__
|
||||
|
||||
struct nouveau_subchannel {
|
||||
struct nouveau_grobj *gr;
|
||||
unsigned sequence;
|
||||
};
|
||||
|
||||
struct nouveau_channel {
|
||||
struct nouveau_device *device;
|
||||
int id;
|
||||
|
||||
struct nouveau_pushbuf *pushbuf;
|
||||
|
||||
struct nouveau_grobj *nullobj;
|
||||
struct nouveau_grobj *vram;
|
||||
struct nouveau_grobj *gart;
|
||||
|
||||
void *user_private;
|
||||
void (*hang_notify)(struct nouveau_channel *);
|
||||
void (*flush_notify)(struct nouveau_channel *);
|
||||
|
||||
struct nouveau_subchannel subc[8];
|
||||
unsigned subc_sequence;
|
||||
};
|
||||
|
||||
int
|
||||
nouveau_channel_alloc(struct nouveau_device *, uint32_t fb, uint32_t tt,
|
||||
struct nouveau_channel **);
|
||||
|
||||
void
|
||||
nouveau_channel_free(struct nouveau_channel **);
|
||||
|
||||
#endif
|
||||
8006
libdrm/nouveau/nouveau_class.h
Normal file
8006
libdrm/nouveau/nouveau_class.h
Normal file
File diff suppressed because it is too large
Load diff
186
libdrm/nouveau/nouveau_device.c
Normal file
186
libdrm/nouveau/nouveau_device.c
Normal file
|
|
@ -0,0 +1,186 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "nouveau_private.h"
|
||||
|
||||
#if NOUVEAU_DRM_HEADER_PATCHLEVEL != 12
|
||||
#error nouveau_drm.h does not match expected patchlevel, update libdrm.
|
||||
#endif
|
||||
|
||||
int
|
||||
nouveau_device_open_existing(struct nouveau_device **dev, int close,
|
||||
int fd, drm_context_t ctx)
|
||||
{
|
||||
struct nouveau_device_priv *nvdev;
|
||||
drmVersionPtr ver;
|
||||
uint64_t value;
|
||||
int ret;
|
||||
|
||||
if (!dev || *dev)
|
||||
return -EINVAL;
|
||||
|
||||
ver = drmGetVersion(fd);
|
||||
if (!ver || ver->version_patchlevel != NOUVEAU_DRM_HEADER_PATCHLEVEL)
|
||||
return -EINVAL;
|
||||
drmFreeVersion(ver);
|
||||
|
||||
nvdev = calloc(1, sizeof(*nvdev));
|
||||
if (!nvdev)
|
||||
return -ENOMEM;
|
||||
nvdev->fd = fd;
|
||||
nvdev->ctx = ctx;
|
||||
nvdev->needs_close = close;
|
||||
|
||||
ret = drmCommandNone(nvdev->fd, DRM_NOUVEAU_CARD_INIT);
|
||||
if (ret) {
|
||||
nouveau_device_close((void *)&nvdev);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = nouveau_device_get_param(&nvdev->base,
|
||||
NOUVEAU_GETPARAM_MM_ENABLED, &value);
|
||||
if (ret) {
|
||||
nouveau_device_close((void *)&nvdev);
|
||||
return ret;
|
||||
}
|
||||
nvdev->mm_enabled = value;
|
||||
|
||||
ret = nouveau_device_get_param(&nvdev->base,
|
||||
NOUVEAU_GETPARAM_VM_VRAM_BASE, &value);
|
||||
if (ret) {
|
||||
nouveau_device_close((void *)&nvdev);
|
||||
return ret;
|
||||
}
|
||||
nvdev->base.vm_vram_base = value;
|
||||
|
||||
ret = nouveau_bo_init(&nvdev->base);
|
||||
if (ret) {
|
||||
nouveau_device_close((void *)&nvdev);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = nouveau_device_get_param(&nvdev->base,
|
||||
NOUVEAU_GETPARAM_CHIPSET_ID, &value);
|
||||
if (ret) {
|
||||
nouveau_device_close((void *)&nvdev);
|
||||
return ret;
|
||||
}
|
||||
nvdev->base.chipset = value;
|
||||
|
||||
*dev = &nvdev->base;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
nouveau_device_open(struct nouveau_device **dev, const char *busid)
|
||||
{
|
||||
drm_context_t ctx;
|
||||
int fd, ret;
|
||||
|
||||
if (!dev || *dev)
|
||||
return -EINVAL;
|
||||
|
||||
fd = drmOpen("nouveau", busid);
|
||||
if (fd < 0)
|
||||
return -EINVAL;
|
||||
|
||||
ret = drmCreateContext(fd, &ctx);
|
||||
if (ret) {
|
||||
drmClose(fd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = nouveau_device_open_existing(dev, 1, fd, ctx);
|
||||
if (ret) {
|
||||
drmDestroyContext(fd, ctx);
|
||||
drmClose(fd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
nouveau_device_close(struct nouveau_device **dev)
|
||||
{
|
||||
struct nouveau_device_priv *nvdev;
|
||||
|
||||
if (dev || !*dev)
|
||||
return;
|
||||
nvdev = nouveau_device(*dev);
|
||||
*dev = NULL;
|
||||
|
||||
nouveau_bo_takedown(&nvdev->base);
|
||||
|
||||
if (nvdev->needs_close) {
|
||||
drmDestroyContext(nvdev->fd, nvdev->ctx);
|
||||
drmClose(nvdev->fd);
|
||||
}
|
||||
free(nvdev);
|
||||
}
|
||||
|
||||
int
|
||||
nouveau_device_get_param(struct nouveau_device *dev,
|
||||
uint64_t param, uint64_t *value)
|
||||
{
|
||||
struct nouveau_device_priv *nvdev = nouveau_device(dev);
|
||||
struct drm_nouveau_getparam g;
|
||||
int ret;
|
||||
|
||||
if (!nvdev || !value)
|
||||
return -EINVAL;
|
||||
|
||||
g.param = param;
|
||||
ret = drmCommandWriteRead(nvdev->fd, DRM_NOUVEAU_GETPARAM,
|
||||
&g, sizeof(g));
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
*value = g.value;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
nouveau_device_set_param(struct nouveau_device *dev,
|
||||
uint64_t param, uint64_t value)
|
||||
{
|
||||
struct nouveau_device_priv *nvdev = nouveau_device(dev);
|
||||
struct drm_nouveau_setparam s;
|
||||
int ret;
|
||||
|
||||
if (!nvdev)
|
||||
return -EINVAL;
|
||||
|
||||
s.param = param;
|
||||
s.value = value;
|
||||
ret = drmCommandWriteRead(nvdev->fd, DRM_NOUVEAU_SETPARAM,
|
||||
&s, sizeof(s));
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
31
libdrm/nouveau/nouveau_device.h
Normal file
31
libdrm/nouveau/nouveau_device.h
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef __NOUVEAU_DEVICE_H__
|
||||
#define __NOUVEAU_DEVICE_H__
|
||||
|
||||
struct nouveau_device {
|
||||
unsigned chipset;
|
||||
uint64_t vm_vram_base;
|
||||
};
|
||||
|
||||
#endif
|
||||
216
libdrm/nouveau/nouveau_dma.c
Normal file
216
libdrm/nouveau/nouveau_dma.c
Normal file
|
|
@ -0,0 +1,216 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "nouveau_drmif.h"
|
||||
#include "nouveau_dma.h"
|
||||
|
||||
static inline uint32_t
|
||||
READ_GET(struct nouveau_channel_priv *nvchan)
|
||||
{
|
||||
return *nvchan->get;
|
||||
}
|
||||
|
||||
static inline void
|
||||
WRITE_PUT(struct nouveau_channel_priv *nvchan, uint32_t val)
|
||||
{
|
||||
uint32_t put = ((val << 2) + nvchan->dma->base);
|
||||
volatile int dum;
|
||||
|
||||
NOUVEAU_DMA_BARRIER;
|
||||
dum = READ_GET(nvchan);
|
||||
|
||||
*nvchan->put = put;
|
||||
nvchan->dma->put = val;
|
||||
#ifdef NOUVEAU_DMA_TRACE
|
||||
printf("WRITE_PUT %d/0x%08x\n", nvchan->drm.channel, put);
|
||||
#endif
|
||||
|
||||
NOUVEAU_DMA_BARRIER;
|
||||
}
|
||||
|
||||
static inline int
|
||||
LOCAL_GET(struct nouveau_dma_priv *dma, uint32_t *val)
|
||||
{
|
||||
uint32_t get = *val;
|
||||
|
||||
if (get >= dma->base && get <= (dma->base + (dma->max << 2))) {
|
||||
*val = (get - dma->base) >> 2;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
nouveau_dma_channel_init(struct nouveau_channel *chan)
|
||||
{
|
||||
struct nouveau_channel_priv *nvchan = nouveau_channel(chan);
|
||||
int i;
|
||||
|
||||
nvchan->dma = &nvchan->struct_dma;
|
||||
nvchan->dma->base = nvchan->drm.put_base;
|
||||
nvchan->dma->cur = nvchan->dma->put = 0;
|
||||
nvchan->dma->max = (nvchan->drm.cmdbuf_size >> 2) - 2;
|
||||
nvchan->dma->free = nvchan->dma->max - nvchan->dma->cur;
|
||||
|
||||
RING_SPACE_CH(chan, RING_SKIPS);
|
||||
for (i = 0; i < RING_SKIPS; i++)
|
||||
OUT_RING_CH(chan, 0);
|
||||
}
|
||||
|
||||
#define CHECK_TIMEOUT() do { \
|
||||
if ((NOUVEAU_TIME_MSEC() - t_start) > NOUVEAU_DMA_TIMEOUT) \
|
||||
return - EBUSY; \
|
||||
} while(0)
|
||||
|
||||
int
|
||||
nouveau_dma_wait(struct nouveau_channel *chan, unsigned size)
|
||||
{
|
||||
struct nouveau_channel_priv *nvchan = nouveau_channel(chan);
|
||||
struct nouveau_dma_priv *dma = nvchan->dma;
|
||||
uint32_t get, t_start;
|
||||
|
||||
FIRE_RING_CH(chan);
|
||||
|
||||
t_start = NOUVEAU_TIME_MSEC();
|
||||
while (dma->free < size) {
|
||||
CHECK_TIMEOUT();
|
||||
|
||||
get = READ_GET(nvchan);
|
||||
if (!LOCAL_GET(dma, &get))
|
||||
continue;
|
||||
|
||||
if (dma->put >= get) {
|
||||
dma->free = dma->max - dma->cur;
|
||||
|
||||
if (dma->free < size) {
|
||||
#ifdef NOUVEAU_DMA_DEBUG
|
||||
dma->push_free = 1;
|
||||
#endif
|
||||
OUT_RING_CH(chan, 0x20000000 | dma->base);
|
||||
if (get <= RING_SKIPS) {
|
||||
/*corner case - will be idle*/
|
||||
if (dma->put <= RING_SKIPS)
|
||||
WRITE_PUT(nvchan,
|
||||
RING_SKIPS + 1);
|
||||
|
||||
do {
|
||||
CHECK_TIMEOUT();
|
||||
get = READ_GET(nvchan);
|
||||
if (!LOCAL_GET(dma, &get))
|
||||
get = 0;
|
||||
} while (get <= RING_SKIPS);
|
||||
}
|
||||
|
||||
WRITE_PUT(nvchan, RING_SKIPS);
|
||||
dma->cur = dma->put = RING_SKIPS;
|
||||
dma->free = get - (RING_SKIPS + 1);
|
||||
}
|
||||
} else {
|
||||
dma->free = get - dma->cur - 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef NOUVEAU_DMA_DUMP_POSTRELOC_PUSHBUF
|
||||
static void
|
||||
nouveau_dma_parse_pushbuf(struct nouveau_channel *chan, int get, int put)
|
||||
{
|
||||
struct nouveau_channel_priv *nvchan = nouveau_channel(chan);
|
||||
unsigned mthd_count = 0;
|
||||
|
||||
while (get != put) {
|
||||
uint32_t gpuget = (get << 2) + nvchan->drm.put_base;
|
||||
uint32_t data;
|
||||
|
||||
if (get < 0 || get >= nvchan->drm.cmdbuf_size)
|
||||
assert(0);
|
||||
data = nvchan->pushbuf[get++];
|
||||
|
||||
if (mthd_count) {
|
||||
printf("0x%08x 0x%08x\n", gpuget, data);
|
||||
mthd_count--;
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (data & 0x60000000) {
|
||||
case 0x00000000:
|
||||
mthd_count = (data >> 18) & 0x7ff;
|
||||
printf("0x%08x 0x%08x MTHD "
|
||||
"Sc %d Mthd 0x%04x Size %d\n",
|
||||
gpuget, data, (data>>13) & 7, data & 0x1ffc,
|
||||
mthd_count);
|
||||
break;
|
||||
case 0x20000000:
|
||||
get = (data & 0x1ffffffc) >> 2;
|
||||
printf("0x%08x 0x%08x JUMP 0x%08x\n",
|
||||
gpuget, data, data & 0x1ffffffc);
|
||||
continue;
|
||||
case 0x40000000:
|
||||
mthd_count = (data >> 18) & 0x7ff;
|
||||
printf("0x%08x 0x%08x NINC "
|
||||
"Sc %d Mthd 0x%04x Size %d\n",
|
||||
gpuget, data, (data>>13) & 7, data & 0x1ffc,
|
||||
mthd_count);
|
||||
break;
|
||||
case 0x60000000:
|
||||
/* DMA_OPCODE_CALL apparently, doesn't seem to work on
|
||||
* my NV40 at least..
|
||||
*/
|
||||
/* fall-through */
|
||||
default:
|
||||
printf("DMA_PUSHER 0x%08x 0x%08x\n", gpuget, data);
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
nouveau_dma_kickoff(struct nouveau_channel *chan)
|
||||
{
|
||||
struct nouveau_channel_priv *nvchan = nouveau_channel(chan);
|
||||
struct nouveau_dma_priv *dma = nvchan->dma;
|
||||
|
||||
if (dma->cur == dma->put)
|
||||
return;
|
||||
|
||||
#ifdef NOUVEAU_DMA_DEBUG
|
||||
if (dma->push_free) {
|
||||
printf("Packet incomplete: %d left\n", dma->push_free);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef NOUVEAU_DMA_DUMP_POSTRELOC_PUSHBUF
|
||||
nouveau_dma_parse_pushbuf(chan, dma->put, dma->cur);
|
||||
#endif
|
||||
|
||||
WRITE_PUT(nvchan, dma->cur);
|
||||
}
|
||||
154
libdrm/nouveau/nouveau_dma.h
Normal file
154
libdrm/nouveau/nouveau_dma.h
Normal file
|
|
@ -0,0 +1,154 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef __NOUVEAU_DMA_H__
|
||||
#define __NOUVEAU_DMA_H__
|
||||
|
||||
#include <string.h>
|
||||
#include "nouveau_private.h"
|
||||
|
||||
//#define NOUVEAU_DMA_DEBUG
|
||||
//#define NOUVEAU_DMA_TRACE
|
||||
//#define NOUVEAU_DMA_DUMP_POSTRELOC_PUSHBUF
|
||||
#if defined(__amd64__)
|
||||
#define NOUVEAU_DMA_BARRIER asm volatile("lock; addl $0,0(%%rsp)" ::: "memory")
|
||||
#elif defined(__i386__)
|
||||
#define NOUVEAU_DMA_BARRIER asm volatile("lock; addl $0,0(%%esp)" ::: "memory")
|
||||
#else
|
||||
#define NOUVEAU_DMA_BARRIER
|
||||
#endif
|
||||
#define NOUVEAU_DMA_TIMEOUT 2000
|
||||
#define NOUVEAU_TIME_MSEC() 0
|
||||
#define RING_SKIPS 8
|
||||
|
||||
extern int nouveau_dma_wait(struct nouveau_channel *chan, unsigned size);
|
||||
extern void nouveau_dma_subc_bind(struct nouveau_grobj *);
|
||||
extern void nouveau_dma_channel_init(struct nouveau_channel *);
|
||||
extern void nouveau_dma_kickoff(struct nouveau_channel *);
|
||||
|
||||
#ifdef NOUVEAU_DMA_DEBUG
|
||||
static char faulty[1024];
|
||||
#endif
|
||||
|
||||
static inline void
|
||||
nouveau_dma_out(struct nouveau_channel *chan, uint32_t data)
|
||||
{
|
||||
struct nouveau_channel_priv *nvchan = nouveau_channel(chan);
|
||||
struct nouveau_dma_priv *dma = nvchan->dma;
|
||||
|
||||
#ifdef NOUVEAU_DMA_DEBUG
|
||||
if (dma->push_free == 0) {
|
||||
printf("No space left in packet at %s\n", faulty);
|
||||
return;
|
||||
}
|
||||
dma->push_free--;
|
||||
#endif
|
||||
#ifdef NOUVEAU_DMA_TRACE
|
||||
{
|
||||
uint32_t offset = (dma->cur << 2) + dma->base;
|
||||
printf("\tOUT_RING %d/0x%08x -> 0x%08x\n",
|
||||
nvchan->drm.channel, offset, data);
|
||||
}
|
||||
#endif
|
||||
nvchan->pushbuf[dma->cur + (dma->base - nvchan->drm.put_base)/4] = data;
|
||||
dma->cur++;
|
||||
}
|
||||
|
||||
static inline void
|
||||
nouveau_dma_outp(struct nouveau_channel *chan, uint32_t *ptr, int size)
|
||||
{
|
||||
struct nouveau_channel_priv *nvchan = nouveau_channel(chan);
|
||||
struct nouveau_dma_priv *dma = nvchan->dma;
|
||||
(void)dma;
|
||||
|
||||
#ifdef NOUVEAU_DMA_DEBUG
|
||||
if (dma->push_free < size) {
|
||||
printf("Packet too small. Free=%d, Need=%d\n",
|
||||
dma->push_free, size);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#ifdef NOUVEAU_DMA_TRACE
|
||||
while (size--) {
|
||||
nouveau_dma_out(chan, *ptr);
|
||||
ptr++;
|
||||
}
|
||||
#else
|
||||
memcpy(&nvchan->pushbuf[dma->cur], ptr, size << 2);
|
||||
#ifdef NOUVEAU_DMA_DEBUG
|
||||
dma->push_free -= size;
|
||||
#endif
|
||||
dma->cur += size;
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void
|
||||
nouveau_dma_space(struct nouveau_channel *chan, unsigned size)
|
||||
{
|
||||
struct nouveau_channel_priv *nvchan = nouveau_channel(chan);
|
||||
struct nouveau_dma_priv *dma = nvchan->dma;
|
||||
|
||||
if (dma->free < size) {
|
||||
if (nouveau_dma_wait(chan, size) && chan->hang_notify)
|
||||
chan->hang_notify(chan);
|
||||
}
|
||||
dma->free -= size;
|
||||
#ifdef NOUVEAU_DMA_DEBUG
|
||||
dma->push_free = size;
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void
|
||||
nouveau_dma_begin(struct nouveau_channel *chan, struct nouveau_grobj *grobj,
|
||||
int method, int size, const char* file, int line)
|
||||
{
|
||||
struct nouveau_channel_priv *nvchan = nouveau_channel(chan);
|
||||
struct nouveau_dma_priv *dma = nvchan->dma;
|
||||
(void)dma;
|
||||
|
||||
#ifdef NOUVEAU_DMA_TRACE
|
||||
printf("BEGIN_RING %d/%08x/%d/0x%04x/%d\n", nvchan->drm.channel,
|
||||
grobj->handle, grobj->subc, method, size);
|
||||
#endif
|
||||
|
||||
#ifdef NOUVEAU_DMA_DEBUG
|
||||
if (dma->push_free) {
|
||||
printf("Previous packet incomplete: %d left at %s\n",
|
||||
dma->push_free, faulty);
|
||||
return;
|
||||
}
|
||||
sprintf(faulty,"%s:%d",file,line);
|
||||
#endif
|
||||
|
||||
nouveau_dma_space(chan, (size + 1));
|
||||
nouveau_dma_out(chan, (size << 18) | (grobj->subc << 13) | method);
|
||||
}
|
||||
|
||||
#define RING_SPACE_CH(ch,sz) nouveau_dma_space((ch), (sz))
|
||||
#define BEGIN_RING_CH(ch,gr,m,sz) nouveau_dma_begin((ch), (gr), (m), (sz), __FUNCTION__, __LINE__ )
|
||||
#define OUT_RING_CH(ch, data) nouveau_dma_out((ch), (data))
|
||||
#define OUT_RINGp_CH(ch,ptr,dwords) nouveau_dma_outp((ch), (void*)(ptr), \
|
||||
(dwords))
|
||||
#define FIRE_RING_CH(ch) nouveau_dma_kickoff((ch))
|
||||
#define WAIT_RING_CH(ch,sz) nouveau_dma_wait((ch), (sz))
|
||||
|
||||
#endif
|
||||
59
libdrm/nouveau/nouveau_drmif.h
Normal file
59
libdrm/nouveau/nouveau_drmif.h
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright 2008 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.
|
||||
*/
|
||||
|
||||
#ifndef __NOUVEAU_DRMIF_H__
|
||||
#define __NOUVEAU_DRMIF_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <xf86drm.h>
|
||||
|
||||
#include "nouveau_device.h"
|
||||
|
||||
struct nouveau_device_priv {
|
||||
struct nouveau_device base;
|
||||
|
||||
int fd;
|
||||
drm_context_t ctx;
|
||||
drmLock *lock;
|
||||
int needs_close;
|
||||
|
||||
int mm_enabled;
|
||||
};
|
||||
#define nouveau_device(n) ((struct nouveau_device_priv *)(n))
|
||||
|
||||
int
|
||||
nouveau_device_open_existing(struct nouveau_device **, int close,
|
||||
int fd, drm_context_t ctx);
|
||||
|
||||
int
|
||||
nouveau_device_open(struct nouveau_device **, const char *busid);
|
||||
|
||||
void
|
||||
nouveau_device_close(struct nouveau_device **);
|
||||
|
||||
int
|
||||
nouveau_device_get_param(struct nouveau_device *, uint64_t param, uint64_t *v);
|
||||
|
||||
int
|
||||
nouveau_device_set_param(struct nouveau_device *, uint64_t param, uint64_t val);
|
||||
|
||||
#endif
|
||||
249
libdrm/nouveau/nouveau_fence.c
Normal file
249
libdrm/nouveau/nouveau_fence.c
Normal file
|
|
@ -0,0 +1,249 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "nouveau_private.h"
|
||||
#include "nouveau_dma.h"
|
||||
|
||||
static void
|
||||
nouveau_fence_del_unsignalled(struct nouveau_fence *fence)
|
||||
{
|
||||
struct nouveau_channel_priv *nvchan = nouveau_channel(fence->channel);
|
||||
struct nouveau_fence *le;
|
||||
|
||||
if (nvchan->fence_head == fence) {
|
||||
nvchan->fence_head = nouveau_fence(fence)->next;
|
||||
if (nvchan->fence_head == NULL)
|
||||
nvchan->fence_tail = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
le = nvchan->fence_head;
|
||||
while (le && nouveau_fence(le)->next != fence)
|
||||
le = nouveau_fence(le)->next;
|
||||
assert(le && nouveau_fence(le)->next == fence);
|
||||
nouveau_fence(le)->next = nouveau_fence(fence)->next;
|
||||
if (nvchan->fence_tail == fence)
|
||||
nvchan->fence_tail = le;
|
||||
}
|
||||
|
||||
static void
|
||||
nouveau_fence_del(struct nouveau_fence **fence)
|
||||
{
|
||||
struct nouveau_fence_priv *nvfence;
|
||||
|
||||
if (!fence || !*fence)
|
||||
return;
|
||||
nvfence = nouveau_fence(*fence);
|
||||
*fence = NULL;
|
||||
|
||||
if (--nvfence->refcount)
|
||||
return;
|
||||
|
||||
if (nvfence->emitted && !nvfence->signalled) {
|
||||
if (nvfence->signal_cb) {
|
||||
nvfence->refcount++;
|
||||
nouveau_fence_wait((void *)&nvfence);
|
||||
return;
|
||||
}
|
||||
|
||||
nouveau_fence_del_unsignalled(&nvfence->base);
|
||||
}
|
||||
free(nvfence);
|
||||
}
|
||||
|
||||
int
|
||||
nouveau_fence_new(struct nouveau_channel *chan, struct nouveau_fence **fence)
|
||||
{
|
||||
struct nouveau_fence_priv *nvfence;
|
||||
|
||||
if (!chan || !fence || *fence)
|
||||
return -EINVAL;
|
||||
|
||||
nvfence = calloc(1, sizeof(struct nouveau_fence_priv));
|
||||
if (!nvfence)
|
||||
return -ENOMEM;
|
||||
nvfence->base.channel = chan;
|
||||
nvfence->refcount = 1;
|
||||
|
||||
*fence = &nvfence->base;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
nouveau_fence_ref(struct nouveau_fence *ref, struct nouveau_fence **fence)
|
||||
{
|
||||
struct nouveau_fence_priv *nvfence;
|
||||
|
||||
if (!fence)
|
||||
return -EINVAL;
|
||||
|
||||
if (*fence) {
|
||||
nouveau_fence_del(fence);
|
||||
*fence = NULL;
|
||||
}
|
||||
|
||||
if (ref) {
|
||||
nvfence = nouveau_fence(ref);
|
||||
nvfence->refcount++;
|
||||
*fence = &nvfence->base;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
nouveau_fence_signal_cb(struct nouveau_fence *fence, void (*func)(void *),
|
||||
void *priv)
|
||||
{
|
||||
struct nouveau_fence_priv *nvfence = nouveau_fence(fence);
|
||||
struct nouveau_fence_cb *cb;
|
||||
|
||||
if (!nvfence || !func)
|
||||
return -EINVAL;
|
||||
|
||||
cb = malloc(sizeof(struct nouveau_fence_cb));
|
||||
if (!cb)
|
||||
return -ENOMEM;
|
||||
|
||||
cb->func = func;
|
||||
cb->priv = priv;
|
||||
cb->next = nvfence->signal_cb;
|
||||
nvfence->signal_cb = cb;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
nouveau_fence_emit(struct nouveau_fence *fence)
|
||||
{
|
||||
struct nouveau_channel_priv *nvchan = nouveau_channel(fence->channel);
|
||||
struct nouveau_fence_priv *nvfence = nouveau_fence(fence);
|
||||
|
||||
nvfence->emitted = 1;
|
||||
nvfence->sequence = ++nvchan->fence_sequence;
|
||||
if (nvfence->sequence == 0xffffffff)
|
||||
printf("AII wrap unhandled\n");
|
||||
|
||||
if (!nvchan->fence_ntfy) {
|
||||
/*XXX: assumes subc 0 is populated */
|
||||
nouveau_dma_space(fence->channel, 2);
|
||||
nouveau_dma_out (fence->channel, 0x00040050);
|
||||
nouveau_dma_out (fence->channel, nvfence->sequence);
|
||||
}
|
||||
nouveau_dma_kickoff(fence->channel);
|
||||
|
||||
if (nvchan->fence_tail) {
|
||||
nouveau_fence(nvchan->fence_tail)->next = fence;
|
||||
} else {
|
||||
nvchan->fence_head = fence;
|
||||
}
|
||||
nvchan->fence_tail = fence;
|
||||
}
|
||||
|
||||
static void
|
||||
nouveau_fence_flush_seq(struct nouveau_channel *chan, uint32_t sequence)
|
||||
{
|
||||
struct nouveau_channel_priv *nvchan = nouveau_channel(chan);
|
||||
|
||||
while (nvchan->fence_head) {
|
||||
struct nouveau_fence_priv *nvfence;
|
||||
|
||||
nvfence = nouveau_fence(nvchan->fence_head);
|
||||
if (nvfence->sequence > sequence)
|
||||
break;
|
||||
nouveau_fence_del_unsignalled(&nvfence->base);
|
||||
nvfence->signalled = 1;
|
||||
|
||||
if (nvfence->signal_cb) {
|
||||
struct nouveau_fence *fence = NULL;
|
||||
|
||||
nouveau_fence_ref(&nvfence->base, &fence);
|
||||
|
||||
while (nvfence->signal_cb) {
|
||||
struct nouveau_fence_cb *cb;
|
||||
|
||||
cb = nvfence->signal_cb;
|
||||
nvfence->signal_cb = cb->next;
|
||||
cb->func(cb->priv);
|
||||
free(cb);
|
||||
}
|
||||
|
||||
nouveau_fence_ref(NULL, &fence);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nouveau_fence_flush(struct nouveau_channel *chan)
|
||||
{
|
||||
struct nouveau_channel_priv *nvchan = nouveau_channel(chan);
|
||||
|
||||
if (!nvchan->fence_ntfy)
|
||||
nouveau_fence_flush_seq(chan, *nvchan->ref_cnt);
|
||||
}
|
||||
|
||||
int
|
||||
nouveau_fence_wait(struct nouveau_fence **fence)
|
||||
{
|
||||
struct nouveau_fence_priv *nvfence;
|
||||
struct nouveau_channel_priv *nvchan;
|
||||
|
||||
if (!fence)
|
||||
return -EINVAL;
|
||||
|
||||
nvfence = nouveau_fence(*fence);
|
||||
if (!nvfence)
|
||||
return 0;
|
||||
nvchan = nouveau_channel(nvfence->base.channel);
|
||||
|
||||
if (nvfence->emitted) {
|
||||
if (!nvfence->signalled && nvchan->fence_ntfy) {
|
||||
struct nouveau_channel *chan = &nvchan->base;
|
||||
int ret;
|
||||
|
||||
/*XXX: NV04/NV05: Full sync + flush all fences */
|
||||
nouveau_notifier_reset(nvchan->fence_ntfy, 0);
|
||||
BEGIN_RING(chan, nvchan->fence_grobj, 0x0104, 1);
|
||||
OUT_RING (chan, 0);
|
||||
BEGIN_RING(chan, nvchan->fence_grobj, 0x0100, 1);
|
||||
OUT_RING (chan, 0);
|
||||
FIRE_RING (chan);
|
||||
ret = nouveau_notifier_wait_status(nvchan->fence_ntfy,
|
||||
0, 0, 2.0);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
nouveau_fence_flush_seq(chan, nvchan->fence_sequence);
|
||||
}
|
||||
|
||||
while (!nvfence->signalled)
|
||||
nouveau_fence_flush(nvfence->base.channel);
|
||||
}
|
||||
|
||||
nouveau_fence_ref(NULL, fence);
|
||||
return 0;
|
||||
}
|
||||
|
||||
138
libdrm/nouveau/nouveau_grobj.c
Normal file
138
libdrm/nouveau/nouveau_grobj.c
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "nouveau_private.h"
|
||||
|
||||
int
|
||||
nouveau_grobj_alloc(struct nouveau_channel *chan, uint32_t handle,
|
||||
int class, struct nouveau_grobj **grobj)
|
||||
{
|
||||
struct nouveau_device_priv *nvdev = nouveau_device(chan->device);
|
||||
struct nouveau_grobj_priv *nvgrobj;
|
||||
struct drm_nouveau_grobj_alloc g;
|
||||
int ret;
|
||||
|
||||
if (!nvdev || !grobj || *grobj)
|
||||
return -EINVAL;
|
||||
|
||||
nvgrobj = calloc(1, sizeof(*nvgrobj));
|
||||
if (!nvgrobj)
|
||||
return -ENOMEM;
|
||||
nvgrobj->base.channel = chan;
|
||||
nvgrobj->base.handle = handle;
|
||||
nvgrobj->base.grclass = class;
|
||||
nvgrobj->base.bound = NOUVEAU_GROBJ_UNBOUND;
|
||||
nvgrobj->base.subc = -1;
|
||||
|
||||
g.channel = chan->id;
|
||||
g.handle = handle;
|
||||
g.class = class;
|
||||
ret = drmCommandWrite(nvdev->fd, DRM_NOUVEAU_GROBJ_ALLOC,
|
||||
&g, sizeof(g));
|
||||
if (ret) {
|
||||
nouveau_grobj_free((void *)&nvgrobj);
|
||||
return ret;
|
||||
}
|
||||
|
||||
*grobj = &nvgrobj->base;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
nouveau_grobj_ref(struct nouveau_channel *chan, uint32_t handle,
|
||||
struct nouveau_grobj **grobj)
|
||||
{
|
||||
struct nouveau_grobj_priv *nvgrobj;
|
||||
|
||||
if (!chan || !grobj || *grobj)
|
||||
return -EINVAL;
|
||||
|
||||
nvgrobj = calloc(1, sizeof(struct nouveau_grobj_priv));
|
||||
if (!nvgrobj)
|
||||
return -ENOMEM;
|
||||
nvgrobj->base.channel = chan;
|
||||
nvgrobj->base.handle = handle;
|
||||
nvgrobj->base.grclass = 0;
|
||||
|
||||
*grobj = &nvgrobj->base;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
nouveau_grobj_free(struct nouveau_grobj **grobj)
|
||||
{
|
||||
struct nouveau_device_priv *nvdev;
|
||||
struct nouveau_channel_priv *chan;
|
||||
struct nouveau_grobj_priv *nvgrobj;
|
||||
|
||||
if (!grobj || !*grobj)
|
||||
return;
|
||||
nvgrobj = nouveau_grobj(*grobj);
|
||||
*grobj = NULL;
|
||||
|
||||
|
||||
chan = nouveau_channel(nvgrobj->base.channel);
|
||||
nvdev = nouveau_device(chan->base.device);
|
||||
|
||||
if (nvgrobj->base.grclass) {
|
||||
struct drm_nouveau_gpuobj_free f;
|
||||
|
||||
f.channel = chan->drm.channel;
|
||||
f.handle = nvgrobj->base.handle;
|
||||
drmCommandWrite(nvdev->fd, DRM_NOUVEAU_GPUOBJ_FREE,
|
||||
&f, sizeof(f));
|
||||
}
|
||||
free(nvgrobj);
|
||||
}
|
||||
|
||||
void
|
||||
nouveau_grobj_autobind(struct nouveau_grobj *grobj)
|
||||
{
|
||||
struct nouveau_subchannel *subc = NULL;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
struct nouveau_subchannel *scc = &grobj->channel->subc[i];
|
||||
|
||||
if (scc->gr && scc->gr->bound == NOUVEAU_GROBJ_BOUND_EXPLICIT)
|
||||
continue;
|
||||
|
||||
if (!subc || scc->sequence < subc->sequence)
|
||||
subc = scc;
|
||||
}
|
||||
|
||||
if (subc->gr) {
|
||||
subc->gr->bound = NOUVEAU_GROBJ_UNBOUND;
|
||||
subc->gr->subc = -1;
|
||||
}
|
||||
|
||||
subc->gr = grobj;
|
||||
subc->gr->bound = NOUVEAU_GROBJ_BOUND;
|
||||
subc->gr->subc = subc - &grobj->channel->subc[0];
|
||||
|
||||
BEGIN_RING(grobj->channel, grobj, 0x0000, 1);
|
||||
OUT_RING (grobj->channel, grobj->handle);
|
||||
}
|
||||
|
||||
48
libdrm/nouveau/nouveau_grobj.h
Normal file
48
libdrm/nouveau/nouveau_grobj.h
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef __NOUVEAU_GROBJ_H__
|
||||
#define __NOUVEAU_GROBJ_H__
|
||||
|
||||
#include "nouveau_channel.h"
|
||||
|
||||
struct nouveau_grobj {
|
||||
struct nouveau_channel *channel;
|
||||
int grclass;
|
||||
uint32_t handle;
|
||||
|
||||
enum {
|
||||
NOUVEAU_GROBJ_UNBOUND = 0,
|
||||
NOUVEAU_GROBJ_BOUND = 1,
|
||||
NOUVEAU_GROBJ_BOUND_EXPLICIT = 2
|
||||
} bound;
|
||||
int subc;
|
||||
};
|
||||
|
||||
int nouveau_grobj_alloc(struct nouveau_channel *, uint32_t handle,
|
||||
int class, struct nouveau_grobj **);
|
||||
int nouveau_grobj_ref(struct nouveau_channel *, uint32_t handle,
|
||||
struct nouveau_grobj **);
|
||||
void nouveau_grobj_free(struct nouveau_grobj **);
|
||||
void nouveau_grobj_autobind(struct nouveau_grobj *);
|
||||
|
||||
#endif
|
||||
146
libdrm/nouveau/nouveau_notifier.c
Normal file
146
libdrm/nouveau/nouveau_notifier.c
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "nouveau_private.h"
|
||||
|
||||
#define NOTIFIER(__v) \
|
||||
struct nouveau_notifier_priv *nvnotify = nouveau_notifier(notifier); \
|
||||
volatile uint32_t *__v = (uint32_t *)((char *)nvnotify->map + (id * 32))
|
||||
|
||||
int
|
||||
nouveau_notifier_alloc(struct nouveau_channel *chan, uint32_t handle,
|
||||
int count, struct nouveau_notifier **notifier)
|
||||
{
|
||||
struct nouveau_notifier_priv *nvnotify;
|
||||
int ret;
|
||||
|
||||
if (!chan || !notifier || *notifier)
|
||||
return -EINVAL;
|
||||
|
||||
nvnotify = calloc(1, sizeof(struct nouveau_notifier_priv));
|
||||
if (!nvnotify)
|
||||
return -ENOMEM;
|
||||
nvnotify->base.channel = chan;
|
||||
nvnotify->base.handle = handle;
|
||||
|
||||
nvnotify->drm.channel = chan->id;
|
||||
nvnotify->drm.handle = handle;
|
||||
nvnotify->drm.count = count;
|
||||
if ((ret = drmCommandWriteRead(nouveau_device(chan->device)->fd,
|
||||
DRM_NOUVEAU_NOTIFIEROBJ_ALLOC,
|
||||
&nvnotify->drm,
|
||||
sizeof(nvnotify->drm)))) {
|
||||
nouveau_notifier_free((void *)&nvnotify);
|
||||
return ret;
|
||||
}
|
||||
|
||||
nvnotify->map = (char *)nouveau_channel(chan)->notifier_block +
|
||||
nvnotify->drm.offset;
|
||||
*notifier = &nvnotify->base;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
nouveau_notifier_free(struct nouveau_notifier **notifier)
|
||||
{
|
||||
|
||||
struct nouveau_notifier_priv *nvnotify;
|
||||
struct nouveau_channel_priv *nvchan;
|
||||
struct nouveau_device_priv *nvdev;
|
||||
struct drm_nouveau_gpuobj_free f;
|
||||
|
||||
if (!notifier || !*notifier)
|
||||
return;
|
||||
nvnotify = nouveau_notifier(*notifier);
|
||||
*notifier = NULL;
|
||||
|
||||
nvchan = nouveau_channel(nvnotify->base.channel);
|
||||
nvdev = nouveau_device(nvchan->base.device);
|
||||
|
||||
f.channel = nvchan->drm.channel;
|
||||
f.handle = nvnotify->base.handle;
|
||||
drmCommandWrite(nvdev->fd, DRM_NOUVEAU_GPUOBJ_FREE, &f, sizeof(f));
|
||||
free(nvnotify);
|
||||
}
|
||||
|
||||
void
|
||||
nouveau_notifier_reset(struct nouveau_notifier *notifier, int id)
|
||||
{
|
||||
NOTIFIER(n);
|
||||
|
||||
n[NV_NOTIFY_TIME_0 /4] = 0x00000000;
|
||||
n[NV_NOTIFY_TIME_1 /4] = 0x00000000;
|
||||
n[NV_NOTIFY_RETURN_VALUE/4] = 0x00000000;
|
||||
n[NV_NOTIFY_STATE /4] = (NV_NOTIFY_STATE_STATUS_IN_PROCESS <<
|
||||
NV_NOTIFY_STATE_STATUS_SHIFT);
|
||||
}
|
||||
|
||||
uint32_t
|
||||
nouveau_notifier_status(struct nouveau_notifier *notifier, int id)
|
||||
{
|
||||
NOTIFIER(n);
|
||||
|
||||
return n[NV_NOTIFY_STATE/4] >> NV_NOTIFY_STATE_STATUS_SHIFT;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
nouveau_notifier_return_val(struct nouveau_notifier *notifier, int id)
|
||||
{
|
||||
NOTIFIER(n);
|
||||
|
||||
return n[NV_NOTIFY_RETURN_VALUE/4];
|
||||
}
|
||||
|
||||
static inline double
|
||||
gettime(void)
|
||||
{
|
||||
struct timeval tv;
|
||||
|
||||
gettimeofday(&tv, NULL);
|
||||
return (double)tv.tv_sec + tv.tv_usec / 1000000.0;
|
||||
}
|
||||
|
||||
int
|
||||
nouveau_notifier_wait_status(struct nouveau_notifier *notifier, int id,
|
||||
uint32_t status, double timeout)
|
||||
{
|
||||
NOTIFIER(n);
|
||||
double time = 0, t_start = gettime();
|
||||
|
||||
while (time <= timeout) {
|
||||
uint32_t v;
|
||||
|
||||
v = n[NV_NOTIFY_STATE/4] >> NV_NOTIFY_STATE_STATUS_SHIFT;
|
||||
if (v == status)
|
||||
return 0;
|
||||
|
||||
if (timeout)
|
||||
time = gettime() - t_start;
|
||||
}
|
||||
|
||||
return -EBUSY;
|
||||
}
|
||||
|
||||
63
libdrm/nouveau/nouveau_notifier.h
Normal file
63
libdrm/nouveau/nouveau_notifier.h
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef __NOUVEAU_NOTIFIER_H__
|
||||
#define __NOUVEAU_NOTIFIER_H__
|
||||
|
||||
#define NV_NOTIFIER_SIZE 32
|
||||
#define NV_NOTIFY_TIME_0 0x00000000
|
||||
#define NV_NOTIFY_TIME_1 0x00000004
|
||||
#define NV_NOTIFY_RETURN_VALUE 0x00000008
|
||||
#define NV_NOTIFY_STATE 0x0000000C
|
||||
#define NV_NOTIFY_STATE_STATUS_MASK 0xFF000000
|
||||
#define NV_NOTIFY_STATE_STATUS_SHIFT 24
|
||||
#define NV_NOTIFY_STATE_STATUS_COMPLETED 0x00
|
||||
#define NV_NOTIFY_STATE_STATUS_IN_PROCESS 0x01
|
||||
#define NV_NOTIFY_STATE_ERROR_CODE_MASK 0x0000FFFF
|
||||
#define NV_NOTIFY_STATE_ERROR_CODE_SHIFT 0
|
||||
|
||||
struct nouveau_notifier {
|
||||
struct nouveau_channel *channel;
|
||||
uint32_t handle;
|
||||
};
|
||||
|
||||
int
|
||||
nouveau_notifier_alloc(struct nouveau_channel *, uint32_t handle, int count,
|
||||
struct nouveau_notifier **);
|
||||
|
||||
void
|
||||
nouveau_notifier_free(struct nouveau_notifier **);
|
||||
|
||||
void
|
||||
nouveau_notifier_reset(struct nouveau_notifier *, int id);
|
||||
|
||||
uint32_t
|
||||
nouveau_notifier_status(struct nouveau_notifier *, int id);
|
||||
|
||||
uint32_t
|
||||
nouveau_notifier_return_val(struct nouveau_notifier *, int id);
|
||||
|
||||
int
|
||||
nouveau_notifier_wait_status(struct nouveau_notifier *, int id, uint32_t status,
|
||||
double timeout);
|
||||
|
||||
#endif
|
||||
203
libdrm/nouveau/nouveau_private.h
Normal file
203
libdrm/nouveau/nouveau_private.h
Normal file
|
|
@ -0,0 +1,203 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef __NOUVEAU_PRIVATE_H__
|
||||
#define __NOUVEAU_PRIVATE_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <xf86drm.h>
|
||||
#include <nouveau_drm.h>
|
||||
|
||||
#include "nouveau_drmif.h"
|
||||
#include "nouveau_device.h"
|
||||
#include "nouveau_channel.h"
|
||||
#include "nouveau_grobj.h"
|
||||
#include "nouveau_notifier.h"
|
||||
#include "nouveau_bo.h"
|
||||
#include "nouveau_resource.h"
|
||||
#include "nouveau_pushbuf.h"
|
||||
|
||||
#define NOUVEAU_PUSHBUF_MAX_BUFFERS 1024
|
||||
#define NOUVEAU_PUSHBUF_MAX_RELOCS 1024
|
||||
struct nouveau_pushbuf_priv {
|
||||
struct nouveau_pushbuf base;
|
||||
|
||||
int use_cal;
|
||||
struct nouveau_bo *buffer;
|
||||
|
||||
unsigned *pushbuf;
|
||||
unsigned size;
|
||||
|
||||
struct drm_nouveau_gem_pushbuf_bo *buffers;
|
||||
unsigned nr_buffers;
|
||||
struct drm_nouveau_gem_pushbuf_reloc *relocs;
|
||||
unsigned nr_relocs;
|
||||
|
||||
/*XXX: nomm */
|
||||
struct nouveau_fence *fence;
|
||||
};
|
||||
#define nouveau_pushbuf(n) ((struct nouveau_pushbuf_priv *)(n))
|
||||
|
||||
#define pbbo_to_ptr(o) ((uint64_t)(unsigned long)(o))
|
||||
#define ptr_to_pbbo(h) ((struct nouveau_pushbuf_bo *)(unsigned long)(h))
|
||||
#define pbrel_to_ptr(o) ((uint64_t)(unsigned long)(o))
|
||||
#define ptr_to_pbrel(h) ((struct nouveau_pushbuf_reloc *)(unsigned long)(h))
|
||||
#define bo_to_ptr(o) ((uint64_t)(unsigned long)(o))
|
||||
#define ptr_to_bo(h) ((struct nouveau_bo_priv *)(unsigned long)(h))
|
||||
|
||||
int
|
||||
nouveau_pushbuf_init(struct nouveau_channel *);
|
||||
|
||||
struct nouveau_dma_priv {
|
||||
uint32_t base;
|
||||
uint32_t max;
|
||||
uint32_t cur;
|
||||
uint32_t put;
|
||||
uint32_t free;
|
||||
|
||||
int push_free;
|
||||
} dma;
|
||||
|
||||
struct nouveau_channel_priv {
|
||||
struct nouveau_channel base;
|
||||
|
||||
struct drm_nouveau_channel_alloc drm;
|
||||
|
||||
void *notifier_block;
|
||||
|
||||
struct nouveau_pushbuf_priv pb;
|
||||
|
||||
/*XXX: nomm */
|
||||
volatile uint32_t *user, *put, *get, *ref_cnt;
|
||||
uint32_t *pushbuf;
|
||||
struct nouveau_dma_priv struct_dma;
|
||||
struct nouveau_dma_priv *dma;
|
||||
struct nouveau_fence *fence_head;
|
||||
struct nouveau_fence *fence_tail;
|
||||
uint32_t fence_sequence;
|
||||
struct nouveau_grobj *fence_grobj;
|
||||
struct nouveau_notifier *fence_ntfy;
|
||||
};
|
||||
#define nouveau_channel(n) ((struct nouveau_channel_priv *)(n))
|
||||
|
||||
struct nouveau_fence {
|
||||
struct nouveau_channel *channel;
|
||||
};
|
||||
|
||||
struct nouveau_fence_cb {
|
||||
struct nouveau_fence_cb *next;
|
||||
void (*func)(void *);
|
||||
void *priv;
|
||||
};
|
||||
|
||||
struct nouveau_fence_priv {
|
||||
struct nouveau_fence base;
|
||||
int refcount;
|
||||
|
||||
struct nouveau_fence *next;
|
||||
struct nouveau_fence_cb *signal_cb;
|
||||
|
||||
uint32_t sequence;
|
||||
int emitted;
|
||||
int signalled;
|
||||
};
|
||||
#define nouveau_fence(n) ((struct nouveau_fence_priv *)(n))
|
||||
|
||||
int
|
||||
nouveau_fence_new(struct nouveau_channel *, struct nouveau_fence **);
|
||||
|
||||
int
|
||||
nouveau_fence_ref(struct nouveau_fence *, struct nouveau_fence **);
|
||||
|
||||
int
|
||||
nouveau_fence_signal_cb(struct nouveau_fence *, void (*)(void *), void *);
|
||||
|
||||
void
|
||||
nouveau_fence_emit(struct nouveau_fence *);
|
||||
|
||||
int
|
||||
nouveau_fence_wait(struct nouveau_fence **);
|
||||
|
||||
void
|
||||
nouveau_fence_flush(struct nouveau_channel *);
|
||||
|
||||
struct nouveau_grobj_priv {
|
||||
struct nouveau_grobj base;
|
||||
};
|
||||
#define nouveau_grobj(n) ((struct nouveau_grobj_priv *)(n))
|
||||
|
||||
struct nouveau_notifier_priv {
|
||||
struct nouveau_notifier base;
|
||||
|
||||
struct drm_nouveau_notifierobj_alloc drm;
|
||||
volatile void *map;
|
||||
};
|
||||
#define nouveau_notifier(n) ((struct nouveau_notifier_priv *)(n))
|
||||
|
||||
struct nouveau_bo_priv {
|
||||
struct nouveau_bo base;
|
||||
int refcount;
|
||||
|
||||
/* Buffer configuration + usage hints */
|
||||
unsigned flags;
|
||||
unsigned size;
|
||||
unsigned align;
|
||||
int user;
|
||||
|
||||
/* Tracking */
|
||||
struct drm_nouveau_gem_pushbuf_bo *pending;
|
||||
struct nouveau_channel *pending_channel;
|
||||
int write_marker;
|
||||
|
||||
/* Userspace object */
|
||||
void *sysmem;
|
||||
|
||||
/* Kernel object */
|
||||
uint32_t global_handle;
|
||||
unsigned handle;
|
||||
void *map;
|
||||
|
||||
/* Last known information from kernel on buffer status */
|
||||
int pinned;
|
||||
uint64_t offset;
|
||||
uint32_t domain;
|
||||
|
||||
/*XXX: nomm stuff */
|
||||
struct nouveau_fence *fence;
|
||||
struct nouveau_fence *wr_fence;
|
||||
};
|
||||
#define nouveau_bo(n) ((struct nouveau_bo_priv *)(n))
|
||||
|
||||
int
|
||||
nouveau_bo_init(struct nouveau_device *);
|
||||
|
||||
void
|
||||
nouveau_bo_takedown(struct nouveau_device *);
|
||||
|
||||
struct drm_nouveau_gem_pushbuf_bo *
|
||||
nouveau_bo_emit_buffer(struct nouveau_channel *, struct nouveau_bo *);
|
||||
|
||||
int
|
||||
nouveau_bo_validate_nomm(struct nouveau_bo_priv *, uint32_t);
|
||||
|
||||
#include "nouveau_dma.h"
|
||||
#endif
|
||||
276
libdrm/nouveau/nouveau_pushbuf.c
Normal file
276
libdrm/nouveau/nouveau_pushbuf.c
Normal file
|
|
@ -0,0 +1,276 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "nouveau_private.h"
|
||||
#include "nouveau_dma.h"
|
||||
|
||||
#define PB_BUFMGR_DWORDS (4096 / 2)
|
||||
#define PB_MIN_USER_DWORDS 2048
|
||||
|
||||
static uint32_t
|
||||
nouveau_pushbuf_calc_reloc(struct drm_nouveau_gem_pushbuf_bo *pbbo,
|
||||
struct drm_nouveau_gem_pushbuf_reloc *r,
|
||||
int mm_enabled)
|
||||
{
|
||||
uint32_t push = 0;
|
||||
const unsigned is_vram = mm_enabled ? NOUVEAU_GEM_DOMAIN_VRAM :
|
||||
NOUVEAU_BO_VRAM;
|
||||
|
||||
if (r->flags & NOUVEAU_GEM_RELOC_LOW)
|
||||
push = (pbbo->presumed_offset + r->data);
|
||||
else
|
||||
if (r->flags & NOUVEAU_GEM_RELOC_HIGH)
|
||||
push = (pbbo->presumed_offset + r->data) >> 32;
|
||||
else
|
||||
push = r->data;
|
||||
|
||||
if (r->flags & NOUVEAU_GEM_RELOC_OR) {
|
||||
if (pbbo->presumed_domain & is_vram)
|
||||
push |= r->vor;
|
||||
else
|
||||
push |= r->tor;
|
||||
}
|
||||
|
||||
return push;
|
||||
}
|
||||
|
||||
int
|
||||
nouveau_pushbuf_emit_reloc(struct nouveau_channel *chan, void *ptr,
|
||||
struct nouveau_bo *bo, uint32_t data, uint32_t flags,
|
||||
uint32_t vor, uint32_t tor)
|
||||
{
|
||||
struct nouveau_device_priv *nvdev = nouveau_device(chan->device);
|
||||
struct nouveau_pushbuf_priv *nvpb = nouveau_pushbuf(chan->pushbuf);
|
||||
struct drm_nouveau_gem_pushbuf_reloc *r;
|
||||
struct drm_nouveau_gem_pushbuf_bo *pbbo;
|
||||
uint32_t domains = 0;
|
||||
|
||||
if (nvpb->nr_relocs >= NOUVEAU_PUSHBUF_MAX_RELOCS)
|
||||
return -ENOMEM;
|
||||
|
||||
if (nouveau_bo(bo)->user && (flags & NOUVEAU_BO_WR)) {
|
||||
fprintf(stderr, "write to user buffer!!\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
pbbo = nouveau_bo_emit_buffer(chan, bo);
|
||||
if (!pbbo)
|
||||
return -ENOMEM;
|
||||
|
||||
if (flags & NOUVEAU_BO_VRAM)
|
||||
domains |= NOUVEAU_GEM_DOMAIN_VRAM;
|
||||
if (flags & NOUVEAU_BO_GART)
|
||||
domains |= NOUVEAU_GEM_DOMAIN_GART;
|
||||
pbbo->valid_domains &= domains;
|
||||
assert(pbbo->valid_domains);
|
||||
|
||||
if (!nvdev->mm_enabled) {
|
||||
struct nouveau_bo_priv *nvbo = nouveau_bo(bo);
|
||||
|
||||
nouveau_fence_ref(nvpb->fence, &nvbo->fence);
|
||||
if (flags & NOUVEAU_BO_WR)
|
||||
nouveau_fence_ref(nvpb->fence, &nvbo->wr_fence);
|
||||
}
|
||||
|
||||
assert(flags & NOUVEAU_BO_RDWR);
|
||||
if (flags & NOUVEAU_BO_RD) {
|
||||
pbbo->read_domains |= domains;
|
||||
}
|
||||
if (flags & NOUVEAU_BO_WR) {
|
||||
pbbo->write_domains |= domains;
|
||||
nouveau_bo(bo)->write_marker = 1;
|
||||
}
|
||||
|
||||
r = nvpb->relocs + nvpb->nr_relocs++;
|
||||
r->bo_index = pbbo - nvpb->buffers;
|
||||
r->reloc_index = (uint32_t *)ptr - nvpb->pushbuf;
|
||||
r->flags = 0;
|
||||
if (flags & NOUVEAU_BO_LOW)
|
||||
r->flags |= NOUVEAU_GEM_RELOC_LOW;
|
||||
if (flags & NOUVEAU_BO_HIGH)
|
||||
r->flags |= NOUVEAU_GEM_RELOC_HIGH;
|
||||
if (flags & NOUVEAU_BO_OR)
|
||||
r->flags |= NOUVEAU_GEM_RELOC_OR;
|
||||
r->data = data;
|
||||
r->vor = vor;
|
||||
r->tor = tor;
|
||||
|
||||
*(uint32_t *)ptr = (flags & NOUVEAU_BO_DUMMY) ? 0 :
|
||||
nouveau_pushbuf_calc_reloc(pbbo, r, nvdev->mm_enabled);
|
||||
return 0;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if (nvpb->pushbuf) {
|
||||
free(nvpb->pushbuf);
|
||||
nvpb->pushbuf = NULL;
|
||||
}
|
||||
|
||||
nvpb->size = min < PB_MIN_USER_DWORDS ? PB_MIN_USER_DWORDS : min;
|
||||
nvpb->pushbuf = malloc(sizeof(uint32_t) * nvpb->size);
|
||||
|
||||
nvpb->base.channel = chan;
|
||||
nvpb->base.remaining = nvpb->size;
|
||||
nvpb->base.cur = nvpb->pushbuf;
|
||||
|
||||
if (!nouveau_device(chan->device)->mm_enabled) {
|
||||
nouveau_fence_ref(NULL, &nvpb->fence);
|
||||
nouveau_fence_new(chan, &nvpb->fence);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
nouveau_pushbuf_init(struct nouveau_channel *chan)
|
||||
{
|
||||
struct nouveau_channel_priv *nvchan = nouveau_channel(chan);
|
||||
struct nouveau_pushbuf_priv *nvpb = &nvchan->pb;
|
||||
|
||||
nouveau_pushbuf_space(chan, 0);
|
||||
|
||||
nvpb->buffers = calloc(NOUVEAU_PUSHBUF_MAX_BUFFERS,
|
||||
sizeof(struct drm_nouveau_gem_pushbuf_bo));
|
||||
nvpb->relocs = calloc(NOUVEAU_PUSHBUF_MAX_RELOCS,
|
||||
sizeof(struct drm_nouveau_gem_pushbuf_reloc));
|
||||
|
||||
chan->pushbuf = &nvpb->base;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
nouveau_pushbuf_flush_nomm(struct nouveau_channel_priv *nvchan)
|
||||
{
|
||||
struct nouveau_pushbuf_priv *nvpb = &nvchan->pb;
|
||||
struct drm_nouveau_gem_pushbuf_bo *bo = nvpb->buffers;
|
||||
struct drm_nouveau_gem_pushbuf_reloc *reloc = nvpb->relocs;
|
||||
unsigned b, r;
|
||||
int ret;
|
||||
|
||||
for (b = 0; b < nvpb->nr_buffers; b++) {
|
||||
struct nouveau_bo_priv *nvbo =
|
||||
(void *)(unsigned long)bo[b].user_priv;
|
||||
uint32_t flags = 0;
|
||||
|
||||
if (bo[b].valid_domains & NOUVEAU_GEM_DOMAIN_VRAM)
|
||||
flags |= NOUVEAU_BO_VRAM;
|
||||
if (bo[b].valid_domains & NOUVEAU_GEM_DOMAIN_GART)
|
||||
flags |= NOUVEAU_BO_GART;
|
||||
|
||||
ret = nouveau_bo_validate_nomm(nvbo, flags);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
if (1 || bo[b].presumed_domain != nvbo->domain ||
|
||||
bo[b].presumed_offset != nvbo->offset) {
|
||||
bo[b].presumed_ok = 0;
|
||||
bo[b].presumed_domain = nvbo->domain;
|
||||
bo[b].presumed_offset = nvbo->offset;
|
||||
}
|
||||
}
|
||||
|
||||
for (r = 0; r < nvpb->nr_relocs; r++, reloc++) {
|
||||
uint32_t push;
|
||||
|
||||
if (bo[reloc->bo_index].presumed_ok)
|
||||
continue;
|
||||
|
||||
push = nouveau_pushbuf_calc_reloc(&bo[reloc->bo_index], reloc, 0);
|
||||
nvpb->pushbuf[reloc->reloc_index] = push;
|
||||
}
|
||||
|
||||
nouveau_dma_space(&nvchan->base, nvpb->size);
|
||||
nouveau_dma_outp (&nvchan->base, nvpb->pushbuf, nvpb->size);
|
||||
nouveau_fence_emit(nvpb->fence);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
nouveau_pushbuf_flush(struct nouveau_channel *chan, unsigned min)
|
||||
{
|
||||
struct nouveau_device_priv *nvdev = nouveau_device(chan->device);
|
||||
struct nouveau_channel_priv *nvchan = nouveau_channel(chan);
|
||||
struct nouveau_pushbuf_priv *nvpb = &nvchan->pb;
|
||||
struct drm_nouveau_gem_pushbuf req;
|
||||
unsigned i;
|
||||
int ret;
|
||||
|
||||
if (nvpb->base.remaining == nvpb->size)
|
||||
return 0;
|
||||
nvpb->size -= nvpb->base.remaining;
|
||||
|
||||
if (nvdev->mm_enabled) {
|
||||
req.channel = chan->id;
|
||||
req.nr_dwords = nvpb->size;
|
||||
req.dwords = (uint64_t)(unsigned long)nvpb->pushbuf;
|
||||
req.nr_buffers = nvpb->nr_buffers;
|
||||
req.buffers = (uint64_t)(unsigned long)nvpb->buffers;
|
||||
req.nr_relocs = nvpb->nr_relocs;
|
||||
req.relocs = (uint64_t)(unsigned long)nvpb->relocs;
|
||||
ret = drmCommandWrite(nvdev->fd, DRM_NOUVEAU_GEM_PUSHBUF,
|
||||
&req, sizeof(req));
|
||||
} else {
|
||||
nouveau_fence_flush(chan);
|
||||
ret = nouveau_pushbuf_flush_nomm(nvchan);
|
||||
}
|
||||
assert(ret == 0);
|
||||
|
||||
|
||||
/* Update presumed offset/domain for any buffers that moved.
|
||||
* Dereference all buffers on validate list
|
||||
*/
|
||||
for (i = 0; i < nvpb->nr_buffers; i++) {
|
||||
struct drm_nouveau_gem_pushbuf_bo *pbbo = &nvpb->buffers[i];
|
||||
struct nouveau_bo *bo = (void *)(unsigned long)pbbo->user_priv;
|
||||
|
||||
if (pbbo->presumed_ok == 0) {
|
||||
nouveau_bo(bo)->domain = pbbo->presumed_domain;
|
||||
nouveau_bo(bo)->offset = pbbo->presumed_offset;
|
||||
}
|
||||
|
||||
nouveau_bo(bo)->pending = NULL;
|
||||
nouveau_bo_ref(NULL, &bo);
|
||||
}
|
||||
nvpb->nr_buffers = 0;
|
||||
nvpb->nr_relocs = 0;
|
||||
|
||||
/* Allocate space for next push buffer */
|
||||
ret = nouveau_pushbuf_space(chan, min);
|
||||
assert(!ret);
|
||||
|
||||
if (chan->flush_notify)
|
||||
chan->flush_notify(chan);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
160
libdrm/nouveau/nouveau_pushbuf.h
Normal file
160
libdrm/nouveau/nouveau_pushbuf.h
Normal file
|
|
@ -0,0 +1,160 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef __NOUVEAU_PUSHBUF_H__
|
||||
#define __NOUVEAU_PUSHBUF_H__
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "nouveau_bo.h"
|
||||
#include "nouveau_grobj.h"
|
||||
|
||||
struct nouveau_pushbuf {
|
||||
struct nouveau_channel *channel;
|
||||
|
||||
unsigned remaining;
|
||||
uint32_t *cur;
|
||||
};
|
||||
|
||||
int
|
||||
nouveau_pushbuf_flush(struct nouveau_channel *, unsigned min);
|
||||
|
||||
int
|
||||
nouveau_pushbuf_emit_reloc(struct nouveau_channel *, void *ptr,
|
||||
struct nouveau_bo *, uint32_t data, uint32_t flags,
|
||||
uint32_t vor, uint32_t tor);
|
||||
|
||||
/* Push buffer access macros */
|
||||
static __inline__ void
|
||||
OUT_RING(struct nouveau_channel *chan, unsigned data)
|
||||
{
|
||||
*(chan->pushbuf->cur++) = (data);
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
OUT_RINGp(struct nouveau_channel *chan, const void *data, unsigned size)
|
||||
{
|
||||
memcpy(chan->pushbuf->cur, data, size * 4);
|
||||
chan->pushbuf->cur += size;
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
OUT_RINGf(struct nouveau_channel *chan, float f)
|
||||
{
|
||||
union { uint32_t i; float f; } c;
|
||||
c.f = f;
|
||||
OUT_RING(chan, c.i);
|
||||
}
|
||||
|
||||
static __inline__ unsigned
|
||||
AVAIL_RING(struct nouveau_channel *chan)
|
||||
{
|
||||
return chan->pushbuf->remaining;
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
WAIT_RING(struct nouveau_channel *chan, unsigned size)
|
||||
{
|
||||
if (chan->pushbuf->remaining < size)
|
||||
nouveau_pushbuf_flush(chan, size);
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
BEGIN_RING(struct nouveau_channel *chan, struct nouveau_grobj *gr,
|
||||
unsigned mthd, unsigned size)
|
||||
{
|
||||
if (gr->bound == NOUVEAU_GROBJ_UNBOUND)
|
||||
nouveau_grobj_autobind(gr);
|
||||
chan->subc[gr->subc].sequence = chan->subc_sequence++;
|
||||
|
||||
WAIT_RING(chan, size + 1);
|
||||
OUT_RING(chan, (gr->subc << 13) | (size << 18) | mthd);
|
||||
chan->pushbuf->remaining -= (size + 1);
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
FIRE_RING(struct nouveau_channel *chan)
|
||||
{
|
||||
nouveau_pushbuf_flush(chan, 0);
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
BIND_RING(struct nouveau_channel *chan, struct nouveau_grobj *gr, unsigned sc)
|
||||
{
|
||||
struct nouveau_subchannel *subc = &gr->channel->subc[sc];
|
||||
|
||||
if (subc->gr) {
|
||||
if (subc->gr->bound == NOUVEAU_GROBJ_BOUND_EXPLICIT)
|
||||
assert(0);
|
||||
subc->gr->bound = NOUVEAU_GROBJ_UNBOUND;
|
||||
}
|
||||
subc->gr = gr;
|
||||
subc->gr->subc = sc;
|
||||
subc->gr->bound = NOUVEAU_GROBJ_BOUND_EXPLICIT;
|
||||
|
||||
BEGIN_RING(chan, gr, 0x0000, 1);
|
||||
OUT_RING (chan, gr->handle);
|
||||
}
|
||||
|
||||
static __inline__ void
|
||||
OUT_RELOC(struct nouveau_channel *chan, struct nouveau_bo *bo,
|
||||
unsigned data, unsigned flags, unsigned vor, unsigned tor)
|
||||
{
|
||||
nouveau_pushbuf_emit_reloc(chan, chan->pushbuf->cur++, bo,
|
||||
data, flags, vor, tor);
|
||||
}
|
||||
|
||||
/* Raw data + flags depending on FB/TT buffer */
|
||||
static __inline__ void
|
||||
OUT_RELOCd(struct nouveau_channel *chan, struct nouveau_bo *bo,
|
||||
unsigned data, unsigned flags, unsigned vor, unsigned tor)
|
||||
{
|
||||
OUT_RELOC(chan, bo, data, flags | NOUVEAU_BO_OR, vor, tor);
|
||||
}
|
||||
|
||||
/* FB/TT object handle */
|
||||
static __inline__ void
|
||||
OUT_RELOCo(struct nouveau_channel *chan, struct nouveau_bo *bo,
|
||||
unsigned flags)
|
||||
{
|
||||
OUT_RELOC(chan, bo, 0, flags | NOUVEAU_BO_OR,
|
||||
chan->vram->handle, chan->gart->handle);
|
||||
}
|
||||
|
||||
/* Low 32-bits of offset */
|
||||
static __inline__ void
|
||||
OUT_RELOCl(struct nouveau_channel *chan, struct nouveau_bo *bo,
|
||||
unsigned delta, unsigned flags)
|
||||
{
|
||||
OUT_RELOC(chan, bo, delta, flags | NOUVEAU_BO_LOW, 0, 0);
|
||||
}
|
||||
|
||||
/* High 32-bits of offset */
|
||||
static __inline__ void
|
||||
OUT_RELOCh(struct nouveau_channel *chan, struct nouveau_bo *bo,
|
||||
unsigned delta, unsigned flags)
|
||||
{
|
||||
OUT_RELOC(chan, bo, delta, flags | NOUVEAU_BO_HIGH, 0, 0);
|
||||
}
|
||||
|
||||
#endif
|
||||
115
libdrm/nouveau/nouveau_resource.c
Normal file
115
libdrm/nouveau/nouveau_resource.c
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "nouveau_private.h"
|
||||
|
||||
int
|
||||
nouveau_resource_init(struct nouveau_resource **heap,
|
||||
unsigned start, unsigned size)
|
||||
{
|
||||
struct nouveau_resource *r;
|
||||
|
||||
r = calloc(1, sizeof(struct nouveau_resource));
|
||||
if (!r)
|
||||
return 1;
|
||||
|
||||
r->start = start;
|
||||
r->size = size;
|
||||
*heap = r;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
nouveau_resource_alloc(struct nouveau_resource *heap, unsigned size, void *priv,
|
||||
struct nouveau_resource **res)
|
||||
{
|
||||
struct nouveau_resource *r;
|
||||
|
||||
if (!heap || !size || !res || *res)
|
||||
return 1;
|
||||
|
||||
while (heap) {
|
||||
if (!heap->in_use && heap->size >= size) {
|
||||
r = calloc(1, sizeof(struct nouveau_resource));
|
||||
if (!r)
|
||||
return 1;
|
||||
|
||||
r->start = (heap->start + heap->size) - size;
|
||||
r->size = size;
|
||||
r->in_use = 1;
|
||||
r->priv = priv;
|
||||
|
||||
heap->size -= size;
|
||||
|
||||
r->next = heap->next;
|
||||
if (heap->next)
|
||||
heap->next->prev = r;
|
||||
r->prev = heap;
|
||||
heap->next = r;
|
||||
|
||||
*res = r;
|
||||
return 0;
|
||||
}
|
||||
|
||||
heap = heap->next;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
nouveau_resource_free(struct nouveau_resource **res)
|
||||
{
|
||||
struct nouveau_resource *r;
|
||||
|
||||
if (!res || !*res)
|
||||
return;
|
||||
r = *res;
|
||||
*res = NULL;
|
||||
|
||||
r->in_use = 0;
|
||||
|
||||
if (r->next && !r->next->in_use) {
|
||||
struct nouveau_resource *new = r->next;
|
||||
|
||||
new->prev = r->prev;
|
||||
if (r->prev)
|
||||
r->prev->next = new;
|
||||
new->size += r->size;
|
||||
new->start = r->start;
|
||||
|
||||
free(r);
|
||||
r = new;
|
||||
}
|
||||
|
||||
if (r->prev && !r->prev->in_use) {
|
||||
r->prev->next = r->next;
|
||||
if (r->next)
|
||||
r->next->prev = r->prev;
|
||||
r->prev->size += r->size;
|
||||
free(r);
|
||||
}
|
||||
|
||||
}
|
||||
48
libdrm/nouveau/nouveau_resource.h
Normal file
48
libdrm/nouveau/nouveau_resource.h
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef __NOUVEAU_RESOURCE_H__
|
||||
#define __NOUVEAU_RESOURCE_H__
|
||||
|
||||
struct nouveau_resource {
|
||||
struct nouveau_resource *prev;
|
||||
struct nouveau_resource *next;
|
||||
|
||||
int in_use;
|
||||
void *priv;
|
||||
|
||||
unsigned int start;
|
||||
unsigned int size;
|
||||
};
|
||||
|
||||
int
|
||||
nouveau_resource_init(struct nouveau_resource **heap, unsigned start,
|
||||
unsigned size);
|
||||
|
||||
int
|
||||
nouveau_resource_alloc(struct nouveau_resource *heap, unsigned size, void *priv,
|
||||
struct nouveau_resource **);
|
||||
|
||||
void
|
||||
nouveau_resource_free(struct nouveau_resource **);
|
||||
|
||||
#endif
|
||||
|
|
@ -76,7 +76,7 @@ void* drmAllocCpy(void *array, int count, int entry_size)
|
|||
* A couple of free functions.
|
||||
*/
|
||||
|
||||
void drmModeFreeModeInfo(struct drm_mode_modeinfo *ptr)
|
||||
void drmModeFreeModeInfo(drmModeModeInfoPtr ptr)
|
||||
{
|
||||
if (!ptr)
|
||||
return;
|
||||
|
|
@ -273,7 +273,7 @@ drmModeCrtcPtr drmModeGetCrtc(int fd, uint32_t crtcId)
|
|||
|
||||
int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId,
|
||||
uint32_t x, uint32_t y, uint32_t *connectors, int count,
|
||||
struct drm_mode_modeinfo *mode)
|
||||
drmModeModeInfoPtr mode)
|
||||
{
|
||||
struct drm_mode_crtc crtc;
|
||||
|
||||
|
|
@ -419,7 +419,7 @@ err_allocs:
|
|||
return r;
|
||||
}
|
||||
|
||||
int drmModeAttachMode(int fd, uint32_t connector_id, struct drm_mode_modeinfo *mode_info)
|
||||
int drmModeAttachMode(int fd, uint32_t connector_id, drmModeModeInfoPtr mode_info)
|
||||
{
|
||||
struct drm_mode_mode_cmd res;
|
||||
|
||||
|
|
@ -429,7 +429,7 @@ int drmModeAttachMode(int fd, uint32_t connector_id, struct drm_mode_modeinfo *m
|
|||
return drmIoctl(fd, DRM_IOCTL_MODE_ATTACHMODE, &res);
|
||||
}
|
||||
|
||||
int drmModeDetachMode(int fd, uint32_t connector_id, struct drm_mode_modeinfo *mode_info)
|
||||
int drmModeDetachMode(int fd, uint32_t connector_id, drmModeModeInfoPtr mode_info)
|
||||
{
|
||||
struct drm_mode_mode_cmd res;
|
||||
|
||||
|
|
|
|||
|
|
@ -52,6 +52,99 @@
|
|||
* buffer object interface. This object needs to be pinned.
|
||||
*/
|
||||
|
||||
/*
|
||||
* If we pickup an old version of drm.h which doesn't include drm_mode.h
|
||||
* we should redefine defines. This is so that builds doesn't breaks with
|
||||
* new libdrm on old kernels.
|
||||
*/
|
||||
#ifndef _DRM_MODE_H
|
||||
|
||||
#define DRM_DISPLAY_INFO_LEN 32
|
||||
#define DRM_CONNECTOR_NAME_LEN 32
|
||||
#define DRM_DISPLAY_MODE_LEN 32
|
||||
#define DRM_PROP_NAME_LEN 32
|
||||
|
||||
#define DRM_MODE_TYPE_BUILTIN (1<<0)
|
||||
#define DRM_MODE_TYPE_CLOCK_C ((1<<1) | DRM_MODE_TYPE_BUILTIN)
|
||||
#define DRM_MODE_TYPE_CRTC_C ((1<<2) | DRM_MODE_TYPE_BUILTIN)
|
||||
#define DRM_MODE_TYPE_PREFERRED (1<<3)
|
||||
#define DRM_MODE_TYPE_DEFAULT (1<<4)
|
||||
#define DRM_MODE_TYPE_USERDEF (1<<5)
|
||||
#define DRM_MODE_TYPE_DRIVER (1<<6)
|
||||
|
||||
/* Video mode flags */
|
||||
/* bit compatible with the xorg definitions. */
|
||||
#define DRM_MODE_FLAG_PHSYNC (1<<0)
|
||||
#define DRM_MODE_FLAG_NHSYNC (1<<1)
|
||||
#define DRM_MODE_FLAG_PVSYNC (1<<2)
|
||||
#define DRM_MODE_FLAG_NVSYNC (1<<3)
|
||||
#define DRM_MODE_FLAG_INTERLACE (1<<4)
|
||||
#define DRM_MODE_FLAG_DBLSCAN (1<<5)
|
||||
#define DRM_MODE_FLAG_CSYNC (1<<6)
|
||||
#define DRM_MODE_FLAG_PCSYNC (1<<7)
|
||||
#define DRM_MODE_FLAG_NCSYNC (1<<8)
|
||||
#define DRM_MODE_FLAG_HSKEW (1<<9) /* hskew provided */
|
||||
#define DRM_MODE_FLAG_BCAST (1<<10)
|
||||
#define DRM_MODE_FLAG_PIXMUX (1<<11)
|
||||
#define DRM_MODE_FLAG_DBLCLK (1<<12)
|
||||
#define DRM_MODE_FLAG_CLKDIV2 (1<<13)
|
||||
|
||||
/* DPMS flags */
|
||||
/* bit compatible with the xorg definitions. */
|
||||
#define DRM_MODE_DPMS_ON 0
|
||||
#define DRM_MODE_DPMS_STANDBY 1
|
||||
#define DRM_MODE_DPMS_SUSPEND 2
|
||||
#define DRM_MODE_DPMS_OFF 3
|
||||
|
||||
/* Scaling mode options */
|
||||
#define DRM_MODE_SCALE_NON_GPU 0
|
||||
#define DRM_MODE_SCALE_FULLSCREEN 1
|
||||
#define DRM_MODE_SCALE_NO_SCALE 2
|
||||
#define DRM_MODE_SCALE_ASPECT 3
|
||||
|
||||
/* Dithering mode options */
|
||||
#define DRM_MODE_DITHERING_OFF 0
|
||||
#define DRM_MODE_DITHERING_ON 1
|
||||
|
||||
#define DRM_MODE_ENCODER_NONE 0
|
||||
#define DRM_MODE_ENCODER_DAC 1
|
||||
#define DRM_MODE_ENCODER_TMDS 2
|
||||
#define DRM_MODE_ENCODER_LVDS 3
|
||||
#define DRM_MODE_ENCODER_TVDAC 4
|
||||
|
||||
#define DRM_MODE_SUBCONNECTOR_Automatic 0
|
||||
#define DRM_MODE_SUBCONNECTOR_Unknown 0
|
||||
#define DRM_MODE_SUBCONNECTOR_DVID 3
|
||||
#define DRM_MODE_SUBCONNECTOR_DVIA 4
|
||||
#define DRM_MODE_SUBCONNECTOR_Composite 5
|
||||
#define DRM_MODE_SUBCONNECTOR_SVIDEO 6
|
||||
#define DRM_MODE_SUBCONNECTOR_Component 8
|
||||
|
||||
#define DRM_MODE_CONNECTOR_Unknown 0
|
||||
#define DRM_MODE_CONNECTOR_VGA 1
|
||||
#define DRM_MODE_CONNECTOR_DVII 2
|
||||
#define DRM_MODE_CONNECTOR_DVID 3
|
||||
#define DRM_MODE_CONNECTOR_DVIA 4
|
||||
#define DRM_MODE_CONNECTOR_Composite 5
|
||||
#define DRM_MODE_CONNECTOR_SVIDEO 6
|
||||
#define DRM_MODE_CONNECTOR_LVDS 7
|
||||
#define DRM_MODE_CONNECTOR_Component 8
|
||||
#define DRM_MODE_CONNECTOR_9PinDIN 9
|
||||
#define DRM_MODE_CONNECTOR_DisplayPort 10
|
||||
#define DRM_MODE_CONNECTOR_HDMIA 11
|
||||
#define DRM_MODE_CONNECTOR_HDMIB 12
|
||||
|
||||
#define DRM_MODE_PROP_PENDING (1<<0)
|
||||
#define DRM_MODE_PROP_RANGE (1<<1)
|
||||
#define DRM_MODE_PROP_IMMUTABLE (1<<2)
|
||||
#define DRM_MODE_PROP_ENUM (1<<3) /* enumerated type with text strings */
|
||||
#define DRM_MODE_PROP_BLOB (1<<4)
|
||||
|
||||
#define DRM_MODE_CURSOR_BO (1<<0)
|
||||
#define DRM_MODE_CURSOR_MOVE (1<<1)
|
||||
|
||||
#endif /* _DRM_MODE_H */
|
||||
|
||||
typedef struct _drmModeRes {
|
||||
|
||||
int count_fbs;
|
||||
|
|
@ -70,7 +163,27 @@ typedef struct _drmModeRes {
|
|||
uint32_t min_height, max_height;
|
||||
} drmModeRes, *drmModeResPtr;
|
||||
|
||||
typedef struct drm_mode_fb_cmd drmModeFB, *drmModeFBPtr;
|
||||
typedef struct _drmModeModeInfo {
|
||||
uint32_t clock;
|
||||
uint16_t hdisplay, hsync_start, hsync_end, htotal, hskew;
|
||||
uint16_t vdisplay, vsync_start, vsync_end, vtotal, vscan;
|
||||
|
||||
uint32_t vrefresh; /* vertical refresh * 1000 */
|
||||
|
||||
uint32_t flags;
|
||||
uint32_t type;
|
||||
char name[DRM_DISPLAY_MODE_LEN];
|
||||
} drmModeModeInfo, *drmModeModeInfoPtr;
|
||||
|
||||
typedef struct _drmModeFB {
|
||||
uint32_t fb_id;
|
||||
uint32_t width, height;
|
||||
uint32_t pitch;
|
||||
uint32_t bpp;
|
||||
uint32_t depth;
|
||||
/* driver specific handle */
|
||||
uint32_t handle;
|
||||
} drmModeFB, *drmModeFBPtr;
|
||||
|
||||
typedef struct _drmModePropertyBlob {
|
||||
uint32_t id;
|
||||
|
|
@ -97,7 +210,7 @@ typedef struct _drmModeCrtc {
|
|||
uint32_t x, y; /**< Position on the framebuffer */
|
||||
uint32_t width, height;
|
||||
int mode_valid;
|
||||
struct drm_mode_modeinfo mode;
|
||||
drmModeModeInfo mode;
|
||||
|
||||
int gamma_size; /**< Number of gamma stops */
|
||||
|
||||
|
|
@ -136,7 +249,7 @@ typedef struct _drmModeConnector {
|
|||
drmModeSubPixel subpixel;
|
||||
|
||||
int count_modes;
|
||||
struct drm_mode_modeinfo *modes;
|
||||
drmModeModeInfoPtr modes;
|
||||
|
||||
int count_props;
|
||||
uint32_t *props; /**< List of property ids */
|
||||
|
|
@ -148,7 +261,7 @@ typedef struct _drmModeConnector {
|
|||
|
||||
|
||||
|
||||
extern void drmModeFreeModeInfo( struct drm_mode_modeinfo *ptr );
|
||||
extern void drmModeFreeModeInfo( drmModeModeInfoPtr ptr );
|
||||
extern void drmModeFreeResources( drmModeResPtr ptr );
|
||||
extern void drmModeFreeFB( drmModeFBPtr ptr );
|
||||
extern void drmModeFreeCrtc( drmModeCrtcPtr ptr );
|
||||
|
|
@ -194,7 +307,7 @@ extern drmModeCrtcPtr drmModeGetCrtc(int fd, uint32_t crtcId);
|
|||
*/
|
||||
int drmModeSetCrtc(int fd, uint32_t crtcId, uint32_t bufferId,
|
||||
uint32_t x, uint32_t y, uint32_t *connectors, int count,
|
||||
struct drm_mode_modeinfo *mode);
|
||||
drmModeModeInfoPtr mode);
|
||||
|
||||
/*
|
||||
* Cursor functions
|
||||
|
|
@ -228,13 +341,13 @@ extern drmModeConnectorPtr drmModeGetConnector(int fd,
|
|||
/**
|
||||
* Attaches the given mode to an connector.
|
||||
*/
|
||||
extern int drmModeAttachMode(int fd, uint32_t connectorId, struct drm_mode_modeinfo *mode_info);
|
||||
extern int drmModeAttachMode(int fd, uint32_t connectorId, drmModeModeInfoPtr mode_info);
|
||||
|
||||
/**
|
||||
* Detaches a mode from the connector
|
||||
* must be unused, by the given mode.
|
||||
*/
|
||||
extern int drmModeDetachMode(int fd, uint32_t connectorId, struct drm_mode_modeinfo *mode_info);
|
||||
extern int drmModeDetachMode(int fd, uint32_t connectorId, drmModeModeInfoPtr mode_info);
|
||||
|
||||
extern drmModePropertyPtr drmModeGetProperty(int fd, uint32_t propertyId);
|
||||
extern void drmModeFreeProperty(drmModePropertyPtr ptr);
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@
|
|||
* of chars for next/prev indices */
|
||||
#define I915_LOG_MIN_TEX_REGION_SIZE 14
|
||||
|
||||
typedef struct drm_i915_init {
|
||||
typedef struct _drm_i915_init {
|
||||
enum {
|
||||
I915_INIT_DMA = 0x01,
|
||||
I915_CLEANUP_DMA = 0x02,
|
||||
|
|
@ -270,7 +270,7 @@ typedef struct drm_i915_batchbuffer {
|
|||
/* As above, but pass a pointer to userspace buffer which can be
|
||||
* validated by the kernel prior to sending to hardware.
|
||||
*/
|
||||
typedef struct drm_i915_cmdbuffer {
|
||||
typedef struct _drm_i915_cmdbuffer {
|
||||
char __user *buf; /* pointer to userspace command buffer */
|
||||
int sz; /* nr bytes in buf */
|
||||
int DR1; /* hw flags for GFX_OP_DRAWRECT_INFO */
|
||||
|
|
@ -296,6 +296,7 @@ typedef struct drm_i915_irq_wait {
|
|||
#define I915_PARAM_LAST_DISPATCH 3
|
||||
#define I915_PARAM_CHIPSET_ID 4
|
||||
#define I915_PARAM_HAS_GEM 5
|
||||
#define I915_PARAM_NUM_FENCES_AVAIL 6
|
||||
|
||||
typedef struct drm_i915_getparam {
|
||||
int param;
|
||||
|
|
@ -307,6 +308,7 @@ typedef struct drm_i915_getparam {
|
|||
#define I915_SETPARAM_USE_MI_BATCHBUFFER_START 1
|
||||
#define I915_SETPARAM_TEX_LRU_LOG_GRANULARITY 2
|
||||
#define I915_SETPARAM_ALLOW_BATCHBUFFER 3
|
||||
#define I915_SETPARAM_NUM_USED_FENCES 4
|
||||
|
||||
typedef struct drm_i915_setparam {
|
||||
int param;
|
||||
|
|
@ -374,10 +376,6 @@ typedef struct drm_i915_vblank_swap {
|
|||
#define MMIO_REGS_CL_INVOCATION_COUNT 6
|
||||
#define MMIO_REGS_PS_INVOCATION_COUNT 7
|
||||
#define MMIO_REGS_PS_DEPTH_COUNT 8
|
||||
#define MMIO_REGS_DOVSTA 9
|
||||
#define MMIO_REGS_GAMMA 10
|
||||
#define MMIO_REGS_FENCE 11
|
||||
#define MMIO_REGS_FENCE_NEW 12
|
||||
|
||||
typedef struct drm_i915_mmio_entry {
|
||||
unsigned int flag;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue