msm_smp2p.txt 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  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. | CDSP processor | 5 |
  167. -------------------------------------------------
  168. | Power processor | 6 |
  169. -------------------------------------------------
  170. | TrustZone processor | 7 |
  171. -------------------------------------------------
  172. | NUM PROCESSORS | 8 |
  173. -------------------------------------------------
  174. Table 3 - Processor IDs
  175. SMEM Item
  176. ---------
  177. The responsibility of creating an SMEM item is with the local processor that is
  178. initiating outbound traffic. After creating the item, the local and remote
  179. processors negotiate the version and feature flags for the item to ensure
  180. compatibility.
  181. Table 4 lists the SMEM item base identifiers. To get the SMEM item ID for a
  182. particular edge, the remote processor ID (Table 3) is added to the base item ID
  183. for the local processor (Table 4). For example, the Apps ==> Modem (id 1) SMEM
  184. Item ID will be 427 + 1 = 428.
  185. ---------------------------------------------------
  186. | Description | SMEM ID value |
  187. ---------------------------------------------------
  188. | CDSP SMEM Item base | 94 |
  189. ---------------------------------------------------
  190. | Apps SMP2P SMEM Item base | 427 |
  191. ---------------------------------------------------
  192. | Modem SMP2P SMEM Item base | 435 |
  193. ---------------------------------------------------
  194. | Audio SMP2P SMEM Item base | 443 |
  195. ---------------------------------------------------
  196. | Sensors SMP2P SMEM Item base | 481 |
  197. ---------------------------------------------------
  198. | Wireless SMP2P SMEM Item base | 451 |
  199. ---------------------------------------------------
  200. | Power SMP2P SMEM Item base | 459 |
  201. ---------------------------------------------------
  202. | TrustZone SMP2P SMEM Item base | 489 |
  203. ---------------------------------------------------
  204. Table 4 - SMEM Items Base IDs
  205. Version and Feature Negotiation
  206. -------------------------------
  207. To enable upgrading without breaking the system and to enable graceful feature
  208. fall-back support, SMP2P supports a version number and feature flags. The
  209. combination of the version number and feature flags enable:
  210. 1) SMP2P software updates to be rolled out to each processor separately.
  211. 2) Individual features to be enabled or disabled per connection or edge.
  212. The version number represents any change in SMP2P that breaks compatibility
  213. between processors. Examples would be a change in the shared data structures
  214. or changes to fundamental behavior. Each implementation of SMP2P must be able
  215. to support a minimum of the current version and the previous version.
  216. The feature flags represent any changes in SMP2P that are optional and
  217. backwards compatible. Endpoints will negotiate the supported flag when the
  218. SMEM items are created and they cannot be changed after negotiation has been
  219. completed.
  220. Negotiation Algorithm
  221. ----------------------
  222. While creating the SMEM item the following algorithm shall be used.
  223. if remote endpoint's SMEM Item exists
  224. Read remote version number and flags
  225. Local version number must be lower of
  226. - remote version number
  227. - highest supported local version number
  228. Flags value is bitwise AND of
  229. - remote feature flags
  230. - locally supported flags
  231. Create SMEM item and populate negotiated number and flags
  232. Interrupt remote processor
  233. if version and flags match, negotiation is complete, else wait
  234. for remote interrupt below.
  235. Else
  236. Create SMEM item and populate it with highest supported version and any
  237. requested feature flag.
  238. Interrupt remote processor.
  239. Wait for Interrupt below.
  240. Upon receiving the interrupt from remote processor and negotiation is not
  241. complete, check the version number and feature flags:
  242. if equal, negotiation is complete.
  243. if remote number is less than local number, and remote number is
  244. supported:
  245. Set local version number to remote version number
  246. Bitwise AND local flags with remote flags
  247. Interrupt remote processor
  248. Negotiation is complete
  249. if remote number is not supported, then negotiation has failed
  250. Set version number to 0xFF and report failure in kernel log.
  251. if remote number is more than local number:
  252. Wait for remote endpoint to process our interrupt and negotiate down.
  253. Creating an SMEM Entry
  254. ----------------------
  255. Each new SMEM entry used in data transfer must be created at the end of the
  256. entry array in the SMEM item and cannot be deleted until the system is
  257. rebooted. The following sequence is be followed:
  258. 1) Compare Entries Valid and Entries Total to verify if there is room in the
  259. entry array for this request (if not, return error code to client).
  260. 2) Populate the Identifier of new entry and do a write memory barrier.
  261. 3) Update Entries Valid and Entries Total and do a write memory barrier.
  262. 4) Interrupt remote endpoint.
  263. Entry Write
  264. -----------
  265. An entry write is achieved by the following sequence of operations:
  266. 1) Update data field in the entry and do a write memory barrier.
  267. 2) Interrupt remote endpoint.
  268. Entry Read / Receiving Interrupts
  269. ---------------------------------
  270. An interrupt will be received from the remote system for one or more of the following events:
  271. 1) Initialization
  272. 2) Entry change
  273. 3) New Entry
  274. As long as the SMEM item initialization is complete, then each interrupt should
  275. trigger SMP2P to:
  276. 1) Compare valid entry data value to cached value and notify client if it
  277. has changed.
  278. 2) Compare Entries Valid to cached value. If changed, initialize new entries.
  279. Security
  280. ========
  281. Since the implementation resides in the kernel and does not expose interfaces
  282. to userspace, no security issues are anticipated. The usage of separate SMEM
  283. items allows for future security enhancements in SMEM.
  284. Performance
  285. ===========
  286. No performance issues are anticipated as the signaling rate is expected to be
  287. low and is performed in interrupt context which minimizes latency.
  288. Interfaces
  289. ================
  290. SMP2P is only supported in the kernel and interfaces with clients through the
  291. GPIO and interrupt subsystems.
  292. To map an entry to the client, the client must add two nodes to the Device
  293. Tree:
  294. 1) A node that matches "qcom,smp2pgpio" to create the entry
  295. 2) A node that matches the client driver to provide the GPIO pin mapping
  296. The details of the device tree entries for the GPIO interface are contained in
  297. the file Documentation/devicetree/bindings/gpio/gpio-smp2p.txt.
  298. /* SMP2P Test Driver for inbound entry. */
  299. smp2pgpio_smp2p_7_in: qcom,smp2pgpio-smp2p-7-in {
  300. compatible = "qcom,smp2pgpio";
  301. qcom,entry-name = "smp2p";
  302. qcom,remote-pid = <7>;
  303. qcom,is-inbound;
  304. gpio-controller;
  305. #gpio-cells = <2>;
  306. interrupt-controller;
  307. #interrupt-cells = <2>;
  308. };
  309. /* SMP2P Test Client for inbound entry. */
  310. qcom,smp2pgpio_test_smp2p_7_in {
  311. compatible = "qcom,smp2pgpio_test_smp2p_7_in";
  312. gpios = <&smp2pgpio_smp2p_7_in 0 0>,
  313. <&smp2pgpio_smp2p_7_in 1 0>,
  314. . . .
  315. <&smp2pgpio_smp2p_7_in 31 0>;
  316. };
  317. /* SMP2P Test Driver for outbound entries */
  318. smp2pgpio_smp2p_345_out: qcom,smp2pgpio-smp2p-7-out {
  319. compatible = "qcom,smp2pgpio";
  320. qcom,entry-name = "smp2p";
  321. qcom,remote-pid = <7>;
  322. gpio-controller;
  323. #gpio-cells = <2>;
  324. interrupt-controller;
  325. #interrupt-cells = <2>;
  326. };
  327. /* SMP2P Test Client for outbound entry. */
  328. qcom,smp2pgpio_test_smp2p_7_out {
  329. compatible = "qcom,smp2pgpio_test_smp2p_7_out";
  330. gpios = <&smp2pgpio_smp2p_7_out 0 0>,
  331. <&smp2pgpio_smp2p_7_out 1 0>,
  332. . . .
  333. <&smp2pgpio_smp2p_7_out 31 0>;
  334. The client can use a match entry for "qcom,smp2pgpio_test_smp2p_7_in" to
  335. retrieve the Device Tree configuration node. Once that node has been
  336. retrieved, the client can call of_get_gpio() to get the virtual GPIO pin and
  337. also use gpio_to_irq() to map the GPIO pin to a virtual interrupt. After that
  338. point, the standard GPIO and Interrupt APIs can be used to manipulate the SMP2P
  339. entries and receive notifications of changes. Examples of typical function
  340. calls are shown below:
  341. of_get_gpio()
  342. gpio_get_value()
  343. gpio_set_value()
  344. gpio_to_irq()
  345. request_irq()
  346. free_irq()
  347. Please reference the unit test code for example usage.
  348. Subsystem Restart
  349. =================
  350. SMP2P is unaffected by SubSystem Restart (SSR) on the high-level OS side and is
  351. actually used as an underlying communication mechanism for SSR. On the
  352. peripheral system that is being restarted, SMP2P will zero out all existing
  353. state entries upon reboot as part of the SMP2P initialization process and if the
  354. SSR_ACK feature is enabled, then it waits for an acknowledgment as outlined in
  355. the following subsections.
  356. SSR_ACK Feature - Reboot Use Case (Non-HLOS Only)
  357. -------------------------------------------------
  358. If a remote system boots up after an SSR and sees that the remote and local
  359. version numbers and feature flags are equal, then it zeros out entry values. If
  360. the SSR_ACK feature is enabled, it will wait for an acknowledgment from the other
  361. processor that it has seen the zero entry before completing the negotiation
  362. sequence.
  363. if remote and local version numbers and feature flags are equal
  364. Zero out all entry values
  365. if SSR_ACK feature is enabled
  366. Set local RESTART_DONE flag to inverse of the remote RESTART_ACK
  367. Send interrupt to remote system
  368. Wait for interrupt and for remote RESTART_ACK to be equal to local
  369. RESTART_DONE
  370. Continue with normal negotiation sequence
  371. Interrupt Use Case
  372. ------------------
  373. For every interrupt triggered by a remote change, SMP2P will notify the client
  374. of a change in state. In addition, if the SSR_ACK feature is enabled, the SSR
  375. handshaking will also be handled.
  376. if SSR_ACK feature is enabled
  377. if remote RESTART_DONE != local RESTART_ACK
  378. Notify client of entry change (will be * -> 0 transition)
  379. Toggle local RESTART_ACK
  380. Send interrupt to remote system
  381. else
  382. Notify client of entry change as usual
  383. else
  384. Notify client of entry change as usual
  385. Debug
  386. =====
  387. The state values and names for all entries accessible by the Apps are
  388. accessible through debugfs nodes for general debug purposes.
  389. Debugfs entries for triggering unit-tests are also exported.
  390. Internal logging will be performed using the IPC Logging module to enable
  391. post-mortem analysis.
  392. Testing
  393. =======
  394. On-target unit testing will be done to verify internal functionality and the
  395. GPIO/IRQ API's.
  396. Driver parameters
  397. =================
  398. One module parameter will be provided to change the verbosity of internal logging.
  399. Config options
  400. ==============
  401. Configuration of interrupts will be done using Device Tree per the format in
  402. Documentation/devicetree/bindings/arm/msm/smp2p.txt. By default, the testing
  403. components will be enabled since it does not affect performance and has a
  404. minimal impact on kernel size. However, customers can disable the testing
  405. component for size optimization.
  406. CONFIG_MSM_SMP2P - enables SMP2P
  407. CONFIG_MSM_SMP2P_TEST - enables unit test support
  408. Dependencies
  409. ===========
  410. Requires SMEM for creating the SMEM items.
  411. User Space utilities
  412. ====================
  413. No userspace utilities are planned.
  414. Known issues
  415. ============
  416. None.