DevPciIch9.cpp revision 43584499dab07c88c88605e4b062f63c986cd624
/* $Id$ */
/** @file
* DevPCI - ICH9 southbridge PCI bus emulation Device.
*/
/*
* Copyright (C) 2010 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_DEV_PCI
/* Hack to get PCIDEVICEINT declare at the right point - include "PCIInternal.h". */
#define PCI_INCLUDE_PRIVATE
#include "../Builtins.h"
/**
* PCI Bus instance.
*/
typedef struct PCIBus
{
/** Bus number. */
/** Number of bridges attached to the bus. */
/** Array of PCI devices. We assume 32 slots, each with 8 functions. */
/** Array of bridges attached to the bus. */
/** R3 pointer to the device instance. */
/** Pointer to the PCI R3 helpers. */
/** R0 pointer to the device instance. */
/** Pointer to the PCI R0 helpers. */
/** RC pointer to the device instance. */
/** Pointer to the PCI RC helpers. */
/** The PCI device for the PCI bridge. */
/** @def PCI_IRQ_PINS
* Number of pins for interrupts (PIRQ#0...PIRQ#3)
*/
#define PCI_IRQ_PINS 4
/** @def PCI_APIC_IRQ_PINS
* Number of pins for interrupts if the APIC is used.
*/
#define PCI_APIC_IRQ_PINS 8
/**
* PCI Globals - This is the host-to-pci bridge and the root bus.
*/
typedef struct
{
/** R3 pointer to the device instance. */
/** R0 pointer to the device instance. */
/** RC pointer to the device instance. */
#if HC_ARCH_BITS == 64
#endif
/** PIC irq levels */
/** I/O APIC irq levels */
/** ACPI IRQ level */
/** .. and number */
/** Config register. */
/** I/O APIC usage flag */
bool fUseIoApic;
/** PCI bus which is attached to the host-to-PCI bridge. */
} PCIGLOBALS, *PPCIGLOBALS;
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
/** @def VBOX_ICH9PCI_SAVED_STATE_VERSION
* Saved state version of the ICH9 PCI bus device.
*/
#define VBOX_ICH9PCI_SAVED_STATE_VERSION 1
/** Converts a bus instance pointer to a device instance pointer. */
/** Converts a device instance pointer to a PCIGLOBALS pointer. */
/** Converts a device instance pointer to a PCIBUS pointer. */
#ifndef VBOX_DEVICE_STRUCT_TESTCASE
PDMBOTHCBDECL(void) ich9pcibridgeSetIrq(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, int iIrq, int iLevel);
PDMBOTHCBDECL(int) ich9pciIOPortAddressWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb);
PDMBOTHCBDECL(int) ich9pciIOPortAddressRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb);
PDMBOTHCBDECL(int) ich9pciIOPortDataWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb);
PDMBOTHCBDECL(int) ich9pciIOPortDataRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb);
#ifdef IN_RING3
#endif
{
return;
}
PDMBOTHCBDECL(void) ich9pcibridgeSetIrq(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, int iIrq, int iLevel)
{
return;
}
PDMBOTHCBDECL(int) ich9pciIOPortAddressWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb)
{
return 0;
}
PDMBOTHCBDECL(int) ich9pciIOPortAddressRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb)
{
return 0;
}
PDMBOTHCBDECL(int) ich9pciIOPortDataWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb)
{
return 0;
}
PDMBOTHCBDECL(int) ich9pciIOPortDataRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb)
{
return 0;
}
#ifdef IN_RING3
#endif
#ifdef IN_RING3
static DECLCALLBACK(int) ich9pciRegister(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, const char *pszName, int iDev)
{
return 0;
}
static DECLCALLBACK(int) ich9pcibridgeRegister(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, const char *pszName, int iDev)
{
return 0;
}
static DECLCALLBACK(int) ich9pciIORegionRegister(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, int iRegion, uint32_t cbRegion, PCIADDRESSSPACE enmType, PFNPCIIOREGIONMAP pfnCallback)
{
return 0;
}
static DECLCALLBACK(void) ich9pciSetConfigCallbacks(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, PFNPCICONFIGREAD pfnRead, PPFNPCICONFIGREAD ppfnReadOld,
{
}
/**
* Saves a state of the PCI device.
*
* @returns VBox status code.
* @param pDevIns Device instance of the PCI Bus.
* @param pPciDev Pointer to PCI device.
* @param pSSM The handle to save the state to.
*/
static DECLCALLBACK(int) pciGenericSaveExec(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, PSSMHANDLE pSSM)
{
}
{
/*
* Iterate thru all the devices.
*/
{
if (pDev)
{
SSMR3PutU32(pSSM, i);
if (RT_FAILURE(rc))
return rc;
}
}
}
{
}
{
}
static DECLCALLBACK(int) pciR3CommonLoadExec(PPCIBUS pBus, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
{
return 0;
}
/**
* Loads a saved PCI device state.
*
* @returns VBox status code.
* @param pDevIns Device instance of the PCI Bus.
* @param pPciDev Pointer to PCI device.
* @param pSSM The handle to the saved state.
*/
static DECLCALLBACK(int) pciGenericLoadExec(PPDMDEVINS pDevIns, PPCIDEVICE pPciDev, PSSMHANDLE pSSM)
{
}
static DECLCALLBACK(int) pciR3LoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
{
}
static DECLCALLBACK(int) pcibridgeR3LoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
{
}
{
return 0;
}
{
{
Assert(false);
return 0;
}
switch (len)
{
case 1:
case 2:
default:
case 4:
}
}
static DECLCALLBACK(void) ich9pciConfigWrite(PCIDevice *aDev, uint32_t u32Address, uint32_t val, unsigned len)
{
// @todo: write me
}
static const struct {
const char* pszName;
} PciSlotAssignments[] = {
{
"piix3ide", 1, 1 // do we really need it?
},
{
"lan", 25, 0
},
{
"hda", 27, 0 /* High Definition Audio */
},
{
"i82801", 30, 0 /* Host Controller */
},
{
"lpc", 31, 0 /* Low Pin Count bus */
},
{
"ahci", 31, 2 /* SATA controller */
},
{
"smbus", 31, 3 /* System Management Bus */
},
{
"thermal", 31, 6 /* Thermal controller */
},
};
{
{
{
}
}
/* Otherwise when assigning a slot, we need to make sure all its functions are available */
{
return iPos;
}
return -1;
}
{
;
}
{
/*
* Find device position
*/
if (iDev < 0)
{
if (iDev < 0)
{
AssertMsgFailed(("Couldn't find free spot!\n"));
return VERR_PDM_TOO_PCI_MANY_DEVICES;
}
}
/*
* Check if we can really take this slot, possibly by relocating
* its current habitant, if it wasn't hard assigned too.
*/
{
/*
* Smth like hasHardAssignedDevsInSlot(pBus, iDev >> 3) shall be use to make
* it compatible with DevPCI.cpp version, but this way we cannot assign
* in accordance with the chipset spec.
*/
AssertReleaseMsgFailed(("Configuration error:'%s' and '%s' are both configured as device %d\n",
return VERR_INTERNAL_ERROR;
}
{
/* if we got here, we shall (and usually can) relocate the device */
{
AssertMsgFailed(("Couldn't find free spot!\n"));
return VERR_PDM_TOO_PCI_MANY_DEVICES;
}
/* Copy device function by function to its new position */
for (int i = 0; i < 8; i++)
{
continue;
Log(("PCI: relocating '%s' from slot %#x to %#x\n", pBus->devices[iDev + i]->name, iDev + i, iRelDev + i));
}
}
/*
* Fill in device information.
*/
{
AssertMsg(pBus->cBridges < RT_ELEMENTS(pBus->devices), ("Number of bridges exceeds the number of possible devices on the bus\n"));
}
Log(("PCI: Registered device %d function %d (%#x) '%s'.\n",
return VINF_SUCCESS;
}
int iInstance,
{
int rc;
/*
* Validate and read configuration.
*/
/* query whether we got an IOAPIC */
bool fUseIoApic;
if (RT_FAILURE(rc))
N_("Configuration error: Failed to query boolean value \"IOAPIC\""));
/* check if RC code is enabled. */
bool fGCEnabled;
if (RT_FAILURE(rc))
N_("Configuration error: Failed to query boolean value \"GCEnabled\""));
/* check if R0 code is enabled. */
bool fR0Enabled;
if (RT_FAILURE(rc))
N_("Configuration error: Failed to query boolean value \"R0Enabled\""));
Log(("PCI: fUseIoApic=%RTbool fGCEnabled=%RTbool fR0Enabled=%RTbool\n", fUseIoApic, fGCEnabled, fR0Enabled));
/*
* Init data.
*/
/* Zero out everything */
/* And fill values */
pGlobals->aPciBus.papBridgesR3 = (PPCIDEVICE *)PDMDevHlpMMHeapAllocZ(pDevIns, sizeof(PPCIDEVICE) * RT_ELEMENTS(pGlobals->aPciBus.devices));
/*
* Register bus
*/
if (RT_FAILURE(rc))
N_("Failed to register ourselves as a PCI Bus"));
N_("PCI helper version mismatch; got %#x expected %#x"),
/*
* Fill in PCI configs and add them to the bus.
*/
/**
* We emulate 82801IB ICH9 IO chip used in Q35,
*
* Stepping S-Spec Top Marking
*
* A2 SLA9M NH82801IB
*/
/* We register Host<->PCI controller on the bus */
/** @todo: ther chipset devices shall be registered too */
/** @todo: bridges? */
return VINF_SUCCESS;
}
/**
* @copydoc FNPDMDEVRELOCATE
*/
{
}
/**
* @interface_method_impl{PDMDEVREG,pfnConstruct}
*/
int iInstance,
{
int rc;
/*
* Validate and read configuration.
*/
/* check if RC code is enabled. */
bool fGCEnabled;
if (RT_FAILURE(rc))
N_("Configuration error: Failed to query boolean value \"GCEnabled\""));
/* check if R0 code is enabled. */
bool fR0Enabled;
if (RT_FAILURE(rc))
N_("Configuration error: Failed to query boolean value \"R0Enabled\""));
return VINF_SUCCESS;
}
/**
* @copydoc FNPDMDEVRESET
*/
{
}
/**
* @copydoc FNPDMDEVRELOCATE
*/
{
}
/**
* The PCI bus device registration structure.
*/
const PDMDEVREG g_DevicePciIch9 =
{
/* u32Version */
/* szName */
"ich9pci",
/* szRCMod */
"VBoxDDGC.gc",
/* szR0Mod */
"VBoxDDR0.r0",
/* pszDescription */
"ICH9 PCI bridge",
/* fFlags */
/* fClass */
/* cMaxInstances */
1,
/* cbInstance */
sizeof(PCIGLOBALS),
/* pfnConstruct */
/* pfnDestruct */
NULL,
/* pfnRelocate */
/* pfnIOCtl */
NULL,
/* pfnPowerOn */
NULL,
/* pfnReset */
NULL,
/* pfnSuspend */
NULL,
/* pfnResume */
NULL,
/* pfnAttach */
NULL,
/* pfnDetach */
NULL,
/* pfnQueryInterface */
NULL,
/* pfnInitComplete */
NULL,
/* pfnPowerOff */
NULL,
/* pfnSoftReset */
NULL,
/* u32VersionEnd */
};
/**
* The device registration structure
* for the PCI-to-PCI bridge.
*/
const PDMDEVREG g_DevicePciIch9Bridge =
{
/* u32Version */
/* szName */
"ich9pcibridge",
/* szRCMod */
"VBoxDDGC.gc",
/* szR0Mod */
"VBoxDDR0.r0",
/* pszDescription */
"ICH9 PCI to PCI bridge",
/* fFlags */
/* fClass */
/* cMaxInstances */
~0,
/* cbInstance */
sizeof(PCIBUS),
/* pfnConstruct */
/* pfnDestruct */
NULL,
/* pfnRelocate */
/* pfnIOCtl */
NULL,
/* pfnPowerOn */
NULL,
/* pfnReset */
/* pfnSuspend */
NULL,
/* pfnResume */
NULL,
/* pfnAttach */
NULL,
/* pfnDetach */
NULL,
/* pfnQueryInterface */
NULL,
/* pfnInitComplete */
NULL,
/* pfnPowerOff */
NULL,
/* pfnSoftReset */
NULL,
/* u32VersionEnd */
};
#endif /* IN_RING3 */
#endif /* !VBOX_DEVICE_STRUCT_TESTCASE */