Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 08671464 authored by Alex Shi's avatar Alex Shi
Browse files

Merge branch 'v3.18/topic/of-overlay' into linux-linaro-lsk-v3.18

parents abacc500 37e8e4f1
Loading
Loading
Loading
Loading
+14 −0
Original line number Original line Diff line number Diff line
* OF selftest platform device

** selftest

Required properties:
- compatible: must be "selftest"

All other properties are optional.

Example:
	selftest {
		compatible = "selftest";
		status = "okay";
	};
+3 −17
Original line number Original line Diff line number Diff line
@@ -63,7 +63,6 @@ struct device_node {
    struct  device_node *parent;
    struct  device_node *parent;
    struct  device_node *child;
    struct  device_node *child;
    struct  device_node *sibling;
    struct  device_node *sibling;
    struct  device_node *allnext;   /* next in list of all nodes */
    ...
    ...
 };
 };


@@ -99,12 +98,6 @@ child11 -> sibling12 -> sibling13 -> sibling14 -> null
Figure 1: Generic structure of un-flattened device tree
Figure 1: Generic structure of un-flattened device tree




*allnext: it is used to link all the nodes of DT into a list. So, for the
 above tree the list would be as follows:

root->child1->child11->sibling12->sibling13->child131->sibling14->sibling2->
child21->sibling22->sibling23->sibling3->child31->sibling32->sibling4->null

Before executing OF selftest, it is required to attach the test data to
Before executing OF selftest, it is required to attach the test data to
machine's device tree (if present). So, when selftest_data_add() is called,
machine's device tree (if present). So, when selftest_data_add() is called,
at first it reads the flattened device tree data linked into the kernel image
at first it reads the flattened device tree data linked into the kernel image
@@ -131,11 +124,6 @@ root ('/')
 test-child01      null             null             null
 test-child01      null             null             null




allnext list:

root->testcase-data->test-child0->test-child01->test-sibling1->test-sibling2
->test-sibling3->null

Figure 2: Example test data tree to be attached to live tree.
Figure 2: Example test data tree to be attached to live tree.


According to the scenario above, the live tree is already present so it isn't
According to the scenario above, the live tree is already present so it isn't
@@ -204,8 +192,6 @@ detached and then moving up the parent nodes are removed, and eventually the
whole tree). selftest_data_remove() calls detach_node_and_children() that uses
whole tree). selftest_data_remove() calls detach_node_and_children() that uses
of_detach_node() to detach the nodes from the live device tree.
of_detach_node() to detach the nodes from the live device tree.


To detach a node, of_detach_node() first updates all_next linked list, by
To detach a node, of_detach_node() either updates the child pointer of given
attaching the previous node's allnext to current node's allnext pointer. And
node's parent to its sibling or attaches the previous sibling to the given
then, it either updates the child pointer of given node's parent to its
node's sibling, as appropriate. That is it :)
sibling or attaches the previous sibling to the given node's sibling, as
appropriate. That is it :)
+133 −0
Original line number Original line Diff line number Diff line
Device Tree Overlay Notes
-------------------------

This document describes the implementation of the in-kernel
device tree overlay functionality residing in drivers/of/overlay.c and is a
companion document to Documentation/devicetree/dt-object-internal.txt[1] &
Documentation/devicetree/dynamic-resolution-notes.txt[2]

How overlays work
-----------------

A Device Tree's overlay purpose is to modify the kernel's live tree, and
have the modification affecting the state of the the kernel in a way that
is reflecting the changes.
Since the kernel mainly deals with devices, any new device node that result
in an active device should have it created while if the device node is either
disabled or removed all together, the affected device should be deregistered.

Lets take an example where we have a foo board with the following base tree
which is taken from [1].

---- foo.dts -----------------------------------------------------------------
	/* FOO platform */
	/ {
		compatible = "corp,foo";

		/* shared resources */
		res: res {
		};

		/* On chip peripherals */
		ocp: ocp {
			/* peripherals that are always instantiated */
			peripheral1 { ... };
		}
	};
---- foo.dts -----------------------------------------------------------------

The overlay bar.dts, when loaded (and resolved as described in [2]) should

---- bar.dts -----------------------------------------------------------------
/plugin/;	/* allow undefined label references and record them */
/ {
	....	/* various properties for loader use; i.e. part id etc. */
	fragment@0 {
		target = <&ocp>;
		__overlay__ {
			/* bar peripheral */
			bar {
				compatible = "corp,bar";
				... /* various properties and child nodes */
			}
		};
	};
};
---- bar.dts -----------------------------------------------------------------

result in foo+bar.dts

---- foo+bar.dts -------------------------------------------------------------
	/* FOO platform + bar peripheral */
	/ {
		compatible = "corp,foo";

		/* shared resources */
		res: res {
		};

		/* On chip peripherals */
		ocp: ocp {
			/* peripherals that are always instantiated */
			peripheral1 { ... };

			/* bar peripheral */
			bar {
				compatible = "corp,bar";
				... /* various properties and child nodes */
			}
		}
	};
---- foo+bar.dts -------------------------------------------------------------

As a result of the the overlay, a new device node (bar) has been created
so a bar platform device will be registered and if a matching device driver
is loaded the device will be created as expected.

Overlay in-kernel API
--------------------------------

The API is quite easy to use.

1. Call of_overlay_create() to create and apply an overlay. The return value
is a cookie identifying this overlay.

2. Call of_overlay_destroy() to remove and cleanup the overlay previously
created via the call to of_overlay_create(). Removal of an overlay that
is stacked by another will not be permitted.

Finally, if you need to remove all overlays in one-go, just call
of_overlay_destroy_all() which will remove every single one in the correct
order.

Overlay DTS Format
------------------

The DTS of an overlay should have the following format:

{
	/* ignored properties by the overlay */

	fragment@0 {	/* first child node */

		target=<phandle>;	/* phandle target of the overlay */
	or
		target-path="/path";	/* target path of the overlay */

		__overlay__ {
			property-a;	/* add property-a to the target */
			node-a {	/* add to an existing, or create a node-a */
				...
			};
		};
	}
	fragment@1 {	/* second child node */
		...
	};
	/* more fragments follow */
}

Using the non-phandle based target method allows one to use a base DT which does
not contain a __symbols__ node, i.e. it was not compiled with the -@ option.
The __symbols__ node is only required for the target=<phandle> method, since it
contains the information required to map from a phandle to a tree location.
+0 −1
Original line number Original line Diff line number Diff line
@@ -2,7 +2,6 @@ Todo list for devicetree:


=== General structure ===
=== General structure ===
- Switch from custom lists to (h)list_head for nodes and properties structure
- Switch from custom lists to (h)list_head for nodes and properties structure
- Remove of_allnodes list and iterate using list of child nodes alone


=== CONFIG_OF_DYNAMIC ===
=== CONFIG_OF_DYNAMIC ===
- Switch to RCU for tree updates and get rid of global spinlock
- Switch to RCU for tree updates and get rid of global spinlock
+1 −2
Original line number Original line Diff line number Diff line
@@ -1711,12 +1711,11 @@ static void stage_topology_update(int core_id)
static int dt_update_callback(struct notifier_block *nb,
static int dt_update_callback(struct notifier_block *nb,
				unsigned long action, void *data)
				unsigned long action, void *data)
{
{
	struct of_prop_reconfig *update;
	struct of_reconfig_data *update = data;
	int rc = NOTIFY_DONE;
	int rc = NOTIFY_DONE;


	switch (action) {
	switch (action) {
	case OF_RECONFIG_UPDATE_PROPERTY:
	case OF_RECONFIG_UPDATE_PROPERTY:
		update = (struct of_prop_reconfig *)data;
		if (!of_prop_cmp(update->dn->type, "cpu") &&
		if (!of_prop_cmp(update->dn->type, "cpu") &&
		    !of_prop_cmp(update->prop->name, "ibm,associativity")) {
		    !of_prop_cmp(update->prop->name, "ibm,associativity")) {
			u32 core_id;
			u32 core_id;
Loading