From patchwork Wed Jan 31 02:36:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 126307 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp292792ljc; Tue, 30 Jan 2018 18:38:29 -0800 (PST) X-Google-Smtp-Source: AH8x225guLtz/0mKtv1ZyLy3z9eXjJhjd4pIq7jrPxqaEYi0mr6eozjkoeRc+G9K1a3GploNeBPC X-Received: by 10.99.117.18 with SMTP id q18mr24687166pgc.71.1517366309382; Tue, 30 Jan 2018 18:38:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517366309; cv=none; d=google.com; s=arc-20160816; b=H9id8yL2hOIVaDltryNr82mAJZHgKth9kXjesHvYqkT1pj9X9bWdyZi82h1lR77Exa 1oP4pI2A+V0hsg0Vq8pfxvY1brEtBEZVLv86hGXTbPboAFZMVgV+nUdO9lgXWXwta2N6 JkAWkYxy4sodCEe2BwsCDtanSnKw7AYSpH2Be9UtMtUAE43yb+h+/dyZWk7/u6H7AfFw 5TrOeYp1HYnzE7qii/IL0oIMT8Nx7wfGwz+drV55/2WlfHwGXrirZIKDl3P26VX9Sfdm 0IWGfSpjvAwrICONKdnR57poWIcosyM1g9P7YkTJF34Js17naFm+iii0OXgx7v2i49fE 1EIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=/u11YKCNzSuoPIBruRMFf16dWqobqyaB73VAsP6oJ7Y=; b=s7TeF1vHCfkAeKUz8qbx5YqzPiGnHMzpCR9cW91D754/7kzoKrSi1xXJLriup7FX0T Ab6fqGC76ty454mXIW2jF+nArdik3rRYgcyBqjc0NdPhPRgZLFkk9ZIlYD+zViICwAKT HL+9vjzMmffPXG5j0AfDgR6CLX1zmjaFNQndgRpIJAWHzmVJ/pj/9zz2+GsZtDRzcYpI B0mB30Rm9MhZfiLBxq4ABV4fQxymxoO0bedy2i8JoUGzwuMKVrKKa2J0exTk21MHZcjz swS70j7zfRi6z9Ir6mjbOca81LyOqJaJinqsorHwksd/pTdGw8cQjBNUF/2RFCswGLNZ JDGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=UFuTM+2d; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j13si10316180pgt.279.2018.01.30.18.38.29; Tue, 30 Jan 2018 18:38:29 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=UFuTM+2d; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751534AbeAaCi2 (ORCPT + 6 others); Tue, 30 Jan 2018 21:38:28 -0500 Received: from mail-pf0-f196.google.com ([209.85.192.196]:33943 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753406AbeAaCg2 (ORCPT ); Tue, 30 Jan 2018 21:36:28 -0500 Received: by mail-pf0-f196.google.com with SMTP id e76so11109213pfk.1 for ; Tue, 30 Jan 2018 18:36:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hmz9pFTLL9FxGzYoILOre5LtfUxP/Ya4sEnaNAaWvx4=; b=UFuTM+2dPn4Jpz9bwkFqQuMji+w8ia5zvfzYjCmrHDDq9vreuvs7N0ZVybAw3H6/oh oxxb0WaxjyxeWYDCJjqCd9Iq3pOFDKW0FLeN8WNR1lfauJDUnTBx+XEknTXu83L/5bz9 X74/7KjfXhe/+DBiNdSSKkEnja8t5qzNQ757I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hmz9pFTLL9FxGzYoILOre5LtfUxP/Ya4sEnaNAaWvx4=; b=gzhcQxyF3t2uV1T+7rewta1a60zG0UjGuuehqJezmJD4/owvTFofS3XPT3P+jMdw7o iecBtNFbTnRo4BoRv8K2/dfo04eVrjRl8k9l1lpZSJe5mtoY3LKTXgyH6CJNniS3UTYM qQMX0cxOxy5S4eMtc/ALJObYHX4ZL+8i0Uzg54mZcPxrLCYNi9vFewEUElHOCrLkclqs P9W5krauTeCqFQbj2WJBqGlI6jC57eqc96AhF1NpaDCZSPKR8DnYsMJ7dJ48HN4RzBW2 tG60AVSkBgFMwVySzF4R8s0Fv+ajlcrZN3PaVyvSyGrJqYHdCtObI7aayx/SYXZ4auwE wvyw== X-Gm-Message-State: AKwxytch+jsNHM6knWbPW7VYNSUGIktFJAfcS6RGTmaqVQETPQGgqwSd v05eorclZTA3BB78Gf06jkRzsQ== X-Received: by 10.98.71.197 with SMTP id p66mr32164234pfi.3.1517366188125; Tue, 30 Jan 2018 18:36:28 -0800 (PST) Received: from localhost.localdomain (pat_11.qualcomm.com. [192.35.156.11]) by smtp.gmail.com with ESMTPSA id z2sm24126828pgz.22.2018.01.30.18.36.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 30 Jan 2018 18:36:27 -0800 (PST) From: Stephen Boyd To: Rob Herring , Frank Rowand Cc: devicetree@vger.kernel.org, Russell King - ARM Linux , devicetree-spec@vger.kernel.org Subject: [PATCH v5 1/4] Document nexus nodes/specifier remapping Date: Tue, 30 Jan 2018 18:36:15 -0800 Message-Id: <20180131023618.14292-2-stephen.boyd@linaro.org> X-Mailer: git-send-email 2.14.GIT In-Reply-To: <20180131023618.14292-1-stephen.boyd@linaro.org> References: <20180131023618.14292-1-stephen.boyd@linaro.org> MIME-Version: 1.0 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Document the generic nexus node properties. This can be used by any specifier that conforms to #-cells where they want to support remapping phandle lists through nexus nodes. This is similar to interrupt remapping, but slightly different because we don't consider unit addresses when doing mappings. This is mostly a copy/paste of the interrupt specification, with the unit address parts removed and generalized to any specifier. There's also the addition of a pass through mechanism to make things more compact if desired in the mapping table. Signed-off-by: Stephen Boyd --- source/devicetree-basics.rst | 206 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 206 insertions(+) -- 2.14.GIT -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/source/devicetree-basics.rst b/source/devicetree-basics.rst index 1900cc881818..3aecd9ea22bc 100644 --- a/source/devicetree-basics.rst +++ b/source/devicetree-basics.rst @@ -1283,3 +1283,209 @@ performed: * That result is looked up in the *interrupt-map* table, which maps to the parent interrupt specifier ``<4 1>``. +.. _sect-nexus: + +Nexus Nodes and Specifier Mapping +--------------------------------- + +Nexus Node Properties +~~~~~~~~~~~~~~~~~~~~~ + +A nexus node shall have a *#-cells* property, where is +some specifier space such as 'gpio', 'clock', 'reset', etc. + +-map +^^^^^^^^^^^^^^^ + +Property: ``-map`` + +Value type: ```` encoded as an arbitrary number of +specifier mapping entries. + +Description: + + A *-map* is a property in a nexus node that bridges one + specifier domain with a set of parent specifier domains and describes + how specifiers in the child domain are mapped to their respective parent + domains. + + The map is a table where each row is a mapping entry + consisting of three components: *child specifier*, *specifier parent*, and + *parent specifier*. + + child specifier + The specifier of the child node being mapped. The number + of 32-bit cells required to specify this component is described by + the *#-cells* property of this nodeā€”the nexus node + containing the *-map* property. + + specifier parent + A single ** value that points to the specifier parent to + which the child domain is being mapped. + + parent specifier + The specifier in the parent domain. The number of 32-bit + cells required to specify this component is described by the + *#-cells* property of the specifier parent node. + + Lookups are performed on the mapping table by matching a specifier against + the child specifier in the map. Because some fields in the specifier may + not be relevant or need to be modified, a mask is applied before the lookup + is done. This mask is defined in the *-map-mask* property (see + section :ref:`sect-specifier-map-mask`). + + Similarly, when the specifier is mapped, some fields in the unit specifier + may need to be kept unmodified and passed through from the child node to the + parent node. In this case, a *-map-pass-thru* property (see + section :ref:`sect-specifier-map-pass-thru`) may be specified to apply + a mask to the child specifier and copy any bits that match to the parent + unit specifier. + +.. _sect-specifier-map-mask: + +-map-mask +^^^^^^^^^^^^^^^^^^^^ + +Property: ``-map-mask`` + +Value type: ```` encoded as a bit mask + +Description: + + A *-map-mask* property may be specified for a nexus node. + This property specifies a mask that is applied to the child unit + specifier being looked up in the table specified in the *-map* + property. If this property is not specified, the mask is assumed to be + a mask with all bits set. + +.. _sect-specifier-map-pass-thru: + +-map-pass-thru +^^^^^^^^^^^^^^^^^^^^^^^^^ + +Property: ``-map-pass-thru`` + +Value type: ```` encoded as a bit mask + +Description: + + A *-map-pass-thru* property may be specified for a nexus node. + This property specifies a mask that is applied to the child unit + specifier being looked up in the table specified in the *-map* + property. Any matching bits in the child unit specifier are copied over + to the parent specifier. If this property is not specified, the mask is + assumed to be a mask with no bits set. + +#-cells +^^^^^^^^^^^^^^^^^^ + +Property: ``#-cells`` + +Value type: ```` + +Description: + + The *#-cells* property defines the number of cells required to + encode a specifier for a domain. + +Specifier Mapping Example +~~~~~~~~~~~~~~~~~~~~~~~~~ + +The following shows the representation of a fragment of a devicetree with +two GPIO controllers and a sample specifier map for describing the +GPIO routing of a few gpios on both of the controllers through a connector +on a board to a device. The expansion device node is one one side of the +connector node and the SoC with the two GPIO controllers is on the other +side of the connector. + +.. _example-specifier-mapping: + +.. code-block:: dts + + soc { + soc_gpio1: gpio-controller1 { + #gpio-cells = <2>; + }; + + soc_gpio2: gpio-controller2 { + #gpio-cells = <2>; + }; + }; + + connector: connector { + #gpio-cells = <2>; + gpio-map = <0 0 &soc_gpio1 1 0>, + <1 0 &soc_gpio2 4 0>, + <2 0 &soc_gpio1 3 0>, + <3 0 &soc_gpio2 2 0>; + gpio-map-mask = <0xf 0x0>; + gpio-map-pass-thru = <0x0 0x1>; + }; + + expansion_device { + reset-gpios = <&connector 2 GPIO_ACTIVE_LOW>; + }; + + +Each row in the gpio-map table consists of three parts: a child unit +specifier, which is mapped to a *gpio-controller* +node with a parent specifier. + +* For example, the first row of the specifier-map table specifies the + mapping for GPIO 0 of the connector. The components of that row are shown + here + + | child specifier: ``0 0`` + | specifier parent: ``&soc_gpio1`` + | parent specifier: ``1 0`` + + * The child specifier is ``<0 0>``, which specifies GPIO 0 in the connector + with a *flags* field of ``0``. This takes two 32-bit cells as specified + by the *#gpio-cells* property of the connector node, which is the + child specifier domian. + + * The specifier parent is specified by a phandle which points to the + specifier parent of the connector, the first GPIO controller in the SoC. + + * The parent specifier is ``<1 0>``. The number of cells to + represent the gpio specifier (two cells) is determined by the + *#gpio-cells* property on the specifier parent, the soc_gpio1 + node. + + * The value ``<1 0>`` is a value specified by the device binding for + the GPIO controller. The value ``<1>`` specifies the + GPIO pin number on the GPIO controller to which GPIO 0 on the connector + is wired. The value ``<0>`` specifies the flags (active low, + active high, etc.). + +In this example, the *gpio-map-mask* property has a value of ``<0xf 0>``. +This mask is applied to a child unit specifier before performing a lookup in +the *gpio-map* table. Similarly, the *gpio-map-pass-thru* property has a value +of ``<0x0 0x1>``. This mask is applied to a child unit specifier when mapping +it to the parent unit specifier. Any bits set in this mask are cleared out of +the parent unit specifier and copied over from the child unit specifier +to the parent unit specifier. + +To perform a lookup of the connector's specifier source number for GPIO 2 +from the expansion device's reset-gpios property, the following steps would be +performed: + +* The child specifier forms the value ``<2 GPIO_ACTIVE_LOW>``. + + * The specifier is encoding GPIO 2 with active low flags per the GPIO + binding. + +* The *gpio-map-mask* value ``<0xf 0x0>`` is ANDed with the child specifier, + giving a result of ``<0x2 0>``. + +* The result is looked up in the *gpio-map* table, which maps to + the parent specifier ``<3 0>`` and &soc_gpio1 *phandle*. + +* The *gpio-map-pass-thru* value ``<0x0 0x1>`` is inverted and ANDed with the + parent specifier found in the *gpio-map* table, resulting in ``<3 0>``. + The child specifier is ANDed with the *gpio-map-pass-thru* mask, forming + ``<0 GPIO_ACTIVE_LOW>`` which is then ORed with the cleared parent specifier + ``<3 0>`` resulting in ``<3 GPIO_ACTIVE_LOW>``. + +* The specifier ``<3 GPIO_ACTIVE_LOW>`` is appended to the mapped *phandle* + &soc_gpio1 resulting in ``<&soc_gpio1 3 GPIO_ACTIVE_LOW>``. From patchwork Wed Jan 31 02:36:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 126306 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp292620ljc; Tue, 30 Jan 2018 18:38:09 -0800 (PST) X-Google-Smtp-Source: AH8x225Gr9oChtuwxxdae9ccCK7g/RYL0haxJAYg/Ca2RMtvHgBtUSON/9E6tebM2WFMXVQhNDLb X-Received: by 10.98.198.2 with SMTP id m2mr32203008pfg.113.1517366289118; Tue, 30 Jan 2018 18:38:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517366289; cv=none; d=google.com; s=arc-20160816; b=Ww6C/ziK0z0pq04PJIw2ppST4d3Onx0jQckXSZfMj2l032CUBiblcrIkKJl6OUH8lT KqRXIRsauGFF/k9/q4Vvp/E0pPOctE7u12St0E8qL0TFETMqcV/i6QrfzRh0PxDjNuEa hez6HugPEyWFaoxPnyTMbBptDTF9P6lOpiTSPnnBI31DU+0RSura1MJluOaqHwVB4ff5 n2VeiKJ0veli3sZRTZAl/SqN+40aEbQMDv3+bbT2i7muXFGMTxZ7p0VWxtxEkls4/UZ6 0UWrQJ6krKILrR82nfPQoF1UhkWFa/XqRVgCa6THnKd23mmgoJCF53wBV6l74rYThjGl 40Hw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=SkZ+zpUFJNAbCfzaFz68al90BxR/IVVto7xjJG42HZE=; b=iRB4LuqOAYzvxnqjfH8Drx7OelJO97mcP0LdosH0+GTh1d3p1OTokylAztjUMMjbD7 S0boC4PftDN/buPMAymjOF405fdKi/+f24kQ7UUW4h+nNyMrb4Xr4eLVCuGMltAAimo+ CDdQpok4MCpXc8Nihg/BISC1DNx8a5o1j9KOtBE4ebU38UYNNfkWiwi51k22BZiWE9PW JGfpnVZS/bO9IQuq1JUFBXJ1Yi+WkMpSU/tfXZfcv6yZ56yrebol4PwlNWzKSlrSRveS 7mGX7PdqP6a7m2vgIESZRs0MuvjmP41YZVEF6pruBIxePo3JXVNiPKGq2wliSD9aIica TdNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=AswY0FJk; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t12si848039pgo.110.2018.01.30.18.38.08; Tue, 30 Jan 2018 18:38:09 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=AswY0FJk; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752027AbeAaCiH (ORCPT + 6 others); Tue, 30 Jan 2018 21:38:07 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:37945 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753446AbeAaCgd (ORCPT ); Tue, 30 Jan 2018 21:36:33 -0500 Received: by mail-pg0-f67.google.com with SMTP id y27so8865611pgc.5 for ; Tue, 30 Jan 2018 18:36:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=tqfmEbQPOgtzIm9LdGK35l+0oMPOC0IewQ+itnidCZI=; b=AswY0FJkh5O0tXC9MD4ao6oKIf92GfQWh5WbyxKBMKE7npXYFCrL59/zGVQka6j6Yj tSCllWKi2bWKn5K0hVojl1uUjKupcPfMlr/EU2SHrv5m+4pGSylPkUP/hIk45T/2lqQA MzAubgATPVfeH63XTIX6Au5HiSOK3jrixGQfo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=tqfmEbQPOgtzIm9LdGK35l+0oMPOC0IewQ+itnidCZI=; b=R+xDWppwPf31AzdBKdpT4luaCqgs4hHx2r4upGKvMgxX6Jwg27plwqUj7V4dwFNNw1 k5dOaOcuI7KH6B9j7QiGuWSK3elUAhD2MZUnPPouZSOf2b8km0fn0UlDQxxJ90IDnD6W S4zQZuhEps1c/Q4Psu0CytGalKyIswo53rynU6muhHoC0pzCDBB4CVcJFl282GudOqSv zCOu87uoijwUZKrctplgNFkdZYmhw5s5LAEGZlhkE/PN8K5uw58Asr+EXsMJ7oXYzB5I gEfbJVbInCZIhkEnB0YakuBAIh/+5N+8knSHo57DII9yzuqTm5UrXdwLFDjtiDsKJIBd HxMg== X-Gm-Message-State: AKwxytfBvASmuP/PgMEoAnk+iabpkZRWHz10npQfBmg+D4BFpEpHptwr GlMSp06OZqlbROo3thWRvUpc9Q== X-Received: by 2002:a17:902:123:: with SMTP id 32-v6mr27204583plb.278.1517366192464; Tue, 30 Jan 2018 18:36:32 -0800 (PST) Received: from localhost.localdomain (pat_11.qualcomm.com. [192.35.156.11]) by smtp.gmail.com with ESMTPSA id z2sm24126828pgz.22.2018.01.30.18.36.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 30 Jan 2018 18:36:31 -0800 (PST) From: Stephen Boyd To: Rob Herring , Frank Rowand Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Russell King - ARM Linux , devicetree-spec@vger.kernel.org, Pantelis Antoniou , Linus Walleij , Mark Brown Subject: [PATCH v5 3/4] of: unittest: Add phandle remapping test Date: Tue, 30 Jan 2018 18:36:17 -0800 Message-Id: <20180131023618.14292-4-stephen.boyd@linaro.org> X-Mailer: git-send-email 2.14.GIT In-Reply-To: <20180131023618.14292-1-stephen.boyd@linaro.org> References: <20180131023618.14292-1-stephen.boyd@linaro.org> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Test the functionality of of_parse_phandle_with_args_map(). Cc: Pantelis Antoniou Cc: Linus Walleij Cc: Mark Brown Signed-off-by: Stephen Boyd --- drivers/of/unittest-data/tests-phandle.dtsi | 25 ++++++ drivers/of/unittest.c | 120 ++++++++++++++++++++++++++++ 2 files changed, 145 insertions(+) -- 2.14.GIT -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/of/unittest-data/tests-phandle.dtsi b/drivers/of/unittest-data/tests-phandle.dtsi index 3c2f09e56b61..6b33be4c4416 100644 --- a/drivers/of/unittest-data/tests-phandle.dtsi +++ b/drivers/of/unittest-data/tests-phandle.dtsi @@ -26,6 +26,18 @@ #phandle-cells = <3>; }; + provider4: provider4 { + #phandle-cells = <2>; + phandle-map = <0 1 &provider1 3>, + <4 0 &provider0>, + <16 5 &provider3 3 5 0>, + <200 8 &provider2 23 6>, + <19 0 &provider2 15 0>, + <2 3 &provider3 2 5 3>; + phandle-map-mask = <0xff 0xf>; + phandle-map-pass-thru = <0x0 0xf0>; + }; + consumer-a { phandle-list = <&provider1 1>, <&provider2 2 0>, @@ -44,6 +56,19 @@ unterminated-string = [40 41 42 43]; unterminated-string-list = "first", "second", [40 41 42 43]; }; + + consumer-b { + phandle-list = <&provider1 1>, + <&provider4 2 3>, + <0>, + <&provider4 4 0x100>, + <&provider4 0 0x61>, + <&provider0>, + <&provider4 19 0x20>; + phandle-list-bad-phandle = <12345678 0 0>; + phandle-list-bad-args = <&provider2 1 0>, + <&provider4 0>; + }; }; }; }; diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index 0f8052f1355c..de27f62a8e8d 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -452,6 +452,125 @@ static void __init of_unittest_parse_phandle_with_args(void) unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); } +static void __init of_unittest_parse_phandle_with_args_map(void) +{ + struct device_node *np, *p0, *p1, *p2, *p3; + struct of_phandle_args args; + int i, rc; + + np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-b"); + if (!np) { + pr_err("missing testcase data\n"); + return; + } + + p0 = of_find_node_by_path("/testcase-data/phandle-tests/provider0"); + if (!p0) { + pr_err("missing testcase data\n"); + return; + } + + p1 = of_find_node_by_path("/testcase-data/phandle-tests/provider1"); + if (!p1) { + pr_err("missing testcase data\n"); + return; + } + + p2 = of_find_node_by_path("/testcase-data/phandle-tests/provider2"); + if (!p2) { + pr_err("missing testcase data\n"); + return; + } + + p3 = of_find_node_by_path("/testcase-data/phandle-tests/provider3"); + if (!p3) { + pr_err("missing testcase data\n"); + return; + } + + rc = of_count_phandle_with_args(np, "phandle-list", "#phandle-cells"); + unittest(rc == 7, "of_count_phandle_with_args() returned %i, expected 7\n", rc); + + for (i = 0; i < 8; i++) { + bool passed = true; + + rc = of_parse_phandle_with_args_map(np, "phandle-list", + "phandle", i, &args); + + /* Test the values from tests-phandle.dtsi */ + switch (i) { + case 0: + passed &= !rc; + passed &= (args.np == p1); + passed &= (args.args_count == 1); + passed &= (args.args[0] == 1); + break; + case 1: + passed &= !rc; + passed &= (args.np == p3); + passed &= (args.args_count == 3); + passed &= (args.args[0] == 2); + passed &= (args.args[1] == 5); + passed &= (args.args[2] == 3); + break; + case 2: + passed &= (rc == -ENOENT); + break; + case 3: + passed &= !rc; + passed &= (args.np == p0); + passed &= (args.args_count == 0); + break; + case 4: + passed &= !rc; + passed &= (args.np == p1); + passed &= (args.args_count == 1); + passed &= (args.args[0] == 3); + break; + case 5: + passed &= !rc; + passed &= (args.np == p0); + passed &= (args.args_count == 0); + break; + case 6: + passed &= !rc; + passed &= (args.np == p2); + passed &= (args.args_count == 2); + passed &= (args.args[0] == 15); + passed &= (args.args[1] == 0x20); + break; + case 7: + passed &= (rc == -ENOENT); + break; + default: + passed = false; + } + + unittest(passed, "index %i - data error on node %s rc=%i\n", + i, args.np->full_name, rc); + } + + /* Check for missing list property */ + rc = of_parse_phandle_with_args_map(np, "phandle-list-missing", + "phandle", 0, &args); + unittest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc); + + /* Check for missing cells,map,mask property */ + rc = of_parse_phandle_with_args_map(np, "phandle-list", + "phandle-missing", 0, &args); + unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); + + /* Check for bad phandle in list */ + rc = of_parse_phandle_with_args_map(np, "phandle-list-bad-phandle", + "phandle", 0, &args); + unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); + + /* Check for incorrectly formed argument list */ + rc = of_parse_phandle_with_args_map(np, "phandle-list-bad-args", + "phandle", 1, &args); + unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); +} + static void __init of_unittest_property_string(void) { const char *strings[4]; @@ -2354,6 +2473,7 @@ static int __init of_unittest(void) of_unittest_find_node_by_name(); of_unittest_dynamic(); of_unittest_parse_phandle_with_args(); + of_unittest_parse_phandle_with_args_map(); of_unittest_printf(); of_unittest_property_string(); of_unittest_property_copy();