Skip to content

Commit 7ef58b3

Browse files
committed
Merge tag 'devicetree-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/glikely/linux
Pull devicetree changes from Grant Likely: "Lots of activity in the devicetree code for v3.18. Most of it is related to getting all of the overlay support code in place, but there are other important things in there. Highlights: - OF_RECONFIG notifiers for SPI, I2C and Platform devices. Those subsystems can now respond to live changes to the device tree. - CONFIG_OF_OVERLAY method for applying live changes to the device tree - Removal of the of_allnodes list. This used to be used to iterate over all the nodes in the device tree, but it is unnecessary because the same thing can be done by iterating over the list of child pointers. Getting rid of of_allnodes saves some memory and avoids the possibility of of_allnodes being sorted differently from the child lists. - Support for retrieving original DTB blob via sysfs. Needed by kexec. - More unittests - Documentation and minor bug fixes" * tag 'devicetree-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/glikely/linux: (42 commits) of: Delete unnecessary check before calling "of_node_put()" of: Drop ->next pointer from struct device_node spi: Check for spi_of_notifier when CONFIG_OF_DYNAMIC=y of: support passing console options with stdout-path of: add optional options parameter to of_find_node_by_path() of: Add bindings for chosen node, stdout-path of: Remove unneeded and incorrect MODULE_DEVICE_TABLE ARM: dt: fix up PL011 device tree bindings of: base, fix of_property_read_string_helper kernel-doc of: remove select of non-existant OF_DEVICE config symbol spi/of: Add OF notifier handler spi/of: Create new device registration method and accessors i2c/of: Add OF_RECONFIG notifier handler i2c/of: Factor out Devicetree registration code of/overlay: Add overlay unittests of/overlay: Introduce DT overlay support of/reconfig: Add OF_DYNAMIC notifier for platform_bus_type of/reconfig: Always use the same structure for notifiers of/reconfig: Add debug output for OF_RECONFIG notifiers of/reconfig: Add empty stubs for the of_reconfig methods ...
2 parents 413fd0e + c46ca3c commit 7ef58b3

39 files changed

+2560
-523
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
The chosen node
2+
---------------
3+
4+
The chosen node does not represent a real device, but serves as a place
5+
for passing data between firmware and the operating system, like boot
6+
arguments. Data in the chosen node does not represent the hardware.
7+
8+
9+
stdout-path property
10+
--------------------
11+
12+
Device trees may specify the device to be used for boot console output
13+
with a stdout-path property under /chosen, as described in ePAPR, e.g.
14+
15+
/ {
16+
chosen {
17+
stdout-path = "/serial@f00:115200";
18+
};
19+
20+
serial@f00 {
21+
compatible = "vendor,some-uart";
22+
reg = <0xf00 0x10>;
23+
};
24+
};
25+
26+
If the character ":" is present in the value, this terminates the path.
27+
The meaning of any characters following the ":" is device-specific, and
28+
must be specified in the relevant binding documentation.
29+
30+
For UART devices, the preferred binding is a string in the form:
31+
32+
<baud>{<parity>{<bits>{<flow>}}}
33+
34+
where
35+
36+
baud - baud rate in decimal
37+
parity - 'n' (none), 'o', (odd) or 'e' (even)
38+
bits - number of data bits
39+
flow - 'r' (rts)
40+
41+
For example: 115200n8r
42+
43+
Implementation note: Linux will look for the property "linux,stdout-path" or
44+
on PowerPC "stdout" if "stdout-path" is not found. However, the
45+
"linux,stdout-path" and "stdout" properties are deprecated. New platforms
46+
should only use the "stdout-path" property.

Documentation/devicetree/bindings/serial/pl011.txt

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,34 @@ Required properties:
66
- interrupts: exactly one interrupt specifier
77

88
Optional properties:
9-
- pinctrl: When present, must have one state named "sleep"
10-
and one state named "default"
11-
- clocks: When present, must refer to exactly one clock named
9+
- pinctrl: When present, must have one state named "default",
10+
and may contain a second name named "sleep". The former
11+
state sets up pins for ordinary operation whereas
12+
the latter state will put the associated pins to sleep
13+
when the UART is unused
14+
- clocks: When present, the first clock listed must correspond to
15+
the clock named UARTCLK on the IP block, i.e. the clock
16+
to the external serial line, whereas the second clock
17+
must correspond to the PCLK clocking the internal logic
18+
of the block. Just listing one clock (the first one) is
19+
deprecated.
20+
- clocks-names: When present, the first clock listed must be named
21+
"uartclk" and the second clock listed must be named
1222
"apb_pclk"
1323
- dmas: When present, may have one or two dma channels.
1424
The first one must be named "rx", the second one
1525
must be named "tx".
1626

1727
See also bindings/arm/primecell.txt
28+
29+
Example:
30+
31+
uart@80120000 {
32+
compatible = "arm,pl011", "arm,primecell";
33+
reg = <0x80120000 0x1000>;
34+
interrupts = <0 11 IRQ_TYPE_LEVEL_HIGH>;
35+
dmas = <&dma 13 0 0x2>, <&dma 13 0 0x0>;
36+
dma-names = "rx", "tx";
37+
clocks = <&foo_clk>, <&bar_clk>;
38+
clock-names = "uartclk", "apb_pclk";
39+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
* OF selftest platform device
2+
3+
** selftest
4+
5+
Required properties:
6+
- compatible: must be "selftest"
7+
8+
All other properties are optional.
9+
10+
Example:
11+
selftest {
12+
compatible = "selftest";
13+
status = "okay";
14+
};

Documentation/devicetree/of_selftest.txt

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ struct device_node {
6363
struct device_node *parent;
6464
struct device_node *child;
6565
struct device_node *sibling;
66-
struct device_node *allnext; /* next in list of all nodes */
6766
...
6867
};
6968

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

101100

102-
*allnext: it is used to link all the nodes of DT into a list. So, for the
103-
above tree the list would be as follows:
104-
105-
root->child1->child11->sibling12->sibling13->child131->sibling14->sibling2->
106-
child21->sibling22->sibling23->sibling3->child31->sibling32->sibling4->null
107-
108101
Before executing OF selftest, it is required to attach the test data to
109102
machine's device tree (if present). So, when selftest_data_add() is called,
110103
at first it reads the flattened device tree data linked into the kernel image
@@ -131,11 +124,6 @@ root ('/')
131124
test-child01 null null null
132125

133126

134-
allnext list:
135-
136-
root->testcase-data->test-child0->test-child01->test-sibling1->test-sibling2
137-
->test-sibling3->null
138-
139127
Figure 2: Example test data tree to be attached to live tree.
140128

141129
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
204192
whole tree). selftest_data_remove() calls detach_node_and_children() that uses
205193
of_detach_node() to detach the nodes from the live device tree.
206194

207-
To detach a node, of_detach_node() first updates all_next linked list, by
208-
attaching the previous node's allnext to current node's allnext pointer. And
209-
then, it either updates the child pointer of given node's parent to its
210-
sibling or attaches the previous sibling to the given node's sibling, as
211-
appropriate. That is it :)
195+
To detach a node, of_detach_node() either updates the child pointer of given
196+
node's parent to its sibling or attaches the previous sibling to the given
197+
node's sibling, as appropriate. That is it :)
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
Device Tree Overlay Notes
2+
-------------------------
3+
4+
This document describes the implementation of the in-kernel
5+
device tree overlay functionality residing in drivers/of/overlay.c and is a
6+
companion document to Documentation/devicetree/dt-object-internal.txt[1] &
7+
Documentation/devicetree/dynamic-resolution-notes.txt[2]
8+
9+
How overlays work
10+
-----------------
11+
12+
A Device Tree's overlay purpose is to modify the kernel's live tree, and
13+
have the modification affecting the state of the the kernel in a way that
14+
is reflecting the changes.
15+
Since the kernel mainly deals with devices, any new device node that result
16+
in an active device should have it created while if the device node is either
17+
disabled or removed all together, the affected device should be deregistered.
18+
19+
Lets take an example where we have a foo board with the following base tree
20+
which is taken from [1].
21+
22+
---- foo.dts -----------------------------------------------------------------
23+
/* FOO platform */
24+
/ {
25+
compatible = "corp,foo";
26+
27+
/* shared resources */
28+
res: res {
29+
};
30+
31+
/* On chip peripherals */
32+
ocp: ocp {
33+
/* peripherals that are always instantiated */
34+
peripheral1 { ... };
35+
}
36+
};
37+
---- foo.dts -----------------------------------------------------------------
38+
39+
The overlay bar.dts, when loaded (and resolved as described in [2]) should
40+
41+
---- bar.dts -----------------------------------------------------------------
42+
/plugin/; /* allow undefined label references and record them */
43+
/ {
44+
.... /* various properties for loader use; i.e. part id etc. */
45+
fragment@0 {
46+
target = <&ocp>;
47+
__overlay__ {
48+
/* bar peripheral */
49+
bar {
50+
compatible = "corp,bar";
51+
... /* various properties and child nodes */
52+
}
53+
};
54+
};
55+
};
56+
---- bar.dts -----------------------------------------------------------------
57+
58+
result in foo+bar.dts
59+
60+
---- foo+bar.dts -------------------------------------------------------------
61+
/* FOO platform + bar peripheral */
62+
/ {
63+
compatible = "corp,foo";
64+
65+
/* shared resources */
66+
res: res {
67+
};
68+
69+
/* On chip peripherals */
70+
ocp: ocp {
71+
/* peripherals that are always instantiated */
72+
peripheral1 { ... };
73+
74+
/* bar peripheral */
75+
bar {
76+
compatible = "corp,bar";
77+
... /* various properties and child nodes */
78+
}
79+
}
80+
};
81+
---- foo+bar.dts -------------------------------------------------------------
82+
83+
As a result of the the overlay, a new device node (bar) has been created
84+
so a bar platform device will be registered and if a matching device driver
85+
is loaded the device will be created as expected.
86+
87+
Overlay in-kernel API
88+
--------------------------------
89+
90+
The API is quite easy to use.
91+
92+
1. Call of_overlay_create() to create and apply an overlay. The return value
93+
is a cookie identifying this overlay.
94+
95+
2. Call of_overlay_destroy() to remove and cleanup the overlay previously
96+
created via the call to of_overlay_create(). Removal of an overlay that
97+
is stacked by another will not be permitted.
98+
99+
Finally, if you need to remove all overlays in one-go, just call
100+
of_overlay_destroy_all() which will remove every single one in the correct
101+
order.
102+
103+
Overlay DTS Format
104+
------------------
105+
106+
The DTS of an overlay should have the following format:
107+
108+
{
109+
/* ignored properties by the overlay */
110+
111+
fragment@0 { /* first child node */
112+
113+
target=<phandle>; /* phandle target of the overlay */
114+
or
115+
target-path="/path"; /* target path of the overlay */
116+
117+
__overlay__ {
118+
property-a; /* add property-a to the target */
119+
node-a { /* add to an existing, or create a node-a */
120+
...
121+
};
122+
};
123+
}
124+
fragment@1 { /* second child node */
125+
...
126+
};
127+
/* more fragments follow */
128+
}
129+
130+
Using the non-phandle based target method allows one to use a base DT which does
131+
not contain a __symbols__ node, i.e. it was not compiled with the -@ option.
132+
The __symbols__ node is only required for the target=<phandle> method, since it
133+
contains the information required to map from a phandle to a tree location.

Documentation/devicetree/todo.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ Todo list for devicetree:
22

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

76
=== CONFIG_OF_DYNAMIC ===
87
- Switch to RCU for tree updates and get rid of global spinlock

arch/powerpc/mm/numa.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,12 +1711,11 @@ static void stage_topology_update(int core_id)
17111711
static int dt_update_callback(struct notifier_block *nb,
17121712
unsigned long action, void *data)
17131713
{
1714-
struct of_prop_reconfig *update;
1714+
struct of_reconfig_data *update = data;
17151715
int rc = NOTIFY_DONE;
17161716

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

arch/powerpc/platforms/pseries/hotplug-cpu.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,16 +340,17 @@ static void pseries_remove_processor(struct device_node *np)
340340
}
341341

342342
static int pseries_smp_notifier(struct notifier_block *nb,
343-
unsigned long action, void *node)
343+
unsigned long action, void *data)
344344
{
345+
struct of_reconfig_data *rd = data;
345346
int err = 0;
346347

347348
switch (action) {
348349
case OF_RECONFIG_ATTACH_NODE:
349-
err = pseries_add_processor(node);
350+
err = pseries_add_processor(rd->dn);
350351
break;
351352
case OF_RECONFIG_DETACH_NODE:
352-
pseries_remove_processor(node);
353+
pseries_remove_processor(rd->dn);
353354
break;
354355
}
355356
return notifier_from_errno(err);

arch/powerpc/platforms/pseries/hotplug-memory.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ static int pseries_add_mem_node(struct device_node *np)
183183
return (ret < 0) ? -EINVAL : 0;
184184
}
185185

186-
static int pseries_update_drconf_memory(struct of_prop_reconfig *pr)
186+
static int pseries_update_drconf_memory(struct of_reconfig_data *pr)
187187
{
188188
struct of_drconf_cell *new_drmem, *old_drmem;
189189
unsigned long memblock_size;
@@ -232,22 +232,21 @@ static int pseries_update_drconf_memory(struct of_prop_reconfig *pr)
232232
}
233233

234234
static int pseries_memory_notifier(struct notifier_block *nb,
235-
unsigned long action, void *node)
235+
unsigned long action, void *data)
236236
{
237-
struct of_prop_reconfig *pr;
237+
struct of_reconfig_data *rd = data;
238238
int err = 0;
239239

240240
switch (action) {
241241
case OF_RECONFIG_ATTACH_NODE:
242-
err = pseries_add_mem_node(node);
242+
err = pseries_add_mem_node(rd->dn);
243243
break;
244244
case OF_RECONFIG_DETACH_NODE:
245-
err = pseries_remove_mem_node(node);
245+
err = pseries_remove_mem_node(rd->dn);
246246
break;
247247
case OF_RECONFIG_UPDATE_PROPERTY:
248-
pr = (struct of_prop_reconfig *)node;
249-
if (!strcmp(pr->prop->name, "ibm,dynamic-memory"))
250-
err = pseries_update_drconf_memory(pr);
248+
if (!strcmp(rd->prop->name, "ibm,dynamic-memory"))
249+
err = pseries_update_drconf_memory(rd);
251250
break;
252251
}
253252
return notifier_from_errno(err);

arch/powerpc/platforms/pseries/iommu.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,10 +1251,11 @@ static struct notifier_block iommu_mem_nb = {
12511251
.notifier_call = iommu_mem_notifier,
12521252
};
12531253

1254-
static int iommu_reconfig_notifier(struct notifier_block *nb, unsigned long action, void *node)
1254+
static int iommu_reconfig_notifier(struct notifier_block *nb, unsigned long action, void *data)
12551255
{
12561256
int err = NOTIFY_OK;
1257-
struct device_node *np = node;
1257+
struct of_reconfig_data *rd = data;
1258+
struct device_node *np = rd->dn;
12581259
struct pci_dn *pci = PCI_DN(np);
12591260
struct direct_window *window;
12601261

arch/powerpc/platforms/pseries/setup.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,10 @@ static void __init pseries_discover_pic(void)
251251
" interrupt-controller\n");
252252
}
253253

254-
static int pci_dn_reconfig_notifier(struct notifier_block *nb, unsigned long action, void *node)
254+
static int pci_dn_reconfig_notifier(struct notifier_block *nb, unsigned long action, void *data)
255255
{
256-
struct device_node *np = node;
256+
struct of_reconfig_data *rd = data;
257+
struct device_node *np = rd->dn;
257258
struct pci_dn *pci = NULL;
258259
int err = NOTIFY_OK;
259260

drivers/base/platform.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,7 @@ int __init platform_bus_init(void)
10061006
error = bus_register(&platform_bus_type);
10071007
if (error)
10081008
device_unregister(&platform_bus);
1009+
of_platform_register_reconfig_notifier();
10091010
return error;
10101011
}
10111012

0 commit comments

Comments
 (0)