[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] Re: [Qemu-devel] [PATCH V2 02/10] Introduce HostPCIDevice to access a pci device on the host.



On Thu, Oct 20, 2011 at 11:57, Stefano Stabellini
<stefano.stabellini@xxxxxxxxxxxxx> wrote:
> On Wed, 19 Oct 2011, Anthony PERARD wrote:
>> Signed-off-by: Anthony PERARD <anthony.perard@xxxxxxxxxx>
>> ---
>> ÂMakefile.target   Â|  Â1 +
>> Âhw/host-pci-device.c | Â245 
>> ++++++++++++++++++++++++++++++++++++++++++++++++++
>> Âhw/host-pci-device.h | Â 75 +++++++++++++++
>> Â3 files changed, 321 insertions(+), 0 deletions(-)
>> Âcreate mode 100644 hw/host-pci-device.c
>> Âcreate mode 100644 hw/host-pci-device.h
>>
>> diff --git a/Makefile.target b/Makefile.target
>> index c518103..ca3420d 100644
>> --- a/Makefile.target
>> +++ b/Makefile.target
>> @@ -209,6 +209,7 @@ obj-$(CONFIG_NO_XEN) += xen-stub.o
>> Âobj-i386-$(CONFIG_XEN) += xen_platform.o
>>
>> Â# Xen PCI Passthrough
>> +obj-i386-$(CONFIG_XEN_PCI_PASSTHROUGH) += host-pci-device.o
>>
>> Â# Inter-VM PCI shared memory
>> ÂCONFIG_IVSHMEM =
>> diff --git a/hw/host-pci-device.c b/hw/host-pci-device.c
>> new file mode 100644
>> index 0000000..0f25fcf
>> --- /dev/null
>> +++ b/hw/host-pci-device.c
>> @@ -0,0 +1,245 @@
>> +/*
>> + * Copyright (C) 2011 Â Â Â Citrix Ltd.
>> + *
>> + * This work is licensed under the terms of the GNU GPL, version 2. ÂSee
>> + * the COPYING file in the top-level directory.
>> + *
>> + */
>> +
>> +#include "qemu-common.h"
>> +#include "host-pci-device.h"
>> +
>> +static int path_to(const HostPCIDevice *d,
>> + Â Â Â Â Â Â Â Â Â const char *name, char *buf, ssize_t size)
>> +{
>> + Â Âreturn snprintf(buf, size, "/sys/bus/pci/devices/%04x:%02x:%02x.%x/%s",
>> + Â Â Â Â Â Â Â Â Â Âd->domain, d->bus, d->dev, d->func, name);
>> +}
>> +
>> +static int get_resource(HostPCIDevice *d)
>> +{
>> + Â Âint i, rc = 0;
>> + Â ÂFILE *f;
>> + Â Âchar path[PATH_MAX];
>> + Â Âunsigned long long start, end, flags, size;
>> +
>> + Â Âpath_to(d, "resource", path, sizeof (path));
>> + Â Âf = fopen(path, "r");
>> + Â Âif (!f) {
>> + Â Â Â Âfprintf(stderr, "Error: Can't open %s: %s\n", path, 
>> strerror(errno));
>> + Â Â Â Âreturn -1;
>
> it would be better to return a proper error code, rather than just -1

probably -errno will do it.


>> + Â Â}
>> +
>> + Â Âfor (i = 0; i < PCI_NUM_REGIONS; i++) {
>> + Â Â Â Âif (fscanf(f, "%llx %llx %llx", &start, &end, &flags) != 3) {
>> + Â Â Â Â Â Âfprintf(stderr, "Error: Syntax error in %s\n", path);
>> + Â Â Â Â Â Ârc = -1;
>
> Ditto

probably 1 with a define on the top of the file.

>> + Â Â Â Â Â Âbreak;
>> + Â Â Â Â}
>> + Â Â Â Âif (start) {
>> + Â Â Â Â Â Âsize = end - start + 1;
>> + Â Â Â Â} else {
>> + Â Â Â Â Â Âsize = 0;
>> + Â Â Â Â}
>> +
>> + Â Â Â Âif (i < PCI_ROM_SLOT) {
>> + Â Â Â Â Â Âd->io_regions[i].base_addr = start;
>> + Â Â Â Â Â Âd->io_regions[i].size = size;
>> + Â Â Â Â Â Âd->io_regions[i].flags = flags;
>> + Â Â Â Â} else {
>> + Â Â Â Â Â Âd->rom.base_addr = start;
>> + Â Â Â Â Â Âd->rom.size = size;
>> + Â Â Â Â Â Âd->rom.flags = flags;
>> + Â Â Â Â}
>> + Â Â}
>> +
>> + Â Âfclose(f);
>> + Â Âreturn rc;
>> +}

[...]

>> +
>> +uint32_t host_pci_find_ext_cap_offset(HostPCIDevice *d, uint32_t cap)
>> +{
>> + Â Âuint32_t header = 0;
>> + Â Âint max_cap = 480;
>> + Â Âint pos = 0x100;
>
> could you used some defined constants here?

Yes, I will.

>> + Â Âdo {
>> + Â Â Â Âheader = host_pci_get_long(d, pos);
>> + Â Â Â Â/*
>> + Â Â Â Â * If we have no capabilities, this is indicated by cap ID,
>> + Â Â Â Â * cap version and next pointer all being 0.
>> + Â Â Â Â */
>> + Â Â Â Âif (header == 0) {
>> + Â Â Â Â Â Âbreak;
>> + Â Â Â Â}
>> +
>> + Â Â Â Âif (PCI_EXT_CAP_ID(header) == cap) {
>> + Â Â Â Â Â Âreturn pos;
>> + Â Â Â Â}
>> +
>> + Â Â Â Âpos = PCI_EXT_CAP_NEXT(header);
>> + Â Â Â Âif (pos < 0x100) {
>> + Â Â Â Â Â Âbreak;
>> + Â Â Â Â}
>> +
>> + Â Â Â Âmax_cap--;
>> + Â Â} while (max_cap > 0);
>> +
>> + Â Âreturn 0;
>> +}


-- 
Anthony PERARD

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.