1 /* _NVRM_COPYRIGHT_BEGIN_
3 * Copyright 2001-2002 by NVIDIA Corporation. All rights reserved. All
4 * information contained herein is proprietary and confidential to NVIDIA
5 * Corporation. Any use, reproduction, or disclosure without the written
6 * permission of NVIDIA Corporation is prohibited.
12 #include "os-interface.h"
14 #include "nv-freebsd.h"
16 static d_open_t nvidia_ctl_open;
17 static d_close_t nvidia_ctl_close;
18 static d_ioctl_t nvidia_ctl_ioctl;
19 static d_poll_t nvidia_ctl_poll;
21 static struct dev_ops nvidia_ctl_ops = {
22 { "nvidiactl", CDEV_MAJOR, D_TRACKCLOSE },
23 .d_open = nvidia_ctl_open,
24 .d_close = nvidia_ctl_close,
25 .d_ioctl = nvidia_ctl_ioctl,
26 .d_poll = nvidia_ctl_poll,
29 static struct cdev *nvidia_ctl_cdev = NULL;
30 struct nvidia_softc nvidia_ctl_sc;
32 static int nvidia_count = 0;
35 struct dev_open_args *ap
39 nv_state_t *nv = &nvidia_ctl_state;
42 status = nvidia_open_ctl(ap->a_head.a_dev, curthread);
49 struct dev_close_args *ap
53 nv_state_t *nv = &nvidia_ctl_state;
56 status = nvidia_close_ctl(ap->a_head.a_dev, curthread);
63 struct dev_ioctl_args *ap
66 u_long cmd = ap->a_cmd;
67 caddr_t data = ap->a_data;
69 nv_state_t *nv = &nvidia_ctl_state;
70 struct nvidia_softc *sc;
74 if (__NV_IOC_TYPE(cmd) != NV_IOCTL_MAGIC)
78 status = nvidia_handle_ioctl(ap->a_head.a_dev, cmd, data, ap->a_fflag, curthread);
85 struct dev_poll_args *ap
88 int events = ap->a_events;
90 struct nvidia_softc *sc;
91 struct nvidia_event *et;
93 nv = &nvidia_ctl_state;
98 STAILQ_FOREACH(et, &sc->event_queue, queue) {
99 if (et->event.file == __TD_FDT(curthread))
105 selrecord(curthread, &sc->rsel);
109 ap->a_events = events & (POLLIN | POLLPRI | POLLRDNORM);
115 int nvidia_ctl_attach(void)
117 if (nvidia_count == 0) {
119 * This routine is called from nvidia_attach(), multiple times
120 * when more than one device is installed.
122 #if __DragonFly_version < 200205
123 dev_ops_add(&nvidia_ctl_ops, -1, CDEV_CTL_MINOR);
125 nvidia_ctl_cdev = make_dev(&nvidia_ctl_ops,
127 UID_ROOT, GID_WHEEL, 0666,
128 "%s", nvidia_ctl_ops.head.name);
135 int nvidia_ctl_detach(void)
137 struct nvidia_softc *sc;
142 if (nvidia_count == 0) {
144 * Like nvidia_ctl_attach(), nvidia_ctl_detach() will also be
145 * called more than once with multiple devices.
147 #if __DragonFly_version < 200205
148 dev_ops_remove(&nvidia_ctl_ops, -1, CDEV_CTL_MINOR);
150 destroy_dev(nvidia_ctl_cdev);