DevParallel.cpp revision cad8876b46f9e366c4a1007a40c27ca1df078950
c74832c7184337c330041742d88e6dacaa07b378vboxsync/* $Id$ */
c74832c7184337c330041742d88e6dacaa07b378vboxsync/** @file
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync * DevParallel - Parallel (Port) Device Emulation.
d192cc72774b02a0df2fdd46350d418236ac09aevboxsync *
d192cc72774b02a0df2fdd46350d418236ac09aevboxsync * Contributed by: Alexander Eichner
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync * Based on DevSerial.cpp
c74832c7184337c330041742d88e6dacaa07b378vboxsync */
c74832c7184337c330041742d88e6dacaa07b378vboxsync
c74832c7184337c330041742d88e6dacaa07b378vboxsync/*
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
c74832c7184337c330041742d88e6dacaa07b378vboxsync *
c74832c7184337c330041742d88e6dacaa07b378vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
c74832c7184337c330041742d88e6dacaa07b378vboxsync * available from http://www.virtualbox.org. This file is free software;
c74832c7184337c330041742d88e6dacaa07b378vboxsync * you can redistribute it and/or modify it under the terms of the GNU
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * General Public License (GPL) as published by the Free Software
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync *
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * additional information or have any questions.
c74832c7184337c330041742d88e6dacaa07b378vboxsync */
c74832c7184337c330041742d88e6dacaa07b378vboxsync
c74832c7184337c330041742d88e6dacaa07b378vboxsync/*******************************************************************************
c74832c7184337c330041742d88e6dacaa07b378vboxsync* Header Files *
c74832c7184337c330041742d88e6dacaa07b378vboxsync*******************************************************************************/
c74832c7184337c330041742d88e6dacaa07b378vboxsync#define LOG_GROUP LOG_GROUP_DEV_PARALLEL
da957c069c2a3c582fe265ff88170ce4c42b499dvboxsync#include <VBox/pdmdev.h>
c74832c7184337c330041742d88e6dacaa07b378vboxsync#include <iprt/assert.h>
c74832c7184337c330041742d88e6dacaa07b378vboxsync#include <iprt/uuid.h>
c74832c7184337c330041742d88e6dacaa07b378vboxsync#include <iprt/string.h>
c74832c7184337c330041742d88e6dacaa07b378vboxsync#include <iprt/semaphore.h>
c74832c7184337c330041742d88e6dacaa07b378vboxsync#include <iprt/critsect.h>
c74832c7184337c330041742d88e6dacaa07b378vboxsync
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync#include "../Builtins.h"
c74832c7184337c330041742d88e6dacaa07b378vboxsync
a6e58d30b4d856cf924fda15cd743fed386fff93vboxsync
a6e58d30b4d856cf924fda15cd743fed386fff93vboxsync/*******************************************************************************
a6e58d30b4d856cf924fda15cd743fed386fff93vboxsync* Defined Constants And Macros *
a6e58d30b4d856cf924fda15cd743fed386fff93vboxsync*******************************************************************************/
c74832c7184337c330041742d88e6dacaa07b378vboxsync#define PARALLEL_SAVED_STATE_VERSION 1
c74832c7184337c330041742d88e6dacaa07b378vboxsync
c74832c7184337c330041742d88e6dacaa07b378vboxsync/* defines for accessing the register bits */
c74832c7184337c330041742d88e6dacaa07b378vboxsync#define LPT_STATUS_BUSY 0x80
c74832c7184337c330041742d88e6dacaa07b378vboxsync#define LPT_STATUS_ACK 0x40
c74832c7184337c330041742d88e6dacaa07b378vboxsync#define LPT_STATUS_PAPER_OUT 0x20
c74832c7184337c330041742d88e6dacaa07b378vboxsync#define LPT_STATUS_SELECT_IN 0x10
c74832c7184337c330041742d88e6dacaa07b378vboxsync#define LPT_STATUS_ERROR 0x08
c74832c7184337c330041742d88e6dacaa07b378vboxsync#define LPT_STATUS_IRQ 0x04
c74832c7184337c330041742d88e6dacaa07b378vboxsync#define LPT_STATUS_BIT1 0x02 /* reserved (only for completeness) */
4fbca3751fe239da5934c23a783c3422618336e8vboxsync#define LPT_STATUS_EPP_TIMEOUT 0x01
c74832c7184337c330041742d88e6dacaa07b378vboxsync
c74832c7184337c330041742d88e6dacaa07b378vboxsync#define LPT_CONTROL_BIT7 0x80 /* reserved (only for completeness) */
c74832c7184337c330041742d88e6dacaa07b378vboxsync#define LPT_CONTROL_BIT6 0x40 /* reserved (only for completeness) */
c74832c7184337c330041742d88e6dacaa07b378vboxsync#define LPT_CONTROL_ENABLE_BIDIRECT 0x20
c74832c7184337c330041742d88e6dacaa07b378vboxsync#define LPT_CONTROL_ENABLE_IRQ_VIA_ACK 0x10
c74832c7184337c330041742d88e6dacaa07b378vboxsync#define LPT_CONTROL_SELECT_PRINTER 0x08
c74832c7184337c330041742d88e6dacaa07b378vboxsync#define LPT_CONTROL_RESET 0x04
c74832c7184337c330041742d88e6dacaa07b378vboxsync#define LPT_CONTROL_AUTO_LINEFEED 0x02
c74832c7184337c330041742d88e6dacaa07b378vboxsync#define LPT_CONTROL_STROBE 0x01
c74832c7184337c330041742d88e6dacaa07b378vboxsync
4fbca3751fe239da5934c23a783c3422618336e8vboxsync/** mode defines for the extended control register */
4fbca3751fe239da5934c23a783c3422618336e8vboxsync#define LPT_ECP_ECR_CHIPMODE_MASK 0xe0
4fbca3751fe239da5934c23a783c3422618336e8vboxsync#define LPT_ECP_ECR_CHIPMODE_GET_BITS(reg) ((reg) >> 5)
4fbca3751fe239da5934c23a783c3422618336e8vboxsync#define LPT_ECP_ECR_CHIPMODE_SET_BITS(val) ((val) << 5)
4fbca3751fe239da5934c23a783c3422618336e8vboxsync#define LPT_ECP_ECR_CHIPMODE_CONFIGURATION 0x07
4fbca3751fe239da5934c23a783c3422618336e8vboxsync#define LPT_ECP_ECR_CHIPMODE_FIFO_TEST 0x06
4fbca3751fe239da5934c23a783c3422618336e8vboxsync#define LPT_ECP_ECR_CHIPMODE_RESERVED 0x05
4fbca3751fe239da5934c23a783c3422618336e8vboxsync#define LPT_ECP_ECR_CHIPMODE_EPP 0x04
4fbca3751fe239da5934c23a783c3422618336e8vboxsync#define LPT_ECP_ECR_CHIPMODE_ECP_FIFO 0x03
4fbca3751fe239da5934c23a783c3422618336e8vboxsync#define LPT_ECP_ECR_CHIPMODE_PP_FIFO 0x02
4fbca3751fe239da5934c23a783c3422618336e8vboxsync#define LPT_ECP_ECR_CHIPMODE_BYTE 0x01
4fbca3751fe239da5934c23a783c3422618336e8vboxsync#define LPT_ECP_ECR_CHIPMODE_COMPAT 0x00
4fbca3751fe239da5934c23a783c3422618336e8vboxsync
4fbca3751fe239da5934c23a783c3422618336e8vboxsync/** FIFO status bits in extended control register */
4fbca3751fe239da5934c23a783c3422618336e8vboxsync#define LPT_ECP_ECR_FIFO_MASK 0x03
4fbca3751fe239da5934c23a783c3422618336e8vboxsync#define LPT_ECP_ECR_FIFO_SOME_DATA 0x00
4fbca3751fe239da5934c23a783c3422618336e8vboxsync#define LPT_ECP_ECR_FIFO_FULL 0x02
4fbca3751fe239da5934c23a783c3422618336e8vboxsync#define LPT_ECP_ECR_FIFO_EMPTY 0x01
4fbca3751fe239da5934c23a783c3422618336e8vboxsync
4fbca3751fe239da5934c23a783c3422618336e8vboxsync#define LPT_ECP_CONFIGA_FIFO_WITDH_MASK 0x70
4fbca3751fe239da5934c23a783c3422618336e8vboxsync#define LPT_ECP_CONFIGA_FIFO_WIDTH_GET_BITS(reg) ((reg) >> 4)
4fbca3751fe239da5934c23a783c3422618336e8vboxsync#define LPT_ECP_CONFIGA_FIFO_WIDTH_SET_BITS(val) ((val) << 4)
4fbca3751fe239da5934c23a783c3422618336e8vboxsync#define LPT_ECP_CONFIGA_FIFO_WIDTH_16 0x00
4fbca3751fe239da5934c23a783c3422618336e8vboxsync#define LPT_ECP_CONFIGA_FIFO_WIDTH_32 0x20
4fbca3751fe239da5934c23a783c3422618336e8vboxsync#define LPT_ECP_CONFIGA_FIFO_WIDTH_8 0x10
4fbca3751fe239da5934c23a783c3422618336e8vboxsync
4fbca3751fe239da5934c23a783c3422618336e8vboxsync#define LPT_ECP_FIFO_DEPTH 2
4fbca3751fe239da5934c23a783c3422618336e8vboxsync
4fbca3751fe239da5934c23a783c3422618336e8vboxsync
a6e58d30b4d856cf924fda15cd743fed386fff93vboxsync/*******************************************************************************
a6e58d30b4d856cf924fda15cd743fed386fff93vboxsync* Structures and Typedefs *
a6e58d30b4d856cf924fda15cd743fed386fff93vboxsync*******************************************************************************/
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync/**
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * Parallel device state.
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync *
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * @implements PDMIBASE
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * @implements PDMIHOSTPARALLELPORT
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync */
c74832c7184337c330041742d88e6dacaa07b378vboxsynctypedef struct ParallelState
c74832c7184337c330041742d88e6dacaa07b378vboxsync{
c74832c7184337c330041742d88e6dacaa07b378vboxsync /** Access critical section. */
c74832c7184337c330041742d88e6dacaa07b378vboxsync PDMCRITSECT CritSect;
c74832c7184337c330041742d88e6dacaa07b378vboxsync
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync /** Pointer to the device instance - R3 Ptr */
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync PPDMDEVINSR3 pDevInsR3;
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync /** Pointer to the device instance - R0 Ptr */
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync PPDMDEVINSR0 pDevInsR0;
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync /** Pointer to the device instance - RC Ptr */
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync PPDMDEVINSRC pDevInsRC;
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync RTRCPTR Alignment0; /**< Alignment. */
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync /** LUN\#0: The base interface. */
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync PDMIBASE IBase;
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync /** LUN\#0: The host device port interface. */
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync PDMIHOSTPARALLELPORT IHostParallelPort;
c74832c7184337c330041742d88e6dacaa07b378vboxsync /** Pointer to the attached base driver. */
0c34933fc8f84dd5183d1897881bbc7683d24541vboxsync R3PTRTYPE(PPDMIBASE) pDrvBase;
c74832c7184337c330041742d88e6dacaa07b378vboxsync /** Pointer to the attached host device. */
4fbca3751fe239da5934c23a783c3422618336e8vboxsync R3PTRTYPE(PPDMIHOSTPARALLELCONNECTOR) pDrvHostParallelConnector;
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync /** Unused event semaphore... */
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync RTSEMEVENT ReceiveSem;
c74832c7184337c330041742d88e6dacaa07b378vboxsync
c74832c7184337c330041742d88e6dacaa07b378vboxsync uint8_t reg_data;
c74832c7184337c330041742d88e6dacaa07b378vboxsync uint8_t reg_status;
c74832c7184337c330041742d88e6dacaa07b378vboxsync uint8_t reg_control;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync uint8_t reg_epp_addr;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync uint8_t reg_epp_data;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync uint8_t reg_ecp_ecr;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync uint8_t reg_ecp_base_plus_400h; /* has different meanings */
4fbca3751fe239da5934c23a783c3422618336e8vboxsync uint8_t reg_ecp_config_b;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync
4fbca3751fe239da5934c23a783c3422618336e8vboxsync /** The ECP FIFO implementation*/
4fbca3751fe239da5934c23a783c3422618336e8vboxsync uint8_t ecp_fifo[LPT_ECP_FIFO_DEPTH];
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync uint8_t abAlignemnt[2];
4fbca3751fe239da5934c23a783c3422618336e8vboxsync int act_fifo_pos_write;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync int act_fifo_pos_read;
c74832c7184337c330041742d88e6dacaa07b378vboxsync
c74832c7184337c330041742d88e6dacaa07b378vboxsync int irq;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync uint8_t epp_timeout;
c74832c7184337c330041742d88e6dacaa07b378vboxsync
c74832c7184337c330041742d88e6dacaa07b378vboxsync bool fGCEnabled;
c74832c7184337c330041742d88e6dacaa07b378vboxsync bool fR0Enabled;
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync bool afAlignment[1];
c74832c7184337c330041742d88e6dacaa07b378vboxsync
c74832c7184337c330041742d88e6dacaa07b378vboxsync uint32_t base;
c74832c7184337c330041742d88e6dacaa07b378vboxsync
c74832c7184337c330041742d88e6dacaa07b378vboxsync} DEVPARALLELSTATE, *PDEVPARALLELSTATE;
c74832c7184337c330041742d88e6dacaa07b378vboxsynctypedef DEVPARALLELSTATE ParallelState;
c74832c7184337c330041742d88e6dacaa07b378vboxsync
c74832c7184337c330041742d88e6dacaa07b378vboxsync#ifndef VBOX_DEVICE_STRUCT_TESTCASE
c74832c7184337c330041742d88e6dacaa07b378vboxsync
a6e58d30b4d856cf924fda15cd743fed386fff93vboxsync#define PDMIHOSTPARALLELPORT_2_PARALLELSTATE(pInstance) ( (ParallelState *)((uintptr_t)(pInterface) - RT_OFFSETOF(ParallelState, IHostParallelPort)) )
c74832c7184337c330041742d88e6dacaa07b378vboxsync#define PDMIHOSTDEVICEPORT_2_PARALLELSTATE(pInstance) ( (ParallelState *)((uintptr_t)(pInterface) - RT_OFFSETOF(ParallelState, IHostDevicePort)) )
a6e58d30b4d856cf924fda15cd743fed386fff93vboxsync#define PDMIBASE_2_PARALLELSTATE(pInstance) ( (ParallelState *)((uintptr_t)(pInterface) - RT_OFFSETOF(ParallelState, IBase)) )
c74832c7184337c330041742d88e6dacaa07b378vboxsync
a6e58d30b4d856cf924fda15cd743fed386fff93vboxsync
a6e58d30b4d856cf924fda15cd743fed386fff93vboxsync/*******************************************************************************
a6e58d30b4d856cf924fda15cd743fed386fff93vboxsync* Internal Functions *
a6e58d30b4d856cf924fda15cd743fed386fff93vboxsync*******************************************************************************/
590bfe12ce22cd3716448fbb9f4dc51664bfe5e2vboxsyncRT_C_DECLS_BEGIN
c74832c7184337c330041742d88e6dacaa07b378vboxsyncPDMBOTHCBDECL(int) parallelIOPortRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb);
c74832c7184337c330041742d88e6dacaa07b378vboxsyncPDMBOTHCBDECL(int) parallelIOPortWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb);
4fbca3751fe239da5934c23a783c3422618336e8vboxsync#if 0
4fbca3751fe239da5934c23a783c3422618336e8vboxsyncPDMBOTHCBDECL(int) parallelIOPortReadECP(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb);
4fbca3751fe239da5934c23a783c3422618336e8vboxsyncPDMBOTHCBDECL(int) parallelIOPortWriteECP(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb);
4fbca3751fe239da5934c23a783c3422618336e8vboxsync#endif
590bfe12ce22cd3716448fbb9f4dc51664bfe5e2vboxsyncRT_C_DECLS_END
c74832c7184337c330041742d88e6dacaa07b378vboxsync
a6e58d30b4d856cf924fda15cd743fed386fff93vboxsync
509c0d9c2c05b40f3f07f79e44c06c9395c1b293vboxsync#ifdef IN_RING3
4fbca3751fe239da5934c23a783c3422618336e8vboxsyncstatic void parallel_set_irq(ParallelState *s)
c74832c7184337c330041742d88e6dacaa07b378vboxsync{
4fbca3751fe239da5934c23a783c3422618336e8vboxsync if (s->reg_control & LPT_CONTROL_ENABLE_IRQ_VIA_ACK)
4fbca3751fe239da5934c23a783c3422618336e8vboxsync {
c74832c7184337c330041742d88e6dacaa07b378vboxsync Log(("parallel_update_irq %d 1\n", s->irq));
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync PDMDevHlpISASetIrqNoWait(s->CTX_SUFF(pDevIns), s->irq, 1);
c74832c7184337c330041742d88e6dacaa07b378vboxsync }
c74832c7184337c330041742d88e6dacaa07b378vboxsync}
c74832c7184337c330041742d88e6dacaa07b378vboxsync
4fbca3751fe239da5934c23a783c3422618336e8vboxsyncstatic void parallel_clear_irq(ParallelState *s)
4fbca3751fe239da5934c23a783c3422618336e8vboxsync{
4fbca3751fe239da5934c23a783c3422618336e8vboxsync Log(("parallel_update_irq %d 0\n", s->irq));
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync PDMDevHlpISASetIrqNoWait(s->CTX_SUFF(pDevIns), s->irq, 0);
4fbca3751fe239da5934c23a783c3422618336e8vboxsync}
509c0d9c2c05b40f3f07f79e44c06c9395c1b293vboxsync#endif
4fbca3751fe239da5934c23a783c3422618336e8vboxsync
c74832c7184337c330041742d88e6dacaa07b378vboxsyncstatic int parallel_ioport_write(void *opaque, uint32_t addr, uint32_t val)
c74832c7184337c330041742d88e6dacaa07b378vboxsync{
c74832c7184337c330041742d88e6dacaa07b378vboxsync ParallelState *s = (ParallelState *)opaque;
c74832c7184337c330041742d88e6dacaa07b378vboxsync unsigned char ch;
c74832c7184337c330041742d88e6dacaa07b378vboxsync
c74832c7184337c330041742d88e6dacaa07b378vboxsync addr &= 7;
c74832c7184337c330041742d88e6dacaa07b378vboxsync LogFlow(("parallel: write addr=0x%02x val=0x%02x\n", addr, val));
4fbca3751fe239da5934c23a783c3422618336e8vboxsync ch = val;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync
c74832c7184337c330041742d88e6dacaa07b378vboxsync switch(addr) {
c74832c7184337c330041742d88e6dacaa07b378vboxsync default:
c74832c7184337c330041742d88e6dacaa07b378vboxsync case 0:
c74832c7184337c330041742d88e6dacaa07b378vboxsync#ifndef IN_RING3
c74832c7184337c330041742d88e6dacaa07b378vboxsync NOREF(ch);
c74832c7184337c330041742d88e6dacaa07b378vboxsync return VINF_IOM_HC_IOPORT_WRITE;
c74832c7184337c330041742d88e6dacaa07b378vboxsync#else
c74832c7184337c330041742d88e6dacaa07b378vboxsync s->reg_data = ch;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync if (RT_LIKELY(s->pDrvHostParallelConnector))
c74832c7184337c330041742d88e6dacaa07b378vboxsync {
c74832c7184337c330041742d88e6dacaa07b378vboxsync Log(("parallel_io_port_write: write 0x%X\n", ch));
c74832c7184337c330041742d88e6dacaa07b378vboxsync size_t cbWrite = 1;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync int rc = s->pDrvHostParallelConnector->pfnWrite(s->pDrvHostParallelConnector, &ch, &cbWrite);
c74832c7184337c330041742d88e6dacaa07b378vboxsync AssertRC(rc);
c74832c7184337c330041742d88e6dacaa07b378vboxsync }
c74832c7184337c330041742d88e6dacaa07b378vboxsync#endif
c74832c7184337c330041742d88e6dacaa07b378vboxsync break;
c74832c7184337c330041742d88e6dacaa07b378vboxsync case 1:
c74832c7184337c330041742d88e6dacaa07b378vboxsync break;
c74832c7184337c330041742d88e6dacaa07b378vboxsync case 2:
6f8a1ec7a08590986f176ea072ad499630fe5b6evboxsync /* Set the reserved bits to one */
4fbca3751fe239da5934c23a783c3422618336e8vboxsync ch |= (LPT_CONTROL_BIT6 | LPT_CONTROL_BIT7);
4fbca3751fe239da5934c23a783c3422618336e8vboxsync if (ch != s->reg_control) {
4fbca3751fe239da5934c23a783c3422618336e8vboxsync#ifndef IN_RING3
4fbca3751fe239da5934c23a783c3422618336e8vboxsync return VINF_IOM_HC_IOPORT_WRITE;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync#else
4fbca3751fe239da5934c23a783c3422618336e8vboxsync int rc = s->pDrvHostParallelConnector->pfnWriteControl(s->pDrvHostParallelConnector, ch);
4fbca3751fe239da5934c23a783c3422618336e8vboxsync AssertRC(rc);
4fbca3751fe239da5934c23a783c3422618336e8vboxsync s->reg_control = val;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync#endif
4fbca3751fe239da5934c23a783c3422618336e8vboxsync }
c74832c7184337c330041742d88e6dacaa07b378vboxsync break;
c74832c7184337c330041742d88e6dacaa07b378vboxsync case 3:
4fbca3751fe239da5934c23a783c3422618336e8vboxsync s->reg_epp_addr = val;
c74832c7184337c330041742d88e6dacaa07b378vboxsync break;
c74832c7184337c330041742d88e6dacaa07b378vboxsync case 4:
4fbca3751fe239da5934c23a783c3422618336e8vboxsync s->reg_epp_data = val;
c74832c7184337c330041742d88e6dacaa07b378vboxsync break;
c74832c7184337c330041742d88e6dacaa07b378vboxsync case 5:
c74832c7184337c330041742d88e6dacaa07b378vboxsync break;
c74832c7184337c330041742d88e6dacaa07b378vboxsync case 6:
c74832c7184337c330041742d88e6dacaa07b378vboxsync break;
c74832c7184337c330041742d88e6dacaa07b378vboxsync case 7:
c74832c7184337c330041742d88e6dacaa07b378vboxsync break;
c74832c7184337c330041742d88e6dacaa07b378vboxsync }
c74832c7184337c330041742d88e6dacaa07b378vboxsync return VINF_SUCCESS;
c74832c7184337c330041742d88e6dacaa07b378vboxsync}
c74832c7184337c330041742d88e6dacaa07b378vboxsync
c74832c7184337c330041742d88e6dacaa07b378vboxsyncstatic uint32_t parallel_ioport_read(void *opaque, uint32_t addr, int *pRC)
c74832c7184337c330041742d88e6dacaa07b378vboxsync{
c74832c7184337c330041742d88e6dacaa07b378vboxsync ParallelState *s = (ParallelState *)opaque;
c74832c7184337c330041742d88e6dacaa07b378vboxsync uint32_t ret = ~0U;
c74832c7184337c330041742d88e6dacaa07b378vboxsync
c74832c7184337c330041742d88e6dacaa07b378vboxsync *pRC = VINF_SUCCESS;
c74832c7184337c330041742d88e6dacaa07b378vboxsync
c74832c7184337c330041742d88e6dacaa07b378vboxsync addr &= 7;
c74832c7184337c330041742d88e6dacaa07b378vboxsync switch(addr) {
c74832c7184337c330041742d88e6dacaa07b378vboxsync default:
c74832c7184337c330041742d88e6dacaa07b378vboxsync case 0:
4fbca3751fe239da5934c23a783c3422618336e8vboxsync if (!(s->reg_control & LPT_CONTROL_ENABLE_BIDIRECT))
4fbca3751fe239da5934c23a783c3422618336e8vboxsync ret = s->reg_data;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync else
4fbca3751fe239da5934c23a783c3422618336e8vboxsync {
c74832c7184337c330041742d88e6dacaa07b378vboxsync#ifndef IN_RING3
c74832c7184337c330041742d88e6dacaa07b378vboxsync *pRC = VINF_IOM_HC_IOPORT_READ;
c74832c7184337c330041742d88e6dacaa07b378vboxsync#else
4fbca3751fe239da5934c23a783c3422618336e8vboxsync if (RT_LIKELY(s->pDrvHostParallelConnector))
c74832c7184337c330041742d88e6dacaa07b378vboxsync {
c74832c7184337c330041742d88e6dacaa07b378vboxsync size_t cbRead;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync int rc = s->pDrvHostParallelConnector->pfnRead(s->pDrvHostParallelConnector, &s->reg_data, &cbRead);
c74832c7184337c330041742d88e6dacaa07b378vboxsync Log(("parallel_io_port_read: read 0x%X\n", s->reg_data));
c74832c7184337c330041742d88e6dacaa07b378vboxsync AssertRC(rc);
c74832c7184337c330041742d88e6dacaa07b378vboxsync }
c74832c7184337c330041742d88e6dacaa07b378vboxsync ret = s->reg_data;
c74832c7184337c330041742d88e6dacaa07b378vboxsync#endif
4fbca3751fe239da5934c23a783c3422618336e8vboxsync }
c74832c7184337c330041742d88e6dacaa07b378vboxsync break;
c74832c7184337c330041742d88e6dacaa07b378vboxsync case 1:
4fbca3751fe239da5934c23a783c3422618336e8vboxsync#ifndef IN_RING3
4fbca3751fe239da5934c23a783c3422618336e8vboxsync *pRC = VINF_IOM_HC_IOPORT_READ;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync#else
4fbca3751fe239da5934c23a783c3422618336e8vboxsync if (RT_LIKELY(s->pDrvHostParallelConnector))
4fbca3751fe239da5934c23a783c3422618336e8vboxsync {
4fbca3751fe239da5934c23a783c3422618336e8vboxsync int rc = s->pDrvHostParallelConnector->pfnReadStatus(s->pDrvHostParallelConnector, &s->reg_status);
4fbca3751fe239da5934c23a783c3422618336e8vboxsync AssertRC(rc);
4fbca3751fe239da5934c23a783c3422618336e8vboxsync }
c74832c7184337c330041742d88e6dacaa07b378vboxsync ret = s->reg_status;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync parallel_clear_irq(s);
4fbca3751fe239da5934c23a783c3422618336e8vboxsync#endif
c74832c7184337c330041742d88e6dacaa07b378vboxsync break;
c74832c7184337c330041742d88e6dacaa07b378vboxsync case 2:
c74832c7184337c330041742d88e6dacaa07b378vboxsync ret = s->reg_control;
c74832c7184337c330041742d88e6dacaa07b378vboxsync break;
c74832c7184337c330041742d88e6dacaa07b378vboxsync case 3:
4fbca3751fe239da5934c23a783c3422618336e8vboxsync ret = s->reg_epp_addr;
c74832c7184337c330041742d88e6dacaa07b378vboxsync break;
c74832c7184337c330041742d88e6dacaa07b378vboxsync case 4:
4fbca3751fe239da5934c23a783c3422618336e8vboxsync ret = s->reg_epp_data;
c74832c7184337c330041742d88e6dacaa07b378vboxsync break;
c74832c7184337c330041742d88e6dacaa07b378vboxsync case 5:
c74832c7184337c330041742d88e6dacaa07b378vboxsync break;
c74832c7184337c330041742d88e6dacaa07b378vboxsync case 6:
c74832c7184337c330041742d88e6dacaa07b378vboxsync break;
c74832c7184337c330041742d88e6dacaa07b378vboxsync case 7:
c74832c7184337c330041742d88e6dacaa07b378vboxsync break;
c74832c7184337c330041742d88e6dacaa07b378vboxsync }
c74832c7184337c330041742d88e6dacaa07b378vboxsync LogFlow(("parallel: read addr=0x%02x val=0x%02x\n", addr, ret));
c74832c7184337c330041742d88e6dacaa07b378vboxsync return ret;
c74832c7184337c330041742d88e6dacaa07b378vboxsync}
c74832c7184337c330041742d88e6dacaa07b378vboxsync
4fbca3751fe239da5934c23a783c3422618336e8vboxsync#if 0
4fbca3751fe239da5934c23a783c3422618336e8vboxsyncstatic int parallel_ioport_write_ecp(void *opaque, uint32_t addr, uint32_t val)
c74832c7184337c330041742d88e6dacaa07b378vboxsync{
4fbca3751fe239da5934c23a783c3422618336e8vboxsync ParallelState *s = (ParallelState *)opaque;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync unsigned char ch;
c74832c7184337c330041742d88e6dacaa07b378vboxsync
4fbca3751fe239da5934c23a783c3422618336e8vboxsync addr &= 7;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync LogFlow(("parallel: write ecp addr=0x%02x val=0x%02x\n", addr, val));
4fbca3751fe239da5934c23a783c3422618336e8vboxsync ch = val;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync switch(addr) {
4fbca3751fe239da5934c23a783c3422618336e8vboxsync default:
4fbca3751fe239da5934c23a783c3422618336e8vboxsync case 0:
4fbca3751fe239da5934c23a783c3422618336e8vboxsync if (LPT_ECP_ECR_CHIPMODE_GET_BITS(s->reg_ecp_ecr) == LPT_ECP_ECR_CHIPMODE_FIFO_TEST) {
4fbca3751fe239da5934c23a783c3422618336e8vboxsync s->ecp_fifo[s->act_fifo_pos_write] = ch;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync s->act_fifo_pos_write++;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync if (s->act_fifo_pos_write < LPT_ECP_FIFO_DEPTH) {
6f8a1ec7a08590986f176ea072ad499630fe5b6evboxsync /* FIFO has some data (clear both FIFO bits) */
4fbca3751fe239da5934c23a783c3422618336e8vboxsync s->reg_ecp_ecr &= ~(LPT_ECP_ECR_FIFO_EMPTY | LPT_ECP_ECR_FIFO_FULL);
4fbca3751fe239da5934c23a783c3422618336e8vboxsync } else {
6f8a1ec7a08590986f176ea072ad499630fe5b6evboxsync /* FIFO is full */
6f8a1ec7a08590986f176ea072ad499630fe5b6evboxsync /* Clear FIFO empty bit */
4fbca3751fe239da5934c23a783c3422618336e8vboxsync s->reg_ecp_ecr &= ~LPT_ECP_ECR_FIFO_EMPTY;
6f8a1ec7a08590986f176ea072ad499630fe5b6evboxsync /* Set FIFO full bit */
4fbca3751fe239da5934c23a783c3422618336e8vboxsync s->reg_ecp_ecr |= LPT_ECP_ECR_FIFO_FULL;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync s->act_fifo_pos_write = 0;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync }
4fbca3751fe239da5934c23a783c3422618336e8vboxsync } else {
4fbca3751fe239da5934c23a783c3422618336e8vboxsync s->reg_ecp_base_plus_400h = ch;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync }
4fbca3751fe239da5934c23a783c3422618336e8vboxsync break;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync case 1:
4fbca3751fe239da5934c23a783c3422618336e8vboxsync s->reg_ecp_config_b = ch;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync break;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync case 2:
6f8a1ec7a08590986f176ea072ad499630fe5b6evboxsync /* If we change the mode clear FIFO */
4fbca3751fe239da5934c23a783c3422618336e8vboxsync if ((ch & LPT_ECP_ECR_CHIPMODE_MASK) != (s->reg_ecp_ecr & LPT_ECP_ECR_CHIPMODE_MASK)) {
6f8a1ec7a08590986f176ea072ad499630fe5b6evboxsync /* reset the fifo */
4fbca3751fe239da5934c23a783c3422618336e8vboxsync s->act_fifo_pos_write = 0;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync s->act_fifo_pos_read = 0;
6f8a1ec7a08590986f176ea072ad499630fe5b6evboxsync /* Set FIFO empty bit */
4fbca3751fe239da5934c23a783c3422618336e8vboxsync s->reg_ecp_ecr |= LPT_ECP_ECR_FIFO_EMPTY;
6f8a1ec7a08590986f176ea072ad499630fe5b6evboxsync /* Clear FIFO full bit */
4fbca3751fe239da5934c23a783c3422618336e8vboxsync s->reg_ecp_ecr &= ~LPT_ECP_ECR_FIFO_FULL;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync }
6f8a1ec7a08590986f176ea072ad499630fe5b6evboxsync /* Set new mode */
4fbca3751fe239da5934c23a783c3422618336e8vboxsync s->reg_ecp_ecr |= LPT_ECP_ECR_CHIPMODE_SET_BITS(LPT_ECP_ECR_CHIPMODE_GET_BITS(ch));
4fbca3751fe239da5934c23a783c3422618336e8vboxsync break;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync case 3:
4fbca3751fe239da5934c23a783c3422618336e8vboxsync break;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync case 4:
4fbca3751fe239da5934c23a783c3422618336e8vboxsync break;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync case 5:
4fbca3751fe239da5934c23a783c3422618336e8vboxsync break;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync case 6:
4fbca3751fe239da5934c23a783c3422618336e8vboxsync break;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync case 7:
4fbca3751fe239da5934c23a783c3422618336e8vboxsync break;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync }
c74832c7184337c330041742d88e6dacaa07b378vboxsync return VINF_SUCCESS;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync}
c74832c7184337c330041742d88e6dacaa07b378vboxsync
4fbca3751fe239da5934c23a783c3422618336e8vboxsyncstatic uint32_t parallel_ioport_read_ecp(void *opaque, uint32_t addr, int *pRC)
4fbca3751fe239da5934c23a783c3422618336e8vboxsync{
4fbca3751fe239da5934c23a783c3422618336e8vboxsync ParallelState *s = (ParallelState *)opaque;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync uint32_t ret = ~0U;
c74832c7184337c330041742d88e6dacaa07b378vboxsync
4fbca3751fe239da5934c23a783c3422618336e8vboxsync *pRC = VINF_SUCCESS;
c74832c7184337c330041742d88e6dacaa07b378vboxsync
4fbca3751fe239da5934c23a783c3422618336e8vboxsync addr &= 7;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync switch(addr) {
4fbca3751fe239da5934c23a783c3422618336e8vboxsync default:
4fbca3751fe239da5934c23a783c3422618336e8vboxsync case 0:
4fbca3751fe239da5934c23a783c3422618336e8vboxsync if (LPT_ECP_ECR_CHIPMODE_GET_BITS(s->reg_ecp_ecr) == LPT_ECP_ECR_CHIPMODE_FIFO_TEST) {
4fbca3751fe239da5934c23a783c3422618336e8vboxsync ret = s->ecp_fifo[s->act_fifo_pos_read];
4fbca3751fe239da5934c23a783c3422618336e8vboxsync s->act_fifo_pos_read++;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync if (s->act_fifo_pos_read == LPT_ECP_FIFO_DEPTH)
6f8a1ec7a08590986f176ea072ad499630fe5b6evboxsync s->act_fifo_pos_read = 0; /* end of FIFO, start at beginning */
4fbca3751fe239da5934c23a783c3422618336e8vboxsync if (s->act_fifo_pos_read == s->act_fifo_pos_write) {
6f8a1ec7a08590986f176ea072ad499630fe5b6evboxsync /* FIFO is empty */
6f8a1ec7a08590986f176ea072ad499630fe5b6evboxsync /* Set FIFO empty bit */
4fbca3751fe239da5934c23a783c3422618336e8vboxsync s->reg_ecp_ecr |= LPT_ECP_ECR_FIFO_EMPTY;
6f8a1ec7a08590986f176ea072ad499630fe5b6evboxsync /* Clear FIFO full bit */
4fbca3751fe239da5934c23a783c3422618336e8vboxsync s->reg_ecp_ecr &= ~LPT_ECP_ECR_FIFO_FULL;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync } else {
6f8a1ec7a08590986f176ea072ad499630fe5b6evboxsync /* FIFO has some data (clear all FIFO bits) */
4fbca3751fe239da5934c23a783c3422618336e8vboxsync s->reg_ecp_ecr &= ~(LPT_ECP_ECR_FIFO_EMPTY | LPT_ECP_ECR_FIFO_FULL);
4fbca3751fe239da5934c23a783c3422618336e8vboxsync }
4fbca3751fe239da5934c23a783c3422618336e8vboxsync } else {
4fbca3751fe239da5934c23a783c3422618336e8vboxsync ret = s->reg_ecp_base_plus_400h;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync }
4fbca3751fe239da5934c23a783c3422618336e8vboxsync break;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync case 1:
4fbca3751fe239da5934c23a783c3422618336e8vboxsync ret = s->reg_ecp_config_b;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync break;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync case 2:
4fbca3751fe239da5934c23a783c3422618336e8vboxsync ret = s->reg_ecp_ecr;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync break;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync case 3:
4fbca3751fe239da5934c23a783c3422618336e8vboxsync break;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync case 4:
4fbca3751fe239da5934c23a783c3422618336e8vboxsync break;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync case 5:
4fbca3751fe239da5934c23a783c3422618336e8vboxsync break;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync case 6:
4fbca3751fe239da5934c23a783c3422618336e8vboxsync break;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync case 7:
4fbca3751fe239da5934c23a783c3422618336e8vboxsync break;
c74832c7184337c330041742d88e6dacaa07b378vboxsync }
4fbca3751fe239da5934c23a783c3422618336e8vboxsync LogFlow(("parallel: read ecp addr=0x%02x val=0x%02x\n", addr, ret));
4fbca3751fe239da5934c23a783c3422618336e8vboxsync return ret;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync}
4fbca3751fe239da5934c23a783c3422618336e8vboxsync#endif
c74832c7184337c330041742d88e6dacaa07b378vboxsync
4fbca3751fe239da5934c23a783c3422618336e8vboxsync#ifdef IN_RING3
4fbca3751fe239da5934c23a783c3422618336e8vboxsyncstatic DECLCALLBACK(int) parallelNotifyInterrupt(PPDMIHOSTPARALLELPORT pInterface)
4fbca3751fe239da5934c23a783c3422618336e8vboxsync{
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync ParallelState *pThis = PDMIHOSTPARALLELPORT_2_PARALLELSTATE(pInterface);
4fbca3751fe239da5934c23a783c3422618336e8vboxsync
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync PDMCritSectEnter(&pThis->CritSect, VINF_SUCCESS);
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync parallel_set_irq(pThis);
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync PDMCritSectLeave(&pThis->CritSect);
c74832c7184337c330041742d88e6dacaa07b378vboxsync
4fbca3751fe239da5934c23a783c3422618336e8vboxsync return VINF_SUCCESS;
c74832c7184337c330041742d88e6dacaa07b378vboxsync}
c74832c7184337c330041742d88e6dacaa07b378vboxsync#endif /* IN_RING3 */
c74832c7184337c330041742d88e6dacaa07b378vboxsync
c74832c7184337c330041742d88e6dacaa07b378vboxsync/**
c74832c7184337c330041742d88e6dacaa07b378vboxsync * Port I/O Handler for OUT operations.
c74832c7184337c330041742d88e6dacaa07b378vboxsync *
c74832c7184337c330041742d88e6dacaa07b378vboxsync * @returns VBox status code.
c74832c7184337c330041742d88e6dacaa07b378vboxsync *
c74832c7184337c330041742d88e6dacaa07b378vboxsync * @param pDevIns The device instance.
c74832c7184337c330041742d88e6dacaa07b378vboxsync * @param pvUser User argument.
c74832c7184337c330041742d88e6dacaa07b378vboxsync * @param Port Port number used for the IN operation.
c74832c7184337c330041742d88e6dacaa07b378vboxsync * @param u32 The value to output.
c74832c7184337c330041742d88e6dacaa07b378vboxsync * @param cb The value size in bytes.
c74832c7184337c330041742d88e6dacaa07b378vboxsync */
c74832c7184337c330041742d88e6dacaa07b378vboxsyncPDMBOTHCBDECL(int) parallelIOPortWrite(PPDMDEVINS pDevIns, void *pvUser,
c74832c7184337c330041742d88e6dacaa07b378vboxsync RTIOPORT Port, uint32_t u32, unsigned cb)
c74832c7184337c330041742d88e6dacaa07b378vboxsync{
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync ParallelState *pThis = PDMINS_2_DATA(pDevIns, ParallelState *);
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync int rc = VINF_SUCCESS;
c74832c7184337c330041742d88e6dacaa07b378vboxsync
c74832c7184337c330041742d88e6dacaa07b378vboxsync if (cb == 1)
c74832c7184337c330041742d88e6dacaa07b378vboxsync {
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync rc = PDMCritSectEnter(&pThis->CritSect, VINF_IOM_HC_IOPORT_WRITE);
c74832c7184337c330041742d88e6dacaa07b378vboxsync if (rc == VINF_SUCCESS)
c74832c7184337c330041742d88e6dacaa07b378vboxsync {
c74832c7184337c330041742d88e6dacaa07b378vboxsync Log2(("%s: port %#06x val %#04x\n", __FUNCTION__, Port, u32));
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync rc = parallel_ioport_write (pThis, Port, u32);
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync PDMCritSectLeave(&pThis->CritSect);
c74832c7184337c330041742d88e6dacaa07b378vboxsync }
c74832c7184337c330041742d88e6dacaa07b378vboxsync }
c74832c7184337c330041742d88e6dacaa07b378vboxsync else
c74832c7184337c330041742d88e6dacaa07b378vboxsync AssertMsgFailed(("Port=%#x cb=%d u32=%#x\n", Port, cb, u32));
c74832c7184337c330041742d88e6dacaa07b378vboxsync
c74832c7184337c330041742d88e6dacaa07b378vboxsync return rc;
c74832c7184337c330041742d88e6dacaa07b378vboxsync}
c74832c7184337c330041742d88e6dacaa07b378vboxsync
c74832c7184337c330041742d88e6dacaa07b378vboxsync/**
c74832c7184337c330041742d88e6dacaa07b378vboxsync * Port I/O Handler for IN operations.
c74832c7184337c330041742d88e6dacaa07b378vboxsync *
c74832c7184337c330041742d88e6dacaa07b378vboxsync * @returns VBox status code.
c74832c7184337c330041742d88e6dacaa07b378vboxsync *
c74832c7184337c330041742d88e6dacaa07b378vboxsync * @param pDevIns The device instance.
c74832c7184337c330041742d88e6dacaa07b378vboxsync * @param pvUser User argument.
c74832c7184337c330041742d88e6dacaa07b378vboxsync * @param Port Port number used for the IN operation.
d59a43b735abea2db17caa9b5661d2f5118f0e02vboxsync * @param pu32 Where to return the read value.
c74832c7184337c330041742d88e6dacaa07b378vboxsync * @param cb The value size in bytes.
c74832c7184337c330041742d88e6dacaa07b378vboxsync */
c74832c7184337c330041742d88e6dacaa07b378vboxsyncPDMBOTHCBDECL(int) parallelIOPortRead(PPDMDEVINS pDevIns, void *pvUser,
c74832c7184337c330041742d88e6dacaa07b378vboxsync RTIOPORT Port, uint32_t *pu32, unsigned cb)
c74832c7184337c330041742d88e6dacaa07b378vboxsync{
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync ParallelState *pThis = PDMINS_2_DATA(pDevIns, ParallelState *);
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync int rc = VINF_SUCCESS;
c74832c7184337c330041742d88e6dacaa07b378vboxsync
c74832c7184337c330041742d88e6dacaa07b378vboxsync if (cb == 1)
c74832c7184337c330041742d88e6dacaa07b378vboxsync {
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync rc = PDMCritSectEnter(&pThis->CritSect, VINF_IOM_HC_IOPORT_READ);
c74832c7184337c330041742d88e6dacaa07b378vboxsync if (rc == VINF_SUCCESS)
c74832c7184337c330041742d88e6dacaa07b378vboxsync {
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync *pu32 = parallel_ioport_read (pThis, Port, &rc);
c74832c7184337c330041742d88e6dacaa07b378vboxsync Log2(("%s: port %#06x val %#04x\n", __FUNCTION__, Port, *pu32));
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync PDMCritSectLeave(&pThis->CritSect);
c74832c7184337c330041742d88e6dacaa07b378vboxsync }
c74832c7184337c330041742d88e6dacaa07b378vboxsync }
c74832c7184337c330041742d88e6dacaa07b378vboxsync else
c74832c7184337c330041742d88e6dacaa07b378vboxsync rc = VERR_IOM_IOPORT_UNUSED;
c74832c7184337c330041742d88e6dacaa07b378vboxsync
c74832c7184337c330041742d88e6dacaa07b378vboxsync return rc;
c74832c7184337c330041742d88e6dacaa07b378vboxsync}
c74832c7184337c330041742d88e6dacaa07b378vboxsync
4fbca3751fe239da5934c23a783c3422618336e8vboxsync#if 0
4fbca3751fe239da5934c23a783c3422618336e8vboxsync/**
4fbca3751fe239da5934c23a783c3422618336e8vboxsync * Port I/O Handler for OUT operations on ECP registers.
4fbca3751fe239da5934c23a783c3422618336e8vboxsync *
4fbca3751fe239da5934c23a783c3422618336e8vboxsync * @returns VBox status code.
4fbca3751fe239da5934c23a783c3422618336e8vboxsync *
4fbca3751fe239da5934c23a783c3422618336e8vboxsync * @param pDevIns The device instance.
4fbca3751fe239da5934c23a783c3422618336e8vboxsync * @param pvUser User argument.
4fbca3751fe239da5934c23a783c3422618336e8vboxsync * @param Port Port number used for the IN operation.
4fbca3751fe239da5934c23a783c3422618336e8vboxsync * @param u32 The value to output.
4fbca3751fe239da5934c23a783c3422618336e8vboxsync * @param cb The value size in bytes.
4fbca3751fe239da5934c23a783c3422618336e8vboxsync */
4fbca3751fe239da5934c23a783c3422618336e8vboxsyncPDMBOTHCBDECL(int) parallelIOPortWriteECP(PPDMDEVINS pDevIns, void *pvUser,
4fbca3751fe239da5934c23a783c3422618336e8vboxsync RTIOPORT Port, uint32_t u32, unsigned cb)
4fbca3751fe239da5934c23a783c3422618336e8vboxsync{
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync ParallelState *pThis = PDMINS_2_DATA(pDevIns, ParallelState *);
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync int rc = VINF_SUCCESS;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync
4fbca3751fe239da5934c23a783c3422618336e8vboxsync if (cb == 1)
4fbca3751fe239da5934c23a783c3422618336e8vboxsync {
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync rc = PDMCritSectEnter(&pThis->CritSect, VINF_IOM_HC_IOPORT_WRITE);
4fbca3751fe239da5934c23a783c3422618336e8vboxsync if (rc == VINF_SUCCESS)
4fbca3751fe239da5934c23a783c3422618336e8vboxsync {
4fbca3751fe239da5934c23a783c3422618336e8vboxsync Log2(("%s: ecp port %#06x val %#04x\n", __FUNCTION__, Port, u32));
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync rc = parallel_ioport_write_ecp (pThis, Port, u32);
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync PDMCritSectLeave(&pThis->CritSect);
4fbca3751fe239da5934c23a783c3422618336e8vboxsync }
4fbca3751fe239da5934c23a783c3422618336e8vboxsync }
4fbca3751fe239da5934c23a783c3422618336e8vboxsync else
4fbca3751fe239da5934c23a783c3422618336e8vboxsync AssertMsgFailed(("Port=%#x cb=%d u32=%#x\n", Port, cb, u32));
4fbca3751fe239da5934c23a783c3422618336e8vboxsync
4fbca3751fe239da5934c23a783c3422618336e8vboxsync return rc;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync}
4fbca3751fe239da5934c23a783c3422618336e8vboxsync
4fbca3751fe239da5934c23a783c3422618336e8vboxsync/**
4fbca3751fe239da5934c23a783c3422618336e8vboxsync * Port I/O Handler for IN operations on ECP registers.
4fbca3751fe239da5934c23a783c3422618336e8vboxsync *
4fbca3751fe239da5934c23a783c3422618336e8vboxsync * @returns VBox status code.
4fbca3751fe239da5934c23a783c3422618336e8vboxsync *
4fbca3751fe239da5934c23a783c3422618336e8vboxsync * @param pDevIns The device instance.
4fbca3751fe239da5934c23a783c3422618336e8vboxsync * @param pvUser User argument.
4fbca3751fe239da5934c23a783c3422618336e8vboxsync * @param Port Port number used for the IN operation.
4fbca3751fe239da5934c23a783c3422618336e8vboxsync * @param u32 The value to output.
4fbca3751fe239da5934c23a783c3422618336e8vboxsync * @param cb The value size in bytes.
4fbca3751fe239da5934c23a783c3422618336e8vboxsync */
4fbca3751fe239da5934c23a783c3422618336e8vboxsyncPDMBOTHCBDECL(int) parallelIOPortReadECP(PPDMDEVINS pDevIns, void *pvUser,
4fbca3751fe239da5934c23a783c3422618336e8vboxsync RTIOPORT Port, uint32_t *pu32, unsigned cb)
4fbca3751fe239da5934c23a783c3422618336e8vboxsync{
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync ParallelState *pThis = PDMINS_2_DATA(pDevIns, ParallelState *);
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync int rc = VINF_SUCCESS;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync
4fbca3751fe239da5934c23a783c3422618336e8vboxsync if (cb == 1)
4fbca3751fe239da5934c23a783c3422618336e8vboxsync {
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync rc = PDMCritSectEnter(&pThis->CritSect, VINF_IOM_HC_IOPORT_READ);
4fbca3751fe239da5934c23a783c3422618336e8vboxsync if (rc == VINF_SUCCESS)
4fbca3751fe239da5934c23a783c3422618336e8vboxsync {
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync *pu32 = parallel_ioport_read_ecp (pThis, Port, &rc);
4fbca3751fe239da5934c23a783c3422618336e8vboxsync Log2(("%s: ecp port %#06x val %#04x\n", __FUNCTION__, Port, *pu32));
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync PDMCritSectLeave(&pThis->CritSect);
4fbca3751fe239da5934c23a783c3422618336e8vboxsync }
4fbca3751fe239da5934c23a783c3422618336e8vboxsync }
4fbca3751fe239da5934c23a783c3422618336e8vboxsync else
4fbca3751fe239da5934c23a783c3422618336e8vboxsync rc = VERR_IOM_IOPORT_UNUSED;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync
4fbca3751fe239da5934c23a783c3422618336e8vboxsync return rc;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync}
4fbca3751fe239da5934c23a783c3422618336e8vboxsync#endif
4fbca3751fe239da5934c23a783c3422618336e8vboxsync
c74832c7184337c330041742d88e6dacaa07b378vboxsync#ifdef IN_RING3
c74832c7184337c330041742d88e6dacaa07b378vboxsync/**
6b98f92a0c2c5dd90d8496ee553e5763c4debd49vboxsync * @copydoc FNSSMDEVLIVEEXEC
6b98f92a0c2c5dd90d8496ee553e5763c4debd49vboxsync */
6b98f92a0c2c5dd90d8496ee553e5763c4debd49vboxsyncstatic DECLCALLBACK(int) parallelLiveExec(PPDMDEVINS pDevIns,
e7925b345f17e5bd9f0c1cf3540b7d8573ec274fvboxsync PSSMHANDLE pSSM,
6b98f92a0c2c5dd90d8496ee553e5763c4debd49vboxsync uint32_t uPass)
6b98f92a0c2c5dd90d8496ee553e5763c4debd49vboxsync{
6b98f92a0c2c5dd90d8496ee553e5763c4debd49vboxsync ParallelState *pThis = PDMINS_2_DATA(pDevIns, ParallelState *);
6b98f92a0c2c5dd90d8496ee553e5763c4debd49vboxsync
e7925b345f17e5bd9f0c1cf3540b7d8573ec274fvboxsync SSMR3PutS32(pSSM, pThis->irq);
e7925b345f17e5bd9f0c1cf3540b7d8573ec274fvboxsync SSMR3PutU32(pSSM, pThis->base);
e7925b345f17e5bd9f0c1cf3540b7d8573ec274fvboxsync SSMR3PutU32(pSSM, ~0); /* sanity/terminator */
6b98f92a0c2c5dd90d8496ee553e5763c4debd49vboxsync return VINF_SSM_DONT_CALL_AGAIN;
6b98f92a0c2c5dd90d8496ee553e5763c4debd49vboxsync}
6b98f92a0c2c5dd90d8496ee553e5763c4debd49vboxsync
6b98f92a0c2c5dd90d8496ee553e5763c4debd49vboxsync/**
6b98f92a0c2c5dd90d8496ee553e5763c4debd49vboxsync * @copydoc FNSSMDEVSAVEEXEC
c74832c7184337c330041742d88e6dacaa07b378vboxsync */
c74832c7184337c330041742d88e6dacaa07b378vboxsyncstatic DECLCALLBACK(int) parallelSaveExec(PPDMDEVINS pDevIns,
e7925b345f17e5bd9f0c1cf3540b7d8573ec274fvboxsync PSSMHANDLE pSSM)
c74832c7184337c330041742d88e6dacaa07b378vboxsync{
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync ParallelState *pThis = PDMINS_2_DATA(pDevIns, ParallelState *);
c74832c7184337c330041742d88e6dacaa07b378vboxsync
e7925b345f17e5bd9f0c1cf3540b7d8573ec274fvboxsync SSMR3PutU8(pSSM, pThis->reg_data);
e7925b345f17e5bd9f0c1cf3540b7d8573ec274fvboxsync SSMR3PutU8(pSSM, pThis->reg_status);
e7925b345f17e5bd9f0c1cf3540b7d8573ec274fvboxsync SSMR3PutU8(pSSM, pThis->reg_control);
c74832c7184337c330041742d88e6dacaa07b378vboxsync
e7925b345f17e5bd9f0c1cf3540b7d8573ec274fvboxsync parallelLiveExec(pDevIns, pSSM, 0);
6b98f92a0c2c5dd90d8496ee553e5763c4debd49vboxsync return VINF_SUCCESS;
c74832c7184337c330041742d88e6dacaa07b378vboxsync}
c74832c7184337c330041742d88e6dacaa07b378vboxsync
c74832c7184337c330041742d88e6dacaa07b378vboxsync/**
6b98f92a0c2c5dd90d8496ee553e5763c4debd49vboxsync * @copydoc FNSSMDEVLOADEXEC
c74832c7184337c330041742d88e6dacaa07b378vboxsync */
c74832c7184337c330041742d88e6dacaa07b378vboxsyncstatic DECLCALLBACK(int) parallelLoadExec(PPDMDEVINS pDevIns,
e7925b345f17e5bd9f0c1cf3540b7d8573ec274fvboxsync PSSMHANDLE pSSM,
b5d837811bf21f30a31748bbbcb28ee562bb2355vboxsync uint32_t uVersion,
6dea6d87ed79bc0994d314fed1c90431091e8820vboxsync uint32_t uPass)
c74832c7184337c330041742d88e6dacaa07b378vboxsync{
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync ParallelState *pThis = PDMINS_2_DATA(pDevIns, ParallelState *);
c74832c7184337c330041742d88e6dacaa07b378vboxsync
b5d837811bf21f30a31748bbbcb28ee562bb2355vboxsync AssertMsgReturn(uVersion == PARALLEL_SAVED_STATE_VERSION, ("%d\n", uVersion), VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION);
6dea6d87ed79bc0994d314fed1c90431091e8820vboxsync Assert(uPass == SSM_PASS_FINAL); NOREF(uPass);
6b98f92a0c2c5dd90d8496ee553e5763c4debd49vboxsync if (uPass == SSM_PASS_FINAL)
6b98f92a0c2c5dd90d8496ee553e5763c4debd49vboxsync {
e7925b345f17e5bd9f0c1cf3540b7d8573ec274fvboxsync SSMR3GetU8(pSSM, &pThis->reg_data);
e7925b345f17e5bd9f0c1cf3540b7d8573ec274fvboxsync SSMR3GetU8(pSSM, &pThis->reg_status);
e7925b345f17e5bd9f0c1cf3540b7d8573ec274fvboxsync SSMR3GetU8(pSSM, &pThis->reg_control);
6b98f92a0c2c5dd90d8496ee553e5763c4debd49vboxsync }
c74832c7184337c330041742d88e6dacaa07b378vboxsync
6b98f92a0c2c5dd90d8496ee553e5763c4debd49vboxsync /* the config */
6b98f92a0c2c5dd90d8496ee553e5763c4debd49vboxsync int32_t iIrq;
e7925b345f17e5bd9f0c1cf3540b7d8573ec274fvboxsync SSMR3GetS32(pSSM, &iIrq);
6b98f92a0c2c5dd90d8496ee553e5763c4debd49vboxsync uint32_t uIoBase;
e7925b345f17e5bd9f0c1cf3540b7d8573ec274fvboxsync SSMR3GetU32(pSSM, &uIoBase);
b5d837811bf21f30a31748bbbcb28ee562bb2355vboxsync uint32_t u32;
e7925b345f17e5bd9f0c1cf3540b7d8573ec274fvboxsync int rc = SSMR3GetU32(pSSM, &u32);
b7a5b3f9f9ecce32ddacf8404c625ce0451bbdc1vboxsync if (RT_FAILURE(rc))
c74832c7184337c330041742d88e6dacaa07b378vboxsync return rc;
b5d837811bf21f30a31748bbbcb28ee562bb2355vboxsync AssertMsgReturn(u32 == ~0U, ("%#x\n", u32), VERR_SSM_DATA_UNIT_FORMAT_CHANGED);
c74832c7184337c330041742d88e6dacaa07b378vboxsync
6b98f92a0c2c5dd90d8496ee553e5763c4debd49vboxsync if (pThis->irq != iIrq)
e7925b345f17e5bd9f0c1cf3540b7d8573ec274fvboxsync return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("IRQ changed: config=%#x state=%#x"), pThis->irq, iIrq);
6b98f92a0c2c5dd90d8496ee553e5763c4debd49vboxsync
6b98f92a0c2c5dd90d8496ee553e5763c4debd49vboxsync if (pThis->base != uIoBase)
e7925b345f17e5bd9f0c1cf3540b7d8573ec274fvboxsync return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("IOBase changed: config=%#x state=%#x"), pThis->base, uIoBase);
6b98f92a0c2c5dd90d8496ee553e5763c4debd49vboxsync
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync /* not necessary... but it doesn't harm. */
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync pThis->pDevInsR3 = pDevIns;
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync pThis->pDevInsR0 = PDMDEVINS_2_R0PTR(pDevIns);
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync pThis->pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
c74832c7184337c330041742d88e6dacaa07b378vboxsync return VINF_SUCCESS;
c74832c7184337c330041742d88e6dacaa07b378vboxsync}
c74832c7184337c330041742d88e6dacaa07b378vboxsync
c74832c7184337c330041742d88e6dacaa07b378vboxsync
c74832c7184337c330041742d88e6dacaa07b378vboxsync/**
c74832c7184337c330041742d88e6dacaa07b378vboxsync * @copydoc FNPDMDEVRELOCATE
c74832c7184337c330041742d88e6dacaa07b378vboxsync */
c74832c7184337c330041742d88e6dacaa07b378vboxsyncstatic DECLCALLBACK(void) parallelRelocate(PPDMDEVINS pDevIns, RTGCINTPTR offDelta)
c74832c7184337c330041742d88e6dacaa07b378vboxsync{
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync ParallelState *pThis = PDMINS_2_DATA(pDevIns, ParallelState *);
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync pThis->pDevInsRC += offDelta;
c74832c7184337c330041742d88e6dacaa07b378vboxsync}
c74832c7184337c330041742d88e6dacaa07b378vboxsync
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync/**
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * @interface_method_impl{PDMIBASE,pfnQueryInterface}
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync */
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsyncstatic DECLCALLBACK(void *) parallelQueryInterface(PPDMIBASE pInterface, const char *pszIID)
c74832c7184337c330041742d88e6dacaa07b378vboxsync{
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync ParallelState *pThis = PDMIBASE_2_PARALLELSTATE(pInterface);
a39ea3668b7019c23a68936259545f9b71bce1aavboxsync PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pThis->IBase);
0db6a029780d9f9b347500e117320a8d5661efe5vboxsync PDMIBASE_RETURN_INTERFACE(pszIID, PDMIHOSTPARALLELPORT, &pThis->IHostParallelPort);
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync return NULL;
c74832c7184337c330041742d88e6dacaa07b378vboxsync}
c74832c7184337c330041742d88e6dacaa07b378vboxsync
c74832c7184337c330041742d88e6dacaa07b378vboxsync/**
c74832c7184337c330041742d88e6dacaa07b378vboxsync * Destruct a device instance.
c74832c7184337c330041742d88e6dacaa07b378vboxsync *
c74832c7184337c330041742d88e6dacaa07b378vboxsync * Most VM resources are freed by the VM. This callback is provided so that any non-VM
c74832c7184337c330041742d88e6dacaa07b378vboxsync * resources can be freed correctly.
c74832c7184337c330041742d88e6dacaa07b378vboxsync *
c74832c7184337c330041742d88e6dacaa07b378vboxsync * @returns VBox status.
c74832c7184337c330041742d88e6dacaa07b378vboxsync * @param pDevIns The device instance data.
c74832c7184337c330041742d88e6dacaa07b378vboxsync */
c74832c7184337c330041742d88e6dacaa07b378vboxsyncstatic DECLCALLBACK(int) parallelDestruct(PPDMDEVINS pDevIns)
c74832c7184337c330041742d88e6dacaa07b378vboxsync{
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync ParallelState *pThis = PDMINS_2_DATA(pDevIns, ParallelState *);
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync PDMDEV_CHECK_VERSIONS_RETURN_QUIET(pDevIns);
c74832c7184337c330041742d88e6dacaa07b378vboxsync
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync PDMR3CritSectDelete(&pThis->CritSect);
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync RTSemEventDestroy(pThis->ReceiveSem);
4fbca3751fe239da5934c23a783c3422618336e8vboxsync
c74832c7184337c330041742d88e6dacaa07b378vboxsync return VINF_SUCCESS;
c74832c7184337c330041742d88e6dacaa07b378vboxsync}
c74832c7184337c330041742d88e6dacaa07b378vboxsync
c74832c7184337c330041742d88e6dacaa07b378vboxsync
c74832c7184337c330041742d88e6dacaa07b378vboxsync/**
cad8876b46f9e366c4a1007a40c27ca1df078950vboxsync * @interface_method_impl{PDMDEVREG,pfnConstruct}
c74832c7184337c330041742d88e6dacaa07b378vboxsync */
c74832c7184337c330041742d88e6dacaa07b378vboxsyncstatic DECLCALLBACK(int) parallelConstruct(PPDMDEVINS pDevIns,
c74832c7184337c330041742d88e6dacaa07b378vboxsync int iInstance,
c74832c7184337c330041742d88e6dacaa07b378vboxsync PCFGMNODE pCfgHandle)
c74832c7184337c330041742d88e6dacaa07b378vboxsync{
c74832c7184337c330041742d88e6dacaa07b378vboxsync int rc;
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync ParallelState *pThis = PDMINS_2_DATA(pDevIns, ParallelState*);
c74832c7184337c330041742d88e6dacaa07b378vboxsync
c74832c7184337c330041742d88e6dacaa07b378vboxsync Assert(iInstance < 4);
e74eef731a813e4e06680c587a6759b9974b29c9vboxsync PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
c74832c7184337c330041742d88e6dacaa07b378vboxsync
c74832c7184337c330041742d88e6dacaa07b378vboxsync /*
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync * Init the data so parallelDestruct doesn't choke.
c74832c7184337c330041742d88e6dacaa07b378vboxsync */
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync pThis->pDevInsR3 = pDevIns;
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync pThis->pDevInsR0 = PDMDEVINS_2_R0PTR(pDevIns);
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync pThis->pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync pThis->ReceiveSem = NIL_RTSEMEVENT;
c74832c7184337c330041742d88e6dacaa07b378vboxsync
c74832c7184337c330041742d88e6dacaa07b378vboxsync /* IBase */
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync pThis->IBase.pfnQueryInterface = parallelQueryInterface;
c74832c7184337c330041742d88e6dacaa07b378vboxsync
4fbca3751fe239da5934c23a783c3422618336e8vboxsync /* IHostParallelPort */
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync pThis->IHostParallelPort.pfnNotifyInterrupt = parallelNotifyInterrupt;
c74832c7184337c330041742d88e6dacaa07b378vboxsync
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync /* Init parallel state */
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync pThis->reg_data = 0;
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync pThis->reg_ecp_ecr = LPT_ECP_ECR_CHIPMODE_COMPAT | LPT_ECP_ECR_FIFO_EMPTY;
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync pThis->act_fifo_pos_read = 0;
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync pThis->act_fifo_pos_write = 0;
c74832c7184337c330041742d88e6dacaa07b378vboxsync
c74832c7184337c330041742d88e6dacaa07b378vboxsync /*
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync * Validate and read the configuration.
c74832c7184337c330041742d88e6dacaa07b378vboxsync */
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync if (!CFGMR3AreValuesValid(pCfgHandle, "IRQ\0" "IOBase\0" "GCEnabled\0" "R0Enabled\0"))
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync return PDMDEV_SET_ERROR(pDevIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES,
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync N_("Configuration error: Unknown config key"));
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync rc = CFGMR3QueryBoolDef(pCfgHandle, "GCEnabled", &pThis->fGCEnabled, true);
b7a5b3f9f9ecce32ddacf8404c625ce0451bbdc1vboxsync if (RT_FAILURE(rc))
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync return PDMDEV_SET_ERROR(pDevIns, rc,
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync N_("Configuration error: Failed to get the \"GCEnabled\" value"));
c74832c7184337c330041742d88e6dacaa07b378vboxsync
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync rc = CFGMR3QueryBoolDef(pCfgHandle, "R0Enabled", &pThis->fR0Enabled, true);
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync if (RT_FAILURE(rc))
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync return PDMDEV_SET_ERROR(pDevIns, rc,
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync N_("Configuration error: Failed to get the \"R0Enabled\" value"));
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync uint8_t irq_lvl;
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync rc = CFGMR3QueryU8Def(pCfgHandle, "IRQ", &irq_lvl, 7);
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync if (RT_FAILURE(rc))
4fbca3751fe239da5934c23a783c3422618336e8vboxsync return PDMDEV_SET_ERROR(pDevIns, rc,
4fbca3751fe239da5934c23a783c3422618336e8vboxsync N_("Configuration error: Failed to get the \"IRQ\" value"));
c74832c7184337c330041742d88e6dacaa07b378vboxsync
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync uint16_t io_base;
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync rc = CFGMR3QueryU16Def(pCfgHandle, "IOBase", &io_base, 0x378);
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync if (RT_FAILURE(rc))
4fbca3751fe239da5934c23a783c3422618336e8vboxsync return PDMDEV_SET_ERROR(pDevIns, rc,
4fbca3751fe239da5934c23a783c3422618336e8vboxsync N_("Configuration error: Failed to get the \"IOBase\" value"));
c74832c7184337c330041742d88e6dacaa07b378vboxsync
c74832c7184337c330041742d88e6dacaa07b378vboxsync Log(("parallelConstruct instance %d iobase=%04x irq=%d\n", iInstance, io_base, irq_lvl));
c74832c7184337c330041742d88e6dacaa07b378vboxsync
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync pThis->irq = irq_lvl;
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync pThis->base = io_base;
b7a5b3f9f9ecce32ddacf8404c625ce0451bbdc1vboxsync
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync /*
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync * Initialize critical section and event semaphore.
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync * This must of course be done before attaching drivers or anything else which can call us back..
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync */
3e9c5c3e44de15c28695c7b570bc2551639187e3vboxsync rc = PDMDevHlpCritSectInit(pDevIns, &pThis->CritSect, RT_SRC_POS, "Parallel#%d", iInstance);
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync if (RT_FAILURE(rc))
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync return rc;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync rc = RTSemEventCreate(&pThis->ReceiveSem);
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync if (RT_FAILURE(rc))
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync return rc;
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync /*
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync * Register the I/O ports and saved state.
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync */
c74832c7184337c330041742d88e6dacaa07b378vboxsync rc = PDMDevHlpIOPortRegister(pDevIns, io_base, 8, 0,
c74832c7184337c330041742d88e6dacaa07b378vboxsync parallelIOPortWrite, parallelIOPortRead,
c74832c7184337c330041742d88e6dacaa07b378vboxsync NULL, NULL, "PARALLEL");
b7a5b3f9f9ecce32ddacf8404c625ce0451bbdc1vboxsync if (RT_FAILURE(rc))
c74832c7184337c330041742d88e6dacaa07b378vboxsync return rc;
c74832c7184337c330041742d88e6dacaa07b378vboxsync
4fbca3751fe239da5934c23a783c3422618336e8vboxsync#if 0
4fbca3751fe239da5934c23a783c3422618336e8vboxsync /* register ecp registers */
4fbca3751fe239da5934c23a783c3422618336e8vboxsync rc = PDMDevHlpIOPortRegister(pDevIns, io_base+0x400, 8, 0,
4fbca3751fe239da5934c23a783c3422618336e8vboxsync parallelIOPortWriteECP, parallelIOPortReadECP,
4fbca3751fe239da5934c23a783c3422618336e8vboxsync NULL, NULL, "PARALLEL ECP");
b7a5b3f9f9ecce32ddacf8404c625ce0451bbdc1vboxsync if (RT_FAILURE(rc))
4fbca3751fe239da5934c23a783c3422618336e8vboxsync return rc;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync#endif
4fbca3751fe239da5934c23a783c3422618336e8vboxsync
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync if (pThis->fGCEnabled)
4fbca3751fe239da5934c23a783c3422618336e8vboxsync {
8b90eb0585fa16024709ca374c69f1eb5d5a5a7cvboxsync rc = PDMDevHlpIOPortRegisterRC(pDevIns, io_base, 8, 0, "parallelIOPortWrite",
c74832c7184337c330041742d88e6dacaa07b378vboxsync "parallelIOPortRead", NULL, NULL, "Parallel");
b7a5b3f9f9ecce32ddacf8404c625ce0451bbdc1vboxsync if (RT_FAILURE(rc))
4fbca3751fe239da5934c23a783c3422618336e8vboxsync return rc;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync
4fbca3751fe239da5934c23a783c3422618336e8vboxsync#if 0
4fbca3751fe239da5934c23a783c3422618336e8vboxsync rc = PDMDevHlpIOPortRegisterGC(pDevIns, io_base+0x400, 8, 0, "parallelIOPortWriteECP",
4fbca3751fe239da5934c23a783c3422618336e8vboxsync "parallelIOPortReadECP", NULL, NULL, "Parallel Ecp");
b7a5b3f9f9ecce32ddacf8404c625ce0451bbdc1vboxsync if (RT_FAILURE(rc))
4fbca3751fe239da5934c23a783c3422618336e8vboxsync return rc;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync#endif
4fbca3751fe239da5934c23a783c3422618336e8vboxsync }
c74832c7184337c330041742d88e6dacaa07b378vboxsync
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync if (pThis->fR0Enabled)
4fbca3751fe239da5934c23a783c3422618336e8vboxsync {
c74832c7184337c330041742d88e6dacaa07b378vboxsync rc = PDMDevHlpIOPortRegisterR0(pDevIns, io_base, 8, 0, "parallelIOPortWrite",
c74832c7184337c330041742d88e6dacaa07b378vboxsync "parallelIOPortRead", NULL, NULL, "Parallel");
b7a5b3f9f9ecce32ddacf8404c625ce0451bbdc1vboxsync if (RT_FAILURE(rc))
4fbca3751fe239da5934c23a783c3422618336e8vboxsync return rc;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync
4fbca3751fe239da5934c23a783c3422618336e8vboxsync#if 0
4fbca3751fe239da5934c23a783c3422618336e8vboxsync rc = PDMDevHlpIOPortRegisterR0(pDevIns, io_base+0x400, 8, 0, "parallelIOPortWriteECP",
4fbca3751fe239da5934c23a783c3422618336e8vboxsync "parallelIOPortReadECP", NULL, NULL, "Parallel Ecp");
b7a5b3f9f9ecce32ddacf8404c625ce0451bbdc1vboxsync if (RT_FAILURE(rc))
4fbca3751fe239da5934c23a783c3422618336e8vboxsync return rc;
4fbca3751fe239da5934c23a783c3422618336e8vboxsync#endif
4fbca3751fe239da5934c23a783c3422618336e8vboxsync }
c74832c7184337c330041742d88e6dacaa07b378vboxsync
6b98f92a0c2c5dd90d8496ee553e5763c4debd49vboxsync rc = PDMDevHlpSSMRegister3(pDevIns, PARALLEL_SAVED_STATE_VERSION, sizeof(*pThis),
6b98f92a0c2c5dd90d8496ee553e5763c4debd49vboxsync parallelLiveExec, parallelSaveExec, parallelLoadExec);
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync if (RT_FAILURE(rc))
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync return rc;
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync /*
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync * Attach the parallel port driver and get the interfaces.
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync * For now no run-time changes are supported.
120ee2736ed70b5ce8b0b4dd73cc4f8b4b9416c1vboxsync */
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync rc = PDMDevHlpDriverAttach(pDevIns, 0, &pThis->IBase, &pThis->pDrvBase, "Parallel Host");
b7a5b3f9f9ecce32ddacf8404c625ce0451bbdc1vboxsync if (RT_SUCCESS(rc))
c74832c7184337c330041742d88e6dacaa07b378vboxsync {
0db6a029780d9f9b347500e117320a8d5661efe5vboxsync pThis->pDrvHostParallelConnector = PDMIBASE_QUERY_INTERFACE(pThis->pDrvBase, PDMIHOSTPARALLELCONNECTOR);
0db6a029780d9f9b347500e117320a8d5661efe5vboxsync AssertMsgReturn(pThis->pDrvHostParallelConnector,
0db6a029780d9f9b347500e117320a8d5661efe5vboxsync ("Configuration error: instance %d has no host parallel interface!\n", iInstance),
0db6a029780d9f9b347500e117320a8d5661efe5vboxsync VERR_PDM_MISSING_INTERFACE);
c74832c7184337c330041742d88e6dacaa07b378vboxsync /** @todo provide read notification interface!!!! */
c74832c7184337c330041742d88e6dacaa07b378vboxsync }
c74832c7184337c330041742d88e6dacaa07b378vboxsync else if (rc == VERR_PDM_NO_ATTACHED_DRIVER)
c74832c7184337c330041742d88e6dacaa07b378vboxsync {
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync pThis->pDrvBase = NULL;
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync pThis->pDrvHostParallelConnector = NULL;
c74832c7184337c330041742d88e6dacaa07b378vboxsync LogRel(("Parallel%d: no unit\n", iInstance));
c74832c7184337c330041742d88e6dacaa07b378vboxsync }
c74832c7184337c330041742d88e6dacaa07b378vboxsync else
c74832c7184337c330041742d88e6dacaa07b378vboxsync {
fe813b3594039ba864493438e78ee0e7132bc445vboxsync AssertMsgFailed(("Parallel%d: Failed to attach to host driver. rc=%Rrc\n", iInstance, rc));
c74832c7184337c330041742d88e6dacaa07b378vboxsync return PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS,
a40c05ca69e15a5efdd0796ef52e26ec0b1bc4d2vboxsync N_("Parallel device %d cannot attach to host driver"), iInstance);
c74832c7184337c330041742d88e6dacaa07b378vboxsync }
c74832c7184337c330041742d88e6dacaa07b378vboxsync
6f8a1ec7a08590986f176ea072ad499630fe5b6evboxsync /* Set compatibility mode */
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync pThis->pDrvHostParallelConnector->pfnSetMode(pThis->pDrvHostParallelConnector, PDM_PARALLEL_PORT_MODE_COMPAT);
6f8a1ec7a08590986f176ea072ad499630fe5b6evboxsync /* Get status of control register */
548ca31b6b47c36bacce49bed3339cb8075b9681vboxsync pThis->pDrvHostParallelConnector->pfnReadControl(pThis->pDrvHostParallelConnector, &pThis->reg_control);
4fbca3751fe239da5934c23a783c3422618336e8vboxsync
c74832c7184337c330041742d88e6dacaa07b378vboxsync return VINF_SUCCESS;
c74832c7184337c330041742d88e6dacaa07b378vboxsync}
c74832c7184337c330041742d88e6dacaa07b378vboxsync
c74832c7184337c330041742d88e6dacaa07b378vboxsync/**
c74832c7184337c330041742d88e6dacaa07b378vboxsync * The device registration structure.
c74832c7184337c330041742d88e6dacaa07b378vboxsync */
c74832c7184337c330041742d88e6dacaa07b378vboxsyncconst PDMDEVREG g_DeviceParallelPort =
c74832c7184337c330041742d88e6dacaa07b378vboxsync{
c74832c7184337c330041742d88e6dacaa07b378vboxsync /* u32Version */
c74832c7184337c330041742d88e6dacaa07b378vboxsync PDM_DEVREG_VERSION,
c74832c7184337c330041742d88e6dacaa07b378vboxsync /* szDeviceName */
c74832c7184337c330041742d88e6dacaa07b378vboxsync "parallel",
f01175bdcb5e36a1a89fca88f45d7ee7fb034ed6vboxsync /* szRCMod */
c74832c7184337c330041742d88e6dacaa07b378vboxsync "VBoxDDGC.gc",
c74832c7184337c330041742d88e6dacaa07b378vboxsync /* szR0Mod */
c74832c7184337c330041742d88e6dacaa07b378vboxsync "VBoxDDR0.r0",
c74832c7184337c330041742d88e6dacaa07b378vboxsync /* pszDescription */
c74832c7184337c330041742d88e6dacaa07b378vboxsync "Parallel Communication Port",
c74832c7184337c330041742d88e6dacaa07b378vboxsync /* fFlags */
3cf2cf6eea0401233eece976db8cf31909f1f955vboxsync PDM_DEVREG_FLAGS_DEFAULT_BITS | PDM_DEVREG_FLAGS_RC | PDM_DEVREG_FLAGS_R0,
c74832c7184337c330041742d88e6dacaa07b378vboxsync /* fClass */
c74832c7184337c330041742d88e6dacaa07b378vboxsync PDM_DEVREG_CLASS_PARALLEL,
c74832c7184337c330041742d88e6dacaa07b378vboxsync /* cMaxInstances */
c74832c7184337c330041742d88e6dacaa07b378vboxsync 1,
c74832c7184337c330041742d88e6dacaa07b378vboxsync /* cbInstance */
c74832c7184337c330041742d88e6dacaa07b378vboxsync sizeof(ParallelState),
c74832c7184337c330041742d88e6dacaa07b378vboxsync /* pfnConstruct */
c74832c7184337c330041742d88e6dacaa07b378vboxsync parallelConstruct,
c74832c7184337c330041742d88e6dacaa07b378vboxsync /* pfnDestruct */
c74832c7184337c330041742d88e6dacaa07b378vboxsync parallelDestruct,
c74832c7184337c330041742d88e6dacaa07b378vboxsync /* pfnRelocate */
c74832c7184337c330041742d88e6dacaa07b378vboxsync parallelRelocate,
c74832c7184337c330041742d88e6dacaa07b378vboxsync /* pfnIOCtl */
c74832c7184337c330041742d88e6dacaa07b378vboxsync NULL,
c74832c7184337c330041742d88e6dacaa07b378vboxsync /* pfnPowerOn */
c74832c7184337c330041742d88e6dacaa07b378vboxsync NULL,
c74832c7184337c330041742d88e6dacaa07b378vboxsync /* pfnReset */
c74832c7184337c330041742d88e6dacaa07b378vboxsync NULL,
c74832c7184337c330041742d88e6dacaa07b378vboxsync /* pfnSuspend */
c74832c7184337c330041742d88e6dacaa07b378vboxsync NULL,
c74832c7184337c330041742d88e6dacaa07b378vboxsync /* pfnResume */
c74832c7184337c330041742d88e6dacaa07b378vboxsync NULL,
c74832c7184337c330041742d88e6dacaa07b378vboxsync /* pfnAttach */
c74832c7184337c330041742d88e6dacaa07b378vboxsync NULL,
c74832c7184337c330041742d88e6dacaa07b378vboxsync /* pfnDetach */
c74832c7184337c330041742d88e6dacaa07b378vboxsync NULL,
c74832c7184337c330041742d88e6dacaa07b378vboxsync /* pfnQueryInterface. */
f01175bdcb5e36a1a89fca88f45d7ee7fb034ed6vboxsync NULL,
f01175bdcb5e36a1a89fca88f45d7ee7fb034ed6vboxsync /* pfnInitComplete */
f01175bdcb5e36a1a89fca88f45d7ee7fb034ed6vboxsync NULL,
f01175bdcb5e36a1a89fca88f45d7ee7fb034ed6vboxsync /* pfnPowerOff */
f01175bdcb5e36a1a89fca88f45d7ee7fb034ed6vboxsync NULL,
f01175bdcb5e36a1a89fca88f45d7ee7fb034ed6vboxsync /* pfnSoftReset */
f01175bdcb5e36a1a89fca88f45d7ee7fb034ed6vboxsync NULL,
f01175bdcb5e36a1a89fca88f45d7ee7fb034ed6vboxsync /* u32VersionEnd */
f01175bdcb5e36a1a89fca88f45d7ee7fb034ed6vboxsync PDM_DEVREG_VERSION
c74832c7184337c330041742d88e6dacaa07b378vboxsync};
c74832c7184337c330041742d88e6dacaa07b378vboxsync#endif /* IN_RING3 */
c74832c7184337c330041742d88e6dacaa07b378vboxsync
c74832c7184337c330041742d88e6dacaa07b378vboxsync
c74832c7184337c330041742d88e6dacaa07b378vboxsync#endif /* !VBOX_DEVICE_STRUCT_TESTCASE */