Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 24 Jun 2001 19:30:17 +0200 (MET DST)
From:      j@uriah.heep.sax.de (Joerg Wunsch)
To:        freebsd-current@freebsd.org
Subject:   Re: hints code bugs [Was: orm driver itches...]
Message-ID:  <200106241730.f5OHUHj27111@uriah.heep.sax.de>
References:  <200106211632.f5LGWWV90008@harmony.village.org> <20010621214747.061293808@overcee.netplex.com.au>

next in thread | previous in thread | raw e-mail | index | archive | help
--=-=-=__d4A40WGTWhScgOUopldlWVGGa__=-=-=

Peter Wemm <peter@wemm.org> wrote:

> Definately a bug. :-(  The scanner is effectively concatenating
> the device.hints and the config hints together when enumerating them.

Speaking about bugs in the hints processing:

Triggered by Michael Reifenberger <root@nihil.plaut.de>, i started
experimenting to get fdc(4) working as a KLD.  There are several
resource deallocation things still wrong in it, but i have fixed a
number of them in my private tree (and know about more of them...).

So far, i've encountered two serious problems.  First, when trying to
load the KLD at run-time, it cannot allocate the IO ports for fdc0,
and then registers successfully as fdc1 (but of course without any
drive connected to it since there are none mentioned in the hints for
fdc1).  Michael wrote that loading the KLD by the boot loader works
well, however.  I gdb'ed a little around, and found that the resource
allocator will eventually divert int pci_alloc_resources() when called
on behalf of fdc0.  Naturally, this function doesn't even know how to
handle IO port allocation, thus fails.  When called next time on
behalf of fdc1, the device is however (mis?)detected as PnP, and all
works out well.

Does anybody have an idea why the code would believe fdc0 to be
connected to the PCI bus?  (The hints do say it's located on the ISA
bus, of course.)  Can anybody describe the rough picture how the
`default' IO port allocation (range 0 .. ~0UL) is supposed to work at
all?  I'm a bit confused.

Is it possible to modify the hints at run-time (i. e. before
kldloading the module)?

Second, the driver doesn't deallocate completely.  When calling
devinfo(1) after kldunloading it, i get a panic somewhere in the
depths of kprintf(), where it is trying to print the device
description of fdc1 (where the string dev->descr was pointing to has
been kldunloaded since).  What needs to be done in order to destroy
the device structure completely, and which of those tasks is the
kernel linker supposed to perform?

In case anybody wants to give it a try, i'll append my private patches
collected so far.

-- 
cheers, J"org               .-.-.   --... ...--   -.. .  DL8DTL

http://www.sax.de/~joerg/                        NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)
--=-=-=__d4A40WGTWhScgOUopldlWVGGa__=-=-=
Content-Type: text/plain
Content-Disposition: attachment; filename="fdcdiff"

Index: isa/fd.c
===================================================================
RCS file: /home/ncvs/src/sys/isa/fd.c,v
retrieving revision 1.204
diff -u -u -r1.204 fd.c
--- isa/fd.c	2001/06/20 20:21:55	1.204
+++ isa/fd.c	2001/06/24 17:28:58
@@ -170,6 +170,8 @@
 	struct	callout_handle toffhandle;
 	struct	callout_handle tohandle;
 	struct	devstat device_stats;
+	eventhandler_tag clonetag;
+	dev_t	masterdev;
 	device_t dev;
 	fdu_t	fdu;
 };
@@ -497,7 +499,7 @@
 fdc_alloc_resources(struct fdc_data *fdc)
 {
 	device_t dev;
-	int ispnp, ispcmcia;
+	int ispnp, ispcmcia, nports;
 
 	dev = fdc->fdc_dev;
 	ispnp = (fdc->flags & FDC_ISPNP) != 0;
@@ -516,12 +518,13 @@
 	 * uses the register with offset 6 for pseudo-DMA, and the
 	 * one with offset 7 as control register.
 	 */
+	nports = ispcmcia ? 8 : (ispnp ? 1 : 6);
 	fdc->res_ioport = bus_alloc_resource(dev, SYS_RES_IOPORT,
 					     &fdc->rid_ioport, 0ul, ~0ul, 
-					     ispcmcia ? 8 : (ispnp ? 1 : 6),
-					     RF_ACTIVE);
+					     nports, RF_ACTIVE);
 	if (fdc->res_ioport == 0) {
-		device_printf(dev, "cannot reserve I/O port range\n");
+		device_printf(dev, "cannot reserve I/O port range (%d ports)\n",
+			      nports);
 		return ENXIO;
 	}
 	fdc->portt = rman_get_bustag(fdc->res_ioport);
@@ -569,7 +572,7 @@
 						  0ul, ~0ul, 1, RF_ACTIVE);
 		if (fdc->res_ctl == 0) {
 			device_printf(dev,
-				      "cannot reserve control I/O port range\n");
+		"cannot reserve control I/O port range (control port)\n");
 			return ENXIO;
 		}
 		fdc->ctlt = rman_get_bustag(fdc->res_ctl);
@@ -760,8 +763,10 @@
 	return (error);
 }
 
+#endif /* NCARD > 0 */
+
 static int
-fdc_pccard_detach(device_t dev)
+fdc_detach(device_t dev)
 {
 	struct	fdc_data *fdc;
 	int	error;
@@ -772,6 +777,12 @@
 	if ((error = bus_generic_detach(dev)))
 		return (error);
 
+	/* reset controller, turn motor off */
+	fdout_wr(fdc, 0);
+
+	if ((fdc->flags & FDC_NODMA) == 0)
+		isa_dma_release(fdc->dmachan);
+
 	if ((fdc->flags & FDC_ATTACHED) == 0) {
 		device_printf(dev, "already unloaded\n");
 		return (0);
@@ -785,8 +796,6 @@
 	return (0);
 }
 
-#endif /* NCARD > 0 */
-
 /*
  * Add a child device to the fdc controller.  It will then be probed etc.
  */
@@ -877,7 +886,7 @@
 	/* Device interface */
 	DEVMETHOD(device_probe,		fdc_probe),
 	DEVMETHOD(device_attach,	fdc_attach),
-	DEVMETHOD(device_detach,	bus_generic_detach),
+	DEVMETHOD(device_detach,	fdc_detach),
 	DEVMETHOD(device_shutdown,	bus_generic_shutdown),
 	DEVMETHOD(device_suspend,	bus_generic_suspend),
 	DEVMETHOD(device_resume,	bus_generic_resume),
@@ -904,7 +913,7 @@
 	/* Device interface */
 	DEVMETHOD(device_probe,		fdc_pccard_probe),
 	DEVMETHOD(device_attach,	fdc_attach),
-	DEVMETHOD(device_detach,	fdc_pccard_detach),
+	DEVMETHOD(device_detach,	fdc_detach),
 	DEVMETHOD(device_shutdown,	bus_generic_shutdown),
 	DEVMETHOD(device_suspend,	bus_generic_suspend),
 	DEVMETHOD(device_resume,	bus_generic_resume),
@@ -1138,9 +1147,9 @@
 		cdevsw_add(&fd_cdevsw);	/* XXX */
 		cdevsw_add_done++;
 	}
-	EVENTHANDLER_REGISTER(dev_clone, fd_clone, 0, 1000);
-	make_dev(&fd_cdevsw, (fd->fdu << 6),
-		UID_ROOT, GID_OPERATOR, 0640, "fd%d", fd->fdu);
+	fd->clonetag = EVENTHANDLER_REGISTER(dev_clone, fd_clone, 0, 1000);
+	fd->masterdev = make_dev(&fd_cdevsw, (fd->fdu << 6),
+				 UID_ROOT, GID_OPERATOR, 0640, "fd%d", fd->fdu);
 
 	/*
 	 * Export the drive to the devstat interface.
@@ -1158,6 +1167,10 @@
 	struct	fd_data *fd;
 
 	fd = device_get_softc(dev);
+	devstat_remove_entry(&fd->device_stats);
+	destroy_dev(fd->masterdev);
+	/* XXX need to destroy cloned devs as well */
+	EVENTHANDLER_DEREGISTER(dev_clone, fd->clonetag);
 	untimeout(fd_turnoff, fd, fd->toffhandle);
 
 	return (0);
Index: modules/Makefile
===================================================================
RCS file: /home/ncvs/src/sys/modules/Makefile,v
retrieving revision 1.186
diff -u -u -r1.186 Makefile
--- modules/Makefile	2001/06/14 15:15:54	1.186
+++ modules/Makefile	2001/06/19 21:47:36
@@ -7,7 +7,7 @@
 .endif
 
 SUBDIR=	3dfx accf_data accf_http agp aha amr an aue \
-	cam ccd cd9660 coda cue dc de dgm digi ed fdescfs fs fxp if_disc if_ef \
+	cam ccd cd9660 coda cue dc de dgm digi ed fdc fdescfs fs fxp if_disc if_ef \
 	if_ppp if_sl if_tap if_tun ip6fw ipfilter ipfw ispfw joy kue lge \
 	libmchain linux lnc md mii mlx msdosfs ncp netgraph nfs nge ntfs \
 	nullfs nwfs pcn portalfs procfs ${_random}  \
--- /dev/null	Sun Jun 24 19:19:47 2001
+++ modules/fdc/Makefile	Tue Jun 19 23:44:45 2001
@@ -0,0 +1,28 @@
+# $FreeBSD$
+
+.PATH:  ${.CURDIR}/../../isa
+
+KMOD=	fdc
+SRCS=	fd.c \
+	opt_fdc.h card.h \
+	bus_if.h card_if.h device_if.h isa_if.h
+NOMAN=
+
+FDC_DEBUG=	1	# 0/1
+FDC_PCCARD=	0	# 0/1  whether pccard support (i. e. Y-E DATA PCMCIA fdc) is desired
+
+CLEANFILES=	card.h
+
+opt_fdc.h:
+	touch ${.TARGET}
+.if ${FDC_DEBUG} > 0
+	echo "#define FDC_DEBUG 1" >> ${.TARGET}
+.endif
+
+card.h:
+	touch ${.TARGET}
+.if ${FDC_PCCARD} > 0
+	echo "#define NCARD 1" >> ${.TARGET}
+.endif
+
+.include <bsd.kmod.mk>
--=-=-=__d4A40WGTWhScgOUopldlWVGGa__=-=-=--

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




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