[50] | 1 | /* |
---|
[107] | 2 | * hal_ppm.c - Generic Physical Page Manager API implementation for TSAR |
---|
[50] | 3 | * |
---|
[632] | 4 | * Authors Alain Greiner (2016,2017,2018,2019) |
---|
[50] | 5 | * |
---|
| 6 | * Copyright (c) UPMC Sorbonne Universites |
---|
| 7 | * |
---|
| 8 | * This file is part of ALMOS-MKH. |
---|
| 9 | * |
---|
| 10 | * ALMOS-MKH is free software; you can redistribute it and/or modify it |
---|
| 11 | * under the terms of the GNU General Public License as published by |
---|
| 12 | * the Free Software Foundation; version 2.0 of the License. |
---|
| 13 | * |
---|
| 14 | * ALMOS-MKH is distributed in the hope that it will be useful, but |
---|
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 17 | * General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with ALMOS-MKH; if not, write to the Free Software Foundation, |
---|
| 21 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 22 | */ |
---|
| 23 | |
---|
[53] | 24 | #include <kernel_config.h> |
---|
[457] | 25 | #include <hal_kernel_types.h> |
---|
[53] | 26 | #include <hal_ppm.h> |
---|
| 27 | #include <hal_special.h> |
---|
| 28 | #include <printk.h> |
---|
[570] | 29 | #include <busylock.h> |
---|
[53] | 30 | #include <process.h> |
---|
| 31 | #include <ppm.h> |
---|
| 32 | #include <thread.h> |
---|
| 33 | #include <cluster.h> |
---|
| 34 | #include <page.h> |
---|
[50] | 35 | |
---|
| 36 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
[409] | 37 | // This file contains the TSAR specific code for the physical memory |
---|
| 38 | // allocators initialisation. |
---|
[313] | 39 | // |
---|
[106] | 40 | // For The TSAR architecture, the kernel pointers are identity mapped: |
---|
| 41 | // - the 32 bits PTR value is identical to the 32 bits LPA value, |
---|
[50] | 42 | // - the 64 bits XPTR value is identical to the 64 bits PADDR value. |
---|
[296] | 43 | // This hal_ppm_init() function initializes the pages_tbl[] array used by the generic |
---|
| 44 | // kmem memory allocator in the local cluster. This array starts in first free page |
---|
[432] | 45 | // after kernel code, as defined by the 'pages_offset' field in boot_info. |
---|
[50] | 46 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 47 | |
---|
[570] | 48 | |
---|
[53] | 49 | /////////////////////////////////////////// |
---|
| 50 | error_t hal_ppm_init( boot_info_t * info ) |
---|
[50] | 51 | { |
---|
[106] | 52 | uint32_t i; |
---|
[53] | 53 | |
---|
[106] | 54 | // get relevant info from boot_info structure |
---|
[107] | 55 | uint32_t pages_nr = info->pages_nr; |
---|
| 56 | uint32_t pages_tbl_offset = info->pages_offset; |
---|
[50] | 57 | |
---|
[106] | 58 | // get pointer on local Physical Page Manager |
---|
| 59 | ppm_t * ppm = &LOCAL_CLUSTER->ppm; |
---|
| 60 | |
---|
| 61 | // initialize lock protecting the free_pages[] lists |
---|
[632] | 62 | remote_busylock_init( XPTR( local_cxy , &ppm->free_lock ) , LOCK_PPM_FREE ); |
---|
[50] | 63 | |
---|
[106] | 64 | // initialize lock protecting the dirty_pages list |
---|
[610] | 65 | remote_queuelock_init( XPTR( local_cxy , &ppm->dirty_lock ) , LOCK_PPM_DIRTY ); |
---|
[50] | 66 | |
---|
[106] | 67 | // initialize all free_pages[] lists as empty |
---|
[50] | 68 | for( i = 0 ; i < CONFIG_PPM_MAX_ORDER ; i++ ) |
---|
| 69 | { |
---|
| 70 | list_root_init( &ppm->free_pages_root[i] ); |
---|
| 71 | ppm->free_pages_nr[i] = 0; |
---|
| 72 | } |
---|
| 73 | |
---|
[106] | 74 | // initialize dirty_list as empty |
---|
| 75 | list_root_init( &ppm->dirty_root ); |
---|
[50] | 76 | |
---|
[106] | 77 | // compute size of pages_tbl[] array rounded to an integer number of pages |
---|
| 78 | uint32_t bytes = ARROUND_UP( pages_nr * sizeof(page_t), CONFIG_PPM_PAGE_SIZE ); |
---|
[50] | 79 | |
---|
[106] | 80 | // compute number of pages required to store page descriptor array |
---|
[686] | 81 | uint32_t pages_tbl_nr = bytes >> CONFIG_PPM_PAGE_ORDER; |
---|
[50] | 82 | |
---|
[106] | 83 | // compute total number of reserved pages (kernel code & pages_tbl[]) |
---|
[53] | 84 | uint32_t reserved_pages = pages_tbl_offset + pages_tbl_nr; |
---|
[50] | 85 | |
---|
[107] | 86 | // initialize pages_nr, pages_tbl, and vaddr_base pointers |
---|
| 87 | // (TSAR uses identity mapping for kernel pointers) |
---|
| 88 | // x86 architectures should use vaddr_base = 0xFFFF8000000000 + (cxy << 36) |
---|
| 89 | ppm->pages_nr = pages_nr; |
---|
| 90 | ppm->vaddr_base = NULL; |
---|
| 91 | ppm->pages_tbl = (page_t*)( ppm->vaddr_base + |
---|
[686] | 92 | (pages_tbl_offset << CONFIG_PPM_PAGE_ORDER) ); |
---|
[107] | 93 | |
---|
[106] | 94 | // initialize all page descriptors in pages_tbl[] |
---|
[50] | 95 | for( i = 0 ; i < pages_nr ; i++ ) |
---|
[106] | 96 | { |
---|
| 97 | page_init( &ppm->pages_tbl[i] ); |
---|
[50] | 98 | |
---|
[106] | 99 | // TODO optimisation for this enormous loop on small pages: |
---|
| 100 | // make only a partial init with a memset, and complete the |
---|
| 101 | // initialisation when page is allocated [AG] |
---|
| 102 | } |
---|
[50] | 103 | |
---|
[106] | 104 | // - set PG_RESERVED flag for reserved pages (kernel code & pages_tbl[]) |
---|
| 105 | // - release all other pages to populate the free lists |
---|
[50] | 106 | for( i = 0 ; i < reserved_pages ; i++) |
---|
[106] | 107 | { |
---|
| 108 | page_set_flag( &ppm->pages_tbl[i] , PG_RESERVED ); |
---|
| 109 | } |
---|
[50] | 110 | for( i = reserved_pages ; i < pages_nr ; i++ ) |
---|
| 111 | { |
---|
[106] | 112 | ppm_free_pages_nolock( &ppm->pages_tbl[i] ); |
---|
[50] | 113 | |
---|
[106] | 114 | // TODO optimisation : decompose this enormous set of small pages |
---|
[432] | 115 | // to several sets of big pages with various order values [AG] |
---|
[50] | 116 | } |
---|
| 117 | |
---|
[106] | 118 | // check consistency |
---|
[632] | 119 | return ppm_assert_order(); |
---|
[50] | 120 | |
---|
[296] | 121 | } // end hal_ppm_init() |
---|
| 122 | |
---|
| 123 | |
---|