e75220931c595de3b9418929390653e394a0715b
[cascardo/ovs.git] / datapath-windows / ovsext / Util.h
1 /*
2  * Copyright (c) 2014 VMware, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef __UTIL_H_
18 #define __UTIL_H_ 1
19
20 #define OVS_MEMORY_TAG                  'TSVO'
21 #define OVS_FIX_SIZE_NBL_POOL_TAG       'FSVO'
22 #define OVS_VARIABLE_SIZE_NBL_POOL_TAG  'VSVO'
23 #define OVS_NBL_ONLY_POOL_TAG           'OSVO'
24 #define OVS_NET_BUFFER_POOL_TAG         'NSVO'
25 #define OVS_OTHER_POOL_TAG              'MSVO'
26
27 VOID *OvsAllocateMemory(size_t size);
28 VOID *OvsAllocateAlignedMemory(size_t size, UINT16 align);
29 VOID OvsFreeMemory(VOID *ptr);
30 VOID OvsFreeAlignedMemory(VOID *ptr);
31
32 #define LIST_FORALL(_headPtr, _itemPtr) \
33     for (_itemPtr = (_headPtr)->Flink;  \
34          _itemPtr != _headPtr;          \
35          _itemPtr = (_itemPtr)->Flink)
36
37 #define LIST_FORALL_SAFE(_headPtr, _itemPtr, _nextPtr)                \
38     for (_itemPtr = (_headPtr)->Flink, _nextPtr = (_itemPtr)->Flink; \
39          _itemPtr != _headPtr;                                       \
40          _itemPtr = _nextPtr, _nextPtr = (_itemPtr)->Flink)
41
42 #define LIST_FORALL_REVERSE(_headPtr, _itemPtr) \
43     for (_itemPtr = (_headPtr)->Blink;  \
44          _itemPtr != _headPtr;          \
45          _itemPtr = (_itemPtr)->Blink)
46
47 #define LIST_FORALL_REVERSE_SAFE(_headPtr, _itemPtr, _nextPtr)        \
48     for (_itemPtr = (_headPtr)->Blink, _nextPtr = (_itemPtr)->Blink; \
49          _itemPtr != _headPtr;                                       \
50          _itemPtr = _nextPtr, _nextPtr = (_itemPtr)->Blink)
51
52 VOID OvsAppendList(PLIST_ENTRY dst, PLIST_ENTRY src);
53
54
55 #define MIN(_a, _b) (_a) > (_b) ? (_b) : (_a)
56 #define ARRAY_SIZE(_x)  ((sizeof(_x))/sizeof (_x)[0])
57 #define OVS_SWITCH_PORT_ID_INVALID  (NDIS_SWITCH_PORT_ID)(-1)
58
59 #ifndef htons
60 #define htons(_x)    _byteswap_ushort((USHORT)(_x))
61 #define ntohs(_x)    _byteswap_ushort((USHORT)(_x))
62 #define htonl(_x)    _byteswap_ulong((ULONG)(_x))
63 #define ntohl(_x)    _byteswap_ulong((ULONG)(_x))
64 #endif
65
66 #define OVS_INIT_OBJECT_HEADER(_obj, _type, _revision, _size) \
67     {                                                         \
68         PNDIS_OBJECT_HEADER hdrp = _obj;                      \
69         hdrp->Type = _type;                                   \
70         hdrp->Revision = _revision;                           \
71         hdrp->Size = _size;                                   \
72     }
73
74
75 #define BIT16(_x)                       ((UINT16)0x1 << (_x))
76 #define BIT32(_x)                       ((UINT32)0x1 << (_x))
77
78 BOOLEAN OvsCompareString(PVOID string1, PVOID string2);
79
80 #endif /* __UTIL_H_ */