Jimmy Zhang | e3a938d | 2014-09-15 16:50:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright 2014 Google Inc. |
| 5 | * |
| 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. |
| 9 | * |
| 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. |
Jimmy Zhang | e3a938d | 2014-09-15 16:50:36 -0700 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #ifndef __TEGRA_MISC_TYPES_H__ |
| 17 | #define __TEGRA_MISC_TYPES_H__ |
| 18 | |
| 19 | #define EFAULT 1 |
| 20 | #define EINVAL 2 |
| 21 | #define ETIMEDOUT 3 |
| 22 | #define ENOSPC 4 |
| 23 | #define ENOSYS 5 |
| 24 | #define EPTR 6 |
| 25 | |
| 26 | #define IS_ERR_PTR(ptr) \ |
| 27 | (ptr == (void *)-EPTR) |
| 28 | |
| 29 | #ifndef bool |
| 30 | #define bool int |
| 31 | #endif |
| 32 | |
| 33 | #ifndef false |
| 34 | #define false 0 |
| 35 | #endif |
| 36 | |
| 37 | #ifndef true |
| 38 | #define true 1 |
| 39 | #endif |
| 40 | |
| 41 | #ifndef container_of |
| 42 | /** |
| 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. |
| 47 | * |
| 48 | */ |
| 49 | #define container_of(ptr, type, member) ({ \ |
| 50 | const typeof( ((type *)0)->member ) *__mptr = (ptr); \ |
| 51 | (type *)( (char *)__mptr - offsetof(type,member) );}) |
| 52 | #endif |
| 53 | |
| 54 | #define DIV_ROUND_UP(x, y) (((x) + (y) - 1) / (y)) |
| 55 | |
| 56 | /* |
| 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. |
| 60 | */ |
| 61 | #define DIV_ROUND_CLOSEST(x, divisor)( \ |
| 62 | { \ |
| 63 | typeof(x) __x = x; \ |
| 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)); \ |
| 69 | } \ |
| 70 | ) |
| 71 | |
| 72 | #endif /* __TEGRA_MISC_TYPES_H__ */ |