|
[ source navigation ] [ diff markup ] [ identifier search ] [ general search ] |
|||
|
001 /* Copyright (C) 2004 David Decotigny 001 /* Copyright (C) 2004 David Decotigny 002 002 003 This program is free software; you can redi 003 This program is free software; you can redistribute it and/or 004 modify it under the terms of the GNU Genera 004 modify it under the terms of the GNU General Public License 005 as published by the Free Software Foundatio 005 as published by the Free Software Foundation; either version 2 006 of the License, or (at your option) any lat 006 of the License, or (at your option) any later version. 007 007 008 This program is distributed in the hope tha 008 This program is distributed in the hope that it will be useful, 009 but WITHOUT ANY WARRANTY; without even the 009 but WITHOUT ANY WARRANTY; without even the implied warranty of 010 MERCHANTABILITY or FITNESS FOR A PARTICULAR 010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 011 GNU General Public License for more details 011 GNU General Public License for more details. 012 012 013 You should have received a copy of the GNU 013 You should have received a copy of the GNU General Public License 014 along with this program; if not, write to t 014 along with this program; if not, write to the Free Software 015 Foundation, Inc., 59 Temple Place - Suite 3 015 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 016 USA. 016 USA. 017 */ 017 */ 018 #ifndef _SOS_PAGING_H_ 018 #ifndef _SOS_PAGING_H_ 019 #define _SOS_PAGING_H_ 019 #define _SOS_PAGING_H_ 020 020 021 /** 021 /** 022 * @file paging.h 022 * @file paging.h 023 * 023 * 024 * MMU management routines (arch-dependent). S 024 * MMU management routines (arch-dependent). Setup the MMU without 025 * identity-mapping physical<->virtual address 025 * identity-mapping physical<->virtual addresses over the whole 026 * physical address space: a single, restricte 026 * physical address space: a single, restricted and known, area is 027 * identity-mapped, the remaining kernel/user 027 * identity-mapped, the remaining kernel/user space is not. To access 028 * and manage the MMU translation tables (PD/P 028 * and manage the MMU translation tables (PD/PT on x86), we rely on a 029 * particular configuration, called "mirroring 029 * particular configuration, called "mirroring", where the top-level 030 * translation table (PD on x86) maps itself a 030 * translation table (PD on x86) maps itself at a known and fixed (virtual) 031 * address. The only assumption for this to be 031 * address. The only assumption for this to be possible is that the 032 * structure of the translation table entries 032 * structure of the translation table entries are compatible at the 033 * different levels of vadddr->paddr translati 033 * different levels of vadddr->paddr translation process (PDE and PTE 034 * on x86 are Ok). Credits go to Christophe Av 034 * on x86 are Ok). Credits go to Christophe Avoinne for that. 035 */ 035 */ 036 036 037 #include <sos/types.h> 037 #include <sos/types.h> 038 #include <sos/errno.h> 038 #include <sos/errno.h> 039 039 >> 040 >> 041 /** >> 042 * Basic SOS virtual memory organization >> 043 */ >> 044 /** Frontier between kernel and user space virtual addresses */ >> 045 #define SOS_PAGING_BASE_USER_ADDRESS (0x40000000) /* 1GB */ >> 046 #define SOS_PAGING_TOP_USER_ADDRESS (0xFFFFFFFF) /* 4GB */ >> 047 >> 048 /** Length of the space reserved for the mirroring in the kernel >> 049 virtual space */ >> 050 #define SOS_PAGING_MIRROR_SIZE (1 << 22) /* 1 PD = 1024 Page Tables = 4MB */ >> 051 >> 052 /** Virtual address where the mirroring takes place */ >> 053 #define SOS_PAGING_MIRROR_VADDR \ >> 054 (SOS_PAGING_BASE_USER_ADDRESS - SOS_PAGING_MIRROR_SIZE) >> 055 >> 056 040 /** 057 /** 041 * sos_paging_map flags 058 * sos_paging_map flags 042 */ 059 */ 043 /** Usual virtual memory access rights */ 060 /** Usual virtual memory access rights */ 044 #define SOS_VM_MAP_PROT_NONE 0 061 #define SOS_VM_MAP_PROT_NONE 0 045 #define SOS_VM_MAP_PROT_READ (1<<0) 062 #define SOS_VM_MAP_PROT_READ (1<<0) 046 #define SOS_VM_MAP_PROT_WRITE (1<<1) 063 #define SOS_VM_MAP_PROT_WRITE (1<<1) 047 /* EXEC not supported */ 064 /* EXEC not supported */ >> 065 048 /** Mapping a page may involve an physical pag 066 /** Mapping a page may involve an physical page allocation (for a new 049 PT), hence may potentially block */ 067 PT), hence may potentially block */ 050 #define SOS_VM_MAP_ATOMIC (1<<31) 068 #define SOS_VM_MAP_ATOMIC (1<<31) 051 069 052 /** Virtual address where the mirroring takes << 053 #define SOS_PAGING_MIRROR_VADDR 0x3fc00000 /* << 054 /** Length of the space reserved for the mirro << 055 virtual space */ << 056 #define SOS_PAGING_MIRROR_SIZE (1 << 22) /* << 057 070 058 /** 071 /** 059 * Setup initial page directory structure wher 072 * Setup initial page directory structure where the kernel is 060 * identically-mapped, and the mirroring. This 073 * identically-mapped, and the mirroring. This routine also 061 * identity-maps the BIOS and video areas, to 074 * identity-maps the BIOS and video areas, to allow some debugging 062 * text to be printed to the console. Finally, 075 * text to be printed to the console. Finally, this routine installs 063 * the whole configuration into the MMU. 076 * the whole configuration into the MMU. 064 */ 077 */ 065 sos_ret_t sos_paging_subsystem_setup(sos_paddr 078 sos_ret_t sos_paging_subsystem_setup(sos_paddr_t identity_mapping_base, 066 sos_paddr 079 sos_paddr_t identity_mapping_top); 067 080 068 /** 081 /** 069 * Map the given physical page at the given vi 082 * Map the given physical page at the given virtual address in the 070 * current address space. 083 * current address space. 071 * 084 * 072 * @note *IMPORTANT*: The physical page ppage_ 085 * @note *IMPORTANT*: The physical page ppage_paddr *MUST* have been 073 * referenced by the caller through either a c 086 * referenced by the caller through either a call to 074 * sos_physmem_ref_physpage_new() or sos_physm 087 * sos_physmem_ref_physpage_new() or sos_physmem_ref_physpage_at(). It 075 * would work if this were untrue, but this wo 088 * would work if this were untrue, but this would be INCORRECT (it is 076 * expected that one is owning the page before 089 * expected that one is owning the page before mapping it, or 077 * otherwise the page could have been stolen b 090 * otherwise the page could have been stolen by an interrupt or 078 * another thread). 091 * another thread). 079 * 092 * 080 * @param ppage_paddr The address of a physic 093 * @param ppage_paddr The address of a physical page (page-aligned) 081 * @param vpage_vaddr The address of the virt 094 * @param vpage_vaddr The address of the virtual page (page-aligned) 082 * @param is_user_page TRUE when the page is a 095 * @param is_user_page TRUE when the page is available from user space 083 * @param flags A mask made of SOS_VM_* 096 * @param flags A mask made of SOS_VM_* bits 084 * 097 * 085 * @note Unless the SOS_VM_MAP_ATOMIC bit is s 098 * @note Unless the SOS_VM_MAP_ATOMIC bit is set in the flags, the 086 * function may potentially block, because a p 099 * function may potentially block, because a physical page may be 087 * allocated for a new PT. 100 * allocated for a new PT. 088 */ 101 */ 089 sos_ret_t sos_paging_map(sos_paddr_t ppage_pad 102 sos_ret_t sos_paging_map(sos_paddr_t ppage_paddr, 090 sos_vaddr_t vpage_vad 103 sos_vaddr_t vpage_vaddr, 091 sos_bool_t is_user_pa 104 sos_bool_t is_user_page, 092 sos_ui32_t flags); 105 sos_ui32_t flags); 093 106 094 /** 107 /** 095 * Undo the mapping from vaddr to the underlyi 108 * Undo the mapping from vaddr to the underlying physical page (if any) 096 * @param vpage_vaddr The address of the virt 109 * @param vpage_vaddr The address of the virtual page (page-aligned) 097 */ 110 */ 098 sos_ret_t sos_paging_unmap(sos_vaddr_t vpage_v 111 sos_ret_t sos_paging_unmap(sos_vaddr_t vpage_vaddr); 099 112 100 /** 113 /** 101 * Return the page protection flags (SOS_VM_MA 114 * Return the page protection flags (SOS_VM_MAP_PROT_*) associated 102 * with the address, or SOS_VM_MAP_PROT_NONE w 115 * with the address, or SOS_VM_MAP_PROT_NONE when page is not mapped 103 */ 116 */ 104 int sos_paging_get_prot(sos_vaddr_t vaddr); 117 int sos_paging_get_prot(sos_vaddr_t vaddr); 105 118 106 /** 119 /** 107 * Return the physical address of the given vi 120 * Return the physical address of the given virtual address. Since page 108 * at physical addr 0 is not mapped, the NULL 121 * at physical addr 0 is not mapped, the NULL result means "page not 109 * mapped". 122 * mapped". 110 */ 123 */ 111 sos_paddr_t sos_paging_get_paddr(sos_vaddr_t v 124 sos_paddr_t sos_paging_get_paddr(sos_vaddr_t vaddr); 112 125 113 /** 126 /** 114 * Tell whether the address is physically mapp 127 * Tell whether the address is physically mapped 115 */ 128 */ 116 #define sos_paging_check_present(vaddr) \ 129 #define sos_paging_check_present(vaddr) \ 117 (sos_paging_get_paddr(vaddr) != NULL) 130 (sos_paging_get_paddr(vaddr) != NULL) 118 << 119 131 120 #endif /* _SOS_PAGING_H_ */ 132 #endif /* _SOS_PAGING_H_ */
[ source navigation ] | [ diff markup ] | [ identifier search ] | [ general search ] |