Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 25 Jan 2000 05:42:29 +0900
From:      Mitsuru IWASAKI <iwasaki@jp.FreeBSD.org>
To:        mobile@freebsd.org
Subject:   pccardd patch [Auto select config index]
Message-ID:  <200001242042.FAA02072@tasogare.imasy.or.jp>

next in thread | raw e-mail | index | archive | help
Hi,

Attached patch allow you to specify config index something like
	config auto "sio3" ?
or 
	config default "ed0" ?
in your pccard.conf like PAO configuration.

There are a lot of sio (sio1, 2, 3, 4 are mixed) entries in
pccard.conf.sample, but it seems we don't have guidelines for new
entry registration.  Once we get guideline, we just rewrite
pccard.conf.sample. But it is not easy to survey again to get suitable
config index for many cards...

Then I made following patch, we don't need to survey again, just put 
`auto' as config index and "sio3" (or sio4) as driver name in usual cases.

Specifying `auto', pccardd try to find cis_config entry which have
available i/o port dynamically.

Would this be one of the 4.0-RELEASE candidates?

Index: cardd.c
===================================================================
RCS file: /home/ncvs/src/usr.sbin/pccard/pccardd/cardd.c,v
retrieving revision 1.45
diff -u -r1.45 cardd.c
--- cardd.c	2000/01/24 13:15:05	1.45
+++ cardd.c	2000/01/24 20:00:19
@@ -60,9 +60,21 @@
 	for (cp = cards; cp; cp = cp->next) {
 		printf("Card manuf %s, vers %s\n", cp->manuf, cp->version);
 		printf("Configuration entries:\n");
-		for (confp = cp->config; confp; confp = confp->next)
-			printf("\tIndex code = 0x%x, driver name = %s\n",
-			    confp->index, confp->driver->name);
+		for (confp = cp->config; confp; confp = confp->next) {
+			printf("\tIndex code = ");
+			switch (confp->index_type) {
+			case DEFAULT_INDEX:
+				printf("default");
+				break;
+			case AUTO_INDEX:
+				printf("auto");
+				break;
+			default:
+				printf("0x%x", confp->index);
+				break;
+			}
+			printf(", driver name = %s\n", confp->driver->name);
+		}
 		if (cp->insert) {
 			printf("Insert commands are:\n");
 			pr_cmd(cp->insert);
@@ -392,6 +404,30 @@
 }
 
 /*
+ *	Auto select config index
+ */
+static struct cis_config *
+assign_card_index(struct cis * cis)
+{
+	struct cis_config *cp;
+	struct cis_ioblk *cio;
+	int i;
+
+	for (cp = cis->conf; cp; cp = cp->next) {
+		if (!cp->iospace || !cp->io)
+			continue;
+		for (cio = cp->io; cio; cio = cio->next) {
+			for (i = cio->addr; i < cio->addr + cio->size - 1; i++)
+				if (!bit_test(io_avail, i))
+					goto next;
+		}
+		return cp;	/* found */
+	next:
+	}
+	return cis->def_config;
+}
+
+/*
  *	assign_io - Allocate resources to slot matching the
  *	configuration index selected.
  */
@@ -403,9 +439,21 @@
 
 	cis = sp->cis;
 	defconf = cis->def_config;
-	for (cisconf = cis->conf; cisconf; cisconf = cisconf->next)
-		if (cisconf->id == sp->config->index)
-			break;
+	switch (sp->config->index_type) {
+	case DEFAULT_INDEX:	/* default */
+		cisconf = defconf;
+		sp->config->index = cisconf->id;
+		break;
+	case AUTO_INDEX:	/* auto */
+		cisconf = assign_card_index(cis);
+		sp->config->index = cisconf->id;
+		break;
+	default:		/* normal, use index value */
+		for (cisconf = cis->conf; cisconf; cisconf = cisconf->next)
+			if (cisconf->id == sp->config->index)
+				break;
+	}
+
 	if (cisconf == 0) {
 		logmsg("Config id %d not present in this card",
 		    sp->config->index);
Index: cardd.h
===================================================================
RCS file: /home/ncvs/src/usr.sbin/pccard/pccardd/cardd.h,v
retrieving revision 1.17
diff -u -r1.17 cardd.h
--- cardd.h	2000/01/21 09:12:00	1.17
+++ cardd.h	2000/01/24 19:52:50
@@ -46,6 +46,7 @@
 
 struct card_config {
 	struct card_config *next;
+	unsigned char index_type;
 	unsigned char index;
 	struct driver *driver;
 	int     irq;
@@ -172,3 +173,11 @@
 #define	BIT2MEM(x) (((x)*MEMUNIT)+MEMSTART)
 
 #define MAXINCLUDES	10
+
+/*
+ * Config index types
+ */
+#define NORMAL_INDEX	0
+#define DEFAULT_INDEX	1
+#define AUTO_INDEX	2
+
Index: file.c
===================================================================
RCS file: /home/ncvs/src/usr.sbin/pccard/pccardd/file.c,v
retrieving revision 1.23
diff -u -r1.23 file.c
--- file.c	2000/01/21 09:12:00	1.23
+++ file.c	2000/01/24 20:05:35
@@ -87,6 +87,7 @@
 static void    error(char *);
 static int     keyword(char *);
 static int     irq_tok(int);
+static int     config_tok(unsigned char *);
 static int     debuglevel_tok(int);
 static struct allocblk *ioblk_tok(int);
 static struct allocblk *memblk_tok(int);
@@ -214,6 +215,7 @@
 parse_card(void)
 {
 	char   *man, *vers, *tmp;
+	unsigned char index_type;
 	struct card *cp;
 	int     i, iosize;
 	struct card_config *confp, *lastp;
@@ -232,7 +234,7 @@
 		switch (keyword(next_tok())) {
 		case KWD_CONFIG:
 			/* config */
-			i = num_tok();
+			i = config_tok(&index_type);
 			if (i == -1) {
 				error("illegal card config index");
 				break;
@@ -251,6 +253,7 @@
 				break;
 			}
 			confp->index = i & 0x3F;
+			confp->index_type = index_type;
 
 			/*
 			 * If no valid driver for this config, then do not save
@@ -437,6 +440,26 @@
 	if (force)
 		error("illegal IRQ value");
 	return (-1);
+}
+
+/*
+ *	Config index token
+ */
+static int
+config_tok(unsigned char *index_type)
+{
+	if (strcmp("default", next_tok()) == 0)	{
+		*index_type = DEFAULT_INDEX;
+		return 0;
+	}
+	pusht = 1;
+	if (strcmp("auto", next_tok()) == 0) {
+		*index_type = AUTO_INDEX;
+		return 0;
+	}
+	pusht = 1;
+	*index_type = NORMAL_INDEX;
+	return num_tok();
 }
 
 /*


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-mobile" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200001242042.FAA02072>