1 | /* |
---|
2 | * kmem.h - unified kernel memory allocator definition |
---|
3 | * |
---|
4 | * Authors Alain Greiner (2016,2017,2018,2019,2020) |
---|
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 | |
---|
27 | #include <hal_kernel_types.h> |
---|
28 | #include <kcm.h> |
---|
29 | |
---|
30 | /************************************************************************************* |
---|
31 | * This defines the generic Allocation Flags that can be associated to |
---|
32 | * a Kernel Memory Request. |
---|
33 | ************************************************************************************/ |
---|
34 | |
---|
35 | #define AF_NONE 0x0000 // no attributes |
---|
36 | #define AF_KERNEL 0x0001 // for kernel use ??? |
---|
37 | #define AF_ZERO 0x0002 // data buffer must be reset to 0 |
---|
38 | |
---|
39 | /************************************************************************************* |
---|
40 | * These two functions allocate physical memory in a local or remote cluster |
---|
41 | * as specified by the <cxy>, <order> and <flags> arguments, and return a local |
---|
42 | * pointer on the allocated buffer. The buffer size (in bytes) is a power of 2, |
---|
43 | * equal to (1 << order) bytes. It can be initialized to zero if requested. |
---|
44 | * Depending on the <order> value, it uses two specialised allocators: |
---|
45 | * - When order is larger or equal to CONFIG_PPM_PAGE_ORDER, the PPM (Physical Pages |
---|
46 | * Manager) allocates 2**(order - PPM_PAGE_ORDER) contiguous small physical pages. |
---|
47 | * This allocator implements the buddy algorithm. |
---|
48 | * - When order is smaller than CONFIG_PPM_PAGE_ORDER, the KCM (Kernel Cache Manager) |
---|
49 | * allocates an aligned block of 2**order bytes from specialised KCM[ORDER] caches |
---|
50 | * (one KCM cache per block size). |
---|
51 | ************************************************************************************* |
---|
52 | * @ cxy : [in] target cluster identifier for a remote access). |
---|
53 | * @ order : [in] ln( block size in bytes). |
---|
54 | * @ flags : [in] allocation flags defined above. |
---|
55 | * @ return local pointer on allocated buffer if success / return NULL if no memory. |
---|
56 | ************************************************************************************/ |
---|
57 | void * kmem_alloc( uint32_t order, |
---|
58 | uint32_t flags ); |
---|
59 | |
---|
60 | void * kmem_remote_alloc( cxy_t cxy, |
---|
61 | uint32_t order, |
---|
62 | uint32_t flags ); |
---|
63 | |
---|
64 | /************************************************************************************* |
---|
65 | * These two functions release a previously allocated physical memory block, |
---|
66 | * as specified by the <cxy>, <order> and <ptr> arguments. |
---|
67 | * - When order is larger or equal to CONFIG_PPM_PAGE_ORDER, the PPM (Physical Pages |
---|
68 | * Manager) releases 2**(order - PPM_PAGE_ORDER) contiguous small physical pages. |
---|
69 | * This allocator implements the buddy algorithm. |
---|
70 | * - When order is smaller than CONFIG_PPM_PAGE_ORDER, the KCM (Kernel Cache Manager) |
---|
71 | * release release the block of 2**order bytes to the specialised KCM[order] cache. |
---|
72 | ************************************************************************************* |
---|
73 | * @ cxy : [in] target cluster identifier for a remote access. |
---|
74 | * @ ptr : [in] local pointer to released block. |
---|
75 | * @ order : [in] ln( block size in bytes ). |
---|
76 | ************************************************************************************/ |
---|
77 | void kmem_free( void * ptr, |
---|
78 | uint32_t order ); |
---|
79 | |
---|
80 | void kmem_remote_free( cxy_t cxy, |
---|
81 | void * ptr, |
---|
82 | uint32_t order ); |
---|
83 | |
---|
84 | |
---|
85 | #endif /* _KMEM_H_ */ |
---|