public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH/RFC] SPI core: turn transfers to be linked list
@ 2005-12-17 21:18 Vitaly Wool
  2005-12-18 20:40 ` David Brownell
  0 siblings, 1 reply; 11+ messages in thread
From: Vitaly Wool @ 2005-12-17 21:18 UTC (permalink / raw)
  To: David Brownell; +Cc: linux-kernel, Greg KH

[-- 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);
 }
 

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

end of thread, other threads:[~2005-12-23  0:19 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-12-17 21:18 [PATCH/RFC] SPI core: turn transfers to be linked list Vitaly Wool
2005-12-18 20:40 ` 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

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