zte's code,first commit
Change-Id: I9a04da59e459a9bc0d67f101f700d9d7dc8d681b
diff --git a/ap/os/linux/linux-3.4.x/mm/ramdump/Makefile b/ap/os/linux/linux-3.4.x/mm/ramdump/Makefile
new file mode 100755
index 0000000..eb6eab5
--- /dev/null
+++ b/ap/os/linux/linux-3.4.x/mm/ramdump/Makefile
@@ -0,0 +1,36 @@
+#
+# Makefile for the linux ramdump
+#
+ifeq ($(CONFIG_MMU),y)
+ccflags-y += -D__USE_MMU__
+endif
+
+ifeq ($(CONFIG_MPU),y)
+ccflags-y += -D__USE_MPU__
+endif
+
+ifeq ($(CONFIG_TRANS_WITH_COLLECT),y)
+ccflags-y += -D__USE_TRANS_WITH_COLLECT__
+endif
+
+ifeq ($(CONFIG_RAMDUMP_TRANS_SERVER),y)
+ccflags-y += -D__USE_RAMDUMP_TRANS_SERVER__
+endif
+
+ifeq ($(CONFIG_RAMDUMP_CLIENT),y)
+ccflags-y += -D__USE_RAMDUMP_CLIENT__
+endif
+
+ifeq ($(CONFIG_CLIENT_WITH_COLLECT),y)
+ccflags-y += -D__USE_CLIENT_WITH_COLLECT__
+endif
+
+ccflags-y += -D_OS_LINUX
+
+ccflags-y += -I$(srctree)/include/linux/ramdump
+obj-$(CONFIG_RAMDUMP_TRANS_SERVER) += ramdump_oss.o
+#obj-$(CONFIG_RAMDUMP) += ramdump_oss.o
+obj-$(CONFIG_TRANS_WITH_COLLECT) += ramdump_collect_server.o
+obj-$(CONFIG_RAMDUMP_TRANS_SERVER) += ramdump_trans_server.o
+obj-$(CONFIG_RAMDUMP_CLIENT) += ramdump_client.o
+obj-$(CONFIG_SYSTEM_CAP) += ramdump_client_cap.o
\ No newline at end of file
diff --git a/ap/os/linux/linux-3.4.x/mm/ramdump/ramdump_client_cap.c b/ap/os/linux/linux-3.4.x/mm/ramdump/ramdump_client_cap.c
new file mode 100755
index 0000000..f1c79b3
--- /dev/null
+++ b/ap/os/linux/linux-3.4.x/mm/ramdump/ramdump_client_cap.c
@@ -0,0 +1,330 @@
+/*******************************************************************************
+* °æÈ¨ËùÓÐ (C)2016, ÖÐÐËͨѶ¹É·ÝÓÐÏÞ¹«Ë¾¡£
+*
+* ÎļþÃû³Æ: ramdump_client_cap.c
+* Îļþ±êʶ: ramdump_client_cap.c
+* ÄÚÈÝÕªÒª: ramdump cap¿Í»§¶ËÒì³£ËÀ»úÏÖ³¡Êý¾Ýµ¼³öʵÏÖ
+*
+* ÐÞ¸ÄÈÕÆÚ °æ±¾ºÅ Ð޸ıê¼Ç ÐÞ¸ÄÈË ÐÞ¸ÄÄÚÈÝ
+* ------------------------------------------------------------------------------
+* 2019/10/10 V1.0 Create 00130574 ´´½¨
+*
+*******************************************************************************/
+
+/*******************************************************************************
+* Í·Îļþ *
+*******************************************************************************/
+#include "ramdump_pub.h"
+#include "ramdump_oss.h"
+#include <linux/module.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*******************************************************************************
+* ³£Á¿¶¨Òå *
+*******************************************************************************/
+
+/*******************************************************************************
+* ºê¶¨Òå *
+*******************************************************************************/
+
+/*******************************************************************************
+* Êý¾ÝÀàÐͶ¨Òå *
+*******************************************************************************/
+
+/*******************************************************************************
+* º¯ÊýÉùÃ÷ *
+*******************************************************************************/
+
+/*******************************************************************************
+* ¾Ö²¿¾²Ì¬±äÁ¿¶¨Òå *
+*******************************************************************************/
+static int ramdump_cap_init_flag;
+static int ramdump_count;
+
+#define RAMDUMP_ON_DEFAULT_VAL (1)
+#define ramdump_cap_cmm_buf (ZX_DDR_CAPBUF_BASE + ICP_CAP_BUF_LEN + TOOL_CAP_BUF_LEN)
+
+/*******************************************************************************
+* È«¾Ö±äÁ¿¶¨Òå *
+*******************************************************************************/
+/*
+ * run time control dump or not, use ( echo "0" > ramdump_on ) to close ramdump
+ */
+int sysctl_ramdump_on_panic = RAMDUMP_ON_DEFAULT_VAL;
+
+/*******************************************************************************
+* ¾Ö²¿º¯ÊýʵÏÖ *
+*******************************************************************************/
+/*******************************************************************************
+* ¹¦ÄÜÃèÊö: ramdump_cap_icp_handle
+* ²ÎÊý˵Ã÷:
+* (´«Èë²ÎÊý) buf: icp msg addr
+* len: icp msg len
+* (´«³ö²ÎÊý) void
+* ·µ »Ø Öµ: void
+* ÆäËü˵Ã÷: This function is used for ramdump client icp msg handle, common entry
+*******************************************************************************/
+static void ramdump_cap_icp_handle(void *buf, unsigned int len)
+{
+ ramdump_msg_t *icp_msg = (ramdump_msg_t *)buf;
+
+ switch(icp_msg->msg_id)
+ {
+ case RAMDUMP_MSG_EXCEPT:
+ {
+ OSS_PANIC("trans server received forced dump request from Ap server!\n");
+
+ break;
+ }
+
+ default:
+ {
+ OSS_PANIC("trans server received forced dump request from Ap server!\n");
+
+ break;
+ }
+ }
+}
+
+/*******************************************************************************
+* ¹¦ÄÜÃèÊö: ramdump_oss_icp_create_channel
+* ²ÎÊý˵Ã÷:
+* (´«Èë²ÎÊý) actorID: icp send core id
+ chID: icp channel id
+ size: icp channel size
+* (´«³ö²ÎÊý) void
+* ·µ »Ø Öµ: int: if msg send success
+* ÆäËü˵Ã÷:
+*******************************************************************************/
+static int ramdump_cap_icp_create_channel(
+ ramdump_oss_icp_actorid actorID,
+ ramdump_oss_icp_channelid chID,
+ unsigned int size)
+{
+ return zDrvRpMsg_CreateChannel(actorID, chID, size);
+}
+
+/*******************************************************************************
+* ¹¦ÄÜÃèÊö: ramdump_oss_icp_regcallback
+* ²ÎÊý˵Ã÷:
+* (´«Èë²ÎÊý) actorID: icp send core id
+ chID: icp channel id
+ callback:icp callback fun
+* (´«³ö²ÎÊý) void
+* ·µ »Ø Öµ: int: if msg send success
+* ÆäËü˵Ã÷:
+*******************************************************************************/
+static int ramdump_cap_icp_regcallback (
+ ramdump_oss_icp_actorid actorID,
+ unsigned int chID,
+ ramdump_oss_icp_callback callback)
+{
+ return zDrvRpMsg_RegCallBack(actorID,chID,callback);
+}
+
+/*******************************************************************************
+* ¹¦ÄÜÃèÊö: ramdump_cap_icp_init
+* ²ÎÊý˵Ã÷:
+* (´«Èë²ÎÊý) void
+* (´«³ö²ÎÊý) void
+* ·µ »Ø Öµ: void
+* ÆäËü˵Ã÷: This function is used for ramdump client icp init
+*******************************************************************************/
+static int ramdump_cap_icp_init(void)
+{
+ int ret = 0;
+
+ ret = ramdump_cap_icp_create_channel(
+ AP_ID,
+ RAMDUMP_CHANNEL,
+ RAMDUMP_CHANNEL_SIZE);
+
+ if (ret != RAMDUMP_SUCCESS)
+ return ret;
+ ret = ramdump_cap_icp_regcallback(
+ AP_ID,
+ RAMDUMP_CHANNEL,
+ ramdump_cap_icp_handle);
+
+ if (ret != RAMDUMP_SUCCESS)
+ return ret;
+
+ return RAMDUMP_SUCCESS;
+}
+
+/*******************************************************************************
+* ¹¦ÄÜÃèÊö: ramdump_notify_server_panic
+* ²ÎÊý˵Ã÷:
+* (´«Èë²ÎÊý) void
+* (´«³ö²ÎÊý) void
+* ·µ »Ø Öµ: void
+* ÆäËü˵Ã÷: This function is used for cap notify ramdump server to panic
+*******************************************************************************/
+static void ramdump_notify_server_panic()
+{
+ int Rlt = 0;
+
+ T_ZDrvRpMsg_Msg tMsg ={AP_ID, RAMDUMP_CHANNEL, 1, NULL, 0};
+
+ Rlt = zDrvRpMsg_WriteLockIrq(&tMsg);
+}
+
+/*******************************************************************************
+* ¹¦ÄÜÃèÊö: ramdump_cap_store_ram_conf
+* ²ÎÊý˵Ã÷:
+* (´«Èë²ÎÊý) mem: addr
+* (´«³ö²ÎÊý) void
+* ·µ »Ø Öµ: unsigend char*: changed addr
+* ÆäËü˵Ã÷: This function is used to store ram conf
+*******************************************************************************/
+static unsigned char *ramdump_cap_store_ram_conf(unsigned char *mem)
+{
+ unsigned long cap_cmm_phy = 0;
+
+ cap_cmm_phy = RAMDUMP_CAP_CMM_BUF_ADDR;
+
+ mem += sprintf(
+ mem,
+ "data.load.binary &ramdump_dir\\%s 0x%x--0x%x /noclear\n",
+ "cap_ddr",
+ (unsigned long)DDR_BASE_CAP_ADDR_PA,
+ (unsigned int)(DDR_BASE_CAP_ADDR_PA + DDR_BASE_LEN_CAP));
+ mem += sprintf(
+ mem,
+ "data.load.binary &ramdump_dir\\%s 0x%x--0x%x /noclear\n",
+ "cap.cmm",
+ cap_cmm_phy,
+ (unsigned int)(cap_cmm_phy + RAMDUMP_CAP_CMM_BUF_LEN));
+ return mem;
+}
+/*******************************************************************************
+* ¹¦ÄÜÃèÊö: ramdump_cap_cmm_create
+* ²ÎÊý˵Ã÷:
+* (´«Èë²ÎÊý) void
+* (´«³ö²ÎÊý) void
+* ·µ »Ø Öµ: void
+* ÆäËü˵Ã÷: This function is used for server to generate cmm scripts
+*******************************************************************************/
+static void ramdump_cap_cmm_create(void)
+{
+ unsigned char *pcmm_buf = ramdump_cap_cmm_buf;
+
+ // store the cmm BEGIN
+ pcmm_buf += sprintf(pcmm_buf, "ENTRY &ramdump_dir\n");
+
+ // store procmodes regs
+ pcmm_buf = ramdump_arch_store_modes_regs(pcmm_buf);
+
+ // store ram config
+ pcmm_buf = ramdump_cap_store_ram_conf(pcmm_buf);
+
+ // store memory map control regs
+ pcmm_buf = ramdump_arch_store_mm_regs(pcmm_buf);
+
+ // store end symbol
+ pcmm_buf += sprintf(pcmm_buf, "ENDDO\n");
+
+}
+/*******************************************************************************
+* È«¾Öº¯ÊýʵÏÖ *
+*******************************************************************************/
+/*******************************************************************************
+* ¹¦ÄÜÃèÊö: ramdump_ram_conf_table_add
+* ²ÎÊý˵Ã÷:
+* (´«Èë²ÎÊý) ram_name: dump ram name
+ ram_start: dump ram start(virtual addr)
+ ram_size: dump ram size
+ ram_virt: dump ram virt addr
+ ram_flag: dump ram flag(copy/exter/callback)
+ ram_extra: dump ram extra access addr
+* (´«³ö²ÎÊý) void
+* ·µ »Ø Öµ: void
+* ÆäËü˵Ã÷: This function is used to add dump ram conf into public table
+*******************************************************************************/
+void ramdump_ram_conf_table_add(
+ char *ram_name,
+ unsigned long ram_phy,
+ unsigned long ram_size,
+ unsigned long ram_virt,
+ unsigned long ram_flag,
+ unsigned long ram_extra)
+{
+ ;
+}
+
+/*******************************************************************************
+* ¹¦ÄÜÃèÊö: ramdump_init
+* ²ÎÊý˵Ã÷:
+* (´«Èë²ÎÊý) void
+* (´«³ö²ÎÊý) void
+* ·µ »Ø Öµ: RAMDUMP_SUCCESS or RAMDUMP_FAILED
+* ÆäËü˵Ã÷: This function is used for ramdump init
+*******************************************************************************/
+int ramdump_init(void)
+{
+ int ret = 0;
+
+ if (ramdump_cap_init_flag == RAMDUMP_TRUE)
+ return RAMDUMP_SUCCESS;
+
+ ret = ramdump_cap_icp_init();
+ if (ret != RAMDUMP_ICP_SUCCESS)
+ return ret;
+
+ OSS_PRINTF("Ramdump cap init success!\n");
+ ramdump_cap_init_flag = RAMDUMP_TRUE;
+
+ return RAMDUMP_SUCCESS;
+}
+module_init(ramdump_init);
+
+/*******************************************************************************
+* ¹¦ÄÜÃèÊö: ramdump_entry
+* ²ÎÊý˵Ã÷:
+* (´«Èë²ÎÊý) void
+* (´«³ö²ÎÊý) void
+* ·µ »Ø Öµ: void
+* ÆäËü˵Ã÷: This function is used for ramdump entry
+*******************************************************************************/
+void ramdump_entry (void)
+{
+ unsigned long flags;
+ if (sysctl_ramdump_on_panic == FALSE)
+ return;
+
+ /*
+ * we need lock the irq, this can`t be interrupt.
+ */
+ OSS_LOCK(flags);
+
+ if (!ramdump_cap_init_flag)
+ while(TRUE); /* endless circle */
+
+ if (++ramdump_count > 1)
+ while(TRUE); /* endless circle */
+
+ /*
+ * save all regs first.
+ */
+ ramdump_arch_save_all_regs();
+
+ //Éú³Écmm½Å±¾µÄµ¼³öÅäÖÃ
+ ramdump_cap_cmm_create();
+ /* notify client ramdump */
+ ramdump_notify_server_panic();
+ ramdump_arch_clean_caches();
+
+ while(TRUE);
+
+ OSS_UNLOCK(flags);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+
+MODULE_LICENSE("GPL");
diff --git a/ap/os/linux/linux-3.4.x/mm/ramdump/ramdump_oss.c b/ap/os/linux/linux-3.4.x/mm/ramdump/ramdump_oss.c
new file mode 100755
index 0000000..f59e646
--- /dev/null
+++ b/ap/os/linux/linux-3.4.x/mm/ramdump/ramdump_oss.c
@@ -0,0 +1,448 @@
+/*******************************************************************************
+* °æÈ¨ËùÓÐ (C)2016, ÖÐÐËͨѶ¹É·ÝÓÐÏÞ¹«Ë¾¡£
+*
+* ÎļþÃû³Æ: ramdump_oss.c
+* Îļþ±êʶ: ramdump_oss.c
+* ÄÚÈÝÕªÒª: ramdump²Ù×÷ϵͳÒÀÀµ½Ó¿Ú/Êý¾Ý½á¹¹¶¨ÒåÍ·Îļþ
+* ʹÓ÷½·¨: Èç¹û¸ü»»²Ù×÷ϵͳ£¬¸ÄÍ·ÎļþÄÚ½Ó¿Ú»òÕßÊý¾Ý¶¨ÒåÐèÒªÖØÐÂÊÊÅä
+*
+* ÐÞ¸ÄÈÕÆÚ °æ±¾ºÅ Ð޸ıê¼Ç ÐÞ¸ÄÈË ÐÞ¸ÄÄÚÈÝ
+* ------------------------------------------------------------------------------
+* 2016/6/10 V1.0 Create ÕÔ¾ü¿ü ´´½¨
+*
+*******************************************************************************/
+
+/*******************************************************************************
+* Í·Îļþ *
+*******************************************************************************/
+#include "ramdump_pub.h"
+#include "ramdump_oss.h"
+#include <linux/module.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*******************************************************************************
+* Íⲿº¯ÊýÉùÃ÷ *
+*******************************************************************************/
+
+/*******************************************************************************
+* ºê¶¨Òå *
+*******************************************************************************/
+
+/*******************************************************************************
+* Êý¾ÝÀàÐͶ¨Òå *
+*******************************************************************************/
+
+/*******************************************************************************
+* È«¾Ö±äÁ¿ÉùÃ÷ *
+*******************************************************************************/
+
+/*******************************************************************************
+* È«¾Öº¯ÊýÉùÃ÷ *
+*******************************************************************************/
+
+#ifdef _OS_LINUX
+/* icp api */
+extern int zDrvRpMsg_CreateChannel(
+ T_ZDrvRpMsg_ActorID actorID,
+ T_ZDrvRpMsg_ChID chID,
+ unsigned int size);
+extern int zDrvRpMsg_RegCallBack(
+ T_ZDrvRpMsg_ActorID actorID,
+ unsigned int chID,
+ T_ZDrvRpMsg_CallbackFunction callback);
+extern int zDrvRpMsg_WriteLockIrq(const T_ZDrvRpMsg_Msg *pMsg);
+extern void panic(const char *fmt, ...);
+
+extern int zDrvUsbPoll_Init(void);
+extern int zDrvUsbPoll_Isr(void);
+extern bool zDrvUsbPoll_isConnect(void);
+extern int zDrvUsbPoll_Read(unsigned char* pBuf,unsigned long length);
+extern int zDrvUsbPoll_Write(unsigned char* pBuf,unsigned long length);
+#if defined CONFIG_PRINTK
+extern void get_logbuf_info(unsigned long *addr, unsigned long *size);
+#endif
+#endif //#ifdef _OS_LINUX
+
+/*******************************************************************************
+* È«¾Öº¯ÊýʵÏÖ *
+*******************************************************************************/
+
+/*******************************************************************************
+* ¹¦ÄÜÃèÊö: ramdump_oss_create_thread
+* ²ÎÊý˵Ã÷:
+* (´«Èë²ÎÊý) void
+* (´«³ö²ÎÊý) void
+* ·µ »Ø Öµ: void
+* ÆäËü˵Ã÷:
+*******************************************************************************/
+void ramdump_oss_create_thread (
+ unsigned char *name,
+ ramdump_oss_thread_entry_t entry)
+{
+#ifdef _OS_TOS
+#define RAMDUMP_THREAD_STACK_DEF_SIZE 2048
+#define RAMDUMP_THREAD_DEF_PRIO 20
+#define RAMDUMP_THREAD_DEF_ARG 0
+#define RAMDUMP_THREAD_AUTORUN 1
+#define RAMDUMP_THREAD_PREEMPT 1
+
+ zOss_CreateThread(
+ name,entry,
+ RAMDUMP_THREAD_DEF_ARG,
+ RAMDUMP_THREAD_STACK_DEF_SIZE,
+ RAMDUMP_THREAD_DEF_PRIO,
+ RAMDUMP_THREAD_PREEMPT,
+ RAMDUMP_THREAD_AUTORUN);
+#endif
+}
+
+/*******************************************************************************
+* ¹¦ÄÜÃèÊö: ramdump_oss_mmap
+* ²ÎÊý˵Ã÷:
+* (´«Èë²ÎÊý) void
+* (´«³ö²ÎÊý) void
+* ·µ »Ø Öµ: void
+* ÆäËü˵Ã÷:
+*******************************************************************************/
+unsigned long ramdump_oss_mmap (unsigned long addr, unsigned long size)
+{
+#ifdef _OS_LINUX
+ return ioremap(addr,size);
+#elif defined (_OS_TOS)
+
+#ifdef __USE_MMU__
+ T_zTos_MmuRamdumpTable mmuTable = {0};
+ zTos_MmuGetMappingRegion(addr, size, &mmuTable);
+ /*
+ * TODO!
+ * current tos mmap one to one
+ * need new API like ioremap realize
+ */
+ return addr;
+#endif
+
+#endif
+}
+
+#ifdef _USE_CAP_SYS
+/*******************************************************************************
+* ¹¦ÄÜÃèÊö: ramdump_oss_icp_send_cap
+* ²ÎÊý˵Ã÷:
+* (´«Èë²ÎÊý) icp_msg: msg info
+ client_id: client id
+* (´«³ö²ÎÊý) void
+* ·µ »Ø Öµ: int: if msg send success
+* ÆäËü˵Ã÷: This function is used for server to send msg to client
+*******************************************************************************/
+int ramdump_oss_icp_send_cap(ramdump_oss_msg_t *icp_msg, unsigned int client_id)
+{
+ int ret;
+ ramdump_oss_icp_msg rpmsg = {0};
+
+ rpmsg.actorID = client_id;
+ rpmsg.chID = channel_10;
+ rpmsg.flag = 1;
+ rpmsg.buf = icp_msg;
+ rpmsg.len = sizeof(*icp_msg);
+
+ /*
+ * clean all the caches to make sure all data in ddr
+ */
+ ramdump_arch_clean_caches();
+
+ ret = zDrvRpMsg_Write_Cap(&rpmsg);
+
+ if (ret != rpmsg.len)
+ {
+ OSS_PRINTF(
+ "[ramdump] icpmsg send fail, ret != rpmsg.len[ret:%d], [client_id:%d]\n",
+ ret,
+ client_id);
+ return ret;
+ }
+
+ return RAMDUMP_ICP_SUCCESS;
+}
+#endif
+
+/*******************************************************************************
+* ¹¦ÄÜÃèÊö: ramdump_oss_icp_send
+* ²ÎÊý˵Ã÷:
+* (´«Èë²ÎÊý) icp_msg: msg info
+ client_id: client id
+* (´«³ö²ÎÊý) void
+* ·µ »Ø Öµ: int: if msg send success
+* ÆäËü˵Ã÷: This function is used for server to send msg to client
+*******************************************************************************/
+int ramdump_oss_icp_send(ramdump_oss_msg_t *icp_msg, unsigned int client_id)
+{
+ int ret;
+ ramdump_oss_icp_msg rpmsg = {0};
+
+ rpmsg.actorID = client_id;
+ rpmsg.chID = channel_40;
+ rpmsg.flag = 1;
+ rpmsg.buf = icp_msg;
+ rpmsg.len = sizeof(*icp_msg);
+
+ /*
+ * clean all the caches to make sure all data in ddr
+ */
+ ramdump_arch_clean_caches();
+
+ ret = ramdump_oss_icp_write(&rpmsg);
+
+ if (ret != rpmsg.len)
+ {
+#ifdef _OS_LINUX
+ OSS_PRINTF(
+ "[ramdump] icpmsg send fail, ret != rpmsg.len[ret:%d], [client_id:%d]\n",
+ ret,
+ client_id);
+#elif defined (_OS_TOS)
+ OSS_PRINTF(
+ SUBMDL_TEST,
+ PRINT_LEVEL_NORMAL,
+ "[ramdump] icpmsg send fail, ret != rpmsg.len[ret:%d], [client_id:%d]\n",
+ ret,
+ client_id);
+#endif
+ return ret;
+ }
+
+ return RAMDUMP_ICP_SUCCESS;
+}
+
+/*******************************************************************************
+* ¹¦ÄÜÃèÊö: ramdump_oss_error_log_creat
+* ²ÎÊý˵Ã÷:
+* (´«Èë²ÎÊý) buf : addr point
+* (´«³ö²ÎÊý) void
+* ·µ »Ø Öµ: void
+* ÆäËü˵Ã÷:
+*******************************************************************************/
+void ramdump_oss_error_log_creat(char *buf)
+{
+#ifdef _OS_LINUX
+ if (current->mm != NULL)
+ sprintf(
+ buf,
+ " dump at user, app name is: %s, load addr is: %lu \n",
+ current->comm,
+ current->mm->start_code);
+ else
+ sprintf(
+ buf,
+ " dump at kernel, app name is: %s \n",
+ current->comm);
+#endif
+
+}
+
+/*******************************************************************************
+* ¹¦ÄÜÃèÊö: ramdump_oss_icp_create_channel
+* ²ÎÊý˵Ã÷:
+* (´«Èë²ÎÊý) actorID: icp send core id
+ chID: icp channel id
+ size: icp channel size
+* (´«³ö²ÎÊý) void
+* ·µ »Ø Öµ: int: if msg send success
+* ÆäËü˵Ã÷:
+*******************************************************************************/
+int ramdump_oss_icp_create_channel(
+ ramdump_oss_icp_actorid actorID,
+ ramdump_oss_icp_channelid chID,
+ unsigned int size)
+{
+#ifdef _OS_LINUX
+ return CPPS_FUNC(cpps_callbacks, zDrvRpMsg_CreateChannel)(actorID, chID, size);
+#elif defined (_OS_TOS)
+ if (actorID == ramdump_cpu_id[RAMDUMP_CPU_2])
+ return 0;
+ else
+ return zDrvRpMsg_CreateChannel(actorID, chID, size);
+#endif
+}
+
+/*******************************************************************************
+* ¹¦ÄÜÃèÊö: ramdump_oss_icp_regcallback
+* ²ÎÊý˵Ã÷:
+* (´«Èë²ÎÊý) actorID: icp send core id
+ chID: icp channel id
+ callback:icp callback fun
+* (´«³ö²ÎÊý) void
+* ·µ »Ø Öµ: int: if msg send success
+* ÆäËü˵Ã÷:
+*******************************************************************************/
+int ramdump_oss_icp_regcallback (
+ ramdump_oss_icp_actorid actorID,
+ unsigned int chID,
+ ramdump_oss_icp_callback callback)
+{
+#ifdef _OS_LINUX
+ return CPPS_FUNC(cpps_callbacks, zDrvRpMsg_RegCallBack)(actorID,chID,callback);
+#elif defined (_OS_TOS)
+ if (actorID == ramdump_cpu_id[RAMDUMP_CPU_2])
+ return zDrvIcp_RegCallback(
+ ICP_ARM0_MODULE_ID_OS,
+ actorID,
+ callback,
+ ICP_ISR_CALLBACK);
+ else
+ return zDrvRpMsg_RegCallBack(actorID,chID,callback);
+#endif
+}
+
+/*******************************************************************************
+* ¹¦ÄÜÃèÊö: ramdump_oss_icp_write
+* ²ÎÊý˵Ã÷:
+* (´«Èë²ÎÊý) pMsg: icp send msg
+* (´«³ö²ÎÊý) void
+* ·µ »Ø Öµ: int: if msg send success
+* ÆäËü˵Ã÷:
+*******************************************************************************/
+int ramdump_oss_icp_write(const ramdump_oss_icp_msg *pMsg)
+{
+#ifdef _OS_LINUX
+ return CPPS_FUNC(cpps_callbacks, zDrvRpMsg_Write)(pMsg);
+#elif defined (_OS_TOS)
+ if ((ramdump_msg_t *)pMsg->actorID == ramdump_cpu_id[RAMDUMP_CPU_2])
+ {
+ switch (((ramdump_msg_t *)(pMsg->buf))->msg_id)
+ {
+ case RAMDUMP_MSG_EXCEPT:
+ {
+ T_HalIcp_Msg icpMsg = { 0 };
+ icpMsg.SrcModId = ICP_ARM0_MODULE_ID_OS;
+ icpMsg.desModId = ICP_ARM1_MODULE_ID_OS;
+ icpMsg.IntInfo.high_word = ZPLAT_PS2PHY_RAMDUMP_INT_ICP_CF;
+ zDrvIcp_SendMsg((const T_HalIcp_Msg *)&icpMsg);
+ }
+ case RAMDUMP_MSG_SYNC:
+ default:
+ return pMsg->len;
+ }
+ }
+ else
+ return zDrvRpMsg_WriteLockIrq(pMsg);
+#endif
+}
+
+/*******************************************************************************
+* ¹¦ÄÜÃèÊö: ramdump_oss_data_trans_init
+* ²ÎÊý˵Ã÷:
+* (´«Èë²ÎÊý) void
+* (´«³ö²ÎÊý) void
+* ·µ »Ø Öµ: void
+* ÆäËü˵Ã÷:
+*******************************************************************************/
+void ramdump_oss_data_trans_init(void)
+{
+#ifdef _OS_LINUX
+ zDrvUsbPoll_Init(); /* ³õʼ»¯USB */
+ while (!zDrvUsbPoll_isConnect()) ; /* ²éѯUSBÊÇ·ñÁ¬½Ó */
+#endif
+}
+
+/*******************************************************************************
+* ¹¦ÄÜÃèÊö: ramdump_oss_data_trans_read
+* ²ÎÊý˵Ã÷:
+* (´«Èë²ÎÊý) buffer: data buff
+ size: data size
+* (´«³ö²ÎÊý) void
+* ·µ »Ø Öµ: void
+* ÆäËü˵Ã÷:
+*******************************************************************************/
+void ramdump_oss_data_trans_read(unsigned char *buffer, unsigned int size)
+{
+#ifdef _OS_LINUX
+ unsigned int count = 0;
+
+ do
+ {
+ zDrvUsbPoll_Isr();
+ count = (unsigned int)zDrvUsbPoll_Read(buffer, size);
+ if ( size <= count)
+ {
+ break;
+ }
+ buffer += count;
+ size -=count;
+ }
+ while (size > 0);
+#endif
+}
+
+/*******************************************************************************
+* ¹¦ÄÜÃèÊö: ramdump_oss_data_trans_write
+* ²ÎÊý˵Ã÷:
+* (´«Èë²ÎÊý) buffer: data buff
+ size: data size
+* (´«³ö²ÎÊý) void
+* ·µ »Ø Öµ: void
+* ÆäËü˵Ã÷:
+*******************************************************************************/
+void ramdump_oss_data_trans_write(unsigned char *buffer, unsigned int size)
+{
+#ifdef _OS_LINUX
+ unsigned int count = 0;
+
+ while (size > 0)
+ {
+ zDrvUsbPoll_Isr();
+ count = (unsigned int)zDrvUsbPoll_Write(buffer, size);
+ if ( size <= count)
+ {
+ break;
+ }
+
+ buffer += count;
+ size -=count;
+ }
+#endif
+}
+
+/*******************************************************************************
+* ¹¦ÄÜÃèÊö: ramdump_oss_data_trans_done
+* ²ÎÊý˵Ã÷:
+* (´«Èë²ÎÊý) void
+* (´«³ö²ÎÊý) void
+* ·µ »Ø Öµ: void
+* ÆäËü˵Ã÷:
+*******************************************************************************/
+void ramdump_oss_data_trans_done(void)
+{
+#ifdef _OS_LINUX
+ /* µÈ´ýÊý¾Ý·¢ËÍÍêºó£¬ÔÙÖØÆô */
+ zDrvUsbPoll_Isr();
+#endif
+}
+
+void ramdump_oss_logbuf_create(void)
+{
+#ifdef _OS_LINUX
+#if defined CONFIG_PRINTK
+
+ unsigned long addr;
+ unsigned long size;
+
+ get_logbuf_info(&addr, &size);
+
+ ramdump_ram_conf_table_add(
+ "ap_log_buf",
+ (unsigned long)OSS_VIRT_TO_PHY(addr),
+ size,
+ addr,
+ RAMDUMP_FLAG_NONE,
+ 0);
+#endif
+#endif
+}
+
+#ifdef __cplusplus
+}
+#endif
+
diff --git a/ap/os/linux/linux-3.4.x/mm/ramdump/ramdump_trans_server.c b/ap/os/linux/linux-3.4.x/mm/ramdump/ramdump_trans_server.c
new file mode 100755
index 0000000..da1a791
--- /dev/null
+++ b/ap/os/linux/linux-3.4.x/mm/ramdump/ramdump_trans_server.c
@@ -0,0 +1,1217 @@
+/*******************************************************************************
+* °æÈ¨ËùÓÐ (C)2016, ÖÐÐËͨѶ¹É·ÝÓÐÏÞ¹«Ë¾¡£
+*
+* ÎļþÃû³Æ: ramdump_server_trans.c
+* Îļþ±êʶ: ramdump_server_trans.c
+* ÄÚÈÝÕªÒª: ramdump·þÎñ¶ËÒì³£ËÀ»úÏÖ³¡Êý¾Ýµ¼³öʵÏÖ
+*
+* ÐÞ¸ÄÈÕÆÚ °æ±¾ºÅ Ð޸ıê¼Ç ÐÞ¸ÄÈË ÐÞ¸ÄÄÚÈÝ
+* ------------------------------------------------------------------------------
+* 2016/3/10 V1.0 Create ÕÔ¾ü¿ü ´´½¨
+*
+*******************************************************************************/
+
+/*******************************************************************************
+* Í·Îļþ *
+*******************************************************************************/
+#include "ramdump_pub.h"
+#include "ramdump_oss.h"
+#include <linux/module.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*******************************************************************************
+* ³£Á¿¶¨Òå *
+*******************************************************************************/
+#define __USE_TRANS_WITH_COLLECT__ 1
+
+/*******************************************************************************
+* ºê¶¨Òå *
+*******************************************************************************/
+#define RAMDUMP_ON_DEFAULT_VAL (1)
+
+#define RAMDUMP_MMAP_SUCCESS (RAMDUMP_SUCCESS)
+#define RAMDUMP_MMAP_FAILED (RAMDUMP_FAILED)
+
+#define RP_MSG_PS_PHY_RAMDUMP_CHANNEL channel_40 //arm¡¢zspÖ®¼äµÄramdumpͨµÀ
+#define RP_MSG_PS_PHY_RAMDUMP_SIZE 0x40 //arm¡¢zspÖ®¼äµÄramdumpͨµÀ
+
+#ifdef _USE_CAP_SYS
+#define RAMDUMP_ICP_MSG_CAP_SIZE 0x40
+#endif
+
+/* ramdump ºÍ PCÇý¶¯´úÀí½»»¥ÃüÁîÔ¼¶¨ */
+/*ͬ²½ÇëÇó*/
+#define RAMDUMP_PC_INTERACTIVE_REQ 1
+/*ͬ²½ÇëÇóÓ¦´ð,´«ÊäramdumpµÄÎļþÊýÄ¿*/
+#define RAMDUMP_TRANS_SERVER_INTERACTIVE_RSP 2
+/*ÇëÇó´«µÝÖ¸¶¨Îļþ±àºÅµÄÎļþÐÅÏ¢*/
+#define RAMDUMP_PC_FILE_INFO_READ_REQ 3
+/*ÇëÇó´«µÝÖ¸¶¨Îļþ±àºÅµÄÎļþÐÅÏ¢µÄÓ¦´ð£¬´«ÊäÎļþÃû¼°´óС*/
+#define RAMDUMP_TRANS_SERVER_FILE_INFO_READ_RSP 4
+/*ÇëÇó¶Áȡָ¶¨Îļþ±àºÅµÄÎļþÄÚÈÝ*/
+#define RAMDUMP_PC_FILE_DATA_TRANS_REQ 5
+/*ÇëÇó¶Áȡָ¶¨Îļþ±àºÅµÄÎļþÄÚÈݵÄÓ¦´ð£¬´«ÊäÎļþÄÚÈÝ*/
+#define RAMDUMP_TRANS_SERVER_FILE_DATA_TRANS_RSP 6
+/*´«Êä½áÊø*/
+#define RAMDUMP_PC_FILE_TRANS_DONE_REQ 7
+/*´«Êä½áÊøÓ¦´ð*/
+#define RAMDUMP_TRANS_SERVER_FILE_TRANS_DONE_RSP 8
+
+/* ´íÎóÀàÐÍ */
+/*Ö¸Áî´íÎó*/
+#define RAMDUMP_INTERACTIVE_CMD_ERROR 9
+/*ÇëÇó´«µÝÖ¸¶¨Îļþ±àºÅ´í*/
+#define RAMDUMP_FILE_NUMBER_ERROR 10
+/*ÇëÇó´«µÝÖ¸¶¨ÎļþλÖôóС´í*/
+#define RAMDUMP_FILE_SIZE_ERROR 11
+/*Ö¸ÁîÖ¡³¤¶È */
+#define RAMDUMP_INTERACTIVE_DATA_LEN 16
+
+#define RAMDUMP_TRANS_SERVER_DDR_BINNAME "trans_server_ddr.bin"
+#define RAMDUMP_TRANS_SERVER_CMM_SCRNAME "trans_server_cmm.cmm"
+#define RAMDUMP_TRANS_SERVER_ERR_LOG "trans_server_error_log.txt"
+#define RAMDUMP_TRANS_SERVER_DEF_BINNAME "trans_server_"
+
+/*******************************************************************************
+* Êý¾ÝÀàÐͶ¨Òå *
+*******************************************************************************/
+
+/*
+ * struct TRANS WITH PC
+ */
+
+/* trans_server rsp pc, interactive msg struct */
+typedef struct
+{
+ unsigned long cmd;
+ unsigned long file_num;
+} ramdump_trans_server_interactive_rsp;
+
+/* trans_server rsp pc, file info msg struct */
+typedef struct
+{
+ unsigned long cmd;
+ char file_name[RAMDUMP_RAMCONF_FILENAME_MAXLEN];
+ unsigned long file_size;
+} ramdump_trans_server_file_info_rsp;
+
+/* pc req trans_server, file info msg struct */
+typedef struct
+{
+ unsigned long cmd;
+ unsigned long file_id;
+} ramdump_pc_file_info_req;
+
+/* trans_server rsp pc, trans data msg struct */
+typedef struct
+{
+ unsigned long cmd;
+ unsigned long buf_addr;
+ unsigned long buf_left_size;
+} ramdump_trans_server_data_trans_rsp;
+
+/* pc req trans_server, trans data msg struct */
+typedef struct
+{
+ unsigned long cmd;
+ unsigned long file_id; /* Îļþ±àºÅ */
+ unsigned long offset; /* offsetΪÊý¾ÝÆ«ÒÆ */
+ unsigned long length; /* lengthΪÊý¾Ý³¤¶È */
+} ramdump_pc_trans_data_req;
+
+
+/*******************************************************************************
+* º¯ÊýÉùÃ÷ *
+*******************************************************************************/
+#ifndef CONFIG_SYSTEM_RECOVERY
+extern unsigned int zOss_GetExceptResetFlag(void);
+extern int zSys_ExceptReboot(unsigned int except_cpu);
+#else
+extern void emergency_restart(void);
+#endif
+
+extern void zx_wdt_m0_stop(void);
+extern struct meminfo meminfo;
+
+/*******************************************************************************
+* ¾Ö²¿¾²Ì¬±äÁ¿¶¨Òå *
+*******************************************************************************/
+static int ramdump_server_init_flag;
+static int ramdump_count;
+static int ramdump_file_num;
+
+static DEFINE_MUTEX(ramdump_mutex);
+
+/* Cmm file content */
+static unsigned char ramdump_server_cmm_buf[RAMDUMP_CMM_SIZE];
+/* err log file */
+static char ramdump_server_error_log[RAMDUMP_ERROR_LOG_SIZE];
+
+/* trans server ram conf table */
+static ramdump_ram_config_t ramdump_trans_server_ram_conf[RAMDUMP_RAMCONF_TABLE_MAX_ENTRYS];
+static unsigned int ddr_ap_size;
+
+#ifndef __USE_TRANS_WITH_COLLECT__
+/* trans server ram conf data done flag*/
+static unsigned long ramdump_trans_server_data_done_flag = RAMDUMP_SYNC_RESET;
+/* collect server ram conf addr */
+static ramdump_ram_config_sync_msg_t ramdump_collect_server_ram_conf;
+
+static ramdump_ram_config_msg_t ramdump_ap_config;
+static int ramdump_ap_file_num;
+
+#endif
+
+/*******************************************************************************
+* È«¾Ö±äÁ¿¶¨Òå *
+*******************************************************************************/
+/*
+ * run time control dump or not, use ( echo "0" > ramdump_on ) to close ramdump
+ */
+int sysctl_ramdump_on_panic = RAMDUMP_ON_DEFAULT_VAL;
+
+/* diff server crash or client crash */
+int ramdump_trans_server_force_panic_flag = RAMDUMP_FALSE;
+
+/*******************************************************************************
+* ¾Ö²¿º¯ÊýʵÏÖ *
+*******************************************************************************/
+
+/*******************************************************************************
+* ¹¦ÄÜÃèÊö: ramdump_trans_server_dynamic_ram_conf_collect
+* ²ÎÊý˵Ã÷:
+* (´«Èë²ÎÊý) void
+* (´«³ö²ÎÊý) void
+* ·µ »Ø Öµ: void
+* ÆäËü˵Ã÷: This function is used to collect server ram conf before client mmap
+*******************************************************************************/
+static unsigned long ramdump_phy_to_vir(ramdump_ram_config_t * ram_config)
+{
+ unsigned long pfn = 0;
+ unsigned long vir_addr = 0;
+
+ if(ram_config->vir != 0)
+ return ram_config->vir;
+
+ pfn = OSS_PHY_TO_PFN((unsigned long)(ram_config->phy));
+ if (OSS_PFN_VALID(pfn))
+ vir_addr = OSS_PHY_TO_VIRT((unsigned long)ram_config->phy);
+ else
+ if (ram_config->copy != 0 &&
+ ram_config->copy != ram_config->phy)
+ {
+ vir_addr =(unsigned long)ram_config->copy;
+ }
+ else if (ram_config->exter != 0 && ram_config->exter != ram_config->phy)
+ {
+ vir_addr = (unsigned long)ram_config->exter;
+ }
+ else
+ vir_addr = (unsigned long)OSS_MMAP(ram_config->phy, ram_config->size);
+
+ return vir_addr;
+}
+
+#ifndef __USE_TRANS_WITH_COLLECT__
+/*******************************************************************************
+* ¹¦ÄÜÃèÊö: ramdump_trans_server_ram_conf_table_mmap
+* ²ÎÊý˵Ã÷:
+* (´«Èë²ÎÊý) array: ram conf table addr
+* nr: ram conf table size
+* (´«³ö²ÎÊý) void
+* ·µ »Ø Öµ: void
+* ÆäËü˵Ã÷: This function is used for ramdump trans to mmap addr table space
+*******************************************************************************/
+static void ramdump_trans_server_ram_conf_table_mmap(
+ void *array,
+ unsigned int nr)
+{
+ unsigned long cpu_id = 0;
+ unsigned long vir_addr = 0;
+ unsigned long pfn = 0;
+ while (cpu_id < nr)
+ {
+ vir_addr = 0;
+ pfn = 0;
+ ramdump_ram_config_msg_t *array_entry =
+ (ramdump_ram_config_msg_t *)(&(ramdump_collect_server_ram_conf.array[cpu_id]));
+ if (((((ramdump_ram_config_msg_t *)array)[cpu_id]).array) == NULL ||
+ ((((ramdump_ram_config_msg_t *)array)[cpu_id]).nr) == 0)
+ {
+ cpu_id++;
+ continue;
+ }
+
+ pfn = OSS_PHY_TO_PFN((unsigned long)((((ramdump_ram_config_msg_t *)array)[cpu_id]).array));
+ if (OSS_PFN_VALID(pfn))
+ vir_addr = OSS_PHY_TO_VIRT((unsigned long)((((ramdump_ram_config_msg_t *)array)[cpu_id]).array));
+ else
+ vir_addr = (unsigned long)OSS_MMAP(
+ (unsigned long)((((ramdump_ram_config_msg_t *)array)[cpu_id]).array),
+ ((((ramdump_ram_config_msg_t *)array)[cpu_id].nr) * sizeof(ramdump_ram_config_t)));
+ if (vir_addr == 0)
+ {
+ OSS_PRINTF("[ramdump] trans server mmap collect server ram conf table entry failed!\n");
+ cpu_id++;
+ continue;
+ }
+ else
+ {
+ array_entry->array = (ramdump_ram_config_t *)vir_addr;
+ array_entry->nr = (((ramdump_ram_config_msg_t *)array)[cpu_id].nr);
+ }
+
+ /* mmap collect ram conf table space sync done flag */
+ vir_addr = 0;
+ pfn = OSS_PHY_TO_PFN((unsigned long)((((ramdump_ram_config_msg_t *)array)[cpu_id]).done_flag));
+ if (OSS_PFN_VALID(pfn))
+ vir_addr = OSS_PHY_TO_VIRT((unsigned long)((((ramdump_ram_config_msg_t *)array)[cpu_id]).done_flag));
+ else
+ vir_addr = (unsigned long)OSS_MMAP(
+ (unsigned long)((((ramdump_ram_config_msg_t *)array)[cpu_id]).done_flag),
+ sizeof(*((((ramdump_ram_config_msg_t *)array)[cpu_id]).done_flag)));
+ if (vir_addr == 0)
+ {
+ OSS_PRINTF("[ramdump] trans server mmap collect server table entry done flag failed!\n");
+ cpu_id++;
+ continue;
+ }
+ else
+ {
+ array_entry->done_flag = vir_addr;
+ }
+ cpu_id++;
+ }
+
+}
+
+/*******************************************************************************
+* ¹¦ÄÜÃèÊö: ramdump_dump_ram_conf_mmap_init
+* ²ÎÊý˵Ã÷:
+* (´«Èë²ÎÊý) void
+* (´«³ö²ÎÊý) void
+* ·µ »Ø Öµ: void
+* ÆäËü˵Ã÷: This function is used for ramdump client mmap init
+*******************************************************************************/
+static void ramdump_dump_ram_conf_mmap_init(void)
+{
+ unsigned long vir_addr = 0;
+ int cpu_id = 0;
+
+ /* iterate all cpu */
+ while (cpu_id < ramdump_collect_server_ram_conf.nr)
+ {
+ int tb_index = 0;
+ unsigned long pfn = 0;
+ ramdump_ram_config_msg_t *array_entry =
+ (ramdump_ram_config_msg_t *)(&(ramdump_collect_server_ram_conf.array[cpu_id]));
+ if (array_entry->array == NULL || array_entry->nr == 0 || array_entry->done_flag == NULL)
+ {
+ OSS_PRINTF("Ramdump maybe happens before collect server init done, please check!\n");
+ cpu_id++;
+ continue;
+ }
+
+ /* wait collect data done */
+ while (*(array_entry->done_flag) == RAMDUMP_SYNC_RESET)
+ ramdump_wait_done_delay(
+ RAMDUMP_WAIT_TIMELEN,
+ (volatile unsigned long *)array_entry->done_flag,
+ RAMDUMP_SYNC_RAM_CONFIG_DONE);
+
+ /* iterate all ram conf table entry */
+ while (tb_index < array_entry->nr)
+ {
+ if (array_entry->array[tb_index].phy == 0 ||
+ array_entry->array[tb_index].size == 0)
+ {
+ tb_index++;
+ continue;
+ }
+
+ vir_addr = ramdump_phy_to_vir(&array_entry->array[tb_index]);
+ if (vir_addr == 0)
+ OSS_PRINTF("Ramdump init failed, client mem mmap init wrong!\n");
+ else
+ array_entry->array[tb_index].vir = vir_addr;
+ tb_index++;
+ }
+ cpu_id++;
+ }
+
+}
+
+/*******************************************************************************
+* ¹¦ÄÜÃèÊö: ramdump_dump_file_num_recalc
+* ²ÎÊý˵Ã÷:
+* (´«Èë²ÎÊý) void
+* (´«³ö²ÎÊý) void
+* ·µ »Ø Öµ: void
+* ÆäËü˵Ã÷: This function is used to create err log file
+*******************************************************************************/
+static void ramdump_dump_file_num_recalc(void)
+{
+ unsigned long cpu_id = 0;
+ if (ramdump_collect_server_ram_conf.nr == 0 ||
+ ramdump_collect_server_ram_conf.array == NULL)
+ while(TRUE); /* except happends before sync with other core done */
+
+ while (cpu_id < ramdump_collect_server_ram_conf.nr)
+ {
+ unsigned long arr_num = 0;
+ unsigned long file_num = 0;
+ while(arr_num < ramdump_collect_server_ram_conf.array[cpu_id].nr)
+ {
+ /* ram conf have contents,need to dump */
+ if (ramdump_collect_server_ram_conf.array[cpu_id].array[arr_num].vir != 0 &&
+ ramdump_collect_server_ram_conf.array[cpu_id].array[arr_num].size != 0)
+ file_num++;
+ arr_num++;
+ }
+ ramdump_collect_server_ram_conf.array[cpu_id].nr = file_num;
+ cpu_id++;
+ }
+}
+
+/*******************************************************************************
+* ¹¦ÄÜÃèÊö: ramdump_find_collect_ram_conf_entry_id
+* ²ÎÊý˵Ã÷:
+* (´«Èë²ÎÊý) file_id: file number
+* (´«³ö²ÎÊý) cpu_id : cpu index
+* ·µ »Ø Öµ: unsigned long: file id
+* ÆäËü˵Ã÷: This function is used for ramdump to
+*******************************************************************************/
+static unsigned long ramdump_find_collect_ram_conf_entry_id(
+ unsigned long file_id,
+ unsigned long* cpu_id)
+{
+ unsigned long cpu_index = 0;
+ while (cpu_index < RAMDUMP_CPU_MAX)
+ {
+ if (file_id >= ramdump_collect_server_ram_conf.array[cpu_index].nr)
+ file_id -= ramdump_collect_server_ram_conf.array[cpu_index].nr;
+ else
+ break;
+ cpu_index++;
+ }
+
+ *cpu_id = cpu_index;
+ return file_id;
+}
+
+/*******************************************************************************
+* ¹¦ÄÜÃèÊö: ramdump_wait_clients_dump_done
+* ²ÎÊý˵Ã÷:
+* (´«Èë²ÎÊý) void
+* (´«³ö²ÎÊý) void
+* ·µ »Ø Öµ: void
+* ÆäËü˵Ã÷: This function is used for ramdump client dump done charge
+*******************************************************************************/
+static void ramdump_wait_clients_dump_done(void)
+{
+ unsigned long cpu_id = 0;
+ while (cpu_id < RAMDUMP_CPU_MAX)
+ {
+ if (ramdump_collect_server_ram_conf.array[cpu_id].array == NULL ||
+ ramdump_collect_server_ram_conf.array[cpu_id].nr == NULL ||
+ ramdump_collect_server_ram_conf.array[cpu_id].done_flag == NULL)
+ break;
+ while (*(ramdump_collect_server_ram_conf.array[cpu_id].done_flag) == RAMDUMP_SYNC_RESET)
+ ramdump_wait_done_delay(
+ RAMDUMP_WAIT_TIMELEN,
+ (volatile unsigned long *)(ramdump_collect_server_ram_conf.array[cpu_id].done_flag),
+ RAMDUMP_SYNC_RAM_CONTENT_DONE);
+ cpu_id++;
+ }
+}
+#endif //#ifndef __USE_TRANS_WITH_COLLECT__
+
+/*******************************************************************************
+* ¹¦ÄÜÃèÊö: ramdump_do_panic
+* ²ÎÊý˵Ã÷:
+* (´«Èë²ÎÊý) void
+* (´«³ö²ÎÊý) void
+* ·µ »Ø Öµ: void
+* ÆäËü˵Ã÷: This function is used for ramdump client icp msg handle, do panic
+*******************************************************************************/
+static void ramdump_do_panic(void)
+{
+ if (ramdump_trans_server_force_panic_flag == RAMDUMP_CLIENT_ZSP)
+ OSS_PANIC("trans server received forced dump request from zsp client!\n");
+ else if (ramdump_trans_server_force_panic_flag == RAMDUMP_CLIENT_CAP)
+ OSS_PANIC("trans server received forced dump request from cap client!\n");
+ else
+ OSS_PANIC("AP server recv error icp msg\n");
+}
+
+/*******************************************************************************
+* ¹¦ÄÜÃèÊö: ramdump_clients_icp_handle
+* ²ÎÊý˵Ã÷:
+* (´«Èë²ÎÊý) buf: icp msg addr
+* len: icp msg len
+* (´«³ö²ÎÊý) void
+* ·µ »Ø Öµ: void
+* ÆäËü˵Ã÷: This function is used for ramdump client icp msg handle, common entry
+*******************************************************************************/
+static void ramdump_clients_icp_handle(void *buf, unsigned int len)
+{
+ unsigned long vir_addr = 0;
+ ramdump_msg_t *icp_msg = (ramdump_msg_t *)buf;
+ switch(icp_msg->msg_id)
+ {
+#ifndef __USE_TRANS_WITH_COLLECT__
+ case RAMDUMP_MSG_INIT_REQ:
+ {
+ /* trans ram conf send to collect server */
+ ramdump_msg_t icp_msg_to_server = {0};
+ icp_msg_to_server.msg_id = RAMDUMP_MSG_INIT_RSP;
+ icp_msg_to_server.cpu_id = ramdump_cpu_id[RAMDUMP_CPU_1];
+ icp_msg_to_server.msg_data_t.ram_config.array =
+ OSS_VIRT_TO_PHY(ramdump_trans_server_ram_conf);
+ icp_msg_to_server.msg_data_t.ram_config.nr =
+ RAMDUMP_ARRAY_NR(ramdump_trans_server_ram_conf);
+ icp_msg_to_server.msg_data_t.ram_config.done_flag =
+ OSS_VIRT_TO_PHY((unsigned long*)&ramdump_trans_server_data_done_flag);
+
+ ramdump_oss_icp_send(&icp_msg_to_server, ramdump_cpu_id[RAMDUMP_CPU_0]);
+ break;
+ }
+ case RAMDUMP_MSG_SYNC: /* handle collect ram conf */
+ {
+ unsigned long addr = RAMDUMP_SYNC_RESET;
+ if (icp_msg->msg_data_t.ram_config_sync.array == NULL ||
+ icp_msg->msg_data_t.ram_config_sync.nr == 0)
+ break;
+
+ /* mmap collect ram conf table space */
+ vir_addr = (unsigned long)OSS_MMAP(
+ (unsigned long)icp_msg->msg_data_t.ram_config_sync.array,
+ ((icp_msg->msg_data_t.ram_config_sync.nr) * sizeof(ramdump_ram_config_msg_t)));
+ if (vir_addr == 0)
+ {
+ OSS_PRINTF("[ramdump] trans server mmap collect server ram conf table failed!\n");
+ break;
+ }
+ ramdump_collect_server_ram_conf.array = (ramdump_ram_config_msg_t *)vir_addr;
+ ramdump_collect_server_ram_conf.nr = icp_msg->msg_data_t.ram_config_sync.nr;
+
+ /* mmap collect ram conf table entry space */
+ ramdump_trans_server_ram_conf_table_mmap(
+ ramdump_collect_server_ram_conf.array,
+ ramdump_collect_server_ram_conf.nr);
+
+ /* wait ioremap work */
+ ramdump_wait_done_delay(RAMDUMP_WAIT_TIMELEN, &addr, RAMDUMP_SYNC_RAM_CONFIG_DONE);
+
+ /* we have to mmap first,sometime except happend in interrupt
+ handlers , then we can`t mmap - -! */
+ ramdump_dump_ram_conf_mmap_init();
+
+ break;
+ }
+#endif
+ case RAMDUMP_MSG_EXCEPT:
+ {
+ ramdump_do_panic();
+ break;
+ }
+ default:
+ {
+ ramdump_do_panic();
+ break;
+ }
+ }
+}
+
+/**************************************************************************
+ * º¯ÊýÃû³Æ£º ramdump_icp_msg_from_zsp
+ * ¹¦ÄÜÃèÊö£º server ´¦ÀízspµÄICPÏûÏ¢º¯Êý
+ * ²ÎÊý˵Ã÷£º
+* (´«Èë²ÎÊý) pMsg: ic msg buf
+* (´«³ö²ÎÊý) void
+ * ·µ »Ø Öµ£º void
+ * ÆäËü˵Ã÷£º void
+**************************************************************************/
+static void ramdump_icp_msg_from_zsp(void *buf, unsigned int len)
+{
+ ramdump_trans_server_force_panic_flag = RAMDUMP_CLIENT_ZSP;
+
+ ramdump_clients_icp_handle(buf, len);
+}
+
+/**************************************************************************
+ * º¯ÊýÃû³Æ£º ramdump_icp_msg_from_cap
+ * ¹¦ÄÜÃèÊö£º server ´¦ÀízspµÄICPÏûÏ¢º¯Êý
+ * ²ÎÊý˵Ã÷£º
+* (´«Èë²ÎÊý) pMsg: ic msg buf
+* (´«³ö²ÎÊý) void
+ * ·µ »Ø Öµ£º void
+ * ÆäËü˵Ã÷£º void
+**************************************************************************/
+static void ramdump_icp_msg_from_cap(void *buf, unsigned int len)
+{
+ ramdump_trans_server_force_panic_flag = RAMDUMP_CLIENT_CAP;
+
+ ramdump_clients_icp_handle(buf, len);
+}
+
+/**************************************************************************
+ * º¯ÊýÃû³Æ£º ramdump_icp_msg_from_m0
+ * ¹¦ÄÜÃèÊö£º server ´¦ÀízspµÄICPÏûÏ¢º¯Êý
+ * ²ÎÊý˵Ã÷£º
+* (´«Èë²ÎÊý) pMsg: ic msg buf
+* (´«³ö²ÎÊý) void
+ * ·µ »Ø Öµ£º void
+ * ÆäËü˵Ã÷£º void
+**************************************************************************/
+void ramdump_icp_msg_from_m0(void *buf, int len)
+{
+ ramdump_trans_server_force_panic_flag = RAMDUMP_CLIENT_M0;
+ OSS_PANIC("trans server received forced dump request from M0 client!\n");
+}
+
+/*******************************************************************************
+* ¹¦ÄÜÃèÊö: ramdump_icp_init
+* ²ÎÊý˵Ã÷:
+* (´«Èë²ÎÊý) void
+* (´«³ö²ÎÊý) void
+* ·µ »Ø Öµ: void
+* ÆäËü˵Ã÷: This function is used for ramdump client icp init
+*******************************************************************************/
+static int ramdump_icp_init(void)
+{
+ int ret = 0;
+#ifndef __USE_TRANS_WITH_COLLECT__
+ ret = ramdump_oss_icp_create_channel(
+ ramdump_cpu_id[RAMDUMP_CPU_0],
+ RAMDUMP_CHANNEL,
+ RAMDUMP_CHANNEL_SIZE);
+ if (ret != RAMDUMP_SUCCESS)
+ return ret;
+
+ ret = ramdump_oss_icp_regcallback(
+ ramdump_cpu_id[RAMDUMP_CPU_0],
+ RAMDUMP_CHANNEL,
+ ramdump_collect_server_icp_handle);
+ if (ret != RAMDUMP_SUCCESS)
+ return ret;
+#else
+#ifdef _USE_CAP_SYS
+ ret = zDrvRpMsg_CreateChannel_Cap(
+ CAP_ID,
+ RAMDUMP_CHANNEL,
+ RAMDUMP_ICP_MSG_CAP_SIZE);
+ if (ret != RAMDUMP_SUCCESS)
+ return ret;
+ ret = zDrvRpMsg_RegCallBack_Cap(
+ CAP_ID,
+ RAMDUMP_CHANNEL,
+ ramdump_icp_msg_from_cap);
+ if (ret != RAMDUMP_SUCCESS)
+ return ret;
+#endif
+ ret = ramdump_oss_icp_create_channel(
+ ramdump_cpu_id[RAMDUMP_CPU_2],
+ RP_MSG_PS_PHY_RAMDUMP_CHANNEL,
+ RP_MSG_PS_PHY_RAMDUMP_SIZE);
+ if (ret != RAMDUMP_SUCCESS)
+ return ret;
+
+ ret = ramdump_oss_icp_regcallback(
+ ramdump_cpu_id[RAMDUMP_CPU_2],
+ RP_MSG_PS_PHY_RAMDUMP_CHANNEL,
+ ramdump_icp_msg_from_zsp);
+ if (ret != RAMDUMP_SUCCESS)
+ return ret;
+
+ ret = ramdump_oss_icp_create_channel(
+ M0_ID,
+ channel_3,
+ 0x14);
+ if (ret != RAMDUMP_SUCCESS)
+ return ret;
+
+ ret = ramdump_oss_icp_regcallback(
+ M0_ID,
+ channel_3,
+ ramdump_icp_msg_from_m0);
+
+ if (ret != RAMDUMP_SUCCESS)
+ return ret;
+
+#endif
+
+ return RAMDUMP_SUCCESS;
+}
+
+/*******************************************************************************
+* ¹¦ÄÜÃèÊö: ramdump_notify_client_dump
+* ²ÎÊý˵Ã÷:
+* (´«Èë²ÎÊý) void
+* (´«³ö²ÎÊý) void
+* ·µ »Ø Öµ: void
+* ÆäËü˵Ã÷: This function is used for
+*******************************************************************************/
+static void ramdump_notify_client_dump(void)
+{
+ ramdump_msg_t icp_msg = {0};
+#ifndef __USE_TRANS_WITH_COLLECT__
+
+ /* client except interactive */
+ icp_msg.msg_id = RAMDUMP_MSG_EXCEPT;
+ icp_msg.cpu_id = RAMDUMP_CPU_1;
+ ramdump_oss_icp_send(&icp_msg, ramdump_cpu_id[RAMDUMP_CPU_0]);
+#else
+#ifdef _USE_CAP_SYS
+ /* client except interactive */
+ icp_msg.msg_id = RAMDUMP_MSG_EXCEPT;
+ icp_msg.cpu_id = RAMDUMP_CPU_0;
+ ramdump_oss_icp_send_cap(&icp_msg, CAP_ID);
+#endif
+ /* client except interactive */
+ icp_msg.msg_id = RAMDUMP_MSG_EXCEPT;
+ icp_msg.cpu_id = RAMDUMP_CPU_0;
+ ramdump_oss_icp_send(&icp_msg, ramdump_cpu_id[RAMDUMP_CPU_2]);
+#endif
+}
+
+/*******************************************************************************
+* ¹¦ÄÜÃèÊö: ramdump_server_store_ram_conf
+* ²ÎÊý˵Ã÷:
+* (´«Èë²ÎÊý) mem: addr
+* (´«³ö²ÎÊý) void
+* ·µ »Ø Öµ: unsigend char*: changed addr
+* ÆäËü˵Ã÷: This function is used to store ram conf
+*******************************************************************************/
+static unsigned char *ramdump_server_store_ram_conf(unsigned char *mem)
+{
+ unsigned long i_ram_conf = 0;
+ while (ramdump_trans_server_ram_conf[i_ram_conf].vir != 0 &&
+ ramdump_trans_server_ram_conf[i_ram_conf].size != 0)
+ {
+ ramdump_ram_config_t *config_entry = &(ramdump_trans_server_ram_conf[i_ram_conf]);
+ /* session can be access */
+ if (config_entry->callback == NULL ||
+ (config_entry->callback != NULL &&
+ (*(config_entry->callback))() == RAMDUMP_TRUE))
+ mem += sprintf(
+ mem,
+ "data.load.binary &ramdump_dir\\%s 0x%x--0x%x /noclear\n",
+ (config_entry->name),
+ (unsigned int)config_entry->phy,
+ (unsigned int)(config_entry->phy + config_entry->size));
+ i_ram_conf++;
+ }
+
+ return mem;
+}
+
+/*******************************************************************************
+* ¹¦ÄÜÃèÊö: ramdump_trans_server_cmm_create
+* ²ÎÊý˵Ã÷:
+* (´«Èë²ÎÊý) void
+* (´«³ö²ÎÊý) void
+* ·µ »Ø Öµ: void
+* ÆäËü˵Ã÷: This function is used for server to generate cmm scripts
+*******************************************************************************/
+static void ramdump_trans_server_cmm_create(void)
+{
+ unsigned char *pcmm_buf = ramdump_server_cmm_buf;
+ unsigned int cmm_buf_len = 0;
+ char cmm_name[RAMDUMP_RAMCONF_FILENAME_MAXLEN] = {0};
+
+ // store the cmm BEGIN
+ pcmm_buf += sprintf(pcmm_buf, "ENTRY &ramdump_dir\n");
+ // store procmodes regs
+ pcmm_buf = ramdump_arch_store_modes_regs(pcmm_buf);
+ // store ram config
+ pcmm_buf = ramdump_server_store_ram_conf(pcmm_buf);
+ // store memory map control regs
+ pcmm_buf = ramdump_arch_store_mm_regs(pcmm_buf);
+
+ // store end symbol
+ pcmm_buf += sprintf(pcmm_buf, "ENDDO\n");
+
+ // generate cmm name
+ sprintf(
+ cmm_name,
+ "%s-%s",
+ ramdump_cpu_name[RAMDUMP_CPU_1],
+ RAMDUMP_TRANS_SERVER_CMM_SCRNAME);
+
+ //if out of buf, since we can`t stop it, then cut it
+ cmm_buf_len = ((unsigned int)pcmm_buf - (unsigned int)ramdump_server_cmm_buf);
+ if (cmm_buf_len <= RAMDUMP_CMM_SIZE)
+ ramdump_ram_conf_table_add(
+ cmm_name,
+ (unsigned long)OSS_VIRT_TO_PHY(ramdump_server_cmm_buf),
+ cmm_buf_len,
+ (unsigned long)ramdump_server_cmm_buf,
+ RAMDUMP_FLAG_NONE,
+ 0);
+ else
+ ramdump_ram_conf_table_add(
+ cmm_name,
+ (unsigned long)OSS_VIRT_TO_PHY(ramdump_server_cmm_buf),
+ RAMDUMP_CMM_SIZE,
+ (unsigned long)ramdump_server_cmm_buf,
+ RAMDUMP_FLAG_NONE,
+ 0);
+}
+
+/*******************************************************************************
+* ¹¦ÄÜÃèÊö: ramdump_trans_server_error_log_create
+* ²ÎÊý˵Ã÷:
+* (´«Èë²ÎÊý) void
+* (´«³ö²ÎÊý) void
+* ·µ »Ø Öµ: void
+* ÆäËü˵Ã÷: This function is used to create err log file
+*******************************************************************************/
+static void ramdump_trans_server_error_log_create(void)
+{
+ int offset = 0;
+ char err_log_name[RAMDUMP_RAMCONF_FILENAME_MAXLEN] = {0};
+
+ if (ramdump_trans_server_force_panic_flag == RAMDUMP_CLIENT_ZSP)
+ offset = sprintf(ramdump_server_error_log, "trans server received force dump request from ZSP client !\n");
+ else if (ramdump_trans_server_force_panic_flag == RAMDUMP_CLIENT_M0)
+ offset = sprintf(ramdump_server_error_log, "trans server received force dump request from M0 client !\n");
+ else if (ramdump_trans_server_force_panic_flag == RAMDUMP_CLIENT_CAP)
+ offset = sprintf(ramdump_server_error_log, "trans server received force dump request from CAP client !\n");
+ else
+ offset = sprintf(ramdump_server_error_log, "AP server breakdown happens !\n");
+
+ ramdump_oss_error_log_creat(ramdump_server_error_log + offset);
+ // generate err_log name
+ sprintf(
+ err_log_name,
+ "%s-%s",
+ ramdump_cpu_name[RAMDUMP_CPU_1],
+ RAMDUMP_TRANS_SERVER_ERR_LOG);
+ ramdump_ram_conf_table_add(
+ err_log_name,
+ (unsigned long)OSS_VIRT_TO_PHY(ramdump_server_error_log),
+ ((strlen(ramdump_server_error_log) >= RAMDUMP_ERROR_LOG_SIZE) ?
+ RAMDUMP_ERROR_LOG_SIZE : strlen(ramdump_server_error_log)),
+ (unsigned long)ramdump_server_error_log,
+ RAMDUMP_FLAG_NONE,
+ 0);
+}
+
+/*******************************************************************************
+* ¹¦ÄÜÃèÊö: ramdump_data_transfer_to_pc
+* ²ÎÊý˵Ã÷:
+* (´«Èë²ÎÊý) void
+* (´«³ö²ÎÊý) void
+* ·µ »Ø Öµ: void
+* ÆäËü˵Ã÷: This function is used for ramdump to trans dump data to PC
+*******************************************************************************/
+static void ramdump_data_transfer_to_pc(void)
+{
+ char req_buf[RAMDUMP_INTERACTIVE_DATA_LEN] = {0};
+
+ /* interactive begin */
+ ramdump_oss_data_trans_init();
+
+ for(;;)
+ {
+ ramdump_oss_data_trans_read((unsigned char *)req_buf, RAMDUMP_INTERACTIVE_DATA_LEN);
+ switch (*(unsigned long *)req_buf)
+ {
+ case RAMDUMP_PC_INTERACTIVE_REQ:
+ {
+ ramdump_trans_server_interactive_rsp server_to_pc_msg = {0};
+ server_to_pc_msg.cmd = RAMDUMP_TRANS_SERVER_INTERACTIVE_RSP;
+ server_to_pc_msg.file_num = ramdump_file_num;
+
+ ramdump_oss_data_trans_write(
+ (unsigned char*)(&server_to_pc_msg),
+ sizeof(server_to_pc_msg));
+
+ break;
+ }
+ case RAMDUMP_PC_FILE_INFO_READ_REQ:
+ {
+ ramdump_trans_server_file_info_rsp server_to_pc_msg = {0};
+ /* data from pc to server */
+ ramdump_pc_file_info_req *pc_to_server_msg = (ramdump_pc_file_info_req *)req_buf;
+
+ /* data respond pc from server */
+ server_to_pc_msg.cmd = RAMDUMP_TRANS_SERVER_FILE_INFO_READ_RSP;
+ strncpy(server_to_pc_msg.file_name,
+ ramdump_trans_server_ram_conf[pc_to_server_msg->file_id].name,
+ RAMDUMP_RAMCONF_FILENAME_MAXLEN - 1);
+ server_to_pc_msg.file_name[RAMDUMP_RAMCONF_FILENAME_MAXLEN - 1] = '\0';
+ server_to_pc_msg.file_size = ramdump_trans_server_ram_conf[pc_to_server_msg->file_id].size;
+ if (ramdump_trans_server_ram_conf[pc_to_server_msg->file_id].callback != NULL &&
+ (ramdump_trans_server_ram_conf[pc_to_server_msg->file_id].callback)() == RAMDUMP_FALSE)
+ server_to_pc_msg.file_size = 0;
+ /* interactive data trans */
+ ramdump_oss_data_trans_write(
+ (unsigned char*)(&server_to_pc_msg),
+ sizeof(server_to_pc_msg));
+
+ break;
+ }
+ case RAMDUMP_PC_FILE_DATA_TRANS_REQ:
+ {
+ ramdump_trans_server_data_trans_rsp server_to_pc_msg = {0};
+ /* data from pc to server */
+ ramdump_pc_trans_data_req *pc_to_server_msg = (ramdump_pc_trans_data_req *)req_buf;
+
+ /* data respond pc from server */
+ server_to_pc_msg.cmd = RAMDUMP_TRANS_SERVER_FILE_DATA_TRANS_RSP;
+ server_to_pc_msg.buf_addr =
+ (ramdump_trans_server_ram_conf[pc_to_server_msg->file_id].vir +
+ pc_to_server_msg->offset);
+ server_to_pc_msg.buf_left_size = pc_to_server_msg->length;
+ /* interactive data trans */
+ /*
+ * TODO!
+ * now multiplex old interactive flow.
+ * need to be optimize, write once is better.
+ * like this ramdump_oss_data_trans_write((unsigned char *)(&server_to_pc_msg),
+ * sizeof(server_to_pc_msg));
+ */
+ ramdump_oss_data_trans_write(
+ (unsigned char *)(&(server_to_pc_msg.cmd)),
+ sizeof(server_to_pc_msg.cmd));
+ ramdump_oss_data_trans_write(
+ (unsigned char *)(server_to_pc_msg.buf_addr),
+ server_to_pc_msg.buf_left_size);
+
+ continue;
+ }
+ case RAMDUMP_PC_FILE_TRANS_DONE_REQ:
+ {
+ unsigned long finish_cmd = RAMDUMP_TRANS_SERVER_FILE_TRANS_DONE_RSP;
+ /* interactive data trans */
+ ramdump_oss_data_trans_write(
+ (unsigned char *)(&finish_cmd),
+ sizeof(finish_cmd));
+ ramdump_oss_data_trans_done();
+ return;
+ }
+ default:
+ {
+ unsigned long error_cmd = RAMDUMP_INTERACTIVE_CMD_ERROR;
+ /* interactive data trans */
+ ramdump_oss_data_trans_write((unsigned char *)(&error_cmd),
+ sizeof(error_cmd));
+ break;
+ }
+ }
+ }
+}
+
+/*******************************************************************************
+* ¹¦ÄÜÃèÊö: ramdump_client_copy_data
+* ²ÎÊý˵Ã÷:
+* (´«Èë²ÎÊý) void
+* (´«³ö²ÎÊý) void
+* ·µ »Ø Öµ: void
+* ÆäËü˵Ã÷: This function is used to create err log file
+*******************************************************************************/
+static void ramdump_trans_copy_data(void)
+{
+ unsigned long i_ram_conf = 0;
+
+ while (ramdump_trans_server_ram_conf[i_ram_conf].phy != 0 &&
+ ramdump_trans_server_ram_conf[i_ram_conf].size != 0)
+ {
+ if (ramdump_trans_server_ram_conf[i_ram_conf].flag == RAMDUMP_FLAG_NEED_COPY &&
+ ramdump_trans_server_ram_conf[i_ram_conf].copy != 0 &&
+ (ramdump_trans_server_ram_conf[i_ram_conf].phy !=
+ ramdump_trans_server_ram_conf[i_ram_conf].copy))
+ memcpy(
+ ramdump_trans_server_ram_conf[i_ram_conf].copy,
+ ramdump_trans_server_ram_conf[i_ram_conf].phy,
+ ramdump_trans_server_ram_conf[i_ram_conf].size);
+ i_ram_conf++;
+ }
+}
+
+/*******************************************************************************
+* È«¾Öº¯ÊýʵÏÖ *
+*******************************************************************************/
+
+/*******************************************************************************
+* ¹¦ÄÜÃèÊö: ramdump_ram_conf_table_add
+* ²ÎÊý˵Ã÷:
+* (´«Èë²ÎÊý) ram_name: dump ram name
+ ram_start: dump ram start(virtual addr)
+ ram_size: dump ram size
+ ram_virt: dump ram virt addr
+ ram_flag: dump ram flag(copy/exter/callback)
+ ram_extra: dump ram extra access addr
+* (´«³ö²ÎÊý) void
+* ·µ »Ø Öµ: void
+* ÆäËü˵Ã÷: This function is used to add dump ram conf into public table
+*******************************************************************************/
+void ramdump_ram_conf_table_add(
+ char *ram_name,
+ unsigned long ram_phy,
+ unsigned long ram_size,
+ unsigned long ram_virt,
+ unsigned long ram_flag,
+ unsigned long ram_extra)
+{
+ static unsigned int i_entry = 0;
+
+ if ((ram_phy == 0) && (ram_size == 0))
+ return;
+
+ mutex_lock(&ramdump_mutex);
+
+ strncpy(ramdump_trans_server_ram_conf[i_entry].name,
+ ram_name,
+ RAMDUMP_RAMCONF_FILENAME_MAXLEN - 1);
+ ramdump_trans_server_ram_conf[i_entry].name[RAMDUMP_RAMCONF_FILENAME_MAXLEN - 1] = '\0';
+ ramdump_trans_server_ram_conf[i_entry].phy = ram_phy;
+ ramdump_trans_server_ram_conf[i_entry].size = ram_size;
+ ramdump_trans_server_ram_conf[i_entry].vir = ram_virt;
+ ramdump_trans_server_ram_conf[i_entry].flag = ram_flag;
+
+ switch (ram_flag)
+ {
+ case RAMDUMP_FLAG_NEED_COPY:
+ ramdump_trans_server_ram_conf[i_entry].exter = ram_extra;
+ ramdump_trans_server_ram_conf[i_entry].flag = RAMDUMP_FLAG_HAS_EXTERNAL;
+ break;
+ case RAMDUMP_FLAG_HAS_EXTERNAL:
+ ramdump_trans_server_ram_conf[i_entry].exter = ram_extra;
+ break;
+ case RAMDUMP_FLAG_HAS_CALLBACK:
+ ramdump_trans_server_ram_conf[i_entry].callback = ram_extra;
+ break;
+ default:
+ break;
+ }
+
+ if (ram_phy != 0 && ram_size != 0)
+ ramdump_trans_server_ram_conf[i_entry].vir = ramdump_phy_to_vir(&ramdump_trans_server_ram_conf[i_entry]);
+
+ i_entry++;
+
+ if (i_entry >= RAMDUMP_RAMCONF_TABLE_MAX_ENTRYS)
+ i_entry = 0;
+
+ ramdump_file_num ++;
+ mutex_unlock(&ramdump_mutex);
+}
+EXPORT_SYMBOL(ramdump_ram_conf_table_add);
+
+/*******************************************************************************
+* ¹¦ÄÜÃèÊö: ramdump_init
+* ²ÎÊý˵Ã÷:
+* (´«Èë²ÎÊý) void
+* (´«³ö²ÎÊý) void
+* ·µ »Ø Öµ: RAMDUMP_SUCCESS or RAMDUMP_FAILED
+* ÆäËü˵Ã÷: This function is used for ramdump init
+*******************************************************************************/
+static int test_fun(void)
+{
+ return RAMDUMP_TRUE;
+}
+int ramdump_init(void)
+{
+ if (ramdump_server_init_flag == RAMDUMP_TRUE)
+ return RAMDUMP_SUCCESS;
+
+ int ret = 0;
+ int i = 0;
+ char bin_name[RAMDUMP_RAMCONF_FILENAME_MAXLEN] = {0};
+
+ for(i = 0;i < meminfo.nr_banks;i++) {
+ if(meminfo.bank[i].start == RAMDUMP_SERVER_DDR_BASE)
+ ddr_ap_size = meminfo.bank[i].size;
+ }
+ BUG_ON(ddr_ap_size == 0);
+
+ /* change the interactive cpu value */
+ ramdump_cpu_id[RAMDUMP_CPU_2] = ICP_MSG_ACTOR_ZSP;
+
+ /* client icp init */
+ ret = ramdump_icp_init();
+ if (ret != RAMDUMP_ICP_SUCCESS)
+ return ret;
+
+ sprintf(
+ bin_name,
+ "%s-%s",
+ ramdump_cpu_name[RAMDUMP_CPU_1],
+ RAMDUMP_TRANS_SERVER_DDR_BINNAME);
+ ramdump_ram_conf_table_add(
+ bin_name,
+ RAMDUMP_SERVER_DDR_BASE,
+ ddr_ap_size,
+ (unsigned long)OSS_PHY_TO_VIRT(RAMDUMP_SERVER_DDR_BASE),
+ RAMDUMP_FLAG_NONE,
+ 0);
+
+ ramdump_ram_conf_table_add(
+ "AP_test_bus_call_false.bin",
+ RAMDUMP_SERVER_DDR_BASE,
+ 0x1000,
+ (unsigned long)OSS_PHY_TO_VIRT(RAMDUMP_SERVER_DDR_BASE),
+ RAMDUMP_FLAG_HAS_CALLBACK,
+ test_fun);
+
+#ifdef CONFIG_MEM_TRACKER
+ ramdump_ram_conf_table_add(
+ "mem_tracker.bin",
+ ZX29_MEM_TRACKER_PHYS,
+ ZX_MEM_TRACKER_SIZE,
+ ZX_MEM_TRACKER_BASE,
+ RAMDUMP_FLAG_NONE,
+ 0);
+ ramdump_ram_conf_table_add(
+ "kmalloc_tracker.bin",
+ ZX29_KMALLOC_TRACKER_PHYS,
+ ZX_KMALLOC_TRACKER_SIZE,
+ ZX_KMALLOC_TRACKER_BASE,
+ RAMDUMP_FLAG_NONE,
+ 0);
+#endif
+#ifdef _USE_CAP_SYS
+ /* cap ramdump cmm */
+ ramdump_ram_conf_table_add(
+ "cap_ddr",
+ DDR_BASE_CAP_ADDR_PA,
+ DDR_BASE_LEN_CAP,
+ 0,
+ RAMDUMP_FLAG_NONE,
+ 0);
+ ramdump_ram_conf_table_add(
+ "cap.cmm",
+ RAMDUMP_CAP_CMM_BUF_ADDR,
+ RAMDUMP_CAP_CMM_BUF_LEN,
+ 0,
+ RAMDUMP_FLAG_NONE,
+ 0);
+#endif
+ /* set trans ram data done flag */
+// ramdump_trans_server_data_done_flag = RAMDUMP_SYNC_RAM_CONTENT_DONE;
+
+ OSS_PRINTF("Ramdump server init success!\n");
+ ramdump_server_init_flag = RAMDUMP_TRUE;
+
+ return RAMDUMP_SUCCESS;
+}
+//OSS_INIT(ramdump_init);
+EXPORT_SYMBOL(ramdump_init);
+extern void show_stack_state();
+
+/*******************************************************************************
+* ¹¦ÄÜÃèÊö: ramdump_info
+* ²ÎÊý˵Ã÷:
+* (´«Èë²ÎÊý) void
+* (´«³ö²ÎÊý) void
+* ·µ »Ø Öµ: void
+* ÆäËü˵Ã÷: This function is used for print ramdump info
+*******************************************************************************/
+void ramdump_info(void)
+{
+ if(CPPS_FUNC(cpps_callbacks, zOss_GetExceptResetFlag)() == 1)
+ printk(KERN_EMERG "Ramdump info: Ramdump Except Reboot enabled!\n");
+ else if(CPPS_FUNC(cpps_callbacks, zOss_GetExceptResetFlag)() == 2)
+ printk(KERN_EMERG "Ramdump info: Ramdump Except Reboot after export!\n");
+ if (sysctl_ramdump_on_panic == FALSE)
+ printk(KERN_EMERG "Ramdump info: Ramdump disabled!\n");
+ printk(KERN_EMERG "Ramdump info: Current Process is: %s, pid is %i!\n", current->comm, current->pid);
+}
+
+/*******************************************************************************
+* ¹¦ÄÜÃèÊö: ramdump_entry
+* ²ÎÊý˵Ã÷:
+* (´«Èë²ÎÊý) void
+* (´«³ö²ÎÊý) void
+* ·µ »Ø Öµ: void
+* ÆäËü˵Ã÷: This function is used for ramdump entry
+*******************************************************************************/
+void ramdump_entry (void)
+{
+ unsigned long flags;
+
+#ifndef CONFIG_SYSTEM_RECOVERY
+ if(CPPS_FUNC(cpps_callbacks, zOss_GetExceptResetFlag)() == 1)
+ CPPS_FUNC(cpps_callbacks, zSys_ExceptReboot)(0);
+#else
+ emergency_restart();
+#endif
+
+#ifdef CONFIG_ZX29_WATCHDOG
+ zx_wdt_m0_stop();
+#endif
+
+ if (sysctl_ramdump_on_panic == FALSE)
+ return;
+
+ /*
+ * we need lock the irq, this can`t be interrupt.
+ */
+ OSS_LOCK(flags);
+#ifdef CONFIG_STACK_SIZE
+ show_stack_state();
+#endif
+ if (!ramdump_server_init_flag)
+ while(TRUE); /* endless circle */
+
+ if (++ramdump_count > 1)
+ while(TRUE); /* endless circle */
+
+ /*
+ * save all regs first.
+ */
+ ramdump_arch_save_all_regs();
+
+ //Éú³Écmm½Å±¾µÄµ¼³öÅäÖÃ
+ ramdump_trans_server_cmm_create();
+
+ /* error log file */
+ ramdump_trans_server_error_log_create();
+
+ /* log buf */
+ ramdump_oss_logbuf_create();
+
+ /* notify client ramdump */
+ ramdump_notify_client_dump();
+
+ /* special data copy to the copy addr
+ * then other core read from the copy addr
+ */
+ ramdump_trans_copy_data();
+
+#ifndef __USE_TRANS_WITH_COLLECT__ // if not collect server, need to do this
+ /* wait client all data done */
+ ramdump_wait_clients_dump_done();
+#endif
+
+ /* caculate the true dump file num */
+ //ramdump_dump_file_num_recalc();
+ /* ram data trans to pc */
+ ramdump_data_transfer_to_pc();
+
+ /*
+ * TODO!
+ * now endless circle, e.g., config restart or not is more better.
+ */
+#ifndef CONFIG_SYSTEM_RECOVERY
+ if(CPPS_FUNC(cpps_callbacks, zOss_GetExceptResetFlag)() == 2)
+ CPPS_FUNC(cpps_callbacks, zSys_ExceptReboot)(0);
+ else
+#endif
+ while(TRUE);
+
+ OSS_UNLOCK(flags);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+
+MODULE_LICENSE("GPL");