sbi_platform.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. /*
  2. * SPDX-License-Identifier: BSD-2-Clause
  3. *
  4. * Copyright (c) 2019 Western Digital Corporation or its affiliates.
  5. *
  6. * Authors:
  7. * Anup Patel <anup.patel@wdc.com>
  8. */
  9. #ifndef __SBI_PLATFORM_H__
  10. #define __SBI_PLATFORM_H__
  11. /**
  12. * OpenSBI 32-bit platform version with:
  13. * 1. upper 16-bits as major number
  14. * 2. lower 16-bits as minor number
  15. */
  16. #define SBI_PLATFORM_VERSION(Major, Minor) ((Major << 16) | Minor)
  17. /** Offset of opensbi_version in struct sbi_platform */
  18. #define SBI_PLATFORM_OPENSBI_VERSION_OFFSET (0x00)
  19. /** Offset of platform_version in struct sbi_platform */
  20. #define SBI_PLATFORM_VERSION_OFFSET (0x04)
  21. /** Offset of name in struct sbi_platform */
  22. #define SBI_PLATFORM_NAME_OFFSET (0x08)
  23. /** Offset of features in struct sbi_platform */
  24. #define SBI_PLATFORM_FEATURES_OFFSET (0x48)
  25. /** Offset of hart_count in struct sbi_platform */
  26. #define SBI_PLATFORM_HART_COUNT_OFFSET (0x50)
  27. /** Offset of hart_stack_size in struct sbi_platform */
  28. #define SBI_PLATFORM_HART_STACK_SIZE_OFFSET (0x54)
  29. /** Offset of platform_ops_addr in struct sbi_platform */
  30. #define SBI_PLATFORM_OPS_OFFSET (0x58)
  31. /** Offset of firmware_context in struct sbi_platform */
  32. #define SBI_PLATFORM_FIRMWARE_CONTEXT_OFFSET (0x58 + __SIZEOF_POINTER__)
  33. /** Offset of hart_index2id in struct sbi_platform */
  34. #define SBI_PLATFORM_HART_INDEX2ID_OFFSET (0x58 + (__SIZEOF_POINTER__ * 2))
  35. #define SBI_PLATFORM_TLB_RANGE_FLUSH_LIMIT_DEFAULT (1UL << 12)
  36. #ifndef __ASSEMBLER__
  37. #include <sbi/sbi_ecall_interface.h>
  38. #include <sbi/sbi_error.h>
  39. #include <sbi/sbi_scratch.h>
  40. #include <sbi/sbi_version.h>
  41. struct sbi_domain_memregion;
  42. struct sbi_trap_info;
  43. struct sbi_trap_regs;
  44. struct sbi_hart_features;
  45. /** Possible feature flags of a platform */
  46. enum sbi_platform_features {
  47. /** Platform has fault delegation support */
  48. SBI_PLATFORM_HAS_MFAULTS_DELEGATION = (1 << 1),
  49. /** Last index of Platform features*/
  50. SBI_PLATFORM_HAS_LAST_FEATURE = SBI_PLATFORM_HAS_MFAULTS_DELEGATION,
  51. };
  52. /** Default feature set for a platform */
  53. #define SBI_PLATFORM_DEFAULT_FEATURES \
  54. (SBI_PLATFORM_HAS_MFAULTS_DELEGATION)
  55. /** Platform functions */
  56. struct sbi_platform_operations {
  57. /* Check if specified HART is allowed to do cold boot */
  58. bool (*cold_boot_allowed)(u32 hartid);
  59. /* Platform nascent initialization */
  60. int (*nascent_init)(void);
  61. /** Platform early initialization */
  62. int (*early_init)(bool cold_boot);
  63. /** Platform final initialization */
  64. int (*final_init)(bool cold_boot);
  65. /** Platform early exit */
  66. void (*early_exit)(void);
  67. /** Platform final exit */
  68. void (*final_exit)(void);
  69. /**
  70. * For platforms that do not implement misa, non-standard
  71. * methods are needed to determine cpu extension.
  72. */
  73. int (*misa_check_extension)(char ext);
  74. /**
  75. * For platforms that do not implement misa, non-standard
  76. * methods are needed to get MXL field of misa.
  77. */
  78. int (*misa_get_xlen)(void);
  79. /** Initialize (or populate) HART extensions for the platform */
  80. int (*extensions_init)(struct sbi_hart_features *hfeatures);
  81. /** Initialize (or populate) domains for the platform */
  82. int (*domains_init)(void);
  83. /** Initialize hw performance counters */
  84. int (*pmu_init)(void);
  85. /** Get platform specific mhpmevent value */
  86. uint64_t (*pmu_xlate_to_mhpmevent)(uint32_t event_idx, uint64_t data);
  87. /** Initialize the platform console */
  88. int (*console_init)(void);
  89. /** Initialize the platform interrupt controller for current HART */
  90. int (*irqchip_init)(bool cold_boot);
  91. /** Exit the platform interrupt controller for current HART */
  92. void (*irqchip_exit)(void);
  93. /** Initialize IPI for current HART */
  94. int (*ipi_init)(bool cold_boot);
  95. /** Exit IPI for current HART */
  96. void (*ipi_exit)(void);
  97. /** Get tlb flush limit value **/
  98. u64 (*get_tlbr_flush_limit)(void);
  99. /** Initialize platform timer for current HART */
  100. int (*timer_init)(bool cold_boot);
  101. /** Exit platform timer for current HART */
  102. void (*timer_exit)(void);
  103. /** Check if SBI vendor extension is implemented or not */
  104. bool (*vendor_ext_check)(void);
  105. /** platform specific SBI extension implementation provider */
  106. int (*vendor_ext_provider)(long funcid,
  107. const struct sbi_trap_regs *regs,
  108. unsigned long *out_value,
  109. struct sbi_trap_info *out_trap);
  110. };
  111. /** Platform default per-HART stack size for exception/interrupt handling */
  112. #define SBI_PLATFORM_DEFAULT_HART_STACK_SIZE 8192
  113. /** Representation of a platform */
  114. struct sbi_platform {
  115. /**
  116. * OpenSBI version this sbi_platform is based on.
  117. * It's a 32-bit value where upper 16-bits are major number
  118. * and lower 16-bits are minor number
  119. */
  120. u32 opensbi_version;
  121. /**
  122. * OpenSBI platform version released by vendor.
  123. * It's a 32-bit value where upper 16-bits are major number
  124. * and lower 16-bits are minor number
  125. */
  126. u32 platform_version;
  127. /** Name of the platform */
  128. char name[64];
  129. /** Supported features */
  130. u64 features;
  131. /** Total number of HARTs */
  132. u32 hart_count;
  133. /** Per-HART stack size for exception/interrupt handling */
  134. u32 hart_stack_size;
  135. /** Pointer to sbi platform operations */
  136. unsigned long platform_ops_addr;
  137. /** Pointer to system firmware specific context */
  138. unsigned long firmware_context;
  139. /**
  140. * HART index to HART id table
  141. *
  142. * For used HART index <abc>:
  143. * hart_index2id[<abc>] = some HART id
  144. * For unused HART index <abc>:
  145. * hart_index2id[<abc>] = -1U
  146. *
  147. * If hart_index2id == NULL then we assume identity mapping
  148. * hart_index2id[<abc>] = <abc>
  149. *
  150. * We have only two restrictions:
  151. * 1. HART index < sbi_platform hart_count
  152. * 2. HART id < SBI_HARTMASK_MAX_BITS
  153. */
  154. const u32 *hart_index2id;
  155. };
  156. /**
  157. * Prevent modification of struct sbi_platform from affecting
  158. * SBI_PLATFORM_xxx_OFFSET
  159. */
  160. _Static_assert(
  161. offsetof(struct sbi_platform, opensbi_version)
  162. == SBI_PLATFORM_OPENSBI_VERSION_OFFSET,
  163. "struct sbi_platform definition has changed, please redefine "
  164. "SBI_PLATFORM_OPENSBI_VERSION_OFFSET");
  165. _Static_assert(
  166. offsetof(struct sbi_platform, platform_version)
  167. == SBI_PLATFORM_VERSION_OFFSET,
  168. "struct sbi_platform definition has changed, please redefine "
  169. "SBI_PLATFORM_VERSION_OFFSET");
  170. _Static_assert(
  171. offsetof(struct sbi_platform, name)
  172. == SBI_PLATFORM_NAME_OFFSET,
  173. "struct sbi_platform definition has changed, please redefine "
  174. "SBI_PLATFORM_NAME_OFFSET");
  175. _Static_assert(
  176. offsetof(struct sbi_platform, features)
  177. == SBI_PLATFORM_FEATURES_OFFSET,
  178. "struct sbi_platform definition has changed, please redefine "
  179. "SBI_PLATFORM_FEATURES_OFFSET");
  180. _Static_assert(
  181. offsetof(struct sbi_platform, hart_count)
  182. == SBI_PLATFORM_HART_COUNT_OFFSET,
  183. "struct sbi_platform definition has changed, please redefine "
  184. "SBI_PLATFORM_HART_COUNT_OFFSET");
  185. _Static_assert(
  186. offsetof(struct sbi_platform, hart_stack_size)
  187. == SBI_PLATFORM_HART_STACK_SIZE_OFFSET,
  188. "struct sbi_platform definition has changed, please redefine "
  189. "SBI_PLATFORM_HART_STACK_SIZE_OFFSET");
  190. _Static_assert(
  191. offsetof(struct sbi_platform, platform_ops_addr)
  192. == SBI_PLATFORM_OPS_OFFSET,
  193. "struct sbi_platform definition has changed, please redefine "
  194. "SBI_PLATFORM_OPS_OFFSET");
  195. _Static_assert(
  196. offsetof(struct sbi_platform, firmware_context)
  197. == SBI_PLATFORM_FIRMWARE_CONTEXT_OFFSET,
  198. "struct sbi_platform definition has changed, please redefine "
  199. "SBI_PLATFORM_FIRMWARE_CONTEXT_OFFSET");
  200. _Static_assert(
  201. offsetof(struct sbi_platform, hart_index2id)
  202. == SBI_PLATFORM_HART_INDEX2ID_OFFSET,
  203. "struct sbi_platform definition has changed, please redefine "
  204. "SBI_PLATFORM_HART_INDEX2ID_OFFSET");
  205. /** Get pointer to sbi_platform for sbi_scratch pointer */
  206. #define sbi_platform_ptr(__s) \
  207. ((const struct sbi_platform *)((__s)->platform_addr))
  208. /** Get pointer to sbi_platform for current HART */
  209. #define sbi_platform_thishart_ptr() ((const struct sbi_platform *) \
  210. (sbi_scratch_thishart_ptr()->platform_addr))
  211. /** Get pointer to platform_ops_addr from platform pointer **/
  212. #define sbi_platform_ops(__p) \
  213. ((const struct sbi_platform_operations *)(__p)->platform_ops_addr)
  214. /** Check whether the platform supports fault delegation */
  215. #define sbi_platform_has_mfaults_delegation(__p) \
  216. ((__p)->features & SBI_PLATFORM_HAS_MFAULTS_DELEGATION)
  217. /**
  218. * Get HART index for the given HART
  219. *
  220. * @param plat pointer to struct sbi_platform
  221. * @param hartid HART ID
  222. *
  223. * @return 0 <= value < hart_count for valid HART otherwise -1U
  224. */
  225. u32 sbi_platform_hart_index(const struct sbi_platform *plat, u32 hartid);
  226. /**
  227. * Get the platform features in string format
  228. *
  229. * @param plat pointer to struct sbi_platform
  230. * @param features_str pointer to a char array where the features string will be
  231. * updated
  232. * @param nfstr length of the features_str. The feature string will be truncated
  233. * if nfstr is not long enough.
  234. */
  235. void sbi_platform_get_features_str(const struct sbi_platform *plat,
  236. char *features_str, int nfstr);
  237. /**
  238. * Get name of the platform
  239. *
  240. * @param plat pointer to struct sbi_platform
  241. *
  242. * @return pointer to platform name on success and "Unknown" on failure
  243. */
  244. static inline const char *sbi_platform_name(const struct sbi_platform *plat)
  245. {
  246. if (plat)
  247. return plat->name;
  248. return "Unknown";
  249. }
  250. /**
  251. * Get the platform features
  252. *
  253. * @param plat pointer to struct sbi_platform
  254. *
  255. * @return the features value currently set for the given platform
  256. */
  257. static inline unsigned long sbi_platform_get_features(
  258. const struct sbi_platform *plat)
  259. {
  260. if (plat)
  261. return plat->features;
  262. return 0;
  263. }
  264. /**
  265. * Get platform specific tlb range flush maximum value. Any request with size
  266. * higher than this is upgraded to a full flush.
  267. *
  268. * @param plat pointer to struct sbi_platform
  269. *
  270. * @return tlb range flush limit value. Returns a default (page size) if not
  271. * defined by platform.
  272. */
  273. static inline u64 sbi_platform_tlbr_flush_limit(const struct sbi_platform *plat)
  274. {
  275. if (plat && sbi_platform_ops(plat)->get_tlbr_flush_limit)
  276. return sbi_platform_ops(plat)->get_tlbr_flush_limit();
  277. return SBI_PLATFORM_TLB_RANGE_FLUSH_LIMIT_DEFAULT;
  278. }
  279. /**
  280. * Get total number of HARTs supported by the platform
  281. *
  282. * @param plat pointer to struct sbi_platform
  283. *
  284. * @return total number of HARTs
  285. */
  286. static inline u32 sbi_platform_hart_count(const struct sbi_platform *plat)
  287. {
  288. if (plat)
  289. return plat->hart_count;
  290. return 0;
  291. }
  292. /**
  293. * Get per-HART stack size for exception/interrupt handling
  294. *
  295. * @param plat pointer to struct sbi_platform
  296. *
  297. * @return stack size in bytes
  298. */
  299. static inline u32 sbi_platform_hart_stack_size(const struct sbi_platform *plat)
  300. {
  301. if (plat)
  302. return plat->hart_stack_size;
  303. return 0;
  304. }
  305. /**
  306. * Check whether given HART is invalid
  307. *
  308. * @param plat pointer to struct sbi_platform
  309. * @param hartid HART ID
  310. *
  311. * @return true if HART is invalid and false otherwise
  312. */
  313. static inline bool sbi_platform_hart_invalid(const struct sbi_platform *plat,
  314. u32 hartid)
  315. {
  316. if (!plat)
  317. return true;
  318. if (plat->hart_count <= sbi_platform_hart_index(plat, hartid))
  319. return true;
  320. return false;
  321. }
  322. /**
  323. * Check whether given HART is allowed to do cold boot
  324. *
  325. * @param plat pointer to struct sbi_platform
  326. * @param hartid HART ID
  327. *
  328. * @return true if HART is allowed to do cold boot and false otherwise
  329. */
  330. static inline bool sbi_platform_cold_boot_allowed(
  331. const struct sbi_platform *plat,
  332. u32 hartid)
  333. {
  334. if (plat && sbi_platform_ops(plat)->cold_boot_allowed)
  335. return sbi_platform_ops(plat)->cold_boot_allowed(hartid);
  336. return true;
  337. }
  338. /**
  339. * Nascent (very early) initialization for current HART
  340. *
  341. * NOTE: This function can be used to do very early initialization of
  342. * platform specific per-HART CSRs and devices.
  343. *
  344. * @param plat pointer to struct sbi_platform
  345. *
  346. * @return 0 on success and negative error code on failure
  347. */
  348. static inline int sbi_platform_nascent_init(const struct sbi_platform *plat)
  349. {
  350. if (plat && sbi_platform_ops(plat)->nascent_init)
  351. return sbi_platform_ops(plat)->nascent_init();
  352. return 0;
  353. }
  354. /**
  355. * Early initialization for current HART
  356. *
  357. * @param plat pointer to struct sbi_platform
  358. * @param cold_boot whether cold boot (true) or warm_boot (false)
  359. *
  360. * @return 0 on success and negative error code on failure
  361. */
  362. static inline int sbi_platform_early_init(const struct sbi_platform *plat,
  363. bool cold_boot)
  364. {
  365. if (plat && sbi_platform_ops(plat)->early_init)
  366. return sbi_platform_ops(plat)->early_init(cold_boot);
  367. return 0;
  368. }
  369. /**
  370. * Final initialization for current HART
  371. *
  372. * @param plat pointer to struct sbi_platform
  373. * @param cold_boot whether cold boot (true) or warm_boot (false)
  374. *
  375. * @return 0 on success and negative error code on failure
  376. */
  377. static inline int sbi_platform_final_init(const struct sbi_platform *plat,
  378. bool cold_boot)
  379. {
  380. if (plat && sbi_platform_ops(plat)->final_init)
  381. return sbi_platform_ops(plat)->final_init(cold_boot);
  382. return 0;
  383. }
  384. /**
  385. * Early exit for current HART
  386. *
  387. * @param plat pointer to struct sbi_platform
  388. */
  389. static inline void sbi_platform_early_exit(const struct sbi_platform *plat)
  390. {
  391. if (plat && sbi_platform_ops(plat)->early_exit)
  392. sbi_platform_ops(plat)->early_exit();
  393. }
  394. /**
  395. * Final exit for current HART
  396. *
  397. * @param plat pointer to struct sbi_platform
  398. */
  399. static inline void sbi_platform_final_exit(const struct sbi_platform *plat)
  400. {
  401. if (plat && sbi_platform_ops(plat)->final_exit)
  402. sbi_platform_ops(plat)->final_exit();
  403. }
  404. /**
  405. * Check CPU extension in MISA
  406. *
  407. * @param plat pointer to struct sbi_platform
  408. * @param ext shorthand letter for CPU extensions
  409. *
  410. * @return zero for not-supported and non-zero for supported
  411. */
  412. static inline int sbi_platform_misa_extension(const struct sbi_platform *plat,
  413. char ext)
  414. {
  415. if (plat && sbi_platform_ops(plat)->misa_check_extension)
  416. return sbi_platform_ops(plat)->misa_check_extension(ext);
  417. return 0;
  418. }
  419. /**
  420. * Get MXL field of MISA
  421. *
  422. * @param plat pointer to struct sbi_platform
  423. *
  424. * @return 1/2/3 on success and error code on failure
  425. */
  426. static inline int sbi_platform_misa_xlen(const struct sbi_platform *plat)
  427. {
  428. if (plat && sbi_platform_ops(plat)->misa_get_xlen)
  429. return sbi_platform_ops(plat)->misa_get_xlen();
  430. return -1;
  431. }
  432. /**
  433. * Initialize (or populate) HART extensions for the platform
  434. *
  435. * @param plat pointer to struct sbi_platform
  436. *
  437. * @return 0 on success and negative error code on failure
  438. */
  439. static inline int sbi_platform_extensions_init(
  440. const struct sbi_platform *plat,
  441. struct sbi_hart_features *hfeatures)
  442. {
  443. if (plat && sbi_platform_ops(plat)->extensions_init)
  444. return sbi_platform_ops(plat)->extensions_init(hfeatures);
  445. return 0;
  446. }
  447. /**
  448. * Initialize (or populate) domains for the platform
  449. *
  450. * @param plat pointer to struct sbi_platform
  451. *
  452. * @return 0 on success and negative error code on failure
  453. */
  454. static inline int sbi_platform_domains_init(const struct sbi_platform *plat)
  455. {
  456. if (plat && sbi_platform_ops(plat)->domains_init)
  457. return sbi_platform_ops(plat)->domains_init();
  458. return 0;
  459. }
  460. /**
  461. * Setup hw PMU events for the platform
  462. *
  463. * @param plat pointer to struct sbi_platform
  464. *
  465. * @return 0 on success and negative error code on failure
  466. */
  467. static inline int sbi_platform_pmu_init(const struct sbi_platform *plat)
  468. {
  469. if (plat && sbi_platform_ops(plat)->pmu_init)
  470. return sbi_platform_ops(plat)->pmu_init();
  471. return 0;
  472. }
  473. /**
  474. * Get the value to be written in mhpmeventx for event_idx
  475. *
  476. * @param plat pointer to struct sbi_platform
  477. * @param event_idx ID of the PMU event
  478. * @param data Additional configuration data passed from supervisor software
  479. *
  480. * @return expected value by the platform or 0 if platform doesn't know about
  481. * the event
  482. */
  483. static inline uint64_t sbi_platform_pmu_xlate_to_mhpmevent(const struct sbi_platform *plat,
  484. uint32_t event_idx, uint64_t data)
  485. {
  486. if (plat && sbi_platform_ops(plat)->pmu_xlate_to_mhpmevent)
  487. return sbi_platform_ops(plat)->pmu_xlate_to_mhpmevent(event_idx,
  488. data);
  489. return 0;
  490. }
  491. /**
  492. * Initialize the platform console
  493. *
  494. * @param plat pointer to struct sbi_platform
  495. *
  496. * @return 0 on success and negative error code on failure
  497. */
  498. static inline int sbi_platform_console_init(const struct sbi_platform *plat)
  499. {
  500. if (plat && sbi_platform_ops(plat)->console_init)
  501. return sbi_platform_ops(plat)->console_init();
  502. return 0;
  503. }
  504. /**
  505. * Initialize the platform interrupt controller for current HART
  506. *
  507. * @param plat pointer to struct sbi_platform
  508. * @param cold_boot whether cold boot (true) or warm_boot (false)
  509. *
  510. * @return 0 on success and negative error code on failure
  511. */
  512. static inline int sbi_platform_irqchip_init(const struct sbi_platform *plat,
  513. bool cold_boot)
  514. {
  515. if (plat && sbi_platform_ops(plat)->irqchip_init)
  516. return sbi_platform_ops(plat)->irqchip_init(cold_boot);
  517. return 0;
  518. }
  519. /**
  520. * Exit the platform interrupt controller for current HART
  521. *
  522. * @param plat pointer to struct sbi_platform
  523. */
  524. static inline void sbi_platform_irqchip_exit(const struct sbi_platform *plat)
  525. {
  526. if (plat && sbi_platform_ops(plat)->irqchip_exit)
  527. sbi_platform_ops(plat)->irqchip_exit();
  528. }
  529. /**
  530. * Initialize the platform IPI support for current HART
  531. *
  532. * @param plat pointer to struct sbi_platform
  533. * @param cold_boot whether cold boot (true) or warm_boot (false)
  534. *
  535. * @return 0 on success and negative error code on failure
  536. */
  537. static inline int sbi_platform_ipi_init(const struct sbi_platform *plat,
  538. bool cold_boot)
  539. {
  540. if (plat && sbi_platform_ops(plat)->ipi_init)
  541. return sbi_platform_ops(plat)->ipi_init(cold_boot);
  542. return 0;
  543. }
  544. /**
  545. * Exit the platform IPI support for current HART
  546. *
  547. * @param plat pointer to struct sbi_platform
  548. */
  549. static inline void sbi_platform_ipi_exit(const struct sbi_platform *plat)
  550. {
  551. if (plat && sbi_platform_ops(plat)->ipi_exit)
  552. sbi_platform_ops(plat)->ipi_exit();
  553. }
  554. /**
  555. * Initialize the platform timer for current HART
  556. *
  557. * @param plat pointer to struct sbi_platform
  558. * @param cold_boot whether cold boot (true) or warm_boot (false)
  559. *
  560. * @return 0 on success and negative error code on failure
  561. */
  562. static inline int sbi_platform_timer_init(const struct sbi_platform *plat,
  563. bool cold_boot)
  564. {
  565. if (plat && sbi_platform_ops(plat)->timer_init)
  566. return sbi_platform_ops(plat)->timer_init(cold_boot);
  567. return 0;
  568. }
  569. /**
  570. * Exit the platform timer for current HART
  571. *
  572. * @param plat pointer to struct sbi_platform
  573. */
  574. static inline void sbi_platform_timer_exit(const struct sbi_platform *plat)
  575. {
  576. if (plat && sbi_platform_ops(plat)->timer_exit)
  577. sbi_platform_ops(plat)->timer_exit();
  578. }
  579. /**
  580. * Check if SBI vendor extension is implemented or not.
  581. *
  582. * @param plat pointer to struct sbi_platform
  583. *
  584. * @return false if not implemented and true if implemented
  585. */
  586. static inline bool sbi_platform_vendor_ext_check(
  587. const struct sbi_platform *plat)
  588. {
  589. if (plat && sbi_platform_ops(plat)->vendor_ext_check)
  590. return sbi_platform_ops(plat)->vendor_ext_check();
  591. return false;
  592. }
  593. /**
  594. * Invoke platform specific vendor SBI extension implementation.
  595. *
  596. * @param plat pointer to struct sbi_platform
  597. * @param funcid SBI function id within the extension id
  598. * @param regs pointer to trap registers passed by the caller
  599. * @param out_value output value that can be filled by the callee
  600. * @param out_trap trap info that can be filled by the callee
  601. *
  602. * @return 0 on success and negative error code on failure
  603. */
  604. static inline int sbi_platform_vendor_ext_provider(
  605. const struct sbi_platform *plat,
  606. long funcid,
  607. const struct sbi_trap_regs *regs,
  608. unsigned long *out_value,
  609. struct sbi_trap_info *out_trap)
  610. {
  611. if (plat && sbi_platform_ops(plat)->vendor_ext_provider) {
  612. return sbi_platform_ops(plat)->vendor_ext_provider(funcid,
  613. regs,
  614. out_value,
  615. out_trap);
  616. }
  617. return SBI_ENOTSUPP;
  618. }
  619. #endif
  620. #endif