sbi_platform.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  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 __ASSEMBLY__
  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;
  42. struct sbi_trap_info;
  43. struct sbi_trap_regs;
  44. /** Possible feature flags of a platform */
  45. enum sbi_platform_features {
  46. /** Platform has timer value */
  47. SBI_PLATFORM_HAS_TIMER_VALUE = (1 << 0),
  48. /** Platform has HART hotplug support */
  49. SBI_PLATFORM_HAS_HART_HOTPLUG = (1 << 1),
  50. /** Platform has fault delegation support */
  51. SBI_PLATFORM_HAS_MFAULTS_DELEGATION = (1 << 2),
  52. /** Platform has custom secondary hart booting support */
  53. SBI_PLATFORM_HAS_HART_SECONDARY_BOOT = (1 << 3),
  54. /** Last index of Platform features*/
  55. SBI_PLATFORM_HAS_LAST_FEATURE = SBI_PLATFORM_HAS_HART_SECONDARY_BOOT,
  56. };
  57. /** Default feature set for a platform */
  58. #define SBI_PLATFORM_DEFAULT_FEATURES \
  59. (SBI_PLATFORM_HAS_TIMER_VALUE | SBI_PLATFORM_HAS_MFAULTS_DELEGATION)
  60. /** Platform functions */
  61. struct sbi_platform_operations {
  62. /** Platform early initialization */
  63. int (*early_init)(bool cold_boot);
  64. /** Platform final initialization */
  65. int (*final_init)(bool cold_boot);
  66. /** Platform early exit */
  67. void (*early_exit)(void);
  68. /** Platform final exit */
  69. void (*final_exit)(void);
  70. /**
  71. * For platforms that do not implement misa, non-standard
  72. * methods are needed to determine cpu extension.
  73. */
  74. int (*misa_check_extension)(char ext);
  75. /**
  76. * For platforms that do not implement misa, non-standard
  77. * methods are needed to get MXL field of misa.
  78. */
  79. int (*misa_get_xlen)(void);
  80. /** Initialize (or populate) domains for the platform */
  81. int (*domains_init)(void);
  82. /** Write a character to the platform console output */
  83. void (*console_putc)(char ch);
  84. /** Read a character from the platform console input */
  85. int (*console_getc)(void);
  86. /** Initialize the platform console */
  87. int (*console_init)(void);
  88. /** Initialize the platform interrupt controller for current HART */
  89. int (*irqchip_init)(bool cold_boot);
  90. /** Exit the platform interrupt controller for current HART */
  91. void (*irqchip_exit)(void);
  92. /** Send IPI to a target HART */
  93. void (*ipi_send)(u32 target_hart);
  94. /** Clear IPI for a target HART */
  95. void (*ipi_clear)(u32 target_hart);
  96. /** Initialize IPI for current HART */
  97. int (*ipi_init)(bool cold_boot);
  98. /** Exit IPI for current HART */
  99. void (*ipi_exit)(void);
  100. /** Get tlb flush limit value **/
  101. u64 (*get_tlbr_flush_limit)(void);
  102. /** Get platform timer value */
  103. u64 (*timer_value)(void);
  104. /** Start platform timer event for current HART */
  105. void (*timer_event_start)(u64 next_event);
  106. /** Stop platform timer event for current HART */
  107. void (*timer_event_stop)(void);
  108. /** Initialize platform timer for current HART */
  109. int (*timer_init)(bool cold_boot);
  110. /** Exit platform timer for current HART */
  111. void (*timer_exit)(void);
  112. /** Bringup the given hart */
  113. int (*hart_start)(u32 hartid, ulong saddr);
  114. /**
  115. * Stop the current hart from running. This call doesn't expect to
  116. * return if success.
  117. */
  118. int (*hart_stop)(void);
  119. /* Check whether reset type and reason supported by the platform */
  120. int (*system_reset_check)(u32 reset_type, u32 reset_reason);
  121. /** Reset the platform */
  122. void (*system_reset)(u32 reset_type, u32 reset_reason);
  123. /** platform specific SBI extension implementation probe function */
  124. int (*vendor_ext_check)(long extid);
  125. /** platform specific SBI extension implementation provider */
  126. int (*vendor_ext_provider)(long extid, long funcid,
  127. const struct sbi_trap_regs *regs,
  128. unsigned long *out_value,
  129. struct sbi_trap_info *out_trap);
  130. } __packed;
  131. /** Platform default per-HART stack size for exception/interrupt handling */
  132. #define SBI_PLATFORM_DEFAULT_HART_STACK_SIZE 8192
  133. /** Representation of a platform */
  134. struct sbi_platform {
  135. /**
  136. * OpenSBI version this sbi_platform is based on.
  137. * It's a 32-bit value where upper 16-bits are major number
  138. * and lower 16-bits are minor number
  139. */
  140. u32 opensbi_version;
  141. /**
  142. * OpenSBI platform version released by vendor.
  143. * It's a 32-bit value where upper 16-bits are major number
  144. * and lower 16-bits are minor number
  145. */
  146. u32 platform_version;
  147. /** Name of the platform */
  148. char name[64];
  149. /** Supported features */
  150. u64 features;
  151. /** Total number of HARTs */
  152. u32 hart_count;
  153. /** Per-HART stack size for exception/interrupt handling */
  154. u32 hart_stack_size;
  155. /** Pointer to sbi platform operations */
  156. unsigned long platform_ops_addr;
  157. /** Pointer to system firmware specific context */
  158. unsigned long firmware_context;
  159. /**
  160. * HART index to HART id table
  161. *
  162. * For used HART index <abc>:
  163. * hart_index2id[<abc>] = some HART id
  164. * For unused HART index <abc>:
  165. * hart_index2id[<abc>] = -1U
  166. *
  167. * If hart_index2id == NULL then we assume identity mapping
  168. * hart_index2id[<abc>] = <abc>
  169. *
  170. * We have only two restrictions:
  171. * 1. HART index < sbi_platform hart_count
  172. * 2. HART id < SBI_HARTMASK_MAX_BITS
  173. */
  174. const u32 *hart_index2id;
  175. } __packed;
  176. /** Get pointer to sbi_platform for sbi_scratch pointer */
  177. #define sbi_platform_ptr(__s) \
  178. ((const struct sbi_platform *)((__s)->platform_addr))
  179. /** Get pointer to sbi_platform for current HART */
  180. #define sbi_platform_thishart_ptr() ((const struct sbi_platform *) \
  181. (sbi_scratch_thishart_ptr()->platform_addr))
  182. /** Get pointer to platform_ops_addr from platform pointer **/
  183. #define sbi_platform_ops(__p) \
  184. ((const struct sbi_platform_operations *)(__p)->platform_ops_addr)
  185. /** Check whether the platform supports timer value */
  186. #define sbi_platform_has_timer_value(__p) \
  187. ((__p)->features & SBI_PLATFORM_HAS_TIMER_VALUE)
  188. /** Check whether the platform supports HART hotplug */
  189. #define sbi_platform_has_hart_hotplug(__p) \
  190. ((__p)->features & SBI_PLATFORM_HAS_HART_HOTPLUG)
  191. /** Check whether the platform supports fault delegation */
  192. #define sbi_platform_has_mfaults_delegation(__p) \
  193. ((__p)->features & SBI_PLATFORM_HAS_MFAULTS_DELEGATION)
  194. /** Check whether the platform supports custom secondary hart booting support */
  195. #define sbi_platform_has_hart_secondary_boot(__p) \
  196. ((__p)->features & SBI_PLATFORM_HAS_HART_SECONDARY_BOOT)
  197. /**
  198. * Get HART index for the given HART
  199. *
  200. * @param plat pointer to struct sbi_platform
  201. * @param hartid HART ID
  202. *
  203. * @return 0 <= value < hart_count for valid HART otherwise -1U
  204. */
  205. u32 sbi_platform_hart_index(const struct sbi_platform *plat, u32 hartid);
  206. /**
  207. * Get the platform features in string format
  208. *
  209. * @param plat pointer to struct sbi_platform
  210. * @param features_str pointer to a char array where the features string will be
  211. * updated
  212. * @param nfstr length of the features_str. The feature string will be truncated
  213. * if nfstr is not long enough.
  214. */
  215. void sbi_platform_get_features_str(const struct sbi_platform *plat,
  216. char *features_str, int nfstr);
  217. /**
  218. * Get name of the platform
  219. *
  220. * @param plat pointer to struct sbi_platform
  221. *
  222. * @return pointer to platform name on success and "Unknown" on failure
  223. */
  224. static inline const char *sbi_platform_name(const struct sbi_platform *plat)
  225. {
  226. if (plat)
  227. return plat->name;
  228. return "Unknown";
  229. }
  230. /**
  231. * Get the platform features
  232. *
  233. * @param plat pointer to struct sbi_platform
  234. *
  235. * @return the features value currently set for the given platform
  236. */
  237. static inline unsigned long sbi_platform_get_features(
  238. const struct sbi_platform *plat)
  239. {
  240. if (plat)
  241. return plat->features;
  242. return 0;
  243. }
  244. /**
  245. * Get platform specific tlb range flush maximum value. Any request with size
  246. * higher than this is upgraded to a full flush.
  247. *
  248. * @param plat pointer to struct sbi_platform
  249. *
  250. * @return tlb range flush limit value. Returns a default (page size) if not
  251. * defined by platform.
  252. */
  253. static inline u64 sbi_platform_tlbr_flush_limit(const struct sbi_platform *plat)
  254. {
  255. if (plat && sbi_platform_ops(plat)->get_tlbr_flush_limit)
  256. return sbi_platform_ops(plat)->get_tlbr_flush_limit();
  257. return SBI_PLATFORM_TLB_RANGE_FLUSH_LIMIT_DEFAULT;
  258. }
  259. /**
  260. * Get total number of HARTs supported by the platform
  261. *
  262. * @param plat pointer to struct sbi_platform
  263. *
  264. * @return total number of HARTs
  265. */
  266. static inline u32 sbi_platform_hart_count(const struct sbi_platform *plat)
  267. {
  268. if (plat)
  269. return plat->hart_count;
  270. return 0;
  271. }
  272. /**
  273. * Get per-HART stack size for exception/interrupt handling
  274. *
  275. * @param plat pointer to struct sbi_platform
  276. *
  277. * @return stack size in bytes
  278. */
  279. static inline u32 sbi_platform_hart_stack_size(const struct sbi_platform *plat)
  280. {
  281. if (plat)
  282. return plat->hart_stack_size;
  283. return 0;
  284. }
  285. /**
  286. * Check whether given HART is invalid
  287. *
  288. * @param plat pointer to struct sbi_platform
  289. * @param hartid HART ID
  290. *
  291. * @return TRUE if HART is invalid and FALSE otherwise
  292. */
  293. static inline bool sbi_platform_hart_invalid(const struct sbi_platform *plat,
  294. u32 hartid)
  295. {
  296. if (!plat)
  297. return TRUE;
  298. if (plat->hart_count <= sbi_platform_hart_index(plat, hartid))
  299. return TRUE;
  300. return FALSE;
  301. }
  302. /**
  303. * Bringup a given hart from previous stage. Platform should implement this
  304. * operation if they support a custom mechanism to start a hart. Otherwise,
  305. * a generic WFI based approach will be used to start/stop a hart in OpenSBI.
  306. *
  307. * @param plat pointer to struct sbi_platform
  308. * @param hartid HART id
  309. * @param saddr M-mode start physical address for the HART
  310. *
  311. * @return 0 if sucessful and negative error code on failure
  312. */
  313. static inline int sbi_platform_hart_start(const struct sbi_platform *plat,
  314. u32 hartid, ulong saddr)
  315. {
  316. if (plat && sbi_platform_ops(plat)->hart_start)
  317. return sbi_platform_ops(plat)->hart_start(hartid, saddr);
  318. return SBI_ENOTSUPP;
  319. }
  320. /**
  321. * Stop the current hart in OpenSBI.
  322. *
  323. * @param plat pointer to struct sbi_platform
  324. *
  325. * @return Negative error code on failure. It doesn't return on success.
  326. */
  327. static inline int sbi_platform_hart_stop(const struct sbi_platform *plat)
  328. {
  329. if (plat && sbi_platform_ops(plat)->hart_stop)
  330. return sbi_platform_ops(plat)->hart_stop();
  331. return SBI_ENOTSUPP;
  332. }
  333. /**
  334. * Early initialization for current HART
  335. *
  336. * @param plat pointer to struct sbi_platform
  337. * @param cold_boot whether cold boot (TRUE) or warm_boot (FALSE)
  338. *
  339. * @return 0 on success and negative error code on failure
  340. */
  341. static inline int sbi_platform_early_init(const struct sbi_platform *plat,
  342. bool cold_boot)
  343. {
  344. if (plat && sbi_platform_ops(plat)->early_init)
  345. return sbi_platform_ops(plat)->early_init(cold_boot);
  346. return 0;
  347. }
  348. /**
  349. * Final initialization for current HART
  350. *
  351. * @param plat pointer to struct sbi_platform
  352. * @param cold_boot whether cold boot (TRUE) or warm_boot (FALSE)
  353. *
  354. * @return 0 on success and negative error code on failure
  355. */
  356. static inline int sbi_platform_final_init(const struct sbi_platform *plat,
  357. bool cold_boot)
  358. {
  359. if (plat && sbi_platform_ops(plat)->final_init)
  360. return sbi_platform_ops(plat)->final_init(cold_boot);
  361. return 0;
  362. }
  363. /**
  364. * Early exit for current HART
  365. *
  366. * @param plat pointer to struct sbi_platform
  367. */
  368. static inline void sbi_platform_early_exit(const struct sbi_platform *plat)
  369. {
  370. if (plat && sbi_platform_ops(plat)->early_exit)
  371. sbi_platform_ops(plat)->early_exit();
  372. }
  373. /**
  374. * Final exit for current HART
  375. *
  376. * @param plat pointer to struct sbi_platform
  377. */
  378. static inline void sbi_platform_final_exit(const struct sbi_platform *plat)
  379. {
  380. if (plat && sbi_platform_ops(plat)->final_exit)
  381. sbi_platform_ops(plat)->final_exit();
  382. }
  383. /**
  384. * Check CPU extension in MISA
  385. *
  386. * @param plat pointer to struct sbi_platform
  387. * @param ext shorthand letter for CPU extensions
  388. *
  389. * @return zero for not-supported and non-zero for supported
  390. */
  391. static inline int sbi_platform_misa_extension(const struct sbi_platform *plat,
  392. char ext)
  393. {
  394. if (plat && sbi_platform_ops(plat)->misa_check_extension)
  395. return sbi_platform_ops(plat)->misa_check_extension(ext);
  396. return 0;
  397. }
  398. /**
  399. * Get MXL field of MISA
  400. *
  401. * @param plat pointer to struct sbi_platform
  402. *
  403. * @return 1/2/3 on success and error code on failure
  404. */
  405. static inline int sbi_platform_misa_xlen(const struct sbi_platform *plat)
  406. {
  407. if (plat && sbi_platform_ops(plat)->misa_get_xlen)
  408. return sbi_platform_ops(plat)->misa_get_xlen();
  409. return -1;
  410. }
  411. /**
  412. * Initialize (or populate) domains for the platform
  413. *
  414. * @param plat pointer to struct sbi_platform
  415. *
  416. * @return 0 on success and negative error code on failure
  417. */
  418. static inline int sbi_platform_domains_init(const struct sbi_platform *plat)
  419. {
  420. if (plat && sbi_platform_ops(plat)->domains_init)
  421. return sbi_platform_ops(plat)->domains_init();
  422. return 0;
  423. }
  424. /**
  425. * Write a character to the platform console output
  426. *
  427. * @param plat pointer to struct sbi_platform
  428. * @param ch character to write
  429. */
  430. static inline void sbi_platform_console_putc(const struct sbi_platform *plat,
  431. char ch)
  432. {
  433. if (plat && sbi_platform_ops(plat)->console_putc)
  434. sbi_platform_ops(plat)->console_putc(ch);
  435. }
  436. /**
  437. * Read a character from the platform console input
  438. *
  439. * @param plat pointer to struct sbi_platform
  440. *
  441. * @return character read from console input
  442. */
  443. static inline int sbi_platform_console_getc(const struct sbi_platform *plat)
  444. {
  445. if (plat && sbi_platform_ops(plat)->console_getc)
  446. return sbi_platform_ops(plat)->console_getc();
  447. return -1;
  448. }
  449. /**
  450. * Initialize the platform console
  451. *
  452. * @param plat pointer to struct sbi_platform
  453. *
  454. * @return 0 on success and negative error code on failure
  455. */
  456. static inline int sbi_platform_console_init(const struct sbi_platform *plat)
  457. {
  458. if (plat && sbi_platform_ops(plat)->console_init)
  459. return sbi_platform_ops(plat)->console_init();
  460. return 0;
  461. }
  462. /**
  463. * Initialize the platform interrupt controller for current HART
  464. *
  465. * @param plat pointer to struct sbi_platform
  466. * @param cold_boot whether cold boot (TRUE) or warm_boot (FALSE)
  467. *
  468. * @return 0 on success and negative error code on failure
  469. */
  470. static inline int sbi_platform_irqchip_init(const struct sbi_platform *plat,
  471. bool cold_boot)
  472. {
  473. if (plat && sbi_platform_ops(plat)->irqchip_init)
  474. return sbi_platform_ops(plat)->irqchip_init(cold_boot);
  475. return 0;
  476. }
  477. /**
  478. * Exit the platform interrupt controller for current HART
  479. *
  480. * @param plat pointer to struct sbi_platform
  481. */
  482. static inline void sbi_platform_irqchip_exit(const struct sbi_platform *plat)
  483. {
  484. if (plat && sbi_platform_ops(plat)->irqchip_exit)
  485. sbi_platform_ops(plat)->irqchip_exit();
  486. }
  487. /**
  488. * Send IPI to a target HART
  489. *
  490. * @param plat pointer to struct sbi_platform
  491. * @param target_hart HART ID of IPI target
  492. */
  493. static inline void sbi_platform_ipi_send(const struct sbi_platform *plat,
  494. u32 target_hart)
  495. {
  496. if (plat && sbi_platform_ops(plat)->ipi_send)
  497. sbi_platform_ops(plat)->ipi_send(target_hart);
  498. }
  499. /**
  500. * Clear IPI for a target HART
  501. *
  502. * @param plat pointer to struct sbi_platform
  503. * @param target_hart HART ID of IPI target
  504. */
  505. static inline void sbi_platform_ipi_clear(const struct sbi_platform *plat,
  506. u32 target_hart)
  507. {
  508. if (plat && sbi_platform_ops(plat)->ipi_clear)
  509. sbi_platform_ops(plat)->ipi_clear(target_hart);
  510. }
  511. /**
  512. * Initialize the platform IPI support for current HART
  513. *
  514. * @param plat pointer to struct sbi_platform
  515. * @param cold_boot whether cold boot (TRUE) or warm_boot (FALSE)
  516. *
  517. * @return 0 on success and negative error code on failure
  518. */
  519. static inline int sbi_platform_ipi_init(const struct sbi_platform *plat,
  520. bool cold_boot)
  521. {
  522. if (plat && sbi_platform_ops(plat)->ipi_init)
  523. return sbi_platform_ops(plat)->ipi_init(cold_boot);
  524. return 0;
  525. }
  526. /**
  527. * Exit the platform IPI support for current HART
  528. *
  529. * @param plat pointer to struct sbi_platform
  530. */
  531. static inline void sbi_platform_ipi_exit(const struct sbi_platform *plat)
  532. {
  533. if (plat && sbi_platform_ops(plat)->ipi_exit)
  534. sbi_platform_ops(plat)->ipi_exit();
  535. }
  536. /**
  537. * Get platform timer value
  538. *
  539. * @param plat pointer to struct sbi_platform
  540. *
  541. * @return 64-bit timer value
  542. */
  543. static inline u64 sbi_platform_timer_value(const struct sbi_platform *plat)
  544. {
  545. if (plat && sbi_platform_ops(plat)->timer_value)
  546. return sbi_platform_ops(plat)->timer_value();
  547. return 0;
  548. }
  549. /**
  550. * Start platform timer event for current HART
  551. *
  552. * @param plat pointer to struct struct sbi_platform
  553. * @param next_event timer value when timer event will happen
  554. */
  555. static inline void
  556. sbi_platform_timer_event_start(const struct sbi_platform *plat, u64 next_event)
  557. {
  558. if (plat && sbi_platform_ops(plat)->timer_event_start)
  559. sbi_platform_ops(plat)->timer_event_start(next_event);
  560. }
  561. /**
  562. * Stop platform timer event for current HART
  563. *
  564. * @param plat pointer to struct sbi_platform
  565. */
  566. static inline void
  567. sbi_platform_timer_event_stop(const struct sbi_platform *plat)
  568. {
  569. if (plat && sbi_platform_ops(plat)->timer_event_stop)
  570. sbi_platform_ops(plat)->timer_event_stop();
  571. }
  572. /**
  573. * Initialize the platform timer for current HART
  574. *
  575. * @param plat pointer to struct sbi_platform
  576. * @param cold_boot whether cold boot (TRUE) or warm_boot (FALSE)
  577. *
  578. * @return 0 on success and negative error code on failure
  579. */
  580. static inline int sbi_platform_timer_init(const struct sbi_platform *plat,
  581. bool cold_boot)
  582. {
  583. if (plat && sbi_platform_ops(plat)->timer_init)
  584. return sbi_platform_ops(plat)->timer_init(cold_boot);
  585. return 0;
  586. }
  587. /**
  588. * Exit the platform timer for current HART
  589. *
  590. * @param plat pointer to struct sbi_platform
  591. */
  592. static inline void sbi_platform_timer_exit(const struct sbi_platform *plat)
  593. {
  594. if (plat && sbi_platform_ops(plat)->timer_exit)
  595. sbi_platform_ops(plat)->timer_exit();
  596. }
  597. /**
  598. * Check whether reset type and reason supported by the platform
  599. *
  600. * @param plat pointer to struct sbi_platform
  601. * @param reset_type type of reset
  602. * @param reset_reason reason for reset
  603. *
  604. * @return 0 if reset type and reason not supported and 1 if supported
  605. */
  606. static inline int sbi_platform_system_reset_check(
  607. const struct sbi_platform *plat,
  608. u32 reset_type, u32 reset_reason)
  609. {
  610. if (plat && sbi_platform_ops(plat)->system_reset_check)
  611. return sbi_platform_ops(plat)->system_reset_check(reset_type,
  612. reset_reason);
  613. return 0;
  614. }
  615. /**
  616. * Reset the platform
  617. *
  618. * This function will not return for supported reset type and reset reason
  619. *
  620. * @param plat pointer to struct sbi_platform
  621. * @param reset_type type of reset
  622. * @param reset_reason reason for reset
  623. */
  624. static inline void sbi_platform_system_reset(const struct sbi_platform *plat,
  625. u32 reset_type, u32 reset_reason)
  626. {
  627. if (plat && sbi_platform_ops(plat)->system_reset)
  628. sbi_platform_ops(plat)->system_reset(reset_type, reset_reason);
  629. }
  630. /**
  631. * Check if a vendor extension is implemented or not.
  632. *
  633. * @param plat pointer to struct sbi_platform
  634. * @param extid vendor SBI extension id
  635. *
  636. * @return 0 if extid is not implemented and 1 if implemented
  637. */
  638. static inline int sbi_platform_vendor_ext_check(const struct sbi_platform *plat,
  639. long extid)
  640. {
  641. if (plat && sbi_platform_ops(plat)->vendor_ext_check)
  642. return sbi_platform_ops(plat)->vendor_ext_check(extid);
  643. return 0;
  644. }
  645. /**
  646. * Invoke platform specific vendor SBI extension implementation.
  647. *
  648. * @param plat pointer to struct sbi_platform
  649. * @param extid vendor SBI extension id
  650. * @param funcid SBI function id within the extension id
  651. * @param regs pointer to trap registers passed by the caller
  652. * @param out_value output value that can be filled by the callee
  653. * @param out_trap trap info that can be filled by the callee
  654. *
  655. * @return 0 on success and negative error code on failure
  656. */
  657. static inline int sbi_platform_vendor_ext_provider(
  658. const struct sbi_platform *plat,
  659. long extid, long funcid,
  660. const struct sbi_trap_regs *regs,
  661. unsigned long *out_value,
  662. struct sbi_trap_info *out_trap)
  663. {
  664. if (plat && sbi_platform_ops(plat)->vendor_ext_provider) {
  665. return sbi_platform_ops(plat)->vendor_ext_provider(extid,
  666. funcid, regs,
  667. out_value,
  668. out_trap);
  669. }
  670. return SBI_ENOTSUPP;
  671. }
  672. #endif
  673. #endif