Re: [PATCH v2 02/14] soc: ti: k3: add navss ringacc driver
From: Vignesh Raghavendra
Date: Mon Sep 09 2019 - 03:24:57 EST
Hi,
On 09/09/19 11:39 AM, Tero Kristo wrote:
[...]
>> diff --git a/drivers/soc/ti/k3-ringacc.c b/drivers/soc/ti/k3-ringacc.c
>> new file mode 100644
>> index 000000000000..401dfc963319
>> --- /dev/null
>> +++ b/drivers/soc/ti/k3-ringacc.c
>> @@ -0,0 +1,1191 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/*
>> + * TI K3 NAVSS Ring Accelerator subsystem driver
>> + *
>> + * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com
>> + */
>> +
>> +#include <linux/dma-mapping.h>
>> +#include <linux/io.h>
>> +#include <linux/module.h>
>> +#include <linux/of.h>
>> +#include <linux/platform_device.h>
>> +#include <linux/pm_runtime.h>
>> +#include <linux/soc/ti/k3-ringacc.h>
>> +#include <linux/soc/ti/ti_sci_protocol.h>
>> +#include <linux/soc/ti/ti_sci_inta_msi.h>
>> +#include <linux/of_irq.h>
>> +#include <linux/irqdomain.h>
>> +
>> +static LIST_HEAD(k3_ringacc_list);
>> +static DEFINE_MUTEX(k3_ringacc_list_lock);
>> +
>> +#ifdef CONFIG_TI_K3_RINGACC_DEBUG
>> +#defineÂÂÂ k3_nav_dbg(dev, arg...) dev_err(dev, arg)
>
> dev_err seems exaggeration for debug purposes, maybe just dev_info.
If you make this dev_dbg(), it should be possible to just enable
CONFIG_DYNAMIC_DEBUG[1] and control whether or not debug prints are
enabled for this module. Have you explored that option? If that works we
may not need CONFIG_TI_K3_RINGACC_DEBUG at all.
[1] Documentation/admin-guide/dynamic-debug-howto.rst
Regards
Vignesh
>
>> +staticÂÂÂ void dbg_writel(u32 v, void __iomem *reg)
>> +{
>> +ÂÂÂ pr_err("WRITEL(32): v(%08X)-->reg(%p)\n", v, reg);
>
> Again, maybe just pr_info.
>
>> +ÂÂÂ writel(v, reg);
>> +}
>> +
>> +staticÂÂÂ u32 dbg_readl(void __iomem *reg)
>> +{
>> +ÂÂÂ u32 v;
>> +
>> +ÂÂÂ v = readl(reg);
>> +ÂÂÂ pr_err("READL(32): v(%08X)<--reg(%p)\n", v, reg);
>> +ÂÂÂ return v;
>> +}
>> +#else
>> +#defineÂÂÂ k3_nav_dbg(dev, arg...) dev_dbg(dev, arg)
>> +#define dbg_writel(v, reg) writel(v, reg)
>
> Do you need to use hard writel, writel_relaxed is not enough?
>
>> +
>> +#define dbg_readl(reg) readl(reg)
>
> Same as above but for read?
>
>> +#endif
>> +
>> +#define K3_RINGACC_CFG_RING_SIZE_ELCNT_MASKÂÂÂÂÂÂÂ GENMASK(19, 0)
>> +
>> +/**
>> + * struct k3_ring_rt_regs -Â The RA Control/Status Registers region
>> + */
>> +struct k3_ring_rt_regs {
>> +ÂÂÂ u32ÂÂÂ resv_16[4];
>> +ÂÂÂ u32ÂÂÂ db;ÂÂÂÂÂÂÂ /* RT Ring N Doorbell Register */
>> +ÂÂÂ u32ÂÂÂ resv_4[1];
>> +ÂÂÂ u32ÂÂÂ occ;ÂÂÂÂÂÂÂ /* RT Ring N Occupancy Register */
>> +ÂÂÂ u32ÂÂÂ indx;ÂÂÂÂÂÂÂ /* RT Ring N Current Index Register */
>> +ÂÂÂ u32ÂÂÂ hwocc;ÂÂÂÂÂÂÂ /* RT Ring N Hardware Occupancy Register */
>> +ÂÂÂ u32ÂÂÂ hwindx;ÂÂÂÂÂÂÂ /* RT Ring N Current Index Register */
>> +};
>> +
>> +#define K3_RINGACC_RT_REGS_STEPÂÂÂ 0x1000
>> +
>> +/**
>> + * struct k3_ring_fifo_regs -Â The Ring Accelerator Queues Registers
>> region
>> + */
>> +struct k3_ring_fifo_regs {
>> +ÂÂÂ u32ÂÂÂ head_data[128];ÂÂÂÂÂÂÂ /* Ring Head Entry Data Registers */
>> +ÂÂÂ u32ÂÂÂ tail_data[128];ÂÂÂÂÂÂÂ /* Ring Tail Entry Data Registers */
>> +ÂÂÂ u32ÂÂÂ peek_head_data[128];ÂÂÂ /* Ring Peek Head Entry Data Regs */
>> +ÂÂÂ u32ÂÂÂ peek_tail_data[128];ÂÂÂ /* Ring Peek Tail Entry Data Regs */
>> +};
>> +
>> +/**
>> + * struct k3_ringacc_proxy_gcfg_regs - RA Proxy Global Config MMIO
>> Region
>> + */
>> +struct k3_ringacc_proxy_gcfg_regs {
>> +ÂÂÂ u32ÂÂÂ revision;ÂÂÂ /* Revision Register */
>> +ÂÂÂ u32ÂÂÂ config;ÂÂÂÂÂÂÂ /* Config Register */
>> +};
>> +
>> +#define K3_RINGACC_PROXY_CFG_THREADS_MASKÂÂÂÂÂÂÂ GENMASK(15, 0)
>> +
>> +/**
>> + * struct k3_ringacc_proxy_target_regs -Â Proxy Datapath MMIO Region
>> + */
>> +struct k3_ringacc_proxy_target_regs {
>> +ÂÂÂ u32ÂÂÂ control;ÂÂÂ /* Proxy Control Register */
>> +ÂÂÂ u32ÂÂÂ status;ÂÂÂÂÂÂÂ /* Proxy Status Register */
>> +ÂÂÂ u8ÂÂÂ resv_512[504];
>> +ÂÂÂ u32ÂÂÂ data[128];ÂÂÂ /* Proxy Data Register */
>> +};
>> +
>> +#define K3_RINGACC_PROXY_TARGET_STEPÂÂÂ 0x1000
>> +#define K3_RINGACC_PROXY_NOT_USEDÂÂÂ (-1)
>> +
>> +enum k3_ringacc_proxy_access_mode {
>> +ÂÂÂ PROXY_ACCESS_MODE_HEAD = 0,
>> +ÂÂÂ PROXY_ACCESS_MODE_TAIL = 1,
>> +ÂÂÂ PROXY_ACCESS_MODE_PEEK_HEAD = 2,
>> +ÂÂÂ PROXY_ACCESS_MODE_PEEK_TAIL = 3,
>> +};
>> +
>> +#define K3_RINGACC_FIFO_WINDOW_SIZE_BYTESÂ (512U)
>> +#define K3_RINGACC_FIFO_REGS_STEPÂÂÂ 0x1000
>> +#define K3_RINGACC_MAX_DB_RING_CNTÂÂÂ (127U)
>> +
>> +/**
>> + * struct k3_ring_ops -Â Ring operations
>> + */
>> +struct k3_ring_ops {
>> +ÂÂÂ int (*push_tail)(struct k3_ring *ring, void *elm);
>> +ÂÂÂ int (*push_head)(struct k3_ring *ring, void *elm);
>> +ÂÂÂ int (*pop_tail)(struct k3_ring *ring, void *elm);
>> +ÂÂÂ int (*pop_head)(struct k3_ring *ring, void *elm);
>> +};
>> +
>> +/**
>> + * struct k3_ring - RA Ring descriptor
>> + *
>> + * @rt - Ring control/status registers
>> + * @fifos - Ring queues registers
>> + * @proxy - Ring Proxy Datapath registers
>> + * @ring_mem_dma - Ring buffer dma address
>> + * @ring_mem_virt - Ring buffer virt address
>> + * @ops - Ring operations
>> + * @size - Ring size in elements
>> + * @elm_size - Size of the ring element
>> + * @mode - Ring mode
>> + * @flags - flags
>> + * @free - Number of free elements
>> + * @occ - Ring occupancy
>> + * @windex - Write index (only for @K3_RINGACC_RING_MODE_RING)
>> + * @rindex - Read index (only for @K3_RINGACC_RING_MODE_RING)
>> + * @ring_id - Ring Id
>> + * @parent - Pointer on struct @k3_ringacc
>> + * @use_count - Use count for shared rings
>> + * @proxy_id - RA Ring Proxy Id (only if @K3_RINGACC_RING_USE_PROXY)
>> + */
>> +struct k3_ring {
>> +ÂÂÂ struct k3_ring_rt_regs __iomem *rt;
>> +ÂÂÂ struct k3_ring_fifo_regs __iomem *fifos;
>> + struct k3_ringacc_proxy_target_regs __iomem *proxy;
>> +ÂÂÂ dma_addr_tÂÂÂ ring_mem_dma;
>> +ÂÂÂ voidÂÂÂÂÂÂÂ *ring_mem_virt;
>> +ÂÂÂ struct k3_ring_ops *ops;
>> +ÂÂÂ u32ÂÂÂÂÂÂÂ size;
>> +ÂÂÂ enum k3_ring_size elm_size;
>> +ÂÂÂ enum k3_ring_mode mode;
>> +ÂÂÂ u32ÂÂÂÂÂÂÂ flags;
>> +#define K3_RING_FLAG_BUSYÂÂÂ BIT(1)
>> +#define K3_RING_FLAG_SHAREDÂÂÂ BIT(2)
>> +ÂÂÂ u32ÂÂÂÂÂÂÂ free;
>> +ÂÂÂ u32ÂÂÂÂÂÂÂ occ;
>> +ÂÂÂ u32ÂÂÂÂÂÂÂ windex;
>> +ÂÂÂ u32ÂÂÂÂÂÂÂ rindex;
>> +ÂÂÂ u32ÂÂÂÂÂÂÂ ring_id;
>> +ÂÂÂ struct k3_ringaccÂÂÂ *parent;
>> +ÂÂÂ u32ÂÂÂÂÂÂÂ use_count;
>> +ÂÂÂ intÂÂÂÂÂÂÂ proxy_id;
>> +};
>> +
>> +/**
>> + * struct k3_ringacc - Rings accelerator descriptor
>> + *
>> + * @dev - pointer on RA device
>> + * @proxy_gcfg - RA proxy global config registers
>> + * @proxy_target_base - RA proxy datapath region
>> + * @num_rings - number of ring in RA
>> + * @rm_gp_range - general purpose rings range from tisci
>> + * @dma_ring_reset_quirk - DMA reset w/a enable
>> + * @num_proxies - number of RA proxies
>> + * @rings - array of rings descriptors (struct @k3_ring)
>> + * @list - list of RAs in the system
>> + * @tisci - pointer ti-sci handle
>> + * @tisci_ring_ops - ti-sci rings ops
>> + * @tisci_dev_id - ti-sci device id
>> + */
>> +struct k3_ringacc {
>> +ÂÂÂ struct device *dev;
>> +ÂÂÂ struct k3_ringacc_proxy_gcfg_regs __iomem *proxy_gcfg;
>> +ÂÂÂ void __iomem *proxy_target_base;
>> +ÂÂÂ u32 num_rings; /* number of rings in Ringacc module */
>> +ÂÂÂ unsigned long *rings_inuse;
>> +ÂÂÂ struct ti_sci_resource *rm_gp_range;
>> +
>> +ÂÂÂ bool dma_ring_reset_quirk;
>> +ÂÂÂ u32 num_proxies;
>> +ÂÂÂ unsigned long *proxy_inuse;
>
> proxy_inuse is not documented above.
>
>> +
>> +ÂÂÂ struct k3_ring *rings;
>> +ÂÂÂ struct list_head list;
>> +ÂÂÂ struct mutex req_lock; /* protect rings allocation */
>> +
>> +ÂÂÂ const struct ti_sci_handle *tisci;
>> +ÂÂÂ const struct ti_sci_rm_ringacc_ops *tisci_ring_ops;
>> +ÂÂÂ u32Â tisci_dev_id;
>> +};
>> +
>> +static long k3_ringacc_ring_get_fifo_pos(struct k3_ring *ring)
>> +{
>> +ÂÂÂ return K3_RINGACC_FIFO_WINDOW_SIZE_BYTES -
>> +ÂÂÂÂÂÂÂÂÂÂ (4 << ring->elm_size);
>> +}
>> +
>> +static void *k3_ringacc_get_elm_addr(struct k3_ring *ring, u32 idx)
>> +{
>> +ÂÂÂ return (idx * (4 << ring->elm_size) + ring->ring_mem_virt);
>
> The arithmetic here seems backwards compared to most other code I've
> seen. It would be more readable if you have it like:
>
> ring->ring_mem_virt + idx * (4 << ring->elm_size);
>
>> +}
>> +
>> +static int k3_ringacc_ring_push_mem(struct k3_ring *ring, void *elem);
>> +static int k3_ringacc_ring_pop_mem(struct k3_ring *ring, void *elem);
>> +
>> +static struct k3_ring_ops k3_ring_mode_ring_ops = {
>> +ÂÂÂÂÂÂÂ .push_tail = k3_ringacc_ring_push_mem,
>> +ÂÂÂÂÂÂÂ .pop_head = k3_ringacc_ring_pop_mem,
>> +};
>> +
>> +static int k3_ringacc_ring_push_io(struct k3_ring *ring, void *elem);
>> +static int k3_ringacc_ring_pop_io(struct k3_ring *ring, void *elem);
>> +static int k3_ringacc_ring_push_head_io(struct k3_ring *ring, void
>> *elem);
>> +static int k3_ringacc_ring_pop_tail_io(struct k3_ring *ring, void
>> *elem);
>> +
>> +static struct k3_ring_ops k3_ring_mode_msg_ops = {
>> +ÂÂÂÂÂÂÂ .push_tail = k3_ringacc_ring_push_io,
>> +ÂÂÂÂÂÂÂ .push_head = k3_ringacc_ring_push_head_io,
>> +ÂÂÂÂÂÂÂ .pop_tail = k3_ringacc_ring_pop_tail_io,
>> +ÂÂÂÂÂÂÂ .pop_head = k3_ringacc_ring_pop_io,
>> +};
>> +
>> +static int k3_ringacc_ring_push_head_proxy(struct k3_ring *ring, void
>> *elem);
>> +static int k3_ringacc_ring_push_tail_proxy(struct k3_ring *ring, void
>> *elem);
>> +static int k3_ringacc_ring_pop_head_proxy(struct k3_ring *ring, void
>> *elem);
>> +static int k3_ringacc_ring_pop_tail_proxy(struct k3_ring *ring, void
>> *elem);
>> +
>> +static struct k3_ring_ops k3_ring_mode_proxy_ops = {
>> +ÂÂÂÂÂÂÂ .push_tail = k3_ringacc_ring_push_tail_proxy,
>> +ÂÂÂÂÂÂÂ .push_head = k3_ringacc_ring_push_head_proxy,
>> +ÂÂÂÂÂÂÂ .pop_tail = k3_ringacc_ring_pop_tail_proxy,
>> +ÂÂÂÂÂÂÂ .pop_head = k3_ringacc_ring_pop_head_proxy,
>> +};
>> +
>> +#ifdef CONFIG_TI_K3_RINGACC_DEBUG
>> +void k3_ringacc_ring_dump(struct k3_ring *ring)
>> +{
>> +ÂÂÂ struct device *dev = ring->parent->dev;
>> +
>> +ÂÂÂ k3_nav_dbg(dev, "dump ring: %d\n", ring->ring_id);
>> +ÂÂÂ k3_nav_dbg(dev, "dump mem virt %p, dma %pad\n",
>> +ÂÂÂÂÂÂÂÂÂÂ ring->ring_mem_virt, &ring->ring_mem_dma);
>> +ÂÂÂ k3_nav_dbg(dev, "dump elmsize %d, size %d, mode %d, proxy_id %d\n",
>> +ÂÂÂÂÂÂÂÂÂÂ ring->elm_size, ring->size, ring->mode, ring->proxy_id);
>> +
>> +ÂÂÂ k3_nav_dbg(dev, "dump ring_rt_regs: db%08x\n",
>> +ÂÂÂÂÂÂÂÂÂÂ readl(&ring->rt->db));
>
> Why not use readl_relaxed in this func?
>
>> +ÂÂÂ k3_nav_dbg(dev, "dump occ%08x\n",
>> +ÂÂÂÂÂÂÂÂÂÂ readl(&ring->rt->occ));
>> +ÂÂÂ k3_nav_dbg(dev, "dump indx%08x\n",
>> +ÂÂÂÂÂÂÂÂÂÂ readl(&ring->rt->indx));
>> +ÂÂÂ k3_nav_dbg(dev, "dump hwocc%08x\n",
>> +ÂÂÂÂÂÂÂÂÂÂ readl(&ring->rt->hwocc));
>> +ÂÂÂ k3_nav_dbg(dev, "dump hwindx%08x\n",
>> +ÂÂÂÂÂÂÂÂÂÂ readl(&ring->rt->hwindx));
>> +
>> +ÂÂÂ if (ring->ring_mem_virt)
>> +ÂÂÂÂÂÂÂ print_hex_dump(KERN_ERR, "dump ring_mem_virt ",
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ DUMP_PREFIX_NONE, 16, 1,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ ring->ring_mem_virt, 16 * 8, false);
>> +}
>> +EXPORT_SYMBOL_GPL(k3_ringacc_ring_dump);
>
> Do you really need to export a debug function?
>
>> +#endif
>> +
>> +struct k3_ring *k3_ringacc_request_ring(struct k3_ringacc *ringacc,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ int id, u32 flags)
>> +{
>> +ÂÂÂ int proxy_id = K3_RINGACC_PROXY_NOT_USED;
>> +
>> +ÂÂÂ mutex_lock(&ringacc->req_lock);
>> +
>> +ÂÂÂ if (id == K3_RINGACC_RING_ID_ANY) {
>> +ÂÂÂÂÂÂÂ /* Request for any general purpose ring */
>> +ÂÂÂÂÂÂÂ struct ti_sci_resource_desc *gp_rings =
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ &ringacc->rm_gp_range->desc[0];
>> +ÂÂÂÂÂÂÂ unsigned long size;
>> +
>> +ÂÂÂÂÂÂÂ size = gp_rings->start + gp_rings->num;
>> +ÂÂÂÂÂÂÂ id = find_next_zero_bit(ringacc->rings_inuse, size,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ gp_rings->start);
>> +ÂÂÂÂÂÂÂ if (id == size)
>> +ÂÂÂÂÂÂÂÂÂÂÂ goto error;
>> +ÂÂÂ } else if (id < 0) {
>> +ÂÂÂÂÂÂÂ goto error;
>> +ÂÂÂ }
>> +
>> +ÂÂÂ if (test_bit(id, ringacc->rings_inuse) &&
>> +ÂÂÂÂÂÂÂ !(ringacc->rings[id].flags & K3_RING_FLAG_SHARED))
>> +ÂÂÂÂÂÂÂ goto error;
>> +ÂÂÂ else if (ringacc->rings[id].flags & K3_RING_FLAG_SHARED)
>> +ÂÂÂÂÂÂÂ goto out;
>> +
>> +ÂÂÂ if (flags & K3_RINGACC_RING_USE_PROXY) {
>> +ÂÂÂÂÂÂÂ proxy_id = find_next_zero_bit(ringacc->proxy_inuse,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ ringacc->num_proxies, 0);
>> +ÂÂÂÂÂÂÂ if (proxy_id == ringacc->num_proxies)
>> +ÂÂÂÂÂÂÂÂÂÂÂ goto error;
>> +ÂÂÂ }
>> +
>> +ÂÂÂ if (!try_module_get(ringacc->dev->driver->owner))
>> +ÂÂÂÂÂÂÂ goto error;
>> +
>> +ÂÂÂ if (proxy_id != K3_RINGACC_PROXY_NOT_USED) {
>> +ÂÂÂÂÂÂÂ set_bit(proxy_id, ringacc->proxy_inuse);
>> +ÂÂÂÂÂÂÂ ringacc->rings[id].proxy_id = proxy_id;
>> +ÂÂÂÂÂÂÂ k3_nav_dbg(ringacc->dev, "Giving ring#%d proxy#%d\n",
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ id, proxy_id);
>> +ÂÂÂ } else {
>> +ÂÂÂÂÂÂÂ k3_nav_dbg(ringacc->dev, "Giving ring#%d\n", id);
>> +ÂÂÂ }
>> +
>> +ÂÂÂ set_bit(id, ringacc->rings_inuse);
>> +out:
>> +ÂÂÂ ringacc->rings[id].use_count++;
>> +ÂÂÂ mutex_unlock(&ringacc->req_lock);
>> +ÂÂÂ return &ringacc->rings[id];
>> +
>> +error:
>> +ÂÂÂ mutex_unlock(&ringacc->req_lock);
>> +ÂÂÂ return NULL;
>> +}
>> +EXPORT_SYMBOL_GPL(k3_ringacc_request_ring);
>> +
>> +static void k3_ringacc_ring_reset_sci(struct k3_ring *ring)
>> +{
>> +ÂÂÂ struct k3_ringacc *ringacc = ring->parent;
>> +ÂÂÂ int ret;
>> +
>> +ÂÂÂ ret = ringacc->tisci_ring_ops->config(
>> +ÂÂÂÂÂÂÂÂÂÂÂ ringacc->tisci,
>> +ÂÂÂÂÂÂÂÂÂÂÂ TI_SCI_MSG_VALUE_RM_RING_COUNT_VALID,
>> +ÂÂÂÂÂÂÂÂÂÂÂ ringacc->tisci_dev_id,
>> +ÂÂÂÂÂÂÂÂÂÂÂ ring->ring_id,
>> +ÂÂÂÂÂÂÂÂÂÂÂ 0,
>> +ÂÂÂÂÂÂÂÂÂÂÂ 0,
>> +ÂÂÂÂÂÂÂÂÂÂÂ ring->size,
>> +ÂÂÂÂÂÂÂÂÂÂÂ 0,
>> +ÂÂÂÂÂÂÂÂÂÂÂ 0,
>> +ÂÂÂÂÂÂÂÂÂÂÂ 0);
>> +ÂÂÂ if (ret)
>> +ÂÂÂÂÂÂÂ dev_err(ringacc->dev, "TISCI reset ring fail (%d) ring_idx
>> %d\n",
>> +ÂÂÂÂÂÂÂÂÂÂÂ ret, ring->ring_id);
>
> Return value of sci ops is masked, why not return it and let the caller
> handle it properly?
>
> Same comment for anything similar that follows.
>
>> +}
>> +
>> +void k3_ringacc_ring_reset(struct k3_ring *ring)
>> +{
>> +ÂÂÂ if (!ring || !(ring->flags & K3_RING_FLAG_BUSY))
>> +ÂÂÂÂÂÂÂ return;
>> +
>> +ÂÂÂ ring->occ = 0;
>> +ÂÂÂ ring->free = 0;
>> +ÂÂÂ ring->rindex = 0;
>> +ÂÂÂ ring->windex = 0;
>> +
>> +ÂÂÂ k3_ringacc_ring_reset_sci(ring);
>> +}
>> +EXPORT_SYMBOL_GPL(k3_ringacc_ring_reset);
>> +
>> +static void k3_ringacc_ring_reconfig_qmode_sci(struct k3_ring *ring,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ enum k3_ring_mode mode)
>> +{
>> +ÂÂÂ struct k3_ringacc *ringacc = ring->parent;
>> +ÂÂÂ int ret;
>> +
>> +ÂÂÂ ret = ringacc->tisci_ring_ops->config(
>> +ÂÂÂÂÂÂÂÂÂÂÂ ringacc->tisci,
>> +ÂÂÂÂÂÂÂÂÂÂÂ TI_SCI_MSG_VALUE_RM_RING_MODE_VALID,
>> +ÂÂÂÂÂÂÂÂÂÂÂ ringacc->tisci_dev_id,
>> +ÂÂÂÂÂÂÂÂÂÂÂ ring->ring_id,
>> +ÂÂÂÂÂÂÂÂÂÂÂ 0,
>> +ÂÂÂÂÂÂÂÂÂÂÂ 0,
>> +ÂÂÂÂÂÂÂÂÂÂÂ 0,
>> +ÂÂÂÂÂÂÂÂÂÂÂ mode,
>> +ÂÂÂÂÂÂÂÂÂÂÂ 0,
>> +ÂÂÂÂÂÂÂÂÂÂÂ 0);
>> +ÂÂÂ if (ret)
>> +ÂÂÂÂÂÂÂ dev_err(ringacc->dev, "TISCI reconf qmode fail (%d) ring_idx
>> %d\n",
>> +ÂÂÂÂÂÂÂÂÂÂÂ ret, ring->ring_id);
>> +}
>> +
>> +void k3_ringacc_ring_reset_dma(struct k3_ring *ring, u32 occ)
>> +{
>> +ÂÂÂ if (!ring || !(ring->flags & K3_RING_FLAG_BUSY))
>> +ÂÂÂÂÂÂÂ return;
>> +
>> +ÂÂÂ if (!ring->parent->dma_ring_reset_quirk)
>> +ÂÂÂÂÂÂÂ return;
>> +
>> +ÂÂÂ if (!occ)
>> +ÂÂÂÂÂÂÂ occ = dbg_readl(&ring->rt->occ);
>> +
>> +ÂÂÂ if (occ) {
>> +ÂÂÂÂÂÂÂ u32 db_ring_cnt, db_ring_cnt_cur;
>> +
>> +ÂÂÂÂÂÂÂ k3_nav_dbg(ring->parent->dev, "%s %u occ: %u\n", __func__,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ ring->ring_id, occ);
>> +ÂÂÂÂÂÂÂ /* 2. Reset the ring */
>
> 2? Where is 1?
>
>> +ÂÂÂÂÂÂÂ k3_ringacc_ring_reset_sci(ring);
>> +
>> +ÂÂÂÂÂÂÂ /*
>> +ÂÂÂÂÂÂÂÂ * 3. Setup the ring in ring/doorbell mode
>> +ÂÂÂÂÂÂÂÂ * (if not already in this mode)
>> +ÂÂÂÂÂÂÂÂ */
>> +ÂÂÂÂÂÂÂ if (ring->mode != K3_RINGACC_RING_MODE_RING)
>> +ÂÂÂÂÂÂÂÂÂÂÂ k3_ringacc_ring_reconfig_qmode_sci(
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ ring, K3_RINGACC_RING_MODE_RING);
>> +ÂÂÂÂÂÂÂ /*
>> +ÂÂÂÂÂÂÂÂ * 4. Ring the doorbell 2**22 â ringOcc times.
>> +ÂÂÂÂÂÂÂÂ * This will wrap the internal UDMAP ring state occupancy
>> +ÂÂÂÂÂÂÂÂ * counter (which is 21-bits wide) to 0.
>> +ÂÂÂÂÂÂÂÂ */
>> +ÂÂÂÂÂÂÂ db_ring_cnt = (1U << 22) - occ;
>> +
>> +ÂÂÂÂÂÂÂ while (db_ring_cnt != 0) {
>> +ÂÂÂÂÂÂÂÂÂÂÂ /*
>> +ÂÂÂÂÂÂÂÂÂÂÂÂ * Ring the doorbell with the maximum count each
>> +ÂÂÂÂÂÂÂÂÂÂÂÂ * iteration if possible to minimize the total
>> +ÂÂÂÂÂÂÂÂÂÂÂÂ * of writes
>> +ÂÂÂÂÂÂÂÂÂÂÂÂ */
>> +ÂÂÂÂÂÂÂÂÂÂÂ if (db_ring_cnt > K3_RINGACC_MAX_DB_RING_CNT)
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ db_ring_cnt_cur = K3_RINGACC_MAX_DB_RING_CNT;
>> +ÂÂÂÂÂÂÂÂÂÂÂ else
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ db_ring_cnt_cur = db_ring_cnt;
>> +
>> +ÂÂÂÂÂÂÂÂÂÂÂ writel(db_ring_cnt_cur, &ring->rt->db);
>> +ÂÂÂÂÂÂÂÂÂÂÂ db_ring_cnt -= db_ring_cnt_cur;
>> +ÂÂÂÂÂÂÂ }
>> +
>> +ÂÂÂÂÂÂÂ /* 5. Restore the original ring mode (if not ring mode) */
>> +ÂÂÂÂÂÂÂ if (ring->mode != K3_RINGACC_RING_MODE_RING)
>> +ÂÂÂÂÂÂÂÂÂÂÂ k3_ringacc_ring_reconfig_qmode_sci(ring, ring->mode);
>> +ÂÂÂ }
>> +
>> +ÂÂÂ /* 2. Reset the ring */
>
> Again 2?
>
>> +ÂÂÂ k3_ringacc_ring_reset(ring);
>> +}
>> +EXPORT_SYMBOL_GPL(k3_ringacc_ring_reset_dma);
>> +
>> +static void k3_ringacc_ring_free_sci(struct k3_ring *ring)
>> +{
>> +ÂÂÂ struct k3_ringacc *ringacc = ring->parent;
>> +ÂÂÂ int ret;
>> +
>> +ÂÂÂ ret = ringacc->tisci_ring_ops->config(
>> +ÂÂÂÂÂÂÂÂÂÂÂ ringacc->tisci,
>> +ÂÂÂÂÂÂÂÂÂÂÂ TI_SCI_MSG_VALUE_RM_ALL_NO_ORDER,
>> +ÂÂÂÂÂÂÂÂÂÂÂ ringacc->tisci_dev_id,
>> +ÂÂÂÂÂÂÂÂÂÂÂ ring->ring_id,
>> +ÂÂÂÂÂÂÂÂÂÂÂ 0,
>> +ÂÂÂÂÂÂÂÂÂÂÂ 0,
>> +ÂÂÂÂÂÂÂÂÂÂÂ 0,
>> +ÂÂÂÂÂÂÂÂÂÂÂ 0,
>> +ÂÂÂÂÂÂÂÂÂÂÂ 0,
>> +ÂÂÂÂÂÂÂÂÂÂÂ 0);
>> +ÂÂÂ if (ret)
>> +ÂÂÂÂÂÂÂ dev_err(ringacc->dev, "TISCI ring free fail (%d) ring_idx %d\n",
>> +ÂÂÂÂÂÂÂÂÂÂÂ ret, ring->ring_id);
>> +}
>> +
>> +int k3_ringacc_ring_free(struct k3_ring *ring)
>> +{
>> +ÂÂÂ struct k3_ringacc *ringacc;
>> +
>> +ÂÂÂ if (!ring)
>> +ÂÂÂÂÂÂÂ return -EINVAL;
>> +
>> +ÂÂÂ ringacc = ring->parent;
>> +
>> +ÂÂÂ k3_nav_dbg(ring->parent->dev, "flags: 0x%08x\n", ring->flags);
>> +
>> +ÂÂÂ if (!test_bit(ring->ring_id, ringacc->rings_inuse))
>> +ÂÂÂÂÂÂÂ return -EINVAL;
>> +
>> +ÂÂÂ mutex_lock(&ringacc->req_lock);
>> +
>> +ÂÂÂ if (--ring->use_count)
>> +ÂÂÂÂÂÂÂ goto out;
>> +
>> +ÂÂÂ if (!(ring->flags & K3_RING_FLAG_BUSY))
>> +ÂÂÂÂÂÂÂ goto no_init;
>> +
>> +ÂÂÂ k3_ringacc_ring_free_sci(ring);
>> +
>> +ÂÂÂ dma_free_coherent(ringacc->dev,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂ ring->size * (4 << ring->elm_size),
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂ ring->ring_mem_virt, ring->ring_mem_dma);
>> +ÂÂÂ ring->flags = 0;
>> +ÂÂÂ ring->ops = NULL;
>> +ÂÂÂ if (ring->proxy_id != K3_RINGACC_PROXY_NOT_USED) {
>> +ÂÂÂÂÂÂÂ clear_bit(ring->proxy_id, ringacc->proxy_inuse);
>> +ÂÂÂÂÂÂÂ ring->proxy = NULL;
>> +ÂÂÂÂÂÂÂ ring->proxy_id = K3_RINGACC_PROXY_NOT_USED;
>> +ÂÂÂ }
>> +
>> +no_init:
>> +ÂÂÂ clear_bit(ring->ring_id, ringacc->rings_inuse);
>> +
>> +ÂÂÂ module_put(ringacc->dev->driver->owner);
>> +
>> +out:
>> +ÂÂÂ mutex_unlock(&ringacc->req_lock);
>> +ÂÂÂ return 0;
>> +}
>> +EXPORT_SYMBOL_GPL(k3_ringacc_ring_free);
>> +
>> +u32 k3_ringacc_get_ring_id(struct k3_ring *ring)
>> +{
>> +ÂÂÂ if (!ring)
>> +ÂÂÂÂÂÂÂ return -EINVAL;
>> +
>> +ÂÂÂ return ring->ring_id;
>> +}
>> +EXPORT_SYMBOL_GPL(k3_ringacc_get_ring_id);
>> +
>> +u32 k3_ringacc_get_tisci_dev_id(struct k3_ring *ring)
>> +{
>> +ÂÂÂ if (!ring)
>> +ÂÂÂÂÂÂÂ return -EINVAL;
>> +
>
> What if parent is NULL? Can it ever be here?
>
>> +ÂÂÂ return ring->parent->tisci_dev_id;
>> +}
>> +EXPORT_SYMBOL_GPL(k3_ringacc_get_tisci_dev_id);
>> +
>> +int k3_ringacc_get_ring_irq_num(struct k3_ring *ring)
>> +{
>> +ÂÂÂ int irq_num;
>> +
>> +ÂÂÂ if (!ring)
>> +ÂÂÂÂÂÂÂ return -EINVAL;
>> +
>> +ÂÂÂ irq_num = ti_sci_inta_msi_get_virq(ring->parent->dev,
>> ring->ring_id);
>> +ÂÂÂ if (irq_num <= 0)
>> +ÂÂÂÂÂÂÂ irq_num = -EINVAL;
>> +ÂÂÂ return irq_num;
>> +}
>> +EXPORT_SYMBOL_GPL(k3_ringacc_get_ring_irq_num);
>> +
>> +static int k3_ringacc_ring_cfg_sci(struct k3_ring *ring)
>> +{
>> +ÂÂÂ struct k3_ringacc *ringacc = ring->parent;
>> +ÂÂÂ u32 ring_idx;
>> +ÂÂÂ int ret;
>> +
>> +ÂÂÂ if (!ringacc->tisci)
>> +ÂÂÂÂÂÂÂ return -EINVAL;
>> +
>> +ÂÂÂ ring_idx = ring->ring_id;
>> +ÂÂÂ ret = ringacc->tisci_ring_ops->config(
>> +ÂÂÂÂÂÂÂÂÂÂÂ ringacc->tisci,
>> +ÂÂÂÂÂÂÂÂÂÂÂ TI_SCI_MSG_VALUE_RM_ALL_NO_ORDER,
>> +ÂÂÂÂÂÂÂÂÂÂÂ ringacc->tisci_dev_id,
>> +ÂÂÂÂÂÂÂÂÂÂÂ ring_idx,
>> +ÂÂÂÂÂÂÂÂÂÂÂ lower_32_bits(ring->ring_mem_dma),
>> +ÂÂÂÂÂÂÂÂÂÂÂ upper_32_bits(ring->ring_mem_dma),
>> +ÂÂÂÂÂÂÂÂÂÂÂ ring->size,
>> +ÂÂÂÂÂÂÂÂÂÂÂ ring->mode,
>> +ÂÂÂÂÂÂÂÂÂÂÂ ring->elm_size,
>> +ÂÂÂÂÂÂÂÂÂÂÂ 0);
>> +ÂÂÂ if (ret)
>> +ÂÂÂÂÂÂÂ dev_err(ringacc->dev, "TISCI config ring fail (%d) ring_idx
>> %d\n",
>> +ÂÂÂÂÂÂÂÂÂÂÂ ret, ring_idx);
>> +
>> +ÂÂÂ return ret;
>> +}
>> +
>> +int k3_ringacc_ring_cfg(struct k3_ring *ring, struct k3_ring_cfg *cfg)
>> +{
>> +ÂÂÂ struct k3_ringacc *ringacc = ring->parent;
>> +ÂÂÂ int ret = 0;
>> +
>> +ÂÂÂ if (!ring || !cfg)
>> +ÂÂÂÂÂÂÂ return -EINVAL;
>> +ÂÂÂ if (cfg->elm_size > K3_RINGACC_RING_ELSIZE_256 ||
>> +ÂÂÂÂÂÂÂ cfg->mode > K3_RINGACC_RING_MODE_QM ||
>> +ÂÂÂÂÂÂÂ cfg->size & ~K3_RINGACC_CFG_RING_SIZE_ELCNT_MASK ||
>> +ÂÂÂÂÂÂÂ !test_bit(ring->ring_id, ringacc->rings_inuse))
>> +ÂÂÂÂÂÂÂ return -EINVAL;
>> +
>> +ÂÂÂ if (ring->use_count != 1)
>
> Hmm, isn't this a failure actually?
>
>> +ÂÂÂÂÂÂÂ return 0;
>> +
>> +ÂÂÂ ring->size = cfg->size;
>> +ÂÂÂ ring->elm_size = cfg->elm_size;
>> +ÂÂÂ ring->mode = cfg->mode;
>> +ÂÂÂ ring->occ = 0;
>> +ÂÂÂ ring->free = 0;
>> +ÂÂÂ ring->rindex = 0;
>> +ÂÂÂ ring->windex = 0;
>> +
>> +ÂÂÂ if (ring->proxy_id != K3_RINGACC_PROXY_NOT_USED)
>> +ÂÂÂÂÂÂÂ ring->proxy = ringacc->proxy_target_base +
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ ring->proxy_id * K3_RINGACC_PROXY_TARGET_STEP;
>> +
>> +ÂÂÂ switch (ring->mode) {
>> +ÂÂÂ case K3_RINGACC_RING_MODE_RING:
>> +ÂÂÂÂÂÂÂ ring->ops = &k3_ring_mode_ring_ops;
>> +ÂÂÂÂÂÂÂ break;
>> +ÂÂÂ case K3_RINGACC_RING_MODE_QM:
>> +ÂÂÂÂÂÂÂ /*
>> +ÂÂÂÂÂÂÂÂ * In Queue mode elm_size can be 8 only and each operation
>> +ÂÂÂÂÂÂÂÂ * uses 2 element slots
>> +ÂÂÂÂÂÂÂÂ */
>> +ÂÂÂÂÂÂÂ if (cfg->elm_size != K3_RINGACC_RING_ELSIZE_8 ||
>> +ÂÂÂÂÂÂÂÂÂÂÂ cfg->size % 2)
>> +ÂÂÂÂÂÂÂÂÂÂÂ goto err_free_proxy;
>> +ÂÂÂÂÂÂÂ /* else, fall through */
>> +ÂÂÂ case K3_RINGACC_RING_MODE_MESSAGE:
>> +ÂÂÂÂÂÂÂ if (ring->proxy)
>> +ÂÂÂÂÂÂÂÂÂÂÂ ring->ops = &k3_ring_mode_proxy_ops;
>> +ÂÂÂÂÂÂÂ else
>> +ÂÂÂÂÂÂÂÂÂÂÂ ring->ops = &k3_ring_mode_msg_ops;
>> +ÂÂÂÂÂÂÂ break;
>> +ÂÂÂ default:
>> +ÂÂÂÂÂÂÂ ring->ops = NULL;
>> +ÂÂÂÂÂÂÂ ret = -EINVAL;
>> +ÂÂÂÂÂÂÂ goto err_free_proxy;
>> +ÂÂÂ };
>> +
>> +ÂÂÂ ring->ring_mem_virt =
>> +ÂÂÂÂÂÂÂÂÂÂÂ dma_alloc_coherent(ringacc->dev,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ ring->size * (4 << ring->elm_size),
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ &ring->ring_mem_dma, GFP_KERNEL);
>> +ÂÂÂ if (!ring->ring_mem_virt) {
>> +ÂÂÂÂÂÂÂ dev_err(ringacc->dev, "Failed to alloc ring mem\n");
>> +ÂÂÂÂÂÂÂ ret = -ENOMEM;
>> +ÂÂÂÂÂÂÂ goto err_free_ops;
>> +ÂÂÂ }
>> +
>> +ÂÂÂ ret = k3_ringacc_ring_cfg_sci(ring);
>> +
>> +ÂÂÂ if (ret)
>> +ÂÂÂÂÂÂÂ goto err_free_mem;
>> +
>> +ÂÂÂ ring->flags |= K3_RING_FLAG_BUSY;
>> +ÂÂÂ ring->flags |= (cfg->flags & K3_RINGACC_RING_SHARED) ?
>> +ÂÂÂÂÂÂÂÂÂÂÂ K3_RING_FLAG_SHARED : 0;
>> +
>> +ÂÂÂ k3_ringacc_ring_dump(ring);
>> +
>> +ÂÂÂ return 0;
>> +
>> +err_free_mem:
>> +ÂÂÂ dma_free_coherent(ringacc->dev,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂ ring->size * (4 << ring->elm_size),
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂ ring->ring_mem_virt,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂ ring->ring_mem_dma);
>> +err_free_ops:
>> +ÂÂÂ ring->ops = NULL;
>> +err_free_proxy:
>> +ÂÂÂ ring->proxy = NULL;
>> +ÂÂÂ return ret;
>> +}
>> +EXPORT_SYMBOL_GPL(k3_ringacc_ring_cfg);
>> +
>> +u32 k3_ringacc_ring_get_size(struct k3_ring *ring)
>> +{
>> +ÂÂÂ if (!ring || !(ring->flags & K3_RING_FLAG_BUSY))
>> +ÂÂÂÂÂÂÂ return -EINVAL;
>> +
>> +ÂÂÂ return ring->size;
>> +}
>> +EXPORT_SYMBOL_GPL(k3_ringacc_ring_get_size);
>> +
>> +u32 k3_ringacc_ring_get_free(struct k3_ring *ring)
>> +{
>> +ÂÂÂ if (!ring || !(ring->flags & K3_RING_FLAG_BUSY))
>> +ÂÂÂÂÂÂÂ return -EINVAL;
>> +
>> +ÂÂÂ if (!ring->free)
>> +ÂÂÂÂÂÂÂ ring->free = ring->size - dbg_readl(&ring->rt->occ);
>> +
>> +ÂÂÂ return ring->free;
>> +}
>> +EXPORT_SYMBOL_GPL(k3_ringacc_ring_get_free);
>> +
>> +u32 k3_ringacc_ring_get_occ(struct k3_ring *ring)
>> +{
>> +ÂÂÂ if (!ring || !(ring->flags & K3_RING_FLAG_BUSY))
>> +ÂÂÂÂÂÂÂ return -EINVAL;
>> +
>> +ÂÂÂ return dbg_readl(&ring->rt->occ);
>> +}
>> +EXPORT_SYMBOL_GPL(k3_ringacc_ring_get_occ);
>> +
>> +u32 k3_ringacc_ring_is_full(struct k3_ring *ring)
>> +{
>> +ÂÂÂ return !k3_ringacc_ring_get_free(ring);
>> +}
>> +EXPORT_SYMBOL_GPL(k3_ringacc_ring_is_full);
>> +
>> +enum k3_ringacc_access_mode {
>> +ÂÂÂ K3_RINGACC_ACCESS_MODE_PUSH_HEAD,
>> +ÂÂÂ K3_RINGACC_ACCESS_MODE_POP_HEAD,
>> +ÂÂÂ K3_RINGACC_ACCESS_MODE_PUSH_TAIL,
>> +ÂÂÂ K3_RINGACC_ACCESS_MODE_POP_TAIL,
>> +ÂÂÂ K3_RINGACC_ACCESS_MODE_PEEK_HEAD,
>> +ÂÂÂ K3_RINGACC_ACCESS_MODE_PEEK_TAIL,
>> +};
>> +
>> +static int k3_ringacc_ring_cfg_proxy(struct k3_ring *ring,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ enum k3_ringacc_proxy_access_mode mode)
>> +{
>> +ÂÂÂ u32 val;
>> +
>> +ÂÂÂ val = ring->ring_id;
>> +ÂÂÂ val |= mode << 16;
>> +ÂÂÂ val |= ring->elm_size << 24;
>
> Would be nice to have these magic shifts as defines.
>
>> +ÂÂÂ dbg_writel(val, &ring->proxy->control);
>> +ÂÂÂ return 0;
>> +}
>> +
>> +static int k3_ringacc_ring_access_proxy(struct k3_ring *ring, void
>> *elem,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ enum k3_ringacc_access_mode access_mode)
>> +{
>> +ÂÂÂ void __iomem *ptr;
>> +
>> +ÂÂÂ ptr = (void __iomem *)&ring->proxy->data;
>> +
>> +ÂÂÂ switch (access_mode) {
>> +ÂÂÂ case K3_RINGACC_ACCESS_MODE_PUSH_HEAD:
>> +ÂÂÂ case K3_RINGACC_ACCESS_MODE_POP_HEAD:
>> +ÂÂÂÂÂÂÂ k3_ringacc_ring_cfg_proxy(ring, PROXY_ACCESS_MODE_HEAD);
>> +ÂÂÂÂÂÂÂ break;
>> +ÂÂÂ case K3_RINGACC_ACCESS_MODE_PUSH_TAIL:
>> +ÂÂÂ case K3_RINGACC_ACCESS_MODE_POP_TAIL:
>> +ÂÂÂÂÂÂÂ k3_ringacc_ring_cfg_proxy(ring, PROXY_ACCESS_MODE_TAIL);
>> +ÂÂÂÂÂÂÂ break;
>> +ÂÂÂ default:
>> +ÂÂÂÂÂÂÂ return -EINVAL;
>> +ÂÂÂ }
>> +
>> +ÂÂÂ ptr += k3_ringacc_ring_get_fifo_pos(ring);
>> +
>> +ÂÂÂ switch (access_mode) {
>> +ÂÂÂ case K3_RINGACC_ACCESS_MODE_POP_HEAD:
>> +ÂÂÂ case K3_RINGACC_ACCESS_MODE_POP_TAIL:
>> +ÂÂÂÂÂÂÂ k3_nav_dbg(ring->parent->dev, "proxy:memcpy_fromio(x): -->
>> ptr(%p), mode:%d\n",
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ ptr, access_mode);
>> +ÂÂÂÂÂÂÂ memcpy_fromio(elem, ptr, (4 << ring->elm_size));
>> +ÂÂÂÂÂÂÂ ring->occ--;
>> +ÂÂÂÂÂÂÂ break;
>> +ÂÂÂ case K3_RINGACC_ACCESS_MODE_PUSH_TAIL:
>> +ÂÂÂ case K3_RINGACC_ACCESS_MODE_PUSH_HEAD:
>> +ÂÂÂÂÂÂÂ k3_nav_dbg(ring->parent->dev, "proxy:memcpy_toio(x): -->
>> ptr(%p), mode:%d\n",
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ ptr, access_mode);
>> +ÂÂÂÂÂÂÂ memcpy_toio(ptr, elem, (4 << ring->elm_size));
>> +ÂÂÂÂÂÂÂ ring->free--;
>> +ÂÂÂÂÂÂÂ break;
>> +ÂÂÂ default:
>> +ÂÂÂÂÂÂÂ return -EINVAL;
>> +ÂÂÂ }
>> +
>> +ÂÂÂ k3_nav_dbg(ring->parent->dev, "proxy: free%d occ%d\n",
>> +ÂÂÂÂÂÂÂÂÂÂ ring->free, ring->occ);
>> +ÂÂÂ return 0;
>> +}
>> +
>> +static int k3_ringacc_ring_push_head_proxy(struct k3_ring *ring, void
>> *elem)
>> +{
>> +ÂÂÂ return k3_ringacc_ring_access_proxy(ring, elem,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ K3_RINGACC_ACCESS_MODE_PUSH_HEAD);
>> +}
>> +
>> +static int k3_ringacc_ring_push_tail_proxy(struct k3_ring *ring, void
>> *elem)
>> +{
>> +ÂÂÂ return k3_ringacc_ring_access_proxy(ring, elem,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ K3_RINGACC_ACCESS_MODE_PUSH_TAIL);
>> +}
>> +
>> +static int k3_ringacc_ring_pop_head_proxy(struct k3_ring *ring, void
>> *elem)
>> +{
>> +ÂÂÂ return k3_ringacc_ring_access_proxy(ring, elem,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ K3_RINGACC_ACCESS_MODE_POP_HEAD);
>> +}
>> +
>> +static int k3_ringacc_ring_pop_tail_proxy(struct k3_ring *ring, void
>> *elem)
>> +{
>> +ÂÂÂ return k3_ringacc_ring_access_proxy(ring, elem,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ K3_RINGACC_ACCESS_MODE_POP_HEAD);
>> +}
>> +
>> +static int k3_ringacc_ring_access_io(struct k3_ring *ring, void *elem,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ enum k3_ringacc_access_mode access_mode)
>> +{
>> +ÂÂÂ void __iomem *ptr;
>> +
>> +ÂÂÂ switch (access_mode) {
>> +ÂÂÂ case K3_RINGACC_ACCESS_MODE_PUSH_HEAD:
>> +ÂÂÂ case K3_RINGACC_ACCESS_MODE_POP_HEAD:
>> +ÂÂÂÂÂÂÂ ptr = (void __iomem *)&ring->fifos->head_data;
>> +ÂÂÂÂÂÂÂ break;
>> +ÂÂÂ case K3_RINGACC_ACCESS_MODE_PUSH_TAIL:
>> +ÂÂÂ case K3_RINGACC_ACCESS_MODE_POP_TAIL:
>> +ÂÂÂÂÂÂÂ ptr = (void __iomem *)&ring->fifos->tail_data;
>> +ÂÂÂÂÂÂÂ break;
>> +ÂÂÂ default:
>> +ÂÂÂÂÂÂÂ return -EINVAL;
>> +ÂÂÂ }
>> +
>> +ÂÂÂ ptr += k3_ringacc_ring_get_fifo_pos(ring);
>> +
>> +ÂÂÂ switch (access_mode) {
>> +ÂÂÂ case K3_RINGACC_ACCESS_MODE_POP_HEAD:
>> +ÂÂÂ case K3_RINGACC_ACCESS_MODE_POP_TAIL:
>> +ÂÂÂÂÂÂÂ k3_nav_dbg(ring->parent->dev, "memcpy_fromio(x): --> ptr(%p),
>> mode:%d\n",
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ ptr, access_mode);
>> +ÂÂÂÂÂÂÂ memcpy_fromio(elem, ptr, (4 << ring->elm_size));
>> +ÂÂÂÂÂÂÂ ring->occ--;
>> +ÂÂÂÂÂÂÂ break;
>> +ÂÂÂ case K3_RINGACC_ACCESS_MODE_PUSH_TAIL:
>> +ÂÂÂ case K3_RINGACC_ACCESS_MODE_PUSH_HEAD:
>> +ÂÂÂÂÂÂÂ k3_nav_dbg(ring->parent->dev, "memcpy_toio(x): --> ptr(%p),
>> mode:%d\n",
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ ptr, access_mode);
>> +ÂÂÂÂÂÂÂ memcpy_toio(ptr, elem, (4 << ring->elm_size));
>> +ÂÂÂÂÂÂÂ ring->free--;
>> +ÂÂÂÂÂÂÂ break;
>> +ÂÂÂ default:
>> +ÂÂÂÂÂÂÂ return -EINVAL;
>> +ÂÂÂ }
>> +
>> +ÂÂÂ k3_nav_dbg(ring->parent->dev, "free%d index%d occ%d index%d\n",
>> +ÂÂÂÂÂÂÂÂÂÂ ring->free, ring->windex, ring->occ, ring->rindex);
>> +ÂÂÂ return 0;
>> +}
>> +
>> +static int k3_ringacc_ring_push_head_io(struct k3_ring *ring, void
>> *elem)
>> +{
>> +ÂÂÂ return k3_ringacc_ring_access_io(ring, elem,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ K3_RINGACC_ACCESS_MODE_PUSH_HEAD);
>> +}
>> +
>> +static int k3_ringacc_ring_push_io(struct k3_ring *ring, void *elem)
>> +{
>> +ÂÂÂ return k3_ringacc_ring_access_io(ring, elem,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ K3_RINGACC_ACCESS_MODE_PUSH_TAIL);
>> +}
>> +
>> +static int k3_ringacc_ring_pop_io(struct k3_ring *ring, void *elem)
>> +{
>> +ÂÂÂ return k3_ringacc_ring_access_io(ring, elem,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ K3_RINGACC_ACCESS_MODE_POP_HEAD);
>> +}
>> +
>> +static int k3_ringacc_ring_pop_tail_io(struct k3_ring *ring, void *elem)
>> +{
>> +ÂÂÂ return k3_ringacc_ring_access_io(ring, elem,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ K3_RINGACC_ACCESS_MODE_POP_HEAD);
>> +}
>> +
>> +static int k3_ringacc_ring_push_mem(struct k3_ring *ring, void *elem)
>> +{
>> +ÂÂÂ void *elem_ptr;
>> +
>> +ÂÂÂ elem_ptr = k3_ringacc_get_elm_addr(ring, ring->windex);
>> +
>> +ÂÂÂ memcpy(elem_ptr, elem, (4 << ring->elm_size));
>> +
>> +ÂÂÂ ring->windex = (ring->windex + 1) % ring->size;
>> +ÂÂÂ ring->free--;
>> +ÂÂÂ dbg_writel(1, &ring->rt->db);
>> +
>> +ÂÂÂ k3_nav_dbg(ring->parent->dev, "ring_push_mem: free%d index%d\n",
>> +ÂÂÂÂÂÂÂÂÂÂ ring->free, ring->windex);
>> +
>> +ÂÂÂ return 0;
>> +}
>> +
>> +static int k3_ringacc_ring_pop_mem(struct k3_ring *ring, void *elem)
>> +{
>> +ÂÂÂ void *elem_ptr;
>> +
>> +ÂÂÂ elem_ptr = k3_ringacc_get_elm_addr(ring, ring->rindex);
>> +
>> +ÂÂÂ memcpy(elem, elem_ptr, (4 << ring->elm_size));
>> +
>> +ÂÂÂ ring->rindex = (ring->rindex + 1) % ring->size;
>> +ÂÂÂ ring->occ--;
>> +ÂÂÂ dbg_writel(-1, &ring->rt->db);
>> +
>> +ÂÂÂ k3_nav_dbg(ring->parent->dev, "ring_pop_mem: occ%d index%d
>> pos_ptr%p\n",
>> +ÂÂÂÂÂÂÂÂÂÂ ring->occ, ring->rindex, elem_ptr);
>> +ÂÂÂ return 0;
>> +}
>> +
>> +int k3_ringacc_ring_push(struct k3_ring *ring, void *elem)
>> +{
>> +ÂÂÂ int ret = -EOPNOTSUPP;
>> +
>> +ÂÂÂ if (!ring || !(ring->flags & K3_RING_FLAG_BUSY))
>> +ÂÂÂÂÂÂÂ return -EINVAL;
>> +
>> +ÂÂÂ k3_nav_dbg(ring->parent->dev, "ring_push: free%d index%d\n",
>> +ÂÂÂÂÂÂÂÂÂÂ ring->free, ring->windex);
>> +
>> +ÂÂÂ if (k3_ringacc_ring_is_full(ring))
>> +ÂÂÂÂÂÂÂ return -ENOMEM;
>> +
>> +ÂÂÂ if (ring->ops && ring->ops->push_tail)
>> +ÂÂÂÂÂÂÂ ret = ring->ops->push_tail(ring, elem);
>> +
>> +ÂÂÂ return ret;
>> +}
>> +EXPORT_SYMBOL_GPL(k3_ringacc_ring_push);
>> +
>> +int k3_ringacc_ring_push_head(struct k3_ring *ring, void *elem)
>> +{
>> +ÂÂÂ int ret = -EOPNOTSUPP;
>> +
>> +ÂÂÂ if (!ring || !(ring->flags & K3_RING_FLAG_BUSY))
>> +ÂÂÂÂÂÂÂ return -EINVAL;
>> +
>> +ÂÂÂ k3_nav_dbg(ring->parent->dev, "ring_push_head: free%d index%d\n",
>> +ÂÂÂÂÂÂÂÂÂÂ ring->free, ring->windex);
>> +
>> +ÂÂÂ if (k3_ringacc_ring_is_full(ring))
>> +ÂÂÂÂÂÂÂ return -ENOMEM;
>> +
>> +ÂÂÂ if (ring->ops && ring->ops->push_head)
>> +ÂÂÂÂÂÂÂ ret = ring->ops->push_head(ring, elem);
>> +
>> +ÂÂÂ return ret;
>> +}
>> +EXPORT_SYMBOL_GPL(k3_ringacc_ring_push_head);
>> +
>> +int k3_ringacc_ring_pop(struct k3_ring *ring, void *elem)
>> +{
>> +ÂÂÂ int ret = -EOPNOTSUPP;
>> +
>> +ÂÂÂ if (!ring || !(ring->flags & K3_RING_FLAG_BUSY))
>> +ÂÂÂÂÂÂÂ return -EINVAL;
>> +
>> +ÂÂÂ if (!ring->occ)
>> +ÂÂÂÂÂÂÂ ring->occ = k3_ringacc_ring_get_occ(ring);
>> +
>> +ÂÂÂ k3_nav_dbg(ring->parent->dev, "ring_pop: occ%d index%d\n",
>> +ÂÂÂÂÂÂÂÂÂÂ ring->occ, ring->rindex);
>> +
>> +ÂÂÂ if (!ring->occ)
>> +ÂÂÂÂÂÂÂ return -ENODATA;
>> +
>> +ÂÂÂ if (ring->ops && ring->ops->pop_head)
>> +ÂÂÂÂÂÂÂ ret = ring->ops->pop_head(ring, elem);
>> +
>> +ÂÂÂ return ret;
>> +}
>> +EXPORT_SYMBOL_GPL(k3_ringacc_ring_pop);
>> +
>> +int k3_ringacc_ring_pop_tail(struct k3_ring *ring, void *elem)
>> +{
>> +ÂÂÂ int ret = -EOPNOTSUPP;
>> +
>> +ÂÂÂ if (!ring || !(ring->flags & K3_RING_FLAG_BUSY))
>> +ÂÂÂÂÂÂÂ return -EINVAL;
>> +
>> +ÂÂÂ if (!ring->occ)
>> +ÂÂÂÂÂÂÂ ring->occ = k3_ringacc_ring_get_occ(ring);
>> +
>> +ÂÂÂ k3_nav_dbg(ring->parent->dev, "ring_pop_tail: occ%d index%d\n",
>> +ÂÂÂÂÂÂÂÂÂÂ ring->occ, ring->rindex);
>> +
>> +ÂÂÂ if (!ring->occ)
>> +ÂÂÂÂÂÂÂ return -ENODATA;
>> +
>> +ÂÂÂ if (ring->ops && ring->ops->pop_tail)
>> +ÂÂÂÂÂÂÂ ret = ring->ops->pop_tail(ring, elem);
>> +
>> +ÂÂÂ return ret;
>> +}
>> +EXPORT_SYMBOL_GPL(k3_ringacc_ring_pop_tail);
>> +
>> +struct k3_ringacc *of_k3_ringacc_get_by_phandle(struct device_node *np,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ const char *property)
>> +{
>> +ÂÂÂ struct device_node *ringacc_np;
>> +ÂÂÂ struct k3_ringacc *ringacc = ERR_PTR(-EPROBE_DEFER);
>> +ÂÂÂ struct k3_ringacc *entry;
>> +
>> +ÂÂÂ ringacc_np = of_parse_phandle(np, property, 0);
>> +ÂÂÂ if (!ringacc_np)
>> +ÂÂÂÂÂÂÂ return ERR_PTR(-ENODEV);
>> +
>> +ÂÂÂ mutex_lock(&k3_ringacc_list_lock);
>> +ÂÂÂ list_for_each_entry(entry, &k3_ringacc_list, list)
>> +ÂÂÂÂÂÂÂ if (entry->dev->of_node == ringacc_np) {
>> +ÂÂÂÂÂÂÂÂÂÂÂ ringacc = entry;
>> +ÂÂÂÂÂÂÂÂÂÂÂ break;
>> +ÂÂÂÂÂÂÂ }
>> +ÂÂÂ mutex_unlock(&k3_ringacc_list_lock);
>> +ÂÂÂ of_node_put(ringacc_np);
>> +
>> +ÂÂÂ return ringacc;
>> +}
>> +EXPORT_SYMBOL_GPL(of_k3_ringacc_get_by_phandle);
>> +
>> +static int k3_ringacc_probe_dt(struct k3_ringacc *ringacc)
>> +{
>> +ÂÂÂ struct device_node *node = ringacc->dev->of_node;
>> +ÂÂÂ struct device *dev = ringacc->dev;
>> +ÂÂÂ struct platform_device *pdev = to_platform_device(dev);
>> +ÂÂÂ int ret;
>> +
>> +ÂÂÂ if (!node) {
>> +ÂÂÂÂÂÂÂ dev_err(dev, "device tree info unavailable\n");
>> +ÂÂÂÂÂÂÂ return -ENODEV;
>> +ÂÂÂ }
>> +
>> +ÂÂÂ ret = of_property_read_u32(node, "ti,num-rings",
>> &ringacc->num_rings);
>> +ÂÂÂ if (ret) {
>> +ÂÂÂÂÂÂÂ dev_err(dev, "ti,num-rings read failure %d\n", ret);
>> +ÂÂÂÂÂÂÂ return ret;
>> +ÂÂÂ }
>> +
>> +ÂÂÂ ringacc->dma_ring_reset_quirk =
>> +ÂÂÂÂÂÂÂÂÂÂÂ of_property_read_bool(node, "ti,dma-ring-reset-quirk");
>> +
>> +ÂÂÂ ringacc->tisci = ti_sci_get_by_phandle(node, "ti,sci");
>> +ÂÂÂ if (IS_ERR(ringacc->tisci)) {
>> +ÂÂÂÂÂÂÂ ret = PTR_ERR(ringacc->tisci);
>> +ÂÂÂÂÂÂÂ if (ret != -EPROBE_DEFER)
>> +ÂÂÂÂÂÂÂÂÂÂÂ dev_err(dev, "ti,sci read fail %d\n", ret);
>> +ÂÂÂÂÂÂÂ ringacc->tisci = NULL;
>> +ÂÂÂÂÂÂÂ return ret;
>> +ÂÂÂ }
>> +
>> +ÂÂÂ ret = of_property_read_u32(node, "ti,sci-dev-id",
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ &ringacc->tisci_dev_id);
>> +ÂÂÂ if (ret) {
>> +ÂÂÂÂÂÂÂ dev_err(dev, "ti,sci-dev-id read fail %d\n", ret);
>> +ÂÂÂÂÂÂÂ return ret;
>> +ÂÂÂ }
>> +
>> +ÂÂÂ pdev->id = ringacc->tisci_dev_id;
>> +
>> +ÂÂÂ ringacc->rm_gp_range =
>> devm_ti_sci_get_of_resource(ringacc->tisci, dev,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ ringacc->tisci_dev_id,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ "ti,sci-rm-range-gp-rings");
>> +ÂÂÂ if (IS_ERR(ringacc->rm_gp_range)) {
>> +ÂÂÂÂÂÂÂ dev_err(dev, "Failed to allocate MSI interrupts\n");
>> +ÂÂÂÂÂÂÂ return PTR_ERR(ringacc->rm_gp_range);
>> +ÂÂÂ }
>> +
>> +ÂÂÂ return ti_sci_inta_msi_domain_alloc_irqs(ringacc->dev,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ ringacc->rm_gp_range);
>> +}
>> +
>> +static int k3_ringacc_probe(struct platform_device *pdev)
>> +{
>> +ÂÂÂ struct k3_ringacc *ringacc;
>> +ÂÂÂ void __iomem *base_fifo, *base_rt;
>> +ÂÂÂ struct device *dev = &pdev->dev;
>> +ÂÂÂ struct resource *res;
>> +ÂÂÂ int ret, i;
>> +
>> +ÂÂÂ ringacc = devm_kzalloc(dev, sizeof(*ringacc), GFP_KERNEL);
>> +ÂÂÂ if (!ringacc)
>> +ÂÂÂÂÂÂÂ return -ENOMEM;
>> +
>> +ÂÂÂ ringacc->dev = dev;
>> +ÂÂÂ mutex_init(&ringacc->req_lock);
>> +
>> +ÂÂÂ dev->msi_domain = of_msi_get_domain(dev, dev->of_node,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ DOMAIN_BUS_TI_SCI_INTA_MSI);
>> +ÂÂÂ if (!dev->msi_domain) {
>> +ÂÂÂÂÂÂÂ dev_err(dev, "Failed to get MSI domain\n");
>> +ÂÂÂÂÂÂÂ return -EPROBE_DEFER;
>> +ÂÂÂ }
>> +
>> +ÂÂÂ ret = k3_ringacc_probe_dt(ringacc);
>> +ÂÂÂ if (ret)
>> +ÂÂÂÂÂÂÂ return ret;
>> +
>> +ÂÂÂ res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "rt");
>> +ÂÂÂ base_rt = devm_ioremap_resource(dev, res);
>> +ÂÂÂ if (IS_ERR(base_rt))
>> +ÂÂÂÂÂÂÂ return PTR_ERR(base_rt);
>> +
>> +ÂÂÂ res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "fifos");
>> +ÂÂÂ base_fifo = devm_ioremap_resource(dev, res);
>> +ÂÂÂ if (IS_ERR(base_fifo))
>> +ÂÂÂÂÂÂÂ return PTR_ERR(base_fifo);
>> +
>> +ÂÂÂ res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
>> "proxy_gcfg");
>> +ÂÂÂ ringacc->proxy_gcfg = devm_ioremap_resource(dev, res);
>> +ÂÂÂ if (IS_ERR(ringacc->proxy_gcfg))
>> +ÂÂÂÂÂÂÂ return PTR_ERR(ringacc->proxy_gcfg);
>> +
>> +ÂÂÂ res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ "proxy_target");
>> +ÂÂÂ ringacc->proxy_target_base = devm_ioremap_resource(dev, res);
>> +ÂÂÂ if (IS_ERR(ringacc->proxy_target_base))
>> +ÂÂÂÂÂÂÂ return PTR_ERR(ringacc->proxy_target_base);
>> +
>> +ÂÂÂ ringacc->num_proxies = dbg_readl(&ringacc->proxy_gcfg->config) &
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ K3_RINGACC_PROXY_CFG_THREADS_MASK;
>> +
>> +ÂÂÂ ringacc->rings = devm_kzalloc(dev,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ sizeof(*ringacc->rings) *
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ ringacc->num_rings,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ GFP_KERNEL);
>> +ÂÂÂ ringacc->rings_inuse = devm_kcalloc(dev,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ BITS_TO_LONGS(ringacc->num_rings),
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ sizeof(unsigned long), GFP_KERNEL);
>> +ÂÂÂ ringacc->proxy_inuse = devm_kcalloc(dev,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ BITS_TO_LONGS(ringacc->num_proxies),
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ sizeof(unsigned long), GFP_KERNEL);
>> +
>> +ÂÂÂ if (!ringacc->rings || !ringacc->rings_inuse ||
>> !ringacc->proxy_inuse)
>> +ÂÂÂÂÂÂÂ return -ENOMEM;
>> +
>> +ÂÂÂ for (i = 0; i < ringacc->num_rings; i++) {
>> +ÂÂÂÂÂÂÂ ringacc->rings[i].rt = base_rt +
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ K3_RINGACC_RT_REGS_STEP * i;
>> +ÂÂÂÂÂÂÂ ringacc->rings[i].fifos = base_fifo +
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ K3_RINGACC_FIFO_REGS_STEP * i;
>> +ÂÂÂÂÂÂÂ ringacc->rings[i].parent = ringacc;
>> +ÂÂÂÂÂÂÂ ringacc->rings[i].ring_id = i;
>> +ÂÂÂÂÂÂÂ ringacc->rings[i].proxy_id = K3_RINGACC_PROXY_NOT_USED;
>> +ÂÂÂ }
>> +ÂÂÂ dev_set_drvdata(dev, ringacc);
>> +
>> +ÂÂÂ ringacc->tisci_ring_ops = &ringacc->tisci->ops.rm_ring_ops;
>> +
>> +ÂÂÂ pm_runtime_enable(dev);
>> +ÂÂÂ ret = pm_runtime_get_sync(dev);
>> +ÂÂÂ if (ret < 0) {
>> +ÂÂÂÂÂÂÂ pm_runtime_put_noidle(dev);
>> +ÂÂÂÂÂÂÂ dev_err(dev, "Failed to enable pm %d\n", ret);
>> +ÂÂÂÂÂÂÂ goto err;
>> +ÂÂÂ }
>> +
>> +ÂÂÂ mutex_lock(&k3_ringacc_list_lock);
>> +ÂÂÂ list_add_tail(&ringacc->list, &k3_ringacc_list);
>> +ÂÂÂ mutex_unlock(&k3_ringacc_list_lock);
>> +
>> +ÂÂÂ dev_info(dev, "Ring Accelerator probed rings:%u, gp-rings[%u,%u]
>> sci-dev-id:%u\n",
>> +ÂÂÂÂÂÂÂÂ ringacc->num_rings,
>> +ÂÂÂÂÂÂÂÂ ringacc->rm_gp_range->desc[0].start,
>> +ÂÂÂÂÂÂÂÂ ringacc->rm_gp_range->desc[0].num,
>> +ÂÂÂÂÂÂÂÂ ringacc->tisci_dev_id);
>> +ÂÂÂ dev_info(dev, "dma-ring-reset-quirk: %s\n",
>> +ÂÂÂÂÂÂÂÂ ringacc->dma_ring_reset_quirk ? "enabled" : "disabled");
>> +ÂÂÂ dev_info(dev, "RA Proxy rev. %08x, num_proxies:%u\n",
>> +ÂÂÂÂÂÂÂÂ dbg_readl(&ringacc->proxy_gcfg->revision),
>> +ÂÂÂÂÂÂÂÂ ringacc->num_proxies);
>> +ÂÂÂ return 0;
>> +
>> +err:
>> +ÂÂÂ pm_runtime_disable(dev);
>> +ÂÂÂ return ret;
>> +}
>> +
>> +static int k3_ringacc_remove(struct platform_device *pdev)
>> +{
>> +ÂÂÂ struct k3_ringacc *ringacc = dev_get_drvdata(&pdev->dev);
>> +
>> +ÂÂÂ pm_runtime_put_sync(&pdev->dev);
>> +ÂÂÂ pm_runtime_disable(&pdev->dev);
>> +
>> +ÂÂÂ mutex_lock(&k3_ringacc_list_lock);
>> +ÂÂÂ list_del(&ringacc->list);
>> +ÂÂÂ mutex_unlock(&k3_ringacc_list_lock);
>> +ÂÂÂ return 0;
>> +}
>> +
>> +/* Match table for of_platform binding */
>> +static const struct of_device_id k3_ringacc_of_match[] = {
>> +ÂÂÂ { .compatible = "ti,am654-navss-ringacc", },
>> +ÂÂÂ {},
>> +};
>> +MODULE_DEVICE_TABLE(of, k3_ringacc_of_match);
>> +
>> +static struct platform_driver k3_ringacc_driver = {
>> +ÂÂÂ .probeÂÂÂÂÂÂÂ = k3_ringacc_probe,
>> +ÂÂÂ .removeÂÂÂÂÂÂÂ = k3_ringacc_remove,
>> +ÂÂÂ .driverÂÂÂÂÂÂÂ = {
>> +ÂÂÂÂÂÂÂ .nameÂÂÂ = "k3-ringacc",
>> +ÂÂÂÂÂÂÂ .of_match_table = k3_ringacc_of_match,
>> +ÂÂÂ },
>> +};
>> +module_platform_driver(k3_ringacc_driver);
>> +
>> +MODULE_LICENSE("GPL v2");
>> +MODULE_DESCRIPTION("TI Ringacc driver for K3 SOCs");
>> +MODULE_AUTHOR("Grygorii Strashko <grygorii.strashko@xxxxxx>");
>> diff --git a/include/linux/soc/ti/k3-ringacc.h
>> b/include/linux/soc/ti/k3-ringacc.h
>> new file mode 100644
>> index 000000000000..debffba48ac9
>> --- /dev/null
>> +++ b/include/linux/soc/ti/k3-ringacc.h
>> @@ -0,0 +1,262 @@
>> +/* SPDX-License-Identifier: GPL-2.0 */
>> +/*
>> + * K3 Ring Accelerator (RA) subsystem interface
>> + *
>> + * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com
>> + */
>> +
>> +#ifndef __SOC_TI_K3_RINGACC_API_H_
>> +#define __SOC_TI_K3_RINGACC_API_H_
>> +
>> +#include <linux/types.h>
>> +
>> +struct device_node;
>> +
>> +/**
>> + * enum k3_ring_mode - &struct k3_ring_cfg mode
>> + *
>> + * RA ring operational modes
>> + *
>> + * @K3_RINGACC_RING_MODE_RING: Exposed Ring mode for SW direct access
>> + * @K3_RINGACC_RING_MODE_MESSAGE: Messaging mode. Messaging mode
>> requires
>> + *ÂÂÂ that all accesses to the queue must go through this IP so that all
>> + *ÂÂÂ accesses to the memory are controlled and ordered. This IP then
>> + *ÂÂÂ controls the entire state of the queue, and SW has no directly
>> control,
>> + *ÂÂÂ such as through doorbells and cannot access the storage memory
>> directly.
>> + *ÂÂÂ This is particularly useful when more than one SW or HW entity
>> can be
>> + *ÂÂÂ the producer and/or consumer at the same time
>> + * @K3_RINGACC_RING_MODE_CREDENTIALS: Credentials mode is message
>> mode plus
>> + *ÂÂÂ stores credentials with each message, requiring the element
>> size to be
>> + *ÂÂÂ doubled to fit the credentials. Any exposed memory should be
>> protected
>> + *ÂÂÂ by a firewall from unwanted access
>> + * @K3_RINGACC_RING_MODE_QM:Â Queue manager mode. This takes the
>> credentials
>> + *ÂÂÂ mode and adds packet length per element, along with additional
>> read only
>> + *ÂÂÂ fields for element count and accumulated queue length. The QM
>> mode only
>> + *ÂÂÂ operates with an 8 byte element size (any other element size is
>> + *ÂÂÂ illegal), and like in credentials mode each operation uses 2
>> element
>> + *ÂÂÂ slots to store the credentials and length fields
>> + */
>> +enum k3_ring_mode {
>> +ÂÂÂ K3_RINGACC_RING_MODE_RING = 0,
>> +ÂÂÂ K3_RINGACC_RING_MODE_MESSAGE,
>> +ÂÂÂ K3_RINGACC_RING_MODE_CREDENTIALS,
>> +ÂÂÂ K3_RINGACC_RING_MODE_QM,
>> +ÂÂÂ K3_RINGACC_RING_MODE_INVALID
>> +};
>> +
>> +/**
>> + * enum k3_ring_size - &struct k3_ring_cfg elm_size
>> + *
>> + * RA ring element's sizes in bytes.
>> + */
>> +enum k3_ring_size {
>> +ÂÂÂ K3_RINGACC_RING_ELSIZE_4 = 0,
>> +ÂÂÂ K3_RINGACC_RING_ELSIZE_8,
>> +ÂÂÂ K3_RINGACC_RING_ELSIZE_16,
>> +ÂÂÂ K3_RINGACC_RING_ELSIZE_32,
>> +ÂÂÂ K3_RINGACC_RING_ELSIZE_64,
>> +ÂÂÂ K3_RINGACC_RING_ELSIZE_128,
>> +ÂÂÂ K3_RINGACC_RING_ELSIZE_256,
>> +ÂÂÂ K3_RINGACC_RING_ELSIZE_INVALID
>> +};
>> +
>> +struct k3_ringacc;
>> +struct k3_ring;
>> +
>> +/**
>> + * enum k3_ring_cfg - RA ring configuration structure
>> + *
>> + * @size: Ring size, number of elements
>> + * @elm_size: Ring element size
>> + * @mode: Ring operational mode
>> + * @flags: Ring configuration flags. Possible values:
>> + *ÂÂÂÂ @K3_RINGACC_RING_SHARED: when set allows to request the same ring
>> + *ÂÂÂÂ few times. It's usable when the same ring is used as Free Host
>> PD ring
>> + *ÂÂÂÂ for different flows, for example.
>> + *ÂÂÂÂ Note: Locking should be done by consumer if required
>> + */
>> +struct k3_ring_cfg {
>> +ÂÂÂ u32 size;
>> +ÂÂÂ enum k3_ring_size elm_size;
>> +ÂÂÂ enum k3_ring_mode mode;
>> +#define K3_RINGACC_RING_SHARED BIT(1)
>> +ÂÂÂ u32 flags;
>> +};
>> +
>> +#define K3_RINGACC_RING_ID_ANY (-1)
>> +
>> +/**
>> + * of_k3_ringacc_get_by_phandle - find a RA by phandle property
>> + * @np: device node
>> + * @propname: property name containing phandle on RA node
>> + *
>> + * Returns pointer on the RA - struct k3_ringacc
>> + * or -ENODEV if not found,
>> + * or -EPROBE_DEFER if not yet registered
>> + */
>> +struct k3_ringacc *of_k3_ringacc_get_by_phandle(struct device_node *np,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ const char *property);
>> +
>> +#define K3_RINGACC_RING_USE_PROXY BIT(1)
>> +
>> +/**
>> + * k3_ringacc_request_ring - request ring from ringacc
>> + * @ringacc: pointer on ringacc
>> + * @id: ring id or K3_RINGACC_RING_ID_ANY for any general purpose ring
>> + * @flags:
>> + *ÂÂÂ @K3_RINGACC_RING_USE_PROXY: if set - proxy will be allocated and
>> + *ÂÂÂÂÂÂÂ used to access ring memory. Sopported only for rings in
>> + *ÂÂÂÂÂÂÂ Message/Credentials/Queue mode.
>> + *
>> + * Returns pointer on the Ring - struct k3_ring
>> + * or NULL in case of failure.
>> + */
>> +struct k3_ring *k3_ringacc_request_ring(struct k3_ringacc *ringacc,
>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ int id, u32 flags);
>> +
>> +/**
>> + * k3_ringacc_ring_reset - ring reset
>> + * @ring: pointer on Ring
>> + *
>> + * Resets ring internal state ((hw)occ, (hw)idx).
>> + * TODO_GS: ? Ring can be reused without reconfiguration
>> + */
>> +void k3_ringacc_ring_reset(struct k3_ring *ring);
>> +/**
>> + * k3_ringacc_ring_reset - ring reset for DMA rings
>> + * @ring: pointer on Ring
>> + *
>> + * Resets ring internal state ((hw)occ, (hw)idx). Should be used for
>> rings
>> + * which are read by K3 UDMA, like TX or Free Host PD rings.
>> + */
>> +void k3_ringacc_ring_reset_dma(struct k3_ring *ring, u32 occ);
>> +
>> +/**
>> + * k3_ringacc_ring_free - ring free
>> + * @ring: pointer on Ring
>> + *
>> + * Resets ring and free all alocated resources.
>> + */
>> +int k3_ringacc_ring_free(struct k3_ring *ring);
>> +
>> +/**
>> + * k3_ringacc_get_ring_id - Get the Ring ID
>> + * @ring: pointer on ring
>> + *
>> + * Returns the Ring ID
>> + */
>> +u32 k3_ringacc_get_ring_id(struct k3_ring *ring);
>> +
>> +/**
>> + * k3_ringacc_get_ring_irq_num - Get the irq number for the ring
>> + * @ring: pointer on ring
>> + *
>> + * Returns the interrupt number which can be used to request the
>> interrupt
>> + */
>> +int k3_ringacc_get_ring_irq_num(struct k3_ring *ring);
>> +
>> +/**
>> + * k3_ringacc_ring_cfg - ring configure
>> + * @ring: pointer on ring
>> + * @cfg: Ring configuration parameters (see &struct k3_ring_cfg)
>> + *
>> + * Configures ring, including ring memory allocation.
>> + * Returns 0 on success, errno otherwise.
>> + */
>> +int k3_ringacc_ring_cfg(struct k3_ring *ring, struct k3_ring_cfg *cfg);
>> +
>> +/**
>> + * k3_ringacc_ring_get_size - get ring size
>> + * @ring: pointer on ring
>> + *
>> + * Returns ring size in number of elements.
>> + */
>> +u32 k3_ringacc_ring_get_size(struct k3_ring *ring);
>> +
>> +/**
>> + * k3_ringacc_ring_get_free - get free elements
>> + * @ring: pointer on ring
>> + *
>> + * Returns number of free elements in the ring.
>> + */
>> +u32 k3_ringacc_ring_get_free(struct k3_ring *ring);
>> +
>> +/**
>> + * k3_ringacc_ring_get_occ - get ring occupancy
>> + * @ring: pointer on ring
>> + *
>> + * Returns total number of valid entries on the ring
>> + */
>> +u32 k3_ringacc_ring_get_occ(struct k3_ring *ring);
>> +
>> +/**
>> + * k3_ringacc_ring_is_full - checks if ring is full
>> + * @ring: pointer on ring
>> + *
>> + * Returns true if the ring is full
>> + */
>> +u32 k3_ringacc_ring_is_full(struct k3_ring *ring);
>> +
>> +/**
>> + * k3_ringacc_ring_push - push element to the ring tail
>> + * @ring: pointer on ring
>> + * @elem: pointer on ring element buffer
>> + *
>> + * Push one ring element to the ring tail. Size of the ring element is
>> + * determined by ring configuration &struct k3_ring_cfg elm_size.
>> + *
>> + * Returns 0 on success, errno otherwise.
>> + */
>> +int k3_ringacc_ring_push(struct k3_ring *ring, void *elem);
>> +
>> +/**
>> + * k3_ringacc_ring_pop - pop element from the ring head
>> + * @ring: pointer on ring
>> + * @elem: pointer on ring element buffer
>> + *
>> + * Push one ring element from the ring head. Size of the ring element is
>> + * determined by ring configuration &struct k3_ring_cfg elm_size..
>> + *
>> + * Returns 0 on success, errno otherwise.
>> + */
>> +int k3_ringacc_ring_pop(struct k3_ring *ring, void *elem);
>> +
>> +/**
>> + * k3_ringacc_ring_push_head - push element to the ring head
>> + * @ring: pointer on ring
>> + * @elem: pointer on ring element buffer
>> + *
>> + * Push one ring element to the ring head. Size of the ring element is
>> + * determined by ring configuration &struct k3_ring_cfg elm_size.
>> + *
>> + * Returns 0 on success, errno otherwise.
>> + * Not Supported by ring modes: K3_RINGACC_RING_MODE_RING
>> + */
>> +int k3_ringacc_ring_push_head(struct k3_ring *ring, void *elem);
>> +
>> +/**
>> + * k3_ringacc_ring_pop_tail - pop element from the ring tail
>> + * @ring: pointer on ring
>> + * @elem: pointer on ring element buffer
>> + *
>> + * Push one ring element from the ring tail. Size of the ring element is
>> + * determined by ring configuration &struct k3_ring_cfg elm_size.
>> + *
>> + * Returns 0 on success, errno otherwise.
>> + * Not Supported by ring modes: K3_RINGACC_RING_MODE_RING
>> + */
>> +int k3_ringacc_ring_pop_tail(struct k3_ring *ring, void *elem);
>> +
>> +u32 k3_ringacc_get_tisci_dev_id(struct k3_ring *ring);
>> +
>> +/**
>> + * Debugging definitions
>> + * TODO: might be removed
>> + */
>> +#ifdef CONFIG_TI_K3_RINGACC_DEBUG
>> +void k3_ringacc_ring_dump(struct k3_ring *ring);
>> +#else
>> +static inline void k3_ringacc_ring_dump(struct k3_ring *ring) {};
>> +#endif
>> +
>> +#endif /* __SOC_TI_K3_RINGACC_API_H_ */
>>
>
> --
> Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
> Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
>
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@xxxxxxxxxxxxxxxxxxx
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
--
Regards
Vignesh