VirtualBox

Changeset 66130 in vbox


Ignore:
Timestamp:
Mar 16, 2017 2:21:01 PM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
114032
Message:

Devices/PC/DevPcBios+Devices/PC/BIOS/apm.c: relocate the APM shutdown port to the chipset range (avoiding future trouble with PCI resource allocation), including backward compatibility support (so that old VMs with saved state are keeping the old port until they're reset).

Location:
trunk/src/VBox/Devices/PC
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/src/VBox/Devices/PC/BIOS/apm.c

    r63562 r66130  
    7777};
    7878
    79 #define APM_PORT        0x8900      /* Bochs power control port. */
     79#define APM_PORT        0x040f      /* Relocated Bochs power control port, original value of 0x9800 causes potential trouble with PCI resource allocation. */
    8080
    8181/// @todo merge with system.c
  • TabularUnified trunk/src/VBox/Devices/PC/DevPcBios.cpp

    r65859 r66130  
    55
    66/*
    7  * Copyright (C) 2006-2016 Oracle Corporation
     7 * Copyright (C) 2006-2017 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    213213    /** Number of soft resets we've logged. */
    214214    uint32_t        cLoggedSoftResets;
     215    /** Current port number for Bochs shutdown (used by APM). */
     216    RTIOPORT        ShutdownPort;
     217    /** True=use new port number for Bochs shutdown (used by APM). */
     218    bool            fNewShutdownPort;
    215219} DEVPCBIOS;
    216220/** Pointer to the BIOS device state. */
     
    218222
    219223
    220 /**
    221  * @callback_method_impl{FNIOMIOPORTIN, Boch Debug and Shutdown ports.}
     224/*********************************************************************************************************************************
     225*   Defined Constants And Macros                                                                                                 *
     226*********************************************************************************************************************************/
     227/** The saved state version. */
     228#define PCBIOS_SSM_VERSION 0
     229
     230
     231/*********************************************************************************************************************************
     232*   Global Variables                                                                                                             *
     233*********************************************************************************************************************************/
     234/** Saved state DEVPCBIOS field descriptors. */
     235static SSMFIELD const g_aPcBiosFields[] =
     236{
     237    SSMFIELD_ENTRY(         DEVPCBIOS, fNewShutdownPort),
     238    SSMFIELD_ENTRY_TERM()
     239};
     240
     241
     242/**
     243 * @callback_method_impl{FNIOMIOPORTIN, Bochs Debug and Shutdown ports.}
    222244 */
    223245static DECLCALLBACK(int) pcbiosIOPortRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb)
     
    229251
    230252/**
    231  * @callback_method_impl{FNIOMIOPORTOUT, Boch Debug and Shutdown ports.}
     253 * @callback_method_impl{FNIOMIOPORTOUT, Bochs Debug and Shutdown ports.}
    232254 */
    233255static DECLCALLBACK(int) pcbiosIOPortWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb)
    234256{
    235257    RT_NOREF1(pvUser);
     258    PDEVPCBIOS pThis = PDMINS_2_DATA(pDevIns, PDEVPCBIOS);
    236259
    237260    /*
     
    242265             || Port == 0x403))
    243266    {
    244         PDEVPCBIOS pThis = PDMINS_2_DATA(pDevIns, PDEVPCBIOS);
    245267        /* The raw version. */
    246268        switch (u32)
     
    277299     * Bochs BIOS shutdown request.
    278300     */
    279     if (cb == 1 && Port == 0x8900)
     301    if (cb == 1 && Port == pThis->ShutdownPort)
    280302    {
    281303        static const unsigned char szShutdown[] = "Shutdown";
     
    287309            {
    288310                pThis->iShutdown = 0;
    289                 LogRel(("PcBios: 8900h shutdown request\n"));
     311                LogRel(("PcBios: APM shutdown request\n"));
    290312                return PDMDevHlpVMPowerOff(pDevIns);
    291313            }
     
    298320    /* not in use. */
    299321    return VINF_SUCCESS;
     322}
     323
     324
     325/**
     326 * Register the Bochs shutdown port.
     327 * This is used by pcbiosConstruct, pcbiosReset and pcbiosLoadExec.
     328 */
     329static int pcbiosRegisterShutdown(PPDMDEVINS pDevIns, PDEVPCBIOS pThis, bool fNewShutdownPort)
     330{
     331    if (pThis->ShutdownPort != 0)
     332    {
     333        int rc = PDMDevHlpIOPortDeregister(pDevIns, pThis->ShutdownPort, 1);
     334        AssertRC(rc);
     335    }
     336    pThis->fNewShutdownPort = fNewShutdownPort;
     337    if (fNewShutdownPort)
     338        pThis->ShutdownPort = 0x040f;
     339    else
     340        pThis->ShutdownPort = 0x9800;
     341    return PDMDevHlpIOPortRegister(pDevIns, pThis->ShutdownPort, 1, NULL,
     342                                   pcbiosIOPortWrite, pcbiosIOPortRead,
     343                                   NULL, NULL, "Bochs PC BIOS - Shutdown");
     344}
     345
     346/**
     347 * Execute state save operation.
     348 *
     349 * @returns VBox status code.
     350 * @param   pDevIns         Device instance which registered the data unit.
     351 * @param   pSSM            SSM operation handle.
     352 */
     353static DECLCALLBACK(int) pcbiosSaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
     354{
     355    PDEVPCBIOS pThis = PDMINS_2_DATA(pDevIns, PDEVPCBIOS);
     356    SSMR3PutStruct(pSSM, pThis, g_aPcBiosFields);
     357    return VINF_SUCCESS;
     358}
     359
     360
     361/**
     362 * Prepare state load operation.
     363 *
     364 * @returns VBox status code.
     365 * @param   pDevIns         Device instance which registered the data unit.
     366 * @param   pSSM            SSM operation handle.
     367 */
     368static DECLCALLBACK(int) pcbiosLoadPrep(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
     369{
     370    RT_NOREF(pSSM);
     371    PDEVPCBIOS pThis = PDMINS_2_DATA(pDevIns, PDEVPCBIOS);
     372    /* Since there are legacy saved state files without any SSM data for PCBIOS
     373     * this is the only way to handle them correctly. */
     374    pThis->fNewShutdownPort = false;
     375
     376    return VINF_SUCCESS;
     377}
     378
     379/**
     380 * Execute state load operation.
     381 *
     382 * @returns VBox status code.
     383 * @param   pDevIns         Device instance which registered the data unit.
     384 * @param   pSSM            SSM operation handle.
     385 * @param   uVersion        Data layout version.
     386 * @param   uPass           The data pass.
     387 */
     388static DECLCALLBACK(int) pcbiosLoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
     389{
     390    PDEVPCBIOS pThis = PDMINS_2_DATA(pDevIns, PDEVPCBIOS);
     391
     392    if (uVersion > PCBIOS_SSM_VERSION)
     393        return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
     394    Assert(uPass == SSM_PASS_FINAL); NOREF(uPass);
     395
     396    SSMR3GetStruct(pSSM, &pThis, g_aPcBiosFields);
     397
     398    return VINF_SUCCESS;
     399}
     400
     401/**
     402 * Finish state load operation.
     403 *
     404 * @returns VBox status code.
     405 * @param   pDevIns         Device instance which registered the data unit.
     406 * @param   pSSM            SSM operation handle.
     407 */
     408static DECLCALLBACK(int) pcbiosLoadDone(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
     409{
     410    RT_NOREF(pSSM);
     411    PDEVPCBIOS pThis = PDMINS_2_DATA(pDevIns, PDEVPCBIOS);
     412
     413    /* Update the shutdown port registration to match the flag. */
     414    return pcbiosRegisterShutdown(pDevIns, pThis, pThis->fNewShutdownPort);
    300415}
    301416
     
    378493        }
    379494    }
     495
     496    /* After reset the new BIOS code is active, use the new shutdown port. */
     497    pcbiosRegisterShutdown(pDevIns, pThis, true /* fNewShutdownPort */);
    380498}
    381499
     
    12561374    if (RT_FAILURE(rc))
    12571375        return rc;
    1258     rc = PDMDevHlpIOPortRegister(pDevIns, 0x8900, 1, NULL, pcbiosIOPortWrite, pcbiosIOPortRead,
    1259                                  NULL, NULL, "Bochs PC BIOS - Shutdown");
     1376    rc = pcbiosRegisterShutdown(pDevIns, pThis, true /* fNewShutdownPort */);
    12601377    if (RT_FAILURE(rc))
    12611378        return rc;
     1379
     1380    /*
     1381     * Register SSM handlers, for remembering which shutdown port to use.
     1382     */
     1383    rc = PDMDevHlpSSMRegisterEx(pDevIns, PCBIOS_SSM_VERSION, 1 /* cbGuess */, NULL,
     1384                                NULL, NULL, NULL,
     1385                                NULL, pcbiosSaveExec, NULL,
     1386                                pcbiosLoadPrep, pcbiosLoadExec, pcbiosLoadDone);
    12621387
    12631388    /*
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette