From owner-svn-soc-all@FreeBSD.ORG Sat Sep 14 16:00:27 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 6A78A8B5 for ; Sat, 14 Sep 2013 16:00:27 +0000 (UTC) (envelope-from zcore@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 57BA82D5C for ; Sat, 14 Sep 2013 16:00:27 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r8EG0Rtn019619 for ; Sat, 14 Sep 2013 16:00:27 GMT (envelope-from zcore@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r8EG0RMG019599 for svn-soc-all@FreeBSD.org; Sat, 14 Sep 2013 16:00:27 GMT (envelope-from zcore@FreeBSD.org) Date: Sat, 14 Sep 2013 16:00:27 GMT Message-Id: <201309141600.r8EG0RMG019599@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to zcore@FreeBSD.org using -f From: zcore@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r257333 - soc2013/zcore/head/usr.sbin/bhyve MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 14 Sep 2013 16:00:27 -0000 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); }