source: trunk/hal/tsar_mips32/hal_ppm.c @ 50

Last change on this file since 50 was 50, checked in by alain, 7 years ago

bloup

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