yuezonghe | 824eb0c | 2024-06-27 02:32:26 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * °æÈ¨ËùÓÐ (C)2016, ÖÐÐËͨѶ¹É·ÝÓÐÏÞ¹«Ë¾¡£ |
| 3 | * |
| 4 | * ÎļþÃû³Æ: ramdump_oss.c |
| 5 | * Îļþ±êʶ: ramdump_oss.c |
| 6 | * ÄÚÈÝÕªÒª: ramdump²Ù×÷ϵͳÒÀÀµ½Ó¿Ú/Êý¾Ý½á¹¹¶¨ÒåÍ·Îļþ |
| 7 | * ʹÓ÷½·¨: Èç¹û¸ü»»²Ù×÷ϵͳ£¬¸ÄÍ·ÎļþÄÚ½Ó¿Ú»òÕßÊý¾Ý¶¨ÒåÐèÒªÖØÐÂÊÊÅä |
| 8 | * |
| 9 | * ÐÞ¸ÄÈÕÆÚ °æ±¾ºÅ Ð޸ıê¼Ç ÐÞ¸ÄÈË ÐÞ¸ÄÄÚÈÝ |
| 10 | * ------------------------------------------------------------------------------ |
| 11 | * 2016/6/10 V1.0 Create ÕÔ¾ü¿ü ´´½¨ |
| 12 | * |
| 13 | *******************************************************************************/ |
| 14 | |
| 15 | /******************************************************************************* |
| 16 | * Í·Îļþ * |
| 17 | *******************************************************************************/ |
| 18 | #include "ramdump_pub.h" |
| 19 | #include "ramdump_oss.h" |
| 20 | #include <linux/module.h> |
| 21 | |
| 22 | #ifdef __cplusplus |
| 23 | extern "C" { |
| 24 | #endif |
| 25 | |
| 26 | /******************************************************************************* |
| 27 | * Íⲿº¯ÊýÉùÃ÷ * |
| 28 | *******************************************************************************/ |
| 29 | |
| 30 | /******************************************************************************* |
| 31 | * ºê¶¨Òå * |
| 32 | *******************************************************************************/ |
| 33 | |
| 34 | /******************************************************************************* |
| 35 | * Êý¾ÝÀàÐͶ¨Òå * |
| 36 | *******************************************************************************/ |
| 37 | |
| 38 | /******************************************************************************* |
| 39 | * È«¾Ö±äÁ¿ÉùÃ÷ * |
| 40 | *******************************************************************************/ |
| 41 | |
| 42 | /******************************************************************************* |
| 43 | * È«¾Öº¯ÊýÉùÃ÷ * |
| 44 | *******************************************************************************/ |
| 45 | |
| 46 | #ifdef _OS_LINUX |
| 47 | /* icp api */ |
| 48 | extern int zDrvRpMsg_CreateChannel( |
| 49 | T_ZDrvRpMsg_ActorID actorID, |
| 50 | T_ZDrvRpMsg_ChID chID, |
| 51 | unsigned int size); |
| 52 | extern int zDrvRpMsg_RegCallBack( |
| 53 | T_ZDrvRpMsg_ActorID actorID, |
| 54 | unsigned int chID, |
| 55 | T_ZDrvRpMsg_CallbackFunction callback); |
| 56 | extern int zDrvRpMsg_WriteLockIrq(const T_ZDrvRpMsg_Msg *pMsg); |
| 57 | extern void panic(const char *fmt, ...); |
| 58 | |
| 59 | extern int zDrvUsbPoll_Init(void); |
| 60 | extern int zDrvUsbPoll_Isr(void); |
| 61 | extern bool zDrvUsbPoll_isConnect(void); |
| 62 | extern int zDrvUsbPoll_Read(unsigned char* pBuf,unsigned long length); |
| 63 | extern int zDrvUsbPoll_Write(unsigned char* pBuf,unsigned long length); |
| 64 | #if defined CONFIG_PRINTK |
| 65 | extern void get_logbuf_info(unsigned long *addr, unsigned long *size); |
| 66 | #endif |
| 67 | #endif //#ifdef _OS_LINUX |
| 68 | |
| 69 | /******************************************************************************* |
| 70 | * È«¾Öº¯ÊýʵÏÖ * |
| 71 | *******************************************************************************/ |
| 72 | |
| 73 | /******************************************************************************* |
| 74 | * ¹¦ÄÜÃèÊö: ramdump_oss_create_thread |
| 75 | * ²ÎÊý˵Ã÷: |
| 76 | * (´«Èë²ÎÊý) void |
| 77 | * (´«³ö²ÎÊý) void |
| 78 | * ·µ »Ø Öµ: void |
| 79 | * ÆäËü˵Ã÷: |
| 80 | *******************************************************************************/ |
| 81 | void ramdump_oss_create_thread ( |
| 82 | unsigned char *name, |
| 83 | ramdump_oss_thread_entry_t entry) |
| 84 | { |
| 85 | #ifdef _OS_TOS |
| 86 | #define RAMDUMP_THREAD_STACK_DEF_SIZE 2048 |
| 87 | #define RAMDUMP_THREAD_DEF_PRIO 20 |
| 88 | #define RAMDUMP_THREAD_DEF_ARG 0 |
| 89 | #define RAMDUMP_THREAD_AUTORUN 1 |
| 90 | #define RAMDUMP_THREAD_PREEMPT 1 |
| 91 | |
| 92 | zOss_CreateThread( |
| 93 | name,entry, |
| 94 | RAMDUMP_THREAD_DEF_ARG, |
| 95 | RAMDUMP_THREAD_STACK_DEF_SIZE, |
| 96 | RAMDUMP_THREAD_DEF_PRIO, |
| 97 | RAMDUMP_THREAD_PREEMPT, |
| 98 | RAMDUMP_THREAD_AUTORUN); |
| 99 | #endif |
| 100 | } |
| 101 | |
| 102 | /******************************************************************************* |
| 103 | * ¹¦ÄÜÃèÊö: ramdump_oss_mmap |
| 104 | * ²ÎÊý˵Ã÷: |
| 105 | * (´«Èë²ÎÊý) void |
| 106 | * (´«³ö²ÎÊý) void |
| 107 | * ·µ »Ø Öµ: void |
| 108 | * ÆäËü˵Ã÷: |
| 109 | *******************************************************************************/ |
| 110 | unsigned long ramdump_oss_mmap (unsigned long addr, unsigned long size) |
| 111 | { |
| 112 | #ifdef _OS_LINUX |
| 113 | return ioremap(addr,size); |
| 114 | #elif defined (_OS_TOS) |
| 115 | |
| 116 | #ifdef __USE_MMU__ |
| 117 | T_zTos_MmuRamdumpTable mmuTable = {0}; |
| 118 | zTos_MmuGetMappingRegion(addr, size, &mmuTable); |
| 119 | /* |
| 120 | * TODO! |
| 121 | * current tos mmap one to one |
| 122 | * need new API like ioremap realize |
| 123 | */ |
| 124 | return addr; |
| 125 | #endif |
| 126 | |
| 127 | #endif |
| 128 | } |
| 129 | |
| 130 | #ifdef _USE_CAP_SYS |
| 131 | /******************************************************************************* |
| 132 | * ¹¦ÄÜÃèÊö: ramdump_oss_icp_send_cap |
| 133 | * ²ÎÊý˵Ã÷: |
| 134 | * (´«Èë²ÎÊý) icp_msg: msg info |
| 135 | client_id: client id |
| 136 | * (´«³ö²ÎÊý) void |
| 137 | * ·µ »Ø Öµ: int: if msg send success |
| 138 | * ÆäËü˵Ã÷: This function is used for server to send msg to client |
| 139 | *******************************************************************************/ |
| 140 | int ramdump_oss_icp_send_cap(ramdump_oss_msg_t *icp_msg, unsigned int client_id) |
| 141 | { |
| 142 | int ret; |
| 143 | ramdump_oss_icp_msg rpmsg = {0}; |
| 144 | |
| 145 | rpmsg.actorID = client_id; |
| 146 | rpmsg.chID = channel_10; |
| 147 | rpmsg.flag = 1; |
| 148 | rpmsg.buf = icp_msg; |
| 149 | rpmsg.len = sizeof(*icp_msg); |
| 150 | |
| 151 | /* |
| 152 | * clean all the caches to make sure all data in ddr |
| 153 | */ |
| 154 | ramdump_arch_clean_caches(); |
| 155 | |
| 156 | ret = zDrvRpMsg_Write_Cap(&rpmsg); |
| 157 | |
| 158 | if (ret != rpmsg.len) |
| 159 | { |
| 160 | OSS_PRINTF( |
| 161 | "[ramdump] icpmsg send fail, ret != rpmsg.len[ret:%d], [client_id:%d]\n", |
| 162 | ret, |
| 163 | client_id); |
| 164 | return ret; |
| 165 | } |
| 166 | |
| 167 | return RAMDUMP_ICP_SUCCESS; |
| 168 | } |
| 169 | #endif |
| 170 | |
| 171 | /******************************************************************************* |
| 172 | * ¹¦ÄÜÃèÊö: ramdump_oss_icp_send |
| 173 | * ²ÎÊý˵Ã÷: |
| 174 | * (´«Èë²ÎÊý) icp_msg: msg info |
| 175 | client_id: client id |
| 176 | * (´«³ö²ÎÊý) void |
| 177 | * ·µ »Ø Öµ: int: if msg send success |
| 178 | * ÆäËü˵Ã÷: This function is used for server to send msg to client |
| 179 | *******************************************************************************/ |
| 180 | int ramdump_oss_icp_send(ramdump_oss_msg_t *icp_msg, unsigned int client_id) |
| 181 | { |
| 182 | int ret; |
| 183 | ramdump_oss_icp_msg rpmsg = {0}; |
| 184 | |
| 185 | rpmsg.actorID = client_id; |
| 186 | rpmsg.chID = channel_40; |
| 187 | rpmsg.flag = 1; |
| 188 | rpmsg.buf = icp_msg; |
| 189 | rpmsg.len = sizeof(*icp_msg); |
| 190 | |
| 191 | /* |
| 192 | * clean all the caches to make sure all data in ddr |
| 193 | */ |
| 194 | ramdump_arch_clean_caches(); |
| 195 | |
| 196 | ret = ramdump_oss_icp_write(&rpmsg); |
| 197 | |
| 198 | if (ret != rpmsg.len) |
| 199 | { |
| 200 | #ifdef _OS_LINUX |
| 201 | OSS_PRINTF( |
| 202 | "[ramdump] icpmsg send fail, ret != rpmsg.len[ret:%d], [client_id:%d]\n", |
| 203 | ret, |
| 204 | client_id); |
| 205 | #elif defined (_OS_TOS) |
| 206 | OSS_PRINTF( |
| 207 | SUBMDL_TEST, |
| 208 | PRINT_LEVEL_NORMAL, |
| 209 | "[ramdump] icpmsg send fail, ret != rpmsg.len[ret:%d], [client_id:%d]\n", |
| 210 | ret, |
| 211 | client_id); |
| 212 | #endif |
| 213 | return ret; |
| 214 | } |
| 215 | |
| 216 | return RAMDUMP_ICP_SUCCESS; |
| 217 | } |
| 218 | |
| 219 | /******************************************************************************* |
| 220 | * ¹¦ÄÜÃèÊö: ramdump_oss_error_log_creat |
| 221 | * ²ÎÊý˵Ã÷: |
| 222 | * (´«Èë²ÎÊý) buf : addr point |
| 223 | * (´«³ö²ÎÊý) void |
| 224 | * ·µ »Ø Öµ: void |
| 225 | * ÆäËü˵Ã÷: |
| 226 | *******************************************************************************/ |
| 227 | void ramdump_oss_error_log_creat(char *buf) |
| 228 | { |
| 229 | #ifdef _OS_LINUX |
| 230 | if (current->mm != NULL) |
| 231 | sprintf( |
| 232 | buf, |
| 233 | " dump at user, app name is: %s, load addr is: %lu \n", |
| 234 | current->comm, |
| 235 | current->mm->start_code); |
| 236 | else |
| 237 | sprintf( |
| 238 | buf, |
| 239 | " dump at kernel, app name is: %s \n", |
| 240 | current->comm); |
| 241 | #endif |
| 242 | |
| 243 | } |
| 244 | |
| 245 | /******************************************************************************* |
| 246 | * ¹¦ÄÜÃèÊö: ramdump_oss_icp_create_channel |
| 247 | * ²ÎÊý˵Ã÷: |
| 248 | * (´«Èë²ÎÊý) actorID: icp send core id |
| 249 | chID: icp channel id |
| 250 | size: icp channel size |
| 251 | * (´«³ö²ÎÊý) void |
| 252 | * ·µ »Ø Öµ: int: if msg send success |
| 253 | * ÆäËü˵Ã÷: |
| 254 | *******************************************************************************/ |
| 255 | int ramdump_oss_icp_create_channel( |
| 256 | ramdump_oss_icp_actorid actorID, |
| 257 | ramdump_oss_icp_channelid chID, |
| 258 | unsigned int size) |
| 259 | { |
| 260 | #ifdef _OS_LINUX |
| 261 | return CPPS_FUNC(cpps_callbacks, zDrvRpMsg_CreateChannel)(actorID, chID, size); |
| 262 | #elif defined (_OS_TOS) |
| 263 | if (actorID == ramdump_cpu_id[RAMDUMP_CPU_2]) |
| 264 | return 0; |
| 265 | else |
| 266 | return zDrvRpMsg_CreateChannel(actorID, chID, size); |
| 267 | #endif |
| 268 | } |
| 269 | |
| 270 | /******************************************************************************* |
| 271 | * ¹¦ÄÜÃèÊö: ramdump_oss_icp_regcallback |
| 272 | * ²ÎÊý˵Ã÷: |
| 273 | * (´«Èë²ÎÊý) actorID: icp send core id |
| 274 | chID: icp channel id |
| 275 | callback:icp callback fun |
| 276 | * (´«³ö²ÎÊý) void |
| 277 | * ·µ »Ø Öµ: int: if msg send success |
| 278 | * ÆäËü˵Ã÷: |
| 279 | *******************************************************************************/ |
| 280 | int ramdump_oss_icp_regcallback ( |
| 281 | ramdump_oss_icp_actorid actorID, |
| 282 | unsigned int chID, |
| 283 | ramdump_oss_icp_callback callback) |
| 284 | { |
| 285 | #ifdef _OS_LINUX |
| 286 | return CPPS_FUNC(cpps_callbacks, zDrvRpMsg_RegCallBack)(actorID,chID,callback); |
| 287 | #elif defined (_OS_TOS) |
| 288 | if (actorID == ramdump_cpu_id[RAMDUMP_CPU_2]) |
| 289 | return zDrvIcp_RegCallback( |
| 290 | ICP_ARM0_MODULE_ID_OS, |
| 291 | actorID, |
| 292 | callback, |
| 293 | ICP_ISR_CALLBACK); |
| 294 | else |
| 295 | return zDrvRpMsg_RegCallBack(actorID,chID,callback); |
| 296 | #endif |
| 297 | } |
| 298 | |
| 299 | /******************************************************************************* |
| 300 | * ¹¦ÄÜÃèÊö: ramdump_oss_icp_write |
| 301 | * ²ÎÊý˵Ã÷: |
| 302 | * (´«Èë²ÎÊý) pMsg: icp send msg |
| 303 | * (´«³ö²ÎÊý) void |
| 304 | * ·µ »Ø Öµ: int: if msg send success |
| 305 | * ÆäËü˵Ã÷: |
| 306 | *******************************************************************************/ |
| 307 | int ramdump_oss_icp_write(const ramdump_oss_icp_msg *pMsg) |
| 308 | { |
| 309 | #ifdef _OS_LINUX |
| 310 | return CPPS_FUNC(cpps_callbacks, zDrvRpMsg_Write)(pMsg); |
| 311 | #elif defined (_OS_TOS) |
| 312 | if ((ramdump_msg_t *)pMsg->actorID == ramdump_cpu_id[RAMDUMP_CPU_2]) |
| 313 | { |
| 314 | switch (((ramdump_msg_t *)(pMsg->buf))->msg_id) |
| 315 | { |
| 316 | case RAMDUMP_MSG_EXCEPT: |
| 317 | { |
| 318 | T_HalIcp_Msg icpMsg = { 0 }; |
| 319 | icpMsg.SrcModId = ICP_ARM0_MODULE_ID_OS; |
| 320 | icpMsg.desModId = ICP_ARM1_MODULE_ID_OS; |
| 321 | icpMsg.IntInfo.high_word = ZPLAT_PS2PHY_RAMDUMP_INT_ICP_CF; |
| 322 | zDrvIcp_SendMsg((const T_HalIcp_Msg *)&icpMsg); |
| 323 | } |
| 324 | case RAMDUMP_MSG_SYNC: |
| 325 | default: |
| 326 | return pMsg->len; |
| 327 | } |
| 328 | } |
| 329 | else |
| 330 | return zDrvRpMsg_WriteLockIrq(pMsg); |
| 331 | #endif |
| 332 | } |
| 333 | |
| 334 | /******************************************************************************* |
| 335 | * ¹¦ÄÜÃèÊö: ramdump_oss_data_trans_init |
| 336 | * ²ÎÊý˵Ã÷: |
| 337 | * (´«Èë²ÎÊý) void |
| 338 | * (´«³ö²ÎÊý) void |
| 339 | * ·µ »Ø Öµ: void |
| 340 | * ÆäËü˵Ã÷: |
| 341 | *******************************************************************************/ |
| 342 | void ramdump_oss_data_trans_init(void) |
| 343 | { |
| 344 | #ifdef _OS_LINUX |
| 345 | zDrvUsbPoll_Init(); /* ³õʼ»¯USB */ |
| 346 | while (!zDrvUsbPoll_isConnect()) ; /* ²éѯUSBÊÇ·ñÁ¬½Ó */ |
| 347 | #endif |
| 348 | } |
| 349 | |
| 350 | /******************************************************************************* |
| 351 | * ¹¦ÄÜÃèÊö: ramdump_oss_data_trans_read |
| 352 | * ²ÎÊý˵Ã÷: |
| 353 | * (´«Èë²ÎÊý) buffer: data buff |
| 354 | size: data size |
| 355 | * (´«³ö²ÎÊý) void |
| 356 | * ·µ »Ø Öµ: void |
| 357 | * ÆäËü˵Ã÷: |
| 358 | *******************************************************************************/ |
| 359 | void ramdump_oss_data_trans_read(unsigned char *buffer, unsigned int size) |
| 360 | { |
| 361 | #ifdef _OS_LINUX |
| 362 | unsigned int count = 0; |
| 363 | |
| 364 | do |
| 365 | { |
| 366 | zDrvUsbPoll_Isr(); |
| 367 | count = (unsigned int)zDrvUsbPoll_Read(buffer, size); |
| 368 | if ( size <= count) |
| 369 | { |
| 370 | break; |
| 371 | } |
| 372 | buffer += count; |
| 373 | size -=count; |
| 374 | } |
| 375 | while (size > 0); |
| 376 | #endif |
| 377 | } |
| 378 | |
| 379 | /******************************************************************************* |
| 380 | * ¹¦ÄÜÃèÊö: ramdump_oss_data_trans_write |
| 381 | * ²ÎÊý˵Ã÷: |
| 382 | * (´«Èë²ÎÊý) buffer: data buff |
| 383 | size: data size |
| 384 | * (´«³ö²ÎÊý) void |
| 385 | * ·µ »Ø Öµ: void |
| 386 | * ÆäËü˵Ã÷: |
| 387 | *******************************************************************************/ |
| 388 | void ramdump_oss_data_trans_write(unsigned char *buffer, unsigned int size) |
| 389 | { |
| 390 | #ifdef _OS_LINUX |
| 391 | unsigned int count = 0; |
| 392 | |
| 393 | while (size > 0) |
| 394 | { |
| 395 | zDrvUsbPoll_Isr(); |
| 396 | count = (unsigned int)zDrvUsbPoll_Write(buffer, size); |
| 397 | if ( size <= count) |
| 398 | { |
| 399 | break; |
| 400 | } |
| 401 | |
| 402 | buffer += count; |
| 403 | size -=count; |
| 404 | } |
| 405 | #endif |
| 406 | } |
| 407 | |
| 408 | /******************************************************************************* |
| 409 | * ¹¦ÄÜÃèÊö: ramdump_oss_data_trans_done |
| 410 | * ²ÎÊý˵Ã÷: |
| 411 | * (´«Èë²ÎÊý) void |
| 412 | * (´«³ö²ÎÊý) void |
| 413 | * ·µ »Ø Öµ: void |
| 414 | * ÆäËü˵Ã÷: |
| 415 | *******************************************************************************/ |
| 416 | void ramdump_oss_data_trans_done(void) |
| 417 | { |
| 418 | #ifdef _OS_LINUX |
| 419 | /* µÈ´ýÊý¾Ý·¢ËÍÍêºó£¬ÔÙÖØÆô */ |
| 420 | zDrvUsbPoll_Isr(); |
| 421 | #endif |
| 422 | } |
| 423 | |
| 424 | void ramdump_oss_logbuf_create(void) |
| 425 | { |
| 426 | #ifdef _OS_LINUX |
| 427 | #if defined CONFIG_PRINTK |
| 428 | |
| 429 | unsigned long addr; |
| 430 | unsigned long size; |
| 431 | |
| 432 | get_logbuf_info(&addr, &size); |
| 433 | |
| 434 | ramdump_ram_conf_table_add( |
| 435 | "ap_log_buf", |
| 436 | (unsigned long)OSS_VIRT_TO_PHY(addr), |
| 437 | size, |
| 438 | addr, |
| 439 | RAMDUMP_FLAG_NONE, |
| 440 | 0); |
| 441 | #endif |
| 442 | #endif |
| 443 | } |
| 444 | |
| 445 | #ifdef __cplusplus |
| 446 | } |
| 447 | #endif |
| 448 | |