HGSMI.h revision 5ce202824bd2fbece9bc3b1b3de6a7abfa6b8f9a
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * VBox Host Guest Shared Memory Interface (HGSMI).
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * Host/Guest shared part.
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * Copyright (C) 2006-2008 Sun Microsystems, Inc.
cf5f6bf2704d4fff443139e10bccc6a0a7fa4b85vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
cf5f6bf2704d4fff443139e10bccc6a0a7fa4b85vboxsync * available from http://www.virtualbox.org. This file is free software;
cf5f6bf2704d4fff443139e10bccc6a0a7fa4b85vboxsync * you can redistribute it and/or modify it under the terms of the GNU
cf5f6bf2704d4fff443139e10bccc6a0a7fa4b85vboxsync * General Public License (GPL) as published by the Free Software
cf5f6bf2704d4fff443139e10bccc6a0a7fa4b85vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
cf5f6bf2704d4fff443139e10bccc6a0a7fa4b85vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
cf5f6bf2704d4fff443139e10bccc6a0a7fa4b85vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
cf5f6bf2704d4fff443139e10bccc6a0a7fa4b85vboxsync * The contents of this file may alternatively be used under the terms
cf5f6bf2704d4fff443139e10bccc6a0a7fa4b85vboxsync * of the Common Development and Distribution License Version 1.0
cf5f6bf2704d4fff443139e10bccc6a0a7fa4b85vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
cf5f6bf2704d4fff443139e10bccc6a0a7fa4b85vboxsync * VirtualBox OSE distribution, in which case the provisions of the
cf5f6bf2704d4fff443139e10bccc6a0a7fa4b85vboxsync * CDDL are applicable instead of those of the GPL.
cf5f6bf2704d4fff443139e10bccc6a0a7fa4b85vboxsync * You may elect to license modified versions of this file under the
cf5f6bf2704d4fff443139e10bccc6a0a7fa4b85vboxsync * terms and conditions of either the GPL or the CDDL or both.
cf5f6bf2704d4fff443139e10bccc6a0a7fa4b85vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
cf5f6bf2704d4fff443139e10bccc6a0a7fa4b85vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
cf5f6bf2704d4fff443139e10bccc6a0a7fa4b85vboxsync * additional information or have any questions.
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync/* HGSMI uses 32 bit offsets and sizes. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * Basic mechanism for the HGSMI is to prepare and pass data buffer to the host and the guest.
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * Data inside these buffers are opaque for the HGSMI and are interpreted by higher levels.
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * Every shared memory buffer passed between the guest/host has the following structure:
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * HGSMIBUFFERHEADER header;
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * uint8_t data[header.u32BufferSize];
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * HGSMIBUFFERTAIL tail;
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * Note: Offset of the 'header' in the memory is used for virtual hardware IO.
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * Buffers are verifyed using the offset and the content of the header and the tail,
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * which are constant during a call.
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * Invalid buffers are ignored.
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * Actual 'data' is not verifyed, as it is expected that the data can be changed by the
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * called function.
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * Since only the offset of the buffer is passed in a IO operation, the header and tail
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * must contain:
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * * size of data in this buffer;
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * * checksum for buffer verification.
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * For segmented transfers:
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * * the sequence identifier;
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * * offset of the current segment in the sequence;
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * * total bytes in the transfer.
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * Additionally contains:
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * * the channel ID;
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * * the channel information.
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync/* Describes a shared memory area buffer.
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * Used for calculations with offsets and for buffers verification.
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsynctypedef struct _HGSMIAREA
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync uint8_t *pu8Base; /* The starting address of the area. Corresponds to offset 'offBase'. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync HGSMIOFFSET offBase; /* The starting offset of the area. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * offBase + cbArea - 1 - (sizeof (header) + sizeof (tail)).
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync/* The buffer description flags. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync#define HGSMI_BUFFER_HEADER_F_SEQ_MASK 0x03 /* Buffer sequence type mask. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync#define HGSMI_BUFFER_HEADER_F_SEQ_SINGLE 0x00 /* Single buffer, not a part of a sequence. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync#define HGSMI_BUFFER_HEADER_F_SEQ_START 0x01 /* The first buffer in a sequence. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync#define HGSMI_BUFFER_HEADER_F_SEQ_CONTINUE 0x02 /* A middle buffer in a sequence. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync#define HGSMI_BUFFER_HEADER_F_SEQ_END 0x03 /* The last buffer in a sequence. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync/* 16 bytes buffer header. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync uint32_t u32DataSize; /* Size of data that follows the header. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync uint8_t u8Flags; /* The buffer description: HGSMI_BUFFER_HEADER_F_* */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync uint8_t u8Channel; /* The channel the data must be routed to. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync uint16_t u16ChannelInfo; /* Opaque to the HGSMI, used by the channel. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync uint8_t au8Union[8]; /* Opaque placeholder to make the union 8 bytes. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync { /* HGSMI_BUFFER_HEADER_F_SEQ_SINGLE */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync uint32_t u32Reserved1; /* A reserved field, initialize to 0. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync uint32_t u32Reserved2; /* A reserved field, initialize to 0. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync { /* HGSMI_BUFFER_HEADER_F_SEQ_START */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync uint32_t u32SequenceNumber; /* The sequence number, the same for all buffers in the sequence. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync uint32_t u32SequenceSize; /* The total size of the sequence. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync { /* HGSMI_BUFFER_HEADER_F_SEQ_CONTINUE and HGSMI_BUFFER_HEADER_F_SEQ_END */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync uint32_t u32SequenceNumber; /* The sequence number, the same for all buffers in the sequence. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync uint32_t u32SequenceOffset; /* Data offset in the entire sequence. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync/* 8 bytes buffer tail. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync uint32_t u32Reserved; /* Reserved, must be initialized to 0. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync uint32_t u32Checksum; /* Verifyer for the buffer header and offset and for first 4 bytes of the tail. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsynctypedef struct _HGSMIHEAP
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync/* The size of the array of channels. Array indexes are uint8_t. Note: the value must not be changed. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync/* Channel handler called when the guest submits a buffer. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsynctypedef DECLCALLBACK(int) FNHGSMICHANNELHANDLER(void *pvHandler, uint16_t u16ChannelInfo, void *pvBuffer, HGSMISIZE cbBuffer);
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsynctypedef FNHGSMICHANNELHANDLER *PFNHGSMICHANNELHANDLER;
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync/* Information about a handler: pfn + context. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync/* Channel description. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync HGSMICHANNELHANDLER handler; /* The channel handler. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync const char *pszName; /* NULL for hardcoded channels or RTStrDup'ed name. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync uint8_t u8Channel; /* The channel id, equal to the channel index in the array. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync HGSMICHANNEL Channels[HGSMI_NUMBER_OF_CHANNELS]; /* Channel handlers indexed by the channel id.
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * The array is accessed under the instance lock.
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync return sizeof (HGSMIBUFFERHEADER) + sizeof (HGSMIBUFFERTAIL);
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncDECLINLINE(uint8_t *) HGSMIBufferData (const HGSMIBUFFERHEADER *pHeader)
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync return (uint8_t *)pHeader + sizeof (HGSMIBUFFERHEADER);
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncDECLINLINE(HGSMIBUFFERTAIL *) HGSMIBufferTail (const HGSMIBUFFERHEADER *pHeader)
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync return (HGSMIBUFFERTAIL *)(HGSMIBufferData (pHeader) + pHeader->u32DataSize);
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncDECLINLINE(HGSMIBUFFERHEADER *) HGSMIBufferHeaderFromData (const void *pvData)
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync return (HGSMIBUFFERHEADER *)((uint8_t *)pvData - sizeof (HGSMIBUFFERHEADER));
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncDECLINLINE(HGSMISIZE) HGSMIBufferRequiredSize (uint32_t u32DataSize)
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncDECLINLINE(HGSMIOFFSET) HGSMIPointerToOffset (const HGSMIAREA *pArea,
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync return pArea->offBase + (HGSMIOFFSET)((uint8_t *)pHeader - pArea->pu8Base);
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncDECLINLINE(HGSMIBUFFERHEADER *) HGSMIOffsetToPointer (const HGSMIAREA *pArea,
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync return (HGSMIBUFFERHEADER *)(pArea->pu8Base + (offBuffer - pArea->offBase));
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncDECLINLINE(uint8_t *) HGSMIBufferDataFromOffset (const HGSMIAREA *pArea, HGSMIOFFSET offBuffer)
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync HGSMIBUFFERHEADER *pHeader = HGSMIOffsetToPointer (pArea, offBuffer);
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncHGSMICHANNEL *HGSMIChannelFindById (HGSMICHANNELINFO * pChannelInfo, uint8_t u8Channel);
974de75a5a0c1d17919acfe706ebd403d9dcc440vboxsyncDECLINLINE(bool) HGSMIAreaContainsOffset(HGSMIAREA *pArea, HGSMIOFFSET offSet)
5ce202824bd2fbece9bc3b1b3de6a7abfa6b8f9avboxsync return pArea->offBase <= offSet && pArea->offBase + pArea->cbArea > offSet;
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncHGSMIOFFSET HGSMIBufferInitializeSingle (const HGSMIAREA *pArea,
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncHGSMIOFFSET HGSMIHeapBufferOffset (HGSMIHEAP *pHeap,
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncDECLINLINE(HGSMIOFFSET) HGSMIHeapOffset(HGSMIHEAP *pHeap)
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync/* needed for heap relocation */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncDECLINLINE(HGSMIOFFSET) HGSMIHeapHandleLocationOffset(HGSMIHEAP *pHeap)
8f1c8e96fab0c5f5a8dcabeb4e20a56a8b4cea18vboxsync AssertCompile((uintptr_t)NIL_RTHEAPSIMPLE == (uintptr_t)NIL_RTHEAPOFFSET);
8f1c8e96fab0c5f5a8dcabeb4e20a56a8b4cea18vboxsync ? (HGSMIOFFSET)(pHeap->area.pu8Base - (uint8_t*)pHeap->u.hPtr)
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncDECLINLINE(HGSMISIZE) HGSMIHeapSize(HGSMIHEAP *pHeap)
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncint HGSMIChannelRegister (HGSMICHANNELINFO * pChannelInfo,
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync const char *pszName,
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync#endif /* __HGSMI_h__*/