mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* (no subject)
@ 2011-04-08 14:48 Sascha Hauer
  2011-04-08 14:48 ` [PATCH 1/4] add block support Sascha Hauer
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Sascha Hauer @ 2011-04-08 14:48 UTC (permalink / raw)
  To: barebox

The following adds a caching block layer to speed up for
example mmc card operations. Also, write support on ata and
mci devices is made optional to save some binary space.

Sascha Hauer (4):
      add block support
      ata: use block support
      ata: make write support optional
      mci: make write support optional

 common/Kconfig           |    6 +
 common/Makefile          |    1 +
 common/block.c           |  263 ++++++++++++++++++++++++++++++++++++++++++++++
 drivers/ata/Kconfig      |    5 +
 drivers/ata/disk_drive.c |  196 +++++++---------------------------
 drivers/mci/Kconfig      |    5 +
 drivers/mci/mci-core.c   |    6 +
 fs/Makefile              |    2 +-
 include/block.h          |   32 ++++++
 9 files changed, 357 insertions(+), 159 deletions(-)
 create mode 100644 common/block.c
 create mode 100644 include/block.h


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/4] add block support
  2011-04-08 14:48 Sascha Hauer
@ 2011-04-08 14:48 ` Sascha Hauer
  2011-04-08 14:48 ` [PATCH 2/4] ata: use " Sascha Hauer
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2011-04-08 14:48 UTC (permalink / raw)
  To: barebox

This adds a simple block layer to barebox. Reading and writing
to block devices can be painfully slow without caching, so
add a simple caching layer here.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/Kconfig  |    6 ++
 common/Makefile |    1 +
 common/block.c  |  263 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 fs/Makefile     |    2 +-
 include/block.h |   32 +++++++
 5 files changed, 303 insertions(+), 1 deletions(-)
 create mode 100644 common/block.c
 create mode 100644 include/block.h

diff --git a/common/Kconfig b/common/Kconfig
index 9e30579..ac83231 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -31,6 +31,12 @@ config ENV_HANDLING
 config GENERIC_GPIO
 	bool
 
+config BLOCK
+	bool
+
+config BLOCK_WRITE
+	bool
+
 menu "General Settings              "
 
 config LOCALVERSION_AUTO
diff --git a/common/Makefile b/common/Makefile
index d8c302f..3fc66f4 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -6,6 +6,7 @@ obj-$(CONFIG_KALLSYMS)		+= kallsyms.o
 obj-$(CONFIG_ENV_HANDLING)	+= environment.o
 obj-$(CONFIG_AUTO_COMPLETE)	+= complete.o
 obj-$(CONFIG_POLLER)		+= poller.o
+obj-$(CONFIG_BLOCK)		+= block.o
 
 obj-y += dlmalloc.o
 obj-y += clock.o
diff --git a/common/block.c b/common/block.c
new file mode 100644
index 0000000..24377c6
--- /dev/null
+++ b/common/block.c
@@ -0,0 +1,263 @@
+/*
+ * block.c - simple block layer
+ *
+ * Copyright (c) 2011 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+#include <common.h>
+#include <block.h>
+#include <linux/err.h>
+
+#define BLOCKSIZE(blk)	(1 << blk->blockbits)
+
+#define WRBUFFER_LAST(blk)	(blk->wrblock + blk->wrbufblocks - 1)
+
+#ifdef CONFIG_BLOCK_WRITE
+static int writebuffer_flush(struct block_device *blk)
+{
+	if (!blk->wrbufblocks)
+		return 0;
+
+	blk->ops->write(blk, blk->wrbuf, blk->wrblock,
+			blk->wrbufblocks);
+
+	blk->wrbufblocks = 0;
+
+	return 0;
+}
+
+static int block_put(struct block_device *blk, const void *buf, int block)
+{
+	if (block >= blk->num_blocks)
+		return -EIO;
+
+	if (block < blk->wrblock || block > blk->wrblock + blk->wrbufblocks) {
+		writebuffer_flush(blk);
+	}
+
+	if (blk->wrbufblocks == 0) {
+		blk->wrblock = block;
+		blk->wrbufblocks = 1;
+	}
+
+	memcpy(blk->wrbuf + (block - blk->wrblock) * BLOCKSIZE(blk),
+			buf, BLOCKSIZE(blk));
+
+	if (block > WRBUFFER_LAST(blk))
+		blk->wrbufblocks++;
+
+	if (blk->wrbufblocks == blk->wrbufsize)
+		writebuffer_flush(blk);
+
+	return 0;
+}
+
+#else
+static int writebuffer_flush(struct block_device *blk)
+{
+	return 0;
+}
+#endif
+
+static void *block_get(struct block_device *blk, int block)
+{
+	int ret;
+	int num_blocks;
+
+	if (block >= blk->num_blocks)
+		return ERR_PTR(-EIO);
+
+	/* first look into write buffer */
+	if (block >= blk->wrblock && block <= WRBUFFER_LAST(blk))
+		return blk->wrbuf + (block - blk->wrblock) * BLOCKSIZE(blk);
+
+	/* then look into read buffer */
+	if (block >= blk->rdblock && block <= blk->rdblockend)
+		return blk->rdbuf + (block - blk->rdblock) * BLOCKSIZE(blk);
+
+	/*
+	 * If none of the buffers above match read the block from
+	 * the device
+	 */
+	num_blocks = min(blk->rdbufsize, blk->num_blocks - block);
+
+	ret = blk->ops->read(blk, blk->rdbuf, block, num_blocks);
+	if (ret)
+		return ERR_PTR(ret);
+
+	blk->rdblock = block;
+	blk->rdblockend = block + num_blocks - 1;
+
+	return blk->rdbuf;
+}
+
+static ssize_t block_read(struct cdev *cdev, void *buf, size_t count,
+		unsigned long offset, unsigned long flags)
+{
+	struct block_device *blk = cdev->priv;
+	unsigned long mask = BLOCKSIZE(blk) - 1;
+	unsigned long block = offset >> blk->blockbits;
+	size_t icount = count;
+	int blocks;
+
+	if (offset & mask) {
+		size_t now = BLOCKSIZE(blk) - (offset & mask);
+		void *iobuf = block_get(blk, block);
+
+		now = min(count, now);
+
+		if (IS_ERR(iobuf))
+			return PTR_ERR(iobuf);
+
+		memcpy(buf, iobuf + (offset & mask), now);
+		buf += now;
+		count -= now;
+		block++;
+	}
+
+	blocks = count >> blk->blockbits;
+
+	while (blocks) {
+		void *iobuf = block_get(blk, block);
+
+		if (IS_ERR(iobuf))
+			return PTR_ERR(iobuf);
+
+		memcpy(buf, iobuf, BLOCKSIZE(blk));
+		buf += BLOCKSIZE(blk);
+		blocks--;
+		block++;
+		count -= BLOCKSIZE(blk);
+	}
+
+	if (count) {
+		void *iobuf = block_get(blk, block);
+
+		if (IS_ERR(iobuf))
+			return PTR_ERR(iobuf);
+
+		memcpy(buf, iobuf, count);
+	}
+
+	return icount;
+}
+
+#ifdef CONFIG_BLOCK_WRITE
+static ssize_t block_write(struct cdev *cdev, const void *buf, size_t count,
+		unsigned long offset, ulong flags)
+{
+	struct block_device *blk = cdev->priv;
+	unsigned long mask = BLOCKSIZE(blk) - 1;
+	unsigned long block = offset >> blk->blockbits;
+	size_t icount = count;
+	int blocks;
+
+	if (offset & mask) {
+		size_t now = BLOCKSIZE(blk) - (offset & mask);
+		void *iobuf = block_get(blk, block);
+
+		now = min(count, now);
+
+		if (IS_ERR(iobuf))
+			return PTR_ERR(iobuf);
+
+		memcpy(iobuf + (offset & mask), buf, now);
+		block_put(blk, iobuf, block);
+		buf += now;
+		count -= now;
+		block++;
+	}
+
+	blocks = count >> blk->blockbits;
+
+	while (blocks) {
+		block_put(blk, buf, block);
+		buf += BLOCKSIZE(blk);
+		blocks--;
+		block++;
+		count -= BLOCKSIZE(blk);
+	}
+
+	if (count) {
+		void *iobuf = block_get(blk, block);
+
+		if (IS_ERR(iobuf))
+			return PTR_ERR(iobuf);
+
+		memcpy(iobuf, buf, count);
+		block_put(blk, iobuf, block);
+	}
+
+	return icount;
+}
+#endif
+
+static int block_close(struct cdev *cdev)
+{
+	struct block_device *blk = cdev->priv;
+
+	return writebuffer_flush(blk);
+}
+
+static int block_flush(struct cdev *cdev)
+{
+	struct block_device *blk = cdev->priv;
+
+	return writebuffer_flush(blk);
+}
+
+struct file_operations block_ops = {
+	.read	= block_read,
+#ifdef CONFIG_BLOCK_WRITE
+	.write	= block_write,
+#endif
+	.close	= block_close,
+	.flush	= block_flush,
+	.lseek	= dev_lseek_default,
+};
+
+int blockdevice_register(struct block_device *blk)
+{
+	size_t size = blk->num_blocks * BLOCKSIZE(blk);
+	int ret;
+
+	blk->cdev.size = size;
+	blk->cdev.dev = blk->dev;
+	blk->cdev.ops = &block_ops;
+	blk->cdev.priv = blk;
+	blk->rdbufsize = PAGE_SIZE >> blk->blockbits;
+	blk->rdbuf = xmalloc(PAGE_SIZE);
+	blk->rdblock = 1;
+	blk->rdblockend = 0;
+	blk->wrbufsize = PAGE_SIZE >> blk->blockbits;
+	blk->wrbuf = xmalloc(PAGE_SIZE);
+	blk->wrblock = 0;
+	blk->wrbufblocks = 0;
+
+	ret = devfs_create(&blk->cdev);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
+int blockdevice_unregister(struct block_device *blk)
+{
+	return 0;
+}
+
diff --git a/fs/Makefile b/fs/Makefile
index 4aa92ef..9e97db3 100644
--- a/fs/Makefile
+++ b/fs/Makefile
@@ -2,4 +2,4 @@ obj-$(CONFIG_FS_CRAMFS)	+= cramfs/
 obj-$(CONFIG_FS_RAMFS)	+= ramfs.o
 obj-y			+= devfs-core.o
 obj-$(CONFIG_FS_DEVFS)	+= devfs.o
-obj-y	+= fs.o
+obj-$(CONFIG_FS_FAT)	+= fat/
diff --git a/include/block.h b/include/block.h
new file mode 100644
index 0000000..aaab4e3
--- /dev/null
+++ b/include/block.h
@@ -0,0 +1,32 @@
+#ifndef __BLOCK_H
+#define __BLOCK_H
+
+#include <driver.h>
+
+struct block_device;
+
+struct block_device_ops {
+	int (*read)(struct block_device *, void *buf, int block, int num_blocks);
+	int (*write)(struct block_device *, const void *buf, int block, int num_blocks);
+};
+
+struct block_device {
+	struct device_d *dev;
+	struct block_device_ops *ops;
+	int blockbits;
+	int num_blocks;
+	void *rdbuf; /* read buffer */
+	int rdbufsize;
+	int rdblock; /* start block in read buffer */
+	int rdblockend; /* end block in read buffer */
+	void *wrbuf; /* write buffer */
+	int wrblock; /* start block in write buffer */
+	int wrbufblocks; /* number of blocks currently in write buffer */
+	int wrbufsize; /* size of write buffer in blocks */
+	struct cdev cdev;
+};
+
+int blockdevice_register(struct block_device *blk);
+int blockdevice_unregister(struct block_device *blk);
+
+#endif /* __BLOCK_H */
-- 
1.7.2.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/4] ata: use block support
  2011-04-08 14:48 Sascha Hauer
  2011-04-08 14:48 ` [PATCH 1/4] add block support Sascha Hauer
@ 2011-04-08 14:48 ` Sascha Hauer
  2011-04-08 14:48 ` [PATCH 3/4] ata: make write support optional Sascha Hauer
  2011-04-08 14:48 ` [PATCH 4/4] mci: " Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2011-04-08 14:48 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/ata/Kconfig      |    1 +
 drivers/ata/disk_drive.c |  192 ++++++++-------------------------------------
 2 files changed, 35 insertions(+), 158 deletions(-)

diff --git a/drivers/ata/Kconfig b/drivers/ata/Kconfig
index b43c975..05cba70 100644
--- a/drivers/ata/Kconfig
+++ b/drivers/ata/Kconfig
@@ -1,4 +1,5 @@
 menuconfig ATA
+	select BLOCK
 	bool "ATA                           "
 	help
 	  Add support for ATA types of drives like harddisks and CDROMs.
diff --git a/drivers/ata/disk_drive.c b/drivers/ata/disk_drive.c
index a54429a..4ad5a7a 100644
--- a/drivers/ata/disk_drive.c
+++ b/drivers/ata/disk_drive.c
@@ -36,6 +36,8 @@
 #include <string.h>
 #include <linux/kernel.h>
 #include <malloc.h>
+#include <common.h>
+#include <block.h>
 
 /**
  * Description of one partition table entry (D*S type)
@@ -121,149 +123,31 @@ static int disk_register_partitions(struct device_d *dev, struct partition_entry
 	return 0;
 }
 
-/**
- * Write some data to a disk
- * @param cdev the device to write to
- * @param _buf source of data
- * @param count byte count to write
- * @param offset where to write to disk
- * @param flags Ignored
- * @return Written bytes or negative value in case of failure
- */
-static ssize_t disk_write(struct cdev *cdev, const void *_buf, size_t count, ulong offset, ulong flags)
-{
-	struct device_d *dev = cdev->dev;
-	struct ata_interface *intf = dev->platform_data;
-	int rc;
-	unsigned sep_count = offset & (SECTOR_SIZE - 1);
-	ssize_t written = 0;
-
-	/* starting at no sector boundary? */
-	if (sep_count != 0) {
-		uint8_t tmp_buf[SECTOR_SIZE];
-		unsigned to_write = min(SECTOR_SIZE - sep_count, count);
-
-		rc = intf->read(dev, offset / SECTOR_SIZE, 1, tmp_buf);
-		if (rc != 0) {
-			dev_err(dev, "Cannot read data\n");
-			return -1;
-		}
-		memcpy(&tmp_buf[sep_count], _buf, to_write);
-		rc = intf->write(dev, offset / SECTOR_SIZE, 1, tmp_buf);
-		if (rc != 0) {
-			dev_err(dev, "Cannot write data\n");
-			return -1;
-		}
-
-		_buf += to_write;
-		offset += to_write;
-		count -= to_write;
-		written += to_write;
-	}
-
-	/* full sector part */
-	sep_count = count / SECTOR_SIZE;
-	if (sep_count) {
-		rc = intf->write(dev, offset / SECTOR_SIZE, sep_count, _buf);
-		if (rc != 0) {
-			dev_err(dev, "Cannot write data\n");
-			return -1;
-		}
-		_buf += sep_count * SECTOR_SIZE;
-		offset += sep_count * SECTOR_SIZE;
-		count -= sep_count * SECTOR_SIZE;
-		written += sep_count * SECTOR_SIZE;
-	}
-
-	/* ending at no sector boundary? */
-	if (count) {
-		uint8_t tmp_buf[SECTOR_SIZE];
+struct ata_block_device {
+	struct block_device blk;
+	struct device_d *dev;
+	struct ata_interface *intf;
+};
 
-		rc = intf->read(dev, offset / SECTOR_SIZE, 1, tmp_buf);
-		if (rc != 0) {
-			dev_err(dev, "Cannot read data\n");
-			return -1;
-		}
-		memcpy(tmp_buf, _buf, count);
-		rc = intf->write(dev, offset / SECTOR_SIZE, 1, tmp_buf);
-		if (rc != 0) {
-			dev_err(dev, "Cannot write data\n");
-			return -1;
-		}
-		written += count;
-	}
+static int atablk_read(struct block_device *blk, void *buf, int block,
+		int num_blocks)
+{
+	struct ata_block_device *atablk = container_of(blk, struct ata_block_device, blk);
 
-	return written;
+	return atablk->intf->read(atablk->dev, block, num_blocks, buf);
 }
 
-/**
- * Read some data from a disk
- * @param cdev the device to read from
- * @param _buf destination of the data
- * @param count byte count to read
- * @param offset where to read from
- * @param flags Ignored
- * @return Read bytes or negative value in case of failure
- */
-static ssize_t disk_read(struct cdev *cdev, void *_buf, size_t count, ulong offset, ulong flags)
+static int atablk_write(struct block_device *blk, const void *buf, int block,
+		int num_blocks)
 {
-	struct device_d *dev = cdev->dev;
-	struct ata_interface *intf = dev->platform_data;
-	int rc;
-	unsigned sep_count = offset & (SECTOR_SIZE - 1);
-	ssize_t read = 0;
+	struct ata_block_device *atablk = container_of(blk, struct ata_block_device, blk);
 
-	/* starting at no sector boundary? */
-	if (sep_count != 0) {
-		uint8_t tmp_buf[SECTOR_SIZE];
-		unsigned to_read = min(SECTOR_SIZE - sep_count, count);
-
-		rc = intf->read(dev, offset / SECTOR_SIZE, 1, tmp_buf);
-		if (rc != 0) {
-			dev_err(dev, "Cannot read data\n");
-			return -1;
-		}
-		memcpy(_buf, &tmp_buf[sep_count], to_read);
-		_buf += to_read;
-		offset += to_read;
-		count -= to_read;
-		read += to_read;
-	}
-
-	/* full sector part */
-	sep_count = count / SECTOR_SIZE;
-	if (sep_count) {
-		rc = intf->read(dev, offset / SECTOR_SIZE, sep_count, _buf);
-		if (rc != 0) {
-			dev_err(dev, "Cannot read data\n");
-			return -1;
-		}
-		_buf += sep_count * SECTOR_SIZE;
-		offset += sep_count * SECTOR_SIZE;
-		count -= sep_count * SECTOR_SIZE;
-		read += sep_count * SECTOR_SIZE;
-	}
-
-	/* ending at no sector boundary? */
-	if (count) {
-		uint8_t tmp_buf[SECTOR_SIZE];
-
-		rc = intf->read(dev, offset / SECTOR_SIZE, 1, tmp_buf);
-		if (rc != 0) {
-			dev_err(dev, "Cannot read data\n");
-			return -1;
-		}
-		memcpy(_buf, tmp_buf, count);
-		read += count;
-	}
-
-	return read;
+	return atablk->intf->write(atablk->dev, block, num_blocks, buf);
 }
 
-static struct file_operations disk_ops = {
-	.read  = disk_read,
-	.write = disk_write,
-	.lseek = dev_lseek_default,
+static struct block_device_ops ataops = {
+	.read = atablk_read,
+	.write = atablk_write,
 };
 
 /**
@@ -274,7 +158,7 @@ static int disk_probe(struct device_d *dev)
 	uint8_t *sector;
 	int rc;
 	struct ata_interface *intf = dev->platform_data;
-	struct cdev *disk_cdev;
+	struct ata_block_device *atablk = xzalloc(sizeof(*atablk));
 
 	sector = xmalloc(SECTOR_SIZE);
 
@@ -285,9 +169,6 @@ static int disk_probe(struct device_d *dev)
 		goto on_error;
 	}
 
-	/* It seems a valuable disk. Register it */
-	disk_cdev = xzalloc(sizeof(struct cdev));
-
 	/*
 	 * BIOS based disks needs special handling. Not the driver can
 	 * enumerate the hardware, the BIOS did it already. To show the user
@@ -296,23 +177,25 @@ static int disk_probe(struct device_d *dev)
 	 */
 #ifdef CONFIG_ATA_BIOS
 	if (strcmp(dev->driver->name, "biosdisk") == 0)
-		disk_cdev->name = asprintf("biosdisk%d", dev->id);
+		atablk->blk.cdev.name = asprintf("biosdisk%d", dev->id);
 	else
 #endif
-		disk_cdev->name = asprintf("disk%d", dev->id);
+		atablk->blk.cdev.name = asprintf("disk%d", dev->id);
 
 	/* On x86, BIOS based disks are coming without a valid .size field */
 	if (dev->size == 0) {
-		/*
-		 * We need always the size of the drive, else its nearly impossible
-		 * to do anything with it (at least with the generic routines)
-		 */
-		disk_cdev->size = 32;
-	} else
-		disk_cdev->size = dev->size;
-	disk_cdev->ops = &disk_ops;
-	disk_cdev->dev = dev;
-	devfs_create(disk_cdev);
+		/* guess the size of this drive if not otherwise given */
+		dev->size = disk_guess_size(dev,
+			(struct partition_entry*)&sector[446]) * SECTOR_SIZE;
+		dev_info(dev, "Drive size guessed to %u kiB\n", dev->size / 1024);
+	}
+
+	atablk->blk.num_blocks = dev->size / SECTOR_SIZE;
+	atablk->blk.ops = &ataops;
+	atablk->blk.blockbits = 9;
+	atablk->dev = dev;
+	atablk->intf = intf;
+	blockdevice_register(&atablk->blk);
 
 	if ((sector[510] != 0x55) || (sector[511] != 0xAA)) {
 		dev_info(dev, "No partition table found\n");
@@ -320,13 +203,6 @@ static int disk_probe(struct device_d *dev)
 		goto on_error;
 	}
 
-	if (dev->size == 0) {
-		/* guess the size of this drive if not otherwise given */
-		dev->size = disk_guess_size(dev,
-			(struct partition_entry*)&sector[446]) * SECTOR_SIZE;
-		dev_info(dev, "Drive size guessed to %u kiB\n", dev->size / 1024);
-		disk_cdev->size = dev->size;
-	}
 
 	rc = disk_register_partitions(dev, (struct partition_entry*)&sector[446]);
 
-- 
1.7.2.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 3/4] ata: make write support optional
  2011-04-08 14:48 Sascha Hauer
  2011-04-08 14:48 ` [PATCH 1/4] add block support Sascha Hauer
  2011-04-08 14:48 ` [PATCH 2/4] ata: use " Sascha Hauer
@ 2011-04-08 14:48 ` Sascha Hauer
  2011-04-08 14:48 ` [PATCH 4/4] mci: " Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2011-04-08 14:48 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/ata/Kconfig      |    4 ++++
 drivers/ata/disk_drive.c |    4 ++++
 2 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/drivers/ata/Kconfig b/drivers/ata/Kconfig
index 05cba70..d7f4dcb 100644
--- a/drivers/ata/Kconfig
+++ b/drivers/ata/Kconfig
@@ -8,6 +8,10 @@ if ATA
 
 comment "drive types"
 
+config ATA_WRITE
+	select BLOCK_WRITE
+	bool "support writing to ATA drives"
+
 config ATA_DISK
 	bool "disk drives"
 	help
diff --git a/drivers/ata/disk_drive.c b/drivers/ata/disk_drive.c
index 4ad5a7a..f526b1e 100644
--- a/drivers/ata/disk_drive.c
+++ b/drivers/ata/disk_drive.c
@@ -137,6 +137,7 @@ static int atablk_read(struct block_device *blk, void *buf, int block,
 	return atablk->intf->read(atablk->dev, block, num_blocks, buf);
 }
 
+#ifdef CONFIG_ATA_WRITE
 static int atablk_write(struct block_device *blk, const void *buf, int block,
 		int num_blocks)
 {
@@ -144,10 +145,13 @@ static int atablk_write(struct block_device *blk, const void *buf, int block,
 
 	return atablk->intf->write(atablk->dev, block, num_blocks, buf);
 }
+#endif
 
 static struct block_device_ops ataops = {
 	.read = atablk_read,
+#ifdef CONFIG_ATA_WRITE
 	.write = atablk_write,
+#endif
 };
 
 /**
-- 
1.7.2.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 4/4] mci: make write support optional
  2011-04-08 14:48 Sascha Hauer
                   ` (2 preceding siblings ...)
  2011-04-08 14:48 ` [PATCH 3/4] ata: make write support optional Sascha Hauer
@ 2011-04-08 14:48 ` Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2011-04-08 14:48 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/mci/Kconfig    |    5 +++++
 drivers/mci/mci-core.c |    6 ++++++
 2 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/drivers/mci/Kconfig b/drivers/mci/Kconfig
index 9cb7eb6..cfed72f 100644
--- a/drivers/mci/Kconfig
+++ b/drivers/mci/Kconfig
@@ -25,6 +25,11 @@ config MCI_INFO
 	  This entry adds more info about the attached MCI card, when the
 	  'devinfo' command is used on the mci device.
 
+config MCI_WRITE
+	bool "Support writing to MCI cards"
+	default y
+	select ATA_WRITE
+
 comment "--- MCI host drivers ---"
 
 config MCI_MXS
diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 8fd948c..4752b3d 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -106,6 +106,7 @@ static void *sector_buf;
  * @param blocknum Block number to write
  * @return Transaction status (0 on success)
  */
+#ifdef CONFIG_MCI_WRITE
 static int mci_block_write(struct device_d *mci_dev, const void *src, unsigned blocknum)
 {
 	struct mci *mci = GET_MCI_DATA(mci_dev);
@@ -132,6 +133,7 @@ static int mci_block_write(struct device_d *mci_dev, const void *src, unsigned b
 
 	return mci_send_cmd(mci_dev, &cmd, &data);
 }
+#endif
 
 /**
  * Read one block of data from the card
@@ -944,6 +946,7 @@ static int sd_send_if_cond(struct device_d *mci_dev)
  *
  * This routine expects the buffer has the correct size to read all data!
  */
+#ifdef CONFIG_MCI_WRITE
 static int mci_sd_write(struct device_d *disk_dev, uint64_t sector_start,
 			unsigned sector_count, const void *buffer)
 {
@@ -980,6 +983,7 @@ static int mci_sd_write(struct device_d *disk_dev, uint64_t sector_start,
 
 	return 0;
 }
+#endif
 
 /**
  * Read a chunk of sectors from media
@@ -1218,7 +1222,9 @@ static int mci_card_probe(struct device_d *mci_dev)
 	disk_dev = xzalloc(sizeof(struct device_d) + sizeof(struct ata_interface));
 	p = (struct ata_interface*)&disk_dev[1];
 
+#ifdef CONFIG_MCI_WRITE
 	p->write = mci_sd_write;
+#endif
 	p->read = mci_sd_read;
 	p->priv = mci_dev;
 
-- 
1.7.2.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-04-08 14:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-08 14:48 Sascha Hauer
2011-04-08 14:48 ` [PATCH 1/4] add block support Sascha Hauer
2011-04-08 14:48 ` [PATCH 2/4] ata: use " Sascha Hauer
2011-04-08 14:48 ` [PATCH 3/4] ata: make write support optional Sascha Hauer
2011-04-08 14:48 ` [PATCH 4/4] mci: " Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox