public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Vitaly Wool <vwool@ru.mvista.com>
To: David Brownell <david-b@pacbell.net>
Cc: linux-kernel@vger.kernel.org, Greg KH <greg@kroah.com>
Subject: [PATCH/RFC] SPI core: turn transfers to be linked list
Date: Sun, 18 Dec 2005 00:18:56 +0300	[thread overview]
Message-ID: <43A480C0.9080201@ru.mvista.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 690 bytes --]

Greetings,

the patch attached changes the way transfers are chained in the SPI 
core. Namely, they are turned into linked lists instead of array. The 
reason behind is that we'd like to be able to use lightweight memory 
allocation  mechanism to use it in interrupt context. An example of such 
kind of mechanism can be found in spi-alloc.c file in our core. The 
lightweightness is achieved by the knowledge that all the blocks to be 
allocated are of the same size. We'd like to use this allocation 
technique for both message structure and transfer structure The problem 
with the current code is that transfers are represnted as an array so it 
can be of any size effectively.

Vitaly

[-- Attachment #2: spi-list.patch --]
[-- Type: text/plain, Size: 2350 bytes --]

diff -uNr a/drivers/spi/spi.c b/drivers/spi/spi.c
--- a/drivers/spi/spi.c	2005-12-17 22:13:13.947792000 +0300
+++ b/drivers/spi/spi.c	2005-12-17 22:29:07.283863088 +0300
@@ -535,7 +535,9 @@
 	static DECLARE_MUTEX(lock);
 
 	int			status;
-	struct spi_message	message;
+	struct spi_message	message = {
+		.transfers = LIST_HEAD_INIT(message.transfers);
+	};
 	struct spi_transfer	x[2];
 
 	/* Use preallocated DMA-safe buffer.  We can't avoid copying here,
@@ -551,13 +553,13 @@
 	memcpy(buf, txbuf, n_tx);
 	x[0].tx_buf = buf;
 	x[0].len = n_tx;
+	list_add_tail(&x[0].link, &message.transfers);
 
 	x[1].rx_buf = buf + n_tx;
 	x[1].len = n_rx;
+	list_add_tail(&x[1].link, &message.transfers);
 
 	/* do the i/o */
-	message.transfers = x;
-	message.n_transfer = ARRAY_SIZE(x);
 	status = spi_sync(spi, &message);
 	if (status == 0) {
 		memcpy(rxbuf, x[1].rx_buf, n_rx);
diff -uNr a/include/linux/spi/spi.h b/include/linux/spi/spi.h
--- a/include/linux/spi/spi.h	2005-12-17 22:13:13.957790000 +0300
+++ b/include/linux/spi/spi.h	2005-12-17 23:39:32.304562312 +0300
@@ -286,6 +286,8 @@
 
 	unsigned	cs_change:1;
 	u16		delay_usecs;
+
+	struct list_head link;
 };
 
 /**
@@ -304,8 +306,7 @@
  * @state: for use by whichever driver currently owns the message
  */
 struct spi_message {
-	struct spi_transfer	*transfers;
-	unsigned		n_transfer;
+	struct list_head	transfers;
 
 	struct spi_device	*spi;
 
@@ -406,16 +407,16 @@
 spi_write(struct spi_device *spi, const u8 *buf, size_t len)
 {
 	struct spi_transfer	t = {
-			.tx_buf		= buf,
-			.rx_buf		= NULL,
-			.len		= len,
-			.cs_change	= 0,
-		};
+		.tx_buf		= buf,
+		.rx_buf		= NULL,
+		.len		= len,
+		.cs_change	= 0,
+	};
 	struct spi_message	m = {
-			.transfers	= &t,
-			.n_transfer	= 1,
-		};
+		.transfers = LIST_HEAD_INIT(m.transfers);
+	};
 
+	list_add_tail(&t.link, &m.transfers);
 	return spi_sync(spi, &m);
 }
 
@@ -432,16 +433,16 @@
 spi_read(struct spi_device *spi, u8 *buf, size_t len)
 {
 	struct spi_transfer	t = {
-			.tx_buf		= NULL,
-			.rx_buf		= buf,
-			.len		= len,
-			.cs_change	= 0,
-		};
+		.tx_buf		= NULL,
+		.rx_buf		= buf,
+		.len		= len,
+		.cs_change	= 0,
+	};
 	struct spi_message	m = {
-			.transfers	= &t,
-			.n_transfer	= 1,
-		};
+		.transfers = LIST_HEAD_INIT(m.transfers);
+	};
 
+	list_add_tail(&t.link, &m.transfers);
 	return spi_sync(spi, &m);
 }
 

             reply	other threads:[~2005-12-17 21:19 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-12-17 21:18 Vitaly Wool [this message]
2005-12-18 20:40 ` [PATCH/RFC] SPI core: turn transfers to be linked list David Brownell
2005-12-19  7:49   ` Vitaly Wool
2005-12-19 17:00     ` Greg KH
2005-12-19 20:03       ` Vitaly Wool
2005-12-20  8:11     ` David Brownell
2005-12-20 18:15       ` Vitaly Wool
2005-12-21 13:22       ` Vitaly Wool
2005-12-22 17:55         ` David Brownell
2005-12-22 22:12           ` Vitaly Wool
2005-12-22 23:57             ` David Brownell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=43A480C0.9080201@ru.mvista.com \
    --to=vwool@ru.mvista.com \
    --cc=david-b@pacbell.net \
    --cc=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox