1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com 4 * Author: Peter Ujfalusi <peter.ujfalusi@ti.com> 5 */ 6 #include <linux/of.h> 7 #include <linux/of_platform.h> 8 9 int xudma_navss_psil_pair(struct udma_dev *ud, u32 src_thread, u32 dst_thread) 10 { 11 return navss_psil_pair(ud, src_thread, dst_thread); 12 } 13 EXPORT_SYMBOL(xudma_navss_psil_pair); 14 15 int xudma_navss_psil_unpair(struct udma_dev *ud, u32 src_thread, u32 dst_thread) 16 { 17 return navss_psil_unpair(ud, src_thread, dst_thread); 18 } 19 EXPORT_SYMBOL(xudma_navss_psil_unpair); 20 21 struct udma_dev *of_xudma_dev_get(struct device_node *np, const char *property) 22 { 23 struct device_node *udma_node = np; 24 struct platform_device *pdev; 25 struct udma_dev *ud; 26 27 if (property) { 28 udma_node = of_parse_phandle(np, property, 0); 29 if (!udma_node) { 30 pr_err("UDMA node is not found\n"); 31 return ERR_PTR(-ENODEV); 32 } 33 } 34 35 pdev = of_find_device_by_node(udma_node); 36 if (np != udma_node) 37 of_node_put(udma_node); 38 39 if (!pdev) { 40 pr_debug("UDMA device not found\n"); 41 return ERR_PTR(-EPROBE_DEFER); 42 } 43 44 ud = platform_get_drvdata(pdev); 45 if (!ud) { 46 pr_debug("UDMA has not been probed\n"); 47 put_device(&pdev->dev); 48 return ERR_PTR(-EPROBE_DEFER); 49 } 50 51 return ud; 52 } 53 EXPORT_SYMBOL(of_xudma_dev_get); 54 55 struct device *xudma_get_device(struct udma_dev *ud) 56 { 57 return ud->dev; 58 } 59 EXPORT_SYMBOL(xudma_get_device); 60 61 struct k3_ringacc *xudma_get_ringacc(struct udma_dev *ud) 62 { 63 return ud->ringacc; 64 } 65 EXPORT_SYMBOL(xudma_get_ringacc); 66 67 u32 xudma_dev_get_psil_base(struct udma_dev *ud) 68 { 69 return ud->psil_base; 70 } 71 EXPORT_SYMBOL(xudma_dev_get_psil_base); 72 73 struct udma_tisci_rm *xudma_dev_get_tisci_rm(struct udma_dev *ud) 74 { 75 return &ud->tisci_rm; 76 } 77 EXPORT_SYMBOL(xudma_dev_get_tisci_rm); 78 79 int xudma_alloc_gp_rflow_range(struct udma_dev *ud, int from, int cnt) 80 { 81 return __udma_alloc_gp_rflow_range(ud, from, cnt); 82 } 83 EXPORT_SYMBOL(xudma_alloc_gp_rflow_range); 84 85 int xudma_free_gp_rflow_range(struct udma_dev *ud, int from, int cnt) 86 { 87 return __udma_free_gp_rflow_range(ud, from, cnt); 88 } 89 EXPORT_SYMBOL(xudma_free_gp_rflow_range); 90 91 bool xudma_rflow_is_gp(struct udma_dev *ud, int id) 92 { 93 if (!ud->rflow_gp_map) 94 return false; 95 96 return !test_bit(id, ud->rflow_gp_map); 97 } 98 EXPORT_SYMBOL(xudma_rflow_is_gp); 99 100 #define XUDMA_GET_PUT_RESOURCE(res) \ 101 struct udma_##res *xudma_##res##_get(struct udma_dev *ud, int id) \ 102 { \ 103 return __udma_reserve_##res(ud, UDMA_TP_NORMAL, id); \ 104 } \ 105 EXPORT_SYMBOL(xudma_##res##_get); \ 106 \ 107 void xudma_##res##_put(struct udma_dev *ud, struct udma_##res *p) \ 108 { \ 109 clear_bit(p->id, ud->res##_map); \ 110 } \ 111 EXPORT_SYMBOL(xudma_##res##_put) 112 XUDMA_GET_PUT_RESOURCE(tchan); 113 XUDMA_GET_PUT_RESOURCE(rchan); 114 115 struct udma_rflow *xudma_rflow_get(struct udma_dev *ud, int id) 116 { 117 return __udma_get_rflow(ud, id); 118 } 119 EXPORT_SYMBOL(xudma_rflow_get); 120 121 void xudma_rflow_put(struct udma_dev *ud, struct udma_rflow *p) 122 { 123 __udma_put_rflow(ud, p); 124 } 125 EXPORT_SYMBOL(xudma_rflow_put); 126 127 int xudma_get_rflow_ring_offset(struct udma_dev *ud) 128 { 129 return ud->tflow_cnt; 130 } 131 EXPORT_SYMBOL(xudma_get_rflow_ring_offset); 132 133 #define XUDMA_GET_RESOURCE_ID(res) \ 134 int xudma_##res##_get_id(struct udma_##res *p) \ 135 { \ 136 return p->id; \ 137 } \ 138 EXPORT_SYMBOL(xudma_##res##_get_id) 139 XUDMA_GET_RESOURCE_ID(tchan); 140 XUDMA_GET_RESOURCE_ID(rchan); 141 XUDMA_GET_RESOURCE_ID(rflow); 142 143 /* Exported register access functions */ 144 #define XUDMA_RT_IO_FUNCTIONS(res) \ 145 u32 xudma_##res##rt_read(struct udma_##res *p, int reg) \ 146 { \ 147 if (!p) \ 148 return 0; \ 149 return udma_read(p->reg_rt, reg); \ 150 } \ 151 EXPORT_SYMBOL(xudma_##res##rt_read); \ 152 \ 153 void xudma_##res##rt_write(struct udma_##res *p, int reg, u32 val) \ 154 { \ 155 if (!p) \ 156 return; \ 157 udma_write(p->reg_rt, reg, val); \ 158 } \ 159 EXPORT_SYMBOL(xudma_##res##rt_write) 160 XUDMA_RT_IO_FUNCTIONS(tchan); 161 XUDMA_RT_IO_FUNCTIONS(rchan); 162 163 int xudma_is_pktdma(struct udma_dev *ud) 164 { 165 return ud->match_data->type == DMA_TYPE_PKTDMA; 166 } 167 EXPORT_SYMBOL(xudma_is_pktdma); 168 169 int xudma_pktdma_tflow_get_irq(struct udma_dev *ud, int udma_tflow_id) 170 { 171 const struct udma_oes_offsets *oes = &ud->soc_data->oes; 172 173 return msi_get_virq(ud->dev, udma_tflow_id + oes->pktdma_tchan_flow); 174 } 175 EXPORT_SYMBOL(xudma_pktdma_tflow_get_irq); 176 177 int xudma_pktdma_rflow_get_irq(struct udma_dev *ud, int udma_rflow_id) 178 { 179 const struct udma_oes_offsets *oes = &ud->soc_data->oes; 180 181 return msi_get_virq(ud->dev, udma_rflow_id + oes->pktdma_rchan_flow); 182 } 183 EXPORT_SYMBOL(xudma_pktdma_rflow_get_irq); 184