IxNpeDlNpeMgr.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936
  1. /**
  2. * @file IxNpeDlNpeMgr.c
  3. *
  4. * @author Intel Corporation
  5. * @date 09 January 2002
  6. *
  7. * @brief This file contains the implementation of the private API for the
  8. * IXP425 NPE Downloader NpeMgr module
  9. *
  10. *
  11. * @par
  12. * IXP400 SW Release version 2.0
  13. *
  14. * -- Copyright Notice --
  15. *
  16. * @par
  17. * Copyright 2001-2005, Intel Corporation.
  18. * All rights reserved.
  19. *
  20. * @par
  21. * Redistribution and use in source and binary forms, with or without
  22. * modification, are permitted provided that the following conditions
  23. * are met:
  24. * 1. Redistributions of source code must retain the above copyright
  25. * notice, this list of conditions and the following disclaimer.
  26. * 2. Redistributions in binary form must reproduce the above copyright
  27. * notice, this list of conditions and the following disclaimer in the
  28. * documentation and/or other materials provided with the distribution.
  29. * 3. Neither the name of the Intel Corporation nor the names of its contributors
  30. * may be used to endorse or promote products derived from this software
  31. * without specific prior written permission.
  32. *
  33. * @par
  34. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
  35. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  36. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  37. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
  38. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  39. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  40. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  41. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  42. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  43. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  44. * SUCH DAMAGE.
  45. *
  46. * @par
  47. * -- End of Copyright Notice --
  48. */
  49. /*
  50. * Put the user defined include files required.
  51. */
  52. /*
  53. * Put the user defined include files required.
  54. */
  55. #include "IxOsal.h"
  56. #include "IxNpeDl.h"
  57. #include "IxNpeDlNpeMgr_p.h"
  58. #include "IxNpeDlNpeMgrUtils_p.h"
  59. #include "IxNpeDlNpeMgrEcRegisters_p.h"
  60. #include "IxNpeDlMacros_p.h"
  61. #include "IxFeatureCtrl.h"
  62. /*
  63. * #defines and macros used in this file.
  64. */
  65. #define IX_NPEDL_BYTES_PER_WORD 4
  66. /* used to read download map from version in microcode image */
  67. #define IX_NPEDL_BLOCK_TYPE_INSTRUCTION 0x00000000
  68. #define IX_NPEDL_BLOCK_TYPE_DATA 0x00000001
  69. #define IX_NPEDL_BLOCK_TYPE_STATE 0x00000002
  70. #define IX_NPEDL_END_OF_DOWNLOAD_MAP 0x0000000F
  71. /*
  72. * masks used to extract address info from State information context
  73. * register addresses as read from microcode image
  74. */
  75. #define IX_NPEDL_MASK_STATE_ADDR_CTXT_REG 0x0000000F
  76. #define IX_NPEDL_MASK_STATE_ADDR_CTXT_NUM 0x000000F0
  77. /* LSB offset of Context Number field in State-Info Context Address */
  78. #define IX_NPEDL_OFFSET_STATE_ADDR_CTXT_NUM 4
  79. /* size (in words) of single State Information entry (ctxt reg address|data) */
  80. #define IX_NPEDL_STATE_INFO_ENTRY_SIZE 2
  81. #define IX_NPEDL_RESET_NPE_PARITY 0x0800
  82. #define IX_NPEDL_PARITY_BIT_MASK 0x3F00FFFF
  83. #define IX_NPEDL_CONFIG_CTRL_REG_MASK 0x3F3FFFFF
  84. /*
  85. * Typedefs whose scope is limited to this file.
  86. */
  87. typedef struct
  88. {
  89. UINT32 type;
  90. UINT32 offset;
  91. } IxNpeDlNpeMgrDownloadMapBlockEntry;
  92. typedef union
  93. {
  94. IxNpeDlNpeMgrDownloadMapBlockEntry block;
  95. UINT32 eodmMarker;
  96. } IxNpeDlNpeMgrDownloadMapEntry;
  97. typedef struct
  98. {
  99. /* 1st entry in the download map (there may be more than one) */
  100. IxNpeDlNpeMgrDownloadMapEntry entry[1];
  101. } IxNpeDlNpeMgrDownloadMap;
  102. /* used to access an instruction or data block in a microcode image */
  103. typedef struct
  104. {
  105. UINT32 npeMemAddress;
  106. UINT32 size;
  107. UINT32 data[1];
  108. } IxNpeDlNpeMgrCodeBlock;
  109. /* used to access each Context Reg entry state-information block */
  110. typedef struct
  111. {
  112. UINT32 addressInfo;
  113. UINT32 value;
  114. } IxNpeDlNpeMgrStateInfoCtxtRegEntry;
  115. /* used to access a state-information block in a microcode image */
  116. typedef struct
  117. {
  118. UINT32 size;
  119. IxNpeDlNpeMgrStateInfoCtxtRegEntry ctxtRegEntry[1];
  120. } IxNpeDlNpeMgrStateInfoBlock;
  121. /* used to store some useful NPE information for easy access */
  122. typedef struct
  123. {
  124. UINT32 baseAddress;
  125. UINT32 insMemSize;
  126. UINT32 dataMemSize;
  127. } IxNpeDlNpeInfo;
  128. /* used to distinguish instruction and data memory operations */
  129. typedef enum
  130. {
  131. IX_NPEDL_MEM_TYPE_INSTRUCTION = 0,
  132. IX_NPEDL_MEM_TYPE_DATA
  133. } IxNpeDlNpeMemType;
  134. /* used to hold a reset value for a particular ECS register */
  135. typedef struct
  136. {
  137. UINT32 regAddr;
  138. UINT32 regResetVal;
  139. } IxNpeDlEcsRegResetValue;
  140. /* prototype of function to write either Instruction or Data memory */
  141. typedef IX_STATUS (*IxNpeDlNpeMgrMemWrite) (UINT32 npeBaseAddress,
  142. UINT32 npeMemAddress,
  143. UINT32 npeMemData,
  144. BOOL verify);
  145. /* module statistics counters */
  146. typedef struct
  147. {
  148. UINT32 instructionBlocksLoaded;
  149. UINT32 dataBlocksLoaded;
  150. UINT32 stateInfoBlocksLoaded;
  151. UINT32 criticalNpeErrors;
  152. UINT32 criticalMicrocodeErrors;
  153. UINT32 npeStarts;
  154. UINT32 npeStops;
  155. UINT32 npeResets;
  156. } IxNpeDlNpeMgrStats;
  157. /*
  158. * Variable declarations global to this file only. Externs are followed by
  159. * static variables.
  160. */
  161. static IxNpeDlNpeInfo ixNpeDlNpeInfo[] =
  162. {
  163. {
  164. 0,
  165. IX_NPEDL_INS_MEMSIZE_WORDS_NPEA,
  166. IX_NPEDL_DATA_MEMSIZE_WORDS_NPEA
  167. },
  168. {
  169. 0,
  170. IX_NPEDL_INS_MEMSIZE_WORDS_NPEB,
  171. IX_NPEDL_DATA_MEMSIZE_WORDS_NPEB
  172. },
  173. {
  174. 0,
  175. IX_NPEDL_INS_MEMSIZE_WORDS_NPEC,
  176. IX_NPEDL_DATA_MEMSIZE_WORDS_NPEC
  177. }
  178. };
  179. /* contains Reset values for Context Store Registers */
  180. static UINT32 ixNpeDlCtxtRegResetValues[] =
  181. {
  182. IX_NPEDL_CTXT_REG_RESET_STEVT,
  183. IX_NPEDL_CTXT_REG_RESET_STARTPC,
  184. IX_NPEDL_CTXT_REG_RESET_REGMAP,
  185. IX_NPEDL_CTXT_REG_RESET_CINDEX,
  186. };
  187. /* contains Reset values for Context Store Registers */
  188. static IxNpeDlEcsRegResetValue ixNpeDlEcsRegResetValues[] =
  189. {
  190. {IX_NPEDL_ECS_BG_CTXT_REG_0, IX_NPEDL_ECS_BG_CTXT_REG_0_RESET},
  191. {IX_NPEDL_ECS_BG_CTXT_REG_1, IX_NPEDL_ECS_BG_CTXT_REG_1_RESET},
  192. {IX_NPEDL_ECS_BG_CTXT_REG_2, IX_NPEDL_ECS_BG_CTXT_REG_2_RESET},
  193. {IX_NPEDL_ECS_PRI_1_CTXT_REG_0, IX_NPEDL_ECS_PRI_1_CTXT_REG_0_RESET},
  194. {IX_NPEDL_ECS_PRI_1_CTXT_REG_1, IX_NPEDL_ECS_PRI_1_CTXT_REG_1_RESET},
  195. {IX_NPEDL_ECS_PRI_1_CTXT_REG_2, IX_NPEDL_ECS_PRI_1_CTXT_REG_2_RESET},
  196. {IX_NPEDL_ECS_PRI_2_CTXT_REG_0, IX_NPEDL_ECS_PRI_2_CTXT_REG_0_RESET},
  197. {IX_NPEDL_ECS_PRI_2_CTXT_REG_1, IX_NPEDL_ECS_PRI_2_CTXT_REG_1_RESET},
  198. {IX_NPEDL_ECS_PRI_2_CTXT_REG_2, IX_NPEDL_ECS_PRI_2_CTXT_REG_2_RESET},
  199. {IX_NPEDL_ECS_DBG_CTXT_REG_0, IX_NPEDL_ECS_DBG_CTXT_REG_0_RESET},
  200. {IX_NPEDL_ECS_DBG_CTXT_REG_1, IX_NPEDL_ECS_DBG_CTXT_REG_1_RESET},
  201. {IX_NPEDL_ECS_DBG_CTXT_REG_2, IX_NPEDL_ECS_DBG_CTXT_REG_2_RESET},
  202. {IX_NPEDL_ECS_INSTRUCT_REG, IX_NPEDL_ECS_INSTRUCT_REG_RESET}
  203. };
  204. static IxNpeDlNpeMgrStats ixNpeDlNpeMgrStats;
  205. /* Set when NPE register memory has been mapped */
  206. static BOOL ixNpeDlMemInitialised = FALSE;
  207. /*
  208. * static function prototypes.
  209. */
  210. PRIVATE IX_STATUS
  211. ixNpeDlNpeMgrMemLoad (IxNpeDlNpeId npeId, UINT32 npeBaseAddress,
  212. IxNpeDlNpeMgrCodeBlock *codeBlockPtr,
  213. BOOL verify, IxNpeDlNpeMemType npeMemType);
  214. PRIVATE IX_STATUS
  215. ixNpeDlNpeMgrStateInfoLoad (UINT32 npeBaseAddress,
  216. IxNpeDlNpeMgrStateInfoBlock *codeBlockPtr,
  217. BOOL verify);
  218. PRIVATE BOOL
  219. ixNpeDlNpeMgrBitsSetCheck (UINT32 npeBaseAddress, UINT32 regOffset,
  220. UINT32 expectedBitsSet);
  221. PRIVATE UINT32
  222. ixNpeDlNpeMgrBaseAddressGet (IxNpeDlNpeId npeId);
  223. /*
  224. * Function definition: ixNpeDlNpeMgrBaseAddressGet
  225. */
  226. PRIVATE UINT32
  227. ixNpeDlNpeMgrBaseAddressGet (IxNpeDlNpeId npeId)
  228. {
  229. IX_OSAL_ASSERT (ixNpeDlMemInitialised);
  230. return ixNpeDlNpeInfo[npeId].baseAddress;
  231. }
  232. /*
  233. * Function definition: ixNpeDlNpeMgrInit
  234. */
  235. void
  236. ixNpeDlNpeMgrInit (void)
  237. {
  238. /* Only map the memory once */
  239. if (!ixNpeDlMemInitialised)
  240. {
  241. UINT32 virtAddr;
  242. /* map the register memory for NPE-A */
  243. virtAddr = (UINT32) IX_OSAL_MEM_MAP (IX_NPEDL_NPEBASEADDRESS_NPEA,
  244. IX_OSAL_IXP400_NPEA_MAP_SIZE);
  245. IX_OSAL_ASSERT(virtAddr);
  246. ixNpeDlNpeInfo[IX_NPEDL_NPEID_NPEA].baseAddress = virtAddr;
  247. /* map the register memory for NPE-B */
  248. virtAddr = (UINT32) IX_OSAL_MEM_MAP (IX_NPEDL_NPEBASEADDRESS_NPEB,
  249. IX_OSAL_IXP400_NPEB_MAP_SIZE);
  250. IX_OSAL_ASSERT(virtAddr);
  251. ixNpeDlNpeInfo[IX_NPEDL_NPEID_NPEB].baseAddress = virtAddr;
  252. /* map the register memory for NPE-C */
  253. virtAddr = (UINT32) IX_OSAL_MEM_MAP (IX_NPEDL_NPEBASEADDRESS_NPEC,
  254. IX_OSAL_IXP400_NPEC_MAP_SIZE);
  255. IX_OSAL_ASSERT(virtAddr);
  256. ixNpeDlNpeInfo[IX_NPEDL_NPEID_NPEC].baseAddress = virtAddr;
  257. ixNpeDlMemInitialised = TRUE;
  258. }
  259. }
  260. /*
  261. * Function definition: ixNpeDlNpeMgrUninit
  262. */
  263. IX_STATUS
  264. ixNpeDlNpeMgrUninit (void)
  265. {
  266. if (!ixNpeDlMemInitialised)
  267. {
  268. return IX_FAIL;
  269. }
  270. IX_OSAL_MEM_UNMAP (ixNpeDlNpeInfo[IX_NPEDL_NPEID_NPEA].baseAddress);
  271. IX_OSAL_MEM_UNMAP (ixNpeDlNpeInfo[IX_NPEDL_NPEID_NPEB].baseAddress);
  272. IX_OSAL_MEM_UNMAP (ixNpeDlNpeInfo[IX_NPEDL_NPEID_NPEC].baseAddress);
  273. ixNpeDlNpeInfo[IX_NPEDL_NPEID_NPEA].baseAddress = 0;
  274. ixNpeDlNpeInfo[IX_NPEDL_NPEID_NPEB].baseAddress = 0;
  275. ixNpeDlNpeInfo[IX_NPEDL_NPEID_NPEC].baseAddress = 0;
  276. ixNpeDlMemInitialised = FALSE;
  277. return IX_SUCCESS;
  278. }
  279. /*
  280. * Function definition: ixNpeDlNpeMgrImageLoad
  281. */
  282. IX_STATUS
  283. ixNpeDlNpeMgrImageLoad (
  284. IxNpeDlNpeId npeId,
  285. UINT32 *imageCodePtr,
  286. BOOL verify)
  287. {
  288. UINT32 npeBaseAddress;
  289. IxNpeDlNpeMgrDownloadMap *downloadMap;
  290. UINT32 *blockPtr;
  291. UINT32 mapIndex = 0;
  292. IX_STATUS status = IX_SUCCESS;
  293. IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
  294. "Entering ixNpeDlNpeMgrImageLoad\n");
  295. /* get base memory address of NPE from npeId */
  296. npeBaseAddress = ixNpeDlNpeMgrBaseAddressGet (npeId);
  297. /* check execution status of NPE to verify NPE Stop was successful */
  298. if (!ixNpeDlNpeMgrBitsSetCheck (npeBaseAddress, IX_NPEDL_REG_OFFSET_EXCTL,
  299. IX_NPEDL_EXCTL_STATUS_STOP))
  300. {
  301. IX_NPEDL_ERROR_REPORT ("ixNpeDlNpeMgrImageDownload - "
  302. "NPE was not stopped before download\n");
  303. status = IX_FAIL;
  304. }
  305. else
  306. {
  307. /*
  308. * Read Download Map, checking each block type and calling
  309. * appropriate function to perform download
  310. */
  311. downloadMap = (IxNpeDlNpeMgrDownloadMap *) imageCodePtr;
  312. while ((downloadMap->entry[mapIndex].eodmMarker !=
  313. IX_NPEDL_END_OF_DOWNLOAD_MAP)
  314. && (status == IX_SUCCESS))
  315. {
  316. /* calculate pointer to block to be downloaded */
  317. blockPtr = imageCodePtr +
  318. downloadMap->entry[mapIndex].block.offset;
  319. switch (downloadMap->entry[mapIndex].block.type)
  320. {
  321. case IX_NPEDL_BLOCK_TYPE_INSTRUCTION:
  322. status = ixNpeDlNpeMgrMemLoad (npeId, npeBaseAddress,
  323. (IxNpeDlNpeMgrCodeBlock *)blockPtr,
  324. verify,
  325. IX_NPEDL_MEM_TYPE_INSTRUCTION);
  326. break;
  327. case IX_NPEDL_BLOCK_TYPE_DATA:
  328. status = ixNpeDlNpeMgrMemLoad (npeId, npeBaseAddress,
  329. (IxNpeDlNpeMgrCodeBlock *)blockPtr,
  330. verify, IX_NPEDL_MEM_TYPE_DATA);
  331. break;
  332. case IX_NPEDL_BLOCK_TYPE_STATE:
  333. status = ixNpeDlNpeMgrStateInfoLoad (npeBaseAddress,
  334. (IxNpeDlNpeMgrStateInfoBlock *) blockPtr,
  335. verify);
  336. break;
  337. default:
  338. IX_NPEDL_ERROR_REPORT ("ixNpeDlNpeMgrImageLoad: "
  339. "unknown block type in download map\n");
  340. status = IX_NPEDL_CRITICAL_MICROCODE_ERR;
  341. ixNpeDlNpeMgrStats.criticalMicrocodeErrors++;
  342. break;
  343. }
  344. mapIndex++;
  345. }/* loop: for each entry in download map, while status == SUCCESS */
  346. }/* condition: NPE stopped before attempting download */
  347. IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
  348. "Exiting ixNpeDlNpeMgrImageLoad : status = %d\n",
  349. status);
  350. return status;
  351. }
  352. /*
  353. * Function definition: ixNpeDlNpeMgrMemLoad
  354. */
  355. PRIVATE IX_STATUS
  356. ixNpeDlNpeMgrMemLoad (
  357. IxNpeDlNpeId npeId,
  358. UINT32 npeBaseAddress,
  359. IxNpeDlNpeMgrCodeBlock *blockPtr,
  360. BOOL verify,
  361. IxNpeDlNpeMemType npeMemType)
  362. {
  363. UINT32 npeMemAddress;
  364. UINT32 blockSize;
  365. UINT32 memSize = 0;
  366. IxNpeDlNpeMgrMemWrite memWriteFunc = NULL;
  367. UINT32 localIndex = 0;
  368. IX_STATUS status = IX_SUCCESS;
  369. IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
  370. "Entering ixNpeDlNpeMgrMemLoad\n");
  371. /*
  372. * select NPE EXCTL reg read/write commands depending on memory
  373. * type (instruction/data) to be accessed
  374. */
  375. if (npeMemType == IX_NPEDL_MEM_TYPE_INSTRUCTION)
  376. {
  377. memSize = ixNpeDlNpeInfo[npeId].insMemSize;
  378. memWriteFunc = (IxNpeDlNpeMgrMemWrite) ixNpeDlNpeMgrInsMemWrite;
  379. }
  380. else if (npeMemType == IX_NPEDL_MEM_TYPE_DATA)
  381. {
  382. memSize = ixNpeDlNpeInfo[npeId].dataMemSize;
  383. memWriteFunc = (IxNpeDlNpeMgrMemWrite) ixNpeDlNpeMgrDataMemWrite;
  384. }
  385. /*
  386. * NPE memory is loaded contiguously from each block, so only address
  387. * of 1st word in block is needed
  388. */
  389. npeMemAddress = blockPtr->npeMemAddress;
  390. /* number of words of instruction/data microcode in block to download */
  391. blockSize = blockPtr->size;
  392. if ((npeMemAddress + blockSize) > memSize)
  393. {
  394. IX_NPEDL_ERROR_REPORT ("ixNpeDlNpeMgrMemLoad: "
  395. "Block size too big for NPE memory\n");
  396. status = IX_NPEDL_CRITICAL_MICROCODE_ERR;
  397. ixNpeDlNpeMgrStats.criticalMicrocodeErrors++;
  398. }
  399. else
  400. {
  401. for (localIndex = 0; localIndex < blockSize; localIndex++)
  402. {
  403. status = memWriteFunc (npeBaseAddress, npeMemAddress,
  404. blockPtr->data[localIndex], verify);
  405. if (status != IX_SUCCESS)
  406. {
  407. IX_NPEDL_ERROR_REPORT ("ixNpeDlNpeMgrMemLoad: "
  408. "write to NPE memory failed\n");
  409. status = IX_NPEDL_CRITICAL_NPE_ERR;
  410. ixNpeDlNpeMgrStats.criticalNpeErrors++;
  411. break; /* abort download */
  412. }
  413. /* increment target (word)address in NPE memory */
  414. npeMemAddress++;
  415. }
  416. }/* condition: block size will fit in NPE memory */
  417. if (status == IX_SUCCESS)
  418. {
  419. if (npeMemType == IX_NPEDL_MEM_TYPE_INSTRUCTION)
  420. {
  421. ixNpeDlNpeMgrStats.instructionBlocksLoaded++;
  422. }
  423. else if (npeMemType == IX_NPEDL_MEM_TYPE_DATA)
  424. {
  425. ixNpeDlNpeMgrStats.dataBlocksLoaded++;
  426. }
  427. }
  428. IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
  429. "Exiting ixNpeDlNpeMgrMemLoad : status = %d\n", status);
  430. return status;
  431. }
  432. /*
  433. * Function definition: ixNpeDlNpeMgrStateInfoLoad
  434. */
  435. PRIVATE IX_STATUS
  436. ixNpeDlNpeMgrStateInfoLoad (
  437. UINT32 npeBaseAddress,
  438. IxNpeDlNpeMgrStateInfoBlock *blockPtr,
  439. BOOL verify)
  440. {
  441. UINT32 blockSize;
  442. UINT32 ctxtRegAddrInfo;
  443. UINT32 ctxtRegVal;
  444. IxNpeDlCtxtRegNum ctxtReg; /* identifies Context Store reg (0-3) */
  445. UINT32 ctxtNum; /* identifies Context number (0-16) */
  446. UINT32 i;
  447. IX_STATUS status = IX_SUCCESS;
  448. IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
  449. "Entering ixNpeDlNpeMgrStateInfoLoad\n");
  450. /* block size contains number of words of state-info in block */
  451. blockSize = blockPtr->size;
  452. ixNpeDlNpeMgrDebugInstructionPreExec (npeBaseAddress);
  453. /* for each state-info context register entry in block */
  454. for (i = 0; i < (blockSize/IX_NPEDL_STATE_INFO_ENTRY_SIZE); i++)
  455. {
  456. /* each state-info entry is 2 words (address, value) in length */
  457. ctxtRegAddrInfo = (blockPtr->ctxtRegEntry[i]).addressInfo;
  458. ctxtRegVal = (blockPtr->ctxtRegEntry[i]).value;
  459. ctxtReg = (ctxtRegAddrInfo & IX_NPEDL_MASK_STATE_ADDR_CTXT_REG);
  460. ctxtNum = (ctxtRegAddrInfo & IX_NPEDL_MASK_STATE_ADDR_CTXT_NUM) >>
  461. IX_NPEDL_OFFSET_STATE_ADDR_CTXT_NUM;
  462. /* error-check Context Register No. and Context Number values */
  463. /* NOTE that there is no STEVT register for Context 0 */
  464. if ((ctxtReg < 0) ||
  465. (ctxtReg >= IX_NPEDL_CTXT_REG_MAX) ||
  466. (ctxtNum > IX_NPEDL_CTXT_NUM_MAX) ||
  467. ((ctxtNum == 0) && (ctxtReg == IX_NPEDL_CTXT_REG_STEVT)))
  468. {
  469. IX_NPEDL_ERROR_REPORT ("ixNpeDlNpeMgrStateInfoLoad: "
  470. "invalid Context Register Address\n");
  471. status = IX_NPEDL_CRITICAL_MICROCODE_ERR;
  472. ixNpeDlNpeMgrStats.criticalMicrocodeErrors++;
  473. break; /* abort download */
  474. }
  475. status = ixNpeDlNpeMgrCtxtRegWrite (npeBaseAddress, ctxtNum, ctxtReg,
  476. ctxtRegVal, verify);
  477. if (status != IX_SUCCESS)
  478. {
  479. IX_NPEDL_ERROR_REPORT ("ixNpeDlNpeMgrStateInfoLoad: "
  480. "write of state-info to NPE failed\n");
  481. status = IX_NPEDL_CRITICAL_NPE_ERR;
  482. ixNpeDlNpeMgrStats.criticalNpeErrors++;
  483. break; /* abort download */
  484. }
  485. }/* loop: for each context reg entry in State Info block */
  486. ixNpeDlNpeMgrDebugInstructionPostExec (npeBaseAddress);
  487. if (status == IX_SUCCESS)
  488. {
  489. ixNpeDlNpeMgrStats.stateInfoBlocksLoaded++;
  490. }
  491. IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
  492. "Exiting ixNpeDlNpeMgrStateInfoLoad : status = %d\n",
  493. status);
  494. return status;
  495. }
  496. /*
  497. * Function definition: ixNpeDlNpeMgrNpeReset
  498. */
  499. IX_STATUS
  500. ixNpeDlNpeMgrNpeReset (
  501. IxNpeDlNpeId npeId)
  502. {
  503. UINT32 npeBaseAddress;
  504. IxNpeDlCtxtRegNum ctxtReg; /* identifies Context Store reg (0-3) */
  505. UINT32 ctxtNum; /* identifies Context number (0-16) */
  506. UINT32 regAddr;
  507. UINT32 regVal;
  508. UINT32 localIndex;
  509. UINT32 indexMax;
  510. IX_STATUS status = IX_SUCCESS;
  511. IxFeatureCtrlReg unitFuseReg;
  512. UINT32 ixNpeConfigCtrlRegVal;
  513. IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
  514. "Entering ixNpeDlNpeMgrNpeReset\n");
  515. /* get base memory address of NPE from npeId */
  516. npeBaseAddress = ixNpeDlNpeMgrBaseAddressGet (npeId);
  517. /* pre-store the NPE Config Control Register Value */
  518. IX_NPEDL_REG_READ (npeBaseAddress, IX_NPEDL_REG_OFFSET_CTL, &ixNpeConfigCtrlRegVal);
  519. ixNpeConfigCtrlRegVal |= 0x3F000000;
  520. /* disable the parity interrupt */
  521. IX_NPEDL_REG_WRITE (npeBaseAddress, IX_NPEDL_REG_OFFSET_CTL, (ixNpeConfigCtrlRegVal & IX_NPEDL_PARITY_BIT_MASK));
  522. ixNpeDlNpeMgrDebugInstructionPreExec (npeBaseAddress);
  523. /*
  524. * clear the FIFOs
  525. */
  526. while (ixNpeDlNpeMgrBitsSetCheck (npeBaseAddress,
  527. IX_NPEDL_REG_OFFSET_WFIFO,
  528. IX_NPEDL_MASK_WFIFO_VALID))
  529. {
  530. /* read from the Watch-point FIFO until empty */
  531. IX_NPEDL_REG_READ (npeBaseAddress, IX_NPEDL_REG_OFFSET_WFIFO,
  532. &regVal);
  533. }
  534. while (ixNpeDlNpeMgrBitsSetCheck (npeBaseAddress,
  535. IX_NPEDL_REG_OFFSET_STAT,
  536. IX_NPEDL_MASK_STAT_OFNE))
  537. {
  538. /* read from the outFIFO until empty */
  539. IX_NPEDL_REG_READ (npeBaseAddress, IX_NPEDL_REG_OFFSET_FIFO,
  540. &regVal);
  541. }
  542. while (ixNpeDlNpeMgrBitsSetCheck (npeBaseAddress,
  543. IX_NPEDL_REG_OFFSET_STAT,
  544. IX_NPEDL_MASK_STAT_IFNE))
  545. {
  546. /*
  547. * step execution of the NPE intruction to read inFIFO using
  548. * the Debug Executing Context stack
  549. */
  550. status = ixNpeDlNpeMgrDebugInstructionExec (npeBaseAddress,
  551. IX_NPEDL_INSTR_RD_FIFO, 0, 0);
  552. if (IX_SUCCESS != status)
  553. {
  554. return status;
  555. }
  556. }
  557. /*
  558. * Reset the mailbox reg
  559. */
  560. /* ...from XScale side */
  561. IX_NPEDL_REG_WRITE (npeBaseAddress, IX_NPEDL_REG_OFFSET_MBST,
  562. IX_NPEDL_REG_RESET_MBST);
  563. /* ...from NPE side */
  564. status = ixNpeDlNpeMgrDebugInstructionExec (npeBaseAddress,
  565. IX_NPEDL_INSTR_RESET_MBOX, 0, 0);
  566. if (IX_SUCCESS != status)
  567. {
  568. return status;
  569. }
  570. /*
  571. * Reset the physical registers in the NPE register file:
  572. * Note: no need to save/restore REGMAP for Context 0 here
  573. * since all Context Store regs are reset in subsequent code
  574. */
  575. for (regAddr = 0;
  576. (regAddr < IX_NPEDL_TOTAL_NUM_PHYS_REG) && (status != IX_FAIL);
  577. regAddr++)
  578. {
  579. /* for each physical register in the NPE reg file, write 0 : */
  580. status = ixNpeDlNpeMgrPhysicalRegWrite (npeBaseAddress, regAddr,
  581. 0, TRUE);
  582. if (status != IX_SUCCESS)
  583. {
  584. return status; /* abort reset */
  585. }
  586. }
  587. /*
  588. * Reset the context store:
  589. */
  590. for (ctxtNum = IX_NPEDL_CTXT_NUM_MIN;
  591. ctxtNum <= IX_NPEDL_CTXT_NUM_MAX; ctxtNum++)
  592. {
  593. /* set each context's Context Store registers to reset values: */
  594. for (ctxtReg = 0; ctxtReg < IX_NPEDL_CTXT_REG_MAX; ctxtReg++)
  595. {
  596. /* NOTE that there is no STEVT register for Context 0 */
  597. if (!((ctxtNum == 0) && (ctxtReg == IX_NPEDL_CTXT_REG_STEVT)))
  598. {
  599. regVal = ixNpeDlCtxtRegResetValues[ctxtReg];
  600. status = ixNpeDlNpeMgrCtxtRegWrite (npeBaseAddress, ctxtNum,
  601. ctxtReg, regVal, TRUE);
  602. if (status != IX_SUCCESS)
  603. {
  604. return status; /* abort reset */
  605. }
  606. }
  607. }
  608. }
  609. ixNpeDlNpeMgrDebugInstructionPostExec (npeBaseAddress);
  610. /* write Reset values to Execution Context Stack registers */
  611. indexMax = sizeof (ixNpeDlEcsRegResetValues) /
  612. sizeof (IxNpeDlEcsRegResetValue);
  613. for (localIndex = 0; localIndex < indexMax; localIndex++)
  614. {
  615. regAddr = ixNpeDlEcsRegResetValues[localIndex].regAddr;
  616. regVal = ixNpeDlEcsRegResetValues[localIndex].regResetVal;
  617. ixNpeDlNpeMgrExecAccRegWrite (npeBaseAddress, regAddr, regVal);
  618. }
  619. /* clear the profile counter */
  620. ixNpeDlNpeMgrCommandIssue (npeBaseAddress,
  621. IX_NPEDL_EXCTL_CMD_CLR_PROFILE_CNT);
  622. /* clear registers EXCT, AP0, AP1, AP2 and AP3 */
  623. for (regAddr = IX_NPEDL_REG_OFFSET_EXCT;
  624. regAddr <= IX_NPEDL_REG_OFFSET_AP3;
  625. regAddr += IX_NPEDL_BYTES_PER_WORD)
  626. {
  627. IX_NPEDL_REG_WRITE (npeBaseAddress, regAddr, 0);
  628. }
  629. /* Reset the Watch-count register */
  630. IX_NPEDL_REG_WRITE (npeBaseAddress, IX_NPEDL_REG_OFFSET_WC, 0);
  631. /*
  632. * WR IXA00055043 - Remove IMEM Parity Introduced by NPE Reset Operation
  633. */
  634. /*
  635. * Call the feature control API to fused out and reset the NPE and its
  636. * coprocessor - to reset internal states and remove parity error
  637. */
  638. unitFuseReg = ixFeatureCtrlRead ();
  639. unitFuseReg |= (IX_NPEDL_RESET_NPE_PARITY << npeId);
  640. ixFeatureCtrlWrite (unitFuseReg);
  641. /* call the feature control API to un-fused and un-reset the NPE & COP */
  642. unitFuseReg &= (~(IX_NPEDL_RESET_NPE_PARITY << npeId));
  643. ixFeatureCtrlWrite (unitFuseReg);
  644. /*
  645. * Call NpeMgr function to stop the NPE again after the Feature Control
  646. * has unfused and Un-Reset the NPE and its associated Coprocessors
  647. */
  648. status = ixNpeDlNpeMgrNpeStop (npeId);
  649. /* restore NPE configuration bus Control Register - Parity Settings */
  650. IX_NPEDL_REG_WRITE (npeBaseAddress, IX_NPEDL_REG_OFFSET_CTL,
  651. (ixNpeConfigCtrlRegVal & IX_NPEDL_CONFIG_CTRL_REG_MASK));
  652. ixNpeDlNpeMgrStats.npeResets++;
  653. IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
  654. "Exiting ixNpeDlNpeMgrNpeReset : status = %d\n", status);
  655. return status;
  656. }
  657. /*
  658. * Function definition: ixNpeDlNpeMgrNpeStart
  659. */
  660. IX_STATUS
  661. ixNpeDlNpeMgrNpeStart (
  662. IxNpeDlNpeId npeId)
  663. {
  664. UINT32 npeBaseAddress;
  665. UINT32 ecsRegVal;
  666. BOOL npeRunning;
  667. IX_STATUS status = IX_SUCCESS;
  668. IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
  669. "Entering ixNpeDlNpeMgrNpeStart\n");
  670. /* get base memory address of NPE from npeId */
  671. npeBaseAddress = ixNpeDlNpeMgrBaseAddressGet (npeId);
  672. /*
  673. * ensure only Background Context Stack Level is Active by turning off
  674. * the Active bit in each of the other Executing Context Stack levels
  675. */
  676. ecsRegVal = ixNpeDlNpeMgrExecAccRegRead (npeBaseAddress,
  677. IX_NPEDL_ECS_PRI_1_CTXT_REG_0);
  678. ecsRegVal &= ~IX_NPEDL_MASK_ECS_REG_0_ACTIVE;
  679. ixNpeDlNpeMgrExecAccRegWrite (npeBaseAddress, IX_NPEDL_ECS_PRI_1_CTXT_REG_0,
  680. ecsRegVal);
  681. ecsRegVal = ixNpeDlNpeMgrExecAccRegRead (npeBaseAddress,
  682. IX_NPEDL_ECS_PRI_2_CTXT_REG_0);
  683. ecsRegVal &= ~IX_NPEDL_MASK_ECS_REG_0_ACTIVE;
  684. ixNpeDlNpeMgrExecAccRegWrite (npeBaseAddress, IX_NPEDL_ECS_PRI_2_CTXT_REG_0,
  685. ecsRegVal);
  686. ecsRegVal = ixNpeDlNpeMgrExecAccRegRead (npeBaseAddress,
  687. IX_NPEDL_ECS_DBG_CTXT_REG_0);
  688. ecsRegVal &= ~IX_NPEDL_MASK_ECS_REG_0_ACTIVE;
  689. ixNpeDlNpeMgrExecAccRegWrite (npeBaseAddress, IX_NPEDL_ECS_DBG_CTXT_REG_0,
  690. ecsRegVal);
  691. /* clear the pipeline */
  692. ixNpeDlNpeMgrCommandIssue (npeBaseAddress, IX_NPEDL_EXCTL_CMD_NPE_CLR_PIPE);
  693. /* start NPE execution by issuing command through EXCTL register on NPE */
  694. ixNpeDlNpeMgrCommandIssue (npeBaseAddress, IX_NPEDL_EXCTL_CMD_NPE_START);
  695. /*
  696. * check execution status of NPE to verify NPE Start operation was
  697. * successful
  698. */
  699. npeRunning = ixNpeDlNpeMgrBitsSetCheck (npeBaseAddress,
  700. IX_NPEDL_REG_OFFSET_EXCTL,
  701. IX_NPEDL_EXCTL_STATUS_RUN);
  702. if (npeRunning)
  703. {
  704. ixNpeDlNpeMgrStats.npeStarts++;
  705. }
  706. else
  707. {
  708. IX_NPEDL_ERROR_REPORT ("ixNpeDlNpeMgrNpeStart: "
  709. "failed to start NPE execution\n");
  710. status = IX_FAIL;
  711. }
  712. IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
  713. "Exiting ixNpeDlNpeMgrNpeStart : status = %d\n", status);
  714. return status;
  715. }
  716. /*
  717. * Function definition: ixNpeDlNpeMgrNpeStop
  718. */
  719. IX_STATUS
  720. ixNpeDlNpeMgrNpeStop (
  721. IxNpeDlNpeId npeId)
  722. {
  723. UINT32 npeBaseAddress;
  724. IX_STATUS status = IX_SUCCESS;
  725. IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
  726. "Entering ixNpeDlNpeMgrNpeStop\n");
  727. /* get base memory address of NPE from npeId */
  728. npeBaseAddress = ixNpeDlNpeMgrBaseAddressGet (npeId);
  729. /* stop NPE execution by issuing command through EXCTL register on NPE */
  730. ixNpeDlNpeMgrCommandIssue (npeBaseAddress, IX_NPEDL_EXCTL_CMD_NPE_STOP);
  731. /* verify that NPE Stop was successful */
  732. if (! ixNpeDlNpeMgrBitsSetCheck (npeBaseAddress, IX_NPEDL_REG_OFFSET_EXCTL,
  733. IX_NPEDL_EXCTL_STATUS_STOP))
  734. {
  735. IX_NPEDL_ERROR_REPORT ("ixNpeDlNpeMgrNpeStop: "
  736. "failed to stop NPE execution\n");
  737. status = IX_FAIL;
  738. }
  739. ixNpeDlNpeMgrStats.npeStops++;
  740. IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
  741. "Exiting ixNpeDlNpeMgrNpeStop : status = %d\n", status);
  742. return status;
  743. }
  744. /*
  745. * Function definition: ixNpeDlNpeMgrBitsSetCheck
  746. */
  747. PRIVATE BOOL
  748. ixNpeDlNpeMgrBitsSetCheck (
  749. UINT32 npeBaseAddress,
  750. UINT32 regOffset,
  751. UINT32 expectedBitsSet)
  752. {
  753. UINT32 regVal;
  754. IX_NPEDL_REG_READ (npeBaseAddress, regOffset, &regVal);
  755. return expectedBitsSet == (expectedBitsSet & regVal);
  756. }
  757. /*
  758. * Function definition: ixNpeDlNpeMgrStatsShow
  759. */
  760. void
  761. ixNpeDlNpeMgrStatsShow (void)
  762. {
  763. ixOsalLog (IX_OSAL_LOG_LVL_USER,
  764. IX_OSAL_LOG_DEV_STDOUT,
  765. "\nixNpeDlNpeMgrStatsShow:\n"
  766. "\tInstruction Blocks loaded: %u\n"
  767. "\tData Blocks loaded: %u\n"
  768. "\tState Information Blocks loaded: %u\n"
  769. "\tCritical NPE errors: %u\n"
  770. "\tCritical Microcode errors: %u\n",
  771. ixNpeDlNpeMgrStats.instructionBlocksLoaded,
  772. ixNpeDlNpeMgrStats.dataBlocksLoaded,
  773. ixNpeDlNpeMgrStats.stateInfoBlocksLoaded,
  774. ixNpeDlNpeMgrStats.criticalNpeErrors,
  775. ixNpeDlNpeMgrStats.criticalMicrocodeErrors,
  776. 0);
  777. ixOsalLog (IX_OSAL_LOG_LVL_USER,
  778. IX_OSAL_LOG_DEV_STDOUT,
  779. "\tSuccessful NPE Starts: %u\n"
  780. "\tSuccessful NPE Stops: %u\n"
  781. "\tSuccessful NPE Resets: %u\n\n",
  782. ixNpeDlNpeMgrStats.npeStarts,
  783. ixNpeDlNpeMgrStats.npeStops,
  784. ixNpeDlNpeMgrStats.npeResets,
  785. 0,0,0);
  786. ixNpeDlNpeMgrUtilsStatsShow ();
  787. }
  788. /*
  789. * Function definition: ixNpeDlNpeMgrStatsReset
  790. */
  791. void
  792. ixNpeDlNpeMgrStatsReset (void)
  793. {
  794. ixNpeDlNpeMgrStats.instructionBlocksLoaded = 0;
  795. ixNpeDlNpeMgrStats.dataBlocksLoaded = 0;
  796. ixNpeDlNpeMgrStats.stateInfoBlocksLoaded = 0;
  797. ixNpeDlNpeMgrStats.criticalNpeErrors = 0;
  798. ixNpeDlNpeMgrStats.criticalMicrocodeErrors = 0;
  799. ixNpeDlNpeMgrStats.npeStarts = 0;
  800. ixNpeDlNpeMgrStats.npeStops = 0;
  801. ixNpeDlNpeMgrStats.npeResets = 0;
  802. ixNpeDlNpeMgrUtilsStatsReset ();
  803. }