diff options
Diffstat (limited to 'firmware/include/disk_cache.h')
-rw-r--r-- | firmware/include/disk_cache.h | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/firmware/include/disk_cache.h b/firmware/include/disk_cache.h new file mode 100644 index 0000000000..725b3778cc --- /dev/null +++ b/firmware/include/disk_cache.h | |||
@@ -0,0 +1,83 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2014 by Michael Sevakis | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | #ifndef DISK_CACHE_H | ||
22 | #define DISK_CACHE_H | ||
23 | |||
24 | /* This needs enough for all file handles to have a buffer in the worst case | ||
25 | * plus at least one reserved exclusively for the cache client and a couple | ||
26 | * for other file system code. The buffers are put to use by the cache if not | ||
27 | * taken for another purpose (meaning nothing is wasted sitting fallow). | ||
28 | * | ||
29 | * One map per volume is maintained in order to avoid collisions between | ||
30 | * volumes that would slow cache probing. DC_MAP_NUM_ENTRIES is the number | ||
31 | * for each map per volume. The buffers themselves are shared. | ||
32 | */ | ||
33 | #if MEMORYSIZE < 8 | ||
34 | #define DC_NUM_ENTRIES 32 | ||
35 | #define DC_MAP_NUM_ENTRIES 128 | ||
36 | #elif MEMORYSIZE <= 32 | ||
37 | #define DC_NUM_ENTRIES 48 | ||
38 | #define DC_MAP_NUM_ENTRIES 128 | ||
39 | #else /* MEMORYSIZE > 32 */ | ||
40 | #define DC_NUM_ENTRIES 64 | ||
41 | #define DC_MAP_NUM_ENTRIES 256 | ||
42 | #endif /* MEMORYSIZE */ | ||
43 | |||
44 | /* this _could_ be larger than a sector if that would ever be useful */ | ||
45 | #define DC_CACHE_BUFSIZE SECTOR_SIZE | ||
46 | |||
47 | #include "mutex.h" | ||
48 | #include "mv.h" | ||
49 | |||
50 | static inline void dc_lock_cache(void) | ||
51 | { | ||
52 | extern struct mutex disk_cache_mutex; | ||
53 | mutex_lock(&disk_cache_mutex); | ||
54 | } | ||
55 | |||
56 | static inline void dc_unlock_cache(void) | ||
57 | { | ||
58 | extern struct mutex disk_cache_mutex; | ||
59 | mutex_unlock(&disk_cache_mutex); | ||
60 | } | ||
61 | |||
62 | void * dc_cache_probe(IF_MV(int volume,) unsigned long secnum, | ||
63 | unsigned int *flags); | ||
64 | void dc_dirty_buf(void *buf); | ||
65 | void dc_discard_buf(void *buf); | ||
66 | void dc_commit_all(IF_MV_NONVOID(int volume)); | ||
67 | void dc_discard_all(IF_MV_NONVOID(int volume)); | ||
68 | |||
69 | void dc_init(void) INIT_ATTR; | ||
70 | |||
71 | /* in addition to filling, writeback is implemented by the client */ | ||
72 | extern void dc_writeback_callback(IF_MV(int volume, ) unsigned long sector, | ||
73 | void *buf); | ||
74 | |||
75 | |||
76 | /** These synchronize and can be called by anyone **/ | ||
77 | |||
78 | /* expropriate a buffer from the cache of DC_CACHE_BUFSIZE bytes */ | ||
79 | void * dc_get_buffer(void); | ||
80 | /* return buffer to the cache by buffer */ | ||
81 | void dc_release_buffer(void *buf); | ||
82 | |||
83 | #endif /* DISK_CACHE_H */ | ||