Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 06 Sep 2001 17:49:06 -0700
From:      Julian Elischer <julian@vicor-nb.com>
To:        current@freebsd.org
Subject:   RFC: hack volatile bzero and bcopy
Message-ID:  <3B981982.4E939CDF@vicor-nb.com>

next in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------754057C4937561F384C03E88
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit


Here is a hack to remove the 20 or so warning messages from if_ie.c

Most of them are due to the supply of volatile pointers to bcopy and
bzero.

I do the following to produce macros that call bzero and bcopy, but
don't produce 
warning messages when called with volatile arguments.


typedef void Xcopy( void volatile *, void volatile *, int);
#define VBCOPY(A,B,L) (*(Xcopy *)&bcopy)((A),(B),(L))
typedef void Xzero( void volatile *, int);
#define VBZERO(A,L) (*(Xzero *)&bzero)((A),(L))

This is kind-of a hack but a couple of things come to mind:
1/ Most drivers should probably use volatile mor ethan they do if they
share
structures with hardware. These often need bcopy(), so this is probably
not an unlikely
combination..
2/ initializing these volatile structures with bzero is also not
unlikely.
3/ It probably wouldn't hurt if bzero ALWAYS had a volatile pointer
argument.
and it may remove several warnings in other drivers as well.



questions:
Is this hack to horrible to contemplate?
Is it a reasonable thing thing to define bzero to take a volatile
argument.
(It does not hurt to pass a nonvolatile argument to a volatile but the
reverse
produces an error message). I've compiled LINT with this change and it
compiles fine.
Should we define an "official" volatile_bcopy() to use in these cases,
even if it is just a (nicer) version of this hack in systm.h?


BTW what is ovbcopy() for? is it for overlaping?
I can't find a definition for it here, but google finds references in
true64.
(overlapping)

I notice that KAME ar the major users of it, and it's defined to be the
same as 
bcopy..
I also notice that NetBSD are (or were) having a kill
ovbcopy/bcopy/bzero  effort
to replace them with memcpy and friends.
--------------754057C4937561F384C03E88
Content-Type: text/plain; charset=us-ascii;
 name="iediff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="iediff"

--- if_ie.c	Thu Sep  6 17:05:12 2001
+++ if_ie.c.new	Thu Sep  6 17:03:42 2001
@@ -62,6 +62,10 @@
  * Intel EtherExpress 16 support from if_ix.c, written by Rodney W. Grimes.
  */
 
+typedef void Xcopy( void volatile *, void volatile *, int);
+#define VBCOPY(A,B,L) (*(Xcopy *)&bcopy)((A),(B),(L))
+typedef void Xzero( void volatile *, int);
+#define VBZERO(A,L) (*(Xzero *)&bzero)((A),(L))
 /*
  * The i82586 is a very versatile chip, found in many implementations.
  * Programming this chip is mostly the same, but certain details differ
@@ -219,9 +223,10 @@
 /*
  * This tells the autoconf code how to set us up.
  */
+static char drivername[] = "ie";
 struct isa_driver iedriver = {
 	INTR_TYPE_NET,
-	ieprobe, ieattach, "ie"
+	ieprobe, ieattach, drivername
 };
 
 enum ie_hardware {
@@ -776,7 +781,7 @@
 
 	ifp->if_softc = ie;
 	ifp->if_unit = unit;
-	ifp->if_name = iedriver.name;
+	ifp->if_name = drivername;
 	ifp->if_mtu = ETHERMTU;
 	printf("ie%d: <%s R%d> address %6D\n", unit,
 	       ie_hardware_names[ie->hard_type],
@@ -1140,7 +1145,7 @@
 	/*
 	 * Snarf the Ethernet header.
 	 */
-	bcopy((v_caddr_t) ie->cbuffs[i], (caddr_t) ehp, sizeof *ehp);
+	VBCOPY(ie->cbuffs[i], (caddr_t) ehp, sizeof *ehp);
 	/* ignore cast-qual warning here */
 
 	/*
@@ -1228,7 +1233,7 @@
 		if (thislen > m->m_len - thismboff) {
 			int	newlen = m->m_len - thismboff;
 
-			bcopy((v_caddr_t) (ie->cbuffs[head] + offset),
+			VBCOPY((v_caddr_t) (ie->cbuffs[head] + offset),
 			      mtod(m, v_caddr_t) +thismboff, (unsigned) newlen);
 			/* ignore cast-qual warning */
 			m = m->m_next;
@@ -1245,7 +1250,7 @@
 		 * pointers, and so on.
 		 */
 		if (thislen < m->m_len - thismboff) {
-			bcopy((v_caddr_t) (ie->cbuffs[head] + offset),
+			VBCOPY((v_caddr_t) (ie->cbuffs[head] + offset),
 			    mtod(m, caddr_t) +thismboff, (unsigned) thislen);
 			thismboff += thislen;	/* we are this far into the
 						 * mbuf */
@@ -1257,7 +1262,7 @@
 		 * buffer's contents into the current mbuf.  Do the
 		 * combination of the above actions.
 		 */
-		bcopy((v_caddr_t) (ie->cbuffs[head] + offset),
+		VBCOPY((v_caddr_t) (ie->cbuffs[head] + offset),
 		      mtod(m, caddr_t) + thismboff, (unsigned) thislen);
 		m = m->m_next;
 		thismboff = 0;		/* new mbuf, start at the beginning */
@@ -1300,7 +1305,7 @@
 	struct mbuf *m = 0;
 	struct ether_header eh;
 
-	bcopy((v_caddr_t) (ie->rframes[num]), &rfd,
+	VBCOPY((v_caddr_t) (ie->rframes[num]), &rfd,
 	      sizeof(struct ie_recv_frame_desc));
 
 	/*
@@ -1400,12 +1405,11 @@
 		len = 0;
 
 		for (m0 = m; m && len < IE_BUF_LEN; m = m->m_next) {
-			bcopy(mtod(m, caddr_t), buffer, m->m_len);
+			VBCOPY(mtod(m, caddr_t), buffer, m->m_len);
 			buffer += m->m_len;
 			len += m->m_len;
 		}
 
-		m_freem(m0);
 		len = max(len, ETHER_MIN_LEN);
 
 		/*
@@ -1413,9 +1417,9 @@
 		 * packet before we commit it to the wire.
 		 */
 		if (ie->arpcom.ac_if.if_bpf)
-			bpf_tap(&ie->arpcom.ac_if,
-				(void *)ie->xmit_cbuffs[ie->xmit_count], len);
+			bpf_mtap(&ie->arpcom.ac_if, m0);
 
+		m_freem(m0);
 		ie->xmit_buffs[ie->xmit_count]->ie_xmit_flags =
 		    IE_XMIT_LAST|len;
 		ie->xmit_buffs[ie->xmit_count]->ie_xmit_next = 0xffff;
@@ -1468,7 +1472,7 @@
 
 	scp = (volatile struct ie_sys_conf_ptr *) (uintptr_t)
 	      (realbase + IE_SCP_ADDR);
-	bzero((volatile char *) scp, sizeof *scp);
+	VBZERO(scp, sizeof *scp);
 
 	/*
 	 * First we put the ISCP at the bottom of memory; this tests to make
@@ -1477,10 +1481,10 @@
 	 * operation.
 	 */
 	iscp = (volatile struct ie_int_sys_conf_ptr *) where;
-	bzero((volatile char *)iscp, sizeof *iscp);
+	VBZERO(iscp, sizeof *iscp);
 
 	scb = (volatile struct ie_sys_ctl_block *) where;
-	bzero((volatile char *)scb, sizeof *scb);
+	VBZERO(scb, sizeof *scb);
 
 	scp->ie_bus_use = ie_softc[unit].bus_use;	/* 8-bit or 16-bit */
 	scp->ie_iscp_ptr = (caddr_t) (uintptr_t)
@@ -1505,7 +1509,7 @@
 	iscp = (void *) Align((caddr_t) (uintptr_t)
 			      (realbase + IE_SCP_ADDR -
 			       sizeof(struct ie_int_sys_conf_ptr)));
-	bzero((volatile char *) iscp, sizeof *iscp);	/* ignore cast-qual */
+	VBZERO(iscp, sizeof *iscp);	/* ignore cast-qual */
 
 	scp->ie_iscp_ptr = (caddr_t) (uintptr_t)
 	    ((volatile char *) iscp - (volatile char *) (uintptr_t) realbase);
@@ -1750,7 +1754,7 @@
 command_and_wait(int unit, int cmd, volatile void *pcmd, int mask)
 {
 	volatile struct ie_cmd_common *cc = pcmd;
-	volatile int timedout = 0;
+	int timedout = 0;
 	struct	 callout_handle ch;
 
 	ie_softc[unit].scb->ie_command = (u_short) cmd;
@@ -1863,7 +1867,7 @@
 	/* First lay them out */
 	for (i = 0; i < ie->nframes; i++) {
 		ie->rframes[i] = rfd;
-		bzero((volatile char *) rfd, sizeof *rfd);	/* ignore cast-qual */
+		VBZERO( rfd, sizeof *rfd);	/* ignore cast-qual */
 		rfd++;
 	}
 
@@ -1887,7 +1891,7 @@
 
 	for (i = 0; i < ie->nrxbufs; i++) {
 		ie->rbuffs[i] = rbd;
-		bzero((volatile char *)rbd, sizeof *rbd);
+		VBZERO(rbd, sizeof *rbd);
 		ptr = Alignvol(ptr + sizeof *rbd);
 		rbd->ie_rbd_length = IE_RBUF_SIZE;
 		rbd->ie_rbd_buffer = MK_24(MEM, ptr);
@@ -1937,7 +1941,7 @@
 	cmd->com.ie_cmd_link = 0xffff;
 
 	/* ignore cast-qual */
-	bcopy((v_caddr_t) ie->mcast_addrs, (v_caddr_t) cmd->ie_mcast_addrs,
+	VBCOPY(ie->mcast_addrs, cmd->ie_mcast_addrs,
 	      ie->mcast_count * sizeof *ie->mcast_addrs);
 
 	cmd->ie_mcast_bytes = ie->mcast_count * 6;	/* grrr... */
@@ -2001,8 +2005,8 @@
 		cmd->com.ie_cmd_cmd = IE_CMD_IASETUP | IE_CMD_LAST;
 		cmd->com.ie_cmd_link = 0xffff;
 
-		bcopy((volatile char *)ie_softc[unit].arpcom.ac_enaddr,
-		      (volatile char *)&cmd->ie_address, sizeof cmd->ie_address);
+		VBCOPY(ie_softc[unit].arpcom.ac_enaddr,
+		      &cmd->ie_address, sizeof cmd->ie_address);
 		scb->ie_command_list = MK_16(MEM, cmd);
 		if (command_and_wait(unit, IE_CU_START, cmd, IE_STAT_COMPL)
 		    || !(cmd->com.ie_cmd_status & IE_STAT_OK)) {
@@ -2051,8 +2055,8 @@
 	ie->xmit_cbuffs[ie->ntxbufs - 1] = (volatile void *) ptr;
 
 	for (i = 1; i < ie->ntxbufs; i++) {
-		bzero((v_caddr_t) ie->xmit_cmds[i], sizeof *ie->xmit_cmds[i]);
-		bzero((v_caddr_t) ie->xmit_buffs[i], sizeof *ie->xmit_buffs[i]);
+		VBZERO(ie->xmit_cmds[i], sizeof *ie->xmit_cmds[i]);
+		VBZERO(ie->xmit_buffs[i], sizeof *ie->xmit_buffs[i]);
 	}
 
 	/*

--------------754057C4937561F384C03E88--


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?3B981982.4E939CDF>