memobj-r0drv-solaris.c revision 23426d510501558cd6941a2256e3449b8f0aec11
/* $Id$ */
/** @file
* IPRT - Ring-0 Memory Objects, Solaris.
*/
/*
* Copyright (C) 2006-2007 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include "the-solaris-kernel.h"
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/**
* The Solaris version of the memory object structure.
*/
typedef struct RTR0MEMOBJSOLARIS
{
/** The core structure. */
/** Pointer to kernel memory cookie. */
/** Shadow locked pages. */
/**
* Used for supplying the solaris kernel info. about memory limits
* during contiguous allocations (i_ddi_mem_alloc)
*/
struct ddi_dma_attr g_SolarisX86PhysMemLimits =
{
DMA_ATTR_V0, /* Version Number */
(uint64_t)0, /* lower limit */
1, /* scatter-gather list length (1 for contiguous) */
1, /* device granularity */
0 /* bus-specific flags */
};
{
/* We could use paddr_t (more solaris-like) rather than uint64_t but paddr_t isn't defined for 64-bit */
if (pfn == PFN_INVALID)
{
return PFN_INVALID;
}
/* Both works, but second will work for non-page aligned virtAddr */
#if 0
#else
#endif
return physAddr;
}
{
{
case RTR0MEMOBJTYPE_CONT:
break;
case RTR0MEMOBJTYPE_PAGE:
break;
case RTR0MEMOBJTYPE_LOCK:
{
else
as_pageunlock(addrSpace, pMemSolaris->ppShadowPages, pMemSolaris->Core.pv, pMemSolaris->Core.cb, S_WRITE);
break;
}
case RTR0MEMOBJTYPE_MAPPING:
{
{
/* Kernel process*/
}
else
{
/* User process */
}
break;
}
/* unused */
case RTR0MEMOBJTYPE_LOW:
case RTR0MEMOBJTYPE_PHYS:
case RTR0MEMOBJTYPE_RES_VIRT:
default:
return VERR_INTERNAL_ERROR;
}
return VINF_SUCCESS;
}
{
/* Create the object */
PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_PAGE, NULL, cb);
if (!pMemSolaris)
return VERR_NO_MEMORY;
if (!virtAddr)
{
return VERR_NO_PAGE_MEMORY;
}
return VINF_SUCCESS;
}
{
/* Try page alloc first */
if (RT_SUCCESS(rc))
{
while (iPage-- > 0)
{
/* Failed! Fall back to physical contiguous alloc */
RTR0MemObjFree(*ppMem, false);
break;
}
}
return rc;
}
{
/* Create the object */
PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_CONT, NULL, cb);
if (!pMemSolaris)
return VERR_NO_MEMORY;
/* Allocate physically contiguous page-aligned memory. */
if (rc != DDI_SUCCESS)
{
return VERR_NO_CONT_MEMORY;
}
return VINF_SUCCESS;
}
{
/** @todo rtR0MemObjNativeAllocPhysNC / solaris */
return VERR_NOT_SUPPORTED; /* see the RTR0MemObjAllocPhysNC specs */
}
{
}
{
/* Create the object */
PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_PHYS, NULL, cb);
if (!pMemSolaris)
return VERR_NO_MEMORY;
/* There is no allocation here, it needs to be mapped somewhere first */
return VINF_SUCCESS;
}
int rtR0MemObjNativeLockUser(PPRTR0MEMOBJINTERNAL ppMem, RTR3PTR R3Ptr, size_t cb, RTR0PROCESS R0Process)
{
/* Create the locking object */
PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_LOCK, (void *)R3Ptr, cb);
if (!pMemSolaris)
return VERR_NO_MEMORY;
/* Lock down user pages */
if (rc != 0)
{
return VERR_LOCK_FAILED;
}
if (!ppl)
{
return VERR_LOCK_FAILED;
}
return VINF_SUCCESS;
}
{
/* Create the locking object */
PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_LOCK, pv, cb);
if (!pMemSolaris)
return VERR_NO_MEMORY;
/* Lock down kernel pages */
if (rc != 0)
{
return VERR_LOCK_FAILED;
}
if (!ppl)
{
return VERR_LOCK_FAILED;
}
pMemSolaris->Core.u.Lock.R0Process = NIL_RTR0PROCESS; /* means kernel, see rtR0MemObjNativeFree() */
return VINF_SUCCESS;
}
int rtR0MemObjNativeReserveKernel(PPRTR0MEMOBJINTERNAL ppMem, void *pvFixed, size_t cb, size_t uAlignment)
{
return VERR_NOT_IMPLEMENTED;
}
int rtR0MemObjNativeReserveUser(PPRTR0MEMOBJINTERNAL ppMem, RTR3PTR R3PtrFixed, size_t cb, size_t uAlignment, RTR0PROCESS R0Process)
{
return VERR_NOT_IMPLEMENTED;
}
int rtR0MemObjNativeMapKernel(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJ pMemToMap, void *pvFixed, size_t uAlignment, unsigned fProt)
{
int rc;
/* Create the mapping object */
PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_MAPPING, pv, size);
if (!pMemSolaris)
return VERR_NO_MEMORY;
as_rangelock(&kas);
if (pvFixed != (void *)-1)
{
/* Use user specified address */
/* Blow away any previous mapping */
}
else
{
/* Let the system choose an address */
{
return VERR_NO_MEMORY;
}
/* Check address against alignment, fail if it doesn't match */
{
return VERR_MAP_FAILED;
}
}
* need to add PROT_USER for the pages to be accessible by user
*/
if (rc != 0)
{
return VERR_NO_MEMORY;
}
/* Map each page into kernel space */
{
}
return VINF_SUCCESS;
}
int rtR0MemObjNativeMapUser(PPRTR0MEMOBJINTERNAL ppMem, PRTR0MEMOBJINTERNAL pMemToMap, RTR3PTR R3PtrFixed, size_t uAlignment, unsigned fProt, RTR0PROCESS R0Process)
{
int rc;
/* Create the mapping object */
PRTR0MEMOBJSOLARIS pMemSolaris = (PRTR0MEMOBJSOLARIS)rtR0MemObjNew(sizeof(*pMemSolaris), RTR0MEMOBJTYPE_MAPPING, pv, size);
if (!pMemSolaris)
return VERR_NO_MEMORY;
{
/* Use user specified address */
/* Verify user address (a bit paranoid) */
if (rc != RANGE_OKAY)
{
return VERR_INVALID_POINTER;
}
/* Blow away any previous mapping */
}
else
{
/* Let the system choose an address */
{
return VERR_MAP_FAILED;
}
/* Check address against alignment, fail if it doesn't match */
{
return VERR_MAP_FAILED;
}
}
* need to add PROT_USER for the pages to be accessible by user
*/
if (rc != 0)
{
return VERR_MAP_FAILED;
}
#if 0
/* Lock down the pages and get the shadow page list
* In this case we must as_pageunlock if(ppShadowPages) exists while freeing CONT, PAGE
*/
{
return VERR_NO_MEMORY;
}
/* Map each page into user space */
{
}
#else
/* Map each page into user space */
{
}
#endif
return VINF_SUCCESS;
}
{
{
case RTR0MEMOBJTYPE_PAGE:
case RTR0MEMOBJTYPE_LOW:
case RTR0MEMOBJTYPE_MAPPING:
{
}
case RTR0MEMOBJTYPE_LOCK:
{
{
/* User */
}
else /* Kernel */
}
case RTR0MEMOBJTYPE_CONT:
case RTR0MEMOBJTYPE_PHYS:
case RTR0MEMOBJTYPE_PHYS_NC:
AssertFailed(/* not implemented */);
case RTR0MEMOBJTYPE_RES_VIRT:
default:
return NIL_RTHCPHYS;
}
}