devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thierry Reding <thierry.reding@gmail.com>
To: Janne Grunau <j@jannau.net>
Cc: Rob Herring <robh+dt@kernel.org>, Joerg Roedel <joro@8bytes.org>,
	Will Deacon <will@kernel.org>,
	Robin Murphy <robin.murphy@arm.com>,
	Nicolin Chen <nicolinc@nvidia.com>,
	Krishna Reddy <vdumpa@nvidia.com>,
	Dmitry Osipenko <dmitry.osipenko@collabora.com>,
	Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>,
	Sameer Pujar <spujar@nvidia.com>,
	devicetree@vger.kernel.org, iommu@lists.linux-foundation.org,
	linux-tegra@vger.kernel.org, asahi@lists.linux.dev
Subject: Re: [PATCH v5 0/5] iommu: Support mappings/reservations in reserved-memory regions
Date: Wed, 18 May 2022 17:29:20 +0200	[thread overview]
Message-ID: <YoUQ0HlhwGiFPUrz@orome> (raw)
In-Reply-To: <20220515103544.GC26732@jannau.net>

[-- Attachment #1: Type: text/plain, Size: 5200 bytes --]

On Sun, May 15, 2022 at 12:35:44PM +0200, Janne Grunau wrote:
> Hej,
> 
> I'm working on the display controller for Apple silicon SoCs and will 
> add some comments with support for it in mind.
> 
> added asahi@lists.linux.dev to CC for the Apple silicon related aspects
> 
> On 2022-05-12 21:00:47 +0200, Thierry Reding wrote:
> > 
> > this is another attempt at solving the problem of passing IOMMU
> > configuration via device tree. It has significantly evolved since the
> > last attempt, based on the discussion that followed. The discussion can
> > be found here:
> > 
> >   https://lore.kernel.org/all/20210423163234.3651547-1-thierry.reding@gmail.com/
> > 
> > Rather than using a memory-region specifier, this new version introduces
> > a new "iommu-addresses" property for the reserved-memory regions
> > themselves.
> 
> If experimented with both proposed bindings for dcp and I think this 
> binding is easer to understand and to work with.
> 
> > These are used to describe either a static mapping or
> > reservation that should be created for a given device. If both "reg" and
> > "iommu-addresses" properties are given, a mapping will be created
> > (typically this would be an identity mapping)
> 
> dcp on Apple silicon will not use identity mappings. The IOMMU supports 
> identity mapping but the pre-configured mappings setup by Apple's system 
> firmware will not work with identity mapping. It maps multiple regions 
> which are incompatible with a linear identity mapping. In addition the 
> embbeded aarch64 micro controllers used in the display subsystem appears 
> to use a heap mapped at low IOVA space starting at 0.
> 
> > whereas if only an "iommu-addresses" property is specified, a 
> > reservation for the specified range will be installed.
> > 
> > An example is included in the DT bindings, but here is an extract of
> > what I've used to test this:
> > 
> > 	reserved-memory {
> > 		#address-cells = <2>;
> > 		#size-cells = <2>;
> > 		ranges;
> > 
> > 		/*
> > 		 * Creates an identity mapping for the framebuffer that
> > 		 * the firmware has setup to scan out a bootsplash from.
> > 		 */
> > 		fb: framebuffer@92cb2000 {
> > 			reg = <0x0 0x92cb2000 0x0 0x00800000>;
> > 			iommu-addresses = <&dc0 0x0 0x92cb2000 0x0 0x00800000>;
> > 		};
> 
> The binding supports mapping the same region to multiple devices. The 
> code supports that and it will be used on Apple silicon. Not necessary 
> to extend and complicate the example for I wanted to mention it 
> explicitly.
> 
> > 
> > 		/*
> > 		 * Creates a reservation in the IOVA space to prevent
> > 		 * any buffers from being mapped to that region. Note
> > 		 * that on Tegra the range is actually quite different
> > 		 * from this, but it would conflict with the display
> > 		 * driver that I tested this against, so this is just
> > 		 * a dummy region for testing.
> > 		 */
> > 		adsp: reservation-adsp {
> > 			iommu-addresses = <&dc0 0x0 0x90000000 0x0 0x00010000>;
> > 		};
> > 	};
> > 
> > 	host1x@50000000 {
> > 		dc@54200000 {
> > 			memory-region = <&fb>, <&adsp>;
> > 		};
> > 	};
> > 
> > This is abbreviated a little to focus on the essentials. Note also that
> > the ADSP reservation is not actually used on this device and the driver
> > for this doesn't exist yet, but I wanted to include this variant for
> > testing, because we'll want to use these bindings for the reservation
> > use-case as well at some point.
> > 
> > Adding Alyssa and Janne who have in the past tried to make these
> > bindings work on Apple M1. Also adding Sameer from the Tegra audio team
> > to look at the ADSP reservation and double-check that this is suitable
> > for our needs.
> 
> The binding itself is sufficient for the needs of the display subsystem 
> on Apple silicon. The device tree parsing code for reserved regions is 
> of limited use in it's current form. We will have either to extend or 
> duplicate it to retrieve the non-identity mappings. That's our problem 
> to solve.

I had looked at it a bit to see if I could easily implement that, but
the direct mapping support in the IOMMU subsystem currently only
supports either reservations or identity mappings, so arbitrary mappings
would either have to be added to that code, or it would have to take a
different code path that basically goes through the same steps, except
that it uses different physical and I/O virtual addresses.

The easiest, I think, would be for struct iommu_resv_region to be
extended with a pair of start/length fields for the I/O virtual address
and then the rest of the code should mostly work. This shouldn't even be
very invasive, maybe just adding a version of iommu_alloc_resv_region()
that takes the I/O virtual addresses as additional parameters.

Come to think of it, the current code could probably be improved a bit
by checking if the addresses in the reg and iommu-addresses properties
match. Currently the code just ignores the reserved memory region's
"reg" property, so one could technically set up a mapping that points to
physical memory that the device doesn't "own".

Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

      reply	other threads:[~2022-05-18 15:29 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-12 19:00 [PATCH v5 0/5] iommu: Support mappings/reservations in reserved-memory regions Thierry Reding
2022-05-12 19:00 ` [PATCH v5 1/5] dt-bindings: reserved-memory: Document iommu-addresses Thierry Reding
2022-05-13 12:33   ` Rob Herring
2022-05-15 10:45   ` Janne Grunau
2022-05-18 13:01     ` Thierry Reding
2022-05-12 19:00 ` [PATCH v5 2/5] iommu: Implement of_iommu_get_resv_regions() Thierry Reding
2022-05-15 11:10   ` Janne Grunau
2022-05-18 12:42     ` Thierry Reding
2022-05-12 19:00 ` [PATCH v5 3/5] iommu: dma: Use of_iommu_get_resv_regions() Thierry Reding
2022-05-12 19:00 ` [PATCH v5 4/5] iommu/tegra-smmu: Add support for reserved regions Thierry Reding
2022-05-12 19:00 ` [PATCH v5 5/5] iommu/tegra-smmu: Support managed domains Thierry Reding
2022-05-16 18:30   ` Dmitry Osipenko
2022-05-15 10:35 ` [PATCH v5 0/5] iommu: Support mappings/reservations in reserved-memory regions Janne Grunau
2022-05-18 15:29   ` Thierry Reding [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YoUQ0HlhwGiFPUrz@orome \
    --to=thierry.reding@gmail.com \
    --cc=alyssa.rosenzweig@collabora.com \
    --cc=asahi@lists.linux.dev \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.osipenko@collabora.com \
    --cc=iommu@lists.linux-foundation.org \
    --cc=j@jannau.net \
    --cc=joro@8bytes.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=nicolinc@nvidia.com \
    --cc=robh+dt@kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=spujar@nvidia.com \
    --cc=vdumpa@nvidia.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).