* - IO Cache
*
* By thePowersGang (John Hodge)
+ *
+ * TODO: Convert to use spare physical pages instead
*/
#define DEBUG 0
#include <acess.h>
// === TYPES ===
typedef struct sIOCache_Ent tIOCache_Ent;
+typedef struct sIOCache_PageInfo tIOCache_PageInfo;
// === STRUCTURES ===
struct sIOCache_Ent
Uint8 Data[];
};
+struct sIOCache_PageInfo
+{
+ tIOCache_PageInfo *GlobalNext;
+ tIOCache_PageInfo *CacheNext;
+ tIOCache *Owner;
+ tPAddr BasePhys;
+ Uint64 BaseOffset;
+};
+
struct sIOCache
{
tIOCache *Next;
tShortSpinlock glIOCache_Caches;
tIOCache *gIOCache_Caches = NULL;
int giIOCache_NumCaches = 0;
+tIOCache_PageInfo *gIOCache_GlobalPages;
// === CODE ===
/**
*/
tIOCache *IOCache_Create( tIOCache_WriteCallback Write, Uint32 ID, int SectorSize, int CacheSize )
{
- tIOCache *ret = malloc( sizeof(tIOCache) );
+ tIOCache *ret = calloc( 1, sizeof(tIOCache) );
// Sanity Check
if(!ret) return NULL;
ret->ID = ID;
ret->Write = Write;
ret->CacheSize = CacheSize;
- ret->CacheUsed = 0;
- ret->Entries = 0;
// Append to list
SHORTLOCK( &glIOCache_Caches );
oldestPrev = prev;
}
}
+ if( !oldest ) {
+ Log_Error("IOCache", "Cache full, but also empty");
+ return -1;
+ }
// Remove from list, write back and free
oldestPrev->Next = oldest->Next;
if(oldest->LastWrite && Cache->Mode != IOCACHE_VIRTUAL)
// Remove from list
SHORTLOCK( &glIOCache_Caches );
{
- tIOCache *ent;
- tIOCache *prev = (tIOCache*)&gIOCache_Caches;
- for(ent = gIOCache_Caches;
- ent;
- prev = ent, ent = ent->Next )
+ tIOCache *cache;
+ tIOCache *prev_cache = (tIOCache*)&gIOCache_Caches;
+ for(cache = gIOCache_Caches;
+ cache;
+ prev_cache = cache, cache = cache->Next )
{
- if(ent == Cache) {
- prev->Next = ent->Next;
+ if(cache == Cache) {
+ prev_cache->Next = cache->Next;
break;
}
}