1e358b4fbSSasha Levin 2c1b3d8d8SSasha Levin #ifndef KVM__LINUX_KERNEL_H_ 3c1b3d8d8SSasha Levin #define KVM__LINUX_KERNEL_H_ 4c1b3d8d8SSasha Levin 5c1b3d8d8SSasha Levin #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) 6c1b3d8d8SSasha Levin 7c1b3d8d8SSasha Levin #define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1) 8c1b3d8d8SSasha Levin #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask)) 9c1b3d8d8SSasha Levin 10c1b3d8d8SSasha Levin #ifndef offsetof 11c1b3d8d8SSasha Levin #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) 12c1b3d8d8SSasha Levin #endif 13c1b3d8d8SSasha Levin 14c1b3d8d8SSasha Levin #ifndef container_of 15c1b3d8d8SSasha Levin /** 16c1b3d8d8SSasha Levin * container_of - cast a member of a structure out to the containing structure 17c1b3d8d8SSasha Levin * @ptr: the pointer to the member. 18c1b3d8d8SSasha Levin * @type: the type of the container struct this is embedded in. 19c1b3d8d8SSasha Levin * @member: the name of the member within the struct. 20c1b3d8d8SSasha Levin * 21c1b3d8d8SSasha Levin */ 22c1b3d8d8SSasha Levin #define container_of(ptr, type, member) ({ \ 23c1b3d8d8SSasha Levin const typeof(((type *)0)->member) * __mptr = (ptr); \ 24c1b3d8d8SSasha Levin (type *)((char *)__mptr - offsetof(type, member)); }) 25c1b3d8d8SSasha Levin #endif 26c1b3d8d8SSasha Levin 27e358b4fbSSasha Levin #define min(x, y) ({ \ 28e358b4fbSSasha Levin typeof(x) _min1 = (x); \ 29e358b4fbSSasha Levin typeof(y) _min2 = (y); \ 30e358b4fbSSasha Levin (void) (&_min1 == &_min2); \ 31e358b4fbSSasha Levin _min1 < _min2 ? _min1 : _min2; }) 32e358b4fbSSasha Levin 33e358b4fbSSasha Levin #define max(x, y) ({ \ 34e358b4fbSSasha Levin typeof(x) _max1 = (x); \ 35e358b4fbSSasha Levin typeof(y) _max2 = (y); \ 36e358b4fbSSasha Levin (void) (&_max1 == &_max2); \ 37e358b4fbSSasha Levin _max1 > _max2 ? _max1 : _max2; }) 38e358b4fbSSasha Levin 39*86824900SIngo Molnar #define true 1 40*86824900SIngo Molnar 41c1b3d8d8SSasha Levin #endif 42