list_for_each_safe(entry, n, &block_cache) {
node = (struct block_cache_node *)entry;
- if ((node->iftype == iftype) &&
- (node->devnum == devnum)) {
+ if (iftype == -1 ||
+ (node->iftype == iftype && node->devnum == devnum)) {
list_del(entry);
free(node->cache);
free(node);
void blkcache_configure(unsigned blocks, unsigned entries)
{
- struct block_cache_node *node;
+ /* invalidate cache if there is a change */
if ((blocks != _stats.max_blocks_per_entry) ||
- (entries != _stats.max_entries)) {
- /* invalidate cache */
- while (!list_empty(&block_cache)) {
- node = (struct block_cache_node *)block_cache.next;
- list_del(&node->lh);
- free(node->cache);
- free(node);
- }
- _stats.entries = 0;
- }
+ (entries != _stats.max_entries))
+ blkcache_invalidate(-1, 0);
_stats.max_blocks_per_entry = blocks;
_stats.max_entries = entries;
_stats.hits = 0;
_stats.misses = 0;
}
+
+void blkcache_free(void)
+{
+ blkcache_invalidate(-1, 0);
+}
* blkcache_invalidate() - discard the cache for a set of blocks
* because of a write or device (re)initialization.
*
- * @param iftype - uclass_id_x for type of device
- * @param dev - device index of particular type
+ * @iftype - UCLASS_ID_ for type of device, or -1 for any
+ * @dev - device index of particular type, if @iftype is not -1
*/
void blkcache_invalidate(int iftype, int dev);
*/
void blkcache_stats(struct block_cache_stats *stats);
+/** blkcache_free() - free all memory allocated to the block cache */
+void blkcache_free(void);
+
#else
static inline int blkcache_read(int iftype, int dev,
static inline void blkcache_invalidate(int iftype, int dev) {}
+static inline void blkcache_free(void) {}
+
#endif
#if CONFIG_IS_ENABLED(BLK)