ReactOS 0.4.17-dev-1190-g4c812f4
iosup.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Kernel
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: ntoskrnl/mm/ARM3/iosup.c
5 * PURPOSE: ARM Memory Manager I/O Mapping Functionality
6 * PROGRAMMERS: ReactOS Portable Systems Group
7 */
8
9/* INCLUDES *******************************************************************/
10
11#include <ntoskrnl.h>
12#define NDEBUG
13#include <debug.h>
14
15#define MODULE_INVOLVED_IN_ARM3
16#include <mm/ARM3/miarm.h>
17
18/* GLOBALS ********************************************************************/
19
20//
21// Each architecture has its own caching attributes for both I/O and Physical
22// memory mappings.
23//
24// This describes the attributes for the x86 architecture. It eventually needs
25// to go in the appropriate i386 directory.
26//
28{
29 //
30 // RAM
31 //
33
34 //
35 // Device Memory
36 //
38};
39
40/* PUBLIC FUNCTIONS ***********************************************************/
41
42/*
43 * @implemented
44 */
50{
51
52 PFN_NUMBER Pfn;
53 PFN_COUNT PageCount;
54 PMMPTE PointerPte;
57 PMMPFN Pfn1 = NULL;
58 MI_PFN_CACHE_ATTRIBUTE CacheAttribute;
59 BOOLEAN IsIoMapping;
60
61 //
62 // Must be called with a non-zero count
63 //
65
66 //
67 // Make sure the upper bits are 0 if this system
68 // can't describe more than 4 GB of physical memory.
69 // FIXME: This doesn't respect PAE, but we currently don't
70 // define a PAE build flag since there is no such build.
71 //
72#if !defined(_M_AMD64)
73 ASSERT(PhysicalAddress.HighPart == 0);
74#endif
75
76 //
77 // Normalize and validate the caching attributes
78 //
79 CacheType &= 0xFF;
80 if (CacheType >= MmMaximumCacheType) return NULL;
81
82 //
83 // Calculate page count
84 //
87
88 //
89 // Compute the PFN and check if it's a known I/O mapping
90 // Also translate the cache attribute
91 //
92 Pfn = (PFN_NUMBER)(PhysicalAddress.QuadPart >> PAGE_SHIFT);
93 Pfn1 = MiGetPfnEntry(Pfn);
94 IsIoMapping = (Pfn1 == NULL) ? TRUE : FALSE;
95 CacheAttribute = MiPlatformCacheAttributes[IsIoMapping][CacheType];
96
97 //
98 // Now allocate system PTEs for the mapping, and get the VA
99 //
100 PointerPte = MiReserveSystemPtes(PageCount, SystemPteSpace);
101 if (!PointerPte) return NULL;
102 BaseAddress = MiPteToAddress(PointerPte);
103
104 //
105 // Check if this is uncached
106 //
107 if (CacheAttribute != MiCached)
108 {
109 //
110 // Flush all caches
111 //
114 }
115
116 //
117 // Now compute the VA offset
118 //
121
122 //
123 // Get the template and configure caching
124 //
126 switch (CacheAttribute)
127 {
128 case MiNonCached:
129
130 //
131 // Disable the cache
132 //
134 break;
135
136 case MiCached:
137
138 //
139 // Enable caching
140 //
142 break;
143
144 case MiWriteCombined:
145
146 //
147 // Enable write combining
148 //
150 break;
151
152 default:
153
154 //
155 // Should never happen
156 //
157 ASSERT(FALSE);
158 break;
159 }
160
161 //
162 // Sanity check and re-flush
163 //
164 Pfn = (PFN_NUMBER)(PhysicalAddress.QuadPart >> PAGE_SHIFT);
165 ASSERT((Pfn1 == MiGetPfnEntry(Pfn)) || (Pfn1 == NULL));
168
169 //
170 // Do the mapping
171 //
172 do
173 {
174 //
175 // Write the PFN
176 //
177 TempPte.u.Hard.PageFrameNumber = Pfn++;
178 MI_WRITE_VALID_PTE(PointerPte++, TempPte);
179 } while (--PageCount);
180
181 //
182 // We're done!
183 //
184 return BaseAddress;
185}
186
187/*
188 * @implemented
189 */
190VOID
191NTAPI
194{
195 PFN_NUMBER Pfn;
196 PFN_COUNT PageCount;
197 PMMPTE PointerPte;
198
199 //
200 // Sanity check
201 //
202 ASSERT(NumberOfBytes != 0);
203
204 //
205 // Get the page count
206 //
208
209 //
210 // Get the PTE and PFN
211 //
212 PointerPte = MiAddressToPte(BaseAddress);
213 Pfn = PFN_FROM_PTE(PointerPte);
214
215 //
216 // Is this an I/O mapping?
217 //
218 if (!MiGetPfnEntry(Pfn))
219 {
220 //
221 // Destroy the PTE
222 //
223 RtlZeroMemory(PointerPte, PageCount * sizeof(MMPTE));
224
225 //
226 // Blow the TLB
227 //
229 }
230
231 //
232 // Release the PTEs
233 //
234 MiReleaseSystemPtes(PointerPte, PageCount, 0);
235}
236
237/*
238 * @implemented
239 */
240PVOID
241NTAPI
245{
246 PAGED_CODE();
247
248 //
249 // Call the real function
250 //
252}
253
254/*
255 * @implemented
256 */
257VOID
258NTAPI
261{
262 //
263 // Call the real function
264 //
266}
267
269NTAPI
272{
274 return FALSE;
275}
276
277/* EOF */
#define PAGED_CODE()
ULONG_PTR PFN_NUMBER
unsigned char BOOLEAN
Definition: actypes.h:127
HARDWARE_PTE_ARMV6 TempPte
Definition: winldr.c:76
#define UNIMPLEMENTED
Definition: ntoskrnl.c:15
_In_ ULONG _In_ MEMORY_CACHING_TYPE _Out_ PPHYSICAL_ADDRESS PhysicalAddress
Definition: dispmprt.h:714
_In_ ULONG _In_ MEMORY_CACHING_TYPE CacheType
Definition: dispmprt.h:713
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define PAGE_SHIFT
Definition: env_spec_w32.h:45
PVOID NTAPI MmMapVideoDisplay(IN PHYSICAL_ADDRESS PhysicalAddress, IN SIZE_T NumberOfBytes, IN MEMORY_CACHING_TYPE CacheType)
Definition: iosup.c:242
MI_PFN_CACHE_ATTRIBUTE MiPlatformCacheAttributes[2][MmMaximumCacheType]
Definition: iosup.c:27
VOID NTAPI MmUnmapIoSpace(IN PVOID BaseAddress, IN SIZE_T NumberOfBytes)
Definition: iosup.c:192
LOGICAL NTAPI MmIsIoSpaceActive(IN PHYSICAL_ADDRESS StartAddress, IN SIZE_T NumberOfBytes)
Definition: iosup.c:270
PVOID NTAPI MmMapIoSpace(IN PHYSICAL_ADDRESS PhysicalAddress, IN SIZE_T NumberOfBytes, IN MEMORY_CACHING_TYPE CacheType)
Definition: iosup.c:47
VOID NTAPI MmUnmapVideoDisplay(IN PVOID BaseAddress, IN SIZE_T NumberOfBytes)
Definition: iosup.c:259
@ SystemPteSpace
Definition: miarm.h:407
VOID NTAPI MiReleaseSystemPtes(IN PMMPTE StartingPte, IN ULONG NumberOfPtes, IN MMSYSTEM_PTE_POOL_TYPE SystemPtePoolType)
Definition: syspte.c:264
enum _MI_PFN_CACHE_ATTRIBUTE MI_PFN_CACHE_ATTRIBUTE
@ MiWriteCombined
Definition: miarm.h:416
@ MiCached
Definition: miarm.h:415
@ MiNonCached
Definition: miarm.h:414
PMMPTE NTAPI MiReserveSystemPtes(IN ULONG NumberOfPtes, IN MMSYSTEM_PTE_POOL_TYPE SystemPtePoolType)
Definition: syspte.c:246
FORCEINLINE VOID MI_WRITE_VALID_PTE(IN PMMPTE PointerPte, IN MMPTE TempPte)
Definition: miarm.h:967
#define ASSERT(a)
Definition: mode.c:44
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize _Pre_valid_ PVOID * BaseAddress
Definition: mmfuncs.h:408
#define MiAddressToPte(x)
Definition: mm.h:144
#define PFN_FROM_PTE(v)
Definition: mm.h:94
#define MI_MAKE_PTE_WRITE_COMBINE(Pte)
Definition: mm.h:94
#define MI_MAKE_PTE_CACHED(Pte)
Definition: mm.h:82
#define MiPteToAddress(_Pte)
Definition: mm.h:131
#define MI_MAKE_PTE_NON_CACHED(Pte)
Definition: mm.h:88
BOOLEAN NTAPI KeInvalidateAllCaches(VOID)
Definition: cpu.c:523
FORCEINLINE PMMPFN MiGetPfnEntry(IN PFN_NUMBER Pfn)
Definition: mm.h:1042
VOID NTAPI KeFlushEntireTb(IN BOOLEAN Invalid, IN BOOLEAN AllProcessors)
Definition: cpu.c:487
MMPTE ValidKernelPte
Definition: init.c:29
ULONG PageFrameNumber
Definition: mmtypes.h:109
Definition: mm.h:386
#define NTAPI
Definition: typedefs.h:36
void * PVOID
Definition: typedefs.h:50
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define IN
Definition: typedefs.h:39
ULONG LOGICAL
Definition: umtypes.h:135
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS _Inout_ PLARGE_INTEGER NumberOfBytes
Definition: iotypes.h:1036
#define BYTE_OFFSET(Va)
#define ADDRESS_AND_SIZE_TO_SPAN_PAGES(_Va, _Size)
enum _MEMORY_CACHING_TYPE MEMORY_CACHING_TYPE
@ MmMaximumCacheType
Definition: mmtypes.h:135
ULONG PFN_COUNT
Definition: mmtypes.h:102