source: trunk/kernel/mm/kmem.h @ 2

Last change on this file since 2 was 1, checked in by alain, 8 years ago

First import

File size: 5.7 KB
Line 
1/*
2 * kmem.h - kernel unified memory allocator interface
3 *
4 * Authors  Ghassan Almaless (2008,2009,2010,2011,2012)
5 *          Mohamed Lamine Karaoui (2015)
6 *          Alain Greiner (2016)
7 *
8 * Copyright (c) UPMC Sorbonne Universites
9 *
10 * This file is part of ALMOS-MKH.
11 *
12 * ALMOS-MKH is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; version 2.0 of the License.
15 *
16 * ALMOS-MKH is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with ALMOS; if not, write to the Free Software Foundation,
23 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26#ifndef _KMEM_H_
27#define _KMEM_H_
28
29#include <hal_types.h>
30#include <kcm.h>
31
32/*************************************************************************************
33 * This enum defines the Kernel Memory Types for dynamically allocated objects.
34 ************************************************************************************/
35
36enum
37{
38  KMEM_PAGE             = 0,   /*! reserved for PPM allocator                       */
39  KMEM_GENERIC          = 1,   /*! reserved for KHM allocator                       */
40  KMEM_KCM              = 2,   /*! kcm_t                                            */
41  KMEM_VSEG             = 3,   /*! vseg_t                                           */
42  KMEM_DEVICE           = 4,   /*! device_t                                         */
43  KMEM_MAPPER           = 5,   /*! mapper_t                                         */
44  KMEM_PROCESS          = 6,   /*! process_t                                        */
45  KMEM_TBD_7            = 7,
46  KMEM_TBD_8            = 8,
47  KMEM_TBD_9            = 9,
48
49  KMEM_FATFS_INODE      = 10,  /*! fatfs_inode_t                                    */
50  KMEM_FATFS_CTX        = 11,  /*! fatfs_ctx_t                                      */
51  KMEM_RAMFS_INODE      = 12,  /*  ramfs_inode_t                                    */
52  KMEM_RAMFS_CTX        = 13,  /*! ramfs_ctx_t                                      */
53  KMEM_VFS_CTX          = 14,  /*! vfs_context_t                                    */
54  KMEM_VFS_INODE        = 15,  /*! vfs_inode_t                                      */
55  KMEM_VFS_DENTRY       = 16,  /*! vfs_dentry_t                                     */
56  KMEM_VFS_FILE         = 17,  /*! vfs_file_t                                       */
57  KMEM_SEM              = 18,  /*! remote_sem_t                                     */
58  KMEM_TBD_19           = 19,
59
60  KMEM_64_BYTES         = 20,  /*! fixed size buffer                                */
61  KMEM_128_BYTES        = 21,  /*! fixed size buffer                                */
62  KMEM_256_BYTES        = 22,  /*! fixed size buffer                                */
63  KMEM_512_BYTES        = 23,  /*! fixed size buffer                                */
64  KMEM_1024_BYTES       = 24,  /*! fixed size buffer                                */
65  KMEM_2048_BYTES       = 25,  /*! fixed size buffer                                */
66
67  KMEM_TYPES_NR         = 26,
68};
69
70/*************************************************************************************
71 * This defines the generic Allocation Flags that can be associated to
72 * a Kernel Memory Request.
73 ************************************************************************************/
74
75#define AF_NONE       0x0000   // no attributes
76#define AF_KERNEL     0x0001   // for kernel use   
77#define AF_ZERO       0x0002   // must be reset to 0
78
79/*************************************************************************************
80 * This structure defines a Kernel Memory Request.
81 ************************************************************************************/
82
83typedef struct kmem_req_s
84{
85    uint32_t      type;   /*! request type                                          */
86    uint32_t      size;   /*! ln2(nb_pages) if PPM / bytes if KHM / unused by KCM   */
87    uint32_t      flags;  /*! request attributes                                    */
88    void        * ptr;    /*! local pointer on allocated buffer (only used by free) */
89} 
90kmem_req_t;
91
92/*************************************************************************************
93 * This generic function allocates physical memory in the local cluster
94 * as specified by the request descriptor.
95 * It uses three specialised physical memory allocators:
96 * - PPM (Physical Pages Manager) allocates N contiguous physical pages,
97 *       N must be a power of 2.
98 * - KHM (Kernel Heap Manager) allocates a physical memory buffer,
99 *       that can have any size.
100 * - KCM (Kernel Cache Manager) allocates various fixed size objects,
101 *       handling a dedicated cache for each object type.
102 *************************************************************************************
103 * @ req : local pointer to allocation request
104 * @ return a local pointer to allocated buffer / NULL otherwise
105 ************************************************************************************/
106void * kmem_alloc( kmem_req_t * req );
107
108/*************************************************************************************
109 * This function releases previously allocated physical memory, as specified
110 * by the "type" and "ptr" fiels of the kmem-req_t request.
111 *************************************************************************************
112 * @ req : local pointer to request descriptor.
113 ************************************************************************************/
114void  kmem_free ( kmem_req_t * req );
115
116
117#endif  /* _KMEM_H_ */
Note: See TracBrowser for help on using the repository browser.