1 /* drivers/mtd/devices/goldfish_nand_cache.h 2 ** 3 ** Copyright (C) 2015 Google, Inc. 4 ** 5 ** This software is licensed under the terms of the GNU General Public 6 ** License version 2, as published by the Free Software Foundation, and 7 ** may be copied, distributed, and modified under those terms. 8 ** 9 ** This program is distributed in the hope that it will be useful, 10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 ** GNU General Public License for more details. 13 ** 14 */ 15 16 #ifndef GOLDFISH_NAND_CACHE_H 17 #define GOLDFISH_NAND_CACHE_H 18 19 #include <linux/mtd/mtd.h> 20 21 struct goldfish_nand_cache; 22 23 /* Allocate a software cache in driver's non-pageable memory for the given 24 * Goldfish device. Return true on success. 25 * This function is not thread-protected. The caller is responsible to make 26 * sure no more than one thread is allocating/deallocating cache at a time. 27 */ 28 bool goldfish_allocate_cache(struct mtd_info *device); 29 30 /* Release the cache allocated by goldfish_allocate_cache() for the given 31 * Goldfish device. 32 * This function is not thread-protected. The caller is responsible to make 33 * sure no more than one thread is allocating/deallocating cache at a time. 34 */ 35 void goldfish_deallocate_cache(struct mtd_info *device); 36 37 /* Return the cache allocated by goldfish_allocate_cache() for the given 38 * Goldfish device. Return NULL if the cache doesn't exist. 39 */ 40 struct goldfish_nand_cache *goldfish_locate_nand_cache( 41 struct mtd_info *device); 42 43 /* Invalidate the cache for the given |device| if needed when the data at 44 * address |from| of |length| bytes becomes dirty. 45 */ 46 void goldfish_invalidate_cache(struct mtd_info *device, loff_t from, 47 size_t length); 48 49 /* Return the number of bytes that the given |cache| should fetch in next 50 * refresh. 51 */ 52 size_t goldfish_get_cache_refresh_size(struct goldfish_nand_cache *cache); 53 54 /* Return the pointer to the data buffer of the given |cache|. */ 55 u_char *goldfish_get_cache_buffer(struct goldfish_nand_cache *cache); 56 57 /* Update state of the given |cache| that it holds a valid copy of data at 58 * address |from| of |length| bytes. 59 */ 60 bool goldfish_update_refreshed_cache(struct goldfish_nand_cache *cache, 61 loff_t from, size_t length); 62 63 /* Read data at address |from| of |length| bytes from the given |cache|. 64 * Return true on success, and if success, update |buffer| with the data from 65 * the cache and set |read_length| to the number of bytes that have been read. 66 */ 67 bool goldfish_read_from_cache(struct goldfish_nand_cache *cache, loff_t from, 68 size_t length, size_t *read_length, 69 u_char *buffer); 70 71 #endif /* GOLDFISH_NAND_CACHE_H */ 72