Benjamin Herrenschmidt | d1405b8 | 2005-11-23 17:53:42 +1100 | [diff] [blame] | 1 | #undef DEBUG |
| 2 | |
| 3 | #include <linux/kernel.h> |
| 4 | #include <linux/string.h> |
Benjamin Herrenschmidt | d2dd482 | 2005-11-30 16:57:28 +1100 | [diff] [blame] | 5 | #include <linux/ioport.h> |
Timur Tabi | 29cfe6f | 2007-02-16 12:01:29 -0600 | [diff] [blame] | 6 | #include <linux/etherdevice.h> |
Grant Likely | 1f5bef3 | 2010-06-08 07:48:09 -0600 | [diff] [blame] | 7 | #include <linux/of_address.h> |
Benjamin Herrenschmidt | d1405b8 | 2005-11-23 17:53:42 +1100 | [diff] [blame] | 8 | #include <asm/prom.h> |
Andy Fleming | 83efafb | 2006-10-16 16:03:33 -0500 | [diff] [blame] | 9 | |
Anton Blanchard | 2083f68 | 2013-08-07 02:01:36 +1000 | [diff] [blame] | 10 | void of_parse_dma_window(struct device_node *dn, const __be32 *dma_window, |
| 11 | unsigned long *busno, unsigned long *phys, |
| 12 | unsigned long *size) |
Jeremy Kerr | d4ad66f | 2006-05-18 18:05:15 +1000 | [diff] [blame] | 13 | { |
Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 14 | u32 cells; |
Anton Blanchard | 2083f68 | 2013-08-07 02:01:36 +1000 | [diff] [blame] | 15 | const __be32 *prop; |
Jeremy Kerr | d4ad66f | 2006-05-18 18:05:15 +1000 | [diff] [blame] | 16 | |
| 17 | /* busno is always one cell */ |
Anton Blanchard | 2083f68 | 2013-08-07 02:01:36 +1000 | [diff] [blame] | 18 | *busno = of_read_number(dma_window, 1); |
| 19 | dma_window++; |
Jeremy Kerr | d4ad66f | 2006-05-18 18:05:15 +1000 | [diff] [blame] | 20 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 21 | prop = of_get_property(dn, "ibm,#dma-address-cells", NULL); |
Will Schmidt | 03ac829 | 2006-05-30 13:38:40 -0500 | [diff] [blame] | 22 | if (!prop) |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 23 | prop = of_get_property(dn, "#address-cells", NULL); |
Will Schmidt | 03ac829 | 2006-05-30 13:38:40 -0500 | [diff] [blame] | 24 | |
Anton Blanchard | 2083f68 | 2013-08-07 02:01:36 +1000 | [diff] [blame] | 25 | cells = prop ? of_read_number(prop, 1) : of_n_addr_cells(dn); |
Benjamin Herrenschmidt | cc9fd71 | 2006-07-03 19:35:17 +1000 | [diff] [blame] | 26 | *phys = of_read_number(dma_window, cells); |
Jeremy Kerr | d4ad66f | 2006-05-18 18:05:15 +1000 | [diff] [blame] | 27 | |
| 28 | dma_window += cells; |
| 29 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 30 | prop = of_get_property(dn, "ibm,#dma-size-cells", NULL); |
Anton Blanchard | 2083f68 | 2013-08-07 02:01:36 +1000 | [diff] [blame] | 31 | cells = prop ? of_read_number(prop, 1) : of_n_size_cells(dn); |
Benjamin Herrenschmidt | cc9fd71 | 2006-07-03 19:35:17 +1000 | [diff] [blame] | 32 | *size = of_read_number(dma_window, cells); |
Jeremy Kerr | d4ad66f | 2006-05-18 18:05:15 +1000 | [diff] [blame] | 33 | } |