1 | /** @file
|
---|
2 | *
|
---|
3 | * VBoxGuestLib - A support library for VirtualBox guest additions:
|
---|
4 | * Generic VMMDev request management
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2006 InnoTek Systemberatung GmbH
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License as published by the Free Software Foundation,
|
---|
14 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
15 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
16 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | *
|
---|
18 | * If you received this file as part of a commercial VirtualBox
|
---|
19 | * distribution, then only the terms of your commercial VirtualBox
|
---|
20 | * license agreement apply instead of the previous paragraph.
|
---|
21 | */
|
---|
22 |
|
---|
23 | #include <VBox/VBoxGuestLib.h>
|
---|
24 | #include "VBGLInternal.h"
|
---|
25 | #include <iprt/asm.h>
|
---|
26 |
|
---|
27 | #if defined(__LINUX__) && defined(__KERNEL__)
|
---|
28 | #include <linux/string.h>
|
---|
29 | #else
|
---|
30 | #include <string.h>
|
---|
31 | #endif
|
---|
32 |
|
---|
33 | DECLVBGL(int) VbglGRAlloc (VMMDevRequestHeader **ppReq, uint32_t cbSize, VMMDevRequestType reqType)
|
---|
34 | {
|
---|
35 | int rc = VbglEnter ();
|
---|
36 | VMMDevRequestHeader *pReq;
|
---|
37 |
|
---|
38 | if (VBOX_FAILURE(rc))
|
---|
39 | {
|
---|
40 | return rc;
|
---|
41 | }
|
---|
42 |
|
---|
43 | if (!ppReq || cbSize < sizeof (VMMDevRequestHeader))
|
---|
44 | {
|
---|
45 | dprintf(("VbglGRAlloc: Invalid parameter: ppReq = %p, cbSize = %d\n", ppReq, cbSize));
|
---|
46 | return VERR_INVALID_PARAMETER;
|
---|
47 | }
|
---|
48 |
|
---|
49 | pReq = (VMMDevRequestHeader *)VbglPhysHeapAlloc (cbSize);
|
---|
50 |
|
---|
51 | if (!pReq)
|
---|
52 | {
|
---|
53 | dprintf(("VbglGRAlloc: no memory\n"));
|
---|
54 | rc = VERR_NO_MEMORY;
|
---|
55 | }
|
---|
56 | else
|
---|
57 | {
|
---|
58 | memset(pReq, 0xAA, cbSize);
|
---|
59 |
|
---|
60 | pReq->size = cbSize;
|
---|
61 | pReq->version = VMMDEV_REQUEST_HEADER_VERSION;
|
---|
62 | pReq->requestType = reqType;
|
---|
63 | pReq->rc = VERR_GENERAL_FAILURE;
|
---|
64 | pReq->reserved1 = 0;
|
---|
65 | pReq->reserved2 = 0;
|
---|
66 |
|
---|
67 | *ppReq = pReq;
|
---|
68 | }
|
---|
69 |
|
---|
70 | return rc;
|
---|
71 | }
|
---|
72 |
|
---|
73 | DECLVBGL(int) VbglGRPerform (VMMDevRequestHeader *pReq)
|
---|
74 | {
|
---|
75 | RTCCPHYS physaddr;
|
---|
76 | int rc = VbglEnter ();
|
---|
77 |
|
---|
78 | if (VBOX_FAILURE(rc))
|
---|
79 | {
|
---|
80 | return rc;
|
---|
81 | }
|
---|
82 |
|
---|
83 | if (!pReq)
|
---|
84 | {
|
---|
85 | return VERR_INVALID_PARAMETER;
|
---|
86 | }
|
---|
87 |
|
---|
88 | if (g_vbgldata.portVMMDev == 0)
|
---|
89 | {
|
---|
90 | return VERR_VBGL_NOT_INITIALIZED;
|
---|
91 | }
|
---|
92 |
|
---|
93 | physaddr = VbglPhysHeapGetPhysAddr (pReq);
|
---|
94 |
|
---|
95 | if (!physaddr)
|
---|
96 | {
|
---|
97 | rc = VERR_VBGL_INVALID_ADDR;
|
---|
98 | }
|
---|
99 | else
|
---|
100 | {
|
---|
101 | ASMOutU32(g_vbgldata.portVMMDev + PORT_VMMDEV_REQUEST_OFFSET, (uint32_t)physaddr);
|
---|
102 |
|
---|
103 | rc = pReq->rc;
|
---|
104 | }
|
---|
105 | return rc;
|
---|
106 | }
|
---|
107 |
|
---|
108 | DECLVBGL(void) VbglGRFree (VMMDevRequestHeader *pReq)
|
---|
109 | {
|
---|
110 | int rc = VbglEnter ();
|
---|
111 |
|
---|
112 | if (VBOX_FAILURE(rc))
|
---|
113 | {
|
---|
114 | return;
|
---|
115 | }
|
---|
116 |
|
---|
117 | VbglPhysHeapFree (pReq);
|
---|
118 | }
|
---|