5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27
28 /*
29 * srn Provide apm-like interfaces to Xorg
30 */
31
32 #include <sys/types.h>
33 #include <sys/errno.h>
34 #include <sys/modctl.h>
35 #include <sys/conf.h> /* driver flags and functions */
36 #include <sys/open.h> /* OTYP_CHR definition */
37 #include <sys/stat.h> /* S_IFCHR definition */
38 #include <sys/pathname.h> /* name -> dev_info xlation */
39 #include <sys/kmem.h> /* memory alloc stuff */
40 #include <sys/debug.h>
41 #include <sys/pm.h>
42 #include <sys/ddi.h>
43 #include <sys/sunddi.h>
44 #include <sys/epm.h>
246 {
247 if ((perm & SU) && secpolicy_power_mgmt(cr) == 0) /* privileged? */
248 return (1);
249 if ((perm & SG) && (crgetgid(cr) == 0)) /* group 0 is ok */
250 return (1);
251 return (0);
252 }
253
254 static int
255 srn_chpoll(dev_t dev, short events, int anyyet, short *reventsp,
256 struct pollhead **phpp)
257 {
258 extern struct pollhead srn_pollhead[];
259 int clone;
260
261 clone = SRN_MINOR_TO_CLONE(getminor(dev));
262 if ((events & (POLLIN | POLLRDNORM)) && srn_poll_cnt[clone]) {
263 *reventsp |= (POLLIN | POLLRDNORM);
264 } else {
265 *reventsp = 0;
266 if (!anyyet) {
267 *phpp = &srn_pollhead[clone];
268 }
269 }
270 return (0);
271 }
272
273 /*ARGSUSED*/
274 static int
275 srn_getinfo(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result)
276 {
277 dev_t dev;
278 int instance;
279
280 switch (infocmd) {
281 case DDI_INFO_DEVT2DEVINFO:
282 if (srn.srn_instance == -1)
283 return (DDI_FAILURE);
284 *result = srn.srn_dip;
285 return (DDI_SUCCESS);
286
287 case DDI_INFO_DEVT2INSTANCE:
288 dev = (dev_t)arg;
289 instance = getminor(dev) >> 8;
|
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 * Copyright 2017 Joyent, Inc.
26 */
27
28
29 /*
30 * srn Provide apm-like interfaces to Xorg
31 */
32
33 #include <sys/types.h>
34 #include <sys/errno.h>
35 #include <sys/modctl.h>
36 #include <sys/conf.h> /* driver flags and functions */
37 #include <sys/open.h> /* OTYP_CHR definition */
38 #include <sys/stat.h> /* S_IFCHR definition */
39 #include <sys/pathname.h> /* name -> dev_info xlation */
40 #include <sys/kmem.h> /* memory alloc stuff */
41 #include <sys/debug.h>
42 #include <sys/pm.h>
43 #include <sys/ddi.h>
44 #include <sys/sunddi.h>
45 #include <sys/epm.h>
247 {
248 if ((perm & SU) && secpolicy_power_mgmt(cr) == 0) /* privileged? */
249 return (1);
250 if ((perm & SG) && (crgetgid(cr) == 0)) /* group 0 is ok */
251 return (1);
252 return (0);
253 }
254
255 static int
256 srn_chpoll(dev_t dev, short events, int anyyet, short *reventsp,
257 struct pollhead **phpp)
258 {
259 extern struct pollhead srn_pollhead[];
260 int clone;
261
262 clone = SRN_MINOR_TO_CLONE(getminor(dev));
263 if ((events & (POLLIN | POLLRDNORM)) && srn_poll_cnt[clone]) {
264 *reventsp |= (POLLIN | POLLRDNORM);
265 } else {
266 *reventsp = 0;
267 }
268
269 if ((*reventsp == 0 && !anyyet) || (events & POLLET)) {
270 *phpp = &srn_pollhead[clone];
271 }
272 return (0);
273 }
274
275 /*ARGSUSED*/
276 static int
277 srn_getinfo(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result)
278 {
279 dev_t dev;
280 int instance;
281
282 switch (infocmd) {
283 case DDI_INFO_DEVT2DEVINFO:
284 if (srn.srn_instance == -1)
285 return (DDI_FAILURE);
286 *result = srn.srn_dip;
287 return (DDI_SUCCESS);
288
289 case DDI_INFO_DEVT2INSTANCE:
290 dev = (dev_t)arg;
291 instance = getminor(dev) >> 8;
|