BusMouse.cpp revision aa327535f5ce61d8851bf6495ca1b507f013252b
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * BusMouse - Microsoft Bus (parallel) mouse controller device.
904810c4c6668233349b025cc58013cb7c11c701vboxsync * Copyright (C) 2006-2013 Oracle Corporation
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * Permission is hereby granted, free of charge, to any person
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * obtaining a copy of this software and associated documentation
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * files (the "Software"), to deal in the Software without
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * restriction, including without limitation the rights to use,
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * copy, modify, merge, publish, distribute, sublicense, and/or sell
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * copies of the Software, and to permit persons to whom the
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * Software is furnished to do so, subject to the following
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * conditions:
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync * The above copyright notice and this permission notice shall be
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync * included in all copies or substantial portions of the Software.
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1ce069685b24d243eb0464f46d4c56b250c64445vboxsync * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
a55af63ead2dcca370bfc0dfe49771d9dcc61b93vboxsync * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
e0778e583cb4a0bdc9bcc48f5957e00a01108388vboxsync * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
a55af63ead2dcca370bfc0dfe49771d9dcc61b93vboxsync * OTHER DEALINGS IN THE SOFTWARE.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync/*******************************************************************************
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync* Header Files *
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync*******************************************************************************/
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync/** @page pg_busmouse DevBusMouse - Microsoft Bus Mouse Emulation
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync * The Microsoft Bus Mouse was an early mouse sold by Microsoft, originally
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync * introduced in 1983. The mouse had a D-shaped 9-pin connector which plugged
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync * into a small ISA add-in board.
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync * The mouse itself was very simple (compared to a serial mouse) and most of the
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync * logic was located on the ISA board. Later, Microsoft sold an InPort mouse,
b0ad0bbadf3a5b5258acda1bfe16f0ad8bee5ff0vboxsync * which was also called a "bus mouse", but used a different interface.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * Microsoft part numbers for the Bus Mouse were 037-099 (100 ppi)
229a63857c5fd2e441a62206eacce4156d0b2a26vboxsync * and 037-199 (200 ppi).
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * The Bus Mouse adapter included IRQ configuration jumpers (ref. MS article
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * Q12230). The IRQ could be set to one of 2, 3, 4, 5. The typical setting
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * would be IRQ 2 for a PC/XT and IRQ 5 for an AT compatible. Because IRQ 5
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * may conflict with a SoundBlaster or a PCI device, this device defaults to
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * IRQ 3. Note that IRQ 3 is also used by the COM 2 device, not often needed.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * The ISA adapter was built around an Intel 8255A compatible chip (ref.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * MS article Q46369). Once enabled, the adapter raises the configured IRQ
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * 30 times per second; the rate is not configurable. The interrupts
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * occur regardless of whether the mouse state has changed or not.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * To function properly, the 8255A must be programmed as follows:
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * - Port A: Input. Used to read motion deltas and button states.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * - Port B: Output. Not used except for mouse detection.
a0644dbbd30adb9bd2937110d6f016e56c4cc52bvboxsync * - Port C: Split. Upper bits set as output, used for control purposes.
a0644dbbd30adb9bd2937110d6f016e56c4cc52bvboxsync * Lower bits set as input, reflecting IRQ state.
a0644dbbd30adb9bd2937110d6f016e56c4cc52bvboxsync * Detailed information was gleaned from Windows and OS/2 DDK mouse samples.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync/*******************************************************************************
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync* Defined Constants And Macros *
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync*******************************************************************************/
a2d9f81753c129b5e3bbe3769627dcd25a3724bdvboxsync/** The original bus mouse controller is fixed at I/O port 0x23C. */
a2d9f81753c129b5e3bbe3769627dcd25a3724bdvboxsync/** @name Offsets relative to the I/O base.
a0644dbbd30adb9bd2937110d6f016e56c4cc52bvboxsync/** @name Port C bits (control port).
a2d9f81753c129b5e3bbe3769627dcd25a3724bdvboxsync#define BMS_CTL_INT_DIS RT_BIT(4) /**< Disable IRQ (else enabled). */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync#define BMS_CTL_SEL_HIGH RT_BIT(5) /**< Select hi nibble (else lo). */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync#define BMS_CTL_SEL_Y RT_BIT(6) /**< Select X to read (else Y). */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync#define BMS_CTL_HOLD RT_BIT(7) /**< Hold counter (else clear). */
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync/** @name Port A bits (data port).
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync#define BMS_DATA_DELTA 0x0F /**< Motion delta in lower nibble. */
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync#define BMS_DATA_B3_UP RT_BIT(5) /**< Button 3 (right) is up. */
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsync#define BMS_DATA_B2_UP RT_BIT(6) /**< Button 2 (middle) is up. */
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsync#define BMS_DATA_B1_UP RT_BIT(7) /**< Button 1 (left) is up. */
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsync/** Convert IRQ level (2/3/4/5) to a bit in the control register. */
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsync/** IRQ period, corresponds to approx. 30 Hz. */
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsync/** Default IRQ setting. */
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsync/** The saved state version. */
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsync/*******************************************************************************
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsync* Structures and Typedefs *
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync*******************************************************************************/
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync * The device state.
7bf07b1592dfaab1a4fb6d497fd0ff1302fb7585vboxsynctypedef struct MouState
7c1f498692cd2393f8ba68cb62be482495106f93vboxsync /** @name 8255A state
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsync uint8_t cnt_held; /**< Counters held for reading. */
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync /** Mouse timer handle - HC. */
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsync /** Timer period in milliseconds. */
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsync /** @name mouse state
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync int32_t mouse_dx; /* current values, needed for 'poll' mode */
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsync /** Pointer to the device instance - RC. */
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync /** Pointer to the device instance - R3 . */
7e8d44e04156d78379666f20d5daa2a79e5cbf44vboxsync /** Pointer to the device instance. */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * Mouse port - LUN#0.
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync * @implements PDMIBASE
c6d49c0483db5a491b9394f017de7760aa5d6ac7vboxsync * @implements PDMIMOUSEPORT
361a7fb527903c8dbfd0cc7dc779f943c6e348f6vboxsync /** The base interface for the mouse port. */
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync /** The mouse port base interface. */
a1b4fb3917412d2632d358ff8989f1ec971f2d5bvboxsync /** The base interface of the attached mouse driver. */
505ddd00252720bfb5569fcb17bfda53dc141e3bvboxsync /** The mouse interface of the attached mouse driver. */
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync * Report a change in status down the driver chain.
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync * We want to report the mouse as enabled if and only if the guest is "using"
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync * it. That way, other devices (e.g. a PS/2 or USB mouse) can receive mouse
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync * events when the bus mouse is disabled. Enabling interrupts constitutes
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync * enabling the bus mouse. The mouse is considered disabled if interrupts are
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync * disabled for several consecutive mouse timer ticks; this is because the
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync * interrupt handler in the guest typically temporarily disables interrupts and
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync * we do not want to toggle the enabled/disabled state more often than
657b2c9f6d33f08001e5fa6f6e0572dcf0391013vboxsync * necessary.
8b36957d815c23b479eb35d93ac76c66392e9402vboxsyncstatic void bms_update_downstream_status(MouState *pThis)
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync pDrv->pfnReportModes(pDrv, fEnabled, false, false);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync * Set the emulated hardware to a known initial state.
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync /* Clear the device setup. */
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync pThis->port_c = BMS_CTL_INT_DIS; /* Interrupts disabled. */
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync pThis->ctrl_port = 0x91; /* Default 8255A setup. */
229a63857c5fd2e441a62206eacce4156d0b2a26vboxsync /* Clear motion/button state. */
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync/* Process a mouse event coming from the host. */
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsyncstatic void bms_mouse_event(MouState *pThis, int dx, int dy, int dz, int dw,
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync LogRel3(("%s: dx=%d, dy=%d, dz=%d, dw=%d, buttons_state=0x%x\n",
b604fbf16eda38d14b4999c245f032bfaa5aa85avboxsync __PRETTY_FUNCTION__, dx, dy, dz, dw, buttons_state));
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync /* Only record X/Y movement and buttons. */
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsyncstatic DECLCALLBACK(void) bmsTimerCallback(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser)
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync MouState *pThis = PDMINS_2_DATA(pDevIns, MouState *);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync /* Toggle the IRQ line if interrupts are enabled. */
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync PDMDevHlpISASetIrq(pThis->CTX_SUFF(pDevIns), pThis->irq, PDM_IRQ_LEVEL_LOW);
a85c47589af3385deccdbb1367b75108806d7cf5vboxsync PDMDevHlpISASetIrq(pThis->CTX_SUFF(pDevIns), pThis->irq, PDM_IRQ_LEVEL_HIGH);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync /* Handle enabling/disabling of the mouse interface. */
67ee25dd0b63a61dc35a35d0aade75ca6cd06350vboxsync if (pThis->disable_counter == 0 && pThis->mouse_enabled)
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync pThis->disable_counter = 8; /* Re-arm the disable countdown. */
5704a317c3b6bdf4b59f6a6ebe45d443296b1995vboxsync /* Re-arm the timer. */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync# endif /* IN_RING3 */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsyncstatic void bms_set_reported_buttons(MouState *pThis, unsigned fButtons, unsigned fButtonMask)
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync pThis->mouse_buttons_reported |= (fButtons & fButtonMask);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync pThis->mouse_buttons_reported &= (fButtons | ~fButtonMask);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync/* Update the internal state after a write to port C. */
a0644dbbd30adb9bd2937110d6f016e56c4cc52bvboxsync /* If the controller is in hold state, transfer data from counters. */
229a63857c5fd2e441a62206eacce4156d0b2a26vboxsync dx = pThis->mouse_dx < 0 ? RT_MAX(pThis->mouse_dx, -128)
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync dy = pThis->mouse_dy < 0 ? RT_MAX(pThis->mouse_dy, -128)
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync bms_set_reported_buttons(pThis, pThis->mouse_buttons & 0x07, 0x07);
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync /* Force type conversion. */
2a171646d32f8a15e9820d6fb3bf3f9b9990ca3fvboxsync /* Move the appropriate nibble into port A. */
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync /* And update the button bits. */
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync pThis->port_a |= pThis->mouse_buttons & 1 ? 0 : BMS_DATA_B1_UP;
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync pThis->port_a |= pThis->mouse_buttons & 2 ? 0 : BMS_DATA_B3_UP;
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync pThis->port_a |= pThis->mouse_buttons & 4 ? 0 : BMS_DATA_B2_UP;
a9315925c69e4c3bb342bb317ca5b6d29e1ee467vboxsync /* Immediately clear the IRQ if necessary. */
80b09746c07120c881b61b18f30c9c4a2a4af9c5vboxsync PDMDevHlpISASetIrq(pThis->CTX_SUFF(pDevIns), pThis->irq, PDM_IRQ_LEVEL_LOW);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsyncstatic int bms_write_port(MouState *pThis, uint32_t offPort, uint32_t uValue)
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync LogRel3(("%s: write port %d: 0x%02x\n", __PRETTY_FUNCTION__, offPort, uValue));
45a01ef53b009e9f56ce427bd8688da02ad32389vboxsync /* Update port B. */
94c4b844625733fedcd2b473c207981b31316bd9vboxsync /* Do nothing, port A is not writable. */
2c6d6ff2ff146c92be6ec38cb87465c4f867a8fevboxsync /* Update the high nibble of port C. */
2c6d6ff2ff146c92be6ec38cb87465c4f867a8fevboxsync pThis->port_c = (uValue & 0xF0) | (pThis->port_c & 0x0F);
c6d49c0483db5a491b9394f017de7760aa5d6ac7vboxsyncstatic uint32_t bms_read_port(MouState *pThis, uint32_t offPort)
f271f5e8fefdfe224f8bdeac77fefe6c655ae87evboxsync /* Read port A. */
f271f5e8fefdfe224f8bdeac77fefe6c655ae87evboxsync /* Read port B. */
8ae161fca703d669e1306fafee128914f831f72bvboxsync /* Read port C. */
8ae161fca703d669e1306fafee128914f831f72bvboxsync /* Some Microsoft driver code reads the control port 10,000 times when
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync * determining the IRQ level. This can occur faster than the IRQ line
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsync * transitions and the detection fails. To work around this, we force
b8c2e8ba48bd659fa09a06770a7cedfae977d73bvboxsync * the IRQ bit to toggle every once in a while.
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync /* Read the 8255A control port. */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync LogRel3(("%s: read port %d: 0x%02x\n", __PRETTY_FUNCTION__, offPort, uValue));
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync * Port I/O Handler for port IN operations.
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync * @returns VBox status code.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * @param pDevIns The device instance.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * @param pvUser User argument - ignored.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * @param Port Port number used for the IN operation.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * @param pu32 Where to store the result.
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync * @param cb Number of bytes read.
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsyncPDMBOTHCBDECL(int) mouIOPortRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb)
4b9a9888c020ed3508c8ac3a5b47842d6aa3f8d2vboxsync MouState *pThis = PDMINS_2_DATA(pDevIns, MouState *);
aa0553becec2abc2e781f839ba1d399c31c2c07fvboxsync Log2(("mouIOPortRead: Port=%#x cb=%d *pu32=%#x\n", Port, cb, *pu32));
b4bcdbd7ac35c938e6f71a6403fe9f3ebf106a07vboxsync * Port I/O Handler for port OUT operations.
bc016d9f481b47ade01223d4d589080ad2e2a246vboxsync * @returns VBox status code.
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync * @param pDevIns The device instance.
6fe1329154975472e055284198df7fa8e64dee3avboxsync * @param pvUser User argument - ignored.
6fe1329154975472e055284198df7fa8e64dee3avboxsync * @param Port Port number used for the IN operation.
bc016d9f481b47ade01223d4d589080ad2e2a246vboxsync * @param u32 The value to output.
bc016d9f481b47ade01223d4d589080ad2e2a246vboxsync * @param cb The value size in bytes.
36a04912b64bea8318327fe0723535f1b3f041b0vboxsyncPDMBOTHCBDECL(int) mouIOPortWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb)
9ce5d949e4f1572d445a5c0aecabe9de8b672c99vboxsync MouState *pThis = PDMINS_2_DATA(pDevIns, MouState *);
ab9d561bc33f1705a10c5e4bffed9c9e660dc32fvboxsync Log2(("mouIOPortWrite: Port=%#x cb=%d u32=%#x\n", Port, cb, u32));
bc016d9f481b47ade01223d4d589080ad2e2a246vboxsync * Saves the state of the device.
101e307bb33304d9dda53a7652510880e8228b13vboxsync * @returns VBox status code.
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsync * @param pDevIns The device instance.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * @param pSSMHandle The handle to save the state to.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsyncstatic DECLCALLBACK(int) mouSaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSMHandle)
c6d49c0483db5a491b9394f017de7760aa5d6ac7vboxsync MouState *pThis = PDMINS_2_DATA(pDevIns, MouState *);
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync /* 8255A state. */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync /* Other device state. */
c6d49c0483db5a491b9394f017de7760aa5d6ac7vboxsync /* Current mouse state deltas. */
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync SSMR3PutU8(pSSMHandle, pThis->mouse_buttons_reported);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync /* Timer. */
a5224d14bb71df1d2da62ff9e4b0598ed5d2d85fvboxsync return TMR3TimerSave(pThis->MouseTimer, pSSMHandle);
ac2b2ae448fe887af9a3269e40afff11ebb1f9d3vboxsync * Loads a saved device state.
c6d49c0483db5a491b9394f017de7760aa5d6ac7vboxsync * @returns VBox status code.
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync * @param pDevIns The device instance.
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsync * @param pSSMHandle The handle to the saved state.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * @param uVersion The data unit version number.
a425b5e790c27d6a1a2cf738802e9034f0764a00vboxsync * @param uPass The data pass.
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsyncstatic DECLCALLBACK(int) mouLoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSMHandle, uint32_t uVersion, uint32_t uPass)
1568d715e75b8d2484ea3dc87f0483d4cf377838vboxsync MouState *pThis = PDMINS_2_DATA(pDevIns, MouState *);
80e46f984efd827517661c0e081a36014ca41af8vboxsync /* 8255A state. */
6febf3149010855617e4a37e2c49f93d68930d44vboxsync /* Other device state. */
aeb9498c4d9854ed42b271541d34c7bad97b4c77vboxsync /* Current mouse state deltas. */
aeb9498c4d9854ed42b271541d34c7bad97b4c77vboxsync SSMR3GetU8(pSSMHandle, &pThis->mouse_buttons_reported);
48dafba24ef28f07a241e5857a43b327822574a8vboxsync /* Timer. */
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsync * Reset notification.
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync * @returns VBox status.
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync * @param pDevIns The device instance data.
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsyncstatic DECLCALLBACK(void) mouReset(PPDMDEVINS pDevIns)
bf88068260ded16af90b7da4867240fbdd9c8017vboxsync MouState *pThis = PDMINS_2_DATA(pDevIns, MouState *);
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsync /* Reinitialize the timer. */
63b785c3291332a86a9bc473e68f08121368898bvboxsync TMTimerSetMillies(pThis->MouseTimer, pThis->cTimerPeriodMs);
94c4b844625733fedcd2b473c207981b31316bd9vboxsync/* -=-=-=-=-=- Mouse: IBase -=-=-=-=-=- */
94c4b844625733fedcd2b473c207981b31316bd9vboxsync * @interface_method_impl{PDMIBASE,pfnQueryInterface}
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsyncstatic DECLCALLBACK(void *) mouQueryMouseInterface(PPDMIBASE pInterface, const char *pszIID)
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync MouState *pThis = RT_FROM_MEMBER(pInterface, MouState, Mouse.IBase);
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pThis->Mouse.IBase);
c6d49c0483db5a491b9394f017de7760aa5d6ac7vboxsync PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMOUSEPORT, &pThis->Mouse.IPort);
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsync/* -=-=-=-=-=- Mouse: IMousePort -=-=-=-=-=- */
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync * @interface_method_impl{PDMIMOUSEPORT, pfnPutEvent}
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsyncstatic DECLCALLBACK(int) mouPutEvent(PPDMIMOUSEPORT pInterface, int32_t dx,
c6d49c0483db5a491b9394f017de7760aa5d6ac7vboxsync MouState *pThis = RT_FROM_MEMBER(pInterface, MouState, Mouse.IPort);
aed4b2dfb1673c0b476588860c9d27705700ce0dvboxsync int rc = PDMCritSectEnter(pThis->CTX_SUFF(pDevIns)->CTX_SUFF(pCritSectRo), VERR_SEM_BUSY);
5434d84d270a73565d8c3bed826cb4f95aba317bvboxsync PDMCritSectLeave(pThis->CTX_SUFF(pDevIns)->CTX_SUFF(pCritSectRo));
c6d49c0483db5a491b9394f017de7760aa5d6ac7vboxsync * @interface_method_impl{PDMIMOUSEPORT, pfnPutEventAbs}
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsyncstatic DECLCALLBACK(int) mouPutEventAbs(PPDMIMOUSEPORT pInterface, uint32_t x,
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync * @interface_method_impl{PDMIMOUSEPORT, pfnPutEventMT}
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsyncstatic DECLCALLBACK(int) mouPutEventMT(PPDMIMOUSEPORT pInterface, uint32_t x,
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync/* -=-=-=-=-=- setup code -=-=-=-=-=- */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * Attach command.
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync * This is called to let the device attach to a driver for a specified LUN
c6d49c0483db5a491b9394f017de7760aa5d6ac7vboxsync * during runtime. This is not called during VM construction, the device
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync * constructor have to attach to all the available drivers.
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsync * This is like plugging in the mouse after turning on the PC.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * @returns VBox status code.
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync * @param pDevIns The device instance.
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsync * @param iLUN The logical unit which is being detached.
9cc9fd4046b0e8dca741e26455a2a6e79a92ac20vboxsync * @param fFlags Flags, combination of the PDMDEVATT_FLAGS_* \#defines.
3933885bc0c2c93436d858a14564c6179ec72872vboxsync * @remark The controller doesn't support this action, this is just
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync * implemented to try out the driver<->device structure.
200cc6562c6e5cec617903ea827cfb22083f5325vboxsyncstatic DECLCALLBACK(int) mouAttach(PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags)
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsync MouState *pThis = PDMINS_2_DATA(pDevIns, MouState *);
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync AssertMsgReturn(fFlags & PDM_TACH_FLAGS_NOT_HOT_PLUG,
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync ("Bus mouse device does not support hotplugging\n"),
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync /* LUN #0: mouse */
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync rc = PDMDevHlpDriverAttach(pDevIns, iLUN, &pThis->Mouse.IBase, &pThis->Mouse.pDrvBase, "Bus Mouse Port");
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync pThis->Mouse.pDrv = PDMIBASE_QUERY_INTERFACE(pThis->Mouse.pDrvBase, PDMIMOUSECONNECTOR);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync AssertLogRelMsgFailed(("LUN #0 doesn't have a mouse interface! rc=%Rrc\n", rc));
c6d49c0483db5a491b9394f017de7760aa5d6ac7vboxsync Log(("%s/%d: warning: no driver attached to LUN #0!\n", pDevIns->pReg->szName, pDevIns->iInstance));
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync AssertLogRelMsgFailed(("Failed to attach LUN #0! rc=%Rrc\n", rc));
c6d49c0483db5a491b9394f017de7760aa5d6ac7vboxsync * Detach notification.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * This is called when a driver is detaching itself from a LUN of the device.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * The device should adjust it's state to reflect this.
c6d49c0483db5a491b9394f017de7760aa5d6ac7vboxsync * This is like unplugging the network cable to use it for the laptop or
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync * something while the PC is still running.
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsync * @param pDevIns The device instance.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * @param iLUN The logical unit which is being detached.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * @param fFlags Flags, combination of the PDMDEVATT_FLAGS_* \#defines.
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync * @remark The controller doesn't support this action, this is just
c6d49c0483db5a491b9394f017de7760aa5d6ac7vboxsync * implemented to try out the driver<->device structure.
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsyncstatic DECLCALLBACK(void) mouDetach(PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags)
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsync * Reset the interfaces and update the controller state.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync MouState *pThis = PDMINS_2_DATA(pDevIns, MouState *);
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsync /* LUN #0: mouse */
d36016c7e22c0a816c7eae1b6d53f46b7d180589vboxsync * @copydoc FNPDMDEVRELOCATE
94c4b844625733fedcd2b473c207981b31316bd9vboxsyncstatic DECLCALLBACK(void) mouRelocate(PPDMDEVINS pDevIns, RTGCINTPTR offDelta)
94c4b844625733fedcd2b473c207981b31316bd9vboxsync MouState *pThis = PDMINS_2_DATA(pDevIns, MouState *);
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync * @interface_method_impl{PDMDEVREG,pfnConstruct}
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsyncstatic DECLCALLBACK(int) mouConstruct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg)
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsync MouState *pThis = PDMINS_2_DATA(pDevIns, MouState *);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync * Validate and read the configuration.
914fe6f35c397cfd7d97b44a63398c6422579c49vboxsync if (!CFGMR3AreValuesValid(pCfg, "IRQ\0GCEnabled\0R0Enabled\0"))
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync rc = CFGMR3QueryBoolDef(pCfg, "GCEnabled", &fGCEnabled, true);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync return PDMDEV_SET_ERROR(pDevIns, rc, N_("Failed to query \"GCEnabled\" from the config"));
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync rc = CFGMR3QueryBoolDef(pCfg, "R0Enabled", &fR0Enabled, true);
aeb9498c4d9854ed42b271541d34c7bad97b4c77vboxsync return PDMDEV_SET_ERROR(pDevIns, rc, N_("Failed to query \"R0Enabled\" from the config"));
71429ad59515f9055f394527e1ae942c98373cddvboxsync rc = CFGMR3QueryU8Def(pCfg, "IRQ", &irq_lvl, BMS_DEFAULT_IRQ);
71429ad59515f9055f394527e1ae942c98373cddvboxsync return PDMDEV_SET_ERROR(pDevIns, rc, N_("Failed to query \"IRQ\" from the config"));
71429ad59515f9055f394527e1ae942c98373cddvboxsync return PDMDEV_SET_ERROR(pDevIns, rc, N_("Invalid \"IRQ\" config setting"));
71429ad59515f9055f394527e1ae942c98373cddvboxsync ///@todo: remove after properly enabling RC/GC support
71429ad59515f9055f394527e1ae942c98373cddvboxsync Log(("busmouse: IRQ=%d fGCEnabled=%RTbool fR0Enabled=%RTbool\n", irq_lvl, fGCEnabled, fR0Enabled));
71429ad59515f9055f394527e1ae942c98373cddvboxsync * Initialize the interfaces.
71429ad59515f9055f394527e1ae942c98373cddvboxsync pThis->Mouse.IBase.pfnQueryInterface = mouQueryMouseInterface;
71429ad59515f9055f394527e1ae942c98373cddvboxsync pThis->Mouse.IPort.pfnPutEventAbs = mouPutEventAbs;
71429ad59515f9055f394527e1ae942c98373cddvboxsync * Create the interrupt timer.
71429ad59515f9055f394527e1ae942c98373cddvboxsync rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL, bmsTimerCallback,
ec9dc23c50665e8603e1be5a9b6b6fd4c4d949d4vboxsync * Register I/O ports, saved state, and mouse event handlers.
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync rc = PDMDevHlpIOPortRegister(pDevIns, BMS_IO_BASE, BMS_IO_SIZE, NULL, mouIOPortWrite, mouIOPortRead, NULL, NULL, "Bus Mouse");
98fbc4732a9519502e92799ef769789cbdd97dcevboxsync rc = PDMDevHlpIOPortRegisterRC(pDevIns, BMS_IO_BASE, BMS_IO_SIZE, 0, "mouIOPortWrite", "mouIOPortRead", NULL, NULL, "Bus Mouse");
ec9dc23c50665e8603e1be5a9b6b6fd4c4d949d4vboxsync rc = PDMDevHlpIOPortRegisterR0(pDevIns, BMS_IO_BASE, BMS_IO_SIZE, 0, "mouIOPortWrite", "mouIOPortRead", NULL, NULL, "Bus Mouse");
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync rc = PDMDevHlpSSMRegister(pDevIns, BMS_SAVED_STATE_VERSION, sizeof(*pThis), mouSaveExec, mouLoadExec);
4c8907a420ed66a42f729eb08cddf9c1e57f25eavboxsync * Attach to the mouse driver.
4c8907a420ed66a42f729eb08cddf9c1e57f25eavboxsync rc = mouAttach(pDevIns, 0, PDM_TACH_FLAGS_NOT_HOT_PLUG);
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync * Initialize the device state.
4c8907a420ed66a42f729eb08cddf9c1e57f25eavboxsync * The device registration structure.
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync /* u32Version */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync /* szName */
53c715b46bccd175005ee523f7acc7962cfcdf94vboxsync "busmouse",
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync /* szRCMod */
53c715b46bccd175005ee523f7acc7962cfcdf94vboxsync "VBoxDDGC.gc",
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync /* szR0Mod */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync "VBoxDDR0.r0",
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync /* pszDescription */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync "Microsoft Bus Mouse controller. "
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync "LUN #0 is the mouse connector.",
824ae3158a8b8f8233fec3f5a12c81f139933698vboxsync /* fFlags */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync PDM_DEVREG_FLAGS_HOST_BITS_DEFAULT | PDM_DEVREG_FLAGS_GUEST_BITS_32_64 | PDM_DEVREG_FLAGS_PAE36
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync /* fClass */
3a8aa22ef125135ef67bfc396771bcee15ef02dfvboxsync /* cMaxInstances */
53c715b46bccd175005ee523f7acc7962cfcdf94vboxsync /* cbInstance */
2711c80499bbd95e3da4a6cd2dffd9f81a5dce98vboxsync /* pfnConstruct */
a55af63ead2dcca370bfc0dfe49771d9dcc61b93vboxsync /* pfnDestruct */
53c715b46bccd175005ee523f7acc7962cfcdf94vboxsync /* pfnRelocate */
a55af63ead2dcca370bfc0dfe49771d9dcc61b93vboxsync /* pfnMemSetup */
a55af63ead2dcca370bfc0dfe49771d9dcc61b93vboxsync /* pfnPowerOn */
53c715b46bccd175005ee523f7acc7962cfcdf94vboxsync /* pfnReset */
1ce069685b24d243eb0464f46d4c56b250c64445vboxsync /* pfnSuspend */
1ce069685b24d243eb0464f46d4c56b250c64445vboxsync /* pfnResume */
1ce069685b24d243eb0464f46d4c56b250c64445vboxsync /* pfnAttach */
1ce069685b24d243eb0464f46d4c56b250c64445vboxsync /* pfnDetach */
1ce069685b24d243eb0464f46d4c56b250c64445vboxsync /* pfnQueryInterface. */
1ce069685b24d243eb0464f46d4c56b250c64445vboxsync /* pfnInitComplete */
1ce069685b24d243eb0464f46d4c56b250c64445vboxsync /* pfnPowerOff */
1ce069685b24d243eb0464f46d4c56b250c64445vboxsync /* pfnSoftReset */
1ce069685b24d243eb0464f46d4c56b250c64445vboxsync /* u32VersionEnd */
1ce069685b24d243eb0464f46d4c56b250c64445vboxsync# endif /* IN_RING3 */
1ce069685b24d243eb0464f46d4c56b250c64445vboxsync#endif /* !VBOX_DEVICE_STRUCT_TESTCASE */