Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3e7ee490 authored by Hank Janssen's avatar Hank Janssen Committed by Greg Kroah-Hartman
Browse files

Staging: hv: add the Hyper-V virtual bus



This is the virtual bus that all of the Linux Hyper-V drivers use.

Signed-off-by: default avatarHank Janssen <hjanssen@microsoft.com>
Signed-off-by: default avatarHaiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent ab057781
Loading
Loading
Loading
Loading
+1199 −0

File added.

Preview size limit exceeded, changes collapsed.

+157 −0
Original line number Diff line number Diff line
/*
 *
 * Copyright (c) 2009, Microsoft Corporation.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place - Suite 330, Boston, MA 02111-1307 USA.
 *
 * Authors:
 *   Haiyang Zhang <haiyangz@microsoft.com>
 *   Hank Janssen  <hjanssen@microsoft.com>
 *
 */


#ifndef _CHANNEL_H_
#define _CHANNEL_H_

#include "osd.h"
#include "ChannelMgmt.h"

#pragma pack(push,1)


// The format must be the same as VMDATA_GPA_DIRECT
typedef struct _VMBUS_CHANNEL_PACKET_PAGE_BUFFER {
    UINT16				Type;
    UINT16				DataOffset8;
    UINT16				Length8;
    UINT16				Flags;
    UINT64				TransactionId;
	UINT32				Reserved;
	UINT32				RangeCount;
    PAGE_BUFFER			Range[MAX_PAGE_BUFFER_COUNT];
} VMBUS_CHANNEL_PACKET_PAGE_BUFFER;


// The format must be the same as VMDATA_GPA_DIRECT
typedef struct _VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER {
    UINT16				Type;
    UINT16				DataOffset8;
    UINT16				Length8;
    UINT16				Flags;
    UINT64				TransactionId;
	UINT32				Reserved;
	UINT32				RangeCount;		// Always 1 in this case
	MULTIPAGE_BUFFER	Range;
} VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER;

#pragma pack(pop)

//
// Routines
//

INTERNAL int
VmbusChannelOpen(
	VMBUS_CHANNEL			*Channel,
	UINT32					SendRingBufferSize,
	UINT32					RecvRingBufferSize,
	PVOID					UserData,
	UINT32					UserDataLen,
	PFN_CHANNEL_CALLBACK	pfnOnChannelCallback,
	PVOID					Context
	);

INTERNAL void
VmbusChannelClose(
	VMBUS_CHANNEL		*Channel
	);

INTERNAL int
VmbusChannelSendPacket(
	VMBUS_CHANNEL		*Channel,
	const PVOID			Buffer,
	UINT32				BufferLen,
	UINT64				RequestId,
	VMBUS_PACKET_TYPE	Type,
	UINT32				Flags
);

INTERNAL int
VmbusChannelSendPacketPageBuffer(
	VMBUS_CHANNEL		*Channel,
	PAGE_BUFFER			PageBuffers[],
	UINT32				PageCount,
	PVOID				Buffer,
	UINT32				BufferLen,
	UINT64				RequestId
	);

INTERNAL int
VmbusChannelSendPacketMultiPageBuffer(
	VMBUS_CHANNEL		*Channel,
	MULTIPAGE_BUFFER	*MultiPageBuffer,
	PVOID				Buffer,
	UINT32				BufferLen,
	UINT64				RequestId
);

INTERNAL int
VmbusChannelEstablishGpadl(
	VMBUS_CHANNEL		*Channel,
	PVOID				Kbuffer,	// from kmalloc()
	UINT32				Size,		// page-size multiple
	UINT32				*GpadlHandle
	);

INTERNAL int
VmbusChannelTeardownGpadl(
	VMBUS_CHANNEL	*Channel,
	UINT32			GpadlHandle
	);

INTERNAL int
VmbusChannelRecvPacket(
	VMBUS_CHANNEL		*Channel,
	PVOID				Buffer,
	UINT32				BufferLen,
	UINT32*				BufferActualLen,
	UINT64*				RequestId
	);

INTERNAL int
VmbusChannelRecvPacketRaw(
	VMBUS_CHANNEL		*Channel,
	PVOID				Buffer,
	UINT32				BufferLen,
	UINT32*				BufferActualLen,
	UINT64*				RequestId
	);

INTERNAL void
VmbusChannelOnChannelEvent(
	VMBUS_CHANNEL		*Channel
	);

INTERNAL void
VmbusChannelGetDebugInfo(
	VMBUS_CHANNEL				*Channel,
	VMBUS_CHANNEL_DEBUG_INFO	*DebugInfo
	);

INTERNAL void
VmbusChannelOnTimer(
	void		*Context
	);
#endif //_CHANNEL_H_
+222 −0
Original line number Diff line number Diff line
/*
 *
 * Copyright (c) 2009, Microsoft Corporation.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place - Suite 330, Boston, MA 02111-1307 USA.
 *
 * Authors:
 *   Haiyang Zhang <haiyangz@microsoft.com>
 *   Hank Janssen  <hjanssen@microsoft.com>
 *
 */

#include "VmbusPrivate.h"

INTERNAL int
IVmbusChannelOpen(
	PDEVICE_OBJECT		Device,
	UINT32				SendBufferSize,
	UINT32				RecvRingBufferSize,
	PVOID				UserData,
	UINT32				UserDataLen,
	VMBUS_CHANNEL_CALLBACK ChannelCallback,
	PVOID				Context
	)
{
	return VmbusChannelOpen( (VMBUS_CHANNEL*)Device->context,
								SendBufferSize,
								RecvRingBufferSize,
								UserData,
								UserDataLen,
								ChannelCallback,
								Context);
}


INTERNAL void
IVmbusChannelClose(
	PDEVICE_OBJECT		Device
	)
{
	VmbusChannelClose((VMBUS_CHANNEL*)Device->context);
}


INTERNAL int
IVmbusChannelSendPacket(
	PDEVICE_OBJECT		Device,
	const PVOID			Buffer,
	UINT32				BufferLen,
	UINT64				RequestId,
	UINT32				Type,
	UINT32				Flags
	)
{
	return VmbusChannelSendPacket((VMBUS_CHANNEL*)Device->context,
									Buffer,
									BufferLen,
									RequestId,
									Type,
									Flags);
}

INTERNAL int
IVmbusChannelSendPacketPageBuffer(
	PDEVICE_OBJECT		Device,
	PAGE_BUFFER			PageBuffers[],
	UINT32				PageCount,
	PVOID				Buffer,
	UINT32				BufferLen,
	UINT64				RequestId
	)
{
	return VmbusChannelSendPacketPageBuffer((VMBUS_CHANNEL*)Device->context,
												PageBuffers,
												PageCount,
												Buffer,
												BufferLen,
												RequestId);
}

INTERNAL int
IVmbusChannelSendPacketMultiPageBuffer(
	PDEVICE_OBJECT		Device,
	MULTIPAGE_BUFFER	*MultiPageBuffer,
	PVOID				Buffer,
	UINT32				BufferLen,
	UINT64				RequestId
	)
{
	return VmbusChannelSendPacketMultiPageBuffer((VMBUS_CHANNEL*)Device->context,
													MultiPageBuffer,
													Buffer,
													BufferLen,
													RequestId);
}

INTERNAL int
IVmbusChannelRecvPacket (
	PDEVICE_OBJECT		Device,
	PVOID				Buffer,
	UINT32				BufferLen,
	UINT32*				BufferActualLen,
	UINT64*				RequestId
	)
{
	return VmbusChannelRecvPacket((VMBUS_CHANNEL*)Device->context,
									Buffer,
									BufferLen,
									BufferActualLen,
									RequestId);
}

INTERNAL int
IVmbusChannelRecvPacketRaw(
	PDEVICE_OBJECT		Device,
	PVOID				Buffer,
	UINT32				BufferLen,
	UINT32*				BufferActualLen,
	UINT64*				RequestId
	)
{
	return VmbusChannelRecvPacketRaw((VMBUS_CHANNEL*)Device->context,
										Buffer,
										BufferLen,
										BufferActualLen,
										RequestId);
}

INTERNAL int
IVmbusChannelEstablishGpadl(
	PDEVICE_OBJECT		Device,
	PVOID				Buffer,
	UINT32				BufferLen,
	UINT32*				GpadlHandle
	)
{
	return VmbusChannelEstablishGpadl((VMBUS_CHANNEL*)Device->context,
										Buffer,
										BufferLen,
										GpadlHandle);
}

INTERNAL int
IVmbusChannelTeardownGpadl(
   PDEVICE_OBJECT		Device,
   UINT32				GpadlHandle
	)
{
	return VmbusChannelTeardownGpadl((VMBUS_CHANNEL*)Device->context,
										GpadlHandle);

}

INTERNAL void
GetChannelInterface(
	VMBUS_CHANNEL_INTERFACE *ChannelInterface
	)
{
	ChannelInterface->Open						= IVmbusChannelOpen;
	ChannelInterface->Close						= IVmbusChannelClose;
	ChannelInterface->SendPacket				= IVmbusChannelSendPacket;
	ChannelInterface->SendPacketPageBuffer		= IVmbusChannelSendPacketPageBuffer;
	ChannelInterface->SendPacketMultiPageBuffer = IVmbusChannelSendPacketMultiPageBuffer;
	ChannelInterface->RecvPacket				= IVmbusChannelRecvPacket;
	ChannelInterface->RecvPacketRaw				= IVmbusChannelRecvPacketRaw;
	ChannelInterface->EstablishGpadl			= IVmbusChannelEstablishGpadl;
	ChannelInterface->TeardownGpadl				= IVmbusChannelTeardownGpadl;
	ChannelInterface->GetInfo					= GetChannelInfo;
}


INTERNAL void
GetChannelInfo(
	PDEVICE_OBJECT		Device,
	DEVICE_INFO			*DeviceInfo
			   )
{
	VMBUS_CHANNEL_DEBUG_INFO debugInfo;

	if (Device->context)
	{
		VmbusChannelGetDebugInfo((VMBUS_CHANNEL*)Device->context, &debugInfo);

		DeviceInfo->ChannelId = debugInfo.RelId;
		DeviceInfo->ChannelState = debugInfo.State;
		memcpy(&DeviceInfo->ChannelType, &debugInfo.InterfaceType, sizeof(GUID));
		memcpy(&DeviceInfo->ChannelInstance, &debugInfo.InterfaceInstance, sizeof(GUID));

		DeviceInfo->MonitorId = debugInfo.MonitorId;

		DeviceInfo->ServerMonitorPending = debugInfo.ServerMonitorPending;
		DeviceInfo->ServerMonitorLatency = debugInfo.ServerMonitorLatency;
		DeviceInfo->ServerMonitorConnectionId = debugInfo.ServerMonitorConnectionId;

		DeviceInfo->ClientMonitorPending = debugInfo.ClientMonitorPending;
		DeviceInfo->ClientMonitorLatency = debugInfo.ClientMonitorLatency;
		DeviceInfo->ClientMonitorConnectionId = debugInfo.ClientMonitorConnectionId;

		DeviceInfo->Inbound.InterruptMask = debugInfo.Inbound.CurrentInterruptMask;
		DeviceInfo->Inbound.ReadIndex = debugInfo.Inbound.CurrentReadIndex;
		DeviceInfo->Inbound.WriteIndex = debugInfo.Inbound.CurrentWriteIndex;
		DeviceInfo->Inbound.BytesAvailToRead = debugInfo.Inbound.BytesAvailToRead;
		DeviceInfo->Inbound.BytesAvailToWrite = debugInfo.Inbound.BytesAvailToWrite;

		DeviceInfo->Outbound.InterruptMask = debugInfo.Outbound.CurrentInterruptMask;
		DeviceInfo->Outbound.ReadIndex = debugInfo.Outbound.CurrentReadIndex;
		DeviceInfo->Outbound.WriteIndex = debugInfo.Outbound.CurrentWriteIndex;
		DeviceInfo->Outbound.BytesAvailToRead = debugInfo.Outbound.BytesAvailToRead;
		DeviceInfo->Outbound.BytesAvailToWrite = debugInfo.Outbound.BytesAvailToWrite;
	}
}
+41 −0
Original line number Diff line number Diff line
/*
 *
 * Copyright (c) 2009, Microsoft Corporation.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place - Suite 330, Boston, MA 02111-1307 USA.
 *
 * Authors:
 *   Haiyang Zhang <haiyangz@microsoft.com>
 *   Hank Janssen  <hjanssen@microsoft.com>
 *
 */


#ifndef _CHANNEL_INTERFACE_H_
#define _CHANNEL_INTERFACE_H_

#include "VmbusApi.h"

INTERNAL void
GetChannelInterface(
	VMBUS_CHANNEL_INTERFACE *ChannelInterface
	);

INTERNAL void
GetChannelInfo(
	PDEVICE_OBJECT		Device,
	DEVICE_INFO			*DeviceInfo
	);

#endif // _CHANNEL_INTERFACE_H_
+826 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading