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