HGSMI.h revision d0a71f63bd810b54e0359223fe53b07730154dc5
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync/** @file
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync *
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * VBox Host Guest Shared Memory Interface (HGSMI).
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * Host/Guest shared part.
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync/*
e64031e20c39650a7bc902a3e1aba613b9415deevboxsync * Copyright (C) 2006-2008 Oracle Corporation
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync *
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 *
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 *
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.
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
7420e5ee5565b181c144eabb14da0da9e8cce657vboxsync#ifndef ___VBox_HGSMI_HGSMI_h
7420e5ee5565b181c144eabb14da0da9e8cce657vboxsync#define ___VBox_HGSMI_HGSMI_h
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync#include <iprt/assert.h>
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync#include <iprt/types.h>
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync#include <VBox/HGSMI/HGSMIChannels.h>
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync/* HGSMI uses 32 bit offsets and sizes. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsynctypedef uint32_t HGSMISIZE;
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsynctypedef uint32_t HGSMIOFFSET;
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync#define HGSMIOFFSET_VOID ((HGSMIOFFSET)~0)
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync/*
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 *
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * Every shared memory buffer passed between the guest/host has the following structure:
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync *
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * HGSMIBUFFERHEADER header;
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * uint8_t data[header.u32BufferSize];
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * HGSMIBUFFERTAIL tail;
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync *
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * Note: Offset of the 'header' in the memory is used for virtual hardware IO.
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync *
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * Buffers are verifyed using the offset and the content of the header and the tail,
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * which are constant during a call.
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync *
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * Invalid buffers are ignored.
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync *
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * Actual 'data' is not verifyed, as it is expected that the data can be changed by the
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * called function.
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync *
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 *
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * For segmented transfers:
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * * the sequence identifier;
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * * offset of the current segment in the sequence;
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * * total bytes in the transfer.
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync *
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * Additionally contains:
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * * the channel ID;
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * * the channel information.
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync/* Describes a shared memory area buffer.
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * Used for calculations with offsets and for buffers verification.
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsynctypedef struct _HGSMIAREA
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync{
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync uint8_t *pu8Base; /* The starting address of the area. Corresponds to offset 'offBase'. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync HGSMIOFFSET offBase; /* The starting offset of the area. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync HGSMIOFFSET offLast; /* The last valid offset:
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * offBase + cbArea - 1 - (sizeof (header) + sizeof (tail)).
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync HGSMISIZE cbArea; /* Size of the area. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync} HGSMIAREA;
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
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
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync#pragma pack(1)
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync/* 16 bytes buffer header. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsynctypedef struct _HGSMIBUFFERHEADER
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync{
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync uint32_t u32DataSize; /* Size of data that follows the header. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync uint8_t u8Flags; /* The buffer description: HGSMI_BUFFER_HEADER_F_* */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
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
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync union {
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync uint8_t au8Union[8]; /* Opaque placeholder to make the union 8 bytes. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync struct
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 } Buffer;
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync struct
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 } SequenceStart;
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync struct
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 } SequenceContinue;
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync } u;
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync} HGSMIBUFFERHEADER;
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync/* 8 bytes buffer tail. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsynctypedef struct _HGSMIBUFFERTAIL
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync{
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. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync} HGSMIBUFFERTAIL;
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync#pragma pack()
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncAssertCompile(sizeof (HGSMIBUFFERHEADER) == 16);
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncAssertCompile(sizeof (HGSMIBUFFERTAIL) == 8);
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync#pragma pack(1)
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsynctypedef struct _HGSMIHEAP
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync{
8f1c8e96fab0c5f5a8dcabeb4e20a56a8b4cea18vboxsync union
8f1c8e96fab0c5f5a8dcabeb4e20a56a8b4cea18vboxsync {
8f1c8e96fab0c5f5a8dcabeb4e20a56a8b4cea18vboxsync RTHEAPSIMPLE hPtr; /**< Pointer based heap. */
8f1c8e96fab0c5f5a8dcabeb4e20a56a8b4cea18vboxsync RTHEAPOFFSET hOff; /**< Offset based heap. */
8f1c8e96fab0c5f5a8dcabeb4e20a56a8b4cea18vboxsync } u;
8f1c8e96fab0c5f5a8dcabeb4e20a56a8b4cea18vboxsync HGSMIAREA area; /**< Description. */
8f1c8e96fab0c5f5a8dcabeb4e20a56a8b4cea18vboxsync int cRefs; /**< Number of heap allocations. */
8f1c8e96fab0c5f5a8dcabeb4e20a56a8b4cea18vboxsync bool fOffsetBased; /**< Set if offset based. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync} HGSMIHEAP;
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync#pragma pack()
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync#pragma pack(1)
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync/* The size of the array of channels. Array indexes are uint8_t. Note: the value must not be changed. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync#define HGSMI_NUMBER_OF_CHANNELS 0x100
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
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
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync/* Information about a handler: pfn + context. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsynctypedef struct _HGSMICHANNELHANDLER
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync{
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync PFNHGSMICHANNELHANDLER pfnHandler;
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync void *pvHandler;
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync} HGSMICHANNELHANDLER;
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync/* Channel description. */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsynctypedef struct _HGSMICHANNEL
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync{
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 uint8_t u8Flags; /* HGSMI_CH_F_* */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync} HGSMICHANNEL;
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsynctypedef struct _HGSMICHANNELINFO
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync{
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync HGSMICHANNEL Channels[HGSMI_NUMBER_OF_CHANNELS]; /* Channel handlers indexed by the channel id.
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync * The array is accessed under the instance lock.
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync} HGSMICHANNELINFO;
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync#pragma pack()
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncRT_C_DECLS_BEGIN
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncDECLINLINE(HGSMISIZE) HGSMIBufferMinimumSize (void)
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync{
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync return sizeof (HGSMIBUFFERHEADER) + sizeof (HGSMIBUFFERTAIL);
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync}
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncDECLINLINE(uint8_t *) HGSMIBufferData (const HGSMIBUFFERHEADER *pHeader)
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync{
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync return (uint8_t *)pHeader + sizeof (HGSMIBUFFERHEADER);
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync}
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncDECLINLINE(HGSMIBUFFERTAIL *) HGSMIBufferTail (const HGSMIBUFFERHEADER *pHeader)
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync{
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync return (HGSMIBUFFERTAIL *)(HGSMIBufferData (pHeader) + pHeader->u32DataSize);
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync}
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncDECLINLINE(HGSMIBUFFERHEADER *) HGSMIBufferHeaderFromData (const void *pvData)
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync{
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync return (HGSMIBUFFERHEADER *)((uint8_t *)pvData - sizeof (HGSMIBUFFERHEADER));
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync}
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncDECLINLINE(HGSMISIZE) HGSMIBufferRequiredSize (uint32_t u32DataSize)
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync{
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync return HGSMIBufferMinimumSize () + u32DataSize;
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync}
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncDECLINLINE(HGSMIOFFSET) HGSMIPointerToOffset (const HGSMIAREA *pArea,
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync const HGSMIBUFFERHEADER *pHeader)
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync{
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync return pArea->offBase + (HGSMIOFFSET)((uint8_t *)pHeader - pArea->pu8Base);
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync}
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncDECLINLINE(HGSMIBUFFERHEADER *) HGSMIOffsetToPointer (const HGSMIAREA *pArea,
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync HGSMIOFFSET offBuffer)
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync{
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync return (HGSMIBUFFERHEADER *)(pArea->pu8Base + (offBuffer - pArea->offBase));
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync}
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncDECLINLINE(uint8_t *) HGSMIBufferDataFromOffset (const HGSMIAREA *pArea, HGSMIOFFSET offBuffer)
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync{
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync HGSMIBUFFERHEADER *pHeader = HGSMIOffsetToPointer (pArea, offBuffer);
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync Assert(pHeader);
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync if(pHeader)
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync return HGSMIBufferData(pHeader);
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync return NULL;
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync}
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
85e5ab5adbba74b522731762dd05ca88cb529140vboxsyncDECLINLINE(uint8_t *) HGSMIBufferDataAndChInfoFromOffset (const HGSMIAREA *pArea, HGSMIOFFSET offBuffer, uint16_t * pChInfo)
85e5ab5adbba74b522731762dd05ca88cb529140vboxsync{
85e5ab5adbba74b522731762dd05ca88cb529140vboxsync HGSMIBUFFERHEADER *pHeader = HGSMIOffsetToPointer (pArea, offBuffer);
85e5ab5adbba74b522731762dd05ca88cb529140vboxsync Assert(pHeader);
85e5ab5adbba74b522731762dd05ca88cb529140vboxsync if(pHeader)
85e5ab5adbba74b522731762dd05ca88cb529140vboxsync {
85e5ab5adbba74b522731762dd05ca88cb529140vboxsync *pChInfo = pHeader->u16ChannelInfo;
85e5ab5adbba74b522731762dd05ca88cb529140vboxsync return HGSMIBufferData(pHeader);
85e5ab5adbba74b522731762dd05ca88cb529140vboxsync }
85e5ab5adbba74b522731762dd05ca88cb529140vboxsync return NULL;
85e5ab5adbba74b522731762dd05ca88cb529140vboxsync}
85e5ab5adbba74b522731762dd05ca88cb529140vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncHGSMICHANNEL *HGSMIChannelFindById (HGSMICHANNELINFO * pChannelInfo, uint8_t u8Channel);
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncuint32_t HGSMIChecksum (HGSMIOFFSET offBuffer,
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync const HGSMIBUFFERHEADER *pHeader,
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync const HGSMIBUFFERTAIL *pTail);
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncint HGSMIAreaInitialize (HGSMIAREA *pArea,
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync void *pvBase,
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync HGSMISIZE cbArea,
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync HGSMIOFFSET offBase);
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncvoid HGSMIAreaClear (HGSMIAREA *pArea);
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
974de75a5a0c1d17919acfe706ebd403d9dcc440vboxsyncDECLINLINE(bool) HGSMIAreaContainsOffset(HGSMIAREA *pArea, HGSMIOFFSET offSet)
974de75a5a0c1d17919acfe706ebd403d9dcc440vboxsync{
5ce202824bd2fbece9bc3b1b3de6a7abfa6b8f9avboxsync return pArea->offBase <= offSet && pArea->offBase + pArea->cbArea > offSet;
974de75a5a0c1d17919acfe706ebd403d9dcc440vboxsync}
974de75a5a0c1d17919acfe706ebd403d9dcc440vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncHGSMIOFFSET HGSMIBufferInitializeSingle (const HGSMIAREA *pArea,
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync HGSMIBUFFERHEADER *pHeader,
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync HGSMISIZE cbBuffer,
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync uint8_t u8Channel,
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync uint16_t u16ChannelInfo);
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncint HGSMIHeapSetup (HGSMIHEAP *pHeap,
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync void *pvBase,
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync HGSMISIZE cbArea,
8f1c8e96fab0c5f5a8dcabeb4e20a56a8b4cea18vboxsync HGSMIOFFSET offBase,
8f1c8e96fab0c5f5a8dcabeb4e20a56a8b4cea18vboxsync bool fOffsetBased);
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncint HGSMIHeapRelocate (HGSMIHEAP *pHeap,
8f1c8e96fab0c5f5a8dcabeb4e20a56a8b4cea18vboxsync void *pvBase,
8f1c8e96fab0c5f5a8dcabeb4e20a56a8b4cea18vboxsync uint32_t offHeapHandle,
8f1c8e96fab0c5f5a8dcabeb4e20a56a8b4cea18vboxsync uintptr_t offDelta,
8f1c8e96fab0c5f5a8dcabeb4e20a56a8b4cea18vboxsync HGSMISIZE cbArea,
8f1c8e96fab0c5f5a8dcabeb4e20a56a8b4cea18vboxsync HGSMIOFFSET offBase,
8f1c8e96fab0c5f5a8dcabeb4e20a56a8b4cea18vboxsync bool fOffsetBased);
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncvoid HGSMIHeapSetupUnitialized (HGSMIHEAP *pHeap);
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncbool HGSMIHeapIsItialized (HGSMIHEAP *pHeap);
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncvoid HGSMIHeapDestroy (HGSMIHEAP *pHeap);
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
d0a71f63bd810b54e0359223fe53b07730154dc5vboxsyncvoid* HGSMIHeapBufferAlloc (HGSMIHEAP *pHeap,
d0a71f63bd810b54e0359223fe53b07730154dc5vboxsync HGSMISIZE cbBuffer);
d0a71f63bd810b54e0359223fe53b07730154dc5vboxsync
d0a71f63bd810b54e0359223fe53b07730154dc5vboxsyncvoid HGSMIHeapBufferFree(HGSMIHEAP *pHeap,
d0a71f63bd810b54e0359223fe53b07730154dc5vboxsync void *pvBuf);
d0a71f63bd810b54e0359223fe53b07730154dc5vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncvoid *HGSMIHeapAlloc (HGSMIHEAP *pHeap,
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync HGSMISIZE cbData,
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync uint8_t u8Channel,
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync uint16_t u16ChannelInfo);
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncHGSMIOFFSET HGSMIHeapBufferOffset (HGSMIHEAP *pHeap,
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync void *pvData);
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncvoid HGSMIHeapFree (HGSMIHEAP *pHeap,
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync void *pvData);
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncDECLINLINE(HGSMIOFFSET) HGSMIHeapOffset(HGSMIHEAP *pHeap)
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync{
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync return pHeap->area.offBase;
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync}
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
7420e5ee5565b181c144eabb14da0da9e8cce657vboxsync#ifdef IN_RING3
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync/* needed for heap relocation */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncDECLINLINE(HGSMIOFFSET) HGSMIHeapHandleLocationOffset(HGSMIHEAP *pHeap)
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync{
8fa7c8ea1fd9355ab51e7592aff6c1ae0836dcbfvboxsync#if (__GNUC__ * 100 + __GNUC_MINOR__) < 405
8fa7c8ea1fd9355ab51e7592aff6c1ae0836dcbfvboxsync /* does not work with gcc-4.5 */
8fa7c8ea1fd9355ab51e7592aff6c1ae0836dcbfvboxsync AssertCompile((uintptr_t)NIL_RTHEAPSIMPLE == (uintptr_t)NIL_RTHEAPOFFSET);
8fa7c8ea1fd9355ab51e7592aff6c1ae0836dcbfvboxsync#endif
8f1c8e96fab0c5f5a8dcabeb4e20a56a8b4cea18vboxsync return pHeap->u.hPtr != NIL_RTHEAPSIMPLE
8f1c8e96fab0c5f5a8dcabeb4e20a56a8b4cea18vboxsync ? (HGSMIOFFSET)(pHeap->area.pu8Base - (uint8_t*)pHeap->u.hPtr)
8f1c8e96fab0c5f5a8dcabeb4e20a56a8b4cea18vboxsync : HGSMIOFFSET_VOID;
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync}
7420e5ee5565b181c144eabb14da0da9e8cce657vboxsync#endif /* IN_RING3 */
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncDECLINLINE(HGSMISIZE) HGSMIHeapSize(HGSMIHEAP *pHeap)
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync{
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync return pHeap->area.cbArea;
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync}
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncint HGSMIChannelRegister (HGSMICHANNELINFO * pChannelInfo,
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync uint8_t u8Channel,
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync const char *pszName,
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync PFNHGSMICHANNELHANDLER pfnChannelHandler,
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync void *pvChannelHandler,
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync HGSMICHANNELHANDLER *pOldHandler);
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncint HGSMIBufferProcess (HGSMIAREA *pArea,
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync HGSMICHANNELINFO * pChannelInfo,
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync HGSMIOFFSET offBuffer);
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsyncRT_C_DECLS_END
6a97c5c107ea1c9935054f25a4fb5ca59a214b72vboxsync
7420e5ee5565b181c144eabb14da0da9e8cce657vboxsync#endif /* !___VBox_HGSMI_HGSMI_h */
7420e5ee5565b181c144eabb14da0da9e8cce657vboxsync