SimpleOS

LXR

Navigation



Site hébergé par : enix

The LXR Cross Referencer for SOS

source navigation ]
diff markup ]
identifier search ]
general search ]
 
 
Article:1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 6.5 ] [ 7 ] [ 7.5 ] [ 8 ] [ 9 ] [ 9.5 ]

Diff markup

Differences between /hwcore/paging.h (Article 9.5) and /hwcore/paging.h (Article 7)


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                                                   040 
041 /**                                               041 /**
042  * Basic SOS virtual memory organization          042  * Basic SOS virtual memory organization
043  */                                               043  */
044 /** Frontier between kernel and user space vir    044 /** Frontier between kernel and user space virtual addresses */
045 #define SOS_PAGING_BASE_USER_ADDRESS (0x400000    045 #define SOS_PAGING_BASE_USER_ADDRESS (0x40000000) /* 1GB (must be 4MB-aligned) */
046 #define SOS_PAGING_TOP_USER_ADDRESS  (0xFFFFFF    046 #define SOS_PAGING_TOP_USER_ADDRESS  (0xFFFFFFFF) /* 4GB - 1B */
047 #define SOS_PAGING_USER_SPACE_SIZE   (0xc00000    047 #define SOS_PAGING_USER_SPACE_SIZE   (0xc0000000) /* 3GB */
048                                                   048 
049 /** Length of the space reserved for the mirro    049 /** Length of the space reserved for the mirroring in the kernel
050     virtual space */                              050     virtual space */
051 #define SOS_PAGING_MIRROR_SIZE  (1 << 22)  /*     051 #define SOS_PAGING_MIRROR_SIZE  (1 << 22)  /* 1 PD = 1024 Page Tables = 4MB */
052                                                   052 
053 /** Virtual address where the mirroring takes     053 /** Virtual address where the mirroring takes place */
054 #define SOS_PAGING_MIRROR_VADDR \                 054 #define SOS_PAGING_MIRROR_VADDR \
055    (SOS_PAGING_BASE_USER_ADDRESS - SOS_PAGING_    055    (SOS_PAGING_BASE_USER_ADDRESS - SOS_PAGING_MIRROR_SIZE)
056                                                   056 
057                                                   057 
058 /**                                               058 /**
059  * sos_paging_map flags                           059  * sos_paging_map flags
060  */                                               060  */
061 /** Usual virtual memory access rights */         061 /** Usual virtual memory access rights */
062 #define SOS_VM_MAP_PROT_NONE  0                   062 #define SOS_VM_MAP_PROT_NONE  0
063 #define SOS_VM_MAP_PROT_READ  (1<<0)              063 #define SOS_VM_MAP_PROT_READ  (1<<0)
064 #define SOS_VM_MAP_PROT_WRITE (1<<1)              064 #define SOS_VM_MAP_PROT_WRITE (1<<1)
065 #define SOS_VM_MAP_PROT_EXEC  (1<<2) /* Not su    065 #define SOS_VM_MAP_PROT_EXEC  (1<<2) /* Not supported on IA32 */
066                                                   066 
067 /** Mapping a page may involve an physical pag    067 /** Mapping a page may involve an physical page allocation (for a new
068     PT), hence may potentially block */           068     PT), hence may potentially block */
069 #define SOS_VM_MAP_ATOMIC     (1<<31)             069 #define SOS_VM_MAP_ATOMIC     (1<<31)
070                                                   070 
071                                                   071 
072 /**                                               072 /**
073  * Setup initial page directory structure wher    073  * Setup initial page directory structure where the kernel is
074  * identically-mapped, and the mirroring. This    074  * identically-mapped, and the mirroring. This routine also
075  * identity-maps the BIOS and video areas, to     075  * identity-maps the BIOS and video areas, to allow some debugging
076  * text to be printed to the console. Finally,    076  * text to be printed to the console. Finally, this routine installs
077  * the whole configuration into the MMU.          077  * the whole configuration into the MMU.
078  */                                               078  */
079 sos_ret_t sos_paging_subsystem_setup(sos_paddr    079 sos_ret_t sos_paging_subsystem_setup(sos_paddr_t identity_mapping_base,
080                                      sos_paddr    080                                      sos_paddr_t identity_mapping_top);
081                                                   081 
082                                                << 
083 /**                                               082 /**
084  * Map the given physical page at the given vi    083  * Map the given physical page at the given virtual address in the
085  * current address space.                         084  * current address space.
086  *                                                085  *
087  * @note *IMPORTANT*: The physical page ppage_    086  * @note *IMPORTANT*: The physical page ppage_paddr *MUST* have been
088  * referenced by the caller through either a c    087  * referenced by the caller through either a call to
089  * sos_physmem_ref_physpage_new() or sos_physm    088  * sos_physmem_ref_physpage_new() or sos_physmem_ref_physpage_at(). It
090  * would work if this were untrue, but this wo    089  * would work if this were untrue, but this would be INCORRECT (it is
091  * expected that one is owning the page before    090  * expected that one is owning the page before mapping it, or
092  * otherwise the page could have been stolen b    091  * otherwise the page could have been stolen by an interrupt or
093  * another thread).                               092  * another thread).
094  *                                                093  *
095  * @param ppage_paddr  The address of a physic    094  * @param ppage_paddr  The address of a physical page (page-aligned)
096  * @param vpage_vaddr  The address of the virt    095  * @param vpage_vaddr  The address of the virtual page (page-aligned)
097  * @param is_user_page TRUE when the page is a    096  * @param is_user_page TRUE when the page is available from user space
098  * @param flags        A mask made of SOS_VM_*    097  * @param flags        A mask made of SOS_VM_* bits
099  *                                                098  *
100  * @note Unless the SOS_VM_MAP_ATOMIC bit is s    099  * @note Unless the SOS_VM_MAP_ATOMIC bit is set in the flags, the
101  * function may potentially block, because a p    100  * function may potentially block, because a physical page may be
102  * allocated for a new PT.                        101  * allocated for a new PT.
103  */                                               102  */
104 sos_ret_t sos_paging_map(sos_paddr_t ppage_pad    103 sos_ret_t sos_paging_map(sos_paddr_t ppage_paddr,
105                          sos_vaddr_t vpage_vad    104                          sos_vaddr_t vpage_vaddr,
106                          sos_bool_t is_user_pa    105                          sos_bool_t is_user_page,
107                          sos_ui32_t flags);       106                          sos_ui32_t flags);
108                                                   107 
109 /**                                               108 /**
110  * Undo the mapping from vaddr to the underlyi    109  * Undo the mapping from vaddr to the underlying physical page (if any)
111  * @param vpage_vaddr  The address of the virt    110  * @param vpage_vaddr  The address of the virtual page (page-aligned)
112  *                                                111  *
113  * @return >= 0 when OK (the number of bytes o    112  * @return >= 0 when OK (the number of bytes of RAM unmapped), < 0 on error
114  */                                               113  */
115 sos_ret_t sos_paging_unmap(sos_vaddr_t vpage_v    114 sos_ret_t sos_paging_unmap(sos_vaddr_t vpage_vaddr);
116                                                   115 
117 /**                                               116 /**
118  * Undo the mapping from [vaddr .. vaddr + siz    117  * Undo the mapping from [vaddr .. vaddr + size[ to the underlying
119  * physical pages (if any)                        118  * physical pages (if any)
120  * @param vpage_vaddr The address of the virtu    119  * @param vpage_vaddr The address of the virtual page (page-aligned)
121  * @param size        The size (in bytes) to u    120  * @param size        The size (in bytes) to unmap. MUST be page-aligned
122  */                                               121  */
123 sos_ret_t sos_paging_unmap_interval(sos_vaddr_    122 sos_ret_t sos_paging_unmap_interval(sos_vaddr_t base_vpage_vaddr,
124                                     sos_size_t    123                                     sos_size_t  size);
125                                                   124 
126 /**                                               125 /**
127  * Return the page protection flags (SOS_VM_MA    126  * Return the page protection flags (SOS_VM_MAP_PROT_*) associated
128  * with the address, or SOS_VM_MAP_PROT_NONE w    127  * with the address, or SOS_VM_MAP_PROT_NONE when page is not mapped
129  */                                               128  */
130 sos_ui32_t sos_paging_get_prot(sos_vaddr_t vad    129 sos_ui32_t sos_paging_get_prot(sos_vaddr_t vaddr);
131                                                   130 
132 /**                                               131 /**
133  * Change the page access rights                  132  * Change the page access rights
134  */                                               133  */
135 sos_ret_t sos_paging_set_prot(sos_vaddr_t vadd    134 sos_ret_t sos_paging_set_prot(sos_vaddr_t vaddr,
136                               sos_ui32_t  new_    135                               sos_ui32_t  new_prot);
137                                                   136 
138                                                << 
139 /**                                            << 
140  * Get the "dirty" status of the page          << 
141  */                                            << 
142 sos_bool_t sos_paging_is_dirty(sos_vaddr_t vad << 
143                                                << 
144 /**                                            << 
145  * Change the "dirty" status of the page       << 
146  */                                            << 
147 sos_ret_t sos_paging_set_dirty(sos_vaddr_t vad << 
148                                sos_bool_t is_d << 
149                                                << 
150                                                << 
151 /**                                               137 /**
152  * Change the access rights of the mapping fro    138  * Change the access rights of the mapping from [vaddr .. vaddr +
153  * size[ to the underlying physical pages (if     139  * size[ to the underlying physical pages (if any)
154  * @param vpage_vaddr The address of the virtu    140  * @param vpage_vaddr The address of the virtual page (page-aligned)
155  * @param size        The size (in bytes) to u    141  * @param size        The size (in bytes) to unmap. MUST be page-aligned
156  */                                               142  */
157 sos_ret_t sos_paging_set_prot_of_interval(sos_    143 sos_ret_t sos_paging_set_prot_of_interval(sos_vaddr_t vaddr,
158                                           sos_    144                                           sos_size_t  size,
159                                           sos_    145                                           sos_ui32_t  new_prot);
160                                                   146 
161 /**                                               147 /**
162  * Return the physical address of the given vi    148  * Return the physical address of the given virtual address. Since page
163  * at physical addr 0 is not mapped, the NULL     149  * at physical addr 0 is not mapped, the NULL result means "page not
164  * mapped".                                       150  * mapped".
165  */                                               151  */
166 sos_paddr_t sos_paging_get_paddr(sos_vaddr_t v    152 sos_paddr_t sos_paging_get_paddr(sos_vaddr_t vaddr);
167                                                   153 
168 /**                                               154 /**
169  * Tell whether the address is physically mapp    155  * Tell whether the address is physically mapped
170  */                                               156  */
171 #define sos_paging_check_present(vaddr) \         157 #define sos_paging_check_present(vaddr) \
172   (sos_paging_get_paddr(vaddr) != NULL)           158   (sos_paging_get_paddr(vaddr) != NULL)
173                                                   159 
174                                                   160 
175 /* *******************************************    161 /* *************************************************
176  * Functions restricted to mm_context module      162  * Functions restricted to mm_context module
177  */                                               163  */
178                                                   164 
179                                                   165 
180 /**                                               166 /**
181  * Release the references to all the reference    167  * Release the references to all the referenced pages (and PT on
182  * x86). On x86, this applies only to the USER    168  * x86). On x86, this applies only to the USER pages and PT.
183  */                                               169  */
184 sos_ret_t sos_paging_dispose(sos_vaddr_t vaddr    170 sos_ret_t sos_paging_dispose(sos_vaddr_t vaddr_PD);
185                                                   171 
186                                                   172 
187 /**                                               173 /**
188  * Copy the MMU configuration related to the k    174  * Copy the MMU configuration related to the kernel virtual area
189  */                                               175  */
190 sos_ret_t sos_paging_copy_kernel_space(sos_vad    176 sos_ret_t sos_paging_copy_kernel_space(sos_vaddr_t dest_vaddr_PD,
191                                        sos_vad    177                                        sos_vaddr_t src_vaddr_PD);
192                                                   178 
193                                                   179 
194 /**                                               180 /**
195  * Copy the MMU configuration related to the u << 
196  */                                            << 
197 sos_ret_t sos_paging_copy_user_space(sos_vaddr << 
198                                      sos_vaddr << 
199                                                << 
200                                                << 
201 /**                                            << 
202  * Prepare the *current* address space for COW << 
203  * mapping                                     << 
204  */                                            << 
205 sos_ret_t sos_paging_prepare_COW(sos_uaddr_t b << 
206                                  sos_size_t le << 
207                                                << 
208                                                << 
209 /**                                            << 
210  * Try to resolve the given page fault excepti << 
211  *                                             << 
212  * @param uaddr The user-space address (of the << 
213  * the faulting access                         << 
214  *                                             << 
215  * @return TRUE if the page fault was a real C << 
216  * FALSE if the page fault is not subject to C << 
217  * mapped at this address). <0 in case the giv << 
218  * COW BUT could not be resolved due to runtim << 
219  */                                            << 
220 sos_ret_t sos_paging_try_resolve_COW(sos_uaddr << 
221                                                << 
222                                                << 
223 /**                                            << 
224  * Retrieve the current physical address of th    181  * Retrieve the current physical address of the PD
225  */                                               182  */
226 sos_paddr_t sos_paging_get_current_PD_paddr(vo !! 183 sos_paddr_t sos_paging_get_current_PD_paddr();
227                                                   184 
228                                                   185 
229 /**                                               186 /**
230  * Change the current MMU configuration.          187  * Change the current MMU configuration.
231  *                                                188  *
232  * @note DANGEROUS. Don't use it unless you kn    189  * @note DANGEROUS. Don't use it unless you know exactly what you're
233  * doing !                                        190  * doing !
234  */                                               191  */
235 sos_ret_t sos_paging_set_current_PD_paddr(sos_    192 sos_ret_t sos_paging_set_current_PD_paddr(sos_paddr_t paddr_PD);
236                                                   193 
237 #endif /* _SOS_PAGING_H_ */                       194 #endif /* _SOS_PAGING_H_ */
                                                      

source navigation ] diff markup ] identifier search ] general search ]