blob: e232c3eec3356e18d7ce5dce601b2f6805f8b111 [file] [log] [blame]
#include "drm_setup.h"
#include "memutil.h"
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
struct drm_test_info *drm_test_setup(int argc, char **argv)
{
struct drm_test_info *info;
drmVersionPtr version;
if (argc < 2) {
printf("Usage: %s /dev/dri/...\n", argv[0]);
return NULL;
}
info = CALLOC_STRUCT(drm_test_info);
info->fd = open(argv[1], O_RDWR);
if (info->fd < 0) {
fprintf(stdout, "Unable to open %s\n", argv[1]);
goto out;
}
version = drmGetVersion(info->fd);
if (version) {
printf("Version: %d.%d.%d\n", version->version_major,
version->version_minor, version->version_patchlevel);
printf(" Name: %s\n", version->name);
printf(" Date: %s\n", version->date);
printf(" Description: %s\n", version->desc);
drmFreeVersion(version);
}
info->dev = etna_device_new(info->fd);
if (!info->dev) {
fprintf(stdout, "Unable to create device\n");
goto out;
}
/* TODO: we assume that core 1 is a 3D+CL capable one.
* This is pretty much only true for i.MX6q(p).
* If the tests don't work on your hardware check this carefully.
*/
info->gpu = etna_gpu_new(info->dev, 1);
if (!info->gpu) {
fprintf(stdout, "Unable to create gpu\n");
goto out_device;
}
info->pipe = etna_pipe_new(info->gpu, ETNA_PIPE_3D);
if (!info->pipe) {
fprintf(stdout, "Unable to create pipe\n");
goto out_gpu;
}
info->stream = etna_cmd_stream_new(info->pipe, 0x3000, NULL, NULL);
if (!info->stream) {
fprintf(stdout, "Unable to create command stream\n");
goto out_pipe;
}
return info;
out_pipe:
etna_pipe_del(info->pipe);
out_gpu:
etna_gpu_del(info->gpu);
out_device:
etna_device_del(info->dev);
out:
close(info->fd);
free(info);
return NULL;
}
void drm_test_teardown(struct drm_test_info *info)
{
etna_cmd_stream_del(info->stream);
etna_pipe_del(info->pipe);
etna_gpu_del(info->gpu);
etna_device_del(info->dev);
close(info->fd);
free(info);
}