From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stephen Warren Subject: Re: Reparenting a platform device Date: Thu, 05 Apr 2012 09:40:30 -0600 Message-ID: <4F7DBCEE.9080400@wwwdotorg.org> References: <20120405084258.GA19798@avionic-0098.adnet.avionic-design.de> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20120405084258.GA19798-RM9K5IK7kjIyiCvfTdI0JKcOhU4Rzj621B7CTYaBSLdn68oJJulU0Q@public.gmane.org> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: devicetree-discuss-bounces+gldd-devicetree-discuss=m.gmane.org-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org Sender: devicetree-discuss-bounces+gldd-devicetree-discuss=m.gmane.org-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org To: Thierry Reding Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org, iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org, Hiroshi Doyu List-Id: devicetree@vger.kernel.org On 04/05/2012 02:42 AM, Thierry Reding wrote: > Hi, > > I have a device tree where I have a GART device and a DRM device which uses > the GART. The GART is implemented by an IOMMU driver (tegra-gart) and > requires the user device to be a child of the GART device (it explicitly > checks for this when the user device is attached). Isn't this wrong? I would expect the device parent/child relationship to reflect the CPU-initiated register access bus topology. A device's interaction with an IOMMU is an aspect of a device's initiating accesses itself, not CPU-initiated register accesses. > I've tried two alternatives to achieve this: create the GART device in the > user driver's .probe() function and explicitly set the DRM device's parent > to the resulting platform device like so: > > gart = platform_device_alloc(...); > ... > pdev->dev.parent = &gart->dev; I guess that won't work when there's more than one device affected by the IOMMU? > The alternative is to use the device tree to look up the GART device node and > resolve it to the corresponding struct device: > > gart_node = of_parse_phandle(drm->dev->of_node, "gart-parent", 0); That seems more logical to me. > gart = bus_find_device(drm->dev->bus, NULL, gart_node, match_of_node); That part should probably be encapsulated into the IOMMU subsystem? In fact, even the of_parse_phandle should perhaps be hidden inside some IOMMU iommu_get() call, that can use DT as a data source, or some other data structure set up by board files.