blob: 5c5145a9145997a4b54121f3eeb3d792fec2e789 [file] [log] [blame]
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -07001/*
2 * Copyright (c) 2008 Travis Geiselbrecht
3 *
Channagoud Kadabi7ee286a2013-04-19 17:16:37 -07004 * Copyright (c) 2013, The Linux Foundation. All rights reserved.
5 *
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -07006 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files
8 * (the "Software"), to deal in the Software without restriction,
9 * including without limitation the rights to use, copy, modify, merge,
10 * publish, distribute, sublicense, and/or sell copies of the Software,
11 * and to permit persons to whom the Software is furnished to do so,
12 * subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25#ifndef __STDLIB_H
26#define __STDLIB_H
27
28#include <sys/types.h>
29#include <stddef.h>
30#include <malloc.h>
31#include <printf.h>
32#include <endian.h>
33#include <arch/defines.h>
34
Deepa Dinamani39112ac2012-12-20 11:32:05 -080035unsigned gcd(unsigned m, unsigned n);
36unsigned lcm(unsigned m, unsigned n);
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070037int atoi(const char *num);
38unsigned int atoui(const char *num);
39long atol(const char *num);
40unsigned long atoul(const char *num);
Deepa Dinamanieb9eefe2012-09-24 11:35:01 -070041int itoa(int num, unsigned char* str, int len, int base);
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070042
43#define MIN(a, b) (((a) < (b)) ? (a) : (b))
44#define MAX(a, b) (((a) > (b)) ? (a) : (b))
45
46#define ROUNDUP(a, b) (((a) + ((b)-1)) & ~((b)-1))
47#define ROUNDDOWN(a, b) ((a) & ~((b)-1))
48
49/* allocate a buffer on the stack aligned and padded to the cpu's cache line size */
50#define STACKBUF_DMA_ALIGN(var, size) \
51 uint8_t __##var[(size) + CACHE_LINE]; uint8_t *var = (uint8_t *)(ROUNDUP((addr_t)__##var, CACHE_LINE))
52
Channagoud Kadabi7ee286a2013-04-19 17:16:37 -070053/* Macro to allocate buffer in both local & global space, the STACKBUF_DMA_ALIGN cannot
54 * be used for global space.
55 * If we use STACKBUF_DMA_ALIGN 'C' compiler throws the error "Initializer element
56 * is not constant", since global variable need to be initialized with a constant value.
57 */
58#define BUF_DMA_ALIGN(var, size) \
59 static uint8_t var[ROUNDUP(size, CACHE_LINE)] __attribute__((aligned(CACHE_LINE)));
60
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070061#endif