msm_smp2p.txt 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. Introduction
  2. ============
  3. The Shared Memory Point to Point (SMP2P) protocol facilitates communication of
  4. a single 32-bit value between two processors. Each value has a single writer
  5. (the local side) and a single reader (the remote side). Values are uniquely
  6. identified in the system by the directed edge (local processor ID to remote
  7. processor ID) and a string identifier.
  8. Version and feature negotiation has been included in the design to allow for
  9. phased upgrades of all processors.
  10. Software Architecture Description
  11. =================================
  12. The data and interrupt coupling between processors is shown in Fig. 1. Each
  13. processor is responsible for creating the outgoing SMEM items and each item is
  14. writable by the local processor and readable by the remote processor. By using
  15. two separate SMEM items that are single-reader and single-writer, SMP2P does
  16. not require any remote locking mechanisms.
  17. The client API uses the Linux GPIO and interrupt framework to expose a virtual
  18. GPIO and a virtual interrupt controller for each entry.
  19. =================
  20. | |
  21. -----write------>|SMEM item A->B |-----read------
  22. | | | |
  23. | ================= |
  24. | |
  25. | v
  26. GPIO API => ------------ ======= Interrupt line ======> ------------
  27. Processor A Processor B
  28. Interrupt <= ------------ <====== Interrupt line ======= ------------
  29. API ^ |
  30. | |
  31. | |
  32. | ================= |
  33. | | | |
  34. ------read-------|SMEM item A<-B |<-----write----
  35. | |
  36. =================
  37. Fig 1
  38. Design
  39. ======
  40. Each SMEM item contains a header that is used to identify and manage the edge
  41. along with an array of actual entries. The overall structure is captured in
  42. Fig 2 and the details of the header and entries are covered later in this
  43. section. The memory format of all shared structures is little-endian.
  44. -----------------------------------------------
  45. | SMEM item A->B |
  46. | |
  47. | ----------------------------------------- |
  48. | |31 24| 16| 8| 0| |
  49. | |----------|---------|----------|---------| |
  50. | | Identifier Constant(Magic Number) | |
  51. | |----------|---------|----------|---------| |
  52. | | Feature Flags |Version | |
  53. | | |Number | |
  54. | |----------|---------|----------|---------| |
  55. | | Remote Proc ID |Local Proc ID | |
  56. | |----------|---------|----------|---------| |
  57. | | Entries Valid | Entries Total | |
  58. | |-----------------------------------------| |
  59. | |
  60. | |
  61. | ----------------------------------------- |
  62. | | Entry 0 | |
  63. | | ---------------------------------- | |
  64. | | | Identifier String | | |
  65. | | |---------------------------------| | |
  66. | | | Data | | |
  67. | | |---------------------------------| | |
  68. | |---------------------------------------| |
  69. | ----------------------------------------- |
  70. | | Entry 1 | |
  71. | | ---------------------------------- | |
  72. | | | Identifier String | | |
  73. | | |---------------------------------| | |
  74. | | | Data | | |
  75. | | |---------------------------------| | |
  76. | |---------------------------------------| |
  77. | - |
  78. | - |
  79. | - |
  80. | ----------------------------------------- |
  81. | | Entry N | |
  82. | | ---------------------------------- | |
  83. | | | Identifier String | | |
  84. | | |---------------------------------| | |
  85. | | | Data | | |
  86. | | |---------------------------------| | |
  87. | |---------------------------------------| |
  88. -----------------------------------------------
  89. Fig 2
  90. The header of each SMEM item contains metadata that describes the processors
  91. using the edge, the version information, and the entry count. The constant
  92. identifier is used as a magic number to enable extraction of the items from a
  93. memory dump. The size of each entry depends upon the version, but the number
  94. of total entries (and hence the size of each SMEM item) is configurable with a
  95. suggested value of 16.
  96. The number of valid entries is used to indicate how many of the Entries Total
  97. are currently used and are current valid.
  98. ---------------------------------------------------------------------------
  99. |Field Size Description Valid Values |
  100. ---------------------------------------------------------------------------
  101. | Identifier 4 Bytes Value used to identify |
  102. | Constant structure in memory. Must be set to $SMP |
  103. | Useful for debugging. (0x504D5324) |
  104. ---------------------------------------------------------------------------
  105. | Local 2 Bytes Writing processor ID. Refer Processor ID Table 3|
  106. | Processor |
  107. | ID |
  108. ---------------------------------------------------------------------------
  109. | Remote 2 Bytes Reading processor ID. Refer Processor ID Table 3|
  110. | Processor |
  111. | ID |
  112. ---------------------------------------------------------------------------
  113. | Version 1 Bytes Refer to Version |
  114. | Number Feature Negotiation Must be set to 1. |
  115. | section. |
  116. ---------------------------------------------------------------------------
  117. | Feature 3 Bytes Refer to Version |
  118. | flags and Feature Negotiation |
  119. | section for details. |
  120. | bit 0 SSR_ACK Feature Supported when set to 1 |
  121. | bits 1:31 Reserved Must be set to 0. |
  122. ---------------------------------------------------------------------------
  123. | Entries 2 Bytes Total number of Must be 0 or greater. |
  124. | Total entries. |
  125. ---------------------------------------------------------------------------
  126. | Entries 2 Bytes Number of valid Must be between 0 |
  127. | Valid entries. and Entries Total. |
  128. ---------------------------------------------------------------------------
  129. | Flags 4 Bytes |
  130. | bit 0 RESTART_DONE Toggle for every restart |
  131. | bit 1 RESTART_ACK Toggle to ACK remote |
  132. | RESTART_DONE |
  133. | bits 2:31 Reserved Must be set to 0. |
  134. ---------------------------------------------------------------------------
  135. Table 1 - SMEM Item Header
  136. The content of each SMEM entries is described in Table 2 and consists of a
  137. string identifier and a 32-bit data value. The string identifier must be
  138. unique for each SMEM item. The data value is opaque to SMP2P giving the client
  139. complete flexibility as to its usage.
  140. ----------------------- --------------------- -----------------------------
  141. | Field | Size | Description | Valid Values |
  142. ------------|----------|---------------------|-----------------------------
  143. | | | | |
  144. | Identifier | 16 Bytes | Null Terminated | NON-NULL for |
  145. | String | | ASCII string. | valid entries. |
  146. | | | | |
  147. ------------|----------|---------------------|-----------------------------
  148. | Data | 4 Bytes | Data | Any (client defined) |
  149. ------------ ---------- --------------------- -----------------------------
  150. Table 2 - Entry Format
  151. The processor IDs in the system are fixed and new processors IDs will be
  152. added to the end of the list (Table 3).
  153. -------------------------------------------------
  154. | Processor Name | ID value |
  155. -------------------------------------------------
  156. | Application processor | 0 |
  157. -------------------------------------------------
  158. | Modem processor | 1 |
  159. -------------------------------------------------
  160. | Audio processor | 2 |
  161. -------------------------------------------------
  162. | Sensor processor | 3 |
  163. -------------------------------------------------
  164. | Wireless processor | 4 |
  165. -------------------------------------------------
  166. | Modem Fw | 5 |
  167. -------------------------------------------------
  168. | Power processor | 6 |
  169. -------------------------------------------------
  170. | NUM PROCESSORS | 7 |
  171. -------------------------------------------------
  172. Table 3 - Processor IDs
  173. SMEM Item
  174. ---------
  175. The responsibility of creating an SMEM item is with the local processor that is
  176. initiating outbound traffic. After creating the item, the local and remote
  177. processors negotiate the version and feature flags for the item to ensure
  178. compatibility.
  179. Table 4 lists the SMEM item base identifiers. To get the SMEM item ID for a
  180. particular edge, the remote processor ID (Table 3) is added to the base item ID
  181. for the local processor (Table 4). For example, the Apps ==> Modem (id 1) SMEM
  182. Item ID will be 427 + 1 = 428.
  183. --------------------------------------------------
  184. | Description | SMEM ID value |
  185. --------------------------------------------------
  186. | Apps SMP2P SMEM Item base | 427 |
  187. --------------------------------------------------
  188. | Modem SMP2P SMEM Item base | 435 |
  189. --------------------------------------------------
  190. | Audio SMP2P SMEM Item base | 443 |
  191. --------------------------------------------------
  192. | Wireless SMP2P SMEM Item base | 451 |
  193. --------------------------------------------------
  194. | Power SMP2P SMEM Item base | 459 |
  195. --------------------------------------------------
  196. Table 4 - SMEM Items Base IDs
  197. Version and Feature Negotiation
  198. -------------------------------
  199. To enable upgrading without breaking the system and to enable graceful feature
  200. fall-back support, SMP2P supports a version number and feature flags. The
  201. combination of the version number and feature flags enable:
  202. 1) SMP2P software updates to be rolled out to each processor separately.
  203. 2) Individual features to be enabled or disabled per connection or edge.
  204. The version number represents any change in SMP2P that breaks compatibility
  205. between processors. Examples would be a change in the shared data structures
  206. or changes to fundamental behavior. Each implementation of SMP2P must be able
  207. to support a minimum of the current version and the previous version.
  208. The feature flags represent any changes in SMP2P that are optional and
  209. backwards compatible. Endpoints will negotiate the supported flag when the
  210. SMEM items are created and they cannot be changed after negotiation has been
  211. completed.
  212. Negotiation Algorithm
  213. ----------------------
  214. While creating the SMEM item the following algorithm shall be used.
  215. if remote endpoint's SMEM Item exists
  216. Read remote version number and flags
  217. Local version number must be lower of
  218. - remote version number
  219. - highest supported local version number
  220. Flags value is bitwise AND of
  221. - remote feature flags
  222. - locally supported flags
  223. Create SMEM item and populate negotiated number and flags
  224. Interrupt remote processor
  225. if version and flags match, negotiation is complete, else wait
  226. for remote interrupt below.
  227. Else
  228. Create SMEM item and populate it with highest supported version and any
  229. requested feature flag.
  230. Interrupt remote processor.
  231. Wait for Interrupt below.
  232. Upon receiving the interrupt from remote processor and negotiation is not
  233. complete, check the version number and feature flags:
  234. if equal, negotiation is complete.
  235. if remote number is less than local number, and remote number is
  236. supported:
  237. Set local version number to remote version number
  238. Bitwise AND local flags with remote flags
  239. Interrupt remote processor
  240. Negotiation is complete
  241. if remote number is not supported, then negotiation has failed
  242. Set version number to 0xFF and report failure in kernel log.
  243. if remote number is more than local number:
  244. Wait for remote endpoint to process our interrupt and negotiate down.
  245. Creating an SMEM Entry
  246. ----------------------
  247. Each new SMEM entry used in data transfer must be created at the end of the
  248. entry array in the SMEM item and cannot be deleted until the system is
  249. rebooted. The following sequence is be followed:
  250. 1) Compare Entries Valid and Entries Total to verify if there is room in the
  251. entry array for this request (if not, return error code to client).
  252. 2) Populate the Identifier of new entry and do a write memory barrier.
  253. 3) Update Entries Valid and Entries Total and do a write memory barrier.
  254. 4) Interrupt remote endpoint.
  255. Entry Write
  256. -----------
  257. An entry write is achieved by the following sequence of operations:
  258. 1) Update data field in the entry and do a write memory barrier.
  259. 2) Interrupt remote endpoint.
  260. Entry Read / Receiving Interrupts
  261. ---------------------------------
  262. An interrupt will be received from the remote system for one or more of the following events:
  263. 1) Initialization
  264. 2) Entry change
  265. 3) New Entry
  266. As long as the SMEM item initialization is complete, then each interrupt should
  267. trigger SMP2P to:
  268. 1) Compare valid entry data value to cached value and notify client if it
  269. has changed.
  270. 2) Compare Entries Valid to cached value. If changed, initialize new entries.
  271. Security
  272. ========
  273. Since the implementation resides in the kernel and does not expose interfaces
  274. to userspace, no security issues are anticipated. The usage of separate SMEM
  275. items allows for future security enhancements in SMEM.
  276. Performance
  277. ===========
  278. No performance issues are anticipated as the signaling rate is expected to be
  279. low and is performed in interrupt context which minimizes latency.
  280. Interfaces
  281. ================
  282. SMP2P is only supported in the kernel and interfaces with clients through the
  283. GPIO and interrupt subsystems.
  284. To map an entry to the client, the client must add two nodes to the Device
  285. Tree:
  286. 1) A node that matches "qcom,smp2pgpio" to create the entry
  287. 2) A node that matches the client driver to provide the GPIO pin mapping
  288. The details of the device tree entries for the GPIO interface are contained in
  289. the file Documentation/devicetree/bindings/gpio/gpio-smp2p.txt.
  290. /* SMP2P Test Driver for inbound entry. */
  291. smp2pgpio_smp2p_7_in: qcom,smp2pgpio-smp2p-7-in {
  292. compatible = "qcom,smp2pgpio";
  293. qcom,entry-name = "smp2p";
  294. qcom,remote-pid = <7>;
  295. qcom,is-inbound;
  296. gpio-controller;
  297. #gpio-cells = <2>;
  298. interrupt-controller;
  299. #interrupt-cells = <2>;
  300. };
  301. /* SMP2P Test Client for inbound entry. */
  302. qcom,smp2pgpio_test_smp2p_7_in {
  303. compatible = "qcom,smp2pgpio_test_smp2p_7_in";
  304. gpios = <&smp2pgpio_smp2p_7_in 0 0>,
  305. <&smp2pgpio_smp2p_7_in 1 0>,
  306. . . .
  307. <&smp2pgpio_smp2p_7_in 31 0>;
  308. };
  309. /* SMP2P Test Driver for outbound entries */
  310. smp2pgpio_smp2p_345_out: qcom,smp2pgpio-smp2p-7-out {
  311. compatible = "qcom,smp2pgpio";
  312. qcom,entry-name = "smp2p";
  313. qcom,remote-pid = <7>;
  314. gpio-controller;
  315. #gpio-cells = <2>;
  316. interrupt-controller;
  317. #interrupt-cells = <2>;
  318. };
  319. /* SMP2P Test Client for outbound entry. */
  320. qcom,smp2pgpio_test_smp2p_7_out {
  321. compatible = "qcom,smp2pgpio_test_smp2p_7_out";
  322. gpios = <&smp2pgpio_smp2p_7_out 0 0>,
  323. <&smp2pgpio_smp2p_7_out 1 0>,
  324. . . .
  325. <&smp2pgpio_smp2p_7_out 31 0>;
  326. The client can use a match entry for "qcom,smp2pgpio_test_smp2p_7_in" to
  327. retrieve the Device Tree configuration node. Once that node has been
  328. retrieved, the client can call of_get_gpio() to get the virtual GPIO pin and
  329. also use gpio_to_irq() to map the GPIO pin to a virtual interrupt. After that
  330. point, the standard GPIO and Interrupt APIs can be used to manipulate the SMP2P
  331. entries and receive notifications of changes. Examples of typical function
  332. calls are shown below:
  333. of_get_gpio()
  334. gpio_get_value()
  335. gpio_set_value()
  336. gpio_to_irq()
  337. request_irq()
  338. free_irq()
  339. Please reference the unit test code for example usage.
  340. Subsystem Restart
  341. =================
  342. SMP2P is unaffected by SubSystem Restart (SSR) on the high-level OS side and is
  343. actually used as an underlying communication mechanism for SSR. On the
  344. peripheral system that is being restarted, SMP2P will zero out all existing
  345. state entries upon reboot as part of the SMP2P initialization process and if the
  346. SSR_ACK feature is enabled, then it waits for an acknowledgement as outlined in
  347. the following subsections.
  348. SSR_ACK Feature - Reboot Use Case (Non-HLOS Only)
  349. -------------------------------------------------
  350. If a remote system boots up after an SSR and sees that the remote and local
  351. version numbers and feature flags are equal, then it zeros out entry values. If
  352. the SSR_ACK feature is enabled, it will wait for an acknowledgement from the other
  353. processor that it has seen the zero entry before completing the negotiation
  354. sequence.
  355. if remote and local version numbers and feature flags are equal
  356. Zero out all entry values
  357. if SSR_ACK feature is enabled
  358. Set local RESTART_DONE flag to inverse of the remote RESTART_ACK
  359. Send interrupt to remote system
  360. Wait for interrupt and for remote RESTART_ACK to be equal to local
  361. RESTART_DONE
  362. Continue with normal negotiation sequence
  363. Interrupt Use Case
  364. ------------------
  365. For every interrupt triggered by a remote change, SMP2P will notify the client
  366. of a change in state. In addition, if the SSR_ACK feature is enabled, the SSR
  367. handshaking will also be handled.
  368. if SSR_ACK feature is enabled
  369. if remote RESTART_DONE != local RESTART_ACK
  370. Notify client of entry change (will be * -> 0 transition)
  371. Toggle local RESTART_ACK
  372. Send interrupt to remote system
  373. else
  374. Notify client of entry change as usual
  375. else
  376. Notify client of entry change as usual
  377. Debug
  378. =====
  379. The state values and names for all entries accessible by the Apps are
  380. accessible through debugfs nodes for general debug purposes.
  381. Debugfs entries for triggering unit-tests are also exported.
  382. Internal logging will be performed using the IPC Logging module to enable
  383. post-mortem analysis.
  384. Testing
  385. =======
  386. On-target unit testing will be done to verify internal functionality and the
  387. GPIO/IRQ API's.
  388. Driver parameters
  389. =================
  390. One module parameter will be provided to change the verbosity of internal logging.
  391. Config options
  392. ==============
  393. Configuration of interrupts will be done using Device Tree per the format in
  394. Documentation/devicetree/bindings/arm/msm/smp2p.txt. By default, the testing
  395. components will be enabled since it does not affect performance and has a
  396. minimal impact on kernel size. However, customers can disable the testing
  397. component for size optimization.
  398. CONFIG_MSM_SMP2P - enables SMP2P
  399. CONFIG_MSM_SMP2P_TEST - enables unit test support
  400. Dependencies
  401. ===========
  402. Requires SMEM for creating the SMEM items.
  403. User Space utilities
  404. ====================
  405. No userspace utilities are planned.
  406. Known issues
  407. ============
  408. None.