Merge changes from topic "av/console-register" into integration

* changes:
  Console: Remove Arm console unregister on suspend
  Console: Allow to register multiple times
diff --git a/plat/ti/k3/common/drivers/sec_proxy/sec_proxy.c b/plat/ti/k3/common/drivers/sec_proxy/sec_proxy.c
index 49cecd4..ee1eecf 100644
--- a/plat/ti/k3/common/drivers/sec_proxy/sec_proxy.c
+++ b/plat/ti/k3/common/drivers/sec_proxy/sec_proxy.c
@@ -51,14 +51,14 @@
 };
 
 /**
- * struct k3_sec_proxy_thread - Description of a secure proxy Thread
- * @id:		Thread ID
+ * struct k3_sec_proxy_thread - Description of a Secure Proxy Thread
+ * @name:	Thread Name
  * @data:	Thread Data path region for target
  * @scfg:	Secure Config Region for Thread
  * @rt:		RealTime Region for Thread
  */
 struct k3_sec_proxy_thread {
-	uint32_t id;
+	const char *name;
 	uintptr_t data;
 	uintptr_t scfg;
 	uintptr_t rt;
@@ -83,7 +83,7 @@
  */
 #define SP_THREAD(_x) \
 	[_x] = { \
-		.id = _x, \
+		.name = #_x, \
 		.data = SEC_PROXY_THREAD(SEC_PROXY_DATA_BASE, _x), \
 		.scfg = SEC_PROXY_THREAD(SEC_PROXY_SCFG_BASE, _x), \
 		.rt = SEC_PROXY_THREAD(SEC_PROXY_RT_BASE, _x), \
@@ -131,19 +131,19 @@
 	/* Check for any errors already available */
 	if (mmio_read_32(spt->rt + RT_THREAD_STATUS) &
 	    RT_THREAD_STATUS_ERROR_MASK) {
-		ERROR("Thread %d is corrupted, cannot send data\n", spt->id);
+		ERROR("Thread %s is corrupted, cannot send data\n", spt->name);
 		return -EINVAL;
 	}
 
 	/* Make sure thread is configured for right direction */
 	if ((mmio_read_32(spt->scfg + SCFG_THREAD_CTRL) & SCFG_THREAD_CTRL_DIR_MASK)
 	    != (dir << SCFG_THREAD_CTRL_DIR_SHIFT)) {
-		if (dir)
-			ERROR("Trying to send data on RX Thread %d\n",
-			      spt->id);
+		if (dir == THREAD_IS_TX)
+			ERROR("Trying to send data on RX Thread %s\n",
+			      spt->name);
 		else
-			ERROR("Trying to receive data on TX Thread %d\n",
-			      spt->id);
+			ERROR("Trying to receive data on TX Thread %s\n",
+			      spt->name);
 		return -EINVAL;
 	}
 
@@ -151,10 +151,12 @@
 	uint32_t tick_start = (uint32_t)read_cntpct_el0();
 	uint32_t ticks_per_us = SYS_COUNTER_FREQ_IN_TICKS / 1000000;
 	while (!(mmio_read_32(spt->rt + RT_THREAD_STATUS) & RT_THREAD_STATUS_CUR_CNT_MASK)) {
-		VERBOSE("Waiting for thread %d to clear\n", spt->id);
+		VERBOSE("Waiting for thread %s to %s\n",
+			spt->name, (dir == THREAD_IS_TX) ? "empty" : "fill");
 		if (((uint32_t)read_cntpct_el0() - tick_start) >
 		    (spm.desc.timeout_us * ticks_per_us)) {
-			ERROR("Timeout waiting for thread %d to clear\n", spt->id);
+			ERROR("Timeout waiting for thread %s to %s\n",
+				spt->name, (dir == THREAD_IS_TX) ? "empty" : "fill");
 			return -ETIMEDOUT;
 		}
 	}
@@ -176,13 +178,13 @@
 	/* Check for any errors already available */
 	if (mmio_read_32(spt->rt + RT_THREAD_STATUS) &
 	    RT_THREAD_STATUS_ERROR_MASK) {
-		ERROR("Thread %d is corrupted, cannot send data\n", spt->id);
+		ERROR("Thread %s is corrupted, cannot send data\n", spt->name);
 		return -EINVAL;
 	}
 
 	/* Make sure thread is configured for right direction */
 	if (!(mmio_read_32(spt->scfg + SCFG_THREAD_CTRL) & SCFG_THREAD_CTRL_DIR_MASK)) {
-		ERROR("Cannot clear a transmit thread %d\n", spt->id);
+		ERROR("Cannot clear a transmit thread %s\n", spt->name);
 		return -EINVAL;
 	}
 
@@ -190,10 +192,10 @@
 	uint32_t try_count = 10;
 	while (mmio_read_32(spt->rt + RT_THREAD_STATUS) & RT_THREAD_STATUS_CUR_CNT_MASK) {
 		if (!(try_count--)) {
-			ERROR("Could not clear all messages from thread %d\n", spt->id);
+			ERROR("Could not clear all messages from thread %s\n", spt->name);
 			return -ETIMEDOUT;
 		}
-		WARN("Clearing message from thread %d\n", spt->id);
+		WARN("Clearing message from thread %s\n", spt->name);
 		mmio_read_32(spt->data + spm.desc.data_end_offset);
 	}
 
@@ -216,14 +218,14 @@
 
 	ret = k3_sec_proxy_verify_thread(spt, THREAD_IS_TX);
 	if (ret) {
-		ERROR("Thread %d verification failed (%d)\n", spt->id, ret);
+		ERROR("Thread %s verification failed (%d)\n", spt->name, ret);
 		return ret;
 	}
 
 	/* Check the message size */
 	if (msg->len + sizeof(secure_header) > spm.desc.max_msg_size) {
-		ERROR("Thread %d message length %lu > max msg size\n",
-		      spt->id, msg->len);
+		ERROR("Thread %s message length %lu > max msg size\n",
+		      spt->name, msg->len);
 		return -EINVAL;
 	}
 
@@ -263,7 +265,7 @@
 	if (data_reg <= spm.desc.data_end_offset)
 		mmio_write_32(spt->data + spm.desc.data_end_offset, 0);
 
-	VERBOSE("Message successfully sent on thread %ud\n", id);
+	VERBOSE("Message successfully sent on thread %s\n", spt->name);
 
 	return 0;
 }
@@ -275,7 +277,7 @@
  *
  * Return: 0 if all goes well, else appropriate error message
  */
-int k3_sec_proxy_recv(uint32_t id, struct k3_sec_proxy_msg *msg)
+int k3_sec_proxy_recv(enum k3_sec_proxy_chan_id id, struct k3_sec_proxy_msg *msg)
 {
 	struct k3_sec_proxy_thread *spt = &spm.threads[id];
 	union sec_msg_hdr secure_header;
@@ -284,7 +286,7 @@
 
 	ret = k3_sec_proxy_verify_thread(spt, THREAD_IS_RX);
 	if (ret) {
-		ERROR("Thread %d verification failed (%d)\n", spt->id, ret);
+		ERROR("Thread %s verification failed (%d)\n", spt->name, ret);
 		return ret;
 	}
 
@@ -323,7 +325,7 @@
 	/* TODO: Verify checksum */
 	(void)secure_header.checksum;
 
-	VERBOSE("Message successfully received from thread %ud\n", id);
+	VERBOSE("Message successfully received from thread %s\n", spt->name);
 
 	return 0;
 }
diff --git a/plat/ti/k3/common/drivers/ti_sci/ti_sci.c b/plat/ti/k3/common/drivers/ti_sci/ti_sci.c
index df0b794..ac33278 100644
--- a/plat/ti/k3/common/drivers/ti_sci/ti_sci.c
+++ b/plat/ti/k3/common/drivers/ti_sci/ti_sci.c
@@ -45,7 +45,6 @@
 		.host_id = TI_SCI_HOST_ID,
 		.max_msg_size = TI_SCI_MAX_MESSAGE_SIZE,
 	},
-	.seq = 0x0a,
 };
 
 /**
@@ -89,10 +88,8 @@
 	    tx_message_size < sizeof(*hdr))
 		return -ERANGE;
 
-	info.seq++;
-
 	hdr = (struct ti_sci_msg_hdr *)tx_buf;
-	hdr->seq = info.seq;
+	hdr->seq = ++info.seq;
 	hdr->type = msg_type;
 	hdr->host = info.desc.host_id;
 	hdr->flags = msg_flags | TI_SCI_FLAG_REQ_ACK_ON_PROCESSED;
@@ -119,21 +116,28 @@
 {
 	struct k3_sec_proxy_msg *msg = &xfer->rx_message;
 	struct ti_sci_msg_hdr *hdr;
+	unsigned int retry = 5;
 	int ret;
 
-	/* Receive the response */
-	ret = k3_sec_proxy_recv(chan, msg);
-	if (ret) {
-		ERROR("Message receive failed (%d)\n", ret);
-		return ret;
-	}
+	for (; retry > 0; retry--) {
+		/* Receive the response */
+		ret = k3_sec_proxy_recv(chan, msg);
+		if (ret) {
+			ERROR("Message receive failed (%d)\n", ret);
+			return ret;
+		}
 
-	/* msg is updated by Secure Proxy driver */
-	hdr = (struct ti_sci_msg_hdr *)msg->buf;
+		/* msg is updated by Secure Proxy driver */
+		hdr = (struct ti_sci_msg_hdr *)msg->buf;
 
-	/* Sanity check for message response */
-	if (hdr->seq != info.seq) {
-		ERROR("Message for %d is not expected\n", hdr->seq);
+		/* Sanity check for message response */
+		if (hdr->seq == info.seq)
+			break;
+		else
+			WARN("Message with sequence ID %u is not expected\n", hdr->seq);
+	}
+	if (!retry) {
+		ERROR("Timed out waiting for message\n");
 		return -EINVAL;
 	}
 
@@ -425,7 +429,7 @@
 		return -ERANGE;
 
 	hdr = (struct ti_sci_msg_hdr *)&req;
-	hdr->seq = info.seq;
+	hdr->seq = ++info.seq;
 	hdr->type = TI_SCI_MSG_SET_DEVICE_STATE;
 	hdr->host = info.desc.host_id;
 	/* Setup with NORESPONSE flag to keep response queue clean */
@@ -1408,7 +1412,7 @@
 		return -ERANGE;
 
 	hdr = (struct ti_sci_msg_hdr *)&req;
-	hdr->seq = info.seq;
+	hdr->seq = ++info.seq;
 	hdr->type = TISCI_MSG_SET_PROC_BOOT_CTRL;
 	hdr->host = info.desc.host_id;
 	/* Setup with NORESPONSE flag to keep response queue clean */
@@ -1650,7 +1654,7 @@
 		return -ERANGE;
 
 	hdr = (struct ti_sci_msg_hdr *)&req;
-	hdr->seq = info.seq;
+	hdr->seq = ++info.seq;
 	hdr->type = TISCI_MSG_WAIT_PROC_BOOT_STATUS;
 	hdr->host = info.desc.host_id;
 	/* Setup with NORESPONSE flag to keep response queue clean */
diff --git a/plat/ti/k3/common/k3_bl31_setup.c b/plat/ti/k3/common/k3_bl31_setup.c
index 78fb696..b4ec374 100644
--- a/plat/ti/k3/common/k3_bl31_setup.c
+++ b/plat/ti/k3/common/k3_bl31_setup.c
@@ -21,10 +21,9 @@
 
 /* Table of regions to map using the MMU */
 const mmap_region_t plat_k3_mmap[] = {
-	MAP_REGION_FLAT(SHARED_RAM_BASE, SHARED_RAM_SIZE, MT_DEVICE | MT_RW | MT_SECURE),
-	MAP_REGION_FLAT(K3_USART_BASE_ADDRESS, K3_USART_SIZE, MT_DEVICE | MT_RW | MT_SECURE),
-	MAP_REGION_FLAT(K3_GIC_BASE, K3_GIC_SIZE, MT_DEVICE | MT_RW | MT_SECURE),
-	MAP_REGION_FLAT(SEC_PROXY_RT_BASE, SEC_PROXY_RT_SIZE, MT_DEVICE | MT_RW | MT_SECURE),
+	MAP_REGION_FLAT(K3_USART_BASE,       K3_USART_SIZE,       MT_DEVICE | MT_RW | MT_SECURE),
+	MAP_REGION_FLAT(K3_GIC_BASE,         K3_GIC_SIZE,         MT_DEVICE | MT_RW | MT_SECURE),
+	MAP_REGION_FLAT(SEC_PROXY_RT_BASE,   SEC_PROXY_RT_SIZE,   MT_DEVICE | MT_RW | MT_SECURE),
 	MAP_REGION_FLAT(SEC_PROXY_SCFG_BASE, SEC_PROXY_SCFG_SIZE, MT_DEVICE | MT_RW | MT_SECURE),
 	MAP_REGION_FLAT(SEC_PROXY_DATA_BASE, SEC_PROXY_DATA_SIZE, MT_DEVICE | MT_RW | MT_SECURE),
 	{ /* sentinel */ }
@@ -100,13 +99,10 @@
 void bl31_plat_arch_setup(void)
 {
 	const mmap_region_t bl_regions[] = {
-		MAP_REGION_FLAT(BL31_BASE, BL31_END - BL31_BASE,
-				MT_MEMORY | MT_RW | MT_SECURE),
-		MAP_REGION_FLAT(BL_CODE_BASE, BL_CODE_END - BL_CODE_BASE,
-				MT_CODE | MT_SECURE),
-		MAP_REGION_FLAT(BL_RO_DATA_BASE, BL_RO_DATA_END - BL_RO_DATA_END,
-				MT_RO_DATA | MT_SECURE),
-		{0}
+		MAP_REGION_FLAT(BL31_START,      BL31_END       - BL31_START,     MT_MEMORY  | MT_RW | MT_SECURE),
+		MAP_REGION_FLAT(BL_CODE_BASE,    BL_CODE_END    - BL_CODE_BASE,   MT_CODE    | MT_RO | MT_SECURE),
+		MAP_REGION_FLAT(BL_RO_DATA_BASE, BL_RO_DATA_END - BL_RO_DATA_END, MT_RO_DATA | MT_RO | MT_SECURE),
+		{ /* sentinel */ }
 	};
 
 	setup_page_tables(bl_regions, plat_k3_mmap);
diff --git a/plat/ti/k3/common/k3_console.c b/plat/ti/k3/common/k3_console.c
index 31c9632..ba0ddac 100644
--- a/plat/ti/k3/common/k3_console.c
+++ b/plat/ti/k3/common/k3_console.c
@@ -16,6 +16,6 @@
 	static console_16550_t console;
 
 	/* Initialize the console to provide early debug support */
-	console_16550_register(K3_USART_BASE_ADDRESS, K3_USART_CLK_SPEED,
+	console_16550_register(K3_USART_BASE, K3_USART_CLK_SPEED,
 			       K3_USART_BAUD, &console);
 }
diff --git a/plat/ti/k3/common/plat_common.mk b/plat/ti/k3/common/plat_common.mk
index c91a035..29fcafd 100644
--- a/plat/ti/k3/common/plat_common.mk
+++ b/plat/ti/k3/common/plat_common.mk
@@ -22,6 +22,9 @@
 ERRATA_A53_843419	:=	1
 ERRATA_A53_855873	:=	1
 
+# Split out RO data into a non-executable section
+SEPARATE_CODE_AND_RODATA :=    1
+
 # Leave the caches enabled on core powerdown path
 TI_AM65X_WORKAROUND	:=	1
 $(eval $(call add_define,TI_AM65X_WORKAROUND))
diff --git a/plat/ti/k3/include/platform_def.h b/plat/ti/k3/include/platform_def.h
index f1511c1..68fdae7 100644
--- a/plat/ti/k3/include/platform_def.h
+++ b/plat/ti/k3/include/platform_def.h
@@ -74,20 +74,14 @@
 
 /*
  * ARM-TF lives in SRAM, partition it here
- */
-
-#define SHARED_RAM_BASE			BL31_LIMIT
-#define SHARED_RAM_SIZE			0x00001000
-
-/*
+ *
  * BL3-1 specific defines.
  *
- * Put BL3-1 at the base of the Trusted SRAM, before SHARED_RAM.
+ * Put BL3-1 at the base of the Trusted SRAM.
  */
 #define BL31_BASE			SEC_SRAM_BASE
-#define BL31_SIZE			(SEC_SRAM_SIZE - SHARED_RAM_SIZE)
+#define BL31_SIZE			SEC_SRAM_SIZE
 #define BL31_LIMIT			(BL31_BASE + BL31_SIZE)
-#define BL31_PROGBITS_LIMIT		BL31_LIMIT
 
 /*
  * Defines the maximum number of translation tables that are allocated by the
@@ -125,8 +119,8 @@
 #define CACHE_WRITEBACK_GRANULE		(1 << CACHE_WRITEBACK_SHIFT)
 
 /* Platform default console definitions */
-#ifndef K3_USART_BASE_ADDRESS
-#define K3_USART_BASE_ADDRESS 0x02800000
+#ifndef K3_USART_BASE
+#define K3_USART_BASE 0x02800000
 #endif
 
 /* USART has a default size for address space */
@@ -137,7 +131,7 @@
 #endif
 
 /* Crash console defaults */
-#define CRASH_CONSOLE_BASE K3_USART_BASE_ADDRESS
+#define CRASH_CONSOLE_BASE K3_USART_BASE
 #define CRASH_CONSOLE_CLK K3_USART_CLK_SPEED
 #define CRASH_CONSOLE_BAUD_RATE K3_USART_BAUD