Changeset 315 for trunk/kernel/mm
- Timestamp:
- Aug 3, 2017, 10:15:18 AM (7 years ago)
- Location:
- trunk/kernel/mm
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/mm/kcm.c
r182 r315 160 160 161 161 // get page base address 162 kcm_page = (kcm_page_t *)ppm_page2vaddr( page ); 162 xptr_t base_xp = ppm_page2base( XPTR( local_cxy , page ) ); 163 kcm_page = (kcm_page_t *)GET_PTR( base_xp ); 163 164 164 165 // initialize KCM-page descriptor -
trunk/kernel/mm/khm.c
r175 r315 51 51 // get kernel heap base from PPM 52 52 page_t * page = ppm_alloc_pages( CONFIG_PPM_HEAP_ORDER ); 53 void * heap_base = ppm_page2vaddr( page ); 53 xptr_t base_xp = ppm_page2base( XPTR( local_cxy, page ) ); 54 void * heap_base = GET_PTR( base_xp ); 54 55 55 56 // initialize first block (complete heap) -
trunk/kernel/mm/mapper.c
r313 r315 349 349 350 350 // compute pointer in mapper 351 map_ptr = (uint8_t *)ppm_page2vaddr( page ) + page_offset; 351 xptr_t base_xp = ppm_page2base( XPTR( local_cxy, page ) ); 352 map_ptr = (uint8_t *)GET_PTR( base_xp ) + page_offset; 352 353 353 354 // compute pointer in buffer … … 446 447 if ( page == NULL ) return EINVAL; 447 448 449 // get page base address 450 uint8_t * base = (uint8_t *)GET_PTR( XPTR( local_cxy , page ) ); 451 448 452 // compute source and destination pointers 449 453 if( to_buffer ) 450 454 { 451 dst_ptr = buf _ptr + done;452 src_ptr = (uint8_t *)ppm_page2vaddr( page )+ page_offset;455 dst_ptr = buffer_ptr + done; 456 src_ptr = base + page_offset; 453 457 } 454 458 else 455 459 { 456 src_ptr = buf _ptr + done;457 dst_ptr = (uint8_t *)ppm_page2vaddr( page )+ page_offset;460 src_ptr = buffer_ptr + done; 461 dst_ptr = base + page_offset; 458 462 459 463 page_do_dirty( page ); -
trunk/kernel/mm/mapper.h
r313 r315 130 130 * @ mapper : local pointer on mapper. 131 131 * @ to_buffer : mapper -> buffer if true / buffer -> mapper if false. 132 * @ is_user : user space buffer if true / kernel local buffer if false.133 132 * @ file_offset : first byte to move in file. 134 133 * @ buffer : user space pointer on user buffer. … … 138 137 error_t mapper_move_user( mapper_t * mapper, 139 138 bool_t to_buffer, 140 bool_t is_user,141 139 uint32_t file_offset, 142 140 void * buffer, -
trunk/kernel/mm/page.c
r296 r315 232 232 } 233 233 234 //////////////////////////////235 void page_copy( page_t * dst,236 page_t * src )237 {238 uint32_t size;239 void * src_base;240 void * dst_base;241 242 assert( (dst->order == src->order) , __FUNCTION__ , "src size != dst size\n" );243 244 size = (1 << dst->order) * CONFIG_PPM_PAGE_SIZE;245 src_base = ppm_page2vaddr( src );246 dst_base = ppm_page2vaddr( dst );247 248 memcpy( dst_base , src_base , size );249 }250 251 234 /////////////////////////////// 252 235 void page_zero( page_t * page ) 253 236 { 254 uint32_t size; 255 void * base; 256 257 size = (1 << page->order) * CONFIG_PPM_PAGE_SIZE; 258 base = ppm_page2vaddr( page ); 259 260 memset( base , 0 , size ); 237 uint32_t size = (1 << page->order) * CONFIG_PPM_PAGE_SIZE; 238 239 xptr_t base_xp = ppm_page2base( XPTR( local_cxy , page ) ); 240 241 memset( GET_PTR( base_xp ) , 0 , size ); 261 242 } 262 243 … … 266 247 printk("*** Page %d : base = %x / flags = %x / order = %d / count = %d\n", 267 248 page->index, 268 ppm_page2vaddr( page),249 GET_PTR( ppm_page2base( XPTR( local_cxy , page ) ) ), 269 250 page->flags, 270 251 page->order, -
trunk/kernel/mm/page.h
r68 r315 132 132 133 133 /************************************************************************************* 134 * This function makes a local copy of the content of a src page to a dst page.135 *************************************************************************************136 * @ dst : pointer on destination page descriptor.137 * @ src : pointer on source page descriptor.138 ************************************************************************************/139 void page_copy( page_t * dst,140 page_t * src );141 142 /*************************************************************************************143 134 * This function resets to 0 all bytes in a given page. 144 135 ************************************************************************************* -
trunk/kernel/mm/ppm.c
r313 r315 47 47 48 48 49 49 50 ///////////////////////////////////////////// 50 inline void * ppm_page2vaddr( page_t * page ) 51 { 52 ppm_t * ppm = &LOCAL_CLUSTER->ppm; 53 return ppm->vaddr_base + ((page - ppm->pages_tbl) << CONFIG_PPM_PAGE_SHIFT); 54 } 55 56 ////////////////////////////////////////////// 57 inline page_t * ppm_vaddr2page( void * vaddr ) 58 { 59 ppm_t * ppm = &LOCAL_CLUSTER->ppm; 60 return ppm->pages_tbl + (vaddr - ppm->vaddr_base); 61 } 51 inline xptr_t ppm_page2base( xptr_t page_xp ) 52 { 53 ppm_t * ppm = &LOCAL_CLUSTER->ppm; 54 55 cxy_t page_cxy = GET_CXY( page_xp ); 56 page_t * page_ptr = (page_t *)GET_PTR( page_xp ); 57 58 void * base_ptr = ppm->vaddr_base + 59 ((page_ptr - ppm->pages_tbl)<<CONFIG_PPM_PAGE_SHIFT); 60 61 return XPTR( page_cxy , base_ptr ); 62 63 } // end ppm_page2base() 64 65 ///////////////////////////////////////////// 66 inline xptr_t ppm_base2page( xptr_t base_xp ) 67 { 68 ppm_t * ppm = &LOCAL_CLUSTER->ppm; 69 70 cxy_t base_cxy = GET_CXY( base_xp ); 71 void * base_ptr = (void *)GET_PTR( base_xp ); 72 73 page_t * page_ptr = ppm->pages_tbl + 74 ((base_ptr - ppm->vaddr_base)>>CONFIG_PPM_PAGE_SHIFT); 75 76 return XPTR( base_cxy , page_ptr ); 77 78 } // end ppm_base2page() 79 80 81 82 /////////////////////////////////////////// 83 inline ppn_t ppm_page2ppn( xptr_t page_xp ) 84 { 85 ppm_t * ppm = &LOCAL_CLUSTER->ppm; 86 87 cxy_t page_cxy = GET_CXY( page_xp ); 88 page_t * page_ptr = (page_t *)GET_PTR( page_xp ); 89 90 paddr_t paddr = PADDR( page_cxy , (page_ptr - ppm->pages_tbl)<<CONFIG_PPM_PAGE_SHIFT ); 91 92 return paddr >> CONFIG_PPM_PAGE_SHIFT; 93 94 } // end hal_page2ppn() 95 96 /////////////////////////////////////// 97 inline xptr_t ppm_ppn2page( ppn_t ppn ) 98 { 99 ppm_t * ppm = &LOCAL_CLUSTER->ppm; 100 101 paddr_t paddr = ppn << CONFIG_PPM_PAGE_SHIFT; 102 103 cxy_t page_cxy = CXY_FROM_PADDR( paddr ); 104 lpa_t page_lpa = LPA_FROM_PADDR( paddr ); 105 106 return XPTR( page_cxy , &ppm->pages_tbl[page_lpa>>CONFIG_PPM_PAGE_SHIFT] ); 107 108 } // end hal_ppn2page 109 110 111 112 /////////////////////////////////////// 113 inline xptr_t ppm_ppn2base( ppn_t ppn ) 114 { 115 ppm_t * ppm = &LOCAL_CLUSTER->ppm; 116 117 paddr_t paddr = ppn << CONFIG_PPM_PAGE_SHIFT; 118 119 cxy_t page_cxy = CXY_FROM_PADDR( paddr ); 120 lpa_t page_lpa = LPA_FROM_PADDR( paddr ); 121 122 void * base_ptr = (void *)ppm->vaddr_base + (page_lpa & ~CONFIG_PPM_PAGE_SHIFT); 123 124 return XPTR( page_cxy , base_ptr ); 125 126 } // end ppm_ppn2base() 127 128 /////////////////////////////////////////// 129 inline ppn_t ppm_base2ppn( xptr_t base_xp ) 130 { 131 ppm_t * ppm = &LOCAL_CLUSTER->ppm; 132 133 cxy_t base_cxy = GET_CXY( base_xp ); 134 void * base_ptr = (void *)GET_PTR( base_xp ); 135 136 paddr_t paddr = PADDR( base_cxy , (base_ptr - ppm->vaddr_base) ); 137 138 return paddr >> CONFIG_PPM_PAGE_SHIFT; 139 140 } // end ppm_base2ppn() 141 142 62 143 63 144 /////////////////////////////////////////// -
trunk/kernel/mm/ppm.h
r313 r315 106 106 inline bool_t ppm_page_is_valid( page_t * page ); 107 107 108 /***************************************************************************************** 109 * Get the page virtual address from the page descriptor pointer. 110 ***************************************************************************************** 111 * @ page : pointer to page descriptor 112 * @ returns virtual address of page itself. 113 ****************************************************************************************/ 114 inline void* ppm_page2vaddr( page_t * page ); 108 115 109 116 110 /***************************************************************************************** 117 * Get the page descriptor pointer from the page virtual address.111 * Get extended pointer on page base from extended pointer on page descriptor. 118 112 ***************************************************************************************** 119 * @ vaddr : page virtual address120 * @ returns pointer on page descriptor113 * @ page_xp : extended pointer to page descriptor 114 * @ returns extended pointer on page base. 121 115 ****************************************************************************************/ 122 inline page_t * ppm_vaddr2page( void * vaddr ); 116 inline xptr_t ppm_page2base( xptr_t page_xp ); 117 118 /***************************************************************************************** 119 * Get extended pointer on page descriptor from extended pointer on page base. 120 ***************************************************************************************** 121 * @ base_xp : extended pointer to page base. 122 * @ returns extended pointer on page descriptor 123 ****************************************************************************************/ 124 inline xptr_t ppm_base2page( xptr_t base_xp ); 125 126 127 128 /***************************************************************************************** 129 * Get extended pointer on page base from Global PPN. 130 ***************************************************************************************** 131 * @ ppn : global physical page number. 132 * @ returns extended pointer on page base. 133 ****************************************************************************************/ 134 inline xptr_t ppm_ppn2base( ppn_t ppn ); 135 136 /***************************************************************************************** 137 * Get global PPN from extended pointer on page base. 138 ***************************************************************************************** 139 * @ base_xp : extended pointer to page base. 140 * @ returns global physical page number. 141 ****************************************************************************************/ 142 inline ppn_t ppm_base2ppn( xptr_t base_xp ); 143 144 145 146 /***************************************************************************************** 147 * Get global PPN from extended pointer on page descriptor. 148 ***************************************************************************************** 149 * @ page_xp : pointer to page descriptor 150 * @ returns global physical page number. 151 ****************************************************************************************/ 152 inline ppn_t ppm_page2ppn( xptr_t page_xp ); 153 154 /***************************************************************************************** 155 * Get extended pointer on page descriptor from global PPN. 156 ***************************************************************************************** 157 * @ ppn : global physical page number 158 * @ returns extended pointer on page descriptor. 159 ****************************************************************************************/ 160 inline xptr_t ppm_ppn2page( ppn_t ppn ); 161 162 123 163 124 164 /***************************************************************************************** -
trunk/kernel/mm/vmm.c
r313 r315 524 524 525 525 // initialize vseg descriptor 526 vseg_init( vseg , base, size , vpn_base , vpn_size , type , local_cxy , 0 , 0);526 vseg_init( vseg , base, size , vpn_base , vpn_size , type , local_cxy ); 527 527 528 528 // update "heap_vseg" in VMM … … 633 633 634 634 // set page table entry 635 ppn = ppm_page2ppn( page);635 ppn = ppm_page2ppn( XPTR( local_cxy , page ) ); 636 636 error = hal_gpt_set_pte( gpt , vpn , ppn , attr ); 637 637 if( error ) … … 752 752 uint32_t type = vseg->type; 753 753 xptr_t mapper_xp = vseg->mapper_xp; 754 uint32_t flags = vseg->flags; 754 755 755 756 // get mapper cluster and local pointer … … 816 817 817 818 // compute missing page offset in .elf file 818 intptr_t page_offset = vseg->file_offset + (page_index << PPM_PAGE_SHIFT); 819 820 // compute both local and extended pointer on page first byte 821 // WARNING : the pages_offset must have the same value in all clusters !!! 822 // to use this ppm_page2vaddr() function for a remote cluster 823 uint8_t * base_ptr = (uint8_t *)ppm_page2vaddr( page_ptr ); 824 xptr_t base_xp = XPTR( page_cxy , base_ptr ); 819 intptr_t page_offset = vseg->file_offset + 820 (page_index << CONFIG_PPM_PAGE_SHIFT); 821 822 // compute extended pointer on page first byte 823 xptr_t base_xp = ppm_page2base( XPTR( page_cxy , page_ptr ) ); 825 824 826 825 // file_size can be smaller than vseg_size for BSS 827 file_size = vseg->file_size;828 829 if( file_size < page_offset ) // pagefully in BSS826 intptr_t file_size = vseg->file_size; 827 828 if( file_size < page_offset ) // fully in BSS 830 829 { 831 830 if( page_cxy == local_cxy ) 832 831 { 833 memset( base_ptr , 0 ,PPM_PAGE_SIZE );832 memset( GET_PTR( base_xp ) , 0 , CONFIG_PPM_PAGE_SIZE ); 834 833 } 835 834 else 836 835 { 837 hal_remote_memset( base_xp , 0 , PPM_PAGE_SIZE );836 hal_remote_memset( base_xp , 0 , CONFIG_PPM_PAGE_SIZE ); 838 837 } 839 838 } 840 else if( file size >= (page_offset + PPM_PAGE_SIZE) ) // pagefully in mapper841 839 else if( file_size >= (page_offset + CONFIG_PPM_PAGE_SIZE) ) // fully in mapper 840 { 842 841 if( mapper_cxy == local_cxy ) 843 842 { … … 846 845 page_offset, 847 846 base_xp, 848 PPM_PAGE_SIZE );847 CONFIG_PPM_PAGE_SIZE ); 849 848 } 850 849 else … … 856 855 page_offset, 857 856 (uint64_t)base_xp, 858 PPM_PAGE_SIZE,857 CONFIG_PPM_PAGE_SIZE, 859 858 &error ); 860 859 } … … 865 864 { 866 865 // initialize mapper part 867 if( mapper_cxy == local_cxy ) // mapper is local866 if( mapper_cxy == local_cxy ) 868 867 { 869 868 error = mapper_move_kernel( mapper_ptr, 870 true, // to _buffer869 true, // to buffer 871 870 page_offset, 872 871 base_xp, 873 872 file_size - page_offset ); 874 873 } 875 else // mapper is remote874 else 876 875 { 877 876 rpc_mapper_move_buffer_client( mapper_cxy, 878 877 mapper_ptr, 879 true, 878 true, // to buffer 880 879 false, // kernel buffer 881 880 page_offset, … … 889 888 if( page_cxy == local_cxy ) 890 889 { 891 memset( base_ptr+ file_size - page_offset , 0 ,892 page_offset + PPM_PAGE_SIZE - file_size );890 memset( GET_PTR( base_xp ) + file_size - page_offset , 0 , 891 page_offset + CONFIG_PPM_PAGE_SIZE - file_size ); 893 892 } 894 893 else 895 894 { 896 895 hal_remote_memset( base_xp + file_size - page_offset , 0 , 897 page_offset + PPM_PAGE_SIZE - file_size );896 page_offset + CONFIG_PPM_PAGE_SIZE - file_size ); 898 897 } 899 898 } … … 902 901 903 902 // return ppn 904 *ppn = hal_page2ppn( XPTR( page_cxy , page_ptr ) );903 *ppn = ppm_page2ppn( XPTR( page_cxy , page_ptr ) ); 905 904 return 0; 906 905 … … 1064 1063 return error; 1065 1064 1066 } 1067 /* 1065 } // end vmm_v2p_translate() 1066 1067 /* deprecated 1068 1068 1069 1069 /////////////////////////////////////////////////////////////////// -
trunk/kernel/mm/vseg.c
r184 r315 92 92 vpn_t vpn_size, 93 93 uint32_t type, 94 cxy_t cxy, 95 fdid_t fdid, 96 uint32_t offset ) 94 cxy_t cxy ) 97 95 { 98 96 vseg->type = type; … … 101 99 vseg->vpn_base = vpn_base; 102 100 vseg->vpn_size = vpn_size; 103 vseg->mapper = XPTR_NULL; 104 vseg->fdid = fdid; 105 vseg->offset = offset; 101 vseg->mapper_xp = XPTR_NULL; 106 102 vseg->cxy = cxy; 107 103 … … 171 167 hal_core_sleep(); 172 168 } 173 } 169 170 } // end vseg_init() 174 171 175 172 ////////////////////////////////////////// … … 182 179 183 180 // initialize vseg with remote_read access 184 vseg->type = hal_remote_lw ( XPTR( cxy , &ptr->type ) ); 185 vseg->min = (intptr_t)hal_remote_lpt( XPTR( cxy , &ptr->min ) ); 186 vseg->max = (intptr_t)hal_remote_lpt( XPTR( cxy , &ptr->max ) ); 187 vseg->vpn_base = hal_remote_lw ( XPTR( cxy , &ptr->vpn_base ) ); 188 vseg->vpn_size = hal_remote_lw ( XPTR( cxy , &ptr->vpn_size ) ); 189 vseg->flags = hal_remote_lw ( XPTR( cxy , &ptr->flags ) ); 190 vseg->mapper = (xptr_t) hal_remote_lwd( XPTR( cxy , &ptr->mapper ) ); 191 192 if( vseg->type == VSEG_TYPE_FILE ) 193 { 194 vseg->fdid = hal_remote_lw( XPTR( cxy , &ptr->fdid ) ); 195 vseg->offset = hal_remote_lw( XPTR( cxy , &ptr->offset ) ); 196 } 197 else 198 { 199 vseg->fdid = 0; 200 vseg->offset = 0; 201 } 181 vseg->type = hal_remote_lw ( XPTR( cxy , &ptr->type ) ); 182 vseg->min = (intptr_t)hal_remote_lpt( XPTR( cxy , &ptr->min ) ); 183 vseg->max = (intptr_t)hal_remote_lpt( XPTR( cxy , &ptr->max ) ); 184 vseg->vpn_base = hal_remote_lw ( XPTR( cxy , &ptr->vpn_base ) ); 185 vseg->vpn_size = hal_remote_lw ( XPTR( cxy , &ptr->vpn_size ) ); 186 vseg->flags = hal_remote_lw ( XPTR( cxy , &ptr->flags ) ); 187 vseg->mapper_xp = (xptr_t) hal_remote_lwd( XPTR( cxy , &ptr->mapper_xp ) ); 202 188 } 203 189 -
trunk/kernel/mm/vseg.h
r313 r315 81 81 vpn_t vpn_size; /*! number of pages occupied */ 82 82 uint32_t flags; /*! vseg attributes */ 83 xptr_t file_mapper;/*! xptr on remote mapper (for types CODE / DATA / FILE) */84 intptr_t file_offset; /*! offset in file (for types CODE / DATA / FILE)*/85 intptr_t file_size; /*! max segment size in mapper (for type DATA)*/86 cxy_t cxy; /*! cluster for physical mapping (for non distributed)*/83 xptr_t mapper_xp; /*! xptr on remote mapper (for types CODE / DATA / FILE) */ 84 intptr_t file_offset; /*! vseg offset in file (for types CODE/DATA) */ 85 intptr_t file_size; /*! max segment size in mapper (for type CODE/DATA) */ 86 cxy_t cxy; /*! physical mapping (for non distributed vseg) */ 87 87 } 88 88 vseg_t; … … 123 123 * @ type : vseg type. 124 124 * @ cxy : target cluster for physical mapping. 125 * @ fdid : file descriptor index if VSEG_TYPE_FILE.126 * @ offset : offset in file if VSEG_TYPE_FILE.127 125 *********************************************************************************************/ 128 126 void vseg_init( vseg_t * vseg, … … 132 130 vpn_t vpn_size, 133 131 uint32_t type, 134 cxy_t cxy, 135 fdid_t fdid, 136 uint32_t offset ); 132 cxy_t cxy ); 137 133 138 134 /**********************************************************************************************
Note: See TracChangeset
for help on using the changeset viewer.