Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygeniosup.c
Go to the documentation of this file.
00001 /* 00002 * PROJECT: ReactOS Kernel 00003 * LICENSE: BSD - See COPYING.ARM in the top level directory 00004 * FILE: ntoskrnl/mm/ARM3/iosup.c 00005 * PURPOSE: ARM Memory Manager I/O Mapping Functionality 00006 * PROGRAMMERS: ReactOS Portable Systems Group 00007 */ 00008 00009 /* INCLUDES *******************************************************************/ 00010 00011 #include <ntoskrnl.h> 00012 #define NDEBUG 00013 #include <debug.h> 00014 00015 #define MODULE_INVOLVED_IN_ARM3 00016 #include "../ARM3/miarm.h" 00017 00018 /* GLOBALS ********************************************************************/ 00019 00020 // 00021 // Each architecture has its own caching attributes for both I/O and Physical 00022 // memory mappings. 00023 // 00024 // This describes the attributes for the x86 architecture. It eventually needs 00025 // to go in the appropriate i386 directory. 00026 // 00027 MI_PFN_CACHE_ATTRIBUTE MiPlatformCacheAttributes[2][MmMaximumCacheType] = 00028 { 00029 // 00030 // RAM 00031 // 00032 {MiNonCached,MiCached,MiWriteCombined,MiCached,MiNonCached,MiWriteCombined}, 00033 00034 // 00035 // Device Memory 00036 // 00037 {MiNonCached,MiCached,MiWriteCombined,MiCached,MiNonCached,MiWriteCombined}, 00038 }; 00039 00040 /* PUBLIC FUNCTIONS ***********************************************************/ 00041 00042 /* 00043 * @implemented 00044 */ 00045 PVOID 00046 NTAPI 00047 MmMapIoSpace(IN PHYSICAL_ADDRESS PhysicalAddress, 00048 IN SIZE_T NumberOfBytes, 00049 IN MEMORY_CACHING_TYPE CacheType) 00050 { 00051 00052 PFN_NUMBER Pfn; 00053 PFN_COUNT PageCount; 00054 PMMPTE PointerPte; 00055 PVOID BaseAddress; 00056 MMPTE TempPte; 00057 PMMPFN Pfn1 = NULL; 00058 MI_PFN_CACHE_ATTRIBUTE CacheAttribute; 00059 BOOLEAN IsIoMapping; 00060 00061 // 00062 // Must be called with a non-zero count 00063 // 00064 ASSERT(NumberOfBytes != 0); 00065 00066 // 00067 // Make sure the upper bits are 0 if this system 00068 // can't describe more than 4 GB of physical memory. 00069 // FIXME: This doesn't respect PAE, but we currently don't 00070 // define a PAE build flag since there is no such build. 00071 // 00072 #if !defined(_M_AMD64) 00073 ASSERT(PhysicalAddress.HighPart == 0); 00074 #endif 00075 00076 // 00077 // Normalize and validate the caching attributes 00078 // 00079 CacheType &= 0xFF; 00080 if (CacheType >= MmMaximumCacheType) return NULL; 00081 00082 // 00083 // Calculate page count 00084 // 00085 PageCount = ADDRESS_AND_SIZE_TO_SPAN_PAGES(PhysicalAddress.LowPart, 00086 NumberOfBytes); 00087 00088 // 00089 // Compute the PFN and check if it's a known I/O mapping 00090 // Also translate the cache attribute 00091 // 00092 Pfn = (PFN_NUMBER)(PhysicalAddress.QuadPart >> PAGE_SHIFT); 00093 Pfn1 = MiGetPfnEntry(Pfn); 00094 IsIoMapping = (Pfn1 == NULL) ? TRUE : FALSE; 00095 CacheAttribute = MiPlatformCacheAttributes[IsIoMapping][CacheType]; 00096 00097 // 00098 // Now allocate system PTEs for the mapping, and get the VA 00099 // 00100 PointerPte = MiReserveSystemPtes(PageCount, SystemPteSpace); 00101 if (!PointerPte) return NULL; 00102 BaseAddress = MiPteToAddress(PointerPte); 00103 00104 // 00105 // Check if this is uncached 00106 // 00107 if (CacheAttribute != MiCached) 00108 { 00109 // 00110 // Flush all caches 00111 // 00112 KeFlushEntireTb(TRUE, TRUE); 00113 KeInvalidateAllCaches(); 00114 } 00115 00116 // 00117 // Now compute the VA offset 00118 // 00119 BaseAddress = (PVOID)((ULONG_PTR)BaseAddress + 00120 BYTE_OFFSET(PhysicalAddress.LowPart)); 00121 00122 // 00123 // Get the template and configure caching 00124 // 00125 TempPte = ValidKernelPte; 00126 switch (CacheAttribute) 00127 { 00128 case MiNonCached: 00129 00130 // 00131 // Disable the cache 00132 // 00133 MI_PAGE_DISABLE_CACHE(&TempPte); 00134 MI_PAGE_WRITE_THROUGH(&TempPte); 00135 break; 00136 00137 case MiCached: 00138 00139 // 00140 // Leave defaults 00141 // 00142 break; 00143 00144 case MiWriteCombined: 00145 00146 // 00147 // We don't support write combining yet 00148 // 00149 ASSERT(FALSE); 00150 break; 00151 00152 default: 00153 00154 // 00155 // Should never happen 00156 // 00157 ASSERT(FALSE); 00158 break; 00159 } 00160 00161 // 00162 // Sanity check and re-flush 00163 // 00164 Pfn = (PFN_NUMBER)(PhysicalAddress.QuadPart >> PAGE_SHIFT); 00165 ASSERT((Pfn1 == MiGetPfnEntry(Pfn)) || (Pfn1 == NULL)); 00166 KeFlushEntireTb(TRUE, TRUE); 00167 KeInvalidateAllCaches(); 00168 00169 // 00170 // Do the mapping 00171 // 00172 do 00173 { 00174 // 00175 // Write the PFN 00176 // 00177 TempPte.u.Hard.PageFrameNumber = Pfn++; 00178 MI_WRITE_VALID_PTE(PointerPte++, TempPte); 00179 } while (--PageCount); 00180 00181 // 00182 // We're done! 00183 // 00184 return BaseAddress; 00185 } 00186 00187 /* 00188 * @implemented 00189 */ 00190 VOID 00191 NTAPI 00192 MmUnmapIoSpace(IN PVOID BaseAddress, 00193 IN SIZE_T NumberOfBytes) 00194 { 00195 PFN_NUMBER Pfn; 00196 PFN_COUNT PageCount; 00197 PMMPTE PointerPte; 00198 00199 // 00200 // Sanity check 00201 // 00202 ASSERT(NumberOfBytes != 0); 00203 00204 // 00205 // Get the page count 00206 // 00207 PageCount = ADDRESS_AND_SIZE_TO_SPAN_PAGES(BaseAddress, NumberOfBytes); 00208 00209 // 00210 // Get the PTE and PFN 00211 // 00212 PointerPte = MiAddressToPte(BaseAddress); 00213 Pfn = PFN_FROM_PTE(PointerPte); 00214 00215 // 00216 // Is this an I/O mapping? 00217 // 00218 if (!MiGetPfnEntry(Pfn)) 00219 { 00220 // 00221 // Destroy the PTE 00222 // 00223 RtlZeroMemory(PointerPte, PageCount * sizeof(MMPTE)); 00224 00225 // 00226 // Blow the TLB 00227 // 00228 KeFlushEntireTb(TRUE, TRUE); 00229 } 00230 00231 // 00232 // Release the PTEs 00233 // 00234 MiReleaseSystemPtes(PointerPte, PageCount, 0); 00235 } 00236 00237 /* 00238 * @implemented 00239 */ 00240 PVOID 00241 NTAPI 00242 MmMapVideoDisplay(IN PHYSICAL_ADDRESS PhysicalAddress, 00243 IN SIZE_T NumberOfBytes, 00244 IN MEMORY_CACHING_TYPE CacheType) 00245 { 00246 PAGED_CODE(); 00247 00248 // 00249 // Call the real function 00250 // 00251 return MmMapIoSpace(PhysicalAddress, NumberOfBytes, CacheType); 00252 } 00253 00254 /* 00255 * @implemented 00256 */ 00257 VOID 00258 NTAPI 00259 MmUnmapVideoDisplay(IN PVOID BaseAddress, 00260 IN SIZE_T NumberOfBytes) 00261 { 00262 // 00263 // Call the real function 00264 // 00265 MmUnmapIoSpace(BaseAddress, NumberOfBytes); 00266 } 00267 00268 /* EOF */ Generated on Sat May 26 2012 04:36:21 for ReactOS by
1.7.6.1
|