global_data.h 14 KB

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