hikey960: HiFi3 DSP firmware and documentation

HiFi3 DSP firmware source code, documentation to build and understand DSP

Change-Id: I752416536cc2165868c56d2a2ba2d60b71c2b9a4
Signed-off-by: Niranjan Yadla <nyadla@cadence.com>
diff --git a/hifi/xaf/hifi-dpf/include/lib/mutex.h b/hifi/xaf/hifi-dpf/include/lib/mutex.h
new file mode 100644
index 0000000..2aef0f6
--- /dev/null
+++ b/hifi/xaf/hifi-dpf/include/lib/mutex.h
@@ -0,0 +1,59 @@
+/*******************************************************************************
+* Copyright (C) 2018 Cadence Design Systems, Inc.
+* 
+* Permission is hereby granted, free of charge, to any person obtaining
+* a copy of this software and associated documentation files (the
+* "Software"), to use this Software with Cadence processor cores only and 
+* not with any other processors and platforms, subject to
+* the following conditions:
+* 
+* The above copyright notice and this permission notice shall be included
+* in all copies or substantial portions of the Software.
+* 
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+******************************************************************************/
+
+/*******************************************************************************
+ * mutex.h
+ *
+ *
+ * Implementation of "non-robust" Szymanski linear-waiting algorithm. Types of
+ * failures tolerated by Szymanski's "robust" algorithm are not specific for
+ * Xtensa DSP cluster and therefore more lightweight version of the algorithm
+ * is used. FIFO servicing property is of low importance, and faster/smaller
+ * version with linear-wait property is preferable.
+ *
+ * We assume there is just a single mutex in the system, and all communication
+ * variables are defined somewhere in board-specific headers and imported here
+ * by means of macros MUTEX_SHARED_READ/WRITE.
+ ******************************************************************************/
+
+#ifndef __MUTEX_H
+#define __MUTEX_H
+
+/*******************************************************************************
+ * Imported macros
+ ******************************************************************************/
+
+#if !defined(MUTEX_SHARED_READ) || !defined(MUTEX_SHARED_WRITE)
+#error "Macros MUTEX_SHARED_READ and/or MUTEX_SHARED_WRITE not defined"
+#endif
+
+/*******************************************************************************
+ * Entry points
+ ******************************************************************************/
+
+/* ...acquire global mutex from i-th core */
+extern void mutex_lock(u32 i);
+
+/* ...release global mutex from i-th core */
+extern void mutex_unlock(u32 i);
+
+#endif  /* __MUTEX_H */
diff --git a/hifi/xaf/hifi-dpf/include/lib/rbtree.h b/hifi/xaf/hifi-dpf/include/lib/rbtree.h
new file mode 100644
index 0000000..7f02cdf
--- /dev/null
+++ b/hifi/xaf/hifi-dpf/include/lib/rbtree.h
@@ -0,0 +1,157 @@
+/*******************************************************************************
+* Copyright (C) 2018 Cadence Design Systems, Inc.
+* 
+* Permission is hereby granted, free of charge, to any person obtaining
+* a copy of this software and associated documentation files (the
+* "Software"), to use this Software with Cadence processor cores only and 
+* not with any other processors and platforms, subject to
+* the following conditions:
+* 
+* The above copyright notice and this permission notice shall be included
+* in all copies or substantial portions of the Software.
+* 
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+******************************************************************************/
+
+/*******************************************************************************
+ * rbtree.h
+ *
+ * Generic implmentation of red-black trees
+ *
+ *******************************************************************************/
+
+#ifndef __RBTREE_H
+#define __RBTREE_H
+
+/*******************************************************************************
+ * Red-black tree node definition
+ ******************************************************************************/
+
+/* ...reference to rb-tree node */
+typedef struct rb_node  *rb_idx_t;
+
+/* ...rb-tree node */
+typedef struct rb_node
+{
+    /* ...pointers to parent and two children */
+    rb_idx_t            parent, left, right;
+    
+    /* ...node color (least-significant-bit only) */
+    u32                 color;
+
+}   rb_node_t;
+
+/* ...rb-tree data */
+typedef struct rb_tree_t
+{
+    /* ...tree sentinel node */
+    rb_node_t           root;
+
+}   rb_tree_t;    
+
+/*******************************************************************************
+ * Helpers
+ ******************************************************************************/
+
+/* ...left child accessor */
+static inline rb_idx_t rb_left(rb_tree_t *tree, rb_idx_t n_idx)
+{
+    return n_idx->left;
+}
+
+/* ...right child accessor */
+static inline rb_idx_t rb_right(rb_tree_t *tree, rb_idx_t n_idx)
+{
+    return n_idx->right;
+}
+
+/* ...parent node accessor */
+static inline rb_idx_t rb_parent(rb_tree_t *tree, rb_idx_t n_idx)
+{
+    return n_idx->parent;
+}
+
+/* ...tree root node accessor */
+static inline rb_idx_t rb_root(rb_tree_t *tree)
+{
+    return rb_left(tree, &tree->root);
+}
+
+/* ...tree data pointer accessor */
+static inline rb_idx_t rb_cache(rb_tree_t *tree)
+{
+    return rb_right(tree, &tree->root);
+}
+
+/* ...tree null node */
+static inline rb_idx_t rb_null(rb_tree_t *tree)
+{
+    return &tree->root;
+}
+
+/* ...get user-bits stored in node color */
+static inline u32 rb_node_data(rb_tree_t *tree, rb_idx_t n_idx)
+{
+    return (n_idx->color >> 1);
+}
+
+/* ...left child assignment */
+static inline void rb_set_left(rb_tree_t *tree, rb_idx_t n_idx, rb_node_t *child)
+{
+    n_idx->left = child;
+}
+
+/* ...right child assignment */
+static inline void rb_set_right(rb_tree_t *tree, rb_idx_t n_idx, rb_node_t *child)
+{
+    n_idx->right = child;
+}
+
+/* ...cache tree client index */
+static inline void rb_set_cache(rb_tree_t *tree, rb_idx_t c_idx)
+{
+    tree->root.right = c_idx;
+}
+
+/* ...get user-bits stored in node color */
+static inline void rb_set_node_data(rb_tree_t *tree, rb_idx_t n_idx, u32 data)
+{
+    n_idx->color = (n_idx->color & 0x1) | (data << 1);
+}
+
+/*******************************************************************************
+ * API functions
+ ******************************************************************************/
+
+/* ...initialize rb-tree */
+extern void     rb_init(rb_tree_t *tree);
+
+/* ...insert node into tree as a child of p */
+extern void     rb_insert(rb_tree_t *tree, rb_idx_t n_idx, rb_idx_t p_idx);
+
+/* ...replace the node with same-key value and fixup tree pointers */
+extern void     rb_replace(rb_tree_t *tree, rb_idx_t n_idx, rb_idx_t t_idx);
+
+/* ...delete node from the tree and return its in-order predecessor/successor */
+extern rb_idx_t rb_delete(rb_tree_t *tree, rb_idx_t n_idx);
+
+/* ...first in-order item in the tree */
+extern rb_idx_t rb_first(rb_tree_t *tree);
+
+/* ...last in-order item in the tree */
+extern rb_idx_t rb_last(rb_tree_t *tree);
+
+/* ...forward tree iterator */
+extern rb_idx_t rb_next(rb_tree_t *tree, rb_idx_t n_idx);
+
+/* ...backward tree iterator */
+extern rb_idx_t rb_prev(rb_tree_t *tree, rb_idx_t n_idx);
+
+#endif  /* __RBTREE_H */
diff --git a/hifi/xaf/hifi-dpf/include/lib/tinyput.h b/hifi/xaf/hifi-dpf/include/lib/tinyput.h
new file mode 100644
index 0000000..dadd088
--- /dev/null
+++ b/hifi/xaf/hifi-dpf/include/lib/tinyput.h
@@ -0,0 +1,31 @@
+/*******************************************************************************
+* Copyright (C) 2018 Cadence Design Systems, Inc.
+* 
+* Permission is hereby granted, free of charge, to any person obtaining
+* a copy of this software and associated documentation files (the
+* "Software"), to use this Software with Cadence processor cores only and 
+* not with any other processors and platforms, subject to
+* the following conditions:
+* 
+* The above copyright notice and this permission notice shall be included
+* in all copies or substantial portions of the Software.
+* 
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+******************************************************************************/
+
+/* $Id: //depot/dev/Cottonwood/Xtensa/OS/mpg2/tinyput.h#2 $ */
+
+#include <stdarg.h>
+
+extern void tiny_putc(char c);
+extern int  tiny_puts(const char *s);
+extern int  tiny_atoi(const char *s);
+extern int  tiny_vsprintf(char *out, const char *fmt, va_list ap);
+extern int  tiny_sprintf(char *out, const char *fmt, ...);