of: Move CONFIG_OF_DYNAMIC code into a separate file

Split the dynamic device tree code into a separate file to make it
really clear what features CONFIF_OF_DYNAMIC add to the kernel. Without
CONFIG_OF_DYNAMIC only properties can be changed, and notifiers do not
get sent. Enabling it turns on reference counting, notifiers and the
ability to add and remove nodes.

Changes by Pantelis Antoniou:
* Added missing prototypes for non-dynamic case.
* Moved of_node_release to dynamic.c
* Cosmetic fixes and changes (checkpatch warnings fixes)

Signed-off-by: Grant Likely <grant.likely@linaro.org>
Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
configfs: Implement binary attributes

ConfigFS lacked binary attributes up until now. This patch
introduces support for binary attributes in a somewhat similar
manner of sysfs binary attributes albeit with changes that
fit the configfs usage model.

Problems that configfs binary attributes fix are everything that
requires a binary blob as part of the configuration of a resource,
such as bitstream loading for FPGAs, DTBs for dynamically created
devices etc.

Look at Documentation/filesystems/configfs/configfs.txt for internals
and howto use them.

This patch generates a bunch of checkpatch warnings, but this stems from
following the formatting of the configfs code, so please ignore.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
dtc: Dynamic symbols & fixup support (v2)

Enable the generation of symbol & fixup information for
usage with dynamic DT loading.

Passing the -@ option generates a __symbols__ node at the
root node of the resulting blob for any node labels used.

When using the /plugin/ tag all unresolved label references
be tracked in the __fixups__ node, while all local phandle
references will the tracked in the __local_fixups__ node.

This is sufficient to implement a dynamic DT object loader.

Changes since v1:

* Forward ported to 1.4 version
* Added manual entries for the -@ option

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
dtc: Update shipped files after DT objects

Update shipped files after DT object support.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
of: Do not free memory at of_node_release option

Introduce an option whether to free or not the memory of a node
and it's properties when of_node_release is called.

The option is located in the chosen node, and its name is
of-node-keep. When this boolean property is missing the default
behaviour of freeing is preserved.

The rational behind this option is as follows:

The life-cycle of nodes and properties does not allow us to release
the memory taken by a device_node. Pointer to properties and nodes
might still be in use in drivers, so any memory free'ing is dangerous.

Simply move all the properties to the deadprops list, and the node
itself to of_alldeadnodes until the life-cycles issues are resolved.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
of: platform: Fix and export of_platform_device_destroy

This is a rework of the original patch by Grant.
Minor cleanup by Pantelis, and tested.

On Sun, 22 Jun 2014 12:40:36 +0300, Pantelis Antoniou <pantelis.antoniou@konsulko.com> wrote:
> of_platform_destroy did not work properly, since the tree
> population test was iterating on all devices having a parent
> a given platform device.
>
> The check was intended to check whether any other *platform*
> devices were still populated, but instead checked for every
> kind of device. This is wrong, since platform devices typically
> create a subsystem regular device and set themselves as parents.
>
> Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
> ---
>  drivers/of/platform.c       | 11 ++++++++++-
>  include/linux/of_platform.h |  2 ++
>  2 files changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/of/platform.c b/drivers/of/platform.c
> index 500436f..4f60060 100644
> --- a/drivers/of/platform.c
> +++ b/drivers/of/platform.c
> @@ -506,10 +506,18 @@ int of_platform_populate(struct device_node *root,
>  }
>  EXPORT_SYMBOL_GPL(of_platform_populate);
>
> -static int of_platform_device_destroy(struct device *dev, void *data)
> +int of_platform_device_destroy(struct device *dev, void *data)
>  {
>  	bool *children_left = data;
>
> +	/* if the device is not a platform device, do nothing */
> +	if (dev->bus != &platform_bus_type
> +#ifdef CONFIG_ARM_AMBA
> +		&& dev->bus != &amba_bustype
> +#endif
> +	   )
> +		return 0;
> +

[Adding Pawel who introduced of_platform_device_destroy()]

Actually, it occurs to me that the *children_left test is completly
wrong and should just be removed outright. If there are devices left,
then it is a great big driver bug because the driver failed to clean up
after itself on remove. We can let the driver core complain loudly when
things go wrong. In fact, we must do that because the device unregister
functions don't provide any return code anyway.

Pawel, does the following patch look correct to you?

g.

Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
OF: Export a number of __of_* methods

As part of moving to transactional DT, a number of methods are
reworked and exported.

The methods exported are:
__of_add_property, __of_remove_property, __of_update_property, __of_attach_node,
__of_detach_node

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
OF: Utility helper functions for dynamic nodes

Introduce helper functions for working with the live DT tree,
all of them related to dynamically adding/removing nodes and
properties.

__of_copy_property() copies a property dynamically
__of_create_empty_node() creates an empty node

Bug fix about prop->len == 0 by Ionut Nicu <ioan.nicu.ext@nsn.com>

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
of: Introduce tree change __foo_post methods.

As part of transactional DT support there needs to be a clearer
definition of how each dynamic tree change method works.

Let's take for example the of_add_property method. There are
discrete steps taken in sequence.

1. The OF_RECONFIG_ADD_PROPERTY notifier will be fired.
2. The devtree lock will be taken.
3. Insertion of the property in the live tree.
4. The devtree lock will be released.
5. The property will be inserted in the sysfs tree.

For each of the of_attach_node, of_detach_node, of_add_property,
of_remove_property and of_update_property methods we export (and
introduce if not available), their counterparts of
__of_attach_node, __of_attach_node_post, __of_detach_node,
__of_detach_node_post, __of_add_property, __of_add_property_post,
__of_remove_property, __of_remove_property_post, __of_update_property
and __of_update_property post.

So each of the tree modification methods is following the same
pattern, i.e. for method foo we have:

Firing of the notifer, lock, __foo, unlock, __foo_post

This breakdown is required when we introduce transaction.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
of: Transactional DT support.

Introducing DT transactional support.

A DT transaction is a method which allows one to apply changes
in the live tree, in such a way that either the full set of changes
take effect, or the state of the tree can be rolled-back to the
state it was before it was attempted. An applied transaction
can be rolled-back at any time.

If any transaction results in the change of a state of a device
node, a notifier for that node will be fired which allows a bus
to create/destroy devices as directed.

Documentation is in
	Documentation/devicetree/transactions.txt

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
OF: Introduce Device Tree resolve support.

Introduce support for dynamic device tree resolution.
Using it, it is possible to prepare a device tree that's
been loaded on runtime to be modified and inserted at the kernel
live tree.

Export of of_resolve and bug fix of double free by
	Guenter Roeck <groeck@juniper.net>

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
OF: Introduce DT overlay support.

Introduce DT overlay support.

Makes it possible to dynamically overlay a part of the kernel's
tree with another tree that's been dynamically loaded.
Removal of nodes and properties is also possible.

The hard part of applying and reverting the overlay is done
using transactions.

Documentation about internal and APIs is provided in
	Documentation/devicetree/overlay-notes.txt

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
OF: selftest: Add overlay self-test support.

This patch adds overlay tests to the OF selftest.

It tests overlay device addition/removal and whether
the apply revert sequence is correct.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
OF: DT-Overlay configfs interface

Add a runtime interface to using configfs for generic device tree overlay
usage.

A device-tree configfs entry is created in /config/device-tree/overlays

* To create an overlay you mkdir the directory:

	# mkdir /config/device-tree/overlays/foo

* Either you echo the overlay firmware file to the path property file.

	# echo foo.dtbo >/config/device-tree/overlays/foo/path

* Or you cat the contents of the overlay to the dtbo file

	# cat foo.dtbo >/config/device-tree/overlays/foo/dtbo

The overlay file will be applied.

To remove it simply rmdir the directory.

	# rmdir /config/device-tree/overlays/foo

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
OF: platform: Add OF notifier handler

Add OF notifier handler needed for creating/destroying platform devices
according to dynamic runtime changes in the DT live tree.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
of: i2c: Export single device registration method

Dynamically inserting i2c client device nodes requires the use
of a single device registration method. Rework and export it.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
OF: i2c: Add OF notifier handler

Add OF notifier handler needed for creating/destroying i2c devices
according to dynamic runtime changes in the DT live tree.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
of: spi: Export single device registration method and accessors

Dynamically inserting spi device nodes requires the use of a single
device registration method. Rework and export it.

Methods to lookup a device/master using a device node are added
as well, of_find_spi_master_by_node() & of_find_spi_device_by_node().

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
OF: spi: Add OF notifier handler

Add OF notifier handler needed for creating/destroying spi devices
according to dynamic runtime changes in the DT live tree.

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
gitignore: Ignore DTB files

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>