porting-guide.rst 133 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550
  1. Porting Guide
  2. =============
  3. Introduction
  4. ------------
  5. Porting Trusted Firmware-A (TF-A) to a new platform involves making some
  6. mandatory and optional modifications for both the cold and warm boot paths.
  7. Modifications consist of:
  8. - Implementing a platform-specific function or variable,
  9. - Setting up the execution context in a certain way, or
  10. - Defining certain constants (for example #defines).
  11. The platform-specific functions and variables are declared in
  12. ``include/plat/common/platform.h``. The firmware provides a default
  13. implementation of variables and functions to fulfill the optional requirements.
  14. These implementations are all weakly defined; they are provided to ease the
  15. porting effort. Each platform port can override them with its own implementation
  16. if the default implementation is inadequate.
  17. Some modifications are common to all Boot Loader (BL) stages. Section 2
  18. discusses these in detail. The subsequent sections discuss the remaining
  19. modifications for each BL stage in detail.
  20. Please refer to the :ref:`Platform Ports Policy` for the policy regarding
  21. compatibility and deprecation of these porting interfaces.
  22. Only Arm development platforms (such as FVP and Juno) may use the
  23. functions/definitions in ``include/plat/arm/common/`` and the corresponding
  24. source files in ``plat/arm/common/``. This is done so that there are no
  25. dependencies between platforms maintained by different people/companies. If you
  26. want to use any of the functionality present in ``plat/arm`` files, please
  27. create a pull request that moves the code to ``plat/common`` so that it can be
  28. discussed.
  29. Common modifications
  30. --------------------
  31. This section covers the modifications that should be made by the platform for
  32. each BL stage to correctly port the firmware stack. They are categorized as
  33. either mandatory or optional.
  34. Common mandatory modifications
  35. ------------------------------
  36. A platform port must enable the Memory Management Unit (MMU) as well as the
  37. instruction and data caches for each BL stage. Setting up the translation
  38. tables is the responsibility of the platform port because memory maps differ
  39. across platforms. A memory translation library (see ``lib/xlat_tables/``) is
  40. provided to help in this setup.
  41. Note that although this library supports non-identity mappings, this is intended
  42. only for re-mapping peripheral physical addresses and allows platforms with high
  43. I/O addresses to reduce their virtual address space. All other addresses
  44. corresponding to code and data must currently use an identity mapping.
  45. Also, the only translation granule size supported in TF-A is 4KB, as various
  46. parts of the code assume that is the case. It is not possible to switch to
  47. 16 KB or 64 KB granule sizes at the moment.
  48. In Arm standard platforms, each BL stage configures the MMU in the
  49. platform-specific architecture setup function, ``blX_plat_arch_setup()``, and uses
  50. an identity mapping for all addresses.
  51. If the build option ``USE_COHERENT_MEM`` is enabled, each platform can allocate a
  52. block of identity mapped secure memory with Device-nGnRE attributes aligned to
  53. page boundary (4K) for each BL stage. All sections which allocate coherent
  54. memory are grouped under ``.coherent_ram``. For ex: Bakery locks are placed in a
  55. section identified by name ``.bakery_lock`` inside ``.coherent_ram`` so that its
  56. possible for the firmware to place variables in it using the following C code
  57. directive:
  58. ::
  59. __section(".bakery_lock")
  60. Or alternatively the following assembler code directive:
  61. ::
  62. .section .bakery_lock
  63. The ``.coherent_ram`` section is a sum of all sections like ``.bakery_lock`` which are
  64. used to allocate any data structures that are accessed both when a CPU is
  65. executing with its MMU and caches enabled, and when it's running with its MMU
  66. and caches disabled. Examples are given below.
  67. The following variables, functions and constants must be defined by the platform
  68. for the firmware to work correctly.
  69. .. _platform_def_mandatory:
  70. File : platform_def.h [mandatory]
  71. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  72. Each platform must ensure that a header file of this name is in the system
  73. include path with the following constants defined. This will require updating
  74. the list of ``PLAT_INCLUDES`` in the ``platform.mk`` file.
  75. Platform ports may optionally use the file ``include/plat/common/common_def.h``,
  76. which provides typical values for some of the constants below. These values are
  77. likely to be suitable for all platform ports.
  78. - **#define : PLATFORM_LINKER_FORMAT**
  79. Defines the linker format used by the platform, for example
  80. ``elf64-littleaarch64``.
  81. - **#define : PLATFORM_LINKER_ARCH**
  82. Defines the processor architecture for the linker by the platform, for
  83. example ``aarch64``.
  84. - **#define : PLATFORM_STACK_SIZE**
  85. Defines the normal stack memory available to each CPU. This constant is used
  86. by ``plat/common/aarch64/platform_mp_stack.S`` and
  87. ``plat/common/aarch64/platform_up_stack.S``.
  88. - **#define : CACHE_WRITEBACK_GRANULE**
  89. Defines the size in bytes of the largest cache line across all the cache
  90. levels in the platform.
  91. - **#define : FIRMWARE_WELCOME_STR**
  92. Defines the character string printed by BL1 upon entry into the ``bl1_main()``
  93. function.
  94. - **#define : PLATFORM_CORE_COUNT**
  95. Defines the total number of CPUs implemented by the platform across all
  96. clusters in the system.
  97. - **#define : PLAT_NUM_PWR_DOMAINS**
  98. Defines the total number of nodes in the power domain topology
  99. tree at all the power domain levels used by the platform.
  100. This macro is used by the PSCI implementation to allocate
  101. data structures to represent power domain topology.
  102. - **#define : PLAT_MAX_PWR_LVL**
  103. Defines the maximum power domain level that the power management operations
  104. should apply to. More often, but not always, the power domain level
  105. corresponds to affinity level. This macro allows the PSCI implementation
  106. to know the highest power domain level that it should consider for power
  107. management operations in the system that the platform implements. For
  108. example, the Base AEM FVP implements two clusters with a configurable
  109. number of CPUs and it reports the maximum power domain level as 1.
  110. - **#define : PLAT_MAX_OFF_STATE**
  111. Defines the local power state corresponding to the deepest power down
  112. possible at every power domain level in the platform. The local power
  113. states for each level may be sparsely allocated between 0 and this value
  114. with 0 being reserved for the RUN state. The PSCI implementation uses this
  115. value to initialize the local power states of the power domain nodes and
  116. to specify the requested power state for a PSCI_CPU_OFF call.
  117. - **#define : PLAT_MAX_RET_STATE**
  118. Defines the local power state corresponding to the deepest retention state
  119. possible at every power domain level in the platform. This macro should be
  120. a value less than PLAT_MAX_OFF_STATE and greater than 0. It is used by the
  121. PSCI implementation to distinguish between retention and power down local
  122. power states within PSCI_CPU_SUSPEND call.
  123. - **#define : PLAT_MAX_PWR_LVL_STATES**
  124. Defines the maximum number of local power states per power domain level
  125. that the platform supports. The default value of this macro is 2 since
  126. most platforms just support a maximum of two local power states at each
  127. power domain level (power-down and retention). If the platform needs to
  128. account for more local power states, then it must redefine this macro.
  129. Currently, this macro is used by the Generic PSCI implementation to size
  130. the array used for PSCI_STAT_COUNT/RESIDENCY accounting.
  131. - **#define : BL1_RO_BASE**
  132. Defines the base address in secure ROM where BL1 originally lives. Must be
  133. aligned on a page-size boundary.
  134. - **#define : BL1_RO_LIMIT**
  135. Defines the maximum address in secure ROM that BL1's actual content (i.e.
  136. excluding any data section allocated at runtime) can occupy.
  137. - **#define : BL1_RW_BASE**
  138. Defines the base address in secure RAM where BL1's read-write data will live
  139. at runtime. Must be aligned on a page-size boundary.
  140. - **#define : BL1_RW_LIMIT**
  141. Defines the maximum address in secure RAM that BL1's read-write data can
  142. occupy at runtime.
  143. - **#define : BL2_BASE**
  144. Defines the base address in secure RAM where BL1 loads the BL2 binary image.
  145. Must be aligned on a page-size boundary. This constant is not applicable
  146. when BL2_IN_XIP_MEM is set to '1'.
  147. - **#define : BL2_LIMIT**
  148. Defines the maximum address in secure RAM that the BL2 image can occupy.
  149. This constant is not applicable when BL2_IN_XIP_MEM is set to '1'.
  150. - **#define : BL2_RO_BASE**
  151. Defines the base address in secure XIP memory where BL2 RO section originally
  152. lives. Must be aligned on a page-size boundary. This constant is only needed
  153. when BL2_IN_XIP_MEM is set to '1'.
  154. - **#define : BL2_RO_LIMIT**
  155. Defines the maximum address in secure XIP memory that BL2's actual content
  156. (i.e. excluding any data section allocated at runtime) can occupy. This
  157. constant is only needed when BL2_IN_XIP_MEM is set to '1'.
  158. - **#define : BL2_RW_BASE**
  159. Defines the base address in secure RAM where BL2's read-write data will live
  160. at runtime. Must be aligned on a page-size boundary. This constant is only
  161. needed when BL2_IN_XIP_MEM is set to '1'.
  162. - **#define : BL2_RW_LIMIT**
  163. Defines the maximum address in secure RAM that BL2's read-write data can
  164. occupy at runtime. This constant is only needed when BL2_IN_XIP_MEM is set
  165. to '1'.
  166. - **#define : BL31_BASE**
  167. Defines the base address in secure RAM where BL2 loads the BL31 binary
  168. image. Must be aligned on a page-size boundary.
  169. - **#define : BL31_LIMIT**
  170. Defines the maximum address in secure RAM that the BL31 image can occupy.
  171. - **#define : PLAT_RSS_COMMS_PAYLOAD_MAX_SIZE**
  172. Defines the maximum message size between AP and RSS. Need to define if
  173. platform supports RSS.
  174. For every image, the platform must define individual identifiers that will be
  175. used by BL1 or BL2 to load the corresponding image into memory from non-volatile
  176. storage. For the sake of performance, integer numbers will be used as
  177. identifiers. The platform will use those identifiers to return the relevant
  178. information about the image to be loaded (file handler, load address,
  179. authentication information, etc.). The following image identifiers are
  180. mandatory:
  181. - **#define : BL2_IMAGE_ID**
  182. BL2 image identifier, used by BL1 to load BL2.
  183. - **#define : BL31_IMAGE_ID**
  184. BL31 image identifier, used by BL2 to load BL31.
  185. - **#define : BL33_IMAGE_ID**
  186. BL33 image identifier, used by BL2 to load BL33.
  187. If Trusted Board Boot is enabled, the following certificate identifiers must
  188. also be defined:
  189. - **#define : TRUSTED_BOOT_FW_CERT_ID**
  190. BL2 content certificate identifier, used by BL1 to load the BL2 content
  191. certificate.
  192. - **#define : TRUSTED_KEY_CERT_ID**
  193. Trusted key certificate identifier, used by BL2 to load the trusted key
  194. certificate.
  195. - **#define : SOC_FW_KEY_CERT_ID**
  196. BL31 key certificate identifier, used by BL2 to load the BL31 key
  197. certificate.
  198. - **#define : SOC_FW_CONTENT_CERT_ID**
  199. BL31 content certificate identifier, used by BL2 to load the BL31 content
  200. certificate.
  201. - **#define : NON_TRUSTED_FW_KEY_CERT_ID**
  202. BL33 key certificate identifier, used by BL2 to load the BL33 key
  203. certificate.
  204. - **#define : NON_TRUSTED_FW_CONTENT_CERT_ID**
  205. BL33 content certificate identifier, used by BL2 to load the BL33 content
  206. certificate.
  207. - **#define : FWU_CERT_ID**
  208. Firmware Update (FWU) certificate identifier, used by NS_BL1U to load the
  209. FWU content certificate.
  210. - **#define : PLAT_CRYPTOCELL_BASE**
  211. This defines the base address of Arm® TrustZone® CryptoCell and must be
  212. defined if CryptoCell crypto driver is used for Trusted Board Boot. For
  213. capable Arm platforms, this driver is used if ``ARM_CRYPTOCELL_INTEG`` is
  214. set.
  215. If the AP Firmware Updater Configuration image, BL2U is used, the following
  216. must also be defined:
  217. - **#define : BL2U_BASE**
  218. Defines the base address in secure memory where BL1 copies the BL2U binary
  219. image. Must be aligned on a page-size boundary.
  220. - **#define : BL2U_LIMIT**
  221. Defines the maximum address in secure memory that the BL2U image can occupy.
  222. - **#define : BL2U_IMAGE_ID**
  223. BL2U image identifier, used by BL1 to fetch an image descriptor
  224. corresponding to BL2U.
  225. If the SCP Firmware Update Configuration Image, SCP_BL2U is used, the following
  226. must also be defined:
  227. - **#define : SCP_BL2U_IMAGE_ID**
  228. SCP_BL2U image identifier, used by BL1 to fetch an image descriptor
  229. corresponding to SCP_BL2U.
  230. .. note::
  231. TF-A does not provide source code for this image.
  232. If the Non-Secure Firmware Updater ROM, NS_BL1U is used, the following must
  233. also be defined:
  234. - **#define : NS_BL1U_BASE**
  235. Defines the base address in non-secure ROM where NS_BL1U executes.
  236. Must be aligned on a page-size boundary.
  237. .. note::
  238. TF-A does not provide source code for this image.
  239. - **#define : NS_BL1U_IMAGE_ID**
  240. NS_BL1U image identifier, used by BL1 to fetch an image descriptor
  241. corresponding to NS_BL1U.
  242. If the Non-Secure Firmware Updater, NS_BL2U is used, the following must also
  243. be defined:
  244. - **#define : NS_BL2U_BASE**
  245. Defines the base address in non-secure memory where NS_BL2U executes.
  246. Must be aligned on a page-size boundary.
  247. .. note::
  248. TF-A does not provide source code for this image.
  249. - **#define : NS_BL2U_IMAGE_ID**
  250. NS_BL2U image identifier, used by BL1 to fetch an image descriptor
  251. corresponding to NS_BL2U.
  252. For the the Firmware update capability of TRUSTED BOARD BOOT, the following
  253. macros may also be defined:
  254. - **#define : PLAT_FWU_MAX_SIMULTANEOUS_IMAGES**
  255. Total number of images that can be loaded simultaneously. If the platform
  256. doesn't specify any value, it defaults to 10.
  257. If a SCP_BL2 image is supported by the platform, the following constants must
  258. also be defined:
  259. - **#define : SCP_BL2_IMAGE_ID**
  260. SCP_BL2 image identifier, used by BL2 to load SCP_BL2 into secure memory
  261. from platform storage before being transferred to the SCP.
  262. - **#define : SCP_FW_KEY_CERT_ID**
  263. SCP_BL2 key certificate identifier, used by BL2 to load the SCP_BL2 key
  264. certificate (mandatory when Trusted Board Boot is enabled).
  265. - **#define : SCP_FW_CONTENT_CERT_ID**
  266. SCP_BL2 content certificate identifier, used by BL2 to load the SCP_BL2
  267. content certificate (mandatory when Trusted Board Boot is enabled).
  268. If a BL32 image is supported by the platform, the following constants must
  269. also be defined:
  270. - **#define : BL32_IMAGE_ID**
  271. BL32 image identifier, used by BL2 to load BL32.
  272. - **#define : TRUSTED_OS_FW_KEY_CERT_ID**
  273. BL32 key certificate identifier, used by BL2 to load the BL32 key
  274. certificate (mandatory when Trusted Board Boot is enabled).
  275. - **#define : TRUSTED_OS_FW_CONTENT_CERT_ID**
  276. BL32 content certificate identifier, used by BL2 to load the BL32 content
  277. certificate (mandatory when Trusted Board Boot is enabled).
  278. - **#define : BL32_BASE**
  279. Defines the base address in secure memory where BL2 loads the BL32 binary
  280. image. Must be aligned on a page-size boundary.
  281. - **#define : BL32_LIMIT**
  282. Defines the maximum address that the BL32 image can occupy.
  283. If the Test Secure-EL1 Payload (TSP) instantiation of BL32 is supported by the
  284. platform, the following constants must also be defined:
  285. - **#define : TSP_SEC_MEM_BASE**
  286. Defines the base address of the secure memory used by the TSP image on the
  287. platform. This must be at the same address or below ``BL32_BASE``.
  288. - **#define : TSP_SEC_MEM_SIZE**
  289. Defines the size of the secure memory used by the BL32 image on the
  290. platform. ``TSP_SEC_MEM_BASE`` and ``TSP_SEC_MEM_SIZE`` must fully
  291. accommodate the memory required by the BL32 image, defined by ``BL32_BASE``
  292. and ``BL32_LIMIT``.
  293. - **#define : TSP_IRQ_SEC_PHY_TIMER**
  294. Defines the ID of the secure physical generic timer interrupt used by the
  295. TSP's interrupt handling code.
  296. If the platform port uses the translation table library code, the following
  297. constants must also be defined:
  298. - **#define : PLAT_XLAT_TABLES_DYNAMIC**
  299. Optional flag that can be set per-image to enable the dynamic allocation of
  300. regions even when the MMU is enabled. If not defined, only static
  301. functionality will be available, if defined and set to 1 it will also
  302. include the dynamic functionality.
  303. - **#define : MAX_XLAT_TABLES**
  304. Defines the maximum number of translation tables that are allocated by the
  305. translation table library code. To minimize the amount of runtime memory
  306. used, choose the smallest value needed to map the required virtual addresses
  307. for each BL stage. If ``PLAT_XLAT_TABLES_DYNAMIC`` flag is enabled for a BL
  308. image, ``MAX_XLAT_TABLES`` must be defined to accommodate the dynamic regions
  309. as well.
  310. - **#define : MAX_MMAP_REGIONS**
  311. Defines the maximum number of regions that are allocated by the translation
  312. table library code. A region consists of physical base address, virtual base
  313. address, size and attributes (Device/Memory, RO/RW, Secure/Non-Secure), as
  314. defined in the ``mmap_region_t`` structure. The platform defines the regions
  315. that should be mapped. Then, the translation table library will create the
  316. corresponding tables and descriptors at runtime. To minimize the amount of
  317. runtime memory used, choose the smallest value needed to register the
  318. required regions for each BL stage. If ``PLAT_XLAT_TABLES_DYNAMIC`` flag is
  319. enabled for a BL image, ``MAX_MMAP_REGIONS`` must be defined to accommodate
  320. the dynamic regions as well.
  321. - **#define : PLAT_VIRT_ADDR_SPACE_SIZE**
  322. Defines the total size of the virtual address space in bytes. For example,
  323. for a 32 bit virtual address space, this value should be ``(1ULL << 32)``.
  324. - **#define : PLAT_PHY_ADDR_SPACE_SIZE**
  325. Defines the total size of the physical address space in bytes. For example,
  326. for a 32 bit physical address space, this value should be ``(1ULL << 32)``.
  327. If the platform port uses the IO storage framework, the following constants
  328. must also be defined:
  329. - **#define : MAX_IO_DEVICES**
  330. Defines the maximum number of registered IO devices. Attempting to register
  331. more devices than this value using ``io_register_device()`` will fail with
  332. -ENOMEM.
  333. - **#define : MAX_IO_HANDLES**
  334. Defines the maximum number of open IO handles. Attempting to open more IO
  335. entities than this value using ``io_open()`` will fail with -ENOMEM.
  336. - **#define : MAX_IO_BLOCK_DEVICES**
  337. Defines the maximum number of registered IO block devices. Attempting to
  338. register more devices this value using ``io_dev_open()`` will fail
  339. with -ENOMEM. MAX_IO_BLOCK_DEVICES should be less than MAX_IO_DEVICES.
  340. With this macro, multiple block devices could be supported at the same
  341. time.
  342. If the platform needs to allocate data within the per-cpu data framework in
  343. BL31, it should define the following macro. Currently this is only required if
  344. the platform decides not to use the coherent memory section by undefining the
  345. ``USE_COHERENT_MEM`` build flag. In this case, the framework allocates the
  346. required memory within the the per-cpu data to minimize wastage.
  347. - **#define : PLAT_PCPU_DATA_SIZE**
  348. Defines the memory (in bytes) to be reserved within the per-cpu data
  349. structure for use by the platform layer.
  350. The following constants are optional. They should be defined when the platform
  351. memory layout implies some image overlaying like in Arm standard platforms.
  352. - **#define : BL31_PROGBITS_LIMIT**
  353. Defines the maximum address in secure RAM that the BL31's progbits sections
  354. can occupy.
  355. - **#define : TSP_PROGBITS_LIMIT**
  356. Defines the maximum address that the TSP's progbits sections can occupy.
  357. If the platform port uses the PL061 GPIO driver, the following constant may
  358. optionally be defined:
  359. - **PLAT_PL061_MAX_GPIOS**
  360. Maximum number of GPIOs required by the platform. This allows control how
  361. much memory is allocated for PL061 GPIO controllers. The default value is
  362. #. $(eval $(call add_define,PLAT_PL061_MAX_GPIOS))
  363. If the platform port uses the partition driver, the following constant may
  364. optionally be defined:
  365. - **PLAT_PARTITION_MAX_ENTRIES**
  366. Maximum number of partition entries required by the platform. This allows
  367. control how much memory is allocated for partition entries. The default
  368. value is 128.
  369. For example, define the build flag in ``platform.mk``:
  370. PLAT_PARTITION_MAX_ENTRIES := 12
  371. $(eval $(call add_define,PLAT_PARTITION_MAX_ENTRIES))
  372. - **PLAT_PARTITION_BLOCK_SIZE**
  373. The size of partition block. It could be either 512 bytes or 4096 bytes.
  374. The default value is 512.
  375. For example, define the build flag in ``platform.mk``:
  376. PLAT_PARTITION_BLOCK_SIZE := 4096
  377. $(eval $(call add_define,PLAT_PARTITION_BLOCK_SIZE))
  378. The following constant is optional. It should be defined to override the default
  379. behaviour of the ``assert()`` function (for example, to save memory).
  380. - **PLAT_LOG_LEVEL_ASSERT**
  381. If ``PLAT_LOG_LEVEL_ASSERT`` is higher or equal than ``LOG_LEVEL_VERBOSE``,
  382. ``assert()`` prints the name of the file, the line number and the asserted
  383. expression. Else if it is higher than ``LOG_LEVEL_INFO``, it prints the file
  384. name and the line number. Else if it is lower than ``LOG_LEVEL_INFO``, it
  385. doesn't print anything to the console. If ``PLAT_LOG_LEVEL_ASSERT`` isn't
  386. defined, it defaults to ``LOG_LEVEL``.
  387. If the platform port uses the DRTM feature, the following constants must be
  388. defined:
  389. - **#define : PLAT_DRTM_EVENT_LOG_MAX_SIZE**
  390. Maximum Event Log size used by the platform. Platform can decide the maximum
  391. size of the Event Log buffer, depending upon the highest hash algorithm
  392. chosen and the number of components selected to measure during the DRTM
  393. execution flow.
  394. - **#define : PLAT_DRTM_MMAP_ENTRIES**
  395. Number of the MMAP entries used by the DRTM implementation to calculate the
  396. size of address map region of the platform.
  397. File : plat_macros.S [mandatory]
  398. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  399. Each platform must ensure a file of this name is in the system include path with
  400. the following macro defined. In the Arm development platforms, this file is
  401. found in ``plat/arm/board/<plat_name>/include/plat_macros.S``.
  402. - **Macro : plat_crash_print_regs**
  403. This macro allows the crash reporting routine to print relevant platform
  404. registers in case of an unhandled exception in BL31. This aids in debugging
  405. and this macro can be defined to be empty in case register reporting is not
  406. desired.
  407. For instance, GIC or interconnect registers may be helpful for
  408. troubleshooting.
  409. Handling Reset
  410. --------------
  411. BL1 by default implements the reset vector where execution starts from a cold
  412. or warm boot. BL31 can be optionally set as a reset vector using the
  413. ``RESET_TO_BL31`` make variable.
  414. For each CPU, the reset vector code is responsible for the following tasks:
  415. #. Distinguishing between a cold boot and a warm boot.
  416. #. In the case of a cold boot and the CPU being a secondary CPU, ensuring that
  417. the CPU is placed in a platform-specific state until the primary CPU
  418. performs the necessary steps to remove it from this state.
  419. #. In the case of a warm boot, ensuring that the CPU jumps to a platform-
  420. specific address in the BL31 image in the same processor mode as it was
  421. when released from reset.
  422. The following functions need to be implemented by the platform port to enable
  423. reset vector code to perform the above tasks.
  424. Function : plat_get_my_entrypoint() [mandatory when PROGRAMMABLE_RESET_ADDRESS == 0]
  425. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  426. ::
  427. Argument : void
  428. Return : uintptr_t
  429. This function is called with the MMU and caches disabled
  430. (``SCTLR_EL3.M`` = 0 and ``SCTLR_EL3.C`` = 0). The function is responsible for
  431. distinguishing between a warm and cold reset for the current CPU using
  432. platform-specific means. If it's a warm reset, then it returns the warm
  433. reset entrypoint point provided to ``plat_setup_psci_ops()`` during
  434. BL31 initialization. If it's a cold reset then this function must return zero.
  435. This function does not follow the Procedure Call Standard used by the
  436. Application Binary Interface for the Arm 64-bit architecture. The caller should
  437. not assume that callee saved registers are preserved across a call to this
  438. function.
  439. This function fulfills requirement 1 and 3 listed above.
  440. Note that for platforms that support programming the reset address, it is
  441. expected that a CPU will start executing code directly at the right address,
  442. both on a cold and warm reset. In this case, there is no need to identify the
  443. type of reset nor to query the warm reset entrypoint. Therefore, implementing
  444. this function is not required on such platforms.
  445. Function : plat_secondary_cold_boot_setup() [mandatory when COLD_BOOT_SINGLE_CPU == 0]
  446. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  447. ::
  448. Argument : void
  449. This function is called with the MMU and data caches disabled. It is responsible
  450. for placing the executing secondary CPU in a platform-specific state until the
  451. primary CPU performs the necessary actions to bring it out of that state and
  452. allow entry into the OS. This function must not return.
  453. In the Arm FVP port, when using the normal boot flow, each secondary CPU powers
  454. itself off. The primary CPU is responsible for powering up the secondary CPUs
  455. when normal world software requires them. When booting an EL3 payload instead,
  456. they stay powered on and are put in a holding pen until their mailbox gets
  457. populated.
  458. This function fulfills requirement 2 above.
  459. Note that for platforms that can't release secondary CPUs out of reset, only the
  460. primary CPU will execute the cold boot code. Therefore, implementing this
  461. function is not required on such platforms.
  462. Function : plat_is_my_cpu_primary() [mandatory when COLD_BOOT_SINGLE_CPU == 0]
  463. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  464. ::
  465. Argument : void
  466. Return : unsigned int
  467. This function identifies whether the current CPU is the primary CPU or a
  468. secondary CPU. A return value of zero indicates that the CPU is not the
  469. primary CPU, while a non-zero return value indicates that the CPU is the
  470. primary CPU.
  471. Note that for platforms that can't release secondary CPUs out of reset, only the
  472. primary CPU will execute the cold boot code. Therefore, there is no need to
  473. distinguish between primary and secondary CPUs and implementing this function is
  474. not required.
  475. Function : platform_mem_init() [mandatory]
  476. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  477. ::
  478. Argument : void
  479. Return : void
  480. This function is called before any access to data is made by the firmware, in
  481. order to carry out any essential memory initialization.
  482. Function: plat_get_rotpk_info()
  483. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  484. ::
  485. Argument : void *, void **, unsigned int *, unsigned int *
  486. Return : int
  487. This function is mandatory when Trusted Board Boot is enabled. It returns a
  488. pointer to the ROTPK stored in the platform (or a hash of it) and its length.
  489. The ROTPK must be encoded in DER format according to the following ASN.1
  490. structure:
  491. ::
  492. AlgorithmIdentifier ::= SEQUENCE {
  493. algorithm OBJECT IDENTIFIER,
  494. parameters ANY DEFINED BY algorithm OPTIONAL
  495. }
  496. SubjectPublicKeyInfo ::= SEQUENCE {
  497. algorithm AlgorithmIdentifier,
  498. subjectPublicKey BIT STRING
  499. }
  500. In case the function returns a hash of the key:
  501. ::
  502. DigestInfo ::= SEQUENCE {
  503. digestAlgorithm AlgorithmIdentifier,
  504. digest OCTET STRING
  505. }
  506. The function returns 0 on success. Any other value is treated as error by the
  507. Trusted Board Boot. The function also reports extra information related
  508. to the ROTPK in the flags parameter:
  509. ::
  510. ROTPK_IS_HASH : Indicates that the ROTPK returned by the platform is a
  511. hash.
  512. ROTPK_NOT_DEPLOYED : This allows the platform to skip certificate ROTPK
  513. verification while the platform ROTPK is not deployed.
  514. When this flag is set, the function does not need to
  515. return a platform ROTPK, and the authentication
  516. framework uses the ROTPK in the certificate without
  517. verifying it against the platform value. This flag
  518. must not be used in a deployed production environment.
  519. Function: plat_get_nv_ctr()
  520. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  521. ::
  522. Argument : void *, unsigned int *
  523. Return : int
  524. This function is mandatory when Trusted Board Boot is enabled. It returns the
  525. non-volatile counter value stored in the platform in the second argument. The
  526. cookie in the first argument may be used to select the counter in case the
  527. platform provides more than one (for example, on platforms that use the default
  528. TBBR CoT, the cookie will correspond to the OID values defined in
  529. TRUSTED_FW_NVCOUNTER_OID or NON_TRUSTED_FW_NVCOUNTER_OID).
  530. The function returns 0 on success. Any other value means the counter value could
  531. not be retrieved from the platform.
  532. Function: plat_set_nv_ctr()
  533. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  534. ::
  535. Argument : void *, unsigned int
  536. Return : int
  537. This function is mandatory when Trusted Board Boot is enabled. It sets a new
  538. counter value in the platform. The cookie in the first argument may be used to
  539. select the counter (as explained in plat_get_nv_ctr()). The second argument is
  540. the updated counter value to be written to the NV counter.
  541. The function returns 0 on success. Any other value means the counter value could
  542. not be updated.
  543. Function: plat_set_nv_ctr2()
  544. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  545. ::
  546. Argument : void *, const auth_img_desc_t *, unsigned int
  547. Return : int
  548. This function is optional when Trusted Board Boot is enabled. If this
  549. interface is defined, then ``plat_set_nv_ctr()`` need not be defined. The
  550. first argument passed is a cookie and is typically used to
  551. differentiate between a Non Trusted NV Counter and a Trusted NV
  552. Counter. The second argument is a pointer to an authentication image
  553. descriptor and may be used to decide if the counter is allowed to be
  554. updated or not. The third argument is the updated counter value to
  555. be written to the NV counter.
  556. The function returns 0 on success. Any other value means the counter value
  557. either could not be updated or the authentication image descriptor indicates
  558. that it is not allowed to be updated.
  559. Function: plat_convert_pk()
  560. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  561. ::
  562. Argument : void *, unsigned int, void **, unsigned int *
  563. Return : int
  564. This function is optional when Trusted Board Boot is enabled, and only
  565. used if the platform saves a hash of the ROTPK.
  566. First argument is the Distinguished Encoding Rules (DER) ROTPK.
  567. Second argument is its size.
  568. Third argument is used to return a pointer to a buffer, which hash should
  569. be the one saved in OTP.
  570. Fourth argument is a pointer to return its size.
  571. Most platforms save the hash of the ROTPK, but some may save slightly different
  572. information - e.g the hash of the ROTPK plus some related information.
  573. Defining this function allows to transform the ROTPK used to verify
  574. the signature to the buffer (a platform specific public key) which
  575. hash is saved in OTP.
  576. The default implementation copies the input key and length to the output without
  577. modification.
  578. The function returns 0 on success. Any other value means the expected
  579. public key buffer cannot be extracted.
  580. Dynamic Root of Trust for Measurement support (in BL31)
  581. -------------------------------------------------------
  582. The functions mentioned in this section are mandatory, when platform enables
  583. DRTM_SUPPORT build flag.
  584. Function : plat_get_addr_mmap()
  585. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  586. ::
  587. Argument : void
  588. Return : const mmap_region_t *
  589. This function is used to return the address of the platform *address-map* table,
  590. which describes the regions of normal memory, memory mapped I/O
  591. and non-volatile memory.
  592. Function : plat_has_non_host_platforms()
  593. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  594. ::
  595. Argument : void
  596. Return : bool
  597. This function returns *true* if the platform has any trusted devices capable of
  598. DMA, otherwise returns *false*.
  599. Function : plat_has_unmanaged_dma_peripherals()
  600. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  601. ::
  602. Argument : void
  603. Return : bool
  604. This function returns *true* if platform uses peripherals whose DMA is not
  605. managed by an SMMU, otherwise returns *false*.
  606. Note -
  607. If the platform has peripherals that are not managed by the SMMU, then the
  608. platform should investigate such peripherals to determine whether they can
  609. be trusted, and such peripherals should be moved under "Non-host platforms"
  610. if they can be trusted.
  611. Function : plat_get_total_num_smmus()
  612. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  613. ::
  614. Argument : void
  615. Return : unsigned int
  616. This function returns the total number of SMMUs in the platform.
  617. Function : plat_enumerate_smmus()
  618. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  619. ::
  620. Argument : void
  621. Return : const uintptr_t *, size_t
  622. This function returns an array of SMMU addresses and the actual number of SMMUs
  623. reported by the platform.
  624. Function : plat_drtm_get_dma_prot_features()
  625. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  626. ::
  627. Argument : void
  628. Return : const plat_drtm_dma_prot_features_t*
  629. This function returns the address of plat_drtm_dma_prot_features_t structure
  630. containing the maximum number of protected regions and bitmap with the types
  631. of DMA protection supported by the platform.
  632. For more details see section 3.3 Table 6 of `DRTM`_ specification.
  633. Function : plat_drtm_dma_prot_get_max_table_bytes()
  634. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  635. ::
  636. Argument : void
  637. Return : uint64_t
  638. This function returns the maximum size of DMA protected regions table in
  639. bytes.
  640. Function : plat_drtm_get_tpm_features()
  641. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  642. ::
  643. Argument : void
  644. Return : const plat_drtm_tpm_features_t*
  645. This function returns the address of *plat_drtm_tpm_features_t* structure
  646. containing PCR usage schema, TPM-based hash, and firmware hash algorithm
  647. supported by the platform.
  648. Function : plat_drtm_get_min_size_normal_world_dce()
  649. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  650. ::
  651. Argument : void
  652. Return : uint64_t
  653. This function returns the size normal-world DCE of the platform.
  654. Function : plat_drtm_get_imp_def_dlme_region_size()
  655. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  656. ::
  657. Argument : void
  658. Return : uint64_t
  659. This function returns the size of implementation defined DLME region
  660. of the platform.
  661. Function : plat_drtm_get_tcb_hash_table_size()
  662. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  663. ::
  664. Argument : void
  665. Return : uint64_t
  666. This function returns the size of TCB hash table of the platform.
  667. Function : plat_drtm_get_tcb_hash_features()
  668. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  669. ::
  670. Argument : void
  671. Return : uint64_t
  672. This function returns the Maximum number of TCB hashes recorded by the
  673. platform.
  674. For more details see section 3.3 Table 6 of `DRTM`_ specification.
  675. Function : plat_drtm_validate_ns_region()
  676. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  677. ::
  678. Argument : uintptr_t, uintptr_t
  679. Return : int
  680. This function validates that given region is within the Non-Secure region
  681. of DRAM. This function takes a region start address and size an input
  682. arguments, and returns 0 on success and -1 on failure.
  683. Function : plat_set_drtm_error()
  684. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  685. ::
  686. Argument : uint64_t
  687. Return : int
  688. This function writes a 64 bit error code received as input into
  689. non-volatile storage and returns 0 on success and -1 on failure.
  690. Function : plat_get_drtm_error()
  691. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  692. ::
  693. Argument : uint64_t*
  694. Return : int
  695. This function reads a 64 bit error code from the non-volatile storage
  696. into the received address, and returns 0 on success and -1 on failure.
  697. Common mandatory function modifications
  698. ---------------------------------------
  699. The following functions are mandatory functions which need to be implemented
  700. by the platform port.
  701. Function : plat_my_core_pos()
  702. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  703. ::
  704. Argument : void
  705. Return : unsigned int
  706. This function returns the index of the calling CPU which is used as a
  707. CPU-specific linear index into blocks of memory (for example while allocating
  708. per-CPU stacks). This function will be invoked very early in the
  709. initialization sequence which mandates that this function should be
  710. implemented in assembly and should not rely on the availability of a C
  711. runtime environment. This function can clobber x0 - x8 and must preserve
  712. x9 - x29.
  713. This function plays a crucial role in the power domain topology framework in
  714. PSCI and details of this can be found in
  715. :ref:`PSCI Power Domain Tree Structure`.
  716. Function : plat_core_pos_by_mpidr()
  717. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  718. ::
  719. Argument : u_register_t
  720. Return : int
  721. This function validates the ``MPIDR`` of a CPU and converts it to an index,
  722. which can be used as a CPU-specific linear index into blocks of memory. In
  723. case the ``MPIDR`` is invalid, this function returns -1. This function will only
  724. be invoked by BL31 after the power domain topology is initialized and can
  725. utilize the C runtime environment. For further details about how TF-A
  726. represents the power domain topology and how this relates to the linear CPU
  727. index, please refer :ref:`PSCI Power Domain Tree Structure`.
  728. Function : plat_get_mbedtls_heap() [when TRUSTED_BOARD_BOOT == 1]
  729. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  730. ::
  731. Arguments : void **heap_addr, size_t *heap_size
  732. Return : int
  733. This function is invoked during Mbed TLS library initialisation to get a heap,
  734. by means of a starting address and a size. This heap will then be used
  735. internally by the Mbed TLS library. Hence, each BL stage that utilises Mbed TLS
  736. must be able to provide a heap to it.
  737. A helper function can be found in `drivers/auth/mbedtls/mbedtls_common.c` in
  738. which a heap is statically reserved during compile time inside every image
  739. (i.e. every BL stage) that utilises Mbed TLS. In this default implementation,
  740. the function simply returns the address and size of this "pre-allocated" heap.
  741. For a platform to use this default implementation, only a call to the helper
  742. from inside plat_get_mbedtls_heap() body is enough and nothing else is needed.
  743. However, by writting their own implementation, platforms have the potential to
  744. optimise memory usage. For example, on some Arm platforms, the Mbed TLS heap is
  745. shared between BL1 and BL2 stages and, thus, the necessary space is not reserved
  746. twice.
  747. On success the function should return 0 and a negative error code otherwise.
  748. Function : plat_get_enc_key_info() [when FW_ENC_STATUS == 0 or 1]
  749. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  750. ::
  751. Arguments : enum fw_enc_status_t fw_enc_status, uint8_t *key,
  752. size_t *key_len, unsigned int *flags, const uint8_t *img_id,
  753. size_t img_id_len
  754. Return : int
  755. This function provides a symmetric key (either SSK or BSSK depending on
  756. fw_enc_status) which is invoked during runtime decryption of encrypted
  757. firmware images. `plat/common/plat_bl_common.c` provides a dummy weak
  758. implementation for testing purposes which must be overridden by the platform
  759. trying to implement a real world firmware encryption use-case.
  760. It also allows the platform to pass symmetric key identifier rather than
  761. actual symmetric key which is useful in cases where the crypto backend provides
  762. secure storage for the symmetric key. So in this case ``ENC_KEY_IS_IDENTIFIER``
  763. flag must be set in ``flags``.
  764. In addition to above a platform may also choose to provide an image specific
  765. symmetric key/identifier using img_id.
  766. On success the function should return 0 and a negative error code otherwise.
  767. Note that this API depends on ``DECRYPTION_SUPPORT`` build flag.
  768. Function : plat_fwu_set_images_source() [when PSA_FWU_SUPPORT == 1]
  769. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  770. ::
  771. Argument : const struct fwu_metadata *metadata
  772. Return : void
  773. This function is mandatory when PSA_FWU_SUPPORT is enabled.
  774. It provides a means to retrieve image specification (offset in
  775. non-volatile storage and length) of active/updated images using the passed
  776. FWU metadata, and update I/O policies of active/updated images using retrieved
  777. image specification information.
  778. Further I/O layer operations such as I/O open, I/O read, etc. on these
  779. images rely on this function call.
  780. In Arm platforms, this function is used to set an I/O policy of the FIP image,
  781. container of all active/updated secure and non-secure images.
  782. Function : plat_fwu_set_metadata_image_source() [when PSA_FWU_SUPPORT == 1]
  783. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  784. ::
  785. Argument : unsigned int image_id, uintptr_t *dev_handle,
  786. uintptr_t *image_spec
  787. Return : int
  788. This function is mandatory when PSA_FWU_SUPPORT is enabled. It is
  789. responsible for setting up the platform I/O policy of the requested metadata
  790. image (either FWU_METADATA_IMAGE_ID or BKUP_FWU_METADATA_IMAGE_ID) that will
  791. be used to load this image from the platform's non-volatile storage.
  792. FWU metadata can not be always stored as a raw image in non-volatile storage
  793. to define its image specification (offset in non-volatile storage and length)
  794. statically in I/O policy.
  795. For example, the FWU metadata image is stored as a partition inside the GUID
  796. partition table image. Its specification is defined in the partition table
  797. that needs to be parsed dynamically.
  798. This function provides a means to retrieve such dynamic information to set
  799. the I/O policy of the FWU metadata image.
  800. Further I/O layer operations such as I/O open, I/O read, etc. on FWU metadata
  801. image relies on this function call.
  802. It returns '0' on success, otherwise a negative error value on error.
  803. Alongside, returns device handle and image specification from the I/O policy
  804. of the requested FWU metadata image.
  805. Function : plat_fwu_get_boot_idx() [when PSA_FWU_SUPPORT == 1]
  806. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  807. ::
  808. Argument : void
  809. Return : uint32_t
  810. This function is mandatory when PSA_FWU_SUPPORT is enabled. It provides the
  811. means to retrieve the boot index value from the platform. The boot index is the
  812. bank from which the platform has booted the firmware images.
  813. By default, the platform will read the metadata structure and try to boot from
  814. the active bank. If the platform fails to boot from the active bank due to
  815. reasons like an Authentication failure, or on crossing a set number of watchdog
  816. resets while booting from the active bank, the platform can then switch to boot
  817. from a different bank. This function then returns the bank that the platform
  818. should boot its images from.
  819. Common optional modifications
  820. -----------------------------
  821. The following are helper functions implemented by the firmware that perform
  822. common platform-specific tasks. A platform may choose to override these
  823. definitions.
  824. Function : plat_set_my_stack()
  825. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  826. ::
  827. Argument : void
  828. Return : void
  829. This function sets the current stack pointer to the normal memory stack that
  830. has been allocated for the current CPU. For BL images that only require a
  831. stack for the primary CPU, the UP version of the function is used. The size
  832. of the stack allocated to each CPU is specified by the platform defined
  833. constant ``PLATFORM_STACK_SIZE``.
  834. Common implementations of this function for the UP and MP BL images are
  835. provided in ``plat/common/aarch64/platform_up_stack.S`` and
  836. ``plat/common/aarch64/platform_mp_stack.S``
  837. Function : plat_get_my_stack()
  838. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  839. ::
  840. Argument : void
  841. Return : uintptr_t
  842. This function returns the base address of the normal memory stack that
  843. has been allocated for the current CPU. For BL images that only require a
  844. stack for the primary CPU, the UP version of the function is used. The size
  845. of the stack allocated to each CPU is specified by the platform defined
  846. constant ``PLATFORM_STACK_SIZE``.
  847. Common implementations of this function for the UP and MP BL images are
  848. provided in ``plat/common/aarch64/platform_up_stack.S`` and
  849. ``plat/common/aarch64/platform_mp_stack.S``
  850. Function : plat_report_exception()
  851. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  852. ::
  853. Argument : unsigned int
  854. Return : void
  855. A platform may need to report various information about its status when an
  856. exception is taken, for example the current exception level, the CPU security
  857. state (secure/non-secure), the exception type, and so on. This function is
  858. called in the following circumstances:
  859. - In BL1, whenever an exception is taken.
  860. - In BL2, whenever an exception is taken.
  861. The default implementation doesn't do anything, to avoid making assumptions
  862. about the way the platform displays its status information.
  863. For AArch64, this function receives the exception type as its argument.
  864. Possible values for exceptions types are listed in the
  865. ``include/common/bl_common.h`` header file. Note that these constants are not
  866. related to any architectural exception code; they are just a TF-A convention.
  867. For AArch32, this function receives the exception mode as its argument.
  868. Possible values for exception modes are listed in the
  869. ``include/lib/aarch32/arch.h`` header file.
  870. Function : plat_reset_handler()
  871. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  872. ::
  873. Argument : void
  874. Return : void
  875. A platform may need to do additional initialization after reset. This function
  876. allows the platform to do the platform specific initializations. Platform
  877. specific errata workarounds could also be implemented here. The API should
  878. preserve the values of callee saved registers x19 to x29.
  879. The default implementation doesn't do anything. If a platform needs to override
  880. the default implementation, refer to the :ref:`Firmware Design` for general
  881. guidelines.
  882. Function : plat_disable_acp()
  883. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  884. ::
  885. Argument : void
  886. Return : void
  887. This API allows a platform to disable the Accelerator Coherency Port (if
  888. present) during a cluster power down sequence. The default weak implementation
  889. doesn't do anything. Since this API is called during the power down sequence,
  890. it has restrictions for stack usage and it can use the registers x0 - x17 as
  891. scratch registers. It should preserve the value in x18 register as it is used
  892. by the caller to store the return address.
  893. Function : plat_error_handler()
  894. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  895. ::
  896. Argument : int
  897. Return : void
  898. This API is called when the generic code encounters an error situation from
  899. which it cannot continue. It allows the platform to perform error reporting or
  900. recovery actions (for example, reset the system). This function must not return.
  901. The parameter indicates the type of error using standard codes from ``errno.h``.
  902. Possible errors reported by the generic code are:
  903. - ``-EAUTH``: a certificate or image could not be authenticated (when Trusted
  904. Board Boot is enabled)
  905. - ``-ENOENT``: the requested image or certificate could not be found or an IO
  906. error was detected
  907. - ``-ENOMEM``: resources exhausted. TF-A does not use dynamic memory, so this
  908. error is usually an indication of an incorrect array size
  909. The default implementation simply spins.
  910. Function : plat_panic_handler()
  911. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  912. ::
  913. Argument : void
  914. Return : void
  915. This API is called when the generic code encounters an unexpected error
  916. situation from which it cannot recover. This function must not return,
  917. and must be implemented in assembly because it may be called before the C
  918. environment is initialized.
  919. .. note::
  920. The address from where it was called is stored in x30 (Link Register).
  921. The default implementation simply spins.
  922. Function : plat_system_reset()
  923. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  924. ::
  925. Argument : void
  926. Return : void
  927. This function is used by the platform to resets the system. It can be used
  928. in any specific use-case where system needs to be resetted. For example,
  929. in case of DRTM implementation this function reset the system after
  930. writing the DRTM error code in the non-volatile storage. This function
  931. never returns. Failure in reset results in panic.
  932. Function : plat_get_bl_image_load_info()
  933. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  934. ::
  935. Argument : void
  936. Return : bl_load_info_t *
  937. This function returns pointer to the list of images that the platform has
  938. populated to load. This function is invoked in BL2 to load the
  939. BL3xx images.
  940. Function : plat_get_next_bl_params()
  941. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  942. ::
  943. Argument : void
  944. Return : bl_params_t *
  945. This function returns a pointer to the shared memory that the platform has
  946. kept aside to pass TF-A related information that next BL image needs. This
  947. function is invoked in BL2 to pass this information to the next BL
  948. image.
  949. Function : plat_get_stack_protector_canary()
  950. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  951. ::
  952. Argument : void
  953. Return : u_register_t
  954. This function returns a random value that is used to initialize the canary used
  955. when the stack protector is enabled with ENABLE_STACK_PROTECTOR. A predictable
  956. value will weaken the protection as the attacker could easily write the right
  957. value as part of the attack most of the time. Therefore, it should return a
  958. true random number.
  959. .. warning::
  960. For the protection to be effective, the global data need to be placed at
  961. a lower address than the stack bases. Failure to do so would allow an
  962. attacker to overwrite the canary as part of the stack buffer overflow attack.
  963. Function : plat_flush_next_bl_params()
  964. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  965. ::
  966. Argument : void
  967. Return : void
  968. This function flushes to main memory all the image params that are passed to
  969. next image. This function is invoked in BL2 to flush this information
  970. to the next BL image.
  971. Function : plat_log_get_prefix()
  972. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  973. ::
  974. Argument : unsigned int
  975. Return : const char *
  976. This function defines the prefix string corresponding to the `log_level` to be
  977. prepended to all the log output from TF-A. The `log_level` (argument) will
  978. correspond to one of the standard log levels defined in debug.h. The platform
  979. can override the common implementation to define a different prefix string for
  980. the log output. The implementation should be robust to future changes that
  981. increase the number of log levels.
  982. Function : plat_get_soc_version()
  983. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  984. ::
  985. Argument : void
  986. Return : int32_t
  987. This function returns soc version which mainly consist of below fields
  988. ::
  989. soc_version[30:24] = JEP-106 continuation code for the SiP
  990. soc_version[23:16] = JEP-106 identification code with parity bit for the SiP
  991. soc_version[15:0] = Implementation defined SoC ID
  992. Function : plat_get_soc_revision()
  993. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  994. ::
  995. Argument : void
  996. Return : int32_t
  997. This function returns soc revision in below format
  998. ::
  999. soc_revision[0:30] = SOC revision of specific SOC
  1000. Function : plat_is_smccc_feature_available()
  1001. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1002. ::
  1003. Argument : u_register_t
  1004. Return : int32_t
  1005. This function returns SMC_ARCH_CALL_SUCCESS if the platform supports
  1006. the SMCCC function specified in the argument; otherwise returns
  1007. SMC_ARCH_CALL_NOT_SUPPORTED.
  1008. Function : plat_mboot_measure_image()
  1009. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1010. ::
  1011. Argument : unsigned int, image_info_t *
  1012. Return : int
  1013. When the MEASURED_BOOT flag is enabled:
  1014. - This function measures the given image and records its measurement using
  1015. the measured boot backend driver.
  1016. - On the Arm FVP port, this function measures the given image using its
  1017. passed id and information and then records that measurement in the
  1018. Event Log buffer.
  1019. - This function must return 0 on success, a signed integer error code
  1020. otherwise.
  1021. When the MEASURED_BOOT flag is disabled, this function doesn't do anything.
  1022. Function : plat_mboot_measure_critical_data()
  1023. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1024. ::
  1025. Argument : unsigned int, const void *, size_t
  1026. Return : int
  1027. When the MEASURED_BOOT flag is enabled:
  1028. - This function measures the given critical data structure and records its
  1029. measurement using the measured boot backend driver.
  1030. - This function must return 0 on success, a signed integer error code
  1031. otherwise.
  1032. When the MEASURED_BOOT flag is disabled, this function doesn't do anything.
  1033. Function : plat_can_cmo()
  1034. ~~~~~~~~~~~~~~~~~~~~~~~~~
  1035. ::
  1036. Argument : void
  1037. Return : uint64_t
  1038. When CONDITIONAL_CMO flag is enabled:
  1039. - This function indicates whether cache management operations should be
  1040. performed. It returns 0 if CMOs should be skipped and non-zero
  1041. otherwise.
  1042. - The function must not clobber x1, x2 and x3. It's also not safe to rely on
  1043. stack. Otherwise obey AAPCS.
  1044. Modifications specific to a Boot Loader stage
  1045. ---------------------------------------------
  1046. Boot Loader Stage 1 (BL1)
  1047. -------------------------
  1048. BL1 implements the reset vector where execution starts from after a cold or
  1049. warm boot. For each CPU, BL1 is responsible for the following tasks:
  1050. #. Handling the reset as described in section 2.2
  1051. #. In the case of a cold boot and the CPU being the primary CPU, ensuring that
  1052. only this CPU executes the remaining BL1 code, including loading and passing
  1053. control to the BL2 stage.
  1054. #. Identifying and starting the Firmware Update process (if required).
  1055. #. Loading the BL2 image from non-volatile storage into secure memory at the
  1056. address specified by the platform defined constant ``BL2_BASE``.
  1057. #. Populating a ``meminfo`` structure with the following information in memory,
  1058. accessible by BL2 immediately upon entry.
  1059. ::
  1060. meminfo.total_base = Base address of secure RAM visible to BL2
  1061. meminfo.total_size = Size of secure RAM visible to BL2
  1062. By default, BL1 places this ``meminfo`` structure at the end of secure
  1063. memory visible to BL2.
  1064. It is possible for the platform to decide where it wants to place the
  1065. ``meminfo`` structure for BL2 or restrict the amount of memory visible to
  1066. BL2 by overriding the weak default implementation of
  1067. ``bl1_plat_handle_post_image_load`` API.
  1068. The following functions need to be implemented by the platform port to enable
  1069. BL1 to perform the above tasks.
  1070. Function : bl1_early_platform_setup() [mandatory]
  1071. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1072. ::
  1073. Argument : void
  1074. Return : void
  1075. This function executes with the MMU and data caches disabled. It is only called
  1076. by the primary CPU.
  1077. On Arm standard platforms, this function:
  1078. - Enables a secure instance of SP805 to act as the Trusted Watchdog.
  1079. - Initializes a UART (PL011 console), which enables access to the ``printf``
  1080. family of functions in BL1.
  1081. - Enables issuing of snoop and DVM (Distributed Virtual Memory) requests to
  1082. the CCI slave interface corresponding to the cluster that includes the
  1083. primary CPU.
  1084. Function : bl1_plat_arch_setup() [mandatory]
  1085. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1086. ::
  1087. Argument : void
  1088. Return : void
  1089. This function performs any platform-specific and architectural setup that the
  1090. platform requires. Platform-specific setup might include configuration of
  1091. memory controllers and the interconnect.
  1092. In Arm standard platforms, this function enables the MMU.
  1093. This function helps fulfill requirement 2 above.
  1094. Function : bl1_platform_setup() [mandatory]
  1095. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1096. ::
  1097. Argument : void
  1098. Return : void
  1099. This function executes with the MMU and data caches enabled. It is responsible
  1100. for performing any remaining platform-specific setup that can occur after the
  1101. MMU and data cache have been enabled.
  1102. if support for multiple boot sources is required, it initializes the boot
  1103. sequence used by plat_try_next_boot_source().
  1104. In Arm standard platforms, this function initializes the storage abstraction
  1105. layer used to load the next bootloader image.
  1106. This function helps fulfill requirement 4 above.
  1107. Function : bl1_plat_sec_mem_layout() [mandatory]
  1108. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1109. ::
  1110. Argument : void
  1111. Return : meminfo *
  1112. This function should only be called on the cold boot path. It executes with the
  1113. MMU and data caches enabled. The pointer returned by this function must point to
  1114. a ``meminfo`` structure containing the extents and availability of secure RAM for
  1115. the BL1 stage.
  1116. ::
  1117. meminfo.total_base = Base address of secure RAM visible to BL1
  1118. meminfo.total_size = Size of secure RAM visible to BL1
  1119. This information is used by BL1 to load the BL2 image in secure RAM. BL1 also
  1120. populates a similar structure to tell BL2 the extents of memory available for
  1121. its own use.
  1122. This function helps fulfill requirements 4 and 5 above.
  1123. Function : bl1_plat_prepare_exit() [optional]
  1124. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1125. ::
  1126. Argument : entry_point_info_t *
  1127. Return : void
  1128. This function is called prior to exiting BL1 in response to the
  1129. ``BL1_SMC_RUN_IMAGE`` SMC request raised by BL2. It should be used to perform
  1130. platform specific clean up or bookkeeping operations before transferring
  1131. control to the next image. It receives the address of the ``entry_point_info_t``
  1132. structure passed from BL2. This function runs with MMU disabled.
  1133. Function : bl1_plat_set_ep_info() [optional]
  1134. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1135. ::
  1136. Argument : unsigned int image_id, entry_point_info_t *ep_info
  1137. Return : void
  1138. This function allows platforms to override ``ep_info`` for the given ``image_id``.
  1139. The default implementation just returns.
  1140. Function : bl1_plat_get_next_image_id() [optional]
  1141. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1142. ::
  1143. Argument : void
  1144. Return : unsigned int
  1145. This and the following function must be overridden to enable the FWU feature.
  1146. BL1 calls this function after platform setup to identify the next image to be
  1147. loaded and executed. If the platform returns ``BL2_IMAGE_ID`` then BL1 proceeds
  1148. with the normal boot sequence, which loads and executes BL2. If the platform
  1149. returns a different image id, BL1 assumes that Firmware Update is required.
  1150. The default implementation always returns ``BL2_IMAGE_ID``. The Arm development
  1151. platforms override this function to detect if firmware update is required, and
  1152. if so, return the first image in the firmware update process.
  1153. Function : bl1_plat_get_image_desc() [optional]
  1154. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1155. ::
  1156. Argument : unsigned int image_id
  1157. Return : image_desc_t *
  1158. BL1 calls this function to get the image descriptor information ``image_desc_t``
  1159. for the provided ``image_id`` from the platform.
  1160. The default implementation always returns a common BL2 image descriptor. Arm
  1161. standard platforms return an image descriptor corresponding to BL2 or one of
  1162. the firmware update images defined in the Trusted Board Boot Requirements
  1163. specification.
  1164. Function : bl1_plat_handle_pre_image_load() [optional]
  1165. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1166. ::
  1167. Argument : unsigned int image_id
  1168. Return : int
  1169. This function can be used by the platforms to update/use image information
  1170. corresponding to ``image_id``. This function is invoked in BL1, both in cold
  1171. boot and FWU code path, before loading the image.
  1172. Function : bl1_plat_handle_post_image_load() [optional]
  1173. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1174. ::
  1175. Argument : unsigned int image_id
  1176. Return : int
  1177. This function can be used by the platforms to update/use image information
  1178. corresponding to ``image_id``. This function is invoked in BL1, both in cold
  1179. boot and FWU code path, after loading and authenticating the image.
  1180. The default weak implementation of this function calculates the amount of
  1181. Trusted SRAM that can be used by BL2 and allocates a ``meminfo_t``
  1182. structure at the beginning of this free memory and populates it. The address
  1183. of ``meminfo_t`` structure is updated in ``arg1`` of the entrypoint
  1184. information to BL2.
  1185. Function : bl1_plat_fwu_done() [optional]
  1186. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1187. ::
  1188. Argument : unsigned int image_id, uintptr_t image_src,
  1189. unsigned int image_size
  1190. Return : void
  1191. BL1 calls this function when the FWU process is complete. It must not return.
  1192. The platform may override this function to take platform specific action, for
  1193. example to initiate the normal boot flow.
  1194. The default implementation spins forever.
  1195. Function : bl1_plat_mem_check() [mandatory]
  1196. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1197. ::
  1198. Argument : uintptr_t mem_base, unsigned int mem_size,
  1199. unsigned int flags
  1200. Return : int
  1201. BL1 calls this function while handling FWU related SMCs, more specifically when
  1202. copying or authenticating an image. Its responsibility is to ensure that the
  1203. region of memory identified by ``mem_base`` and ``mem_size`` is mapped in BL1, and
  1204. that this memory corresponds to either a secure or non-secure memory region as
  1205. indicated by the security state of the ``flags`` argument.
  1206. This function can safely assume that the value resulting from the addition of
  1207. ``mem_base`` and ``mem_size`` fits into a ``uintptr_t`` type variable and does not
  1208. overflow.
  1209. This function must return 0 on success, a non-null error code otherwise.
  1210. The default implementation of this function asserts therefore platforms must
  1211. override it when using the FWU feature.
  1212. Function : bl1_plat_mboot_init() [optional]
  1213. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1214. ::
  1215. Argument : void
  1216. Return : void
  1217. When the MEASURED_BOOT flag is enabled:
  1218. - This function is used to initialize the backend driver(s) of measured boot.
  1219. - On the Arm FVP port, this function is used to initialize the Event Log
  1220. backend driver, and also to write header information in the Event Log buffer.
  1221. When the MEASURED_BOOT flag is disabled, this function doesn't do anything.
  1222. Function : bl1_plat_mboot_finish() [optional]
  1223. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1224. ::
  1225. Argument : void
  1226. Return : void
  1227. When the MEASURED_BOOT flag is enabled:
  1228. - This function is used to finalize the measured boot backend driver(s),
  1229. and also, set the information for the next bootloader component to
  1230. extend the measurement if needed.
  1231. - On the Arm FVP port, this function is used to pass the base address of
  1232. the Event Log buffer and its size to BL2 via tb_fw_config to extend the
  1233. Event Log buffer with the measurement of various images loaded by BL2.
  1234. It results in panic on error.
  1235. When the MEASURED_BOOT flag is disabled, this function doesn't do anything.
  1236. Boot Loader Stage 2 (BL2)
  1237. -------------------------
  1238. The BL2 stage is executed only by the primary CPU, which is determined in BL1
  1239. using the ``platform_is_primary_cpu()`` function. BL1 passed control to BL2 at
  1240. ``BL2_BASE``. BL2 executes in Secure EL1 and and invokes
  1241. ``plat_get_bl_image_load_info()`` to retrieve the list of images to load from
  1242. non-volatile storage to secure/non-secure RAM. After all the images are loaded
  1243. then BL2 invokes ``plat_get_next_bl_params()`` to get the list of executable
  1244. images to be passed to the next BL image.
  1245. The following functions must be implemented by the platform port to enable BL2
  1246. to perform the above tasks.
  1247. Function : bl2_early_platform_setup2() [mandatory]
  1248. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1249. ::
  1250. Argument : u_register_t, u_register_t, u_register_t, u_register_t
  1251. Return : void
  1252. This function executes with the MMU and data caches disabled. It is only called
  1253. by the primary CPU. The 4 arguments are passed by BL1 to BL2 and these arguments
  1254. are platform specific.
  1255. On Arm standard platforms, the arguments received are :
  1256. arg0 - Points to load address of FW_CONFIG
  1257. arg1 - ``meminfo`` structure populated by BL1. The platform copies
  1258. the contents of ``meminfo`` as it may be subsequently overwritten by BL2.
  1259. On Arm standard platforms, this function also:
  1260. - Initializes a UART (PL011 console), which enables access to the ``printf``
  1261. family of functions in BL2.
  1262. - Initializes the storage abstraction layer used to load further bootloader
  1263. images. It is necessary to do this early on platforms with a SCP_BL2 image,
  1264. since the later ``bl2_platform_setup`` must be done after SCP_BL2 is loaded.
  1265. Function : bl2_plat_arch_setup() [mandatory]
  1266. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1267. ::
  1268. Argument : void
  1269. Return : void
  1270. This function executes with the MMU and data caches disabled. It is only called
  1271. by the primary CPU.
  1272. The purpose of this function is to perform any architectural initialization
  1273. that varies across platforms.
  1274. On Arm standard platforms, this function enables the MMU.
  1275. Function : bl2_platform_setup() [mandatory]
  1276. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1277. ::
  1278. Argument : void
  1279. Return : void
  1280. This function may execute with the MMU and data caches enabled if the platform
  1281. port does the necessary initialization in ``bl2_plat_arch_setup()``. It is only
  1282. called by the primary CPU.
  1283. The purpose of this function is to perform any platform initialization
  1284. specific to BL2.
  1285. In Arm standard platforms, this function performs security setup, including
  1286. configuration of the TrustZone controller to allow non-secure masters access
  1287. to most of DRAM. Part of DRAM is reserved for secure world use.
  1288. Function : bl2_plat_handle_pre_image_load() [optional]
  1289. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1290. ::
  1291. Argument : unsigned int
  1292. Return : int
  1293. This function can be used by the platforms to update/use image information
  1294. for given ``image_id``. This function is currently invoked in BL2 before
  1295. loading each image.
  1296. Function : bl2_plat_handle_post_image_load() [optional]
  1297. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1298. ::
  1299. Argument : unsigned int
  1300. Return : int
  1301. This function can be used by the platforms to update/use image information
  1302. for given ``image_id``. This function is currently invoked in BL2 after
  1303. loading each image.
  1304. Function : bl2_plat_preload_setup [optional]
  1305. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1306. ::
  1307. Argument : void
  1308. Return : void
  1309. This optional function performs any BL2 platform initialization
  1310. required before image loading, that is not done later in
  1311. bl2_platform_setup(). Specifically, if support for multiple
  1312. boot sources is required, it initializes the boot sequence used by
  1313. plat_try_next_boot_source().
  1314. Function : plat_try_next_boot_source() [optional]
  1315. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1316. ::
  1317. Argument : void
  1318. Return : int
  1319. This optional function passes to the next boot source in the redundancy
  1320. sequence.
  1321. This function moves the current boot redundancy source to the next
  1322. element in the boot sequence. If there are no more boot sources then it
  1323. must return 0, otherwise it must return 1. The default implementation
  1324. of this always returns 0.
  1325. Function : bl2_plat_mboot_init() [optional]
  1326. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1327. ::
  1328. Argument : void
  1329. Return : void
  1330. When the MEASURED_BOOT flag is enabled:
  1331. - This function is used to initialize the backend driver(s) of measured boot.
  1332. - On the Arm FVP port, this function is used to initialize the Event Log
  1333. backend driver with the Event Log buffer information (base address and
  1334. size) received from BL1. It results in panic on error.
  1335. When the MEASURED_BOOT flag is disabled, this function doesn't do anything.
  1336. Function : bl2_plat_mboot_finish() [optional]
  1337. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1338. ::
  1339. Argument : void
  1340. Return : void
  1341. When the MEASURED_BOOT flag is enabled:
  1342. - This function is used to finalize the measured boot backend driver(s),
  1343. and also, set the information for the next bootloader component to extend
  1344. the measurement if needed.
  1345. - On the Arm FVP port, this function is used to pass the Event Log buffer
  1346. information (base address and size) to non-secure(BL33) and trusted OS(BL32)
  1347. via nt_fw and tos_fw config respectively. It results in panic on error.
  1348. When the MEASURED_BOOT flag is disabled, this function doesn't do anything.
  1349. Boot Loader Stage 2 (BL2) at EL3
  1350. --------------------------------
  1351. When the platform has a non-TF-A Boot ROM it is desirable to jump
  1352. directly to BL2 instead of TF-A BL1. In this case BL2 is expected to
  1353. execute at EL3 instead of executing at EL1. Refer to the :ref:`Firmware Design`
  1354. document for more information.
  1355. All mandatory functions of BL2 must be implemented, except the functions
  1356. bl2_early_platform_setup and bl2_el3_plat_arch_setup, because
  1357. their work is done now by bl2_el3_early_platform_setup and
  1358. bl2_el3_plat_arch_setup. These functions should generally implement
  1359. the bl1_plat_xxx() and bl2_plat_xxx() functionality combined.
  1360. Function : bl2_el3_early_platform_setup() [mandatory]
  1361. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1362. ::
  1363. Argument : u_register_t, u_register_t, u_register_t, u_register_t
  1364. Return : void
  1365. This function executes with the MMU and data caches disabled. It is only called
  1366. by the primary CPU. This function receives four parameters which can be used
  1367. by the platform to pass any needed information from the Boot ROM to BL2.
  1368. On Arm standard platforms, this function does the following:
  1369. - Initializes a UART (PL011 console), which enables access to the ``printf``
  1370. family of functions in BL2.
  1371. - Initializes the storage abstraction layer used to load further bootloader
  1372. images. It is necessary to do this early on platforms with a SCP_BL2 image,
  1373. since the later ``bl2_platform_setup`` must be done after SCP_BL2 is loaded.
  1374. - Initializes the private variables that define the memory layout used.
  1375. Function : bl2_el3_plat_arch_setup() [mandatory]
  1376. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1377. ::
  1378. Argument : void
  1379. Return : void
  1380. This function executes with the MMU and data caches disabled. It is only called
  1381. by the primary CPU.
  1382. The purpose of this function is to perform any architectural initialization
  1383. that varies across platforms.
  1384. On Arm standard platforms, this function enables the MMU.
  1385. Function : bl2_el3_plat_prepare_exit() [optional]
  1386. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1387. ::
  1388. Argument : void
  1389. Return : void
  1390. This function is called prior to exiting BL2 and run the next image.
  1391. It should be used to perform platform specific clean up or bookkeeping
  1392. operations before transferring control to the next image. This function
  1393. runs with MMU disabled.
  1394. FWU Boot Loader Stage 2 (BL2U)
  1395. ------------------------------
  1396. The AP Firmware Updater Configuration, BL2U, is an optional part of the FWU
  1397. process and is executed only by the primary CPU. BL1 passes control to BL2U at
  1398. ``BL2U_BASE``. BL2U executes in Secure-EL1 and is responsible for:
  1399. #. (Optional) Transferring the optional SCP_BL2U binary image from AP secure
  1400. memory to SCP RAM. BL2U uses the SCP_BL2U ``image_info`` passed by BL1.
  1401. ``SCP_BL2U_BASE`` defines the address in AP secure memory where SCP_BL2U
  1402. should be copied from. Subsequent handling of the SCP_BL2U image is
  1403. implemented by the platform specific ``bl2u_plat_handle_scp_bl2u()`` function.
  1404. If ``SCP_BL2U_BASE`` is not defined then this step is not performed.
  1405. #. Any platform specific setup required to perform the FWU process. For
  1406. example, Arm standard platforms initialize the TZC controller so that the
  1407. normal world can access DDR memory.
  1408. The following functions must be implemented by the platform port to enable
  1409. BL2U to perform the tasks mentioned above.
  1410. Function : bl2u_early_platform_setup() [mandatory]
  1411. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1412. ::
  1413. Argument : meminfo *mem_info, void *plat_info
  1414. Return : void
  1415. This function executes with the MMU and data caches disabled. It is only
  1416. called by the primary CPU. The arguments to this function is the address
  1417. of the ``meminfo`` structure and platform specific info provided by BL1.
  1418. The platform may copy the contents of the ``mem_info`` and ``plat_info`` into
  1419. private storage as the original memory may be subsequently overwritten by BL2U.
  1420. On Arm CSS platforms ``plat_info`` is interpreted as an ``image_info_t`` structure,
  1421. to extract SCP_BL2U image information, which is then copied into a private
  1422. variable.
  1423. Function : bl2u_plat_arch_setup() [mandatory]
  1424. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1425. ::
  1426. Argument : void
  1427. Return : void
  1428. This function executes with the MMU and data caches disabled. It is only
  1429. called by the primary CPU.
  1430. The purpose of this function is to perform any architectural initialization
  1431. that varies across platforms, for example enabling the MMU (since the memory
  1432. map differs across platforms).
  1433. Function : bl2u_platform_setup() [mandatory]
  1434. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1435. ::
  1436. Argument : void
  1437. Return : void
  1438. This function may execute with the MMU and data caches enabled if the platform
  1439. port does the necessary initialization in ``bl2u_plat_arch_setup()``. It is only
  1440. called by the primary CPU.
  1441. The purpose of this function is to perform any platform initialization
  1442. specific to BL2U.
  1443. In Arm standard platforms, this function performs security setup, including
  1444. configuration of the TrustZone controller to allow non-secure masters access
  1445. to most of DRAM. Part of DRAM is reserved for secure world use.
  1446. Function : bl2u_plat_handle_scp_bl2u() [optional]
  1447. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1448. ::
  1449. Argument : void
  1450. Return : int
  1451. This function is used to perform any platform-specific actions required to
  1452. handle the SCP firmware. Typically it transfers the image into SCP memory using
  1453. a platform-specific protocol and waits until SCP executes it and signals to the
  1454. Application Processor (AP) for BL2U execution to continue.
  1455. This function returns 0 on success, a negative error code otherwise.
  1456. This function is included if SCP_BL2U_BASE is defined.
  1457. Boot Loader Stage 3-1 (BL31)
  1458. ----------------------------
  1459. During cold boot, the BL31 stage is executed only by the primary CPU. This is
  1460. determined in BL1 using the ``platform_is_primary_cpu()`` function. BL1 passes
  1461. control to BL31 at ``BL31_BASE``. During warm boot, BL31 is executed by all
  1462. CPUs. BL31 executes at EL3 and is responsible for:
  1463. #. Re-initializing all architectural and platform state. Although BL1 performs
  1464. some of this initialization, BL31 remains resident in EL3 and must ensure
  1465. that EL3 architectural and platform state is completely initialized. It
  1466. should make no assumptions about the system state when it receives control.
  1467. #. Passing control to a normal world BL image, pre-loaded at a platform-
  1468. specific address by BL2. On ARM platforms, BL31 uses the ``bl_params`` list
  1469. populated by BL2 in memory to do this.
  1470. #. Providing runtime firmware services. Currently, BL31 only implements a
  1471. subset of the Power State Coordination Interface (PSCI) API as a runtime
  1472. service. See :ref:`psci_in_bl31` below for details of porting the PSCI
  1473. implementation.
  1474. #. Optionally passing control to the BL32 image, pre-loaded at a platform-
  1475. specific address by BL2. BL31 exports a set of APIs that allow runtime
  1476. services to specify the security state in which the next image should be
  1477. executed and run the corresponding image. On ARM platforms, BL31 uses the
  1478. ``bl_params`` list populated by BL2 in memory to do this.
  1479. If BL31 is a reset vector, It also needs to handle the reset as specified in
  1480. section 2.2 before the tasks described above.
  1481. The following functions must be implemented by the platform port to enable BL31
  1482. to perform the above tasks.
  1483. Function : bl31_early_platform_setup2() [mandatory]
  1484. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1485. ::
  1486. Argument : u_register_t, u_register_t, u_register_t, u_register_t
  1487. Return : void
  1488. This function executes with the MMU and data caches disabled. It is only called
  1489. by the primary CPU. BL2 can pass 4 arguments to BL31 and these arguments are
  1490. platform specific.
  1491. In Arm standard platforms, the arguments received are :
  1492. arg0 - The pointer to the head of `bl_params_t` list
  1493. which is list of executable images following BL31,
  1494. arg1 - Points to load address of SOC_FW_CONFIG if present
  1495. except in case of Arm FVP and Juno platform.
  1496. In case of Arm FVP and Juno platform, points to load address
  1497. of FW_CONFIG.
  1498. arg2 - Points to load address of HW_CONFIG if present
  1499. arg3 - A special value to verify platform parameters from BL2 to BL31. Not
  1500. used in release builds.
  1501. The function runs through the `bl_param_t` list and extracts the entry point
  1502. information for BL32 and BL33. It also performs the following:
  1503. - Initialize a UART (PL011 console), which enables access to the ``printf``
  1504. family of functions in BL31.
  1505. - Enable issuing of snoop and DVM (Distributed Virtual Memory) requests to the
  1506. CCI slave interface corresponding to the cluster that includes the primary
  1507. CPU.
  1508. Function : bl31_plat_arch_setup() [mandatory]
  1509. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1510. ::
  1511. Argument : void
  1512. Return : void
  1513. This function executes with the MMU and data caches disabled. It is only called
  1514. by the primary CPU.
  1515. The purpose of this function is to perform any architectural initialization
  1516. that varies across platforms.
  1517. On Arm standard platforms, this function enables the MMU.
  1518. Function : bl31_platform_setup() [mandatory]
  1519. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1520. ::
  1521. Argument : void
  1522. Return : void
  1523. This function may execute with the MMU and data caches enabled if the platform
  1524. port does the necessary initialization in ``bl31_plat_arch_setup()``. It is only
  1525. called by the primary CPU.
  1526. The purpose of this function is to complete platform initialization so that both
  1527. BL31 runtime services and normal world software can function correctly.
  1528. On Arm standard platforms, this function does the following:
  1529. - Initialize the generic interrupt controller.
  1530. Depending on the GIC driver selected by the platform, the appropriate GICv2
  1531. or GICv3 initialization will be done, which mainly consists of:
  1532. - Enable secure interrupts in the GIC CPU interface.
  1533. - Disable the legacy interrupt bypass mechanism.
  1534. - Configure the priority mask register to allow interrupts of all priorities
  1535. to be signaled to the CPU interface.
  1536. - Mark SGIs 8-15 and the other secure interrupts on the platform as secure.
  1537. - Target all secure SPIs to CPU0.
  1538. - Enable these secure interrupts in the GIC distributor.
  1539. - Configure all other interrupts as non-secure.
  1540. - Enable signaling of secure interrupts in the GIC distributor.
  1541. - Enable system-level implementation of the generic timer counter through the
  1542. memory mapped interface.
  1543. - Grant access to the system counter timer module
  1544. - Initialize the power controller device.
  1545. In particular, initialise the locks that prevent concurrent accesses to the
  1546. power controller device.
  1547. Function : bl31_plat_runtime_setup() [optional]
  1548. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1549. ::
  1550. Argument : void
  1551. Return : void
  1552. The purpose of this function is allow the platform to perform any BL31 runtime
  1553. setup just prior to BL31 exit during cold boot. The default weak
  1554. implementation of this function will invoke ``console_switch_state()`` to switch
  1555. console output to consoles marked for use in the ``runtime`` state.
  1556. Function : bl31_plat_get_next_image_ep_info() [mandatory]
  1557. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1558. ::
  1559. Argument : uint32_t
  1560. Return : entry_point_info *
  1561. This function may execute with the MMU and data caches enabled if the platform
  1562. port does the necessary initializations in ``bl31_plat_arch_setup()``.
  1563. This function is called by ``bl31_main()`` to retrieve information provided by
  1564. BL2 for the next image in the security state specified by the argument. BL31
  1565. uses this information to pass control to that image in the specified security
  1566. state. This function must return a pointer to the ``entry_point_info`` structure
  1567. (that was copied during ``bl31_early_platform_setup()``) if the image exists. It
  1568. should return NULL otherwise.
  1569. Function : plat_rmmd_get_cca_attest_token() [mandatory when ENABLE_RME == 1]
  1570. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1571. ::
  1572. Argument : uintptr_t, size_t *, uintptr_t, size_t
  1573. Return : int
  1574. This function returns the Platform attestation token.
  1575. The parameters of the function are:
  1576. arg0 - A pointer to the buffer where the Platform token should be copied by
  1577. this function. The buffer must be big enough to hold the Platform
  1578. token.
  1579. arg1 - Contains the size (in bytes) of the buffer passed in arg0. The
  1580. function returns the platform token length in this parameter.
  1581. arg2 - A pointer to the buffer where the challenge object is stored.
  1582. arg3 - The length of the challenge object in bytes. Possible values are 32,
  1583. 48 and 64.
  1584. The function returns 0 on success, -EINVAL on failure.
  1585. Function : plat_rmmd_get_cca_realm_attest_key() [mandatory when ENABLE_RME == 1]
  1586. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1587. ::
  1588. Argument : uintptr_t, size_t *, unsigned int
  1589. Return : int
  1590. This function returns the delegated realm attestation key which will be used to
  1591. sign Realm attestation token. The API currently only supports P-384 ECC curve
  1592. key.
  1593. The parameters of the function are:
  1594. arg0 - A pointer to the buffer where the attestation key should be copied
  1595. by this function. The buffer must be big enough to hold the
  1596. attestation key.
  1597. arg1 - Contains the size (in bytes) of the buffer passed in arg0. The
  1598. function returns the attestation key length in this parameter.
  1599. arg2 - The type of the elliptic curve to which the requested attestation key
  1600. belongs.
  1601. The function returns 0 on success, -EINVAL on failure.
  1602. Function : plat_rmmd_get_el3_rmm_shared_mem() [when ENABLE_RME == 1]
  1603. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1604. ::
  1605. Argument : uintptr_t *
  1606. Return : size_t
  1607. This function returns the size of the shared area between EL3 and RMM (or 0 on
  1608. failure). A pointer to the shared area (or a NULL pointer on failure) is stored
  1609. in the pointer passed as argument.
  1610. Function : plat_rmmd_load_manifest() [when ENABLE_RME == 1]
  1611. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1612. ::
  1613. Arguments : rmm_manifest_t *manifest
  1614. Return : int
  1615. When ENABLE_RME is enabled, this function populates a boot manifest for the
  1616. RMM image and stores it in the area specified by manifest.
  1617. When ENABLE_RME is disabled, this function is not used.
  1618. Function : bl31_plat_enable_mmu [optional]
  1619. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1620. ::
  1621. Argument : uint32_t
  1622. Return : void
  1623. This function enables the MMU. The boot code calls this function with MMU and
  1624. caches disabled. This function should program necessary registers to enable
  1625. translation, and upon return, the MMU on the calling PE must be enabled.
  1626. The function must honor flags passed in the first argument. These flags are
  1627. defined by the translation library, and can be found in the file
  1628. ``include/lib/xlat_tables/xlat_mmu_helpers.h``.
  1629. On DynamIQ systems, this function must not use stack while enabling MMU, which
  1630. is how the function in xlat table library version 2 is implemented.
  1631. Function : plat_init_apkey [optional]
  1632. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1633. ::
  1634. Argument : void
  1635. Return : uint128_t
  1636. This function returns the 128-bit value which can be used to program ARMv8.3
  1637. pointer authentication keys.
  1638. The value should be obtained from a reliable source of randomness.
  1639. This function is only needed if ARMv8.3 pointer authentication is used in the
  1640. Trusted Firmware by building with ``BRANCH_PROTECTION`` option set to non-zero.
  1641. Function : plat_get_syscnt_freq2() [mandatory]
  1642. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1643. ::
  1644. Argument : void
  1645. Return : unsigned int
  1646. This function is used by the architecture setup code to retrieve the counter
  1647. frequency for the CPU's generic timer. This value will be programmed into the
  1648. ``CNTFRQ_EL0`` register. In Arm standard platforms, it returns the base frequency
  1649. of the system counter, which is retrieved from the first entry in the frequency
  1650. modes table.
  1651. #define : PLAT_PERCPU_BAKERY_LOCK_SIZE [optional]
  1652. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1653. When ``USE_COHERENT_MEM = 0``, this constant defines the total memory (in
  1654. bytes) aligned to the cache line boundary that should be allocated per-cpu to
  1655. accommodate all the bakery locks.
  1656. If this constant is not defined when ``USE_COHERENT_MEM = 0``, the linker
  1657. calculates the size of the ``.bakery_lock`` input section, aligns it to the
  1658. nearest ``CACHE_WRITEBACK_GRANULE``, multiplies it with ``PLATFORM_CORE_COUNT``
  1659. and stores the result in a linker symbol. This constant prevents a platform
  1660. from relying on the linker and provide a more efficient mechanism for
  1661. accessing per-cpu bakery lock information.
  1662. If this constant is defined and its value is not equal to the value
  1663. calculated by the linker then a link time assertion is raised. A compile time
  1664. assertion is raised if the value of the constant is not aligned to the cache
  1665. line boundary.
  1666. .. _porting_guide_sdei_requirements:
  1667. SDEI porting requirements
  1668. ~~~~~~~~~~~~~~~~~~~~~~~~~
  1669. The |SDEI| dispatcher requires the platform to provide the following macros
  1670. and functions, of which some are optional, and some others mandatory.
  1671. Macros
  1672. ......
  1673. Macro: PLAT_SDEI_NORMAL_PRI [mandatory]
  1674. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  1675. This macro must be defined to the EL3 exception priority level associated with
  1676. Normal |SDEI| events on the platform. This must have a higher value
  1677. (therefore of lower priority) than ``PLAT_SDEI_CRITICAL_PRI``.
  1678. Macro: PLAT_SDEI_CRITICAL_PRI [mandatory]
  1679. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  1680. This macro must be defined to the EL3 exception priority level associated with
  1681. Critical |SDEI| events on the platform. This must have a lower value
  1682. (therefore of higher priority) than ``PLAT_SDEI_NORMAL_PRI``.
  1683. **Note**: |SDEI| exception priorities must be the lowest among Secure
  1684. priorities. Among the |SDEI| exceptions, Critical |SDEI| priority must
  1685. be higher than Normal |SDEI| priority.
  1686. Functions
  1687. .........
  1688. Function: int plat_sdei_validate_entry_point() [optional]
  1689. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  1690. ::
  1691. Argument: uintptr_t ep, unsigned int client_mode
  1692. Return: int
  1693. This function validates the entry point address of the event handler provided by
  1694. the client for both event registration and *Complete and Resume* |SDEI| calls.
  1695. The function ensures that the address is valid in the client translation regime.
  1696. The second argument is the exception level that the client is executing in. It
  1697. can be Non-Secure EL1 or Non-Secure EL2.
  1698. The function must return ``0`` for successful validation, or ``-1`` upon failure.
  1699. The default implementation always returns ``0``. On Arm platforms, this function
  1700. translates the entry point address within the client translation regime and
  1701. further ensures that the resulting physical address is located in Non-secure
  1702. DRAM.
  1703. Function: void plat_sdei_handle_masked_trigger(uint64_t mpidr, unsigned int intr) [optional]
  1704. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  1705. ::
  1706. Argument: uint64_t
  1707. Argument: unsigned int
  1708. Return: void
  1709. |SDEI| specification requires that a PE comes out of reset with the events
  1710. masked. The client therefore is expected to call ``PE_UNMASK`` to unmask
  1711. |SDEI| events on the PE. No |SDEI| events can be dispatched until such
  1712. time.
  1713. Should a PE receive an interrupt that was bound to an |SDEI| event while the
  1714. events are masked on the PE, the dispatcher implementation invokes the function
  1715. ``plat_sdei_handle_masked_trigger``. The MPIDR of the PE that received the
  1716. interrupt and the interrupt ID are passed as parameters.
  1717. The default implementation only prints out a warning message.
  1718. .. _porting_guide_trng_requirements:
  1719. TRNG porting requirements
  1720. ~~~~~~~~~~~~~~~~~~~~~~~~~
  1721. The |TRNG| backend requires the platform to provide the following values
  1722. and mandatory functions.
  1723. Values
  1724. ......
  1725. value: uuid_t plat_trng_uuid [mandatory]
  1726. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  1727. This value must be defined to the UUID of the TRNG backend that is specific to
  1728. the hardware after ``plat_entropy_setup`` function is called. This value must
  1729. conform to the SMCCC calling convention; The most significant 32 bits of the
  1730. UUID must not equal ``0xffffffff`` or the signed integer ``-1`` as this value in
  1731. w0 indicates failure to get a TRNG source.
  1732. Functions
  1733. .........
  1734. Function: void plat_entropy_setup(void) [mandatory]
  1735. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  1736. ::
  1737. Argument: none
  1738. Return: none
  1739. This function is expected to do platform-specific initialization of any TRNG
  1740. hardware. This may include generating a UUID from a hardware-specific seed.
  1741. Function: bool plat_get_entropy(uint64_t \*out) [mandatory]
  1742. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  1743. ::
  1744. Argument: uint64_t *
  1745. Return: bool
  1746. Out : when the return value is true, the entropy has been written into the
  1747. storage pointed to
  1748. This function writes entropy into storage provided by the caller. If no entropy
  1749. is available, it must return false and the storage must not be written.
  1750. .. _psci_in_bl31:
  1751. Power State Coordination Interface (in BL31)
  1752. --------------------------------------------
  1753. The TF-A implementation of the PSCI API is based around the concept of a
  1754. *power domain*. A *power domain* is a CPU or a logical group of CPUs which
  1755. share some state on which power management operations can be performed as
  1756. specified by `PSCI`_. Each CPU in the system is assigned a cpu index which is
  1757. a unique number between ``0`` and ``PLATFORM_CORE_COUNT - 1``. The
  1758. *power domains* are arranged in a hierarchical tree structure and each
  1759. *power domain* can be identified in a system by the cpu index of any CPU that
  1760. is part of that domain and a *power domain level*. A processing element (for
  1761. example, a CPU) is at level 0. If the *power domain* node above a CPU is a
  1762. logical grouping of CPUs that share some state, then level 1 is that group of
  1763. CPUs (for example, a cluster), and level 2 is a group of clusters (for
  1764. example, the system). More details on the power domain topology and its
  1765. organization can be found in :ref:`PSCI Power Domain Tree Structure`.
  1766. BL31's platform initialization code exports a pointer to the platform-specific
  1767. power management operations required for the PSCI implementation to function
  1768. correctly. This information is populated in the ``plat_psci_ops`` structure. The
  1769. PSCI implementation calls members of the ``plat_psci_ops`` structure for performing
  1770. power management operations on the power domains. For example, the target
  1771. CPU is specified by its ``MPIDR`` in a PSCI ``CPU_ON`` call. The ``pwr_domain_on()``
  1772. handler (if present) is called for the CPU power domain.
  1773. The ``power-state`` parameter of a PSCI ``CPU_SUSPEND`` call can be used to
  1774. describe composite power states specific to a platform. The PSCI implementation
  1775. defines a generic representation of the power-state parameter, which is an
  1776. array of local power states where each index corresponds to a power domain
  1777. level. Each entry contains the local power state the power domain at that power
  1778. level could enter. It depends on the ``validate_power_state()`` handler to
  1779. convert the power-state parameter (possibly encoding a composite power state)
  1780. passed in a PSCI ``CPU_SUSPEND`` call to this representation.
  1781. The following functions form part of platform port of PSCI functionality.
  1782. Function : plat_psci_stat_accounting_start() [optional]
  1783. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1784. ::
  1785. Argument : const psci_power_state_t *
  1786. Return : void
  1787. This is an optional hook that platforms can implement for residency statistics
  1788. accounting before entering a low power state. The ``pwr_domain_state`` field of
  1789. ``state_info`` (first argument) can be inspected if stat accounting is done
  1790. differently at CPU level versus higher levels. As an example, if the element at
  1791. index 0 (CPU power level) in the ``pwr_domain_state`` array indicates a power down
  1792. state, special hardware logic may be programmed in order to keep track of the
  1793. residency statistics. For higher levels (array indices > 0), the residency
  1794. statistics could be tracked in software using PMF. If ``ENABLE_PMF`` is set, the
  1795. default implementation will use PMF to capture timestamps.
  1796. Function : plat_psci_stat_accounting_stop() [optional]
  1797. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1798. ::
  1799. Argument : const psci_power_state_t *
  1800. Return : void
  1801. This is an optional hook that platforms can implement for residency statistics
  1802. accounting after exiting from a low power state. The ``pwr_domain_state`` field
  1803. of ``state_info`` (first argument) can be inspected if stat accounting is done
  1804. differently at CPU level versus higher levels. As an example, if the element at
  1805. index 0 (CPU power level) in the ``pwr_domain_state`` array indicates a power down
  1806. state, special hardware logic may be programmed in order to keep track of the
  1807. residency statistics. For higher levels (array indices > 0), the residency
  1808. statistics could be tracked in software using PMF. If ``ENABLE_PMF`` is set, the
  1809. default implementation will use PMF to capture timestamps.
  1810. Function : plat_psci_stat_get_residency() [optional]
  1811. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1812. ::
  1813. Argument : unsigned int, const psci_power_state_t *, unsigned int
  1814. Return : u_register_t
  1815. This is an optional interface that is is invoked after resuming from a low power
  1816. state and provides the time spent resident in that low power state by the power
  1817. domain at a particular power domain level. When a CPU wakes up from suspend,
  1818. all its parent power domain levels are also woken up. The generic PSCI code
  1819. invokes this function for each parent power domain that is resumed and it
  1820. identified by the ``lvl`` (first argument) parameter. The ``state_info`` (second
  1821. argument) describes the low power state that the power domain has resumed from.
  1822. The current CPU is the first CPU in the power domain to resume from the low
  1823. power state and the ``last_cpu_idx`` (third parameter) is the index of the last
  1824. CPU in the power domain to suspend and may be needed to calculate the residency
  1825. for that power domain.
  1826. Function : plat_get_target_pwr_state() [optional]
  1827. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1828. ::
  1829. Argument : unsigned int, const plat_local_state_t *, unsigned int
  1830. Return : plat_local_state_t
  1831. The PSCI generic code uses this function to let the platform participate in
  1832. state coordination during a power management operation. The function is passed
  1833. a pointer to an array of platform specific local power state ``states`` (second
  1834. argument) which contains the requested power state for each CPU at a particular
  1835. power domain level ``lvl`` (first argument) within the power domain. The function
  1836. is expected to traverse this array of upto ``ncpus`` (third argument) and return
  1837. a coordinated target power state by the comparing all the requested power
  1838. states. The target power state should not be deeper than any of the requested
  1839. power states.
  1840. A weak definition of this API is provided by default wherein it assumes
  1841. that the platform assigns a local state value in order of increasing depth
  1842. of the power state i.e. for two power states X & Y, if X < Y
  1843. then X represents a shallower power state than Y. As a result, the
  1844. coordinated target local power state for a power domain will be the minimum
  1845. of the requested local power state values.
  1846. Function : plat_get_power_domain_tree_desc() [mandatory]
  1847. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1848. ::
  1849. Argument : void
  1850. Return : const unsigned char *
  1851. This function returns a pointer to the byte array containing the power domain
  1852. topology tree description. The format and method to construct this array are
  1853. described in :ref:`PSCI Power Domain Tree Structure`. The BL31 PSCI
  1854. initialization code requires this array to be described by the platform, either
  1855. statically or dynamically, to initialize the power domain topology tree. In case
  1856. the array is populated dynamically, then plat_core_pos_by_mpidr() and
  1857. plat_my_core_pos() should also be implemented suitably so that the topology tree
  1858. description matches the CPU indices returned by these APIs. These APIs together
  1859. form the platform interface for the PSCI topology framework.
  1860. Function : plat_setup_psci_ops() [mandatory]
  1861. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1862. ::
  1863. Argument : uintptr_t, const plat_psci_ops **
  1864. Return : int
  1865. This function may execute with the MMU and data caches enabled if the platform
  1866. port does the necessary initializations in ``bl31_plat_arch_setup()``. It is only
  1867. called by the primary CPU.
  1868. This function is called by PSCI initialization code. Its purpose is to let
  1869. the platform layer know about the warm boot entrypoint through the
  1870. ``sec_entrypoint`` (first argument) and to export handler routines for
  1871. platform-specific psci power management actions by populating the passed
  1872. pointer with a pointer to BL31's private ``plat_psci_ops`` structure.
  1873. A description of each member of this structure is given below. Please refer to
  1874. the Arm FVP specific implementation of these handlers in
  1875. ``plat/arm/board/fvp/fvp_pm.c`` as an example. For each PSCI function that the
  1876. platform wants to support, the associated operation or operations in this
  1877. structure must be provided and implemented (Refer section 4 of
  1878. :ref:`Firmware Design` for the PSCI API supported in TF-A). To disable a PSCI
  1879. function in a platform port, the operation should be removed from this
  1880. structure instead of providing an empty implementation.
  1881. plat_psci_ops.cpu_standby()
  1882. ...........................
  1883. Perform the platform-specific actions to enter the standby state for a cpu
  1884. indicated by the passed argument. This provides a fast path for CPU standby
  1885. wherein overheads of PSCI state management and lock acquisition is avoided.
  1886. For this handler to be invoked by the PSCI ``CPU_SUSPEND`` API implementation,
  1887. the suspend state type specified in the ``power-state`` parameter should be
  1888. STANDBY and the target power domain level specified should be the CPU. The
  1889. handler should put the CPU into a low power retention state (usually by
  1890. issuing a wfi instruction) and ensure that it can be woken up from that
  1891. state by a normal interrupt. The generic code expects the handler to succeed.
  1892. plat_psci_ops.pwr_domain_on()
  1893. .............................
  1894. Perform the platform specific actions to power on a CPU, specified
  1895. by the ``MPIDR`` (first argument). The generic code expects the platform to
  1896. return PSCI_E_SUCCESS on success or PSCI_E_INTERN_FAIL for any failure.
  1897. plat_psci_ops.pwr_domain_off()
  1898. ..............................
  1899. Perform the platform specific actions to prepare to power off the calling CPU
  1900. and its higher parent power domain levels as indicated by the ``target_state``
  1901. (first argument). It is called by the PSCI ``CPU_OFF`` API implementation.
  1902. The ``target_state`` encodes the platform coordinated target local power states
  1903. for the CPU power domain and its parent power domain levels. The handler
  1904. needs to perform power management operation corresponding to the local state
  1905. at each power level.
  1906. For this handler, the local power state for the CPU power domain will be a
  1907. power down state where as it could be either power down, retention or run state
  1908. for the higher power domain levels depending on the result of state
  1909. coordination. The generic code expects the handler to succeed.
  1910. plat_psci_ops.pwr_domain_suspend_pwrdown_early() [optional]
  1911. ...........................................................
  1912. This optional function may be used as a performance optimization to replace
  1913. or complement pwr_domain_suspend() on some platforms. Its calling semantics
  1914. are identical to pwr_domain_suspend(), except the PSCI implementation only
  1915. calls this function when suspending to a power down state, and it guarantees
  1916. that data caches are enabled.
  1917. When HW_ASSISTED_COHERENCY = 0, the PSCI implementation disables data caches
  1918. before calling pwr_domain_suspend(). If the target_state corresponds to a
  1919. power down state and it is safe to perform some or all of the platform
  1920. specific actions in that function with data caches enabled, it may be more
  1921. efficient to move those actions to this function. When HW_ASSISTED_COHERENCY
  1922. = 1, data caches remain enabled throughout, and so there is no advantage to
  1923. moving platform specific actions to this function.
  1924. plat_psci_ops.pwr_domain_suspend()
  1925. ..................................
  1926. Perform the platform specific actions to prepare to suspend the calling
  1927. CPU and its higher parent power domain levels as indicated by the
  1928. ``target_state`` (first argument). It is called by the PSCI ``CPU_SUSPEND``
  1929. API implementation.
  1930. The ``target_state`` has a similar meaning as described in
  1931. the ``pwr_domain_off()`` operation. It encodes the platform coordinated
  1932. target local power states for the CPU power domain and its parent
  1933. power domain levels. The handler needs to perform power management operation
  1934. corresponding to the local state at each power level. The generic code
  1935. expects the handler to succeed.
  1936. The difference between turning a power domain off versus suspending it is that
  1937. in the former case, the power domain is expected to re-initialize its state
  1938. when it is next powered on (see ``pwr_domain_on_finish()``). In the latter
  1939. case, the power domain is expected to save enough state so that it can resume
  1940. execution by restoring this state when its powered on (see
  1941. ``pwr_domain_suspend_finish()``).
  1942. When suspending a core, the platform can also choose to power off the GICv3
  1943. Redistributor and ITS through an implementation-defined sequence. To achieve
  1944. this safely, the ITS context must be saved first. The architectural part is
  1945. implemented by the ``gicv3_its_save_disable()`` helper, but most of the needed
  1946. sequence is implementation defined and it is therefore the responsibility of
  1947. the platform code to implement the necessary sequence. Then the GIC
  1948. Redistributor context can be saved using the ``gicv3_rdistif_save()`` helper.
  1949. Powering off the Redistributor requires the implementation to support it and it
  1950. is the responsibility of the platform code to execute the right implementation
  1951. defined sequence.
  1952. When a system suspend is requested, the platform can also make use of the
  1953. ``gicv3_distif_save()`` helper to save the context of the GIC Distributor after
  1954. it has saved the context of the Redistributors and ITS of all the cores in the
  1955. system. The context of the Distributor can be large and may require it to be
  1956. allocated in a special area if it cannot fit in the platform's global static
  1957. data, for example in DRAM. The Distributor can then be powered down using an
  1958. implementation-defined sequence.
  1959. plat_psci_ops.pwr_domain_pwr_down_wfi()
  1960. .......................................
  1961. This is an optional function and, if implemented, is expected to perform
  1962. platform specific actions including the ``wfi`` invocation which allows the
  1963. CPU to powerdown. Since this function is invoked outside the PSCI locks,
  1964. the actions performed in this hook must be local to the CPU or the platform
  1965. must ensure that races between multiple CPUs cannot occur.
  1966. The ``target_state`` has a similar meaning as described in the ``pwr_domain_off()``
  1967. operation and it encodes the platform coordinated target local power states for
  1968. the CPU power domain and its parent power domain levels. This function must
  1969. not return back to the caller (by calling wfi in an infinite loop to ensure
  1970. some CPUs power down mitigations work properly).
  1971. If this function is not implemented by the platform, PSCI generic
  1972. implementation invokes ``psci_power_down_wfi()`` for power down.
  1973. plat_psci_ops.pwr_domain_on_finish()
  1974. ....................................
  1975. This function is called by the PSCI implementation after the calling CPU is
  1976. powered on and released from reset in response to an earlier PSCI ``CPU_ON`` call.
  1977. It performs the platform-specific setup required to initialize enough state for
  1978. this CPU to enter the normal world and also provide secure runtime firmware
  1979. services.
  1980. The ``target_state`` (first argument) is the prior state of the power domains
  1981. immediately before the CPU was turned on. It indicates which power domains
  1982. above the CPU might require initialization due to having previously been in
  1983. low power states. The generic code expects the handler to succeed.
  1984. plat_psci_ops.pwr_domain_on_finish_late() [optional]
  1985. ...........................................................
  1986. This optional function is called by the PSCI implementation after the calling
  1987. CPU is fully powered on with respective data caches enabled. The calling CPU and
  1988. the associated cluster are guaranteed to be participating in coherency. This
  1989. function gives the flexibility to perform any platform-specific actions safely,
  1990. such as initialization or modification of shared data structures, without the
  1991. overhead of explicit cache maintainace operations.
  1992. The ``target_state`` has a similar meaning as described in the ``pwr_domain_on_finish()``
  1993. operation. The generic code expects the handler to succeed.
  1994. plat_psci_ops.pwr_domain_suspend_finish()
  1995. .........................................
  1996. This function is called by the PSCI implementation after the calling CPU is
  1997. powered on and released from reset in response to an asynchronous wakeup
  1998. event, for example a timer interrupt that was programmed by the CPU during the
  1999. ``CPU_SUSPEND`` call or ``SYSTEM_SUSPEND`` call. It performs the platform-specific
  2000. setup required to restore the saved state for this CPU to resume execution
  2001. in the normal world and also provide secure runtime firmware services.
  2002. The ``target_state`` (first argument) has a similar meaning as described in
  2003. the ``pwr_domain_on_finish()`` operation. The generic code expects the platform
  2004. to succeed.
  2005. If the Distributor, Redistributors or ITS have been powered off as part of a
  2006. suspend, their context must be restored in this function in the reverse order
  2007. to how they were saved during suspend sequence.
  2008. plat_psci_ops.system_off()
  2009. ..........................
  2010. This function is called by PSCI implementation in response to a ``SYSTEM_OFF``
  2011. call. It performs the platform-specific system poweroff sequence after
  2012. notifying the Secure Payload Dispatcher.
  2013. plat_psci_ops.system_reset()
  2014. ............................
  2015. This function is called by PSCI implementation in response to a ``SYSTEM_RESET``
  2016. call. It performs the platform-specific system reset sequence after
  2017. notifying the Secure Payload Dispatcher.
  2018. plat_psci_ops.validate_power_state()
  2019. ....................................
  2020. This function is called by the PSCI implementation during the ``CPU_SUSPEND``
  2021. call to validate the ``power_state`` parameter of the PSCI API and if valid,
  2022. populate it in ``req_state`` (second argument) array as power domain level
  2023. specific local states. If the ``power_state`` is invalid, the platform must
  2024. return PSCI_E_INVALID_PARAMS as error, which is propagated back to the
  2025. normal world PSCI client.
  2026. plat_psci_ops.validate_ns_entrypoint()
  2027. ......................................
  2028. This function is called by the PSCI implementation during the ``CPU_SUSPEND``,
  2029. ``SYSTEM_SUSPEND`` and ``CPU_ON`` calls to validate the non-secure ``entry_point``
  2030. parameter passed by the normal world. If the ``entry_point`` is invalid,
  2031. the platform must return PSCI_E_INVALID_ADDRESS as error, which is
  2032. propagated back to the normal world PSCI client.
  2033. plat_psci_ops.get_sys_suspend_power_state()
  2034. ...........................................
  2035. This function is called by the PSCI implementation during the ``SYSTEM_SUSPEND``
  2036. call to get the ``req_state`` parameter from platform which encodes the power
  2037. domain level specific local states to suspend to system affinity level. The
  2038. ``req_state`` will be utilized to do the PSCI state coordination and
  2039. ``pwr_domain_suspend()`` will be invoked with the coordinated target state to
  2040. enter system suspend.
  2041. plat_psci_ops.get_pwr_lvl_state_idx()
  2042. .....................................
  2043. This is an optional function and, if implemented, is invoked by the PSCI
  2044. implementation to convert the ``local_state`` (first argument) at a specified
  2045. ``pwr_lvl`` (second argument) to an index between 0 and
  2046. ``PLAT_MAX_PWR_LVL_STATES`` - 1. This function is only needed if the platform
  2047. supports more than two local power states at each power domain level, that is
  2048. ``PLAT_MAX_PWR_LVL_STATES`` is greater than 2, and needs to account for these
  2049. local power states.
  2050. plat_psci_ops.translate_power_state_by_mpidr()
  2051. ..............................................
  2052. This is an optional function and, if implemented, verifies the ``power_state``
  2053. (second argument) parameter of the PSCI API corresponding to a target power
  2054. domain. The target power domain is identified by using both ``MPIDR`` (first
  2055. argument) and the power domain level encoded in ``power_state``. The power domain
  2056. level specific local states are to be extracted from ``power_state`` and be
  2057. populated in the ``output_state`` (third argument) array. The functionality
  2058. is similar to the ``validate_power_state`` function described above and is
  2059. envisaged to be used in case the validity of ``power_state`` depend on the
  2060. targeted power domain. If the ``power_state`` is invalid for the targeted power
  2061. domain, the platform must return PSCI_E_INVALID_PARAMS as error. If this
  2062. function is not implemented, then the generic implementation relies on
  2063. ``validate_power_state`` function to translate the ``power_state``.
  2064. This function can also be used in case the platform wants to support local
  2065. power state encoding for ``power_state`` parameter of PSCI_STAT_COUNT/RESIDENCY
  2066. APIs as described in Section 5.18 of `PSCI`_.
  2067. plat_psci_ops.get_node_hw_state()
  2068. .................................
  2069. This is an optional function. If implemented this function is intended to return
  2070. the power state of a node (identified by the first parameter, the ``MPIDR``) in
  2071. the power domain topology (identified by the second parameter, ``power_level``),
  2072. as retrieved from a power controller or equivalent component on the platform.
  2073. Upon successful completion, the implementation must map and return the final
  2074. status among ``HW_ON``, ``HW_OFF`` or ``HW_STANDBY``. Upon encountering failures, it
  2075. must return either ``PSCI_E_INVALID_PARAMS`` or ``PSCI_E_NOT_SUPPORTED`` as
  2076. appropriate.
  2077. Implementations are not expected to handle ``power_levels`` greater than
  2078. ``PLAT_MAX_PWR_LVL``.
  2079. plat_psci_ops.system_reset2()
  2080. .............................
  2081. This is an optional function. If implemented this function is
  2082. called during the ``SYSTEM_RESET2`` call to perform a reset
  2083. based on the first parameter ``reset_type`` as specified in
  2084. `PSCI`_. The parameter ``cookie`` can be used to pass additional
  2085. reset information. If the ``reset_type`` is not supported, the
  2086. function must return ``PSCI_E_NOT_SUPPORTED``. For architectural
  2087. resets, all failures must return ``PSCI_E_INVALID_PARAMETERS``
  2088. and vendor reset can return other PSCI error codes as defined
  2089. in `PSCI`_. On success this function will not return.
  2090. plat_psci_ops.write_mem_protect()
  2091. .................................
  2092. This is an optional function. If implemented it enables or disables the
  2093. ``MEM_PROTECT`` functionality based on the value of ``val``.
  2094. A non-zero value enables ``MEM_PROTECT`` and a value of zero
  2095. disables it. Upon encountering failures it must return a negative value
  2096. and on success it must return 0.
  2097. plat_psci_ops.read_mem_protect()
  2098. ................................
  2099. This is an optional function. If implemented it returns the current
  2100. state of ``MEM_PROTECT`` via the ``val`` parameter. Upon encountering
  2101. failures it must return a negative value and on success it must
  2102. return 0.
  2103. plat_psci_ops.mem_protect_chk()
  2104. ...............................
  2105. This is an optional function. If implemented it checks if a memory
  2106. region defined by a base address ``base`` and with a size of ``length``
  2107. bytes is protected by ``MEM_PROTECT``. If the region is protected
  2108. then it must return 0, otherwise it must return a negative number.
  2109. .. _porting_guide_imf_in_bl31:
  2110. Interrupt Management framework (in BL31)
  2111. ----------------------------------------
  2112. BL31 implements an Interrupt Management Framework (IMF) to manage interrupts
  2113. generated in either security state and targeted to EL1 or EL2 in the non-secure
  2114. state or EL3/S-EL1 in the secure state. The design of this framework is
  2115. described in the :ref:`Interrupt Management Framework`
  2116. A platform should export the following APIs to support the IMF. The following
  2117. text briefly describes each API and its implementation in Arm standard
  2118. platforms. The API implementation depends upon the type of interrupt controller
  2119. present in the platform. Arm standard platform layer supports both
  2120. `Arm Generic Interrupt Controller version 2.0 (GICv2)`_
  2121. and `3.0 (GICv3)`_. Juno builds the Arm platform layer to use GICv2 and the
  2122. FVP can be configured to use either GICv2 or GICv3 depending on the build flag
  2123. ``FVP_USE_GIC_DRIVER`` (See :ref:`build_options_arm_fvp_platform` for more
  2124. details).
  2125. See also: :ref:`Interrupt Controller Abstraction APIs<Platform Interrupt Controller API>`.
  2126. Function : plat_interrupt_type_to_line() [mandatory]
  2127. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2128. ::
  2129. Argument : uint32_t, uint32_t
  2130. Return : uint32_t
  2131. The Arm processor signals an interrupt exception either through the IRQ or FIQ
  2132. interrupt line. The specific line that is signaled depends on how the interrupt
  2133. controller (IC) reports different interrupt types from an execution context in
  2134. either security state. The IMF uses this API to determine which interrupt line
  2135. the platform IC uses to signal each type of interrupt supported by the framework
  2136. from a given security state. This API must be invoked at EL3.
  2137. The first parameter will be one of the ``INTR_TYPE_*`` values (see
  2138. :ref:`Interrupt Management Framework`) indicating the target type of the
  2139. interrupt, the second parameter is the security state of the originating
  2140. execution context. The return result is the bit position in the ``SCR_EL3``
  2141. register of the respective interrupt trap: IRQ=1, FIQ=2.
  2142. In the case of Arm standard platforms using GICv2, S-EL1 interrupts are
  2143. configured as FIQs and Non-secure interrupts as IRQs from either security
  2144. state.
  2145. In the case of Arm standard platforms using GICv3, the interrupt line to be
  2146. configured depends on the security state of the execution context when the
  2147. interrupt is signalled and are as follows:
  2148. - The S-EL1 interrupts are signaled as IRQ in S-EL0/1 context and as FIQ in
  2149. NS-EL0/1/2 context.
  2150. - The Non secure interrupts are signaled as FIQ in S-EL0/1 context and as IRQ
  2151. in the NS-EL0/1/2 context.
  2152. - The EL3 interrupts are signaled as FIQ in both S-EL0/1 and NS-EL0/1/2
  2153. context.
  2154. Function : plat_ic_get_pending_interrupt_type() [mandatory]
  2155. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2156. ::
  2157. Argument : void
  2158. Return : uint32_t
  2159. This API returns the type of the highest priority pending interrupt at the
  2160. platform IC. The IMF uses the interrupt type to retrieve the corresponding
  2161. handler function. ``INTR_TYPE_INVAL`` is returned when there is no interrupt
  2162. pending. The valid interrupt types that can be returned are ``INTR_TYPE_EL3``,
  2163. ``INTR_TYPE_S_EL1`` and ``INTR_TYPE_NS``. This API must be invoked at EL3.
  2164. In the case of Arm standard platforms using GICv2, the *Highest Priority
  2165. Pending Interrupt Register* (``GICC_HPPIR``) is read to determine the id of
  2166. the pending interrupt. The type of interrupt depends upon the id value as
  2167. follows.
  2168. #. id < 1022 is reported as a S-EL1 interrupt
  2169. #. id = 1022 is reported as a Non-secure interrupt.
  2170. #. id = 1023 is reported as an invalid interrupt type.
  2171. In the case of Arm standard platforms using GICv3, the system register
  2172. ``ICC_HPPIR0_EL1``, *Highest Priority Pending group 0 Interrupt Register*,
  2173. is read to determine the id of the pending interrupt. The type of interrupt
  2174. depends upon the id value as follows.
  2175. #. id = ``PENDING_G1S_INTID`` (1020) is reported as a S-EL1 interrupt
  2176. #. id = ``PENDING_G1NS_INTID`` (1021) is reported as a Non-secure interrupt.
  2177. #. id = ``GIC_SPURIOUS_INTERRUPT`` (1023) is reported as an invalid interrupt type.
  2178. #. All other interrupt id's are reported as EL3 interrupt.
  2179. Function : plat_ic_get_pending_interrupt_id() [mandatory]
  2180. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2181. ::
  2182. Argument : void
  2183. Return : uint32_t
  2184. This API returns the id of the highest priority pending interrupt at the
  2185. platform IC. ``INTR_ID_UNAVAILABLE`` is returned when there is no interrupt
  2186. pending.
  2187. In the case of Arm standard platforms using GICv2, the *Highest Priority
  2188. Pending Interrupt Register* (``GICC_HPPIR``) is read to determine the id of the
  2189. pending interrupt. The id that is returned by API depends upon the value of
  2190. the id read from the interrupt controller as follows.
  2191. #. id < 1022. id is returned as is.
  2192. #. id = 1022. The *Aliased Highest Priority Pending Interrupt Register*
  2193. (``GICC_AHPPIR``) is read to determine the id of the non-secure interrupt.
  2194. This id is returned by the API.
  2195. #. id = 1023. ``INTR_ID_UNAVAILABLE`` is returned.
  2196. In the case of Arm standard platforms using GICv3, if the API is invoked from
  2197. EL3, the system register ``ICC_HPPIR0_EL1``, *Highest Priority Pending Interrupt
  2198. group 0 Register*, is read to determine the id of the pending interrupt. The id
  2199. that is returned by API depends upon the value of the id read from the
  2200. interrupt controller as follows.
  2201. #. id < ``PENDING_G1S_INTID`` (1020). id is returned as is.
  2202. #. id = ``PENDING_G1S_INTID`` (1020) or ``PENDING_G1NS_INTID`` (1021). The system
  2203. register ``ICC_HPPIR1_EL1``, *Highest Priority Pending Interrupt group 1
  2204. Register* is read to determine the id of the group 1 interrupt. This id
  2205. is returned by the API as long as it is a valid interrupt id
  2206. #. If the id is any of the special interrupt identifiers,
  2207. ``INTR_ID_UNAVAILABLE`` is returned.
  2208. When the API invoked from S-EL1 for GICv3 systems, the id read from system
  2209. register ``ICC_HPPIR1_EL1``, *Highest Priority Pending group 1 Interrupt
  2210. Register*, is returned if is not equal to GIC_SPURIOUS_INTERRUPT (1023) else
  2211. ``INTR_ID_UNAVAILABLE`` is returned.
  2212. Function : plat_ic_acknowledge_interrupt() [mandatory]
  2213. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2214. ::
  2215. Argument : void
  2216. Return : uint32_t
  2217. This API is used by the CPU to indicate to the platform IC that processing of
  2218. the highest pending interrupt has begun. It should return the raw, unmodified
  2219. value obtained from the interrupt controller when acknowledging an interrupt.
  2220. The actual interrupt number shall be extracted from this raw value using the API
  2221. `plat_ic_get_interrupt_id()<plat_ic_get_interrupt_id>`.
  2222. This function in Arm standard platforms using GICv2, reads the *Interrupt
  2223. Acknowledge Register* (``GICC_IAR``). This changes the state of the highest
  2224. priority pending interrupt from pending to active in the interrupt controller.
  2225. It returns the value read from the ``GICC_IAR``, unmodified.
  2226. In the case of Arm standard platforms using GICv3, if the API is invoked
  2227. from EL3, the function reads the system register ``ICC_IAR0_EL1``, *Interrupt
  2228. Acknowledge Register group 0*. If the API is invoked from S-EL1, the function
  2229. reads the system register ``ICC_IAR1_EL1``, *Interrupt Acknowledge Register
  2230. group 1*. The read changes the state of the highest pending interrupt from
  2231. pending to active in the interrupt controller. The value read is returned
  2232. unmodified.
  2233. The TSP uses this API to start processing of the secure physical timer
  2234. interrupt.
  2235. Function : plat_ic_end_of_interrupt() [mandatory]
  2236. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2237. ::
  2238. Argument : uint32_t
  2239. Return : void
  2240. This API is used by the CPU to indicate to the platform IC that processing of
  2241. the interrupt corresponding to the id (passed as the parameter) has
  2242. finished. The id should be the same as the id returned by the
  2243. ``plat_ic_acknowledge_interrupt()`` API.
  2244. Arm standard platforms write the id to the *End of Interrupt Register*
  2245. (``GICC_EOIR``) in case of GICv2, and to ``ICC_EOIR0_EL1`` or ``ICC_EOIR1_EL1``
  2246. system register in case of GICv3 depending on where the API is invoked from,
  2247. EL3 or S-EL1. This deactivates the corresponding interrupt in the interrupt
  2248. controller.
  2249. The TSP uses this API to finish processing of the secure physical timer
  2250. interrupt.
  2251. Function : plat_ic_get_interrupt_type() [mandatory]
  2252. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2253. ::
  2254. Argument : uint32_t
  2255. Return : uint32_t
  2256. This API returns the type of the interrupt id passed as the parameter.
  2257. ``INTR_TYPE_INVAL`` is returned if the id is invalid. If the id is valid, a valid
  2258. interrupt type (one of ``INTR_TYPE_EL3``, ``INTR_TYPE_S_EL1`` and ``INTR_TYPE_NS``) is
  2259. returned depending upon how the interrupt has been configured by the platform
  2260. IC. This API must be invoked at EL3.
  2261. Arm standard platforms using GICv2 configures S-EL1 interrupts as Group0 interrupts
  2262. and Non-secure interrupts as Group1 interrupts. It reads the group value
  2263. corresponding to the interrupt id from the relevant *Interrupt Group Register*
  2264. (``GICD_IGROUPRn``). It uses the group value to determine the type of interrupt.
  2265. In the case of Arm standard platforms using GICv3, both the *Interrupt Group
  2266. Register* (``GICD_IGROUPRn``) and *Interrupt Group Modifier Register*
  2267. (``GICD_IGRPMODRn``) is read to figure out whether the interrupt is configured
  2268. as Group 0 secure interrupt, Group 1 secure interrupt or Group 1 NS interrupt.
  2269. Common helper functions
  2270. -----------------------
  2271. Function : do_panic()
  2272. ~~~~~~~~~~~~~~~~~~~~~
  2273. ::
  2274. Argument : void
  2275. Return : void
  2276. This API is called from assembly files when encountering a critical failure that
  2277. cannot be recovered from. It also invokes elx_panic() which allows to report a
  2278. crash from lower exception level. This function assumes that it is invoked from
  2279. a C runtime environment i.e. valid stack exists. This call **must not** return.
  2280. Function : panic()
  2281. ~~~~~~~~~~~~~~~~~~
  2282. ::
  2283. Argument : void
  2284. Return : void
  2285. This API called from C files when encountering a critical failure that cannot
  2286. be recovered from. This function in turn prints backtrace (if enabled) and calls
  2287. do_panic(). This call **must not** return.
  2288. Crash Reporting mechanism (in BL31)
  2289. -----------------------------------
  2290. BL31 implements a crash reporting mechanism which prints the various registers
  2291. of the CPU to enable quick crash analysis and debugging. This mechanism relies
  2292. on the platform implementing ``plat_crash_console_init``,
  2293. ``plat_crash_console_putc`` and ``plat_crash_console_flush``.
  2294. The file ``plat/common/aarch64/crash_console_helpers.S`` contains sample
  2295. implementation of all of them. Platforms may include this file to their
  2296. makefiles in order to benefit from them. By default, they will cause the crash
  2297. output to be routed over the normal console infrastructure and get printed on
  2298. consoles configured to output in crash state. ``console_set_scope()`` can be
  2299. used to control whether a console is used for crash output.
  2300. .. note::
  2301. Platforms are responsible for making sure that they only mark consoles for
  2302. use in the crash scope that are able to support this, i.e. that are written
  2303. in assembly and conform with the register clobber rules for putc()
  2304. (x0-x2, x16-x17) and flush() (x0-x3, x16-x17) crash callbacks.
  2305. In some cases (such as debugging very early crashes that happen before the
  2306. normal boot console can be set up), platforms may want to control crash output
  2307. more explicitly. These platforms may instead provide custom implementations for
  2308. these. They are executed outside of a C environment and without a stack. Many
  2309. console drivers provide functions named ``console_xxx_core_init/putc/flush``
  2310. that are designed to be used by these functions. See Arm platforms (like juno)
  2311. for an example of this.
  2312. Function : plat_crash_console_init [mandatory]
  2313. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2314. ::
  2315. Argument : void
  2316. Return : int
  2317. This API is used by the crash reporting mechanism to initialize the crash
  2318. console. It must only use the general purpose registers x0 through x7 to do the
  2319. initialization and returns 1 on success.
  2320. Function : plat_crash_console_putc [mandatory]
  2321. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2322. ::
  2323. Argument : int
  2324. Return : int
  2325. This API is used by the crash reporting mechanism to print a character on the
  2326. designated crash console. It must only use general purpose registers x1 and
  2327. x2 to do its work. The parameter and the return value are in general purpose
  2328. register x0.
  2329. Function : plat_crash_console_flush [mandatory]
  2330. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2331. ::
  2332. Argument : void
  2333. Return : void
  2334. This API is used by the crash reporting mechanism to force write of all buffered
  2335. data on the designated crash console. It should only use general purpose
  2336. registers x0 through x5 to do its work.
  2337. .. _External Abort handling and RAS Support:
  2338. External Abort handling and RAS Support
  2339. ---------------------------------------
  2340. Function : plat_ea_handler
  2341. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  2342. ::
  2343. Argument : int
  2344. Argument : uint64_t
  2345. Argument : void *
  2346. Argument : void *
  2347. Argument : uint64_t
  2348. Return : void
  2349. This function is invoked by the RAS framework for the platform to handle an
  2350. External Abort received at EL3. The intention of the function is to attempt to
  2351. resolve the cause of External Abort and return; if that's not possible, to
  2352. initiate orderly shutdown of the system.
  2353. The first parameter (``int ea_reason``) indicates the reason for External Abort.
  2354. Its value is one of ``ERROR_EA_*`` constants defined in ``ea_handle.h``.
  2355. The second parameter (``uint64_t syndrome``) is the respective syndrome
  2356. presented to EL3 after having received the External Abort. Depending on the
  2357. nature of the abort (as can be inferred from the ``ea_reason`` parameter), this
  2358. can be the content of either ``ESR_EL3`` or ``DISR_EL1``.
  2359. The third parameter (``void *cookie``) is unused for now. The fourth parameter
  2360. (``void *handle``) is a pointer to the preempted context. The fifth parameter
  2361. (``uint64_t flags``) indicates the preempted security state. These parameters
  2362. are received from the top-level exception handler.
  2363. If ``RAS_EXTENSION`` is set to ``1``, the default implementation of this
  2364. function iterates through RAS handlers registered by the platform. If any of the
  2365. RAS handlers resolve the External Abort, no further action is taken.
  2366. If ``RAS_EXTENSION`` is set to ``0``, or if none of the platform RAS handlers
  2367. could resolve the External Abort, the default implementation prints an error
  2368. message, and panics.
  2369. Function : plat_handle_uncontainable_ea
  2370. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2371. ::
  2372. Argument : int
  2373. Argument : uint64_t
  2374. Return : void
  2375. This function is invoked by the RAS framework when an External Abort of
  2376. Uncontainable type is received at EL3. Due to the critical nature of
  2377. Uncontainable errors, the intention of this function is to initiate orderly
  2378. shutdown of the system, and is not expected to return.
  2379. This function must be implemented in assembly.
  2380. The first and second parameters are the same as that of ``plat_ea_handler``.
  2381. The default implementation of this function calls
  2382. ``report_unhandled_exception``.
  2383. Function : plat_handle_double_fault
  2384. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2385. ::
  2386. Argument : int
  2387. Argument : uint64_t
  2388. Return : void
  2389. This function is invoked by the RAS framework when another External Abort is
  2390. received at EL3 while one is already being handled. I.e., a call to
  2391. ``plat_ea_handler`` is outstanding. Due to its critical nature, the intention of
  2392. this function is to initiate orderly shutdown of the system, and is not expected
  2393. recover or return.
  2394. This function must be implemented in assembly.
  2395. The first and second parameters are the same as that of ``plat_ea_handler``.
  2396. The default implementation of this function calls
  2397. ``report_unhandled_exception``.
  2398. Function : plat_handle_el3_ea
  2399. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2400. ::
  2401. Return : void
  2402. This function is invoked when an External Abort is received while executing in
  2403. EL3. Due to its critical nature, the intention of this function is to initiate
  2404. orderly shutdown of the system, and is not expected recover or return.
  2405. This function must be implemented in assembly.
  2406. The default implementation of this function calls
  2407. ``report_unhandled_exception``.
  2408. Function : plat_handle_rng_trap
  2409. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2410. ::
  2411. Argument : uint64_t
  2412. Argument : cpu_context_t *
  2413. Return : int
  2414. This function is invoked by BL31's exception handler when there is a synchronous
  2415. system register trap caused by access to the RNDR or RNDRRS registers. It allows
  2416. platforms implementing ``FEAT_RNG_TRAP`` and enabling ``ENABLE_FEAT_RNG_TRAP`` to
  2417. emulate those system registers by returing back some entropy to the lower EL.
  2418. The first parameter (``uint64_t esr_el3``) contains the content of the ESR_EL3
  2419. syndrome register, which encodes the instruction that was trapped. The interesting
  2420. information in there is the target register (``get_sysreg_iss_rt()``).
  2421. The second parameter (``cpu_context_t *ctx``) represents the CPU state in the
  2422. lower exception level, at the time when the execution of the ``mrs`` instruction
  2423. was trapped. Its content can be changed, to put the entropy into the target
  2424. register.
  2425. The return value indicates how to proceed:
  2426. - When returning ``TRAP_RET_UNHANDLED`` (-1), the machine will panic.
  2427. - When returning ``TRAP_RET_REPEAT`` (0), the exception handler will return
  2428. to the same instruction, so its execution will be repeated.
  2429. - When returning ``TRAP_RET_CONTINUE`` (1), the exception handler will return
  2430. to the next instruction.
  2431. This function needs to be implemented by a platform if it enables FEAT_RNG_TRAP.
  2432. Build flags
  2433. -----------
  2434. There are some build flags which can be defined by the platform to control
  2435. inclusion or exclusion of certain BL stages from the FIP image. These flags
  2436. need to be defined in the platform makefile which will get included by the
  2437. build system.
  2438. - **NEED_BL33**
  2439. By default, this flag is defined ``yes`` by the build system and ``BL33``
  2440. build option should be supplied as a build option. The platform has the
  2441. option of excluding the BL33 image in the ``fip`` image by defining this flag
  2442. to ``no``. If any of the options ``EL3_PAYLOAD_BASE`` or ``PRELOADED_BL33_BASE``
  2443. are used, this flag will be set to ``no`` automatically.
  2444. Platform include paths
  2445. ----------------------
  2446. Platforms are allowed to add more include paths to be passed to the compiler.
  2447. The ``PLAT_INCLUDES`` variable is used for this purpose. This is needed in
  2448. particular for the file ``platform_def.h``.
  2449. Example:
  2450. .. code:: c
  2451. PLAT_INCLUDES += -Iinclude/plat/myplat/include
  2452. C Library
  2453. ---------
  2454. To avoid subtle toolchain behavioral dependencies, the header files provided
  2455. by the compiler are not used. The software is built with the ``-nostdinc`` flag
  2456. to ensure no headers are included from the toolchain inadvertently. Instead the
  2457. required headers are included in the TF-A source tree. The library only
  2458. contains those C library definitions required by the local implementation. If
  2459. more functionality is required, the needed library functions will need to be
  2460. added to the local implementation.
  2461. Some C headers have been obtained from `FreeBSD`_ and `SCC`_, while others have
  2462. been written specifically for TF-A. Some implementation files have been obtained
  2463. from `FreeBSD`_, others have been written specifically for TF-A as well. The
  2464. files can be found in ``include/lib/libc`` and ``lib/libc``.
  2465. SCC can be found in http://www.simple-cc.org/. A copy of the `FreeBSD`_ sources
  2466. can be obtained from http://github.com/freebsd/freebsd.
  2467. Storage abstraction layer
  2468. -------------------------
  2469. In order to improve platform independence and portability a storage abstraction
  2470. layer is used to load data from non-volatile platform storage. Currently
  2471. storage access is only required by BL1 and BL2 phases and performed inside the
  2472. ``load_image()`` function in ``bl_common.c``.
  2473. .. uml:: ../resources/diagrams/plantuml/io_framework_usage_overview.puml
  2474. It is mandatory to implement at least one storage driver. For the Arm
  2475. development platforms the Firmware Image Package (FIP) driver is provided as
  2476. the default means to load data from storage (see :ref:`firmware_design_fip`).
  2477. The storage layer is described in the header file
  2478. ``include/drivers/io/io_storage.h``. The implementation of the common library is
  2479. in ``drivers/io/io_storage.c`` and the driver files are located in
  2480. ``drivers/io/``.
  2481. .. uml:: ../resources/diagrams/plantuml/io_arm_class_diagram.puml
  2482. Each IO driver must provide ``io_dev_*`` structures, as described in
  2483. ``drivers/io/io_driver.h``. These are returned via a mandatory registration
  2484. function that is called on platform initialization. The semi-hosting driver
  2485. implementation in ``io_semihosting.c`` can be used as an example.
  2486. Each platform should register devices and their drivers via the storage
  2487. abstraction layer. These drivers then need to be initialized by bootloader
  2488. phases as required in their respective ``blx_platform_setup()`` functions.
  2489. .. uml:: ../resources/diagrams/plantuml/io_dev_registration.puml
  2490. The storage abstraction layer provides mechanisms (``io_dev_init()``) to
  2491. initialize storage devices before IO operations are called.
  2492. .. uml:: ../resources/diagrams/plantuml/io_dev_init_and_check.puml
  2493. The basic operations supported by the layer
  2494. include ``open()``, ``close()``, ``read()``, ``write()``, ``size()`` and ``seek()``.
  2495. Drivers do not have to implement all operations, but each platform must
  2496. provide at least one driver for a device capable of supporting generic
  2497. operations such as loading a bootloader image.
  2498. The current implementation only allows for known images to be loaded by the
  2499. firmware. These images are specified by using their identifiers, as defined in
  2500. ``include/plat/common/common_def.h`` (or a separate header file included from
  2501. there). The platform layer (``plat_get_image_source()``) then returns a reference
  2502. to a device and a driver-specific ``spec`` which will be understood by the driver
  2503. to allow access to the image data.
  2504. The layer is designed in such a way that is it possible to chain drivers with
  2505. other drivers. For example, file-system drivers may be implemented on top of
  2506. physical block devices, both represented by IO devices with corresponding
  2507. drivers. In such a case, the file-system "binding" with the block device may
  2508. be deferred until the file-system device is initialised.
  2509. The abstraction currently depends on structures being statically allocated
  2510. by the drivers and callers, as the system does not yet provide a means of
  2511. dynamically allocating memory. This may also have the affect of limiting the
  2512. amount of open resources per driver.
  2513. --------------
  2514. *Copyright (c) 2013-2023, Arm Limited and Contributors. All rights reserved.*
  2515. .. _PSCI: http://infocenter.arm.com/help/topic/com.arm.doc.den0022c/DEN0022C_Power_State_Coordination_Interface.pdf
  2516. .. _Arm Generic Interrupt Controller version 2.0 (GICv2): http://infocenter.arm.com/help/topic/com.arm.doc.ihi0048b/index.html
  2517. .. _3.0 (GICv3): http://infocenter.arm.com/help/topic/com.arm.doc.ihi0069b/index.html
  2518. .. _FreeBSD: https://www.freebsd.org
  2519. .. _SCC: http://www.simple-cc.org/
  2520. .. _DRTM: https://developer.arm.com/documentation/den0113/a