-/*++\r
+/** @file\r
+ Cache implementation for EFI FAT File system driver.\r
\r
Copyright (c) 2005 - 2013, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials are licensed and made available\r
-under the terms and conditions of the BSD License which accompanies this\r
-distribution. The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+**/\r
\r
+#include "Fat.h"\r
\r
-Module Name:\r
-\r
- DiskCache.c\r
-\r
-Abstract:\r
+/**\r
\r
- Cache implementation for EFI FAT File system driver\r
+ This function is used by the Data Cache.\r
\r
-Revision History\r
+ When this function is called by write command, all entries in this range\r
+ are older than the contents in disk, so they are invalid; just mark them invalid.\r
\r
---*/\r
+ When this function is called by read command, if any entry in this range\r
+ is dirty, it means that the relative info directly readed from media is older than\r
+ than the info in the cache; So need to update the relative info in the Buffer.\r
\r
-#include "Fat.h"\r
+ @param Volume - FAT file system volume.\r
+ @param IoMode - This function is called by read command or write command\r
+ @param StartPageNo - First PageNo to be checked in the cache.\r
+ @param EndPageNo - Last PageNo to be checked in the cache.\r
+ @param Buffer - The user buffer need to update. Only when doing the read command\r
+ and there is dirty cache in the cache range, this parameter will be used.\r
\r
+**/\r
STATIC\r
VOID\r
FatFlushDataCacheRange (\r
IN UINTN EndPageNo,\r
OUT UINT8 *Buffer\r
)\r
-/*++\r
-\r
-Routine Description:\r
-\r
- This function is used by the Data Cache.\r
-\r
- When this function is called by write command, all entries in this range\r
- are older than the contents in disk, so they are invalid; just mark them invalid.\r
-\r
- When this function is called by read command, if any entry in this range\r
- is dirty, it means that the relative info directly readed from media is older than\r
- than the info in the cache; So need to update the relative info in the Buffer.\r
-\r
-Arguments:\r
-\r
- Volume - FAT file system volume.\r
- IoMode - This function is called by read command or write command\r
- StartPageNo - First PageNo to be checked in the cache.\r
- EndPageNo - Last PageNo to be checked in the cache.\r
- Buffer - The user buffer need to update. Only when doing the read command\r
- and there is dirty cache in the cache range, this parameter will be used.\r
-\r
-Returns:\r
-\r
- None.\r
-\r
---*/\r
{\r
UINTN PageNo;\r
UINTN GroupNo;\r
CACHE_TAG *CacheTag;\r
UINT8 *BaseAddress;\r
\r
- DiskCache = &Volume->DiskCache[CACHE_DATA];\r
+ DiskCache = &Volume->DiskCache[CacheData];\r
BaseAddress = DiskCache->CacheBase;\r
GroupMask = DiskCache->GroupMask;\r
PageAlignment = DiskCache->PageAlignment;\r
// in cache is in this rang, this data in the Buffer need to\r
// be updated with the cache's dirty data.\r
//\r
- if (IoMode == READ_DISK) {\r
+ if (IoMode == ReadDisk) {\r
if (CacheTag->Dirty) {\r
CopyMem (\r
Buffer + ((PageNo - StartPageNo) << PageAlignment),\r
}\r
}\r
\r
+/**\r
+\r
+ Exchange the cache page with the image on the disk\r
+\r
+ @param Volume - FAT file system volume.\r
+ @param DataType - Indicate the cache type.\r
+ @param IoMode - Indicate whether to load this page from disk or store this page to disk.\r
+ @param CacheTag - The Cache Tag for the current cache page.\r
+ @param Task point to task instance.\r
+\r
+ @retval EFI_SUCCESS - Cache page exchanged successfully.\r
+ @return Others - An error occurred when exchanging cache page.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
FatExchangeCachePage (\r
IN CACHE_TAG *CacheTag,\r
IN FAT_TASK *Task\r
)\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Exchange the cache page with the image on the disk\r
-\r
-Arguments:\r
-\r
- Volume - FAT file system volume.\r
- DataType - Indicate the cache type.\r
- IoMode - Indicate whether to load this page from disk or store this page to disk.\r
- CacheTag - The Cache Tag for the current cache page.\r
-\r
-Returns:\r
-\r
- EFI_SUCCESS - Cache page exchanged successfully.\r
- Others - An error occurred when exchanging cache page.\r
-\r
---*/\r
{\r
EFI_STATUS Status;\r
UINTN GroupNo;\r
PageAddress = DiskCache->CacheBase + (GroupNo << PageAlignment);\r
EntryPos = DiskCache->BaseAddress + LShiftU64 (PageNo, PageAlignment);\r
RealSize = CacheTag->RealSize;\r
- if (IoMode == READ_DISK) {\r
+ if (IoMode == ReadDisk) {\r
RealSize = (UINTN)1 << PageAlignment;\r
MaxSize = DiskCache->LimitAddress - EntryPos;\r
if (MaxSize < RealSize) {\r
}\r
\r
WriteCount = 1;\r
- if (DataType == CACHE_FAT && IoMode == WRITE_DISK) {\r
+ if (DataType == CacheFat && IoMode == WriteDisk) {\r
WriteCount = Volume->NumFats;\r
}\r
\r
return EFI_SUCCESS;\r
}\r
\r
+/**\r
+\r
+ Get one cache page by specified PageNo.\r
+\r
+ @param Volume - FAT file system volume.\r
+ @param CacheDataType - The cache type: CACHE_FAT or CACHE_DATA.\r
+ @param PageNo - PageNo to match with the cache.\r
+ @param CacheTag - The Cache Tag for the current cache page.\r
+\r
+ @retval EFI_SUCCESS - Get the cache page successfully.\r
+ @return other - An error occurred when accessing data.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
FatGetCachePage (\r
IN UINTN PageNo,\r
IN CACHE_TAG *CacheTag\r
)\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Get one cache page by specified PageNo.\r
-\r
-Arguments:\r
-\r
- Volume - FAT file system volume.\r
- CacheDataType - The cache type: CACHE_FAT or CACHE_DATA.\r
- PageNo - PageNo to match with the cache.\r
- CacheTag - The Cache Tag for the current cache page.\r
-\r
-Returns:\r
-\r
- EFI_SUCCESS - Get the cache page successfully.\r
- other - An error occurred when accessing data.\r
-\r
---*/\r
{\r
EFI_STATUS Status;\r
UINTN OldPageNo;\r
// Write dirty cache page back to disk\r
//\r
if (CacheTag->RealSize > 0 && CacheTag->Dirty) {\r
- Status = FatExchangeCachePage (Volume, CacheDataType, WRITE_DISK, CacheTag, NULL);\r
+ Status = FatExchangeCachePage (Volume, CacheDataType, WriteDisk, CacheTag, NULL);\r
if (EFI_ERROR (Status)) {\r
return Status;\r
}\r
// Load new data from disk;\r
//\r
CacheTag->PageNo = PageNo;\r
- Status = FatExchangeCachePage (Volume, CacheDataType, READ_DISK, CacheTag, NULL);\r
+ Status = FatExchangeCachePage (Volume, CacheDataType, ReadDisk, CacheTag, NULL);\r
\r
return Status;\r
}\r
\r
+/**\r
+\r
+ Read Length bytes from the position of Offset into Buffer, or\r
+ write Length bytes from Buffer into the position of Offset.\r
+\r
+ @param Volume - FAT file system volume.\r
+ @param CacheDataType - The type of cache: CACHE_DATA or CACHE_FAT.\r
+ @param IoMode - Indicate the type of disk access.\r
+ @param PageNo - The number of unaligned cache page.\r
+ @param Offset - The starting byte of cache page.\r
+ @param Length - The number of bytes that is read or written\r
+ @param Buffer - Buffer containing cache data.\r
+\r
+ @retval EFI_SUCCESS - The data was accessed correctly.\r
+ @return Others - An error occurred when accessing unaligned cache page.\r
+\r
+**/\r
STATIC\r
EFI_STATUS\r
FatAccessUnalignedCachePage (\r
IN UINTN Length,\r
IN OUT VOID *Buffer\r
)\r
-/*++\r
-Routine Description:\r
-\r
- Read Length bytes from the position of Offset into Buffer, or\r
- write Length bytes from Buffer into the position of Offset.\r
-\r
-Arguments:\r
-\r
- Volume - FAT file system volume.\r
- CacheDataType - The type of cache: CACHE_DATA or CACHE_FAT.\r
- IoMode - Indicate the type of disk access.\r
- PageNo - The number of unaligned cache page.\r
- Offset - The starting byte of cache page.\r
- Length - The number of bytes that is read or written\r
- Buffer - Buffer containing cache data.\r
-\r
-Returns:\r
-\r
- EFI_SUCCESS - The data was accessed correctly.\r
- Others - An error occurred when accessing unaligned cache page.\r
-\r
---*/\r
{\r
EFI_STATUS Status;\r
VOID *Source;\r
if (!EFI_ERROR (Status)) {\r
Source = DiskCache->CacheBase + (GroupNo << DiskCache->PageAlignment) + Offset;\r
Destination = Buffer;\r
- if (IoMode != READ_DISK) {\r
+ if (IoMode != ReadDisk) {\r
CacheTag->Dirty = TRUE;\r
DiskCache->Dirty = TRUE;\r
Destination = Source;\r
return Status;\r
}\r
\r
-EFI_STATUS\r
-FatAccessCache (\r
- IN FAT_VOLUME *Volume,\r
- IN CACHE_DATA_TYPE CacheDataType,\r
- IN IO_MODE IoMode,\r
- IN UINT64 Offset,\r
- IN UINTN BufferSize,\r
- IN OUT UINT8 *Buffer,\r
- IN FAT_TASK *Task\r
- )\r
-/*++\r
-Routine Description:\r
+/**\r
\r
Read BufferSize bytes from the position of Offset into Buffer,\r
or write BufferSize bytes from Buffer into the position of Offset.\r
The UnderRun data and OverRun data will be accessed by the Data cache,\r
but the Aligned data will be accessed with disk directly.\r
\r
-Arguments:\r
-\r
- Volume - FAT file system volume.\r
- CacheDataType - The type of cache: CACHE_DATA or CACHE_FAT.\r
- IoMode - Indicate the type of disk access.\r
- Offset - The starting byte offset to read from.\r
- BufferSize - Size of Buffer.\r
- Buffer - Buffer containing cache data.\r
+ @param Volume - FAT file system volume.\r
+ @param CacheDataType - The type of cache: CACHE_DATA or CACHE_FAT.\r
+ @param IoMode - Indicate the type of disk access.\r
+ @param Offset - The starting byte offset to read from.\r
+ @param BufferSize - Size of Buffer.\r
+ @param Buffer - Buffer containing cache data.\r
+ @param Task point to task instance.\r
\r
-Returns:\r
+ @retval EFI_SUCCESS - The data was accessed correctly.\r
+ @retval EFI_MEDIA_CHANGED - The MediaId does not match the current device.\r
+ @return Others - An error occurred when accessing cache.\r
\r
- EFI_SUCCESS - The data was accessed correctly.\r
- EFI_MEDIA_CHANGED - The MediaId does not match the current device.\r
- Others - An error occurred when accessing cache.\r
-\r
---*/\r
+**/\r
+EFI_STATUS\r
+FatAccessCache (\r
+ IN FAT_VOLUME *Volume,\r
+ IN CACHE_DATA_TYPE CacheDataType,\r
+ IN IO_MODE IoMode,\r
+ IN UINT64 Offset,\r
+ IN UINTN BufferSize,\r
+ IN OUT UINT8 *Buffer,\r
+ IN FAT_TASK *Task\r
+ )\r
{\r
EFI_STATUS Status;\r
UINTN PageSize;\r
//\r
// Accessing fat table cannot have alignment data\r
//\r
- ASSERT (CacheDataType == CACHE_DATA);\r
+ ASSERT (CacheDataType == CacheData);\r
\r
EntryPos = Volume->RootPos + LShiftU64 (PageNo, PageAlignment);\r
AlignedSize = AlignedPageCount << PageAlignment;\r
return Status;\r
}\r
\r
-EFI_STATUS\r
-FatVolumeFlushCache (\r
- IN FAT_VOLUME *Volume,\r
- IN FAT_TASK *Task\r
- )\r
-/*++\r
-\r
-Routine Description:\r
+/**\r
\r
Flush all the dirty cache back, include the FAT cache and the Data cache.\r
\r
-Arguments:\r
-\r
- Volume - FAT file system volume.\r
+ @param Volume - FAT file system volume.\r
+ @param Task point to task instance.\r
\r
-Returns:\r
+ @retval EFI_SUCCESS - Flush all the dirty cache back successfully\r
+ @return other - An error occurred when writing the data into the disk\r
\r
- EFI_SUCCESS - Flush all the dirty cache back successfully\r
- other - An error occurred when writing the data into the disk\r
-\r
---*/\r
+**/\r
+EFI_STATUS\r
+FatVolumeFlushCache (\r
+ IN FAT_VOLUME *Volume,\r
+ IN FAT_TASK *Task\r
+ )\r
{\r
EFI_STATUS Status;\r
CACHE_DATA_TYPE CacheDataType;\r
DISK_CACHE *DiskCache;\r
CACHE_TAG *CacheTag;\r
\r
- for (CacheDataType = (CACHE_DATA_TYPE) 0; CacheDataType < CACHE_MAX_TYPE; CacheDataType++) {\r
+ for (CacheDataType = (CACHE_DATA_TYPE) 0; CacheDataType < CacheMaxType; CacheDataType++) {\r
DiskCache = &Volume->DiskCache[CacheDataType];\r
if (DiskCache->Dirty) {\r
//\r
//\r
// Write back all Dirty Data Cache Page to disk\r
//\r
- Status = FatExchangeCachePage (Volume, CacheDataType, WRITE_DISK, CacheTag, Task);\r
+ Status = FatExchangeCachePage (Volume, CacheDataType, WriteDisk, CacheTag, Task);\r
if (EFI_ERROR (Status)) {\r
return Status;\r
}\r
return Status;\r
}\r
\r
-EFI_STATUS\r
-FatInitializeDiskCache (\r
- IN FAT_VOLUME *Volume\r
- )\r
-/*++\r
-\r
-Routine Description:\r
+/**\r
\r
Initialize the disk cache according to Volume's FatType.\r
\r
-Arguments:\r
-\r
- Volume - FAT file system volume.\r
+ @param Volume - FAT file system volume.\r
\r
-Returns:\r
+ @retval EFI_SUCCESS - The disk cache is successfully initialized.\r
+ @retval EFI_OUT_OF_RESOURCES - Not enough memory to allocate disk cache.\r
\r
- EFI_SUCCESS - The disk cache is successfully initialized.\r
- EFI_OUT_OF_RESOURCES - Not enough memory to allocate disk cache.\r
-\r
---*/\r
+**/\r
+EFI_STATUS\r
+FatInitializeDiskCache (\r
+ IN FAT_VOLUME *Volume\r
+ )\r
{\r
DISK_CACHE *DiskCache;\r
UINTN FatCacheGroupCount;\r
//\r
// Configure the parameters of disk cache\r
//\r
- if (Volume->FatType == FAT12) {\r
+ if (Volume->FatType == Fat12) {\r
FatCacheGroupCount = FAT_FATCACHE_GROUP_MIN_COUNT;\r
- DiskCache[CACHE_FAT].PageAlignment = FAT_FATCACHE_PAGE_MIN_ALIGNMENT;\r
- DiskCache[CACHE_DATA].PageAlignment = FAT_DATACACHE_PAGE_MIN_ALIGNMENT;\r
+ DiskCache[CacheFat].PageAlignment = FAT_FATCACHE_PAGE_MIN_ALIGNMENT;\r
+ DiskCache[CacheData].PageAlignment = FAT_DATACACHE_PAGE_MIN_ALIGNMENT;\r
} else {\r
FatCacheGroupCount = FAT_FATCACHE_GROUP_MAX_COUNT;\r
- DiskCache[CACHE_FAT].PageAlignment = FAT_FATCACHE_PAGE_MAX_ALIGNMENT;\r
- DiskCache[CACHE_DATA].PageAlignment = FAT_DATACACHE_PAGE_MAX_ALIGNMENT;\r
+ DiskCache[CacheFat].PageAlignment = FAT_FATCACHE_PAGE_MAX_ALIGNMENT;\r
+ DiskCache[CacheData].PageAlignment = FAT_DATACACHE_PAGE_MAX_ALIGNMENT;\r
}\r
\r
- DiskCache[CACHE_DATA].GroupMask = FAT_DATACACHE_GROUP_COUNT - 1;\r
- DiskCache[CACHE_DATA].BaseAddress = Volume->RootPos;\r
- DiskCache[CACHE_DATA].LimitAddress = Volume->VolumeSize;\r
- DiskCache[CACHE_FAT].GroupMask = FatCacheGroupCount - 1;\r
- DiskCache[CACHE_FAT].BaseAddress = Volume->FatPos;\r
- DiskCache[CACHE_FAT].LimitAddress = Volume->FatPos + Volume->FatSize;\r
- FatCacheSize = FatCacheGroupCount << DiskCache[CACHE_FAT].PageAlignment;\r
- DataCacheSize = FAT_DATACACHE_GROUP_COUNT << DiskCache[CACHE_DATA].PageAlignment;\r
+ DiskCache[CacheData].GroupMask = FAT_DATACACHE_GROUP_COUNT - 1;\r
+ DiskCache[CacheData].BaseAddress = Volume->RootPos;\r
+ DiskCache[CacheData].LimitAddress = Volume->VolumeSize;\r
+ DiskCache[CacheFat].GroupMask = FatCacheGroupCount - 1;\r
+ DiskCache[CacheFat].BaseAddress = Volume->FatPos;\r
+ DiskCache[CacheFat].LimitAddress = Volume->FatPos + Volume->FatSize;\r
+ FatCacheSize = FatCacheGroupCount << DiskCache[CacheFat].PageAlignment;\r
+ DataCacheSize = FAT_DATACACHE_GROUP_COUNT << DiskCache[CacheData].PageAlignment;\r
//\r
// Allocate the Fat Cache buffer\r
//\r
}\r
\r
Volume->CacheBuffer = CacheBuffer;\r
- DiskCache[CACHE_FAT].CacheBase = CacheBuffer;\r
- DiskCache[CACHE_DATA].CacheBase = CacheBuffer + FatCacheSize;\r
+ DiskCache[CacheFat].CacheBase = CacheBuffer;\r
+ DiskCache[CacheData].CacheBase = CacheBuffer + FatCacheSize;\r
return EFI_SUCCESS;\r
}\r