Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp473768ybk; Wed, 20 May 2020 04:30:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwl06/bQdrnWNVJnaaAxQ9hz5uUk9N/KPqDxAyyhuDx+t3hhKtwepJPAHORt8ZqObItgGtR X-Received: by 2002:a50:e84b:: with SMTP id k11mr3053538edn.204.1589974218746; Wed, 20 May 2020 04:30:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589974218; cv=none; d=google.com; s=arc-20160816; b=WlLROVEWH58/FdBi4H62T1nn2f4PIvkJZcEumh6j06rPSeBXOAGWLiAGFvp9hpVf+t 2S1F6I9zGox0qjaeJiWIRvNkaQQSvwBavcCGrDDQIpbKUNfs4dOjxTa/tyRADDUm2y1k WoVu5L/N+NvO/B3M+pYaj9H1NsJnKjAEdCj8f7ATOhEEOLDkCekGoXI86YwskIKac8U7 Pfhp4x1xN48J0L16DdILqpwQTf4guwbMdE621a2F/dwg4azmo/lbWc5BglkhOTWWsHpI xuMFpUUNizoRH3iwr5dfRZusLkinbiBZ/DIUryfmalO6vegpoFF0ns0N0Ps8s1d+8v8v Zjeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:date:cc:to:from:subject:message-id; bh=vJNmee77BurqfJJFxQYCJJdQrCseTo3YMZMqk/h4I68=; b=pGU4F1YRWIIpKm90d51NAIFk3R57dicSuml9Vst/IiAfyoGpHome3sOYu0bT1noMnu Oj0B/AZ3fI/uQNvY+Be9Ozd0p3XY/a1XAtf73C2oP6wVbor46I3bY4/yA/GBU1FbNeqi 82A1tEEFszsV5zNyjCB8Hj3Si/Fsmau1XObWGQJD2FiOd2mffiCkMmNGiLlyi796NO/u OwUHLGzTFd3KXXeCAne+vPympox+QFH7ug5EnZprvzw20h2XXxupW/1Z4js+t8jvigg5 Z0UUDIh9mN1T8bGni9i9Jsea1vPfQLnys72AMiBejFNbPe0HGrF7Tqn14ibeZCQYfZ3R jCbA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dd15si1282128edb.187.2020.05.20.04.29.56; Wed, 20 May 2020 04:30:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726596AbgETL2i (ORCPT + 99 others); Wed, 20 May 2020 07:28:38 -0400 Received: from mx2.suse.de ([195.135.220.15]:47278 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726403AbgETL2i (ORCPT ); Wed, 20 May 2020 07:28:38 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 8F94FAD78; Wed, 20 May 2020 11:28:38 +0000 (UTC) Message-ID: <2aa6f276085319a5af7a96b3d7bdd0501641a7d7.camel@suse.de> Subject: Re: [PATCH 09/15] device core: Add ability to handle multiple dma offsets From: Nicolas Saenz Julienne To: Jim Quinlan Cc: Rob Herring , Frank Rowand , Christoph Hellwig , Marek Szyprowski , Robin Murphy , Greg Kroah-Hartman , Suzuki K Poulose , Saravana Kannan , Heikki Krogerus , "Rafael J. Wysocki" , Dan Williams , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE" , open list , "open list:DMA MAPPING HELPERS" Date: Wed, 20 May 2020 13:28:32 +0200 In-Reply-To: <20200519203419.12369-10-james.quinlan@broadcom.com> References: <20200519203419.12369-1-james.quinlan@broadcom.com> <20200519203419.12369-10-james.quinlan@broadcom.com> Content-Type: multipart/signed; micalg="pgp-sha256"; protocol="application/pgp-signature"; boundary="=-Ttdr9J6hcKekh9mdkCgm" User-Agent: Evolution 3.36.2 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --=-Ttdr9J6hcKekh9mdkCgm Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Jim, thanks for having a go at this! My two cents. On Tue, 2020-05-19 at 16:34 -0400, Jim Quinlan wrote: > The device variable 'dma_pfn_offset' is used to do a single > linear map between cpu addrs and dma addrs. The variable > 'dma_map' is added to struct device to point to an array > of multiple offsets which is required for some devices. >=20 > Signed-off-by: Jim Quinlan > --- [...] > --- a/include/linux/device.h > +++ b/include/linux/device.h > @@ -493,6 +493,8 @@ struct dev_links_info { > * @bus_dma_limit: Limit of an upstream bridge or bus which imposes a sm= aller > * DMA limit than the device itself supports. > * @dma_pfn_offset: offset of DMA memory range relatively of RAM > + * @dma_map: Like dma_pfn_offset but used when there are multiple > + * pfn offsets for multiple dma-ranges. > * @dma_parms: A low level driver may set these to teach IOMMU code > about > * segment limitations. > * @dma_pools: Dma pools (if dma'ble device). > @@ -578,7 +580,12 @@ struct device { > allocations such descriptors. */ > u64 bus_dma_limit; /* upstream dma constraint */ > unsigned long dma_pfn_offset; > - > +#ifdef CONFIG_DMA_PFN_OFFSET_MAP > + const void *dma_offset_map; /* Like dma_pfn_offset, but for > + * the unlikely case of multiple > + * offsets. If non-null, dma_pfn_offset > + * will be 0. */ I get a bad feeling about separating the DMA offset handling into two disti= nct variables. Albeit generally frowned upon, there is a fair amount of tricker= y around dev->dma_pfn_offset all over the kernel. usb_alloc_dev() comes to mi= nd for example. And this obviously doesn't play well with it. I feel a potenti= al solution to multiple DMA ranges should completely integrate with the curren= t device DMA handling code, without special cases, on top of that, be transpa= rent to the user. In more concrete terms, I'd repackage dev->bus_dma_limit and dev->dma_pfn_offset into a list/array of DMA range structures and adapt/cre= ate the relevant getter/setter functions so as for DMA users not to have to wor= ry about the specifics of a device's DMA constraints. For example, instead of editing dev->dma_pfn_offset, you'd be passing a DMA range structure to the device core, and let it take the relevant decisions on how to handle it internally (overwrite, add a new entry, merge them, etc...). Easier said than done. :) Regards, Nicolas --=-Ttdr9J6hcKekh9mdkCgm Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- iQEzBAABCAAdFiEErOkkGDHCg2EbPcGjlfZmHno8x/4FAl7FFGAACgkQlfZmHno8 x/62Gwf/ZcX0GjUG2kX8dOQj+DmylB81fPXdO67lCfYb36/3AaWub3SgdS6OElwx EUkGWiXfQspc2tFLJ9QHVOvKZ4dn1axmHzBdSUxOS3Y7K/5Ui7G7hzbi22njfPOR TjQzAlozY8g7HB3GWRHX6ptZwNsk2GgfywpFPTHQzZphJtsqhRkC+1NBVZJqcxUg PP0lJ4op3lIusNEoZXTvss0CGvIqPZroj3V6gxMllerV0UGayKnZRijn+VnqKhM0 kJUKjAA7TXjaIHzJZYfVncgp2eZtNCpmP+WM7/YDKoNbbkJYHBelwCqCq42YEJhk 50yZpb9YqlD0TwGBilnlPIHc33lp8g== =LCl4 -----END PGP SIGNATURE----- --=-Ttdr9J6hcKekh9mdkCgm--