source: trunk/kernel/mm/page.c @ 589

Last change on this file since 589 was 567, checked in by alain, 6 years ago

Complete restructuration of kernel locks.

File size: 2.8 KB
Line 
1/*
2 * page.c - physical page related operations implementation
3 *
4 * Authors  Ghassan Almaless (2008,2009,2010,2011,2012)
5 *          Alain Greiner    (2016,2017)
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-MKH; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25#include <hal_kernel_types.h>
26#include <hal_special.h>
27#include <hal_atomic.h>
28#include <list.h>
29#include <queuelock.h>
30#include <memcpy.h>
31#include <printk.h>
32#include <vfs.h>
33#include <process.h>
34#include <page.h>
35
36
37////////////////////////////////////////
38inline void page_init( page_t   * page )
39{
40        page->flags    = 0;
41        page->order    = 0;
42        page->mapper   = NULL;
43        page->index    = 0;
44        page->refcount = 0;
45        page->forks    = 0;
46
47        remote_busylock_init( XPTR( local_cxy , &page->lock ), LOCK_PAGE_STATE );
48
49        list_entry_init( &page->list );
50}
51
52////////////////////////////////////////////
53inline void page_set_flag( page_t   * page,
54                           uint32_t   value )
55{
56        hal_atomic_or( (uint32_t *)&page->flags , (uint32_t)value );
57}
58
59//////////////////////////////////////////////
60inline void page_clear_flag( page_t   * page,
61                             uint32_t   value )
62{
63        hal_atomic_and( (uint32_t *)&page->flags , ~((uint32_t)value) );
64}
65
66//////////////////////////////////////////////
67inline bool_t page_is_flag( page_t   * page,
68                            uint32_t   value )
69{
70    return ( (page->flags & value) ? 1 : 0 );
71}
72
73////////////////////////////////////////////
74inline void page_refcount_up( page_t *page )
75{
76    hal_atomic_add( &page->refcount , +1 );
77}
78
79//////////////////////////////////////////////
80inline void page_refcount_down( page_t *page )
81{
82    hal_atomic_add( &page->refcount , -1 );
83}
84
85///////////////////////////////
86void page_zero( page_t * page )
87{
88        uint32_t   size = (1 << page->order) * CONFIG_PPM_PAGE_SIZE;
89
90        xptr_t base_xp = ppm_page2base( XPTR( local_cxy , page ) );
91
92        memset( GET_PTR( base_xp ) , 0 , size );
93}
94
95////////////////////////////////
96void page_print( page_t * page )
97{
98        printk("*** Page %d : base = %x / flags = %x / order = %d / count = %d\n",
99                page->index,
100                GET_PTR( ppm_page2base( XPTR( local_cxy , page ) ) ),
101                page->flags,
102                page->order,
103                page->refcount );
104}
105
Note: See TracBrowser for help on using the repository browser.