Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3785144pxf; Mon, 22 Mar 2021 15:19:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJycQE37ezQpiJpTQEgjEFxCGozhZZMhuhLWbsSXjoC+xbQ1uJk007t0wp/yy2xNRJV7RGvC X-Received: by 2002:a17:906:1983:: with SMTP id g3mr1855074ejd.370.1616451573616; Mon, 22 Mar 2021 15:19:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616451573; cv=none; d=google.com; s=arc-20160816; b=YCkWg1/uk/5fuixpqdYhQWhOE/C97u85bCkMGj3+f1nChGgdZ4IQN+AaTWnNWmmjYI 6fo0djagguTdMOTY0YIxSiZ0OvflMhQXbCdCiPM2BJSWC/obIp2W6uTaAgOPrBUcqCIf vwZZhuvECwYDIPmWs7C/6EbEYvwpUYT575N6hKSMpQkfBStO/NYzTQ9BjaOK0FuCEEmr dbeNiS9AEVZWm2CXx+OkdzLxLJmE9LtbW6Tnv60uQ7CUJ45nvDPiVHO483/CitEmZooC S4YuNeYbxvVdHRloD20F9CXTF5Rp5u6Pz/e3HuP4In4sNG0tE7EE4nfB34a6X+znMOMO k6Nw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:cc:to:from:date:references:in-reply-to :message-id:mime-version:user-agent:dkim-signature:dkim-signature; bh=ZWi4GtAKz6MJnR4YgJPLnmK6aRpuRQjPkHSWuDbn2hw=; b=hT4daOfgNzPJrt/CdvfXmGzgsTFIC9bUMEUuz3yiRkEhSywc5uxzlrURzfMme6kiiG tnKJDsOZrYj0xc2eYbCOPa3aeU9ct829aHLTo9Q2SSxd49XyebgcMwFWY3A54jYTGraT 0iv6nDoNH19itYm6C+vOl42dQBF0/4sFnPGCIVamkZWRJAPeFLJLgeP5dRk5vDFbdf5s OIDrin87ZnWGoCk4/YgbE4UMeRpSAoXh9fiwgWW75lx4OeGaOXqrCHBwpyztQAEeJss2 3woenA6vC0CacTD13+V7e4Vuj4Wb6h3/emRNg/VPnJ/XeH8jgVAeR6t+GcGLRmqyJSaj gqAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@svenpeter.dev header.s=fm1 header.b=FTv+4Fla; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=jYDkRuJq; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=svenpeter.dev Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l26si12391377ejc.536.2021.03.22.15.19.10; Mon, 22 Mar 2021 15:19:33 -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; dkim=pass header.i=@svenpeter.dev header.s=fm1 header.b=FTv+4Fla; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=jYDkRuJq; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=svenpeter.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229854AbhCVWSV (ORCPT + 99 others); Mon, 22 Mar 2021 18:18:21 -0400 Received: from new4-smtp.messagingengine.com ([66.111.4.230]:59627 "EHLO new4-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229639AbhCVWRz (ORCPT ); Mon, 22 Mar 2021 18:17:55 -0400 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailnew.nyi.internal (Postfix) with ESMTP id 685E45804DD; Mon, 22 Mar 2021 18:17:54 -0400 (EDT) Received: from imap21 ([10.202.2.71]) by compute3.internal (MEProxy); Mon, 22 Mar 2021 18:17:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=svenpeter.dev; h=mime-version:message-id:in-reply-to:references:date:from:to :cc:subject:content-type; s=fm1; bh=ZWi4GtAKz6MJnR4YgJPLnmK6aRpu RQjPkHSWuDbn2hw=; b=FTv+4FlaBI3nXkxsa7BojoAkYJrOjRcOzmC3RGEeEswA zcn8SGPQ5MDiSZvzFOoQaHhYWjY5Zfu8w6RbXJIlX/lkeoihJehq7b3DmVqRdgei Kc31ki6aj6L015JQbET5Eo+gfJ7zO7PslknCI2/93BWPjgsxaLRbjE1bW3T7mVBR zrqQ9K5WjwtmcJBrjd5qLVRW85hTHBXmKYntfSL6+AJkRc0qmIUPWUq4hZlJjpbf r1ruGJJJChwjGlb0/NQb8Opdu7Mq8uLmMy0F1VqyKPl5RfAjj/NVnueqQrE7PzM1 lU3fIxS5Wo9wPleZ1Sm+QuIck8u4mVcse0bDVuFM5g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=ZWi4Gt AKz6MJnR4YgJPLnmK6aRpuRQjPkHSWuDbn2hw=; b=jYDkRuJqLc1gQX1YIg6lJR EsuKs8DlVizuIL6jBEDPwauOF4v77Kf+sA44eeK22O9inufF2Le8r+aQUVL7fEtH +nQvt9LISbklUqPjiIyJfcQajHG4NmUSYBDewSwt57lE8KoxivY8N7SV0jO+Pl6Q HXb3wzkG9q6sPDM3NPQlw/BYj/iX0pNPAzIYQDckl2qN52KbgZQyKAVuVdbhvbzy o4jvi2muKlUsKldoEMnLCgtvPzIIjr/Tt2zIG9NVAU/5DKsyXQqrx7DUF0lhjM/u CYCZpRIfrXF3/mWtyx6EB6Q2wswoZY4f5xEnolb9K48m3Jq+WRcvY37Db8IlkOaw == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudeggedgudehlecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvufgtsehttdertderredtnecuhfhrohhmpedfufhv vghnucfrvghtvghrfdcuoehsvhgvnhesshhvvghnphgvthgvrhdruggvvheqnecuggftrf grthhtvghrnhepgfeigeeiffeuhfettdejgfetjeetfeelfefgfefgvddvtdfghfffudeh vdefkeffnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomh epshhvvghnsehsvhgvnhhpvghtvghrrdguvghv X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 811F851C005E; Mon, 22 Mar 2021 18:17:52 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.5.0-alpha0-271-g88286cf463-fm-20210318.001-g88286cf4 Mime-Version: 1.0 Message-Id: In-Reply-To: References: <20210320151903.60759-1-sven@svenpeter.dev> <8360b3b3-296c-450d-abc3-bb47159bf4e1@www.fastmail.com> Date: Mon, 22 Mar 2021 23:17:31 +0100 From: "Sven Peter" To: "Mark Kettenis" Cc: iommu@lists.linux-foundation.org, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, robh+dt@kernel.org, arnd@kernel.org, marcan@marcan.st, maz@kernel.org, mohamed.mediouni@caramail.com, stan@corellium.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Subject: Re: [PATCH 0/3] Apple M1 DART IOMMU driver Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Mark, On Sun, Mar 21, 2021, at 19:35, Mark Kettenis wrote: > > Guess we do need to understand a little bit better how the USB DART > actually works. My hypothesis (based on our discussion on #asahi) is > that the XHCI host controller and the peripheral controller of the > DWC3 block use different DMA "streams" that are handled by the > different sub-DARTs. I've done some more experiments and the situation is unfortunately more complicated: Most DMA transfers are translated with the first DART. But sometimes (and I have not been able to figure out the exact conditions) transfers instead have to go through the second DART. This happens e.g. with one of my USB keyboards after a stop EP command is issued: Suddenly the xhci_ep_ctx struct must be translated through the second DART. What this likely means is that we'll need to point both DARTs to the same pagetables and just issue the TLB maintenance operations as a group. > > The Corellium folks use a DART + sub-DART model in their driver and a > single node in the device tree that represents both. That might sense > since the error registers and interrupts are shared. Maybe it would > make sense to select the appropriate sub-DART based on the DMA stream > ID? dwc3 specifically seems to require stream id #1 from the DART at <0x5 0x02f00000> and stream id #0 from the DART at <0x5 0x02f80000>. Both of these only share a IRQ line but are otherwise completely independent. Each has their own error registers, etc. and we need some way to specify these two DARTs + the appropriate stream ID. Essentially we have three options to represent this now: 1) Add both DARTs as separate regs, use #iommu-cells = <2> and have the first cell select the DART and the second one the stream ID. We could allow #iommu-cells = <1> in case only one reg is specified for the PCIe DART: usb_dart1@502f00000 { compatible = "apple,t8103-dart"; reg = <0x5 0x02f00000 0x0 0x4000>, <0x5 0x02f80000 0x0 0x4000>; #iommu-cells = <2>; ... }; usb1 { iommus = <&usb_dart1 0 1>, <&usb_dart1 1 0>; ... }; I prefer this option because we fully describe the DART in a single device node here. It also feels natural to group them like this because they need to share some properties (like dma-window and the interrupt) anyway. 2) Create two DART nodes which share the same IRQ line and attach them both to the master node: usb_dart1a@502f00000 { compatible = "apple,t8103-dart"; reg = <0x5 0x02f00000 0x0 0x4000>; #iommu-cells = <1>; ... }; usb_dart1b@502f80000 { compatible = "apple,t8103-dart"; reg = <0x5 0x02f80000 0x0 0x4000>; #iommu-cells = <1>; ... }; usb1 { iommus = <&usb_dart1a 1>, <&usb_dart1b 0>; ... }; I dislike this one because attaching those two DARTs to a single device seems rather unusual. We'd also have to duplicate the dma-window setting, make sure it's the same for both DARTs and there are probably even more complications I can't think of right now. It seems like this would also make the device tree very verbose and the implementation itself more complicated. 3) Introduce another property and let the DART driver take care of mirroring the pagetables. I believe this would be similar to the sid-remap property: usb_dart1@502f00000 { compatible = "apple,t8103-dart"; reg = <0x5 0x02f00000 0x0 0x4000>, <0x5 0x02f80000 0x0 0x4000>; #iommu-cells = <1>; sid-remap = <0 1>; }; usb1 { iommus = <&usb_dart1 0>; }; I slightly dislike this one because we now specify which stream id to use in two places: Once in the device node and another time in the new property in the DART node. I also don't think the binding is much simpler than the first one. > > where #dma-address-cells and #dma-size-cells default to > > #address-cells and #size-cells respectively if I understand > > the code correctly. That way we could also just always use > > a 64bit address and size in the DT, e.g. > > > > pcie_dart { > > [ ... ] > > dma-window = <0 0x100000 0 0x3fe00000>; > > [ ... ] > > }; > > That sounds like a serious contender to me! Hopefully one of the > Linux kernel developers can give this some sort of blessing. > > I think it would make sense for us to just rely on the #address-cells > and #size-cells defaults for the M1 device tree. > Agreed. Best, Sven