1e358b4fbSSasha Levin 2c1b3d8d8SSasha Levin #ifndef KVM__LINUX_KERNEL_H_ 3c1b3d8d8SSasha Levin #define KVM__LINUX_KERNEL_H_ 4c1b3d8d8SSasha Levin 5*0febaae0SAlexandru Elisei #include "asm/kernel.h" 6*0febaae0SAlexandru Elisei 7*0febaae0SAlexandru Elisei #define __round_mask(x, y) ((__typeof__(x))((y)-1)) 8*0febaae0SAlexandru Elisei #define round_down(x, y) ((x) & ~__round_mask(x, y)) 9*0febaae0SAlexandru Elisei 10c1b3d8d8SSasha Levin #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) 11c1b3d8d8SSasha Levin 12c1b3d8d8SSasha Levin #define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1) 13c1b3d8d8SSasha Levin #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask)) 14*0febaae0SAlexandru Elisei #define IS_ALIGNED(x, a) (((x) & ((typeof(x))(a) - 1)) == 0) 15c1b3d8d8SSasha Levin 16c1b3d8d8SSasha Levin #ifndef offsetof 17c1b3d8d8SSasha Levin #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) 18c1b3d8d8SSasha Levin #endif 19c1b3d8d8SSasha Levin 20c1b3d8d8SSasha Levin #ifndef container_of 21c1b3d8d8SSasha Levin /** 22c1b3d8d8SSasha Levin * container_of - cast a member of a structure out to the containing structure 23c1b3d8d8SSasha Levin * @ptr: the pointer to the member. 24c1b3d8d8SSasha Levin * @type: the type of the container struct this is embedded in. 25c1b3d8d8SSasha Levin * @member: the name of the member within the struct. 26c1b3d8d8SSasha Levin * 27c1b3d8d8SSasha Levin */ 28c1b3d8d8SSasha Levin #define container_of(ptr, type, member) ({ \ 29c1b3d8d8SSasha Levin const typeof(((type *)0)->member) * __mptr = (ptr); \ 30c1b3d8d8SSasha Levin (type *)((char *)__mptr - offsetof(type, member)); }) 31c1b3d8d8SSasha Levin #endif 32c1b3d8d8SSasha Levin 33e358b4fbSSasha Levin #define min(x, y) ({ \ 34e358b4fbSSasha Levin typeof(x) _min1 = (x); \ 35e358b4fbSSasha Levin typeof(y) _min2 = (y); \ 36e358b4fbSSasha Levin (void) (&_min1 == &_min2); \ 37e358b4fbSSasha Levin _min1 < _min2 ? _min1 : _min2; }) 38e358b4fbSSasha Levin 39e358b4fbSSasha Levin #define max(x, y) ({ \ 40e358b4fbSSasha Levin typeof(x) _max1 = (x); \ 41e358b4fbSSasha Levin typeof(y) _max2 = (y); \ 42e358b4fbSSasha Levin (void) (&_max1 == &_max2); \ 43e358b4fbSSasha Levin _max1 > _max2 ? _max1 : _max2; }) 44e358b4fbSSasha Levin 45d8f36177SSasha Levin #define min_t(type, x, y) ({ \ 46d8f36177SSasha Levin type __min1 = (x); \ 47d8f36177SSasha Levin type __min2 = (y); \ 48d8f36177SSasha Levin __min1 < __min2 ? __min1: __min2; }) 49d8f36177SSasha Levin 50d8f36177SSasha Levin #define max_t(type, x, y) ({ \ 51d8f36177SSasha Levin type __max1 = (x); \ 52d8f36177SSasha Levin type __max2 = (y); \ 53d8f36177SSasha Levin __max1 > __max2 ? __max1: __max2; }) 54d8f36177SSasha Levin 5586824900SIngo Molnar #define true 1 5686824900SIngo Molnar 57c1b3d8d8SSasha Levin #endif 58