Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 17 Apr 2003 17:08:26 -0700 (PDT)
From:      Doug Ambrisko <ambrisko@ambrisko.com>
To:        current@freebsd.org
Subject:   Getting ready to comit ppc(4) support for puc(4)
Message-ID:  <200304180008.h3I08QoH092576@www.ambrisko.com>

next in thread | raw e-mail | index | archive | help
I've done some patches to add ppc(4) support for puc(4) so you can
use a printer port on the combo serial & parallel port PCI cards on
FreeBSD.

Issues, should ppc be moved into /sys/dev/ppc, /sys/dev/ppbus or left
in /sys/isa?  I've added a ppc_puc.c. file to handle the puc attachment.
We could take things and fan them out in the generic ppc.c and then
have ppc_isa.c & ppc_puc.c for attachments to buses.  If we move it
then I would need help with moving them.  I not sure it should go
in ppbus but I don't see a problem with that.  It probably should
move so that other arch's can use it more easily.

The next issue is that it bumps the existing onboard port to the device
ie ppc1 from ppc0 for example.  Now we could make the isa on if configures
ppc0 but this doesn't buy us anything since is ends up doing
	ppcX -> ppbusY -> lptZ
		       -> plipZ
		       -> ppiZ
etc.  So it would seem like a lot of hacking to make the ordering
work right since it would have to be pushed through the devices
attached to ppc.  Really the ppcX numbering doesn't matter since people
don't use that but rather some attachment to ppbus etc.

Anyhow here is the patch relative to sys.  It fixes a bug in puc(4)
in which is assumes all children that need to register and interrupt
is the child of puc and not a child of a child etc.  So we need to
run up the tree to find puc's child that had the rle that we need.

Thanks,

Doug A.

Index: conf/files.i386
===================================================================
RCS file: /cvs/src/sys/conf/files.i386,v
retrieving revision 1.442
diff -u -r1.442 files.i386
--- conf/files.i386	12 Apr 2003 08:34:40 -0000	1.442
+++ conf/files.i386	17 Apr 2003 23:53:55 -0000
@@ -403,6 +403,7 @@
 isa/atkbdc_isa.c		optional	atkbdc
 isa/fd.c			optional	fdc
 isa/ppc.c			optional	ppc
+isa/ppc_puc.c			optional	ppc puc pci
 isa/psm.c			optional	psm
 isa/syscons_isa.c		optional	sc
 isa/vga_isa.c			optional	vga
Index: isa/ppc.c
===================================================================
RCS file: /cvs/src/sys/isa/ppc.c,v
retrieving revision 1.38
diff -u -r1.38 ppc.c
--- isa/ppc.c	2 Mar 2003 16:54:37 -0000	1.38
+++ isa/ppc.c	17 Apr 2003 23:53:55 -0000
@@ -50,41 +50,26 @@
 #include <dev/ppbus/ppbconf.h>
 #include <dev/ppbus/ppb_msq.h>
 
+#include <isa/ppcvar.h>
 #include <isa/ppcreg.h>
 
 #include "ppbus_if.h"
 
-#define LOG_PPC(function, ppc, string) \
-		if (bootverbose) printf("%s: %s\n", function, string)
-
+static int ppc_isa_probe(device_t dev);
 
-#define DEVTOSOFTC(dev) ((struct ppc_data *)device_get_softc(dev))
-  
-devclass_t ppc_devclass;
-
-static int ppc_probe(device_t dev);
-static int ppc_attach(device_t dev);
-static int ppc_read_ivar(device_t bus, device_t dev, int index, uintptr_t *val);
-
-static void ppc_reset_epp(device_t);
-static void ppc_ecp_sync(device_t);
 static void ppcintr(void *arg);
 
-static int ppc_exec_microseq(device_t, struct ppb_microseq **);
-static int ppc_setmode(device_t, int);
-
-static int ppc_read(device_t, char *, int, int);
-static int ppc_write(device_t, char *, int, int);
+#define LOG_PPC(function, ppc, string) \
+		if (bootverbose) printf("%s: %s\n", function, string)
 
-static u_char ppc_io(device_t, int, u_char *, int, u_char);
 
-static int ppc_setup_intr(device_t, device_t, struct resource *, int,
-		void (*)(void *), void *, void **);
-static int ppc_teardown_intr(device_t, device_t, struct resource *, void *);
+#define DEVTOSOFTC(dev) ((struct ppc_data *)device_get_softc(dev))
 
+devclass_t ppc_devclass;
+  
 static device_method_t ppc_methods[] = {
 	/* device interface */
-	DEVMETHOD(device_probe,         ppc_probe),
+	DEVMETHOD(device_probe,         ppc_isa_probe),
 	DEVMETHOD(device_attach,        ppc_attach),
 
 	/* bus interface */
@@ -110,7 +95,7 @@
 	ppc_methods,
 	sizeof(struct ppc_data),
 };
-  
+
 static char *ppc_models[] = {
 	"SMC-like", "SMC FDC37C665GT", "SMC FDC37C666GT", "PC87332", "PC87306",
 	"82091AA", "Generic", "W83877F", "W83877AF", "Winbond", "PC87334",
@@ -149,7 +134,7 @@
 /*
  * ppc_ecp_sync()		XXX
  */
-static void
+void
 ppc_ecp_sync(device_t dev) {
 
 	int i, r;
@@ -1339,7 +1324,7 @@
  * Execute a microsequence.
  * Microsequence mechanism is supposed to handle fast I/O operations.
  */
-static int
+int
 ppc_exec_microseq(device_t dev, struct ppb_microseq **p_msq)
 {
 	struct ppc_data *ppc = DEVTOSOFTC(dev);
@@ -1626,7 +1611,7 @@
 	return;
 }
 
-static int
+int
 ppc_read(device_t dev, char *buf, int len, int mode)
 {
 	return (EINVAL);
@@ -1639,7 +1624,7 @@
  * If what you want is not possible (no ECP, no DMA...),
  * EINVAL is returned
  */
-static int
+int
 ppc_write(device_t dev, char *buf, int len, int how)
 {
 	struct ppc_data *ppc = DEVTOSOFTC(dev);
@@ -1791,7 +1776,7 @@
 	return (error);
 }
 
-static void
+void
 ppc_reset_epp(device_t dev)
 {
 	struct ppc_data *ppc = DEVTOSOFTC(dev);
@@ -1801,7 +1786,7 @@
 	return;
 }
 
-static int
+int
 ppc_setmode(device_t dev, int mode)
 {
 	struct ppc_data *ppc = DEVTOSOFTC(dev);
@@ -1828,15 +1813,10 @@
 };
 
 static int
-ppc_probe(device_t dev)
+ppc_isa_probe(device_t dev)
 {
-#ifdef __i386__
-	static short next_bios_ppc = 0;
-#endif
-	struct ppc_data *ppc;
 	device_t parent;
 	int error;
-	u_long port;
 
 	parent = device_get_parent(dev);
 
@@ -1846,6 +1826,19 @@
 	else if (error != 0)	/* XXX shall be set after detection */
 		device_set_desc(dev, "Parallel port");
 
+	return(ppc_probe(dev));
+}
+		
+int
+ppc_probe(device_t dev)
+{
+#ifdef __i386__
+	static short next_bios_ppc = 0;
+#endif
+	struct ppc_data *ppc;
+	int error;
+	u_long port;
+
 	/*
 	 * Allocate the ppc_data structure.
 	 */
@@ -1967,7 +1960,7 @@
 	return (ENXIO);
 }
 
-static int
+int
 ppc_attach(device_t dev)
 {
 	struct ppc_data *ppc = DEVTOSOFTC(dev);
@@ -2012,7 +2005,7 @@
 	return (0);
 }
 
-static u_char
+u_char
 ppc_io(device_t ppcdev, int iop, u_char *addr, int cnt, u_char byte)
 {
 	struct ppc_data *ppc = DEVTOSOFTC(ppcdev);
@@ -2085,7 +2078,7 @@
 	return (0);	/* not significative */
 }
 
-static int
+int
 ppc_read_ivar(device_t bus, device_t dev, int index, uintptr_t *val)
 {
 	struct ppc_data *ppc = (struct ppc_data *)device_get_softc(bus);
@@ -2108,7 +2101,7 @@
  * Resource is useless here since ppbus devices' interrupt handlers are
  * multiplexed to the same resource initially allocated by ppc
  */
-static int
+int
 ppc_setup_intr(device_t bus, device_t child, struct resource *r, int flags,
 			void (*ihand)(void *), void *arg, void **cookiep)
 {
@@ -2139,7 +2132,7 @@
  * When no underlying device has a registered interrupt, register the ppc
  * layer one
  */
-static int
+int
 ppc_teardown_intr(device_t bus, device_t child, struct resource *r, void *ih)
 {
 	int error;
Index: dev/puc/puc.c
===================================================================
RCS file: /cvs/src/sys/dev/puc/puc.c,v
retrieving revision 1.22
diff -u -r1.22 puc.c
--- dev/puc/puc.c	15 Mar 2003 16:25:40 -0000	1.22
+++ dev/puc/puc.c	17 Apr 2003 23:53:55 -0000
@@ -256,6 +256,9 @@
 		case PUC_PORT_TYPE_COM:
 			typestr = "sio";
 			break;
+		case PUC_PORT_TYPE_LPT:
+			typestr = "ppc";
+			break;
 		default:
 			continue;
 		}
@@ -304,6 +307,7 @@
 		pdev->serialfreq = sc->sc_desc->ports[i].serialfreq;
 
 		childunit = puc_find_free_unit(typestr);
+
 		sc->sc_ports[i].dev = device_add_child(dev, typestr, childunit);
 		if (sc->sc_ports[i].dev == NULL) {
 			if (sc->barmuxed) {
@@ -457,8 +461,15 @@
 	struct resource *retval;
 	struct resource_list *rl;
 	struct resource_list_entry *rle;
+	device_t my_child;
+
+	/* 
+	 * in the case of a child of child we need to find our immediate child
+	 */
+	for (my_child = child; device_get_parent(my_child) != dev; 
+	     my_child = device_get_parent(my_child));
 
-	pdev = device_get_ivars(child);
+	pdev = device_get_ivars(my_child);
 	rl = &pdev->resources;
 
 #ifdef PUC_DEBUG
@@ -476,8 +487,11 @@
 		printf("found rle, %lx, %lx, %lx\n", start, end, count);
 #endif
 		retval = rle->res;
-	} else
+	} 
+#ifdef PUC_DEBUG
+	else
 		printf("oops rle is gone\n");
+#endif
 
 	return (retval);
 }
--- /dev/null	Thu Apr 17 16:45:10 2003
+++ isa/ppc_puc.c	Thu Apr 17 09:56:02 2003
@@ -0,0 +1,83 @@
+/*-
+ * Copyright (c) 1997-2000 Nicolas Souchu
+ * Copyright (c) 2001 Alcove - Nicolas Souchu
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ *
+ */
+
+#include <sys/param.h>
+#include <sys/kernel.h>
+#include <sys/bus.h>
+  
+#include <machine/bus.h>
+
+#include <dev/ppbus/ppbconf.h>
+#include <dev/ppbus/ppb_msq.h>
+#include <isa/ppcvar.h>
+#include <isa/ppcreg.h>
+
+#include "ppbus_if.h"
+
+static int ppc_puc_probe(device_t dev);
+
+static device_method_t ppc_puc_methods[] = {
+	/* device interface */
+	DEVMETHOD(device_probe,         ppc_puc_probe),
+	DEVMETHOD(device_attach,        ppc_attach),
+
+	/* bus interface */
+	DEVMETHOD(bus_read_ivar,	ppc_read_ivar),
+	DEVMETHOD(bus_setup_intr,	ppc_setup_intr),
+	DEVMETHOD(bus_teardown_intr,	ppc_teardown_intr),
+	DEVMETHOD(bus_alloc_resource,   bus_generic_alloc_resource),
+
+	/* ppbus interface */
+	DEVMETHOD(ppbus_io,		ppc_io),
+	DEVMETHOD(ppbus_exec_microseq,	ppc_exec_microseq),
+	DEVMETHOD(ppbus_reset_epp,	ppc_reset_epp),
+	DEVMETHOD(ppbus_setmode,	ppc_setmode),
+	DEVMETHOD(ppbus_ecp_sync,	ppc_ecp_sync),
+	DEVMETHOD(ppbus_read,		ppc_read),
+	DEVMETHOD(ppbus_write,		ppc_write),
+
+        { 0, 0 }
+  };
+  
+static driver_t ppc_puc_driver = {
+	"ppc",
+	ppc_puc_methods,
+	sizeof(struct ppc_data),
+};
+
+static int
+ppc_puc_probe(dev)
+	device_t	dev;
+{
+	device_set_desc(dev, "Parallel port");
+	return (ppc_probe(dev));
+}
+
+DRIVER_MODULE(ppc, puc, ppc_puc_driver, ppc_devclass, 0, 0);
--- /dev/null	Thu Apr 17 16:45:10 2003
+++ isa/ppcvar.h	Thu Apr 17 09:09:08 2003
@@ -0,0 +1,49 @@
+
+/*-
+ * Copyright (c) 1997-2000 Nicolas Souchu
+ * Copyright (c) 2001 Alcove - Nicolas Souchu
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ *
+ */
+
+int ppc_probe(device_t dev);
+int ppc_attach(device_t dev);
+int ppc_read_ivar(device_t bus, device_t dev, int index, uintptr_t *val);
+
+int ppc_read(device_t, char *, int, int);
+int ppc_write(device_t, char *, int, int);
+
+u_char ppc_io(device_t, int, u_char *, int, u_char);
+int ppc_exec_microseq(device_t, struct ppb_microseq **);
+
+int ppc_setup_intr(device_t, device_t, struct resource *, int,
+		void (*)(void *), void *, void **);
+int ppc_teardown_intr(device_t, device_t, struct resource *, void *);
+void ppc_reset_epp(device_t);
+void ppc_ecp_sync(device_t);
+int ppc_setmode(device_t, int);
+
+extern	devclass_t	ppc_devclass;



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