]> Pileus Git - ~andy/linux/blob - drivers/staging/hv/RingBuffer.h
a190b3a6d30194063d5f0402ff0a20fa34d190f6
[~andy/linux] / drivers / staging / hv / RingBuffer.h
1 /*
2  *
3  * Copyright (c) 2009, Microsoft Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms and conditions of the GNU General Public License,
7  * version 2, as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
16  * Place - Suite 330, Boston, MA 02111-1307 USA.
17  *
18  * Authors:
19  *   Haiyang Zhang <haiyangz@microsoft.com>
20  *   Hank Janssen  <hjanssen@microsoft.com>
21  *
22  */
23
24
25 #ifndef _RING_BUFFER_H_
26 #define _RING_BUFFER_H_
27
28 #include "include/osd.h"
29
30 typedef struct _SG_BUFFER_LIST {
31         void *  Data;
32         UINT32  Length;
33 } SG_BUFFER_LIST;
34
35 typedef struct _RING_BUFFER {
36     volatile UINT32     WriteIndex;     // Offset in bytes from the start of ring data below
37     volatile UINT32     ReadIndex;      // Offset in bytes from the start of ring data below
38
39         volatile UINT32 InterruptMask;
40         u8      Reserved[4084];                 // Pad it to PAGE_SIZE so that data starts on page boundary
41         // NOTE: The InterruptMask field is used only for channels but since our vmbus connection
42         // also uses this data structure and its data starts here, we commented out this field.
43         // volatile UINT32 InterruptMask;
44         // Ring data starts here + RingDataStartOffset !!! DO NOT place any fields below this !!!
45     u8          Buffer[0];
46 } STRUCT_PACKED RING_BUFFER;
47
48 typedef struct _RING_BUFFER_INFO {
49     RING_BUFFER*        RingBuffer;
50     UINT32                      RingSize;                       // Include the shared header
51         HANDLE                  RingLock;
52
53     UINT32                      RingDataSize;           // < ringSize
54         UINT32                  RingDataStartOffset;
55
56 } RING_BUFFER_INFO;
57
58
59 typedef struct _RING_BUFFER_DEBUG_INFO {
60         UINT32          CurrentInterruptMask;
61         UINT32          CurrentReadIndex;
62         UINT32          CurrentWriteIndex;
63         UINT32          BytesAvailToRead;
64         UINT32          BytesAvailToWrite;
65 }RING_BUFFER_DEBUG_INFO;
66
67
68 //
69 // Interface
70 //
71
72 static int
73 RingBufferInit(
74         RING_BUFFER_INFO        *RingInfo,
75         void *                          Buffer,
76         UINT32                          BufferLen
77         );
78
79 static void
80 RingBufferCleanup(
81         RING_BUFFER_INFO        *RingInfo
82         );
83
84 static int
85 RingBufferWrite(
86         RING_BUFFER_INFO        *RingInfo,
87         SG_BUFFER_LIST          SgBuffers[],
88         UINT32                          SgBufferCount
89         );
90
91 static int
92 RingBufferPeek(
93         RING_BUFFER_INFO        *RingInfo,
94         void *                          Buffer,
95         UINT32                          BufferLen
96         );
97
98 static int
99 RingBufferRead(
100         RING_BUFFER_INFO        *RingInfo,
101         void *                          Buffer,
102         UINT32                          BufferLen,
103         UINT32                          Offset
104         );
105
106 static UINT32
107 GetRingBufferInterruptMask(
108         RING_BUFFER_INFO *RingInfo
109         );
110
111 static void
112 DumpRingInfo(
113         RING_BUFFER_INFO* RingInfo,
114         char *Prefix
115         );
116
117 static void
118 RingBufferGetDebugInfo(
119         RING_BUFFER_INFO                *RingInfo,
120         RING_BUFFER_DEBUG_INFO  *DebugInfo
121         );
122
123 #endif // _RING_BUFFER_H_