1 /**************************************************************************
5 Copyright 2012 Samsung Electronics co., Ltd. All Rights Reserved.
7 Contact: SooChan Lim <sc1.lim@samsung.com>, Sangjin Lee <lsj119@samsung.com>
8 Boram Park <boram1288.park@samsung.com>, Changyeon Lee <cyeon.lee@samsung.com>
10 Permission is hereby granted, free of charge, to any person obtaining a
11 copy of this software and associated documentation files (the
12 "Software"), to deal in the Software without restriction, including
13 without limitation the rights to use, copy, modify, merge, publish,
14 distribute, sub license, and/or sell copies of the Software, and to
15 permit persons to whom the Software is furnished to do so, subject to
16 the following conditions:
18 The above copyright notice and this permission notice (including the
19 next paragraph) shall be included in all copies or substantial portions
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
25 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 **************************************************************************/
32 #define WL_HIDE_DEPRECATED
44 #include "tbm_bufmgr_int.h"
46 #include "wayland-tbm-drm-server-protocol.h"
48 struct wayland_tbm_drm_server {
49 struct wl_display *display;
50 struct wl_global *wl_tbm_drm_global;
57 #define MIN(x,y) (((x)<(y))?(x):(y))
59 struct wayland_tbm_drm_server *tbm_drm_srv;
62 _send_server_auth_info(struct wayland_tbm_drm_server *tbm_drm_srv,
63 struct wl_resource *resource)
66 uint32_t capabilities;
67 char *device_name = NULL;
68 drm_magic_t magic = 0;
70 fd = open(tbm_drm_srv->device_name, O_RDWR | O_CLOEXEC);
71 if (fd == -1 && errno == EINVAL) {
72 fd = open(tbm_drm_srv->device_name, O_RDWR);
74 fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
78 TBM_LOG("failed to open drm : device_name, %s\n", tbm_drm_srv->device_name);
80 wl_resource_post_error(resource, WL_TBM_DRM_ERROR_AUTHENTICATE_FAIL,
81 "authenicate failed::open_drm");
85 if (drmGetMagic(fd, &magic) < 0) {
86 if (errno != EACCES) {
87 TBM_LOG("failed to get magic\n");
89 wl_resource_post_error(resource, WL_TBM_DRM_ERROR_AUTHENTICATE_FAIL,
90 "authenicate failed::get_magic");
95 if (drmAuthMagic(tbm_drm_srv->fd, magic) < 0) {
96 TBM_LOG("failed to authenticate magic\n");
98 wl_resource_post_error(resource, WL_TBM_DRM_ERROR_AUTHENTICATE_FAIL,
99 "authenicate failed::auth_magic");
103 capabilities = tbm_drm_srv->flags;
104 device_name = tbm_drm_srv->device_name;
107 wl_tbm_drm_send_authentication_info(resource, device_name, capabilities, fd);
113 if (device_name && device_name != tbm_drm_srv->device_name)
119 _wayland_tbm_drm_server_impl_get_authentication_info(struct wl_client *client,
120 struct wl_resource *resource)
122 struct wayland_tbm_drm_server *tbm_drm_srv = wl_resource_get_user_data(resource);
124 /* if display server is the client of the host display server, for embedded server */
125 _send_server_auth_info(tbm_drm_srv, resource);
129 static const struct wl_tbm_drm_interface _wayland_tbm_drm_server_implementation = {
130 _wayland_tbm_drm_server_impl_get_authentication_info,
134 _wayland_tbm_drm_server_bind_cb(struct wl_client *client, void *data,
138 struct wl_resource *resource;
140 resource = wl_resource_create(client, &wl_tbm_drm_interface, MIN(version, 1), id);
142 wl_client_post_no_memory(client);
146 wl_resource_set_implementation(resource,
147 &_wayland_tbm_drm_server_implementation,
153 tbm_drm_helper_wl_server_init(void *wl_display, int fd, const char *device_name, uint32_t flags)
156 TBM_RETURN_VAL_IF_FAIL(wl_display != NULL, 0);
158 tbm_drm_srv = calloc(1, sizeof(struct wayland_tbm_drm_server));
159 TBM_RETURN_VAL_IF_FAIL(tbm_drm_srv != NULL, 0);
161 tbm_drm_srv->display = (struct wl_display *)wl_display;
162 tbm_drm_srv->device_name = strdup(device_name);
163 tbm_drm_srv->fd = fd;
164 tbm_drm_srv->flags = flags;
166 if(!wl_display_add_socket(tbm_drm_srv->display, "tbm_drm")) {
167 TBM_LOG("[WL_TBM] fail to add socket");
169 if (tbm_drm_srv->device_name)
170 free(tbm_drm_srv->device_name);
178 /* init the client resource list */
179 tbm_drm_srv->wl_tbm_drm_global = wl_global_create(tbm_drm_srv->display, &wl_tbm_drm_interface, 1,
180 tbm_drm_srv, _wayland_tbm_drm_server_bind_cb);
187 tbm_drm_helper_wl_server_deinit(void)
190 wl_global_destroy(tbm_drm_srv->wl_tbm_drm_global);
192 if (tbm_drm_srv->device_name)
193 free(tbm_drm_srv->device_name);
201 tbm_drm_helper_get_master_fd(void)
206 value = (const char*)getenv("TIZEN_DRM_MASTER_FD");
210 ret = sscanf(value, "%d", &fd);
214 TBM_LOG("TIZEN_DRM_MASTER_FD: %d", fd);
220 tbm_drm_helper_set_master_fd(int fd)
225 snprintf(buf, sizeof(buf), "%d", fd);
227 ret = setenv("TIZEN_DRM_MASTER_FD", (const char*)buf, 1);
230 TBM_LOG("failed to set TIZEN_DRM_MASTER_FD to %d", fd);
234 TBM_LOG("TIZEN_DRM_MASTER_FD: %d", fd);