From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48254) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WzgaL-0001s2-F9 for qemu-devel@nongnu.org; Wed, 25 Jun 2014 02:21:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WzgaC-0003A6-EQ for qemu-devel@nongnu.org; Wed, 25 Jun 2014 02:21:33 -0400 Received: from mail-wi0-x235.google.com ([2a00:1450:400c:c05::235]:45909) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WzgaC-00039c-7x for qemu-devel@nongnu.org; Wed, 25 Jun 2014 02:21:24 -0400 Received: by mail-wi0-f181.google.com with SMTP id n3so1792927wiv.8 for ; Tue, 24 Jun 2014 23:21:21 -0700 (PDT) Sender: Paolo Bonzini Message-ID: <53AA6A5B.7050807@redhat.com> Date: Wed, 25 Jun 2014 08:21:15 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1403662641-28526-1-git-send-email-tiejun.chen@intel.com> <1403662641-28526-2-git-send-email-tiejun.chen@intel.com> In-Reply-To: <1403662641-28526-2-git-send-email-tiejun.chen@intel.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [v5][PATCH 1/5] xen, gfx passthrough: basic graphics passthrough support List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Tiejun Chen , anthony.perard@citrix.com, stefano.stabellini@eu.citrix.com, mst@redhat.com, Kelly.Zytaruk@amd.com Cc: peter.maydell@linaro.org, xen-devel@lists.xensource.com, allen.m.kay@intel.com, qemu-devel@nongnu.org, anthony@codemonkey.ws, yang.z.zhang@intel.com Il 25/06/2014 04:17, Tiejun Chen ha scritto: > +static int get_vgabios(unsigned char *buf, XenHostPCIDevice *dev) > +{ > + char rom_file[64]; > + FILE *fp; > + uint8_t val; > + struct stat st; > + uint16_t magic = 0; > + int ret = 0; > + > + snprintf(rom_file, sizeof(rom_file), > + "/sys/bus/pci/devices/%04x:%02x:%02x.%d/rom", > + dev->domain, dev->bus, dev->dev, > + dev->func); > + > + if (stat(rom_file, &st)) { > + return -ENODEV; > + } > + > + if (access(rom_file, F_OK)) { > + XEN_PT_ERR(NULL, "pci-assign: Insufficient privileges for %s", > + rom_file); > + return -ENODEV; > + } These two checks (stat and access) are useless. > + /* Write "1" to the ROM file to enable it */ > + fp = fopen(rom_file, "r+"); > + if (fp == NULL) { > + return -EACCES; > + } > + val = 1; > + if (fwrite(&val, 1, 1, fp) != 1) { > + XEN_PT_LOG("%s\n", "Failed to enable pci-sysfs rom file"); > + ret = -EIO; > + goto close_rom; > + } > + fseek(fp, 0, SEEK_SET); > + > + /* > + * Check if it a real bios extension. > + * The magic number is 0xAA55. > + */ > + if (!fread(&magic, sizeof(magic), 1, fp)) { > + XEN_PT_ERR(NULL, "VGA: can't get magic.\n"); > + ret = -ENODEV; > + goto close_rom; > + } > + if (magic != 0xAA55) { > + XEN_PT_ERR(NULL, "VGA: wrong magic %x.\n", magic); > + ret = -ENODEV; > + goto close_rom; > + } > + fseek(fp, 0, SEEK_SET); > + > + if (!fread(buf, 1, st.st_size, fp)) { > + XEN_PT_ERR(NULL, "VGA: pci-assign: Cannot read from host %s", rom_file); > + XEN_PT_LOG(NULL, "VGA: Device option ROM contents are probably invalid " > + "(check dmesg).\nSkip option ROM probe with rombar=0, " > + "or load from file with romfile=\n"); > + } > + Why is this graphics passthrough specific? Should QEMU's Xen PCI passthrough read ROM BAR contents from network cards too, for example? Paolo From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paolo Bonzini Subject: Re: [v5][PATCH 1/5] xen, gfx passthrough: basic graphics passthrough support Date: Wed, 25 Jun 2014 08:21:15 +0200 Message-ID: <53AA6A5B.7050807@redhat.com> References: <1403662641-28526-1-git-send-email-tiejun.chen@intel.com> <1403662641-28526-2-git-send-email-tiejun.chen@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1403662641-28526-2-git-send-email-tiejun.chen@intel.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+gceq-qemu-devel=gmane.org@nongnu.org Sender: qemu-devel-bounces+gceq-qemu-devel=gmane.org@nongnu.org To: Tiejun Chen , anthony.perard@citrix.com, stefano.stabellini@eu.citrix.com, mst@redhat.com, Kelly.Zytaruk@amd.com Cc: peter.maydell@linaro.org, xen-devel@lists.xensource.com, allen.m.kay@intel.com, qemu-devel@nongnu.org, anthony@codemonkey.ws, yang.z.zhang@intel.com List-Id: xen-devel@lists.xenproject.org Il 25/06/2014 04:17, Tiejun Chen ha scritto: > +static int get_vgabios(unsigned char *buf, XenHostPCIDevice *dev) > +{ > + char rom_file[64]; > + FILE *fp; > + uint8_t val; > + struct stat st; > + uint16_t magic = 0; > + int ret = 0; > + > + snprintf(rom_file, sizeof(rom_file), > + "/sys/bus/pci/devices/%04x:%02x:%02x.%d/rom", > + dev->domain, dev->bus, dev->dev, > + dev->func); > + > + if (stat(rom_file, &st)) { > + return -ENODEV; > + } > + > + if (access(rom_file, F_OK)) { > + XEN_PT_ERR(NULL, "pci-assign: Insufficient privileges for %s", > + rom_file); > + return -ENODEV; > + } These two checks (stat and access) are useless. > + /* Write "1" to the ROM file to enable it */ > + fp = fopen(rom_file, "r+"); > + if (fp == NULL) { > + return -EACCES; > + } > + val = 1; > + if (fwrite(&val, 1, 1, fp) != 1) { > + XEN_PT_LOG("%s\n", "Failed to enable pci-sysfs rom file"); > + ret = -EIO; > + goto close_rom; > + } > + fseek(fp, 0, SEEK_SET); > + > + /* > + * Check if it a real bios extension. > + * The magic number is 0xAA55. > + */ > + if (!fread(&magic, sizeof(magic), 1, fp)) { > + XEN_PT_ERR(NULL, "VGA: can't get magic.\n"); > + ret = -ENODEV; > + goto close_rom; > + } > + if (magic != 0xAA55) { > + XEN_PT_ERR(NULL, "VGA: wrong magic %x.\n", magic); > + ret = -ENODEV; > + goto close_rom; > + } > + fseek(fp, 0, SEEK_SET); > + > + if (!fread(buf, 1, st.st_size, fp)) { > + XEN_PT_ERR(NULL, "VGA: pci-assign: Cannot read from host %s", rom_file); > + XEN_PT_LOG(NULL, "VGA: Device option ROM contents are probably invalid " > + "(check dmesg).\nSkip option ROM probe with rombar=0, " > + "or load from file with romfile=\n"); > + } > + Why is this graphics passthrough specific? Should QEMU's Xen PCI passthrough read ROM BAR contents from network cards too, for example? Paolo