page.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2006 Jakub Jermar
00003  * Copyright (C) 2006 Jakub Vana
00004  * All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  *
00010  * - Redistributions of source code must retain the above copyright
00011  *   notice, this list of conditions and the following disclaimer.
00012  * - Redistributions in binary form must reproduce the above copyright
00013  *   notice, this list of conditions and the following disclaimer in the
00014  *   documentation and/or other materials provided with the distribution.
00015  * - The name of the author may not be used to endorse or promote products
00016  *   derived from this software without specific prior written permission.
00017  *
00018  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00019  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00020  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00021  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00022  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00023  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00024  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00025  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00026  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00027  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00036 #include <arch/mm/page.h>
00037 #include <genarch/mm/page_ht.h>
00038 #include <mm/asid.h>
00039 #include <arch/mm/asid.h>
00040 #include <arch/mm/vhpt.h>
00041 #include <arch/types.h>
00042 #include <typedefs.h>
00043 #include <print.h>
00044 #include <mm/page.h>
00045 #include <mm/frame.h>
00046 #include <config.h>
00047 #include <panic.h>
00048 #include <arch/asm.h>
00049 #include <arch/barrier.h>
00050 #include <memstr.h>
00051 
00052 static void set_environment(void);
00053 
00055 void page_arch_init(void)
00056 {
00057         page_mapping_operations = &ht_mapping_operations;
00058         pk_disable();
00059         set_environment();
00060 }
00061 
00063 void set_environment(void)
00064 {
00065         region_register rr;
00066         pta_register pta;       
00067         int i;
00068 #ifdef CONFIG_VHPT      
00069         __address vhpt_base;
00070 #endif
00071 
00072         /*
00073          * First set up kernel region register.
00074          * This is redundant (see start.S) but we keep it here just for sure.
00075          */
00076         rr.word = rr_read(VRN_KERNEL);
00077         rr.map.ve = 0;                  /* disable VHPT walker */
00078         rr.map.ps = PAGE_WIDTH;
00079         rr.map.rid = ASID2RID(ASID_KERNEL, VRN_KERNEL);
00080         rr_write(VRN_KERNEL, rr.word);
00081         srlz_i();
00082         srlz_d();
00083 
00084         /*
00085          * And setup the rest of region register.
00086          */
00087         for(i = 0; i < REGION_REGISTERS; i++) {
00088                 /* skip kernel rr */
00089                 if (i == VRN_KERNEL)
00090                         continue;
00091         
00092                 rr.word = rr_read(i);
00093                 rr.map.ve = 0;          /* disable VHPT walker */
00094                 rr.map.rid = RID_KERNEL;
00095                 rr.map.ps = PAGE_WIDTH;
00096                 rr_write(i, rr.word);
00097                 srlz_i();
00098                 srlz_d();
00099         }
00100 
00101 #ifdef CONFIG_VHPT      
00102         vhpt_base = vhpt_set_up();
00103 #endif
00104         /*
00105          * Set up PTA register.
00106          */
00107         pta.word = pta_read();
00108 #ifndef CONFIG_VHPT
00109         pta.map.ve = 0;                   /* disable VHPT walker */
00110         pta.map.base = 0 >> PTA_BASE_SHIFT;
00111 #else
00112         pta.map.ve = 1;                   /* enable VHPT walker */
00113         pta.map.base = vhpt_base >> PTA_BASE_SHIFT;
00114 #endif
00115         pta.map.vf = 1;                   /* large entry format */
00116         pta.map.size = VHPT_WIDTH;
00117         pta_write(pta.word);
00118         srlz_i();
00119         srlz_d();
00120 }
00121 
00131 vhpt_entry_t *vhpt_hash(__address page, asid_t asid)
00132 {
00133         region_register rr_save, rr;
00134         index_t vrn;
00135         rid_t rid;
00136         vhpt_entry_t *v;
00137 
00138         vrn = page >> VRN_SHIFT;
00139         rid = ASID2RID(asid, vrn);
00140         
00141         rr_save.word = rr_read(vrn);
00142         if (rr_save.map.rid == rid) {
00143                 /*
00144                  * The RID is already in place, compute thash and return.
00145                  */
00146                 v = (vhpt_entry_t *) thash(page);
00147                 return v;
00148         }
00149         
00150         /*
00151          * The RID must be written to some region register.
00152          * To speed things up, register indexed by vrn is used.
00153          */
00154         rr.word = rr_save.word;
00155         rr.map.rid = rid;
00156         rr_write(vrn, rr.word);
00157         srlz_i();
00158         v = (vhpt_entry_t *) thash(page);
00159         rr_write(vrn, rr_save.word);
00160         srlz_i();
00161         srlz_d();
00162 
00163         return v;
00164 }
00165 
00175 bool vhpt_compare(__address page, asid_t asid, vhpt_entry_t *v)
00176 {
00177         region_register rr_save, rr;    
00178         index_t vrn;
00179         rid_t rid;
00180         bool match;
00181 
00182         ASSERT(v);
00183 
00184         vrn = page >> VRN_SHIFT;
00185         rid = ASID2RID(asid, vrn);
00186         
00187         rr_save.word = rr_read(vrn);
00188         if (rr_save.map.rid == rid) {
00189                 /*
00190                  * The RID is already in place, compare ttag with t and return.
00191                  */
00192                 return ttag(page) == v->present.tag.tag_word;
00193         }
00194         
00195         /*
00196          * The RID must be written to some region register.
00197          * To speed things up, register indexed by vrn is used.
00198          */
00199         rr.word = rr_save.word;
00200         rr.map.rid = rid;
00201         rr_write(vrn, rr.word);
00202         srlz_i();
00203         match = (ttag(page) == v->present.tag.tag_word);
00204         rr_write(vrn, rr_save.word);
00205         srlz_i();
00206         srlz_d();
00207 
00208         return match;           
00209 }
00210 
00219 void vhpt_set_record(vhpt_entry_t *v, __address page, asid_t asid, __address frame, int flags)
00220 {
00221         region_register rr_save, rr;    
00222         index_t vrn;
00223         rid_t rid;
00224         __u64 tag;
00225 
00226         ASSERT(v);
00227 
00228         vrn = page >> VRN_SHIFT;
00229         rid = ASID2RID(asid, vrn);
00230         
00231         /*
00232          * Compute ttag.
00233          */
00234         rr_save.word = rr_read(vrn);
00235         rr.word = rr_save.word;
00236         rr.map.rid = rid;
00237         rr_write(vrn, rr.word);
00238         srlz_i();
00239         tag = ttag(page);
00240         rr_write(vrn, rr_save.word);
00241         srlz_i();
00242         srlz_d();
00243         
00244         /*
00245          * Clear the entry.
00246          */
00247         v->word[0] = 0;
00248         v->word[1] = 0;
00249         v->word[2] = 0;
00250         v->word[3] = 0;
00251         
00252         v->present.p = true;
00253         v->present.ma = (flags & PAGE_CACHEABLE) ? MA_WRITEBACK : MA_UNCACHEABLE;
00254         v->present.a = false;   /* not accessed */
00255         v->present.d = false;   /* not dirty */
00256         v->present.pl = (flags & PAGE_USER) ? PL_USER : PL_KERNEL;
00257         v->present.ar = (flags & PAGE_WRITE) ? AR_WRITE : AR_READ;
00258         v->present.ar |= (flags & PAGE_EXEC) ? AR_EXECUTE : 0; 
00259         v->present.ppn = frame >> PPN_SHIFT;
00260         v->present.ed = false;  /* exception not deffered */
00261         v->present.ps = PAGE_WIDTH;
00262         v->present.key = 0;
00263         v->present.tag.tag_word = tag;
00264 }
00265 

Generated on Sun Jun 18 16:51:21 2006 for HelenOS Kernel (ia64) by  doxygen 1.4.6