blob: 3bbf914246e0700fe1d8d7e32a7a946a9923bce4 [file] [log] [blame]
Stefan Reinauerda1ef022012-12-07 17:24:06 -08001#ifndef STDDEF_H
2#define STDDEF_H
Eric Biederman8ca8d762003-04-22 19:02:15 +00003
4typedef long ptrdiff_t;
Stefan Reinauer0e740d32012-05-14 13:21:08 -07005#ifndef __SIZE_TYPE__
6#define __SIZE_TYPE__ unsigned long
7#endif
8typedef __SIZE_TYPE__ size_t;
Stefan Reinauerf8b36502013-05-02 14:02:28 -07009/* There is a GCC macro for a size_t type, but not
10 * for a ssize_t type. Below construct tricks GCC
11 * into making __SIZE_TYPE__ signed.
12 */
13#define unsigned signed
14typedef __SIZE_TYPE__ ssize_t;
15#undef unsigned
Eric Biederman8ca8d762003-04-22 19:02:15 +000016
17typedef int wchar_t;
18typedef unsigned int wint_t;
19
Eric Biedermanb78c1972004-10-14 20:54:17 +000020#define NULL ((void *)0)
Eric Biederman8ca8d762003-04-22 19:02:15 +000021
Ronald G. Minnichaa3f4282013-03-15 20:17:26 -070022/* Standard units. */
23#define KiB (1<<10)
24#define MiB (1<<20)
25#define GiB (1<<30)
26/* Could we ever run into this one? I hope we get this much memory! */
27#define TiB (1<<40)
28
Aaron Durbin46826c32015-04-02 15:43:12 -050029#define KHz (1000)
30#define MHz (1000 * KHz)
31#define GHz (1000 * MHz)
32
Eric Biederman8ca8d762003-04-22 19:02:15 +000033#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
34
Julius Werner03784fa2013-12-09 17:46:22 -080035#define check_member(structure, member, offset) _Static_assert( \
36 offsetof(struct structure, member) == offset, \
37 "`struct " #structure "` offset for `" #member "` is not " #offset )
38
Stefan Reinauer4417deb2015-01-05 11:09:11 -080039/**
40 * container_of - cast a member of a structure out to the containing structure
41 * @param ptr: the pointer to the member.
42 * @param type: the type of the container struct this is embedded in.
43 * @param member: the name of the member within the struct.
44 *
45 */
46#define container_of(ptr, type, member) ({ \
47 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
48 (type *)( (char *)__mptr - offsetof(type,member) );})
49
Stefan Reinauer57879c92012-07-31 16:47:25 -070050#ifdef __PRE_RAM__
51#define ROMSTAGE_CONST const
52#else
53#define ROMSTAGE_CONST
54#endif
55
Julius Wernerdbe0df12014-06-06 16:10:56 -070056/* Work around non-writable data segment in execute-in-place romstage on x86. */
57#if defined(__PRE_RAM__) && CONFIG_ARCH_X86
58#define MAYBE_STATIC
59#else
60#define MAYBE_STATIC static
61#endif
62
Stefan Reinauerda1ef022012-12-07 17:24:06 -080063#endif /* STDDEF_H */