From 0ca922cad9c6a0d171f82c2cb77bc8fba545e181 Mon Sep 17 00:00:00 2001 From: Justin Hibbits Date: Fri, 30 Sep 2016 02:48:40 +0000 Subject: [PATCH] Use the cell-index property as the unit number if available. Summary: NXP/Freescale, among others, includes an optional cell-index property on nodes to denote the SoC block number of the node. This can be useful if, for example, a node is disabled or nonexistent in the fdt, or the blocks are not organized in address-sorted order. For instance, on the P1022, DMA2 is located at CCSR offset 0xC000, while DMA1 is located at 0x21000. Reviewed By: jmcneill Differential Revision: https://reviews.freebsd.org/D8054 --- sys/dev/fdt/simplebus.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sys/dev/fdt/simplebus.c b/sys/dev/fdt/simplebus.c index 8d43a7057bcf..6f0fe7297e25 100644 --- a/sys/dev/fdt/simplebus.c +++ b/sys/dev/fdt/simplebus.c @@ -265,6 +265,15 @@ simplebus_add_device(device_t dev, phandle_t node, u_int order, if ((ndi = simplebus_setup_dinfo(dev, node, di)) == NULL) return (NULL); + + /* + * If the order is unspecified, use the cell-index field, if available. + * The cell-index property is not part of any standard, but is widely + * used in NXP/Freescale and Marvell device trees. + */ + if (order == -1) + OF_getencprop(node, "cell-index", &order, sizeof(order)); + cdev = device_add_child_ordered(dev, order, name, unit); if (cdev == NULL) { device_printf(dev, "<%s>: device_add_child failed\n",