1 /* Cairo - a vector graphics library with display and print output
3 * Copyright © 2009 Chris Wilson
5 * This library is free software; you can redistribute it and/or
6 * modify it either under the terms of the GNU Lesser General Public
7 * License version 2.1 as published by the Free Software Foundation
8 * (the "LGPL") or, at your option, under the terms of the Mozilla
9 * Public License Version 1.1 (the "MPL"). If you do not alter this
10 * notice, a recipient may use your version of this file under either
11 * the MPL or the LGPL.
13 * You should have received a copy of the LGPL along with this library
14 * in the file COPYING-LGPL-2.1; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
16 * You should have received a copy of the MPL along with this library
17 * in the file COPYING-MPL-1.1
19 * The contents of this file are subject to the Mozilla Public License
20 * Version 1.1 (the "License"); you may not use this file except in
21 * compliance with the License. You may obtain a copy of the License at
22 * http://www.mozilla.org/MPL/
24 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
25 * OF ANY KIND, either express or implied. See the LGPL or the MPL for
26 * the specific language governing rights and limitations.
32 #include "cairo-drm-private.h"
33 #include "cairo-drm-ioctl-private.h"
35 #include "cairo-error-private.h"
37 #include <sys/ioctl.h>
40 #define ERR_DEBUG(x) x
42 struct drm_gem_close {
43 /** Handle of the object to be closed. */
48 struct drm_gem_flink {
49 /** Handle for the object being named */
52 /** Returned global name */
57 /** Name of object being opened */
60 /** Returned handle for the object */
63 /** Returned size of the object */
67 #define DRM_IOCTL_GEM_CLOSE DRM_IOW (0x09, struct drm_gem_close)
68 #define DRM_IOCTL_GEM_FLINK DRM_IOWR(0x0a, struct drm_gem_flink)
69 #define DRM_IOCTL_GEM_OPEN DRM_IOWR(0x0b, struct drm_gem_open)
72 _cairo_drm_bo_open_for_name (const cairo_drm_device_t *dev,
76 struct drm_gem_open open;
83 ret = ioctl (dev->fd, DRM_IOCTL_GEM_OPEN, &open);
84 } while (ret == -1 && errno == EINTR);
86 ERR_DEBUG((fprintf (stderr, "Failed to open bo for name %d: %s\n",
87 name, strerror (errno))));
88 return _cairo_error (CAIRO_STATUS_NO_MEMORY);
93 bo->handle = open.handle;
95 return CAIRO_STATUS_SUCCESS;
99 _cairo_drm_bo_flink (const cairo_drm_device_t *dev,
102 struct drm_gem_flink flink;
105 memset (&flink, 0, sizeof (flink));
106 flink.handle = bo->handle;
107 ret = ioctl (dev->fd, DRM_IOCTL_GEM_FLINK, &flink);
109 ERR_DEBUG((fprintf (stderr, "Failed to flink bo: %s\n",
111 return _cairo_error (CAIRO_STATUS_NO_MEMORY);
114 bo->name = flink.name;
116 return CAIRO_STATUS_SUCCESS;
120 _cairo_drm_bo_close (const cairo_drm_device_t *dev,
123 struct drm_gem_close close;
126 close.handle = bo->handle;
128 ret = ioctl (dev->fd, DRM_IOCTL_GEM_CLOSE, &close);
129 } while (ret == -1 && errno == EINTR);