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

Last change on this file since 612 was 611, checked in by alain, 6 years ago

Introduce sigificant modifs in VFS to support the <ls> command,
and the . and .. directories entries.

File size: 6.7 KB
Line 
1/*
2 * kmem.h - kernel unified memory allocator interface
3 *
4 * Authors  Ghassan Almaless (2008,2009,2010,2011,2012)
5 *          Alain Greiner (2016,2017,2018)
6 *
7 * Copyright (c) UPMC Sorbonne Universites
8 *
9 * This file is part of ALMOS-MKH.
10 *
11 * ALMOS-MKH is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; version 2.0 of the License.
14 *
15 * ALMOS-MKH is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with ALMOS; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25#ifndef _KMEM_H_
26#define _KMEM_H_
27
28#include <hal_kernel_types.h>
29#include <kcm.h>
30
31/*************************************************************************************
32 * This enum defines the Kernel Memory Types for dynamically allocated objects.
33 * WARNING : this enum must be kepts consistent with use in kmem.c file.
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_CPU_CTX          = 7,   /*! hal_cpu_context_t                              */
46    KMEM_FPU_CTX          = 8,   /*! hal_fpu_context_t                              */
47    KMEM_BARRIER          = 9,   /*! remote_barrier_t                               */
48
49    KMEM_DEVFS_CTX        = 10,  /*! fatfs_inode_t                                  */
50    KMEM_FATFS_CTX        = 11,  /*! fatfs_ctx_t                                    */
51    KMEM_VFS_CTX          = 12,  /*! vfs_context_t                                  */
52    KMEM_VFS_INODE        = 13,  /*! vfs_inode_t                                    */
53    KMEM_VFS_DENTRY       = 14,  /*! vfs_dentry_t                                   */
54    KMEM_VFS_FILE         = 15,  /*! vfs_file_t                                     */
55    KMEM_SEM              = 16,  /*! remote_sem_t                                   */
56    KMEM_CONDVAR          = 17,  /*! remote_condvar_t                               */
57    KMEM_MUTEX            = 18,  /*! remote_mutex_t                                 */
58    KMEM_DIR              = 19,  /*! remote_dir_t                                   */
59
60    KMEM_512_BYTES        = 20,  /*! 512 bytes aligned                              */
61
62    KMEM_TYPES_NR         = 21,
63};
64
65/*************************************************************************************
66 * This defines the generic Allocation Flags that can be associated to
67 * a Kernel Memory Request.
68 ************************************************************************************/
69
70#define AF_NONE       0x0000   // no attributes
71#define AF_KERNEL     0x0001   // for kernel use
72#define AF_ZERO       0x0002   // must be reset to 0
73
74/*************************************************************************************
75 * This structure defines a Kernel Memory Request.
76 ************************************************************************************/
77
78typedef struct kmem_req_s
79{
80    uint32_t      type;   /*! request type                                          */
81    uint32_t      size;   /*! ln2(nb_pages) if PPM / bytes if KHM / unused by KCM   */
82    uint32_t      flags;  /*! request attributes                                    */
83    void        * ptr;    /*! local pointer on allocated buffer (only used by free) */
84}
85kmem_req_t;
86
87/*************************************************************************************
88 * This generic function allocates physical memory in the local cluster
89 * as specified by the request descriptor.
90 * It uses three specialised physical memory allocators, depending on request type:
91 * - PPM (Physical Pages Manager) allocates N contiguous physical pages,
92 *       N must be a power of 2.
93 * - KHM (Kernel Heap Manager) allocates a physical memory buffer,
94 *       that can have any size.
95 * - KCM (Kernel Cache Manager) allocates various fixed size objects,
96 *       handling a dedicated cache for each object type.
97 *************************************************************************************
98 * @ req   : local pointer to allocation request.
99 * @ return a local pointer on page descriptor if PPM (i.e. type KMEM_PAGE).
100 *   return a local pointer to allocated buffer if KCM or KHM.
101 *   return NULL if no physical memory available.
102 ************************************************************************************/
103void * kmem_alloc( kmem_req_t * req );
104
105/*************************************************************************************
106 * This function releases previously allocated physical memory, as specified
107 * by the "type" and "ptr" fiels of the kmem-req_t request.
108 *************************************************************************************
109 * @ req : local pointer to request descriptor.
110 ************************************************************************************/
111void  kmem_free ( kmem_req_t * req );
112
113/*************************************************************************************
114 * This function returns a printable string for a kmem object type.
115 *************************************************************************************
116 * @ type   : kmem object type.
117 ************************************************************************************/
118char * kmem_type_str( uint32_t type );
119
120/*************************************************************************************
121 * This function returns the size (bytes) for a kmem object type.
122 *************************************************************************************
123 * @ type   : kmem object type.
124 ************************************************************************************/
125uint32_t kmem_type_size( uint32_t type );
126
127/*************************************************************************************
128 * This function displays the content of the KCM pointers Table
129 ************************************************************************************/
130void kmem_print_kcm_table( void );
131
132
133#endif  /* _KMEM_H_ */
Note: See TracBrowser for help on using the repository browser.