xipif_v1_23_b.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. /* $Id: xipif_v1_23_b.c,v 1.1 2002/03/18 23:24:52 linnj Exp $ */
  2. /******************************************************************************
  3. *
  4. * XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS"
  5. * AS A COURTESY TO YOU, SOLELY FOR USE IN DEVELOPING PROGRAMS AND
  6. * SOLUTIONS FOR XILINX DEVICES. BY PROVIDING THIS DESIGN, CODE,
  7. * OR INFORMATION AS ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE,
  8. * APPLICATION OR STANDARD, XILINX IS MAKING NO REPRESENTATION
  9. * THAT THIS IMPLEMENTATION IS FREE FROM ANY CLAIMS OF INFRINGEMENT,
  10. * AND YOU ARE RESPONSIBLE FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE
  11. * FOR YOUR IMPLEMENTATION. XILINX EXPRESSLY DISCLAIMS ANY
  12. * WARRANTY WHATSOEVER WITH RESPECT TO THE ADEQUACY OF THE
  13. * IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OR
  14. * REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE FROM CLAIMS OF
  15. * INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  16. * FOR A PARTICULAR PURPOSE.
  17. *
  18. * (c) Copyright 2002 Xilinx Inc.
  19. * All rights reserved.
  20. *
  21. ******************************************************************************/
  22. /******************************************************************************
  23. *
  24. * FILENAME:
  25. *
  26. * xipif.c
  27. *
  28. * DESCRIPTION:
  29. *
  30. * This file contains the implementation of the XIpIf component. The
  31. * XIpIf component encapsulates the IPIF, which is the standard interface
  32. * that IP must adhere to when connecting to a bus. The purpose of this
  33. * component is to encapsulate the IPIF processing such that maintainability
  34. * is increased. This component does not provide a lot of abstraction from
  35. * from the details of the IPIF as it is considered a building block for
  36. * device drivers. A device driver designer must be familiar with the
  37. * details of the IPIF hardware to use this component.
  38. *
  39. * The IPIF hardware provides a building block for all hardware devices such
  40. * that each device does not need to reimplement these building blocks. The
  41. * IPIF contains other building blocks, such as FIFOs and DMA channels, which
  42. * are also common to many devices. These blocks are implemented as separate
  43. * hardware blocks and instantiated within the IPIF. The primary hardware of
  44. * the IPIF which is implemented by this software component is the interrupt
  45. * architecture. Since there are many blocks of a device which may generate
  46. * interrupts, all the interrupt processing is contained in the common part
  47. * of the device, the IPIF. This interrupt processing is for the device level
  48. * only and does not include any processing for the interrupt controller.
  49. *
  50. * A device is a mechanism such as an Ethernet MAC. The device is made
  51. * up of several parts which include an IPIF and the IP. The IPIF contains most
  52. * of the device infrastructure which is common to all devices, such as
  53. * interrupt processing, DMA channels, and FIFOs. The infrastructure may also
  54. * be referred to as IPIF internal blocks since they are part of the IPIF and
  55. * are separate blocks that can be selected based upon the needs of the device.
  56. * The IP of the device is the logic that is unique to the device and interfaces
  57. * to the IPIF of the device.
  58. *
  59. * In general, there are two levels of registers within the IPIF. The first
  60. * level, referred to as the device level, contains registers which are for the
  61. * entire device. The second level, referred to as the IP level, contains
  62. * registers which are specific to the IP of the device. The two levels of
  63. * registers are designed to be hierarchical such that the device level is
  64. * is a more general register set above the more specific registers of the IP.
  65. * The IP level of registers provides functionality which is typically common
  66. * across all devices and allows IP designers to focus on the unique aspects
  67. * of the IP.
  68. *
  69. * The interrupt registers of the IPIF are parameterizable such that the only
  70. * the number of bits necessary for the device are implemented. The functions
  71. * of this component do not attempt to validate that the passed in arguments are
  72. * valid based upon the number of implemented bits. This is necessary to
  73. * maintain the level of performance required for the common components. Bits
  74. * of the registers are assigned starting at the least significant bit of the
  75. * registers.
  76. *
  77. * Critical Sections
  78. *
  79. * It is the responsibility of the device driver designer to use critical
  80. * sections as necessary when calling functions of the IPIF. This component
  81. * does not use critical sections and it does access registers using
  82. * read-modify-write operations. Calls to IPIF functions from a main thread
  83. * and from an interrupt context could produce unpredictable behavior such that
  84. * the caller must provide the appropriate critical sections.
  85. *
  86. * Mutual Exclusion
  87. *
  88. * The functions of the IPIF are not thread safe such that the caller of all
  89. * functions is responsible for ensuring mutual exclusion for an IPIF. Mutual
  90. * exclusion across multiple IPIF components is not necessary.
  91. *
  92. * NOTES:
  93. *
  94. * None.
  95. *
  96. * MODIFICATION HISTORY:
  97. *
  98. * Ver Who Date Changes
  99. * ----- ---- -------- -----------------------------------------------
  100. * 1.23b jhl 02/27/01 Repartioned to reduce size
  101. *
  102. ******************************************************************************/
  103. /***************************** Include Files *********************************/
  104. #include "xipif_v1_23_b.h"
  105. #include "xio.h"
  106. /************************** Constant Definitions *****************************/
  107. /* the following constant is used to generate bit masks for register testing
  108. * in the self test functions, it defines the starting bit mask that is to be
  109. * shifted from the LSB to MSB in creating a register test mask
  110. */
  111. #define XIIF_V123B_FIRST_BIT_MASK 1UL
  112. /**************************** Type Definitions *******************************/
  113. /***************** Macros (Inline Functions) Definitions *********************/
  114. /************************** Variable Definitions *****************************/
  115. /************************** Function Prototypes ******************************/
  116. static XStatus IpIntrSelfTest(u32 RegBaseAddress, u32 IpRegistersWidth);
  117. /******************************************************************************
  118. *
  119. * FUNCTION:
  120. *
  121. * XIpIf_SelfTest
  122. *
  123. * DESCRIPTION:
  124. *
  125. * This function performs a self test on the specified IPIF component. Many
  126. * of the registers in the IPIF are tested to ensure proper operation. This
  127. * function is destructive because the IPIF is reset at the start of the test
  128. * and at the end of the test to ensure predictable results. The IPIF reset
  129. * also resets the entire device that uses the IPIF. This function exits with
  130. * all interrupts for the device disabled.
  131. *
  132. * ARGUMENTS:
  133. *
  134. * InstancePtr points to the XIpIf to operate on.
  135. *
  136. * DeviceRegistersWidth contains the number of bits in the device interrupt
  137. * registers. The hardware is parameterizable such that only the number of bits
  138. * necessary to support a device are implemented. This value must be between 0
  139. * and 32 with 0 indicating there are no device interrupt registers used.
  140. *
  141. * IpRegistersWidth contains the number of bits in the IP interrupt registers
  142. * of the device. The hardware is parameterizable such that only the number of
  143. * bits necessary to support a device are implemented. This value must be
  144. * between 0 and 32 with 0 indicating there are no IP interrupt registers used.
  145. *
  146. * RETURN VALUE:
  147. *
  148. * A value of XST_SUCCESS indicates the test was successful with no errors.
  149. * Any one of the following error values may also be returned.
  150. *
  151. * XST_IPIF_RESET_REGISTER_ERROR The value of a register at reset was
  152. * not valid
  153. * XST_IPIF_IP_STATUS_ERROR A write to the IP interrupt status
  154. * register did not read back correctly
  155. * XST_IPIF_IP_ACK_ERROR One or more bits in the IP interrupt
  156. * status register did not reset when acked
  157. * XST_IPIF_IP_ENABLE_ERROR The IP interrupt enable register
  158. * did not read back correctly based upon
  159. * what was written to it
  160. *
  161. * NOTES:
  162. *
  163. * None.
  164. *
  165. ******************************************************************************/
  166. /* the following constant defines the maximum number of bits which may be
  167. * used in the registers at the device and IP levels, this is based upon the
  168. * number of bits available in the registers
  169. */
  170. #define XIIF_V123B_MAX_REG_BIT_COUNT 32
  171. XStatus
  172. XIpIfV123b_SelfTest(u32 RegBaseAddress, u8 IpRegistersWidth)
  173. {
  174. XStatus Status;
  175. /* assert to verify arguments are valid */
  176. XASSERT_NONVOID(IpRegistersWidth <= XIIF_V123B_MAX_REG_BIT_COUNT);
  177. /* reset the IPIF such that it's in a known state before the test
  178. * and interrupts are globally disabled
  179. */
  180. XIIF_V123B_RESET(RegBaseAddress);
  181. /* perform the self test on the IP interrupt registers, if
  182. * it is not successful exit with the status
  183. */
  184. Status = IpIntrSelfTest(RegBaseAddress, IpRegistersWidth);
  185. if (Status != XST_SUCCESS) {
  186. return Status;
  187. }
  188. /* reset the IPIF such that it's in a known state before exiting test */
  189. XIIF_V123B_RESET(RegBaseAddress);
  190. /* reaching this point means there were no errors, return success */
  191. return XST_SUCCESS;
  192. }
  193. /******************************************************************************
  194. *
  195. * FUNCTION:
  196. *
  197. * IpIntrSelfTest
  198. *
  199. * DESCRIPTION:
  200. *
  201. * Perform a self test on the IP interrupt registers of the IPIF. This
  202. * function modifies registers of the IPIF such that they are not guaranteed
  203. * to be in the same state when it returns. Any bits in the IP interrupt
  204. * status register which are set are assumed to be set by default after a reset
  205. * and are not tested in the test.
  206. *
  207. * ARGUMENTS:
  208. *
  209. * InstancePtr points to the XIpIf to operate on.
  210. *
  211. * IpRegistersWidth contains the number of bits in the IP interrupt registers
  212. * of the device. The hardware is parameterizable such that only the number of
  213. * bits necessary to support a device are implemented. This value must be
  214. * between 0 and 32 with 0 indicating there are no IP interrupt registers used.
  215. *
  216. * RETURN VALUE:
  217. *
  218. * A status indicating XST_SUCCESS if the test was successful. Otherwise, one
  219. * of the following values is returned.
  220. *
  221. * XST_IPIF_RESET_REGISTER_ERROR The value of a register at reset was
  222. * not valid
  223. * XST_IPIF_IP_STATUS_ERROR A write to the IP interrupt status
  224. * register did not read back correctly
  225. * XST_IPIF_IP_ACK_ERROR One or more bits in the IP status
  226. * register did not reset when acked
  227. * XST_IPIF_IP_ENABLE_ERROR The IP interrupt enable register
  228. * did not read back correctly based upon
  229. * what was written to it
  230. * NOTES:
  231. *
  232. * None.
  233. *
  234. ******************************************************************************/
  235. static XStatus
  236. IpIntrSelfTest(u32 RegBaseAddress, u32 IpRegistersWidth)
  237. {
  238. /* ensure that the IP interrupt interrupt enable register is zero
  239. * as it should be at reset, the interrupt status is dependent upon the
  240. * IP such that it's reset value is not known
  241. */
  242. if (XIIF_V123B_READ_IIER(RegBaseAddress) != 0) {
  243. return XST_IPIF_RESET_REGISTER_ERROR;
  244. }
  245. /* if there are any used IP interrupts, then test all of the interrupt
  246. * bits in all testable registers
  247. */
  248. if (IpRegistersWidth > 0) {
  249. u32 BitCount;
  250. u32 IpInterruptMask = XIIF_V123B_FIRST_BIT_MASK;
  251. u32 Mask = XIIF_V123B_FIRST_BIT_MASK; /* bits assigned MSB to LSB */
  252. u32 InterruptStatus;
  253. /* generate the register masks to be used for IP register tests, the
  254. * number of bits supported by the hardware is parameterizable such
  255. * that only that number of bits are implemented in the registers, the
  256. * bits are allocated starting at the MSB of the registers
  257. */
  258. for (BitCount = 1; BitCount < IpRegistersWidth; BitCount++) {
  259. Mask = Mask << 1;
  260. IpInterruptMask |= Mask;
  261. }
  262. /* get the current IP interrupt status register contents, any bits
  263. * already set must default to 1 at reset in the device and these
  264. * bits can't be tested in the following test, remove these bits from
  265. * the mask that was generated for the test
  266. */
  267. InterruptStatus = XIIF_V123B_READ_IISR(RegBaseAddress);
  268. IpInterruptMask &= ~InterruptStatus;
  269. /* set the bits in the device status register and verify them by reading
  270. * the register again, all bits of the register are latched
  271. */
  272. XIIF_V123B_WRITE_IISR(RegBaseAddress, IpInterruptMask);
  273. InterruptStatus = XIIF_V123B_READ_IISR(RegBaseAddress);
  274. if ((InterruptStatus & IpInterruptMask) != IpInterruptMask)
  275. {
  276. return XST_IPIF_IP_STATUS_ERROR;
  277. }
  278. /* test to ensure that the bits set in the IP interrupt status register
  279. * can be cleared by acknowledging them in the IP interrupt status
  280. * register then read it again and verify it was cleared
  281. */
  282. XIIF_V123B_WRITE_IISR(RegBaseAddress, IpInterruptMask);
  283. InterruptStatus = XIIF_V123B_READ_IISR(RegBaseAddress);
  284. if ((InterruptStatus & IpInterruptMask) != 0) {
  285. return XST_IPIF_IP_ACK_ERROR;
  286. }
  287. /* set the IP interrupt enable set register and then read the IP
  288. * interrupt enable register and verify the interrupts were enabled
  289. */
  290. XIIF_V123B_WRITE_IIER(RegBaseAddress, IpInterruptMask);
  291. if (XIIF_V123B_READ_IIER(RegBaseAddress) != IpInterruptMask) {
  292. return XST_IPIF_IP_ENABLE_ERROR;
  293. }
  294. /* clear the IP interrupt enable register and then read the
  295. * IP interrupt enable register and verify the interrupts were disabled
  296. */
  297. XIIF_V123B_WRITE_IIER(RegBaseAddress, 0);
  298. if (XIIF_V123B_READ_IIER(RegBaseAddress) != 0) {
  299. return XST_IPIF_IP_ENABLE_ERROR;
  300. }
  301. }
  302. return XST_SUCCESS;
  303. }