ipu6.rst 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. .. SPDX-License-Identifier: GPL-2.0
  2. ==================
  3. Intel IPU6 Driver
  4. ==================
  5. Author: Bingbu Cao <bingbu.cao@intel.com>
  6. Overview
  7. =========
  8. Intel IPU6 is the sixth generation of Intel Image Processing Unit used in some
  9. Intel Chipsets such as Tiger Lake, Jasper Lake, Alder Lake, Raptor Lake and
  10. Meteor Lake. IPU6 consists of two major systems: Input System (ISYS) and
  11. Processing System (PSYS). IPU6 are visible on the PCI bus as a single device, it
  12. can be found by ``lspci``:
  13. ``0000:00:05.0 Multimedia controller: Intel Corporation Device xxxx (rev xx)``
  14. IPU6 has a 16 MB BAR in PCI configuration Space for MMIO registers which is
  15. visible for driver.
  16. Buttress
  17. =========
  18. The IPU6 is connecting to the system fabric with Buttress which is enabling host
  19. driver to control the IPU6, it also allows IPU6 access the system memory to
  20. store and load frame pixel streams and any other metadata.
  21. Buttress mainly manages several system functionalities: power management,
  22. interrupt handling, firmware authentication and global timer sync.
  23. ISYS and PSYS Power flow
  24. ------------------------
  25. IPU6 driver initialize the ISYS and PSYS power up or down request by setting the
  26. Buttress frequency control register for ISYS and PSYS
  27. (``IPU6_BUTTRESS_REG_IS_FREQ_CTL`` and ``IPU6_BUTTRESS_REG_PS_FREQ_CTL``) in
  28. function:
  29. .. c:function:: int ipu6_buttress_power(...)
  30. Buttress forwards the request to Punit, after Punit execute the power up flow,
  31. Buttress indicates driver that ISYS or PSYS is powered up by updating the power
  32. status registers.
  33. .. Note:: ISYS power up needs take place prior to PSYS power up, ISYS power down
  34. needs take place after PSYS power down due to hardware limitation.
  35. Interrupt
  36. ---------
  37. IPU6 interrupt can be generated as MSI or INTA, interrupt will be triggered when
  38. ISYS, PSYS, Buttress event or error happen, driver can get the interrupt cause
  39. by reading the interrupt status register ``BUTTRESS_REG_ISR_STATUS``, driver
  40. clears the irq status and then calls specific ISYS or PSYS irq handler.
  41. .. c:function:: irqreturn_t ipu6_buttress_isr(int irq, ...)
  42. Security and firmware authentication
  43. -------------------------------------
  44. To address the IPU6 firmware security concerns, the IPU6 firmware needs to
  45. undergo an authentication process before it is allowed to executed on the IPU6
  46. internal processors. The IPU6 driver will work with Converged Security Engine
  47. (CSE) to complete authentication process. The CSE is responsible of
  48. authenticating the IPU6 firmware. The authenticated firmware binary is copied
  49. into an isolated memory region. Firmware authentication process is implemented
  50. by CSE following an IPC handshake with the IPU6 driver. There are some Buttress
  51. registers used by the CSE and the IPU6 driver to communicate with each other via
  52. IPC.
  53. .. c:function:: int ipu6_buttress_authenticate(...)
  54. Global timer sync
  55. -----------------
  56. The IPU6 driver initiates a Hammock Harbor synchronization flow each time it
  57. starts camera operation. The IPU6 will synchronizes an internal counter in the
  58. Buttress with a copy of the SoC time, this counter maintains the up-to-date time
  59. until camera operation is stopped. The IPU6 driver can use this time counter to
  60. calibrate the timestamp based on the timestamp in response event from firmware.
  61. .. c:function:: int ipu6_buttress_start_tsc_sync(...)
  62. DMA and MMU
  63. ============
  64. The IPU6 has its own scalar processor where the firmware run at and an internal
  65. 32-bit virtual address space. The IPU6 has MMU address translation hardware to
  66. allow that scalar processors to access the internal memory and external system
  67. memory through IPU6 virtual address. The address translation is based on two
  68. levels of page lookup tables stored in system memory which are maintained by the
  69. IPU6 driver. The IPU6 driver sets the level-1 page table base address to MMU
  70. register and allows MMU to perform page table lookups.
  71. The IPU6 driver exports its own DMA operations. The IPU6 driver will update the
  72. page table entries for each DMA operation and invalidate the MMU TLB after each
  73. unmap and free.
  74. .. code-block:: none
  75. const struct dma_map_ops ipu6_dma_ops = {
  76. .alloc = ipu6_dma_alloc,
  77. .free = ipu6_dma_free,
  78. .mmap = ipu6_dma_mmap,
  79. .map_sg = ipu6_dma_map_sg,
  80. .unmap_sg = ipu6_dma_unmap_sg,
  81. ...
  82. };
  83. .. Note:: IPU6 MMU works behind IOMMU so for each IPU6 DMA ops, driver will call
  84. generic PCI DMA ops to ask IOMMU to do the additional mapping if VT-d
  85. enabled.
  86. Firmware file format
  87. ====================
  88. The IPU6 firmware is in Code Partition Directory (CPD) file format. The CPD
  89. firmware contains a CPD header, several CPD entries and components. The CPD
  90. component includes 3 entries - manifest, metadata and module data. Manifest and
  91. metadata are defined by CSE and used by CSE for authentication. Module data is
  92. specific to IPU6 which holds the binary data of firmware called package
  93. directory. The IPU6 driver (``ipu6-cpd.c`` in particular) parses and validates
  94. the CPD firmware file and gets the package directory binary data of the IPU6
  95. firmware, copies it to specific DMA buffer and sets its base address to Buttress
  96. ``FW_SOURCE_BASE`` register. Finally the CSE will do authentication for this
  97. firmware binary.
  98. Syscom interface
  99. ================
  100. The IPU6 driver communicates with firmware via the Syscom ABI. Syscom is an
  101. inter-processor communication mechanism between the IPU scalar processors and
  102. the CPU. There are a number of resources shared between firmware and software.
  103. A system memory region where the message queues reside, firmware can access the
  104. memory region via the IPU MMU. The Syscom queues are FIFO fixed depth queues
  105. with a configurable number of tokens (messages). There are also common IPU6 MMIO
  106. registers where the queue read and write indices reside. Software and firmware
  107. function as producer and consumer of tokens in the queues and update the write
  108. and read indices separately when sending or receiving each message.
  109. The IPU6 driver must prepare and configure the number of input and output
  110. queues, configure the count of tokens per queue and the size of per token before
  111. initiating and starting the communication with firmware. Firmware and software
  112. must use same configurations. The IPU6 Buttress has a number of firmware boot
  113. parameter registers which can be used to store the address of configuration and
  114. initialise the Syscom state, then driver can request firmware to start and run via
  115. setting the scalar processor control status register.
  116. Input System
  117. ============
  118. IPU6 input system consists of MIPI D-PHY and several CSI-2 receivers. It can
  119. capture image pixel data from camera sensors or other MIPI CSI-2 output devices.
  120. D-PHYs and CSI-2 ports lane mapping
  121. -----------------------------------
  122. The IPU6 integrates different D-PHY IPs on different SoCs, on Tiger Lake and
  123. Alder Lake, IPU6 integrates MCD10 D-PHY, IPU6SE on Jasper Lake integrates JSL
  124. D-PHY and IPU6EP on Meteor Lake integrates a Synopsys DWC D-PHY. There is an
  125. adaptional layer between D-PHY and CSI-2 receiver controller which includes port
  126. configuration, PHY wrapper or private test interfaces for D-PHY. There are 3
  127. D-PHY drivers ``ipu6-isys-mcd-phy.c``, ``ipu6-isys-jsl-phy.c`` and
  128. ``ipu6-isys-dwc-phy.c`` program the above 3 D-PHYs in IPU6.
  129. Different IPU6 versions have different D-PHY lanes mappings, On Tiger Lake,
  130. there are 12 data lanes and 8 clock lanes, IPU6 support maximum 8 CSI-2 ports,
  131. see the PPI mmapping in ``ipu6-isys-mcd-phy.c`` for more information. On Jasper
  132. Lake and Alder Lake, D-PHY has 8 data lanes and 4 clock lanes, the IPU6 supports
  133. maximum 4 CSI-2 ports. For Meteor Lake, D-PHY has 12 data lanes and 6 clock
  134. lanes so IPU6 support maximum 6 CSI-2 ports.
  135. .. Note:: Each pair of CSI-2 two ports is a single unit that can share the data
  136. lanes. For example, for CSI-2 port 0 and 1, CSI-2 port 0 support
  137. maximum 4 data lanes, CSI-2 port 1 support maximum 2 data lanes, CSI-2
  138. port 0 with 2 data lanes can work together with CSI-2 port 1 with 2
  139. data lanes. If trying to use CSI-2 port 0 with 4 lanes, CSI-2 port 1
  140. will not be available as the 4 data lanes are shared by CSI-2 port 0
  141. and 1. The same applies to CSI ports 2/3, 4/5 and 7/8.
  142. ISYS firmware ABIs
  143. ------------------
  144. The IPU6 firmware implements a series of ABIs for software access. In general,
  145. software firstly prepares the stream configuration ``struct
  146. ipu6_fw_isys_stream_cfg_data_abi`` and sends the configuration to firmware via
  147. sending ``STREAM_OPEN`` command. Stream configuration includes input pins and
  148. output pins, input pin ``struct ipu6_fw_isys_input_pin_info_abi`` defines the
  149. resolution and data type of input source, output pin ``struct
  150. ipu6_fw_isys_output_pin_info_abi`` defines the output resolution, stride and
  151. frame format, etc.
  152. Once the driver gets the interrupt from firmware that indicates stream open
  153. successfully, the driver will send the ``STREAM_START`` and ``STREAM_CAPTURE``
  154. command to request firmware to start capturing image frames. ``STREAM_CAPTURE``
  155. command queues the buffers to firmware with ``struct
  156. ipu6_fw_isys_frame_buff_set``, software then waits for the interrupt and
  157. response from firmware, ``PIN_DATA_READY`` means a buffer is ready on a specific
  158. output pin and then software can return the buffer to user.
  159. .. Note:: See :ref:`Examples<ipu6_isys_capture_examples>` about how to do
  160. capture by IPU6 ISYS driver.