From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Return-Path: Subject: Re: Neophyte questions about PCIe To: Bjorn Helgaas 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 References: <20170308151724.GA20780@bhelgaas-glaptop.roam.corp.google.com> <9ba05c2c-57ef-b2c0-6a7c-457c392d98b5@free.fr> <20170313214024.GD8232@bhelgaas-glaptop.roam.corp.google.com> From: Mason Message-ID: <826d0a3f-753f-0330-5792-e11beb78d6bf@free.fr> Date: Mon, 13 Mar 2017 22:57:48 +0100 MIME-Version: 1.0 In-Reply-To: <20170313214024.GD8232@bhelgaas-glaptop.roam.corp.google.com> Content-Type: text/plain; charset=ISO-8859-15 List-ID: On 13/03/2017 22:40, Bjorn Helgaas wrote: > 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. Even when Linux is not able to map the BAR, since it's too large to fit in the mem window? > 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. In fact, that's what I used to do in a previous version :-) I'd like to push support for this PCIe controller upstream. Is the code I posted on the right track? Maybe I can post a RFC patch tomorrow? Regards.