Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 15 Sep 2013 09:48:15 GMT
From:      zcore@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r257358 - soc2013/zcore/head/usr.sbin/bhyve
Message-ID:  <201309150948.r8F9mFBo004754@socsvn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: zcore
Date: Sun Sep 15 09:48:15 2013
New Revision: 257358
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=257358

Log:
  adopt endian functions from <sys/endian.h>

Modified:
  soc2013/zcore/head/usr.sbin/bhyve/pci_ahci.c

Modified: soc2013/zcore/head/usr.sbin/bhyve/pci_ahci.c
==============================================================================
--- soc2013/zcore/head/usr.sbin/bhyve/pci_ahci.c	Sun Sep 15 07:48:42 2013	(r257357)
+++ soc2013/zcore/head/usr.sbin/bhyve/pci_ahci.c	Sun Sep 15 09:48:15 2013	(r257358)
@@ -36,6 +36,7 @@
 #include <sys/ioctl.h>
 #include <sys/disk.h>
 #include <sys/ata.h>
+#include <sys/endian.h>
 
 #include <errno.h>
 #include <fcntl.h>
@@ -163,30 +164,6 @@
 };
 #define	ahci_ctx(sc)	((sc)->asc_pi->pi_vmctx)
 
-static inline uint32_t cpu_to_be32(uint32_t val)
-{
-	return ((val & 0xff) << 24) |
-		((val & 0xff00) << 8) |
-		((val & 0xff0000) >> 8) |
-		((val & 0xff000000) >> 24);
-}
-
-static inline uint32_t cpu_to_be16(uint16_t val)
-{
-	return ((val & 0xff) << 8) |
-		((val & 0xff00) >> 8);
-}
-
-static inline uint16_t be16_to_cpu(uint8_t *val)
-{
-	return (val[0] << 8) | val[1];
-}
-
-static inline uint16_t be32_to_cpu(uint8_t *val)
-{
-	return (val[0] << 24) | (val[1] << 16) | (val[2] << 8) | val[3];
-}
-
 static inline void lba_to_msf(uint8_t *buf, int lba)
 {
 	lba += 150;
@@ -639,12 +616,11 @@
 {
 	uint8_t buf[8];
 	uint64_t sectors;
-	uint32_t *ptr = (uint32_t *)buf;
 
 	sectors = blockif_size(p->bctx) / blockif_sectsz(p->bctx);
 	sectors >>= 2;
-	ptr[0] = cpu_to_be32(sectors - 1);
-	ptr[1] = cpu_to_be32(2048);
+	be32enc(buf, sectors - 1);
+	be32enc(buf + 4, 2048);
 	cfis[4] = (cfis[4] & ~7) | ATA_I_CMD | ATA_I_IN;
 	write_prdt(p, slot, cfis, buf, sizeof(buf));
 	ahci_write_fis_d2h(p, slot, cfis, ATA_S_READY | ATA_S_DSC);
@@ -656,7 +632,7 @@
 	int len;
 	uint8_t format, *acmd = cfis + 0x40;
 
-	len = be16_to_cpu(acmd + 7);
+	len = be16dec(acmd + 7);
 	format = acmd[9] >> 6;
 	switch (format) {
 	case 0:
@@ -706,11 +682,11 @@
 			lba_to_msf(bp, sectors);
 			bp += 3;
 		} else {
-			*(uint32_t *)bp = cpu_to_be32(sectors);
+			be32enc(bp, sectors);
 			bp += 4;
 		}
 		size = bp - buf;
-		*(uint16_t*)buf = cpu_to_be16(size - 2);
+		be16enc(buf, size - 2);
 		if (len > size)
 			len = size;
 		write_prdt(p, slot, cfis, buf, len);
@@ -783,7 +759,7 @@
 			lba_to_msf(bp, sectors);
 			bp += 3;
 		} else {
-			*(uint32_t *)bp = cpu_to_be32(sectors);
+			be32enc(bp, sectors);
 			bp += 4;
 		}
 
@@ -806,7 +782,7 @@
 		}
 
 		size = bp - buf;
-		*(uint16_t*)buf = cpu_to_be16(size - 2);
+		be16enc(buf, size - 2);
 		if (len > size)
 			len = size;
 		write_prdt(p, slot, cfis, buf, len);
@@ -844,8 +820,8 @@
 		p->unhandled_read |= (1 << slot);
 		return;
 	}
-	lba = be32_to_cpu(acmd + 2);
-	len = be16_to_cpu(acmd + 7);
+	lba = be32dec(acmd + 2);
+	len = be16dec(acmd + 7);
 	if (len == 0) {
 		cfis[4] = (cfis[4] & ~7) | ATA_I_CMD | ATA_I_IN;
 		ahci_write_fis_d2h(p, slot, cfis, ATA_S_READY | ATA_S_DSC);



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