From: Stefano Stabellini Subject: Re: [PATCH 1/2] qemu-xen: Pass through, utility functions Date: Wed, 1 Feb 2012 14:47:17 +0000 Message-ID: References: <1328035180-26966-1-git-send-email-jean.guyader@eu.citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1328035180-26966-1-git-send-email-jean.guyader@eu.citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Jean Guyader Cc: "allen.m.kay@intel.com" , "xen-devel@lists.xensource.com" , Ian Jackson , Jean Guyader List-Id: xen-devel@lists.xenproject.org On Tue, 31 Jan 2012, Jean Guyader wrote: > Add a function to map a specific bar into a pt_dev. > > Add a function that gets called everytime the bar of a pass > through device gets remap. > > Signed-off-by: Jean Guyader > --- > hw/pass-through.c | 34 ++++++++++++++++++++++++++++++++++ > hw/pass-through.h | 3 +++ > hw/pt-graphics.c | 7 +++++++ > 3 files changed, 44 insertions(+), 0 deletions(-) Could you please send inline patches in the future? > diff --git a/hw/pass-through.c b/hw/pass-through.c > index dbe8804..1bdb223 100644 > --- a/hw/pass-through.c > +++ b/hw/pass-through.c > @@ -93,6 +93,7 @@ > #include > #include > #include > +#include > > extern int gfx_passthru; > int igd_passthru = 0; > @@ -1155,6 +1156,9 @@ static void pt_iomem_map(PCIDevice *d, int i, uint32_t e_phys, uint32_t e_size, > if ( e_size == 0 ) > return; > > + if (assigned_device->pci_dev->device_class == 0x0300) > + pt_graphic_bar_remap(assigned_device, i, first_map, DPCI_ADD_MAPPING); > + > if ( !first_map && old_ebase != -1 ) > { > if ( has_msix_mapping(assigned_device, i) ) Wouldn't it be better if we move this into _pt_iomem_helper? > @@ -1969,6 +1973,9 @@ static void pt_unregister_regions(struct pt_dev *assigned_device) > if ( type == PCI_ADDRESS_SPACE_MEM || > type == PCI_ADDRESS_SPACE_MEM_PREFETCH ) > { > + if (assigned_device->pci_dev->device_class == 0x0300) > + pt_graphic_bar_remap(assigned_device, i, 0, DPCI_REMOVE_MAPPING); > + > ret = xc_domain_memory_mapping(xc_handle, domid, > assigned_device->bases[i].e_physbase >> XC_PAGE_SHIFT, > assigned_device->bases[i].access.maddr >> XC_PAGE_SHIFT, > > @@ -2101,6 +2108,33 @@ int pt_pci_host_write(struct pci_dev *pci_dev, u32 addr, u32 val, int len) > return ret; > } > > +int pt_pci_host_map_bar(struct pt_dev *pt_dev, int bar) > +{ > + int fd; > + struct stat s; > + uint8_t *map; > + > + char filename[1024]; > + > + snprintf(filename, 1024, "/sys/bus/pci/devices/0000:%02x:%02x.%01x/resource%d", > + pt_dev->pci_dev->bus, > + pt_dev->pci_dev->dev, > + pt_dev->pci_dev->func, > + bar); > + fd = open(filename, O_RDWR | O_SYNC); > + if (fd < 0) > + return fd; > + fstat(fd, &s); > + > + map = mmap(0, s.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); > + if (map != MAP_FAILED) > + { > + pt_dev->bases[bar].map = map; > + return 0; > + } > + return errno; > +} > + > /* parse BAR */ > static int pt_bar_reg_parse( > struct pt_dev *ptdev, struct pt_reg_info_tbl *reg) > diff --git a/hw/pass-through.h b/hw/pass-through.h > index 884139c..26e6ff1 100644 > --- a/hw/pass-through.h > +++ b/hw/pass-through.h > @@ -170,6 +170,7 @@ struct pt_region { > uint64_t pio_base; > uint64_t u; > } access; > + uint8_t *map; > }; > > struct pt_msi_info { > @@ -414,6 +415,7 @@ uint8_t pci_intx(struct pt_dev *ptdev); > struct pci_dev *pt_pci_get_dev(int bus, int dev, int func); > u32 pt_pci_host_read(struct pci_dev *pci_dev, u32 addr, int len); > int pt_pci_host_write(struct pci_dev *pci_dev, u32 addr, u32 val, int len); > +int pt_pci_host_map_bar(struct pt_dev *pt_dev, int bar); > void intel_pch_init(PCIBus *bus); > int register_vga_regions(struct pt_dev *real_device); > int unregister_vga_regions(struct pt_dev *real_device); > @@ -422,6 +424,7 @@ PCIBus *intel_pci_bridge_init(PCIBus *bus, int devfn, uint16_t vid, > uint16_t did, const char *name, uint16_t revision); > void igd_pci_write(PCIDevice *pci_dev, uint32_t config_addr, uint32_t val, int len); > uint32_t igd_pci_read(PCIDevice *pci_dev, uint32_t config_addr, int len); > +void pt_graphic_bar_remap(struct pt_dev *real_device, int bar, int first_map, int map); rename "int map" to "int op" for clarity > > #endif /* __PASSTHROUGH_H__ */ > > diff --git a/hw/pt-graphics.c b/hw/pt-graphics.c > index fec7390..5d5e5da 100644 > --- a/hw/pt-graphics.c > +++ b/hw/pt-graphics.c > @@ -94,6 +94,13 @@ uint32_t igd_pci_read(PCIDevice *pci_dev, uint32_t config_addr, int len) > } > > /* > + * Callback whenever a bar get remapped > + */ > +void pt_graphic_bar_remap(struct pt_dev *real_device, int bar, int first_map, int map) > +{ > +} > + > +/* > * register VGA resources for the domain with assigned gfx > */ > int register_vga_regions(struct pt_dev *real_device)