blob: 9cb7f88df563b52aa6dd8f7594dd8cddeb14b92b [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Benjamin Herrenschmidtd1405b82005-11-23 17:53:42 +11002#undef DEBUG
3
4#include <linux/kernel.h>
5#include <linux/string.h>
Benjamin Herrenschmidtd2dd4822005-11-30 16:57:28 +11006#include <linux/ioport.h>
Timur Tabi29cfe6f2007-02-16 12:01:29 -06007#include <linux/etherdevice.h>
Grant Likely1f5bef32010-06-08 07:48:09 -06008#include <linux/of_address.h>
Benjamin Herrenschmidtd1405b82005-11-23 17:53:42 +11009#include <asm/prom.h>
Andy Fleming83efafb2006-10-16 16:03:33 -050010
Anton Blanchard2083f682013-08-07 02:01:36 +100011void of_parse_dma_window(struct device_node *dn, const __be32 *dma_window,
12 unsigned long *busno, unsigned long *phys,
13 unsigned long *size)
Jeremy Kerrd4ad66f2006-05-18 18:05:15 +100014{
Jeremy Kerra7f67bd2006-07-12 15:35:54 +100015 u32 cells;
Anton Blanchard2083f682013-08-07 02:01:36 +100016 const __be32 *prop;
Jeremy Kerrd4ad66f2006-05-18 18:05:15 +100017
18 /* busno is always one cell */
Anton Blanchard2083f682013-08-07 02:01:36 +100019 *busno = of_read_number(dma_window, 1);
20 dma_window++;
Jeremy Kerrd4ad66f2006-05-18 18:05:15 +100021
Stephen Rothwelle2eb6392007-04-03 22:26:41 +100022 prop = of_get_property(dn, "ibm,#dma-address-cells", NULL);
Will Schmidt03ac8292006-05-30 13:38:40 -050023 if (!prop)
Stephen Rothwelle2eb6392007-04-03 22:26:41 +100024 prop = of_get_property(dn, "#address-cells", NULL);
Will Schmidt03ac8292006-05-30 13:38:40 -050025
Anton Blanchard2083f682013-08-07 02:01:36 +100026 cells = prop ? of_read_number(prop, 1) : of_n_addr_cells(dn);
Benjamin Herrenschmidtcc9fd712006-07-03 19:35:17 +100027 *phys = of_read_number(dma_window, cells);
Jeremy Kerrd4ad66f2006-05-18 18:05:15 +100028
29 dma_window += cells;
30
Stephen Rothwelle2eb6392007-04-03 22:26:41 +100031 prop = of_get_property(dn, "ibm,#dma-size-cells", NULL);
Anton Blanchard2083f682013-08-07 02:01:36 +100032 cells = prop ? of_read_number(prop, 1) : of_n_size_cells(dn);
Benjamin Herrenschmidtcc9fd712006-07-03 19:35:17 +100033 *size = of_read_number(dma_window, cells);
Jeremy Kerrd4ad66f2006-05-18 18:05:15 +100034}