diff --git a/drivers/Kconfig b/drivers/Kconfig index 6828c829fb..5241f95025 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -62,6 +62,23 @@ config DRVR_READAHEAD Enable generic read-ahead buffering support that can be used by a variety of drivers. +if DRVR_WRITEBUFFER || DRVR_READAHEAD + +config DRVR_READBYTES + bool "Support byte read method" + default y if MTD_BYTE_WRITE + default n if !MTD_BYTE_WRITE + +config DRVR_REMOVABLE + bool "Support removable media" + default n + +config DRVR_INVALIDATE + bool "Support cache invalidation" + default n + +endif # DRVR_WRITEBUFFER || DRVR_READAHEAD + config RAMDISK bool "RAM Disk Support" default n diff --git a/drivers/mtd/Kconfig b/drivers/mtd/Kconfig index 26945d5c69..16c84225e0 100644 --- a/drivers/mtd/Kconfig +++ b/drivers/mtd/Kconfig @@ -26,6 +26,16 @@ config MTD_PARTITION managing the sub-region of flash beginning at 'offset' (in blocks) and of size 'nblocks' on the device specified by 'mtd'. +config FTL_WRITEBUFFER + bool "Enable write buffering in the FTL layer" + default n + depends on DRVR_WRITEBUFFER + +config FTL_READAHEAD + bool "Enable read-ahead buffering in the FTL layer" + default n + depends on DRVR_READAHEAD + config MTD_SECT512 bool "512B sector conversion" default n @@ -70,6 +80,8 @@ config MTD_WRBUFFER bool "Enable MTD write buffering default n depends on DRVR_WRITEBUFFER + select DRVR_INVALIDATE + select DRVR_READBYTES ---help--- Build the mtd_rwbuffer layer and enable support for write buffering. @@ -87,6 +99,8 @@ config MTD_READAHEAD bool "Enable MTD read-ahead buffering default n depends on DRVR_READAHEAD + select DRVR_INVALIDATE + select DRVR_READBYTES ---help--- Build the mtd_rwbuffer layer and enable support for read-ahead buffering. @@ -360,15 +374,28 @@ config MTD_SMART (typically 2K - 4K based on memory size) and relocating sectors as needed when an erase block needs to be erased. +if MTD_SMART + config MTD_SMART_SECTOR_SIZE int "SMART Device sector size" - depends on MTD_SMART default 1024 ---help--- - Sets the size of a single alloction on the SMART device. Larger sector sizes + Sets the size of a single allocation on the SMART device. Larger sector sizes reduce overhead per sector, but cause more wasted space with a lot of smaller files. +config MTD_SMART_WRITEBUFFER + bool "Enable SMART write bufferingr" + default n + depends on DRVR_WRITEBUFFER + +config MTD_SMART_READAHEAD + bool "Enable SMART read-ahead buffering" + default n + depends on DRVR_READAHEAD + +endif # MTD_SMART + config MTD_RAMTRON bool "SPI-based RAMTRON NVRAM Devices FM25V10" default n diff --git a/drivers/mtd/ftl.c b/drivers/mtd/ftl.c index f2fb3b6d12..837928fd42 100644 --- a/drivers/mtd/ftl.c +++ b/drivers/mtd/ftl.c @@ -59,8 +59,8 @@ * Pre-processor Definitions ****************************************************************************/ -#if defined(CONFIG_DRVR_READAHEAD) || defined(CONFIG_DRVR_WRITEBUFFER) -# define CONFIG_FTL_RWBUFFER 1 +#if defined(CONFIG_FTL_READAHEAD) || defined(CONFIG_FTL_WRITEBUFFER) +# define FTL_HAVE_RWBUFFER 1 #endif /**************************************************************************** @@ -71,7 +71,7 @@ struct ftl_struct_s { FAR struct mtd_dev_s *mtd; /* Contained MTD interface */ struct mtd_geometry_s geo; /* Device geometry */ -#ifdef CONFIG_FTL_RWBUFFER +#ifdef FTL_HAVE_RWBUFFER struct rwbuffer_s rwb; /* Read-ahead/write buffer support */ #endif uint16_t blkper; /* R/W blocks per erase block */ @@ -188,7 +188,7 @@ static ssize_t ftl_read(FAR struct inode *inode, unsigned char *buffer, DEBUGASSERT(inode && inode->i_private); dev = (FAR struct ftl_struct_s *)inode->i_private; -#ifdef CONFIG_DRVR_READAHEAD +#ifdef CONFIG_FTL_READAHEAD return rwb_read(&dev->rwb, start_sector, nsectors, buffer); #else return ftl_reload(dev, buffer, start_sector, nsectors); @@ -389,7 +389,7 @@ static ssize_t ftl_write(FAR struct inode *inode, const unsigned char *buffer, DEBUGASSERT(inode && inode->i_private); dev = (struct ftl_struct_s *)inode->i_private; -#ifdef CONFIG_DRVR_WRITEBUFFER +#ifdef CONFIG_FTL_WRITEBUFFER return rwb_write(&dev->rwb, start_sector, nsectors, buffer); #else return ftl_flush(dev, buffer, start_sector, nsectors); @@ -562,17 +562,17 @@ int ftl_initialize(int minor, FAR struct mtd_dev_s *mtd) /* Configure read-ahead/write buffering */ -#ifdef CONFIG_FTL_RWBUFFER +#ifdef FTL_HAVE_RWBUFFER dev->rwb.blocksize = dev->geo.blocksize; dev->rwb.nblocks = dev->geo.neraseblocks * dev->blkper; dev->rwb.dev = (FAR void *)dev; -#if defined(CONFIG_FS_WRITABLE) && defined(CONFIG_DRVR_WRITEBUFFER) +#if defined(CONFIG_FS_WRITABLE) && defined(CONFIG_FTL_WRITEBUFFER) dev->rwb.wrmaxblocks = dev->blkper; dev->rwb.wrflush = ftl_flush; #endif -#ifdef CONFIG_DRVR_READAHEAD +#ifdef CONFIG_FTL_READAHEAD dev->rwb.rhmaxblocks = dev->blkper; dev->rwb.rhreload = ftl_reload; #endif diff --git a/drivers/mtd/mtd_rwbuffer.c b/drivers/mtd/mtd_rwbuffer.c index 3aed371af0..0f6e549e6f 100644 --- a/drivers/mtd/mtd_rwbuffer.c +++ b/drivers/mtd/mtd_rwbuffer.c @@ -62,6 +62,14 @@ * Pre-processor Definitions ************************************************************************************/ +#ifndef CONFIG_DRVR_INVALIDATE +# error This driver requires CONFIG_DRVR_INVALIDATE +#endif + +#ifndef CONFIG_DRVR_READBYTES +# error This driver requires CONFIG_DRVR_READBYTES +#endif + #ifndef CONFIG_MTD_NWRBLOCKS # define CONFIG_MTD_NWRBLOCKS 4 #endif @@ -233,7 +241,7 @@ static ssize_t mtd_read(FAR struct mtd_dev_s *dev, off_t offset, size_t nbytes, * needs to read any data. */ - return mtd_readbytes(&priv->rwb, offset, nbytes, buffer); + return rwb_readbytes(&priv->rwb, offset, nbytes, buffer); } /************************************************************************************ diff --git a/drivers/mtd/smart.c b/drivers/mtd/smart.c index b16f58b686..0065bdd71f 100644 --- a/drivers/mtd/smart.c +++ b/drivers/mtd/smart.c @@ -105,9 +105,9 @@ * other for our use, such as format * sector, etc. */ -#if defined(CONFIG_DRVR_READAHEAD) || (defined(CONFIG_DRVR_WRITABLE) && \ - defined(CONFIG_DRVR_WRITEBUFFER)) -# define CONFIG_SMART_RWBUFFER 1 +#if defined(CONFIG_MTD_SMART_READAHEAD) || (defined(CONFIG_DRVR_WRITABLE) && \ + defined(CONFIG_MTD_SMART_WRITEBUFFER)) +# define SMART_HAVE_RWBUFFER 1 #endif #ifndef CONFIG_MTD_SMART_SECTOR_SIZE diff --git a/drivers/rwbuffer.c b/drivers/rwbuffer.c index c54277ddb7..6bb6c27625 100644 --- a/drivers/rwbuffer.c +++ b/drivers/rwbuffer.c @@ -389,7 +389,7 @@ static int rwb_rhreload(struct rwbuffer_s *rwb, off_t startblock) * ****************************************************************************/ -#ifdef CONFIG_DRVR_WRITEBUFFER +#if defined(CONFIG_DRVR_WRITEBUFFER) && defined(CONFIG_DRVR_INVALIDATE) int rwb_invalidate_writebuffer(FAR struct rwbuffer_s *rwb, off_t startblock, size_t blockcount) { @@ -525,7 +525,7 @@ int rwb_invalidate_writebuffer(FAR struct rwbuffer_s *rwb, * ****************************************************************************/ -#ifdef CONFIG_DRVR_READAHEAD +#if defined(CONFIG_DRVR_READAHEAD) && defined(CONFIG_DRVR_INVALIDATE) int rwb_invalidate_readahead(FAR struct rwbuffer_s *rwb, off_t startblock, size_t blockcount) { @@ -924,6 +924,7 @@ int rwb_write(FAR struct rwbuffer_s *rwb, off_t startblock, * ****************************************************************************/ +#ifdef CONFIG_DRVR_REMOVABLE int rwb_mediaremoved(FAR struct rwbuffer_s *rwb) { #ifdef CONFIG_DRVR_WRITEBUFFER @@ -946,6 +947,7 @@ int rwb_mediaremoved(FAR struct rwbuffer_s *rwb) return OK; } +#endif /**************************************************************************** * Name: rwb_invalidate @@ -955,6 +957,7 @@ int rwb_mediaremoved(FAR struct rwbuffer_s *rwb) * ****************************************************************************/ +#ifdef CONFIG_DRVR_INVALIDATE int rwb_invalidate(FAR struct rwbuffer_s *rwb, off_t startblock, size_t blockcount) { @@ -980,6 +983,7 @@ int rwb_invalidate(FAR struct rwbuffer_s *rwb, return OK; } +#endif #endif /* CONFIG_DRVR_WRITEBUFFER || CONFIG_DRVR_READAHEAD */ diff --git a/include/nuttx/rwbuffer.h b/include/nuttx/rwbuffer.h index a920c33ccc..3997a5c7c8 100755 --- a/include/nuttx/rwbuffer.h +++ b/include/nuttx/rwbuffer.h @@ -186,14 +186,21 @@ ssize_t rwb_write(FAR struct rwbuffer_s *rwb, /* Character oriented transfers */ -ssize_t mtd_readbytes(FAR struct rwbuffer_s *dev, off_t offset, +#ifdef CONFIG_DRVR_READBYTES +ssize_t rwb_readbytes(FAR struct rwbuffer_s *dev, off_t offset, size_t nbytes, FAR uint8_t *buffer); +#endif /* Media events */ +#ifdef CONFIG_DRVR_REMOVABLE int rwb_mediaremoved(FAR struct rwbuffer_s *rwb); +#endif + +#ifdef CONFIG_DRVR_INVALIDATE int rwb_invalidate(FAR struct rwbuffer_s *rwb, off_t startblock, size_t blockcount); +#endif #undef EXTERN #if defined(__cplusplus)