2 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
8 /* drm_fops.h -- File operations for DRM -*- linux-c -*-
9 * Created: Mon Jan 4 08:58:31 1999 by faith@valinux.com
12 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
13 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
14 * Copyright (c) 2009, Intel Corporation.
15 * All Rights Reserved.
17 * Permission is hereby granted, free of charge, to any person obtaining a
18 * copy of this software and associated documentation files (the "Software"),
19 * to deal in the Software without restriction, including without limitation
20 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
21 * and/or sell copies of the Software, and to permit persons to whom the
22 * Software is furnished to do so, subject to the following conditions:
24 * The above copyright notice and this permission notice (including the next
25 * paragraph) shall be included in all copies or substantial portions of the
28 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
29 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
30 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
31 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
32 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
33 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
34 * OTHER DEALINGS IN THE SOFTWARE.
37 * Rickard E. (Rik) Faith <faith@valinux.com>
38 * Daryll Strauss <daryll@valinux.com>
39 * Gareth Hughes <gareth@valinux.com>
49 drm_find_file_by_proc(drm_device_t
*dev
, cred_t
*credp
)
51 pid_t pid
= ddi_get_pid();
54 TAILQ_FOREACH(priv
, &dev
->files
, link
)
62 drm_find_file_by_minor(drm_device_t
*dev
, int minor
)
66 TAILQ_FOREACH(mp
, &dev
->minordevs
, link
) {
67 if (mp
->minor
== minor
)
73 /* drm_open_helper is called whenever a process opens /dev/drm. */
76 drm_open_helper(drm_device_t
*dev
, drm_cminor_t
*mp
, int flags
,
77 int otyp
, cred_t
*credp
)
84 return (EBUSY
); /* No exclusive opens */
88 DRM_DEBUG("drm_open_helper :pid = %d", pid
);
91 priv
= drm_find_file_by_proc(dev
, credp
);
95 priv
= drm_alloc(sizeof (*priv
), DRM_MEM_FILES
);
100 bzero(priv
, sizeof (*priv
));
102 priv
->uid
= crgetsuid(credp
);
106 priv
->minor
= 5; /* just for hack */
107 priv
->ioctl_count
= 0;
109 /* for compatibility root is always authenticated */
110 priv
->authenticated
= DRM_SUSER(credp
);
112 if (dev
->driver
->use_gem
== 1)
115 if (dev
->driver
->open
) {
116 retcode
= dev
->driver
->open(dev
, priv
);
118 drm_free(priv
, sizeof (*priv
), DRM_MEM_FILES
);
124 /* first opener automatically becomes master */
125 priv
->master
= TAILQ_EMPTY(&dev
->files
);
126 TAILQ_INSERT_TAIL(&dev
->files
, priv
, link
);