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 8 #ifndef __ASM_GENERIC_GBL_DATA_H 9 #define __ASM_GENERIC_GBL_DATA_H 10 /* 11 * The following data structure is placed in some memory which is 12 * available very early after boot (like DPRAM on MPC8xx/MPC82xx, or 13 * some locked parts of the data cache) to allow for a minimum set of 14 * global variables during system initialization (until we have set 15 * up the memory controller so that we can use RAM). 16 * 17 * Keep it *SMALL* and remember to set GENERATED_GBL_DATA_SIZE > sizeof(gd_t) 18 * 19 * Each architecture has its own private fields. For now all are private 20 */ 21 22 #ifndef __ASSEMBLY__ 23 #include <board_f.h> 24 #include <event_internal.h> 25 #include <fdtdec.h> 26 #include <membuf.h> 27 #include <linux/list.h> 28 #include <linux/build_bug.h> 29 #include <asm-offsets.h> 30 31 struct acpi_ctx; 32 struct driver_rt; 33 struct upl; 34 35 typedef struct global_data gd_t; 36 37 /** 38 * struct global_data - global data structure 39 */ 40 struct global_data { 41 /** 42 * @bd: board information 43 */ 44 struct bd_info *bd; 45 /** 46 * @new_gd: pointer to relocated global data 47 */ 48 struct global_data *new_gd; 49 /** 50 * @fdt_blob: U-Boot's own device tree, NULL if none 51 */ 52 const void *fdt_blob; 53 /** 54 * @cur_serial_dev: current serial device 55 */ 56 struct udevice *cur_serial_dev; 57 #ifndef CONFIG_XPL_BUILD 58 /** 59 * @jt: jump table 60 * 61 * The jump table contains pointers to exported functions. A pointer to 62 * the jump table is passed to standalone applications. 63 */ 64 struct jt_funcs *jt; 65 /** 66 * @boardf: information only used before relocation 67 */ 68 struct board_f *boardf; 69 #endif 70 /** 71 * @ram_size: RAM size in bytes 72 */ 73 phys_size_t ram_size; 74 /** 75 * @ram_top: top address of RAM used by U-Boot 76 */ 77 phys_addr_t ram_top; 78 /** 79 * @flags: global data flags 80 * 81 * See &enum gd_flags 82 */ 83 unsigned long flags; 84 /** 85 * @cpu_clk: CPU clock rate in Hz 86 */ 87 unsigned long cpu_clk; 88 #if CONFIG_IS_ENABLED(ENV_SUPPORT) 89 /** 90 * @env_addr: address of environment structure 91 * 92 * @env_addr contains the address of the structure holding the 93 * environment variables. 94 */ 95 unsigned long env_addr; 96 #endif /* ENV_SUPPORT */ 97 /** 98 * @ram_base: base address of RAM used by U-Boot 99 */ 100 unsigned long ram_base; 101 /** 102 * @relocaddr: start address of U-Boot in RAM 103 * 104 * After relocation this field indicates the address to which U-Boot 105 * has been relocated. It can be displayed using the bdinfo command. 106 * Its value is needed to display the source code when debugging with 107 * GDB using the 'add-symbol-file u-boot <relocaddr>' command. 108 */ 109 unsigned long relocaddr; 110 /** 111 * @irq_sp: IRQ stack pointer 112 */ 113 unsigned long irq_sp; 114 /** 115 * @start_addr_sp: initial stack pointer address 116 */ 117 unsigned long start_addr_sp; 118 /** 119 * @reloc_off: relocation offset 120 */ 121 unsigned long reloc_off; 122 /** 123 * @bus_clk: platform clock rate in Hz 124 */ 125 unsigned int bus_clk; 126 /** 127 * @mem_clk: memory clock rate in Hz 128 */ 129 unsigned int mem_clk; 130 /** 131 * @mon_len: monitor length in bytes 132 */ 133 unsigned int mon_len; 134 /** 135 * @baudrate: baud rate of the serial interface 136 */ 137 unsigned int baudrate; 138 #if CONFIG_IS_ENABLED(ENV_SUPPORT) 139 /** 140 * @env_has_init: bit mask indicating environment locations 141 * 142 * &enum env_location defines which bit relates to which location 143 */ 144 unsigned short env_has_init; 145 /** 146 * @env_valid: environment is valid 147 * 148 * See &enum env_valid 149 */ 150 unsigned char env_valid; 151 /** 152 * @env_load_prio: priority of the loaded environment 153 */ 154 char env_load_prio; 155 /** 156 * @env_buf: buffer for env_get() before reloc 157 */ 158 char env_buf[32]; 159 #endif /* ENV_SUPPORT */ 160 /** 161 * @fdt_src: Source of FDT 162 */ 163 enum fdt_source_t fdt_src; 164 /** 165 * @arch: architecture-specific data 166 */ 167 struct arch_global_data arch; 168 /** 169 * @dmtag_list: List of DM tags 170 */ 171 struct list_head dmtag_list; 172 /** 173 * @timebase_h: high 32 bits of timer 174 */ 175 unsigned int timebase_h; 176 /** 177 * @timebase_l: low 32 bits of timer 178 */ 179 unsigned int timebase_l; 180 #if defined(CONFIG_POST) 181 /** 182 * @post_log_word: active POST tests 183 * 184 * @post_log_word is a bit mask defining which POST tests are recorded 185 * (see constants POST_*). 186 */ 187 unsigned long post_log_word; 188 /** 189 * @post_log_res: POST results 190 * 191 * @post_log_res is a bit mask with the POST results. A bit with value 1 192 * indicates successful execution. 193 */ 194 unsigned long post_log_res; 195 /** 196 * @post_init_f_time: time in ms when post_init_f() started 197 */ 198 unsigned long post_init_f_time; 199 #endif 200 #ifdef CONFIG_BOARD_TYPES 201 /** 202 * @board_type: board type 203 * 204 * If a U-Boot configuration supports multiple board types, the actual 205 * board type may be stored in this field. 206 */ 207 unsigned long board_type; 208 #endif 209 #if CONFIG_IS_ENABLED(PRE_CONSOLE_BUFFER) 210 /** 211 * @precon_buf_idx: pre-console buffer index 212 * 213 * @precon_buf_idx indicates the current position of the 214 * buffer used to collect output before the console becomes 215 * available. When negative, the pre-console buffer is 216 * temporarily disabled (used when the pre-console buffer is 217 * being written out, to prevent adding its contents to 218 * itself). 219 */ 220 long precon_buf_idx; 221 #endif 222 #ifdef CONFIG_DM 223 /** 224 * @dm_root: root instance for Driver Model 225 */ 226 struct udevice *dm_root; 227 /** 228 * @uclass_root_s: 229 * head of core tree when uclasses are not in read-only memory. 230 * 231 * When uclasses are in read-only memory, @uclass_root_s is not used and 232 * @uclass_root points to the root node generated by dtoc. 233 */ 234 struct list_head uclass_root_s; 235 /** 236 * @uclass_root: 237 * pointer to head of core tree, if uclasses are in read-only memory and 238 * cannot be adjusted to use @uclass_root as a list head. 239 * 240 * When not in read-only memory, @uclass_root_s is used to hold the 241 * uclass root, and @uclass_root points to the address of 242 * @uclass_root_s. 243 */ 244 struct list_head *uclass_root; 245 # if CONFIG_IS_ENABLED(OF_PLATDATA_DRIVER_RT) 246 /** @dm_driver_rt: Dynamic info about the driver */ 247 struct driver_rt *dm_driver_rt; 248 # endif 249 #if CONFIG_IS_ENABLED(OF_PLATDATA_RT) 250 /** @dm_udevice_rt: Dynamic info about the udevice */ 251 struct udevice_rt *dm_udevice_rt; 252 /** 253 * @dm_priv_base: Base address of the priv/plat region used when 254 * udevices and uclasses are in read-only memory. This is NULL if not 255 * used 256 */ 257 void *dm_priv_base; 258 # endif 259 #endif 260 #ifdef CONFIG_TIMER 261 /** 262 * @timer: timer instance for Driver Model 263 */ 264 struct udevice *timer; 265 #endif 266 #if CONFIG_IS_ENABLED(OF_LIVE) 267 /** 268 * @of_root: root node of the live tree 269 */ 270 struct device_node *of_root; 271 #endif 272 #if CONFIG_IS_ENABLED(MULTI_DTB_FIT) 273 /** 274 * @multi_dtb_fit: pointer to uncompressed multi-dtb FIT image 275 */ 276 const void *multi_dtb_fit; 277 #endif 278 #ifdef CONFIG_TRACE 279 /** 280 * @trace_buff: trace buffer 281 * 282 * When tracing function in U-Boot this field points to the buffer 283 * recording the function calls. 284 */ 285 void *trace_buff; 286 #endif 287 #if CONFIG_IS_ENABLED(SYS_I2C_LEGACY) 288 /** 289 * @cur_i2c_bus: currently used I2C bus 290 */ 291 int cur_i2c_bus; 292 #endif 293 #if CONFIG_IS_ENABLED(CMD_BDINFO_EXTRA) 294 /** 295 * @malloc_start: start of malloc() region 296 */ 297 unsigned long malloc_start; 298 #endif 299 #if CONFIG_IS_ENABLED(SYS_MALLOC_F) 300 /** 301 * @malloc_base: base address of early malloc() 302 */ 303 unsigned long malloc_base; 304 /** 305 * @malloc_limit: maximum size of early malloc() 306 */ 307 unsigned int malloc_limit; 308 /** 309 * @malloc_ptr: currently used bytes of early malloc() 310 */ 311 unsigned int malloc_ptr; 312 #endif 313 #ifdef CONFIG_CONSOLE_RECORD 314 /** 315 * @console_out: output buffer for console recording 316 * 317 * This buffer is used to collect output during console recording. 318 */ 319 struct membuf console_out; 320 /** 321 * @console_in: input buffer for console recording 322 * 323 * If console recording is activated, this buffer can be used to 324 * emulate input. 325 */ 326 struct membuf console_in; 327 #endif 328 #if CONFIG_IS_ENABLED(VIDEO) 329 /** 330 * @video_top: top of video frame buffer area 331 */ 332 ulong video_top; 333 /** 334 * @video_bottom: bottom of video frame buffer area 335 */ 336 ulong video_bottom; 337 #endif 338 #ifdef CONFIG_BOOTSTAGE 339 /** 340 * @bootstage: boot stage information 341 */ 342 struct bootstage_data *bootstage; 343 #endif 344 #ifdef CONFIG_LOG 345 /** 346 * @log_head: list of logging devices 347 */ 348 struct list_head log_head; 349 /** 350 * @log_fmt: bit mask for logging format 351 * 352 * The @log_fmt bit mask selects the fields to be shown in log messages. 353 * &enum log_fmt defines the bits of the bit mask. 354 */ 355 /** 356 * @log_drop_count: number of dropped log messages 357 * 358 * This counter is incremented for each log message which can not 359 * be processed because logging is not yet available as signaled by 360 * flag %GD_FLG_LOG_READY in @flags. 361 */ 362 int log_drop_count; 363 /** 364 * @default_log_level: default logging level 365 * 366 * For logging devices without filters @default_log_level defines the 367 * logging level, cf. &enum log_level_t. 368 */ 369 char default_log_level; 370 char log_fmt; 371 /** 372 * @logc_prev: logging category of previous message 373 * 374 * This value is used as logging category for continuation messages. 375 */ 376 unsigned char logc_prev; 377 /** 378 * @logl_prev: logging level of the previous message 379 * 380 * This value is used as logging level for continuation messages. 381 */ 382 unsigned char logl_prev; 383 /** 384 * @log_cont: Previous log line did not finished wtih \n 385 * 386 * This allows for chained log messages on the same line 387 */ 388 bool log_cont; 389 /** 390 * @processing_msg: a log message is being processed 391 * 392 * This flag is used to suppress the creation of additional messages 393 * while another message is being processed. 394 */ 395 bool processing_msg; 396 #endif 397 #if CONFIG_IS_ENABLED(BLOBLIST) 398 /** 399 * @bloblist: blob list information 400 */ 401 struct bloblist_hdr *bloblist; 402 #endif 403 #if CONFIG_IS_ENABLED(HANDOFF) 404 /** 405 * @spl_handoff: SPL hand-off information 406 */ 407 struct spl_handoff *spl_handoff; 408 #endif 409 #if defined(CONFIG_TRANSLATION_OFFSET) 410 /** 411 * @translation_offset: optional translation offset 412 * 413 * See CONFIG_TRANSLATION_OFFSET. 414 */ 415 fdt_addr_t translation_offset; 416 #endif 417 #ifdef CONFIG_ACPI 418 /** 419 * @acpi_ctx: ACPI context pointer 420 */ 421 struct acpi_ctx *acpi_ctx; 422 /** 423 * @acpi_start: Start address of ACPI tables 424 */ 425 ulong acpi_start; 426 #endif 427 #if CONFIG_IS_ENABLED(GENERATE_SMBIOS_TABLE) 428 /** 429 * @smbios_version: Points to SMBIOS type 0 version 430 */ 431 char *smbios_version; 432 #endif 433 #if CONFIG_IS_ENABLED(EVENT) 434 /** 435 * @event_state: Points to the current state of events 436 */ 437 struct event_state event_state; 438 #endif 439 #if CONFIG_IS_ENABLED(CYCLIC) 440 /** 441 * @cyclic_list: list of registered cyclic functions 442 */ 443 struct hlist_head cyclic_list; 444 #endif 445 #if CONFIG_IS_ENABLED(UPL) 446 /** 447 * @upl: Universal Payload-handoff information 448 */ 449 struct upl *upl; 450 #endif 451 }; 452 #ifndef DO_DEPS_ONLY 453 static_assert(sizeof(struct global_data) == GD_SIZE); 454 #endif 455 456 /** 457 * gd_board_type() - retrieve board type 458 * 459 * Return: global board type 460 */ 461 #ifdef CONFIG_BOARD_TYPES 462 #define gd_board_type() gd->board_type 463 #else 464 #define gd_board_type() 0 465 #endif 466 467 /* These macros help avoid #ifdefs in the code */ 468 #if CONFIG_IS_ENABLED(OF_LIVE) 469 #define gd_of_root() gd->of_root 470 #define gd_of_root_ptr() &gd->of_root 471 #define gd_set_of_root(_root) gd->of_root = (_root) 472 #else 473 #define gd_of_root() NULL 474 #define gd_of_root_ptr() NULL 475 #define gd_set_of_root(_root) 476 #endif 477 478 #if CONFIG_IS_ENABLED(OF_PLATDATA_DRIVER_RT) 479 #define gd_set_dm_driver_rt(dyn) gd->dm_driver_rt = dyn 480 #define gd_dm_driver_rt() gd->dm_driver_rt 481 #else 482 #define gd_set_dm_driver_rt(dyn) 483 #define gd_dm_driver_rt() NULL 484 #endif 485 486 #if CONFIG_IS_ENABLED(OF_PLATDATA_RT) 487 #define gd_set_dm_udevice_rt(dyn) gd->dm_udevice_rt = dyn 488 #define gd_dm_udevice_rt() gd->dm_udevice_rt 489 #define gd_set_dm_priv_base(dyn) gd->dm_priv_base = dyn 490 #define gd_dm_priv_base() gd->dm_priv_base 491 #else 492 #define gd_set_dm_udevice_rt(dyn) 493 #define gd_dm_udevice_rt() NULL 494 #define gd_set_dm_priv_base(dyn) 495 #define gd_dm_priv_base() NULL 496 #endif 497 498 #ifdef CONFIG_ACPI 499 #define gd_acpi_ctx() gd->acpi_ctx 500 #define gd_acpi_start() gd->acpi_start 501 #define gd_set_acpi_start(addr) gd->acpi_start = addr 502 #else 503 #define gd_acpi_ctx() NULL 504 #define gd_acpi_start() 0UL 505 #define gd_set_acpi_start(addr) 506 #endif 507 508 #ifdef CONFIG_SMBIOS 509 #define gd_smbios_start() gd->arch.smbios_start 510 #define gd_set_smbios_start(addr) gd->arch.smbios_start = addr 511 #else 512 #define gd_smbios_start() 0UL 513 #define gd_set_smbios_start(addr) 514 #endif 515 516 #if CONFIG_IS_ENABLED(MULTI_DTB_FIT) 517 #define gd_multi_dtb_fit() gd->multi_dtb_fit 518 #define gd_set_multi_dtb_fit(_dtb) gd->multi_dtb_fit = _dtb 519 #else 520 #define gd_multi_dtb_fit() NULL 521 #define gd_set_multi_dtb_fit(_dtb) 522 #endif 523 524 #if CONFIG_IS_ENABLED(EVENT_DYNAMIC) 525 #define gd_event_state() ((struct event_state *)&gd->event_state) 526 #else 527 #define gd_event_state() NULL 528 #endif 529 530 #if CONFIG_IS_ENABLED(CMD_BDINFO_EXTRA) 531 #define gd_malloc_start() gd->malloc_start 532 #define gd_set_malloc_start(_val) gd->malloc_start = (_val) 533 #else 534 #define gd_malloc_start() 0 535 #define gd_set_malloc_start(val) 536 #endif 537 538 #if CONFIG_VAL(SYS_MALLOC_F_LEN) 539 #define gd_malloc_ptr() gd->malloc_ptr 540 #else 541 #define gd_malloc_ptr() 0L 542 #endif 543 544 #if CONFIG_IS_ENABLED(UPL) 545 #define gd_upl() gd->upl 546 #define gd_set_upl(_val) gd->upl = (_val) 547 #else 548 #define gd_upl() NULL 549 #define gd_set_upl(val) 550 #endif 551 552 #if CONFIG_IS_ENABLED(BLOBLIST) 553 #define gd_bloblist() gd->bloblist 554 #define gd_set_bloblist(_val) gd->bloblist = (_val) 555 #else 556 #define gd_bloblist() NULL 557 #define gd_set_bloblist(_val) 558 #endif 559 560 #if CONFIG_IS_ENABLED(BOOTSTAGE) 561 #define gd_bootstage() gd->bootstage 562 #else 563 #define gd_bootstage() NULL 564 #endif 565 566 #if CONFIG_IS_ENABLED(TRACE) 567 #define gd_trace_buff() gd->trace_buff 568 #define gd_trace_size() CONFIG_TRACE_BUFFER_SIZE 569 #else 570 #define gd_trace_buff() NULL 571 #define gd_trace_size() 0 572 #endif 573 574 #if CONFIG_IS_ENABLED(VIDEO) 575 #define gd_video_top() gd->video_top 576 #define gd_video_bottom() gd->video_bottom 577 #define gd_video_size() (gd->video_top - gd->video_bottom) 578 #else 579 #define gd_video_top() 0 580 #define gd_video_bottom() 0 581 #define gd_video_size() 0 582 #endif 583 584 /** 585 * enum gd_flags - global data flags 586 * 587 * See field flags of &struct global_data. 588 */ 589 enum gd_flags { 590 /** 591 * @GD_FLG_RELOC: code was relocated to RAM 592 */ 593 GD_FLG_RELOC = 0x00001, 594 /** 595 * @GD_FLG_DEVINIT: devices have been initialized 596 */ 597 GD_FLG_DEVINIT = 0x00002, 598 /** 599 * @GD_FLG_SILENT: silent mode 600 */ 601 GD_FLG_SILENT = 0x00004, 602 /** 603 * @GD_FLG_POSTFAIL: critical POST test failed 604 */ 605 GD_FLG_POSTFAIL = 0x00008, 606 /** 607 * @GD_FLG_POSTSTOP: POST sequence aborted 608 */ 609 GD_FLG_POSTSTOP = 0x00010, 610 /** 611 * @GD_FLG_LOGINIT: log Buffer has been initialized 612 */ 613 GD_FLG_LOGINIT = 0x00020, 614 /** 615 * @GD_FLG_DISABLE_CONSOLE: disable console (in & out) 616 */ 617 GD_FLG_DISABLE_CONSOLE = 0x00040, 618 /** 619 * @GD_FLG_ENV_READY: environment imported into hash table 620 */ 621 GD_FLG_ENV_READY = 0x00080, 622 /** 623 * @GD_FLG_SERIAL_READY: pre-relocation serial console ready 624 */ 625 GD_FLG_SERIAL_READY = 0x00100, 626 /** 627 * @GD_FLG_FULL_MALLOC_INIT: full malloc() is ready 628 */ 629 GD_FLG_FULL_MALLOC_INIT = 0x00200, 630 /** 631 * @GD_FLG_SPL_INIT: spl_init() has been called 632 */ 633 GD_FLG_SPL_INIT = 0x00400, 634 /** 635 * @GD_FLG_SKIP_RELOC: don't relocate 636 */ 637 GD_FLG_SKIP_RELOC = 0x00800, 638 /** 639 * @GD_FLG_RECORD: record console 640 */ 641 GD_FLG_RECORD = 0x01000, 642 /** 643 * @GD_FLG_RECORD_OVF: record console overflow 644 */ 645 GD_FLG_RECORD_OVF = 0x02000, 646 /** 647 * @GD_FLG_ENV_DEFAULT: default variable flag 648 */ 649 GD_FLG_ENV_DEFAULT = 0x04000, 650 /** 651 * @GD_FLG_SPL_EARLY_INIT: early SPL initialization is done 652 */ 653 GD_FLG_SPL_EARLY_INIT = 0x08000, 654 /** 655 * @GD_FLG_LOG_READY: log system is ready for use 656 */ 657 GD_FLG_LOG_READY = 0x10000, 658 /** 659 * @GD_FLG_CYCLIC_RUNNING: cyclic_run is in progress 660 */ 661 GD_FLG_CYCLIC_RUNNING = 0x20000, 662 /** 663 * @GD_FLG_SKIP_LL_INIT: don't perform low-level initialization 664 */ 665 GD_FLG_SKIP_LL_INIT = 0x40000, 666 /** 667 * @GD_FLG_SMP_READY: SMP initialization is complete 668 */ 669 GD_FLG_SMP_READY = 0x80000, 670 /** 671 * @GD_FLG_FDT_CHANGED: Device tree change has been detected by tests 672 */ 673 GD_FLG_FDT_CHANGED = 0x100000, 674 /** 675 * @GD_FLG_OF_TAG_MIGRATE: Device tree has old u-boot,dm- tags 676 */ 677 GD_FLG_OF_TAG_MIGRATE = 0x200000, 678 /** 679 * @GD_FLG_DM_DEAD: Driver model is not accessible. This can be set when 680 * the memory used to holds its tables has been mapped out. 681 */ 682 GD_FLG_DM_DEAD = 0x400000, 683 /** 684 * @GD_FLG_BLOBLIST_READY: bloblist is ready for use 685 */ 686 GD_FLG_BLOBLIST_READY = 0x800000, 687 /** 688 * @GD_FLG_HUSH_OLD_PARSER: Use hush old parser. 689 */ 690 GD_FLG_HUSH_OLD_PARSER = 0x1000000, 691 /** 692 * @GD_FLG_HUSH_MODERN_PARSER: Use hush 2021 parser. 693 */ 694 GD_FLG_HUSH_MODERN_PARSER = 0x2000000, 695 /** 696 * @GD_FLG_UPL: Read/write a Universal Payload (UPL) handoff 697 */ 698 GD_FLG_UPL = 0x4000000, 699 /** 700 * @GD_FLG_HAVE_CONSOLE: serial_init() was called and a console 701 * is available. When not set, indicates that console input and output 702 * drivers shall not be called. 703 */ 704 GD_FLG_HAVE_CONSOLE = 0x8000000, 705 }; 706 707 #endif /* __ASSEMBLY__ */ 708 709 #endif /* __ASM_GENERIC_GBL_DATA_H */ 710