blob: 22dcf4c1d1546b8f34d1b6ace7df719f47538d97 [file] [log] [blame]
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -07001/*
2 * Copyright (c) 2008 Travis Geiselbrecht
3 *
Channagoud Kadabieae00762015-10-23 16:30:07 -07004 * Copyright (c) 2013, 2014-2015 The Linux Foundation. All rights reserved.
Channagoud Kadabi7ee286a2013-04-19 17:16:37 -07005 *
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);
Unnati Gandhi7c536732014-07-17 14:37:49 +053042long int strtol(const char *nptr, char **endptr, int base);
43char *getenv(const char *atypeofinformation);
44void qsort(void *buf, size_t num, size_t size, int (*compare) (const void *, const void *));
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070045
46#define MIN(a, b) (((a) < (b)) ? (a) : (b))
47#define MAX(a, b) (((a) > (b)) ? (a) : (b))
48
49#define ROUNDUP(a, b) (((a) + ((b)-1)) & ~((b)-1))
50#define ROUNDDOWN(a, b) ((a) & ~((b)-1))
51
52/* allocate a buffer on the stack aligned and padded to the cpu's cache line size */
53#define STACKBUF_DMA_ALIGN(var, size) \
Channagoud Kadabieae00762015-10-23 16:30:07 -070054 uint8_t __##var[(size) + CACHE_LINE] __attribute__((aligned(CACHE_LINE))); uint8_t *var = (uint8_t *)(ROUNDUP((addr_t)__##var, CACHE_LINE))
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070055
Channagoud Kadabi7ee286a2013-04-19 17:16:37 -070056/* Macro to allocate buffer in both local & global space, the STACKBUF_DMA_ALIGN cannot
57 * be used for global space.
58 * If we use STACKBUF_DMA_ALIGN 'C' compiler throws the error "Initializer element
59 * is not constant", since global variable need to be initialized with a constant value.
60 */
61#define BUF_DMA_ALIGN(var, size) \
62 static uint8_t var[ROUNDUP(size, CACHE_LINE)] __attribute__((aligned(CACHE_LINE)));
63
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070064#endif