From owner-svn-soc-all@freebsd.org Fri Aug 5 13:55:48 2016 Return-Path: Delivered-To: svn-soc-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 383D0BAFEB2 for ; Fri, 5 Aug 2016 13:55:48 +0000 (UTC) (envelope-from vincenzo@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 1DE5A1E72 for ; Fri, 5 Aug 2016 13:55:48 +0000 (UTC) (envelope-from vincenzo@FreeBSD.org) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.15.2/8.15.2) with ESMTP id u75DtlZr039004 for ; Fri, 5 Aug 2016 13:55:47 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u75Dtlc6038963 for svn-soc-all@FreeBSD.org; Fri, 5 Aug 2016 13:55:47 GMT (envelope-from vincenzo@FreeBSD.org) Date: Fri, 5 Aug 2016 13:55:47 GMT Message-Id: <201608051355.u75Dtlc6038963@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to vincenzo@FreeBSD.org using -f From: vincenzo@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r307220 - soc2016/vincenzo/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.22 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: Fri, 05 Aug 2016 13:55:48 -0000 Author: vincenzo Date: Fri Aug 5 13:55:46 2016 New Revision: 307220 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=307220 Log: ptnet: add PCI device stub Added: soc2016/vincenzo/head/usr.sbin/bhyve/pci_ptnetmap_netif.c Modified: soc2016/vincenzo/head/usr.sbin/bhyve/Makefile Modified: soc2016/vincenzo/head/usr.sbin/bhyve/Makefile ============================================================================== --- soc2016/vincenzo/head/usr.sbin/bhyve/Makefile Fri Aug 5 13:54:55 2016 (r307219) +++ soc2016/vincenzo/head/usr.sbin/bhyve/Makefile Fri Aug 5 13:55:46 2016 (r307220) @@ -33,6 +33,7 @@ pci_lpc.c \ pci_passthru.c \ pci_ptnetmap_memdev.c \ + pci_ptnetmap_netif.c \ pci_virtio_block.c \ pci_virtio_net.c \ pci_virtio_rnd.c \ Added: soc2016/vincenzo/head/usr.sbin/bhyve/pci_ptnetmap_netif.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2016/vincenzo/head/usr.sbin/bhyve/pci_ptnetmap_netif.c Fri Aug 5 13:55:46 2016 (r307220) @@ -0,0 +1,130 @@ +/* + * Copyright (C) 2016 Vincenzo Maffione + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include + +#include /* IFNAMSIZ */ +#include +#include + +#include +#include + +#include "bhyverun.h" +#include "pci_emul.h" + +#ifndef PTNET_CSB_ALLOC +#error "Hypervisor-allocated CSB not supported" +#endif + + +struct ptnet_softc { + struct pci_devinst *pi; /* PCI device instance */ +}; + +static uint64_t +ptnet_bar_read(struct vmctx *ctx, int vcpu, struct pci_devinst *pi, + int baridx, uint64_t offset, int size) +{ + struct ptnet_softc *sc = pi->pi_arg; + + if (sc == NULL) + return 0; + + if (baridx == PTNETMAP_IO_PCI_BAR) { + switch (offset) { + } + } + + printf("%s: Unexpected register read [bar %u, offset %lx size %d]\n", + __func__, baridx, offset, size); + + return 0; +} + +static void +ptnet_bar_write(struct vmctx *ctx, int vcpu, struct pci_devinst *pi, + int baridx, uint64_t offset, int size, uint64_t value) +{ + struct ptnet_softc *sc = pi->pi_arg; + + if (sc == NULL) + return; + + printf("%s: Unexpected register write [bar %u, offset %lx size %d " + "value %lx]\n", __func__, baridx, offset, size, value); +} + +/* PCI device initialization. */ +static int +ptnet_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts) +{ + struct ptnet_softc *sc; + int ret; + + sc = calloc(1, sizeof(*sc)); + if (sc == NULL) { + fprintf(stderr, "%s: out of memory\n", __func__); + return -1; + } + + /* Link our softc in the pci_devinst. */ + pi->pi_arg = sc; + sc->pi = pi; + + /* Initialize PCI configuration space. */ + pci_set_cfgdata16(pi, PCIR_VENDOR, PTNETMAP_PCI_VENDOR_ID); + pci_set_cfgdata16(pi, PCIR_DEVICE, PTNETMAP_PCI_NETIF_ID); + pci_set_cfgdata8(pi, PCIR_CLASS, PCIC_NETWORK); + pci_set_cfgdata8(pi, PCIR_SUBCLASS, PCIS_NETWORK_ETHERNET); + pci_set_cfgdata16(pi, PCIR_SUBDEV_0, 1); + pci_set_cfgdata16(pi, PCIR_SUBVEND_0, PTNETMAP_PCI_VENDOR_ID); + + /* Allocate a BAR for an I/O region. */ + ret = pci_emul_alloc_bar(pi, PTNETMAP_IO_PCI_BAR, PCIBAR_IO, + PTNET_IO_MASK + 1); + if (ret) { + fprintf(stderr, "%s: failed to allocate BAR [%d]\n", + __func__, ret); + return ret; + } + + return 0; +} + +struct pci_devemu pci_de_ptnet = { + .pe_emu = "ptnet", + .pe_init = ptnet_init, + .pe_barwrite = ptnet_bar_write, + .pe_barread = ptnet_bar_read, +}; +PCI_EMUL_SET(pci_de_ptnet);