^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #undef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/ioport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/etherdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/of_address.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <asm/prom.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) void of_parse_dma_window(struct device_node *dn, const __be32 *dma_window,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) unsigned long *busno, unsigned long *phys,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) unsigned long *size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) u32 cells;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) const __be32 *prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) /* busno is always one cell */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) *busno = of_read_number(dma_window, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) dma_window++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) prop = of_get_property(dn, "ibm,#dma-address-cells", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) if (!prop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) prop = of_get_property(dn, "#address-cells", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) cells = prop ? of_read_number(prop, 1) : of_n_addr_cells(dn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) *phys = of_read_number(dma_window, cells);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) dma_window += cells;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) prop = of_get_property(dn, "ibm,#dma-size-cells", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) cells = prop ? of_read_number(prop, 1) : of_n_size_cells(dn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) *size = of_read_number(dma_window, cells);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) }