VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/solaris/vbi/memobj-r0drv-solaris.c@ 21292

Last change on this file since 21292 was 20526, checked in by vboxsync, 16 years ago

rtR0MemObjNativeAllocLow/solaris: removed misplaced assertion (it belongs in vbi_lowmem_alloc, not here).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 11.4 KB
Line 
1/* $Id: memobj-r0drv-solaris.c 20526 2009-06-13 20:18:20Z vboxsync $ */
2/** @file
3 * IPRT - Ring-0 Memory Objects, Solaris.
4 */
5
6/*
7 * Copyright (C) 2006-2007 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 * 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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
27 * Clara, CA 95054 USA or visit http://www.sun.com if you need
28 * additional information or have any questions.
29 */
30
31
32/*******************************************************************************
33* Header Files *
34*******************************************************************************/
35#include "the-solaris-kernel.h"
36
37#include <iprt/memobj.h>
38#include <iprt/mem.h>
39#include <iprt/err.h>
40#include <iprt/assert.h>
41#include <iprt/log.h>
42#include <iprt/param.h>
43#include <iprt/process.h>
44#include "internal/memobj.h"
45
46
47/*******************************************************************************
48* Structures and Typedefs *
49*******************************************************************************/
50/**
51 * The Solaris version of the memory object structure.
52 */
53typedef struct RTR0MEMOBJSOLARIS
54{
55 /** The core structure. */
56 RTR0MEMOBJINTERNAL Core;
57 /** Pointer to kernel memory cookie. */
58 ddi_umem_cookie_t Cookie;
59 /** Shadow locked pages. */
60 void *handle;
61} RTR0MEMOBJSOLARIS, *PRTR0MEMOBJSOLARIS;
62
63
64
65int rtR0MemObjNativeFree(RTR0MEMOBJ pMem)
66{
67 PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)pMem;
68
69 switch (pMemSolaris->Core.enmType)
70 {
71 case RTR0MEMOBJTYPE_LOW:
72 vbi_lowmem_free(pMemSolaris->Core.pv, pMemSolaris->Core.cb);
73 break;
74
75 case RTR0MEMOBJTYPE_CONT:
76 vbi_contig_free(pMemSolaris->Core.pv, pMemSolaris->Core.cb);
77 break;
78
79 case RTR0MEMOBJTYPE_PAGE:
80 ddi_umem_free(pMemSolaris->Cookie);
81 break;
82
83 case RTR0MEMOBJTYPE_LOCK:
84 vbi_unlock_va(pMemSolaris->Core.pv, pMemSolaris->Core.cb, pMemSolaris->handle);
85 break;
86
87 case RTR0MEMOBJTYPE_MAPPING:
88 vbi_unmap(pMemSolaris->Core.pv, pMemSolaris->Core.cb);
89 break;
90
91 /* unused */
92 case RTR0MEMOBJTYPE_PHYS:
93 case RTR0MEMOBJTYPE_RES_VIRT:
94 default:
95 AssertMsgFailed(("enmType=%d\n", pMemSolaris->Core.enmType));
96 return VERR_INTERNAL_ERROR;
97 }
98
99 return VINF_SUCCESS;
100}
101
102
103int rtR0MemObjNativeAllocPage(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable)
104{
105 /* Create the object */
106 PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_PAGE, NULL, cb);
107 if (!pMemSolaris)
108 return VERR_NO_MEMORY;
109
110 void *virtAddr = ddi_umem_alloc(cb, DDI_UMEM_SLEEP, &pMemSolaris->Cookie);
111 if (!virtAddr)
112 {
113 rtR0MemObjDelete(&pMemSolaris->Core);
114 return VERR_NO_PAGE_MEMORY;
115 }
116
117 pMemSolaris->Core.pv = virtAddr;
118 pMemSolaris->handle = NULL;
119 *ppMem = &pMemSolaris->Core;
120 return VINF_SUCCESS;
121}
122
123
124int rtR0MemObjNativeAllocLow(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable)
125{
126 NOREF(fExecutable);
127
128 /* Create the object */
129 PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_LOW, NULL, cb);
130 if (!pMemSolaris)
131 return VERR_NO_MEMORY;
132
133 /* Allocate physically low page-aligned memory. */
134 caddr_t virtAddr;
135 uint64_t phys = (unsigned)0xffffffff;
136 virtAddr = vbi_lowmem_alloc(phys, cb);
137 if (virtAddr == NULL)
138 {
139 rtR0MemObjDelete(&pMemSolaris->Core);
140 return VERR_NO_LOW_MEMORY;
141 }
142 pMemSolaris->Core.pv = virtAddr;
143 pMemSolaris->handle = NULL;
144 *ppMem = &pMemSolaris->Core;
145 return VINF_SUCCESS;
146}
147
148
149int rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable)
150{
151 NOREF(fExecutable);
152
153 /* Create the object */
154 PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_CONT, NULL, cb);
155 if (!pMemSolaris)
156 return VERR_NO_MEMORY;
157
158 /* Allocate physically contiguous page-aligned memory. */
159 caddr_t virtAddr;
160 uint64_t phys = (unsigned)0xffffffff;
161 virtAddr = vbi_contig_alloc(&phys, cb);
162 if (virtAddr == NULL)
163 {
164 rtR0MemObjDelete(&pMemSolaris->Core);
165 return VERR_NO_CONT_MEMORY;
166 }
167 Assert(phys < (uint64_t)1 << 32);
168 pMemSolaris->Core.pv = virtAddr;
169 pMemSolaris->Core.u.Cont.Phys = phys;
170 pMemSolaris->handle = NULL;
171 *ppMem = &pMemSolaris->Core;
172 return VINF_SUCCESS;
173}
174
175
176int rtR0MemObjNativeAllocPhysNC(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest)
177{
178 /** @todo rtR0MemObjNativeAllocPhysNC / solaris */
179 return VERR_NOT_SUPPORTED; /* see the RTR0MemObjAllocPhysNC specs */
180}
181
182
183int rtR0MemObjNativeAllocPhys(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest)
184{
185 AssertMsgReturn(PhysHighest >= 16 *_1M, ("PhysHigest=%RHp\n", PhysHighest), VERR_NOT_IMPLEMENTED);
186
187 return rtR0MemObjNativeAllocCont(ppMem, cb, false);
188}
189
190
191int rtR0MemObjNativeEnterPhys(PPRTR0MEMOBJINTERNAL ppMem, RTHCPHYS Phys, size_t cb)
192{
193 /* Create the object */
194 PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_PHYS, NULL, cb);
195 if (!pMemSolaris)
196 return VERR_NO_MEMORY;
197
198 /* There is no allocation here, it needs to be mapped somewhere first */
199 pMemSolaris->Core.u.Phys.fAllocated = false;
200 pMemSolaris->Core.u.Phys.PhysBase = Phys;
201 *ppMem = &pMemSolaris->Core;
202 return VINF_SUCCESS;
203}
204
205
206int rtR0MemObjNativeLockUser(PPRTR0MEMOBJINTERNAL ppMem, RTR3PTR R3Ptr, size_t cb, RTR0PROCESS R0Process)
207{
208 AssertReturn(R0Process == RTR0ProcHandleSelf(), VERR_INVALID_PARAMETER);
209
210 /* Create the locking object */
211 PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_LOCK, (void *)R3Ptr, cb);
212 if (!pMemSolaris)
213 return VERR_NO_MEMORY;
214
215 void *ppl;
216
217 /* Lock down user pages */
218 int rc = vbi_lock_va((caddr_t)R3Ptr, cb, &ppl);
219 if (rc != 0)
220 {
221 cmn_err(CE_NOTE,"rtR0MemObjNativeLockUser: vbi_lock_va failed rc=%d\n", rc);
222 return VERR_LOCK_FAILED;
223 }
224
225 pMemSolaris->Core.u.Lock.R0Process = (RTR0PROCESS)vbi_proc();
226 pMemSolaris->handle = ppl;
227 *ppMem = &pMemSolaris->Core;
228 return VINF_SUCCESS;
229}
230
231
232int rtR0MemObjNativeLockKernel(PPRTR0MEMOBJINTERNAL ppMem, void *pv, size_t cb)
233{
234 PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_LOCK, pv, cb);
235 if (!pMemSolaris)
236 return VERR_NO_MEMORY;
237
238 void *ppl;
239 int rc = vbi_lock_va((caddr_t)pv, cb, &ppl);
240 if (rc != 0)
241 {
242 cmn_err(CE_NOTE,"rtR0MemObjNativeLockKernel: vbi_lock_va failed rc=%d\n", rc);
243 return VERR_LOCK_FAILED;
244 }
245
246 pMemSolaris->Core.u.Lock.R0Process = NIL_RTR0PROCESS;
247 pMemSolaris->handle = ppl;
248 *ppMem = &pMemSolaris->Core;
249 return VINF_SUCCESS;
250}
251
252
253int rtR0MemObjNativeReserveKernel(PPRTR0MEMOBJINTERNAL ppMem, void *pvFixed, size_t cb, size_t uAlignment)
254{
255 return VERR_NOT_IMPLEMENTED;
256}
257
258
259int rtR0MemObjNativeReserveUser(PPRTR0MEMOBJINTERNAL ppMem, RTR3PTR R3PtrFixed, size_t cb, size_t uAlignment, RTR0PROCESS R0Process)
260{
261 return VERR_NOT_IMPLEMENTED;
262}
263
264int rtR0MemObjNativeMapKernel(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJ pMemToMap, void *pvFixed, size_t uAlignment,
265 unsigned fProt, size_t offSub, size_t cbSub)
266{
267 /* @todo rtR0MemObjNativeMapKernel / Solaris - Should be fairly simple alloc kernel memory and memload it. */
268 return VERR_NOT_IMPLEMENTED;
269}
270
271int rtR0MemObjNativeMapUser(PPRTR0MEMOBJINTERNAL ppMem, PRTR0MEMOBJINTERNAL pMemToMap, RTR3PTR R3PtrFixed, size_t uAlignment, unsigned fProt, RTR0PROCESS R0Process)
272{
273 AssertMsgReturn(R3PtrFixed == (RTR3PTR)-1, ("%p\n", R3PtrFixed), VERR_NOT_SUPPORTED);
274 AssertMsgReturn(R0Process == RTR0ProcHandleSelf(), ("%p != %p\n", R0Process, RTR0ProcHandleSelf()), VERR_NOT_SUPPORTED);
275 AssertMsgReturn(uAlignment == 0 || uAlignment == PAGE_SIZE, ("%d\n", uAlignment), VERR_NOT_SUPPORTED);
276
277 PRTR0MEMOBJSOLARIS pMemToMapSolaris = (PRTR0MEMOBJSOLARIS)pMemToMap;
278 size_t size = pMemToMapSolaris->Core.cb;
279 void *pv = pMemToMapSolaris->Core.pv;
280 pgcnt_t cPages = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
281 pgcnt_t iPage;
282 uint64_t *paddrs;
283 caddr_t addr;
284 int rc;
285
286 /* Create the mapping object */
287 PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_MAPPING, pv, size);
288 if (!pMemSolaris)
289 return VERR_NO_MEMORY;
290
291 paddrs = kmem_zalloc(sizeof(uint64_t) * cPages, KM_SLEEP);
292 for (iPage = 0; iPage < cPages; iPage++)
293 {
294 paddrs[iPage] = vbi_va_to_pa(pv);
295 if (paddrs[iPage] == -(uint64_t)1)
296 {
297 cmn_err(CE_NOTE, "rtR0MemObjNativeMapUser: no page to map.\n");
298 rc = VERR_MAP_FAILED;
299 goto done;
300 }
301 pv = (void *)((uintptr_t)pv + PAGE_SIZE);
302 }
303
304 rc = vbi_user_map(&addr, fProt, paddrs, size);
305 if (rc != 0)
306 {
307 cmn_err(CE_NOTE, "rtR0MemObjNativeMapUser: vbi failure.\n");
308 rc = VERR_MAP_FAILED;
309 rtR0MemObjDelete(&pMemSolaris->Core);
310 goto done;
311 }
312 else
313 rc = VINF_SUCCESS;
314
315 pMemSolaris->Core.u.Mapping.R0Process = (RTR0PROCESS)vbi_proc();
316 pMemSolaris->Core.pv = addr;
317 *ppMem = &pMemSolaris->Core;
318done:
319 kmem_free(paddrs, sizeof(uint64_t) * cPages);
320 return rc;
321}
322
323
324int rtR0MemObjNativeProtect(PRTR0MEMOBJINTERNAL pMem, size_t offSub, size_t cbSub, uint32_t fProt)
325{
326 NOREF(pMem);
327 NOREF(offSub);
328 NOREF(cbSub);
329 NOREF(fProt);
330 return VERR_NOT_SUPPORTED;
331}
332
333
334RTHCPHYS rtR0MemObjNativeGetPagePhysAddr(PRTR0MEMOBJINTERNAL pMem, size_t iPage)
335{
336 PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)pMem;
337
338 switch (pMemSolaris->Core.enmType)
339 {
340 case RTR0MEMOBJTYPE_PAGE:
341 case RTR0MEMOBJTYPE_LOW:
342 case RTR0MEMOBJTYPE_MAPPING:
343 case RTR0MEMOBJTYPE_LOCK:
344 {
345 uint8_t *pb = (uint8_t *)pMemSolaris->Core.pv + ((size_t)iPage << PAGE_SHIFT);
346 return vbi_va_to_pa(pb);
347 }
348
349 case RTR0MEMOBJTYPE_CONT:
350 return pMemSolaris->Core.u.Cont.Phys + (iPage << PAGE_SHIFT);
351
352 case RTR0MEMOBJTYPE_PHYS:
353 return pMemSolaris->Core.u.Phys.PhysBase + (iPage << PAGE_SHIFT);
354
355 case RTR0MEMOBJTYPE_PHYS_NC:
356 AssertFailed(/* not implemented */);
357 case RTR0MEMOBJTYPE_RES_VIRT:
358 default:
359 return NIL_RTHCPHYS;
360 }
361}
362
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette