linux-hardened/include/linux/of_address.h
Stephen Warren 5d61b165c8 of: Allow busses with #size-cells=0
It's quite legitimate for a DT node to specify #size-cells=0. One example
is a node that's used to collect a number of non-memory-mapped devices.
In that scenario, there may be multiple child nodes with the same name
(type) thus necessitating the use of unit addresses in node names, and
reg properties:

/ {
	regulators {
		compatible = "simple-bus";
		#address-cells = <1>;
		#size-cells = <0>;

		regulator@0 {
			compatible = "regulator-fixed";
			reg = <0>;
			...
		};

		regulator@1 {
			compatible = "regulator-fixed";
			reg = <1>;
			...
		};

		...
	};
};

However, #size-cells=0 prevents translation of reg property values into
the parent node's address space. In turn, this triggers the kernel to
emit error messages during boot, such as:

    prom_parse: Bad cell count for /regulators/regulator@0

To prevent printing these error messages for legitimate DT content, a
number of changes are made:

1) of_get_address()/of_get_pci_address() are modified only to validate
   the value of #address-cells, and not #size-cells.

2) of_can_translate_address() is added to indicate whether address
   translation is possible.

3) of_device_make_bus_id() is modified to name devices based on the
   translated address only where possible, and otherwise fall back to
   using the (first cell of the) raw untranslated address.

4) of_device_alloc() is modified to create memory resources for a device
   only if the address can be translated into the CPU's address space.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Signed-off-by: Rob Herring <rob.herring@calxeda.com>
2012-08-03 08:01:46 -05:00

75 lines
2.3 KiB
C

#ifndef __OF_ADDRESS_H
#define __OF_ADDRESS_H
#include <linux/ioport.h>
#include <linux/errno.h>
#include <linux/of.h>
#ifdef CONFIG_OF_ADDRESS
extern u64 of_translate_address(struct device_node *np, const __be32 *addr);
extern bool of_can_translate_address(struct device_node *dev);
extern int of_address_to_resource(struct device_node *dev, int index,
struct resource *r);
extern struct device_node *of_find_matching_node_by_address(
struct device_node *from,
const struct of_device_id *matches,
u64 base_address);
extern void __iomem *of_iomap(struct device_node *device, int index);
/* Extract an address from a device, returns the region size and
* the address space flags too. The PCI version uses a BAR number
* instead of an absolute index
*/
extern const u32 *of_get_address(struct device_node *dev, int index,
u64 *size, unsigned int *flags);
#ifndef pci_address_to_pio
static inline unsigned long pci_address_to_pio(phys_addr_t addr) { return -1; }
#define pci_address_to_pio pci_address_to_pio
#endif
#else /* CONFIG_OF_ADDRESS */
static inline int of_address_to_resource(struct device_node *dev, int index,
struct resource *r)
{
return -EINVAL;
}
static inline struct device_node *of_find_matching_node_by_address(
struct device_node *from,
const struct of_device_id *matches,
u64 base_address)
{
return NULL;
}
static inline void __iomem *of_iomap(struct device_node *device, int index)
{
return NULL;
}
static inline const u32 *of_get_address(struct device_node *dev, int index,
u64 *size, unsigned int *flags)
{
return NULL;
}
#endif /* CONFIG_OF_ADDRESS */
#if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_PCI)
extern const __be32 *of_get_pci_address(struct device_node *dev, int bar_no,
u64 *size, unsigned int *flags);
extern int of_pci_address_to_resource(struct device_node *dev, int bar,
struct resource *r);
#else /* CONFIG_OF_ADDRESS && CONFIG_PCI */
static inline int of_pci_address_to_resource(struct device_node *dev, int bar,
struct resource *r)
{
return -ENOSYS;
}
static inline const __be32 *of_get_pci_address(struct device_node *dev,
int bar_no, u64 *size, unsigned int *flags)
{
return NULL;
}
#endif /* CONFIG_OF_ADDRESS && CONFIG_PCI */
#endif /* __OF_ADDRESS_H */