Virtio-solaris.c revision c7814cf6e1240a519cbec0441e033d0e2470ed00
87902654924b5893d165c3f31f1d8a50f87205b4vboxsync * VirtualBox Guest Additions - Virtio Driver for Solaris.
c7814cf6e1240a519cbec0441e033d0e2470ed00vboxsync * Copyright (C) 2010-2011 Oracle Corporation
1a9a76385f412e8c5762baadaa30afe308b1cd12vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
1a9a76385f412e8c5762baadaa30afe308b1cd12vboxsync * available from http://www.virtualbox.org. This file is free software;
1a9a76385f412e8c5762baadaa30afe308b1cd12vboxsync * you can redistribute it and/or modify it under the terms of the GNU
1a9a76385f412e8c5762baadaa30afe308b1cd12vboxsync * General Public License (GPL) as published by the Free Software
1a9a76385f412e8c5762baadaa30afe308b1cd12vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
1a9a76385f412e8c5762baadaa30afe308b1cd12vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
1a9a76385f412e8c5762baadaa30afe308b1cd12vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
1a9a76385f412e8c5762baadaa30afe308b1cd12vboxsync * The contents of this file may alternatively be used under the terms
1a9a76385f412e8c5762baadaa30afe308b1cd12vboxsync * of the Common Development and Distribution License Version 1.0
1a9a76385f412e8c5762baadaa30afe308b1cd12vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
1a9a76385f412e8c5762baadaa30afe308b1cd12vboxsync * VirtualBox OSE distribution, in which case the provisions of the
1a9a76385f412e8c5762baadaa30afe308b1cd12vboxsync * CDDL are applicable instead of those of the GPL.
1a9a76385f412e8c5762baadaa30afe308b1cd12vboxsync * You may elect to license modified versions of this file under the
1a9a76385f412e8c5762baadaa30afe308b1cd12vboxsync * terms and conditions of either the GPL or the CDDL or both.
38b0f04a36431d57eed1de01653dd0a015eae4c3vboxsync/*******************************************************************************
38b0f04a36431d57eed1de01653dd0a015eae4c3vboxsync* Header Files *
38b0f04a36431d57eed1de01653dd0a015eae4c3vboxsync*******************************************************************************/
38b0f04a36431d57eed1de01653dd0a015eae4c3vboxsync * Virtio Attach routine that should be called from all Virtio drivers' attach
38b0f04a36431d57eed1de01653dd0a015eae4c3vboxsync * routines.
38b0f04a36431d57eed1de01653dd0a015eae4c3vboxsync * @param pDip The module structure instance.
38b0f04a36431d57eed1de01653dd0a015eae4c3vboxsync * @param enmCmd Operation type (attach/resume).
38b0f04a36431d57eed1de01653dd0a015eae4c3vboxsync * @param pDeviceOps Pointer to device ops structure.
38b0f04a36431d57eed1de01653dd0a015eae4c3vboxsync * @param pHyperOps Pointer to hypervisor ops structure.
38b0f04a36431d57eed1de01653dd0a015eae4c3vboxsync * @return Solaris DDI error code. DDI_SUCCESS or DDI_FAILURE.
38b0f04a36431d57eed1de01653dd0a015eae4c3vboxsyncint VirtioAttach(dev_info_t *pDip, ddi_attach_cmd_t enmCmd, PVIRTIODEVICEOPS pDeviceOps, PVIRTIOHYPEROPS pHyperOps)
38b0f04a36431d57eed1de01653dd0a015eae4c3vboxsync LogFlowFunc((VIRTIOLOGNAME ":VirtioAttach: pDip=%p enmCmd=%d pDeviceOps=%p pHyperOps=%p\n", pDip, enmCmd, pDeviceOps, pHyperOps));
38b0f04a36431d57eed1de01653dd0a015eae4c3vboxsync LogRel((VIRTIOLOGNAME ":VirtioAttach: Invalid enmCmd=%#x expected DDI_ATTACH\n", enmCmd));
38b0f04a36431d57eed1de01653dd0a015eae4c3vboxsync PVIRTIODEVICE pDevice = RTMemAllocZ(sizeof(VIRTIODEVICE));
38b0f04a36431d57eed1de01653dd0a015eae4c3vboxsync pDevice->pvDevice = pDevice->pDeviceOps->pfnAlloc(pDevice);
38b0f04a36431d57eed1de01653dd0a015eae4c3vboxsync pDevice->pvHyper = pDevice->pHyperOps->pfnAlloc(pDevice);
38b0f04a36431d57eed1de01653dd0a015eae4c3vboxsync * Attach hypervisor interface and obtain features supported by host.
38b0f04a36431d57eed1de01653dd0a015eae4c3vboxsync pDevice->fHostFeatures = pDevice->pHyperOps->pfnGetFeatures(pDevice);
38b0f04a36431d57eed1de01653dd0a015eae4c3vboxsync LogFlow((VIRTIOLOGNAME ":VirtioAttach: Host features=%#x\n", pDevice->fHostFeatures));
38b0f04a36431d57eed1de01653dd0a015eae4c3vboxsync * Attach the device type interface.
38b0f04a36431d57eed1de01653dd0a015eae4c3vboxsync LogRel((VIRTIOLOGNAME ":VirtioAttach: DeviceOps pfnAttach failed. rc=%d\n", rc));
38b0f04a36431d57eed1de01653dd0a015eae4c3vboxsync LogRel((VIRTIOLOGNAME ":VirtioAttach: HyperOps pfnAttach failed. rc=%d\n", rc));
38b0f04a36431d57eed1de01653dd0a015eae4c3vboxsync LogRel((VIRTIOLOGNAME ":VirtioAttach: HyperOps->pfnAlloc failed!\n"));
38b0f04a36431d57eed1de01653dd0a015eae4c3vboxsync LogRel((VIRTIOLOGNAME ":VirtioAttach: DeviceOps->pfnAlloc failed!\n"));
38b0f04a36431d57eed1de01653dd0a015eae4c3vboxsync LogRel((VIRTIOLOGNAME ":VirtioAttach: failed to alloc %u bytes for device structure.\n", sizeof(VIRTIODEVICE)));
38b0f04a36431d57eed1de01653dd0a015eae4c3vboxsync * Virtio Detach routine that should be called from all Virtio drivers' detach
38b0f04a36431d57eed1de01653dd0a015eae4c3vboxsync * routines.
38b0f04a36431d57eed1de01653dd0a015eae4c3vboxsync * @param pDip The module structure instance.
38b0f04a36431d57eed1de01653dd0a015eae4c3vboxsync * @param enmCmd Operation type (detach/suspend).
38b0f04a36431d57eed1de01653dd0a015eae4c3vboxsync * @return Solaris DDI error code. DDI_SUCCESS or DDI_FAILURE.
38b0f04a36431d57eed1de01653dd0a015eae4c3vboxsyncint VirtioDetach(dev_info_t *pDip, ddi_detach_cmd_t enmCmd)
38b0f04a36431d57eed1de01653dd0a015eae4c3vboxsync LogFlowFunc((VIRTIOLOGNAME ":VirtioDetach pDip=%p enmCmd=%d\n", pDip, enmCmd));
38b0f04a36431d57eed1de01653dd0a015eae4c3vboxsync PVIRTIODEVICE pDevice = ddi_get_driver_private(pDip);
38b0f04a36431d57eed1de01653dd0a015eae4c3vboxsync LogRel((VIRTIOLOGNAME ":VirtioDetach: Invalid enmCmd=%#x expected DDI_DETACH.\n", enmCmd));
38b0f04a36431d57eed1de01653dd0a015eae4c3vboxsync LogRel((VIRTIOLOGNAME ":VirtioDetach: DeviceOps pfnDetach failed. rc=%d\n", rc));
38b0f04a36431d57eed1de01653dd0a015eae4c3vboxsync * Allocates a Virtio Queue object and assigns it an index.
38b0f04a36431d57eed1de01653dd0a015eae4c3vboxsync * @param pDevice Pointer to the Virtio device instance.
38b0f04a36431d57eed1de01653dd0a015eae4c3vboxsync * @return A pointer to a Virtio Queue instance.
38b0f04a36431d57eed1de01653dd0a015eae4c3vboxsyncPVIRTIOQUEUE VirtioGetQueue(PVIRTIODEVICE pDevice, uint16_t Index)
38b0f04a36431d57eed1de01653dd0a015eae4c3vboxsync PVIRTIOQUEUE pQueue = RTMemAllocZ(sizeof(VIRTIOQUEUE));
38b0f04a36431d57eed1de01653dd0a015eae4c3vboxsync LogRel((VIRTIOLOGNAME ":VirtioGetQueue: failed to alloc memory for %u bytes.\n", sizeof(VIRTIOQUEUE)));
38b0f04a36431d57eed1de01653dd0a015eae4c3vboxsync pQueue->pvData = pDevice->pHyperOps->pfnGetQueue(pDevice, pQueue);
38b0f04a36431d57eed1de01653dd0a015eae4c3vboxsync LogRel((VIRTIOLOGNAME ":VirtioGetQueue: HyperOps GetQueue failed!\n"));
38b0f04a36431d57eed1de01653dd0a015eae4c3vboxsync /* @todo enable interrupt. */
38b0f04a36431d57eed1de01653dd0a015eae4c3vboxsync * Puts a queue and destroys the instance.
38b0f04a36431d57eed1de01653dd0a015eae4c3vboxsync * @param pDevice Pointer to the Virtio device instance.
38b0f04a36431d57eed1de01653dd0a015eae4c3vboxsync * @param pQueue Pointer to the Virtio queue.