source: soft/giet_vm/giet_common/vmem.h @ 757

Last change on this file since 757 was 751, checked in by alain, 9 years ago

Introduce the _v2p_add_pte1(), _v2p_add_pte2(), _v2p_del_pte1(), _v2p_del_pte2() functions
to support dynamic mapping / unmapping associated to the giet_fat_mmap() and giet_fat_munmap() system calls.

  • Property svn:executable set to *
File size: 7.5 KB
Line 
1///////////////////////////////////////////////////////////////////////////////////
2// File     : vmem.h
3// Date     : 01/07/2012
4// Author   : alain greiner
5// Copyright (c) UPMC-LIP6
6///////////////////////////////////////////////////////////////////////////////////
7// The vmem.c and vmem.h files are part ot the GIET-VM nano kernel.
8// They define  the data structures implementing the page tables,
9// and the function used for VPN to PPN translation.
10///////////////////////////////////////////////////////////////////////////////////
11// The virtual address format is 32 bits: structures in 3 fields:
12//             |  11  |  9   |   12   |
13//             | IX1  | IX2  | OFFSET |
14// - The IX1 field is the index in the first level page table
15// - The IX2 field is the index in the second level page table
16// - The |IX1|IX2\ concatenation defines the VPN (Virtual Page Number)
17///////////////////////////////////////////////////////////////////////////////////
18
19#ifndef _VMEM_H_
20#define _VMEM_H_
21
22/////////////////////////////////////////////////////////////////////////////////////
23// Page Table sizes definition
24/////////////////////////////////////////////////////////////////////////////////////
25
26#define PT1_SIZE    8192
27#define PT2_SIZE    4096
28
29#define VPN_MASK    0xFFFFF000
30#define BPN_MASK    0xFFE00000
31
32/////////////////////////////////////////////////////////////////////////////////////
33// PTE flags masks definition
34/////////////////////////////////////////////////////////////////////////////////////
35
36#define PTE_V  0x80000000
37#define PTE_T  0x40000000
38#define PTE_L  0x20000000
39#define PTE_R  0x10000000
40#define PTE_C  0x08000000
41#define PTE_W  0x04000000
42#define PTE_X  0x02000000
43#define PTE_U  0x01000000
44#define PTE_G  0x00800000
45#define PTE_D  0x00400000
46
47///////////////////////////////////////////////////////////////////////////////////
48// MMU error codes definition
49///////////////////////////////////////////////////////////////////////////////////
50
51#define MMU_ERR_PT1_UNMAPPED         0x001 // Page fault on Table1 (invalid PTE)
52#define MMU_ERR_PT2_UNMAPPED         0x002 // Page fault on Table 2 (invalid PTE)
53#define MMU_ERR_PRIVILEGE_VIOLATION  0x004 // Protected access in user mode
54#define MMU_ERR_WRITE_VIOLATION      0x008 // Write access to a non write page
55#define MMU_ERR_EXEC_VIOLATION       0x010 // Exec access to a non exec page
56#define MMU_ERR_UNDEFINED_XTN        0x020 // Undefined external access address
57#define MMU_ERR_PT1_ILLEGAL_ACCESS   0x040 // Bus Error in Table1 access
58#define MMU_ERR_PT2_ILLEGAL_ACCESS   0x080 // Bus Error in Table2 access
59#define MMU_ERR_CACHE_ILLEGAL_ACCESS 0x100 // Bus Error during the cache access
60
61///////////////////////////////////////////////////////////////////////////////////
62// Page table structure definition
63///////////////////////////////////////////////////////////////////////////////////
64
65typedef struct PageTable
66{
67    unsigned int pt1[PT1_SIZE / 4];    // PT1 (index is ix1)
68    unsigned int pt2[1][PT2_SIZE / 4]; // PT2s (index is 2*ix2)
69} page_table_t;
70
71///////////////////////////////////////////////////////////////////////////////////
72// functions prototypes
73///////////////////////////////////////////////////////////////////////////////////
74
75///////////////////////////////////////////////////////////////////////////////////
76// This function makes a "virtual" to "physical" address translation,
77// using the page table of the calling task.
78// The MMU is supposed to be activated.
79// It supports both small (4 Kbytes) & big (2 Mbytes) pages.
80// The page flags are written in the flags buffer.
81// It uses the address extension mechanism for physical addressing.
82// Returns the physical address if success, exit if PTE1 or PTE2 unmapped.
83///////////////////////////////////////////////////////////////////////////////////
84unsigned long long _v2p_translate( unsigned int  vaddr,
85                                   unsigned int* flags );
86
87//////////////////////////////////////////////////////////////////////////////
88// This function registers a new PTE1 in the page table defined
89// by the <vspace_id> argument, and the <x,y> coordinates.
90// It updates only the first level PT1.
91// This function checks that the PT1 entry is not already mapped,
92// to enforce the rule: only one vseg in a given BPP.
93// The 4 vsegs used by the boot code being packed in one single BPP,
94// this verif is not done for all identity mapping vsegs.
95//////////////////////////////////////////////////////////////////////////////
96void _v2p_add_pte1( unsigned int vspace_id,   // vspace index
97                    unsigned int x,           // cluster X coordinate
98                    unsigned int y,           // cluster Y coordinate
99                    unsigned int vpn,         // 20 bits right-justified
100                    unsigned int flags,       // 10 bits left-justified
101                    unsigned int ppn,         // 28 bits right-justified
102                    unsigned int ident );     // identity mapping if non zero
103
104//////////////////////////////////////////////////////////////////////////////
105// This function registers a new PTE2 in the page table defined
106// by the <vspace_id> argument, and the (x,y) coordinates.
107// It updates both the first level PT1 and the second level PT2.
108// As the set of PT2s is implemented as a fixed size array (no dynamic
109// allocation), this function checks a possible overflow of the PT2 array.
110// As a given entry in PT1 can be shared by several vsegs, mapped by
111// different processors, we need to take the lock protecting PTAB[v][x][y].
112//////////////////////////////////////////////////////////////////////////////
113void _v2p_add_pte2( unsigned int vspace_id,   // vspace index
114                    unsigned int x,           // cluster X coordinate
115                    unsigned int y,           // cluster Y coordinate
116                    unsigned int vpn,         // 20 bits right-justified
117                    unsigned int flags,       // 10 bits left-justified
118                    unsigned int ppn,         // 28 bits right-justified
119                    unsigned int ident );     // identity mapping if non zero
120
121//////////////////////////////////////////////////////////////////////////////
122// This function invalidate a PTE1 entry in the page table identified by the
123// <vspace_id> argument and the <x,y> coordinates. The PTE1 entry is
124// defined by the <vpn> virtual page number.
125//////////////////////////////////////////////////////////////////////////////
126void _v2p_del_pte1( unsigned int vspace_id,   // vspace index
127                    unsigned int x,           // cluster X coordinate
128                    unsigned int y,           // cluster Y coordinate
129                    unsigned int vpn );       // 20 bits right-justified
130
131//////////////////////////////////////////////////////////////////////////////
132// This function invalidate a PTE2 entry in the page table identified by the
133// <vspace_id> argument and the <x,y> coordinates. The PTE2 entry is
134// defined by the <vpn> virtual page number. The PT1 used to access the PTE2
135// juis not modified.
136//////////////////////////////////////////////////////////////////////////////
137void _v2p_del_pte2( unsigned int vspace_id,   // vspace index
138                    unsigned int x,           // cluster X coordinate
139                    unsigned int y,           // cluster Y coordinate
140                    unsigned int vpn );       // 20 bits right-justified
141
142
143#endif
144
145// Local Variables:
146// tab-width: 4
147// c-basic-offset: 4
148// c-file-offsets:((innamespace . 0)(inline-open . 0))
149// indent-tabs-mode: nil
150// End:
151// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
152
Note: See TracBrowser for help on using the repository browser.