Embedded Linux development
 help / color / mirror / Atom feed
* Re: [RFC 2.6.28 1/2] gpiolib: add set/get batch v4
From: Uwe Kleine-König @ 2009-01-19 17:25 UTC (permalink / raw)
  To: Jaya Kumar
  Cc: David Brownell, Eric Miao, Paulius Zaleckas, Geert Uytterhoeven,
	Sam Ravnborg, linux-arm-kernel, linux-fbdev-devel, linux-kernel,
	linux-embedded
In-Reply-To: <45a44e480901190619i18749c75jaa2d4606da251921@mail.gmail.com>

Hi Jaya,

> >> +[OPTIONAL] Spinlock-Safe GPIO Batch access
> > Is it really spinlock safe in general?  Or only if gpio_cansleep(gpio)
> > if false for each gpio to get or set?
> 
> You are correct to raise this issue. It is only spinlock safe if
> chip->cansleep is false. Initially, I wasn't sure what to do. The
> original gpio set/get_value() just does;
>         WARN_ON(extra_checks && chip->can_sleep);
> and it is documented as:
> 
> "
> Spinlock-Safe GPIO access
> -------------------------
> <snip>
> return zero.  Also, using these calls for GPIOs that can't safely be accessed
> without sleeping (see below) is an error.
> "
> 
> I will change this in the batch code to return an error if can_sleep
> is detected on any involved gpio_chip.
Wait, I got it wrong.  I thought gpio_set_value might sleep if
chip->cansleep is true, but there are extra API functions for
cansleep-chips.  So I'd do it the same way as for the non-batch
functions and just WARN_ON(extra_checks && chip->cansleep) for each
involved chip.

Later it might make sense to add the _cansleep variants.

Best regards
Uwe
-- 
Pengutronix e.K.                              | Uwe Kleine-König            |
Industrial Linux Solutions                    | http://www.pengutronix.de/  |
Peiner Strasse 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686              | Fax:   +49-5121-206917-5555 |

^ permalink raw reply

* Re: [PATCH] mflash: remove small byteswapping function
From: MinChan Kim @ 2009-01-21  5:55 UTC (permalink / raw)
  To: unsik Kim
  Cc: Harvey Harrison, Heikki Orsila, linux-kernel, akpm, Alan Cox,
	linux-arm-kernel, linux-embedded
In-Reply-To: <57afda040901200025q6bc1bab1id9a1e6d6eac86d17@mail.gmail.com>


This is your patch again. 
If you want to review many people, don't send your patch with attach. 
Pz, send your patch with inline. 

You have to use scripts/checkpatch before sending to mainline. 

(linux-arm and linux-embedded Cc:-ed)

> ---
>  drivers/block/Kconfig   |    6 +
>  drivers/block/Makefile  |    2 +
>  drivers/block/mg_disk.c |  878 +++++++++++++++++++++++++++++++++++++++++++++++
>  include/linux/mg_disk.h |  174 ++++++++++
>  4 files changed, 1060 insertions(+), 0 deletions(-)
>  create mode 100644 drivers/block/mg_disk.c
>  create mode 100644 include/linux/mg_disk.h
> 
> diff --git a/drivers/block/Kconfig b/drivers/block/Kconfig
> index 0344a8a..cad48c8 100644
> --- a/drivers/block/Kconfig
> +++ b/drivers/block/Kconfig
> @@ -403,6 +403,12 @@ config ATA_OVER_ETH
>  	This driver provides Support for ATA over Ethernet block
>  	devices like the Coraid EtherDrive (R) Storage Blade.
>  
> +config MG_DISK
> +	tristate "mGine mflash, gflash support"
> +	depends on ARM
> +	help
> +	  mGine mFlash(gFlash) block device driver
> +
>  config SUNVDC
>  	tristate "Sun Virtual Disk Client support"
>  	depends on SUN_LDOMS
> diff --git a/drivers/block/Makefile b/drivers/block/Makefile
> index 204332b..1694d45 100644
> --- a/drivers/block/Makefile
> +++ b/drivers/block/Makefile
> @@ -32,3 +32,5 @@ obj-$(CONFIG_BLK_DEV_UB)	+= ub.o
>  obj-$(CONFIG_BLK_DEV_HD)	+= hd.o
>  
>  obj-$(CONFIG_XEN_BLKDEV_FRONTEND)	+= xen-blkfront.o
> +
> +obj-$(CONFIG_MG_DISK)	+= mg_disk.o
> diff --git a/drivers/block/mg_disk.c b/drivers/block/mg_disk.c
> new file mode 100644
> index 0000000..6239d01
> --- /dev/null
> +++ b/drivers/block/mg_disk.c
> @@ -0,0 +1,878 @@
> +/*
> + *  drivers/block/mg_disk.c
> + *
> + *  Support for the mGine m[g]flash IO mode.
> + *  Based on legacy hd.c
> + *
> + * (c) 2008 mGine Co.,LTD
> + * (c) 2008 unsik Kim <donari75@gmail.com>
> + *
> + *  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.
> + */
> +
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/fs.h>
> +#include <linux/blkdev.h>
> +#include <linux/hdreg.h>
> +#include <linux/interrupt.h>
> +#include <linux/platform_device.h>
> +#include <linux/mg_disk.h>
> +
> +static void mg_request(struct request_queue *);
> +
> +static void mg_dump_status(const char *msg, unsigned int stat, struct mg_host *host)
> +{
> +	char *name = MG_DISK_NAME"?";
> +	struct request *req;
> +
> +	if (host->breq) {
> +		req = elv_next_request(host->breq);
> +		if (req)
> +			name = req->rq_disk->disk_name;
> +	}
> +
> +	printk("%s: %s: status=0x%02x { ", name, msg, stat & 0xff);
> +	if (stat & MG_REG_STATUS_BIT_BUSY)
> +		printk("Busy ");
> +	if (stat & MG_REG_STATUS_BIT_READY)
> +		printk("DriveReady ");
> +	if (stat & MG_REG_STATUS_BIT_WRITE_FAULT)
> +		printk("WriteFault ");
> +	if (stat & MG_REG_STATUS_BIT_SEEK_DONE)
> +		printk("SeekComplete ");
> +	if (stat & MG_REG_STATUS_BIT_DATA_REQ)
> +		printk("DataRequest ");
> +	if (stat & MG_REG_STATUS_BIT_CORRECTED_ERROR)
> +		printk("CorrectedError ");
> +	if (stat & MG_REG_STATUS_BIT_ERROR)
> +		printk("Error ");
> +	printk("}\n");
> +	if ((stat & MG_REG_STATUS_BIT_ERROR) == 0) {
> +		host->error = 0;
> +	} else {
> +		host->error = inb(host->dev_base + MG_REG_ERROR);
> +		printk("%s: %s: error=0x%02x { ", name, msg, host->error & 0xff);
> +		if (host->error & MG_REG_ERR_BBK)
> +			printk("BadSector ");
> +		if (host->error & MG_REG_ERR_UNC)
> +			printk("UncorrectableError ");
> +		if (host->error & MG_REG_ERR_IDNF)
> +			printk("SectorIdNotFound ");
> +		if (host->error & MG_REG_ERR_ABRT)
> +			printk("DriveStatusError ");
> +		if (host->error & MG_REG_ERR_AMNF)
> +			printk("AddrMarkNotFound ");
> +		printk("}");
> +		if (host->error &
> +		    (MG_REG_ERR_BBK | MG_REG_ERR_UNC | MG_REG_ERR_IDNF | MG_REG_ERR_AMNF)) {
> +			if (host->breq) {
> +				req = elv_next_request(host->breq);
> +				if (req)
> +					printk(", sector=%ld", req->sector);
> +			}
> +
> +		}
> +		printk("\n");
> +	}
> +}
> +
> +static unsigned int mg_wait(struct mg_host *host, u32 expect, u32 msec)
> +{
> +	u8 status;
> +	u64 expire, cur_jiffies;
> +
> +	host->error = MG_ERR_NONE;
> +	expire = get_jiffies_64() + msecs_to_jiffies(msec);
> +
> +	status = inb(host->dev_base + MG_REG_STATUS);
> +	do {
> +		cur_jiffies = get_jiffies_64();
> +		if (status & MG_REG_STATUS_BIT_BUSY) {
> +			if (expect == MG_REG_STATUS_BIT_BUSY)
> +				break;
> +		} else {
> +			/* Check the error condition! */
> +			if (status & MG_REG_STATUS_BIT_ERROR) {
> +				mg_dump_status("mg_wait", status, host);
> +				break;
> +			}
> +
> +			if (expect == MG_STAT_READY) {
> +				if (MG_READY_OK(status))
> +					break;
> +			}
> +
> +			if (expect == MG_REG_STATUS_BIT_DATA_REQ) {
> +				if (status & MG_REG_STATUS_BIT_DATA_REQ) {
> +					break;
> +				}
> +			}
> +		}
> +		status = inb(host->dev_base + MG_REG_STATUS);
> +	} while (cur_jiffies < expire);
> +
> +	if (cur_jiffies >= expire) {
> +		host->error = MG_ERR_TIMEOUT;
> +	}
> +
> +	return host->error;
> +}
> +
> +static void mg_unexpected_intr(struct mg_host *host)
> +{
> +	u32 status = inb(host->dev_base + MG_REG_STATUS);
> +
> +	mg_dump_status("mg_unexpected_intr", status, host);
> +}
> +
> +static irqreturn_t mg_irq(int irq, void *dev_id)
> +{
> +	struct mg_host *host = dev_id;
> +	void (*handler)(struct mg_host *) = host->mg_do_intr;
> +
> +	host->mg_do_intr = 0;
> +	del_timer(&host->timer);
> +	if (!handler)
> +		handler = mg_unexpected_intr;
> +	handler(host);
> +	return IRQ_HANDLED;
> +}
> +
> +static void mg_ide_fixstring(u8 *s, const int bytecount)
> +{
> +	u8 *p, *end = &s[bytecount & ~1]; /* bytecount must be even */
> +
> +	/* convert from big-endian to host byte order */
> +	for (p = s ; p != end ; p += 2)
> +		be16_to_cpus((u16 *) p);
> +
> +	/* strip leading blanks */
> +	p = s;
> +	while (s != end && *s == ' ')
> +		++s;
> +	/* compress internal blanks and strip trailing blanks */
> +	while (s != end && *s) {
> +		if (*s++ != ' ' || (s != end && *s && *s != ' '))
> +			*p++ = *(s-1);
> +	}
> +	/* wipe out trailing garbage */
> +	while (p != end)
> +		*p++ = '\0';
> +}
> +
> +static int mg_get_disk_id(struct mg_host *host)
> +{
> +	u32 i;
> +	s32 err;
> +	u16 *id = (u16 *)&host->id_data;
> +	struct mg_drv_data *prv_data = host->dev->platform_data;
> +
> +	if (!prv_data->use_polling) {
> +		outb(MG_REG_CTRL_INTR_DISABLE, host->dev_base + MG_REG_DRV_CTRL);
> +	}
> +
> +	outb(MG_CMD_ID, host->dev_base + MG_REG_COMMAND);
> +	err = mg_wait(host, MG_REG_STATUS_BIT_DATA_REQ, 3000);
> +	if (!err) {
> +		for (i = 0; i < (MG_SECTOR_SIZE >> 1); i++)
> +			id[i] = le16_to_cpu(inw(host->dev_base + MG_BUFF_OFFSET + i * 2));
> +
> +		outb(MG_CMD_RD_CONF, host->dev_base + MG_REG_COMMAND);
> +		err = mg_wait(host, MG_STAT_READY, 3000);
> +		if (!err) {
> +			if ((host->id_data.field_valid & 1) == 0) {
> +				err = MG_ERR_TRANSLATION;
> +			} else {
> +#ifdef __BIG_ENDIAN
> +				host->id_data.lba_capacity = (host->id_data.lba_capacity << 16) | (host->id_data.lba_capacity >> 16);
> +#endif /* __BIG_ENDIAN */
> +				host->tot_sectors = host->id_data.lba_capacity;
> +				mg_ide_fixstring(host->id_data.model, sizeof(host->id_data.model));
> +				mg_ide_fixstring(host->id_data.serial_no, sizeof(host->id_data.serial_no));
> +				mg_ide_fixstring(host->id_data.fw_rev, sizeof(host->id_data.fw_rev));
> +				printk(KERN_INFO "mg_disk: model: %s\n", host->id_data.model);
> +				printk(KERN_INFO "mg_disk: firm: %.8s\n", host->id_data.fw_rev);
> +				printk(KERN_INFO "mg_disk: serial: %s\n", host->id_data.serial_no);
> +				printk(KERN_INFO "mg_disk: %d sectors\n", host->tot_sectors);
> +			}
> +		}
> +	}
> +
> +	if (!prv_data->use_polling) {
> +		outb(MG_REG_CTRL_INTR_ENABLE, host->dev_base + MG_REG_DRV_CTRL);
> +	}
> +
> +	return err;
> +}
> +
> +
> +static int mg_disk_init(struct mg_host *host)
> +{
> +	struct mg_drv_data *prv_data = host->dev->platform_data;
> +	s32 err;
> +	u8 init_status;
> +
> +	/* init ctrl pin */
> +	if (prv_data->mg_ctrl_pin_init)
> +		prv_data->mg_ctrl_pin_init();
> +
> +	if (!prv_data->mg_hdrst_pin)
> +		return MG_ERR_CTRL_RST;
> +
> +	/* hdd rst low */
> +	prv_data->mg_hdrst_pin(0);
> +	err = mg_wait(host, MG_REG_STATUS_BIT_BUSY, 300);
> +	if (err)
> +		return err;
> +
> +	/* hdd rst high */
> +	prv_data->mg_hdrst_pin(1);
> +	err = mg_wait(host, MG_STAT_READY, 3000);
> +	if (err)
> +		return err;
> +
> +	/* soft reset on */
> +	outb(MG_REG_CTRL_RESET |
> +		(prv_data->use_polling ? MG_REG_CTRL_INTR_DISABLE : MG_REG_CTRL_INTR_ENABLE),
> +		host->dev_base + MG_REG_DRV_CTRL);
> +	err = mg_wait(host, MG_REG_STATUS_BIT_BUSY, 3000);
> +	if (err)
> +		return err;
> +
> +	/* soft reset off */
> +	outb(prv_data->use_polling ? MG_REG_CTRL_INTR_DISABLE : MG_REG_CTRL_INTR_ENABLE,
> +		host->dev_base + MG_REG_DRV_CTRL);
> +	err = mg_wait(host, MG_STAT_READY, 3000);
> +	if (err)
> +		return err;
> +
> +	init_status = inb(host->dev_base + MG_REG_STATUS) & 0xf;
> +
> +	if (init_status == 0xf)
> +		return MG_ERR_INIT_STAT;
> +
> +	if (prv_data->op_mode & (MG_OP_CASCADE_SYNC_RD | MG_OP_CASCADE_SYNC_WR)) {
> +		outb(prv_data->burst_latcy | prv_data->burst_len, host->dev_base + MG_REG_BURST_CTRL);
> +	}
> +
> +	return err;
> +}
> +
> +static void mg_bad_rw_intr(struct mg_host *host)
> +{
> +	struct request *req = elv_next_request(host->breq);
> +	if (req != NULL) {
> +		if (++req->errors >= MG_MAX_ERRORS) {
> +			end_request(req, 0);
> +		} else if (req->errors % MG_RESET_FREQ == 0 || host->error == MG_ERR_TIMEOUT) {
> +			host->reset = 1;
> +		}
> +		/* Otherwise just retry */
> +	}
> +}
> +
> +static unsigned int mg_out(struct mg_host *host,
> +			unsigned int sect_num,
> +			unsigned int sect_cnt,
> +			unsigned int cmd,
> +			void (*intr_addr)(struct mg_host *))
> +{
> +	struct mg_drv_data *prv_data = host->dev->platform_data;
> +
> +	if (mg_wait(host, MG_STAT_READY, 3000)) {
> +		return host->error;
> +	}
> +
> +	if (!prv_data->use_polling) {
> +		host->mg_do_intr = intr_addr;
> +		mod_timer(&host->timer, jiffies + 3 * HZ);
> +	}
> +	outb((u8)sect_cnt, host->dev_base + MG_REG_SECT_CNT);
> +	outb((u8)sect_num, host->dev_base + MG_REG_SECT_NUM);
> +	outb((u8)(sect_num >> 8), host->dev_base + MG_REG_CYL_LOW);
> +	outb((u8)(sect_num >> 16), host->dev_base + MG_REG_CYL_HIGH);
> +	outb((u8)((sect_num >> 24) | MG_REG_HEAD_LBA_MODE), host->dev_base + MG_REG_DRV_HEAD);
> +	outb(cmd, host->dev_base + MG_REG_COMMAND);
> +	return MG_ERR_NONE;
> +}
> +
> +static void mg_read(struct request *req)
> +{
> +	u32 remains, j;
> +	struct mg_host *host = req->rq_disk->private_data;
> +
> +	remains = req->nr_sectors;
> +
> +	if (host->reset) {
> +		if (mg_disk_init(host)) {
> +			end_request(req, 0);
> +			return;
> +		}
> +		host->reset = 0;
> +	}
> +
> +	if (mg_out(host, req->sector, req->nr_sectors, MG_CMD_RD, 0) != MG_ERR_NONE) {
> +		mg_bad_rw_intr(host);
> +	}
> +
> +	MG_DBG("requested %d sects (from %ld), buffer=0x%p\n", remains, req->sector, req->buffer);
> +
> +	while (remains) {
> +		if (mg_wait(host, MG_REG_STATUS_BIT_DATA_REQ, 3000) != MG_ERR_NONE) {
> +			mg_bad_rw_intr(host);
> +			return;
> +		}
> +		for (j = 0; j < MG_SECTOR_SIZE >> 1; j++) {
> +			*(u16 *)req->buffer = inw(host->dev_base + MG_BUFF_OFFSET + (j << 1));
> +			req->buffer += 2;
> +		}
> +
> +		req->sector++;
> +		req->errors = 0;
> +		remains = --req->nr_sectors;
> +		--req->current_nr_sectors;
> +
> +		if (req->current_nr_sectors <= 0) {
> +			MG_DBG("remain : %d sects\n", remains);
> +			end_request(req, 1);
> +			if (remains > 0) {
> +				req = elv_next_request(host->breq);
> +			}
> +		}
> +
> +		outb(MG_CMD_RD_CONF, host->dev_base + MG_REG_COMMAND);
> +	}
> +}
> +
> +static void mg_write(struct request *req)
> +{
> +	u32 remains, j;
> +	struct mg_host *host = req->rq_disk->private_data;
> +
> +	remains = req->nr_sectors;
> +
> +	if (host->reset) {
> +		if (mg_disk_init(host)) {
> +			end_request(req, 0);
> +			return;
> +		}
> +		host->reset = 0;
> +	}
> +
> +	if (mg_out(host, req->sector, req->nr_sectors, MG_CMD_WR, 0) != MG_ERR_NONE) {
> +		mg_bad_rw_intr(host);
> +		return;
> +	}
> +
> +
> +	MG_DBG("requested %d sects (from %ld), buffer=0x%p\n", remains, req->sector, req->buffer);
> +	while (remains) {
> +		if (mg_wait(host, MG_REG_STATUS_BIT_DATA_REQ, 3000) != MG_ERR_NONE) {
> +			mg_bad_rw_intr(host);
> +			return;
> +		}
> +		for (j = 0; j < MG_SECTOR_SIZE >> 1; j++) {
> +			outw(*(u16 *)req->buffer, host->dev_base + MG_BUFF_OFFSET + (j << 1));
> +			req->buffer += 2;
> +		}
> +		req->sector++;
> +		remains = --req->nr_sectors;
> +		--req->current_nr_sectors;
> +
> +		if (req->current_nr_sectors <= 0) {
> +			MG_DBG("remain : %d sects\n", remains);
> +			end_request(req, 1);
> +			if (remains > 0) {
> +				req = elv_next_request(host->breq);
> +			}
> +		}
> +
> +		outb(MG_CMD_WR_CONF, host->dev_base + MG_REG_COMMAND);
> +	}
> +}
> +
> +static void mg_read_intr(struct mg_host *host)
> +{
> +	u32 i;
> +	struct request *req;
> +
> +	/* check status */
> +	do {
> +		i = inb(host->dev_base + MG_REG_STATUS);
> +		if (i & MG_REG_STATUS_BIT_BUSY)
> +			break;
> +		if (!MG_READY_OK(i))
> +			break;
> +		if (i & MG_REG_STATUS_BIT_DATA_REQ)
> +			goto ok_to_read;
> +	} while (0);
> +	mg_dump_status("mg_read_intr", i, host);
> +	mg_bad_rw_intr(host);
> +	mg_request(host->breq);
> +	return;
> +
> +ok_to_read:
> +	/* get current segment of request */
> +	req = elv_next_request(host->breq);
> +
> +	/* read 1 sector */
> +	for (i = 0; i < MG_SECTOR_SIZE >> 1; i++) {
> +		*(u16 *)req->buffer = inw(host->dev_base + MG_BUFF_OFFSET + (i << 1));
> +		req->buffer += 2;
> +	}
> +
> +	/* manipulate request */
> +	MG_DBG("sector %ld, remaining=%ld, buffer=0x%p\n", req->sector, req->nr_sectors - 1, req->buffer);
> +
> +	req->sector++;
> +	req->errors = 0;
> +	i = --req->nr_sectors;
> +	--req->current_nr_sectors;
> +
> +	/* let know if current segment done */
> +	if (req->current_nr_sectors <= 0)
> +		end_request(req, 1);
> +
> +	/* set handler if read remains */
> +	if (i > 0) {
> +		host->mg_do_intr = mg_read_intr;
> +		mod_timer(&host->timer, jiffies + 3 * HZ);
> +	}
> +
> +	/* send read confirm */
> +	outb(MG_CMD_RD_CONF, host->dev_base + MG_REG_COMMAND);
> +
> +	/* goto next request */
> +	if (!i) {
> +		mg_request(host->breq);
> +	}
> +}
> +
> +static void mg_write_intr(struct mg_host *host)
> +{
> +	u32 i, j;
> +	u16 *buff;
> +	struct request *req;
> +
> +	/* get current segment of request */
> +	req = elv_next_request(host->breq);
> +
> +	/* check status */
> +	do {
> +		i = inb(host->dev_base + MG_REG_STATUS);
> +		if (i & MG_REG_STATUS_BIT_BUSY)
> +			break;
> +		if (!MG_READY_OK(i))
> +			break;
> +		if ((req->nr_sectors <= 1) || (i & MG_REG_STATUS_BIT_DATA_REQ))
> +			goto ok_to_write;
> +	} while (0);
> +	mg_dump_status("mg_write_intr", i, host);
> +	mg_bad_rw_intr(host);
> +	mg_request(host->breq);
> +	return;
> +
> +ok_to_write:
> +	/* manipulate request */
> +	req->sector++;
> +	i = --req->nr_sectors;
> +	--req->current_nr_sectors;
> +	req->buffer += MG_SECTOR_SIZE;
> +
> +	/* let know if current segment or all done */
> +	if (!i || (req->bio && req->current_nr_sectors <= 0))
> +		end_request(req, 1);
> +
> +	/* write 1 sector and set handler if remains */
> +	if (i > 0) {
> +		buff = (u16 *)req->buffer;
> +		for (j = 0; j < MG_STORAGE_BUFFER_SIZE >> 1; j++) {
> +			outw(*buff, host->dev_base + MG_BUFF_OFFSET + (j << 1));
> +			buff++;
> +		}
> +		MG_DBG("sector %ld, remaining=%ld, buffer=0x%p\n", req->sector, req->nr_sectors, req->buffer);
> +		host->mg_do_intr = mg_write_intr;
> +		mod_timer(&host->timer, jiffies + 3 * HZ);
> +	}
> +
> +	/* send write confirm */
> +	outb(MG_CMD_WR_CONF, host->dev_base + MG_REG_COMMAND);
> +
> +	if (!i) {
> +		mg_request(host->breq);
> +	}
> +}
> +
> +void mg_times_out(unsigned long data)
> +{
> +	struct mg_host *host = (struct mg_host *)data;
> +	char *name;
> +	struct request *req;
> +
> +	req = elv_next_request(host->breq);
> +	if (!req)
> +		return;
> +
> +	host->mg_do_intr = NULL;
> +
> +	name = req->rq_disk->disk_name;
> +	printk("%s: timeout\n", name);
> +
> +	host->error = MG_ERR_TIMEOUT;
> +	mg_bad_rw_intr(host);
> +
> +	mg_request(host->breq);
> +}
> +
> +static void mg_request_poll(struct request_queue *q)
> +{
> +	struct request *req;
> +	struct mg_host *host;
> +
> +	while ((req = elv_next_request(q)) != NULL) {
> +
> +		host = req->rq_disk->private_data;
> +
> +		if (blk_fs_request(req)) {
> +			switch (rq_data_dir(req)) {
> +			case READ:
> +				mg_read(req);
> +				break;
> +			case WRITE:
> +				mg_write(req);
> +				break;
> +			default:
> +				printk(KERN_WARNING "%s:%d unknown command\n", __func__, __LINE__);
> +				end_request(req, 0);
> +				break;
> +			}
> +		}
> +	}
> +}
> +
> +static unsigned int mg_issue_req(struct request *req,
> +					struct mg_host *host,
> +					unsigned int sect_num,
> +					unsigned int sect_cnt)
> +{
> +	u16 *buff;
> +	u32 i;
> +
> +	switch (rq_data_dir(req)) {
> +	case READ:
> +		if (mg_out(host, sect_num, sect_cnt, MG_CMD_RD, &mg_read_intr) != MG_ERR_NONE) {
> +			mg_bad_rw_intr(host);
> +			return host->error;
> +		}
> +		break;
> +	case WRITE:
> +		/* TODO : handler */
> +		outb(MG_REG_CTRL_INTR_DISABLE, host->dev_base + MG_REG_DRV_CTRL);
> +		if (mg_out(host, sect_num, sect_cnt, MG_CMD_WR, &mg_write_intr) != MG_ERR_NONE) {
> +			mg_bad_rw_intr(host);
> +			return host->error;
> +		}
> +		del_timer(&host->timer);
> +		mg_wait(host, MG_REG_STATUS_BIT_DATA_REQ, 3000);
> +		outb(MG_REG_CTRL_INTR_ENABLE, host->dev_base + MG_REG_DRV_CTRL);
> +		if (host->error) {
> +			mg_bad_rw_intr(host);
> +			return host->error;
> +		}
> +		buff = (u16 *)req->buffer;
> +		for (i = 0; i < MG_SECTOR_SIZE >> 1; i++) {
> +			outw(*buff, host->dev_base + MG_BUFF_OFFSET + (i << 1));
> +			buff++;
> +		}
> +		mod_timer(&host->timer, jiffies + 3 * HZ);
> +		outb(MG_CMD_WR_CONF, host->dev_base + MG_REG_COMMAND);
> +		break;
> +	default:
> +		printk(KERN_WARNING "%s:%d unknown command\n", __func__, __LINE__);
> +		end_request(req, 0);
> +		break;
> +	}
> +	return MG_ERR_NONE;
> +}
> +
> +/* This function also called from IRQ context */
> +static void mg_request(struct request_queue *q)
> +{
> +	struct request *req;
> +	struct mg_host *host;
> +	u32 sect_num, sect_cnt;
> +
> +	while (1) {
> +		req = elv_next_request(q);
> +		if (!req)
> +			return;
> +
> +		host = req->rq_disk->private_data;
> +
> +		/* check unwanted request call */
> +		if (host->mg_do_intr)
> +			return;
> +
> +		del_timer(&host->timer);
> +
> +		if (host->reset) {
> +			if (mg_disk_init(host)) {
> +				end_request(req, 0);
> +				return;
> +			}
> +			host->reset = 0;
> +		}
> +
> +		sect_num = req->sector;
> +		/* deal whole segments */
> +		sect_cnt = req->nr_sectors;
> +
> +		/* sanity check */
> +		if (sect_num >= get_capacity(req->rq_disk) ||
> +		    ((sect_num + sect_cnt) > get_capacity(req->rq_disk))) {
> +			printk(KERN_WARNING "%s: bad access: sector=%d, count=%d\n",
> +				 req->rq_disk->disk_name, sect_num, sect_cnt);
> +			end_request(req, 0);
> +			continue;
> +		}
> +
> +		if (!blk_fs_request(req))
> +			return;
> +
> +		if (!mg_issue_req(req, host, sect_num, sect_cnt))
> +			return;
> +	}
> +}
> +
> +static int mg_getgeo(struct block_device *bdev, struct hd_geometry *geo)
> +{
> +	struct mg_host *host = bdev->bd_disk->private_data;
> +
> +	geo->cylinders = host->id_data.cyls;
> +	geo->heads = host->id_data.heads;
> +	geo->sectors = host->id_data.sectors;
> +	return 0;
> +}
> +
> +static struct block_device_operations mg_disk_ops = {
> +	.getgeo = mg_getgeo
> +};
> +
> +static int mg_probe(struct platform_device *plat_dev)
> +{
> +	struct mg_host *host;
> +	struct resource *rsc;
> +	struct mg_drv_data *prv_data = plat_dev->dev.platform_data;
> +	int err = 0;
> +
> +	if (!prv_data) {
> +		printk(KERN_ERR "%s:%d fail (no driver_data)\n", __func__, __LINE__);
> +		err = -EINVAL;
> +		goto probe_err;
> +	}
> +
> +	/* alloc mg_host */
> +	host = kmalloc(sizeof(struct mg_host), GFP_KERNEL);
> +	if (!host) {
> +		printk(KERN_ERR "%s:%d fail (no memory for mg_host)\n", __func__, __LINE__);
> +		err = -ENOMEM;
> +		goto probe_err;
> +	}
> +	memset(host, 0, sizeof(struct mg_host));
> +	host->major = MG_DISK_MAJ;
> +
> +	/* link each other */
> +	prv_data->host = host;
> +	host->dev = &plat_dev->dev;
> +
> +	/* io remap */
> +	rsc = platform_get_resource(plat_dev, IORESOURCE_MEM, 0);
> +	if (!rsc) {
> +		printk(KERN_ERR "%s:%d platform_get_resource fail\n", __func__, __LINE__);
> +		err = -EINVAL;
> +		goto probe_err_2;
> +	}
> +	host->dev_base = (unsigned long)ioremap(rsc->start , rsc->end + 1);
> +	if (!host->dev_base) {
> +		printk(KERN_ERR "%s:%d ioremap fail\n", __func__, __LINE__);
> +		err = -EIO;
> +		goto probe_err_2;
> +	}
> +	MG_DBG("dev_base = 0x%x\n", (u32)host->dev_base);
> +
> +	/* disk init */
> +	err = mg_disk_init(host);
> +	if (err) {
> +		printk(KERN_ERR "%s:%d fail (err code : %d)\n", __func__, __LINE__, err);
> +		err = -EIO;
> +		goto probe_err_3;
> +	}
> +
> +	/* get irq resource */
> +	if (!prv_data->use_polling) {
> +		host->irq = platform_get_irq(plat_dev, 0);
> +		if (host->irq == -ENXIO) {
> +			err = host->irq;
> +			goto probe_err_3;
> +		}
> +		err = request_irq(host->irq, mg_irq, IRQF_DISABLED | IRQF_TRIGGER_RISING, MG_DEV_NAME, host);
> +		if (err) {
> +			printk(KERN_ERR "%s:%d fail (request_irq err=%d)\n", __func__, __LINE__, err);
> +			goto probe_err_3;
> +		}
> +
> +	}
> +
> +	/* get disk id */
> +	err = mg_get_disk_id(host);
> +	if (err) {
> +		printk(KERN_ERR "%s:%d fail (err code : %d)\n", __func__, __LINE__, err);
> +		err = -EIO;
> +		goto probe_err_4;
> +	}
> +
> +	err = register_blkdev(host->major, MG_DISK_NAME);
> +	if (err < 0) {
> +		printk(KERN_ERR "%s:%d (register_blkdev) fail (err code : %d)\n", __func__, __LINE__, err);
> +		goto probe_err_4;
> +	}
> +	err = 0;
> +	if (!host->major)
> +		host->major = err;
> +
> +	spin_lock_init(&host->lock);
> +
> +	if (prv_data->use_polling) {
> +		host->breq = blk_init_queue(mg_request_poll, &host->lock);
> +	} else {
> +		host->breq = blk_init_queue(mg_request, &host->lock);
> +	}
> +
> +	if (!host->breq) {
> +		err = -ENOMEM;
> +		printk(KERN_ERR "%s:%d (blk_init_queue) fail\n", __func__, __LINE__);
> +		goto probe_err_5;
> +	}
> +
> +	/* mflash is random device, thanx for the noop */
> +	elevator_exit(host->breq->elevator);
> +	err = elevator_init(host->breq, "noop");
> +	if (err) {
> +		printk(KERN_ERR "%s:%d (elevator_init) fail\n", __func__, __LINE__);
> +		goto probe_err_6;
> +	}
> +	blk_queue_max_sectors(host->breq, MG_MAX_SECTS);
> +	blk_queue_hardsect_size(host->breq, MG_SECTOR_SIZE);
> +
> +	init_timer(&host->timer);
> +	host->timer.function = mg_times_out;
> +	host->timer.data = (unsigned long)host;
> +
> +	host->gd = alloc_disk(MG_DISK_MAX_PART);
> +	if (!host->gd) {
> +		printk(KERN_ERR "%s:%d (alloc_disk) fail\n", __func__, __LINE__);
> +		err = -ENOMEM;
> +		goto probe_err_7;
> +	}
> +	host->gd->major = MG_DISK_MAJ;
> +	host->gd->first_minor = 0;
> +	host->gd->fops = &mg_disk_ops;
> +	host->gd->queue = host->breq;
> +	host->gd->private_data = host;
> +	sprintf(host->gd->disk_name, MG_DISK_NAME"a");
> +
> +	set_capacity(host->gd, host->tot_sectors);
> +
> +	add_disk(host->gd);
> +
> +	return err;
> +

I think below goto label enumeration is a not good. 
We need to change some good style. but Now, I don't 
have any good idea. 

> +probe_err_7:
> +	del_timer_sync(&host->timer);
> +probe_err_6:
> +	blk_cleanup_queue(host->breq);
> +probe_err_5:
> +	unregister_blkdev(MG_DISK_MAJ, MG_DISK_NAME);
> +probe_err_4:
> +	if (!prv_data->use_polling)
> +		free_irq(host->irq, host);
> +probe_err_3:
> +	iounmap((void __iomem *)host->dev_base);
> +probe_err_2:
> +	kfree(host);
> +probe_err:
> +	return err;
> +}
> +
> +static int mg_remove(struct platform_device *plat_dev)
> +{
> +	struct mg_drv_data *prv_data = plat_dev->dev.platform_data;
> +	struct mg_host *host = prv_data->host;
> +	int err = 0;
> +
> +	/* delete timer */
> +	del_timer_sync(&host->timer);
> +
> +	/* remove disk */
> +	if (host->gd) {
> +		del_gendisk(host->gd);
> +		put_disk(host->gd);
> +	}
> +	/* remove queue */
> +	if (host->breq)
> +		blk_cleanup_queue(host->breq);
> +
> +	/* unregister blk device */
> +	unregister_blkdev(host->major, MG_DISK_NAME);
> +
> +	/* free irq */
> +	if (!prv_data->use_polling)
> +		free_irq(host->irq, host);
> +
> +	/* unmap io */
> +	if (host->dev_base)
> +		iounmap((void __iomem *)host->dev_base);
> +
> +	/* free mg_host */
> +	if (host)
> +		kfree(host);
> +
> +	return err;
> +}
> +
> +static struct platform_driver mg_disk_driver = {
> +	.probe = mg_probe,
> +	.remove = mg_remove,
> +	.driver = {
> +		.name = MG_DEV_NAME,
> +		.owner = THIS_MODULE,
> +	}
> +};
> +
> +/****************************************************************************
> + *
> + * Module stuff
> + *
> + ****************************************************************************/
> +
> +static int __init mg_init(void)
> +{
> +	printk(KERN_INFO "mGine mflash driver, (c) 2008 mGine Co.\n");
> +	return platform_driver_register(&mg_disk_driver);
> +}
> +
> +static void __exit mg_exit(void)
> +{
> +	printk(KERN_INFO "mflash driver : bye bye\n");
> +	platform_driver_unregister(&mg_disk_driver);
> +}
> +
> +module_init(mg_init);
> +module_exit(mg_exit);
> +
> +MODULE_LICENSE("GPL");
> +MODULE_AUTHOR("unsik Kim <donari75@gmail.com>");
> +MODULE_DESCRIPTION("mGine m[g]flash device driver");
> diff --git a/include/linux/mg_disk.h b/include/linux/mg_disk.h
> new file mode 100644
> index 0000000..df6bc04
> --- /dev/null
> +++ b/include/linux/mg_disk.h
> @@ -0,0 +1,174 @@
> +/*
> + *  include/linux/mg_disk.c
> + *
> + *  Support for the mGine m[g]flash IO mode.
> + *  Based on legacy hd.c
> + *
> + * (c) 2008 mGine Co.,LTD
> + * (c) 2008 unsik Kim <donari75@gmail.com>
> + *
> + *  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.
> + */
> +
> +#ifndef __MG_DISK_H__
> +#define __MG_DISK_H__
> +
> +#include <linux/blkdev.h>
> +#include <linux/hdreg.h>
> +
> +/* name for block device */
> +#define MG_DISK_NAME "mgd"
> +/* name for platform device */
> +#define MG_DEV_NAME "mg_disk"
> +
> +#define MG_DISK_MAJ 240
> +#define MG_DISK_MAX_PART 16
> +#define MG_SECTOR_SIZE 512
> +#define MG_MAX_SECTS 256
> +
> +/* Register offsets */
> +#define MG_BUFF_OFFSET			0x8000
> +#define MG_STORAGE_BUFFER_SIZE	0x200
> +#define MG_REG_OFFSET			0xC000
> +#define MG_REG_FEATURE			(MG_REG_OFFSET + 2)	/* write case */
> +#define MG_REG_ERROR			(MG_REG_OFFSET + 2)	/* read case */
> +#define MG_REG_SECT_CNT			(MG_REG_OFFSET + 4)
> +#define MG_REG_SECT_NUM			(MG_REG_OFFSET + 6)
> +#define MG_REG_CYL_LOW			(MG_REG_OFFSET + 8)
> +#define MG_REG_CYL_HIGH			(MG_REG_OFFSET + 0xA)
> +#define MG_REG_DRV_HEAD			(MG_REG_OFFSET + 0xC)
> +#define MG_REG_COMMAND			(MG_REG_OFFSET + 0xE)	/* write case */
> +#define MG_REG_STATUS			(MG_REG_OFFSET + 0xE)	/* read  case */
> +#define MG_REG_DRV_CTRL			(MG_REG_OFFSET + 0x10)
> +#define MG_REG_BURST_CTRL		(MG_REG_OFFSET + 0x12)
> +
> +/* "Drive Select/Head Register" bit values */
> +#define MG_REG_HEAD_MUST_BE_ON	0xA0 /* These 2 bits are always on */
> +#define MG_REG_HEAD_DRIVE_MASTER	(0x00 | MG_REG_HEAD_MUST_BE_ON)
> +#define MG_REG_HEAD_DRIVE_SLAVE	(0x10 | MG_REG_HEAD_MUST_BE_ON)
> +#define MG_REG_HEAD_LBA_MODE		(0x40 | MG_REG_HEAD_MUST_BE_ON)
> +
> +
> +/* "Device Control Register" bit values */
> +#define MG_REG_CTRL_INTR_ENABLE		0x0
> +#define MG_REG_CTRL_INTR_DISABLE		(0x1<<1)
> +#define MG_REG_CTRL_RESET			(0x1<<2)
> +#define MG_REG_CTRL_INTR_POLA_ACTIVE_HIGH	0x0
> +#define MG_REG_CTRL_INTR_POLA_ACTIVE_LOW	(0x1<<4)
> +#define MG_REG_CTRL_DPD_POLA_ACTIVE_LOW	0x0
> +#define MG_REG_CTRL_DPD_POLA_ACTIVE_HIGH	(0x1<<5)
> +#define MG_REG_CTRL_DPD_DISABLE		0x0
> +#define MG_REG_CTRL_DPD_ENABLE		(0x1<<6)
> +
> +/* Status register bit */
> +#define MG_REG_STATUS_BIT_ERROR			0x01 /* error bit in status register */
> +#define MG_REG_STATUS_BIT_CORRECTED_ERROR		0x04 /* corrected error in status register */
> +#define MG_REG_STATUS_BIT_DATA_REQ			0x08 /* data request bit in status register */
> +#define MG_REG_STATUS_BIT_SEEK_DONE			0x10 /* DSC - Drive Seek Complete */
> +#define MG_REG_STATUS_BIT_WRITE_FAULT		0x20 /* DWF - Drive Write Fault */
> +#define MG_REG_STATUS_BIT_READY			0x40
> +#define MG_REG_STATUS_BIT_BUSY			0x80
> +
> +/* handy status */
> +#define MG_STAT_READY		(MG_REG_STATUS_BIT_READY | MG_REG_STATUS_BIT_SEEK_DONE)
> +#define MG_READY_OK(s)		(((s) & (MG_STAT_READY | \
> +					(MG_REG_STATUS_BIT_BUSY | MG_REG_STATUS_BIT_WRITE_FAULT | MG_REG_STATUS_BIT_ERROR))) \
> +					== MG_STAT_READY)
> +
> +/* Error register */
> +#define MG_REG_ERR_AMNF		0x01
> +#define MG_REG_ERR_ABRT		0x04
> +#define MG_REG_ERR_IDNF		0x10
> +#define MG_REG_ERR_UNC		0x40
> +#define MG_REG_ERR_BBK		0x80
> +
> +/* error code for others */
> +#define MG_ERR_NONE 0
> +#define MG_ERR_TIMEOUT 0x100
> +#define MG_ERR_INIT_STAT 0x101
> +#define MG_ERR_TRANSLATION 0x102
> +#define MG_ERR_CTRL_RST 0x103
> +
> +#define MG_MAX_ERRORS	16	/* Max read/write errors/sector */
> +#define MG_RESET_FREQ	4	/* Reset controller every 4th retry */
> +
> +/* command */
> +#define MG_CMD_RD 0x20
> +#define MG_CMD_WR 0x30
> +#define MG_CMD_SLEEP 0x99
> +#define MG_CMD_WAKEUP 0xC3
> +#define MG_CMD_ID 0xEC
> +#define MG_CMD_WR_CONF 0x3C
> +#define MG_CMD_RD_CONF 0x40
> +
> +/* private driver data */
> +struct mg_drv_data {
> +	/* disk resource */
> +	u32 nr_chips;
> +	u32 op_mode;
> +#define MG_OP_CASCADE (1 << 0)
> +#define MG_OP_CASCADE_SYNC_RD (1 << 1)
> +#define MG_OP_CASCADE_SYNC_WR (1 << 2)
> +#define MG_OP_INTERLEAVE (1 << 3)
> +
> +	u32 use_polling;
> +
> +	/* synchronous mode */
> +	u16	burst_latcy;
> +#define MG_BURST_LAT_4 (3 << 4)
> +#define MG_BURST_LAT_5 (4 << 4)
> +#define MG_BURST_LAT_6 (5 << 4)
> +#define MG_BURST_LAT_7 (6 << 4)
> +#define MG_BURST_LAT_8 (7 << 4)
> +	u16	burst_len;
> +#define MG_BURST_LEN_4 (1 << 1)
> +#define MG_BURST_LEN_8 (2 << 1)
> +#define MG_BURST_LEN_16 (3 << 1)
> +#define MG_BURST_LEN_32 (4 << 1)
> +#define MG_BURST_LEN_CONT (0 << 1)
> +
> +	/* control pin resource */
> +	int (*mg_ctrl_pin_init) (void); /* initialize hdrst, wd, dpd pin to GPIO and output high */
> +	void (*mg_hdrst_pin) (u8 level);
> +	void (*mg_wp_pin) (u8 level);
> +	void (*mg_dpd_pin) (u8 level);
> +
> +	/* internally used */
> +	struct mg_host *host;
> +};
> +
> +/* main structure for mflash driver */
> +struct mg_host {
> +	struct device *dev;
> +
> +	struct request_queue *breq;
> +	spinlock_t lock;
> +	struct gendisk *gd;
> +
> +	struct timer_list timer;
> +	void (*mg_do_intr) (struct mg_host *);
> +
> +	struct hd_driveid id_data;
> +	u32 tot_sectors;
> +
> +	unsigned long dev_base;
> +	unsigned int irq;
> +
> +	u32 major;
> +	u32 error;
> +	u32 reset;
> +};
> +
> +/*
> + * Debugging macro and defines
> + */
> +#undef DO_MG_DEBUG
> +#ifdef DO_MG_DEBUG
> +#  define MG_DBG(fmt, args...) printk(KERN_DEBUG "%s:%d "fmt, __func__, __LINE__, ##args)
> +#else /* CONFIG_MG_DEBUG */
> +#  define MG_DBG(fmt, args...) do { } while (0)
> +#endif /* CONFIG_MG_DEBUG */
> +
> +#endif
> -- 
> 1.5.4.3
> 



^ permalink raw reply

* [RFC 2.6.28 1/3] gpiolib: add batch set/get
From: Jaya Kumar @ 2009-01-25  9:54 UTC (permalink / raw)
  To: jayakumar.lkml
  Cc: linux-fbdev-devel, linux-embedded, Jaya Kumar, linux-kernel,
	David Brownell, Paulius Zaleckas, Geert Uytterhoeven, Eric Miao,
	Sam Ravnborg, linux-arm-kernel

Hi friends,

This is v5 of batch support for gpiolib. Thanks to Uwe Kleine-König,
Ryan Mallon and others for prior feedback. The changes I've made are:
- split the patches into generic, arch specific and am300epd
- adjusting the API to remove width (note, the actual API call where
  width was dropped is in the arch specific code, not here.)
- updating documentation of this API in gpio.txt
- cleanup of the width, mask terms

Please let me know your thoughts and feedback.

Thanks,
jaya

Cc: David Brownell <david-b@pacbell.net>
Cc: Eric Miao <eric.miao@marvell.com>
Cc: Paulius Zaleckas <paulius.zaleckas@teltonika.lt>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Sam Ravnborg <sam@ravnborg.org>
Cc: linux-arm-kernel@lists.arm.linux.org.uk
Cc: linux-fbdev-devel@lists.sourceforge.net
Cc: linux-kernel@vger.kernel.org
Cc: linux-embedded@vger.kernel.org
Signed-off-by: Jaya Kumar <jayakumar.lkml@gmail.com>
---
 Documentation/gpio.txt     |   72 ++++++++++++
 drivers/gpio/Kconfig       |    5 +
 drivers/gpio/gpiolib.c     |  272 ++++++++++++++++++++++++++++++++++++++++++++
 include/asm-generic/gpio.h |   17 +++-
 4 files changed, 365 insertions(+), 1 deletions(-)

diff --git a/Documentation/gpio.txt b/Documentation/gpio.txt
index b1b9887..d249b5c 100644
--- a/Documentation/gpio.txt
+++ b/Documentation/gpio.txt
@@ -185,6 +185,78 @@ and not to need spinlocks.  Such optimized calls can make bitbanging
 applications a lot more efficient (in both space and time) than spending
 dozens of instructions on subroutine calls.
 
+[OPTIONAL] Spinlock-Safe GPIO Batch access
+------------------------------------------
+The original GPIO API provides single bit access to GPIO pins. However,
+some devices treat GPIO as a mechanism for bulk data transfer. In this type
+of system, the performance of the single bit API may be inadequate. As such,
+the user can consider enabling the batch access API. The batch access API
+allows access of up-to 32-bits of GPIO at a time. This API is as follows:
+
+	/* BATCH GPIO INPUT */
+int gpio_get_batch(unsigned startpin, u32 mask, u32 *result);
+
+The following examples help explain how this function is to be used.
+ Q: How do I get gpio pins 0 through 7? (8 bits)
+ A: gpio_get_batch(startpin=0, mask=0xFF, &result) result=0xnn
+ Q: How do I get gpio pins 58 through 73? (16 bits)
+ A: gpio_get_batch(startpin=58, mask=0xFFFF, &result) result=0xnnnn
+ Q: How do I get gpio pins 16 through 47? (32 bits)
+ A: gpio_get_batch(startpin=16, mask=0xFFFFFFFF, &result)
+ A: result=0xnnnnnnnn
+ Q: How do I get non-consecutive gpio pins 5 and 9?
+ A: Use the mask to mask out 6, 7 and 8
+ A: So mask in binary is 10001 which is 0x11
+ A: gpio_get_batch(startpin=5, mask=0x11, &result)
+ A: result is in the same form, binary n000n
+
+	/* BATCH GPIO OUTPUT */
+int gpio_set_batch(unsigned startpin, u32 mask, u32 values);
+
+The following examples help explain how this function is to be used.
+ Q: How to set gpio pins 0 through 7 to all 0? (8 bits)
+ A: gpio_set_batch(startpin=0, mask=0xFF, values=0x0);
+ Q: How to set gpio pins 58 through 73 to all 1? (16 bits)
+ A: gpio_set_batch(startpin=58, mask=0xFFFF, values=0xFFFF);
+ Q: How to set gpio pins 16 through 47 to 0xCAFEC001? (32 bits)
+ A: gpio_set_batch(startpin=16, mask=0xFFFFFFFF, values=0xCAFEC001);
+ Q: How do I set non-consecutive gpio pins 5 and 9 to both 1?
+ A: Use the mask to mask out 6, 7 and 8
+ A: So mask in binary is 10001 which is 0x11
+ A: gpio_set_batch(startpin=5, mask=0x11, values=0x11)
+
+The following example shows the use of the batch API and a comparison with
+the original single bit API:
+
+Original input method which loops through a set of pins:
+       for (i = 0; i <= (DB15_GPIO_PIN - DB0_GPIO_PIN) ; i++)
+               res |= (gpio_get_value(DB0_GPIO_PIN + i)) ? (1 << i) : 0;
+
+Batch input method:
+       u32 val;
+       err = gpio_get_batch(DB0_GPIO_PIN, 0xFFFF, &val);
+
+Original output method:
+       for (i = 0; i <= (DB15_GPIO_PIN - DB0_GPIO_PIN) ; i++)
+               gpio_set_value(DB0_GPIO_PIN + i, (data >> i) & 0x01);
+
+Batch output method:
+       int err;
+       err = gpio_set_batch(DB0_GPIO_PIN, 0xFFFF, data);
+
+Using these calls for GPIOs that can't safely be accessed without sleeping
+(see below) is an error.
+
+Platform-specific implementations are encouraged to optimize the two
+calls by checking if the batch get/set requested can be achieved within the
+platform's fast path access to gpio registers. For example, if the starting
+gpio and width of bits to be written is contained within a single register
+then the platform specific implementation may choose to execute it. If the
+request is more complex, then the platform specific implementation can
+choose to call upon the platform independent __gpio_get/set_batch functions
+which are able to cross gpio_chip boundaries. Implementations are also
+encouraged to use the bitops macros. These will also optimize for use cases
+where the masks are constants.
 
 GPIO access that may sleep
 --------------------------
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 3d25654..474070b 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -37,6 +37,11 @@ menuconfig GPIOLIB
 
 if GPIOLIB
 
+config GPIOLIB_BATCH
+	bool "Batch GPIO support"
+	help
+	  Say Y here to add the capability to batch set/get GPIOs.
+
 config DEBUG_GPIO
 	bool "Debug GPIO calls"
 	depends on DEBUG_KERNEL
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 35e7aea..12e1e30 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -643,6 +643,272 @@ static inline void gpiochip_unexport(struct gpio_chip *chip)
 
 #endif /* CONFIG_GPIO_SYSFS */
 
+#ifdef CONFIG_GPIOLIB_BATCH
+/**
+ * __gpio_set_batch_generic() - Set batch of gpio pins in provided gpio_chip.
+ * @chip: gpio_chip containing this set of pins
+ * @startpin: starting gpio pin
+ * @mask: the mask to be applied to values
+ * @width: the width to the last set bit of the mask
+ * @values: values to assign including masked bits
+ * Context: any
+ *
+ * This provides a generic platform independent set_batch capability.
+ * It invokes the associated gpio_chip.set() method to actually set the
+ * value. gpio_chip-s that don't implement their own optimized
+ * set_batch function are assigned this function as a default.
+ *
+ * Returns a negative errno if the caller supplied bad data, such as
+ * startpin or width in excess of this chips gpio. Otherwise, we return zero
+ * as a success code.
+ */
+static int __gpio_set_batch_generic(struct gpio_chip *chip, unsigned startpin,
+					u32 mask, int width, u32 values)
+{
+	int i;
+	u32 pin_mask;
+	int value;
+
+	/*
+	 * If the caller attempted to exceed the number of gpios that
+	 * are in this chip, then we flag that as an invalid value for
+	 * either the startpin or the width supplied.
+	 */
+	if (startpin + width >  chip->ngpio)
+		return -EINVAL;
+
+	/*
+	 * We start the loop and continue till we reach the width
+	 * of the mask that is provided to us.
+	 */
+	for (i = 0; i < width; i++) {
+		/*
+		 * If this bit is enabled by the mask then
+		 * we perform the set. If it is disabled we leave
+		 * it alone.
+		 */
+		pin_mask = 1 << i;
+		if (mask & pin_mask) {
+			value = values & pin_mask;
+			chip->set(chip, startpin + i, value);
+		}
+	}
+
+	return 0;
+}
+
+/**
+ * __gpio_get_batch_generic() - Get batch of gpio pins in provided gpio_chip.
+ * @chip: gpio_chip containing this set of pins
+ * @startpin: starting gpio pin
+ * @mask: the mask to be applied to values
+ * @width: the width to the last set bit of the mask
+ * @result: the result to be returned
+ * Context: any
+ *
+ * This provides a generic platform independent get_batch capability.
+ * It invokes the associated gpio_chip.get() method to actually set the
+ * value. gpio_chip-s that don't implement their own optimized
+ * get_batch function are assigned this function as a default.
+ *
+ * Returns a negative errno if the caller supplied bad data, such as
+ * startpin or width in excess of this chips gpio. Otherwise, we return zero
+ * as a success code.
+ * Context: any
+ */
+static int __gpio_get_batch_generic(struct gpio_chip *chip, unsigned startpin,
+					u32 mask, int width, u32 *result)
+{
+	int i;
+	u32 pin_mask;
+	u32 values = 0;
+
+	/*
+	 * If the caller attempted to exceed the number of gpios that
+	 * are in this chip, then we flag that as an invalid value for
+	 * either the startpin or the width supplied.
+	 */
+	if (startpin + width >  chip->ngpio)
+		return -EINVAL;
+
+	/*
+	 * We start the loop and continue till we reach the width
+	 * of the mask that is provided to us.
+	 */
+	for (i = 0; i < width; i++) {
+		/*
+		 * If this bit is enabled by the mask then
+		 * we perform the get. If it is disabled we leave
+		 * it alone thus leaving it as 0 because we initialized
+		 * values.
+		 */
+		pin_mask = 1 << i;
+		if (mask & pin_mask) {
+			if (chip->get(chip, startpin + i))
+				values |= pin_mask;
+		}
+	}
+
+	*result = values;
+	return 0;
+}
+
+/**
+ * __gpio_set_batch() - set batch of gpio pins across multiple gpio_chip-s
+ * @startpin: starting gpio pin
+ * @mask: the mask to be applied to values
+ * @width: the width to the last set bit of the mask
+ * @values: values to assign including masked bits
+ * Context: any
+ *
+ * This function is platform independent and uses the starting gpio and
+ * width information to iterate through the set of required gpio_chips
+ * to use their set_batch capability in order to set a batch of gpio pins.
+ * This function handles going across gpio_chip boundaries. It is intended
+ * to be called from arch/mach specific code if they detect that the caller
+ * requires functionality outside the fast-path.
+ *
+ * Returns a negative errno if the caller supplied bad data, such as
+ * startpin or width in excess of the platforms max gpio. Otherwise, we return
+ * zero as a success code.
+ *
+ */
+int __gpio_set_batch(unsigned startpin, u32 mask, int width, u32 values)
+{
+	struct gpio_chip *chip;
+	int i = 0;
+	int subwidth, remwidth;
+	u32 subvalue;
+	u32 submask;
+	int ret;
+
+	/*
+	 * If the caller attempted to exceed the number of gpios that
+	 * are available here, then we flag that as an invalid value for
+	 * either the startpin or the width supplied.
+	 */
+	if ((width > 32) || (startpin + width >  ARCH_NR_GPIOS))
+		return -EINVAL;
+
+	do {
+		chip = gpio_to_chip(startpin + i);
+		WARN_ON(extra_checks && chip->can_sleep);
+
+		subvalue = values >> i; /* shift off the used data bits */
+
+		/* Work out the remaining width in this chip. */
+		remwidth = ((chip->base + (int) chip->ngpio) -
+					((int) startpin + i));
+
+		/*
+		 * Check if the remaining bits to be handled are less than
+		 * the remaining width in this chip. That is the width of
+		 * the subset that we are about to handle.
+		 */
+		subwidth = min(width, remwidth);
+
+		/* Shift off the used mask bits. */
+		submask = mask >> i;
+
+		/* Now adjust mask by width of this subset. */
+		submask &= ((1 << subwidth) - 1);
+
+		/* If the mask is empty, then we can skip this chip. */
+		if (submask) {
+			ret = chip->set_batch(chip, startpin + i - chip->base,
+						submask, subwidth, subvalue);
+			if (ret)
+				return ret;
+		}
+
+		/* deduct the used bits from our todolist */
+		i += subwidth;
+		width -= subwidth;
+	} while (width);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(__gpio_set_batch);
+
+/**
+ * __gpio_get_batch() - get batch of gpio pins across multiple gpio_chip-s
+ * @startpin: starting gpio pin
+ * @mask: the mask to be applied to values
+ * @width: the width to the last set bit of the mask
+ * @result: returned values
+ * Context: any
+ *
+ * This function is platform independent and uses the starting gpio and
+ * width information to iterate through the set of required gpio_chips
+ * to use their get_batch capability in order to get a batch of gpio pins.
+ * This function handles going across gpio_chip boundaries. It is intended
+ * to be called from arch/mach specific code if they detect that the caller
+ * requires functionality outside the fast-path.
+ *
+ * Returns a negative errno if the caller supplied bad data, such as
+ * startpin or width in excess of the platforms max gpio. Otherwise, we return
+ * zero as a success code
+ *
+ */
+int __gpio_get_batch(unsigned startpin, u32 mask, int width, u32 *result)
+{
+	struct gpio_chip *chip;
+	int i = 0;
+	int subwidth, remwidth;
+	u32 submask;
+	u32 values = 0;
+	u32 subvalue;
+	int ret;
+
+	/*
+	 * If the caller attempted to exceed the number of gpios that
+	 * are available here, then we flag that as an invalid value for
+	 * either the startpin or the width supplied.
+	 */
+	if ((width > 32) || (startpin + width >  ARCH_NR_GPIOS))
+		return -EINVAL;
+
+	do {
+		chip = gpio_to_chip(startpin + i);
+		WARN_ON(extra_checks && chip->can_sleep);
+
+		/* Work out the remaining width in this chip. */
+		remwidth = ((chip->base + (int) chip->ngpio) -
+					((int) startpin + i));
+
+		/*
+		 * Check if the remaining bits to be handled are less than
+		 * the remaining width in this chip.
+		 */
+		subwidth = min(width, remwidth);
+
+		/* shift off the used mask bits */
+		submask = mask >> i;
+		/* now adjust mask by width of get */
+		submask &= ((1 << width) - 1);
+
+		/* If the mask is empty, then we can skip this chip. */
+		if (submask) {
+			ret = chip->get_batch(chip, startpin + i - chip->base,
+						submask, subwidth, &subvalue);
+			if (ret)
+				return ret;
+
+			/* shift result back into correct position */
+			values |= subvalue << i;
+		}
+
+		/* deduct the used bits from our todolist */
+		i += subwidth;
+		width -= subwidth;
+	} while (width);
+
+	*result = values;
+	return 0;
+}
+EXPORT_SYMBOL_GPL(__gpio_get_batch);
+#endif
+
 /**
  * gpiochip_add() - register a gpio_chip
  * @chip: the chip to register, with chip->base initialized
@@ -683,6 +949,12 @@ int gpiochip_add(struct gpio_chip *chip)
 		}
 		chip->base = base;
 	}
+#ifdef CONFIG_GPIOLIB_BATCH
+	if (!chip->set_batch)
+		chip->set_batch = __gpio_set_batch_generic;
+	if (!chip->get_batch)
+		chip->get_batch = __gpio_get_batch_generic;
+#endif
 
 	/* these GPIO numbers must not be managed by another gpio_chip */
 	for (id = base; id < base + chip->ngpio; id++) {
diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h
index 81797ec..4e92ccf 100644
--- a/include/asm-generic/gpio.h
+++ b/include/asm-generic/gpio.h
@@ -44,6 +44,10 @@ struct module;
  *	returns either the value actually sensed, or zero
  * @direction_output: configures signal "offset" as output, or returns error
  * @set: assigns output value for signal "offset"
+ * @set_batch: batch assigns output values for signals starting at
+ *	"startpin" with mask in "mask" all within this gpio_chip
+ * @get_batch: batch fetches values for consecutive signals starting at
+ *	"startpin" with mask in "mask" all within this gpio_chip
  * @to_irq: optional hook supporting non-static gpio_to_irq() mappings;
  *	implementation may not sleep
  * @dbg_show: optional routine to show contents in debugfs; default code
@@ -84,7 +88,14 @@ struct gpio_chip {
 						unsigned offset, int value);
 	void			(*set)(struct gpio_chip *chip,
 						unsigned offset, int value);
-
+#ifdef CONFIG_GPIOLIB_BATCH
+	int			(*set_batch)(struct gpio_chip *chip,
+						unsigned startpin, u32 mask,
+						int width, u32 values);
+	int			(*get_batch)(struct gpio_chip *chip,
+						unsigned startpin, u32 mask,
+						int width, u32 *result);
+#endif
 	int			(*to_irq)(struct gpio_chip *chip,
 						unsigned offset);
 
@@ -124,6 +135,10 @@ extern void gpio_set_value_cansleep(unsigned gpio, int value);
  */
 extern int __gpio_get_value(unsigned gpio);
 extern void __gpio_set_value(unsigned gpio, int value);
+#ifdef CONFIG_GPIOLIB_BATCH
+extern int __gpio_set_batch(unsigned gpio, u32 mask, int width, u32 values);
+extern int __gpio_get_batch(unsigned gpio, u32 mask, int width, u32 *result);
+#endif
 
 extern int __gpio_cansleep(unsigned gpio);
 
-- 
1.5.2.3


------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Linux-fbdev-devel mailing list
Linux-fbdev-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-fbdev-devel

^ permalink raw reply related

* [RFC 2.6.28 2/3] mach-pxa: gpio add batch set/get
From: Jaya Kumar @ 2009-01-25  9:54 UTC (permalink / raw)
  To: jayakumar.lkml
  Cc: David Brownell, Eric Miao, Paulius Zaleckas, Geert Uytterhoeven,
	Sam Ravnborg, linux-arm-kernel, linux-fbdev-devel, linux-kernel,
	linux-embedded, Jaya Kumar
In-Reply-To: <123287728936-git-send-email-jayakumar.lkml@gmail.com>

This patch adds support for pxa specific batch set/get of gpio. This
is exported to gpiolib via the gpio_chip interface. The API used
conforms with the gpiolib batch set/get API described in
Documentation/gpio.txt.

Cc: David Brownell <david-b@pacbell.net>
Cc: Eric Miao <eric.miao@marvell.com>
Cc: Paulius Zaleckas <paulius.zaleckas@teltonika.lt>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Sam Ravnborg <sam@ravnborg.org>
Cc: linux-arm-kernel@lists.arm.linux.org.uk
Cc: linux-fbdev-devel@lists.sourceforge.net
Cc: linux-kernel@vger.kernel.org
Cc: linux-embedded@vger.kernel.org
Signed-off-by: Jaya Kumar <jayakumar.lkml@gmail.com>
---
 arch/arm/mach-pxa/Kconfig             |    1 +
 arch/arm/mach-pxa/gpio.c              |   63 +++++++++++++++++++++++++++++++++
 arch/arm/mach-pxa/include/mach/gpio.h |   51 ++++++++++++++++++++++++++
 3 files changed, 115 insertions(+), 0 deletions(-)

diff --git a/arch/arm/mach-pxa/Kconfig b/arch/arm/mach-pxa/Kconfig
index f844425..1b3e631 100644
--- a/arch/arm/mach-pxa/Kconfig
+++ b/arch/arm/mach-pxa/Kconfig
@@ -41,6 +41,7 @@ config GUMSTIX_AM200EPD
 	bool "Enable AM200EPD board support"
 
 config GUMSTIX_AM300EPD
+	select GPIOLIB_BATCH
 	bool "Enable AM300EPD board support"
 
 endchoice
diff --git a/arch/arm/mach-pxa/gpio.c b/arch/arm/mach-pxa/gpio.c
index 5fec1e4..0e466e2 100644
--- a/arch/arm/mach-pxa/gpio.c
+++ b/arch/arm/mach-pxa/gpio.c
@@ -162,6 +162,67 @@ static void pxa_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
 		__raw_writel(mask, pxa->regbase + GPCR_OFFSET);
 }
 
+#ifdef CONFIG_GPIOLIB_BATCH
+/*
+ * Set output GPIO level in batches
+ */
+static int pxa_gpio_set_batch(struct gpio_chip *chip, unsigned startpin,
+				u32 mask, int width, u32 values)
+{
+	struct pxa_gpio_chip *pxa;
+
+	/* we're guaranteed by the caller that startpin + mask remains
+	 * in this chip.
+	 */
+	pxa = container_of(chip, struct pxa_gpio_chip, chip);
+
+	/* mask is used twice in shifted form */
+	mask <<= startpin;
+
+	values = (values << startpin) & mask;
+	if (values)
+		__raw_writel(values, pxa->regbase + GPSR_OFFSET);
+
+	values = ~values & mask;
+	if (values)
+		__raw_writel(values, pxa->regbase + GPCR_OFFSET);
+
+	return 0;
+}
+
+/*
+ * Get output GPIO level in batches
+ */
+static int pxa_gpio_get_batch(struct gpio_chip *chip, unsigned startpin,
+				u32 mask, int width, u32 *result)
+{
+	u32 values;
+	struct pxa_gpio_chip *pxa;
+
+	/* we're guaranteed by the caller that startpin + mask remains
+	 * in this chip.
+	 */
+	pxa = container_of(chip, struct pxa_gpio_chip, chip);
+
+	values = __raw_readl(pxa->regbase + GPLR_OFFSET);
+
+	/* shift the result back into original position */
+	*result = (values >> startpin) & mask;
+	return 0;
+}
+#endif
+
+/* this is done this way so that we can insert an ifdef-able value
+ * into the following GPIO_CHIP macro
+ */
+#ifdef CONFIG_GPIOLIB_BATCH
+#define SET_BATCH_MACRO	.set_batch 	  = pxa_gpio_set_batch,
+#define GET_BATCH_MACRO	.get_batch	  = pxa_gpio_get_batch,
+#else
+#define SET_BATCH_MACRO
+#define GET_BATCH_MACRO
+#endif
+
 #define GPIO_CHIP(_n)							\
 	[_n] = {							\
 		.regbase = GPIO##_n##_BASE,				\
@@ -173,6 +234,8 @@ static void pxa_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
 			.set		  = pxa_gpio_set,		\
 			.base		  = (_n) * 32,			\
 			.ngpio		  = 32,				\
+			SET_BATCH_MACRO					\
+			GET_BATCH_MACRO					\
 		},							\
 	}
 
diff --git a/arch/arm/mach-pxa/include/mach/gpio.h b/arch/arm/mach-pxa/include/mach/gpio.h
index 2c538d8..7fa84fe 100644
--- a/arch/arm/mach-pxa/include/mach/gpio.h
+++ b/arch/arm/mach-pxa/include/mach/gpio.h
@@ -24,6 +24,7 @@
 #ifndef __ASM_ARCH_PXA_GPIO_H
 #define __ASM_ARCH_PXA_GPIO_H
 
+#include <linux/bitops.h>
 #include <mach/pxa-regs.h>
 #include <asm/irq.h>
 #include <mach/hardware.h>
@@ -56,6 +57,56 @@ static inline void gpio_set_value(unsigned gpio, int value)
 	}
 }
 
+#ifdef CONFIG_GPIOLIB_BATCH
+static inline int gpio_set_batch(unsigned startpin, u32 mask, u32 values)
+{
+	int err = 0;
+	int width = fls(mask);
+
+	if (__builtin_constant_p(startpin) &&
+		(startpin + width < NR_BUILTIN_GPIO) &&
+		((startpin + width) <= roundup(startpin + 1, 32))) {
+		int shift;
+
+		shift = startpin % 32;
+		mask <<= shift;
+
+		values = (values << shift) & mask;
+		if (values)
+			GPSR(startpin) = values;
+
+		values = ~values & mask;
+		if (values)
+			GPCR(startpin) = values;
+	} else {
+		err = __gpio_set_batch(startpin, mask, width, values);
+	}
+	return err;
+}
+
+static inline int gpio_get_batch(unsigned startpin, u32 mask, u32 *result)
+{
+	int ret = 0;
+	int width = fls(mask);
+
+	if (__builtin_constant_p(startpin) &&
+		(startpin + width < NR_BUILTIN_GPIO) &&
+		((startpin + width) <= roundup(startpin+1, 32))) {
+		int shift;
+		u32 values;
+
+		shift = startpin % 32;
+
+		values = GPLR(startpin);
+
+		*result = (values >> shift) & mask;
+	} else {
+		ret = __gpio_get_batch(startpin, mask, width, result);
+	}
+	return ret;
+}
+#endif
+
 #define gpio_cansleep __gpio_cansleep
 
 #define gpio_to_irq(gpio)	IRQ_GPIO(gpio)
-- 
1.5.2.3

^ permalink raw reply related

* [RFC 2.6.28 3/3] mach-pxa: use batch set/get in am300epd
From: Jaya Kumar @ 2009-01-25  9:54 UTC (permalink / raw)
  To: jayakumar.lkml
  Cc: linux-fbdev-devel, linux-embedded, Jaya Kumar, linux-kernel,
	David Brownell, Paulius Zaleckas, Geert Uytterhoeven, Eric Miao,
	Sam Ravnborg, linux-arm-kernel
In-Reply-To: <123287728936-git-send-email-jayakumar.lkml@gmail.com>

This patch to am300epd uses the batch gpiolib set/get API in order
to significantly improve performance when transferring framebuffer
data.

Cc: David Brownell <david-b@pacbell.net>
Cc: Eric Miao <eric.miao@marvell.com>
Cc: Paulius Zaleckas <paulius.zaleckas@teltonika.lt>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Sam Ravnborg <sam@ravnborg.org>
Cc: linux-arm-kernel@lists.arm.linux.org.uk
Cc: linux-fbdev-devel@lists.sourceforge.net
Cc: linux-kernel@vger.kernel.org
Cc: linux-embedded@vger.kernel.org
Signed-off-by: Jaya Kumar <jayakumar.lkml@gmail.com>
---
 arch/arm/mach-pxa/am300epd.c |   23 ++++++++++++-----------
 1 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/arch/arm/mach-pxa/am300epd.c b/arch/arm/mach-pxa/am300epd.c
index 4bd10a1..237e3be 100644
--- a/arch/arm/mach-pxa/am300epd.c
+++ b/arch/arm/mach-pxa/am300epd.c
@@ -187,24 +187,25 @@ static void am300_cleanup(struct broadsheetfb_par *par)
 
 static u16 am300_get_hdb(struct broadsheetfb_par *par)
 {
-	u16 res = 0;
-	int i;
-
-	for (i = 0; i <= (DB15_GPIO_PIN - DB0_GPIO_PIN) ; i++)
-		res |= (gpio_get_value(DB0_GPIO_PIN + i)) ? (1 << i) : 0;
+	int err;
+	u32 val;
 
-	return res;
+	err = gpio_get_batch(DB0_GPIO_PIN, 0xFFFF, &val);
+	if (err) {
+		dev_err(&am300_device->dev, "get failed: %d\n", err);
+		return 0;
+	}
+	return (u16) val;
 }
 
 static void am300_set_hdb(struct broadsheetfb_par *par, u16 data)
 {
-	int i;
-
-	for (i = 0; i <= (DB15_GPIO_PIN - DB0_GPIO_PIN) ; i++)
-		gpio_set_value(DB0_GPIO_PIN + i, (data >> i) & 0x01);
+	int err;
+	err = gpio_set_batch(DB0_GPIO_PIN, 0xFFFF, data);
+	if (err)
+		dev_err(&am300_device->dev, "set failed: %d\n", err);
 }
 
-
 static void am300_set_ctl(struct broadsheetfb_par *par, unsigned char bit,
 				u8 state)
 {
-- 
1.5.2.3


------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword

^ permalink raw reply related

* Re: [RFC 2.6.28 1/3] gpiolib: add batch set/get
From: Uwe Kleine-König @ 2009-01-25 11:20 UTC (permalink / raw)
  To: Jaya Kumar
  Cc: David Brownell, Eric Miao, Paulius Zaleckas, Geert Uytterhoeven,
	Sam Ravnborg, linux-arm-kernel, linux-fbdev-devel, linux-kernel,
	linux-embedded
In-Reply-To: <123287728936-git-send-email-jayakumar.lkml@gmail.com>

Hello Jaya,

On Sun, Jan 25, 2009 at 05:54:47PM +0800, Jaya Kumar wrote:
> - split the patches into generic, arch specific and am300epd
I would swap the order to have:

	generic
	am300epd
	pxa specific

This way the tree of the second commit is a test case for the generic
implementation.

> - adjusting the API to remove width (note, the actual API call where
>   width was dropped is in the arch specific code, not here.)
Nevertheless I would document the "generic" per arch specific
implementation in gpio.txt.  For the functions like __gpio_get_value you
can just do

	#define gpio_get_value(gpio) __gpio_get_value(gpio)

but for your batch functions you need something like

	#define gpio_set_batch(startpin, mask, values) \
		({ u32 __mask = mask; __gpio_set_batch(startpin, __mask, fls(__mask), values);})

Maybe better use/recommend an inline function?

> Cc: David Brownell <david-b@pacbell.net>
> Cc: Eric Miao <eric.miao@marvell.com>
> Cc: Paulius Zaleckas <paulius.zaleckas@teltonika.lt>
> Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> Cc: Sam Ravnborg <sam@ravnborg.org>
> Cc: linux-arm-kernel@lists.arm.linux.org.uk
> Cc: linux-fbdev-devel@lists.sourceforge.net
> Cc: linux-kernel@vger.kernel.org
> Cc: linux-embedded@vger.kernel.org
> Signed-off-by: Jaya Kumar <jayakumar.lkml@gmail.com>
Note you didn't Cc: me.

-- 
Pengutronix e.K.                              | Uwe Kleine-König            |
Industrial Linux Solutions                    | http://www.pengutronix.de/  |

^ permalink raw reply

* Embedded Linux Conference Europe 2008 videos
From: Michael Opdenacker @ 2009-02-03 10:06 UTC (permalink / raw)
  To: linux-embedded mailing list

Greetings,

Thomas Petazzoni and myself have (at last) completed the production of
ELCE videos. Here they are: http://free-electrons.com/blog/elce-2008-videos/

Many thanks to Ruud Derwig and Tim Bird for filming many presentations!

By the way, if you were a speaker at ELCE 2008, make sure you posted
your slides on
http://tree.celinuxforum.org/CelfPubWiki/ELCEurope2008Presentations .
Many people haven't done it yet.

Thomas and I strongly recommend presentations like David Woodhouse's or
Harald Welte's, and Tim's talk about boot time reduction techniques.
Anyway, they were plenty of very interesting talks.

Cheers,

Michael.

-- 
Michael Opdenacker, Free Electrons
Kernel, drivers and embedded Linux development,
consulting, training and support.
http://free-electrons.com

^ permalink raw reply

* [PATCH] mflash: Initial support
From: unsik Kim @ 2009-02-25  9:31 UTC (permalink / raw)
  To: linux-kernel
  Cc: hch, alan, shdl, akpm, linux-arm-kernel, harvey.harrison,
	linux-embedded, minchan.kim, unsik Kim

This driver supports mflash IO mode for linux.

Mflash is embedded flash drive and mainly targeted mobile and consumer
electronic devices.

Internally, mflash has nand flash and other hardware logics and supports
2 different operation (ATA, IO) modes. ATA mode doesn't need any new
driver and currently works well under standard IDE subsystem. Actually it's
one chip SSD. IO mode is ATA-like custom mode for the host that doesn't have
IDE interface.

Followings are brief descriptions about IO mode.
A. IO mode based on ATA protocol and uses some custom command. (read confirm,
write confirm)
B. IO mode uses SRAM bus interface.
C. IO mode supports 4kB boot area, so host can boot from mflash.

Signed-off-by: unsik Kim <donari75@gmail.com>
---
Hello?

I already posted mflash patch before and many people comments for it.
Unfotunately I broke my local git, so I can't generate git diff for old one.
From now I'll post patches for this one as reference.

Here are some brief change status.
All the style issue from checkpatch fixed.
Documentation added.
reserved area feature added.
suspend, resume feature added.
remove currently not supported code.

I restrict this driver for ARM cause only tested for that arch.
Is it right thing ?

I really appreciate for previous comments and any further comments
are very very welcome.
---
 Documentation/blockdev/00-INDEX   |    2 +
 Documentation/blockdev/mflash.txt |   73 +++
 drivers/block/Kconfig             |   17 +
 drivers/block/Makefile            |    1 +
 drivers/block/mg_disk.c           |  981 +++++++++++++++++++++++++++++++++++++
 include/linux/mg_disk.h           |  173 +++++++
 6 files changed, 1247 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/blockdev/mflash.txt
 create mode 100644 drivers/block/mg_disk.c
 create mode 100644 include/linux/mg_disk.h

diff --git a/Documentation/blockdev/00-INDEX b/Documentation/blockdev/00-INDEX
index 86f054c..c08df56 100644
--- a/Documentation/blockdev/00-INDEX
+++ b/Documentation/blockdev/00-INDEX
@@ -8,6 +8,8 @@ cpqarray.txt
 	- info on using Compaq's SMART2 Intelligent Disk Array Controllers.
 floppy.txt
 	- notes and driver options for the floppy disk driver.
+mflash.txt
+	- info on mGine m(g)flash driver for linux.
 nbd.txt
 	- info on a TCP implementation of a network block device.
 paride.txt
diff --git a/Documentation/blockdev/mflash.txt b/Documentation/blockdev/mflash.txt
new file mode 100644
index 0000000..d7522eb
--- /dev/null
+++ b/Documentation/blockdev/mflash.txt
@@ -0,0 +1,73 @@
+This document describes m[g]flash support in linux.
+
+Contents
+  1. Overview
+  2. Reserved area configuration
+  3. Example of mflash platform driver registration
+
+1. Overview
+
+Mflash and gflash are embedded flash drive. The only difference is mflash is
+MCP(Multi Chip Package) device. These two device operate exactly same way.
+So the rest mflash repersents mflash and gflash altogether.
+
+Internally, mflash has nand flash and other hardware logics and supports
+2 different operation (ATA, IO) modes. ATA mode doesn't need any new
+driver and currently works well under standard IDE subsystem. Actually it's
+one chip SSD. IO mode is ATA-like custom mode for the host that doesn't have
+IDE interface.
+
+Followings are brief descriptions about IO mode.
+A. IO mode based on ATA protocol and uses some custom command. (read confirm,
+write confirm)
+B. IO mode uses SRAM bus interface.
+C. IO mode supports 4kB boot area, so host can boot from mflash.
+
+2. Reserved area configuration
+If host boot from mflash, usually needs raw area for boot loader image. All of
+the mflash's block device operation will be taken this value as start offset.
+Note that boot loader's size of reserved area and kernel configuration value
+must be same.
+
+3. Example of mflash platform driver registration
+Working mflash is very straight forward. Adding platform device stuff to board
+configuration file is all. Here is some pseudo example.
+
+static struct mg_drv_data mflash_drv_data = {
+	/* If you want to polling driver set to 1 */
+	.use_polling = 0,
+};
+
+static struct resource mg_mflash_rsc[] = {
+	/* Base address of mflash */
+	[0] = {
+		.start = 0x08000000,
+		.end = 0x08000000 + SZ_64K - 1,
+		.flags = IORESOURCE_MEM
+	},
+	/* mflash interrupt pin */
+	[1] = {
+		.start = IRQ_GPIO(84),
+		.end = IRQ_GPIO(84),
+		.flags = IORESOURCE_IRQ
+	},
+	/* mflash reset pin */
+	[2] = {
+		.start = 43,
+		.end = 43,
+		.name = "mg_rst",
+		.flags = IORESOURCE_IO
+	},
+};
+
+static struct platform_device mflash_dev = {
+	.name = MG_DEV_NAME,
+	.id = -1,
+	.dev = {
+		.platform_data = &mflash_drv_data,
+	},
+	.num_resources = ARRAY_SIZE(mg_mflash_rsc),
+	.resource = mg_mflash_rsc
+};
+
+platform_device_register(&mflash_dev);
diff --git a/drivers/block/Kconfig b/drivers/block/Kconfig
index 0344a8a..88ad8e7 100644
--- a/drivers/block/Kconfig
+++ b/drivers/block/Kconfig
@@ -403,6 +403,23 @@ config ATA_OVER_ETH
 	This driver provides Support for ATA over Ethernet block
 	devices like the Coraid EtherDrive (R) Storage Blade.
 
+config MG_DISK
+	tristate "mGine mflash, gflash support"
+	depends on ARM
+	help
+	  mGine mFlash(gFlash) block device driver
+
+config MG_DISK_RES
+	int "Size of reserved area before MBR"
+	depends on MG_DISK
+	default 0
+	help
+	  Define size of reserved area that usually used for boot. Unit is KB.
+	  All of the block device operation will be taken this value as start
+	  offset
+	  Examples:
+			1024 => 1 MB
+
 config SUNVDC
 	tristate "Sun Virtual Disk Client support"
 	depends on SUN_LDOMS
diff --git a/drivers/block/Makefile b/drivers/block/Makefile
index 204332b..79dd7c7 100644
--- a/drivers/block/Makefile
+++ b/drivers/block/Makefile
@@ -19,6 +19,7 @@ obj-$(CONFIG_BLK_CPQ_CISS_DA)  += cciss.o
 obj-$(CONFIG_BLK_DEV_DAC960)	+= DAC960.o
 obj-$(CONFIG_XILINX_SYSACE)	+= xsysace.o
 obj-$(CONFIG_CDROM_PKTCDVD)	+= pktcdvd.o
+obj-$(CONFIG_MG_DISK)		+= mg_disk.o
 obj-$(CONFIG_SUNVDC)		+= sunvdc.o
 
 obj-$(CONFIG_BLK_DEV_UMEM)	+= umem.o
diff --git a/drivers/block/mg_disk.c b/drivers/block/mg_disk.c
new file mode 100644
index 0000000..10ac8d6
--- /dev/null
+++ b/drivers/block/mg_disk.c
@@ -0,0 +1,981 @@
+/*
+ *  drivers/block/mg_disk.c
+ *
+ *  Support for the mGine m[g]flash IO mode.
+ *  Based on legacy hd.c
+ *
+ * (c) 2008 mGine Co.,LTD
+ * (c) 2008 unsik Kim <donari75@gmail.com>
+ *
+ *  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.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/fs.h>
+#include <linux/blkdev.h>
+#include <linux/hdreg.h>
+#include <linux/interrupt.h>
+#include <linux/delay.h>
+#include <linux/platform_device.h>
+#include <linux/gpio.h>
+#include <linux/mg_disk.h>
+
+#define MG_RES_SEC (CONFIG_MG_DISK_RES << 1)
+
+static void mg_request(struct request_queue *);
+
+static void mg_dump_status(const char *msg, unsigned int stat,
+		struct mg_host *host)
+{
+	char *name = MG_DISK_NAME"?";
+	struct request *req;
+
+	if (host->breq) {
+		req = elv_next_request(host->breq);
+		if (req)
+			name = req->rq_disk->disk_name;
+	}
+
+	printk(KERN_DEBUG "%s: %s: status=0x%02x { ", name, msg, stat & 0xff);
+	if (stat & MG_REG_STATUS_BIT_BUSY)
+		printk("Busy ");
+	if (stat & MG_REG_STATUS_BIT_READY)
+		printk("DriveReady ");
+	if (stat & MG_REG_STATUS_BIT_WRITE_FAULT)
+		printk("WriteFault ");
+	if (stat & MG_REG_STATUS_BIT_SEEK_DONE)
+		printk("SeekComplete ");
+	if (stat & MG_REG_STATUS_BIT_DATA_REQ)
+		printk("DataRequest ");
+	if (stat & MG_REG_STATUS_BIT_CORRECTED_ERROR)
+		printk("CorrectedError ");
+	if (stat & MG_REG_STATUS_BIT_ERROR)
+		printk("Error ");
+	printk("}\n");
+	if ((stat & MG_REG_STATUS_BIT_ERROR) == 0) {
+		host->error = 0;
+	} else {
+		host->error = inb(host->dev_base + MG_REG_ERROR);
+		printk(KERN_DEBUG "%s: %s: error=0x%02x { ", name, msg,
+				host->error & 0xff);
+		if (host->error & MG_REG_ERR_BBK)
+			printk("BadSector ");
+		if (host->error & MG_REG_ERR_UNC)
+			printk("UncorrectableError ");
+		if (host->error & MG_REG_ERR_IDNF)
+			printk("SectorIdNotFound ");
+		if (host->error & MG_REG_ERR_ABRT)
+			printk("DriveStatusError ");
+		if (host->error & MG_REG_ERR_AMNF)
+			printk("AddrMarkNotFound ");
+		printk("}");
+		if (host->error &
+				(MG_REG_ERR_BBK | MG_REG_ERR_UNC |
+				 MG_REG_ERR_IDNF | MG_REG_ERR_AMNF)) {
+			if (host->breq) {
+				req = elv_next_request(host->breq);
+				if (req)
+					printk(", sector=%ld", req->sector);
+			}
+
+		}
+		printk("\n");
+	}
+}
+
+static unsigned int mg_wait(struct mg_host *host, u32 expect, u32 msec)
+{
+	u8 status;
+	u64 expire, cur_jiffies;
+
+	host->error = MG_ERR_NONE;
+	expire = get_jiffies_64() + msecs_to_jiffies(msec);
+
+	status = inb(host->dev_base + MG_REG_STATUS);
+	do {
+		cur_jiffies = get_jiffies_64();
+		if (status & MG_REG_STATUS_BIT_BUSY) {
+			if (expect == MG_REG_STATUS_BIT_BUSY)
+				break;
+		} else {
+			/* Check the error condition! */
+			if (status & MG_REG_STATUS_BIT_ERROR) {
+				mg_dump_status("mg_wait", status, host);
+				break;
+			}
+
+			if (expect == MG_STAT_READY)
+				if (MG_READY_OK(status))
+					break;
+
+			if (expect == MG_REG_STATUS_BIT_DATA_REQ)
+				if (status & MG_REG_STATUS_BIT_DATA_REQ)
+					break;
+		}
+		status = inb(host->dev_base + MG_REG_STATUS);
+	} while (cur_jiffies < expire);
+
+	if (cur_jiffies >= expire)
+		host->error = MG_ERR_TIMEOUT;
+
+	return host->error;
+}
+
+static void mg_unexpected_intr(struct mg_host *host)
+{
+	u32 status = inb(host->dev_base + MG_REG_STATUS);
+
+	mg_dump_status("mg_unexpected_intr", status, host);
+}
+
+static irqreturn_t mg_irq(int irq, void *dev_id)
+{
+	struct mg_host *host = dev_id;
+	void (*handler)(struct mg_host *) = host->mg_do_intr;
+
+	host->mg_do_intr = 0;
+	del_timer(&host->timer);
+	if (!handler)
+		handler = mg_unexpected_intr;
+	handler(host);
+	return IRQ_HANDLED;
+}
+
+static void mg_ide_fixstring(u8 *s, const int bytecount)
+{
+	u8 *p, *end = &s[bytecount & ~1]; /* bytecount must be even */
+
+	/* convert from big-endian to host byte order */
+	for (p = s ; p != end ; p += 2)
+		be16_to_cpus((u16 *) p);
+
+	/* strip leading blanks */
+	p = s;
+	while (s != end && *s == ' ')
+		++s;
+	/* compress internal blanks and strip trailing blanks */
+	while (s != end && *s) {
+		if (*s++ != ' ' || (s != end && *s && *s != ' '))
+			*p++ = *(s-1);
+	}
+	/* wipe out trailing garbage */
+	while (p != end)
+		*p++ = '\0';
+}
+
+static int mg_get_disk_id(struct mg_host *host)
+{
+	u32 i, res;
+	s32 err;
+	u16 *id = (u16 *)&host->id_data;
+	struct mg_drv_data *prv_data = host->dev->platform_data;
+
+	if (!prv_data->use_polling)
+		outb(MG_REG_CTRL_INTR_DISABLE,
+				host->dev_base + MG_REG_DRV_CTRL);
+
+	outb(MG_CMD_ID, host->dev_base + MG_REG_COMMAND);
+	err = mg_wait(host, MG_REG_STATUS_BIT_DATA_REQ, 3000);
+	if (err)
+		return err;
+
+	for (i = 0; i < (MG_SECTOR_SIZE >> 1); i++)
+		id[i] = le16_to_cpu(inw(host->dev_base + MG_BUFF_OFFSET +
+					i * 2));
+
+	outb(MG_CMD_RD_CONF, host->dev_base + MG_REG_COMMAND);
+	err = mg_wait(host, MG_STAT_READY, 3000);
+	if (err)
+		return err;
+
+	if ((host->id_data.field_valid & 1) == 0)
+		return MG_ERR_TRANSLATION;
+
+#ifdef __BIG_ENDIAN
+	host->id_data.lba_capacity = (host->id_data.lba_capacity << 16)
+		| (host->id_data.lba_capacity >> 16);
+#endif /* __BIG_ENDIAN */
+	if (MG_RES_SEC) {
+		/* modify cyls, lba_capacity */
+		host->id_data.cyls = (host->id_data.lba_capacity - MG_RES_SEC) /
+			host->id_data.heads / host->id_data.sectors;
+		res = host->id_data.lba_capacity - host->id_data.cyls *
+			host->id_data.heads * host->id_data.sectors;
+		host->id_data.lba_capacity -= res;
+	}
+	host->tot_sectors = host->id_data.lba_capacity;
+	mg_ide_fixstring(host->id_data.model,
+			sizeof(host->id_data.model));
+	mg_ide_fixstring(host->id_data.serial_no,
+			sizeof(host->id_data.serial_no));
+	mg_ide_fixstring(host->id_data.fw_rev,
+			sizeof(host->id_data.fw_rev));
+	printk(KERN_INFO "mg_disk: model: %s\n", host->id_data.model);
+	printk(KERN_INFO "mg_disk: firm: %.8s\n", host->id_data.fw_rev);
+	printk(KERN_INFO "mg_disk: serial: %s\n",
+			host->id_data.serial_no);
+	printk(KERN_INFO "mg_disk: %d + reserved %d sectors\n",
+			host->tot_sectors, res);
+
+	if (!prv_data->use_polling)
+		outb(MG_REG_CTRL_INTR_ENABLE, host->dev_base + MG_REG_DRV_CTRL);
+
+	return err;
+}
+
+
+static int mg_disk_init(struct mg_host *host)
+{
+	struct mg_drv_data *prv_data = host->dev->platform_data;
+	s32 err;
+	u8 init_status;
+
+	/* hdd rst low */
+	gpio_set_value(host->rst, 0);
+	err = mg_wait(host, MG_REG_STATUS_BIT_BUSY, 300);
+	if (err)
+		return err;
+
+	/* hdd rst high */
+	gpio_set_value(host->rst, 1);
+	err = mg_wait(host, MG_STAT_READY, 3000);
+	if (err)
+		return err;
+
+	/* soft reset on */
+	outb(MG_REG_CTRL_RESET |
+			(prv_data->use_polling ? MG_REG_CTRL_INTR_DISABLE :
+			 MG_REG_CTRL_INTR_ENABLE),
+			host->dev_base + MG_REG_DRV_CTRL);
+	err = mg_wait(host, MG_REG_STATUS_BIT_BUSY, 3000);
+	if (err)
+		return err;
+
+	/* soft reset off */
+	outb(prv_data->use_polling ? MG_REG_CTRL_INTR_DISABLE :
+			MG_REG_CTRL_INTR_ENABLE,
+			host->dev_base + MG_REG_DRV_CTRL);
+	err = mg_wait(host, MG_STAT_READY, 3000);
+	if (err)
+		return err;
+
+	init_status = inb(host->dev_base + MG_REG_STATUS) & 0xf;
+
+	if (init_status == 0xf)
+		return MG_ERR_INIT_STAT;
+
+	return err;
+}
+
+static void mg_bad_rw_intr(struct mg_host *host)
+{
+	struct request *req = elv_next_request(host->breq);
+	if (req != NULL) {
+		if (++req->errors >= MG_MAX_ERRORS) {
+			end_request(req, 0);
+		} else if (req->errors % MG_RESET_FREQ == 0 ||
+				host->error == MG_ERR_TIMEOUT) {
+			host->reset = 1;
+		}
+		/* Otherwise just retry */
+	}
+}
+
+static unsigned int mg_out(struct mg_host *host,
+		unsigned int sect_num,
+		unsigned int sect_cnt,
+		unsigned int cmd,
+		void (*intr_addr)(struct mg_host *))
+{
+	struct mg_drv_data *prv_data = host->dev->platform_data;
+
+	if (mg_wait(host, MG_STAT_READY, 3000))
+		return host->error;
+
+	if (!prv_data->use_polling) {
+		host->mg_do_intr = intr_addr;
+		mod_timer(&host->timer, jiffies + 3 * HZ);
+	}
+	if (MG_RES_SEC)
+		sect_num += MG_RES_SEC;
+	outb((u8)sect_cnt, host->dev_base + MG_REG_SECT_CNT);
+	outb((u8)sect_num, host->dev_base + MG_REG_SECT_NUM);
+	outb((u8)(sect_num >> 8), host->dev_base + MG_REG_CYL_LOW);
+	outb((u8)(sect_num >> 16), host->dev_base + MG_REG_CYL_HIGH);
+	outb((u8)((sect_num >> 24) | MG_REG_HEAD_LBA_MODE),
+			host->dev_base + MG_REG_DRV_HEAD);
+	outb(cmd, host->dev_base + MG_REG_COMMAND);
+	return MG_ERR_NONE;
+}
+
+static void mg_read(struct request *req)
+{
+	u32 remains, j;
+	struct mg_host *host = req->rq_disk->private_data;
+
+	remains = req->nr_sectors;
+
+	if (host->reset) {
+		if (mg_disk_init(host)) {
+			end_request(req, 0);
+			return;
+		}
+		host->reset = 0;
+	}
+
+	if (mg_out(host, req->sector, req->nr_sectors, MG_CMD_RD, 0) !=
+			MG_ERR_NONE)
+		mg_bad_rw_intr(host);
+
+	MG_DBG("requested %d sects (from %ld), buffer=0x%p\n",
+			remains, req->sector, req->buffer);
+
+	while (remains) {
+		if (mg_wait(host, MG_REG_STATUS_BIT_DATA_REQ, 3000) !=
+				MG_ERR_NONE) {
+			mg_bad_rw_intr(host);
+			return;
+		}
+		for (j = 0; j < MG_SECTOR_SIZE >> 1; j++) {
+			*(u16 *)req->buffer =
+				inw(host->dev_base + MG_BUFF_OFFSET + (j << 1));
+			req->buffer += 2;
+		}
+
+		req->sector++;
+		req->errors = 0;
+		remains = --req->nr_sectors;
+		--req->current_nr_sectors;
+
+		if (req->current_nr_sectors <= 0) {
+			MG_DBG("remain : %d sects\n", remains);
+			end_request(req, 1);
+			if (remains > 0)
+				req = elv_next_request(host->breq);
+		}
+
+		outb(MG_CMD_RD_CONF, host->dev_base + MG_REG_COMMAND);
+	}
+}
+
+static void mg_write(struct request *req)
+{
+	u32 remains, j;
+	struct mg_host *host = req->rq_disk->private_data;
+
+	remains = req->nr_sectors;
+
+	if (host->reset) {
+		if (mg_disk_init(host)) {
+			end_request(req, 0);
+			return;
+		}
+		host->reset = 0;
+	}
+
+	if (mg_out(host, req->sector, req->nr_sectors, MG_CMD_WR, 0) !=
+			MG_ERR_NONE) {
+		mg_bad_rw_intr(host);
+		return;
+	}
+
+
+	MG_DBG("requested %d sects (from %ld), buffer=0x%p\n",
+			remains, req->sector, req->buffer);
+	while (remains) {
+		if (mg_wait(host, MG_REG_STATUS_BIT_DATA_REQ, 3000) !=
+				MG_ERR_NONE) {
+			mg_bad_rw_intr(host);
+			return;
+		}
+		for (j = 0; j < MG_SECTOR_SIZE >> 1; j++) {
+			outw(*(u16 *)req->buffer, host->dev_base +
+					MG_BUFF_OFFSET + (j << 1));
+			req->buffer += 2;
+		}
+		req->sector++;
+		remains = --req->nr_sectors;
+		--req->current_nr_sectors;
+
+		if (req->current_nr_sectors <= 0) {
+			MG_DBG("remain : %d sects\n", remains);
+			end_request(req, 1);
+			if (remains > 0)
+				req = elv_next_request(host->breq);
+		}
+
+		outb(MG_CMD_WR_CONF, host->dev_base + MG_REG_COMMAND);
+	}
+}
+
+static void mg_read_intr(struct mg_host *host)
+{
+	u32 i;
+	struct request *req;
+
+	/* check status */
+	do {
+		i = inb(host->dev_base + MG_REG_STATUS);
+		if (i & MG_REG_STATUS_BIT_BUSY)
+			break;
+		if (!MG_READY_OK(i))
+			break;
+		if (i & MG_REG_STATUS_BIT_DATA_REQ)
+			goto ok_to_read;
+	} while (0);
+	mg_dump_status("mg_read_intr", i, host);
+	mg_bad_rw_intr(host);
+	mg_request(host->breq);
+	return;
+
+ok_to_read:
+	/* get current segment of request */
+	req = elv_next_request(host->breq);
+
+	/* read 1 sector */
+	for (i = 0; i < MG_SECTOR_SIZE >> 1; i++) {
+		*(u16 *)req->buffer =
+			inw(host->dev_base + MG_BUFF_OFFSET + (i << 1));
+		req->buffer += 2;
+	}
+
+	/* manipulate request */
+	MG_DBG("sector %ld, remaining=%ld, buffer=0x%p\n",
+			req->sector, req->nr_sectors - 1, req->buffer);
+
+	req->sector++;
+	req->errors = 0;
+	i = --req->nr_sectors;
+	--req->current_nr_sectors;
+
+	/* let know if current segment done */
+	if (req->current_nr_sectors <= 0)
+		end_request(req, 1);
+
+	/* set handler if read remains */
+	if (i > 0) {
+		host->mg_do_intr = mg_read_intr;
+		mod_timer(&host->timer, jiffies + 3 * HZ);
+	}
+
+	/* send read confirm */
+	outb(MG_CMD_RD_CONF, host->dev_base + MG_REG_COMMAND);
+
+	/* goto next request */
+	if (!i)
+		mg_request(host->breq);
+}
+
+static void mg_write_intr(struct mg_host *host)
+{
+	u32 i, j;
+	u16 *buff;
+	struct request *req;
+
+	/* get current segment of request */
+	req = elv_next_request(host->breq);
+
+	/* check status */
+	do {
+		i = inb(host->dev_base + MG_REG_STATUS);
+		if (i & MG_REG_STATUS_BIT_BUSY)
+			break;
+		if (!MG_READY_OK(i))
+			break;
+		if ((req->nr_sectors <= 1) || (i & MG_REG_STATUS_BIT_DATA_REQ))
+			goto ok_to_write;
+	} while (0);
+	mg_dump_status("mg_write_intr", i, host);
+	mg_bad_rw_intr(host);
+	mg_request(host->breq);
+	return;
+
+ok_to_write:
+	/* manipulate request */
+	req->sector++;
+	i = --req->nr_sectors;
+	--req->current_nr_sectors;
+	req->buffer += MG_SECTOR_SIZE;
+
+	/* let know if current segment or all done */
+	if (!i || (req->bio && req->current_nr_sectors <= 0))
+		end_request(req, 1);
+
+	/* write 1 sector and set handler if remains */
+	if (i > 0) {
+		buff = (u16 *)req->buffer;
+		for (j = 0; j < MG_STORAGE_BUFFER_SIZE >> 1; j++) {
+			outw(*buff, host->dev_base + MG_BUFF_OFFSET + (j << 1));
+			buff++;
+		}
+		MG_DBG("sector %ld, remaining=%ld, buffer=0x%p\n",
+				req->sector, req->nr_sectors, req->buffer);
+		host->mg_do_intr = mg_write_intr;
+		mod_timer(&host->timer, jiffies + 3 * HZ);
+	}
+
+	/* send write confirm */
+	outb(MG_CMD_WR_CONF, host->dev_base + MG_REG_COMMAND);
+
+	if (!i)
+		mg_request(host->breq);
+}
+
+void mg_times_out(unsigned long data)
+{
+	struct mg_host *host = (struct mg_host *)data;
+	char *name;
+	struct request *req;
+
+	req = elv_next_request(host->breq);
+	if (!req)
+		return;
+
+	host->mg_do_intr = NULL;
+
+	name = req->rq_disk->disk_name;
+	printk(KERN_DEBUG "%s: timeout\n", name);
+
+	host->error = MG_ERR_TIMEOUT;
+	mg_bad_rw_intr(host);
+
+	mg_request(host->breq);
+}
+
+static void mg_request_poll(struct request_queue *q)
+{
+	struct request *req;
+	struct mg_host *host;
+
+	while ((req = elv_next_request(q)) != NULL) {
+		host = req->rq_disk->private_data;
+		if (blk_fs_request(req)) {
+			switch (rq_data_dir(req)) {
+			case READ:
+				mg_read(req);
+				break;
+			case WRITE:
+				mg_write(req);
+				break;
+			default:
+				printk(KERN_WARNING "%s:%d unknown command\n",
+						__func__, __LINE__);
+				end_request(req, 0);
+				break;
+			}
+		}
+	}
+}
+
+static unsigned int mg_issue_req(struct request *req,
+		struct mg_host *host,
+		unsigned int sect_num,
+		unsigned int sect_cnt)
+{
+	u16 *buff;
+	u32 i;
+
+	switch (rq_data_dir(req)) {
+	case READ:
+		if (mg_out(host, sect_num, sect_cnt, MG_CMD_RD, &mg_read_intr)
+				!= MG_ERR_NONE) {
+			mg_bad_rw_intr(host);
+			return host->error;
+		}
+		break;
+	case WRITE:
+		/* TODO : handler */
+		outb(MG_REG_CTRL_INTR_DISABLE,
+				host->dev_base + MG_REG_DRV_CTRL);
+		if (mg_out(host, sect_num, sect_cnt, MG_CMD_WR, &mg_write_intr)
+				!= MG_ERR_NONE) {
+			mg_bad_rw_intr(host);
+			return host->error;
+		}
+		del_timer(&host->timer);
+		mg_wait(host, MG_REG_STATUS_BIT_DATA_REQ, 3000);
+		outb(MG_REG_CTRL_INTR_ENABLE, host->dev_base + MG_REG_DRV_CTRL);
+		if (host->error) {
+			mg_bad_rw_intr(host);
+			return host->error;
+		}
+		buff = (u16 *)req->buffer;
+		for (i = 0; i < MG_SECTOR_SIZE >> 1; i++) {
+			outw(*buff, host->dev_base + MG_BUFF_OFFSET + (i << 1));
+			buff++;
+		}
+		mod_timer(&host->timer, jiffies + 3 * HZ);
+		outb(MG_CMD_WR_CONF, host->dev_base + MG_REG_COMMAND);
+		break;
+	default:
+		printk(KERN_WARNING "%s:%d unknown command\n",
+				__func__, __LINE__);
+		end_request(req, 0);
+		break;
+	}
+	return MG_ERR_NONE;
+}
+
+/* This function also called from IRQ context */
+static void mg_request(struct request_queue *q)
+{
+	struct request *req;
+	struct mg_host *host;
+	u32 sect_num, sect_cnt;
+
+	while (1) {
+		req = elv_next_request(q);
+		if (!req)
+			return;
+
+		host = req->rq_disk->private_data;
+
+		/* check unwanted request call */
+		if (host->mg_do_intr)
+			return;
+
+		del_timer(&host->timer);
+
+		if (host->reset) {
+			if (mg_disk_init(host)) {
+				end_request(req, 0);
+				return;
+			}
+			host->reset = 0;
+		}
+
+		sect_num = req->sector;
+		/* deal whole segments */
+		sect_cnt = req->nr_sectors;
+
+		/* sanity check */
+		if (sect_num >= get_capacity(req->rq_disk) ||
+				((sect_num + sect_cnt) >
+				 get_capacity(req->rq_disk))) {
+			printk(KERN_WARNING
+					"%s: bad access: sector=%d, count=%d\n",
+					req->rq_disk->disk_name,
+					sect_num, sect_cnt);
+			end_request(req, 0);
+			continue;
+		}
+
+		if (!blk_fs_request(req))
+			return;
+
+		if (!mg_issue_req(req, host, sect_num, sect_cnt))
+			return;
+	}
+}
+
+static int mg_getgeo(struct block_device *bdev, struct hd_geometry *geo)
+{
+	struct mg_host *host = bdev->bd_disk->private_data;
+
+	geo->cylinders = host->id_data.cyls;
+	geo->heads = host->id_data.heads;
+	geo->sectors = host->id_data.sectors;
+	return 0;
+}
+
+static struct block_device_operations mg_disk_ops = {
+	.getgeo = mg_getgeo
+};
+
+static int mg_suspend(struct platform_device *plat_dev, pm_message_t state)
+{
+	struct mg_drv_data *prv_data = plat_dev->dev.platform_data;
+	struct mg_host *host = prv_data->host;
+
+	if (mg_wait(host, MG_STAT_READY, 3000))
+		return -EIO;
+
+	if (!prv_data->use_polling)
+		outb(MG_REG_CTRL_INTR_DISABLE,
+				host->dev_base + MG_REG_DRV_CTRL);
+
+	outb(MG_CMD_SLEEP, host->dev_base + MG_REG_COMMAND);
+	mdelay(1);
+
+	if (mg_wait(host, MG_STAT_READY, 3000)) {
+		if (!prv_data->use_polling)
+			outb(MG_REG_CTRL_INTR_ENABLE,
+					host->dev_base + MG_REG_DRV_CTRL);
+		return -EIO;
+	}
+
+	return 0;
+}
+
+static int mg_resume(struct platform_device *plat_dev)
+{
+	struct mg_drv_data *prv_data = plat_dev->dev.platform_data;
+	struct mg_host *host = prv_data->host;
+
+	if (mg_wait(host, MG_STAT_READY, 3000))
+		return -EIO;
+
+	outb(MG_CMD_WAKEUP, host->dev_base + MG_REG_COMMAND);
+	mdelay(1);
+
+	if (mg_wait(host, MG_STAT_READY, 3000))
+		return -EIO;
+
+	if (!prv_data->use_polling)
+		outb(MG_REG_CTRL_INTR_ENABLE, host->dev_base + MG_REG_DRV_CTRL);
+
+	return 0;
+}
+
+static int mg_probe(struct platform_device *plat_dev)
+{
+	struct mg_host *host;
+	struct resource *rsc;
+	struct mg_drv_data *prv_data = plat_dev->dev.platform_data;
+	int err = 0;
+
+	if (!prv_data) {
+		printk(KERN_ERR	"%s:%d fail (no driver_data)\n",
+				__func__, __LINE__);
+		err = -EINVAL;
+		goto probe_err;
+	}
+
+	/* alloc mg_host */
+	host = kmalloc(sizeof(struct mg_host), GFP_KERNEL);
+	if (!host) {
+		printk(KERN_ERR "%s:%d fail (no memory for mg_host)\n",
+				__func__, __LINE__);
+		err = -ENOMEM;
+		goto probe_err;
+	}
+	memset(host, 0, sizeof(struct mg_host));
+	host->major = MG_DISK_MAJ;
+
+	/* link each other */
+	prv_data->host = host;
+	host->dev = &plat_dev->dev;
+
+	/* io remap */
+	rsc = platform_get_resource(plat_dev, IORESOURCE_MEM, 0);
+	if (!rsc) {
+		printk(KERN_ERR "%s:%d platform_get_resource fail\n",
+				__func__, __LINE__);
+		err = -EINVAL;
+		goto probe_err_2;
+	}
+	host->dev_base = (unsigned long)ioremap(rsc->start , rsc->end + 1);
+	if (!host->dev_base) {
+		printk(KERN_ERR "%s:%d ioremap fail\n",
+				__func__, __LINE__);
+		err = -EIO;
+		goto probe_err_2;
+	}
+	MG_DBG("dev_base = 0x%x\n", (u32)host->dev_base);
+
+	/* get reset pin */
+	rsc = platform_get_resource(plat_dev, IORESOURCE_IO, 0);
+	if (!rsc) {
+		printk(KERN_ERR "%s:%d get reset pin fail\n",
+				__func__, __LINE__);
+		err = -EIO;
+		goto probe_err_3;
+	}
+	host->rst = rsc->start;
+
+	/* init rst pin */
+	err = gpio_request(host->rst, "mg_rst");
+	if (err)
+		goto probe_err_3;
+	gpio_direction_output(host->rst, 1);
+
+	/* disk init */
+	err = mg_disk_init(host);
+	if (err) {
+		printk(KERN_ERR "%s:%d fail (err code : %d)\n",
+				__func__, __LINE__, err);
+		err = -EIO;
+		goto probe_err_3a;
+	}
+
+	/* get irq resource */
+	if (!prv_data->use_polling) {
+		host->irq = platform_get_irq(plat_dev, 0);
+		if (host->irq == -ENXIO) {
+			err = host->irq;
+			goto probe_err_3a;
+		}
+		err = request_irq(host->irq, mg_irq,
+				IRQF_DISABLED | IRQF_TRIGGER_RISING,
+				MG_DEV_NAME, host);
+		if (err) {
+			printk(KERN_ERR "%s:%d fail (request_irq err=%d)\n",
+					__func__, __LINE__, err);
+			goto probe_err_3a;
+		}
+
+	}
+
+	/* get disk id */
+	err = mg_get_disk_id(host);
+	if (err) {
+		printk(KERN_ERR "%s:%d fail (err code : %d)\n",
+				__func__, __LINE__, err);
+		err = -EIO;
+		goto probe_err_4;
+	}
+
+	err = register_blkdev(host->major, MG_DISK_NAME);
+	if (err < 0) {
+		printk(KERN_ERR "%s:%d register_blkdev fail (err code : %d)\n",
+				__func__, __LINE__, err);
+		goto probe_err_4;
+	}
+	if (!host->major)
+		host->major = err;
+
+	spin_lock_init(&host->lock);
+
+	if (prv_data->use_polling)
+		host->breq = blk_init_queue(mg_request_poll, &host->lock);
+	else
+		host->breq = blk_init_queue(mg_request, &host->lock);
+
+	if (!host->breq) {
+		err = -ENOMEM;
+		printk(KERN_ERR "%s:%d (blk_init_queue) fail\n",
+				__func__, __LINE__);
+		goto probe_err_5;
+	}
+
+	/* mflash is random device, thanx for the noop */
+	elevator_exit(host->breq->elevator);
+	err = elevator_init(host->breq, "noop");
+	if (err) {
+		printk(KERN_ERR "%s:%d (elevator_init) fail\n",
+				__func__, __LINE__);
+		goto probe_err_6;
+	}
+	blk_queue_max_sectors(host->breq, MG_MAX_SECTS);
+	blk_queue_hardsect_size(host->breq, MG_SECTOR_SIZE);
+
+	init_timer(&host->timer);
+	host->timer.function = mg_times_out;
+	host->timer.data = (unsigned long)host;
+
+	host->gd = alloc_disk(MG_DISK_MAX_PART);
+	if (!host->gd) {
+		printk(KERN_ERR "%s:%d (alloc_disk) fail\n",
+				__func__, __LINE__);
+		err = -ENOMEM;
+		goto probe_err_7;
+	}
+	host->gd->major = host->major;
+	host->gd->first_minor = 0;
+	host->gd->fops = &mg_disk_ops;
+	host->gd->queue = host->breq;
+	host->gd->private_data = host;
+	sprintf(host->gd->disk_name, MG_DISK_NAME"a");
+
+	set_capacity(host->gd, host->tot_sectors);
+
+	add_disk(host->gd);
+
+	return err;
+
+probe_err_7:
+	del_timer_sync(&host->timer);
+probe_err_6:
+	blk_cleanup_queue(host->breq);
+probe_err_5:
+	unregister_blkdev(MG_DISK_MAJ, MG_DISK_NAME);
+probe_err_4:
+	if (!prv_data->use_polling)
+		free_irq(host->irq, host);
+probe_err_3a:
+	gpio_free(host->rst);
+probe_err_3:
+	iounmap((void __iomem *)host->dev_base);
+probe_err_2:
+	kfree(host);
+probe_err:
+	return err;
+}
+
+static int mg_remove(struct platform_device *plat_dev)
+{
+	struct mg_drv_data *prv_data = plat_dev->dev.platform_data;
+	struct mg_host *host = prv_data->host;
+	int err = 0;
+
+	/* delete timer */
+	del_timer_sync(&host->timer);
+
+	/* remove disk */
+	if (host->gd) {
+		del_gendisk(host->gd);
+		put_disk(host->gd);
+	}
+	/* remove queue */
+	if (host->breq)
+		blk_cleanup_queue(host->breq);
+
+	/* unregister blk device */
+	unregister_blkdev(host->major, MG_DISK_NAME);
+
+	/* free irq */
+	if (!prv_data->use_polling)
+		free_irq(host->irq, host);
+
+	/* free rst pin */
+	if (host->rst)
+		gpio_free(host->rst);
+
+	/* unmap io */
+	if (host->dev_base)
+		iounmap((void __iomem *)host->dev_base);
+
+	/* free mg_host */
+	kfree(host);
+
+	return err;
+}
+
+static struct platform_driver mg_disk_driver = {
+	.probe = mg_probe,
+	.remove = mg_remove,
+	.suspend = mg_suspend,
+	.resume = mg_resume,
+	.driver = {
+		.name = MG_DEV_NAME,
+		.owner = THIS_MODULE,
+	}
+};
+
+/****************************************************************************
+ *
+ * Module stuff
+ *
+ ****************************************************************************/
+
+static int __init mg_init(void)
+{
+	printk(KERN_INFO "mGine mflash driver, (c) 2008 mGine Co.\n");
+	return platform_driver_register(&mg_disk_driver);
+}
+
+static void __exit mg_exit(void)
+{
+	printk(KERN_INFO "mflash driver : bye bye\n");
+	platform_driver_unregister(&mg_disk_driver);
+}
+
+module_init(mg_init);
+module_exit(mg_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("unsik Kim <donari75@gmail.com>");
+MODULE_DESCRIPTION("mGine m[g]flash device driver");
diff --git a/include/linux/mg_disk.h b/include/linux/mg_disk.h
new file mode 100644
index 0000000..4f1a4a2
--- /dev/null
+++ b/include/linux/mg_disk.h
@@ -0,0 +1,173 @@
+/*
+ *  include/linux/mg_disk.c
+ *
+ *  Support for the mGine m[g]flash IO mode.
+ *  Based on legacy hd.c
+ *
+ * (c) 2008 mGine Co.,LTD
+ * (c) 2008 unsik Kim <donari75@gmail.com>
+ *
+ *  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.
+ */
+
+#ifndef __MG_DISK_H__
+#define __MG_DISK_H__
+
+#include <linux/blkdev.h>
+#include <linux/hdreg.h>
+
+/* name for block device */
+#define MG_DISK_NAME "mgd"
+/* name for platform device */
+#define MG_DEV_NAME "mg_disk"
+
+#define MG_DISK_MAJ 0
+#define MG_DISK_MAX_PART 16
+#define MG_SECTOR_SIZE 512
+#define MG_MAX_SECTS 256
+
+/* Register offsets */
+#define MG_BUFF_OFFSET			0x8000
+#define MG_STORAGE_BUFFER_SIZE		0x200
+#define MG_REG_OFFSET			0xC000
+#define MG_REG_FEATURE			(MG_REG_OFFSET + 2)	/* write case */
+#define MG_REG_ERROR			(MG_REG_OFFSET + 2)	/* read case */
+#define MG_REG_SECT_CNT			(MG_REG_OFFSET + 4)
+#define MG_REG_SECT_NUM			(MG_REG_OFFSET + 6)
+#define MG_REG_CYL_LOW			(MG_REG_OFFSET + 8)
+#define MG_REG_CYL_HIGH			(MG_REG_OFFSET + 0xA)
+#define MG_REG_DRV_HEAD			(MG_REG_OFFSET + 0xC)
+#define MG_REG_COMMAND			(MG_REG_OFFSET + 0xE)	/* write case */
+#define MG_REG_STATUS			(MG_REG_OFFSET + 0xE)	/* read  case */
+#define MG_REG_DRV_CTRL			(MG_REG_OFFSET + 0x10)
+#define MG_REG_BURST_CTRL		(MG_REG_OFFSET + 0x12)
+
+/* "Drive Select/Head Register" bit values */
+#define MG_REG_HEAD_MUST_BE_ON		0xA0 /* These 2 bits are always on */
+#define MG_REG_HEAD_DRIVE_MASTER	(0x00 | MG_REG_HEAD_MUST_BE_ON)
+#define MG_REG_HEAD_DRIVE_SLAVE		(0x10 | MG_REG_HEAD_MUST_BE_ON)
+#define MG_REG_HEAD_LBA_MODE		(0x40 | MG_REG_HEAD_MUST_BE_ON)
+
+
+/* "Device Control Register" bit values */
+#define MG_REG_CTRL_INTR_ENABLE			0x0
+#define MG_REG_CTRL_INTR_DISABLE		(0x1<<1)
+#define MG_REG_CTRL_RESET			(0x1<<2)
+#define MG_REG_CTRL_INTR_POLA_ACTIVE_HIGH	0x0
+#define MG_REG_CTRL_INTR_POLA_ACTIVE_LOW	(0x1<<4)
+#define MG_REG_CTRL_DPD_POLA_ACTIVE_LOW		0x0
+#define MG_REG_CTRL_DPD_POLA_ACTIVE_HIGH	(0x1<<5)
+#define MG_REG_CTRL_DPD_DISABLE			0x0
+#define MG_REG_CTRL_DPD_ENABLE			(0x1<<6)
+
+/* Status register bit */
+/* error bit in status register */
+#define MG_REG_STATUS_BIT_ERROR			0x01
+/* corrected error in status register */
+#define MG_REG_STATUS_BIT_CORRECTED_ERROR	0x04
+/* data request bit in status register */
+#define MG_REG_STATUS_BIT_DATA_REQ		0x08
+/* DSC - Drive Seek Complete */
+#define MG_REG_STATUS_BIT_SEEK_DONE		0x10
+/* DWF - Drive Write Fault */
+#define MG_REG_STATUS_BIT_WRITE_FAULT		0x20
+#define MG_REG_STATUS_BIT_READY			0x40
+#define MG_REG_STATUS_BIT_BUSY			0x80
+
+/* handy status */
+#define MG_STAT_READY	(MG_REG_STATUS_BIT_READY | MG_REG_STATUS_BIT_SEEK_DONE)
+#define MG_READY_OK(s)	(((s) & (MG_STAT_READY | \
+				(MG_REG_STATUS_BIT_BUSY | \
+				 MG_REG_STATUS_BIT_WRITE_FAULT | \
+				 MG_REG_STATUS_BIT_ERROR))) == MG_STAT_READY)
+
+/* Error register */
+#define MG_REG_ERR_AMNF		0x01
+#define MG_REG_ERR_ABRT		0x04
+#define MG_REG_ERR_IDNF		0x10
+#define MG_REG_ERR_UNC		0x40
+#define MG_REG_ERR_BBK		0x80
+
+/* error code for others */
+#define MG_ERR_NONE 0
+#define MG_ERR_TIMEOUT 0x100
+#define MG_ERR_INIT_STAT 0x101
+#define MG_ERR_TRANSLATION 0x102
+#define MG_ERR_CTRL_RST 0x103
+
+#define MG_MAX_ERRORS	16	/* Max read/write errors/sector */
+#define MG_RESET_FREQ	4	/* Reset controller every 4th retry */
+
+/* command */
+#define MG_CMD_RD 0x20
+#define MG_CMD_WR 0x30
+#define MG_CMD_SLEEP 0x99
+#define MG_CMD_WAKEUP 0xC3
+#define MG_CMD_ID 0xEC
+#define MG_CMD_WR_CONF 0x3C
+#define MG_CMD_RD_CONF 0x40
+
+/* operation mode */
+#define MG_OP_CASCADE (1 << 0)
+#define MG_OP_CASCADE_SYNC_RD (1 << 1)
+#define MG_OP_CASCADE_SYNC_WR (1 << 2)
+#define MG_OP_INTERLEAVE (1 << 3)
+
+/* synchronous */
+#define MG_BURST_LAT_4 (3 << 4)
+#define MG_BURST_LAT_5 (4 << 4)
+#define MG_BURST_LAT_6 (5 << 4)
+#define MG_BURST_LAT_7 (6 << 4)
+#define MG_BURST_LAT_8 (7 << 4)
+#define MG_BURST_LEN_4 (1 << 1)
+#define MG_BURST_LEN_8 (2 << 1)
+#define MG_BURST_LEN_16 (3 << 1)
+#define MG_BURST_LEN_32 (4 << 1)
+#define MG_BURST_LEN_CONT (0 << 1)
+
+/* private driver data */
+struct mg_drv_data {
+	/* disk resource */
+	u32 use_polling;
+
+	/* internally used */
+	struct mg_host *host;
+};
+
+/* main structure for mflash driver */
+struct mg_host {
+	struct device *dev;
+
+	struct request_queue *breq;
+	spinlock_t lock;
+	struct gendisk *gd;
+
+	struct timer_list timer;
+	void (*mg_do_intr) (struct mg_host *);
+
+	struct hd_driveid id_data;
+	u32 tot_sectors;
+
+	unsigned long dev_base;
+	unsigned int irq;
+	unsigned int rst;
+
+	u32 major;
+	u32 error;
+	u32 reset;
+};
+
+/*
+ * Debugging macro and defines
+ */
+#undef DO_MG_DEBUG
+#ifdef DO_MG_DEBUG
+#  define MG_DBG(fmt, args...) \
+	printk(KERN_DEBUG "%s:%d "fmt, __func__, __LINE__, ##args)
+#else /* CONFIG_MG_DEBUG */
+#  define MG_DBG(fmt, args...) do { } while (0)
+#endif /* CONFIG_MG_DEBUG */
+
+#endif
-- 
1.5.6.6

Regards,
unsik Kim

^ permalink raw reply related

* Re: [PATCH] mflash: Initial support
From: Andrew Morton @ 2009-02-26 21:35 UTC (permalink / raw)
  Cc: linux-kernel, hch, alan, shdl, linux-arm-kernel, harvey.harrison,
	linux-embedded, minchan.kim, donari75
In-Reply-To: <1235554274-794-1-git-send-email-donari75@gmail.com>

On Wed, 25 Feb 2009 18:31:14 +0900
unsik Kim <donari75@gmail.com> wrote:

> This driver supports mflash IO mode for linux.
> 
> Mflash is embedded flash drive and mainly targeted mobile and consumer
> electronic devices.
> 
> Internally, mflash has nand flash and other hardware logics and supports
> 2 different operation (ATA, IO) modes. ATA mode doesn't need any new
> driver and currently works well under standard IDE subsystem. Actually it's
> one chip SSD. IO mode is ATA-like custom mode for the host that doesn't have
> IDE interface.
> 
> Followings are brief descriptions about IO mode.
> A. IO mode based on ATA protocol and uses some custom command. (read confirm,
> write confirm)
> B. IO mode uses SRAM bus interface.
> C. IO mode supports 4kB boot area, so host can boot from mflash.
> 

Have we fully explored the option of controlling this device with the
current ATA or IDE code, rather than creating a whole new parallel
block device implementation?

>
> ...
>
> --- /dev/null
> +++ b/drivers/block/mg_disk.c
> @@ -0,0 +1,981 @@
> +/*
> + *  drivers/block/mg_disk.c
> + *
> + *  Support for the mGine m[g]flash IO mode.
> + *  Based on legacy hd.c
> + *
> + * (c) 2008 mGine Co.,LTD
> + * (c) 2008 unsik Kim <donari75@gmail.com>
> + *
> + *  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.
> + */
> +
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/fs.h>
> +#include <linux/blkdev.h>
> +#include <linux/hdreg.h>
> +#include <linux/interrupt.h>
> +#include <linux/delay.h>
> +#include <linux/platform_device.h>
> +#include <linux/gpio.h>
> +#include <linux/mg_disk.h>
> +
> +#define MG_RES_SEC (CONFIG_MG_DISK_RES << 1)
> +
> +static void mg_request(struct request_queue *);
> +
> +static void mg_dump_status(const char *msg, unsigned int stat,
> +		struct mg_host *host)
> +{
> +	char *name = MG_DISK_NAME"?";

The "?" seems strange.  Why do we want to print "mgd?" here?

> +	struct request *req;
> +
> +	if (host->breq) {
> +		req = elv_next_request(host->breq);
> +		if (req)
> +			name = req->rq_disk->disk_name;
> +	}
> +
> +	printk(KERN_DEBUG "%s: %s: status=0x%02x { ", name, msg, stat & 0xff);
> +	if (stat & MG_REG_STATUS_BIT_BUSY)
> +		printk("Busy ");
> +	if (stat & MG_REG_STATUS_BIT_READY)
> +		printk("DriveReady ");
> +	if (stat & MG_REG_STATUS_BIT_WRITE_FAULT)
> +		printk("WriteFault ");
> +	if (stat & MG_REG_STATUS_BIT_SEEK_DONE)
> +		printk("SeekComplete ");
> +	if (stat & MG_REG_STATUS_BIT_DATA_REQ)
> +		printk("DataRequest ");
> +	if (stat & MG_REG_STATUS_BIT_CORRECTED_ERROR)
> +		printk("CorrectedError ");
> +	if (stat & MG_REG_STATUS_BIT_ERROR)
> +		printk("Error ");
> +	printk("}\n");
> +	if ((stat & MG_REG_STATUS_BIT_ERROR) == 0) {
> +		host->error = 0;
> +	} else {
> +		host->error = inb(host->dev_base + MG_REG_ERROR);
> +		printk(KERN_DEBUG "%s: %s: error=0x%02x { ", name, msg,
> +				host->error & 0xff);
> +		if (host->error & MG_REG_ERR_BBK)
> +			printk("BadSector ");
> +		if (host->error & MG_REG_ERR_UNC)
> +			printk("UncorrectableError ");
> +		if (host->error & MG_REG_ERR_IDNF)
> +			printk("SectorIdNotFound ");
> +		if (host->error & MG_REG_ERR_ABRT)
> +			printk("DriveStatusError ");
> +		if (host->error & MG_REG_ERR_AMNF)
> +			printk("AddrMarkNotFound ");
> +		printk("}");
> +		if (host->error &
> +				(MG_REG_ERR_BBK | MG_REG_ERR_UNC |
> +				 MG_REG_ERR_IDNF | MG_REG_ERR_AMNF)) {
> +			if (host->breq) {
> +				req = elv_next_request(host->breq);
> +				if (req)
> +					printk(", sector=%ld", req->sector);
> +			}
> +
> +		}
> +		printk("\n");
> +	}
> +}
> +
> +static unsigned int mg_wait(struct mg_host *host, u32 expect, u32 msec)
> +{
> +	u8 status;
> +	u64 expire, cur_jiffies;

cur_jiffies64 would be a clearer name.

> +	host->error = MG_ERR_NONE;
> +	expire = get_jiffies_64() + msecs_to_jiffies(msec);

But why is this code using jiffies_64 at all?  Why not use plain old
jiffies and unsigned longs?


> +	status = inb(host->dev_base + MG_REG_STATUS);
> +	do {
> +		cur_jiffies = get_jiffies_64();
> +		if (status & MG_REG_STATUS_BIT_BUSY) {
> +			if (expect == MG_REG_STATUS_BIT_BUSY)
> +				break;
> +		} else {
> +			/* Check the error condition! */
> +			if (status & MG_REG_STATUS_BIT_ERROR) {
> +				mg_dump_status("mg_wait", status, host);
> +				break;
> +			}
> +
> +			if (expect == MG_STAT_READY)
> +				if (MG_READY_OK(status))
> +					break;
> +
> +			if (expect == MG_REG_STATUS_BIT_DATA_REQ)
> +				if (status & MG_REG_STATUS_BIT_DATA_REQ)
> +					break;
> +		}
> +		status = inb(host->dev_base + MG_REG_STATUS);
> +	} while (cur_jiffies < expire);

This loop will not handle jiffy wrap properly.  Use
time_after/time_before/etc.

> +	if (cur_jiffies >= expire)

ditto.

> +		host->error = MG_ERR_TIMEOUT;
> +
> +	return host->error;
> +}

This function appears to be doing up-to-multi-second busy wait looping.
Bad.

Can we fix this by waiting for some interrupt?  Presumably not.  Can we
at least do something to prevent it from locking up the whole machine
for long periods while it chews up vast amounts of power?  Evan a silly
msleep(1) in there would help tremendously.

> +static void mg_unexpected_intr(struct mg_host *host)
> +{
> +	u32 status = inb(host->dev_base + MG_REG_STATUS);
> +
> +	mg_dump_status("mg_unexpected_intr", status, host);
> +}
> +
> +static irqreturn_t mg_irq(int irq, void *dev_id)
> +{
> +	struct mg_host *host = dev_id;
> +	void (*handler)(struct mg_host *) = host->mg_do_intr;
> +
> +	host->mg_do_intr = 0;
> +	del_timer(&host->timer);
> +	if (!handler)
> +		handler = mg_unexpected_intr;
> +	handler(host);
> +	return IRQ_HANDLED;
> +}
> +
> +static void mg_ide_fixstring(u8 *s, const int bytecount)
> +{
> +	u8 *p, *end = &s[bytecount & ~1]; /* bytecount must be even */
> +
> +	/* convert from big-endian to host byte order */
> +	for (p = s ; p != end ; p += 2)

It's more conventional to omit the space before the semicolon in `for'
statements.

> +		be16_to_cpus((u16 *) p);
> +
> +	/* strip leading blanks */
> +	p = s;
> +	while (s != end && *s == ' ')
> +		++s;
> +	/* compress internal blanks and strip trailing blanks */
> +	while (s != end && *s) {
> +		if (*s++ != ' ' || (s != end && *s && *s != ' '))
> +			*p++ = *(s-1);
> +	}
> +	/* wipe out trailing garbage */
> +	while (p != end)
> +		*p++ = '\0';
> +}

erk, what's this doing?  Regularizing some ID text which it read from
the device, it seems.

It should have a nice comment explaining this, and perhaps explaining
the transformations which it attempts to make.

Because I'm sure that there's library code in the kernel which does at
least some of whatever-this-function-does.  Steve Rostedt presently has
some infrastructure code of this nature under review.

> +static int mg_get_disk_id(struct mg_host *host)
> +{
> +	u32 i, res;
> +	s32 err;
> +	u16 *id = (u16 *)&host->id_data;
> +	struct mg_drv_data *prv_data = host->dev->platform_data;
> +
> +	if (!prv_data->use_polling)
> +		outb(MG_REG_CTRL_INTR_DISABLE,
> +				host->dev_base + MG_REG_DRV_CTRL);
> +
> +	outb(MG_CMD_ID, host->dev_base + MG_REG_COMMAND);
> +	err = mg_wait(host, MG_REG_STATUS_BIT_DATA_REQ, 3000);
> +	if (err)
> +		return err;
> +
> +	for (i = 0; i < (MG_SECTOR_SIZE >> 1); i++)
> +		id[i] = le16_to_cpu(inw(host->dev_base + MG_BUFF_OFFSET +
> +					i * 2));
> +
> +	outb(MG_CMD_RD_CONF, host->dev_base + MG_REG_COMMAND);
> +	err = mg_wait(host, MG_STAT_READY, 3000);
> +	if (err)
> +		return err;
> +
> +	if ((host->id_data.field_valid & 1) == 0)
> +		return MG_ERR_TRANSLATION;
> +
> +#ifdef __BIG_ENDIAN
> +	host->id_data.lba_capacity = (host->id_data.lba_capacity << 16)
> +		| (host->id_data.lba_capacity >> 16);
> +#endif /* __BIG_ENDIAN */
> +	if (MG_RES_SEC) {
> +		/* modify cyls, lba_capacity */
> +		host->id_data.cyls = (host->id_data.lba_capacity - MG_RES_SEC) /
> +			host->id_data.heads / host->id_data.sectors;

Could a bad device trick the kernel into doing a divide-by-zero here?

> +		res = host->id_data.lba_capacity - host->id_data.cyls *
> +			host->id_data.heads * host->id_data.sectors;
> +		host->id_data.lba_capacity -= res;
> +	}
> +	host->tot_sectors = host->id_data.lba_capacity;
> +	mg_ide_fixstring(host->id_data.model,
> +			sizeof(host->id_data.model));
> +	mg_ide_fixstring(host->id_data.serial_no,
> +			sizeof(host->id_data.serial_no));
> +	mg_ide_fixstring(host->id_data.fw_rev,
> +			sizeof(host->id_data.fw_rev));
> +	printk(KERN_INFO "mg_disk: model: %s\n", host->id_data.model);
> +	printk(KERN_INFO "mg_disk: firm: %.8s\n", host->id_data.fw_rev);
> +	printk(KERN_INFO "mg_disk: serial: %s\n",
> +			host->id_data.serial_no);
> +	printk(KERN_INFO "mg_disk: %d + reserved %d sectors\n",
> +			host->tot_sectors, res);
> +
> +	if (!prv_data->use_polling)
> +		outb(MG_REG_CTRL_INTR_ENABLE, host->dev_base + MG_REG_DRV_CTRL);
> +
> +	return err;
> +}
>
> ...
>
> +static int mg_resume(struct platform_device *plat_dev)
> +{
> +	struct mg_drv_data *prv_data = plat_dev->dev.platform_data;
> +	struct mg_host *host = prv_data->host;
> +
> +	if (mg_wait(host, MG_STAT_READY, 3000))
> +		return -EIO;
> +
> +	outb(MG_CMD_WAKEUP, host->dev_base + MG_REG_COMMAND);
> +	mdelay(1);

There's no way in which the reader of this code can determine why this
delay is here, and why it has this duration.  Comments shold be added
to fix this!

Can we avoid using a busy-waiting delay?

> +	if (mg_wait(host, MG_STAT_READY, 3000))
> +		return -EIO;
> +
> +	if (!prv_data->use_polling)
> +		outb(MG_REG_CTRL_INTR_ENABLE, host->dev_base + MG_REG_DRV_CTRL);
> +
> +	return 0;
> +}
> +
> +static int mg_probe(struct platform_device *plat_dev)
> +{
> +	struct mg_host *host;
> +	struct resource *rsc;
> +	struct mg_drv_data *prv_data = plat_dev->dev.platform_data;
> +	int err = 0;
> +
> +	if (!prv_data) {
> +		printk(KERN_ERR	"%s:%d fail (no driver_data)\n",
> +				__func__, __LINE__);
> +		err = -EINVAL;
> +		goto probe_err;
> +	}
> +
> +	/* alloc mg_host */
> +	host = kmalloc(sizeof(struct mg_host), GFP_KERNEL);
> +	if (!host) {
> +		printk(KERN_ERR "%s:%d fail (no memory for mg_host)\n",
> +				__func__, __LINE__);
> +		err = -ENOMEM;
> +		goto probe_err;
> +	}
> +	memset(host, 0, sizeof(struct mg_host));

use kzalloc()

> +	host->major = MG_DISK_MAJ;
> +
> +	/* link each other */
> +	prv_data->host = host;
> +	host->dev = &plat_dev->dev;
> +
> +	/* io remap */
> +	rsc = platform_get_resource(plat_dev, IORESOURCE_MEM, 0);
> +	if (!rsc) {
> +		printk(KERN_ERR "%s:%d platform_get_resource fail\n",
> +				__func__, __LINE__);
> +		err = -EINVAL;
> +		goto probe_err_2;
> +	}
> +	host->dev_base = (unsigned long)ioremap(rsc->start , rsc->end + 1);

ioremap() returns `void __iomem *'.  Casting it into an unsigned long
loses the sparse-checkable annotation and loses the (correct)
information that this is an address.

IOW, host->dev_base has the wrong type, doesn't it?


> +	if (!host->dev_base) {
> +		printk(KERN_ERR "%s:%d ioremap fail\n",
> +				__func__, __LINE__);
> +		err = -EIO;
> +		goto probe_err_2;
> +	}
> +	MG_DBG("dev_base = 0x%x\n", (u32)host->dev_base);
> +
> +	/* get reset pin */
> +	rsc = platform_get_resource(plat_dev, IORESOURCE_IO, 0);
> +	if (!rsc) {
> +		printk(KERN_ERR "%s:%d get reset pin fail\n",
> +				__func__, __LINE__);
> +		err = -EIO;
> +		goto probe_err_3;
> +	}
> +	host->rst = rsc->start;
> +
> +	/* init rst pin */
> +	err = gpio_request(host->rst, "mg_rst");
> +	if (err)
> +		goto probe_err_3;
> +	gpio_direction_output(host->rst, 1);

Did this driver express a dependency on GPIO in its Kconfig?

> +	/* disk init */
> +	err = mg_disk_init(host);
> +	if (err) {
> +		printk(KERN_ERR "%s:%d fail (err code : %d)\n",
> +				__func__, __LINE__, err);
> +		err = -EIO;
> +		goto probe_err_3a;
> +	}
> +
>
> ...
>

^ permalink raw reply

* Re: ramfs/tmpfs for application partition
From: Aras Vaichas @ 2009-03-09  6:00 UTC (permalink / raw)
  To: Jacob Avraham; +Cc: linux-embedded@vger.kernel.org
In-Reply-To: <FF584854D6FFE547AB2F7515A798AC3A045716A1B4@venus.imagineil.tv>

Jacob Avraham wrote:
> Hi,
>
> I have a system with 128M RAM and a flash partitioned so that 10M is dedicated to initramfs image,
> 6M to application partition. And another 6M for JFFS2.
> As I have plenty of RAM, I'd like to have my application directory mounted on RAM, from a pre-populated
> filesystem that resides in the 6M application partition.
> So basically I want to use the same mechanism as initramfs, but mounted on /my/app/partition instead of root.
> Does it make sense? How do I go about and do that?
What about unionfs or Aufs?

I think you'd need to have your "original" as a proper filing system. 
Then you'd mount the unionfs over the top of it, but it would be in RAM. 
From the user's point of view, they'd had full read/write access to the 
whole filing system, but unionfs/Aufs would save the changes into RAM, 
not Flash.

This is how Linux Live CDs work. They allow you to "write" to the filing 
system on the CD using UnionsFS, but it's only temporary.

This should be be faster than uncompressing a compressed image into RAM, 
and the kernel will only cache the data that it needs as it accesses it. 
Since all write-backs will occur in RAM then this should be very fast.

Aras




______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________

^ permalink raw reply

* [ANNOUNCE] Embedded Linux Conference 2009
From: Tim Bird @ 2009-03-09 22:00 UTC (permalink / raw)
  To: linux-embedded

My apologies in advance for this notice.  I only do this
a few times a year. Some people on this list may be interested....

Embedded Linux Developers,

Registration for Embedded Linux Conference 2009 -
   "Ubiquity" - is now open!

The conference is coming soon - It will be April 6, 7 and 8
in San Francisco, California.

The program is now available at the conference web site at:
http://www.embeddedlinuxconference.com/elc_2009/
(see the "Program" and "Sessions" tabs).

Here are some highlights:

Keynote speakers Dirk Hohndel and David Woodhouse will talk about
recent trends in Linux development, and what it means now that
Linux has achieved ubiquity in the embedded space.

* Dirk Hohndel is Intel's Chief Linux and Open Source Technologist
and former CTO of SuSE

* David Woodhouse is the official "embedded" maintainer for the mainline
Linux kernel, and the original author of the JFFS2 flash filesystem.

Just a few of the notable speakers presenting at the conference include:

* Jim Ready - Founder and CTO of MontaVista
* Kate Alhola - Maemo chief engineer in Forum Nokia
* Dan Malek - Founder and CTO of Embedded Alley
* Mike Anderson - CTO and Chief Scientist at The PTR Group

Along with these speakers, there will be 3 days of presentations,
tutorials and Bird-of-a-Feather sessions on topics like:

Flash filesystems, real-time Linux, graphics systems for embedded,
mobile and embedded distributions, optimizations for embedded
processors (SH, ARM, MIPS, PPC), security, memory management,
porting and platform bringup, networking, development tools,
compilers, tracing, bootup time reduction, power management,
   and (surprisingly) more!

This is your chance to talk to engineers working on real products at
some of the largest CE companies in the world, describing how they
solved real issues in their own development projects.  Also, meet
leading developers from the embedded Linux community, and learn about
the latest changes in Linux.  The Embedded Linux Conference is one of
the leading events where you can learn directly from the experts.
Just take a look at past conferences to see the technical depth of
this event!
See http://www.embeddedlinuxconference.com/history.html

I know... - In the current economic conditions, it's going to be tough
to convince your management to let you come to a conference - but NOW
is exactly the time to be honing your Linux skills and increasing
the efficiency of your development work.  A 15-minute hallway
conversation with an expert can save you weeks of development effort.
It's happened to me again and again at Embedded Linux Conferences
over the years, which is one of the reasons I keep coming back!

Register now by following the link on the conference page at:
    http://www.embeddedlinuxconference.com/elc_2009/

Please note that this year, we are co-locating with the Linux Foundation
Collaboration Summit.  This event will be held April 8-10 in the same
venue. As a special one-time opportunity, the Linux Foundation has
agreed to allow to ELC attendees to participate in that event as
well (at no charge). The Collaboration Summit is normally an invitation-only
event, so this is a unique opportunity to participate and interact
with additional community and industry Linux developers and leaders!

The website for the Collaboration Summit is:
http://events.linuxfoundation.org/events/collaboration-summit

We've got a great event planned, that we're sure you won't want to miss.
Register now and join us in San Francisco, for more progress towards
embedded Linux "Ubiquity"!

Register by March 20th to receive the "early-bird" (no relation to me)
discount!
 -- Tim

=============================
Tim Bird
Architecture Group Chair, CE Linux Forum
Senior Staff Engineer, Sony Corporation of America
=============================

^ permalink raw reply

* XZ (LZMA2) decoder
From: Lasse Collin @ 2009-03-22 13:57 UTC (permalink / raw)
  To: linux-embedded

(Please CC your replies to me, I'm not on the list.)

An initial version of the .xz file format decoder for Linux is now 
available at <git://ctrl.tukaani.org/xz-embedded.git>. It supports both 
stateful and single-call decoding using the LZMA2 algorithm.

Two buffers (1.2 KiB and 28 KiB) are allocated with kmalloc() for 
internal data. For stateful decoding, also a dictionary is allocated 
with vmalloc(), which probably will usually be from 64 KiB to 1 MiB. The 
dictionary is allocated when the decoder is created, so the decoder 
never allocates memory in the middle of decoding. This means that if the 
preallocated dictionary was too small for the input stream, decoding 
will fail. In single-call mode, the destination buffer is used as the 
dictionary, thus a separate dictionary doesn't need to be allocated.

On x86, xz_dec.ko is 11-14 KiB. Stack usage is around 120-240 bytes, 
depending on the GCC version and compiler flags. I hope it is not too 
much, but I can try to reduce it slightly if needed.

BCJ filters are not added yet. They will increase the code size a little 
but they should save more space by increasing compression ratio of 
executables (and naturally it will be possible to disable these filters 
in the kernel config).

There is some code (mostly in xz_boot.c), which hopefully makes it 
easier to add support for XZ compressed kernel and initramfs. I hope 
that someone else does the actual work to get XZ support in the arch-
specific trees (IIRC, there were some patches to add bzip2 and LZMA 
support already), but I'm happy to help if my code needs some 
adjustments to support that work.

I have tried to follow to the kernel coding style as well as I can, but 
if there are style issues that should be fixed, please let me know. I 
want to keep the code usable outside Linux, which why there are some 
extra #ifdefs and such. I hope this is OK.

I haven't tested the code much yet. It appears to work in userspace. The 
kernel module compiles cleanly on x86, but I haven't tested it in kernel 
space, because I currently have no code to feed data to the XZ decoder 
in the kernel space.

-- 
Lasse Collin  |  IRC: Larhzu @ IRCnet & Freenode

^ permalink raw reply

* Re: [Patch] ltt-relay-alloc mmap support (due to NFS lack of splice  support)
From: Masahiro Tamori @ 2009-03-23 12:34 UTC (permalink / raw)
  To: Mathieu Desnoyers
  Cc: ltt-dev, linux-kernel-u79uwXL29TY76Z2rM5mHXA, Ingo Molnar,
	linux-nfs-u79uwXL29TY76Z2rM5mHXA,
	linux-embedded-u79uwXL29TY76Z2rM5mHXA
In-Reply-To: <20090320152857.GB30019@Krystal>

2009/3/21 Mathieu Desnoyers <mathieu.desnoyers-scC8bbJcJLCw5LPnMra/2Q@public.gmane.org>:
> * Masahiro Tamori (masahiro.tamori-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org) wrote:
>> Hello Mathieu,
>>
>> I use the following version.
>> LTTV 0.12.12
>> LTTng 0.110
>> LTT Control 0.67
>> Kernles 2.6.29-rc7
>>
>> The target is ARM RealviewEB.
>>
>> Our customer will use NFS to store trace data not storage device for
>> embedded devices.
>> Since newer lttng use splice() even if NFS can not support splice(),
>> I create a patch to support to mmap of ltt-relay-alloc.
>>
>> I will send a mail to this mailing list for ltt-control patch.
>> I do not know which mailing list should be posted for userland tools.
>>
>> Best Regards,
>> Masahiro Tamori
>>
>>
>> ltt-relay-alloc mmap support
>>
>> Splice syscall does not support NFS. We can not save trace data to
>> NFS directory. If this feature is enabled, you can use mmap()
>> instead of splice().
>>
>
>
> Hi Masahiro,
>
> Maybe we should consider implementing splice() support in NFS instead ?
>
> I removed the mmap support from the ltt-relay-alloc files because splice
> is more efficient and does not require to vmap the pages.  Unless there
> is a strong argument telling what in NFS makes it impossible to
> implement splice(), I don't really see the gain in putting back the
> old mmap() mechanism we had.
>
> Maybe the NFS people will have some information about this ?
>
> Thanks,
>
> Mathieu
>

Hello Mathieu,

I think that the best solution is NFS can support splice() even if
it cannot zero copy.

The splice() will be used by any other tools, hence NFS should support
it sooner or later.

If technical issue is remained to support splice() in NFS,
we should support mmap in LTTng until the problem is resolved.
Embedded people will want to use LTTng with NFS,
though this is a bad choice.

Thank you,
Masahiro Tamori

>
>> For embeded system, NFS must be used. Target board has not enough memory
>> to save trace data and some board can not connect ATA, USB and some strage
>> devices.
>>
>> Signed-off-by: Masahiro.Tamori-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
>> ---
>>  ltt/Kconfig              |   11      11 +    0 -     0 !
>>  ltt/ltt-relay-alloc.c    |   88      88 +    0 -     0 !
>>  ltt/ltt-relay-lockless.c |   15      15 +    0 -     0 !
>>  3 files changed, 114 insertions(+)
>>
>> Index: b/ltt/Kconfig
>> ===================================================================
>> --- a/ltt/Kconfig
>> +++ b/ltt/Kconfig
>> @@ -66,6 +66,17 @@ choice
>>
>>  endchoice
>>
>> +config LTT_RELAY_ALLOC_MMAP
>> +     bool "Linux Trace Toolkit Relay mmap Support"
>> +     depends on LTT_RELAY_ALLOC
>> +     default y
>> +     help
>> +       Support mmap for ltt-relay.
>> +
>> +       Splice syscall does not support NFS. We can not save trace data to
>> +          NFS directory. If this feature is enabled, you can use mmap()
>> +          instead of splice().
>> +
>>  config LTT_SERIALIZE
>>       tristate "Linux Trace Toolkit Serializer"
>>       depends on LTT_RELAY_ALLOC
>> Index: b/ltt/ltt-relay-alloc.c
>> ===================================================================
>> --- a/ltt/ltt-relay-alloc.c
>> +++ b/ltt/ltt-relay-alloc.c
>> @@ -27,6 +27,74 @@
>>  static DEFINE_MUTEX(relay_channels_mutex);
>>  static LIST_HEAD(relay_channels);
>>
>> +#ifdef CONFIG_LTT_RELAY_ALLOC_MMAP
>> +/*
>> + * close() vm_op implementation for relay file mapping.
>> + */
>> +static void relay_file_mmap_close(struct vm_area_struct *vma)
>> +{
>> +}
>> +
>> +/*
>> + * fault() vm_op implementation for relay file mapping.
>> + */
>> +static int relay_buf_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
>> +{
>> +     struct page *page = NULL;
>> +     struct rchan_buf *buf = vma->vm_private_data;
>> +     pgoff_t pgoff = vmf->pgoff;
>> +     struct page **pages;
>> +
>> +     if (!buf)
>> +             return VM_FAULT_OOM;
>> +
>> +     if (pgoff >= buf->page_count)
>> +             return VM_FAULT_SIGBUS;
>> +
>> +     pages = buf->pages;
>> +     page = pages[pgoff];
>> +     get_page(page);
>> +     vmf->page = page;
>> +
>> +     return 0;
>> +}
>> +
>> +/*
>> + * vm_ops for relay file mappings.
>> + */
>> +static struct vm_operations_struct relay_file_mmap_ops = {
>> +     .fault = relay_buf_fault,
>> +     .close = relay_file_mmap_close,
>> +};
>> +
>> +/**
>> + *   relay_mmap_buf: - mmap channel buffer to process address space
>> + *   @buf: relay channel buffer
>> + *   @vma: vm_area_struct describing memory to be mapped
>> + *
>> + *   Returns 0 if ok, negative on error
>> + *
>> + *   Caller should already have grabbed mmap_sem.
>> + */
>> +static int relay_mmap_buf(struct rchan_buf *buf, struct vm_area_struct *vma)
>> +{
>> +     unsigned long length = vma->vm_end - vma->vm_start;
>> +
>> +     if (!buf)
>> +             return -EBADF;
>> +
>> +     if (length != (unsigned long)buf->chan->alloc_size)
>> +             return -EINVAL;
>> +
>> +     vma->vm_ops = &relay_file_mmap_ops;
>> +     vma->vm_flags |= VM_DONTEXPAND;
>> +     vma->vm_private_data = buf;
>> +
>> +     return 0;
>> +}
>> +
>> +#endif /* CONFIG_LTT_RELAY_ALLOC_MMAP */
>> +
>>  /**
>>   *   relay_alloc_buf - allocate a channel buffer
>>   *   @buf: the buffer struct
>> @@ -601,6 +669,23 @@ static int relay_file_open(struct inode
>>       return nonseekable_open(inode, filp);
>>  }
>>
>> +#ifdef CONFIG_LTT_RELAY_ALLOC_MMAP
>> +
>> +/**
>> + *   relay_file_mmap - mmap file op for relay files
>> + *   @filp: the file
>> + *   @vma: the vma describing what to map
>> + *
>> + *   Calls upon relay_mmap_buf() to map the file into user space.
>> + */
>> +static int relay_file_mmap(struct file *filp, struct vm_area_struct *vma)
>> +{
>> +     struct rchan_buf *buf = filp->private_data;
>> +     return relay_mmap_buf(buf, vma);
>> +}
>> +
>> +#endif /* CONFIG_LTT_RELAY_ALLOC_MMAP */
>> +
>>  /**
>>   *   relay_file_release - release file op for relay files
>>   *   @inode: the inode
>> @@ -619,6 +704,9 @@ static int relay_file_release(struct ino
>>
>>  const struct file_operations ltt_relay_file_operations = {
>>       .open           = relay_file_open,
>> +#ifdef CONFIG_LTT_RELAY_ALLOC_MMAP
>> +     .mmap           = relay_file_mmap,
>> +#endif
>>       .release        = relay_file_release,
>>  };
>>  EXPORT_SYMBOL_GPL(ltt_relay_file_operations);
>> Index: b/ltt/ltt-relay-lockless.c
>> ===================================================================
>> --- a/ltt/ltt-relay-lockless.c
>> +++ b/ltt/ltt-relay-lockless.c
>> @@ -427,6 +427,18 @@ static int ltt_release(struct inode *ino
>>  }
>>
>>  /**
>> + *   ltt_mmap - mmap file op for ltt files
>> + *   @inode: opened inode
>> + *   @file: opened file
>> + *
>> + *   Mmap implementation.
>> + */
>> +static int ltt_mmap(struct file *file,  struct vm_area_struct *vma)
>> +{
>> +     return ltt_relay_file_operations.mmap(file, vma);
>> +}
>> +
>> +/**
>>   *   ltt_poll - file op for ltt files
>>   *   @filp: the file
>>   *   @wait: poll table
>> @@ -1590,6 +1602,9 @@ static struct ltt_transport ltt_relay_tr
>>  static const struct file_operations ltt_file_operations = {
>>       .open = ltt_open,
>>       .release = ltt_release,
>> +#ifdef CONFIG_LTT_RELAY_ALLOC_MMAP
>> +     .mmap           = ltt_mmap,
>> +#endif
>>       .poll = ltt_poll,
>>       .splice_read = ltt_relay_file_splice_read,
>>       .ioctl = ltt_ioctl,
>
> --
> Mathieu Desnoyers
> OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68
>
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply

* Re: [Patch] ltt-relay-alloc mmap support (due to NFS lack of splice support)
From: Mathieu Desnoyers @ 2009-03-23 17:58 UTC (permalink / raw)
  To: Masahiro Tamori
  Cc: Ingo Molnar, ltt-dev, linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-embedded-u79uwXL29TY76Z2rM5mHXA,
	linux-nfs-u79uwXL29TY76Z2rM5mHXA, Jens Axboe, Nick Piggin
In-Reply-To: <91e0b5050903230534g57d1ef8byd14a1fb5ca807192-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>

* Masahiro Tamori (masahiro.tamori-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org) wrote:
> 2009/3/21 Mathieu Desnoyers <mathieu.desnoyers-scC8bbJcJLCw5LPnMra/2Q@public.gmane.org>:
> > * Masahiro Tamori (masahiro.tamori-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org) wrote:
[...]
> >> Our customer will use NFS to store trace data not storage device for
> >> embedded devices.
> >> Since newer lttng use splice() even if NFS can not support splice(),
> >> I create a patch to support to mmap of ltt-relay-alloc.
> >>
[...]
> >> ltt-relay-alloc mmap support
> >>
> >> Splice syscall does not support NFS. We can not save trace data to
> >> NFS directory. If this feature is enabled, you can use mmap()
> >> instead of splice().
> >>
> >
> >
> > Hi Masahiro,
> >
> > Maybe we should consider implementing splice() support in NFS instead ?
> >
> > I removed the mmap support from the ltt-relay-alloc files because splice
> > is more efficient and does not require to vmap the pages.  Unless there
> > is a strong argument telling what in NFS makes it impossible to
> > implement splice(), I don't really see the gain in putting back the
> > old mmap() mechanism we had.
> >
> > Maybe the NFS people will have some information about this ?
> >
> > Thanks,
> >
> > Mathieu
> >
> 
> Hello Mathieu,
> 
> I think that the best solution is NFS can support splice() even if
> it cannot zero copy.
> 
> The splice() will be used by any other tools, hence NFS should support
> it sooner or later.
> 
> If technical issue is remained to support splice() in NFS,
> we should support mmap in LTTng until the problem is resolved.
> Embedded people will want to use LTTng with NFS,
> though this is a bad choice.
> 
> Thank you,
> Masahiro Tamori
> 

There was a LKML thread on NFS splice support back in 2006 :

http://lkml.indiana.edu/hypermail/linux/kernel/0603.3/2102.html

I don't know what happened with this ? I have tested NFS v2 and v3 and
have seen they do not support splice, but haven't tested NFSv4.

Mathieu

-- 
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply

* Re: [Patch] ltt-relay-alloc mmap support (due to NFS lack of splice support)
From: Trond Myklebust @ 2009-03-23 19:14 UTC (permalink / raw)
  To: Mathieu Desnoyers
  Cc: Masahiro Tamori, Ingo Molnar, ltt-dev, linux-kernel,
	linux-embedded, linux-nfs, Jens Axboe, Nick Piggin
In-Reply-To: <20090323175820.GH24084@Krystal>

On Mon, 2009-03-23 at 13:58 -0400, Mathieu Desnoyers wrote:
> * Masahiro Tamori (masahiro.tamori@gmail.com) wrote:
> > 2009/3/21 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>:
> > > * Masahiro Tamori (masahiro.tamori@gmail.com) wrote:
> [...]
> > >> Our customer will use NFS to store trace data not storage device for
> > >> embedded devices.
> > >> Since newer lttng use splice() even if NFS can not support splice(),
> > >> I create a patch to support to mmap of ltt-relay-alloc.
> > >>
> [...]
> > >> ltt-relay-alloc mmap support
> > >>
> > >> Splice syscall does not support NFS. We can not save trace data to
> > >> NFS directory. If this feature is enabled, you can use mmap()
> > >> instead of splice().
> > >>
> > >
> > >
> > > Hi Masahiro,
> > >
> > > Maybe we should consider implementing splice() support in NFS instead ?
> > >
> > > I removed the mmap support from the ltt-relay-alloc files because splice
> > > is more efficient and does not require to vmap the pages.  Unless there
> > > is a strong argument telling what in NFS makes it impossible to
> > > implement splice(), I don't really see the gain in putting back the
> > > old mmap() mechanism we had.
> > >
> > > Maybe the NFS people will have some information about this ?
> > >
> > > Thanks,
> > >
> > > Mathieu
> > >
> > 
> > Hello Mathieu,
> > 
> > I think that the best solution is NFS can support splice() even if
> > it cannot zero copy.
> > 
> > The splice() will be used by any other tools, hence NFS should support
> > it sooner or later.
> > 
> > If technical issue is remained to support splice() in NFS,
> > we should support mmap in LTTng until the problem is resolved.
> > Embedded people will want to use LTTng with NFS,
> > though this is a bad choice.
> > 
> > Thank you,
> > Masahiro Tamori
> > 
> 
> There was a LKML thread on NFS splice support back in 2006 :
> 
> http://lkml.indiana.edu/hypermail/linux/kernel/0603.3/2102.html
> 
> I don't know what happened with this ? I have tested NFS v2 and v3 and
> have seen they do not support splice, but haven't tested NFSv4.
> 
> Mathieu

We do support splice reads and apparently don't support splice writes.
However I don't see what has been stopping anybody from implementing the
latter.

In fact, it looks to me as if we should just be able to use
generic_file_splice_write() as is. There is no O_APPEND support or
anything that would require us to revalidate file lengths; it's just a
perfectly ordinary write into the page cache...

Cheers
   Trond

^ permalink raw reply

* Sources of entropy?
From: Robin Getz @ 2009-03-24 22:47 UTC (permalink / raw)
  To: linux-embedded

I'm just wondering what people using on standard embedded/headless/diskless 
targets (which do not have hw random number generators) as a source of 
entropy - since networking was removed as an entropy source circa 2.6.26

On my target:

root:/> cat /proc/sys/kernel/random/entropy_avail
0

is about all I get... (since I'm not running any userspace utils yet).


I have seen rngd, clrngd, audio_entropyd, & video_entroyd - but I was just 
wondering what others were actually using. (I was cautioned that everything 
was pretty CPU intensive, since they all have a FIPS testing to ensure 
randomness)...

Thanks in advance.
-Robin

^ permalink raw reply

* Re: Sources of entropy?
From: David VomLehn @ 2009-03-25 17:06 UTC (permalink / raw)
  To: Robin Getz; +Cc: linux-embedded
In-Reply-To: <200903241847.29104.rgetz@blackfin.uclinux.org>

Robin Getz wrote:
> I'm just wondering what people using on standard embedded/headless/diskless 
> targets (which do not have hw random number generators) as a source of 
> entropy - since networking was removed as an entropy source circa 2.6.26
> 
> On my target:
> 
> root:/> cat /proc/sys/kernel/random/entropy_avail
> 0
> 
> is about all I get... (since I'm not running any userspace utils yet).
> 
> I have seen rngd, clrngd, audio_entropyd, & video_entroyd - but I was just 
> wondering what others were actually using. (I was cautioned that everything 
> was pretty CPU intensive, since they all have a FIPS testing to ensure 
> randomness)...

The answer on the box I'm working on is: very little. I need to generate 
  an Ethernet MAC address and had to come up with way so that few random 
bits I had were sufficient, in my particular environment, to avoid 
address collisions.

^ permalink raw reply

* Re: XZ (LZMA2) decoder
From: Leon Woestenberg @ 2009-03-25 21:39 UTC (permalink / raw)
  To: Lasse Collin; +Cc: linux-embedded
In-Reply-To: <200903221557.33588.lasse.collin@tukaani.org>

Hello Lasse,

On Sun, Mar 22, 2009 at 2:57 PM, Lasse Collin <lasse.collin@tukaani.org> wrote:
> (Please CC your replies to me, I'm not on the list.)
>
> An initial version of the .xz file format decoder for Linux is now
> available at <git://ctrl.tukaani.org/xz-embedded.git>. It supports both
> stateful and single-call decoding using the LZMA2 algorithm.
>
Is this something the linux-embedded community must pick up, or maybe
even the LKML?

Regards,
-- 
Leon

^ permalink raw reply

* Re: XZ (LZMA2) decoder
From: Bernhard Reutner-Fischer @ 2009-03-25 21:41 UTC (permalink / raw)
  To: Leon Woestenberg; +Cc: Lasse Collin, linux-embedded
In-Reply-To: <c384c5ea0903251439k2ba46bffq729c013a48e2d6b9@mail.gmail.com>

On Wed, Mar 25, 2009 at 10:39:06PM +0100, Leon Woestenberg wrote:
>Hello Lasse,
>
>On Sun, Mar 22, 2009 at 2:57 PM, Lasse Collin <lasse.collin@tukaani.org> wrote:
>> (Please CC your replies to me, I'm not on the list.)
>>
>> An initial version of the .xz file format decoder for Linux is now
>> available at <git://ctrl.tukaani.org/xz-embedded.git>. It supports both
>> stateful and single-call decoding using the LZMA2 algorithm.
>>
>Is this something the linux-embedded community must pick up, or maybe
>even the LKML?

This is certainly the way to go, yes.

^ permalink raw reply

* Re: Sources of entropy?
From: Jamie Lokier @ 2009-03-26 13:25 UTC (permalink / raw)
  To: Robin Getz; +Cc: linux-embedded
In-Reply-To: <200903241847.29104.rgetz@blackfin.uclinux.org>

Robin Getz wrote:
> I'm just wondering what people using on standard embedded/headless/diskless 
> targets (which do not have hw random number generators) as a source of 
> entropy - since networking was removed as an entropy source circa 2.6.26

You might not have much real entropy to use.  I guess networking was
removed because it's an obvious attack vector.

On my devices, I save the entropy pool to flash on shutdown and merge
it back on reboot.  This lets cumulative history build.
    
    [shutdown]
    dd if=/dev/urandom of=$ENTROPY_STORE.new bs=512 count=1 2>/dev/null \
       && mv $ENTROPY_STORE.new $ENTROPY_STORE \
       || rm -f $ENTROPY_STORE.new

    [boot]
    dd if=$ENTROPY_STORE of=/dev/random bs=512 2>/dev/null

You'll still drain the pool quickly so may need to use /dev/urandom
for everything (e.g. by linking /dev/random -> /dev/urandom), but
keeping history does mean you get more real entropy from /dev/urandom,
even though entropy_avail cannot estimate it (and the lower bound is
still zero, if what you did before has always been predictable).

> I have seen rngd, clrngd, audio_entropyd, & video_entroyd - but I was just 
> wondering what others were actually using. (I was cautioned that everything 
> was pretty CPU intensive, since they all have a FIPS testing to ensure 
> randomness)...

You can write anything you think is an entropy source to /dev/random,
and it won't increase the entropy estimate but it will increase real
entropy if your source has any.  So you could add low-order bits from
high-resolution timing data from your network application from time to
time, for example, if you think it's worth it.

That won't make /dev/random show confirmed non-zero entropy, but that
might not be feasible on your device anyway.

-- Jamie

^ permalink raw reply

* Re: XZ (LZMA2) decoder
From: Lasse Collin @ 2009-03-26 13:34 UTC (permalink / raw)
  To: Leon Woestenberg; +Cc: linux-embedded
In-Reply-To: <c384c5ea0903251439k2ba46bffq729c013a48e2d6b9@mail.gmail.com>

On 2009-03-25 Leon Woestenberg wrote:
> Is this something the linux-embedded community must pick up, or maybe
> even the LKML?

In December, there was some discussion on linux-embedded about getting 
LZMA decoder into Linux. I understood that some of the existing patches 
had trouble meeting the kernel quality standards. There were also 
requirements like support for multi-call decoding, which should be 
useful at least in Squashfs. I promised to write a nice-looking .xz file 
format decoder for Linux (.xz will replace the .lzma format) and post to 
linux-embedded when I have something to show.

Assuming there still is interest like there was in December, hope I will 
get some feedback to know if my code looks promising and possibly how it 
should be improved to be good for in-kernel use. This is my first Linux 
kernel related coding project, so there probably are things (other than 
plain bugs) that need to be fixed before the code can be considered for 
inclusion.

If linux-embedded is not the best list for this, I can post to LKML too. 
However, since I promised to post at least to linux-embedded, and the 
discussion on this list in December was very helpful for me to 
understand what is required from an in-kernel decompressor, starting a 
new discussion first on linux-embedded sounded obvious to me.

Stable userspace tools to handle .xz files are still not available. I 
simply haven't worked on them much in the past two months. I naturally 
hope to get the stable release out soon, but my ability work on these 
projects depends on a couple of other things in my life, so it's better 
I don't promise anything detailed. On the positive side, the latest XZ 
Utils beta should be quite good already.

-- 
Lasse Collin  |  IRC: Larhzu @ IRCnet & Freenode

^ permalink raw reply

* Re: XZ (LZMA2) decoder
From: Geert Uytterhoeven @ 2009-03-26 15:36 UTC (permalink / raw)
  To: Lasse Collin; +Cc: Leon Woestenberg, linux-embedded
In-Reply-To: <200903261534.41887.lasse.collin@tukaani.org>

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: TEXT/PLAIN; charset="ks_c_5601-1987", Size: 2072 bytes --]

On Thu, 26 Mar 2009, Lasse Collin wrote:
> On 2009-03-25 Leon Woestenberg wrote:
> > Is this something the linux-embedded community must pick up, or maybe
> > even the LKML?
> 
> In December, there was some discussion on linux-embedded about getting 
> LZMA decoder into Linux. I understood that some of the existing patches 
> had trouble meeting the kernel quality standards. There were also 
> requirements like support for multi-call decoding, which should be 
> useful at least in Squashfs. I promised to write a nice-looking .xz file 
> format decoder for Linux (.xz will replace the .lzma format) and post to 
> linux-embedded when I have something to show.

Yes, this is interesting work!

> Assuming there still is interest like there was in December, hope I will 
> get some feedback to know if my code looks promising and possibly how it 
> should be improved to be good for in-kernel use. This is my first Linux 
> kernel related coding project, so there probably are things (other than 
> plain bugs) that need to be fixed before the code can be considered for 
> inclusion.

I gave it a quick test on ppc64, and the kernel part built fine with sparse
checking enabled (make C=1), without any warnings.

> If linux-embedded is not the best list for this, I can post to LKML too. 
> However, since I promised to post at least to linux-embedded, and the 
> discussion on this list in December was very helpful for me to 
> understand what is required from an in-kernel decompressor, starting a 
> new discussion first on linux-embedded sounded obvious to me.

Ccing lkml wouldn't hurt, I think.

With kind regards,

Geert Uytterhoeven
Software Architect

Sony Techsoft Centre Europe
The Corporate Village · Da Vincilaan 7-D1 · B-1935 Zaventem · Belgium

Phone:    +32 (0)2 700 8453
Fax:      +32 (0)2 700 8622
E-mail:   Geert.Uytterhoeven@sonycom.com
Internet: http://www.sony-europe.com/

A division of Sony Europe (Belgium) N.V.
VAT BE 0413.825.160 · RPR Brussels
Fortis · BIC GEBABEBB · IBAN BE41293037680010

^ permalink raw reply

* USB console and network devices unsupported for boot
From: VomLehn @ 2009-03-27 18:27 UTC (permalink / raw)
  To: Linux Embedded Mailing List; +Cc: Tony Colclough, Andrew Morton

I've been tracking down a problem with kernels 2.6.28 and 2.6.29 and it looks
like there is a race condition with using USB boot devices. Specifically:

o	The console specified with console=ttyUSB0 does not work
o	Using ip=169.254.0.21::169.254.0.21:255.255.0.0:zeus:eth0: does not
	configure eth0.

Both of these issues arise because the required USB devices aren't ready
when the rest of the kernel wants to initialize them and there is no way
to make the initialization wait for the devices. I opened a bug for this
and you can see the discussion of this issue, with alternative approaches, at:

	http://bugzilla.kernel.org/show_bug.cgi?id=12944

but the bottom line is that this is not regarded as a bug.

My question: are USB serial consoles and auto-configured network devices in
common use or is my application a special case? If the former, we need to push
for a better resolution. Otherwise, I'll go off and figure out something that
works for my application.
--
David VomLehn

^ permalink raw reply

* Re: USB console and network devices unsupported for boot
From: Tim Bird @ 2009-03-27 19:12 UTC (permalink / raw)
  To: VomLehn; +Cc: Linux Embedded Mailing List, Tony Colclough, Andrew Morton
In-Reply-To: <20090327182758.GA10454@cuplxvomd02.corp.sa.net>

VomLehn wrote:
> My question: are USB serial consoles and auto-configured network devices in
> common use or is my application a special case? If the former, we need to push
> for a better resolution. Otherwise, I'll go off and figure out something that
> works for my application.

I'd say that they're not uncommon during development, but I
(personally) don't know of any shipped products with either of
these.
 -- Tim

=============================
Tim Bird
Architecture Group Chair, CE Linux Forum
Senior Staff Engineer, Sony Corporation of America
=============================

^ permalink raw reply

* Re: USB console and network devices unsupported for boot
From: VomLehn @ 2009-03-27 19:55 UTC (permalink / raw)
  To: Tim Bird; +Cc: Linux Embedded Mailing List, Tony Colclough, Andrew Morton
In-Reply-To: <49CD2508.10706@am.sony.com>

On Fri, Mar 27, 2009 at 12:12:08PM -0700, Tim Bird wrote:
> VomLehn wrote:
> > My question: are USB serial consoles and auto-configured network devices in
> > common use or is my application a special case? If the former, we need to push
> > for a better resolution. Otherwise, I'll go off and figure out something that
> > works for my application.
> 
> I'd say that they're not uncommon during development, but I
> (personally) don't know of any shipped products with either of
> these.

Good point. This is definitely a question about development phase use of USB.
--
David VomLehn

^ permalink raw reply


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