From owner-svn-src-projects@FreeBSD.ORG Tue Jun 7 18:35:45 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C0EF1106564A; Tue, 7 Jun 2011 18:35:45 +0000 (UTC) (envelope-from grehan@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id A68738FC12; Tue, 7 Jun 2011 18:35:45 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p57IZjGX095527; Tue, 7 Jun 2011 18:35:45 GMT (envelope-from grehan@svn.freebsd.org) Received: (from grehan@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p57IZjan095524; Tue, 7 Jun 2011 18:35:45 GMT (envelope-from grehan@svn.freebsd.org) Message-Id: <201106071835.p57IZjan095524@svn.freebsd.org> From: Peter Grehan Date: Tue, 7 Jun 2011 18:35:45 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r222830 - projects/bhyve/usr.sbin/bhyve X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Jun 2011 18:35:45 -0000 Author: grehan Date: Tue Jun 7 18:35:45 2011 New Revision: 222830 URL: http://svn.freebsd.org/changeset/base/222830 Log: Allow access to the device's config area with any size i/o access at any offset. This is now spec-compliant. Modified: projects/bhyve/usr.sbin/bhyve/pci_virtio_block.c projects/bhyve/usr.sbin/bhyve/pci_virtio_net.c Modified: projects/bhyve/usr.sbin/bhyve/pci_virtio_block.c ============================================================================== --- projects/bhyve/usr.sbin/bhyve/pci_virtio_block.c Tue Jun 7 17:40:33 2011 (r222829) +++ projects/bhyve/usr.sbin/bhyve/pci_virtio_block.c Tue Jun 7 18:35:45 2011 (r222830) @@ -439,6 +439,7 @@ uint32_t pci_vtblk_read(struct pci_devinst *pi, int baridx, int offset, int size) { struct pci_vtblk_softc *sc = pi->pi_arg; + void *ptr; uint32_t value; if (offset + size > VTBLK_REGSZ) { @@ -481,8 +482,15 @@ pci_vtblk_read(struct pci_devinst *pi, i sc->vbsc_isr = 0; /* a read clears this flag */ break; case VTBLK_R_CFG ... VTBLK_R_CFG_END: - assert(size == 1); - value = *((uint8_t *)&sc->vbsc_cfg + offset - VTBLK_R_CFG); + assert(size + offset <= (VTBLK_R_CFG_END + 1)); + ptr = (uint8_t *)&sc->vbsc_cfg + offset - VTBLK_R_CFG; + if (size == 1) { + value = *(uint8_t *) ptr; + } else if (size == 2) { + value = *(uint16_t *) ptr; + } else { + value = *(uint32_t *) ptr; + } break; default: DPRINTF(("vtblk: unknown i/o read offset %d\n\r", offset)); Modified: projects/bhyve/usr.sbin/bhyve/pci_virtio_net.c ============================================================================== --- projects/bhyve/usr.sbin/bhyve/pci_virtio_net.c Tue Jun 7 17:40:33 2011 (r222829) +++ projects/bhyve/usr.sbin/bhyve/pci_virtio_net.c Tue Jun 7 18:35:45 2011 (r222830) @@ -594,7 +594,8 @@ pci_vtnet_write(struct pci_devinst *pi, uint32_t value) { struct pci_vtnet_softc *sc = pi->pi_arg; - + void *ptr; + if (offset + size > VTNET_REGSZ) { DPRINTF(("vtnet_write: 2big, offset %d size %d\n", offset, size)); @@ -632,11 +633,19 @@ pci_vtnet_write(struct pci_devinst *pi, case VTNET_R_CFG3: case VTNET_R_CFG4: case VTNET_R_CFG5: + assert((size + offset) <= (VTNET_R_CFG5 + 1)); + ptr = &sc->vsc_macaddr[offset - VTNET_R_CFG0]; /* * The driver is allowed to change the MAC address */ - assert(size == 1); sc->vsc_macaddr[offset - VTNET_R_CFG0] = value; + if (size == 1) { + *(uint8_t *) ptr = value; + } else if (size == 2) { + *(uint16_t *) ptr = value; + } else { + *(uint32_t *) ptr = value; + } break; case VTCFG_R_HOSTCAP: case VTCFG_R_QNUM: @@ -658,6 +667,7 @@ uint32_t pci_vtnet_read(struct pci_devinst *pi, int baridx, int offset, int size) { struct pci_vtnet_softc *sc = pi->pi_arg; + void *ptr; uint32_t value; if (offset + size > VTNET_REGSZ) { @@ -708,16 +718,23 @@ pci_vtnet_read(struct pci_devinst *pi, i case VTNET_R_CFG3: case VTNET_R_CFG4: case VTNET_R_CFG5: - assert(size == 1); - value = sc->vsc_macaddr[offset - VTNET_R_CFG0]; + assert((size + offset) <= (VTNET_R_CFG5 + 1)); + ptr = &sc->vsc_macaddr[offset - VTNET_R_CFG0]; + if (size == 1) { + value = *(uint8_t *) ptr; + } else if (size == 2) { + value = *(uint16_t *) ptr; + } else { + value = *(uint32_t *) ptr; + } break; case VTNET_R_CFG6: - assert(size == 1); - value = 0x01; /* XXX link always up */ + assert(size != 4); + value = 0x01; /* XXX link always up */ break; case VTNET_R_CFG7: assert(size == 1); - value = 0; /* link status is in the LSB */ + value = 0; /* XXX link status in LSB */ break; default: DPRINTF(("vtnet: unknown i/o read offset %d\n\r", offset));