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