|
[ source navigation ] [ diff markup ] [ identifier search ] [ general search ] |
|||
|
001 /* Copyright (C) 2004 David Decotigny 001 /* Copyright (C) 2004 David Decotigny 002 Copyright (C) 2000 The KOS Team << 003 002 004 This program is free software; you can redi 003 This program is free software; you can redistribute it and/or 005 modify it under the terms of the GNU Genera 004 modify it under the terms of the GNU General Public License 006 as published by the Free Software Foundatio 005 as published by the Free Software Foundation; either version 2 007 of the License, or (at your option) any lat 006 of the License, or (at your option) any later version. 008 007 009 This program is distributed in the hope tha 008 This program is distributed in the hope that it will be useful, 010 but WITHOUT ANY WARRANTY; without even the 009 but WITHOUT ANY WARRANTY; without even the implied warranty of 011 MERCHANTABILITY or FITNESS FOR A PARTICULAR 010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 GNU General Public License for more details 011 GNU General Public License for more details. 013 012 014 You should have received a copy of the GNU 013 You should have received a copy of the GNU General Public License 015 along with this program; if not, write to t 014 along with this program; if not, write to the Free Software 016 Foundation, Inc., 59 Temple Place - Suite 3 015 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 017 USA. 016 USA. 018 */ 017 */ 019 #ifndef _SOS_PHYSMEM_H_ 018 #ifndef _SOS_PHYSMEM_H_ 020 #define _SOS_PHYSMEM_H_ 019 #define _SOS_PHYSMEM_H_ 021 020 022 /** 021 /** 023 * @file physmem.h 022 * @file physmem.h 024 * 023 * 025 * Physical pages of memory 024 * Physical pages of memory 026 */ 025 */ 027 026 028 #include <sos/errno.h> 027 #include <sos/errno.h> 029 #include <sos/types.h> 028 #include <sos/types.h> 030 #include <sos/macros.h> 029 #include <sos/macros.h> 031 030 032 /** The size of a physical page (arch-dependen 031 /** The size of a physical page (arch-dependent) */ 033 #define SOS_PAGE_SIZE (4*1024) 032 #define SOS_PAGE_SIZE (4*1024) 034 033 035 /** The corresponding shift */ 034 /** The corresponding shift */ 036 #define SOS_PAGE_SHIFT 12 /* 4 kB = 2^12 B */ 035 #define SOS_PAGE_SHIFT 12 /* 4 kB = 2^12 B */ 037 036 038 /** The corresponding mask */ 037 /** The corresponding mask */ 039 #define SOS_PAGE_MASK ((1<<12) - 1) 038 #define SOS_PAGE_MASK ((1<<12) - 1) 040 039 041 #define SOS_PAGE_ALIGN_INF(val) \ 040 #define SOS_PAGE_ALIGN_INF(val) \ 042 SOS_ALIGN_INF((val), SOS_PAGE_SIZE) 041 SOS_ALIGN_INF((val), SOS_PAGE_SIZE) 043 #define SOS_PAGE_ALIGN_SUP(val) \ 042 #define SOS_PAGE_ALIGN_SUP(val) \ 044 SOS_ALIGN_SUP((val), SOS_PAGE_SIZE) 043 SOS_ALIGN_SUP((val), SOS_PAGE_SIZE) 045 #define SOS_IS_PAGE_ALIGNED(val) \ 044 #define SOS_IS_PAGE_ALIGNED(val) \ 046 SOS_IS_ALIGNED((val), SOS_PAGE_SIZE) 045 SOS_IS_ALIGNED((val), SOS_PAGE_SIZE) 047 046 048 /** 047 /** 049 * This is the reserved physical interval for 048 * This is the reserved physical interval for the x86 video memory and 050 * BIOS area. In physmem.c, we have to mark th 049 * BIOS area. In physmem.c, we have to mark this area as "used" in 051 * order to prevent from allocating it. And in 050 * order to prevent from allocating it. And in paging.c, we'd better 052 * map it in virtual space if we really want t 051 * map it in virtual space if we really want to be able to print to 053 * the screen (for debugging purpose, at least 052 * the screen (for debugging purpose, at least): for this, the 054 * simplest is to identity-map this area in vi 053 * simplest is to identity-map this area in virtual space (note 055 * however that this mapping could also be non 054 * however that this mapping could also be non-identical). 056 */ 055 */ 057 #define BIOS_N_VIDEO_START 0xa0000 056 #define BIOS_N_VIDEO_START 0xa0000 058 #define BIOS_N_VIDEO_END 0x100000 057 #define BIOS_N_VIDEO_END 0x100000 059 058 060 059 061 /** 060 /** 062 * Initialize the physical memory subsystem, f 061 * Initialize the physical memory subsystem, for the physical area [0, 063 * ram_size). This routine takes into account 062 * ram_size). This routine takes into account the BIOS and video 064 * areas, to prevent them from future allocati 063 * areas, to prevent them from future allocations. 065 * 064 * 066 * @param ram_size The size of the RAM that wi 065 * @param ram_size The size of the RAM that will be managed by this subsystem 067 * 066 * 068 * @param kernel_core_base The lowest address 067 * @param kernel_core_base The lowest address for which the kernel 069 * assumes identity mapping (ie virtual addres 068 * assumes identity mapping (ie virtual address == physical address) 070 * will be stored here 069 * will be stored here 071 * 070 * 072 * @param kernel_core_top The top address for 071 * @param kernel_core_top The top address for which the kernel 073 * assumes identity mapping (ie virtual addres 072 * assumes identity mapping (ie virtual address == physical address) 074 * will be stored here 073 * will be stored here 075 */ 074 */ 076 sos_ret_t sos_physmem_subsystem_setup(sos_size 075 sos_ret_t sos_physmem_subsystem_setup(sos_size_t ram_size, 077 /* out * 076 /* out */sos_paddr_t *kernel_core_base, 078 /* out * 077 /* out */sos_paddr_t *kernel_core_top); 079 078 080 /** 079 /** 081 * Retrieve the total number of pages, and the 080 * Retrieve the total number of pages, and the number of free pages 082 */ 081 */ 083 sos_ret_t sos_physmem_get_state(/* out */sos_c 082 sos_ret_t sos_physmem_get_state(/* out */sos_count_t *total_ppages, 084 /* out */sos_c 083 /* out */sos_count_t *used_ppages); 085 084 086 085 087 /** 086 /** 088 * Get a free page. 087 * Get a free page. 089 * 088 * 090 * @return The (physical) address of the (phys 089 * @return The (physical) address of the (physical) page allocated, or 091 * NULL when none currently available. 090 * NULL when none currently available. 092 * 091 * 093 * @param can_block TRUE if the function is al 092 * @param can_block TRUE if the function is allowed to block 094 * @note The page returned has a reference cou 093 * @note The page returned has a reference count equal to 1. 095 */ 094 */ 096 sos_paddr_t sos_physmem_ref_physpage_new(sos_b 095 sos_paddr_t sos_physmem_ref_physpage_new(sos_bool_t can_block); 097 096 098 097 099 /** 098 /** 100 * Increment the reference count of a given ph 099 * Increment the reference count of a given physical page. Useful for 101 * VM code which tries to map a precise physic 100 * VM code which tries to map a precise physical address. 102 * 101 * 103 * @param ppage_paddr Physical address of the 102 * @param ppage_paddr Physical address of the page (MUST be page-aligned) 104 * 103 * 105 * @return TRUE when the page was previously i 104 * @return TRUE when the page was previously in use, FALSE when the 106 * page was previously in the free list, <0 wh 105 * page was previously in the free list, <0 when the page address is 107 * invalid. 106 * invalid. 108 */ 107 */ 109 sos_ret_t sos_physmem_ref_physpage_at(sos_padd 108 sos_ret_t sos_physmem_ref_physpage_at(sos_paddr_t ppage_paddr); 110 109 111 110 112 /** 111 /** 113 * Decrement the reference count of the given 112 * Decrement the reference count of the given physical page. When this 114 * reference count reaches 0, the page is mark 113 * reference count reaches 0, the page is marked free, ie is available 115 * for future sos_physmem_get_physpage() 114 * for future sos_physmem_get_physpage() 116 * 115 * 117 * @param ppage_paddr Physical address of the 116 * @param ppage_paddr Physical address of the page (MUST be page-aligned) 118 * 117 * 119 * @return FALSE when the page is still in use 118 * @return FALSE when the page is still in use, TRUE when the page is now 120 * unreferenced, <0 when the page address is i 119 * unreferenced, <0 when the page address is invalid 121 */ 120 */ 122 sos_ret_t sos_physmem_unref_physpage(sos_paddr 121 sos_ret_t sos_physmem_unref_physpage(sos_paddr_t ppage_paddr); 123 122 124 123 125 #include <sos/kmem_vmm.h> 124 #include <sos/kmem_vmm.h> 126 125 127 /** 126 /** 128 * Return the kernel memory allocation range a 127 * Return the kernel memory allocation range associated with the given 129 * physical page, or NULL when page has no ass 128 * physical page, or NULL when page has no associated range 130 * 129 * 131 * @param ppage_paddr Physical address of the 130 * @param ppage_paddr Physical address of the page (MUST be page-aligned) 132 */ 131 */ 133 struct sos_kmem_range* sos_physmem_get_kmem_ra 132 struct sos_kmem_range* sos_physmem_get_kmem_range(sos_paddr_t ppage_paddr); 134 133 135 134 136 /** 135 /** 137 * Set the kernel memory allocation range asso 136 * Set the kernel memory allocation range associated to the given 138 * physical page. 137 * physical page. 139 * 138 * 140 * @param ppage_paddr Physical address of the 139 * @param ppage_paddr Physical address of the page (MUST be page-aligned) 141 * 140 * 142 * @return error if page is invalid 141 * @return error if page is invalid 143 */ 142 */ 144 sos_ret_t sos_physmem_set_kmem_range(sos_paddr 143 sos_ret_t sos_physmem_set_kmem_range(sos_paddr_t ppage_paddr, 145 struct so 144 struct sos_kmem_range *range); 146 145 147 #endif /* _SOS_PHYSMEM_H_ */ 146 #endif /* _SOS_PHYSMEM_H_ */
[ source navigation ] | [ diff markup ] | [ identifier search ] | [ general search ] |