Heiko Schocher | 4f7a9a3 | 2014-06-24 10:10:03 +0200 | [diff] [blame] | 1 | |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 2 | #include <malloc.h> |
Masahiro Yamada | 3c88440 | 2018-08-24 19:30:15 +0900 | [diff] [blame] | 3 | #include <memalign.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 4 | #include <asm/cache.h> |
Heiko Schocher | 4f7a9a3 | 2014-06-24 10:10:03 +0200 | [diff] [blame] | 5 | #include <linux/compat.h> |
| 6 | |
| 7 | struct p_current cur = { |
| 8 | .pid = 1, |
| 9 | }; |
| 10 | __maybe_unused struct p_current *current = &cur; |
| 11 | |
| 12 | unsigned long copy_from_user(void *dest, const void *src, |
| 13 | unsigned long count) |
| 14 | { |
| 15 | memcpy((void *)dest, (void *)src, count); |
| 16 | return 0; |
| 17 | } |
| 18 | |
| 19 | void *kmalloc(size_t size, int flags) |
| 20 | { |
Masahiro Yamada | 7b5ec7e | 2015-07-13 13:17:07 +0900 | [diff] [blame] | 21 | void *p; |
| 22 | |
Masahiro Yamada | 3c88440 | 2018-08-24 19:30:15 +0900 | [diff] [blame] | 23 | p = malloc_cache_aligned(size); |
Marek Szyprowski | fe77e43 | 2019-10-02 14:37:20 +0200 | [diff] [blame] | 24 | if (p && flags & __GFP_ZERO) |
Masahiro Yamada | 7b5ec7e | 2015-07-13 13:17:07 +0900 | [diff] [blame] | 25 | memset(p, 0, size); |
Heiko Schocher | 4f7a9a3 | 2014-06-24 10:10:03 +0200 | [diff] [blame] | 26 | |
Masahiro Yamada | 7b5ec7e | 2015-07-13 13:17:07 +0900 | [diff] [blame] | 27 | return p; |
Heiko Schocher | 4f7a9a3 | 2014-06-24 10:10:03 +0200 | [diff] [blame] | 28 | } |
| 29 | |
Heiko Schocher | 4f7a9a3 | 2014-06-24 10:10:03 +0200 | [diff] [blame] | 30 | struct kmem_cache *get_mem(int element_sz) |
| 31 | { |
| 32 | struct kmem_cache *ret; |
| 33 | |
| 34 | ret = memalign(ARCH_DMA_MINALIGN, sizeof(struct kmem_cache)); |
| 35 | ret->sz = element_sz; |
| 36 | |
| 37 | return ret; |
| 38 | } |
| 39 | |
| 40 | void *kmem_cache_alloc(struct kmem_cache *obj, int flag) |
| 41 | { |
Masahiro Yamada | 3c88440 | 2018-08-24 19:30:15 +0900 | [diff] [blame] | 42 | return malloc_cache_aligned(obj->sz); |
Heiko Schocher | 4f7a9a3 | 2014-06-24 10:10:03 +0200 | [diff] [blame] | 43 | } |
AKASHI Takahiro | 1d8d34d | 2019-11-13 09:44:47 +0900 | [diff] [blame] | 44 | |
| 45 | /** |
| 46 | * kmemdup - duplicate region of memory |
| 47 | * |
| 48 | * @src: memory region to duplicate |
| 49 | * @len: memory region length |
| 50 | * @gfp: GFP mask to use |
| 51 | * |
| 52 | * Return: newly allocated copy of @src or %NULL in case of error |
| 53 | */ |
| 54 | void *kmemdup(const void *src, size_t len, gfp_t gfp) |
| 55 | { |
| 56 | void *p; |
| 57 | |
| 58 | p = kmalloc(len, gfp); |
| 59 | if (p) |
| 60 | memcpy(p, src, len); |
| 61 | return p; |
| 62 | } |