xref: /openbmc/linux/arch/powerpc/boot/devtree.c (revision 762f99f4f3cb41a775b5157dd761217beba65873)
12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
227fbaa97SDavid Gibson /*
327fbaa97SDavid Gibson  * devtree.c - convenience functions for device tree manipulation
427fbaa97SDavid Gibson  * Copyright 2007 David Gibson, IBM Corporation.
527fbaa97SDavid Gibson  * Copyright (c) 2007 Freescale Semiconductor, Inc.
627fbaa97SDavid Gibson  *
727fbaa97SDavid Gibson  * Authors: David Gibson <david@gibson.dropbear.id.au>
827fbaa97SDavid Gibson  *	    Scott Wood <scottwood@freescale.com>
927fbaa97SDavid Gibson  */
1027fbaa97SDavid Gibson #include <stdarg.h>
1127fbaa97SDavid Gibson #include <stddef.h>
1227fbaa97SDavid Gibson #include "types.h"
1327fbaa97SDavid Gibson #include "string.h"
1427fbaa97SDavid Gibson #include "stdio.h"
1527fbaa97SDavid Gibson #include "ops.h"
16*c93f8084SBenjamin Herrenschmidt #include "of.h"
1727fbaa97SDavid Gibson 
dt_fixup_memory(u64 start,u64 size)1827fbaa97SDavid Gibson void dt_fixup_memory(u64 start, u64 size)
1927fbaa97SDavid Gibson {
2027fbaa97SDavid Gibson 	void *root, *memory;
2127fbaa97SDavid Gibson 	int naddr, nsize, i;
2227fbaa97SDavid Gibson 	u32 memreg[4];
2327fbaa97SDavid Gibson 
2427fbaa97SDavid Gibson 	root = finddevice("/");
2527fbaa97SDavid Gibson 	if (getprop(root, "#address-cells", &naddr, sizeof(naddr)) < 0)
2627fbaa97SDavid Gibson 		naddr = 2;
27*c93f8084SBenjamin Herrenschmidt 	else
28*c93f8084SBenjamin Herrenschmidt 		naddr = be32_to_cpu(naddr);
2927fbaa97SDavid Gibson 	if (naddr < 1 || naddr > 2)
3027fbaa97SDavid Gibson 		fatal("Can't cope with #address-cells == %d in /\n\r", naddr);
3127fbaa97SDavid Gibson 
3227fbaa97SDavid Gibson 	if (getprop(root, "#size-cells", &nsize, sizeof(nsize)) < 0)
3327fbaa97SDavid Gibson 		nsize = 1;
34*c93f8084SBenjamin Herrenschmidt 	else
35*c93f8084SBenjamin Herrenschmidt 		nsize = be32_to_cpu(nsize);
3627fbaa97SDavid Gibson 	if (nsize < 1 || nsize > 2)
3727fbaa97SDavid Gibson 		fatal("Can't cope with #size-cells == %d in /\n\r", nsize);
3827fbaa97SDavid Gibson 
3927fbaa97SDavid Gibson 	i = 0;
4027fbaa97SDavid Gibson 	if (naddr == 2)
41*c93f8084SBenjamin Herrenschmidt 		memreg[i++] = cpu_to_be32(start >> 32);
42*c93f8084SBenjamin Herrenschmidt 	memreg[i++] = cpu_to_be32(start & 0xffffffff);
4327fbaa97SDavid Gibson 	if (nsize == 2)
44*c93f8084SBenjamin Herrenschmidt 		memreg[i++] = cpu_to_be32(size >> 32);
45*c93f8084SBenjamin Herrenschmidt 	memreg[i++] = cpu_to_be32(size & 0xffffffff);
4627fbaa97SDavid Gibson 
4727fbaa97SDavid Gibson 	memory = finddevice("/memory");
4827fbaa97SDavid Gibson 	if (! memory) {
4927fbaa97SDavid Gibson 		memory = create_node(NULL, "memory");
5027fbaa97SDavid Gibson 		setprop_str(memory, "device_type", "memory");
5127fbaa97SDavid Gibson 	}
5227fbaa97SDavid Gibson 
53*c93f8084SBenjamin Herrenschmidt 	printf("Memory <- <0x%x", be32_to_cpu(memreg[0]));
5427fbaa97SDavid Gibson 	for (i = 1; i < (naddr + nsize); i++)
55*c93f8084SBenjamin Herrenschmidt 		printf(" 0x%x", be32_to_cpu(memreg[i]));
5627fbaa97SDavid Gibson 	printf("> (%ldMB)\n\r", (unsigned long)(size >> 20));
5727fbaa97SDavid Gibson 
5827fbaa97SDavid Gibson 	setprop(memory, "reg", memreg, (naddr + nsize)*sizeof(u32));
5927fbaa97SDavid Gibson }
6027fbaa97SDavid Gibson 
6127fbaa97SDavid Gibson #define MHZ(x)	((x + 500000) / 1000000)
6227fbaa97SDavid Gibson 
dt_fixup_cpu_clocks(u32 cpu,u32 tb,u32 bus)6327fbaa97SDavid Gibson void dt_fixup_cpu_clocks(u32 cpu, u32 tb, u32 bus)
6427fbaa97SDavid Gibson {
6527fbaa97SDavid Gibson 	void *devp = NULL;
6627fbaa97SDavid Gibson 
6727fbaa97SDavid Gibson 	printf("CPU clock-frequency <- 0x%x (%dMHz)\n\r", cpu, MHZ(cpu));
6827fbaa97SDavid Gibson 	printf("CPU timebase-frequency <- 0x%x (%dMHz)\n\r", tb, MHZ(tb));
6927fbaa97SDavid Gibson 	if (bus > 0)
7027fbaa97SDavid Gibson 		printf("CPU bus-frequency <- 0x%x (%dMHz)\n\r", bus, MHZ(bus));
7127fbaa97SDavid Gibson 
7227fbaa97SDavid Gibson 	while ((devp = find_node_by_devtype(devp, "cpu"))) {
73*c93f8084SBenjamin Herrenschmidt 		setprop_val(devp, "clock-frequency", cpu_to_be32(cpu));
74*c93f8084SBenjamin Herrenschmidt 		setprop_val(devp, "timebase-frequency", cpu_to_be32(tb));
7527fbaa97SDavid Gibson 		if (bus > 0)
76*c93f8084SBenjamin Herrenschmidt 			setprop_val(devp, "bus-frequency", cpu_to_be32(bus));
7727fbaa97SDavid Gibson 	}
78643d3c13SScott Wood 
79643d3c13SScott Wood 	timebase_period_ns = 1000000000 / tb;
8027fbaa97SDavid Gibson }
8127fbaa97SDavid Gibson 
dt_fixup_clock(const char * path,u32 freq)8227fbaa97SDavid Gibson void dt_fixup_clock(const char *path, u32 freq)
8327fbaa97SDavid Gibson {
8427fbaa97SDavid Gibson 	void *devp = finddevice(path);
8527fbaa97SDavid Gibson 
8627fbaa97SDavid Gibson 	if (devp) {
8727fbaa97SDavid Gibson 		printf("%s: clock-frequency <- %x (%dMHz)\n\r", path, freq, MHZ(freq));
88*c93f8084SBenjamin Herrenschmidt 		setprop_val(devp, "clock-frequency", cpu_to_be32(freq));
8927fbaa97SDavid Gibson 	}
9027fbaa97SDavid Gibson }
9127fbaa97SDavid Gibson 
dt_fixup_mac_address_by_alias(const char * alias,const u8 * addr)92ad160681SKumar Gala void dt_fixup_mac_address_by_alias(const char *alias, const u8 *addr)
93ad160681SKumar Gala {
94ad160681SKumar Gala 	void *devp = find_node_by_alias(alias);
95ad160681SKumar Gala 
96ad160681SKumar Gala 	if (devp) {
97ad160681SKumar Gala 		printf("%s: local-mac-address <-"
98ad160681SKumar Gala 		       " %02x:%02x:%02x:%02x:%02x:%02x\n\r", alias,
99ad160681SKumar Gala 		       addr[0], addr[1], addr[2],
100ad160681SKumar Gala 		       addr[3], addr[4], addr[5]);
101ad160681SKumar Gala 
102ad160681SKumar Gala 		setprop(devp, "local-mac-address", addr, 6);
103ad160681SKumar Gala 	}
104ad160681SKumar Gala }
105ad160681SKumar Gala 
dt_fixup_mac_address(u32 index,const u8 * addr)10627ff35d9SScott Wood void dt_fixup_mac_address(u32 index, const u8 *addr)
10727fbaa97SDavid Gibson {
10827ff35d9SScott Wood 	void *devp = find_node_by_prop_value(NULL, "linux,network-index",
10927fbaa97SDavid Gibson 	                                     (void*)&index, sizeof(index));
11027fbaa97SDavid Gibson 
11196ebc3bfSScott Wood 	if (devp) {
11227fbaa97SDavid Gibson 		printf("ENET%d: local-mac-address <-"
11327fbaa97SDavid Gibson 		       " %02x:%02x:%02x:%02x:%02x:%02x\n\r", index,
11496ebc3bfSScott Wood 		       addr[0], addr[1], addr[2],
11596ebc3bfSScott Wood 		       addr[3], addr[4], addr[5]);
11627fbaa97SDavid Gibson 
11727fbaa97SDavid Gibson 		setprop(devp, "local-mac-address", addr, 6);
11896ebc3bfSScott Wood 	}
11927fbaa97SDavid Gibson }
12027ff35d9SScott Wood 
__dt_fixup_mac_addresses(u32 startindex,...)12127ff35d9SScott Wood void __dt_fixup_mac_addresses(u32 startindex, ...)
12227ff35d9SScott Wood {
12327ff35d9SScott Wood 	va_list ap;
12427ff35d9SScott Wood 	u32 index = startindex;
12527ff35d9SScott Wood 	const u8 *addr;
12627ff35d9SScott Wood 
12727ff35d9SScott Wood 	va_start(ap, startindex);
12827ff35d9SScott Wood 
12927ff35d9SScott Wood 	while ((addr = va_arg(ap, const u8 *)))
13027ff35d9SScott Wood 		dt_fixup_mac_address(index++, addr);
13127ff35d9SScott Wood 
13227fbaa97SDavid Gibson 	va_end(ap);
13327fbaa97SDavid Gibson }
1346e1af384SScott Wood 
1356e1af384SScott Wood #define MAX_ADDR_CELLS 4
1366e1af384SScott Wood 
dt_get_reg_format(void * node,u32 * naddr,u32 * nsize)137e5d8d54dSScott Wood void dt_get_reg_format(void *node, u32 *naddr, u32 *nsize)
1386e1af384SScott Wood {
1396e1af384SScott Wood 	if (getprop(node, "#address-cells", naddr, 4) != 4)
1406e1af384SScott Wood 		*naddr = 2;
141*c93f8084SBenjamin Herrenschmidt 	else
142*c93f8084SBenjamin Herrenschmidt 		*naddr = be32_to_cpu(*naddr);
1436e1af384SScott Wood 	if (getprop(node, "#size-cells", nsize, 4) != 4)
1446e1af384SScott Wood 		*nsize = 1;
145*c93f8084SBenjamin Herrenschmidt 	else
146*c93f8084SBenjamin Herrenschmidt 		*nsize = be32_to_cpu(*nsize);
1476e1af384SScott Wood }
1486e1af384SScott Wood 
copy_val(u32 * dest,u32 * src,int naddr)1496e1af384SScott Wood static void copy_val(u32 *dest, u32 *src, int naddr)
1506e1af384SScott Wood {
151e4bb688dSScott Wood 	int pad = MAX_ADDR_CELLS - naddr;
152e4bb688dSScott Wood 
153e4bb688dSScott Wood 	memset(dest, 0, pad * 4);
154e4bb688dSScott Wood 	memcpy(dest + pad, src, naddr * 4);
1556e1af384SScott Wood }
1566e1af384SScott Wood 
sub_reg(u32 * reg,u32 * sub)1576e1af384SScott Wood static int sub_reg(u32 *reg, u32 *sub)
1586e1af384SScott Wood {
1596e1af384SScott Wood 	int i, borrow = 0;
1606e1af384SScott Wood 
161e4bb688dSScott Wood 	for (i = MAX_ADDR_CELLS - 1; i >= 0; i--) {
1626e1af384SScott Wood 		int prev_borrow = borrow;
1636e1af384SScott Wood 		borrow = reg[i] < sub[i] + prev_borrow;
1646e1af384SScott Wood 		reg[i] -= sub[i] + prev_borrow;
1656e1af384SScott Wood 	}
1666e1af384SScott Wood 
1676e1af384SScott Wood 	return !borrow;
1686e1af384SScott Wood }
1696e1af384SScott Wood 
add_reg(u32 * reg,u32 * add,int naddr)170e4bb688dSScott Wood static int add_reg(u32 *reg, u32 *add, int naddr)
1716e1af384SScott Wood {
1726e1af384SScott Wood 	int i, carry = 0;
1736e1af384SScott Wood 
174e4bb688dSScott Wood 	for (i = MAX_ADDR_CELLS - 1; i >= MAX_ADDR_CELLS - naddr; i--) {
175*c93f8084SBenjamin Herrenschmidt 		u64 tmp = (u64)be32_to_cpu(reg[i]) + be32_to_cpu(add[i]) + carry;
1766e1af384SScott Wood 		carry = tmp >> 32;
177*c93f8084SBenjamin Herrenschmidt 		reg[i] = cpu_to_be32((u32)tmp);
1786e1af384SScott Wood 	}
1796e1af384SScott Wood 
1806e1af384SScott Wood 	return !carry;
1816e1af384SScott Wood }
1826e1af384SScott Wood 
1836e1af384SScott Wood /* It is assumed that if the first byte of reg fits in a
1846e1af384SScott Wood  * range, then the whole reg block fits.
1856e1af384SScott Wood  */
compare_reg(u32 * reg,u32 * range,u32 * rangesize)1866e1af384SScott Wood static int compare_reg(u32 *reg, u32 *range, u32 *rangesize)
1876e1af384SScott Wood {
1886e1af384SScott Wood 	int i;
1896e1af384SScott Wood 	u32 end;
1906e1af384SScott Wood 
1916e1af384SScott Wood 	for (i = 0; i < MAX_ADDR_CELLS; i++) {
192*c93f8084SBenjamin Herrenschmidt 		if (be32_to_cpu(reg[i]) < be32_to_cpu(range[i]))
1936e1af384SScott Wood 			return 0;
194*c93f8084SBenjamin Herrenschmidt 		if (be32_to_cpu(reg[i]) > be32_to_cpu(range[i]))
1956e1af384SScott Wood 			break;
1966e1af384SScott Wood 	}
1976e1af384SScott Wood 
1986e1af384SScott Wood 	for (i = 0; i < MAX_ADDR_CELLS; i++) {
199*c93f8084SBenjamin Herrenschmidt 		end = be32_to_cpu(range[i]) + be32_to_cpu(rangesize[i]);
2006e1af384SScott Wood 
201*c93f8084SBenjamin Herrenschmidt 		if (be32_to_cpu(reg[i]) < end)
2026e1af384SScott Wood 			break;
203*c93f8084SBenjamin Herrenschmidt 		if (be32_to_cpu(reg[i]) > end)
2046e1af384SScott Wood 			return 0;
2056e1af384SScott Wood 	}
2066e1af384SScott Wood 
2076e1af384SScott Wood 	return reg[i] != end;
2086e1af384SScott Wood }
2096e1af384SScott Wood 
2106e1af384SScott Wood /* reg must be MAX_ADDR_CELLS */
find_range(u32 * reg,u32 * ranges,int nregaddr,int naddr,int nsize,int buflen)2116e1af384SScott Wood static int find_range(u32 *reg, u32 *ranges, int nregaddr,
2126e1af384SScott Wood                       int naddr, int nsize, int buflen)
2136e1af384SScott Wood {
2146e1af384SScott Wood 	int nrange = nregaddr + naddr + nsize;
2156e1af384SScott Wood 	int i;
2166e1af384SScott Wood 
2176e1af384SScott Wood 	for (i = 0; i + nrange <= buflen; i += nrange) {
2186e1af384SScott Wood 		u32 range_addr[MAX_ADDR_CELLS];
2196e1af384SScott Wood 		u32 range_size[MAX_ADDR_CELLS];
2206e1af384SScott Wood 
22149e6e3f1SScott Wood 		copy_val(range_addr, ranges + i, nregaddr);
2226e1af384SScott Wood 		copy_val(range_size, ranges + i + nregaddr + naddr, nsize);
2236e1af384SScott Wood 
2246e1af384SScott Wood 		if (compare_reg(reg, range_addr, range_size))
2256e1af384SScott Wood 			return i;
2266e1af384SScott Wood 	}
2276e1af384SScott Wood 
2286e1af384SScott Wood 	return -1;
2296e1af384SScott Wood }
2306e1af384SScott Wood 
2316e1af384SScott Wood /* Currently only generic buses without special encodings are supported.
2326e1af384SScott Wood  * In particular, PCI is not supported.  Also, only the beginning of the
2336e1af384SScott Wood  * reg block is tracked; size is ignored except in ranges.
2346e1af384SScott Wood  */
235a73ac50cSScott Wood static u32 prop_buf[MAX_PROP_LEN / 4];
2368895ea48SMark A. Greer 
dt_xlate(void * node,int res,int reglen,unsigned long * addr,unsigned long * size)2378895ea48SMark A. Greer static int dt_xlate(void *node, int res, int reglen, unsigned long *addr,
2386e1af384SScott Wood 		unsigned long *size)
2396e1af384SScott Wood {
2406e1af384SScott Wood 	u32 last_addr[MAX_ADDR_CELLS];
2416e1af384SScott Wood 	u32 this_addr[MAX_ADDR_CELLS];
2426e1af384SScott Wood 	void *parent;
2436e1af384SScott Wood 	u64 ret_addr, ret_size;
2440602801cSScott Wood 	u32 naddr, nsize, prev_naddr, prev_nsize;
2456e1af384SScott Wood 	int buflen, offset;
2466e1af384SScott Wood 
2476e1af384SScott Wood 	parent = get_parent(node);
2486e1af384SScott Wood 	if (!parent)
2496e1af384SScott Wood 		return 0;
2506e1af384SScott Wood 
251e5d8d54dSScott Wood 	dt_get_reg_format(parent, &naddr, &nsize);
2526e1af384SScott Wood 	if (nsize > 2)
2536e1af384SScott Wood 		return 0;
2546e1af384SScott Wood 
2556e1af384SScott Wood 	offset = (naddr + nsize) * res;
2566e1af384SScott Wood 
2578895ea48SMark A. Greer 	if (reglen < offset + naddr + nsize ||
258a73ac50cSScott Wood 	    MAX_PROP_LEN < (offset + naddr + nsize) * 4)
2596e1af384SScott Wood 		return 0;
2606e1af384SScott Wood 
261a73ac50cSScott Wood 	copy_val(last_addr, prop_buf + offset, naddr);
2626e1af384SScott Wood 
263*c93f8084SBenjamin Herrenschmidt 	ret_size = be32_to_cpu(prop_buf[offset + naddr]);
2646e1af384SScott Wood 	if (nsize == 2) {
2656e1af384SScott Wood 		ret_size <<= 32;
266*c93f8084SBenjamin Herrenschmidt 		ret_size |= be32_to_cpu(prop_buf[offset + naddr + 1]);
2676e1af384SScott Wood 	}
2686e1af384SScott Wood 
2690602801cSScott Wood 	for (;;) {
2706e1af384SScott Wood 		prev_naddr = naddr;
2710602801cSScott Wood 		prev_nsize = nsize;
2720602801cSScott Wood 		node = parent;
2736e1af384SScott Wood 
2740602801cSScott Wood 		parent = get_parent(node);
2750602801cSScott Wood 		if (!parent)
2760602801cSScott Wood 			break;
2770602801cSScott Wood 
278e5d8d54dSScott Wood 		dt_get_reg_format(parent, &naddr, &nsize);
2796e1af384SScott Wood 
280a73ac50cSScott Wood 		buflen = getprop(node, "ranges", prop_buf,
281a73ac50cSScott Wood 				sizeof(prop_buf));
2820602801cSScott Wood 		if (buflen == 0)
2836e1af384SScott Wood 			continue;
284a73ac50cSScott Wood 		if (buflen < 0 || buflen > sizeof(prop_buf))
2856e1af384SScott Wood 			return 0;
2866e1af384SScott Wood 
287a73ac50cSScott Wood 		offset = find_range(last_addr, prop_buf, prev_naddr,
2880602801cSScott Wood 		                    naddr, prev_nsize, buflen / 4);
2896e1af384SScott Wood 		if (offset < 0)
2906e1af384SScott Wood 			return 0;
2916e1af384SScott Wood 
292a73ac50cSScott Wood 		copy_val(this_addr, prop_buf + offset, prev_naddr);
2936e1af384SScott Wood 
2946e1af384SScott Wood 		if (!sub_reg(last_addr, this_addr))
2956e1af384SScott Wood 			return 0;
2966e1af384SScott Wood 
297a73ac50cSScott Wood 		copy_val(this_addr, prop_buf + offset + prev_naddr, naddr);
2986e1af384SScott Wood 
299e4bb688dSScott Wood 		if (!add_reg(last_addr, this_addr, naddr))
3006e1af384SScott Wood 			return 0;
3016e1af384SScott Wood 	}
3026e1af384SScott Wood 
3036e1af384SScott Wood 	if (naddr > 2)
3046e1af384SScott Wood 		return 0;
3056e1af384SScott Wood 
306*c93f8084SBenjamin Herrenschmidt 	ret_addr = ((u64)be32_to_cpu(last_addr[2]) << 32) | be32_to_cpu(last_addr[3]);
3076e1af384SScott Wood 	if (sizeof(void *) == 4 &&
3086e1af384SScott Wood 	    (ret_addr >= 0x100000000ULL || ret_size > 0x100000000ULL ||
3096e1af384SScott Wood 	     ret_addr + ret_size > 0x100000000ULL))
3106e1af384SScott Wood 		return 0;
3116e1af384SScott Wood 
3126e1af384SScott Wood 	*addr = ret_addr;
3136e1af384SScott Wood 	if (size)
3146e1af384SScott Wood 		*size = ret_size;
3156e1af384SScott Wood 
3166e1af384SScott Wood 	return 1;
3176e1af384SScott Wood }
3188895ea48SMark A. Greer 
dt_xlate_reg(void * node,int res,unsigned long * addr,unsigned long * size)3198895ea48SMark A. Greer int dt_xlate_reg(void *node, int res, unsigned long *addr, unsigned long *size)
3208895ea48SMark A. Greer {
3218895ea48SMark A. Greer 	int reglen;
3228895ea48SMark A. Greer 
323a73ac50cSScott Wood 	reglen = getprop(node, "reg", prop_buf, sizeof(prop_buf)) / 4;
3248895ea48SMark A. Greer 	return dt_xlate(node, res, reglen, addr, size);
3258895ea48SMark A. Greer }
3268895ea48SMark A. Greer 
dt_xlate_addr(void * node,u32 * buf,int buflen,unsigned long * xlated_addr)3278895ea48SMark A. Greer int dt_xlate_addr(void *node, u32 *buf, int buflen, unsigned long *xlated_addr)
3288895ea48SMark A. Greer {
3298895ea48SMark A. Greer 
330a73ac50cSScott Wood 	if (buflen > sizeof(prop_buf))
3318895ea48SMark A. Greer 		return 0;
3328895ea48SMark A. Greer 
333a73ac50cSScott Wood 	memcpy(prop_buf, buf, buflen);
3348895ea48SMark A. Greer 	return dt_xlate(node, 0, buflen / 4, xlated_addr, NULL);
3358895ea48SMark A. Greer }
336a73ac50cSScott Wood 
dt_is_compatible(void * node,const char * compat)337a73ac50cSScott Wood int dt_is_compatible(void *node, const char *compat)
338a73ac50cSScott Wood {
339a73ac50cSScott Wood 	char *buf = (char *)prop_buf;
340a73ac50cSScott Wood 	int len, pos;
341a73ac50cSScott Wood 
342a73ac50cSScott Wood 	len = getprop(node, "compatible", buf, MAX_PROP_LEN);
343a73ac50cSScott Wood 	if (len < 0)
344a73ac50cSScott Wood 		return 0;
345a73ac50cSScott Wood 
346a73ac50cSScott Wood 	for (pos = 0; pos < len; pos++) {
347a73ac50cSScott Wood 		if (!strcmp(buf + pos, compat))
348a73ac50cSScott Wood 			return 1;
349a73ac50cSScott Wood 
350a73ac50cSScott Wood 		pos += strnlen(&buf[pos], len - pos);
351a73ac50cSScott Wood 	}
352a73ac50cSScott Wood 
353a73ac50cSScott Wood 	return 0;
354a73ac50cSScott Wood }
355da0a5f0cSLaurent Pinchart 
dt_get_virtual_reg(void * node,void ** addr,int nres)356da0a5f0cSLaurent Pinchart int dt_get_virtual_reg(void *node, void **addr, int nres)
357da0a5f0cSLaurent Pinchart {
358da0a5f0cSLaurent Pinchart 	unsigned long xaddr;
359*c93f8084SBenjamin Herrenschmidt 	int n, i;
360da0a5f0cSLaurent Pinchart 
361da0a5f0cSLaurent Pinchart 	n = getprop(node, "virtual-reg", addr, nres * 4);
362*c93f8084SBenjamin Herrenschmidt 	if (n > 0) {
363*c93f8084SBenjamin Herrenschmidt 		for (i = 0; i < n/4; i ++)
364*c93f8084SBenjamin Herrenschmidt 			((u32 *)addr)[i] = be32_to_cpu(((u32 *)addr)[i]);
365da0a5f0cSLaurent Pinchart 		return n / 4;
366*c93f8084SBenjamin Herrenschmidt 	}
367da0a5f0cSLaurent Pinchart 
368da0a5f0cSLaurent Pinchart 	for (n = 0; n < nres; n++) {
369da0a5f0cSLaurent Pinchart 		if (!dt_xlate_reg(node, n, &xaddr, NULL))
370da0a5f0cSLaurent Pinchart 			break;
371da0a5f0cSLaurent Pinchart 
372da0a5f0cSLaurent Pinchart 		addr[n] = (void *)xaddr;
373da0a5f0cSLaurent Pinchart 	}
374da0a5f0cSLaurent Pinchart 
375da0a5f0cSLaurent Pinchart 	return n;
376da0a5f0cSLaurent Pinchart }
377da0a5f0cSLaurent Pinchart 
378