Index: trunk/kernel/mm/ppm.c
===================================================================
--- trunk/kernel/mm/ppm.c	(revision 18)
+++ trunk/kernel/mm/ppm.c	(revision 50)
@@ -3,5 +3,5 @@
  *
  * Authors  Ghassan Almaless (2008,2009,2010,2011,2012)
- *          Alain Greiner    (2016)
+ *          Alain Greiner    (2016,2017)
  *
  * Copyright (c) UPMC Sorbonne Universites
@@ -48,17 +48,21 @@
 }
 
-////////////////////////////////////////////
-inline void * ppm_page2base( page_t * page )
+
+
+/////////////////////////////////////////////
+inline void * ppm_page2vaddr( page_t * page )
 {
 	ppm_t * ppm = &LOCAL_CLUSTER->ppm;
-	return (void*)((page - ppm->pages_tbl) << CONFIG_PPM_PAGE_SHIFT);
-}
-
-////////////////////////////////////////////
-inline page_t * ppm_base2page( void * base )
+	return ppm->vaddr_base + ((page - ppm->pages_tbl) << CONFIG_PPM_PAGE_SHIFT);
+}
+
+//////////////////////////////////////////////
+inline page_t * ppm_vaddr2page( void * vaddr )
 {
 	ppm_t * ppm = &LOCAL_CLUSTER->ppm;
-	return (ppm->pages_tbl + (((uint32_t)base ) >> CONFIG_PPM_PAGE_SHIFT));
-}
+	return ppm->pages_tbl + (vaddr - ppm->vaddr_base);
+}
+
+
 
 //////////////////////////////////////////
@@ -76,18 +80,24 @@
 }
 
+
+
 ///////////////////////////////////////
-inline void * ppm_ppn2base( ppn_t ppn )
-{
-	return (void*)( ppn << CONFIG_PPM_PAGE_SHIFT );
-}
-
-////////////////////////////////////////
-inline ppn_t ppm_base2ppn( void * base )
-{
-	return (ppn_t)( (uint32_t)base >> CONFIG_PPM_PAGE_SHIFT );
-}
-
-//////////////////////////////////////////////////
-static void ppm_free_pages_nolock( page_t * page )
+inline void * ppm_ppn2vaddr( ppn_t ppn )
+{
+	ppm_t  * ppm  = &LOCAL_CLUSTER->ppm;
+	return ppm->vaddr_base + (ppn << CONFIG_PPM_PAGE_SHIFT);
+}
+
+//////////////////////////////////////////
+inline ppn_t ppm_vaddr2ppn( void * vaddr )
+{
+	ppm_t  * ppm  = &LOCAL_CLUSTER->ppm;
+	return  ( (ppm->vaddr_base - vaddr) >> CONFIG_PPM_PAGE_SHIFT );
+}
+
+
+
+///////////////////////////////////////////
+void ppm_free_pages_nolock( page_t * page )
 {
 	page_t   * buddy;            // searched buddy page descriptor
@@ -95,5 +105,5 @@
 	page_t   * current;          // current (merged) page descriptor
 	uint32_t   current_index;    // current (merged) page index
-	uint32_t   current_order;    // current (merget) page order
+	uint32_t   current_order;    // current (merged) page order
 
     ppm_t    * ppm         = &LOCAL_CLUSTER->ppm;
@@ -120,5 +130,4 @@
 		list_unlink( &buddy->list );
 		ppm->free_pages_nr[current_order] --;
-        ppm->total_free_pages -= (1 << current_order);
 
         // merge buddy with current
@@ -134,76 +143,6 @@
 	list_add_first( &ppm->free_pages_root[current_order] , &current->list );
 	ppm->free_pages_nr[current_order] ++;
-    ppm->total_free_pages += (1 << current_order);
 
 }  // end ppm_free_pages_nolock()
-
-//////////////////////////////
-void ppm_init( ppm_t    * ppm,
-               uint32_t   pages_nr,        // total pages number
-               uint32_t   pages_offset )   // occupied pages
-{
-	uint32_t   i;
-
-    // set signature
-	ppm->signature = PPM_SIGNATURE;
-
-    // initialize lock protecting the free_pages[] array
-	spinlock_init( &ppm->free_lock );
-
-    // initialize free_pages[] array as empty
-	ppm->total_free_pages = 0;
-	for( i = 0 ; i < CONFIG_PPM_MAX_ORDER ; i++ )
-	{
-		list_root_init( &ppm->free_pages_root[i] );
-		ppm->free_pages_nr[i] = 0;
-	}
-
-    // initialize dirty_list as empty
-    list_root_init( &ppm->dirty_root );
-
-    // initialize pointer on page descriptors array
-	ppm->pages_tbl = (page_t*)( pages_offset << CONFIG_PPM_PAGE_SHIFT );
-
-    // compute size of pages descriptor array rounded to an integer number of pages
-    uint32_t bytes = ARROUND_UP( pages_nr * sizeof(page_t), CONFIG_PPM_PAGE_SIZE );
-
-    // compute number of pages required to store page descriptor array
-	uint32_t pages_array  = bytes >> CONFIG_PPM_PAGE_SHIFT;
-
-    // compute total number of reserved pages (kernel code & pages_tbl[])
-	uint32_t reserved_pages = pages_offset + pages_array;
-
-	// set pages numbers
-	ppm->pages_nr      = pages_nr;
-    ppm->pages_offset  = reserved_pages;
-
-    // initialises all page descriptors in pages_tbl[]
-	for( i = 0 ; i < pages_nr ; i++ )
-    {
-        page_init( &ppm->pages_tbl[i] );
-
-        // TODO optimisation : make only a partial init [AG]
-        // complete the initialisation when page is allocated [AG]
-        // ppm->pages_tbl[i].flags = 0;
-    }
-
-    // - set PG_RESERVED flag for reserved pages (kernel code & pages_tbl[])
-    // - release all other pages to populate the free lists
-	for( i = 0 ; i < reserved_pages ; i++)
-    {
-        page_set_flag( &ppm->pages_tbl[i] , PG_RESERVED );
-    }
-	for( i = reserved_pages ; i < pages_nr ; i++ )
-	{
-	    ppm_free_pages_nolock( &ppm->pages_tbl[i] );
-
-        // TODO optimisation : decompose this enormous set of small pages
-        // to a set big pages with various order values
-	}
-
-    // check consistency
-    ppm_assert_order( ppm );
-
-} // end ppm_init()
 
 ////////////////////////////////////////////
@@ -216,6 +155,4 @@
     ppm_t    * ppm = &LOCAL_CLUSTER->ppm;
 
-	assert( (ppm->signature == PPM_SIGNATURE) , __FUNCTION__ , "PPM non initialised" );
-
 	assert( (order < CONFIG_PPM_MAX_ORDER) , __FUNCTION__ , "illegal order argument" );
 
@@ -224,8 +161,4 @@
     ppm_dmsg("\n[INFO] %s : enters / order = %d\n",
              __FUNCTION__ , order );
-
-#if( CONFIG_PPM_DEBUG )
-ppm_print( ppm , "before allocation" );
-#endif
 
     // take lock protecting free lists
@@ -252,5 +185,4 @@
 
     // update free-lists after removing a block
-	ppm->total_free_pages -= (1 << current_order);
 	ppm->free_pages_nr[current_order] --;
 	current_size = (1 << current_order);
@@ -268,5 +200,4 @@
 		list_add_first( &ppm->free_pages_root[current_order] , &remaining_block->list );
 		ppm->free_pages_nr[current_order] ++;
-        ppm->total_free_pages += (1 << current_order);
 	}
 
@@ -282,8 +213,4 @@
              __FUNCTION__ , (uint32_t)ppm_page2base( block ) , order );
 
-#if CONFIG_PPM_DEBUG
-ppm_print( ppm , "after allocation" );
-#endif
-
 	return block;
 }  // end pmm_alloc-pages()
@@ -315,6 +242,6 @@
 	spinlock_lock( &ppm->free_lock );
 
-	printk("\n***  PPM state in cluster %x %s : pages = %d / offset = %d / free = %d ***\n",
-	       local_cxy , string , ppm->pages_nr , ppm->pages_offset , ppm->total_free_pages );
+	printk("\n***  PPM in cluster %x : %d pages / &pages_tbl = %x / vaddr_base = %x ***\n",
+	       local_cxy , ppm->pages_nr , (intptr_t)ppm->pages_tbl , (intptr_t)ppm->vaddr_base );
 
 	for( order = 0 ; order < CONFIG_PPM_MAX_ORDER ; order++ )
