2003-04-22 21:02:15 +02:00
|
|
|
#ifndef STDLIB_H
|
|
|
|
#define STDLIB_H
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
2007-10-27 22:05:21 +02:00
|
|
|
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
|
|
|
|
|
2012-03-30 22:00:46 +02:00
|
|
|
#define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1UL)
|
2008-12-23 18:34:15 +01:00
|
|
|
#define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))
|
2013-03-28 22:17:11 +01:00
|
|
|
#define ALIGN_UP(x,a) ALIGN((x),(a))
|
|
|
|
#define ALIGN_DOWN(x,a) ((x) & ~((typeof(x))(a)-1UL))
|
2015-02-05 22:27:59 +01:00
|
|
|
#define IS_ALIGNED(x,a) (((x) & ((typeof(x))(a)-1UL)) == 0)
|
2008-12-23 18:34:15 +01:00
|
|
|
|
2008-03-19 21:24:33 +01:00
|
|
|
#define MIN(a,b) ((a) < (b) ? (a) : (b))
|
|
|
|
#define MAX(a,b) ((a) > (b) ? (a) : (b))
|
2014-07-07 12:33:09 +02:00
|
|
|
#define ABS(a) (((a) < 0) ? (-(a)) : (a))
|
|
|
|
#define CEIL_DIV(a, b) (((a) + (b) - 1) / (b))
|
|
|
|
#define IS_POWER_OF_2(x) (((x) & ((x) - 1)) == 0)
|
2008-03-19 21:24:33 +01:00
|
|
|
|
2014-06-30 08:40:19 +02:00
|
|
|
#define min(a,b) MIN((a),(b))
|
|
|
|
#define max(a,b) MAX((a),(b))
|
|
|
|
|
2010-03-28 23:26:54 +02:00
|
|
|
#if !defined(__PRE_RAM__)
|
2012-04-11 19:30:15 +02:00
|
|
|
void *memalign(size_t boundary, size_t size);
|
2009-09-25 23:59:57 +02:00
|
|
|
void *malloc(size_t size);
|
2012-12-18 23:27:50 +01:00
|
|
|
/* We never free memory */
|
|
|
|
static inline void free(void *ptr) {}
|
2007-11-07 20:02:35 +01:00
|
|
|
#endif
|
2003-04-22 21:02:15 +02:00
|
|
|
|
tegra124: A couple clock fixes.
This fixes two problems with the clock configuration on tegra124. First, the
macro which set up the i2c clocks tried to account for the fact that the i2c
divisor's lsb represents 1.0 where it normally represents 0.5 by multiplying
the target frequency by 2. That doesn't work, unfortunately, because the
divisor is actually n + 1, and what n + 1 means depends on where the one's
place is in the divisor.
Also, when calculating the divisor, the standard C division operator uses
truncation to deal any remainder which tends to make the divisor smaller. That
has the effect of making the output frequency higher than what was requested.
Since it's usually safer to undershoot a frequency than overshoot it, this
change makes those divisions round up instead.
Finally, the hand tuned temporary UART clock configuration was adjusted so
that it still ends up with the same divisor. Without that, very early output
from the bootblock is garbled, specifically the coreboot welcome banner,
build timestamp, etc.
BUG=chrome-os-partner:27220
TEST=Built and booted on nyan. Used a logic analyzer to verify that the TPM
i2c bus ran at 400KHz instead of 660KHz, and that the divisor was the expected
value. Measured boot time with and without EFS and verified that there was no
change. Spot checked the output for errors and verified that none of the
bootblock output was garbled.
BRANCH=None
Had to add the stdlib.h from 89ed6c that hadn't been merged correctly.
Original-Change-Id: I7e948c361ed4bf58c608627d32f2e3424faea1fb
Original-Signed-off-by: Gabe Black <gabeblack@google.com>
Original-Reviewed-on: https://chromium-review.googlesource.com/193362
Original-Reviewed-by: Julius Werner <jwerner@chromium.org>
Original-Commit-Queue: Gabe Black <gabeblack@chromium.org>
Original-Tested-by: Gabe Black <gabeblack@chromium.org>
(cherry picked from commit 164f7010a47d3bbdbc8bb572106140ae186f3807)
Signed-off-by: Marc Jones <marc.jones@se-eng.com>
Change-Id: I317b66eda929c0e5a5832adca267b8b54c6aae34
Reviewed-on: http://review.coreboot.org/7736
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
2014-04-05 12:54:30 +02:00
|
|
|
#ifndef __ROMCC__
|
|
|
|
static inline unsigned long div_round_up(unsigned int n, unsigned int d)
|
|
|
|
{
|
|
|
|
return (n + d - 1) / d;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2003-04-22 21:02:15 +02:00
|
|
|
#endif /* STDLIB_H */
|