Lines Matching +full:ctrl +full:- +full:len
1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright(c) 2016-2018 Intel Corporation. All rights reserved.
5 #include <linux/dma-mapping.h>
11 * mei_dmam_dscr_alloc() - allocate a managed coherent buffer
17 * * 0 - on success or zero allocation request
18 * * -EINVAL - if size is not power of 2
19 * * -ENOMEM - of allocation has failed
24 if (!dscr->size) in mei_dmam_dscr_alloc()
27 if (WARN_ON(!is_power_of_2(dscr->size))) in mei_dmam_dscr_alloc()
28 return -EINVAL; in mei_dmam_dscr_alloc()
30 if (dscr->vaddr) in mei_dmam_dscr_alloc()
33 dscr->vaddr = dmam_alloc_coherent(dev->dev, dscr->size, &dscr->daddr, in mei_dmam_dscr_alloc()
35 if (!dscr->vaddr) in mei_dmam_dscr_alloc()
36 return -ENOMEM; in mei_dmam_dscr_alloc()
42 * mei_dmam_dscr_free() - free a managed coherent buffer
50 if (!dscr->vaddr) in mei_dmam_dscr_free()
53 dmam_free_coherent(dev->dev, dscr->size, dscr->vaddr, dscr->daddr); in mei_dmam_dscr_free()
54 dscr->vaddr = NULL; in mei_dmam_dscr_free()
58 * mei_dmam_ring_free() - free dma ring buffers
66 mei_dmam_dscr_free(dev, &dev->dr_dscr[i]); in mei_dmam_ring_free()
70 * mei_dmam_ring_alloc() - allocate dma ring buffers
73 * Return: -ENOMEM on allocation failure 0 otherwise
80 if (mei_dmam_dscr_alloc(dev, &dev->dr_dscr[i])) in mei_dmam_ring_alloc()
87 return -ENOMEM; in mei_dmam_ring_alloc()
91 * mei_dma_ring_is_allocated() - check if dma ring is allocated
98 return !!dev->dr_dscr[DMA_DSCR_HOST].vaddr; in mei_dma_ring_is_allocated()
104 return (struct hbm_dma_ring_ctrl *)dev->dr_dscr[DMA_DSCR_CTRL].vaddr; in mei_dma_ring_ctrl()
108 * mei_dma_ring_reset() - reset the dma control block
113 struct hbm_dma_ring_ctrl *ctrl = mei_dma_ring_ctrl(dev); in mei_dma_ring_reset() local
115 if (!ctrl) in mei_dma_ring_reset()
118 memset(ctrl, 0, sizeof(*ctrl)); in mei_dma_ring_reset()
122 * mei_dma_copy_from() - copy from dma ring into buffer
131 unsigned char *dbuf = dev->dr_dscr[DMA_DSCR_DEVICE].vaddr; in mei_dma_copy_from()
142 * mei_dma_copy_to() - copy to a buffer to the dma ring
151 unsigned char *hbuf = dev->dr_dscr[DMA_DSCR_HOST].vaddr; in mei_dma_copy_to()
162 * mei_dma_ring_read() - read data from the ring
165 * @len: length to read.
167 void mei_dma_ring_read(struct mei_device *dev, unsigned char *buf, u32 len) in mei_dma_ring_read() argument
169 struct hbm_dma_ring_ctrl *ctrl = mei_dma_ring_ctrl(dev); in mei_dma_ring_read() local
173 if (WARN_ON(!ctrl)) in mei_dma_ring_read()
176 dev_dbg(dev->dev, "reading from dma %u bytes\n", len); in mei_dma_ring_read()
178 if (!len) in mei_dma_ring_read()
181 dbuf_depth = dev->dr_dscr[DMA_DSCR_DEVICE].size >> 2; in mei_dma_ring_read()
182 rd_idx = READ_ONCE(ctrl->dbuf_rd_idx) & (dbuf_depth - 1); in mei_dma_ring_read()
183 slots = mei_data2slots(len); in mei_dma_ring_read()
190 buf += mei_dma_copy_from(dev, buf, rd_idx, dbuf_depth - rd_idx); in mei_dma_ring_read()
191 rem = slots - (dbuf_depth - rd_idx); in mei_dma_ring_read()
199 WRITE_ONCE(ctrl->dbuf_rd_idx, ctrl->dbuf_rd_idx + slots); in mei_dma_ring_read()
204 return dev->dr_dscr[DMA_DSCR_HOST].size >> 2; in mei_dma_ring_hbuf_depth()
208 * mei_dma_ring_empty_slots() - calaculate number of empty slots in dma ring
215 struct hbm_dma_ring_ctrl *ctrl = mei_dma_ring_ctrl(dev); in mei_dma_ring_empty_slots() local
221 if (WARN_ON(!ctrl)) in mei_dma_ring_empty_slots()
226 rd_idx = READ_ONCE(ctrl->hbuf_rd_idx); in mei_dma_ring_empty_slots()
227 wr_idx = READ_ONCE(ctrl->hbuf_wr_idx); in mei_dma_ring_empty_slots()
230 empty = rd_idx - wr_idx; in mei_dma_ring_empty_slots()
232 empty = hbuf_depth - (wr_idx - rd_idx); in mei_dma_ring_empty_slots()
238 * mei_dma_ring_write - write data to dma ring host buffer
242 * @len: data length
244 void mei_dma_ring_write(struct mei_device *dev, unsigned char *buf, u32 len) in mei_dma_ring_write() argument
246 struct hbm_dma_ring_ctrl *ctrl = mei_dma_ring_ctrl(dev); in mei_dma_ring_write() local
250 if (WARN_ON(!ctrl)) in mei_dma_ring_write()
253 dev_dbg(dev->dev, "writing to dma %u bytes\n", len); in mei_dma_ring_write()
255 wr_idx = READ_ONCE(ctrl->hbuf_wr_idx) & (hbuf_depth - 1); in mei_dma_ring_write()
256 slots = mei_data2slots(len); in mei_dma_ring_write()
259 buf += mei_dma_copy_to(dev, buf, wr_idx, hbuf_depth - wr_idx); in mei_dma_ring_write()
260 rem = slots - (hbuf_depth - wr_idx); in mei_dma_ring_write()
268 WRITE_ONCE(ctrl->hbuf_wr_idx, ctrl->hbuf_wr_idx + slots); in mei_dma_ring_write()