blob: 47187cc2cf008c38e14c09667a7fff7b436d5dee [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 Herrenschmidtd1405b82005-11-23 17:53:42 +11005#include <linux/module.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
Jeremy Kerra7f67bd2006-07-12 15:35:54 +100011void of_parse_dma_window(struct device_node *dn, const void *dma_window_prop,
Jeremy Kerrd4ad66f2006-05-18 18:05:15 +100012 unsigned long *busno, unsigned long *phys, unsigned long *size)
13{
Jeremy Kerra7f67bd2006-07-12 15:35:54 +100014 const u32 *dma_window;
15 u32 cells;
16 const unsigned char *prop;
Jeremy Kerrd4ad66f2006-05-18 18:05:15 +100017
Jeremy Kerra7f67bd2006-07-12 15:35:54 +100018 dma_window = dma_window_prop;
Jeremy Kerrd4ad66f2006-05-18 18:05:15 +100019
20 /* busno is always one cell */
21 *busno = *(dma_window++);
22
Stephen Rothwelle2eb6392007-04-03 22:26:41 +100023 prop = of_get_property(dn, "ibm,#dma-address-cells", NULL);
Will Schmidt03ac8292006-05-30 13:38:40 -050024 if (!prop)
Stephen Rothwelle2eb6392007-04-03 22:26:41 +100025 prop = of_get_property(dn, "#address-cells", NULL);
Will Schmidt03ac8292006-05-30 13:38:40 -050026
Stephen Rothwella8bda5d2007-04-03 10:56:50 +100027 cells = prop ? *(u32 *)prop : of_n_addr_cells(dn);
Benjamin Herrenschmidtcc9fd712006-07-03 19:35:17 +100028 *phys = of_read_number(dma_window, cells);
Jeremy Kerrd4ad66f2006-05-18 18:05:15 +100029
30 dma_window += cells;
31
Stephen Rothwelle2eb6392007-04-03 22:26:41 +100032 prop = of_get_property(dn, "ibm,#dma-size-cells", NULL);
Stephen Rothwell9213fee2007-04-03 10:57:48 +100033 cells = prop ? *(u32 *)prop : of_n_size_cells(dn);
Benjamin Herrenschmidtcc9fd712006-07-03 19:35:17 +100034 *size = of_read_number(dma_window, cells);
Jeremy Kerrd4ad66f2006-05-18 18:05:15 +100035}