1 | /* $Revision: 21461 $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxGuestLibR0 - Generic VMMDev request management.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2009 Sun Microsystems, Inc.
|
---|
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 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
18 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
19 | * additional information or have any questions.
|
---|
20 | */
|
---|
21 |
|
---|
22 | #include "VBGLInternal.h"
|
---|
23 | #include <iprt/asm.h>
|
---|
24 | #include <iprt/assert.h>
|
---|
25 | #include <iprt/string.h>
|
---|
26 |
|
---|
27 | DECLVBGL(int) VbglGRAlloc (VMMDevRequestHeader **ppReq, uint32_t cbSize, VMMDevRequestType reqType)
|
---|
28 | {
|
---|
29 | VMMDevRequestHeader *pReq;
|
---|
30 | int rc = vbglR0Enter ();
|
---|
31 |
|
---|
32 | if (RT_FAILURE(rc))
|
---|
33 | return rc;
|
---|
34 |
|
---|
35 | if (!ppReq || cbSize < sizeof (VMMDevRequestHeader))
|
---|
36 | {
|
---|
37 | dprintf(("VbglGRAlloc: Invalid parameter: ppReq = %p, cbSize = %d\n", ppReq, cbSize));
|
---|
38 | return VERR_INVALID_PARAMETER;
|
---|
39 | }
|
---|
40 |
|
---|
41 | pReq = (VMMDevRequestHeader *)VbglPhysHeapAlloc (cbSize);
|
---|
42 | if (!pReq)
|
---|
43 | {
|
---|
44 | AssertMsgFailed(("VbglGRAlloc: no memory\n"));
|
---|
45 | rc = VERR_NO_MEMORY;
|
---|
46 | }
|
---|
47 | else
|
---|
48 | {
|
---|
49 | memset(pReq, 0xAA, cbSize);
|
---|
50 |
|
---|
51 | pReq->size = cbSize;
|
---|
52 | pReq->version = VMMDEV_REQUEST_HEADER_VERSION;
|
---|
53 | pReq->requestType = reqType;
|
---|
54 | pReq->rc = VERR_GENERAL_FAILURE;
|
---|
55 | pReq->reserved1 = 0;
|
---|
56 | pReq->reserved2 = 0;
|
---|
57 |
|
---|
58 | *ppReq = pReq;
|
---|
59 | }
|
---|
60 |
|
---|
61 | return rc;
|
---|
62 | }
|
---|
63 |
|
---|
64 | DECLVBGL(int) VbglGRPerform (VMMDevRequestHeader *pReq)
|
---|
65 | {
|
---|
66 | RTCCPHYS physaddr;
|
---|
67 | int rc = vbglR0Enter ();
|
---|
68 |
|
---|
69 | if (RT_FAILURE(rc))
|
---|
70 | return rc;
|
---|
71 |
|
---|
72 | if (!pReq)
|
---|
73 | return VERR_INVALID_PARAMETER;
|
---|
74 |
|
---|
75 | physaddr = VbglPhysHeapGetPhysAddr (pReq);
|
---|
76 | if ( !physaddr
|
---|
77 | || (physaddr >> 32) != 0) /* Port IO is 32 bit. */
|
---|
78 | {
|
---|
79 | rc = VERR_VBGL_INVALID_ADDR;
|
---|
80 | }
|
---|
81 | else
|
---|
82 | {
|
---|
83 | ASMOutU32(g_vbgldata.portVMMDev + VMMDEV_PORT_OFF_REQUEST, (uint32_t)physaddr);
|
---|
84 | /* Make the compiler aware that the host has changed memory. */
|
---|
85 | ASMCompilerBarrier();
|
---|
86 | rc = pReq->rc;
|
---|
87 | }
|
---|
88 | return rc;
|
---|
89 | }
|
---|
90 |
|
---|
91 | DECLVBGL(void) VbglGRFree (VMMDevRequestHeader *pReq)
|
---|
92 | {
|
---|
93 | int rc = vbglR0Enter ();
|
---|
94 |
|
---|
95 | if (RT_FAILURE(rc))
|
---|
96 | return;
|
---|
97 |
|
---|
98 | VbglPhysHeapFree (pReq);
|
---|
99 | }
|
---|
100 |
|
---|