Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754295AbbKMNDW (ORCPT ); Fri, 13 Nov 2015 08:03:22 -0500 Received: from relmlor3.renesas.com ([210.160.252.173]:62123 "EHLO relmlie2.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753039AbbKMNDT convert rfc822-to-8bit (ORCPT ); Fri, 13 Nov 2015 08:03:19 -0500 X-IronPort-AV: E=Sophos;i="5.20,287,1444662000"; d="scan'208";a="199714965" From: Phil Edworthy To: Arnd Bergmann CC: "linux-arm-kernel@lists.infradead.org" , "Liviu.Dudau@arm.com" , Lorenzo Pieralisi , Magnus , "linux-pci@vger.kernel.org" , Will Deacon , "linux-kernel@vger.kernel.org" , Bjorn Helgaas Subject: RE: PCIe host controller behind IOMMU on ARM Thread-Topic: PCIe host controller behind IOMMU on ARM Thread-Index: AdEXBXpsqoonZ+nqRTu1yvYRg99bGAABv/qAAAApWPAAASaHgAAAPSUwAPRcWiAAcokIAAAe/r+AAAFLFIAACM5fkAAEt8OAACffjcA= Date: Fri, 13 Nov 2015 13:03:11 +0000 Message-ID: References: <6255198.JqytBn7T9E@wuerfel> <4169020.aC5VXkILQm@wuerfel> In-Reply-To: <4169020.aC5VXkILQm@wuerfel> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=phil.edworthy@renesas.com; x-originating-ip: [193.141.220.21] x-microsoft-exchange-diagnostics: 1;PS1PR06MB1178;5:fiLX6TbpIEbRVq50uCJuIdUJu8OoKFDmHfVmmtgaotOd4fTjoSOBQTEg+pfna+BKMSTqiRunKknOf3wh3jyrEqqLKzt+s2uW4djpWOkQvRm395pVrrOKZ9Jf8n1jJUAODr6hfQrQPxGJ2lEkKPOcfg==;24:sIF8dpNh/rkeuINPrwFBRCgSbjzfYT/wGCxq3opRm/S52nXtbl6KMaB9Owf+0KwrjL/b75Yb9g81NfuvUhlQlCg7p6A1oDcrD08yIec04FQ=;20:3Awx/vTd4Cxc+c+NxyMEue+M7qoDLnpDGohvM4C/S86eN/fgMsc51xyIpejEuK0NMMjyAcyyqQM0mqGjWSION3esMKFi9jLi52P4Yd4nr5MKXe3nDYVV/zJ97gF/h+XfipQxMp9zKJ+a9zun8ZwXWDlkyM9Sg0hpkHTppUfjLfY= x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:PS1PR06MB1178; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(601004)(2401047)(5005006)(520078)(8121501046)(10201501046)(3002001);SRVR:PS1PR06MB1178;BCL:0;PCL:0;RULEID:;SRVR:PS1PR06MB1178; x-forefront-prvs: 0759F7A50A x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(6009001)(24454002)(189002)(40764003)(199003)(110136002)(81156007)(189998001)(33656002)(87936001)(76576001)(5007970100001)(5001920100001)(105586002)(5004730100002)(2900100001)(5001960100002)(66066001)(106356001)(97736004)(2950100001)(92566002)(11100500001)(5002640100001)(5003600100002)(50986999)(101416001)(5008740100001)(86362001)(102836002)(74316001)(54356999)(122556002)(40100003)(76176999)(93886004)(10400500002)(77096005);DIR:OUT;SFP:1102;SCL:1;SRVR:PS1PR06MB1178;H:PS1PR06MB1180.apcprd06.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; spamdiagnosticoutput: 1:23 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Nov 2015 13:03:11.2373 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 53d82571-da19-47e4-9cb4-625a166a4a2a X-MS-Exchange-Transport-CrossTenantHeadersStamped: PS1PR06MB1178 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3523 Lines: 73 Hi Arnd, On 12 November 2015 16:17, Arnd Bergmann wrote: > On Thursday 12 November 2015 15:33:41 Phil Edworthy wrote: > > On 12 November 2015 09:49, Arnd Bergmann wrote: > > > On Thursday 12 November 2015 09:26:33 Phil Edworthy wrote: > > > > On 11 November 2015 18:25, LIviu wrote: > > > > > On Mon, Nov 09, 2015 at 12:32:13PM +0000, Phil Edworthy wrote: > > > > > > of_dma_configure calls of_dma_get_range to do all this for the PCIe host, > > > and then calls arch_setup_dma_ops() so the architecture specific code can > > > enforce the limits in dma_set_mask and pick an appropriate set of dma > > > operations. The missing part is in the implementation of > arch_setup_dma_ops, > > > which currently happily ignores the base and limit. > > I don't think it's as simple as that, though I could be wrong! > > > > First off, of_dma_configure() sets a default coherent_dma_mask to 4GiB. > > This default is set for the 'platform soc' device. For my own testing I increased > > this to DMA_BIT_MASK(63). Note that setting it to DMA_BIT_MASK(64) causes > > boot failure that I haven't looked into. > > Most platform devices actually need the 32-bit mask, so we intentionally > followed what PCI does here and default to that and require platform drivers > to explicitly ask for a larger mask if they need it. Ok, that makes sense. > > Then pci_device_add() sets the devices coherent_dma_mask to 4GiB before > > calling of_pci_dma_configure(). I assume it does this on the basis that this is a > > good default for PCI drivers that don't call dma_set_mask(). > > So if arch_setup_dma_ops() walks up the parents to limit the mask, you'll hit > > this mask. > > arch_setup_dma_ops() does not walk up the hierarchy, of_dma_configure() > does this before calling arch_setup_dma_ops(). The PCI devices start out > with the 32-bit mask, but the limit should be whatever PCI host uses. Ok, so of_dma_configure() could walk up the tree and restrict the dma mask to whatever parents limit it to. Then it could be overridden by a dma-ranges entry in the DT node, right? If so, one problem I can see is PCI controllers already use the dma-ranges binding but with 3 address cells since it also specifies the PCI address range. I noticed that of_dma_get_range() skips straight to the parent node. Shouldn't it attempt to get the dma-ranges for the device's node first? I mean most hardware is limited by the peripheral's capabilities, not the bus. If fact, of_dma_get_range() gets the number of address and size cells from the device node, but gets the dma-ranges from the parent. That seems a little odd to me. The only other problem I can see is that currently all PCI drivers can try to set their dma mask to 64 bits. At the moment that succeeds because there are no checks. Until devices using them have their DTs updated with dma-ranges, we would be limiting them to a 32 bit mask. I guess that's not much of an issue in practice. > > Finally, dma_set_mask_and_coherent() is called from the PCI card driver > > but it doesn't check the parents dma masks either. > > The way I think this should work is that arch_setup_dma_ops() stores the > allowed mask in the struct device, and that dma_set_mask compares the > mask against that. That makes sense. Thanks for your help, Phil -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/