machine.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936
  1. /* Copyright 2019 SiFive, Inc */
  2. /* SPDX-License-Identifier: Apache-2.0 */
  3. /* ----------------------------------- */
  4. /* ----------------------------------- */
  5. #ifndef ASSEMBLY
  6. #include <metal/machine/platform.h>
  7. #ifdef __METAL_MACHINE_MACROS
  8. #ifndef MACROS_IF_SIFIVE_HIFIVE1_REVB____METAL_H
  9. #define MACROS_IF_SIFIVE_HIFIVE1_REVB____METAL_H
  10. #define __METAL_CLINT_NUM_PARENTS 2
  11. #ifndef __METAL_CLINT_NUM_PARENTS
  12. #define __METAL_CLINT_NUM_PARENTS 0
  13. #endif
  14. #define __METAL_PLIC_SUBINTERRUPTS 52
  15. #define __METAL_PLIC_NUM_PARENTS 1
  16. #ifndef __METAL_PLIC_SUBINTERRUPTS
  17. #define __METAL_PLIC_SUBINTERRUPTS 0
  18. #endif
  19. #ifndef __METAL_PLIC_NUM_PARENTS
  20. #define __METAL_PLIC_NUM_PARENTS 0
  21. #endif
  22. #ifndef __METAL_CLIC_SUBINTERRUPTS
  23. #define __METAL_CLIC_SUBINTERRUPTS 0
  24. #endif
  25. #endif /* MACROS_IF_SIFIVE_HIFIVE1_REVB____METAL_H*/
  26. #else /* ! __METAL_MACHINE_MACROS */
  27. #ifndef MACROS_ELSE_SIFIVE_HIFIVE1_REVB____METAL_H
  28. #define MACROS_ELSE_SIFIVE_HIFIVE1_REVB____METAL_H
  29. #define __METAL_CLINT_2000000_INTERRUPTS 2
  30. #define METAL_MAX_CLINT_INTERRUPTS 2
  31. #define __METAL_CLINT_NUM_PARENTS 2
  32. #define __METAL_INTERRUPT_CONTROLLER_C000000_INTERRUPTS 1
  33. #define __METAL_PLIC_SUBINTERRUPTS 52
  34. #define METAL_MAX_PLIC_INTERRUPTS 1
  35. #define __METAL_PLIC_NUM_PARENTS 1
  36. #define __METAL_CLIC_SUBINTERRUPTS 0
  37. #define METAL_MAX_CLIC_INTERRUPTS 0
  38. #define __METAL_LOCAL_EXTERNAL_INTERRUPTS_0_INTERRUPTS 16
  39. #define METAL_MAX_LOCAL_EXT_INTERRUPTS 16
  40. #define METAL_MAX_GLOBAL_EXT_INTERRUPTS 0
  41. #define __METAL_GPIO_10012000_INTERRUPTS 16
  42. #define METAL_MAX_GPIO_INTERRUPTS 16
  43. #define __METAL_SERIAL_10013000_INTERRUPTS 1
  44. #define METAL_MAX_UART_INTERRUPTS 1
  45. #include <metal/drivers/fixed-clock.h>
  46. #include <metal/memory.h>
  47. #include <metal/drivers/riscv_clint0.h>
  48. #include <metal/drivers/riscv_cpu.h>
  49. #include <metal/drivers/riscv_plic0.h>
  50. #include <metal/pmp.h>
  51. #include <metal/drivers/sifive_local-external-interrupts0.h>
  52. #include <metal/drivers/sifive_gpio0.h>
  53. #include <metal/drivers/sifive_gpio-leds.h>
  54. #include <metal/drivers/sifive_spi0.h>
  55. #include <metal/drivers/sifive_uart0.h>
  56. #include <metal/drivers/sifive_fe310-g000_hfrosc.h>
  57. #include <metal/drivers/sifive_fe310-g000_hfxosc.h>
  58. #include <metal/drivers/sifive_fe310-g000_pll.h>
  59. #include <metal/drivers/sifive_fe310-g000_prci.h>
  60. /* From clock@0 */
  61. struct __metal_driver_fixed_clock __metal_dt_clock_0;
  62. /* From clock@2 */
  63. struct __metal_driver_fixed_clock __metal_dt_clock_2;
  64. /* From clock@5 */
  65. struct __metal_driver_fixed_clock __metal_dt_clock_5;
  66. struct metal_memory __metal_dt_mem_dtim_80000000;
  67. struct metal_memory __metal_dt_mem_spi_10014000;
  68. struct metal_memory __metal_dt_mem_spi_10024000;
  69. /* From clint@2000000 */
  70. struct __metal_driver_riscv_clint0 __metal_dt_clint_2000000;
  71. /* From cpu@0 */
  72. struct __metal_driver_cpu __metal_dt_cpu_0;
  73. struct __metal_driver_riscv_cpu_intc __metal_dt_cpu_0_interrupt_controller;
  74. /* From interrupt_controller@c000000 */
  75. struct __metal_driver_riscv_plic0 __metal_dt_interrupt_controller_c000000;
  76. struct metal_pmp __metal_dt_pmp;
  77. /* From local_external_interrupts_0 */
  78. struct __metal_driver_sifive_local_external_interrupts0 __metal_dt_local_external_interrupts_0;
  79. /* From gpio@10012000 */
  80. struct __metal_driver_sifive_gpio0 __metal_dt_gpio_10012000;
  81. /* From led@0red */
  82. struct __metal_driver_sifive_gpio_led __metal_dt_led_0red;
  83. /* From led@0green */
  84. struct __metal_driver_sifive_gpio_led __metal_dt_led_0green;
  85. /* From led@0blue */
  86. struct __metal_driver_sifive_gpio_led __metal_dt_led_0blue;
  87. /* From spi@10014000 */
  88. struct __metal_driver_sifive_spi0 __metal_dt_spi_10014000;
  89. /* From spi@10024000 */
  90. struct __metal_driver_sifive_spi0 __metal_dt_spi_10024000;
  91. /* From serial@10013000 */
  92. struct __metal_driver_sifive_uart0 __metal_dt_serial_10013000;
  93. /* From serial@10023000 */
  94. struct __metal_driver_sifive_uart0 __metal_dt_serial_10023000;
  95. /* From clock@3 */
  96. struct __metal_driver_sifive_fe310_g000_hfrosc __metal_dt_clock_3;
  97. /* From clock@1 */
  98. struct __metal_driver_sifive_fe310_g000_hfxosc __metal_dt_clock_1;
  99. /* From clock@4 */
  100. struct __metal_driver_sifive_fe310_g000_pll __metal_dt_clock_4;
  101. /* From prci@10008000 */
  102. struct __metal_driver_sifive_fe310_g000_prci __metal_dt_prci_10008000;
  103. /* --------------------- fixed_clock ------------ */
  104. static inline unsigned long __metal_driver_fixed_clock_rate(const struct metal_clock *clock)
  105. {
  106. if ((uintptr_t)clock == (uintptr_t)&__metal_dt_clock_0) {
  107. return METAL_FIXED_CLOCK_0_CLOCK_FREQUENCY;
  108. }
  109. else if ((uintptr_t)clock == (uintptr_t)&__metal_dt_clock_2) {
  110. return METAL_FIXED_CLOCK_2_CLOCK_FREQUENCY;
  111. }
  112. else if ((uintptr_t)clock == (uintptr_t)&__metal_dt_clock_5) {
  113. return METAL_FIXED_CLOCK_5_CLOCK_FREQUENCY;
  114. }
  115. else {
  116. return 0;
  117. }
  118. }
  119. /* --------------------- fixed_factor_clock ------------ */
  120. /* --------------------- sifive_clint0 ------------ */
  121. static inline unsigned long __metal_driver_sifive_clint0_control_base(struct metal_interrupt *controller)
  122. {
  123. if ((uintptr_t)controller == (uintptr_t)&__metal_dt_clint_2000000) {
  124. return METAL_RISCV_CLINT0_2000000_BASE_ADDRESS;
  125. }
  126. else {
  127. return 0;
  128. }
  129. }
  130. static inline unsigned long __metal_driver_sifive_clint0_control_size(struct metal_interrupt *controller)
  131. {
  132. if ((uintptr_t)controller == (uintptr_t)&__metal_dt_clint_2000000) {
  133. return METAL_RISCV_CLINT0_2000000_SIZE;
  134. }
  135. else {
  136. return 0;
  137. }
  138. }
  139. static inline int __metal_driver_sifive_clint0_num_interrupts(struct metal_interrupt *controller)
  140. {
  141. if ((uintptr_t)controller == (uintptr_t)&__metal_dt_clint_2000000) {
  142. return METAL_MAX_CLINT_INTERRUPTS;
  143. }
  144. else {
  145. return 0;
  146. }
  147. }
  148. static inline struct metal_interrupt * __metal_driver_sifive_clint0_interrupt_parents(struct metal_interrupt *controller, int idx)
  149. {
  150. if (idx == 0) {
  151. return (struct metal_interrupt *)&__metal_dt_cpu_0_interrupt_controller.controller;
  152. }
  153. else if (idx == 1) {
  154. return (struct metal_interrupt *)&__metal_dt_cpu_0_interrupt_controller.controller;
  155. }
  156. else {
  157. return NULL;
  158. }
  159. }
  160. static inline int __metal_driver_sifive_clint0_interrupt_lines(struct metal_interrupt *controller, int idx)
  161. {
  162. if (idx == 0) {
  163. return 3;
  164. }
  165. else if (idx == 1) {
  166. return 7;
  167. }
  168. else {
  169. return 0;
  170. }
  171. }
  172. /* --------------------- cpu ------------ */
  173. static inline int __metal_driver_cpu_hartid(struct metal_cpu *cpu)
  174. {
  175. if ((uintptr_t)cpu == (uintptr_t)&__metal_dt_cpu_0) {
  176. return 0;
  177. }
  178. else {
  179. return -1;
  180. }
  181. }
  182. static inline int __metal_driver_cpu_timebase(struct metal_cpu *cpu)
  183. {
  184. if ((uintptr_t)cpu == (uintptr_t)&__metal_dt_cpu_0) {
  185. return 1000000;
  186. }
  187. else {
  188. return 0;
  189. }
  190. }
  191. static inline struct metal_interrupt * __metal_driver_cpu_interrupt_controller(struct metal_cpu *cpu)
  192. {
  193. if ((uintptr_t)cpu == (uintptr_t)&__metal_dt_cpu_0) {
  194. return &__metal_dt_cpu_0_interrupt_controller.controller;
  195. }
  196. else {
  197. return NULL;
  198. }
  199. }
  200. static inline int __metal_driver_cpu_num_pmp_regions(struct metal_cpu *cpu)
  201. {
  202. if ((uintptr_t)cpu == (uintptr_t)&__metal_dt_cpu_0) {
  203. return 8;
  204. }
  205. else {
  206. return 0;
  207. }
  208. }
  209. /* --------------------- sifive_plic0 ------------ */
  210. static inline unsigned long __metal_driver_sifive_plic0_control_base(struct metal_interrupt *controller)
  211. {
  212. if ((uintptr_t)controller == (uintptr_t)&__metal_dt_interrupt_controller_c000000) {
  213. return METAL_RISCV_PLIC0_C000000_BASE_ADDRESS;
  214. }
  215. else {
  216. return 0;
  217. }
  218. }
  219. static inline unsigned long __metal_driver_sifive_plic0_control_size(struct metal_interrupt *controller)
  220. {
  221. if ((uintptr_t)controller == (uintptr_t)&__metal_dt_interrupt_controller_c000000) {
  222. return METAL_RISCV_PLIC0_C000000_SIZE;
  223. }
  224. else {
  225. return 0;
  226. }
  227. }
  228. static inline int __metal_driver_sifive_plic0_num_interrupts(struct metal_interrupt *controller)
  229. {
  230. if ((uintptr_t)controller == (uintptr_t)&__metal_dt_interrupt_controller_c000000) {
  231. return METAL_RISCV_PLIC0_C000000_RISCV_NDEV;
  232. }
  233. else {
  234. return 0;
  235. }
  236. }
  237. static inline int __metal_driver_sifive_plic0_max_priority(struct metal_interrupt *controller)
  238. {
  239. if ((uintptr_t)controller == (uintptr_t)&__metal_dt_interrupt_controller_c000000) {
  240. return METAL_RISCV_PLIC0_C000000_RISCV_MAX_PRIORITY;
  241. }
  242. else {
  243. return 0;
  244. }
  245. }
  246. static inline struct metal_interrupt * __metal_driver_sifive_plic0_interrupt_parents(struct metal_interrupt *controller, int idx)
  247. {
  248. if (idx == 0) {
  249. return (struct metal_interrupt *)&__metal_dt_cpu_0_interrupt_controller.controller;
  250. }
  251. else if (idx == 0) {
  252. return (struct metal_interrupt *)&__metal_dt_cpu_0_interrupt_controller.controller;
  253. }
  254. else {
  255. return NULL;
  256. }
  257. }
  258. static inline int __metal_driver_sifive_plic0_interrupt_lines(struct metal_interrupt *controller, int idx)
  259. {
  260. if (idx == 0) {
  261. return 11;
  262. }
  263. else if (idx == 0) {
  264. return 11;
  265. }
  266. else {
  267. return 0;
  268. }
  269. }
  270. /* --------------------- sifive_clic0 ------------ */
  271. /* --------------------- sifive_local_external_interrupts0 ------------ */
  272. static inline struct metal_interrupt * __metal_driver_sifive_local_external_interrupts0_interrupt_parent(struct metal_interrupt *controller)
  273. {
  274. if ((uintptr_t)controller == (uintptr_t)&__metal_dt_local_external_interrupts_0) {
  275. return (struct metal_interrupt *)&__metal_dt_cpu_0_interrupt_controller.controller;
  276. }
  277. else {
  278. return NULL;
  279. }
  280. }
  281. static inline int __metal_driver_sifive_local_external_interrupts0_num_interrupts(struct metal_interrupt *controller)
  282. {
  283. if ((uintptr_t)controller == (uintptr_t)&__metal_dt_local_external_interrupts_0) {
  284. return METAL_MAX_LOCAL_EXT_INTERRUPTS;
  285. }
  286. else {
  287. return 0;
  288. }
  289. }
  290. static inline int __metal_driver_sifive_local_external_interrupts0_interrupt_lines(struct metal_interrupt *controller, int idx)
  291. {
  292. if (idx == 0) {
  293. return 16;
  294. }
  295. else if (idx == 1) {
  296. return 17;
  297. }
  298. else if (idx == 2) {
  299. return 18;
  300. }
  301. else if (idx == 3) {
  302. return 19;
  303. }
  304. else if (idx == 4) {
  305. return 20;
  306. }
  307. else if (idx == 5) {
  308. return 21;
  309. }
  310. else if (idx == 6) {
  311. return 22;
  312. }
  313. else if (idx == 7) {
  314. return 23;
  315. }
  316. else if (idx == 8) {
  317. return 24;
  318. }
  319. else if (idx == 9) {
  320. return 25;
  321. }
  322. else if (idx == 10) {
  323. return 26;
  324. }
  325. else if (idx == 11) {
  326. return 27;
  327. }
  328. else if (idx == 12) {
  329. return 28;
  330. }
  331. else if (idx == 13) {
  332. return 29;
  333. }
  334. else if (idx == 14) {
  335. return 30;
  336. }
  337. else if (idx == 15) {
  338. return 31;
  339. }
  340. else {
  341. return 0;
  342. }
  343. }
  344. /* --------------------- sifive_global_external_interrupts0 ------------ */
  345. /* --------------------- sifive_gpio0 ------------ */
  346. static inline unsigned long __metal_driver_sifive_gpio0_base(struct metal_gpio *gpio)
  347. {
  348. if ((uintptr_t)gpio == (uintptr_t)&__metal_dt_gpio_10012000) {
  349. return METAL_SIFIVE_GPIO0_10012000_BASE_ADDRESS;
  350. }
  351. else {
  352. return 0;
  353. }
  354. }
  355. static inline unsigned long __metal_driver_sifive_gpio0_size(struct metal_gpio *gpio)
  356. {
  357. if ((uintptr_t)gpio == (uintptr_t)&__metal_dt_gpio_10012000) {
  358. return METAL_SIFIVE_GPIO0_10012000_SIZE;
  359. }
  360. else {
  361. return 0;
  362. }
  363. }
  364. static inline int __metal_driver_sifive_gpio0_num_interrupts(struct metal_gpio *gpio)
  365. {
  366. if ((uintptr_t)gpio == (uintptr_t)&__metal_dt_gpio_10012000) {
  367. return METAL_MAX_GPIO_INTERRUPTS;
  368. }
  369. else {
  370. return 0;
  371. }
  372. }
  373. static inline struct metal_interrupt * __metal_driver_sifive_gpio0_interrupt_parent(struct metal_gpio *gpio)
  374. {
  375. if ((uintptr_t)gpio == (uintptr_t)&__metal_dt_gpio_10012000) {
  376. return (struct metal_interrupt *)&__metal_dt_interrupt_controller_c000000.controller;
  377. }
  378. else {
  379. return 0;
  380. }
  381. }
  382. static inline int __metal_driver_sifive_gpio0_interrupt_lines(struct metal_gpio *gpio, int idx)
  383. {
  384. if (((uintptr_t)gpio == (uintptr_t)&__metal_dt_gpio_10012000) && (idx == 0)) {
  385. return 7;
  386. }
  387. else if ((((uintptr_t)gpio == (uintptr_t)&__metal_dt_gpio_10012000) && (idx == 1))) {
  388. return 8;
  389. }
  390. else if ((((uintptr_t)gpio == (uintptr_t)&__metal_dt_gpio_10012000) && (idx == 2))) {
  391. return 9;
  392. }
  393. else if ((((uintptr_t)gpio == (uintptr_t)&__metal_dt_gpio_10012000) && (idx == 3))) {
  394. return 10;
  395. }
  396. else if ((((uintptr_t)gpio == (uintptr_t)&__metal_dt_gpio_10012000) && (idx == 4))) {
  397. return 11;
  398. }
  399. else if ((((uintptr_t)gpio == (uintptr_t)&__metal_dt_gpio_10012000) && (idx == 5))) {
  400. return 12;
  401. }
  402. else if ((((uintptr_t)gpio == (uintptr_t)&__metal_dt_gpio_10012000) && (idx == 6))) {
  403. return 13;
  404. }
  405. else if ((((uintptr_t)gpio == (uintptr_t)&__metal_dt_gpio_10012000) && (idx == 7))) {
  406. return 14;
  407. }
  408. else if ((((uintptr_t)gpio == (uintptr_t)&__metal_dt_gpio_10012000) && (idx == 8))) {
  409. return 15;
  410. }
  411. else if ((((uintptr_t)gpio == (uintptr_t)&__metal_dt_gpio_10012000) && (idx == 9))) {
  412. return 16;
  413. }
  414. else if ((((uintptr_t)gpio == (uintptr_t)&__metal_dt_gpio_10012000) && (idx == 10))) {
  415. return 17;
  416. }
  417. else if ((((uintptr_t)gpio == (uintptr_t)&__metal_dt_gpio_10012000) && (idx == 11))) {
  418. return 18;
  419. }
  420. else if ((((uintptr_t)gpio == (uintptr_t)&__metal_dt_gpio_10012000) && (idx == 12))) {
  421. return 19;
  422. }
  423. else if ((((uintptr_t)gpio == (uintptr_t)&__metal_dt_gpio_10012000) && (idx == 13))) {
  424. return 20;
  425. }
  426. else if ((((uintptr_t)gpio == (uintptr_t)&__metal_dt_gpio_10012000) && (idx == 14))) {
  427. return 21;
  428. }
  429. else if ((((uintptr_t)gpio == (uintptr_t)&__metal_dt_gpio_10012000) && (idx == 15))) {
  430. return 22;
  431. }
  432. else {
  433. return 0;
  434. }
  435. }
  436. /* --------------------- sifive_gpio_button ------------ */
  437. /* --------------------- sifive_gpio_led ------------ */
  438. static inline struct metal_gpio * __metal_driver_sifive_gpio_led_gpio(struct metal_led *led)
  439. {
  440. if ((uintptr_t)led == (uintptr_t)&__metal_dt_led_0red) {
  441. return (struct metal_gpio *)&__metal_dt_gpio_10012000;
  442. }
  443. else if ((uintptr_t)led == (uintptr_t)&__metal_dt_led_0green) {
  444. return (struct metal_gpio *)&__metal_dt_gpio_10012000;
  445. }
  446. else if ((uintptr_t)led == (uintptr_t)&__metal_dt_led_0blue) {
  447. return (struct metal_gpio *)&__metal_dt_gpio_10012000;
  448. }
  449. else {
  450. return NULL;
  451. }
  452. }
  453. static inline int __metal_driver_sifive_gpio_led_pin(struct metal_led *led)
  454. {
  455. if ((uintptr_t)led == (uintptr_t)&__metal_dt_led_0red) {
  456. return 22;
  457. }
  458. else if ((uintptr_t)led == (uintptr_t)&__metal_dt_led_0green) {
  459. return 19;
  460. }
  461. else if ((uintptr_t)led == (uintptr_t)&__metal_dt_led_0blue) {
  462. return 21;
  463. }
  464. else {
  465. return 0;
  466. }
  467. }
  468. static inline char * __metal_driver_sifive_gpio_led_label(struct metal_led *led)
  469. {
  470. if ((uintptr_t)led == (uintptr_t)&__metal_dt_led_0red) {
  471. return "LD0red";
  472. }
  473. else if ((uintptr_t)led == (uintptr_t)&__metal_dt_led_0green) {
  474. return "LD0green";
  475. }
  476. else if ((uintptr_t)led == (uintptr_t)&__metal_dt_led_0blue) {
  477. return "LD0blue";
  478. }
  479. else {
  480. return "";
  481. }
  482. }
  483. /* --------------------- sifive_gpio_switch ------------ */
  484. /* --------------------- sifive_spi0 ------------ */
  485. static inline unsigned long __metal_driver_sifive_spi0_control_base(struct metal_spi *spi)
  486. {
  487. if ((uintptr_t)spi == (uintptr_t)&__metal_dt_spi_10014000) {
  488. return METAL_SIFIVE_SPI0_10014000_BASE_ADDRESS;
  489. }
  490. else
  491. if ((uintptr_t)spi == (uintptr_t)&__metal_dt_spi_10024000) {
  492. return METAL_SIFIVE_SPI0_10024000_BASE_ADDRESS;
  493. }
  494. else {
  495. return 0;
  496. }
  497. }
  498. static inline unsigned long __metal_driver_sifive_spi0_control_size(struct metal_spi *spi)
  499. {
  500. if ((uintptr_t)spi == (uintptr_t)&__metal_dt_spi_10014000) {
  501. return METAL_SIFIVE_SPI0_10014000_SIZE;
  502. }
  503. else {
  504. return 0;
  505. }
  506. }
  507. static inline struct metal_clock * __metal_driver_sifive_spi0_clock(struct metal_spi *spi)
  508. {
  509. return (struct metal_clock *)&__metal_dt_clock_4.clock;
  510. }
  511. static inline struct __metal_driver_sifive_gpio0 * __metal_driver_sifive_spi0_pinmux(struct metal_spi *spi)
  512. {
  513. return (struct __metal_driver_sifive_gpio0 *)&__metal_dt_gpio_10012000;
  514. }
  515. static inline unsigned long __metal_driver_sifive_spi0_pinmux_output_selector(struct metal_spi *spi)
  516. {
  517. return 60;
  518. }
  519. static inline unsigned long __metal_driver_sifive_spi0_pinmux_source_selector(struct metal_spi *spi)
  520. {
  521. return 60;
  522. }
  523. /* --------------------- sifive_test0 ------------ */
  524. /* --------------------- sifive_uart0 ------------ */
  525. static inline unsigned long __metal_driver_sifive_uart0_control_base(struct metal_uart *uart)
  526. {
  527. if ((uintptr_t)uart == (uintptr_t)&__metal_dt_serial_10013000) {
  528. return METAL_SIFIVE_UART0_10013000_BASE_ADDRESS;
  529. }
  530. else
  531. if ((uintptr_t)uart == (uintptr_t)&__metal_dt_serial_10023000) {
  532. return METAL_SIFIVE_UART0_10023000_BASE_ADDRESS;
  533. }
  534. else
  535. {
  536. return 0;
  537. }
  538. }
  539. static inline unsigned long __metal_driver_sifive_uart0_control_size(struct metal_uart *uart)
  540. {
  541. if ((uintptr_t)uart == (uintptr_t)&__metal_dt_serial_10013000) {
  542. return METAL_SIFIVE_UART0_10013000_SIZE;
  543. }
  544. else
  545. if ((uintptr_t)uart == (uintptr_t)&__metal_dt_serial_10023000) {
  546. return METAL_SIFIVE_UART0_10023000_SIZE;
  547. }
  548. else
  549. {
  550. return 0;
  551. }
  552. }
  553. static inline int __metal_driver_sifive_uart0_num_interrupts(struct metal_uart *uart)
  554. {
  555. if ((uintptr_t)uart == (uintptr_t)&__metal_dt_serial_10013000) {
  556. return METAL_MAX_UART_INTERRUPTS;
  557. }
  558. else {
  559. return 0;
  560. }
  561. }
  562. static inline struct metal_interrupt * __metal_driver_sifive_uart0_interrupt_parent(struct metal_uart *uart)
  563. {
  564. if ((uintptr_t)uart == (uintptr_t)&__metal_dt_serial_10013000) {
  565. return (struct metal_interrupt *)&__metal_dt_interrupt_controller_c000000.controller;
  566. }
  567. else
  568. if ((uintptr_t)uart == (uintptr_t)&__metal_dt_serial_10023000) {
  569. return (struct metal_interrupt *)&__metal_dt_interrupt_controller_c000000.controller;
  570. }
  571. else {
  572. return NULL;
  573. }
  574. }
  575. static inline int __metal_driver_sifive_uart0_interrupt_line(struct metal_uart *uart)
  576. {
  577. int ret = 0;
  578. if ((uintptr_t)uart == (uintptr_t)&__metal_dt_serial_10013000) {
  579. ret = 1;
  580. }
  581. else
  582. if ((uintptr_t)uart == (uintptr_t)&__metal_dt_serial_10023000) {
  583. ret = 2;
  584. }
  585. return ret;
  586. }
  587. static inline struct metal_clock * __metal_driver_sifive_uart0_clock(struct metal_uart *uart)
  588. {
  589. return (struct metal_clock *)&__metal_dt_clock_4.clock;
  590. }
  591. static inline struct __metal_driver_sifive_gpio0 * __metal_driver_sifive_uart0_pinmux(struct metal_uart *uart)
  592. {
  593. return (struct __metal_driver_sifive_gpio0 *)&__metal_dt_gpio_10012000;
  594. }
  595. static inline unsigned long __metal_driver_sifive_uart0_pinmux_output_selector(struct metal_uart *uart)
  596. {
  597. if ((uintptr_t)uart == (uintptr_t)&__metal_dt_serial_10013000) {
  598. return 196608;
  599. }
  600. else
  601. if ((uintptr_t)uart == (uintptr_t)&__metal_dt_serial_10023000) {
  602. return 8650752;
  603. }
  604. else
  605. {
  606. return 0;
  607. }
  608. }
  609. static inline unsigned long __metal_driver_sifive_uart0_pinmux_source_selector(struct metal_uart *uart)
  610. {
  611. if ((uintptr_t)uart == (uintptr_t)&__metal_dt_serial_10013000) {
  612. return 196608;
  613. }
  614. else
  615. if ((uintptr_t)uart == (uintptr_t)&__metal_dt_serial_10023000) {
  616. return 8650752;
  617. }
  618. else
  619. {
  620. return 0;
  621. }
  622. }
  623. /* --------------------- sifive_fe310_g000_hfrosc ------------ */
  624. static inline struct metal_clock * __metal_driver_sifive_fe310_g000_hfrosc_ref(const struct metal_clock *clock)
  625. {
  626. return (struct metal_clock *)&__metal_dt_clock_2.clock;
  627. }
  628. static inline struct __metal_driver_sifive_fe310_g000_prci * __metal_driver_sifive_fe310_g000_hfrosc_config_base(const struct metal_clock *clock)
  629. {
  630. return (struct __metal_driver_sifive_fe310_g000_prci *)&__metal_dt_prci_10008000;
  631. }
  632. static inline const struct __metal_driver_vtable_sifive_fe310_g000_prci * __metal_driver_sifive_fe310_g000_hfrosc_config_vtable(struct metal_clock *clock)
  633. {
  634. return &__metal_driver_vtable_sifive_fe310_g000_prci;
  635. }
  636. static inline long __metal_driver_sifive_fe310_g000_hfrosc_config_offset(const struct metal_clock *clock)
  637. {
  638. return METAL_SIFIVE_FE310_G000_PRCI_HFROSCCFG;
  639. }
  640. /* --------------------- sifive_fe310_g000_hfxosc ------------ */
  641. static inline struct metal_clock * __metal_driver_sifive_fe310_g000_hfxosc_ref(const struct metal_clock *clock)
  642. {
  643. return (struct metal_clock *)&__metal_dt_clock_0.clock;
  644. }
  645. static inline struct __metal_driver_sifive_fe310_g000_prci * __metal_driver_sifive_fe310_g000_hfxosc_config_base(const struct metal_clock *clock)
  646. {
  647. return (struct __metal_driver_sifive_fe310_g000_prci *)&__metal_dt_prci_10008000;
  648. }
  649. static inline long __metal_driver_sifive_fe310_g000_hfxosc_config_offset(const struct metal_clock *clock)
  650. {
  651. return METAL_SIFIVE_FE310_G000_PRCI_HFXOSCCFG;
  652. }
  653. /* --------------------- sifive_fe310_g000_pll ------------ */
  654. static inline struct metal_clock * __metal_driver_sifive_fe310_g000_pll_pllsel0(const struct metal_clock *clock)
  655. {
  656. return (struct metal_clock *)&__metal_dt_clock_3.clock;
  657. }
  658. static inline struct metal_clock * __metal_driver_sifive_fe310_g000_pll_pllref(const struct metal_clock *clock)
  659. {
  660. return (struct metal_clock *)&__metal_dt_clock_1.clock;
  661. }
  662. static inline struct __metal_driver_sifive_fe310_g000_prci * __metal_driver_sifive_fe310_g000_pll_divider_base(const struct metal_clock *clock)
  663. {
  664. return (struct __metal_driver_sifive_fe310_g000_prci *)&__metal_dt_prci_10008000;
  665. }
  666. static inline long __metal_driver_sifive_fe310_g000_pll_divider_offset(const struct metal_clock *clock)
  667. {
  668. return METAL_SIFIVE_FE310_G000_PRCI_PLLOUTDIV;
  669. }
  670. static inline struct __metal_driver_sifive_fe310_g000_prci * __metal_driver_sifive_fe310_g000_pll_config_base( )
  671. {
  672. return (struct __metal_driver_sifive_fe310_g000_prci *)&__metal_dt_prci_10008000;
  673. }
  674. static inline long __metal_driver_sifive_fe310_g000_pll_config_offset( )
  675. {
  676. return METAL_SIFIVE_FE310_G000_PRCI_PLLCFG;
  677. }
  678. static inline long __metal_driver_sifive_fe310_g000_pll_init_rate( )
  679. {
  680. return 16000000;
  681. }
  682. /* --------------------- sifive_fe310_g000_prci ------------ */
  683. static inline long __metal_driver_sifive_fe310_g000_prci_base( )
  684. {
  685. return METAL_SIFIVE_FE310_G000_PRCI_10008000_BASE_ADDRESS;
  686. }
  687. static inline long __metal_driver_sifive_fe310_g000_prci_size( )
  688. {
  689. return METAL_SIFIVE_FE310_G000_PRCI_10008000_SIZE;
  690. }
  691. static inline const struct __metal_driver_vtable_sifive_fe310_g000_prci * __metal_driver_sifive_fe310_g000_prci_vtable( )
  692. {
  693. return &__metal_driver_vtable_sifive_fe310_g000_prci;
  694. }
  695. /* --------------------- sifive_fu540_c000_l2 ------------ */
  696. #define __METAL_DT_MAX_MEMORIES 2
  697. asm (".weak __metal_memory_table");
  698. struct metal_memory *__metal_memory_table[] = {
  699. &__metal_dt_mem_dtim_80000000,
  700. &__metal_dt_mem_spi_10014000};
  701. /* From serial@10013000 */
  702. #define __METAL_DT_STDOUT_UART_HANDLE (&__metal_dt_serial_10013000.uart)
  703. #define __METAL_DT_SERIAL_10013000_HANDLE (&__metal_dt_serial_10013000.uart)
  704. #define __METAL_DT_STDOUT_UART_BAUD 115200
  705. /* From clint@2000000 */
  706. #define __METAL_DT_RISCV_CLINT0_HANDLE (&__metal_dt_clint_2000000.controller)
  707. #define __METAL_DT_CLINT_2000000_HANDLE (&__metal_dt_clint_2000000.controller)
  708. #define __METAL_DT_MAX_HARTS 1
  709. asm (".weak __metal_cpu_table");
  710. struct __metal_driver_cpu *__metal_cpu_table[] = {
  711. &__metal_dt_cpu_0};
  712. /* From interrupt_controller@c000000 */
  713. #define __METAL_DT_RISCV_PLIC0_HANDLE (&__metal_dt_interrupt_controller_c000000.controller)
  714. #define __METAL_DT_INTERRUPT_CONTROLLER_C000000_HANDLE (&__metal_dt_interrupt_controller_c000000.controller)
  715. #define __METAL_DT_PMP_HANDLE (&__metal_dt_pmp)
  716. /* From local_external_interrupts_0 */
  717. #define __METAL_DT_SIFIVE_LOCAL_EXINTR0_HANDLE (&__metal_dt_local_external_interrupts_0.irc)
  718. #define __METAL_DT_LOCAL_EXTERNAL_INTERRUPTS_0_HANDLE (&__metal_dt_local_external_interrupts_0.irc)
  719. #define __MEE_DT_MAX_GPIOS 1
  720. asm (".weak __metal_gpio_table");
  721. struct __metal_driver_sifive_gpio0 *__metal_gpio_table[] = {
  722. &__metal_dt_gpio_10012000};
  723. #define __METAL_DT_MAX_BUTTONS 0
  724. asm (".weak __metal_button_table");
  725. struct __metal_driver_sifive_gpio_button *__metal_button_table[] = {
  726. NULL };
  727. #define __METAL_DT_MAX_LEDS 3
  728. asm (".weak __metal_led_table");
  729. struct __metal_driver_sifive_gpio_led *__metal_led_table[] = {
  730. &__metal_dt_led_0red,
  731. &__metal_dt_led_0green,
  732. &__metal_dt_led_0blue};
  733. #define __METAL_DT_MAX_SWITCHES 0
  734. asm (".weak __metal_switch_table");
  735. struct __metal_driver_sifive_gpio_switch *__metal_switch_table[] = {
  736. NULL };
  737. #define __METAL_DT_MAX_SPIS 2
  738. asm (".weak __metal_spi_table");
  739. struct __metal_driver_sifive_spi0 *__metal_spi_table[] = {
  740. &__metal_dt_spi_10014000,
  741. &__metal_dt_spi_10024000};
  742. #define __METAL_DT_MAX_UARTS 2
  743. asm (".weak __metal_uart_table");
  744. struct __metal_driver_sifive_uart0 *__metal_uart_table[] = {
  745. &__metal_dt_serial_10013000,
  746. &__metal_dt_serial_10023000};
  747. /* From clock@4 */
  748. #define __METAL_DT_SIFIVE_FE310_G000_PLL_HANDLE (&__metal_dt_clock_4)
  749. #define __METAL_DT_CLOCK_4_HANDLE (&__metal_dt_clock_4)
  750. #endif /* MACROS_ELSE_SIFIVE_HIFIVE1_REVB____METAL_H*/
  751. #endif /* ! __METAL_MACHINE_MACROS */
  752. #endif /* ! ASSEMBLY */