IxNpeDlNpeMgr.c 27 KB

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