Subversion Repositories HelenOS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2198 jancik 1
/*
2
 * Copyright (c) 2003-2004 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 arm32mm
30
 * @{
31
 */
32
/** @file
33
 */
34
 
35
 
36
#ifndef __MM_H__
37
#define __MM_H__
38
 
39
#include "types.h"
40
 
41
 
42
#define FRAME_WIDTH     12 /* 4KB frames */
43
#define FRAME_SIZE      (1 << FRAME_WIDTH)
44
 
45
#define PAGE_WIDTH      FRAME_WIDTH
46
#define PAGE_SIZE       FRAME_SIZE
47
 
48
#ifndef __ASM__
49
#   define KA2PA(x)                         (((uintptr_t) (x)) - 0x80000000)
50
#   define PA2KA(x)                         (((uintptr_t) (x)) + 0x80000000)
51
#else
52
#   define KA2PA(x)                         ((x) - 0x80000000)
53
#   define PA2KA(x)                         ((x) + 0x80000000)
54
#endif
55
 
56
#define SET_PTL0_ADDRESS_ARCH(ptl0)         ( set_ptl0_addr((pte_level0_section *)(ptl0)) ) 
57
 
58
 
59
/// User no acess, kernel read/write
60
#define pte_ap_user_no_kernel_rw    1 
61
 
62
/// Frames per 1MB section
63
#define FRAMES_PER_SECTION          ( ( 1 << 20 ) / FRAME_SIZE )
64
 
65
/// Converts Address to frame
66
#define ADDR2PFN( addr )            ( ((uintptr_t)(addr))>>FRAME_WIDTH )
67
/** Value of descriptor_type in page table entry that signals
68
 * that this entry describe section
69
 */  
70
#define pte_descriptor_section 2
71
 
72
/** Page Table Entry. */
73
typedef struct {
74
    /**PageTables are so different that we have different types
75
     *   for level 0 and level1 page table entries
76
     */  
77
  unsigned dummy : 32;
78
} pte_t;
79
 
80
/** Page table level 0 entry - section format */
81
typedef struct {
82
    unsigned descriptor_type     : 2; // should be 2
83
    unsigned bufferable          : 1;
84
    unsigned cacheable           : 1;
85
    unsigned machine_depend      : 1; // Alf: ???? v Architecture previev neni vyznam definovan
86
    unsigned domain              : 4;
87
    unsigned should_be_zero_1    : 1;
88
    unsigned access_permission   : 2;  
89
    unsigned should_be_zero_2    : 8;
90
    unsigned section_base_addr   : 12;
91
} __attribute__ ((packed)) pte_level0_section;
92
 
93
 
94
/** Set adress of paging level 0 table
95
 * \param pt pointer to page table to set
96
 */  
97
static inline void set_ptl0_addr( pte_level0_section* pt) {
98
    asm volatile ( "mcr p15, 0, %0, c2, c0, 0 \n"
99
    :
100
    : "r"(pt)
101
    );
102
 
103
}
104
 
105
/// Page table that holds 1:1 mapping for kernel starting 
106
extern pte_level0_section page_table[4096];
107
 
108
 
109
/** Set page table entry to point no frame, be read/write by kernel,
110
 *   no access by user, become to domain 0, no cache or buffer
111
 *   \param pte page table entry to set
112
 *   \param frame frame number of first frame 1MB section
113
 *   Note: If frame not aligned it's used first lower  1MB aligned frame
114
 */  
115
void init_pte_level0_section_entry( pte_level0_section* pte, unsigned frame);
116
 
117
/// Sets memory mapping for kernel
118
void mm_kernel_mapping(void);
119
 
120
#endif
121
 
122
/** @}
123
 */
124