Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 28 May 2004 10:40:26 -0700 (PDT)
From:      Scott Long <scottl@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 53674 for review
Message-ID:  <200405281740.i4SHeQaK011707@repoman.freebsd.org>

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

Change 53674 by scottl@scottl-esp-sparc64 on 2004/05/28 10:40:06

	Actually submit the file that should have been submitted last time.
	Pointy hat graciously given by jhb =-)

Affected files ...

.. //depot/projects/scottl-esp/src/sys/dev/esp/esp_sbus.c#5 edit

Differences ...

==== //depot/projects/scottl-esp/src/sys/dev/esp/esp_sbus.c#5 (text+ko) ====

@@ -64,8 +64,6 @@
 #include <dev/esp/ncr53c9xreg.h>
 #include <dev/esp/ncr53c9xvar.h>
 
-#include <sparc64/sbus/sbusvar.h>
-
 /* #define ESP_SBUS_DEBUG */
 
 struct esp_softc {
@@ -97,18 +95,20 @@
 	{0, 0}
 };
 
-#if 0
-CFATTACH_DECL(esp_sbus, sizeof(struct esp_softc),
-    espmatch_sbus, espattach_sbus, NULL, NULL);
-#endif
+static driver_t esp_sbus_driver = {
+	"esp",
+	esp_sbus_methods,
+	sizeof(struct esp_softc)
+};
+
+static devclass_t	esp_devclass;
+DRIVER_MODULE(esp, sbus, esp_sbus_driver, esp_devclass, 0, 0);
 
 /*
  * Functions and the switch for the MI code.
  */
 static u_char	esp_read_reg(struct ncr53c9x_softc *, int);
 static void	esp_write_reg(struct ncr53c9x_softc *, int, u_char);
-static u_char	esp_rdreg1(struct ncr53c9x_softc *, int);
-static void	esp_wrreg1(struct ncr53c9x_softc *, int, u_char);
 static int	esp_dma_isintr(struct ncr53c9x_softc *);
 static void	esp_dma_reset(struct ncr53c9x_softc *);
 static int	esp_dma_intr(struct ncr53c9x_softc *);
@@ -117,6 +117,7 @@
 static void	esp_dma_go(struct ncr53c9x_softc *);
 static void	esp_dma_stop(struct ncr53c9x_softc *);
 static int	esp_dma_isactive(struct ncr53c9x_softc *);
+static void	espattach(struct esp_softc *, struct ncr53c9x_glue *);
 
 static struct ncr53c9x_glue esp_sbus_glue = {
 	esp_read_reg,
@@ -131,66 +132,48 @@
 	NULL,			/* gl_clear_latched_intr */
 };
 
-static struct ncr53c9x_glue esp_sbus_glue1 = {
-	esp_rdreg1,
-	esp_wrreg1,
-	esp_dma_isintr,
-	esp_dma_reset,
-	esp_dma_intr,
-	esp_dma_setup,
-	esp_dma_go,
-	esp_dma_stop,
-	esp_dma_isactive,
-	NULL,			/* gl_clear_latched_intr */
-};
-
-static void	espattach(struct esp_softc *, struct ncr53c9x_glue *);
-
 static int
 esp_sbus_probe(device_t dev)
 {
-	int rv;
-	struct sbus_attach_args *sa = aux;
+	char *name;
 
-	if (strcmp("SUNW,fas", sa->sa_name) == 0)
-	        return 1;
+	name = sbus_get_name(dev);
+	if (strcmp("SUNW,fas", name) == 0)
+	        return (-10);
 
-	rv = (strcmp(cf->cf_name, sa->sa_name) == 0 ||
-	    strcmp("ptscII", sa->sa_name) == 0);
-	return (rv);
+	return (ENXIO);
 }
 
 static int
 esp_sbus_attach(device_t dev)
 {
-	struct esp_softc *esc = (void *)self;
+	struct esp_softc *esc = device_get_softc(dev);
 	struct ncr53c9x_softc *sc = &esc->sc_ncr53c9x;
-	struct sbus_attach_args *sa = aux;
 	struct lsi64854_softc *lsc;
+	phandle_t node;
+	char *name;
 	int burst, sbusburst;
 
-	esc->sc_bustag = sa->sa_bustag;
-	esc->sc_dmatag = sa->sa_dmatag;
+	node = sbus_get_node(dev);
+	name = sbus_get_name(dev);
+	if (OF_getprop(node, "initiator-id", &sc->sc_id,
+		       sizeof(sc->sc_id)) == -1)
+		sc->sc_id = 7;;
+	sc->sc_freq = sbus_get_clockfreq(dev);
 
-	sc->sc_id = PROM_getpropint(sa->sa_node, "initiator-id", 7);
-	sc->sc_freq = PROM_getpropint(sa->sa_node, "clock-frequency", -1);
-	if (sc->sc_freq < 0)
-		sc->sc_freq = ((struct sbus_softc *)
-		    sc->sc_dev.dv_parent)->sc_clockfreq;
-
 #ifdef ESP_SBUS_DEBUG
 	printf("%s: espattach_sbus: sc_id %d, freq %d\n",
 	       self->dv_xname, sc->sc_id, sc->sc_freq);
 #endif
 
-	if (strcmp("SUNW,fas", sa->sa_name) == 0) {
+	if (strcmp("SUNW,fas", name) == 0) {
 
 		/*
 		 * fas has 2 register spaces: dma(lsi64854) and SCSI core (ncr53c9x)
 		 */
 		if (sa->sa_nreg != 2) {
 			printf("%s: %d register spaces\n", self->dv_xname, sa->sa_nreg);
-			return;
+			return (ENXIO);
 		}
 
 		/*
@@ -202,7 +185,7 @@
 		if (lsc == NULL) {
 			printf("%s: out of memory (lsi64854_softc)\n",
 			       self->dv_xname);
-			return;
+			return (ENOMEM);
 		}
 		esc->sc_dma = lsc;
 
@@ -224,7 +207,7 @@
 				0, &lsc->sc_regs) != 0) {
 				printf("%s: cannot map dma registers\n",
 					self->dv_xname);
-				return;
+				return (ENXIO);
 			}
 		}
 
@@ -239,7 +222,7 @@
 		if (sbusburst == 0)
 			sbusburst = SBUS_BURST_32 - 1; /* 1->16 */
 
-		burst = PROM_getpropint(sa->sa_node, "burst-sizes", -1);
+		burst = sbus_get_burstsz(dev);
 
 #if ESP_SBUS_DEBUG
 		printf("espattach_sbus: burst 0x%x, sbus 0x%x\n",
@@ -275,13 +258,13 @@
 				printf("%s @ sbus: "
 					"cannot map scsi core registers\n",
 					self->dv_xname);
-				return;
+				return (ENXIO);
 			}
 		}
 
 		if (sa->sa_nintr == 0) {
 			printf("\n%s: no interrupt property\n", self->dv_xname);
-			return;
+			return (ENXIO);
 		}
 
 		esc->sc_pri = sa->sa_pri;
@@ -294,146 +277,17 @@
 
 		espattach(esc, &esp_sbus_glue);
 
-		return;
+		return (0);
 	}
 
-	/*
-	 * Find the DMA by poking around the dma device structures
-	 *
-	 * What happens here is that if the dma driver has not been
-	 * configured, then this returns a NULL pointer. Then when the
-	 * dma actually gets configured, it does the opposing test, and
-	 * if the sc->sc_esp field in it's softc is NULL, then tries to
-	 * find the matching esp driver.
-	 */
-	esc->sc_dma = (struct lsi64854_softc *)
-				getdevunit("dma", sc->sc_dev.dv_unit);
-
-	/*
-	 * and a back pointer to us, for DMA
-	 */
-	if (esc->sc_dma)
-		esc->sc_dma->sc_client = sc;
-	else {
-		printf("\n");
-		panic("espattach: no dma found");
-	}
-
-	/*
-	 * The `ESC' DMA chip must be reset before we can access
-	 * the esp registers.
-	 */
-	if (esc->sc_dma->sc_rev == DMAREV_ESC)
-		DMA_RESET(esc->sc_dma);
-
-	/*
-	 * Map my registers in, if they aren't already in virtual
-	 * address space.
-	 */
-	if (sa->sa_npromvaddrs) {
-		sbus_promaddr_to_handle(sa->sa_bustag,
-			sa->sa_promvaddrs[0], &esc->sc_reg);
-	} else {
-		if (sbus_bus_map(sa->sa_bustag,
-			sa->sa_slot, sa->sa_offset, sa->sa_size,
-			0, &esc->sc_reg) != 0) {
-			printf("%s @ sbus: cannot map registers\n",
-				self->dv_xname);
-			return;
-		}
-	}
-
-	if (sa->sa_nintr == 0) {
-		/*
-		 * No interrupt properties: we quit; this might
-		 * happen on e.g. a Sparc X terminal.
-		 */
-		printf("\n%s: no interrupt property\n", self->dv_xname);
-		return;
-	}
-
-	esc->sc_pri = sa->sa_pri;
-
-#if 0
-	/* add me to the sbus structures */
-	esc->sc_sd.sd_reset = (void *) ncr53c9x_reset;
-	sbus_establish(&esc->sc_sd, &sc->sc_dev);
-#endif
-
-	if (strcmp("ptscII", sa->sa_name) == 0) {
-		espattach(esc, &esp_sbus_glue1);
-	} else {
-		espattach(esc, &esp_sbus_glue);
-	}
-}
-
-void
-espattach_dma(parent, self, aux)
-	struct device *parent, *self;
-	void *aux;
-{
-	struct esp_softc *esc = (void *)self;
-	struct ncr53c9x_softc *sc = &esc->sc_ncr53c9x;
-	struct sbus_attach_args *sa = aux;
-
-	if (strcmp("ptscII", sa->sa_name) == 0) {
-		return;
-	}
-
-	esc->sc_bustag = sa->sa_bustag;
-	esc->sc_dmatag = sa->sa_dmatag;
-
-	sc->sc_id = PROM_getpropint(sa->sa_node, "initiator-id", 7);
-	sc->sc_freq = PROM_getpropint(sa->sa_node, "clock-frequency", -1);
-
-	esc->sc_dma = (struct lsi64854_softc *)parent;
-	esc->sc_dma->sc_client = sc;
-
-	/*
-	 * Map my registers in, if they aren't already in virtual
-	 * address space.
-	 */
-	if (sa->sa_npromvaddrs) {
-		sbus_promaddr_to_handle(sa->sa_bustag,
-			sa->sa_promvaddrs[0], &esc->sc_reg);
-	} else {
-		if (sbus_bus_map(sa->sa_bustag,
-			sa->sa_slot, sa->sa_offset, sa->sa_size,
-			0, &esc->sc_reg) != 0) {
-			printf("%s @ dma: cannot map registers\n",
-				self->dv_xname);
-			return;
-		}
-	}
-
-	if (sa->sa_nintr == 0) {
-		/*
-		 * No interrupt properties: we quit; this might
-		 * happen on e.g. a Sparc X terminal.
-		 */
-		printf("\n%s: no interrupt property\n", self->dv_xname);
-		return;
-	}
-
-	esc->sc_pri = sa->sa_pri;
-
-#if 0
-	/* Assume SBus is grandparent */
-	esc->sc_sd.sd_reset = (void *) ncr53c9x_reset;
-	sbus_establish(&esc->sc_sd, parent);
-#endif
-
-	espattach(esc, &esp_sbus_glue);
+	return (ENXIO);
 }
 
-
 /*
  * Attach this instance, and then all the sub-devices
  */
 void
-espattach(esc, gluep)
-	struct esp_softc *esc;
-	struct ncr53c9x_glue *gluep;
+espattach(struct esp_softc *esc, struct ncr53c9x_glue *gluep)
 {
 	struct ncr53c9x_softc *sc = &esc->sc_ncr53c9x;
 	void *icookie;
@@ -635,27 +489,6 @@
 	bus_space_write_1(esc->sc_bustag, esc->sc_reg, reg * 4, v);
 }
 
-u_char
-esp_rdreg1(sc, reg)
-	struct ncr53c9x_softc *sc;
-	int reg;
-{
-	struct esp_softc *esc = (struct esp_softc *)sc;
-
-	return (bus_space_read_1(esc->sc_bustag, esc->sc_reg, reg));
-}
-
-void
-esp_wrreg1(sc, reg, v)
-	struct ncr53c9x_softc *sc;
-	int reg;
-	u_char v;
-{
-	struct esp_softc *esc = (struct esp_softc *)sc;
-
-	bus_space_write_1(esc->sc_bustag, esc->sc_reg, reg, v);
-}
-
 int
 esp_dma_isintr(sc)
 	struct ncr53c9x_softc *sc;



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