DevParallel.cpp revision c74832c7184337c330041742d88e6dacaa07b378
/* $Id$ */
/** @file
* VirtualBox Parallel Device Emulation.
*/
/*
* Copyright (C) 2006-2007 innotek GmbH
*
* 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 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.
*
* If you received this file as part of a commercial VirtualBox
* distribution, then only the terms of your commercial VirtualBox
* license agreement apply instead of the previous paragraph.
*/
/* based on DevSerial.cpp */
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_DEV_PARALLEL
#include <iprt/semaphore.h>
#include <iprt/critsect.h>
#include "Builtins.h"
#include "ParallelIOCtlCmd.h"
#define PARALLEL_SAVED_STATE_VERSION 1
/* defines for accessing the register bits */
#define LPT_STATUS_BUSY 0x80
#define LPT_STATUS_ACK 0x40
#define LPT_STATUS_PAPER_OUT 0x20
#define LPT_STATUS_SELECT_IN 0x10
#define LPT_STATUS_ERROR 0x08
#define LPT_STATUS_IRQ 0x04
#define LPT_CONTROL_ENABLE_BIDIRECT 0x20
#define LPT_CONTROL_ENABLE_IRQ_VIA_ACK 0x10
#define LPT_CONTROL_SELECT_PRINTER 0x08
#define LPT_CONTROL_RESET 0x04
#define LPT_CONTROL_AUTO_LINEFEED 0x02
#define LPT_CONTROL_STROBE 0x01
typedef struct ParallelState
{
/** Access critical section. */
/** Pointer to the device instance. */
/** Pointer to the device instance. */
#endif
/** The base interface. */
/** The host device port interface. */
/** Pointer to the attached base driver. */
/** Pointer to the attached host device. */
int irq;
bool fGCEnabled;
bool fR0Enabled;
bool afAlignment[6];
typedef DEVPARALLELSTATE ParallelState;
#ifndef VBOX_DEVICE_STRUCT_TESTCASE
#define PDMIBASE_2_PARALLELSTATE(pInstance) ( (ParallelState *)((uintptr_t)(pInterface) - RT_OFFSETOF(ParallelState, IBase)) )
#define PDMIHOSTDEVICEPORT_2_PARALLELSTATE(pInstance) ( (ParallelState *)((uintptr_t)(pInterface) - RT_OFFSETOF(ParallelState, IHostDevicePort)) )
PDMBOTHCBDECL(int) parallelIOPortRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb);
PDMBOTHCBDECL(int) parallelIOPortWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb);
static void parallel_update_irq(ParallelState *s)
{
if (s->reg_control & LPT_CONTROL_ENABLE_IRQ_VIA_ACK) {
} else {
}
}
{
unsigned char ch;
addr &= 7;
switch(addr) {
default:
case 0:
#ifndef IN_RING3
return VINF_IOM_HC_IOPORT_WRITE;
#else
if (RT_LIKELY(s->pDrvHostDeviceConnector))
{
}
#endif
break;
case 1:
break;
case 2:
s->reg_control = val;
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
case 7:
break;
}
return VINF_SUCCESS;
}
{
*pRC = VINF_SUCCESS;
addr &= 7;
switch(addr) {
default:
case 0:
#ifndef IN_RING3
#else
if (RT_LIKELY(s->pDrvHostDeviceConnector))
{
}
#endif
break;
case 1:
ret = s->reg_status;
break;
case 2:
ret = s->reg_control;
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
case 7:
break;
}
return ret;
}
#ifdef IN_RING3
static DECLCALLBACK(int) parallelNotifyRead(PPDMICHARPORT pInterface, const void *pvBuf, size_t *pcbRead)
{
int rc;
return VINF_SUCCESS;
#if 0
{
/* If a character is still in the read queue, then wait for it to be emptied. */
if (VBOX_FAILURE(rc))
return rc;
}
{
*pcbRead = 1;
rc = VINF_SUCCESS;
}
else
rc = VERR_TIMEOUT;
return rc;
#endif
}
#endif /* IN_RING3 */
/**
* Port I/O Handler for OUT operations.
*
* @returns VBox status code.
*
* @param pDevIns The device instance.
* @param pvUser User argument.
* @param Port Port number used for the IN operation.
* @param u32 The value to output.
* @param cb The value size in bytes.
*/
{
int rc = VINF_SUCCESS;
if (cb == 1)
{
if (rc == VINF_SUCCESS)
{
}
}
else
return rc;
}
/**
* Port I/O Handler for IN operations.
*
* @returns VBox status code.
*
* @param pDevIns The device instance.
* @param pvUser User argument.
* @param Port Port number used for the IN operation.
* @param u32 The value to output.
* @param cb The value size in bytes.
*/
{
int rc = VINF_SUCCESS;
if (cb == 1)
{
if (rc == VINF_SUCCESS)
{
}
}
else
return rc;
}
#ifdef IN_RING3
/**
* Saves a state of the serial port device.
*
* @returns VBox status code.
* @param pDevIns The device instance.
* @param pSSMHandle The handle to save the state to.
*/
{
}
/**
* Loads a saved serial port device state.
*
* @returns VBox status code.
* @param pDevIns The device instance.
* @param pSSMHandle The handle to the saved state.
* @param u32Version The data unit version number.
*/
{
int rc;
{
}
if (VBOX_FAILURE(rc))
return rc;
if (u32 != ~0U)
{
}
return VINF_SUCCESS;
}
/**
* @copydoc FNPDMDEVRELOCATE
*/
{
}
/** @copyfrom PIBASE::pfnqueryInterface */
{
switch (enmInterface)
{
case PDMINTERFACE_BASE:
return &pData->IHostDevicePort;
default:
return NULL;
}
}
/**
* Destruct a device instance.
*
* Most VM resources are freed by the VM. This callback is provided so that any non-VM
* resources can be freed correctly.
*
* @returns VBox status.
* @param pDevIns The device instance data.
*/
{
return VINF_SUCCESS;
}
/**
* Construct a device instance for a VM.
*
* @returns VBox status.
* @param pDevIns The device instance data.
* If the registration structure is needed, pDevIns->pDevReg points to it.
* @param iInstance Instance number. Use this to figure out which registers and such to use.
* The device number is also found in pDevIns->iInstance, but since it's
* likely to be freqently used PDM passes it as parameter.
* @param pCfgHandle Configuration node handle for the device. Use this to obtain the configuration
* of the device instance. It's also found in pDevIns->pCfgHandle, but like
* iInstance it's expected to be used a bit in this function.
*/
int iInstance,
{
int rc;
/*
* Validate configuration.
*/
if (rc == VERR_CFGM_VALUE_NOT_FOUND)
pData->fGCEnabled = true;
else if (VBOX_FAILURE(rc))
N_("Configuration error: Failed to get the \"GCEnabled\" value"));
if (rc == VERR_CFGM_VALUE_NOT_FOUND)
pData->fR0Enabled = true;
else if (VBOX_FAILURE(rc))
N_("Configuration error: Failed to get the \"R0Enabled\" value"));
/* IBase */
/* ICharPort */
/* pData->ICharPort.pfnNotifyRead = parallelNotifyRead; */
/*
* Initialize critical section.
* This must of course be done before attaching drivers or anything else which can call us back..
*/
char szName[24];
if (VBOX_FAILURE(rc))
return rc;
/** @todo r=bird: Check for VERR_CFGM_VALUE_NOT_FOUND and provide sensible defaults.
* Also do AssertMsgFailed(("Configuration error:....)) in the failure cases of CFGMR3Query*()
* and CFGR3AreValuesValid() like we're doing in the other devices. */
if (VBOX_FAILURE(rc))
return rc;
if (VBOX_FAILURE(rc))
return rc;
if (VBOX_FAILURE (rc))
return rc;
if (pData->fGCEnabled)
if (pData->fR0Enabled)
/* Attach the char driver and get the interfaces. For now no run-time
* changes are supported. */
if (VBOX_SUCCESS(rc))
{
pData->pDrvHostDeviceConnector = (PDMIHOSTDEVICECONNECTOR *)pData->pDrvBase->pfnQueryInterface(pData->pDrvBase, PDMINTERFACE_HOST_DEVICE_CONNECTOR);
if (!pData->pDrvHostDeviceConnector)
{
return VERR_PDM_MISSING_INTERFACE;
}
/** @todo provide read notification interface!!!! */
}
else if (rc == VERR_PDM_NO_ATTACHED_DRIVER)
{
}
else
{
}
pDevIns, /* pDevIns */
iInstance, /* u32Instance */
PARALLEL_SAVED_STATE_VERSION, /* u32Version */
sizeof (*pData), /* cbGuess */
NULL, /* pfnSavePrep */
parallelSaveExec, /* pfnSaveExec */
NULL, /* pfnSaveDone */
NULL, /* pfnLoadPrep */
parallelLoadExec, /* pfnLoadExec */
NULL /* pfnLoadDone */
);
if (VBOX_FAILURE(rc))
return rc;
return VINF_SUCCESS;
}
/**
* The device registration structure.
*/
const PDMDEVREG g_DeviceParallelPort =
{
/* u32Version */
/* szDeviceName */
"parallel",
/* szGCMod */
"VBoxDDGC.gc",
/* szR0Mod */
"VBoxDDR0.r0",
/* pszDescription */
"Parallel Communication Port",
/* fFlags */
PDM_DEVREG_FLAGS_HOST_BITS_DEFAULT | PDM_DEVREG_FLAGS_GUEST_BITS_DEFAULT | PDM_DEVREG_FLAGS_GC | PDM_DEVREG_FLAGS_R0,
/* fClass */
/* cMaxInstances */
1,
/* cbInstance */
sizeof(ParallelState),
/* pfnConstruct */
/* pfnDestruct */
/* pfnRelocate */
/* pfnIOCtl */
NULL,
/* pfnPowerOn */
NULL,
/* pfnReset */
NULL,
/* pfnSuspend */
NULL,
/* pfnResume */
NULL,
/* pfnAttach */
NULL,
/* pfnDetach */
NULL,
/* pfnQueryInterface. */
};
#endif /* IN_RING3 */
#endif /* !VBOX_DEVICE_STRUCT_TESTCASE */