LCOV - code coverage report
Current view: top level - include - skiboot.h (source / functions) Hit Total Coverage
Test: skiboot.info Lines: 4 4 100.0 %
Date: 2024-01-02 21:04:04 Functions: 2 2 100.0 %
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : // SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
       2                 :            : /* Copyright 2013-2019 IBM Corp.
       3                 :            :  * Copyright 2021 Stewart Smith
       4                 :            :  */
       5                 :            : 
       6                 :            : #ifndef __SKIBOOT_H
       7                 :            : #define __SKIBOOT_H
       8                 :            : 
       9                 :            : #include <compiler.h>
      10                 :            : #include <stdint.h>
      11                 :            : #include <stdbool.h>
      12                 :            : #include <string.h>
      13                 :            : #include <stdlib.h>
      14                 :            : #include <stdio.h>
      15                 :            : #include <assert.h>
      16                 :            : #include <errno.h>
      17                 :            : #include <bitutils.h>
      18                 :            : #include <types.h>
      19                 :            : 
      20                 :            : #include <ccan/container_of/container_of.h>
      21                 :            : #include <ccan/list/list.h>
      22                 :            : #include <ccan/short_types/short_types.h>
      23                 :            : #include <ccan/build_assert/build_assert.h>
      24                 :            : #include <ccan/array_size/array_size.h>
      25                 :            : #include <ccan/endian/endian.h>
      26                 :            : #include <ccan/str/str.h>
      27                 :            : 
      28                 :            : #include <libflash/blocklevel.h>
      29                 :            : 
      30                 :            : #include <mem-map.h>
      31                 :            : #include <op-panel.h>
      32                 :            : #include <platform.h>
      33                 :            : 
      34                 :            : /* Special ELF sections */
      35                 :            : #define __force_data            __section(".force.data")
      36                 :            : 
      37                 :            : struct mem_region;
      38                 :            : extern struct mem_region *mem_region_next(struct mem_region *region);
      39                 :            : 
      40                 :            : /* Misc linker script symbols */
      41                 :            : extern char _start[];
      42                 :            : extern char _head_end[];
      43                 :            : extern char _stext[];
      44                 :            : extern char _etext[];
      45                 :            : extern char __sym_map_end[];
      46                 :            : extern char _romem_end[];
      47                 :            : 
      48                 :            : #ifndef __TESTING__
      49                 :            : /* Readonly section start and end. */
      50                 :            : extern char __rodata_start[], __rodata_end[];
      51                 :            : 
      52                 :       1878 : static inline bool is_rodata(const void *p)
      53                 :            : {
      54                 :       1878 :         return ((const char *)p >= __rodata_start && (const char *)p < __rodata_end);
      55                 :            : }
      56                 :            : #else
      57                 :            : static inline bool is_rodata(const void *p)
      58                 :            : {
      59                 :            :         return false;
      60                 :            : }
      61                 :            : #endif
      62                 :            : 
      63                 :            : /* Console logging
      64                 :            :  * Update console_get_level() if you add here
      65                 :            :  */
      66                 :            : #define PR_EMERG        0
      67                 :            : #define PR_ALERT        1
      68                 :            : #define PR_CRIT         2
      69                 :            : #define PR_ERR          3
      70                 :            : #define PR_WARNING      4
      71                 :            : #define PR_NOTICE       5
      72                 :            : #define PR_PRINTF       PR_NOTICE
      73                 :            : #define PR_INFO         6
      74                 :            : #define PR_DEBUG        7
      75                 :            : #define PR_TRACE        8
      76                 :            : #define PR_INSANE       9
      77                 :            : 
      78                 :            : #ifndef pr_fmt
      79                 :            : #define pr_fmt(fmt) fmt
      80                 :            : #endif
      81                 :            : 
      82                 :            : int vprlog(int log_level, const char *fmt, va_list ap);
      83                 :            : void _prlog(int log_level, const char* fmt, ...) __attribute__((format (printf, 2, 3)));
      84                 :            : #define prlog(l, f, ...) do { _prlog(l, pr_fmt(f), ##__VA_ARGS__); } while(0)
      85                 :            : #define prerror(fmt...) do { prlog(PR_ERR, fmt); } while(0)
      86                 :            : #define prlog_once(arg, ...)                    \
      87                 :            : ({                                              \
      88                 :            :         static bool __prlog_once = false;       \
      89                 :            :         if (!__prlog_once) {                    \
      90                 :            :                 __prlog_once = true;            \
      91                 :            :                 prlog(arg, ##__VA_ARGS__);      \
      92                 :            :         }                                       \
      93                 :            : })
      94                 :            : 
      95                 :            : /* Location codes  -- at most 80 chars with null termination */
      96                 :            : #define LOC_CODE_SIZE   80
      97                 :            : 
      98                 :            : /* Processor generation */
      99                 :            : enum proc_gen {
     100                 :            :         proc_gen_unknown,
     101                 :            :         proc_gen_p8,
     102                 :            :         proc_gen_p9,
     103                 :            :         proc_gen_p10,
     104                 :            : };
     105                 :            : extern enum proc_gen proc_gen;
     106                 :            : 
     107                 :            : extern bool lpar_per_core;
     108                 :            : 
     109                 :            : extern unsigned int pcie_max_link_speed;
     110                 :            : 
     111                 :            : /* Convert a 4-bit number to a hex char */
     112                 :            : extern char __attrconst tohex(uint8_t nibble);
     113                 :            : 
     114                 :            : #ifndef __TEST__
     115                 :            : /* Bit position of the most significant 1-bit (LSB=0, MSB=63) */
     116                 :            : static inline int ilog2(unsigned long val)
     117                 :            : {
     118                 :            :         int left_zeros;
     119                 :            : 
     120                 :            :         asm volatile ("cntlzd %0,%1" : "=r" (left_zeros) : "r" (val));
     121                 :            : 
     122                 :            :         return 63 - left_zeros;
     123                 :            : }
     124                 :            : 
     125                 :            : static inline bool is_pow2(unsigned long val)
     126                 :            : {
     127                 :            :         return val == (1ul << ilog2(val));
     128                 :            : }
     129                 :            : #endif
     130                 :            : 
     131                 :            : #define lo32(x) ((x) & 0xffffffff)
     132                 :            : #define hi32(x) (((x) >> 32) & 0xffffffff)
     133                 :            : 
     134                 :            : /* WARNING: _a *MUST* be a power of two */
     135                 :            : #define ALIGN_UP(_v, _a)        (((_v) + (_a) - 1) & ~((_a) - 1))
     136                 :            : #define ALIGN_DOWN(_v, _a)      ((_v) & ~((_a) - 1))
     137                 :            : 
     138                 :            : /* TCE alignment */
     139                 :            : #define TCE_SHIFT       12
     140                 :            : #define TCE_PSIZE       (1ul << 12)
     141                 :            : #define TCE_MASK        (TCE_PSIZE - 1)
     142                 :            : 
     143                 :            : /* Not the greatest variants but will do for now ... */
     144                 :            : #define MIN(a, b)       ((a) < (b) ? (a) : (b))
     145                 :            : #define MAX(a, b)       ((a) > (b) ? (a) : (b))
     146                 :            : 
     147                 :            : /* PCI Geographical Addressing */
     148                 :            : #define PCI_BUS_NUM(bdfn)       (((bdfn) >> 8) & 0xff)
     149                 :            : #define PCI_DEV(bdfn)           (((bdfn) >> 3) & 0x1f)
     150                 :            : #define PCI_FUNC(bdfn)          ((bdfn) & 0x07)
     151                 :            : 
     152                 :            : /*
     153                 :            :  * To help the FSP to distinguish between physical address and TCE mapped address.
     154                 :            :  * Also to help hostboot to distinguish physical and relative address.
     155                 :            :  */
     156                 :            : #define HRMOR_BIT (1ul << 63)
     157                 :            : 
     158                 :            : /* Clean the stray high bit which the FSP inserts: we only have 52 bits real */
     159                 :         53 : static inline u64 cleanup_addr(u64 addr)
     160                 :            : {
     161                 :         53 :         return addr & ((1ULL << 52) - 1);
     162                 :            : }
     163                 :            : 
     164                 :            : /* Start the kernel */
     165                 :            : extern void start_kernel(uint64_t entry, void* fdt,
     166                 :            :                          uint64_t mem_top) __noreturn;
     167                 :            : extern void start_kernel32(uint64_t entry, void* fdt,
     168                 :            :                            uint64_t mem_top) __noreturn;
     169                 :            : extern void start_kernel_secondary(uint64_t entry) __noreturn;
     170                 :            : 
     171                 :            : /* Re-set r16 register with CPU pointer, based on stack (r1) value */
     172                 :            : extern void restore_cpu_ptr_r16(void);
     173                 :            : /* Set r16 register with value in 'r16' parameter */
     174                 :            : extern void set_cpu_ptr_r16(uint64_t r16);
     175                 :            : 
     176                 :            : /* Get description of machine from HDAT and create device-tree */
     177                 :            : extern int parse_hdat(bool is_opal);
     178                 :            : 
     179                 :            : struct dt_node;
     180                 :            : 
     181                 :            : /* Add /cpus/features node for boot environment that passes an fdt */
     182                 :            : extern void dt_add_cpufeatures(struct dt_node *root);
     183                 :            : 
     184                 :            : /* Root of device tree. */
     185                 :            : extern struct dt_node *dt_root;
     186                 :            : 
     187                 :            : /* Full skiboot version number (possibly includes gitid). */
     188                 :            : extern const char version[];
     189                 :            : 
     190                 :            : /* Debug support */
     191                 :            : extern char __sym_map_start[];
     192                 :            : extern char __sym_map_end[];
     193                 :            : extern size_t snprintf_symbol(char *buf, size_t len, uint64_t addr);
     194                 :            : 
     195                 :            : /* Direct controls */
     196                 :            : extern void direct_controls_init(void);
     197                 :            : extern int64_t opal_signal_system_reset(int cpu_nr);
     198                 :            : 
     199                 :            : /* Fast reboot support */
     200                 :            : extern void disable_fast_reboot(const char *reason);
     201                 :            : extern void add_fast_reboot_dt_entries(void);
     202                 :            : extern void fast_reboot(void);
     203                 :            : extern void __noreturn __secondary_cpu_entry(void);
     204                 :            : extern void __noreturn load_and_boot_kernel(bool is_reboot);
     205                 :            : extern void cleanup_local_tlb(void);
     206                 :            : extern void cleanup_global_tlb(void);
     207                 :            : extern void init_shared_sprs(void);
     208                 :            : extern void init_replicated_sprs(void);
     209                 :            : extern bool start_preload_kernel(void);
     210                 :            : extern void copy_exception_vectors(void);
     211                 :            : extern void copy_sreset_vector(void);
     212                 :            : extern void copy_sreset_vector_fast_reboot(void);
     213                 :            : extern void patch_traps(bool enable);
     214                 :            : 
     215                 :            : /* Various probe routines, to replace with an initcall system */
     216                 :            : extern int preload_capp_ucode(void);
     217                 :            : extern void preload_io_vpd(void);
     218                 :            : extern void uart_init(void);
     219                 :            : extern void mbox_init(void);
     220                 :            : extern void early_uart_init(void);
     221                 :            : extern void homer_init(void);
     222                 :            : extern void add_cpu_idle_state_properties(void);
     223                 :            : extern void lpc_rtc_init(void);
     224                 :            : 
     225                 :            : /* flash support */
     226                 :            : struct flash_chip;
     227                 :            : extern int flash_register(struct blocklevel_device *bl);
     228                 :            : extern int flash_start_preload_resource(enum resource_id id, uint32_t subid,
     229                 :            :                                         void *buf, size_t *len);
     230                 :            : extern int flash_resource_loaded(enum resource_id id, uint32_t idx);
     231                 :            : extern bool flash_reserve(void);
     232                 :            : extern void flash_release(void);
     233                 :            : extern bool flash_unregister(void);
     234                 :            : #define FLASH_SUBPART_ALIGNMENT 0x1000
     235                 :            : #define FLASH_SUBPART_HEADER_SIZE FLASH_SUBPART_ALIGNMENT
     236                 :            : extern int flash_subpart_info(void *part_header, uint32_t header_len,
     237                 :            :                               uint32_t part_size, uint32_t *part_actual,
     238                 :            :                               uint32_t subid, uint32_t *offset,
     239                 :            :                               uint32_t *size);
     240                 :            : extern void flash_fw_version_preload(void);
     241                 :            : extern void flash_dt_add_fw_version(void);
     242                 :            : extern const char *flash_map_resource_name(enum resource_id id);
     243                 :            : extern int flash_secboot_info(uint32_t *total_size);
     244                 :            : extern int flash_secboot_read(void *dst, uint32_t src, uint32_t len);
     245                 :            : extern int flash_secboot_write(uint32_t dst, void *src, uint32_t len);
     246                 :            : 
     247                 :            : /*
     248                 :            :  * Decompression routines
     249                 :            :  *
     250                 :            :  * The below structure members are needed for the xz library routines,
     251                 :            :  *   src: Source address (The compressed binary)
     252                 :            :  *   src_size: Source size
     253                 :            :  *   dst: Destination address (The memory area where the `src` will be
     254                 :            :  *        decompressed)
     255                 :            :  *   dst_size: Destination size
     256                 :            :  */
     257                 :            : struct xz_decompress {
     258                 :            :         void *dst;
     259                 :            :         void *src;
     260                 :            :         size_t dst_size;
     261                 :            :         size_t src_size;
     262                 :            :         /* The status of the decompress process:
     263                 :            :              - OPAL_PARTIAL: if the job is in progress
     264                 :            :              - OPAL_SUCCESS: if the job is successful
     265                 :            :              - OPAL_NO_MEM: memory allocation failure
     266                 :            :              - OPAL_PARAMETER: If any of the above (src, dst..) are invalid or
     267                 :            :              if xz decompress fails. In which case the caller should check the
     268                 :            :              xz_error for failure reason.
     269                 :            :          */
     270                 :            :         int status;
     271                 :            :         int xz_error;
     272                 :            :         /* The decompression job, this will be freed if the caller uses
     273                 :            :          * `wait_xz_decompression` function, in any other case its the
     274                 :            :          * responsibility of caller to free the allocation job.  */
     275                 :            :         struct cpu_job *job;
     276                 :            : };
     277                 :            : 
     278                 :            : extern void xz_start_decompress(struct xz_decompress *);
     279                 :            : extern void wait_xz_decompress(struct xz_decompress *);
     280                 :            : 
     281                 :            : /* NVRAM support */
     282                 :            : extern void nvram_init(void);
     283                 :            : extern void nvram_read_complete(bool success);
     284                 :            : 
     285                 :            : /* UART stuff */
     286                 :            : enum {
     287                 :            :         UART_CONSOLE_OPAL,
     288                 :            :         UART_CONSOLE_OS
     289                 :            : };
     290                 :            : extern void uart_set_console_policy(int policy);
     291                 :            : extern bool uart_enabled(void);
     292                 :            : 
     293                 :            : /* PRD */
     294                 :            : extern void prd_psi_interrupt(uint32_t proc);
     295                 :            : extern void prd_tmgt_interrupt(uint32_t proc);
     296                 :            : extern void prd_occ_reset(uint32_t proc);
     297                 :            : extern void prd_sbe_passthrough(uint32_t proc);
     298                 :            : extern void prd_init(void);
     299                 :            : extern void prd_register_reserved_memory(void);
     300                 :            : extern void prd_fsp_occ_reset(uint32_t proc);
     301                 :            : extern void prd_fsp_occ_load_start(u32 proc);
     302                 :            : extern void prd_fw_resp_fsp_response(int status);
     303                 :            : extern int  prd_hbrt_fsp_msg_notify(void *data, u32 dsize);
     304                 :            : 
     305                 :            : /* Flatten device-tree */
     306                 :            : extern void *create_dtb(const struct dt_node *root, bool exclusive);
     307                 :            : 
     308                 :            : extern void nx_p9_rng_late_init(void);
     309                 :            : 
     310                 :            : extern void fast_sleep_exit(void);
     311                 :            : 
     312                 :            : /* Fallback fake RTC */
     313                 :            : extern void fake_rtc_init(void);
     314                 :            : 
     315                 :            : /* Exceptions */
     316                 :            : struct stack_frame;
     317                 :            : extern void exception_entry(struct stack_frame *stack);
     318                 :            : extern void exception_entry_pm_sreset(void);
     319                 :            : extern void __noreturn exception_entry_pm_mce(void);
     320                 :            : 
     321                 :            : /* Assembly in head.S */
     322                 :            : extern void disable_machine_check(void);
     323                 :            : extern void enable_machine_check(void);
     324                 :            : extern unsigned int enter_p8_pm_state(bool winkle);
     325                 :            : extern unsigned int enter_p9_pm_state(uint64_t psscr);
     326                 :            : extern void enter_p9_pm_lite_state(uint64_t psscr);
     327                 :            : extern uint32_t reset_patch_start;
     328                 :            : extern uint32_t reset_patch_end;
     329                 :            : extern uint32_t reset_fast_reboot_patch_start;
     330                 :            : extern uint32_t reset_fast_reboot_patch_end;
     331                 :            : 
     332                 :            : /* Fallback fake NVRAM */
     333                 :            : extern int fake_nvram_info(uint32_t *total_size);
     334                 :            : extern int fake_nvram_start_read(void *dst, uint32_t src, uint32_t len);
     335                 :            : extern int fake_nvram_write(uint32_t offset, void *src, uint32_t size);
     336                 :            : 
     337                 :            : /*
     338                 :            :  * A bunch of hardware needs to be probed, sometimes in a particular order.
     339                 :            :  * Very simple dependency graph, with a even simpler way to resolve it.
     340                 :            :  * But it means we can now at link time choose what hardware we support.
     341                 :            :  * This struct should not be defined directly but with the macros.
     342                 :            :  */
     343                 :            : struct hwprobe {
     344                 :            :         const char      *name;
     345                 :            :         void            (*probe)(void);
     346                 :            : 
     347                 :            :         bool            probed;
     348                 :            : 
     349                 :            :         /* NULL or NULL-terminated array of strings */
     350                 :            :         const char      **deps;
     351                 :            : };
     352                 :            : 
     353                 :            : #define DEFINE_HWPROBE(__name, __probe)         \
     354                 :            : static const struct hwprobe __used __section(".hwprobes") hwprobe_##__name = { \
     355                 :            :         .name = #__name,                                \
     356                 :            :         .probe = __probe,                               \
     357                 :            :         .deps = NULL,                                   \
     358                 :            : }
     359                 :            : 
     360                 :            : #define DEFINE_HWPROBE_DEPS(__name, __probe, ...)       \
     361                 :            : static const struct hwprobe __used __section(".hwprobes") hwprobe_##__name = { \
     362                 :            :         .name = #__name,                                \
     363                 :            :         .probe = __probe,                               \
     364                 :            :         .deps = (const char *[]){ __VA_ARGS__, NULL},   \
     365                 :            : }
     366                 :            : 
     367                 :            : extern struct hwprobe __hwprobes_start;
     368                 :            : extern struct hwprobe __hwprobes_end;
     369                 :            : 
     370                 :            : extern void probe_hardware(void);
     371                 :            : 
     372                 :            : #endif /* __SKIBOOT_H */

Generated by: LCOV version 1.14