1 | /* $Id: vboxms.c 48943 2013-10-07 21:30:45Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox Guest Additions Mouse Driver for Solaris.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2012 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | */
|
---|
26 |
|
---|
27 | #define LOG_GROUP LOG_GROUP_DRV_MOUSE
|
---|
28 |
|
---|
29 | /******************************************************************************
|
---|
30 | * Header Files *
|
---|
31 | ******************************************************************************/
|
---|
32 |
|
---|
33 | #include <VBox/VBoxGuestLib.h>
|
---|
34 | #include <VBox/log.h>
|
---|
35 | #include <VBox/version.h>
|
---|
36 | #include <iprt/assert.h>
|
---|
37 | #include <iprt/asm.h>
|
---|
38 |
|
---|
39 | #ifndef TESTCASE
|
---|
40 | # include <sys/modctl.h>
|
---|
41 | # include <sys/msio.h>
|
---|
42 | # include <sys/stat.h>
|
---|
43 | # include <sys/ddi.h>
|
---|
44 | # include <sys/strsun.h>
|
---|
45 | # include <sys/stropts.h>
|
---|
46 | # include <sys/sunddi.h>
|
---|
47 | # include <sys/vuid_event.h>
|
---|
48 | # include <sys/vuid_wheel.h>
|
---|
49 | #undef u /* /usr/include/sys/user.h:249:1 is where this is defined to (curproc->p_user). very cool. */
|
---|
50 | #else /* TESTCASE */
|
---|
51 | # undef IN_RING3
|
---|
52 | # define IN_RING0
|
---|
53 | #endif /* TESTCASE */
|
---|
54 |
|
---|
55 | #ifdef TESTCASE /* Include this last as we . */
|
---|
56 | # include "testcase/solaris.h"
|
---|
57 | # include <iprt/test.h>
|
---|
58 | #endif /* TESTCASE */
|
---|
59 |
|
---|
60 |
|
---|
61 | /******************************************************************************
|
---|
62 | * Defined Constants And Macros *
|
---|
63 | ******************************************************************************/
|
---|
64 |
|
---|
65 | /** The module name. */
|
---|
66 | #define DEVICE_NAME "vboxms"
|
---|
67 | /** The module description as seen in 'modinfo'. */
|
---|
68 | #define DEVICE_DESC "VBoxMouseIntegr"
|
---|
69 |
|
---|
70 |
|
---|
71 | /******************************************************************************
|
---|
72 | * Internal functions used in global structures *
|
---|
73 | ******************************************************************************/
|
---|
74 |
|
---|
75 | static int vbmsSolAttach(dev_info_t *pDip, ddi_attach_cmd_t enmCmd);
|
---|
76 | static int vbmsSolDetach(dev_info_t *pDip, ddi_detach_cmd_t enmCmd);
|
---|
77 | static int vbmsSolGetInfo(dev_info_t *pDip, ddi_info_cmd_t enmCmd, void *pvArg,
|
---|
78 | void **ppvResult);
|
---|
79 | static int vbmsSolOpen(queue_t *pReadQueue, dev_t *pDev, int fFlag,
|
---|
80 | int fMode, cred_t *pCred);
|
---|
81 | static int vbmsSolClose(queue_t *pReadQueue, int fFlag, cred_t *pCred);
|
---|
82 | static int vbmsSolWPut(queue_t *pWriteQueue, mblk_t *pMBlk);
|
---|
83 |
|
---|
84 |
|
---|
85 | /******************************************************************************
|
---|
86 | * Driver global structures *
|
---|
87 | ******************************************************************************/
|
---|
88 |
|
---|
89 | #ifndef TESTCASE /* I see no value in including these in the test. */
|
---|
90 |
|
---|
91 | /*
|
---|
92 | * mod_info: STREAMS module information.
|
---|
93 | */
|
---|
94 | static struct module_info g_vbmsSolModInfo =
|
---|
95 | {
|
---|
96 | 0, /* module id number */
|
---|
97 | "vboxms",
|
---|
98 | 0, /* minimum packet size */
|
---|
99 | INFPSZ, /* maximum packet size accepted */
|
---|
100 | 512, /* high water mark for data flow control */
|
---|
101 | 128 /* low water mark */
|
---|
102 | };
|
---|
103 |
|
---|
104 | /*
|
---|
105 | * rinit: read queue structure for handling messages coming from below. In
|
---|
106 | * our case this means the host and the virtual hardware, so we do not need
|
---|
107 | * the put and service procedures.
|
---|
108 | */
|
---|
109 | static struct qinit g_vbmsSolRInit =
|
---|
110 | {
|
---|
111 | NULL, /* put */
|
---|
112 | NULL, /* service thread procedure */
|
---|
113 | vbmsSolOpen,
|
---|
114 | vbmsSolClose,
|
---|
115 | NULL, /* reserved */
|
---|
116 | &g_vbmsSolModInfo,
|
---|
117 | NULL /* module statistics structure */
|
---|
118 | };
|
---|
119 |
|
---|
120 | /*
|
---|
121 | * winit: write queue structure for handling messages coming from above. Above
|
---|
122 | * means user space applications: either Guest Additions user space tools or
|
---|
123 | * applications reading pointer input. Messages from the last most likely pass
|
---|
124 | * through at least the "consms" console mouse streams module which multiplexes
|
---|
125 | * hardware pointer drivers to a single virtual pointer.
|
---|
126 | */
|
---|
127 | static struct qinit g_vbmsSolWInit =
|
---|
128 | {
|
---|
129 | vbmsSolWPut,
|
---|
130 | NULL, /* service thread procedure */
|
---|
131 | NULL, /* open */
|
---|
132 | NULL, /* close */
|
---|
133 | NULL, /* reserved */
|
---|
134 | &g_vbmsSolModInfo,
|
---|
135 | NULL /* module statistics structure */
|
---|
136 | };
|
---|
137 |
|
---|
138 | /**
|
---|
139 | * streamtab: for drivers that support char/block entry points.
|
---|
140 | */
|
---|
141 | static struct streamtab g_vbmsSolStreamTab =
|
---|
142 | {
|
---|
143 | &g_vbmsSolRInit,
|
---|
144 | &g_vbmsSolWInit,
|
---|
145 | NULL, /* MUX rinit */
|
---|
146 | NULL /* MUX winit */
|
---|
147 | };
|
---|
148 |
|
---|
149 | /**
|
---|
150 | * cb_ops: for drivers that support char/block entry points
|
---|
151 | */
|
---|
152 | static struct cb_ops g_vbmsSolCbOps =
|
---|
153 | {
|
---|
154 | nodev, /* open */
|
---|
155 | nodev, /* close */
|
---|
156 | nodev, /* b strategy */
|
---|
157 | nodev, /* b dump */
|
---|
158 | nodev, /* b print */
|
---|
159 | nodev, /* c read */
|
---|
160 | nodev, /* c write */
|
---|
161 | nodev, /* c ioctl */
|
---|
162 | nodev, /* c devmap */
|
---|
163 | nodev, /* c mmap */
|
---|
164 | nodev, /* c segmap */
|
---|
165 | nochpoll, /* c poll */
|
---|
166 | ddi_prop_op, /* property ops */
|
---|
167 | &g_vbmsSolStreamTab,
|
---|
168 | D_MP,
|
---|
169 | CB_REV /* revision */
|
---|
170 | };
|
---|
171 |
|
---|
172 | /**
|
---|
173 | * dev_ops: for driver device operations
|
---|
174 | */
|
---|
175 | static struct dev_ops g_vbmsSolDevOps =
|
---|
176 | {
|
---|
177 | DEVO_REV, /* driver build revision */
|
---|
178 | 0, /* ref count */
|
---|
179 | vbmsSolGetInfo,
|
---|
180 | nulldev, /* identify */
|
---|
181 | nulldev, /* probe */
|
---|
182 | vbmsSolAttach,
|
---|
183 | vbmsSolDetach,
|
---|
184 | nodev, /* reset */
|
---|
185 | &g_vbmsSolCbOps,
|
---|
186 | NULL, /* bus operations */
|
---|
187 | nodev /* power */
|
---|
188 | };
|
---|
189 |
|
---|
190 | /**
|
---|
191 | * modldrv: export driver specifics to the kernel
|
---|
192 | */
|
---|
193 | static struct modldrv g_vbmsSolModule =
|
---|
194 | {
|
---|
195 | &mod_driverops, /* extern from kernel */
|
---|
196 | DEVICE_DESC " " VBOX_VERSION_STRING "r" RT_XSTR(VBOX_SVN_REV),
|
---|
197 | &g_vbmsSolDevOps
|
---|
198 | };
|
---|
199 |
|
---|
200 | /**
|
---|
201 | * modlinkage: export install/remove/info to the kernel.
|
---|
202 | */
|
---|
203 | static struct modlinkage g_vbmsSolModLinkage =
|
---|
204 | {
|
---|
205 | MODREV_1, /* loadable module system revision */
|
---|
206 | &g_vbmsSolModule,
|
---|
207 | NULL /* terminate array of linkage structures */
|
---|
208 | };
|
---|
209 |
|
---|
210 | #else /* TESTCASE */
|
---|
211 | static void *g_vbmsSolModLinkage;
|
---|
212 | #endif /* TESTCASE */
|
---|
213 |
|
---|
214 | /**
|
---|
215 | * State info for each open file handle.
|
---|
216 | */
|
---|
217 | typedef struct
|
---|
218 | {
|
---|
219 | /** Device handle. */
|
---|
220 | dev_info_t *pDip;
|
---|
221 | /** Mutex protecting the guest library against multiple initialistation or
|
---|
222 | * uninitialisation. */
|
---|
223 | kmutex_t InitMtx;
|
---|
224 | /** Initialisation counter for the guest library. */
|
---|
225 | size_t cInits;
|
---|
226 | /** The STREAMS write queue which we need for sending messages up to
|
---|
227 | * user-space. */
|
---|
228 | queue_t *pWriteQueue;
|
---|
229 | /** Pre-allocated mouse status VMMDev request for use in the IRQ
|
---|
230 | * handler. */
|
---|
231 | VMMDevReqMouseStatus *pMouseStatusReq;
|
---|
232 | /* The current greatest horizontal pixel offset on the screen, used for
|
---|
233 | * absolute mouse position reporting.
|
---|
234 | */
|
---|
235 | int cMaxScreenX;
|
---|
236 | /* The current greatest vertical pixel offset on the screen, used for
|
---|
237 | * absolute mouse position reporting.
|
---|
238 | */
|
---|
239 | int cMaxScreenY;
|
---|
240 | } VBMSSTATE, *PVBMSSTATE;
|
---|
241 |
|
---|
242 |
|
---|
243 | /******************************************************************************
|
---|
244 | * Global Variables *
|
---|
245 | ******************************************************************************/
|
---|
246 |
|
---|
247 | /** Global driver state. Actually this could be allocated dynamically. */
|
---|
248 | static VBMSSTATE g_OpenNodeState /* = { 0 } */;
|
---|
249 |
|
---|
250 |
|
---|
251 | /******************************************************************************
|
---|
252 | * Kernel entry points *
|
---|
253 | ******************************************************************************/
|
---|
254 |
|
---|
255 | /** Driver initialisation. */
|
---|
256 | int _init(void)
|
---|
257 | {
|
---|
258 | int rc;
|
---|
259 | LogRelFlow((DEVICE_NAME ": built on " __DATE__ " at " __TIME__ "\n"));
|
---|
260 | mutex_init(&g_OpenNodeState.InitMtx, NULL, MUTEX_DRIVER, NULL);
|
---|
261 | /*
|
---|
262 | * Prevent module autounloading.
|
---|
263 | */
|
---|
264 | modctl_t *pModCtl = mod_getctl(&g_vbmsSolModLinkage);
|
---|
265 | if (pModCtl)
|
---|
266 | pModCtl->mod_loadflags |= MOD_NOAUTOUNLOAD;
|
---|
267 | else
|
---|
268 | LogRel((DEVICE_NAME ": failed to disable autounloading!\n"));
|
---|
269 | rc = mod_install(&g_vbmsSolModLinkage);
|
---|
270 |
|
---|
271 | LogRelFlow((DEVICE_NAME ": initialisation returning %d.\n", rc));
|
---|
272 | return rc;
|
---|
273 | }
|
---|
274 |
|
---|
275 |
|
---|
276 | #ifdef TESTCASE
|
---|
277 | /** Simple test of the flow through _init. */
|
---|
278 | static void test_init(RTTEST hTest)
|
---|
279 | {
|
---|
280 | RTTestSub(hTest, "Testing _init");
|
---|
281 | RTTEST_CHECK(hTest, _init() == 0);
|
---|
282 | }
|
---|
283 | #endif
|
---|
284 |
|
---|
285 |
|
---|
286 | /** Driver cleanup. */
|
---|
287 | int _fini(void)
|
---|
288 | {
|
---|
289 | int rc;
|
---|
290 |
|
---|
291 | LogRelFlow((DEVICE_NAME ":_fini\n"));
|
---|
292 | rc = mod_remove(&g_vbmsSolModLinkage);
|
---|
293 | mutex_destroy(&g_OpenNodeState.InitMtx);
|
---|
294 |
|
---|
295 | return rc;
|
---|
296 | }
|
---|
297 |
|
---|
298 |
|
---|
299 | /** Driver identification. */
|
---|
300 | int _info(struct modinfo *pModInfo)
|
---|
301 | {
|
---|
302 | int rc;
|
---|
303 | LogRelFlow((DEVICE_NAME ":_info\n"));
|
---|
304 | rc = mod_info(&g_vbmsSolModLinkage, pModInfo);
|
---|
305 | LogRelFlow((DEVICE_NAME ":_info returning %d\n", rc));
|
---|
306 | return rc;
|
---|
307 | }
|
---|
308 |
|
---|
309 |
|
---|
310 | /******************************************************************************
|
---|
311 | * Initialisation entry points *
|
---|
312 | ******************************************************************************/
|
---|
313 |
|
---|
314 | /**
|
---|
315 | * Attach entry point, to attach a device to the system or resume it.
|
---|
316 | *
|
---|
317 | * @param pDip The module structure instance.
|
---|
318 | * @param enmCmd Attach type (ddi_attach_cmd_t)
|
---|
319 | *
|
---|
320 | * @return corresponding solaris error code.
|
---|
321 | */
|
---|
322 | int vbmsSolAttach(dev_info_t *pDip, ddi_attach_cmd_t enmCmd)
|
---|
323 | {
|
---|
324 | LogRelFlow((DEVICE_NAME "::Attach\n"));
|
---|
325 | switch (enmCmd)
|
---|
326 | {
|
---|
327 | case DDI_ATTACH:
|
---|
328 | {
|
---|
329 | int rc;
|
---|
330 | int instance = ddi_get_instance(pDip);
|
---|
331 | /* Only one instance supported. */
|
---|
332 | if (!ASMAtomicCmpXchgPtr(&g_OpenNodeState.pDip, pDip, NULL))
|
---|
333 | return DDI_FAILURE;
|
---|
334 | rc = ddi_create_minor_node(pDip, DEVICE_NAME, S_IFCHR, instance, DDI_PSEUDO, 0);
|
---|
335 | if (rc == DDI_SUCCESS)
|
---|
336 | return DDI_SUCCESS;
|
---|
337 | ASMAtomicWritePtr(&g_OpenNodeState.pDip, NULL);
|
---|
338 | return DDI_FAILURE;
|
---|
339 | }
|
---|
340 |
|
---|
341 | case DDI_RESUME:
|
---|
342 | {
|
---|
343 | /** @todo implement resume for guest driver. */
|
---|
344 | return DDI_SUCCESS;
|
---|
345 | }
|
---|
346 |
|
---|
347 | default:
|
---|
348 | return DDI_FAILURE;
|
---|
349 | }
|
---|
350 | }
|
---|
351 |
|
---|
352 |
|
---|
353 | /**
|
---|
354 | * Detach entry point, to detach a device to the system or suspend it.
|
---|
355 | *
|
---|
356 | * @param pDip The module structure instance.
|
---|
357 | * @param enmCmd Attach type (ddi_attach_cmd_t)
|
---|
358 | *
|
---|
359 | * @return corresponding solaris error code.
|
---|
360 | */
|
---|
361 | int vbmsSolDetach(dev_info_t *pDip, ddi_detach_cmd_t enmCmd)
|
---|
362 | {
|
---|
363 | LogRelFlow((DEVICE_NAME "::Detach\n"));
|
---|
364 | switch (enmCmd)
|
---|
365 | {
|
---|
366 | case DDI_DETACH:
|
---|
367 | {
|
---|
368 | ddi_remove_minor_node(pDip, NULL);
|
---|
369 | ASMAtomicWritePtr(&g_OpenNodeState.pDip, NULL);
|
---|
370 | return DDI_SUCCESS;
|
---|
371 | }
|
---|
372 |
|
---|
373 | case DDI_SUSPEND:
|
---|
374 | {
|
---|
375 | /** @todo implement suspend for guest driver. */
|
---|
376 | return DDI_SUCCESS;
|
---|
377 | }
|
---|
378 |
|
---|
379 | default:
|
---|
380 | return DDI_FAILURE;
|
---|
381 | }
|
---|
382 | }
|
---|
383 |
|
---|
384 |
|
---|
385 | /**
|
---|
386 | * Info entry point, called by solaris kernel for obtaining driver info.
|
---|
387 | *
|
---|
388 | * @param pDip The module structure instance (do not use).
|
---|
389 | * @param enmCmd Information request type.
|
---|
390 | * @param pvArg Type specific argument.
|
---|
391 | * @param ppvResult Where to store the requested info.
|
---|
392 | *
|
---|
393 | * @return corresponding solaris error code.
|
---|
394 | */
|
---|
395 | int vbmsSolGetInfo(dev_info_t *pDip, ddi_info_cmd_t enmCmd, void *pvArg,
|
---|
396 | void **ppvResult)
|
---|
397 | {
|
---|
398 | LogRelFlow((DEVICE_NAME "::GetInfo\n"));
|
---|
399 |
|
---|
400 | int rc = DDI_SUCCESS;
|
---|
401 | switch (enmCmd)
|
---|
402 | {
|
---|
403 | case DDI_INFO_DEVT2DEVINFO:
|
---|
404 | *ppvResult = (void *)g_OpenNodeState.pDip;
|
---|
405 | break;
|
---|
406 |
|
---|
407 | case DDI_INFO_DEVT2INSTANCE:
|
---|
408 | *ppvResult = (void *)(uintptr_t)ddi_get_instance(g_OpenNodeState.pDip);
|
---|
409 | break;
|
---|
410 |
|
---|
411 | default:
|
---|
412 | rc = DDI_FAILURE;
|
---|
413 | break;
|
---|
414 | }
|
---|
415 |
|
---|
416 | NOREF(pvArg);
|
---|
417 | return rc;
|
---|
418 | }
|
---|
419 |
|
---|
420 |
|
---|
421 | /******************************************************************************
|
---|
422 | * Main code *
|
---|
423 | ******************************************************************************/
|
---|
424 |
|
---|
425 | static void vbmsSolNotify(void *pvState);
|
---|
426 | static void vbmsSolVUIDPutAbsEvent(PVBMSSTATE pState, ushort_t cEvent,
|
---|
427 | int cValue);
|
---|
428 |
|
---|
429 | /**
|
---|
430 | * Open callback for the read queue, which we use as a generic device open
|
---|
431 | * handler.
|
---|
432 | */
|
---|
433 | int vbmsSolOpen(queue_t *pReadQueue, dev_t *pDev, int fFlag, int fMode,
|
---|
434 | cred_t *pCred)
|
---|
435 | {
|
---|
436 | PVBMSSTATE pState = NULL;
|
---|
437 | int rc = VINF_SUCCESS;
|
---|
438 |
|
---|
439 | NOREF(fFlag);
|
---|
440 | NOREF(pCred);
|
---|
441 | LogRelFlow((DEVICE_NAME "::Open, pWriteQueue=%p\n", WR(pReadQueue)));
|
---|
442 |
|
---|
443 | /*
|
---|
444 | * Sanity check on the mode parameter - only open as a driver, not a
|
---|
445 | * module, and we do cloning ourselves.
|
---|
446 | */
|
---|
447 | if (fMode)
|
---|
448 | {
|
---|
449 | LogRel(("::Open: invalid attempt to clone device."));
|
---|
450 | return EINVAL;
|
---|
451 | }
|
---|
452 |
|
---|
453 | pState = &g_OpenNodeState;
|
---|
454 | mutex_enter(&pState->InitMtx);
|
---|
455 | /*
|
---|
456 | * Check and remember our STREAM queue.
|
---|
457 | */
|
---|
458 | if ( pState->pWriteQueue
|
---|
459 | && (pState->pWriteQueue != WR(pReadQueue)))
|
---|
460 | {
|
---|
461 | mutex_exit(&pState->InitMtx);
|
---|
462 | LogRel((DEVICE_NAME "::Open: unexpectedly called with a different queue to previous calls. Exiting.\n"));
|
---|
463 | return EINVAL;
|
---|
464 | }
|
---|
465 | if (!pState->cInits)
|
---|
466 | {
|
---|
467 | /*
|
---|
468 | * Initialize IPRT R0 driver, which internally calls OS-specific r0
|
---|
469 | * init, and create a new session.
|
---|
470 | */
|
---|
471 | rc = VbglInit();
|
---|
472 | if (RT_SUCCESS(rc))
|
---|
473 | {
|
---|
474 | rc = VbglGRAlloc((VMMDevRequestHeader **)
|
---|
475 | &pState->pMouseStatusReq,
|
---|
476 | sizeof(*pState->pMouseStatusReq),
|
---|
477 | VMMDevReq_GetMouseStatus);
|
---|
478 | if (RT_FAILURE(rc))
|
---|
479 | VbglTerminate();
|
---|
480 | else
|
---|
481 | {
|
---|
482 | int rc2;
|
---|
483 | /* Initialise user data for the queues to our state and
|
---|
484 | * vice-versa. */
|
---|
485 | pState->pWriteQueue = WR(pReadQueue);
|
---|
486 | WR(pReadQueue)->q_ptr = (char *)pState;
|
---|
487 | pReadQueue->q_ptr = (char *)pState;
|
---|
488 | qprocson(pReadQueue);
|
---|
489 | /* Enable our IRQ handler. */
|
---|
490 | rc2 = VbglSetMouseNotifyCallback(vbmsSolNotify,
|
---|
491 | (void *)pState);
|
---|
492 | if (RT_FAILURE(rc2))
|
---|
493 | /* Log the failure. I may well have not understood what
|
---|
494 | * is going on here, and the logging may help me. */
|
---|
495 | LogRelFlow(("Failed to install the event handler call-back, rc=%Rrc\n",
|
---|
496 | rc2));
|
---|
497 | }
|
---|
498 | }
|
---|
499 | }
|
---|
500 | if (RT_SUCCESS(rc))
|
---|
501 | ++pState->cInits;
|
---|
502 | mutex_exit(&pState->InitMtx);
|
---|
503 | if (RT_FAILURE(rc))
|
---|
504 | {
|
---|
505 | LogRel(("open time initialisation failed. rc=%d\n", rc));
|
---|
506 | ASMAtomicWriteNullPtr(&pState->pWriteQueue);
|
---|
507 | return EINVAL;
|
---|
508 | }
|
---|
509 | return 0;
|
---|
510 | }
|
---|
511 |
|
---|
512 |
|
---|
513 | /**
|
---|
514 | * Notification callback, called when the VBoxGuest mouse pointer is moved.
|
---|
515 | * We send a VUID event up to user space. We may send a miscalculated event
|
---|
516 | * if a resolution change is half-way through, but that is pretty much to be
|
---|
517 | * expected, so we won't worry about it.
|
---|
518 | */
|
---|
519 | void vbmsSolNotify(void *pvState)
|
---|
520 | {
|
---|
521 | PVBMSSTATE pState = (PVBMSSTATE)pvState;
|
---|
522 | int rc;
|
---|
523 |
|
---|
524 | pState->pMouseStatusReq->mouseFeatures = 0;
|
---|
525 | pState->pMouseStatusReq->pointerXPos = 0;
|
---|
526 | pState->pMouseStatusReq->pointerYPos = 0;
|
---|
527 | rc = VbglGRPerform(&pState->pMouseStatusReq->header);
|
---|
528 | if (RT_SUCCESS(rc))
|
---|
529 | {
|
---|
530 | int cMaxScreenX = pState->cMaxScreenX;
|
---|
531 | int cMaxScreenY = pState->cMaxScreenY;
|
---|
532 | int x = pState->pMouseStatusReq->pointerXPos;
|
---|
533 | int y = pState->pMouseStatusReq->pointerYPos;
|
---|
534 |
|
---|
535 | if (cMaxScreenX && cMaxScreenY)
|
---|
536 | {
|
---|
537 | vbmsSolVUIDPutAbsEvent(pState, LOC_X_ABSOLUTE,
|
---|
538 | x * cMaxScreenX / VMMDEV_MOUSE_RANGE_MAX);
|
---|
539 | vbmsSolVUIDPutAbsEvent(pState, LOC_Y_ABSOLUTE,
|
---|
540 | y * cMaxScreenY / VMMDEV_MOUSE_RANGE_MAX);
|
---|
541 | }
|
---|
542 | }
|
---|
543 | }
|
---|
544 |
|
---|
545 |
|
---|
546 | void vbmsSolVUIDPutAbsEvent(PVBMSSTATE pState, ushort_t cEvent,
|
---|
547 | int cValue)
|
---|
548 | {
|
---|
549 | queue_t *pReadQueue = RD(pState->pWriteQueue);
|
---|
550 | mblk_t *pMBlk = allocb(sizeof(Firm_event), BPRI_HI);
|
---|
551 | Firm_event *pEvent;
|
---|
552 | AssertReturnVoid(cEvent == LOC_X_ABSOLUTE || cEvent == LOC_Y_ABSOLUTE);
|
---|
553 | if (!pMBlk)
|
---|
554 | return; /* If kernel memory is short a missed event is acceptable! */
|
---|
555 | pEvent = (Firm_event *)pMBlk->b_wptr;
|
---|
556 | pEvent->id = cEvent;
|
---|
557 | pEvent->pair_type = FE_PAIR_DELTA;
|
---|
558 | pEvent->pair = cEvent == LOC_X_ABSOLUTE ? LOC_X_DELTA : LOC_Y_DELTA;
|
---|
559 | pEvent->value = cValue;
|
---|
560 | uniqtime32(&pEvent->time);
|
---|
561 | pMBlk->b_wptr += sizeof(Firm_event);
|
---|
562 | /* Put the message on the queue immediately if it is not blocked. */
|
---|
563 | if (canput(pReadQueue->q_next))
|
---|
564 | putnext(pReadQueue, pMBlk);
|
---|
565 | else
|
---|
566 | putq(pReadQueue, pMBlk);
|
---|
567 | }
|
---|
568 |
|
---|
569 |
|
---|
570 | /**
|
---|
571 | * Close callback for the read queue, which we use as a generic device close
|
---|
572 | * handler.
|
---|
573 | */
|
---|
574 | int vbmsSolClose(queue_t *pReadQueue, int fFlag, cred_t *pCred)
|
---|
575 | {
|
---|
576 | PVBMSSTATE pState = (PVBMSSTATE)pReadQueue->q_ptr;
|
---|
577 |
|
---|
578 | LogRelFlow((DEVICE_NAME "::Close, pWriteQueue=%p\n", WR(pReadQueue)));
|
---|
579 | NOREF(fFlag);
|
---|
580 | NOREF(pCred);
|
---|
581 |
|
---|
582 | if (!pState)
|
---|
583 | {
|
---|
584 | Log((DEVICE_NAME "::Close: failed to get pState.\n"));
|
---|
585 | return EFAULT;
|
---|
586 | }
|
---|
587 |
|
---|
588 | mutex_enter(&pState->InitMtx);
|
---|
589 | --pState->cInits;
|
---|
590 | if (!pState->cInits)
|
---|
591 | {
|
---|
592 | VbglSetMouseStatus(0);
|
---|
593 | /* Disable our IRQ handler. */
|
---|
594 | VbglSetMouseNotifyCallback(NULL, NULL);
|
---|
595 | qprocsoff(pReadQueue);
|
---|
596 |
|
---|
597 | /*
|
---|
598 | * Close the session.
|
---|
599 | */
|
---|
600 | ASMAtomicWriteNullPtr(&pState->pWriteQueue);
|
---|
601 | pReadQueue->q_ptr = NULL;
|
---|
602 | VbglGRFree(&pState->pMouseStatusReq->header);
|
---|
603 | VbglTerminate();
|
---|
604 | }
|
---|
605 | mutex_exit(&pState->InitMtx);
|
---|
606 | return 0;
|
---|
607 | }
|
---|
608 |
|
---|
609 |
|
---|
610 | #ifdef TESTCASE
|
---|
611 | /** Simple test of vbmsSolOpen and vbmsSolClose. */
|
---|
612 | static void testOpenClose(RTTEST hTest)
|
---|
613 | {
|
---|
614 | queue_t aQueues[2];
|
---|
615 | dev_t device = 0;
|
---|
616 | int rc;
|
---|
617 |
|
---|
618 | RTTestSub(hTest, "Testing vbmsSolOpen and vbmsSolClose");
|
---|
619 | RT_ZERO(g_OpenNodeState);
|
---|
620 | RT_ZERO(aQueues);
|
---|
621 | doInitQueues(&aQueues[0]);
|
---|
622 | rc = vbmsSolOpen(RD(&aQueues[0]), &device, 0, 0, NULL);
|
---|
623 | RTTEST_CHECK(hTest, rc == 0);
|
---|
624 | RTTEST_CHECK(hTest, g_OpenNodeState.pWriteQueue == WR(&aQueues[0]));
|
---|
625 | vbmsSolClose(RD(&aQueues[0]), 0, NULL);
|
---|
626 | }
|
---|
627 | #endif
|
---|
628 |
|
---|
629 |
|
---|
630 | /* Helper for vbmsSolWPut. */
|
---|
631 | static int vbmsSolDispatchIOCtl(PVBMSSTATE pState, mblk_t *pMBlk);
|
---|
632 |
|
---|
633 | /**
|
---|
634 | * Handler for messages sent from above (user-space and upper modules) which
|
---|
635 | * land in our write queue.
|
---|
636 | */
|
---|
637 | int vbmsSolWPut(queue_t *pWriteQueue, mblk_t *pMBlk)
|
---|
638 | {
|
---|
639 | PVBMSSTATE pState = (PVBMSSTATE)pWriteQueue->q_ptr;
|
---|
640 | LogRelFlowFunc((DEVICE_NAME "::"));
|
---|
641 | switch (pMBlk->b_datap->db_type)
|
---|
642 | {
|
---|
643 | case M_FLUSH:
|
---|
644 | LogRelFlow(("M_FLUSH, FLUSHW=%RTbool, FLUSHR=%RTbool\n",
|
---|
645 | *pMBlk->b_rptr & FLUSHW, *pMBlk->b_rptr & FLUSHR));
|
---|
646 | /* Flush the write queue if so requested. */
|
---|
647 | if (*pMBlk->b_rptr & FLUSHW)
|
---|
648 | flushq(pWriteQueue, FLUSHDATA);
|
---|
649 |
|
---|
650 | /* Flush the read queue if so requested. */
|
---|
651 | if (*pMBlk->b_rptr & FLUSHR)
|
---|
652 | flushq(RD(pWriteQueue), FLUSHDATA);
|
---|
653 |
|
---|
654 | /* We have no one below us to pass the message on to. */
|
---|
655 | return 0;
|
---|
656 | /* M_IOCDATA is additional data attached to (at least) transparent
|
---|
657 | * IOCtls. We handle the two together here and separate them further
|
---|
658 | * down. */
|
---|
659 | case M_IOCTL:
|
---|
660 | case M_IOCDATA:
|
---|
661 | {
|
---|
662 | int err;
|
---|
663 |
|
---|
664 | LogRelFlow(( pMBlk->b_datap->db_type == M_IOCTL
|
---|
665 | ? "M_IOCTL\n" : "M_IOCDATA\n"));
|
---|
666 | err = vbmsSolDispatchIOCtl(pState, pMBlk);
|
---|
667 | if (!err)
|
---|
668 | qreply(pWriteQueue, pMBlk);
|
---|
669 | else
|
---|
670 | miocnak(pWriteQueue, pMBlk, 0, err);
|
---|
671 | break;
|
---|
672 | }
|
---|
673 | default:
|
---|
674 | LogRelFlow(("Unknown command, not acknowledging.\n"));
|
---|
675 | }
|
---|
676 | return 0;
|
---|
677 | }
|
---|
678 |
|
---|
679 |
|
---|
680 | #ifdef TESTCASE
|
---|
681 | /* Constants, definitions and test functions for testWPut. */
|
---|
682 | static const int g_ccTestWPutFirmEvent = VUID_FIRM_EVENT;
|
---|
683 | # define PVGFORMAT (&g_ccTestWPutFirmEvent)
|
---|
684 | # define CBGFORMAT (sizeof(g_ccTestWPutFirmEvent))
|
---|
685 | static const Ms_screen_resolution g_TestResolution = { 640, 480 };
|
---|
686 | # define PMSIOSRES (&g_TestResolution)
|
---|
687 | # define CBMSIOSRES (sizeof(g_TestResolution))
|
---|
688 |
|
---|
689 | static inline bool testSetResolution(RTTEST hTest, queue_t *pWriteQueue,
|
---|
690 | struct msgb *pMBlk)
|
---|
691 | {
|
---|
692 | PVBMSSTATE pState = (PVBMSSTATE)pWriteQueue->q_ptr;
|
---|
693 | RTTEST_CHECK_MSG_RET(hTest, pState->cMaxScreenX
|
---|
694 | == g_TestResolution.width - 1,
|
---|
695 | (hTest, "pState->cMaxScreenX=%d\n",
|
---|
696 | pState->cMaxScreenX), false);
|
---|
697 | RTTEST_CHECK_MSG_RET(hTest, pState->cMaxScreenY
|
---|
698 | == g_TestResolution.height - 1,
|
---|
699 | (hTest, "pState->cMaxScreenY=%d\n",
|
---|
700 | pState->cMaxScreenY), false);
|
---|
701 | return true;
|
---|
702 | }
|
---|
703 |
|
---|
704 | /** Data table for testWPut. */
|
---|
705 | static struct
|
---|
706 | {
|
---|
707 | int iIOCCmd;
|
---|
708 | size_t cbData;
|
---|
709 | const void *pvDataIn;
|
---|
710 | size_t cbDataIn;
|
---|
711 | const void *pvDataOut;
|
---|
712 | size_t cbDataOut;
|
---|
713 | int rcExp;
|
---|
714 | bool (*pfnExtra)(RTTEST hTest, queue_t *pWriteQueue, struct msgb *pMBlk);
|
---|
715 | bool fCanTransparent;
|
---|
716 | } g_asTestWPut[] =
|
---|
717 | {
|
---|
718 | /* iIOCCmd cbData pvDataIn cbDataIn
|
---|
719 | pvDataOut cbDataOut rcExp pfnExtra fCanTransparent */
|
---|
720 | { VUIDGFORMAT, sizeof(int), NULL, 0,
|
---|
721 | PVGFORMAT, CBGFORMAT, 0, NULL, true },
|
---|
722 | { VUIDGFORMAT, sizeof(int) - 1, NULL, 0,
|
---|
723 | NULL, 0, EINVAL, NULL, false },
|
---|
724 | { VUIDGFORMAT, sizeof(int) + 1, NULL, 0,
|
---|
725 | PVGFORMAT, CBGFORMAT, 0, NULL, true },
|
---|
726 | { VUIDSFORMAT, sizeof(int), PVGFORMAT, CBGFORMAT,
|
---|
727 | NULL, 0, 0, NULL, true },
|
---|
728 | { MSIOSRESOLUTION, CBMSIOSRES, PMSIOSRES, CBMSIOSRES,
|
---|
729 | NULL, 0, 0, testSetResolution, true },
|
---|
730 | { VUIDGWHEELINFO, 0, NULL, 0,
|
---|
731 | NULL, 0, EINVAL, NULL, true }
|
---|
732 | };
|
---|
733 |
|
---|
734 | # undef PVGFORMAT
|
---|
735 | # undef CBGFORMAT
|
---|
736 | # undef PMSIOSRES
|
---|
737 | # undef CBMSIOSRES
|
---|
738 |
|
---|
739 | /* Helpers for testWPut. */
|
---|
740 | static void testWPutStreams(RTTEST hTest, unsigned i);
|
---|
741 | static void testWPutTransparent(RTTEST hTest, unsigned i);
|
---|
742 | static void testWPutIOCDataIn(RTTEST hTest, unsigned i);
|
---|
743 | static void testWPutIOCDataOut(RTTEST hTest, unsigned i);
|
---|
744 |
|
---|
745 | /** Test WPut's handling of different IOCtls, which is bulk of the logic in
|
---|
746 | * this file. */
|
---|
747 | static void testWPut(RTTEST hTest)
|
---|
748 | {
|
---|
749 | unsigned i;
|
---|
750 |
|
---|
751 | RTTestSub(hTest, "Testing vbmsWPut");
|
---|
752 | for (i = 0; i < RT_ELEMENTS(g_asTestWPut); ++i)
|
---|
753 | {
|
---|
754 | AssertReturnVoid(g_asTestWPut[i].cbDataIn <= g_asTestWPut[i].cbData);
|
---|
755 | AssertReturnVoid(g_asTestWPut[i].cbDataOut <= g_asTestWPut[i].cbData);
|
---|
756 | testWPutStreams(hTest, i);
|
---|
757 | if (g_asTestWPut[i].fCanTransparent)
|
---|
758 | testWPutTransparent(hTest, i);
|
---|
759 | if (g_asTestWPut[i].fCanTransparent && g_asTestWPut[i].cbDataIn)
|
---|
760 | testWPutIOCDataIn(hTest, i);
|
---|
761 | if (g_asTestWPut[i].fCanTransparent && g_asTestWPut[i].cbDataOut)
|
---|
762 | testWPutIOCDataOut(hTest, i);
|
---|
763 | }
|
---|
764 | }
|
---|
765 |
|
---|
766 |
|
---|
767 | #define MSG_DATA_SIZE 1024
|
---|
768 |
|
---|
769 | /** Simulate sending a streams IOCtl to WPut with the parameters from table
|
---|
770 | * line @a i. */
|
---|
771 | void testWPutStreams(RTTEST hTest, unsigned i)
|
---|
772 | {
|
---|
773 | queue_t aQueues[2];
|
---|
774 | dev_t device = 0;
|
---|
775 | struct msgb *pMBlk = allocb(sizeof(struct iocblk), BPRI_MED);
|
---|
776 | struct msgb *pMBlkCont = allocb(MSG_DATA_SIZE, BPRI_MED);
|
---|
777 | struct iocblk *pIOCBlk = pMBlk ? (struct iocblk *)pMBlk->b_rptr : NULL;
|
---|
778 | int rc, cFormat = 0;
|
---|
779 |
|
---|
780 | AssertReturnVoid(pMBlk);
|
---|
781 | AssertReturnVoidStmt(pMBlkCont, freemsg(pMBlk));
|
---|
782 | RT_ZERO(aQueues);
|
---|
783 | doInitQueues(&aQueues[0]);
|
---|
784 | rc = vbmsSolOpen(RD(&aQueues[0]), &device, 0, 0, NULL);
|
---|
785 | RTTEST_CHECK_MSG(hTest, rc == 0, (hTest, "i=%u, rc=%d\n", i, rc));
|
---|
786 | RTTEST_CHECK_MSG(hTest, g_OpenNodeState.pWriteQueue
|
---|
787 | == WR(&aQueues[0]), (hTest, "i=%u\n", i));
|
---|
788 | pMBlk->b_datap->db_type = M_IOCTL;
|
---|
789 | pIOCBlk->ioc_cmd = g_asTestWPut[i].iIOCCmd;
|
---|
790 | pIOCBlk->ioc_count = g_asTestWPut[i].cbData;
|
---|
791 | AssertReturnVoid(g_asTestWPut[i].cbData <= MSG_DATA_SIZE);
|
---|
792 | memcpy(pMBlkCont->b_rptr, g_asTestWPut[i].pvDataIn,
|
---|
793 | g_asTestWPut[i].cbDataIn);
|
---|
794 | pMBlk->b_cont = pMBlkCont;
|
---|
795 | rc = vbmsSolWPut(WR(&aQueues[0]), pMBlk);
|
---|
796 | RTTEST_CHECK_MSG(hTest, pIOCBlk->ioc_error == g_asTestWPut[i].rcExp,
|
---|
797 | (hTest, "i=%u, IOCBlk.ioc_error=%d\n", i,
|
---|
798 | pIOCBlk->ioc_error));
|
---|
799 | RTTEST_CHECK_MSG(hTest, pIOCBlk->ioc_count == g_asTestWPut[i].cbDataOut,
|
---|
800 | (hTest, "i=%u, ioc_count=%u\n", i, pIOCBlk->ioc_count));
|
---|
801 | RTTEST_CHECK_MSG(hTest, !memcmp(pMBlkCont->b_rptr,
|
---|
802 | g_asTestWPut[i].pvDataOut,
|
---|
803 | g_asTestWPut[i].cbDataOut),
|
---|
804 | (hTest, "i=%u\n", i));
|
---|
805 | /* Hack to ensure that miocpullup() gets called when needed. */
|
---|
806 | if (g_asTestWPut[i].cbData > 0)
|
---|
807 | RTTEST_CHECK_MSG(hTest, pMBlk->b_flag == 1, (hTest, "i=%u\n", i));
|
---|
808 | if (!g_asTestWPut[i].rcExp)
|
---|
809 | RTTEST_CHECK_MSG(hTest, RD(&aQueues[0])->q_first == pMBlk,
|
---|
810 | (hTest, "i=%u\n", i));
|
---|
811 | if (g_asTestWPut[i].pfnExtra)
|
---|
812 | if (!g_asTestWPut[i].pfnExtra(hTest, WR(&aQueues[0]), pMBlk))
|
---|
813 | RTTestPrintf(hTest, RTTESTLVL_ALWAYS, "Called from %s.\n",
|
---|
814 | __PRETTY_FUNCTION__);
|
---|
815 | vbmsSolClose(RD(&aQueues[1]), 0, NULL);
|
---|
816 | freemsg(pMBlk);
|
---|
817 | }
|
---|
818 |
|
---|
819 |
|
---|
820 | #define USER_ADDRESS 0xfeedbacc
|
---|
821 |
|
---|
822 | /** Simulate sending a transparent IOCtl to WPut with the parameters from table
|
---|
823 | * line @a i. */
|
---|
824 | void testWPutTransparent(RTTEST hTest, unsigned i)
|
---|
825 | {
|
---|
826 | queue_t aQueues[2];
|
---|
827 | dev_t device = 0;
|
---|
828 | struct msgb *pMBlk = allocb(sizeof(struct iocblk), BPRI_MED);
|
---|
829 | struct msgb *pMBlkCont = allocb(sizeof(void *), BPRI_MED);
|
---|
830 | struct iocblk *pIOCBlk = pMBlk ? (struct iocblk *)pMBlk->b_rptr : NULL;
|
---|
831 | struct copyreq *pCopyReq;
|
---|
832 | int rc, cFormat = 0;
|
---|
833 |
|
---|
834 | /* if (g_asTestWPut[i].cbDataIn == 0 && g_asTestWPut[i].cbDataOut != 0)
|
---|
835 | return; */ /* This case will be handled once the current ones work. */
|
---|
836 | AssertReturnVoid(pMBlk);
|
---|
837 | AssertReturnVoidStmt(pMBlkCont, freemsg(pMBlk));
|
---|
838 | RT_ZERO(aQueues);
|
---|
839 | doInitQueues(&aQueues[0]);
|
---|
840 | rc = vbmsSolOpen(RD(&aQueues[0]), &device, 0, 0, NULL);
|
---|
841 | RTTEST_CHECK_MSG(hTest, rc == 0, (hTest, "i=%u, rc=%d\n", i, rc));
|
---|
842 | RTTEST_CHECK_MSG(hTest, g_OpenNodeState.pWriteQueue
|
---|
843 | == WR(&aQueues[0]), (hTest, "i=%u\n", i));
|
---|
844 | pMBlk->b_datap->db_type = M_IOCTL;
|
---|
845 | pIOCBlk->ioc_cmd = g_asTestWPut[i].iIOCCmd;
|
---|
846 | pIOCBlk->ioc_count = TRANSPARENT;
|
---|
847 | *(void **)pMBlkCont->b_rptr = (void *)USER_ADDRESS;
|
---|
848 | pMBlk->b_cont = pMBlkCont;
|
---|
849 | rc = vbmsSolWPut(WR(&aQueues[0]), pMBlk);
|
---|
850 | pCopyReq = (struct copyreq *)pMBlk->b_rptr;
|
---|
851 | RTTEST_CHECK_MSG(hTest, ( ( g_asTestWPut[i].cbDataIn
|
---|
852 | && (pMBlk->b_datap->db_type == M_COPYIN))
|
---|
853 | || ( g_asTestWPut[i].cbDataOut
|
---|
854 | && (pMBlk->b_datap->db_type == M_COPYOUT))
|
---|
855 | || ( (g_asTestWPut[i].rcExp == 0)
|
---|
856 | && pMBlk->b_datap->db_type == M_IOCACK)
|
---|
857 | || (pMBlk->b_datap->db_type == M_IOCNAK)),
|
---|
858 | (hTest, "i=%u, db_type=%u\n", i,
|
---|
859 | (unsigned) pMBlk->b_datap->db_type));
|
---|
860 | /* Our TRANSPARENT IOCtls can only return non-zero if they have no payload.
|
---|
861 | * Others should either return zero or be non-TRANSPARENT only. */
|
---|
862 | if (pMBlk->b_datap->db_type == M_IOCNAK)
|
---|
863 | RTTEST_CHECK_MSG(hTest, pIOCBlk->ioc_error == g_asTestWPut[i].rcExp,
|
---|
864 | (hTest, "i=%u, IOCBlk.ioc_error=%d\n", i,
|
---|
865 | pIOCBlk->ioc_error));
|
---|
866 | if (g_asTestWPut[i].cbData)
|
---|
867 | {
|
---|
868 | RTTEST_CHECK_MSG(hTest, pCopyReq->cq_addr == (char *)USER_ADDRESS,
|
---|
869 | (hTest, "i=%u, cq_addr=%p\n", i, pCopyReq->cq_addr));
|
---|
870 | RTTEST_CHECK_MSG( hTest, pCopyReq->cq_size
|
---|
871 | == g_asTestWPut[i].cbDataIn
|
---|
872 | ? g_asTestWPut[i].cbDataIn
|
---|
873 | : g_asTestWPut[i].cbDataOut,
|
---|
874 | (hTest, "i=%u, cq_size=%llu\n", i,
|
---|
875 | (unsigned long long)pCopyReq->cq_size));
|
---|
876 | }
|
---|
877 | /* Implementation detail - check that the private pointer is correctly
|
---|
878 | * set to the user address *for two direction IOCtls* or NULL otherwise. */
|
---|
879 | if (g_asTestWPut[i].cbDataIn && g_asTestWPut[i].cbDataOut)
|
---|
880 | RTTEST_CHECK_MSG(hTest, pCopyReq->cq_private == (mblk_t *)USER_ADDRESS,
|
---|
881 | (hTest, "i=%u, cq_private=%p\n", i,
|
---|
882 | pCopyReq->cq_private));
|
---|
883 | else if ( (pMBlk->b_datap->db_type == M_COPYIN)
|
---|
884 | || (pMBlk->b_datap->db_type == M_COPYOUT))
|
---|
885 | RTTEST_CHECK_MSG(hTest, !pCopyReq->cq_private,
|
---|
886 | (hTest, "i=%u, cq_private=%p\n", i,
|
---|
887 | pCopyReq->cq_private));
|
---|
888 | if (!g_asTestWPut[i].rcExp)
|
---|
889 | RTTEST_CHECK_MSG(hTest, RD(&aQueues[0])->q_first == pMBlk,
|
---|
890 | (hTest, "i=%u\n", i));
|
---|
891 | if (g_asTestWPut[i].pfnExtra && !g_asTestWPut[i].cbData)
|
---|
892 | if (!g_asTestWPut[i].pfnExtra(hTest, WR(&aQueues[0]), pMBlk))
|
---|
893 | RTTestPrintf(hTest, RTTESTLVL_ALWAYS, "Called from %s.\n",
|
---|
894 | __PRETTY_FUNCTION__);
|
---|
895 | vbmsSolClose(RD(&aQueues[1]), 0, NULL);
|
---|
896 | freemsg(pMBlk);
|
---|
897 | }
|
---|
898 |
|
---|
899 |
|
---|
900 | /** Simulate sending follow-on IOCData messages to a transparent IOCtl to WPut
|
---|
901 | * with the parameters from table line @a i. */
|
---|
902 | void testWPutIOCDataIn(RTTEST hTest, unsigned i)
|
---|
903 | {
|
---|
904 | queue_t aQueues[2];
|
---|
905 | dev_t device = 0;
|
---|
906 | struct msgb *pMBlk = allocb(sizeof(struct copyresp), BPRI_MED);
|
---|
907 | struct msgb *pMBlkCont = allocb(MSG_DATA_SIZE, BPRI_MED);
|
---|
908 | struct copyresp *pCopyResp = pMBlk ? (struct copyresp *)pMBlk->b_rptr
|
---|
909 | : NULL;
|
---|
910 | void *pvData = pMBlkCont ? pMBlkCont->b_rptr : NULL;
|
---|
911 | struct copyreq *pCopyReq;
|
---|
912 | int rc, cFormat = 0;
|
---|
913 |
|
---|
914 | AssertReturnVoid(pMBlk);
|
---|
915 | AssertReturnVoidStmt(pMBlkCont, freemsg(pMBlk));
|
---|
916 | RTTestPrintf(hTest, RTTESTLVL_ALWAYS, "%s: i=%u\n", __PRETTY_FUNCTION__,
|
---|
917 | i);
|
---|
918 | AssertReturnVoidStmt(g_asTestWPut[i].cbDataIn, freemsg(pMBlk));
|
---|
919 | RT_ZERO(aQueues);
|
---|
920 | doInitQueues(&aQueues[0]);
|
---|
921 | rc = vbmsSolOpen(RD(&aQueues[0]), &device, 0, 0, NULL);
|
---|
922 | RTTEST_CHECK_MSG(hTest, rc == 0, (hTest, "i=%u, rc=%d\n", i, rc));
|
---|
923 | RTTEST_CHECK_MSG(hTest, g_OpenNodeState.pWriteQueue
|
---|
924 | == WR(&aQueues[0]), (hTest, "i=%u\n", i));
|
---|
925 | pMBlk->b_datap->db_type = M_IOCDATA;
|
---|
926 | pCopyResp->cp_cmd = g_asTestWPut[i].iIOCCmd;
|
---|
927 | if (g_asTestWPut[i].cbDataOut)
|
---|
928 | pCopyResp->cp_private = USER_ADDRESS;
|
---|
929 | AssertReturnVoid(g_asTestWPut[i].cbData <= MSG_DATA_SIZE);
|
---|
930 | memcpy(pMBlkCont->b_rptr, g_asTestWPut[i].pvDataIn, g_asTestWPut[i].cbDataIn);
|
---|
931 | pMBlk->b_cont = pMBlkCont;
|
---|
932 | rc = vbmsSolWPut(WR(&aQueues[0]), pMBlk);
|
---|
933 | pCopyReq = (struct copyreq *)pMBlk->b_rptr;
|
---|
934 | RTTEST_CHECK_MSG(hTest, ( ( g_asTestWPut[i].cbDataOut
|
---|
935 | && (pMBlk->b_datap->db_type == M_COPYOUT))
|
---|
936 | || ( (g_asTestWPut[i].rcExp == 0)
|
---|
937 | && pMBlk->b_datap->db_type == M_IOCACK)
|
---|
938 | || (pMBlk->b_datap->db_type == M_IOCNAK)),
|
---|
939 | (hTest, "i=%u, db_type=%u\n", i,
|
---|
940 | (unsigned) pMBlk->b_datap->db_type));
|
---|
941 | if (g_asTestWPut[i].cbDataOut)
|
---|
942 | {
|
---|
943 | RTTEST_CHECK_MSG(hTest, pCopyReq->cq_addr == (char *)pvData,
|
---|
944 | (hTest, "i=%u, cq_addr=%p\n", i, pCopyReq->cq_addr));
|
---|
945 | RTTEST_CHECK_MSG(hTest, pCopyReq->cq_size == g_asTestWPut[i].cbData,
|
---|
946 | (hTest, "i=%u, cq_size=%llu\n", i,
|
---|
947 | (unsigned long long)pCopyReq->cq_size));
|
---|
948 | RTTEST_CHECK_MSG(hTest, !memcmp(pvData, g_asTestWPut[i].pvDataOut,
|
---|
949 | g_asTestWPut[i].cbDataOut),
|
---|
950 | (hTest, "i=%u\n", i));
|
---|
951 | }
|
---|
952 | RTTEST_CHECK_MSG(hTest, !pCopyReq->cq_private,
|
---|
953 | (hTest, "i=%u, cq_private=%p\n", i,
|
---|
954 | pCopyReq->cq_private));
|
---|
955 | if (!g_asTestWPut[i].rcExp)
|
---|
956 | RTTEST_CHECK_MSG(hTest, RD(&aQueues[0])->q_first == pMBlk,
|
---|
957 | (hTest, "i=%u\n", i));
|
---|
958 | if (g_asTestWPut[i].pfnExtra && !g_asTestWPut[i].cbDataOut)
|
---|
959 | if (!g_asTestWPut[i].pfnExtra(hTest, WR(&aQueues[0]), pMBlk))
|
---|
960 | RTTestPrintf(hTest, RTTESTLVL_ALWAYS, "Called from %s.\n",
|
---|
961 | __PRETTY_FUNCTION__);
|
---|
962 | vbmsSolClose(RD(&aQueues[1]), 0, NULL);
|
---|
963 | freemsg(pMBlk);
|
---|
964 | }
|
---|
965 |
|
---|
966 |
|
---|
967 | /** Simulate sending follow-on IOCData messages to a transparent IOCtl to WPut
|
---|
968 | * with the parameters from table line @a i. */
|
---|
969 | void testWPutIOCDataOut(RTTEST hTest, unsigned i)
|
---|
970 | {
|
---|
971 | queue_t aQueues[2];
|
---|
972 | dev_t device = 0;
|
---|
973 | struct msgb *pMBlk = allocb(sizeof(struct copyresp), BPRI_MED);
|
---|
974 | struct copyresp *pCopyResp = pMBlk ? (struct copyresp *)pMBlk->b_rptr
|
---|
975 | : NULL;
|
---|
976 | int rc, cFormat = 0;
|
---|
977 |
|
---|
978 | AssertReturnVoid(pMBlk);
|
---|
979 | AssertReturnVoidStmt(g_asTestWPut[i].cbDataOut, freemsg(pMBlk));
|
---|
980 | RTTestPrintf(hTest, RTTESTLVL_ALWAYS, "%s: i=%u\n", __PRETTY_FUNCTION__,
|
---|
981 | i);
|
---|
982 | RT_ZERO(aQueues);
|
---|
983 | doInitQueues(&aQueues[0]);
|
---|
984 | rc = vbmsSolOpen(RD(&aQueues[0]), &device, 0, 0, NULL);
|
---|
985 | RTTEST_CHECK_MSG(hTest, rc == 0, (hTest, "i=%u, rc=%d\n", i, rc));
|
---|
986 | RTTEST_CHECK_MSG(hTest, g_OpenNodeState.pWriteQueue
|
---|
987 | == WR(&aQueues[0]), (hTest, "i=%u\n", i));
|
---|
988 | pMBlk->b_datap->db_type = M_IOCDATA;
|
---|
989 | pCopyResp->cp_cmd = g_asTestWPut[i].iIOCCmd;
|
---|
990 | rc = vbmsSolWPut(WR(&aQueues[0]), pMBlk);
|
---|
991 | RTTEST_CHECK_MSG(hTest, pMBlk->b_datap->db_type == M_IOCACK,
|
---|
992 | (hTest, "i=%u, db_type=%u\n", i,
|
---|
993 | (unsigned) pMBlk->b_datap->db_type));
|
---|
994 | if (!g_asTestWPut[i].rcExp)
|
---|
995 | RTTEST_CHECK_MSG(hTest, RD(&aQueues[0])->q_first == pMBlk,
|
---|
996 | (hTest, "i=%u\n", i));
|
---|
997 | vbmsSolClose(RD(&aQueues[1]), 0, NULL);
|
---|
998 | freemsg(pMBlk);
|
---|
999 | }
|
---|
1000 | #endif
|
---|
1001 |
|
---|
1002 |
|
---|
1003 | /** Data transfer direction of an IOCtl. This is used for describing
|
---|
1004 | * transparent IOCtls, and @a UNSPECIFIED is not a valid value for them. */
|
---|
1005 | enum IOCTLDIRECTION
|
---|
1006 | {
|
---|
1007 | /** This IOCtl transfers no data. */
|
---|
1008 | NONE,
|
---|
1009 | /** This IOCtl only transfers data from user to kernel. */
|
---|
1010 | IN,
|
---|
1011 | /** This IOCtl only transfers data from kernel to user. */
|
---|
1012 | OUT,
|
---|
1013 | /** This IOCtl transfers data from user to kernel and back. */
|
---|
1014 | BOTH,
|
---|
1015 | /** We aren't saying anything about how the IOCtl transfers data. */
|
---|
1016 | UNSPECIFIED
|
---|
1017 | };
|
---|
1018 |
|
---|
1019 | /**
|
---|
1020 | * IOCtl handler function.
|
---|
1021 | * @returns 0 on success, error code on failure.
|
---|
1022 | * @param iCmd The IOCtl command number.
|
---|
1023 | * @param pvData Buffer for the user data.
|
---|
1024 | * @param cbBuffer Size of the buffer in @a pvData or zero.
|
---|
1025 | * @param pcbData Where to set the size of the data returned. Required for
|
---|
1026 | * handlers which return data.
|
---|
1027 | * @param prc Where to store the return code. Default is zero. Only
|
---|
1028 | * used for IOCtls without data for convenience of
|
---|
1029 | * implemention.
|
---|
1030 | */
|
---|
1031 | typedef int FNVBMSSOLIOCTL(PVBMSSTATE pState, int iCmd, void *pvData,
|
---|
1032 | size_t cbBuffer, size_t *pcbData, int *prc);
|
---|
1033 | typedef FNVBMSSOLIOCTL *PFNVBMSSOLIOCTL;
|
---|
1034 |
|
---|
1035 | /* Helpers for vbmsSolDispatchIOCtl. */
|
---|
1036 | static int vbmsSolHandleIOCtl(PVBMSSTATE pState, mblk_t *pMBlk,
|
---|
1037 | PFNVBMSSOLIOCTL pfnHandler,
|
---|
1038 | int iCmd, size_t cbCmd,
|
---|
1039 | enum IOCTLDIRECTION enmDirection);
|
---|
1040 | static int vbmsSolVUIDIOCtl(PVBMSSTATE pState, int iCmd, void *pvData,
|
---|
1041 | size_t cbBuffer, size_t *pcbData, int *prc);
|
---|
1042 |
|
---|
1043 | /** Table of supported VUID IOCtls. */
|
---|
1044 | struct
|
---|
1045 | {
|
---|
1046 | /** The IOCtl number. */
|
---|
1047 | int iCmd;
|
---|
1048 | /** The size of the buffer which needs to be copied between user and kernel
|
---|
1049 | * space, or zero if unknown (must be known for tranparent IOCtls). */
|
---|
1050 | size_t cbBuffer;
|
---|
1051 | /** The direction the buffer data needs to be copied. This must be
|
---|
1052 | * specified for transparent IOCtls. */
|
---|
1053 | enum IOCTLDIRECTION enmDirection;
|
---|
1054 | } g_aVUIDIOCtlDescriptions[] =
|
---|
1055 | {
|
---|
1056 | { VUIDGFORMAT, sizeof(int), OUT },
|
---|
1057 | { VUIDSFORMAT, sizeof(int), IN },
|
---|
1058 | { VUIDGADDR, 0, UNSPECIFIED },
|
---|
1059 | { VUIDGADDR, 0, UNSPECIFIED },
|
---|
1060 | { MSIOGETPARMS, sizeof(Ms_parms), OUT },
|
---|
1061 | { MSIOSETPARMS, sizeof(Ms_parms), IN },
|
---|
1062 | { MSIOSRESOLUTION, sizeof(Ms_screen_resolution), IN },
|
---|
1063 | { MSIOBUTTONS, sizeof(int), OUT },
|
---|
1064 | { VUIDGWHEELCOUNT, sizeof(int), OUT },
|
---|
1065 | { VUIDGWHEELINFO, 0, UNSPECIFIED },
|
---|
1066 | { VUIDGWHEELSTATE, 0, UNSPECIFIED },
|
---|
1067 | { VUIDSWHEELSTATE, 0, UNSPECIFIED }
|
---|
1068 | };
|
---|
1069 |
|
---|
1070 | /**
|
---|
1071 | * Handle a STREAMS IOCtl message for our driver on the write stream. This
|
---|
1072 | * function takes care of the IOCtl logic only and does not call qreply() or
|
---|
1073 | * miocnak() at all - the caller must call these on success or failure
|
---|
1074 | * respectively.
|
---|
1075 | * @returns 0 on success or the IOCtl error code on failure.
|
---|
1076 | * @param pState pointer to the state structure.
|
---|
1077 | * @param pMBlk pointer to the STREAMS message block structure.
|
---|
1078 | */
|
---|
1079 | static int vbmsSolDispatchIOCtl(PVBMSSTATE pState, mblk_t *pMBlk)
|
---|
1080 | {
|
---|
1081 | struct iocblk *pIOCBlk = (struct iocblk *)pMBlk->b_rptr;
|
---|
1082 | int iCmd = pIOCBlk->ioc_cmd, iCmdType = iCmd & (0xff << 8);
|
---|
1083 | size_t cbBuffer;
|
---|
1084 | enum IOCTLDIRECTION enmDirection;
|
---|
1085 |
|
---|
1086 | LogRelFlowFunc((DEVICE_NAME "::pIOCBlk=%p, iCmdType=%c, iCmd=0x%x\n",
|
---|
1087 | pIOCBlk, (char) (iCmdType >> 8), (unsigned)iCmd));
|
---|
1088 | switch (iCmdType)
|
---|
1089 | {
|
---|
1090 | case MSIOC:
|
---|
1091 | case VUIOC:
|
---|
1092 | {
|
---|
1093 | unsigned i;
|
---|
1094 |
|
---|
1095 | for (i = 0; i < RT_ELEMENTS(g_aVUIDIOCtlDescriptions); ++i)
|
---|
1096 | if (g_aVUIDIOCtlDescriptions[i].iCmd == iCmd)
|
---|
1097 | {
|
---|
1098 | cbBuffer = g_aVUIDIOCtlDescriptions[i].cbBuffer;
|
---|
1099 | enmDirection = g_aVUIDIOCtlDescriptions[i].enmDirection;
|
---|
1100 | return vbmsSolHandleIOCtl(pState, pMBlk,
|
---|
1101 | vbmsSolVUIDIOCtl, iCmd,
|
---|
1102 | cbBuffer, enmDirection);
|
---|
1103 | }
|
---|
1104 | return EINVAL;
|
---|
1105 | }
|
---|
1106 | default:
|
---|
1107 | return ENOTTY;
|
---|
1108 | }
|
---|
1109 | }
|
---|
1110 |
|
---|
1111 |
|
---|
1112 | /* Helpers for vbmsSolHandleIOCtl. */
|
---|
1113 | static int vbmsSolHandleIOCtlData(PVBMSSTATE pState, mblk_t *pMBlk,
|
---|
1114 | PFNVBMSSOLIOCTL pfnHandler, int iCmd,
|
---|
1115 | size_t cbCmd,
|
---|
1116 | enum IOCTLDIRECTION enmDirection);
|
---|
1117 |
|
---|
1118 | static int vbmsSolHandleTransparentIOCtl(PVBMSSTATE pState, mblk_t *pMBlk,
|
---|
1119 | PFNVBMSSOLIOCTL pfnHandler,
|
---|
1120 | int iCmd, size_t cbCmd,
|
---|
1121 | enum IOCTLDIRECTION enmDirection);
|
---|
1122 |
|
---|
1123 | static int vbmsSolHandleIStrIOCtl(PVBMSSTATE pState, mblk_t *pMBlk,
|
---|
1124 | PFNVBMSSOLIOCTL pfnHandler, int iCmd);
|
---|
1125 |
|
---|
1126 | static void vbmsSolAcknowledgeIOCtl(mblk_t *pMBlk, int cbData, int rc)
|
---|
1127 | {
|
---|
1128 | struct iocblk *pIOCBlk = (struct iocblk *)pMBlk->b_rptr;
|
---|
1129 |
|
---|
1130 | pMBlk->b_datap->db_type = M_IOCACK;
|
---|
1131 | pIOCBlk->ioc_count = cbData;
|
---|
1132 | pIOCBlk->ioc_rval = rc;
|
---|
1133 | pIOCBlk->ioc_error = 0;
|
---|
1134 | }
|
---|
1135 |
|
---|
1136 | /**
|
---|
1137 | * Generic code for handling STREAMS-specific IOCtl logic and boilerplate. It
|
---|
1138 | * calls the IOCtl handler passed to it without the handler having to be aware
|
---|
1139 | * of STREAMS structures, or whether this is a transparent (traditional) or an
|
---|
1140 | * I_STR (using a STREAMS structure to describe the data) IOCtl. With the
|
---|
1141 | * caveat that we only support transparent IOCtls which pass all data in a
|
---|
1142 | * single buffer of a fixed size (I_STR IOCtls are restricted to a single
|
---|
1143 | * buffer anyway, but the caller can choose the buffer size).
|
---|
1144 | * @returns 0 on success or the IOCtl error code on failure.
|
---|
1145 | * @param pState pointer to the state structure.
|
---|
1146 | * @param pMBlk pointer to the STREAMS message block structure.
|
---|
1147 | * @param pfnHandler pointer to the right IOCtl handler function for this
|
---|
1148 | * IOCtl number.
|
---|
1149 | * @param iCmd IOCtl command number.
|
---|
1150 | * @param cbCmd size of the user space buffer for this IOCtl number,
|
---|
1151 | * used for processing transparent IOCtls. Pass zero
|
---|
1152 | * for IOCtls with no maximum buffer size (which will
|
---|
1153 | * not be able to be handled as transparent) or with
|
---|
1154 | * no argument.
|
---|
1155 | * @param enmDirection data transfer direction of the IOCtl.
|
---|
1156 | */
|
---|
1157 | static int vbmsSolHandleIOCtl(PVBMSSTATE pState, mblk_t *pMBlk,
|
---|
1158 | PFNVBMSSOLIOCTL pfnHandler, int iCmd,
|
---|
1159 | size_t cbCmd, enum IOCTLDIRECTION enmDirection)
|
---|
1160 | {
|
---|
1161 | struct iocblk *pIOCBlk = (struct iocblk *)pMBlk->b_rptr;
|
---|
1162 |
|
---|
1163 | LogFlowFunc(("iCmd=0x%x, cbBuffer=%d, enmDirection=%d\n",
|
---|
1164 | (unsigned)iCmd, (int)cbCmd, (int)enmDirection));
|
---|
1165 | if (pMBlk->b_datap->db_type == M_IOCDATA)
|
---|
1166 | return vbmsSolHandleIOCtlData(pState, pMBlk, pfnHandler, iCmd,
|
---|
1167 | cbCmd, enmDirection);
|
---|
1168 | else if ( pMBlk->b_datap->db_type == M_IOCTL
|
---|
1169 | && pIOCBlk->ioc_count == TRANSPARENT)
|
---|
1170 | return vbmsSolHandleTransparentIOCtl(pState, pMBlk, pfnHandler,
|
---|
1171 | iCmd, cbCmd, enmDirection);
|
---|
1172 | else if (pMBlk->b_datap->db_type == M_IOCTL)
|
---|
1173 | return vbmsSolHandleIStrIOCtl(pState, pMBlk, pfnHandler, iCmd);
|
---|
1174 | return EINVAL;
|
---|
1175 | }
|
---|
1176 |
|
---|
1177 |
|
---|
1178 | /**
|
---|
1179 | * Helper for vbmsSolHandleIOCtl. This rather complicated-looking
|
---|
1180 | * code is basically the standard boilerplate for handling any streams IOCtl
|
---|
1181 | * additional data, which we currently only use for transparent IOCtls.
|
---|
1182 | * @copydoc vbmsSolHandleIOCtl
|
---|
1183 | */
|
---|
1184 | static int vbmsSolHandleIOCtlData(PVBMSSTATE pState, mblk_t *pMBlk,
|
---|
1185 | PFNVBMSSOLIOCTL pfnHandler, int iCmd,
|
---|
1186 | size_t cbCmd,
|
---|
1187 | enum IOCTLDIRECTION enmDirection)
|
---|
1188 | {
|
---|
1189 | struct copyresp *pCopyResp = (struct copyresp *)pMBlk->b_rptr;
|
---|
1190 |
|
---|
1191 | LogFlowFunc(("iCmd=0x%x, cbBuffer=%d, enmDirection=%d, cp_rval=%d, cp_private=%p\n",
|
---|
1192 | (unsigned)iCmd, (int)cbCmd, (int)enmDirection,
|
---|
1193 | (int)(uintptr_t)pCopyResp->cp_rval,
|
---|
1194 | (void *)pCopyResp->cp_private));
|
---|
1195 | if (pCopyResp->cp_rval) /* cp_rval is a pointer used as a boolean. */
|
---|
1196 | {
|
---|
1197 | freemsg(pMBlk);
|
---|
1198 | return EAGAIN;
|
---|
1199 | }
|
---|
1200 | if ((pCopyResp->cp_private && enmDirection == BOTH) || enmDirection == IN)
|
---|
1201 | {
|
---|
1202 | size_t cbData = 0;
|
---|
1203 | void *pvData = NULL;
|
---|
1204 | int err;
|
---|
1205 |
|
---|
1206 | if (!pMBlk->b_cont)
|
---|
1207 | return EINVAL;
|
---|
1208 | if (enmDirection == BOTH && !pCopyResp->cp_private)
|
---|
1209 | return EINVAL;
|
---|
1210 | pvData = pMBlk->b_cont->b_rptr;
|
---|
1211 | err = pfnHandler(pState, iCmd, pvData, cbCmd, &cbData, NULL);
|
---|
1212 | if (!err && enmDirection == BOTH)
|
---|
1213 | mcopyout(pMBlk, NULL, cbData, pCopyResp->cp_private, NULL);
|
---|
1214 | else if (!err && enmDirection == IN)
|
---|
1215 | vbmsSolAcknowledgeIOCtl(pMBlk, 0, 0);
|
---|
1216 | return err;
|
---|
1217 | }
|
---|
1218 | else
|
---|
1219 | {
|
---|
1220 | AssertReturn(enmDirection == OUT || enmDirection == BOTH, EINVAL);
|
---|
1221 | vbmsSolAcknowledgeIOCtl(pMBlk, 0, 0);
|
---|
1222 | return 0;
|
---|
1223 | }
|
---|
1224 | }
|
---|
1225 |
|
---|
1226 | /**
|
---|
1227 | * Helper for vbmsSolHandleIOCtl. This rather complicated-looking
|
---|
1228 | * code is basically the standard boilerplate for handling transparent IOCtls,
|
---|
1229 | * that is, IOCtls which are not re-packed inside STREAMS IOCtls.
|
---|
1230 | * @copydoc vbmsSolHandleIOCtl
|
---|
1231 | */
|
---|
1232 | int vbmsSolHandleTransparentIOCtl(PVBMSSTATE pState, mblk_t *pMBlk,
|
---|
1233 | PFNVBMSSOLIOCTL pfnHandler, int iCmd,
|
---|
1234 | size_t cbCmd,
|
---|
1235 | enum IOCTLDIRECTION enmDirection)
|
---|
1236 | {
|
---|
1237 | int err = 0, rc = 0;
|
---|
1238 | size_t cbData = 0;
|
---|
1239 |
|
---|
1240 | LogFlowFunc(("iCmd=0x%x, cbBuffer=%d, enmDirection=%d\n",
|
---|
1241 | (unsigned)iCmd, (int)cbCmd, (int)enmDirection));
|
---|
1242 | if ( (enmDirection != NONE && !pMBlk->b_cont)
|
---|
1243 | || enmDirection == UNSPECIFIED)
|
---|
1244 | return EINVAL;
|
---|
1245 | if (enmDirection == IN || enmDirection == BOTH)
|
---|
1246 | {
|
---|
1247 | void *pUserAddr = NULL;
|
---|
1248 | /* We only need state data if there is something to copy back. */
|
---|
1249 | if (enmDirection == BOTH)
|
---|
1250 | pUserAddr = *(void **)pMBlk->b_cont->b_rptr;
|
---|
1251 | mcopyin(pMBlk, pUserAddr /* state data */, cbCmd, NULL);
|
---|
1252 | }
|
---|
1253 | else if (enmDirection == OUT)
|
---|
1254 | {
|
---|
1255 | mblk_t *pMBlkOut = allocb(cbCmd, BPRI_MED);
|
---|
1256 | void *pvData;
|
---|
1257 |
|
---|
1258 | if (!pMBlkOut)
|
---|
1259 | return EAGAIN;
|
---|
1260 | pvData = pMBlkOut->b_rptr;
|
---|
1261 | err = pfnHandler(pState, iCmd, pvData, cbCmd, &cbData, NULL);
|
---|
1262 | if (!err)
|
---|
1263 | mcopyout(pMBlk, NULL, cbData, NULL, pMBlkOut);
|
---|
1264 | else
|
---|
1265 | freemsg(pMBlkOut);
|
---|
1266 | }
|
---|
1267 | else
|
---|
1268 | {
|
---|
1269 | AssertReturn(enmDirection == NONE, EINVAL);
|
---|
1270 | err = pfnHandler(pState, iCmd, NULL, 0, NULL, &rc);
|
---|
1271 | if (!err)
|
---|
1272 | vbmsSolAcknowledgeIOCtl(pMBlk, 0, rc);
|
---|
1273 | }
|
---|
1274 | return err;
|
---|
1275 | }
|
---|
1276 |
|
---|
1277 | /**
|
---|
1278 | * Helper for vbmsSolHandleIOCtl. This rather complicated-looking
|
---|
1279 | * code is basically the standard boilerplate for handling any streams IOCtl.
|
---|
1280 | * @copydoc vbmsSolHandleIOCtl
|
---|
1281 | */
|
---|
1282 | static int vbmsSolHandleIStrIOCtl(PVBMSSTATE pState, mblk_t *pMBlk,
|
---|
1283 | PFNVBMSSOLIOCTL pfnHandler, int iCmd)
|
---|
1284 | {
|
---|
1285 | struct iocblk *pIOCBlk = (struct iocblk *)pMBlk->b_rptr;
|
---|
1286 | uint_t cbBuffer = pIOCBlk->ioc_count;
|
---|
1287 | void *pvData = NULL;
|
---|
1288 | int err, rc = 0;
|
---|
1289 | size_t cbData = 0;
|
---|
1290 |
|
---|
1291 | LogFlowFunc(("iCmd=0x%x, cbBuffer=%u, b_cont=%p\n",
|
---|
1292 | (unsigned)iCmd, cbBuffer, (void *)pMBlk->b_cont));
|
---|
1293 | if (cbBuffer && !pMBlk->b_cont)
|
---|
1294 | return EINVAL;
|
---|
1295 | /* Repack the whole buffer into a single message block if needed. */
|
---|
1296 | if (cbBuffer)
|
---|
1297 | {
|
---|
1298 | err = miocpullup(pMBlk, cbBuffer);
|
---|
1299 | if (err)
|
---|
1300 | return err;
|
---|
1301 | pvData = pMBlk->b_cont->b_rptr;
|
---|
1302 | }
|
---|
1303 | else if (pMBlk->b_cont) /* consms forgets to set ioc_count. */
|
---|
1304 | {
|
---|
1305 | pvData = pMBlk->b_cont->b_rptr;
|
---|
1306 | cbBuffer = pMBlk->b_cont->b_datap->db_lim
|
---|
1307 | - pMBlk->b_cont->b_datap->db_base;
|
---|
1308 | }
|
---|
1309 | err = pfnHandler(pState, iCmd, pvData, cbBuffer, &cbData, &rc);
|
---|
1310 | if (!err)
|
---|
1311 | {
|
---|
1312 | LogRelFlowFunc(("pMBlk=%p, pMBlk->b_datap=%p, pMBlk->b_rptr=%p\n",
|
---|
1313 | pMBlk, pMBlk->b_datap, pMBlk->b_rptr));
|
---|
1314 | vbmsSolAcknowledgeIOCtl(pMBlk, cbData, rc);
|
---|
1315 | }
|
---|
1316 | return err;
|
---|
1317 | }
|
---|
1318 |
|
---|
1319 |
|
---|
1320 | /**
|
---|
1321 | * Handle a VUID input device IOCtl.
|
---|
1322 | * @copydoc FNVBMSSOLIOCTL
|
---|
1323 | */
|
---|
1324 | static int vbmsSolVUIDIOCtl(PVBMSSTATE pState, int iCmd, void *pvData,
|
---|
1325 | size_t cbBuffer, size_t *pcbData, int *prc)
|
---|
1326 | {
|
---|
1327 | LogRelFlowFunc((DEVICE_NAME "::pvData=%p " /* no '\n' */, pvData));
|
---|
1328 | switch (iCmd)
|
---|
1329 | {
|
---|
1330 | case VUIDGFORMAT:
|
---|
1331 | {
|
---|
1332 | LogRelFlowFunc(("VUIDGFORMAT\n"));
|
---|
1333 | if (cbBuffer < sizeof(int))
|
---|
1334 | return EINVAL;
|
---|
1335 | *(int *)pvData = VUID_FIRM_EVENT;
|
---|
1336 | *pcbData = sizeof(int);
|
---|
1337 | return 0;
|
---|
1338 | }
|
---|
1339 | case VUIDSFORMAT:
|
---|
1340 | LogRelFlowFunc(("VUIDSFORMAT\n"));
|
---|
1341 | /* We define our native format to be VUID_FIRM_EVENT, so there
|
---|
1342 | * is nothing more to do and we exit here on success or on
|
---|
1343 | * failure. */
|
---|
1344 | return 0;
|
---|
1345 | case VUIDGADDR:
|
---|
1346 | case VUIDSADDR:
|
---|
1347 | LogRelFlowFunc(("VUIDGADDR/VUIDSADDR\n"));
|
---|
1348 | return ENOTTY;
|
---|
1349 | case MSIOGETPARMS:
|
---|
1350 | {
|
---|
1351 | Ms_parms parms = { 0 };
|
---|
1352 |
|
---|
1353 | LogRelFlowFunc(("MSIOGETPARMS\n"));
|
---|
1354 | if (cbBuffer < sizeof(Ms_parms))
|
---|
1355 | return EINVAL;
|
---|
1356 | *(Ms_parms *)pvData = parms;
|
---|
1357 | *pcbData = sizeof(Ms_parms);
|
---|
1358 | return 0;
|
---|
1359 | }
|
---|
1360 | case MSIOSETPARMS:
|
---|
1361 | LogRelFlowFunc(("MSIOSETPARMS\n"));
|
---|
1362 | return 0;
|
---|
1363 | case MSIOSRESOLUTION:
|
---|
1364 | {
|
---|
1365 | Ms_screen_resolution *pResolution = (Ms_screen_resolution *)pvData;
|
---|
1366 | int rc;
|
---|
1367 |
|
---|
1368 | LogRelFlowFunc(("MSIOSRESOLUTION, cbBuffer=%d, sizeof(Ms_screen_resolution)=%d\n",
|
---|
1369 | (int) cbBuffer,
|
---|
1370 | (int) sizeof(Ms_screen_resolution)));
|
---|
1371 | if (cbBuffer < sizeof(Ms_screen_resolution))
|
---|
1372 | return EINVAL;
|
---|
1373 | LogRelFlowFunc(("%dx%d\n", pResolution->width,
|
---|
1374 | pResolution->height));
|
---|
1375 | pState->cMaxScreenX = pResolution->width - 1;
|
---|
1376 | pState->cMaxScreenY = pResolution->height - 1;
|
---|
1377 | /* Note: we don't disable this again until session close. */
|
---|
1378 | rc = VbglSetMouseStatus( VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE
|
---|
1379 | | VMMDEV_MOUSE_NEW_PROTOCOL);
|
---|
1380 | if (RT_SUCCESS(rc))
|
---|
1381 | return 0;
|
---|
1382 | pState->cMaxScreenX = 0;
|
---|
1383 | pState->cMaxScreenY = 0;
|
---|
1384 | return ENODEV;
|
---|
1385 | }
|
---|
1386 | case MSIOBUTTONS:
|
---|
1387 | {
|
---|
1388 | LogRelFlowFunc(("MSIOBUTTONS\n"));
|
---|
1389 | if (cbBuffer < sizeof(int))
|
---|
1390 | return EINVAL;
|
---|
1391 | *(int *)pvData = 0;
|
---|
1392 | *pcbData = sizeof(int);
|
---|
1393 | return 0;
|
---|
1394 | }
|
---|
1395 | case VUIDGWHEELCOUNT:
|
---|
1396 | {
|
---|
1397 | LogRelFlowFunc(("VUIDGWHEELCOUNT\n"));
|
---|
1398 | if (cbBuffer < sizeof(int))
|
---|
1399 | return EINVAL;
|
---|
1400 | *(int *)pvData = 0;
|
---|
1401 | *pcbData = sizeof(int);
|
---|
1402 | return 0;
|
---|
1403 | }
|
---|
1404 | case VUIDGWHEELINFO:
|
---|
1405 | case VUIDGWHEELSTATE:
|
---|
1406 | case VUIDSWHEELSTATE:
|
---|
1407 | LogRelFlowFunc(("VUIDGWHEELINFO/VUIDGWHEELSTATE/VUIDSWHEELSTATE\n"));
|
---|
1408 | return EINVAL;
|
---|
1409 | default:
|
---|
1410 | LogRelFlowFunc(("Invalid IOCtl command %x\n", iCmd));
|
---|
1411 | return EINVAL;
|
---|
1412 | }
|
---|
1413 | }
|
---|
1414 |
|
---|
1415 |
|
---|
1416 | #ifdef TESTCASE
|
---|
1417 | int main(void)
|
---|
1418 | {
|
---|
1419 | RTTEST hTest;
|
---|
1420 | int rc = RTTestInitAndCreate("tstVBoxGuest-solaris", &hTest);
|
---|
1421 | if (rc)
|
---|
1422 | return rc;
|
---|
1423 | RTTestBanner(hTest);
|
---|
1424 | test_init(hTest);
|
---|
1425 | testOpenClose(hTest);
|
---|
1426 | testWPut(hTest);
|
---|
1427 |
|
---|
1428 | /*
|
---|
1429 | * Summary.
|
---|
1430 | */
|
---|
1431 | return RTTestSummaryAndDestroy(hTest);
|
---|
1432 | }
|
---|
1433 | #endif
|
---|