Skip to contentSkip to conversation

linux-next: comedi: Range_table and range_table_list

PATCH Alexis Berlemont 3 participants 7 messages Apr 26, 2009 – Apr 27, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi,

Please, find attached two patches related with the Comedi layer.

Each patch is a proposal to change the way the ranges tables are managed within the subdevice structure.

As you may know, the range structure allows the translation of freshly acquired logical values into real values (thanks to the unit, the minimal and the maximal value)

An acquisition subdevice can work with various ranges. That is why some tab field is necessary to hold them all in the subdevice descriptor structure. However, what I do not understand is why are there two fields to handle them (and we cannot use both at the same time).

Currently, according to the ranges' type:
- either same ranges for all channels
- or a specific ranges table per channel,
we have to use the field range_table or the field range_table_list.

The range management could be made easier or at least more generic:
- the first proposal introduces a container structure. Thanks to its first field, we could define the range's type for a specific subdevice; and the second field is devoted to store comedi_lrange pointers. Some inline helper functions were added so as to manage the range without having to get through the structures.
- the second patch is the closest one from the original API. An internal structure is added (comedi_trange_struct) so as to handle per channel ranges tables. The internal range management code just has to detect which structure type is hidden behind the subdevice field range_table.

These patches are neither that clean nor perfect, they are just some ideas I would like to share. By the way, these patches modify only the core files (kcomedilib and the drivers have been left unchanged).

Best regards.

Alexis.

Quoted 1 line

From 12b57a9ece86c658fc84db4c635d69d2f7e9638f Mon Sep 17 00:00:00 2001

From: Alexis Berlemont <[email protected]>
Date: Sun, 26 Apr 2009 00:51:43 +0200
Subject: [PATCH] Introduce a container structure for ranges so as to handle global
range tables and per channel range tables

---
 drivers/staging/comedi/comedi_fops.c |   11 +++--
 drivers/staging/comedi/comedidev.h   |   75 +++++++++++++++++++++++++++++++++-
 drivers/staging/comedi/drivers.c     |    5 +-
 drivers/staging/comedi/range.c       |   64 +++++++++++------------------
 4 files changed, 107 insertions(+), 48 deletions(-)
drivers/staging/comedi/comedi_fops.c +7 -4
index bb4a289..c71ddf6 100644
@@ -419,7 +419,7 @@ static int do_subdinfo_ioctl(struct comedi_device *dev, struct comedi_subdinfo *
 		us->maxdata = s->maxdata;
 		if (s->range_table) {
 			us->range_type =
-			    (i << 24) | (0 << 16) | (s->range_table->length);
+			    (i << 24) | (0 << 16) | get_range_table(s, 0)->length;
 		} else {
 			us->range_type = 0;	/* XXX */
 		}
@@ -437,7 +437,8 @@ static int do_subdinfo_ioctl(struct comedi_device *dev, struct comedi_subdinfo *
 			us->subd_flags |= SDF_MAXDATA;
 		if (s->flaglist)
 			us->subd_flags |= SDF_FLAGS;
-		if (s->range_table_list)
+		if (s->range_table && 
+		    (s->range_table->mode & COMEDI_PERCHAN_LRANGE) != 0)
 			us->subd_flags |= SDF_RANGETYPE;
 		if (s->do_cmd)
 			us->subd_flags |= SDF_CMD;
@@ -503,13 +504,15 @@ static int do_chaninfo_ioctl(struct comedi_device *dev, struct comedi_chaninfo *
 	if (it.rangelist) {
 		int i;
 
-		if (!s->range_table_list)
+ 		if(s->range_table == NULL ||
+ 		   (s->range_table->mode & COMEDI_PERCHAN_LRANGE) == 0)
 			return -EINVAL;
+
 		for (i = 0; i < s->n_chan; i++) {
 			int x;
 
 			x = (dev->minor << 28) | (it.subdev << 24) | (i << 16) |
-			    (s->range_table_list[i]->length);
+				get_range_table(s, i)->length;
 			put_user(x, it.rangelist + i);
 		}
 #if 0
drivers/staging/comedi/comedidev.h +73 -2

87 lines not on this page · raw message

drivers/staging/comedi/drivers.c +3 -2
index cabbf09..c0bcff3 100644
@@ -273,8 +273,9 @@ static int postconfig(struct comedi_device *dev)
 			comedi_alloc_subdevice_minor(dev, s);
 		}
 
-		if (!s->range_table && !s->range_table_list)
-			s->range_table = &range_unknown;
+		if (!s->range_table)
+			setup_global_range_table
+				(s, (struct comedi_lrange *)&range_unknown);
 
 		if (!s->insn_read && s->insn_bits)
 			s->insn_read = insn_rw_emulate_bits;
drivers/staging/comedi/range.c +24 -40

75 lines not on this page · raw message

Signature · 1 line
1.6.2.4
Quoted 1 line

From 56980bc984730de6aaa65e14e595a2c8c34f3781 Mon Sep 17 00:00:00 2001

From: Alexis Berlemont <[email protected]>
Date: Sun, 26 Apr 2009 15:50:05 +0200
Subject: [PATCH] Add an internal structure to handle per channel ranges tables.

---
 drivers/staging/comedi/comedi_fops.c |   18 ++++++++---
 drivers/staging/comedi/comedidev.h   |   26 ++++++++++++++++-
 drivers/staging/comedi/drivers.c     |    2 +-
 drivers/staging/comedi/range.c       |   53 ++++++++++++++++++++-------------
 4 files changed, 71 insertions(+), 28 deletions(-)
drivers/staging/comedi/comedi_fops.c +13 -5
index bb4a289..0b9c8e9 100644
@@ -419,7 +419,8 @@ static int do_subdinfo_ioctl(struct comedi_device *dev, struct comedi_subdinfo *
 		us->maxdata = s->maxdata;
 		if (s->range_table) {
 			us->range_type =
-			    (i << 24) | (0 << 16) | (s->range_table->length);
+			    (i << 24) | (0 << 16) | 
+			    (s->range_table->length & ~COMEDI_PERCHAN_LRANGE);
 		} else {
 			us->range_type = 0;	/* XXX */
 		}
@@ -437,7 +438,8 @@ static int do_subdinfo_ioctl(struct comedi_device *dev, struct comedi_subdinfo *
 			us->subd_flags |= SDF_MAXDATA;
 		if (s->flaglist)
 			us->subd_flags |= SDF_FLAGS;
-		if (s->range_table_list)
+		if (s->range_table && 
+		    (s->range_table->length & COMEDI_PERCHAN_LRANGE) != 0)
 			us->subd_flags |= SDF_RANGETYPE;
 		if (s->do_cmd)
 			us->subd_flags |= SDF_CMD;
@@ -503,13 +505,19 @@ static int do_chaninfo_ioctl(struct comedi_device *dev, struct comedi_chaninfo *
 	if (it.rangelist) {
 		int i;
 
-		if (!s->range_table_list)
-			return -EINVAL;
+ 		struct comedi_trange *trng;
+  
+ 		if(s->range_table == NULL ||
+ 		   (s->range_table->length & COMEDI_PERCHAN_LRANGE) == 0)
+  			return -EINVAL;
+ 
+ 		trng = (struct comedi_trange *) s->range_table;
+ 
 		for (i = 0; i < s->n_chan; i++) {
 			int x;
 
 			x = (dev->minor << 28) | (it.subdev << 24) | (i << 16) |
-			    (s->range_table_list[i]->length);
+			    (trng->list[i]->length & ~COMEDI_PERCHAN_LRANGE);
 			put_user(x, it.rangelist + i);
 		}
 #if 0
drivers/staging/comedi/comedidev.h +25 -1
index 753d3ab..cc70048 100644
@@ -150,7 +150,6 @@ struct comedi_subdevice {
 	unsigned int settling_time_0;
 
 	const struct comedi_lrange *range_table;
-	const struct comedi_lrange *const *range_table_list;
 
 	unsigned int *chanlist;	/* driver-owned chanlist (not used) */
 
@@ -406,11 +405,18 @@ extern const struct comedi_lrange range_unknown;
 #define GCC_ZERO_LENGTH_ARRAY 0
 #endif
 
+#define COMEDI_PERCHAN_LRANGE	0x80000000
+
 struct comedi_lrange {
 	int length;
 	struct comedi_krange range[GCC_ZERO_LENGTH_ARRAY];
 };
 
+ struct comedi_trange {
+ 	int length;
+ 	struct comedi_lrange *list[0];
+ };
+
 /* some silly little inline functions */
 
 static inline int alloc_subdevices(struct comedi_device *dev,
@@ -440,6 +446,24 @@ static inline int alloc_private(struct comedi_device *dev, int size)
 	return 0;
 }
 
+static inline int alloc_range_table_list(struct comedi_subdevice * subd)
+{
+	struct comedi_trange * trng = 
+		kmalloc(sizeof(struct comedi_trange) + 
+			subd->n_chan * sizeof(struct comedi_lrange *),
+			GFP_KERNEL);
+	
+	if (trng == NULL)
+		return -ENOMEM;
+
+	memset(trng, 0, sizeof(struct comedi_trange) + 
+	       subd->n_chan * sizeof(struct comedi_lrange *));
+
+	trng->length = COMEDI_PERCHAN_LRANGE | subd->n_chan;
+	
+	return 0;
+}
+
 static inline unsigned int bytes_per_sample(const struct comedi_subdevice *subd)
 {
 	if (subd->subdev_flags & SDF_LSAMPL)
drivers/staging/comedi/drivers.c +1 -1
index cabbf09..f368548 100644
@@ -273,7 +273,7 @@ static int postconfig(struct comedi_device *dev)
 			comedi_alloc_subdevice_minor(dev, s);
 		}
 
-		if (!s->range_table && !s->range_table_list)
+		if (!s->range_table)
 			s->range_table = &range_unknown;
 
 		if (!s->insn_read && s->insn_bits)
drivers/staging/comedi/range.c +32 -21

74 lines not on this page · raw message

Signature · 1 line
1.6.2.4
#1 lore raw
Quoted 3 lines · Alexis Berlemont

Hi,

Please, find attached two patches related with the Comedi layer.

Can you resend this, and cc: the comedi developers at the same time so that they can evaluate your change to the code?

thanks,

greg k-h

#2 lore raw
Quoted 7 lines · On Sun, 26 Apr 2009 19:38:22 -0700 Greg KH <[email protected]> wrote:
Quoted 2 lines · Alexis Berlemont

Please, find attached two patches related with the Comedi layer.

Can you resend this, and cc: the comedi developers at the same time so that they can evaluate your change to the code?

And don't cc linux-next, please.

Signature · 3 lines
Cheers,
Stephen Rothwell                    [email protected]
http://www.canb.auug.org.au/~sfr/
#3 lore raw
In reply to Greg KH

Hi,

Quoted 7 lines · Greg KH
Quoted 3 lines · Alexis Berlemont

Hi,

Please, find attached two patches related with the Comedi layer.

Can you resend this, and cc: the comedi developers at the same time so that they can evaluate your change to the code?

I already did so. As a matter of fact, I reached comedi's mailing list first. Here is the original thread:
http://groups.google.com/group/comedi_list/browse_thread/thread/85be8195ddf52896

Ian Abott told me that the original Comedi CVS tree will not integrate such a code change. He suggested me to redirect my mail to linux-next as the staging area is supposed to host any "cleanup effort".

Alexis.

#4 lore raw

Hi ALexis,

Quoted 4 lines · On Mon, 27 Apr 2009 10:37:43 +0200 Alexis Berlemont…

Ian Abott told me that the original Comedi CVS tree will not integrate such a code change. He suggested me to redirect my mail to linux-next as the staging area is supposed to host any "cleanup effort".

He is mistaken about linux-next: no development work goes on there, just integration testing. All staging tree work needs to be directed to Greg (as this was).

Also, are we going to have problems if the original developers of things in the staging tree are unwilling to take updates back into their trees? Or is this just a procedural thing i.e. do they only want things fed back after they have been in the staging tree? Will this change if their work ends up in the kernel proper?

Signature · 3 lines
Cheers,
Stephen Rothwell                    [email protected]
http://www.canb.auug.org.au/~sfr/
#6 lore raw
In reply to Alexis Berlemont
Quoted 11 lines · Alexis Berlemont

Hi,

Quoted 7 lines · Greg KH
Quoted 3 lines · Alexis Berlemont

Hi,

Please, find attached two patches related with the Comedi layer.

Can you resend this, and cc: the comedi developers at the same time so that they can evaluate your change to the code?

Quoted 7 lines

I already did so. As a matter of fact, I reached comedi's mailing list first. Here is the original thread:
http://groups.google.com/group/comedi_list/browse_thread/thread/85be8195ddf52896

Ian Abott told me that the original Comedi CVS tree will not integrate such a code change. He suggested me to redirect my mail to linux-next as the staging area is supposed to host any "cleanup effort".

Yes, the upstream comedi cvs tree is pretty much "gone" now, as all of the comedi developers are working against the linux-next tree, as you rightly did.

But, the discussion of the development still happens on the comedi mailing list (and cc: me please if you want patches added). Not on the linux-next mailing list, which is only for linux-next specific issues, not general development stuff like this.

Hope this helps clear things up.

thanks,

greg k-h

#5 lore raw
In reply to Stephen Rothwell
Quoted 5 lines · Stephen Rothwell

Also, are we going to have problems if the original developers of things in the staging tree are unwilling to take updates back into their trees? Or is this just a procedural thing i.e. do they only want things fed back after they have been in the staging tree? Will this change if their work ends up in the kernel proper?

The upstream comedi tree should now be "dead" as everything is now fed into mainline and linux-next through staging. So everything should be good.

thanks,

greg k-h