Re: device_t/softc for xcom(4), mha(4)

Tetsuya Isaki <[email protected]> Wed, 25 Jun 2008 17:33:10 +0900
Newsgroups gmane.os.netbsd.ports.x68k
Message-ID <[email protected]>
At Wed, 25 Jun 2008 16:40:35 +0900,
Tetsuya Isaki wrote:
> Now I spliting device_t/softc on x68k devices.
> But I don't have xcom(4) and mha(4) devices, so
> does anyone test them, please?

Oops, I missed mhavar.h in previous mail.
Here is a patch:

Index: sys/arch/x68k/dev/mhavar.h
===================================================================
RCS file: /cvsroot/src/sys/arch/x68k/dev/mhavar.h,v
retrieving revision 1.8
diff -u -r1.8 mhavar.h
--- sys/arch/x68k/dev/mhavar.h	4 Mar 2007 06:01:06 -0000	1.8
+++ sys/arch/x68k/dev/mhavar.h	25 Jun 2008 08:10:49 -0000
@@ -85,7 +85,7 @@
 } tinfo_t;
 
 struct mha_softc {
-	struct device sc_dev;			/* us as a device */
+	device_t sc_dev;
 	volatile void *sc_iobase;
 	volatile u_char	*sc_pc;
 	volatile u_short *sc_ps;

---
Tetsuya Isaki <[email protected] / [email protected]>

> Index: sys/arch/x68k/dev/com.c
> ===================================================================
> RCS file: /cvsroot/src/sys/arch/x68k/dev/com.c,v
> retrieving revision 1.53
> diff -u -r1.53 com.c
> --- sys/arch/x68k/dev/com.c	13 Jun 2008 13:57:58 -0000	1.53
> +++ sys/arch/x68k/dev/com.c	25 Jun 2008 07:36:52 -0000
> @@ -108,7 +108,7 @@
>  #define	COM_IHIGHWATER	((3 * COM_IBUFSIZE) / 4)
>  
>  struct com_softc {
> -	struct device sc_dev;
> +	device_t sc_dev;
>  	void *sc_ih;
>  	struct tty *sc_tty;
>  
> @@ -143,8 +143,8 @@
>  
>  struct callout com_poll_ch;
>  
> -int comprobe(struct device *, struct cfdata *, void *);
> -void comattach(struct device *, struct device *, void *);
> +int comprobe(device_t, cfdata_t, void *);
> +void comattach(device_t, device_t, void *);
>  
>  static int comprobe1(int);
>  static void comdiag(void *);
> @@ -157,7 +157,7 @@
>  
>  static u_char tiocm_xxx2mcr(int);
>  
> -CFATTACH_DECL(xcom, sizeof(struct com_softc),
> +CFATTACH_DECL_NEW(xcom, sizeof(struct com_softc),
>      comprobe, comattach, NULL, NULL);
>  
>  extern struct cfdriver xcom_cd;
> @@ -305,7 +305,7 @@
>  #endif
>  
>  int
> -comprobe(struct device *parent, struct cfdata *cfp, void *aux)
> +comprobe(device_t parent, cfdata_t cfp, void *aux)
>  {
>  	int iobase = (int)&IODEVbase->psx16550;
>  
> @@ -319,15 +319,16 @@
>  }
>  
>  void
> -comattach(struct device *parent, struct device *dev, void *aux)
> +comattach(device_t parent, device_t dev, void *aux)
>  {
> -	struct com_softc *sc = (struct com_softc *)dev;
> +	struct com_softc *sc = device_private(dev);
>  	int iobase = (int)&IODEVbase->psx16550;
>  #ifdef COM_HAYESP
>  	int	hayesp_ports[] = { 0x140, 0x180, 0x280, 0x300, 0 };
>  	int	*hayespp;
>  #endif
>  
> +	sc->sc_dev = dev;
>  	com_attached = 1;
>  
>  	callout_init(&sc->sc_diag_ch, 0);
> @@ -336,7 +337,7 @@
>  	sc->sc_iobase = iobase;
>  	sc->sc_hwflags = 0;
>  	sc->sc_swflags = 0;
> -	printf(": iobase %x", sc->sc_iobase);
> +	aprint_normal(": iobase %x", sc->sc_iobase);
>  
>  #ifdef COM_HAYESP
>  	/* Look for a Hayes ESP board. */
> @@ -356,11 +357,11 @@
>  	if (ISSET(inb(pio(iobase , com_iir)), IIR_FIFO_MASK) == IIR_FIFO_MASK)
>  		if (ISSET(inb(pio(iobase , com_fifo)), FIFO_TRIGGER_14) == FIFO_TRIGGER_14) {
>  			SET(sc->sc_hwflags, COM_HW_FIFO);
> -			printf(": ns16550a, working fifo\n");
> +			aprint_normal(": ns16550a, working fifo\n");
>  		} else
> -			printf(": ns16550, broken fifo\n");
> +			aprint_normal(": ns16550, broken fifo\n");
>  	else
> -		printf(": ns8250 or ns16450, no fifo\n");
> +		aprint_normal(": ns8250 or ns16450, no fifo\n");
>  	outb(pio(iobase , com_fifo), 0);
>  #ifdef COM_HAYESP
>  	}
> @@ -894,7 +895,7 @@
>  	splx(s);
>  
>  	log(LOG_WARNING, "%s: %d silo overflow%s, %d ibuf overflow%s\n",
> -	    sc->sc_dev.dv_xname,
> +	    device_xname(sc->sc_dev),
>  	    overflows, overflows == 1 ? "" : "s",
>  	    floods, floods == 1 ? "" : "s");
>  }
> Index: sys/arch/x68k/dev/mha.c
> ===================================================================
> RCS file: /cvsroot/src/sys/arch/x68k/dev/mha.c,v
> retrieving revision 1.48
> diff -u -r1.48 mha.c
> --- sys/arch/x68k/dev/mha.c	13 Jun 2008 13:57:58 -0000	1.48
> +++ sys/arch/x68k/dev/mha.c	25 Jun 2008 07:36:53 -0000
> @@ -217,7 +217,7 @@
>  #define SPC_DMA(str)   do {if (mha_debug & SPC_SHOWDMA) printf str;}while (0)
>  #define SPC_MSGS(str)  do {if (mha_debug & SPC_SHOWMSGS) printf str;}while (0)
>  #define	SPC_BREAK()    do {if ((mha_debug & SPC_DOBREAK) != 0) Debugger();} while (0)
> -#define	SPC_ASSERT(x)  do {if (x) {} else {printf("%s at line %d: assertion failed\n", sc->sc_dev.dv_xname, __LINE__); Debugger();}} while (0)
> +#define	SPC_ASSERT(x)  do {if (x) {} else {printf("%s at line %d: assertion failed\n", device_xname(sc->sc_dev), __LINE__); Debugger();}} while (0)
>  #else
>  #define SPC_ACBS(str)
>  #define SPC_MISC(str)
> @@ -232,8 +232,8 @@
>  #define	SPC_ASSERT(x)
>  #endif
>  
> -int	mhamatch(struct device *, struct cfdata *, void *);
> -void	mhaattach(struct device *, struct device *, void *);
> +int	mhamatch(device_t, cfdata_t, void *);
> +void	mhaattach(device_t, device_t, void *);
>  void	mhaselect(struct mha_softc *, u_char, u_char, u_char *, u_char);
>  void	mha_scsi_reset(struct mha_softc *);
>  void	mha_reset(struct mha_softc *);
> @@ -265,7 +265,7 @@
>  
>  static int mha_dataio_dma(int, int, struct mha_softc *, u_char *, int);
>  
> -CFATTACH_DECL(mha, sizeof(struct mha_softc),
> +CFATTACH_DECL_NEW(mha, sizeof(struct mha_softc),
>      mhamatch, mhaattach, NULL, NULL);
>  
>  extern struct cfdriver mha_cd;
> @@ -274,7 +274,7 @@
>   * returns non-zero value if a controller is found.
>   */
>  int
> -mhamatch(struct device *parent, struct cfdata *cf, void *aux)
> +mhamatch(device_t parent, cfdata_t cf, void *aux)
>  {
>  	struct intio_attach_args *ia = aux;
>  	bus_space_tag_t iot = ia->ia_bst;
> @@ -304,14 +304,15 @@
>  struct mha_softc *tmpsc;
>  
>  void
> -mhaattach(struct device *parent, struct device *self, void *aux)
> +mhaattach(device_t parent, device_t self, void *aux)
>  {
> -	struct mha_softc *sc = (void *)self;
> +	struct mha_softc *sc = device_private(self);
>  	struct intio_attach_args *ia = aux;
>  
>  	tmpsc = sc;	/* XXX */
> +	sc->sc_dev = self;
>  
> -	printf(": Mankai Mach-2 Fast SCSI Host Adaptor\n");
> +	aprint_normal(": Mankai Mach-2 Fast SCSI Host Adaptor\n");
>  
>  	SPC_TRACE(("mhaattach  "));
>  	sc->sc_state = SPC_INIT;
> @@ -337,7 +338,7 @@
>  	/*
>  	 * Fill in the adapter.
>  	 */
> -	sc->sc_adapter.adapt_dev = &sc->sc_dev;
> +	sc->sc_adapter.adapt_dev = sc->sc_dev;
>  	sc->sc_adapter.adapt_nchannels = 1;
>  	sc->sc_adapter.adapt_openings = 7;
>  	sc->sc_adapter.adapt_max_periph = 1;
> @@ -607,7 +608,7 @@
>  	selid = sc->sc_selid & ~(1 << sc->sc_id);
>  	if (selid & (selid - 1)) {
>  		printf("%s: reselect with invalid selid %02x; sending DEVICE RESET\n",
> -		    sc->sc_dev.dv_xname, selid);
> +		    device_xname(sc->sc_dev), selid);
>  		SPC_BREAK();
>  		goto reset;
>  	}
> @@ -629,7 +630,7 @@
>  	}
>  	if (acb == NULL) {
>  		printf("%s: reselect from target %d lun %d with no nexus; sending ABORT\n",
> -		    sc->sc_dev.dv_xname, target, lun);
> +		    device_xname(sc->sc_dev), target, lun);
>  		SPC_BREAK();
>  		goto abort;
>  	}
> @@ -908,7 +909,7 @@
>  				xs->error = XS_DRIVER_STUFFUP;
>  #if SPC_DEBUG
>  				printf("%s: mha_done: bad stat 0x%x\n",
> -					sc->sc_dev.dv_xname, acb->stat);
> +					device_xname(sc->sc_dev), acb->stat);
>  #endif
>  				break;
>  			}
> @@ -932,7 +933,7 @@
>  	switch (acb->flags & ACB_QBITS) {
>  	case ACB_QNONE:
>  		if (acb != sc->sc_nexus) {
> -			panic("%s: floating acb", sc->sc_dev.dv_xname);
> +			panic("%s: floating acb", device_xname(sc->sc_dev));
>  		}
>  		sc->sc_nexus = NULL;
>  		sc->sc_state = SPC_IDLE;
> @@ -948,11 +949,11 @@
>  		break;
>  	case ACB_QFREE:
>  		panic("%s: dequeue: busy acb on free list",
> -			sc->sc_dev.dv_xname);
> +			device_xname(sc->sc_dev));
>  		break;
>  	default:
>  		panic("%s: dequeue: unknown queue %d",
> -			sc->sc_dev.dv_xname, acb->flags & ACB_QBITS);
> +			device_xname(sc->sc_dev), acb->flags & ACB_QBITS);
>  	}
>  
>  	/* Put it on the free list, and clear flags. */
> @@ -1094,7 +1095,7 @@
>  #if SPC_DEBUG
>  			if (mha_debug & SPC_SHOWMSGS)
>  				printf("%s: our msg rejected by target\n",
> -					sc->sc_dev.dv_xname);
> +					device_xname(sc->sc_dev));
>  #endif
>  #if 1 /* XXX - must remember last message */
>  			scsipi_printaddr(acb->xs->xs_periph);
> @@ -1130,7 +1131,7 @@
>  			if (!acb) {
>  				mha_sched_msgout(SEND_ABORT);
>  				printf("%s: no DATAPOINTERs to restore\n",
> -				    sc->sc_dev.dv_xname);
> +				    device_xname(sc->sc_dev));
>  				break;
>  			}
>  			sc->sc_dp = acb->daddr;
> @@ -1138,7 +1139,7 @@
>  			break;
>  		case MSG_PARITY_ERROR:
>  			printf("%s:target%d: MSG_PARITY_ERROR\n",
> -				sc->sc_dev.dv_xname,
> +				device_xname(sc->sc_dev),
>  				acb->xs->xs_periph->periph_target);
>  			break;
>  		case MSG_EXTENDED:
> @@ -1207,7 +1208,7 @@
>  			/* thanks for that ident... */
>  			if (!MSG_ISIDENTIFY(sc->sc_imess[0])) {
>  				SPC_MISC(("unknown "));
> -printf("%s: unimplemented message: %d\n", sc->sc_dev.dv_xname, sc->sc_imess[0]);
> +printf("%s: unimplemented message: %d\n", device_xname(sc->sc_dev), sc->sc_imess[0]);
>  				CMR = CMD_SET_ATN; /* XXX? */
>  			}
>  			break;
> @@ -1264,12 +1265,12 @@
>  			}
>  		} else {
>  			printf("%s: bogus reselect (no IDENTIFY) %0x2x\n",
> -			    sc->sc_dev.dv_xname, sc->sc_selid);
> +			    device_xname(sc->sc_dev), sc->sc_selid);
>  			mha_sched_msgout(SEND_DEV_RESET);
>  		}
>  	} else { /* Neither SPC_HASNEXUS nor SPC_RESELECTED! */
>  		printf("%s: unexpected message in; will send DEV_RESET\n",
> -		    sc->sc_dev.dv_xname);
> +		    device_xname(sc->sc_dev));
>  		mha_sched_msgout(SEND_DEV_RESET);
>  	}
>  
> @@ -1396,7 +1397,7 @@
>  
>  	default:
>  		printf("%s: unexpected MESSAGE OUT; sending NOOP\n",
> -		    sc->sc_dev.dv_xname);
> +		    device_xname(sc->sc_dev));
>  		SPC_BREAK();
>  		sc->sc_omess[0] = MSG_NOOP;
>  		n = 1;
> @@ -1959,7 +1960,7 @@
>  	scsipi_printaddr(periph);
>  	printf("%s: timed out [acb %p (flags 0x%x, dleft %x, stat %x)], "
>  	       "<state %d, nexus %p, phase(c %x, p %x), resid %x, msg(q %x,o %x) >",
> -		sc->sc_dev.dv_xname,
> +		device_xname(sc->sc_dev),
>  		acb, acb->flags, acb->dleft, acb->stat,
>  		sc->sc_state, sc->sc_nexus, sc->sc_phase, sc->sc_prevphase,
>  		sc->sc_dleft, sc->sc_msgpriq, sc->sc_msgout
> 
> ---
> Tetsuya Isaki <[email protected] / [email protected]>
>