1 // Copyright 2018 The Fuchsia Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #pragma once
6 
7 #include <stdlib.h>
8 
9 /***********************************************************************/
10 /* Type Declarations                                                   */
11 /***********************************************************************/
12 // Cache miss read/write interface
13 typedef int (*ftlmcFuncW)(void* ftl, ui32 mpn, void* buf);
14 typedef int (*ftlmcFuncR)(void* ftl, ui32 mpn, void* buf, int* unmapped);
15 
16 // Cache Entry Type
17 typedef struct ftlmc_cache_entry ftlmcEntry;
18 
19 // Cache Type
20 typedef struct {
21     ftlmcEntry* entry;     // array containing all cache entries
22     ftlmcEntry** hash_tbl; // hash table used to index cached pages
23     CircLink lru_list;     // least recently used entry list
24     void* ftl;             // handle to FTL volume using cache
25     ftlmcFuncW write_TFS;  // write function on cache miss
26     ftlmcFuncR read_TFS;   // read function on cache miss
27     ui32 num_mpgs;         // number of cached map pages
28     ui32 num_dirty;        // number of dirty cached entries
29     ui32 mpg_sz;           // size of a cached map page in bytes
30 } FTLMC;
31 
32 /***********************************************************************/
33 /* Function Prototypes                                                 */
34 /***********************************************************************/
35 FTLMC* ftlmcNew(void* ftl_ndm, ui32 cache_size, ftlmcFuncW wf, ftlmcFuncR rf, ui32 mpg_sz);
36 void ftlmcDelete(FTLMC** ftlmc_ptr);
37 void ftlmcInit(FTLMC* ftlmc);
38 void* ftlmcGetPage(FTLMC* ftlmc, ui32 mpn, int* new_map);
39 int ftlmcFlushPage(FTLMC* ftlmc, ui32 mpn);
40 int ftlmcFlushMaps(FTLMC* ftlmc);
41 ui32* ftlmcInCache(FTLMC* ftlmc, ui32 mpn);
42 ui32 ftlmcRAM(const FTLMC* ftlmc);
43