VBoxGuest-os2.cpp revision 941179b70e2f83fd1a1a398d571450e3e0de905b
/* $Id$ */
/** @file
* VBoxGuest - OS/2 specifics.
*/
/*
* Copyright (C) 2007 knut st. osmundsen <bird-src-spam@anduin.net>
*
* 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.
*
* 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.
* --------------------------------------------------------------------
*
* This code is based on:
*
* VBoxDrv - OS/2 specifics.
*
* Copyright (c) 2007 knut st. osmundsen <bird-src-spam@anduin.net>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include "VBoxGuestInternal.h"
#include <iprt/initterm.h>
#include <iprt/spinlock.h>
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/**
* Device extention & session data association structure.
*/
static VBOXGUESTDEVEXT g_DevExt;
/** The memory object for the MMIO memory. */
/** The memory mapping object the MMIO memory. */
/** Spinlock protecting g_apSessionHashTab. */
/** Hash table */
/** Calculates the index into g_apSessionHashTab.*/
/* Defined in VBoxGuestA-os2.asm */
extern uint32_t g_PhysMMIOBase;
extern uint16_t g_IOPortBase;
extern uint8_t g_bInterruptLine;
extern uint8_t g_bPciBusNo;
extern uint8_t g_bPciDevFunNo;
#ifdef DEBUG_READ
/* (debugging) */
extern uint16_t g_offLogHead;
extern uint16_t volatile g_offLogTail;
extern uint16_t const g_cchLogMax;
extern char g_szLog[];
#endif
/* (init only:) */
extern char g_szInitText[];
extern uint16_t g_cchInitText;
extern uint16_t g_cchInitTextMax;
/*******************************************************************************
* Internal Functions *
*******************************************************************************/
static int vboxGuestOS2MapMemory(void);
static VBOXOSTYPE vboxGuestOS2DetectVersion(void);
/* in VBoxGuestA-os2.asm */
/**
* 32-bit Ring-0 initialization.
*
* This is called from VBoxGuestA-os2.asm upon the first open call to the vboxgst$ device.
*
* @returns 0 on success, non-zero on failure.
* @param pszArgs Pointer to the device arguments.
*/
{
Log(("VBoxGuestOS2Init: pszArgs='%s' MMIO=0x%RX32 IOPort=0x%RX16 Int=%#x Bus=%#x Dev=%#x Fun=%d\n",
pszArgs, g_PhysMMIOBase, g_IOPortBase, g_bInterruptLine, g_bPciBusNo, g_bPciDevFunNo >> 3, g_bPciDevFunNo & 7));
/*
* Initialize the runtime.
*/
if (RT_SUCCESS(rc))
{
/*
* Process the commandline. Later.
*/
bool fVerbose = true;
/*
* Map the MMIO memory if found.
*/
rc = vboxGuestOS2MapMemory();
if (RT_SUCCESS(rc))
{
/*
* Initialize the device extension.
*/
if (g_MemMapMMIO != NIL_RTR0MEMOBJ)
0);
else
0);
if (RT_SUCCESS(rc))
{
/*
* Initialize the session hash table.
*/
if (RT_SUCCESS(rc))
{
/*
* Configure the interrupt handler.
*/
if (g_bInterruptLine)
{
if (rc)
{
}
}
if (RT_SUCCESS(rc))
{
/*
* Success
*/
if (fVerbose)
{
strcpy(&g_szInitText[0],
"\r\n"
"Copyright (C) 2008 Sun Microsystems, Inc.\r\n");
}
return VINF_SUCCESS;
}
g_cchInitText = RTStrPrintf(&g_szInitText[0], g_cchInitTextMax, "VBoxGuest.sys: SetIrq failed for IRQ %#d, rc=%Rrc\n",
}
else
g_cchInitText = RTStrPrintf(&g_szInitText[0], g_cchInitTextMax, "VBoxGuest.sys: RTSpinlockCreate failed, rc=%Rrc\n", rc);
}
else
g_cchInitText = RTStrPrintf(&g_szInitText[0], g_cchInitTextMax, "VBoxGuest.sys: VBoxGuestOS2InitDevExt failed, rc=%Rrc\n", rc);
}
else
g_cchInitText = RTStrPrintf(&g_szInitText[0], g_cchInitTextMax, "VBoxGuest.sys: VBoxGuestOS2MapMMIO failed, rc=%Rrc\n", rc);
RTR0Term();
}
else
g_cchInitText = RTStrPrintf(&g_szInitText[0], g_cchInitTextMax, "VBoxGuest.sys: RTR0Init failed, rc=%Rrc\n", rc);
return rc;
}
/**
* Maps the VMMDev memory.
*
* @returns VBox status code.
* @retval VERR_VERSION_MISMATCH The VMMDev memory didn't meet our expectations.
*
* @param pDevExt The device extension.
*/
static int vboxGuestOS2MapMemory(void)
{
/*
* Did we find any MMIO region (0 or NIL)?
*/
if ( !PhysMMIOBase
|| PhysMMIOBase == NIL_RTCCPHYS)
{
return VINF_SUCCESS;
}
/*
* Create a physical memory object for it.
*
* Since we don't know the actual size (OS/2 doesn't at least), we make
* a qualified guess using the VMMDEV_RAM_SIZE.
*/
if (RT_FAILURE(rc))
{
}
if (RT_FAILURE(rc))
{
Log(("vboxGuestOS2MapMemory: RTR0MemObjEnterPhys(,%RCp,%zx) -> %Rrc\n",
return rc;
}
/*
* Map the object into kernel space.
*
* We want a normal mapping with normal caching, which good in two ways. First
* since the API doesn't have any flags indicating how the mapping should be cached.
* anyway for normal RAM.
*/
if (RT_SUCCESS(rc))
{
/*
* Validate the VMM memory.
*/
{
/*
* Did we hit the correct size? If not we'll have to
* redo the mapping using the correct size.
*/
return VINF_SUCCESS;
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
return VINF_SUCCESS;
Log(("vboxGuestOS2MapMemory: RTR0MemObjMapKernel [%RCp,%zx] -> %Rrc (2nd)\n",
}
else
Log(("vboxGuestOS2MapMemory: RTR0MemObjEnterPhys(,%RCp,%zx) -> %Rrc (2nd)\n",
}
else
{
LogRel(("vboxGuestOS2MapMemory: Bogus VMMDev memory; u32Version=%RX32 (expected %RX32) u32Size=%RX32\n",
}
}
else
Log(("vboxGuestOS2MapMemory: RTR0MemObjMapKernel [%RCp,%zx] -> %Rrc\n",
return rc;
}
/**
* Called fromn VBoxGuestOS2Init to determin which OS/2 version this is.
*
* @returns VBox OS/2 type.
*/
static VBOXOSTYPE vboxGuestOS2DetectVersion(void)
{
#if 0 /** @todo dig up the version stuff from GIS later and verify that the numbers are actually decimal. */
if (uMajor == 2)
{
}
#endif
return enmOSType;
}
{
int rc;
/*
* Create a new session.
*/
if (RT_SUCCESS(rc))
{
/*
* Insert it into the hash table.
*/
}
Log(("VBoxGuestOS2Open: g_DevExt=%p pSession=%p rc=%d pid=%d\n", &g_DevExt, pSession, rc, (int)RTProcSelf()));
return rc;
}
{
/*
* Remove from the hash table.
*/
if (pSession)
{
{
}
else
{
while (pSession)
{
{
break;
}
/* next */
}
}
}
if (!pSession)
{
Log(("VBoxGuestIoctl: WHUT?!? pSession == NULL! This must be a mistake... pid=%d sfn=%d\n", (int)Process, sfn));
return VERR_INVALID_PARAMETER;
}
/*
* Close the session.
*/
return 0;
}
{
/*
* Find the session.
*/
{
while ( pSession
}
if (RT_UNLIKELY(!pSession))
{
Log(("VBoxGuestIoctl: WHAT?!? pSession == NULL! This must be a mistake... pid=%d\n", (int)Process));
return VERR_INVALID_PARAMETER;
}
/*
* Dispatch the fast IOCtl.
*/
return 0;
}
/**
* 32-bit IDC service routine.
*
* @returns VBox status code.
* @param u32Session The session handle (PVBOXGUESTSESSION).
* @param iFunction The requested function.
* cannot be swapped out, or that it's acceptable to take a
* page in fault in the current context. If the request doesn't
* take input or produces output, apssing NULL is okay.
* @param cbData The size of the data buffer.
* @param pcbDataReturned Where to store the amount of data that's returned.
* This can be NULL if pvData is NULL.
*
* @remark This is called from the 16-bit thunker as well as directly from the 32-bit clients.
*/
DECLASM(int) VBoxGuestOS2IDCService(uint32_t u32Session, unsigned iFunction, void *pvData, size_t cbData, size_t *pcbDataReturned)
{
AssertMsgReturn(pSession->pDevExt == &g_DevExt, ("%p != %p\n", pSession->pDevExt, &g_DevExt), VERR_INVALID_HANDLE);
int rc;
switch (iFunction)
{
default:
break;
rc = VINF_SUCCESS;
break;
}
return rc;
}
/**
* Worker for VBoxGuestOS2IDC, it creates the kernel session.
*
* @returns Pointer to the session.
*/
{
if (RT_SUCCESS(rc))
{
return pSession;
}
return NULL;
}
DECLASM(int) VBoxGuestOS2IOCtl(uint16_t sfn, uint8_t iCat, uint8_t iFunction, void *pvParm, void *pvData, uint16_t *pcbParm, uint16_t *pcbData)
{
/*
* Find the session.
*/
{
while ( pSession
}
if (!pSession)
{
Log(("VBoxGuestIoctl: WHAT?!? pSession == NULL! This must be a mistake... pid=%d\n", (int)Process));
return VERR_INVALID_PARAMETER;
}
/*
* Verify the category and dispatch the IOCtl.
*
* buffer similar to the one unix ioctl buffer argument. While the data
* buffer is used for passing the VBox status code back to the caller
* since the status codes that OS/2 accepts thru the DosDevIOCtl API is
* severely restricted.
*/
{
Log(("VBoxGuestOS2IOCtl: pSession=%p iFunction=%#x pvParm=%p pvData=%p *pcbParm=%d *pcbData=%d\n", pSession, iFunction, pvParm, pvData, *pcbParm, *pcbData));
/*
* Lock the buffers.
*/
if (pvParm)
{
AssertMsgReturn(!rc, ("KernVMLock(VMDHL_WRITE, %p, %#x, &p, NULL, NULL) -> %d\n", pvParm, *pcbParm, &ParmLock, rc), VERR_LOCK_FAILED);
}
#if 0 /* don't bother locking it since it's only 4 bytes (the return code). */
if (pvData)
{
if (rc)
{
AssertMsgFailed(("KernVMLock(VMDHL_WRITE, %p, %#x, &p, NULL, NULL) -> %d\n", pvData, *pcbData, &DataLock, rc));
return VERR_LOCK_FAILED;
}
}
#endif
/*
* Process the IOCtl.
*/
/*
* Unlock the buffers.
*/
if (pvParm)
{
}
#if 0
if (pvData)
{
}
#else
AssertMsgReturn(!rc, ("KernCopyOut(%p, %p, sizeof(int32_t)) -> %d\n", pvData, &rc, rc), VERR_LOCK_FAILED);
#endif
return VINF_SUCCESS;
}
return VERR_NOT_SUPPORTED;
}
/**
* 32-bit ISR, called by 16-bit assembly thunker in VBoxGuestA-os2.asm.
*
* @returns true if it's our interrupt, false it isn't.
*/
DECLASM(bool) VBoxGuestOS2ISR(void)
{
Log(("VBoxGuestOS2ISR\n"));
return VBoxGuestCommonISR(&g_DevExt);
}
{
/* No polling on OS/2 */
}
#ifdef DEBUG_READ /** @todo figure out this one once and for all... */
/**
* Callback for writing to the log buffer.
*
* @returns number of bytes written.
* @param pvArg Unused.
* @param pachChars Pointer to an array of utf-8 characters.
* @param cbChars Number of bytes in the character array pointed to by pachChars.
*/
static DECLCALLBACK(size_t) vboxGuestNativeLogOutput(void *pvArg, const char *pachChars, size_t cbChars)
{
size_t cchWritten = 0;
while (cbChars-- > 0)
{
if (offLogHeadNext == g_offLogTail)
break; /* no */
cchWritten++;
}
return cchWritten;
}
int SUPR0Printf(const char *pszFormat, ...)
{
#if 0 //def DEBUG_bird
#endif
return cch;
}
#endif /* DEBUG_READ */