Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2008 Travis Geiselbrecht |
| 3 | * |
Channagoud Kadabi | eae0076 | 2015-10-23 16:30:07 -0700 | [diff] [blame] | 4 | * Copyright (c) 2013, 2014-2015 The Linux Foundation. All rights reserved. |
Channagoud Kadabi | 7ee286a | 2013-04-19 17:16:37 -0700 | [diff] [blame] | 5 | * |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 6 | * 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 Dinamani | 39112ac | 2012-12-20 11:32:05 -0800 | [diff] [blame] | 35 | unsigned gcd(unsigned m, unsigned n); |
| 36 | unsigned lcm(unsigned m, unsigned n); |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 37 | int atoi(const char *num); |
| 38 | unsigned int atoui(const char *num); |
| 39 | long atol(const char *num); |
| 40 | unsigned long atoul(const char *num); |
Deepa Dinamani | eb9eefe | 2012-09-24 11:35:01 -0700 | [diff] [blame] | 41 | int itoa(int num, unsigned char* str, int len, int base); |
Unnati Gandhi | 7c53673 | 2014-07-17 14:37:49 +0530 | [diff] [blame] | 42 | long int strtol(const char *nptr, char **endptr, int base); |
| 43 | char *getenv(const char *atypeofinformation); |
| 44 | void qsort(void *buf, size_t num, size_t size, int (*compare) (const void *, const void *)); |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 45 | |
| 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 Kadabi | eae0076 | 2015-10-23 16:30:07 -0700 | [diff] [blame] | 54 | uint8_t __##var[(size) + CACHE_LINE] __attribute__((aligned(CACHE_LINE))); uint8_t *var = (uint8_t *)(ROUNDUP((addr_t)__##var, CACHE_LINE)) |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 55 | |
Channagoud Kadabi | 7ee286a | 2013-04-19 17:16:37 -0700 | [diff] [blame] | 56 | /* 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 Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 64 | #endif |