source: trunk/hal/tsar_mips32/core/hal_ppm.c @ 68

Last change on this file since 68 was 62, checked in by max@…, 7 years ago

create the core/ sub-directory for tsar

File size: 4.3 KB
Line 
1/*
2 * hal_gpt.C - Generic Physcal Page Table API implementation for the TSAR archtecture.
3 *
4 * Authors  Alain Greiner (2016,2017)
5 *
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 <kernel_config.h>
26#include <hal_types.h>
27#include <hal_ppm.h>
28#include <hal_special.h>
29#include <printk.h>
30#include <spinlock.h>
31#include <process.h>
32#include <ppm.h>
33#include <thread.h>
34#include <cluster.h>
35#include <page.h>
36
37//////////////////////////////////////////////////////////////////////////////////////////
38// For The TSAR architecture, the kernel pointers are identity mapping:
39// - the 32 bits PTR value is identical to the 32 bits LPA value,
40// - the 64 bits XPTR value is identical to the 64 bits PADDR value.
41// The pages_tbl[] is mapped in first free page after kernel code.
42// There is no other reserved zones than the zone occupied by the kernel code.
43//////////////////////////////////////////////////////////////////////////////////////////
44
45
46///////////////////////////////////////////
47error_t  hal_ppm_init( boot_info_t * info )
48{
49    uint32_t i;
50
51    // get relevant info from boot_info structure
52        uint32_t   pages_nr         = info->pages_nr;
53    uint32_t   pages_tbl_offset = info->pages_offset;
54    uint32_t   rsvd_nr          = info->rsvd_nr;
55
56    // check no reserved zones other than kernel code for TSAR
57    assert( (rsvd_nr == 0 ) , __FUNCTION__ , "NO reserved zones for TSAR\n" ); 
58
59    // get pointer on local Physical Page Manager
60    ppm_t * ppm = &LOCAL_CLUSTER->ppm;
61   
62    // initialize lock protecting the free_pages[] lists
63        spinlock_init( &ppm->free_lock );
64
65    // initialize lock protecting the dirty_pages list
66        spinlock_init( &ppm->dirty_lock );
67
68    // initialize all free_pages[] lists as empty
69        for( i = 0 ; i < CONFIG_PPM_MAX_ORDER ; i++ )
70        {
71                list_root_init( &ppm->free_pages_root[i] );
72                ppm->free_pages_nr[i] = 0;
73        }
74
75    // initialize dirty_list as empty
76    list_root_init( &ppm->dirty_root );
77
78    // initialize pages_nr, pages_tbl, and vaddr_base pointers
79    // (TSAR uses identity mapping for kernel pointers)
80    // I86 architectures should use vaddr_base = 0xFFFF8000000000 + (cxy << 36)
81
82        ppm->pages_nr      = pages_nr;
83    ppm->vaddr_base = NULL;
84        ppm->pages_tbl  = (page_t*)( ppm->vaddr_base + 
85                                 (pages_tbl_offset << CONFIG_PPM_PAGE_SHIFT) );
86
87    // compute size of pages_tbl[] array rounded to an integer number of pages
88    uint32_t bytes = ARROUND_UP( pages_nr * sizeof(page_t), CONFIG_PPM_PAGE_SIZE );
89
90    // compute number of pages required to store page descriptor array
91        uint32_t pages_tbl_nr = bytes >> CONFIG_PPM_PAGE_SHIFT;
92
93    // compute total number of reserved pages (kernel code & pages_tbl[])
94        uint32_t reserved_pages = pages_tbl_offset + pages_tbl_nr;
95
96    // initialises all page descriptors in pages_tbl[]
97        for( i = 0 ; i < pages_nr ; i++ )
98    {
99        page_init( &ppm->pages_tbl[i] );
100
101        // TODO optimisation for this enormous loop on small pages:
102        // make only a partial init with a memset, and complete the
103        // initialisation when page is allocated [AG]
104    }
105
106    // - set PG_RESERVED flag for reserved pages (kernel code & pages_tbl[])
107    // - release all other pages to populate the free lists
108        for( i = 0 ; i < reserved_pages ; i++)
109    {
110        page_set_flag( &ppm->pages_tbl[i] , PG_RESERVED );
111    }
112        for( i = reserved_pages ; i < pages_nr ; i++ )
113        {
114            ppm_free_pages_nolock( &ppm->pages_tbl[i] );
115
116        // TODO optimisation : decompose this enormous set of small pages
117        // to several sets of big pages with various order values
118        }
119
120    // check consistency
121    return ppm_assert_order( ppm );
122
123}  // end hal_ppm_init()
124
Note: See TracBrowser for help on using the repository browser.