Subversion Repositories HelenOS

Rev

Rev 1793 | Rev 1851 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright (C) 2005 Jakub Jermar
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  *
  9.  * - Redistributions of source code must retain the above copyright
  10.  *   notice, this list of conditions and the following disclaimer.
  11.  * - Redistributions in binary form must reproduce the above copyright
  12.  *   notice, this list of conditions and the following disclaimer in the
  13.  *   documentation and/or other materials provided with the distribution.
  14.  * - The name of the author may not be used to endorse or promote products
  15.  *   derived from this software without specific prior written permission.
  16.  *
  17.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  18.  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  19.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  20.  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  21.  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26.  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27.  */
  28.  
  29. /** @addtogroup sparc64mm  
  30.  * @{
  31.  */
  32. /** @file
  33.  */
  34.  
  35. #include <arch/mm/tlb.h>
  36. #include <mm/tlb.h>
  37. #include <arch/mm/frame.h>
  38. #include <arch/mm/page.h>
  39. #include <arch/mm/mmu.h>
  40. #include <mm/asid.h>
  41. #include <print.h>
  42. #include <arch/types.h>
  43. #include <typedefs.h>
  44. #include <config.h>
  45. #include <arch/trap/trap.h>
  46. #include <panic.h>
  47. #include <arch/asm.h>
  48. #include <symtab.h>
  49.  
  50. char *context_encoding[] = {
  51.     "Primary",
  52.     "Secondary",
  53.     "Nucleus",
  54.     "Reserved"
  55. };
  56.  
  57. void tlb_arch_init(void)
  58. {
  59.     /*
  60.      * TLBs are actually initialized early
  61.      * in start.S.
  62.      */
  63. }
  64.  
  65. /** Insert privileged mapping into DMMU TLB.
  66.  *
  67.  * @param page Virtual page address.
  68.  * @param frame Physical frame address.
  69.  * @param pagesize Page size.
  70.  * @param locked True for permanent mappings, false otherwise.
  71.  * @param cacheable True if the mapping is cacheable, false otherwise.
  72.  */
  73. void dtlb_insert_mapping(uintptr_t page, uintptr_t frame, int pagesize, bool locked, bool cacheable)
  74. {
  75.     tlb_tag_access_reg_t tag;
  76.     tlb_data_t data;
  77.     page_address_t pg;
  78.     frame_address_t fr;
  79.  
  80.     pg.address = page;
  81.     fr.address = frame;
  82.  
  83.     tag.value = ASID_KERNEL;
  84.     tag.vpn = pg.vpn;
  85.  
  86.     dtlb_tag_access_write(tag.value);
  87.  
  88.     data.value = 0;
  89.     data.v = true;
  90.     data.size = pagesize;
  91.     data.pfn = fr.pfn;
  92.     data.l = locked;
  93.     data.cp = cacheable;
  94.     data.cv = cacheable;
  95.     data.p = true;
  96.     data.w = true;
  97.     data.g = true;
  98.  
  99.     dtlb_data_in_write(data.value);
  100. }
  101.  
  102. /** ITLB miss handler. */
  103. void fast_instruction_access_mmu_miss(void)
  104. {
  105.     panic("%s\n", __FUNCTION__);
  106. }
  107.  
  108. /** DTLB miss handler. */
  109. void fast_data_access_mmu_miss(void)
  110. {
  111.     tlb_tag_access_reg_t tag;
  112.     uintptr_t tpc;
  113.     char *tpc_str;
  114.  
  115.     tag.value = dtlb_tag_access_read();
  116.     if (tag.context != ASID_KERNEL || tag.vpn == 0) {
  117.         tpc = tpc_read();
  118.         tpc_str = get_symtab_entry(tpc);
  119.  
  120.         printf("Faulting page: %p, ASID=%d\n", tag.vpn * PAGE_SIZE, tag.context);
  121.         printf("TPC=%p, (%s)\n", tpc, tpc_str ? tpc_str : "?");
  122.         panic("%s\n", __FUNCTION__);
  123.     }
  124.  
  125.     /*
  126.      * Identity map piece of faulting kernel address space.
  127.      */
  128.     dtlb_insert_mapping(tag.vpn * PAGE_SIZE, tag.vpn * FRAME_SIZE, PAGESIZE_8K, false, true);
  129. }
  130.  
  131. /** DTLB protection fault handler. */
  132. void fast_data_access_protection(void)
  133. {
  134.     panic("%s\n", __FUNCTION__);
  135. }
  136.  
  137. /** Print contents of both TLBs. */
  138. void tlb_print(void)
  139. {
  140.     int i;
  141.     tlb_data_t d;
  142.     tlb_tag_read_reg_t t;
  143.    
  144.     printf("I-TLB contents:\n");
  145.     for (i = 0; i < ITLB_ENTRY_COUNT; i++) {
  146.         d.value = itlb_data_access_read(i);
  147.         t.value = itlb_tag_read_read(i);
  148.        
  149.         printf("%d: vpn=%#llx, context=%d, v=%d, size=%d, nfo=%d, ie=%d, soft2=%#x, diag=%#x, pfn=%#x, soft=%#x, l=%d, cp=%d, cv=%d, e=%d, p=%d, w=%d, g=%d\n",
  150.             i, t.vpn, t.context, d.v, d.size, d.nfo, d.ie, d.soft2, d.diag, d.pfn, d.soft, d.l, d.cp, d.cv, d.e, d.p, d.w, d.g);
  151.     }
  152.  
  153.     printf("D-TLB contents:\n");
  154.     for (i = 0; i < DTLB_ENTRY_COUNT; i++) {
  155.         d.value = dtlb_data_access_read(i);
  156.         t.value = dtlb_tag_read_read(i);
  157.        
  158.         printf("%d: vpn=%#llx, context=%d, v=%d, size=%d, nfo=%d, ie=%d, soft2=%#x, diag=%#x, pfn=%#x, soft=%#x, l=%d, cp=%d, cv=%d, e=%d, p=%d, w=%d, g=%d\n",
  159.             i, t.vpn, t.context, d.v, d.size, d.nfo, d.ie, d.soft2, d.diag, d.pfn, d.soft, d.l, d.cp, d.cv, d.e, d.p, d.w, d.g);
  160.     }
  161.  
  162. }
  163.  
  164. /** Invalidate all unlocked ITLB and DTLB entries. */
  165. void tlb_invalidate_all(void)
  166. {
  167.     int i;
  168.     tlb_data_t d;
  169.     tlb_tag_read_reg_t t;
  170.  
  171.     for (i = 0; i < ITLB_ENTRY_COUNT; i++) {
  172.         d.value = itlb_data_access_read(i);
  173.         if (!d.l) {
  174.             t.value = itlb_tag_read_read(i);
  175.             d.v = false;
  176.             itlb_tag_access_write(t.value);
  177.             itlb_data_access_write(i, d.value);
  178.         }
  179.     }
  180.    
  181.     for (i = 0; i < DTLB_ENTRY_COUNT; i++) {
  182.         d.value = dtlb_data_access_read(i);
  183.         if (!d.l) {
  184.             t.value = dtlb_tag_read_read(i);
  185.             d.v = false;
  186.             dtlb_tag_access_write(t.value);
  187.             dtlb_data_access_write(i, d.value);
  188.         }
  189.     }
  190.    
  191. }
  192.  
  193. /** Invalidate all ITLB and DTLB entries that belong to specified ASID (Context).
  194.  *
  195.  * @param asid Address Space ID.
  196.  */
  197. void tlb_invalidate_asid(asid_t asid)
  198. {
  199.     /* TODO: write asid to some Context register and encode the register in second parameter below. */
  200.     itlb_demap(TLB_DEMAP_CONTEXT, TLB_DEMAP_NUCLEUS, 0);
  201.     dtlb_demap(TLB_DEMAP_CONTEXT, TLB_DEMAP_NUCLEUS, 0);
  202. }
  203.  
  204. /** Invalidate all ITLB and DTLB entries for specified page range in specified address space.
  205.  *
  206.  * @param asid Address Space ID.
  207.  * @param page First page which to sweep out from ITLB and DTLB.
  208.  * @param cnt Number of ITLB and DTLB entries to invalidate.
  209.  */
  210. void tlb_invalidate_pages(asid_t asid, uintptr_t page, count_t cnt)
  211. {
  212.     int i;
  213.    
  214.     for (i = 0; i < cnt; i++) {
  215.         /* TODO: write asid to some Context register and encode the register in second parameter below. */
  216.         itlb_demap(TLB_DEMAP_PAGE, TLB_DEMAP_NUCLEUS, page + i * PAGE_SIZE);
  217.         dtlb_demap(TLB_DEMAP_PAGE, TLB_DEMAP_NUCLEUS, page + i * PAGE_SIZE);
  218.     }
  219. }
  220.  
  221. /** @}
  222.  */
  223.