[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
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |