2 * This file is part of the coreboot project.
4 * Copyright 2014 Google Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #ifndef __TEGRA_MISC_TYPES_H__
17 #define __TEGRA_MISC_TYPES_H__
26 #define IS_ERR_PTR(ptr) \
27 (ptr == (void *)-EPTR)
43 * container_of - cast a member of a structure out to the containing structure
44 * @ptr: the pointer to the member.
45 * @type: the type of the container struct this is embedded in.
46 * @member: the name of the member within the struct.
49 #define container_of(ptr, type, member) ({ \
50 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
51 (type *)( (char *)__mptr - offsetof(type,member) );})
54 #define DIV_ROUND_UP(x, y) (((x) + (y) - 1) / (y))
57 * Divide positive or negative dividend by positive divisor and round
58 * to closest integer. Result is undefined for negative divisors and
59 * for negative dividends if the divisor variable type is unsigned.
61 #define DIV_ROUND_CLOSEST(x, divisor)( \
64 typeof(divisor) __d = divisor; \
65 (((typeof(x))-1) > 0 || \
66 ((typeof(divisor))-1) > 0 || (__x) > 0) ? \
67 (((__x) + ((__d) / 2)) / (__d)) : \
68 (((__x) - ((__d) / 2)) / (__d)); \
72 #endif /* __TEGRA_MISC_TYPES_H__ */