openclose.c revision 08d7334d
108d7334dSsnj/*
208d7334dSsnj * Copyright © 2014 NVIDIA Corporation
308d7334dSsnj *
408d7334dSsnj * Permission is hereby granted, free of charge, to any person obtaining a
508d7334dSsnj * copy of this software and associated documentation files (the "Software"),
608d7334dSsnj * to deal in the Software without restriction, including without limitation
708d7334dSsnj * the rights to use, copy, modify, merge, publish, distribute, sublicense,
808d7334dSsnj * and/or sell copies of the Software, and to permit persons to whom the
908d7334dSsnj * Software is furnished to do so, subject to the following conditions:
1008d7334dSsnj *
1108d7334dSsnj * The above copyright notice and this permission notice shall be included in
1208d7334dSsnj * all copies or substantial portions of the Software.
1308d7334dSsnj *
1408d7334dSsnj * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1508d7334dSsnj * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1608d7334dSsnj * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
1708d7334dSsnj * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
1808d7334dSsnj * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
1908d7334dSsnj * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2008d7334dSsnj * OTHER DEALINGS IN THE SOFTWARE.
2108d7334dSsnj */
2208d7334dSsnj
2308d7334dSsnj#ifdef HAVE_CONFIG_H
2408d7334dSsnj#  include "config.h"
2508d7334dSsnj#endif
2608d7334dSsnj
2708d7334dSsnj#include <fcntl.h>
2808d7334dSsnj#include <stdio.h>
2908d7334dSsnj#include <unistd.h>
3008d7334dSsnj
3108d7334dSsnj#include "xf86drm.h"
3208d7334dSsnj#include "tegra.h"
3308d7334dSsnj
3408d7334dSsnjstatic const char default_device[] = "/dev/dri/card0";
3508d7334dSsnj
3608d7334dSsnjint main(int argc, char *argv[])
3708d7334dSsnj{
3808d7334dSsnj	struct drm_tegra *tegra;
3908d7334dSsnj	drmVersionPtr version;
4008d7334dSsnj	const char *device;
4108d7334dSsnj	int err, fd;
4208d7334dSsnj
4308d7334dSsnj	if (argc < 2)
4408d7334dSsnj		device = default_device;
4508d7334dSsnj	else
4608d7334dSsnj		device = argv[1];
4708d7334dSsnj
4808d7334dSsnj	fd = open(device, O_RDWR);
4908d7334dSsnj	if (fd < 0)
5008d7334dSsnj		return 1;
5108d7334dSsnj
5208d7334dSsnj	version = drmGetVersion(fd);
5308d7334dSsnj	if (version) {
5408d7334dSsnj		printf("Version: %d.%d.%d\n", version->version_major,
5508d7334dSsnj		       version->version_minor, version->version_patchlevel);
5608d7334dSsnj		printf("  Name: %s\n", version->name);
5708d7334dSsnj		printf("  Date: %s\n", version->date);
5808d7334dSsnj		printf("  Description: %s\n", version->desc);
5908d7334dSsnj
6008d7334dSsnj		drmFreeVersion(version);
6108d7334dSsnj	}
6208d7334dSsnj
6308d7334dSsnj	err = drm_tegra_new(&tegra, fd);
6408d7334dSsnj	if (err < 0)
6508d7334dSsnj		return 1;
6608d7334dSsnj
6708d7334dSsnj	drm_tegra_close(tegra);
6808d7334dSsnj	close(fd);
6908d7334dSsnj
7008d7334dSsnj	return 0;
7108d7334dSsnj}
72