blob: 4e1331b8eb33e5c613394e312b2799d365fa07f8 [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
Jeremy Kerra7f67bd2006-07-12 15:35:54 +100010void of_parse_dma_window(struct device_node *dn, const void *dma_window_prop,
Jeremy Kerrd4ad66f2006-05-18 18:05:15 +100011 unsigned long *busno, unsigned long *phys, unsigned long *size)
12{
Jeremy Kerra7f67bd2006-07-12 15:35:54 +100013 const u32 *dma_window;
14 u32 cells;
15 const unsigned char *prop;
Jeremy Kerrd4ad66f2006-05-18 18:05:15 +100016
Jeremy Kerra7f67bd2006-07-12 15:35:54 +100017 dma_window = dma_window_prop;
Jeremy Kerrd4ad66f2006-05-18 18:05:15 +100018
19 /* busno is always one cell */
20 *busno = *(dma_window++);
21
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
Stephen Rothwella8bda5d2007-04-03 10:56:50 +100026 cells = prop ? *(u32 *)prop : 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);
Stephen Rothwell9213fee2007-04-03 10:57:48 +100032 cells = prop ? *(u32 *)prop : 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}