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
133 unsigned char *dbuf = dev->dr_dscr[DMA_DSCR_DEVICE].vaddr; in mei_dma_copy_from()
144 * mei_dma_copy_to() - copy to a buffer to the dma ring
155 unsigned char *hbuf = dev->dr_dscr[DMA_DSCR_HOST].vaddr; in mei_dma_copy_to()
166 * mei_dma_ring_read() - read data from the ring
169 * @len: length to read.
171 void mei_dma_ring_read(struct mei_device *dev, unsigned char *buf, u32 len) in mei_dma_ring_read() argument
173 struct hbm_dma_ring_ctrl *ctrl = mei_dma_ring_ctrl(dev); in mei_dma_ring_read() local
177 if (WARN_ON(!ctrl)) in mei_dma_ring_read()
180 dev_dbg(dev->dev, "reading from dma %u bytes\n", len); in mei_dma_ring_read()
182 if (!len) in mei_dma_ring_read()
185 dbuf_depth = dev->dr_dscr[DMA_DSCR_DEVICE].size >> 2; in mei_dma_ring_read()
186 rd_idx = READ_ONCE(ctrl->dbuf_rd_idx) & (dbuf_depth - 1); in mei_dma_ring_read()
187 slots = mei_data2slots(len); in mei_dma_ring_read()
194 buf += mei_dma_copy_from(dev, buf, rd_idx, dbuf_depth - rd_idx); in mei_dma_ring_read()
195 rem = slots - (dbuf_depth - rd_idx); in mei_dma_ring_read()
203 WRITE_ONCE(ctrl->dbuf_rd_idx, ctrl->dbuf_rd_idx + slots); in mei_dma_ring_read()
208 return dev->dr_dscr[DMA_DSCR_HOST].size >> 2; in mei_dma_ring_hbuf_depth()
212 * mei_dma_ring_empty_slots() - calaculate number of empty slots in dma ring
219 struct hbm_dma_ring_ctrl *ctrl = mei_dma_ring_ctrl(dev); in mei_dma_ring_empty_slots() local
225 if (WARN_ON(!ctrl)) in mei_dma_ring_empty_slots()
230 rd_idx = READ_ONCE(ctrl->hbuf_rd_idx); in mei_dma_ring_empty_slots()
231 wr_idx = READ_ONCE(ctrl->hbuf_wr_idx); in mei_dma_ring_empty_slots()
234 empty = rd_idx - wr_idx; in mei_dma_ring_empty_slots()
236 empty = hbuf_depth - (wr_idx - rd_idx); in mei_dma_ring_empty_slots()
242 * mei_dma_ring_write - write data to dma ring host buffer
246 * @len: data length
248 void mei_dma_ring_write(struct mei_device *dev, unsigned char *buf, u32 len) in mei_dma_ring_write() argument
250 struct hbm_dma_ring_ctrl *ctrl = mei_dma_ring_ctrl(dev); in mei_dma_ring_write() local
254 if (WARN_ON(!ctrl)) in mei_dma_ring_write()
257 dev_dbg(dev->dev, "writing to dma %u bytes\n", len); in mei_dma_ring_write()
259 wr_idx = READ_ONCE(ctrl->hbuf_wr_idx) & (hbuf_depth - 1); in mei_dma_ring_write()
260 slots = mei_data2slots(len); in mei_dma_ring_write()
263 buf += mei_dma_copy_to(dev, buf, wr_idx, hbuf_depth - wr_idx); in mei_dma_ring_write()
264 rem = slots - (hbuf_depth - wr_idx); in mei_dma_ring_write()
272 WRITE_ONCE(ctrl->hbuf_wr_idx, ctrl->hbuf_wr_idx + slots); in mei_dma_ring_write()