Commit | Line | Data |
---|---|---|
3e7ee490 HJ |
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 | ||
09d50ff8 | 28 | #include "include/osd.h" |
3e7ee490 HJ |
29 | |
30 | typedef struct _SG_BUFFER_LIST { | |
8282c400 | 31 | void * Data; |
3e7ee490 HJ |
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; | |
5654e932 | 40 | u8 Reserved[4084]; // Pad it to PAGE_SIZE so that data starts on page boundary |
3e7ee490 HJ |
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 !!! | |
5654e932 | 45 | u8 Buffer[0]; |
3e7ee490 HJ |
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 | ||
2be1301b | 72 | static int |
3e7ee490 HJ |
73 | RingBufferInit( |
74 | RING_BUFFER_INFO *RingInfo, | |
8282c400 | 75 | void * Buffer, |
3e7ee490 HJ |
76 | UINT32 BufferLen |
77 | ); | |
78 | ||
2be1301b | 79 | static void |
3e7ee490 HJ |
80 | RingBufferCleanup( |
81 | RING_BUFFER_INFO *RingInfo | |
82 | ); | |
83 | ||
2be1301b | 84 | static int |
3e7ee490 HJ |
85 | RingBufferWrite( |
86 | RING_BUFFER_INFO *RingInfo, | |
87 | SG_BUFFER_LIST SgBuffers[], | |
88 | UINT32 SgBufferCount | |
89 | ); | |
90 | ||
2be1301b | 91 | static int |
3e7ee490 HJ |
92 | RingBufferPeek( |
93 | RING_BUFFER_INFO *RingInfo, | |
8282c400 | 94 | void * Buffer, |
3e7ee490 HJ |
95 | UINT32 BufferLen |
96 | ); | |
97 | ||
2be1301b | 98 | static int |
3e7ee490 HJ |
99 | RingBufferRead( |
100 | RING_BUFFER_INFO *RingInfo, | |
8282c400 | 101 | void * Buffer, |
3e7ee490 HJ |
102 | UINT32 BufferLen, |
103 | UINT32 Offset | |
104 | ); | |
105 | ||
2be1301b | 106 | static UINT32 |
3e7ee490 HJ |
107 | GetRingBufferInterruptMask( |
108 | RING_BUFFER_INFO *RingInfo | |
109 | ); | |
110 | ||
2be1301b | 111 | static void |
3e7ee490 HJ |
112 | DumpRingInfo( |
113 | RING_BUFFER_INFO* RingInfo, | |
114 | char *Prefix | |
115 | ); | |
116 | ||
2be1301b | 117 | static void |
3e7ee490 HJ |
118 | RingBufferGetDebugInfo( |
119 | RING_BUFFER_INFO *RingInfo, | |
120 | RING_BUFFER_DEBUG_INFO *DebugInfo | |
121 | ); | |
122 | ||
123 | #endif // _RING_BUFFER_H_ |