Rev 2198 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2198 | Rev 2234 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2003-2004 Jakub Jermar |
2 | * Copyright (c) 2003-2004 Jakub Jermar |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
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 |
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. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
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 |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
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 |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
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 |
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. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /** @addtogroup arm32mm |
29 | /** @addtogroup arm32mm |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | /** @file |
32 | /** @file |
33 | */ |
33 | */ |
34 | 34 | ||
35 | 35 | ||
36 | #ifndef __MM_H__ |
36 | #ifndef __MM_H__ |
37 | #define __MM_H__ |
37 | #define __MM_H__ |
38 | 38 | ||
39 | #include "types.h" |
39 | #include "types.h" |
40 | 40 | ||
41 | 41 | ||
42 | #define FRAME_WIDTH 12 /* 4KB frames */ |
42 | #define FRAME_WIDTH 12 /* 4KB frames */ |
43 | #define FRAME_SIZE (1 << FRAME_WIDTH) |
43 | #define FRAME_SIZE (1 << FRAME_WIDTH) |
44 | 44 | ||
45 | #define PAGE_WIDTH FRAME_WIDTH |
45 | #define PAGE_WIDTH FRAME_WIDTH |
46 | #define PAGE_SIZE FRAME_SIZE |
46 | #define PAGE_SIZE FRAME_SIZE |
47 | 47 | ||
48 | #ifndef __ASM__ |
48 | #ifndef __ASM__ |
49 | # define KA2PA(x) (((uintptr_t) (x)) - 0x80000000) |
49 | # define KA2PA(x) (((uintptr_t) (x)) - 0x80000000) |
50 | # define PA2KA(x) (((uintptr_t) (x)) + 0x80000000) |
50 | # define PA2KA(x) (((uintptr_t) (x)) + 0x80000000) |
51 | #else |
51 | #else |
52 | # define KA2PA(x) ((x) - 0x80000000) |
52 | # define KA2PA(x) ((x) - 0x80000000) |
53 | # define PA2KA(x) ((x) + 0x80000000) |
53 | # define PA2KA(x) ((x) + 0x80000000) |
54 | #endif |
54 | #endif |
55 | 55 | ||
- | 56 | #define PTL0_ENTRIES_ARCH (2<<12) /* 4096 */ |
|
56 | #define SET_PTL0_ADDRESS_ARCH(ptl0) ( set_ptl0_addr((pte_level0_section *)(ptl0)) ) |
57 | #define SET_PTL0_ADDRESS_ARCH(ptl0) ( set_ptl0_addr((pte_level0_section *)(ptl0)) ) |
57 | 58 | ||
- | 59 | /** Frames per 1MB section */ |
|
- | 60 | #define FRAMES_PER_SECTION ( ( 1 << 20 ) / FRAME_SIZE ) |
|
58 | 61 | ||
59 | /// User no acess, kernel read/write |
62 | /** Converts adress to frame */ |
60 | #define pte_ap_user_no_kernel_rw 1 |
63 | #define ADDR2PFN( addr ) ( ((uintptr_t)(addr))>>FRAME_WIDTH ) |
61 | 64 | ||
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 |
65 | /** Value of descriptor_type in page table entry that signals |
68 | * that this entry describe section |
66 | * that this entry describe section |
69 | */ |
67 | */ |
70 | #define pte_descriptor_section 2 |
68 | #define PTE_DESCRIPTOR_SECTION 2 |
- | 69 | ||
- | 70 | /** Rights: user-no acess, kernel-read/write */ |
|
- | 71 | #define PTE_AP_USER_NO_KERNEL_RW 1 |
|
71 | 72 | ||
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 | 73 | ||
80 | /** Page table level 0 entry - section format */ |
74 | /** Page table level 0 entry - section format */ |
81 | typedef struct { |
75 | typedef struct { |
82 | unsigned descriptor_type : 2; // should be 2 |
76 | unsigned descriptor_type : 2; // should be 2 |
83 | unsigned bufferable : 1; |
77 | unsigned bufferable : 1; |
84 | unsigned cacheable : 1; |
78 | unsigned cacheable : 1; |
85 | unsigned machine_depend : 1; // Alf: ???? v Architecture previev neni vyznam definovan |
79 | unsigned machine_depend : 1; |
86 | unsigned domain : 4; |
80 | unsigned domain : 4; |
87 | unsigned should_be_zero_1 : 1; |
81 | unsigned should_be_zero_1 : 1; |
88 | unsigned access_permission : 2; |
82 | unsigned access_permission : 2; |
89 | unsigned should_be_zero_2 : 8; |
83 | unsigned should_be_zero_2 : 8; |
90 | unsigned section_base_addr : 12; |
84 | unsigned section_base_addr : 12; |
91 | } __attribute__ ((packed)) pte_level0_section; |
85 | } __attribute__ ((packed)) pte_level0_section; |
92 | 86 | ||
93 | 87 | ||
94 | /** Set adress of paging level 0 table |
88 | /** Set adress of paging level 0 table |
95 | * \param pt pointer to page table to set |
89 | * \param pt pointer to page table to set |
96 | */ |
90 | */ |
97 | static inline void set_ptl0_addr( pte_level0_section* pt) { |
91 | static inline void set_ptl0_addr( pte_level0_section* pt) { |
98 | asm volatile ( "mcr p15, 0, %0, c2, c0, 0 \n" |
92 | asm volatile ( "mcr p15, 0, %0, c2, c0, 0 \n" |
99 | : |
93 | : |
100 | : "r"(pt) |
94 | : "r"(pt) |
101 | ); |
95 | ); |
102 | 96 | ||
103 | } |
97 | } |
104 | 98 | ||
105 | /// Page table that holds 1:1 mapping for kernel starting |
99 | /** Page table that holds 1:1 mapping for kernel starting */ |
106 | extern pte_level0_section page_table[4096]; |
100 | extern pte_level0_section page_table[PTL0_ENTRIES_ARCH]; |
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 | 101 | ||
117 | /// Sets memory mapping for kernel |
102 | /** Sets memory mapping for kernel */ |
118 | void mm_kernel_mapping(void); |
103 | void mm_kernel_mapping(void); |
119 | 104 | ||
120 | #endif |
105 | #endif |
121 | 106 | ||
122 | /** @} |
107 | /** @} |
123 | */ |
108 | */ |
124 | 109 | ||
125 | 110 |