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 | |
Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 10 | void of_parse_dma_window(struct device_node *dn, const void *dma_window_prop, |
Jeremy Kerr | d4ad66f | 2006-05-18 18:05:15 +1000 | [diff] [blame] | 11 | unsigned long *busno, unsigned long *phys, unsigned long *size) |
| 12 | { |
Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 13 | const u32 *dma_window; |
| 14 | u32 cells; |
| 15 | const unsigned char *prop; |
Jeremy Kerr | d4ad66f | 2006-05-18 18:05:15 +1000 | [diff] [blame] | 16 | |
Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 17 | dma_window = dma_window_prop; |
Jeremy Kerr | d4ad66f | 2006-05-18 18:05:15 +1000 | [diff] [blame] | 18 | |
| 19 | /* busno is always one cell */ |
| 20 | *busno = *(dma_window++); |
| 21 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 22 | prop = of_get_property(dn, "ibm,#dma-address-cells", NULL); |
Will Schmidt | 03ac829 | 2006-05-30 13:38:40 -0500 | [diff] [blame] | 23 | if (!prop) |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 24 | prop = of_get_property(dn, "#address-cells", NULL); |
Will Schmidt | 03ac829 | 2006-05-30 13:38:40 -0500 | [diff] [blame] | 25 | |
Stephen Rothwell | a8bda5d | 2007-04-03 10:56:50 +1000 | [diff] [blame] | 26 | cells = prop ? *(u32 *)prop : of_n_addr_cells(dn); |
Benjamin Herrenschmidt | cc9fd71 | 2006-07-03 19:35:17 +1000 | [diff] [blame] | 27 | *phys = of_read_number(dma_window, cells); |
Jeremy Kerr | d4ad66f | 2006-05-18 18:05:15 +1000 | [diff] [blame] | 28 | |
| 29 | dma_window += cells; |
| 30 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 31 | prop = of_get_property(dn, "ibm,#dma-size-cells", NULL); |
Stephen Rothwell | 9213fee | 2007-04-03 10:57:48 +1000 | [diff] [blame] | 32 | cells = prop ? *(u32 *)prop : of_n_size_cells(dn); |
Benjamin Herrenschmidt | cc9fd71 | 2006-07-03 19:35:17 +1000 | [diff] [blame] | 33 | *size = of_read_number(dma_window, cells); |
Jeremy Kerr | d4ad66f | 2006-05-18 18:05:15 +1000 | [diff] [blame] | 34 | } |