2015-06-01 15:37:47 +08:00
|
|
|
#ifndef __TOOLS_LINUX_KERNEL_H
|
|
|
|
#define __TOOLS_LINUX_KERNEL_H
|
2009-07-01 23:28:37 +08:00
|
|
|
|
2009-10-17 23:12:33 +08:00
|
|
|
#include <stdarg.h>
|
2016-07-08 02:42:33 +08:00
|
|
|
#include <stddef.h>
|
2009-10-17 23:12:33 +08:00
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
|
|
|
|
|
2012-09-11 06:15:01 +08:00
|
|
|
#define PERF_ALIGN(x, a) __PERF_ALIGN_MASK(x, (typeof(x))(a)-1)
|
|
|
|
#define __PERF_ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
|
2009-10-17 23:12:33 +08:00
|
|
|
|
2009-07-01 23:28:37 +08:00
|
|
|
#ifndef offsetof
|
|
|
|
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef container_of
|
|
|
|
/**
|
|
|
|
* container_of - cast a member of a structure out to the containing structure
|
|
|
|
* @ptr: the pointer to the member.
|
|
|
|
* @type: the type of the container struct this is embedded in.
|
|
|
|
* @member: the name of the member within the struct.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#define container_of(ptr, type, member) ({ \
|
|
|
|
const typeof(((type *)0)->member) * __mptr = (ptr); \
|
|
|
|
(type *)((char *)__mptr - offsetof(type, member)); })
|
|
|
|
#endif
|
|
|
|
|
2010-05-18 02:39:16 +08:00
|
|
|
#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
|
|
|
|
|
2009-07-11 09:47:28 +08:00
|
|
|
#ifndef max
|
|
|
|
#define max(x, y) ({ \
|
|
|
|
typeof(x) _max1 = (x); \
|
|
|
|
typeof(y) _max2 = (y); \
|
|
|
|
(void) (&_max1 == &_max2); \
|
|
|
|
_max1 > _max2 ? _max1 : _max2; })
|
|
|
|
#endif
|
|
|
|
|
2009-10-17 23:12:33 +08:00
|
|
|
#ifndef min
|
|
|
|
#define min(x, y) ({ \
|
|
|
|
typeof(x) _min1 = (x); \
|
|
|
|
typeof(y) _min2 = (y); \
|
|
|
|
(void) (&_min1 == &_min2); \
|
|
|
|
_min1 < _min2 ? _min1 : _min2; })
|
|
|
|
#endif
|
|
|
|
|
2012-09-11 06:14:59 +08:00
|
|
|
#ifndef roundup
|
|
|
|
#define roundup(x, y) ( \
|
|
|
|
{ \
|
|
|
|
const typeof(y) __y = y; \
|
|
|
|
(((x) + (__y - 1)) / __y) * __y; \
|
|
|
|
} \
|
|
|
|
)
|
|
|
|
#endif
|
|
|
|
|
2009-10-17 23:12:33 +08:00
|
|
|
#ifndef BUG_ON
|
2012-09-08 13:35:51 +08:00
|
|
|
#ifdef NDEBUG
|
|
|
|
#define BUG_ON(cond) do { if (cond) {} } while (0)
|
|
|
|
#else
|
2009-10-17 23:12:33 +08:00
|
|
|
#define BUG_ON(cond) assert(!(cond))
|
|
|
|
#endif
|
2012-09-08 13:35:51 +08:00
|
|
|
#endif
|
2009-10-17 23:12:33 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Both need more care to handle endianness
|
|
|
|
* (Don't use bitmap_copy_le() for now)
|
|
|
|
*/
|
|
|
|
#define cpu_to_le64(x) (x)
|
|
|
|
#define cpu_to_le32(x) (x)
|
|
|
|
|
2016-07-08 02:42:33 +08:00
|
|
|
int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
|
|
|
|
int scnprintf(char * buf, size_t size, const char * fmt, ...);
|
2009-10-17 23:12:33 +08:00
|
|
|
|
2012-06-19 23:48:11 +08:00
|
|
|
/*
|
|
|
|
* This looks more complex than it should be. But we need to
|
|
|
|
* get the type for the ~ right in round_down (it needs to be
|
|
|
|
* as wide as the result!), and we want to evaluate the macro
|
|
|
|
* arguments just once each.
|
|
|
|
*/
|
|
|
|
#define __round_mask(x, y) ((__typeof__(x))((y)-1))
|
|
|
|
#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
|
|
|
|
#define round_down(x, y) ((x) & ~__round_mask(x, y))
|
|
|
|
|
2009-07-01 23:28:37 +08:00
|
|
|
#endif
|