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

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

First import

File size: 8.0 KB
Line 
1/*
2 * ppm.h - Per-cluster Physical Pages Manager Interface
3 *
4 * Authors  Ghassan Almaless (2008,2009,2010,2011,2012)
5 *          Alain Greiner    (2016)
6 *
7 * Copyright (c) UPMC Sorbonne Universites
8 *
9 * This file is part of ALMOS-MKH.
10 *
11 * ALMOS-kernel 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-kernel 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-kernel; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25#ifndef _PPM_H_
26#define _PPM_H_
27
28#include <hal_types.h>
29#include <list.h>
30#include <spinlock.h>
31#include <boot_info.h>
32#include <page.h>
33
34#define  PPM_SIGNATURE     0xBABEF00D
35
36/*****************************************************************************************
37 * This structure defines the list of blocks of a given size for the "buddy"
38 * allocation algorithm implemented by the ppm_t manager.
39 ****************************************************************************************/
40typedef struct buddy_list_s
41{
42        list_entry_t  root;       // root of the list
43        uint32_t      pages_nr;   // number of blocks
44}
45buddy_list_t;
46
47/*****************************************************************************************
48 * This structure defines the Physical Memory Manager in a cluster.
49 * In all clusters, the physical memory bank starts at address 0.
50 * The segments kcode and kdata are mapped in the first "offset" pages.
51 * The physical page descriptors array is implemented just after this offset zone.
52 * The main service provided by the PMM is the dynamic allocation of physical pages.
53 * This low-level allocator implements the buddy algorithm.
54 ****************************************************************************************/
55typedef struct ppm_s
56{
57        uint32_t       signature;               /*! set when initialised                    */
58        spinlock_t     free_lock;               /*! lock protecting free_pages[] array      */
59        list_entry_t   free_pages_root[CONFIG_PPM_MAX_ORDER];  /*! roots of free lists      */
60        uint32_t       free_pages_nr[CONFIG_PPM_MAX_ORDER];    /*! numbers of free pages    */
61    uint32_t       total_free_pages;        /*! total number of free pages              */
62        page_t       * pages_tbl;               /*! pointer on page descriptors array       */
63        uint32_t       pages_nr;                /*! total number of 4 Kbytes physical page  */
64    uint32_t       pages_offset;            /*! allocated pages for kcode & kdata       */
65    uint32_t       pages_desc;              /*! allocated pages for pages_tbl[] array   */
66    spinlock_t     dirty_lock;              /*! lock protecting the dirty list          */
67    list_entry_t   dirty_root;              /*! root of dirty pages list                */
68}
69ppm_t;
70
71/*****************************************************************************************
72 * This function initializes a PPM (Physical Pages Manager) in a cluster.
73 * The physical memory base address in all cluster is zero.
74 * The physical memory size is NOT constrained to be smaller than 4 Gbytes.
75 * @ ppm          : pointer on physical pages manager.
76 * @ pages_nr     : total physical memory size (number of 4 Kbytes pages).
77 * @ pages_offset : number of pages already allocated in this physical memory.
78 ****************************************************************************************/
79void ppm_init( ppm_t    * ppm, 
80               uint32_t   pages_nr,
81                   uint32_t   pages_offset );
82
83/*****************************************************************************************
84 * This is the low-level physical pages allocation function.
85 * It allocates N contiguous physical pages. N is a power of 2.
86 * In normal use, you don't need to call it directly, as the recommanded way to get
87 * physical pages is to call the generic allocator defined in kmem.h.
88 * @ order        : ln2( number of 4 Kbytes pages)
89 * @ returns a pointer on the page descriptor if success / NULL otherwise
90 ****************************************************************************************/
91page_t * ppm_alloc_pages( uint32_t order );
92
93/*****************************************************************************************
94 * This is the low-level physical pages release function.
95 * In normal use, you do not need to call it directly, as the recommanded way to free
96 * physical pages is to call the generic allocator defined in kmem.h.
97 * @ page         : pointer to the page descriptor to be released
98 ****************************************************************************************/
99void ppm_free_pages( page_t * page );
100
101/*****************************************************************************************
102 * This function check if a page descriptor is valid.
103 * @ page         : pointer on a page descriptor
104 * @ returns true if valid / false otherwise.
105 ****************************************************************************************/
106inline bool_t ppm_page_is_valid( page_t * page );
107
108/*****************************************************************************************
109 * Get the page base address from the page descriptor pointer.
110 * @ page         : pointer to page descriptor
111 * @ returns page base address
112 ****************************************************************************************/
113inline void* ppm_page2base( page_t * page );
114
115/*****************************************************************************************
116 * Get the page descriptor pointer from the page base address.
117 * @ vaddr        : page base address
118 * @ returns pointer on page descriptor
119 ****************************************************************************************/
120inline page_t * ppm_base2page( void * vaddr );
121
122/*****************************************************************************************
123 * Get the PPN from the page descriptor pointer.
124 * @ page         : pointer to page descriptor
125 * @ returns physical page number
126 ****************************************************************************************/
127inline ppn_t ppm_page2ppn( page_t * page );
128
129/*****************************************************************************************
130 * Get the page descriptor pointer from the PPN.
131 * @ ppn          : physical page number
132 * @ returns pointer on page descriptor
133 ****************************************************************************************/
134inline page_t * ppm_ppn2page( ppn_t ppn );
135
136/*****************************************************************************************
137 * Get the page base address from the PPN.
138 * @ ppn          : physical page number
139 * @ returns page base address
140 ****************************************************************************************/
141inline void* ppm_ppn2base( ppn_t ppn );
142
143/*****************************************************************************************
144 * Get the PPN from the page base address.
145 * @ vaddr        : page base address
146 * @ returns physical page number
147 ****************************************************************************************/
148inline ppn_t ppm_base2ppn( void * base );
149
150/*****************************************************************************************
151 * This function prints the PPM allocator status.
152 * @ ppm      : pointer on PPM allocator.
153 ****************************************************************************************/
154void ppm_print( ppm_t * ppm );
155
156/*****************************************************************************************
157 * This function checks PPM allocator consistency.
158 * @ ppm      : pointer on PPM allocator.
159 ****************************************************************************************/
160void ppm_assert_order( ppm_t * ppm );
161
162#endif  /* _PPM_H_ */
Note: See TracBrowser for help on using the repository browser.