Skip to content

Commit

Permalink
treewide: prefix RTOS lib/dma.h DMA_ definitions with SOF_DMA_
Browse files Browse the repository at this point in the history
Add a namespace prefix to DMA_ macro definitions in the zephyr/lib/dma.h.
This change makes it easier to identify what code is using native Zephyr
definitions (DMA_*) and which are SOF side definition (SOF_DMA_*).

To support non-Zephyr targets, add a minimimal compatibility layer
to xtos/lib/dma.h and posix/lib/dma.h. This only covers a few definitions
needed by e.g. ipc/ipc[34]/dai.c.

To support Zephyr targets that still use XTOS drivers (like imx8m),
add compatibility definitions to zephyr/lib/dma-legacy.h. It will
be later easy to drop dma-legacy.h when all targets have moved
over.

Signed-off-by: Kai Vehmanen <[email protected]>
  • Loading branch information
kv2019i committed Dec 13, 2024
1 parent 6d18ca5 commit cdc1442
Show file tree
Hide file tree
Showing 21 changed files with 212 additions and 169 deletions.
9 changes: 9 additions & 0 deletions posix/include/sof/lib/dma.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ struct comp_buffer;
*/

/* DMA direction bitmasks used to define DMA copy direction */
#define SOF_DMA_DIR_MEM_TO_MEM DMA_DIR_MEM_TO_MEM
#define SOF_DMA_DIR_HMEM_TO_LMEM DMA_DIR_HMEM_TO_LMEM
#define SOF_DMA_DIR_LMEM_TO_HMEM DMA_DIR_LMEM_TO_HMEM
#define SOF_DMA_DIR_MEM_TO_DEV DMA_DIR_MEM_TO_DEV
#define SOF_DMA_DIR_DEV_TO_MEM DMA_DIR_DEV_TO_MEM
#define SOF_DMA_DIR_DEV_TO_DEV DMA_DIR_DEV_TO_DEV
#define DMA_DIR_MEM_TO_MEM BIT(0) /**< local memory copy */
#define DMA_DIR_HMEM_TO_LMEM BIT(1) /**< host memory to local mem copy */
#define DMA_DIR_LMEM_TO_HMEM BIT(2) /**< local mem to host mem copy */
Expand All @@ -60,6 +66,7 @@ struct comp_buffer;

/* DMA dev type bitmasks used to define the type of DMA */

#define SOF_DMA_DEV_HOST DMA_DEV_HOST
#define DMA_DEV_HOST BIT(0) /**< connectable to host */
#define DMA_DEV_HDA BIT(1) /**< connectable to HD/A link */
#define DMA_DEV_SSP BIT(2) /**< connectable to SSP fifo */
Expand Down Expand Up @@ -98,6 +105,8 @@ enum dma_irq_cmd {
DMA_IRQ_UNMASK
};

#define SOF_DMA_CHAN_INVALID DMA_CHAN_INVALID
#define SOF_DMA_CORE_INVALID DMA_CORE_INVALID
#define DMA_CHAN_INVALID 0xFFFFFFFF
#define DMA_CORE_INVALID 0xFFFFFFFF

Expand Down
8 changes: 4 additions & 4 deletions src/audio/chain_dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -536,18 +536,18 @@ static int chain_task_init(struct comp_dev *dev, uint8_t host_dma_id, uint8_t li

/* request HDA DMA with shared access privilege */
dir = (cd->stream_direction == SOF_IPC_STREAM_PLAYBACK) ?
DMA_DIR_HMEM_TO_LMEM : DMA_DIR_LMEM_TO_HMEM;
SOF_DMA_DIR_HMEM_TO_LMEM : SOF_DMA_DIR_LMEM_TO_HMEM;

cd->dma_host = dma_get(dir, 0, DMA_DEV_HOST, DMA_ACCESS_SHARED);
cd->dma_host = dma_get(dir, 0, SOF_DMA_DEV_HOST, SOF_DMA_ACCESS_SHARED);
if (!cd->dma_host) {
comp_err(dev, "chain_task_init(): dma_get() returned NULL");
return -EINVAL;
}

dir = (cd->stream_direction == SOF_IPC_STREAM_PLAYBACK) ?
DMA_DIR_MEM_TO_DEV : DMA_DIR_DEV_TO_MEM;
SOF_DMA_DIR_MEM_TO_DEV : SOF_DMA_DIR_DEV_TO_MEM;

cd->dma_link = dma_get(dir, DMA_CAP_HDA, DMA_DEV_HDA, DMA_ACCESS_SHARED);
cd->dma_link = dma_get(dir, SOF_DMA_CAP_HDA, SOF_DMA_DEV_HDA, SOF_DMA_ACCESS_SHARED);
if (!cd->dma_link) {
dma_put(cd->dma_host);
comp_err(dev, "chain_task_init(): dma_get() returned NULL");
Expand Down
30 changes: 15 additions & 15 deletions src/audio/dai-zephyr.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,11 @@ static int dai_get_fifo(struct dai *dai, int direction, int stream_id)
}

/* this is called by DMA driver every time descriptor has completed */
static enum dma_cb_status
static enum sof_dma_cb_status
dai_dma_cb(struct dai_data *dd, struct comp_dev *dev, uint32_t bytes,
pcm_converter_func *converter)
{
enum dma_cb_status dma_status = DMA_CB_STATUS_RELOAD;
enum sof_dma_cb_status dma_status = SOF_DMA_CB_STATUS_RELOAD;
int ret;

comp_dbg(dev, "dai_dma_cb()");
Expand All @@ -258,7 +258,7 @@ dai_dma_cb(struct dai_data *dd, struct comp_dev *dev, uint32_t bytes,
dai_trigger_op(dd->dai, COMP_TRIGGER_STOP, dev->direction);

/* tell DMA not to reload */
dma_status = DMA_CB_STATUS_END;
dma_status = SOF_DMA_CB_STATUS_END;
}

/* is our pipeline handling an XRUN ? */
Expand Down Expand Up @@ -401,11 +401,11 @@ dai_dma_cb(struct dai_data *dd, struct comp_dev *dev, uint32_t bytes,
}

/* this is called by DMA driver every time descriptor has completed */
static enum dma_cb_status
static enum sof_dma_cb_status
dai_dma_multi_endpoint_cb(struct dai_data *dd, struct comp_dev *dev, uint32_t frames,
struct comp_buffer *multi_endpoint_buffer)
{
enum dma_cb_status dma_status = DMA_CB_STATUS_RELOAD;
enum sof_dma_cb_status dma_status = SOF_DMA_CB_STATUS_RELOAD;
uint32_t i, bytes;

comp_dbg(dev, "dai_dma_multi_endpoint_cb()");
Expand All @@ -416,7 +416,7 @@ dai_dma_multi_endpoint_cb(struct dai_data *dd, struct comp_dev *dev, uint32_t fr
dai_trigger_op(dd->dai, COMP_TRIGGER_STOP, dev->direction);

/* tell DMA not to reload */
dma_status = DMA_CB_STATUS_END;
dma_status = SOF_DMA_CB_STATUS_END;
}

/* is our pipeline handling an XRUN ? */
Expand Down Expand Up @@ -477,9 +477,9 @@ int dai_common_new(struct dai_data *dd, struct comp_dev *dev,

/* request GP LP DMA with shared access privilege */
dir = dai_cfg->direction == SOF_IPC_STREAM_PLAYBACK ?
DMA_DIR_MEM_TO_DEV : DMA_DIR_DEV_TO_MEM;
SOF_DMA_DIR_MEM_TO_DEV : SOF_DMA_DIR_DEV_TO_MEM;

dd->dma = dma_get(dir, dd->dai->dma_caps, dd->dai->dma_dev, DMA_ACCESS_SHARED);
dd->dma = dma_get(dir, dd->dai->dma_caps, dd->dai->dma_dev, SOF_DMA_ACCESS_SHARED);
if (!dd->dma) {
dai_put(dd->dai);
comp_err(dev, "dma_get() failed to get shared access to DMA.");
Expand Down Expand Up @@ -730,13 +730,13 @@ static int dai_set_sg_config(struct dai_data *dd, struct comp_dev *dev, uint32_t
/* set up DMA configuration */
if (dev->direction == SOF_IPC_STREAM_PLAYBACK) {
dd->process = pcm_get_conversion_function(local_fmt, dma_fmt);
config->direction = DMA_DIR_MEM_TO_DEV;
config->direction = SOF_DMA_DIR_MEM_TO_DEV;
err = dai_get_dma_slot(dd, dev, &config->dest_dev);
if (err < 0)
return err;
} else {
dd->process = pcm_get_conversion_function(dma_fmt, local_fmt);
config->direction = DMA_DIR_DEV_TO_MEM;
config->direction = SOF_DMA_DIR_DEV_TO_MEM;
err = dai_get_dma_slot(dd, dev, &config->src_dev);
if (err < 0)
return err;
Expand Down Expand Up @@ -1123,7 +1123,7 @@ int dai_common_config_prepare(struct dai_data *dd, struct comp_dev *dev)
comp_dbg(dev, "channel = %d", channel);

/* do nothing for asking for channel free, for compatibility. */
if (channel == DMA_CHAN_INVALID) {
if (channel == SOF_DMA_CHAN_INVALID) {
comp_err(dev, "dai_config is not set yet!");
return -EINVAL;
}
Expand Down Expand Up @@ -1292,7 +1292,7 @@ static int dai_comp_trigger_internal(struct dai_data *dd, struct comp_dev *dev,
* Only applies to non HD-DMA links as HD-DMA read/write pointer
* is not reset during stop/config/start
*/
if (!(dd->dai->dma_caps & DMA_CAP_HDA))
if (!(dd->dai->dma_caps & SOF_DMA_CAP_HDA))
audio_stream_reset(&dd->dma_buffer->stream);

/* only start the DAI if we are not XRUN handling */
Expand Down Expand Up @@ -1543,7 +1543,7 @@ int dai_zephyr_multi_endpoint_copy(struct dai_data **dd, struct comp_dev *dev,
}

for (i = 0; i < num_endpoints; i++) {
enum dma_cb_status status;
enum sof_dma_cb_status status;
uint32_t copy_bytes;

/* trigger optional DAI_TRIGGER_COPY which prepares dai to copy */
Expand All @@ -1552,7 +1552,7 @@ int dai_zephyr_multi_endpoint_copy(struct dai_data **dd, struct comp_dev *dev,
comp_warn(dev, "dai trigger copy failed");

status = dai_dma_multi_endpoint_cb(dd[i], dev, frames, multi_endpoint_buffer);
if (status == DMA_CB_STATUS_END)
if (status == SOF_DMA_CB_STATUS_END)
dma_stop(dd[i]->chan->dma->z_dev, dd[i]->chan->index);

copy_bytes = frames * audio_stream_frame_bytes(&dd[i]->dma_buffer->stream);
Expand Down Expand Up @@ -1742,7 +1742,7 @@ int dai_common_copy(struct dai_data *dd, struct comp_dev *dev, pcm_converter_fun
if (ret < 0)
comp_warn(dev, "dai trigger copy failed");

if (dai_dma_cb(dd, dev, copy_bytes, converter) == DMA_CB_STATUS_END)
if (dai_dma_cb(dd, dev, copy_bytes, converter) == SOF_DMA_CB_STATUS_END)
dma_stop(dd->chan->dma->z_dev, dd->chan->index);

ret = dma_reload(dd->chan->dma->z_dev, dd->chan->index, 0, 0, copy_bytes);
Expand Down
18 changes: 9 additions & 9 deletions src/audio/host-zephyr.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ static int create_local_elems(struct host_data *hd, struct comp_dev *dev, uint32
int err;

dir = direction == SOF_IPC_STREAM_PLAYBACK ?
DMA_DIR_HMEM_TO_LMEM : DMA_DIR_LMEM_TO_HMEM;
SOF_DMA_DIR_HMEM_TO_LMEM : SOF_DMA_DIR_LMEM_TO_HMEM;

/* if host buffer set we need to allocate local buffer */
if (hd->host.elem_array.count) {
Expand Down Expand Up @@ -612,9 +612,9 @@ int host_common_new(struct host_data *hd, struct comp_dev *dev,
hd->ipc_host = *ipc_host;
/* request HDA DMA with shared access privilege */
dir = hd->ipc_host.direction == SOF_IPC_STREAM_PLAYBACK ?
DMA_DIR_HMEM_TO_LMEM : DMA_DIR_LMEM_TO_HMEM;
SOF_DMA_DIR_HMEM_TO_LMEM : SOF_DMA_DIR_LMEM_TO_HMEM;

hd->dma = dma_get(dir, 0, DMA_DEV_HOST, DMA_ACCESS_SHARED);
hd->dma = dma_get(dir, 0, SOF_DMA_DEV_HOST, SOF_DMA_ACCESS_SHARED);
if (!hd->dma) {
comp_err(dev, "dma_get() returned NULL");
return -ENODEV;
Expand Down Expand Up @@ -806,11 +806,11 @@ int host_common_params(struct host_data *hd, struct comp_dev *dev,

/* determine source and sink buffer elements */
if (params->direction == SOF_IPC_STREAM_PLAYBACK) {
config->direction = DMA_DIR_HMEM_TO_LMEM;
config->direction = SOF_DMA_DIR_HMEM_TO_LMEM;
hd->source = &hd->host;
hd->sink = &hd->local;
} else {
config->direction = DMA_DIR_LMEM_TO_HMEM;
config->direction = SOF_DMA_DIR_LMEM_TO_HMEM;
hd->source = &hd->local;
hd->sink = &hd->host;
}
Expand Down Expand Up @@ -923,8 +923,8 @@ int host_common_params(struct host_data *hd, struct comp_dev *dev,
for (i = 0; i < config->elem_array.count; i++) {
sg_elem = config->elem_array.elems + i;

if (config->direction == DMA_DIR_HMEM_TO_LMEM ||
config->direction == DMA_DIR_DEV_TO_MEM)
if (config->direction == SOF_DMA_DIR_HMEM_TO_LMEM ||
config->direction == SOF_DMA_DIR_DEV_TO_MEM)
addr = sg_elem->dest;
else
addr = sg_elem->src;
Expand All @@ -938,12 +938,12 @@ int host_common_params(struct host_data *hd, struct comp_dev *dev,
dma_block_cfg->block_size = buffer_bytes;

switch (config->direction) {
case DMA_DIR_LMEM_TO_HMEM:
case SOF_DMA_DIR_LMEM_TO_HMEM:
dma_cfg->channel_direction = MEMORY_TO_HOST;
dma_block_cfg->source_address = buffer_addr;
dma_block_cfg->dest_address = hd->config.elem_array.elems[0].dest;
break;
case DMA_DIR_HMEM_TO_LMEM:
case SOF_DMA_DIR_HMEM_TO_LMEM:
dma_cfg->channel_direction = HOST_TO_MEMORY;
dma_block_cfg->dest_address = buffer_addr;
dma_block_cfg->source_address = hd->config.elem_array.elems[0].src;
Expand Down
8 changes: 4 additions & 4 deletions src/drivers/generic/dummy-dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,8 @@ static int dummy_dma_set_config(struct dma_chan_data *channel,

channel->direction = config->direction;

if (config->direction != DMA_DIR_HMEM_TO_LMEM &&
config->direction != DMA_DIR_LMEM_TO_HMEM) {
if (config->direction != SOF_DMA_DIR_HMEM_TO_LMEM &&
config->direction != SOF_DMA_DIR_LMEM_TO_HMEM) {
/* Shouldn't even happen though */
tr_err(&ddma_tr, "dummy-dmac: %d channel %d invalid direction %d",
channel->dma->plat_data.id, channel->index,
Expand Down Expand Up @@ -490,10 +490,10 @@ static int dummy_dma_get_data_size(struct dma_chan_data *channel,
uint32_t size = dummy_dma_compute_avail_data(pdata);

switch (channel->direction) {
case DMA_DIR_HMEM_TO_LMEM:
case SOF_DMA_DIR_HMEM_TO_LMEM:
*avail = size;
break;
case DMA_DIR_LMEM_TO_HMEM:
case SOF_DMA_DIR_LMEM_TO_HMEM:
*free = size;
break;
default:
Expand Down
4 changes: 2 additions & 2 deletions src/drivers/imx/ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ int platform_ipc_init(struct ipc *ipc)
PLATFORM_PAGE_TABLE_SIZE);
if (iipc->dh_buffer.page_table)
bzero(iipc->dh_buffer.page_table, PLATFORM_PAGE_TABLE_SIZE);
iipc->dh_buffer.dmac = dma_get(DMA_DIR_HMEM_TO_LMEM, 0, DMA_DEV_HOST,
DMA_ACCESS_SHARED);
iipc->dh_buffer.dmac = dma_get(SOF_DMA_DIR_HMEM_TO_LMEM, 0, SOF_DMA_DEV_HOST,
SOF_DMA_ACCESS_SHARED);
if (!iipc->dh_buffer.dmac) {
tr_err(&ipc_tr, "Unable to find DMA for host page table");
sof_panic(SOF_IPC_PANIC_IPC);
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/imx/micfil.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ const struct dai_driver micfil_driver = {
.type = SOF_DAI_IMX_MICFIL,
.uid = SOF_UUID(micfil_uuid),
.tctx = &micfil_tr,
.dma_dev = DMA_DEV_MICFIL,
.dma_dev = SOF_DMA_DEV_MICFIL,
.ops = {
.trigger = micfil_trigger,
.set_config = micfil_set_config,
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/imx/sai.c
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ const struct dai_driver sai_driver = {
.type = SOF_DAI_IMX_SAI,
.uid = SOF_UUID(sai_uuid),
.tctx = &sai_tr,
.dma_dev = DMA_DEV_SAI,
.dma_dev = SOF_DMA_DEV_SAI,
.ops = {
.trigger = sai_trigger,
.set_config = sai_set_config,
Expand Down
22 changes: 11 additions & 11 deletions src/drivers/imx/sdma.c
Original file line number Diff line number Diff line change
Expand Up @@ -664,20 +664,20 @@ static int sdma_read_config(struct dma_chan_data *channel,
uint32_t dma_dev = dd->dai->drv->dma_dev;

switch (config->direction) {
case DMA_DIR_MEM_TO_DEV:
case SOF_DMA_DIR_MEM_TO_DEV:
pdata->hw_event = config->dest_dev;
pdata->sdma_chan_type = SDMA_CHAN_TYPE_MCU2SHP;
pdata->fifo_paddr = config->elem_array.elems[0].dest;
break;
case DMA_DIR_DEV_TO_MEM:
case SOF_DMA_DIR_DEV_TO_MEM:
pdata->hw_event = config->src_dev;
if (dma_dev == DMA_DEV_MICFIL)
if (dma_dev == SOF_DMA_DEV_MICFIL)
pdata->sdma_chan_type = SDMA_CHAN_TYPE_SAI2MCU;
else
pdata->sdma_chan_type = SDMA_CHAN_TYPE_SHP2MCU;
pdata->fifo_paddr = config->elem_array.elems[0].src;
break;
case DMA_DIR_MEM_TO_MEM:
case SOF_DMA_DIR_MEM_TO_MEM:
pdata->sdma_chan_type = SDMA_CHAN_TYPE_AP2AP;
/* Fallthrough, TODO: implement to support m2m */
default:
Expand All @@ -687,13 +687,13 @@ static int sdma_read_config(struct dma_chan_data *channel,
}

for (i = 0; i < config->elem_array.count; i++) {
if (config->direction == DMA_DIR_MEM_TO_DEV &&
if (config->direction == SOF_DMA_DIR_MEM_TO_DEV &&
pdata->fifo_paddr != config->elem_array.elems[i].dest) {
tr_err(&sdma_tr, "sdma_read_config: FIFO changes address!");
return -EINVAL;
}

if (config->direction == DMA_DIR_DEV_TO_MEM &&
if (config->direction == SOF_DMA_DIR_DEV_TO_MEM &&
pdata->fifo_paddr != config->elem_array.elems[i].src) {
tr_err(&sdma_tr, "sdma_read_config: FIFO changes address!");
return -EINVAL;
Expand Down Expand Up @@ -768,15 +768,15 @@ static int sdma_prep_desc(struct dma_chan_data *channel,
* is in buf_xaddr.
*/
switch (config->direction) {
case DMA_DIR_MEM_TO_DEV:
case SOF_DMA_DIR_MEM_TO_DEV:
bd->buf_addr = config->elem_array.elems[i].src;
width = config->src_width;
break;
case DMA_DIR_DEV_TO_MEM:
case SOF_DMA_DIR_DEV_TO_MEM:
bd->buf_addr = config->elem_array.elems[i].dest;
width = config->dest_width;
break;
case DMA_DIR_MEM_TO_MEM:
case SOF_DMA_DIR_MEM_TO_MEM:
bd->buf_addr = config->elem_array.elems[i].src;
bd->buf_xaddr = config->elem_array.elems[i].dest;
width = config->dest_width;
Expand Down Expand Up @@ -985,10 +985,10 @@ static int sdma_get_data_size(struct dma_chan_data *channel, uint32_t *avail,

*avail = *free = 0;
switch (channel->direction) {
case DMA_DIR_MEM_TO_DEV:
case SOF_DMA_DIR_MEM_TO_DEV:
*free = result_data;
break;
case DMA_DIR_DEV_TO_MEM:
case SOF_DMA_DIR_DEV_TO_MEM:
*avail = result_data;
break;
default:
Expand Down
4 changes: 2 additions & 2 deletions src/ipc/ipc3/dai.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ int dai_config_dma_channel(struct dai_data *dd, struct comp_dev *dev, const void
/* other types of DAIs not handled for now */
comp_err(dev, "dai_config_dma_channel(): Unknown dai type %d",
config->type);
channel = DMA_CHAN_INVALID;
channel = SOF_DMA_CHAN_INVALID;
break;
}

Expand Down Expand Up @@ -367,7 +367,7 @@ int dai_config(struct dai_data *dd, struct comp_dev *dev, struct ipc_config_dai
}
#endif
/* do nothing for asking for channel free, for compatibility. */
if (dai_config_dma_channel(dd, dev, spec_config) == DMA_CHAN_INVALID)
if (dai_config_dma_channel(dd, dev, spec_config) == SOF_DMA_CHAN_INVALID)
return 0;

/* allocated dai_config if not yet */
Expand Down
Loading

0 comments on commit cdc1442

Please sign in to comment.