From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.kernel.org ([198.145.29.136]:55276 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751047AbdCMVk3 (ORCPT ); Mon, 13 Mar 2017 17:40:29 -0400 Date: Mon, 13 Mar 2017 16:40:24 -0500 From: Bjorn Helgaas To: Mason Cc: linux-pci , linux-usb , Rob Herring , Arnd Bergmann , Ard Biesheuvel , Marc Zyngier , Thibaud Cornic , David Laight , Phuong Nguyen , Shawn Lin , Robin Murphy , Linux ARM , Kevin Hilman Subject: Re: Neophyte questions about PCIe Message-ID: <20170313214024.GD8232@bhelgaas-glaptop.roam.corp.google.com> References: <20170308151724.GA20780@bhelgaas-glaptop.roam.corp.google.com> <9ba05c2c-57ef-b2c0-6a7c-457c392d98b5@free.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii In-Reply-To: Sender: linux-pci-owner@vger.kernel.org List-ID: On Sat, Mar 11, 2017 at 11:57:56AM +0100, Mason wrote: > On 10/03/2017 18:49, Mason wrote: > > static void tango_pcie_bar_quirk(struct pci_dev *dev) > > { > > struct pci_bus *bus = dev->bus; > > > > printk("%s: bus=%d devfn=%d\n", __func__, bus->number, dev->devfn); > > > > pci_write_config_dword(dev, PCI_BASE_ADDRESS_0, 0x80000004); > > } > > DECLARE_PCI_FIXUP_FINAL(0x1105, PCI_ANY_ID, tango_pcie_bar_quirk); > > And this is where the elusive "black magic" happens. > > Is it "safe" to configure a BAR behind Linux's back? No. Linux maintains a struct resource for every BAR. This quirk makes the BAR out of sync with the resource, so Linux no longer has an accurate idea of what bus address space is consumed and what is available. Normally a BAR is for mapping device registers into PCI bus address space. If this BAR controls how the RC forwards PCI DMA transactions to RAM, then it's not really a BAR and you should prevent Linux from seeing it as a BAR. You could do this by special-casing it in the config accessor so reads return 0 and writes are dropped. Then you could write the register in your host bridge driver safely because the PCI core would think the BAR is not implemented. Bjorn