blob: 6295e646f78cca6a204d4becdb2ec7d8ccdfde40 [file] [log] [blame]
Benjamin Herrenschmidtd1405b82005-11-23 17:53:42 +11001#undef DEBUG
2
3#include <linux/kernel.h>
4#include <linux/string.h>
Benjamin Herrenschmidtd2dd4822005-11-30 16:57:28 +11005#include <linux/ioport.h>
Timur Tabi29cfe6f2007-02-16 12:01:29 -06006#include <linux/etherdevice.h>
Grant Likely1f5bef32010-06-08 07:48:09 -06007#include <linux/of_address.h>
Benjamin Herrenschmidtd1405b82005-11-23 17:53:42 +11008#include <asm/prom.h>
Andy Fleming83efafb2006-10-16 16:03:33 -05009
Anton Blanchard2083f682013-08-07 02:01:36 +100010void of_parse_dma_window(struct device_node *dn, const __be32 *dma_window,
11 unsigned long *busno, unsigned long *phys,
12 unsigned long *size)
Jeremy Kerrd4ad66f2006-05-18 18:05:15 +100013{
Jeremy Kerra7f67bd2006-07-12 15:35:54 +100014 u32 cells;
Anton Blanchard2083f682013-08-07 02:01:36 +100015 const __be32 *prop;
Jeremy Kerrd4ad66f2006-05-18 18:05:15 +100016
17 /* busno is always one cell */
Anton Blanchard2083f682013-08-07 02:01:36 +100018 *busno = of_read_number(dma_window, 1);
19 dma_window++;
Jeremy Kerrd4ad66f2006-05-18 18:05:15 +100020
Stephen Rothwelle2eb6392007-04-03 22:26:41 +100021 prop = of_get_property(dn, "ibm,#dma-address-cells", NULL);
Will Schmidt03ac8292006-05-30 13:38:40 -050022 if (!prop)
Stephen Rothwelle2eb6392007-04-03 22:26:41 +100023 prop = of_get_property(dn, "#address-cells", NULL);
Will Schmidt03ac8292006-05-30 13:38:40 -050024
Anton Blanchard2083f682013-08-07 02:01:36 +100025 cells = prop ? of_read_number(prop, 1) : of_n_addr_cells(dn);
Benjamin Herrenschmidtcc9fd712006-07-03 19:35:17 +100026 *phys = of_read_number(dma_window, cells);
Jeremy Kerrd4ad66f2006-05-18 18:05:15 +100027
28 dma_window += cells;
29
Stephen Rothwelle2eb6392007-04-03 22:26:41 +100030 prop = of_get_property(dn, "ibm,#dma-size-cells", NULL);
Anton Blanchard2083f682013-08-07 02:01:36 +100031 cells = prop ? of_read_number(prop, 1) : of_n_size_cells(dn);
Benjamin Herrenschmidtcc9fd712006-07-03 19:35:17 +100032 *size = of_read_number(dma_window, cells);
Jeremy Kerrd4ad66f2006-05-18 18:05:15 +100033}