socsvn commit: r257333 - soc2013/zcore/head/usr.sbin/bhyve

zcore at FreeBSD.org zcore at FreeBSD.org
Sat Sep 14 16:00:27 UTC 2013


Author: zcore
Date: Sat Sep 14 16:00:27 2013
New Revision: 257333
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=257333

Log:
  consolidate write prdt

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	Sat Sep 14 15:29:06 2013	(r257332)
+++ soc2013/zcore/head/usr.sbin/bhyve/pci_ahci.c	Sat Sep 14 16:00:27 2013	(r257333)
@@ -447,11 +447,34 @@
 	ahci_write_fis_d2h(p, slot, cfis, ATA_S_READY | ATA_S_DSC);
 }
 
+static inline void
+write_prdt(struct ahci_port *p, int slot, uint8_t *cfis,
+		void *buf, int size)
+{
+	int i, len;
+	void *from;
+	struct ahci_cmd_hdr *hdr;
+	struct ahci_prdt_entry *prdt;
+
+	hdr = p->cmd_lst + slot * AHCI_CL_SIZE;
+	len = size;
+	from = buf;
+	prdt = (struct ahci_prdt_entry *)(cfis + 0x80);
+	for (i = 0; i < hdr->prdtl && len; i++) {
+		uint8_t *ptr = paddr_guest2host(ahci_ctx(p->pr_sc),
+				prdt->dba, prdt->dbc + 1);
+		memcpy(ptr, from, prdt->dbc + 1);
+		len -= (prdt->dbc + 1);
+		from += (prdt->dbc + 1);
+		prdt++;
+	}
+	hdr->prdbc = size - len;
+}
+
 static void
 handle_identify(struct ahci_port *p, int slot, uint8_t *cfis)
 {
 	struct ahci_cmd_hdr *hdr;
-	struct pci_ahci_softc *sc = p->pr_sc;
 
 	hdr = p->cmd_lst + slot * AHCI_CL_SIZE;
 	if (p->atapi || hdr->prdtl == 0) {
@@ -460,9 +483,6 @@
 	} else {
 		uint16_t buf[256];
 		uint64_t sectors;
-		int i, len;
-		void *from;
-		struct ahci_prdt_entry *prdt;
 
 		sectors = blockif_size(p->bctx) / blockif_sectsz(p->bctx);
 		memset(buf, 0, sizeof(buf));
@@ -506,39 +526,22 @@
 		buf[101] = (sectors >> 16);
 		buf[102] = (sectors >> 32);
 		buf[103] = (sectors >> 48);
-		len = sizeof(buf);
-		from = buf;
-		prdt = (struct ahci_prdt_entry *)(cfis + 0x80);
-		for (i = 0; i < hdr->prdtl && len; i++) {
-			uint8_t *ptr = paddr_guest2host(ahci_ctx(sc),
-					prdt->dba, prdt->dbc + 1);
-			memcpy(ptr, from, prdt->dbc + 1);
-			len -= (prdt->dbc + 1);
-			from += (prdt->dbc + 1);
-			prdt++;
-		}
-		hdr->prdbc = sizeof(buf) - len;
+		write_prdt(p, slot, cfis, (void *)buf, sizeof(buf));
 		p->tfd = ATA_S_DSC | ATA_S_READY;
 		p->is |= AHCI_P_IX_DP;
 	}
 	p->ci &= ~(1 << slot);
-	ahci_generate_intr(sc);
+	ahci_generate_intr(p->pr_sc);
 }
 
 static void
 handle_atapi_identify(struct ahci_port *p, int slot, uint8_t *cfis)
 {
-	struct pci_ahci_softc *sc = p->pr_sc;
-
 	if (!p->atapi) {
 		p->tfd = (ATA_E_ABORT << 8) | ATA_S_READY | ATA_S_ERROR;
 		p->is |= AHCI_P_IX_TFE;
 	} else {
 		uint16_t buf[256];
-		int i, len;
-		void *from;
-		struct ahci_prdt_entry *prdt;
-		struct ahci_cmd_hdr *hdr;
 
 		memset(buf, 0, sizeof(buf));
 		buf[0] = (2 << 14 | 5 << 8 | 1 << 7 | 2 << 5);
@@ -564,35 +567,20 @@
 		buf[85] = (1 << 4);
 		buf[87] = (1 << 14);
 		buf[88] = (1 << 14 | 0x7f);
-		len = sizeof(buf);
-		from = buf;
-		prdt = (struct ahci_prdt_entry *)(cfis + 0x80);
-		hdr = p->cmd_lst + slot * AHCI_CL_SIZE;
-		for (i = 0; i < hdr->prdtl && len; i++) {
-			uint8_t *p = paddr_guest2host(ahci_ctx(sc),
-					prdt->dba, prdt->dbc + 1);
-			memcpy(p, from, prdt->dbc + 1);
-			len -= (prdt->dbc + 1);
-			from += (prdt->dbc + 1);
-			prdt++;
-		}
-		hdr->prdbc = sizeof(buf) - len;
+		write_prdt(p, slot, cfis, (void *)buf, sizeof(buf));
 		p->tfd = ATA_S_DSC | ATA_S_READY;
 		p->is |= AHCI_P_IX_DHR;
 	}
 	p->ci &= ~(1 << slot);
-	ahci_generate_intr(sc);
+	ahci_generate_intr(p->pr_sc);
 }
 
 static void
 atapi_inquiry(struct ahci_port *p, int slot, uint8_t *cfis)
 {
+	int len;
 	uint8_t buf[36];
 	uint8_t *acmd = cfis + 0x40;
-	int i, len;
-	void *from;
-	struct ahci_cmd_hdr *hdr;
-	struct ahci_prdt_entry *prdt;
 
 	buf[0] = 0x05;
 	buf[1] = 0x80;
@@ -609,18 +597,7 @@
 	len = sizeof(buf);
 	if (len > acmd[4])
 		len = acmd[4];
-	from = buf;
-	hdr = p->cmd_lst + slot * AHCI_CL_SIZE;
-	prdt = (struct ahci_prdt_entry *)(cfis + 0x80);
-	for (i = 0; i < hdr->prdtl && len; i++) {
-		uint8_t *ptr = paddr_guest2host(ahci_ctx(p->pr_sc),
-				prdt->dba, prdt->dbc + 1);
-		memcpy(ptr, from, prdt->dbc + 1);
-		len -= (prdt->dbc + 1);
-		from += (prdt->dbc + 1);
-		prdt++;
-	}
-	hdr->prdbc = sizeof(buf) - len;
+	write_prdt(p, slot, cfis, buf, len);
 	ahci_write_fis_d2h(p, slot, cfis, ATA_S_READY | ATA_S_DSC);
 }
 


More information about the svn-soc-all mailing list