[1] | 1 | /* |
---|
| 2 | * kmem.h - kernel unified memory allocator interface |
---|
| 3 | * |
---|
[635] | 4 | * Authors Alain Greiner (2016,2017,2018,2019) |
---|
[1] | 5 | * |
---|
| 6 | * Copyright (c) UPMC Sorbonne Universites |
---|
| 7 | * |
---|
| 8 | * This file is part of ALMOS-MKH. |
---|
| 9 | * |
---|
| 10 | * ALMOS-MKH is free software; you can redistribute it and/or modify it |
---|
| 11 | * under the terms of the GNU General Public License as published by |
---|
| 12 | * the Free Software Foundation; version 2.0 of the License. |
---|
| 13 | * |
---|
| 14 | * ALMOS-MKH is distributed in the hope that it will be useful, but |
---|
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 17 | * General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with ALMOS; if not, write to the Free Software Foundation, |
---|
| 21 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 22 | */ |
---|
| 23 | |
---|
| 24 | #ifndef _KMEM_H_ |
---|
| 25 | #define _KMEM_H_ |
---|
| 26 | |
---|
[457] | 27 | #include <hal_kernel_types.h> |
---|
[1] | 28 | #include <kcm.h> |
---|
| 29 | |
---|
| 30 | /************************************************************************************* |
---|
[635] | 31 | * This enum defines the three Kernel Memory Allocaror types: |
---|
[1] | 32 | ************************************************************************************/ |
---|
| 33 | |
---|
| 34 | enum |
---|
| 35 | { |
---|
[635] | 36 | KMEM_PPM = 0, /*! PPM allocator */ |
---|
| 37 | KMEM_KCM = 1, /*! KCM allocator */ |
---|
| 38 | KMEM_KHM = 2, /*! KHM allocator */ |
---|
[1] | 39 | }; |
---|
| 40 | |
---|
| 41 | /************************************************************************************* |
---|
[18] | 42 | * This defines the generic Allocation Flags that can be associated to |
---|
[1] | 43 | * a Kernel Memory Request. |
---|
| 44 | ************************************************************************************/ |
---|
| 45 | |
---|
| 46 | #define AF_NONE 0x0000 // no attributes |
---|
[18] | 47 | #define AF_KERNEL 0x0001 // for kernel use |
---|
[1] | 48 | #define AF_ZERO 0x0002 // must be reset to 0 |
---|
| 49 | |
---|
| 50 | /************************************************************************************* |
---|
[18] | 51 | * This structure defines a Kernel Memory Request. |
---|
[1] | 52 | ************************************************************************************/ |
---|
| 53 | |
---|
| 54 | typedef struct kmem_req_s |
---|
| 55 | { |
---|
[635] | 56 | uint32_t type; /*! KMEM_PPM / KMEM_KCM / KMEM_KHM */ |
---|
| 57 | uint32_t order; /*! PPM: ln2(pages) / KCM: ln2(bytes) / KHM: bytes */ |
---|
[1] | 58 | uint32_t flags; /*! request attributes */ |
---|
| 59 | void * ptr; /*! local pointer on allocated buffer (only used by free) */ |
---|
[18] | 60 | } |
---|
[1] | 61 | kmem_req_t; |
---|
| 62 | |
---|
| 63 | /************************************************************************************* |
---|
[635] | 64 | * These two functions allocate physical memory in a local or remote cluster |
---|
| 65 | * as specified by the kmem_req_t request descriptor, and return a local pointer |
---|
| 66 | * on the allocated buffer. It uses three specialised physical memory allocators: |
---|
| 67 | * - PPM (Physical Pages Manager) allocates N contiguous small physical pages. |
---|
| 68 | * N is a power of 2, and req.order = ln(N). Implement the buddy algorithm. |
---|
| 69 | * - KCM (Kernel Cache Manager) allocates aligned blocks of M bytes from a cache. |
---|
| 70 | * M is a power of 2, and req.order = ln( M ). One cache per block size. |
---|
| 71 | * - KHM (Kernel Heap Manager) allocates physical memory buffers of M bytes, |
---|
| 72 | * M can have any value, and req.order = M. |
---|
[1] | 73 | ************************************************************************************* |
---|
[635] | 74 | * @ cxy : target cluster identifier for a remote access. |
---|
| 75 | * @ req : local pointer on allocation request. |
---|
| 76 | * @ return local pointer on allocated buffer if success / return NULL if no memory. |
---|
[1] | 77 | ************************************************************************************/ |
---|
| 78 | void * kmem_alloc( kmem_req_t * req ); |
---|
| 79 | |
---|
[635] | 80 | void * kmem_remote_alloc( cxy_t cxy, |
---|
| 81 | kmem_req_t * req ); |
---|
| 82 | |
---|
[1] | 83 | /************************************************************************************* |
---|
[635] | 84 | * These two functions release previously allocated physical memory, as specified |
---|
| 85 | * by the <type> and <ptr> fields of the kmem_req_t request descriptor. |
---|
[1] | 86 | ************************************************************************************* |
---|
[635] | 87 | * @ cxy : target cluster identifier for a remote access. |
---|
[1] | 88 | * @ req : local pointer to request descriptor. |
---|
| 89 | ************************************************************************************/ |
---|
| 90 | void kmem_free ( kmem_req_t * req ); |
---|
| 91 | |
---|
[635] | 92 | void kmem_remote_free( cxy_t cxy, |
---|
| 93 | kmem_req_t * req ); |
---|
[1] | 94 | |
---|
[7] | 95 | |
---|
[1] | 96 | #endif /* _KMEM_H_ */ |
---|