summaryrefslogtreecommitdiff
path: root/sound/soc/fsl/fsl_dsp_pool.h
blob: 4a56262faf7f791fde3a274a77e73d8d32329e5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/* SPDX-License-Identifier: GPL-2.0+ */
/*
 * Xtensa buffer pool API header
 *
 * Copyright 2018 NXP
 * Copyright (c) 2012-2013 by Tensilica Inc
 */
#ifndef FSL_DSP_POOL_H
#define FSL_DSP_POOL_H

#include <linux/types.h>
#include "fsl_dsp_proxy.h"

/* ...buffer pool type */
typedef u32 xf_pool_type_t;

/* ...previous declaration of struct */
struct xf_buffer;
struct xf_pool;
struct xf_handle;
struct xf_message;
struct xf_client;

/* ...response callback */
typedef void (*xf_response_cb)(struct xf_handle *h, struct xf_message *msg);

/* ...buffer pool type */
enum xf_pool_type {
        XF_POOL_AUX = 0,
        XF_POOL_INPUT = 1,
        XF_POOL_OUTPUT = 2
};

/* ...buffer link pointer */
union xf_buffer_link {
        /* ...pointer to next free buffer in a pool (for free buffer) */
        struct xf_buffer *next;
        /* ...reference to a buffer pool (for allocated buffer) */
        struct xf_pool *pool;
};

/* ...buffer descriptor */
struct xf_buffer {
        /* ...virtual address of contiguous buffer */
        void *address;
        /* ...link pointer */
        union xf_buffer_link link;
};

/* ...buffer pool */
struct xf_pool {
        /* ...reference to proxy data */
        struct xf_proxy *proxy;
        /* ...length of individual buffer in a pool */
        u32 length;
        /* ...number of buffers in a pool */
        u32 number;
        /* ...pointer to pool memory */
        void *p;
        /* ...pointer to first free buffer in a pool */
        struct xf_buffer *free;
        /* ...individual buffers */
        struct xf_buffer buffer[0];
};

/* component handle */
struct xf_handle {
        /* ...reference to proxy data */
        struct xf_proxy *proxy;
        /* ...auxiliary control buffer for control transactions */
        struct xf_buffer *aux;
        /* ...global client-id of the component */
        u32 id;
        /* ...local client number (think about merging into "id" field - tbd) */
        u32 client;
        /* ...response processing hook */
        xf_response_cb response;
};

/* ...accessor to buffer data */
static inline void *xf_buffer_data(struct xf_buffer *buffer)
{
        return buffer->address;
}

/* ...length of buffer data */
static inline size_t xf_buffer_length(struct xf_buffer *buffer)
{
        struct xf_pool *pool = buffer->link.pool;

        return (size_t)pool->length;
}

/* ...component client-id (global scope) */
static inline u32 xf_handle_id(struct xf_handle *handle)
{
        return handle->id;
}

/* ...pointer to auxiliary buffer */
static inline void *xf_handle_aux(struct xf_handle *handle)
{
        return xf_buffer_data(handle->aux);
}

int xf_pool_alloc(struct xf_client *client, struct xf_proxy *proxy, u32 number,
		  u32 length, xf_pool_type_t type, struct xf_pool **pool);
int xf_pool_free(struct xf_client *client, struct xf_pool *pool);

struct xf_buffer *xf_buffer_get(struct xf_pool *pool);
void xf_buffer_put(struct xf_buffer *buffer);

#endif /* FSL_DSP_POOL_H */