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

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

Complete restructuration of kernel locks.

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