*/
-#include "include/logging.h"
-
+#include <linux/kernel.h>
+#include <linux/mm.h>
+#include <linux/vmalloc.h>
+#include "osd.h"
+#include "logging.h"
#include "VmbusPrivate.h"
-//
-// Globals
-//
+/* Globals */
-VMBUS_CONNECTION gVmbusConnection = {
+struct VMBUS_CONNECTION gVmbusConnection = {
.ConnectState = Disconnected,
- .NextGpadlHandle = 0xE1E10,
+ .NextGpadlHandle = ATOMIC_INIT(0xE1E10),
};
Sends a connect request on the partition service connection
--*/
-int
-VmbusConnect(
- )
+int VmbusConnect(void)
{
int ret=0;
- VMBUS_CHANNEL_MSGINFO *msgInfo=NULL;
- VMBUS_CHANNEL_INITIATE_CONTACT *msg;
+ struct vmbus_channel_msginfo *msgInfo = NULL;
+ struct vmbus_channel_initiate_contact *msg;
+ unsigned long flags;
DPRINT_ENTER(VMBUS);
- // Make sure we are not connecting or connected
+ /* Make sure we are not connecting or connected */
if (gVmbusConnection.ConnectState != Disconnected)
return -1;
- // Initialize the vmbus connection
+ /* Initialize the vmbus connection */
gVmbusConnection.ConnectState = Connecting;
- gVmbusConnection.WorkQueue = WorkQueueCreate("vmbusQ");
+ gVmbusConnection.WorkQueue = create_workqueue("hv_vmbus_con");
+ if (!gVmbusConnection.WorkQueue)
+ {
+ ret = -1;
+ goto Cleanup;
+ }
INITIALIZE_LIST_HEAD(&gVmbusConnection.ChannelMsgList);
- gVmbusConnection.ChannelMsgLock = SpinlockCreate();
+ spin_lock_init(&gVmbusConnection.channelmsg_lock);
INITIALIZE_LIST_HEAD(&gVmbusConnection.ChannelList);
- gVmbusConnection.ChannelLock = SpinlockCreate();
+ spin_lock_init(&gVmbusConnection.channel_lock);
- // Setup the vmbus event connection for channel interrupt abstraction stuff
- gVmbusConnection.InterruptPage = PageAlloc(1);
+ /*
+ * Setup the vmbus event connection for channel interrupt
+ * abstraction stuff
+ */
+ gVmbusConnection.InterruptPage = osd_PageAlloc(1);
if (gVmbusConnection.InterruptPage == NULL)
{
ret = -1;
}
gVmbusConnection.RecvInterruptPage = gVmbusConnection.InterruptPage;
- gVmbusConnection.SendInterruptPage = (void*)((ULONG_PTR)gVmbusConnection.InterruptPage + (PAGE_SIZE >> 1));
+ gVmbusConnection.SendInterruptPage = (void*)((unsigned long)gVmbusConnection.InterruptPage + (PAGE_SIZE >> 1));
- // Setup the monitor notification facility. The 1st page for parent->child and the 2nd page for child->parent
- gVmbusConnection.MonitorPages = PageAlloc(2);
+ /* Setup the monitor
+ * notification facility. The 1st page for parent->child and
+ * the 2nd page for child->parent
+ */
+ gVmbusConnection.MonitorPages = osd_PageAlloc(2);
if (gVmbusConnection.MonitorPages == NULL)
{
ret = -1;
goto Cleanup;
}
- msgInfo = (VMBUS_CHANNEL_MSGINFO*)MemAllocZeroed(sizeof(VMBUS_CHANNEL_MSGINFO) + sizeof(VMBUS_CHANNEL_INITIATE_CONTACT));
+ msgInfo = kzalloc(sizeof(*msgInfo) + sizeof(struct vmbus_channel_initiate_contact), GFP_KERNEL);
if (msgInfo == NULL)
{
ret = -1;
goto Cleanup;
}
- msgInfo->WaitEvent = WaitEventCreate();
- msg = (VMBUS_CHANNEL_INITIATE_CONTACT*)msgInfo->Msg;
+ msgInfo->WaitEvent = osd_WaitEventCreate();
+ msg = (struct vmbus_channel_initiate_contact *)msgInfo->Msg;
msg->Header.MessageType = ChannelMessageInitiateContact;
msg->VMBusVersionRequested = VMBUS_REVISION_NUMBER;
- msg->InterruptPage = GetPhysicalAddress(gVmbusConnection.InterruptPage);
- msg->MonitorPage1 = GetPhysicalAddress(gVmbusConnection.MonitorPages);
- msg->MonitorPage2 = GetPhysicalAddress((void *)((ULONG_PTR)gVmbusConnection.MonitorPages + PAGE_SIZE));
-
- // Add to list before we send the request since we may receive the response
- // before returning from this routine
- SpinlockAcquire(gVmbusConnection.ChannelMsgLock);
+ msg->InterruptPage = virt_to_phys(gVmbusConnection.InterruptPage);
+ msg->MonitorPage1 = virt_to_phys(gVmbusConnection.MonitorPages);
+ msg->MonitorPage2 = virt_to_phys((void *)((unsigned long)gVmbusConnection.MonitorPages + PAGE_SIZE));
+
+ /*
+ * Add to list before we send the request since we may
+ * receive the response before returning from this routine
+ */
+ spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
INSERT_TAIL_LIST(&gVmbusConnection.ChannelMsgList, &msgInfo->MsgListEntry);
- SpinlockRelease(gVmbusConnection.ChannelMsgLock);
+ spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
DPRINT_DBG(VMBUS, "Vmbus connection - interrupt pfn %llx, monitor1 pfn %llx,, monitor2 pfn %llx",
msg->InterruptPage, msg->MonitorPage1, msg->MonitorPage2);
DPRINT_DBG(VMBUS, "Sending channel initiate msg...");
- ret = VmbusPostMessage(msg, sizeof(VMBUS_CHANNEL_INITIATE_CONTACT));
+ ret = VmbusPostMessage(msg, sizeof(struct vmbus_channel_initiate_contact));
if (ret != 0)
{
REMOVE_ENTRY_LIST(&msgInfo->MsgListEntry);
goto Cleanup;
}
- // Wait for the connection response
- WaitEventWait(msgInfo->WaitEvent);
+ /* Wait for the connection response */
+ osd_WaitEventWait(msgInfo->WaitEvent);
REMOVE_ENTRY_LIST(&msgInfo->MsgListEntry);
- // Check if successful
+ /* Check if successful */
if (msgInfo->Response.VersionResponse.VersionSupported)
{
DPRINT_INFO(VMBUS, "Vmbus connected!!");
}
- WaitEventClose(msgInfo->WaitEvent);
- MemFree(msgInfo);
+ kfree(msgInfo->WaitEvent);
+ kfree(msgInfo);
DPRINT_EXIT(VMBUS);
return 0;
gVmbusConnection.ConnectState = Disconnected;
- WorkQueueClose(gVmbusConnection.WorkQueue);
- SpinlockClose(gVmbusConnection.ChannelLock);
- SpinlockClose(gVmbusConnection.ChannelMsgLock);
+ if (gVmbusConnection.WorkQueue)
+ destroy_workqueue(gVmbusConnection.WorkQueue);
if (gVmbusConnection.InterruptPage)
{
- PageFree(gVmbusConnection.InterruptPage, 1);
+ osd_PageFree(gVmbusConnection.InterruptPage, 1);
gVmbusConnection.InterruptPage = NULL;
}
if (gVmbusConnection.MonitorPages)
{
- PageFree(gVmbusConnection.MonitorPages, 2);
+ osd_PageFree(gVmbusConnection.MonitorPages, 2);
gVmbusConnection.MonitorPages = NULL;
}
if (msgInfo)
{
if (msgInfo->WaitEvent)
- WaitEventClose(msgInfo->WaitEvent);
+ kfree(msgInfo->WaitEvent);
- MemFree(msgInfo);
+ kfree(msgInfo);
}
DPRINT_EXIT(VMBUS);
Sends a disconnect request on the partition service connection
--*/
-int
-VmbusDisconnect(
- void
- )
+int VmbusDisconnect(void)
{
int ret=0;
- VMBUS_CHANNEL_UNLOAD *msg;
+ struct vmbus_channel_message_header *msg;
DPRINT_ENTER(VMBUS);
- // Make sure we are connected
+ /* Make sure we are connected */
if (gVmbusConnection.ConnectState != Connected)
return -1;
- msg = MemAllocZeroed(sizeof(VMBUS_CHANNEL_UNLOAD));
+ msg = kzalloc(sizeof(struct vmbus_channel_message_header), GFP_KERNEL);
msg->MessageType = ChannelMessageUnload;
- ret = VmbusPostMessage(msg, sizeof(VMBUS_CHANNEL_UNLOAD));
+ ret = VmbusPostMessage(msg, sizeof(struct vmbus_channel_message_header));
if (ret != 0)
{
goto Cleanup;
}
- PageFree(gVmbusConnection.InterruptPage, 1);
-
- // TODO: iterate thru the msg list and free up
+ osd_PageFree(gVmbusConnection.InterruptPage, 1);
- SpinlockClose(gVmbusConnection.ChannelMsgLock);
+ /* TODO: iterate thru the msg list and free up */
- WorkQueueClose(gVmbusConnection.WorkQueue);
+ destroy_workqueue(gVmbusConnection.WorkQueue);
gVmbusConnection.ConnectState = Disconnected;
Cleanup:
if (msg)
{
- MemFree(msg);
+ kfree(msg);
}
DPRINT_EXIT(VMBUS);
Get the channel object given its child relative id (ie channel id)
--*/
-VMBUS_CHANNEL*
-GetChannelFromRelId(
- u32 relId
- )
+struct vmbus_channel *GetChannelFromRelId(u32 relId)
{
- VMBUS_CHANNEL* channel;
- VMBUS_CHANNEL* foundChannel=NULL;
+ struct vmbus_channel *channel;
+ struct vmbus_channel *foundChannel = NULL;
LIST_ENTRY* anchor;
LIST_ENTRY* curr;
+ unsigned long flags;
- SpinlockAcquire(gVmbusConnection.ChannelLock);
+ spin_lock_irqsave(&gVmbusConnection.channel_lock, flags);
ITERATE_LIST_ENTRIES(anchor, curr, &gVmbusConnection.ChannelList)
{
- channel = CONTAINING_RECORD(curr, VMBUS_CHANNEL, ListEntry);
+ channel = CONTAINING_RECORD(curr, struct vmbus_channel, ListEntry);
if (channel->OfferMsg.ChildRelId == relId)
{
break;
}
}
- SpinlockRelease(gVmbusConnection.ChannelLock);
+ spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags);
return foundChannel;
}
void * context
)
{
- VMBUS_CHANNEL* channel;
- u32 relId = (u32)(ULONG_PTR)context;
+ struct vmbus_channel *channel;
+ u32 relId = (u32)(unsigned long)context;
ASSERT(relId > 0);
- // Find the channel based on this relid and invokes
- // the channel callback to process the event
+ /*
+ * Find the channel based on this relid and invokes the
+ * channel callback to process the event
+ */
channel = GetChannelFromRelId(relId);
if (channel)
{
VmbusChannelOnChannelEvent(channel);
- //WorkQueueQueueWorkItem(channel->dataWorkQueue, VmbusChannelOnChannelEvent, (void*)channel);
+ /* WorkQueueQueueWorkItem(channel->dataWorkQueue, VmbusChannelOnChannelEvent, (void*)channel); */
}
else
{
- DPRINT_ERR(VMBUS, "channel not found for relid - %d.", relId);
+ DPRINT_ERR(VMBUS, "channel not found for relid - %d.", relId);
}
}
Handler for events
--*/
-void
-VmbusOnEvents(
- void
- )
+void VmbusOnEvents(void)
{
int dword;
- //int maxdword = PAGE_SIZE >> 3; // receive size is 1/2 page and divide that by 4 bytes
+ /* int maxdword = PAGE_SIZE >> 3; // receive size is 1/2 page and divide that by 4 bytes */
int maxdword = MAX_NUM_CHANNELS_SUPPORTED >> 5;
int bit;
int relid;
u32* recvInterruptPage = gVmbusConnection.RecvInterruptPage;
- //VMBUS_CHANNEL_MESSAGE* receiveMsg;
+ /* VMBUS_CHANNEL_MESSAGE* receiveMsg; */
DPRINT_ENTER(VMBUS);
- // Check events
+ /* Check events */
if (recvInterruptPage)
{
for (dword = 0; dword < maxdword; dword++)
{
for (bit = 0; bit < 32; bit++)
{
- if (BitTestAndClear(&recvInterruptPage[dword], bit))
+ if (test_and_clear_bit(bit, (unsigned long *) &recvInterruptPage[dword]))
{
relid = (dword << 5) + bit;
DPRINT_DBG(VMBUS, "event detected for relid - %d", relid);
- if (relid == 0) // special case - vmbus channel protocol msg
+ if (relid == 0) /* special case - vmbus channel protocol msg */
{
DPRINT_DBG(VMBUS, "invalid relid - %d", relid);
continue; }
else
{
- //QueueWorkItem(VmbusProcessEvent, (void*)relid);
- //ret = WorkQueueQueueWorkItem(gVmbusConnection.workQueue, VmbusProcessChannelEvent, (void*)relid);
- VmbusProcessChannelEvent((void*)(ULONG_PTR)relid);
+ /* QueueWorkItem(VmbusProcessEvent, (void*)relid); */
+ /* ret = WorkQueueQueueWorkItem(gVmbusConnection.workQueue, VmbusProcessChannelEvent, (void*)relid); */
+ VmbusProcessChannelEvent((void*)(unsigned long)relid);
}
}
}
Send a msg on the vmbus's message connection
--*/
-int
-VmbusPostMessage(
- void * buffer,
- SIZE_T bufferLen
- )
+int VmbusPostMessage(void *buffer, size_t bufferLen)
{
int ret=0;
- HV_CONNECTION_ID connId;
+ union hv_connection_id connId;
connId.Asu32 =0;
Send an event notification to the parent
--*/
-int
-VmbusSetEvent(u32 childRelId)
+int VmbusSetEvent(u32 childRelId)
{
int ret=0;
DPRINT_ENTER(VMBUS);
- // Each u32 represents 32 channels
- BitSet((u32*)gVmbusConnection.SendInterruptPage + (childRelId >> 5), childRelId & 31);
+ /* Each u32 represents 32 channels */
+ set_bit(childRelId & 31,
+ (unsigned long *) gVmbusConnection.SendInterruptPage + (childRelId >> 5));
+
ret = HvSignalEvent();
DPRINT_EXIT(VMBUS);
return ret;
}
-// EOF
+/* EOF */