summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThierry Reding <treding@nvidia.com>2014-11-27 16:55:34 +0100
committerThierry Reding <treding@nvidia.com>2016-07-04 11:36:20 +0200
commit3e63a55bc58cde7a1c352eb32a36a8ff36470dbf (patch)
tree7830dfe43356d924123181252aa129ebd5c7f038
parent6155941e45bc244a523a9ca62b234e71365aff2d (diff)
gallium/tegra: Use libdrm_tegra API
Signed-off-by: Thierry Reding <treding@nvidia.com>
-rw-r--r--src/gallium/drivers/tegra/tegra_resource.c32
-rw-r--r--src/gallium/drivers/tegra/tegra_resource.h1
-rw-r--r--src/gallium/drivers/tegra/tegra_screen.c12
-rw-r--r--src/gallium/drivers/tegra/tegra_screen.h2
4 files changed, 37 insertions, 10 deletions
diff --git a/src/gallium/drivers/tegra/tegra_resource.c b/src/gallium/drivers/tegra/tegra_resource.c
index 3b8accad9f3d..8e3b0f493026 100644
--- a/src/gallium/drivers/tegra/tegra_resource.c
+++ b/src/gallium/drivers/tegra/tegra_resource.c
@@ -27,6 +27,7 @@
#include <stdio.h>
#include <drm/tegra_drm.h>
+#include <libdrm/tegra.h>
#include <xf86drm.h>
#include "pipe/p_state.h"
@@ -70,9 +71,10 @@ tegra_resource_create(struct pipe_screen *pscreen,
/* import scanout buffers for display */
if (template->bind & PIPE_BIND_SCANOUT) {
- struct drm_tegra_gem_set_tiling args;
+ struct drm_tegra_bo_tiling tiling;
struct winsys_handle handle;
boolean status;
+ size_t size;
int fd, err;
resource->gpu = screen->gpu->resource_create(screen->gpu,
@@ -89,6 +91,7 @@ tegra_resource_create(struct pipe_screen *pscreen,
if (!status)
goto destroy;
+ size = handle.stride * resource->gpu->height0;
resource->stride = handle.stride;
fd = handle.handle;
@@ -102,18 +105,24 @@ tegra_resource_create(struct pipe_screen *pscreen,
close(fd);
- memset(&args, 0, sizeof(args));
- args.handle = resource->handle;
- args.mode = DRM_TEGRA_GEM_TILING_MODE_BLOCK;
- args.value = 4;
-
- err = drmIoctl(screen->fd, DRM_IOCTL_TEGRA_GEM_SET_TILING,
- &args);
+ err = drm_tegra_bo_wrap(&resource->bo, screen->device,
+ resource->handle, 0, size);
if (err < 0) {
- fprintf(stderr, "failed to set tiling parameters: %s\n",
- strerror(errno));
+ fprintf(stderr, "failed to create buffer object: %s\n",
+ strerror(-err));
goto destroy;
}
+
+ tiling.mode = DRM_TEGRA_GEM_TILING_MODE_BLOCK;
+ tiling.value = 4;
+
+ err = drm_tegra_bo_set_tiling(resource->bo, &tiling);
+ if (err < 0) {
+ fprintf(stderr,
+ "failed to set tiling for buffer object: %s\n",
+ strerror(-err));
+ goto unref;
+ }
} else {
resource->gpu = screen->gpu->resource_create(screen->gpu,
template);
@@ -130,6 +139,8 @@ tegra_resource_create(struct pipe_screen *pscreen,
debug_printf("< %s() = %p\n", __func__, &resource->base);
return &resource->base;
+unref:
+ drm_tegra_bo_unref(resource->bo);
destroy:
screen->gpu->resource_destroy(screen->gpu, resource->gpu);
free:
@@ -203,6 +214,7 @@ tegra_resource_destroy(struct pipe_screen *pscreen,
presource);
pipe_resource_reference(&resource->gpu, NULL);
+ drm_tegra_bo_unref(resource->bo);
free(resource);
debug_printf("< %s()\n", __func__);
diff --git a/src/gallium/drivers/tegra/tegra_resource.h b/src/gallium/drivers/tegra/tegra_resource.h
index 783fb37ec466..5a9afa35091c 100644
--- a/src/gallium/drivers/tegra/tegra_resource.h
+++ b/src/gallium/drivers/tegra/tegra_resource.h
@@ -32,6 +32,7 @@ struct tegra_resource {
struct pipe_resource base;
struct pipe_resource *gpu;
+ struct drm_tegra_bo *bo;
uint32_t stride;
uint32_t handle;
size_t size;
diff --git a/src/gallium/drivers/tegra/tegra_screen.c b/src/gallium/drivers/tegra/tegra_screen.c
index b6394faa0c61..95580c924488 100644
--- a/src/gallium/drivers/tegra/tegra_screen.c
+++ b/src/gallium/drivers/tegra/tegra_screen.c
@@ -29,6 +29,8 @@
#include <libudev.h>
#endif
+#include <libdrm/tegra.h>
+
#include "util/u_debug.h"
#include "tegra/tegra_context.h"
@@ -57,6 +59,7 @@ static void tegra_screen_destroy(struct pipe_screen *pscreen)
debug_printf("> %s(pscreen=%p)\n", __func__, pscreen);
screen->gpu->destroy(screen->gpu);
+ drm_tegra_close(screen->device);
free(pscreen);
debug_printf("< %s()\n", __func__);
@@ -333,6 +336,7 @@ struct pipe_screen *
tegra_screen_create(int fd)
{
struct tegra_screen *screen;
+ int err;
debug_printf("> %s()\n", __func__);
@@ -342,6 +346,14 @@ tegra_screen_create(int fd)
screen->fd = fd;
+ err = drm_tegra_new(&screen->device, fd);
+ if (err < 0) {
+ fprintf(stderr, "failed to create Tegra context: %s\n",
+ strerror(errno));
+ free(screen);
+ return NULL;
+ }
+
screen->gpu_fd = tegra_open_render_node(screen->fd);
if (screen->gpu_fd < 0) {
fprintf(stderr, "failed to open GPU device: %s\n",
diff --git a/src/gallium/drivers/tegra/tegra_screen.h b/src/gallium/drivers/tegra/tegra_screen.h
index 1fba510c241f..e48c73999ccd 100644
--- a/src/gallium/drivers/tegra/tegra_screen.h
+++ b/src/gallium/drivers/tegra/tegra_screen.h
@@ -32,6 +32,8 @@ struct tegra_screen {
struct pipe_screen *gpu;
int gpu_fd;
+
+ struct drm_tegra *device;
};
static inline struct tegra_screen *