VirtualBox

Changeset 63884 in vbox


Ignore:
Timestamp:
Sep 19, 2016 12:21:00 PM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
110748
Message:

Devices/Samples: add "playground" device for making experiments (it isn't used by default and will be changed when specific PDM PCI testing is needed)

Location:
trunk/src/VBox/Devices/Samples
Files:
2 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Samples/DevPlayground.cpp

    r63881 r63884  
    11/* $Id$ */
    22/** @file
    3  * VBox Sample Device.
     3 * DevPlayground - Device for making PDM/PCI/... experiments.
     4 *
     5 * This device uses big PCI BAR64 resources, which needs the ICH9 chipset.
     6 * The device works without any PCI config (because the default setup with the
     7 * ICH9 chipset doesn't have anything at bus=0, device=0, function=0.
     8 *
     9 * To enable this device for a particular VM:
     10 * VBoxManage setextradata vmname VBoxInternal/PDM/Devices/playground/Path .../obj/VBoxSampleDevice/VBoxSampleDevice
     11 * VBoxManage setextradata vmname VBoxInternal/Devices/playground/0/Config/Whatever1 0
    412 */
    513
     
    3543 * Device Instance Data.
    3644 */
    37 typedef struct VBOXSAMPLEDEVICE
    38 {
    39     uint32_t    Whatever;
    40 } VBOXSAMPLEDEVICE;
    41 typedef VBOXSAMPLEDEVICE *PVBOXSAMPLEDEVICE;
    42 
    43 
    44 
    45 static DECLCALLBACK(int) devSampleDestruct(PPDMDEVINS pDevIns)
     45typedef struct VBOXPLAYGROUNDDEVICE
     46{
     47    /** The PCI device. */
     48    PCIDEVICE           PciDev;
     49} VBOXPLAYGROUNDDEVICE;
     50typedef VBOXPLAYGROUNDDEVICE *PVBOXPLAYGROUNDDEVICE;
     51
     52
     53/*********************************************************************************************************************************
     54*   Device Functions                                                                                                             *
     55*********************************************************************************************************************************/
     56/**
     57 * @interface_method_impl{PDMDEVREG,pfnDestruct}
     58 */
     59static DECLCALLBACK(int) devPlaygroundDestruct(PPDMDEVINS pDevIns)
    4660{
    4761    /*
     
    5569
    5670
    57 static DECLCALLBACK(int) devSampleConstruct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg)
    58 {
     71PDMBOTHCBDECL(int) devPlaygroundMMIORead(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, void *pv, unsigned cb)
     72{
     73    NOREF(pDevIns);
     74    NOREF(pvUser);
     75    NOREF(GCPhysAddr);
     76    NOREF(pv);
     77    NOREF(cb);
     78    return VINF_SUCCESS;
     79}
     80
     81
     82PDMBOTHCBDECL(int) devPlaygroundMMIOWrite(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, void const *pv, unsigned cb)
     83{
     84    NOREF(pDevIns);
     85    NOREF(pvUser);
     86    NOREF(GCPhysAddr);
     87    NOREF(pv);
     88    NOREF(cb);
     89    return VINF_SUCCESS;
     90}
     91
     92
     93/**
     94 * @callback_method_impl{FNPCIIOREGIONMAP}
     95 */
     96static DECLCALLBACK(int) devPlaygroundMap(PPCIDEVICE pPciDev, int iRegion, RTGCPHYS GCPhysAddress, RTGCPHYS cb, PCIADDRESSSPACE enmType)
     97{
     98    NOREF(enmType);
     99    int rc;
     100
     101    switch (iRegion)
     102    {
     103        case 0:
     104            rc = PDMDevHlpMMIORegister(pPciDev->pDevIns, GCPhysAddress, cb, NULL,
     105                                       IOMMMIO_FLAGS_READ_PASSTHRU | IOMMMIO_FLAGS_WRITE_PASSTHRU,
     106                                       devPlaygroundMMIOWrite, devPlaygroundMMIORead, "PG-BAR0");
     107            break;
     108        case 2:
     109            rc = PDMDevHlpMMIORegister(pPciDev->pDevIns, GCPhysAddress, cb, NULL,
     110                                       IOMMMIO_FLAGS_READ_PASSTHRU | IOMMMIO_FLAGS_WRITE_PASSTHRU,
     111                                       devPlaygroundMMIOWrite, devPlaygroundMMIORead, "PG-BAR2");
     112            break;
     113        default:
     114            /* We should never get here */
     115            AssertMsgFailed(("Invalid PCI region param in map callback"));
     116            rc = VERR_INTERNAL_ERROR;
     117    }
     118    return rc;
     119
     120}
     121
     122
     123/**
     124 * @interface_method_impl{PDMDEVREG,pfnConstruct}
     125 */
     126static DECLCALLBACK(int) devPlaygroundConstruct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg)
     127{
     128    NOREF(iInstance);
     129
    59130    /*
    60131     * Check that the device instance and device helper structures are compatible.
     
    66137     * Initialize the instance data so that the destructor won't mess up.
    67138     */
    68     PVBOXSAMPLEDEVICE pThis = PDMINS_2_DATA(pDevIns, PVBOXSAMPLEDEVICE);
    69     pThis->Whatever = 0;
     139    PVBOXPLAYGROUNDDEVICE pThis = PDMINS_2_DATA(pDevIns, PVBOXPLAYGROUNDDEVICE);
     140    PCIDevSetVendorId(&pThis->PciDev, 0x80ee);
     141    PCIDevSetDeviceId(&pThis->PciDev, 0xde4e);
     142    PCIDevSetClassBase(&pThis->PciDev, 0x07);   /* communications device */
     143    PCIDevSetClassSub(&pThis->PciDev, 0x80);    /* other communications device */
    70144
    71145    /*
     
    78152
    79153    /*
    80      * Use the instance number if necessary (not for this device, which in
    81      * g_DeviceSample below declares a maximum instance count of 1).
    82      */
    83     NOREF(iInstance);
    84 
    85     return VINF_SUCCESS;
    86 }
    87 
     154     * PCI device setup.
     155     */
     156    int rc = PDMDevHlpPCIRegister(pDevIns, &pThis->PciDev);
     157    if (RT_FAILURE(rc))
     158        return rc;
     159    rc = PDMDevHlpPCIIORegionRegister(pDevIns, 0, 8*_1G64,
     160                                      (PCIADDRESSSPACE)(PCI_ADDRESS_SPACE_MEM | PCI_ADDRESS_SPACE_BAR64),
     161                                      devPlaygroundMap);
     162    if (RT_FAILURE(rc))
     163        return rc;
     164    rc = PDMDevHlpPCIIORegionRegister(pDevIns, 2, 8*_1G64,
     165                                      (PCIADDRESSSPACE)(PCI_ADDRESS_SPACE_MEM | PCI_ADDRESS_SPACE_BAR64),
     166                                      devPlaygroundMap);
     167    if (RT_FAILURE(rc))
     168        return rc;
     169
     170    return VINF_SUCCESS;
     171}
     172
     173RT_C_DECLS_BEGIN
     174extern const PDMDEVREG g_DevicePlayground;
     175RT_C_DECLS_END
    88176
    89177/**
    90178 * The device registration structure.
    91179 */
    92 static const PDMDEVREG g_DeviceSample =
     180const PDMDEVREG g_DevicePlayground =
    93181{
    94182    /* u32Version */
    95183    PDM_DEVREG_VERSION,
    96184    /* szName */
    97     "sample",
     185    "playground",
    98186    /* szRCMod */
    99187    "",
     
    101189    "",
    102190    /* pszDescription */
    103     "VBox Sample Device.",
     191    "VBox Playground Device.",
    104192    /* fFlags */
    105193    PDM_DEVREG_FLAGS_DEFAULT_BITS,
     
    109197    1,
    110198    /* cbInstance */
    111     sizeof(VBOXSAMPLEDEVICE),
     199    sizeof(VBOXPLAYGROUNDDEVICE),
    112200    /* pfnConstruct */
    113     devSampleConstruct,
     201    devPlaygroundConstruct,
    114202    /* pfnDestruct */
    115     devSampleDestruct,
     203    devPlaygroundDestruct,
    116204    /* pfnRelocate */
    117205    NULL,
     
    141229    PDM_DEVREG_VERSION
    142230};
    143 
    144 
    145 /**
    146  * Register devices provided by the plugin.
    147  *
    148  * @returns VBox status code.
    149  * @param   pCallbacks      Pointer to the callback table.
    150  * @param   u32Version      VBox version number.
    151  */
    152 extern "C" DECLEXPORT(int) VBoxDevicesRegister(PPDMDEVREGCB pCallbacks, uint32_t u32Version)
    153 {
    154     LogFlow(("VBoxSampleDevice::VBoxDevicesRegister: u32Version=%#x pCallbacks->u32Version=%#x\n", u32Version, pCallbacks->u32Version));
    155 
    156     AssertLogRelMsgReturn(pCallbacks->u32Version == PDM_DEVREG_CB_VERSION,
    157                           ("%#x, expected %#x\n", pCallbacks->u32Version, PDM_DEVREG_CB_VERSION),
    158                           VERR_VERSION_MISMATCH);
    159 
    160     return pCallbacks->pfnRegister(pCallbacks, &g_DeviceSample);
    161 }
    162 
  • trunk/src/VBox/Devices/Samples/Makefile.kmk

    r62508 r63884  
    2727VBoxSampleDevice_INSTTYPE = none
    2828VBoxSampleDevice_SOURCES  = \
    29         VBoxSampleDevice.cpp
     29        VBoxSampleDevice.cpp \
     30        DevPlayground.cpp
    3031VBoxSampleDevice_LIBS     = \
    3132        $(LIB_RUNTIME) \
  • trunk/src/VBox/Devices/Samples/VBoxSampleDevice.cpp

    r63878 r63884  
    158158                          VERR_VERSION_MISMATCH);
    159159
    160     return pCallbacks->pfnRegister(pCallbacks, &g_DeviceSample);
     160    /* Two devices in this module. */
     161    extern const PDMDEVREG g_DevicePlayground;
     162    int rc = pCallbacks->pfnRegister(pCallbacks, &g_DeviceSample);
     163    if (RT_SUCCESS(rc))
     164        rc = pCallbacks->pfnRegister(pCallbacks, &g_DevicePlayground);
     165    return rc;
    161166}
    162167
Note: See TracChangeset for help on using the changeset viewer.

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