1*e358b4fbSSasha 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 27*e358b4fbSSasha Levin #define min(x, y) ({ \ 28*e358b4fbSSasha Levin typeof(x) _min1 = (x); \ 29*e358b4fbSSasha Levin typeof(y) _min2 = (y); \ 30*e358b4fbSSasha Levin (void) (&_min1 == &_min2); \ 31*e358b4fbSSasha Levin _min1 < _min2 ? _min1 : _min2; }) 32*e358b4fbSSasha Levin 33*e358b4fbSSasha Levin #define max(x, y) ({ \ 34*e358b4fbSSasha Levin typeof(x) _max1 = (x); \ 35*e358b4fbSSasha Levin typeof(y) _max2 = (y); \ 36*e358b4fbSSasha Levin (void) (&_max1 == &_max2); \ 37*e358b4fbSSasha Levin _max1 > _max2 ? _max1 : _max2; }) 38*e358b4fbSSasha Levin 39c1b3d8d8SSasha Levin #endif 40