global_data.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (c) 2012 The Chromium OS Authors.
  4. * (C) Copyright 2002-2010
  5. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  6. */
  7. #ifndef __ASM_GENERIC_GBL_DATA_H
  8. #define __ASM_GENERIC_GBL_DATA_H
  9. /*
  10. * The following data structure is placed in some memory which is
  11. * available very early after boot (like DPRAM on MPC8xx/MPC82xx, or
  12. * some locked parts of the data cache) to allow for a minimum set of
  13. * global variables during system initialization (until we have set
  14. * up the memory controller so that we can use RAM).
  15. *
  16. * Keep it *SMALL* and remember to set GENERATED_GBL_DATA_SIZE > sizeof(gd_t)
  17. *
  18. * Each architecture has its own private fields. For now all are private
  19. */
  20. #ifndef __ASSEMBLY__
  21. #include <fdtdec.h>
  22. #include <membuff.h>
  23. #include <linux/list.h>
  24. struct acpi_ctx;
  25. struct driver_rt;
  26. typedef struct global_data gd_t;
  27. /**
  28. * struct global_data - global data structure
  29. */
  30. struct global_data {
  31. /**
  32. * @bd: board information
  33. */
  34. struct bd_info *bd;
  35. /**
  36. * @flags: global data flags
  37. *
  38. * See &enum gd_flags
  39. */
  40. unsigned long flags;
  41. /**
  42. * @baudrate: baud rate of the serial interface
  43. */
  44. unsigned int baudrate;
  45. /**
  46. * @cpu_clk: CPU clock rate in Hz
  47. */
  48. unsigned long cpu_clk;
  49. /**
  50. * @bus_clk: platform clock rate in Hz
  51. */
  52. unsigned long bus_clk;
  53. /**
  54. * @pci_clk: PCI clock rate in Hz
  55. */
  56. /* We cannot bracket this with CONFIG_PCI due to mpc5xxx */
  57. unsigned long pci_clk;
  58. /**
  59. * @mem_clk: memory clock rate in Hz
  60. */
  61. unsigned long mem_clk;
  62. #if defined(CONFIG_LCD) || defined(CONFIG_VIDEO) || defined(CONFIG_DM_VIDEO)
  63. /**
  64. * @fb_base: base address of frame buffer memory
  65. */
  66. unsigned long fb_base;
  67. #endif
  68. #if defined(CONFIG_POST)
  69. /**
  70. * @post_log_word: active POST tests
  71. *
  72. * @post_log_word is a bit mask defining which POST tests are recorded
  73. * (see constants POST_*).
  74. */
  75. unsigned long post_log_word;
  76. /**
  77. * @post_log_res: POST results
  78. *
  79. * @post_log_res is a bit mask with the POST results. A bit with value 1
  80. * indicates successful execution.
  81. */
  82. unsigned long post_log_res;
  83. /**
  84. * @post_init_f_time: time in ms when post_init_f() started
  85. */
  86. unsigned long post_init_f_time;
  87. #endif
  88. #ifdef CONFIG_BOARD_TYPES
  89. /**
  90. * @board_type: board type
  91. *
  92. * If a U-Boot configuration supports multiple board types, the actual
  93. * board type may be stored in this field.
  94. */
  95. unsigned long board_type;
  96. #endif
  97. /**
  98. * @have_console: console is available
  99. *
  100. * A value of 1 indicates that serial_init() was called and a console
  101. * is available.
  102. * A value of 0 indicates that console input and output drivers shall
  103. * not be called.
  104. */
  105. unsigned long have_console;
  106. #if CONFIG_IS_ENABLED(PRE_CONSOLE_BUFFER)
  107. /**
  108. * @precon_buf_idx: pre-console buffer index
  109. *
  110. * @precon_buf_idx indicates the current position of the buffer used to
  111. * collect output before the console becomes available
  112. */
  113. unsigned long precon_buf_idx;
  114. #endif
  115. /**
  116. * @env_addr: address of environment structure
  117. *
  118. * @env_addr contains the address of the structure holding the
  119. * environment variables.
  120. */
  121. unsigned long env_addr;
  122. /**
  123. * @env_valid: environment is valid
  124. *
  125. * See &enum env_valid
  126. */
  127. unsigned long env_valid;
  128. /**
  129. * @env_has_init: bit mask indicating environment locations
  130. *
  131. * &enum env_location defines which bit relates to which location
  132. */
  133. unsigned long env_has_init;
  134. /**
  135. * @env_load_prio: priority of the loaded environment
  136. */
  137. int env_load_prio;
  138. /**
  139. * @ram_base: base address of RAM used by U-Boot
  140. */
  141. unsigned long ram_base;
  142. /**
  143. * @ram_top: top address of RAM used by U-Boot
  144. */
  145. phys_addr_t ram_top;
  146. /**
  147. * @relocaddr: start address of U-Boot in RAM
  148. *
  149. * After relocation this field indicates the address to which U-Boot
  150. * has been relocated. It can be displayed using the bdinfo command.
  151. * Its value is needed to display the source code when debugging with
  152. * GDB using the 'add-symbol-file u-boot <relocaddr>' command.
  153. */
  154. unsigned long relocaddr;
  155. /**
  156. * @ram_size: RAM size in bytes
  157. */
  158. phys_size_t ram_size;
  159. /**
  160. * @mon_len: monitor length in bytes
  161. */
  162. unsigned long mon_len;
  163. /**
  164. * @irq_sp: IRQ stack pointer
  165. */
  166. unsigned long irq_sp;
  167. /**
  168. * @start_addr_sp: initial stack pointer address
  169. */
  170. unsigned long start_addr_sp;
  171. /**
  172. * @reloc_off: relocation offset
  173. */
  174. unsigned long reloc_off;
  175. /**
  176. * @new_gd: pointer to relocated global data
  177. */
  178. struct global_data *new_gd;
  179. #ifdef CONFIG_DM
  180. /**
  181. * @dm_flags: additional flags for Driver Model
  182. *
  183. * See &enum gd_dm_flags
  184. */
  185. unsigned long dm_flags;
  186. /**
  187. * @dm_root: root instance for Driver Model
  188. */
  189. struct udevice *dm_root;
  190. /**
  191. * @dm_root_f: pre-relocation root instance
  192. */
  193. struct udevice *dm_root_f;
  194. /**
  195. * @uclass_root_s:
  196. * head of core tree when uclasses are not in read-only memory.
  197. *
  198. * When uclasses are in read-only memory, @uclass_root_s is not used and
  199. * @uclass_root points to the root node generated by dtoc.
  200. */
  201. struct list_head uclass_root_s;
  202. /**
  203. * @uclass_root:
  204. * pointer to head of core tree, if uclasses are in read-only memory and
  205. * cannot be adjusted to use @uclass_root as a list head.
  206. *
  207. * When not in read-only memory, @uclass_root_s is used to hold the
  208. * uclass root, and @uclass_root points to the address of
  209. * @uclass_root_s.
  210. */
  211. struct list_head *uclass_root;
  212. # if CONFIG_IS_ENABLED(OF_PLATDATA)
  213. /** @dm_driver_rt: Dynamic info about the driver */
  214. struct driver_rt *dm_driver_rt;
  215. # endif
  216. #endif
  217. #ifdef CONFIG_TIMER
  218. /**
  219. * @timer: timer instance for Driver Model
  220. */
  221. struct udevice *timer;
  222. #endif
  223. /**
  224. * @fdt_blob: U-Boot's own device tree, NULL if none
  225. */
  226. const void *fdt_blob;
  227. /**
  228. * @new_fdt: relocated device tree
  229. */
  230. void *new_fdt;
  231. /**
  232. * @fdt_size: space reserved for relocated device space
  233. */
  234. unsigned long fdt_size;
  235. #if CONFIG_IS_ENABLED(OF_LIVE)
  236. /**
  237. * @of_root: root node of the live tree
  238. */
  239. struct device_node *of_root;
  240. #endif
  241. #if CONFIG_IS_ENABLED(MULTI_DTB_FIT)
  242. /**
  243. * @multi_dtb_fit: pointer to uncompressed multi-dtb FIT image
  244. */
  245. const void *multi_dtb_fit;
  246. #endif
  247. /**
  248. * @jt: jump table
  249. *
  250. * The jump table contains pointers to exported functions. A pointer to
  251. * the jump table is passed to standalone applications.
  252. */
  253. struct jt_funcs *jt;
  254. /**
  255. * @env_buf: buffer for env_get() before reloc
  256. */
  257. char env_buf[32];
  258. #ifdef CONFIG_TRACE
  259. /**
  260. * @trace_buff: trace buffer
  261. *
  262. * When tracing function in U-Boot this field points to the buffer
  263. * recording the function calls.
  264. */
  265. void *trace_buff;
  266. #endif
  267. #if defined(CONFIG_SYS_I2C)
  268. /**
  269. * @cur_i2c_bus: currently used I2C bus
  270. */
  271. int cur_i2c_bus;
  272. #endif
  273. /**
  274. * @timebase_h: high 32 bits of timer
  275. */
  276. unsigned int timebase_h;
  277. /**
  278. * @timebase_l: low 32 bits of timer
  279. */
  280. unsigned int timebase_l;
  281. #if CONFIG_VAL(SYS_MALLOC_F_LEN)
  282. /**
  283. * @malloc_base: base address of early malloc()
  284. */
  285. unsigned long malloc_base;
  286. /**
  287. * @malloc_limit: limit address of early malloc()
  288. */
  289. unsigned long malloc_limit;
  290. /**
  291. * @malloc_ptr: current address of early malloc()
  292. */
  293. unsigned long malloc_ptr;
  294. #endif
  295. #ifdef CONFIG_PCI
  296. /**
  297. * @hose: PCI hose for early use
  298. */
  299. struct pci_controller *hose;
  300. /**
  301. * @pci_ram_top: top of region accessible to PCI
  302. */
  303. phys_addr_t pci_ram_top;
  304. #endif
  305. #ifdef CONFIG_PCI_BOOTDELAY
  306. /**
  307. * @pcidelay_done: delay time before scanning of PIC hose expired
  308. *
  309. * If CONFIG_PCI_BOOTDELAY=y, pci_hose_scan() waits for the number of
  310. * milliseconds defined by environment variable pcidelay before
  311. * scanning. Once this delay has expired the flag @pcidelay_done
  312. * is set to 1.
  313. */
  314. int pcidelay_done;
  315. #endif
  316. /**
  317. * @cur_serial_dev: current serial device
  318. */
  319. struct udevice *cur_serial_dev;
  320. /**
  321. * @arch: architecture-specific data
  322. */
  323. struct arch_global_data arch;
  324. #ifdef CONFIG_CONSOLE_RECORD
  325. /**
  326. * @console_out: output buffer for console recording
  327. *
  328. * This buffer is used to collect output during console recording.
  329. */
  330. struct membuff console_out;
  331. /**
  332. * @console_in: input buffer for console recording
  333. *
  334. * If console recording is activated, this buffer can be used to
  335. * emulate input.
  336. */
  337. struct membuff console_in;
  338. #endif
  339. #ifdef CONFIG_DM_VIDEO
  340. /**
  341. * @video_top: top of video frame buffer area
  342. */
  343. ulong video_top;
  344. /**
  345. * @video_bottom: bottom of video frame buffer area
  346. */
  347. ulong video_bottom;
  348. #endif
  349. #ifdef CONFIG_BOOTSTAGE
  350. /**
  351. * @bootstage: boot stage information
  352. */
  353. struct bootstage_data *bootstage;
  354. /**
  355. * @new_bootstage: relocated boot stage information
  356. */
  357. struct bootstage_data *new_bootstage;
  358. #endif
  359. #ifdef CONFIG_LOG
  360. /**
  361. * @log_drop_count: number of dropped log messages
  362. *
  363. * This counter is incremented for each log message which can not
  364. * be processed because logging is not yet available as signaled by
  365. * flag %GD_FLG_LOG_READY in @flags.
  366. */
  367. int log_drop_count;
  368. /**
  369. * @default_log_level: default logging level
  370. *
  371. * For logging devices without filters @default_log_level defines the
  372. * logging level, cf. &enum log_level_t.
  373. */
  374. int default_log_level;
  375. /**
  376. * @log_head: list of logging devices
  377. */
  378. struct list_head log_head;
  379. /**
  380. * @log_fmt: bit mask for logging format
  381. *
  382. * The @log_fmt bit mask selects the fields to be shown in log messages.
  383. * &enum log_fmt defines the bits of the bit mask.
  384. */
  385. int log_fmt;
  386. /**
  387. * @processing_msg: a log message is being processed
  388. *
  389. * This flag is used to suppress the creation of additional messages
  390. * while another message is being processed.
  391. */
  392. bool processing_msg;
  393. /**
  394. * @logc_prev: logging category of previous message
  395. *
  396. * This value is used as logging category for continuation messages.
  397. */
  398. int logc_prev;
  399. /**
  400. * @logl_prev: logging level of the previous message
  401. *
  402. * This value is used as logging level for continuation messages.
  403. */
  404. int logl_prev;
  405. /**
  406. * @log_cont: Previous log line did not finished wtih \n
  407. *
  408. * This allows for chained log messages on the same line
  409. */
  410. bool log_cont;
  411. #endif
  412. #if CONFIG_IS_ENABLED(BLOBLIST)
  413. /**
  414. * @bloblist: blob list information
  415. */
  416. struct bloblist_hdr *bloblist;
  417. /**
  418. * @new_bloblist: relocated blob list information
  419. */
  420. struct bloblist_hdr *new_bloblist;
  421. #endif
  422. #if CONFIG_IS_ENABLED(HANDOFF)
  423. /**
  424. * @spl_handoff: SPL hand-off information
  425. */
  426. struct spl_handoff *spl_handoff;
  427. #endif
  428. #if defined(CONFIG_TRANSLATION_OFFSET)
  429. /**
  430. * @translation_offset: optional translation offset
  431. *
  432. * See CONFIG_TRANSLATION_OFFSET.
  433. */
  434. fdt_addr_t translation_offset;
  435. #endif
  436. #if CONFIG_IS_ENABLED(WDT)
  437. /**
  438. * @watchdog_dev: watchdog device
  439. */
  440. struct udevice *watchdog_dev;
  441. #endif
  442. #ifdef CONFIG_GENERATE_ACPI_TABLE
  443. /**
  444. * @acpi_ctx: ACPI context pointer
  445. */
  446. struct acpi_ctx *acpi_ctx;
  447. #endif
  448. #if CONFIG_IS_ENABLED(GENERATE_SMBIOS_TABLE)
  449. /**
  450. * @smbios_version: Points to SMBIOS type 0 version
  451. */
  452. char *smbios_version;
  453. #endif
  454. };
  455. /**
  456. * gd_board_type() - retrieve board type
  457. *
  458. * Return: global board type
  459. */
  460. #ifdef CONFIG_BOARD_TYPES
  461. #define gd_board_type() gd->board_type
  462. #else
  463. #define gd_board_type() 0
  464. #endif
  465. /* These macros help avoid #ifdefs in the code */
  466. #if CONFIG_IS_ENABLED(OF_LIVE)
  467. #define gd_of_root() gd->of_root
  468. #define gd_of_root_ptr() &gd->of_root
  469. #define gd_set_of_root(_root) gd->of_root = (_root)
  470. #else
  471. #define gd_of_root() NULL
  472. #define gd_of_root_ptr() NULL
  473. #define gd_set_of_root(_root)
  474. #endif
  475. #if CONFIG_IS_ENABLED(OF_PLATDATA)
  476. #define gd_set_dm_driver_rt(dyn) gd->dm_driver_rt = dyn
  477. #define gd_dm_driver_rt() gd->dm_driver_rt
  478. #else
  479. #define gd_set_dm_driver_rt(dyn)
  480. #define gd_dm_driver_rt() NULL
  481. #endif
  482. #ifdef CONFIG_GENERATE_ACPI_TABLE
  483. #define gd_acpi_ctx() gd->acpi_ctx
  484. #else
  485. #define gd_acpi_ctx() NULL
  486. #endif
  487. #if CONFIG_IS_ENABLED(DM)
  488. #define gd_size_cells_0() (gd->dm_flags & GD_DM_FLG_SIZE_CELLS_0)
  489. #else
  490. #define gd_size_cells_0() (0)
  491. #endif
  492. /**
  493. * enum gd_flags - global data flags
  494. *
  495. * See field flags of &struct global_data.
  496. */
  497. enum gd_flags {
  498. /**
  499. * @GD_FLG_RELOC: code was relocated to RAM
  500. */
  501. GD_FLG_RELOC = 0x00001,
  502. /**
  503. * @GD_FLG_DEVINIT: devices have been initialized
  504. */
  505. GD_FLG_DEVINIT = 0x00002,
  506. /**
  507. * @GD_FLG_SILENT: silent mode
  508. */
  509. GD_FLG_SILENT = 0x00004,
  510. /**
  511. * @GD_FLG_POSTFAIL: critical POST test failed
  512. */
  513. GD_FLG_POSTFAIL = 0x00008,
  514. /**
  515. * @GD_FLG_POSTSTOP: POST sequence aborted
  516. */
  517. GD_FLG_POSTSTOP = 0x00010,
  518. /**
  519. * @GD_FLG_LOGINIT: log Buffer has been initialized
  520. */
  521. GD_FLG_LOGINIT = 0x00020,
  522. /**
  523. * @GD_FLG_DISABLE_CONSOLE: disable console (in & out)
  524. */
  525. GD_FLG_DISABLE_CONSOLE = 0x00040,
  526. /**
  527. * @GD_FLG_ENV_READY: environment imported into hash table
  528. */
  529. GD_FLG_ENV_READY = 0x00080,
  530. /**
  531. * @GD_FLG_SERIAL_READY: pre-relocation serial console ready
  532. */
  533. GD_FLG_SERIAL_READY = 0x00100,
  534. /**
  535. * @GD_FLG_FULL_MALLOC_INIT: full malloc() is ready
  536. */
  537. GD_FLG_FULL_MALLOC_INIT = 0x00200,
  538. /**
  539. * @GD_FLG_SPL_INIT: spl_init() has been called
  540. */
  541. GD_FLG_SPL_INIT = 0x00400,
  542. /**
  543. * @GD_FLG_SKIP_RELOC: don't relocate
  544. */
  545. GD_FLG_SKIP_RELOC = 0x00800,
  546. /**
  547. * @GD_FLG_RECORD: record console
  548. */
  549. GD_FLG_RECORD = 0x01000,
  550. /**
  551. * @GD_FLG_ENV_DEFAULT: default variable flag
  552. */
  553. GD_FLG_ENV_DEFAULT = 0x02000,
  554. /**
  555. * @GD_FLG_SPL_EARLY_INIT: early SPL initialization is done
  556. */
  557. GD_FLG_SPL_EARLY_INIT = 0x04000,
  558. /**
  559. * @GD_FLG_LOG_READY: log system is ready for use
  560. */
  561. GD_FLG_LOG_READY = 0x08000,
  562. /**
  563. * @GD_FLG_WDT_READY: watchdog is ready for use
  564. */
  565. GD_FLG_WDT_READY = 0x10000,
  566. /**
  567. * @GD_FLG_SKIP_LL_INIT: don't perform low-level initialization
  568. */
  569. GD_FLG_SKIP_LL_INIT = 0x20000,
  570. /**
  571. * @GD_FLG_SMP_READY: SMP initialization is complete
  572. */
  573. GD_FLG_SMP_READY = 0x40000,
  574. };
  575. /**
  576. * enum gd_dm_flags - global data flags for Driver Model
  577. *
  578. * See field dm_flags of &struct global_data.
  579. */
  580. enum gd_dm_flags {
  581. /**
  582. * @GD_DM_FLG_SIZE_CELLS_0: Enable #size-cells=<0> translation
  583. */
  584. GD_DM_FLG_SIZE_CELLS_0 = 0x00001,
  585. };
  586. #endif /* __ASSEMBLY__ */
  587. #endif /* __ASM_GENERIC_GBL_DATA_H */