Remapping command stream and base pointers

Add new weak function ethosu_address_remap() that allows the addresses
for QBASE and BASEP to be remapped.

Change-Id: I36b0d71c57bfd293672b10c7b85f3b2415e9c839
diff --git a/include/ethosu_driver.h b/include/ethosu_driver.h
index c48a3f2..187d49a 100644
--- a/include/ethosu_driver.h
+++ b/include/ethosu_driver.h
@@ -136,6 +136,16 @@
 void ethosu_inference_begin(struct ethosu_driver *drv, void *user_arg);
 void ethosu_inference_end(struct ethosu_driver *drv, void *user_arg);
 
+/**
+ * Remapping command stream and base pointer addresses.
+ *
+ * @param address   Address to be remapped.
+ * @param index     -1: command stream, 0-n base address index
+ *
+ * @return Remapped address
+ */
+uint64_t ethosu_address_remap(uint64_t address, int index);
+
 /******************************************************************************
  * Prototypes
  ******************************************************************************/
diff --git a/src/ethosu_config_u55.h b/src/ethosu_config_u55.h
index afb75bc..9330bb1 100644
--- a/src/ethosu_config_u55.h
+++ b/src/ethosu_config_u55.h
@@ -121,12 +121,4 @@
 #define AXI_LIMIT3_MAX_OUTSTANDING_WRITES 16
 #endif
 
-/*
- * Address offset between the CPU and the NPU. The offset is
- * applied to the QBASE and BASEP registers.
- */
-#ifndef BASE_POINTER_OFFSET
-#define BASE_POINTER_OFFSET 0
-#endif
-
 #endif /* #ifndef ETHOSU_CONFIG_H */
diff --git a/src/ethosu_config_u65.h b/src/ethosu_config_u65.h
index d662886..b115f43 100644
--- a/src/ethosu_config_u65.h
+++ b/src/ethosu_config_u65.h
@@ -121,12 +121,4 @@
 #define AXI_LIMIT3_MAX_OUTSTANDING_WRITES 32
 #endif
 
-/*
- * Address offset between the CPU and the NPU. The offset is
- * applied to the QBASE and BASEP registers.
- */
-#ifndef BASE_POINTER_OFFSET
-#define BASE_POINTER_OFFSET 0
-#endif
-
 #endif /* #ifndef ETHOSU_CONFIG_H */
diff --git a/src/ethosu_device_u55_u65.c b/src/ethosu_device_u55_u65.c
index 54d2a79..aec2027 100644
--- a/src/ethosu_device_u55_u65.c
+++ b/src/ethosu_device_u55_u65.c
@@ -16,6 +16,10 @@
  * limitations under the License.
  */
 
+/******************************************************************************
+ * Includes
+ ******************************************************************************/
+
 #include "ethosu_interface.h"
 
 #include "ethosu_device.h"
@@ -34,6 +38,10 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+/******************************************************************************
+ * Defines
+ ******************************************************************************/
+
 #define ETHOSU_PRODUCT_U55 0
 #define ETHOSU_PRODUCT_U65 1
 
@@ -49,6 +57,16 @@
 
 #define NPU_CMD_PWR_CLK_MASK (0xC)
 
+/******************************************************************************
+ * Functions
+ ******************************************************************************/
+
+uint64_t __attribute__((weak)) ethosu_address_remap(uint64_t address, int index)
+{
+    (void)(index);
+    return address;
+}
+
 struct ethosu_device *ethosu_dev_init(const void *base_address, uint32_t secure_enable, uint32_t privilege_enable)
 {
     struct ethosu_device *dev = malloc(sizeof(struct ethosu_device));
@@ -147,9 +165,9 @@
     assert(num_base_addr <= NPU_REG_BASEP_ARRLEN);
 
     struct cmd_r cmd;
-    uint64_t qbase = (uintptr_t)cmd_stream_ptr + BASE_POINTER_OFFSET;
+    uint64_t qbase = ethosu_address_remap((uintptr_t)cmd_stream_ptr, -1);
     assert(qbase <= ADDRESS_MASK);
-    LOG_DEBUG("QBASE=0x%016llx, QSIZE=%u, base_pointer_offset=0x%08x", qbase, cms_length, BASE_POINTER_OFFSET);
+    LOG_DEBUG("QBASE=0x%016llx, QSIZE=%u, cmd_stream_ptr=%p", qbase, cms_length, cmd_stream_ptr);
 
     dev->reg->QBASE.word[0] = qbase & 0xffffffff;
 #ifdef ETHOSU65
@@ -159,7 +177,7 @@
 
     for (int i = 0; i < num_base_addr; i++)
     {
-        uint64_t addr = base_addr[i] + BASE_POINTER_OFFSET;
+        uint64_t addr = ethosu_address_remap(base_addr[i], i);
         assert(addr <= ADDRESS_MASK);
         LOG_DEBUG("BASEP%d=0x%016llx", i, addr);
         dev->reg->BASEP[i].word[0] = addr & 0xffffffff;