k3conf: Initial commit
authorLokesh Vutla <lokeshvutla@ti.com>
Sun, 18 Aug 2019 06:47:24 +0000 (12:17 +0530)
committerLokesh Vutla <lokeshvutla@ti.com>
Sun, 25 Aug 2019 03:13:57 +0000 (08:43 +0530)
Add base build infrastructure with the following support:
- Commands: --help, --version
- SoC detection: AM654, J721E
- TISCI version detection using default host

Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
15 files changed:
.gitignore [new file with mode: 0644]
Makefile [new file with mode: 0644]
common/help.c [new file with mode: 0644]
common/k3conf.c [new file with mode: 0644]
common/mmio.c [new file with mode: 0644]
common/sec_proxy.c [new file with mode: 0644]
common/socinfo.c [new file with mode: 0644]
common/tisci/tisci_core.c [new file with mode: 0644]
include/help.h [new file with mode: 0644]
include/mmio.h [new file with mode: 0644]
include/sec_proxy.h [new file with mode: 0644]
include/socinfo.h [new file with mode: 0644]
include/tisci.h [new file with mode: 0644]
include/tisci_protocol.h [new file with mode: 0644]
include/version.h [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..c63950a
--- /dev/null
@@ -0,0 +1,14 @@
+*.o
+k3conf
+builddate.c
+version.c
+cscope*
+tags
+*.swp
+*.swo
+*.orig
+*.rej
+*~
+\#*#
+*.patch
+*.diff
diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..3f51dec
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,113 @@
+#/*
+# * Makefile for k3conf
+# *
+# * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/
+# *    Lokesh Vutla <lokeshvutla@ti.com>
+# *
+# *  Redistribution and use in source and binary forms, with or without
+# *  modification, are permitted provided that the following conditions
+# *  are met:
+# *
+# *    Redistributions of source code must retain the above copyright
+# *    notice, this list of conditions and the following disclaimer.
+# *
+# *    Redistributions in binary form must reproduce the above copyright
+# *    notice, this list of conditions and the following disclaimer in the
+# *    documentation and/or other materials provided with the
+# *    distribution.
+# *
+# *    Neither the name of Texas Instruments Incorporated nor the names of
+# *    its contributors may be used to endorse or promote products derived
+# *    from this software without specific prior written permission.
+# *
+# *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+# */
+
+VERSION_MAJOR=0
+VERSION_MINOR=0
+
+CROSS_COMPILE ?=aarch64-linux-gnu-
+CC = $(CROSS_COMPILE)gcc
+
+DEF_INC := $(shell $(CROSS_COMPILE)gcc  -print-file-name=include)
+
+DEF_INC_PATH = -I. -Iinclude
+
+STATIC_BUILD ?= -static
+
+MYCFLAGS+=$(CFLAGS) -c -Wall -Wextra -Wno-missing-field-initializers \
+               -I$(DEF_INC) $(DEF_INC_PATH) $(STATIC_BUILD)
+
+ifdef DEBUG
+MYCFLAGS+=-g3 -fno-inline -O0 -DDEBUG
+else
+MYCFLAGS+=-Os
+endif
+
+DESTDIR ?= target
+
+COMMONSOURCES=\
+               common/k3conf.c \
+               common/help.c \
+               common/mmio.c \
+               common/socinfo.c \
+               common/sec_proxy.c \
+               common/tisci/tisci_core.c
+
+COMMONOBJECTS= $(COMMONSOURCES:.c=.o)
+
+ALLSOURCES=    $(COMMONSOURCES)
+
+ALLOBJECTS=    $(COMMONOBJECTS)
+
+#
+# Pretty print
+#
+V             = @
+Q             = $(V:1=)
+QUIET_CC      = $(Q:@=@echo    '     CC       '$@;)
+QUIET_GEN     = $(Q:@=@echo    '     GEN      '$@;)
+QUIET_LINK    = $(Q:@=@echo    '     LINK     '$@;)
+
+EXECUTABLE=    k3conf
+
+.PHONY:        tags cscope
+
+all:           $(EXECUTABLE)
+
+$(EXECUTABLE): $(ALLOBJECTS) builddate.o version.o
+               $(QUIET_CC) $(CC) $(STATIC_BUILD) $(LDFLAGS) $(ALLOBJECTS) builddate.o version.o\
+               -lrt -o $@
+
+.c.o:
+               $(QUIET_CC) $(CC) $(MYCFLAGS) $(LDFLAGS) -c $< -o $@
+
+builddate.c:   $(ALLOBJECTS)
+               @echo 'char *builddate="'`date`'";' > builddate.c
+
+version.c:     $(ALLOBJECTS)
+               @echo 'char *k3conf_version="'`git describe --dirty 2>/dev/null||echo "$(VERSION_MAJOR).$(VERSION_MINOR)-nogit"`'";' > version.c
+
+tags: $(ALLSOURCES)
+       ctags $(shell $(CC) $(MYCFLAGS) -MM -MG $(ALLSOURCES) |\
+                       sed -e "s/^.*\.o://g"|tr -d '\\')
+
+cscope: $(ALLSOURCES)
+       cscope -R -b
+
+clean:
+               @echo "Cleaning up..."
+               -$(shell rm -f $(EXECUTABLE) *.o builddate.c version.c)
+               -$(shell rm -f $(ALLOBJECTS))
+               -$(shell rm -f tags cscope.out)
+               @echo "Done."
diff --git a/common/help.c b/common/help.c
new file mode 100644 (file)
index 0000000..a8e78a2
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * Help Library for K3CONF
+ *
+ * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/
+ *     Lokesh Vutla <lokeshvutla@ti.com>
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions
+ *  are met:
+ *
+ *    Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ *    Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the
+ *    distribution.
+ *
+ *    Neither the name of Texas Instruments Incorporated nor the names of
+ *    its contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <help.h>
+#include <stdio.h>
+
+void help(help_category cat)
+{
+       if (cat >= HELP_CATEGORY_MAX) {
+               fprintf(stderr, "help called with incorrect category!!! (%d)\n",
+                       cat);
+               return;
+       }
+
+       if ((cat == HELP_ALL) || (cat == HELP_USAGE)) {
+               printf("\nNAME\n");
+               printf("\tk3conf - TI K3 Configuration Diagnostic Tool\n");
+
+               printf("\nSYNOPSIS\n");
+               printf("\tk3conf [--version] [--help] <command> [<args>]\n");
+               if (cat == HELP_USAGE)
+                       printf("\n\tSee 'k3conf --help' for more information.\n\n");
+       }
+
+       if (cat == HELP_ALL) {
+               printf("\nDESCRIPTION\n");
+               printf("\tk3conf is standalone application designed to provide"
+                       " a quick'n easy way to \n\tdiagnose/debug/audit"
+                       " TI K3 architecture based processors configuration"
+                       " at\n\truntime, with no particular kernel dependency.\n");
+               printf("\tk3conf is designed to be as much platform-agnostic"
+                       " as possible, being able to \n\trun on any Linux platform"
+                       " and easily ported to other OS.\n");
+               printf("\tEven if k3conf today focuses mainly on TISCI"
+                       " related functionality, it is \n\tintended to be extended"
+                       " to any other area.\n");
+
+               printf("\nOPTIONS\n");
+               printf("\t--help\n");
+               printf("\t    Print k3conf help.\n");
+
+               printf("\n\t--version\n");
+               printf("\t    Print k3conf version.\n");
+       }
+}
diff --git a/common/k3conf.c b/common/k3conf.c
new file mode 100644 (file)
index 0000000..cbdfc1f
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ * K3CONF main entry file
+ *
+ * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/
+ *     Lokesh Vutla <lokeshvutla@ti.com>
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions
+ *  are met:
+ *
+ *    Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ *    Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the
+ *    distribution.
+ *
+ *    Neither the name of Texas Instruments Incorporated nor the names of
+ *    its contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <ctype.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <sec_proxy.h>
+#include <tisci.h>
+#include <version.h>
+#include <socinfo.h>
+#include <help.h>
+#include <string.h>
+
+void k3conf_print_version(FILE *stream)
+{
+       struct ti_sci_version_info ver = soc_info.sci_info.version;
+
+       if (stream == NULL) {
+               fprintf(stderr, "%s(): stream == NULL!!!\n", __func__);
+               return;
+       }
+
+       fprintf(stream, "K3CONF (version %s built %s)\n", k3conf_version,
+               builddate);
+       fprintf(stream, "SoC %s\n", soc_info.soc_full_name);
+
+       if (!soc_info.ti_sci_enabled)
+               return;
+
+       fprintf(stream, "SYSFW ABI: %d.%d (firmware version 0x%04x '%.*s)')\n",
+               ver.abi_major, ver.abi_minor, ver.firmware_version,
+               (int)sizeof(ver.firmware_description),
+               ver.firmware_description);
+}
+
+int main(int argc, char *argv[])
+{
+       int ret = 0;
+
+       /* Scan user arguments for options */
+       argc--;
+       argv++;
+
+       if (argc == 0) {
+               help(HELP_USAGE);
+               ret = -1;
+               goto main_exit;
+       }
+
+       if (soc_init())
+               goto main_exit;
+
+       if (!strcmp(argv[0], "--help")) {
+               k3conf_print_version(stdout);
+               help(HELP_ALL);
+               goto main_exit;
+       } else if (!strcmp(argv[0], "--version")) {
+               k3conf_print_version(stdout);
+               goto main_exit;
+       } else {
+               fprintf(stderr, "Invalid argument %s", argv[0]);
+               help(HELP_USAGE);
+               ret = -1;
+               goto main_exit;
+       }
+
+main_exit:
+       return ret;
+}
diff --git a/common/mmio.c b/common/mmio.c
new file mode 100644 (file)
index 0000000..148f01e
--- /dev/null
@@ -0,0 +1,230 @@
+/*
+ * K3CONF mmio helpers
+ *
+ * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/
+ *     Lokesh Vutla <lokeshvutla@ti.com>
+ *     Nishanth Menon <nm@ti.com>
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions
+ *  are met:
+ *
+ *    Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ *    Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the
+ *    distribution.
+ *
+ *    Neither the name of Texas Instruments Incorporated nor the names of
+ *    its contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/mman.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <mmio.h>
+#include <error.h>
+
+#define MEMORY "/dev/mem"
+
+unsigned page_size, mapped_size, offset_in_page;
+void *map_base, *virt_addr;
+int fd;
+
+static int map_address(off_t target)
+{
+       unsigned int width = 8 * sizeof(uint64_t);
+
+       fd = open(MEMORY, (O_RDWR | O_SYNC));
+       if (fd < 0) {
+               fprintf(stderr, "Could not open %s!\n", MEMORY);
+               return -5;
+       }
+
+       mapped_size = page_size = getpagesize();
+       offset_in_page = (unsigned)target & (page_size - 1);
+       if (offset_in_page + width > page_size) {
+               /*
+                * This access spans pages.
+                * Must map two pages to make it possible:
+                */
+               mapped_size *= 2;
+       }
+       map_base = mmap(NULL,
+                       mapped_size,
+                       (PROT_READ | PROT_WRITE),
+                       MAP_SHARED, fd, target & ~(off_t) (page_size - 1));
+       if (map_base == MAP_FAILED) {
+               fprintf(stderr, "Map fail\n");
+               return -1;
+       }
+
+       virt_addr = (char *)map_base + offset_in_page;
+       return 0;
+}
+
+static uint64_t read_reg(int width)
+{
+       uint64_t read_result = 0x0;
+
+       switch (width) {
+       case 8:
+               read_result = *(volatile uint8_t *)virt_addr;
+               break;
+       case 16:
+               read_result = *(volatile uint16_t *)virt_addr;
+               break;
+       case 32:
+               read_result = *(volatile uint32_t *)virt_addr;
+               break;
+       case 64:
+               read_result = *(volatile uint64_t *)virt_addr;
+               break;
+       default:
+               fprintf(stderr, "bad width");
+       }
+
+       return read_result;
+}
+
+static void write_reg(int width, uint64_t writeval)
+{
+       switch (width) {
+       case 8:
+               *(volatile uint8_t *)virt_addr = writeval;
+               break;
+       case 16:
+               *(volatile uint16_t *)virt_addr = writeval;
+               break;
+       case 32:
+               *(volatile uint32_t *)virt_addr = writeval;
+               break;
+       case 64:
+               *(volatile uint64_t *)virt_addr = writeval;
+               break;
+       default:
+               fprintf(stderr, "bad width");
+       }
+
+}
+
+static void unmap_address(void)
+{
+       if (munmap(map_base, mapped_size) == -1)
+               fprintf(stderr, "munmap");
+       close(fd);
+
+}
+
+void mmio_write_8(uintptr_t addr, uint8_t value)
+{
+       int r;
+
+       r = map_address(addr);
+       if (r)
+               return;
+       write_reg(8, value);
+       unmap_address();
+}
+
+uint8_t mmio_read_8(uintptr_t addr)
+{
+       uint8_t v = 0;
+       int r;
+
+       r = map_address(addr);
+       if (r)
+               return 0;
+       v = read_reg(8);
+       unmap_address();
+       return v;
+}
+
+void mmio_write_16(uintptr_t addr, uint16_t value)
+{
+       int r;
+
+       r = map_address(addr);
+       if (r)
+               return;
+       write_reg(16, value);
+       unmap_address();
+}
+
+uint16_t mmio_read_16(uintptr_t addr)
+{
+       uint16_t v = 0;
+       int r;
+
+       r = map_address(addr);
+       if (r)
+               return 0;
+       v = read_reg(16);
+       unmap_address();
+       return v;
+}
+
+void mmio_write_32(uintptr_t addr, uint32_t value)
+{
+       int r;
+
+       r = map_address(addr);
+       if (r)
+               return;
+       write_reg(32, value);
+       unmap_address();
+}
+
+uint32_t mmio_read_32(uintptr_t addr)
+{
+       uint32_t v = 0;
+       int r;
+
+       r = map_address(addr);
+       if (r)
+               return 0;
+       v = read_reg(32);
+       unmap_address();
+       return v;
+}
+
+void mmio_write_64(uintptr_t addr, uint64_t value)
+{
+       int r;
+
+       r = map_address(addr);
+       if (r)
+               return;
+       write_reg(64, value);
+       unmap_address();
+}
+
+uint64_t mmio_read_64(uintptr_t addr)
+{
+       uint64_t v = 0;
+       int r;
+
+       r = map_address(addr);
+       if (r)
+               return 0;
+       v = read_reg(64);
+       unmap_address();
+       return v;
+}
diff --git a/common/sec_proxy.c b/common/sec_proxy.c
new file mode 100644 (file)
index 0000000..9de3f93
--- /dev/null
@@ -0,0 +1,217 @@
+/*
+ * K3 Secure proxy driver
+ *
+ * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/
+ *     Lokesh Vutla <lokeshvutla@ti.com>
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions
+ *  are met:
+ *
+ *    Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ *    Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the
+ *    distribution.
+ *
+ *    Neither the name of Texas Instruments Incorporated nor the names of
+ *    its contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <sec_proxy.h>
+#include <mmio.h>
+#include <error.h>
+#include <socinfo.h>
+
+/* SEC PROXY RT THREAD STATUS */
+#define RT_THREAD_STATUS                       0x0
+#define RT_THREAD_THRESHOLD                    0x4
+#define RT_THREAD_STATUS_ERROR_SHIFT           31
+#define RT_THREAD_STATUS_ERROR_MASK            (1 << 31)
+#define RT_THREAD_STATUS_CUR_CNT_SHIFT         0
+#define RT_THREAD_STATUS_CUR_CNT_MASK          0xff
+
+/* SEC PROXY SCFG THREAD CTRL */
+#define SCFG_THREAD_CTRL                       0x1000
+#define SCFG_THREAD_CTRL_DIR_SHIFT             31
+#define SCFG_THREAD_CTRL_DIR_MASK              (1 << 31)
+
+#define SEC_PROXY_THREAD(base, x)              ((base) + (0x1000 * (x)))
+#define SEC_PROXY_TX_THREAD                    0
+#define SEC_PROXY_RX_THREAD                    1
+#define SEC_PROXY_MAX_THREADS                  2
+
+#define SEC_PROXY_TIMEOUT_US                   1000000
+
+#define SEC_PROXY_DATA_START_OFFS              0x4
+#define SEC_PROXY_DATA_END_OFFS                        0x3c
+
+/* Physical address for AM6 NAVSS 256 Main domain */
+#define SEC_PROXY0_CFG_MMRS            0x31140000
+#define SEC_PROXY0_SRC_TARGET_DATA     0x32C00000
+#define SEC_PROXY0_CFG_SCFG            0x32800000
+#define SEC_PROXY0_CFG_RT              0x32400000
+
+struct k3_sec_proxy_thread {
+       uint32_t id;
+       uintptr_t data;
+       uintptr_t scfg;
+       uintptr_t rt;
+} spts[SEC_PROXY_MAX_THREADS];
+
+static inline uint32_t sp_readl(uintptr_t addr)
+{
+       return mmio_read_32(addr);
+}
+
+static inline void sp_writel(uintptr_t addr, uint32_t data)
+{
+       mmio_write_32(addr, data);
+}
+
+static int k3_sec_proxy_verify_thread(uint32_t dir)
+{
+       struct k3_sec_proxy_thread *spt = &spts[dir];
+
+       /* Check for any errors already available */
+       if (sp_readl(spt->rt + RT_THREAD_STATUS) &
+           RT_THREAD_STATUS_ERROR_MASK) {
+               fprintf(stderr, "%s: Thread %d is corrupted, cannot send data.\n",
+                      __func__, spt->id);
+               return -1;
+       }
+
+       /* Make sure thread is configured for right direction */
+       if ((sp_readl(spt->scfg + SCFG_THREAD_CTRL)
+           & SCFG_THREAD_CTRL_DIR_MASK) >> SCFG_THREAD_CTRL_DIR_SHIFT != dir) {
+               if (dir)
+                       fprintf(stderr, "%s: Trying to receive data on tx Thread %d\n",
+                              __func__, spt->id);
+               else
+                       fprintf(stderr, "%s: Trying to send data on rx Thread %d\n",
+                              __func__, spt->id);
+               return -1;
+       }
+
+       /* Check the message queue before sending/receiving data */
+       if (!(sp_readl(spt->rt + RT_THREAD_STATUS) &
+             RT_THREAD_STATUS_CUR_CNT_MASK))
+               return -2;
+
+       return 0;
+}
+
+int k3_sec_proxy_send(struct k3_sec_proxy_msg *msg)
+{
+       struct k3_sec_proxy_thread *spt = &spts[SEC_PROXY_TX_THREAD];
+       int num_words, trail_bytes, ret;
+       uint32_t *word_data;
+       uintptr_t data_reg;
+
+       ret = k3_sec_proxy_verify_thread(SEC_PROXY_TX_THREAD);
+       if (ret) {
+               fprintf(stderr, "%s: Thread%d verification failed. ret = %d\n",
+                       __func__, spt->id, ret);
+               return ret;
+       }
+
+       /* Check the message size. */
+       if (msg->len > SEC_PROXY_MAX_MSG_SIZE) {
+               fprintf(stderr, "%s: Thread %u message length %zu > max msg size %d\n",
+                      __func__, spt->id, msg->len, SEC_PROXY_MAX_MSG_SIZE);
+               return -1;
+       }
+
+       /* Send the message */
+       data_reg = spt->data + SEC_PROXY_DATA_START_OFFS;
+       word_data = (uint32_t *)msg->buf;
+       for (num_words = msg->len / sizeof(uint32_t);
+            num_words;
+            num_words--, data_reg += sizeof(uint32_t), word_data++)
+               sp_writel(data_reg, *word_data);
+
+       trail_bytes = msg->len % sizeof(uint32_t);
+       if (trail_bytes) {
+               uint32_t data_trail = *word_data;
+
+               /* Ensure all unused data is 0 */
+               data_trail &= 0xFFFFFFFF >> (8 * (sizeof(uint32_t) - trail_bytes));
+               sp_writel(data_reg, data_trail);
+               data_reg++;
+       }
+
+       /*
+        * 'data_reg' indicates next register to write. If we did not already
+        * write on tx complete reg(last reg), we must do so for transmit
+        */
+       if (data_reg <= (spt->data + SEC_PROXY_DATA_END_OFFS))
+               sp_writel(spt->data + SEC_PROXY_DATA_END_OFFS, 0);
+
+       return 0;
+}
+
+int k3_sec_proxy_recv(struct k3_sec_proxy_msg *msg)
+{
+       struct k3_sec_proxy_thread *spt = &spts[SEC_PROXY_RX_THREAD];
+       int num_words, ret = -1, retry = 10000;
+       uint32_t *word_data;
+       uintptr_t data_reg;
+
+       while (retry-- && ret) {
+               ret = k3_sec_proxy_verify_thread(SEC_PROXY_RX_THREAD);
+               if ((ret && ret != -2) || !retry) {
+                       fprintf(stderr, "%s: Thread%d verification failed. ret = %d\n",
+                               __func__, spt->id, ret);
+                       return ret;
+               }
+       }
+
+       data_reg = spt->data + SEC_PROXY_DATA_START_OFFS;
+       word_data = (uint32_t *)(uintptr_t)msg->buf;
+       for (num_words = SEC_PROXY_MAX_MSG_SIZE / sizeof(uint32_t);
+            num_words;
+            num_words--, data_reg += sizeof(uint32_t), word_data++)
+               *word_data = sp_readl(data_reg);
+
+       return 0;
+}
+
+int k3_sec_proxy_init(void)
+{
+       uint32_t rx_thread, tx_thread;
+
+       if (soc_info.host_id == DEFAULT_HOST_ID) {
+               tx_thread = DEFAULT_SEC_PROXY_TX_THREAD;
+               rx_thread = DEFAULT_SEC_PROXY_RX_THREAD;
+       }
+
+       /* ToDO: Get thread ids using host_id and soc information */
+       spts[SEC_PROXY_TX_THREAD].id = tx_thread;
+       spts[SEC_PROXY_TX_THREAD].data = SEC_PROXY_THREAD(SEC_PROXY0_SRC_TARGET_DATA, tx_thread);
+       spts[SEC_PROXY_TX_THREAD].scfg = SEC_PROXY_THREAD(SEC_PROXY0_CFG_SCFG, tx_thread);
+       spts[SEC_PROXY_TX_THREAD].rt = SEC_PROXY_THREAD(SEC_PROXY0_CFG_RT, tx_thread);
+
+       spts[SEC_PROXY_RX_THREAD].id = rx_thread;
+       spts[SEC_PROXY_RX_THREAD].data = SEC_PROXY_THREAD(SEC_PROXY0_SRC_TARGET_DATA, rx_thread);
+       spts[SEC_PROXY_RX_THREAD].scfg = SEC_PROXY_THREAD(SEC_PROXY0_CFG_SCFG, rx_thread);
+       spts[SEC_PROXY_RX_THREAD].rt = SEC_PROXY_THREAD(SEC_PROXY0_CFG_RT, rx_thread);
+
+       return 0;
+}
diff --git a/common/socinfo.c b/common/socinfo.c
new file mode 100644 (file)
index 0000000..3a23b5a
--- /dev/null
@@ -0,0 +1,121 @@
+/*
+ * K3 SoC detection and helper apis
+ *
+ * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/
+ *     Lokesh Vutla <lokeshvutla@ti.com>
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions
+ *  are met:
+ *
+ *    Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ *    Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the
+ *    distribution.
+ *
+ *    Neither the name of Texas Instruments Incorporated nor the names of
+ *    its contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <socinfo.h>
+#include <mmio.h>
+#include <string.h>
+#include <sec_proxy.h>
+
+/* Assuming these addresses and definitions stay common across K3 devices */
+#define CTRLMMR_WKUP_JTAG_DEVICE_ID    0x43000018
+#define DEVICE_ID_FAMILY_SHIFT 26
+#define DEVICE_ID_FAMILY_MASK  (0x3f << 26)
+#define DEVICE_ID_BASE_SHIFT   11
+#define DEVICE_ID_BASE_MASK    (0x1fff << 11)
+#define DEVICE_ID_SPEED_SHIFT  6
+#define DEVICE_ID_SPEED_MASK   (0x1f << 6)
+#define DEVICE_ID_TEMP_SHIFT   3
+#define DEVICE_ID_TEMP_MASK    (0x7 << 3)
+
+#define CTRLMMR_WKUP_JTAG_ID           0x43000014
+#define JTAG_ID_VARIANT_SHIFT  28
+#define JTAG_ID_VARIANT_MASK   (0xf << 28)
+#define JTAG_ID_PARTNO_SHIFT   12
+#define JTAG_ID_PARTNO_MASK    (0x7ff << 1)
+
+#define CTRLMMR_WKUP_DIE_ID0   0x43000020
+#define CTRLMMR_WKUP_DIE_ID1   0x43000024
+#define CTRLMMR_WKUP_DIE_ID2   0x43000028
+#define CTRLMMR_WKUP_DIE_ID3   0x4300002c
+#define CTRLMMR_WKUP_DEVSTAT   0x43000030
+#define CTRLMMR_WKUP_BOOTCFG   0x43000034
+
+struct k3conf_soc_info soc_info;
+
+static const char soc_name[K3_MAX + 1][SOC_NAME_MAX_LENGTH] = {
+       [AM654] = "AM654",
+       [J721E] = "J721E",
+       [K3_MAX] = "UNKNOWN"
+};
+
+static const char soc_revision[REV_PG_MAX + 1][SOC_REVISION_MAX_LENGTH] = {
+       [REV_PG1_0] = "1.0",
+       [REV_PG2_0] = "2.0",
+       [REV_PG_MAX] = "NULL"
+};
+
+int soc_init(void)
+{
+       memset(&soc_info, 0, sizeof(soc_info));
+
+       soc_info.soc = (mmio_read_32(CTRLMMR_WKUP_JTAG_DEVICE_ID) &
+                       DEVICE_ID_FAMILY_MASK) >> DEVICE_ID_FAMILY_SHIFT;
+       soc_info.rev = (mmio_read_32(CTRLMMR_WKUP_JTAG_ID) &
+                       JTAG_ID_VARIANT_MASK) >> JTAG_ID_VARIANT_SHIFT;
+
+       if (soc_info.soc > K3_MAX || !soc_name[soc_info.soc]) {
+               fprintf(stderr, "Unknown Silicon %d\n", soc_info.soc);
+               return -1;
+       }
+       if (soc_info.rev > REV_PG_MAX) {
+               fprintf(stderr, "Unknown Silicon revision %d for SoC %s\n",
+                       soc_info.rev, soc_name[soc_info.soc]);
+               return -1;
+       }
+
+       strncpy(soc_info.soc_full_name, "", sizeof(soc_info.soc_full_name));
+       strcat(soc_info.soc_full_name, soc_name[soc_info.soc]);
+       strcat(soc_info.soc_full_name, " PG");
+       strcat(soc_info.soc_full_name, soc_revision[soc_info.rev]);
+
+       soc_info.host_id = DEFAULT_HOST_ID;
+
+       /* ToDo: Add error if sec_proxy_init/sci_init is failed */
+       if(!k3_sec_proxy_init())
+               if (!ti_sci_init())
+                       soc_info.ti_sci_enabled = 1;
+
+       return 0;
+}
+
+int soc_is_j721e(void)
+{
+       return soc_info.soc == J721E;
+}
+
+int soc_is_am654(void)
+{
+       return soc_info.soc == AM654;
+}
diff --git a/common/tisci/tisci_core.c b/common/tisci/tisci_core.c
new file mode 100644 (file)
index 0000000..de401da
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ * TISCI core library
+ *
+ * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/
+ *     Lokesh Vutla <lokeshvutla@ti.com>
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions
+ *  are met:
+ *
+ *    Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ *    Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the
+ *    distribution.
+ *
+ *    Neither the name of Texas Instruments Incorporated nor the names of
+ *    its contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <string.h>
+#include <sec_proxy.h>
+#include <tisci.h>
+#include <tisci_protocol.h>
+#include <socinfo.h>
+
+static int seq = 0;
+
+void ti_sci_setup_header(struct ti_sci_msg_hdr *hdr, uint16_t type,
+                        uint32_t flags)
+{
+       hdr->type = type;
+       hdr->host = soc_info.host_id;
+       hdr->seq = seq++;
+       hdr->flags = TI_SCI_FLAG_REQ_ACK_ON_PROCESSED | flags;
+}
+
+int ti_sci_xfer_msg(struct k3_sec_proxy_msg *msg)
+{
+       int ret;
+
+       if (!msg->len || !msg->buf)
+               return -1;
+
+       ret = k3_sec_proxy_send(msg);
+       if (ret)
+               return ret;
+
+       memset(msg->buf, 0, msg->len);
+       ret = k3_sec_proxy_recv(msg);
+       if (ret)
+               return ret;
+
+       if (!ti_sci_is_response_ack(msg->buf))
+               return -1;
+
+       return 0;
+}
+
+int ti_sci_init(void)
+{
+       struct ti_sci_msg_resp_version *version;
+       struct ti_sci_version_info *glb_ver;
+       uint8_t buf[SEC_PROXY_MAX_MSG_SIZE];
+       struct k3_sec_proxy_msg msg;
+       int ret;
+
+       memset(buf, 0, sizeof(buf));
+       ti_sci_setup_header((struct ti_sci_msg_hdr *)buf, TI_SCI_MSG_VERSION,
+                           0);
+
+       msg.len = sizeof(struct ti_sci_msg_hdr);
+       msg.buf = buf;
+       ret = ti_sci_xfer_msg(&msg);
+       if (ret)
+               return ret;
+
+       version = (struct ti_sci_msg_resp_version *)buf;
+       glb_ver = &soc_info.sci_info.version;
+       glb_ver->abi_major = version->abi_major;
+       glb_ver->abi_minor = version->abi_minor;
+       glb_ver->firmware_version = version->version;
+       strncpy(glb_ver->firmware_description, version->firmware_description,
+               sizeof(glb_ver->firmware_description));
+
+       return 0;
+}
diff --git a/include/help.h b/include/help.h
new file mode 100644 (file)
index 0000000..abaf259
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Help Library Header File for K3CONF
+ *
+ * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/
+ *     Lokesh Vutla <lokeshvutla@ti.com>
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions
+ *  are met:
+ *
+ *    Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ *    Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the
+ *    distribution.
+ *
+ *    Neither the name of Texas Instruments Incorporated nor the names of
+ *    its contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __K3CONF_HELP
+#define __K3CONF_HELP
+
+typedef enum {
+       HELP_USAGE,
+       HELP_ALL,
+       HELP_CATEGORY_MAX,
+} help_category;
+
+void help(help_category cat);
+#endif
diff --git a/include/mmio.h b/include/mmio.h
new file mode 100644 (file)
index 0000000..1eb83dc
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * MMIO helper library header file.
+ *
+ * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/
+ *     Lokesh Vutla <lokeshvutla@ti.com>
+ *     Nishanth Menon <nm@ti.com>
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions
+ *  are met:
+ *
+ *    Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ *    Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the
+ *    distribution.
+ *
+ *    Neither the name of Texas Instruments Incorporated nor the names of
+ *    its contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __MMIO_H
+#define __MMIO_H
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <ctype.h>
+
+void mmio_write_8(uintptr_t addr, uint8_t value);
+
+uint8_t mmio_read_8(uintptr_t addr);
+
+void mmio_write_16(uintptr_t addr, uint16_t value);
+
+uint16_t mmio_read_16(uintptr_t addr);
+
+void mmio_write_32(uintptr_t addr, uint32_t value);
+
+uint32_t mmio_read_32(uintptr_t addr);
+
+void mmio_write_64(uintptr_t addr, uint64_t value);
+
+uint64_t mmio_read_64(uintptr_t addr);
+
+static inline void mmio_clrbits_32(uintptr_t addr, uint32_t clear)
+{
+       mmio_write_32(addr, mmio_read_32(addr) & ~clear);
+}
+
+static inline void mmio_setbits_32(uintptr_t addr, uint32_t set)
+{
+       mmio_write_32(addr, mmio_read_32(addr) | set);
+}
+
+static inline void mmio_clrsetbits_32(uintptr_t addr,
+                                     uint32_t clear, uint32_t set)
+{
+       mmio_write_32(addr, (mmio_read_32(addr) & ~clear) | set);
+}
+
+#endif /* __MMIO_H */
diff --git a/include/sec_proxy.h b/include/sec_proxy.h
new file mode 100644 (file)
index 0000000..6ba43a4
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Secure Proxy header file
+ *
+ * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/
+ *     Lokesh Vutla <lokeshvutla@ti.com>
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions
+ *  are met:
+ *
+ *    Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ *    Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the
+ *    distribution.
+ *
+ *    Neither the name of Texas Instruments Incorporated nor the names of
+ *    its contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+
+#ifndef __SEC_PROXY_H
+#define __SEC_PROXY_H
+
+#define DEFAULT_HOST_ID                14
+#define DEFAULT_SEC_PROXY_RX_THREAD    21
+#define DEFAULT_SEC_PROXY_TX_THREAD    23
+
+#define SEC_PROXY_MAX_MSG_SIZE 60
+#define SEC_PROXY_HOST         14
+
+struct k3_sec_proxy_msg {
+       size_t len;
+       uint8_t *buf;
+};
+
+int k3_sec_proxy_send(struct k3_sec_proxy_msg *msg);
+int k3_sec_proxy_recv(struct k3_sec_proxy_msg *msg);
+int k3_sec_proxy_init();
+
+#endif /* __SEC_PROXY_H */
diff --git a/include/socinfo.h b/include/socinfo.h
new file mode 100644 (file)
index 0000000..719e8f5
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * SoC info header file
+ *
+ * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/
+ *     Lokesh Vutla <lokeshvutla@ti.com>
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions
+ *  are met:
+ *
+ *    Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ *    Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the
+ *    distribution.
+ *
+ *    Neither the name of Texas Instruments Incorporated nor the names of
+ *    its contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __SOCINFO_H
+#define __SOCINFO_H
+
+#include <stdint.h>
+#include <tisci.h>
+
+#define SOC_NAME_MAX_LENGTH                    10
+#define SOC_REVISION_MAX_LENGTH                        5
+#define SOC_FULL_NAME_MAX_LENGTH               20
+
+typedef enum {
+       AM654 = 2,
+       J721E = 4,
+       K3_MAX
+} k3_soc;
+
+typedef enum {
+       REV_PG1_0,
+       REV_PG2_0,
+       REV_PG_MAX
+} k3_soc_rev;
+
+struct k3conf_soc_info {
+       k3_soc soc;
+       k3_soc_rev rev;
+       char soc_full_name[SOC_FULL_NAME_MAX_LENGTH];
+       uint8_t host_id;
+       uint8_t ti_sci_enabled;
+       struct ti_sci_info sci_info;
+};
+
+extern struct k3conf_soc_info soc_info;
+int soc_init(void);
+int soc_is_j721e(void);
+int soc_is_am654(void);
+
+#endif
diff --git a/include/tisci.h b/include/tisci.h
new file mode 100644 (file)
index 0000000..43faefe
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * TISCI helper apis header file
+ *
+ * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/
+ *     Lokesh Vutla <lokeshvutla@ti.com>
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions
+ *  are met:
+ *
+ *    Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ *    Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the
+ *    distribution.
+ *
+ *    Neither the name of Texas Instruments Incorporated nor the names of
+ *    its contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __TISCI_H
+#define __TISCI_H
+
+#include <stdint.h>
+
+struct ti_sci_version_info {
+       uint8_t abi_major;
+       uint8_t abi_minor;
+       uint16_t firmware_version;
+       char firmware_description[32];
+};
+
+struct ti_sci_info {
+       uint8_t host_id;
+       struct ti_sci_version_info version;
+};
+
+int ti_sci_init(void);
+#endif
diff --git a/include/tisci_protocol.h b/include/tisci_protocol.h
new file mode 100644 (file)
index 0000000..b40baec
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * TISCI Protocol header file.
+ *
+ * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/
+ *     Lokesh Vutla <lokeshvutla@ti.com>
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions
+ *  are met:
+ *
+ *    Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ *    Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the
+ *    distribution.
+ *
+ *    Neither the name of Texas Instruments Incorporated nor the names of
+ *    its contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __TISCI_P_H
+#define __TISCI_P_H
+
+#include <stdint.h>
+#include <sec_proxy.h>
+
+#define TI_SCI_MSG_VERSION             0x0002
+
+#define TI_SCI_MSG_FLAG(val)                   (1 << (val))
+#define TI_SCI_FLAG_REQ_GENERIC_NORESPONSE     0x0
+#define TI_SCI_FLAG_REQ_ACK_ON_RECEIVED                TI_SCI_MSG_FLAG(0)
+#define TI_SCI_FLAG_REQ_ACK_ON_PROCESSED       TI_SCI_MSG_FLAG(1)
+#define TI_SCI_FLAG_RESP_GENERIC_NACK          0x0
+#define TI_SCI_FLAG_RESP_GENERIC_ACK           TI_SCI_MSG_FLAG(1)
+
+struct ti_sci_msg_hdr {
+       uint16_t type;
+       uint8_t host;
+       uint8_t seq;
+       uint32_t flags;
+} __attribute__ ((__packed__));
+
+struct ti_sci_msg_resp_version {
+       struct ti_sci_msg_hdr hdr;
+       char firmware_description[32];
+       uint16_t version;
+       uint8_t abi_major;
+       uint8_t abi_minor;
+} __attribute__ ((__packed__));
+
+struct ti_sci_secure_msg_hdr {
+       uint16_t checksum;
+       uint16_t reserved;
+} __attribute__ ((__packed__));
+
+int ti_sci_xfer_msg(struct k3_sec_proxy_msg *msg);
+
+static inline uint8_t ti_sci_is_response_ack(uint8_t *resp)
+{
+       struct ti_sci_msg_hdr *hdr = (struct ti_sci_msg_hdr *)resp;
+
+       return hdr->flags & TI_SCI_FLAG_RESP_GENERIC_ACK ? 1 : 0;
+}
+
+#endif
diff --git a/include/version.h b/include/version.h
new file mode 100644 (file)
index 0000000..aca69b7
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Version info header file.
+ *
+ * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/
+ *     Lokesh Vutla <lokeshvutla@ti.com>
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions
+ *  are met:
+ *
+ *    Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ *    Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the
+ *    distribution.
+ *
+ *    Neither the name of Texas Instruments Incorporated nor the names of
+ *    its contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __VERSION_H__
+#define __VERSION_H__
+
+extern char *k3conf_version;
+extern char *builddate;
+
+#endif