Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 22 Dec 2002 11:12:41 -0800 (PST)
From:      Marcel Moolenaar <marcel@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 22623 for review
Message-ID:  <200212221912.gBMJCf5i009504@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=22623

Change 22623 by marcel@marcel_nfs on 2002/12/22 11:11:43

	Convert to the new sioprobe/sioattach interface. While here,
	remove the sio_pci_unit_kludge function. We consider this the
	"future" version which according to the comment makes it
	obsolete :-)

Affected files ...

.. //depot/projects/ia64/sys/dev/sio/sio_pci.c#10 edit

Differences ...

==== //depot/projects/ia64/sys/dev/sio/sio_pci.c#10 (text+ko) ====

@@ -33,16 +33,19 @@
 #include <sys/malloc.h>
 #include <sys/mutex.h>
 #include <sys/module.h>
+#include <sys/timepps.h>
 #include <sys/tty.h>
+
 #include <machine/bus.h>
-#include <sys/timepps.h>
+#include <machine/resource.h>
+
+#include <sys/rman.h>
 
 #include <dev/sio/siovar.h>
 
 #include <pci/pcivar.h>
 
 static	int	sio_pci_attach(device_t dev);
-static	void	sio_pci_kludge_unit(device_t dev);
 static	int	sio_pci_probe(device_t dev);
 
 static device_method_t sio_pci_methods[] = {
@@ -56,7 +59,7 @@
 static driver_t sio_pci_driver = {
 	sio_driver_name,
 	sio_pci_methods,
-	0,
+	sizeof(struct com_s),
 };
 
 struct pci_ids {
@@ -80,70 +83,66 @@
 	{ 0x00000000, NULL, 0 }
 };
 
-static int
-sio_pci_attach(dev)
-	device_t	dev;
+static struct pci_ids *
+pci_id(device_t dev)
 {
-	u_int32_t	type;
-	struct pci_ids	*id;
+	struct pci_ids *id;
+	u_int32_t type;
 
 	type = pci_get_devid(dev);
 	id = pci_ids;
 	while (id->type && id->type != type)
 		id++;
-	if (id->desc == NULL)
-		return (ENXIO);
-	sio_pci_kludge_unit(dev);
-	return (sioattach(dev, id->rid, 0UL));
+	return ((id->desc != NULL) ? id : NULL);
 }
 
-/*
- * Don't cut and paste this to other drivers.  It is a horrible kludge
- * which will fail to work and also be unnecessary in future versions.
- */
-static void
-sio_pci_kludge_unit(dev)
-	device_t dev;
+static int
+sio_pci_attach(device_t dev)
 {
-	devclass_t	dc;
-	int		err;
-	int		start;
-	int		unit;
+	struct com_s *com;
+	struct pci_ids *id;
+	struct resource *res;
+	int error, rid, space;
 
-	unit = 0;
-	start = 0;
-	while (resource_int_value("sio", unit, "port", &start) == 0 && 
-	    start > 0)
-		unit++;
-	if (device_get_unit(dev) < unit) {
-		dc = device_get_devclass(dev);
-		while (devclass_get_device(dc, unit))
-			unit++;
-		device_printf(dev, "moving to sio%d\n", unit);
-		err = device_set_unit(dev, unit);	/* EVIL DO NOT COPY */
-		if (err)
-			device_printf(dev, "error moving device %d\n", err);
-	}
+	com = device_get_softc(dev);
+	id = pci_id(dev);
+	rid = (id->rid >= 0) ? id->rid : -id->rid;
+	space = (id->rid >= 0) ? SYS_RES_IOPORT : SYS_RES_MEMORY;
+	res = bus_alloc_resource(dev, space, &rid, 0, ~0, 8, RF_ACTIVE);
+	com->bsh = rman_get_bushandle(res);
+	com->bst = rman_get_bustag(res);
+	error = sioattach(dev);
+	if (error)
+		bus_release_resource(dev, space, rid, res);
+	return (error);
 }
 
 static int
-sio_pci_probe(dev)
-	device_t	dev;
+sio_pci_probe(device_t dev)
 {
-	u_int32_t	type;
-	struct pci_ids	*id;
+	struct com_s *com;
+	struct pci_ids *id;
+	struct resource *res;
+	int error, rid, space;
 
-	type = pci_get_devid(dev);
-	id = pci_ids;
-	while (id->type && id->type != type)
-		id++;
-	if (id->desc == NULL)
+	com = device_get_softc(dev);
+	id = pci_id(dev);
+	if (id == NULL)
 		return (ENXIO);
 	device_set_desc(dev, id->desc);
+	rid = (id->rid >= 0) ? id->rid : -id->rid;
+	space = (id->rid >= 0) ? SYS_RES_IOPORT : SYS_RES_MEMORY;
+	res = bus_alloc_resource(dev, space, &rid, 0, ~0, 8, RF_ACTIVE);
+	com->bsh = rman_get_bushandle(res);
+	com->bst = rman_get_bustag(res);
+
 #ifdef PC98
 	SET_FLAG(dev, SET_IFTYPE(COM_IF_NS16550));
 #endif
-	return (sioprobe(dev, id->rid, 0UL, 1));
+
+	error = sioprobe(dev);
+	bus_release_resource(dev, space, rid, res);
+	return (error);
 }
 
 DRIVER_MODULE(sio, pci, sio_pci_driver, sio_devclass, 0, 0);

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




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