page.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2005 Martin Decky
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00035 #ifndef __ppc64_PAGE_H__
00036 #define __ppc64_PAGE_H__
00037 
00038 #include <arch/mm/frame.h>
00039 
00040 #define PAGE_WIDTH      FRAME_WIDTH
00041 #define PAGE_SIZE       FRAME_SIZE
00042 
00043 #ifdef KERNEL
00044 
00045 #ifndef __ASM__
00046 #       define KA2PA(x) (((__address) (x)) - 0x80000000)
00047 #       define PA2KA(x) (((__address) (x)) + 0x80000000)
00048 #else
00049 #       define KA2PA(x) ((x) - 0x80000000)
00050 #       define PA2KA(x) ((x) + 0x80000000)
00051 #endif
00052 
00053 /*
00054  * Implementation of generic 4-level page table interface,
00055  * the hardware Page Hash Table is used as cache.
00056  *
00057  * Page table layout:
00058  * - 32-bit virtual addressess
00059  * - Offset is 12 bits => pages are 4K long
00060  * - PTL0 has 1024 entries (10 bits)
00061  * - PTL1 is not used
00062  * - PTL2 is not used
00063  * - PLT3 has 1024 entries (10 bits)
00064  */
00065 
00066 #define PTL0_ENTRIES_ARCH       1024
00067 #define PTL1_ENTRIES_ARCH       0
00068 #define PTL2_ENTRIES_ARCH       0
00069 #define PTL3_ENTRIES_ARCH       1024
00070 
00071 #define PTL0_INDEX_ARCH(vaddr)  (((vaddr) >> 22) & 0x3ff)
00072 #define PTL1_INDEX_ARCH(vaddr)  0
00073 #define PTL2_INDEX_ARCH(vaddr)  0
00074 #define PTL3_INDEX_ARCH(vaddr)  (((vaddr) >> 12) & 0x3ff)
00075 
00076 #define GET_PTL1_ADDRESS_ARCH(ptl0, i)          (((pte_t *) (ptl0))[(i)].pfn << 12)
00077 #define GET_PTL2_ADDRESS_ARCH(ptl1, i)          (ptl1)
00078 #define GET_PTL3_ADDRESS_ARCH(ptl2, i)          (ptl2)
00079 #define GET_FRAME_ADDRESS_ARCH(ptl3, i)         (((pte_t *) (ptl3))[(i)].pfn << 12)
00080 
00081 #define SET_PTL0_ADDRESS_ARCH(ptl0)
00082 #define SET_PTL1_ADDRESS_ARCH(ptl0, i, a)       (((pte_t *) (ptl0))[(i)].pfn = (a) >> 12)
00083 #define SET_PTL2_ADDRESS_ARCH(ptl1, i, a)
00084 #define SET_PTL3_ADDRESS_ARCH(ptl2, i, a)
00085 #define SET_FRAME_ADDRESS_ARCH(ptl3, i, a)      (((pte_t *) (ptl3))[(i)].pfn = (a) >> 12)
00086 
00087 #define GET_PTL1_FLAGS_ARCH(ptl0, i)            get_pt_flags((pte_t *) (ptl0), (index_t) (i))
00088 #define GET_PTL2_FLAGS_ARCH(ptl1, i)            PAGE_PRESENT
00089 #define GET_PTL3_FLAGS_ARCH(ptl2, i)            PAGE_PRESENT
00090 #define GET_FRAME_FLAGS_ARCH(ptl3, i)           get_pt_flags((pte_t *) (ptl3), (index_t) (i))
00091 
00092 #define SET_PTL1_FLAGS_ARCH(ptl0, i, x)         set_pt_flags((pte_t *) (ptl0), (index_t) (i), (x))
00093 #define SET_PTL2_FLAGS_ARCH(ptl1, i, x)
00094 #define SET_PTL3_FLAGS_ARCH(ptl2, i, x)
00095 #define SET_FRAME_FLAGS_ARCH(ptl3, i, x)        set_pt_flags((pte_t *) (ptl3), (index_t) (i), (x))
00096 
00097 #define PTE_VALID_ARCH(pte)                     (*((__u32 *) (pte)) != 0)
00098 #define PTE_PRESENT_ARCH(pte)                   ((pte)->p != 0)
00099 #define PTE_GET_FRAME_ARCH(pte)                 ((__address) ((pte)->pfn << 12))
00100 #define PTE_WRITABLE_ARCH(pte)                  1
00101 #define PTE_EXECUTABLE_ARCH(pte)                1
00102 
00103 #ifndef __ASM__
00104 
00105 #include <mm/page.h>
00106 #include <arch/mm/frame.h>
00107 #include <arch/types.h>
00108 
00109 static inline int get_pt_flags(pte_t *pt, index_t i)
00110 {
00111         pte_t *p = &pt[i];
00112         
00113         return (
00114                 (1 << PAGE_CACHEABLE_SHIFT) |
00115                 ((!p->p) << PAGE_PRESENT_SHIFT) |
00116                 (1 << PAGE_USER_SHIFT) |
00117                 (1 << PAGE_READ_SHIFT) |
00118                 (1 << PAGE_WRITE_SHIFT) |
00119                 (1 << PAGE_EXEC_SHIFT) |
00120                 (p->g << PAGE_GLOBAL_SHIFT)
00121         );
00122 }
00123 
00124 static inline void set_pt_flags(pte_t *pt, index_t i, int flags)
00125 {
00126         pte_t *p = &pt[i];
00127         
00128         p->p = !(flags & PAGE_NOT_PRESENT);
00129         p->g = (flags & PAGE_GLOBAL) != 0;
00130         p->valid = 1;
00131 }
00132 
00133 extern void page_arch_init(void);
00134 
00135 #define PHT_BITS        16
00136 #define PHT_ORDER       4
00137 
00138 typedef struct {
00139         unsigned v : 1;          
00140         unsigned vsid : 24;      
00141         unsigned h : 1;          
00142         unsigned api : 6;        
00143         unsigned rpn : 20;       
00144         unsigned reserved0 : 3;
00145         unsigned r : 1;          
00146         unsigned c : 1;          
00147         unsigned wimg : 4;       
00148         unsigned reserved1 : 1;
00149         unsigned pp : 2;         
00150 } phte_t;
00151 
00152 extern void pht_refill(bool data, istate_t *istate);
00153 extern void pht_init(void);
00154 
00155 #endif /* __ASM__ */
00156 
00157 #endif /* KERNEL */
00158 
00159 #endif
00160 

Generated on Sun Jun 18 17:28:03 2006 for HelenOS Kernel (ppc64) by  doxygen 1.4.6