diff options
author | Tom Rini | 2019-12-02 22:05:35 -0500 |
---|---|---|
committer | Tom Rini | 2019-12-02 22:05:35 -0500 |
commit | a4ef0657e3075d0f951d78cc1398cb7e05af648a (patch) | |
tree | 9a4387de5845e6fd1331f0af32bfd82fac9eb039 /include | |
parent | 357040645f9f56b33909520483df9f840be7e181 (diff) | |
parent | cb3ef6810a27c8ddf5db8694bcef9337f27d12ce (diff) |
Merge branch '2019-12-02-master-imports'
- A large series of clean-ups to reduce common.h contents
Diffstat (limited to 'include')
-rw-r--r-- | include/bootcount.h | 14 | ||||
-rw-r--r-- | include/command.h | 16 | ||||
-rw-r--r-- | include/common.h | 212 | ||||
-rw-r--r-- | include/cpu_func.h | 87 | ||||
-rw-r--r-- | include/eeprom.h | 24 | ||||
-rw-r--r-- | include/exports.h | 4 | ||||
-rw-r--r-- | include/init.h | 33 | ||||
-rw-r--r-- | include/irq_func.h | 26 | ||||
-rw-r--r-- | include/linux/crc8.h | 23 | ||||
-rw-r--r-- | include/linux/mii.h | 2 | ||||
-rw-r--r-- | include/lz4.h | 24 | ||||
-rw-r--r-- | include/net.h | 22 | ||||
-rw-r--r-- | include/rand.h | 40 | ||||
-rw-r--r-- | include/serial.h | 37 | ||||
-rw-r--r-- | include/sort.h | 34 | ||||
-rw-r--r-- | include/status_led.h | 4 | ||||
-rw-r--r-- | include/time.h | 43 | ||||
-rw-r--r-- | include/u-boot/crc.h | 89 | ||||
-rw-r--r-- | include/vsprintf.h | 10 |
19 files changed, 486 insertions, 258 deletions
diff --git a/include/bootcount.h b/include/bootcount.h index 8fa8cf82181..cd304039849 100644 --- a/include/bootcount.h +++ b/include/bootcount.h @@ -59,6 +59,16 @@ int dm_bootcount_set(struct udevice *dev, u32 bootcount); #endif +/** bootcount_store() - store the current bootcount */ +void bootcount_store(ulong); + +/** + * bootcount_load() - load the current bootcount + * + * @return bootcount, read from the appropriate location + */ +ulong bootcount_load(void); + #if defined(CONFIG_SPL_BOOTCOUNT_LIMIT) || defined(CONFIG_BOOTCOUNT_LIMIT) #if !defined(CONFIG_SYS_BOOTCOUNT_LE) && !defined(CONFIG_SYS_BOOTCOUNT_BE) @@ -127,10 +137,6 @@ static inline void bootcount_inc(void) #endif /* !CONFIG_SPL_BUILD */ } -#if defined(CONFIG_SPL_BUILD) && !defined(CONFIG_SPL_BOOTCOUNT_LIMIT) -void bootcount_store(ulong a) {}; -ulong bootcount_load(void) { return 0; } -#endif /* CONFIG_SPL_BUILD && !CONFIG_SPL_BOOTCOUNT_LIMIT */ #else static inline int bootcount_error(void) { return 0; } static inline void bootcount_inc(void) {} diff --git a/include/command.h b/include/command.h index f6170e71515..d1063774ce5 100644 --- a/include/command.h +++ b/include/command.h @@ -199,6 +199,22 @@ void fixup_cmdtable(cmd_tbl_t *cmdtp, int size); * @return 0 if OK, 1 for error */ int board_run_command(const char *cmdline); + +int run_command(const char *cmd, int flag); +int run_command_repeatable(const char *cmd, int flag); + +/** + * Run a list of commands separated by ; or even \0 + * + * Note that if 'len' is not -1, then the command does not need to be nul + * terminated, Memory will be allocated for the command in that case. + * + * @param cmd List of commands to run, each separated bu semicolon + * @param len Length of commands excluding terminator if known (-1 if not) + * @param flag Execution flags (CMD_FLAG_...) + * @return 0 on success, or != 0 on error. + */ +int run_command_list(const char *cmd, int len, int flag); #endif /* __ASSEMBLY__ */ /* diff --git a/include/common.h b/include/common.h index d8f302ea92f..8b37b587474 100644 --- a/include/common.h +++ b/include/common.h @@ -3,8 +3,8 @@ * Common header file for U-Boot * * This file still includes quite a bit of stuff that should be in separate - * headers like command.h, cpu.h and timer.h. Please think before adding more - * things. Patches to remove things are welcome. + * headers. Please think before adding more things. + * Patches to remove things are welcome. * * (C) Copyright 2000-2009 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. @@ -46,8 +46,6 @@ typedef volatile unsigned char vu_char; #include <log.h> -typedef void (interrupt_handler_t)(void *); - #include <asm/u-boot.h> /* boot information for Linux kernel */ #include <asm/global_data.h> /* global data used for startup functions */ @@ -64,27 +62,10 @@ typedef void (interrupt_handler_t)(void *); */ void hang (void) __attribute__ ((noreturn)); -int cpu_init(void); - #include <display_options.h> /* common/main.c */ void main_loop (void); -int run_command(const char *cmd, int flag); -int run_command_repeatable(const char *cmd, int flag); - -/** - * Run a list of commands separated by ; or even \0 - * - * Note that if 'len' is not -1, then the command does not need to be nul - * terminated, Memory will be allocated for the command in that case. - * - * @param cmd List of commands to run, each separated bu semicolon - * @param len Length of commands excluding terminator if known (-1 if not) - * @param flag Execution flags (CMD_FLAG_...) - * @return 0 on success, or != 0 on error. - */ -int run_command_list(const char *cmd, int len, int flag); int checkflash(void); int checkdram(void); @@ -93,26 +74,6 @@ extern u8 __dtb_dt_spl_begin[]; /* embedded device tree blob for SPL/TPL */ int mdm_init(void); /** - * Show the DRAM size in a board-specific way - * - * This is used by boards to display DRAM information in their own way. - * - * @param size Size of DRAM (which should be displayed along with other info) - */ -void board_show_dram(phys_size_t size); - -/** - * Get the uppermost pointer that is valid to access - * - * Some systems may not map all of their address space. This function allows - * boards to indicate what their highest support pointer value is for DRAM - * access. - * - * @param total_size Size of U-Boot (unused?) - */ -ulong board_get_usable_ram_top(ulong total_size); - -/** * arch_fixup_fdt() - Write arch-specific information to fdt * * Defined in arch/$(ARCH)/lib/bootm-fdt.c @@ -141,8 +102,6 @@ int do_fat_fsload(cmd_tbl_t *, int, int, char * const []); /* common/cmd_ext2.c */ int do_ext2load(cmd_tbl_t *, int, int, char * const []); -void pci_init_board(void); - /* common/exports.c */ void jumptable_init(void); @@ -157,77 +116,22 @@ phys_size_t get_effective_memsize(void); void reset_phy (void); void fdc_hw_init (void); -/* $(BOARD)/eeprom.c */ -#ifdef CONFIG_CMD_EEPROM -void eeprom_init (int bus); -int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt); -int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt); -#else -/* - * Some EEPROM code is depecated because it used the legacy I2C interface. Add - * some macros here so we don't have to touch every one of those uses - */ -#define eeprom_init(bus) -#define eeprom_read(dev_addr, offset, buffer, cnt) ((void)-ENOSYS) -#define eeprom_write(dev_addr, offset, buffer, cnt) ((void)-ENOSYS) -#endif - #if !defined(CONFIG_ENV_EEPROM_IS_ON_I2C) && defined(CONFIG_SYS_I2C_EEPROM_ADDR) # define CONFIG_SYS_DEF_EEPROM_ADDR CONFIG_SYS_I2C_EEPROM_ADDR #endif -/* $(BOARD)/$(BOARD).c */ -int board_early_init_f (void); -int board_fix_fdt (void *rw_fdt_blob); /* manipulate the U-Boot fdt before its relocation */ -int board_late_init (void); -int board_postclk_init (void); /* after clocks/timebase, before env/serial */ -int board_early_init_r (void); - #if defined(CONFIG_SYS_DRAM_TEST) int testdram(void); #endif /* CONFIG_SYS_DRAM_TEST */ -/* $(CPU)/start.S */ -int icache_status (void); -void icache_enable (void); -void icache_disable(void); -int dcache_status (void); -void dcache_enable (void); -void dcache_disable(void); -void mmu_disable(void); #if defined(CONFIG_ARM) void relocate_code(ulong); #else void relocate_code(ulong, gd_t *, ulong) __attribute__ ((noreturn)); #endif -ulong get_endaddr (void); -void trap_init (ulong); - -/* $(CPU)/cpu.c */ -static inline int cpumask_next(int cpu, unsigned int mask) -{ - for (cpu++; !((1 << cpu) & mask); cpu++) - ; - - return cpu; -} - -#define for_each_cpu(iter, cpu, num_cpus, mask) \ - for (iter = 0, cpu = cpumask_next(-1, mask); \ - iter < num_cpus; \ - iter++, cpu = cpumask_next(cpu, mask)) \ - -int cpu_numcores (void); -int cpu_num_dspcores(void); -u32 cpu_mask (void); -u32 cpu_dsp_mask(void); -int is_core_valid (unsigned int); void s_init(void); -int checkcpu (void); -int checkicache (void); -int checkdcache (void); void upmconfig (unsigned int, unsigned int *, unsigned int); ulong get_tbclk (void); void reset_misc (void); @@ -235,134 +139,22 @@ void reset_cpu (ulong addr); void ft_cpu_setup(void *blob, bd_t *bd); void ft_pci_setup(void *blob, bd_t *bd); -void smp_set_core_boot_addr(unsigned long addr, int corenr); -void smp_kick_all_cpus(void); - -/* $(CPU)/serial.c */ -int serial_init (void); -void serial_setbrg (void); -void serial_putc (const char); -void serial_putc_raw(const char); -void serial_puts (const char *); -int serial_getc (void); -int serial_tstc (void); - /* $(CPU)/speed.c */ int get_clocks (void); ulong get_bus_freq (ulong); int get_serial_clock(void); -/* $(CPU)/interrupts.c */ -int interrupt_init (void); -void timer_interrupt (struct pt_regs *); -void external_interrupt (struct pt_regs *); -void irq_install_handler(int, interrupt_handler_t *, void *); -void irq_free_handler (int); -void reset_timer (void); - -/* Return value of monotonic microsecond timer */ -unsigned long timer_get_us(void); - -void enable_interrupts (void); -int disable_interrupts (void); - -/* $(CPU)/.../commproc.c */ -void bootcount_store (ulong); -ulong bootcount_load (void); - -/* $(CPU)/.../<eth> */ -void mii_init (void); - -/* arch/$(ARCH)/lib/cache.c */ -void enable_caches(void); -void flush_cache (unsigned long, unsigned long); -void flush_dcache_all(void); -void flush_dcache_range(unsigned long start, unsigned long stop); -void invalidate_dcache_range(unsigned long start, unsigned long stop); -void invalidate_dcache_all(void); -void invalidate_icache_all(void); - -enum { - /* Disable caches (else flush caches but leave them active) */ - CBL_DISABLE_CACHES = 1 << 0, - CBL_SHOW_BOOTSTAGE_REPORT = 1 << 1, - - CBL_ALL = 3, -}; - -/** - * Clean up ready for linux - * - * @param flags Flags to control what is done - */ -int cleanup_before_linux_select(int flags); - -/* arch/$(ARCH)/lib/ticks.S */ -uint64_t get_ticks(void); -void wait_ticks (unsigned long); - -/* arch/$(ARCH)/lib/time.c */ -ulong usec2ticks (unsigned long usec); -ulong ticks2usec (unsigned long ticks); - -/* lib/lz4_wrapper.c */ -int ulz4fn(const void *src, size_t srcn, void *dst, size_t *dstn); - -/* lib/qsort.c */ -void qsort(void *base, size_t nmemb, size_t size, - int(*compar)(const void *, const void *)); -int strcmp_compar(const void *, const void *); - /* lib/uuid.c */ #include <uuid.h> /* lib/vsprintf.c */ #include <vsprintf.h> -/* lib/strmhz.c */ -char * strmhz(char *buf, unsigned long hz); - -/* lib/crc32.c */ -#include <u-boot/crc.h> - -/* lib/rand.c */ -#define RAND_MAX -1U -void srand(unsigned int seed); -unsigned int rand(void); -unsigned int rand_r(unsigned int *seedp); - -/* - * STDIO based functions (can always be used) - */ -/* serial stuff */ -int serial_printf (const char *fmt, ...) - __attribute__ ((format (__printf__, 1, 2))); - /* lib/net_utils.c */ #include <net.h> -static inline struct in_addr env_get_ip(char *var) -{ - return string_to_ip(env_get(var)); -} - -#ifdef CONFIG_LED_STATUS -# include <status_led.h> -#endif #include <bootstage.h> -#ifdef CONFIG_SHOW_ACTIVITY -void show_activity(int arg); -#endif - -/* Multicore arch functions */ -#ifdef CONFIG_MP -int cpu_status(u32 nr); -int cpu_reset(u32 nr); -int cpu_disable(u32 nr); -int cpu_release(u32 nr, int argc, char * const argv[]); -#endif - #else /* __ASSEMBLY__ */ #endif /* __ASSEMBLY__ */ diff --git a/include/cpu_func.h b/include/cpu_func.h new file mode 100644 index 00000000000..46f3d92459b --- /dev/null +++ b/include/cpu_func.h @@ -0,0 +1,87 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * (C) Copyright 2000-2009 + * Wolfgang Denk, DENX Software Engineering, wd@denx.de. + * Copyright 2019 Google LLC + */ + +#ifndef __CPU_LEGACY_H +#define __CPU_LEGACY_H + +#include <linux/types.h> + +/* + * Multicore arch functions + * + * These should be moved to use the CPU uclass. + */ +int cpu_status(u32 nr); +int cpu_reset(u32 nr); +int cpu_disable(u32 nr); +int cpu_release(u32 nr, int argc, char * const argv[]); + +static inline int cpumask_next(int cpu, unsigned int mask) +{ + for (cpu++; !((1 << cpu) & mask); cpu++) + ; + + return cpu; +} + +#define for_each_cpu(iter, cpu, num_cpus, mask) \ + for (iter = 0, cpu = cpumask_next(-1, mask); \ + iter < num_cpus; \ + iter++, cpu = cpumask_next(cpu, mask)) \ + +int cpu_numcores(void); +int cpu_num_dspcores(void); +u32 cpu_mask(void); +u32 cpu_dsp_mask(void); +int is_core_valid(unsigned int core); + +/** + * checkcpu() - perform an early check of the CPU + * + * This is used on PowerPC, SH and X86 machines as a CPU init mechanism. It is + * called during the pre-relocation init sequence in board_init_f(). + * + * @return 0 if oK, -ve on error + */ +int checkcpu(void); + +void smp_set_core_boot_addr(unsigned long addr, int corenr); +void smp_kick_all_cpus(void); + +int icache_status(void); +void icache_enable(void); +void icache_disable(void); +int dcache_status(void); +void dcache_enable(void); +void dcache_disable(void); +void mmu_disable(void); + +/* arch/$(ARCH)/lib/cache.c */ +void enable_caches(void); +void flush_cache(unsigned long addr, unsigned long size); +void flush_dcache_all(void); +void flush_dcache_range(unsigned long start, unsigned long stop); +void invalidate_dcache_range(unsigned long start, unsigned long stop); +void invalidate_dcache_all(void); +void invalidate_icache_all(void); + +enum { + /* Disable caches (else flush caches but leave them active) */ + CBL_DISABLE_CACHES = 1 << 0, + CBL_SHOW_BOOTSTAGE_REPORT = 1 << 1, + + CBL_ALL = 3, +}; + +/** + * Clean up ready for linux + * + * @param flags Flags to control what is done + */ +int cleanup_before_linux_select(int flags); +; +#endif diff --git a/include/eeprom.h b/include/eeprom.h new file mode 100644 index 00000000000..61eb826a734 --- /dev/null +++ b/include/eeprom.h @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * (C) Copyright 2000-2009 + * Wolfgang Denk, DENX Software Engineering, wd@denx.de. + */ + +#ifndef __EEPROM_LEGACY_H +#define __EEPROM_LEGACY_H + +#ifdef CONFIG_CMD_EEPROM +void eeprom_init(int bus); +int eeprom_read(uint dev_addr, uint offset, uchar *buffer, uint cnt); +int eeprom_write(uint dev_addr, uint offset, uchar *buffer, uint cnt); +#else +/* + * Some EEPROM code is depecated because it used the legacy I2C interface. Add + * some macros here so we don't have to touch every one of those uses + */ +#define eeprom_init(bus) +#define eeprom_read(dev_addr, offset, buffer, cnt) ((void)-ENOSYS) +#define eeprom_write(dev_addr, offset, buffer, cnt) ((void)-ENOSYS) +#endif + +#endif diff --git a/include/exports.h b/include/exports.h index 147a00f860b..35f463287fb 100644 --- a/include/exports.h +++ b/include/exports.h @@ -1,12 +1,16 @@ #ifndef __EXPORTS_H__ #define __EXPORTS_H__ +#include <irq_func.h> + #ifndef __ASSEMBLY__ #ifdef CONFIG_PHY_AQUANTIA #include <env.h> #include <phy_interface.h> #endif +#include <irq_func.h> + struct spi_slave; /* These are declarations of exported functions available in C code */ diff --git a/include/init.h b/include/init.h index afc953d51e2..8b65b2afe42 100644 --- a/include/init.h +++ b/include/init.h @@ -10,6 +10,8 @@ #ifndef __INIT_H_ #define __INIT_H_ 1 +#include <linux/types.h> + #ifndef __ASSEMBLY__ /* put C only stuff in this section */ /* @@ -149,6 +151,8 @@ ulong board_init_f_alloc_reserve(ulong top); */ void board_init_f_init_reserve(ulong base); +struct global_data; + /** * arch_setup_gd() - Set up the global_data pointer * @gd_ptr: Pointer to global data @@ -160,10 +164,11 @@ void board_init_f_init_reserve(ulong base); * * gd = gd_ptr; */ -void arch_setup_gd(gd_t *gd_ptr); +void arch_setup_gd(struct global_data *gd_ptr); /* common/board_r.c */ -void board_init_r(gd_t *id, ulong dest_addr) __attribute__ ((noreturn)); +void board_init_r(struct global_data *id, ulong dest_addr) + __attribute__ ((noreturn)); int cpu_init_r(void); int last_stage_init(void); @@ -181,6 +186,30 @@ int init_func_vid(void); int checkboard(void); int show_board_info(void); +/** + * Get the uppermost pointer that is valid to access + * + * Some systems may not map all of their address space. This function allows + * boards to indicate what their highest support pointer value is for DRAM + * access. + * + * @param total_size Size of U-Boot (unused?) + */ +ulong board_get_usable_ram_top(ulong total_size); + +int board_early_init_f(void); + +/* manipulate the U-Boot fdt before its relocation */ +int board_fix_fdt(void *rw_fdt_blob); +int board_late_init(void); +int board_postclk_init(void); /* after clocks/timebase, before env/serial */ +int board_early_init_r(void); + +/* TODO(sjg@chromium.org): Drop this when DM_PCI migration is completed */ +void pci_init_board(void); + +void trap_init(unsigned long reloc_addr); + #endif /* __ASSEMBLY__ */ /* Put only stuff here that the assembler can digest */ diff --git a/include/irq_func.h b/include/irq_func.h new file mode 100644 index 00000000000..c7c4babbfc9 --- /dev/null +++ b/include/irq_func.h @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Header file for interrupt functions + * + * (C) Copyright 2000-2009 + * Wolfgang Denk, DENX Software Engineering, wd@denx.de. + */ + +#ifndef __IRQ_FUNC_H +#define __IRQ_FUNC_H + +struct pt_regs; + +typedef void (interrupt_handler_t)(void *arg); + +int interrupt_init(void); +void timer_interrupt(struct pt_regs *regs); +void external_interrupt(struct pt_regs *regs); +void irq_install_handler(int vec, interrupt_handler_t *handler, void *arg); +void irq_free_handler(int vec); +void reset_timer(void); + +void enable_interrupts(void); +int disable_interrupts(void); + +#endif diff --git a/include/linux/crc8.h b/include/linux/crc8.h deleted file mode 100644 index 0ab5b9ab219..00000000000 --- a/include/linux/crc8.h +++ /dev/null @@ -1,23 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -/* - * Copyright (c) 2013 Google, Inc - */ - - -#ifndef __linux_crc8_h -#define __linux_crc8_h - -/** - * crc8() - Calculate and return CRC-8 of the data - * - * This uses an x^8 + x^2 + x + 1 polynomial. A table-based algorithm would - * be faster, but for only a few bytes it isn't worth the code size - * - * @crc_start: CRC8 start value - * @vptr: Buffer to checksum - * @len: Length of buffer in bytes - * @return CRC8 checksum - */ -unsigned int crc8(unsigned int crc_start, const unsigned char *vptr, int len); - -#endif diff --git a/include/linux/mii.h b/include/linux/mii.h index 21db032340e..49e29ac314a 100644 --- a/include/linux/mii.h +++ b/include/linux/mii.h @@ -225,4 +225,6 @@ static inline u8 mii_resolve_flowctrl_fdx(u16 lcladv, u16 rmtadv) return cap; } +void mii_init(void); + #endif /* __LINUX_MII_H__ */ diff --git a/include/lz4.h b/include/lz4.h new file mode 100644 index 00000000000..1276fb98a34 --- /dev/null +++ b/include/lz4.h @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright 2019 Google LLC + */ + +#ifndef __LZ4_H +#define __LZ4_H + +/** + * ulz4fn() - Decompress LZ4 data + * + * @src: Source data to decompress + * @srcn: Length of source data + * @dst: Destination for uncompressed data + * @dstn: Returns length of uncompressed data + * @return 0 if OK, -EPROTONOSUPPORT if the magic number or version number are + * not recognised or independent blocks are used, -EINVAL if the reserved + * fields are non-zero, or input is overrun, -EENOBUFS if the destination + * buffer is overrun, -EEPROTO if the compressed data causes an error in + * the decompression algorithm + */ +int ulz4fn(const void *src, size_t srcn, void *dst, size_t *dstn); + +#endif diff --git a/include/net.h b/include/net.h index 75a16e4c8f8..11eca1bc6c3 100644 --- a/include/net.h +++ b/include/net.h @@ -16,6 +16,7 @@ #include <asm/byteorder.h> /* for nton* / ntoh* stuff */ #include <env.h> #include <linux/if_ether.h> +#include <rand.h> #define DEBUG_LL_STATE 0 /* Link local state machine changes */ #define DEBUG_DEV_PKT 0 /* Packets or info directed to the device */ @@ -828,7 +829,13 @@ static inline void net_random_ethaddr(uchar *addr) /* Convert an IP address to a string */ void ip_to_string(struct in_addr x, char *s); -/* Convert a string to ip address */ +/** + * string_to_ip() - Convert a string to ip address + * + * @s: String to conver, in the format format a.b.c.d, where each value is a + * decimal number from 0 to 255 + * @return IP address, or 0 if invalid + */ struct in_addr string_to_ip(const char *s); /* Convert a VLAN id to a string */ @@ -886,4 +893,17 @@ int update_tftp(ulong addr, char *interface, char *devstring); */ void eth_parse_enetaddr(const char *addr, uint8_t *enetaddr); +/** + * env_get_ip() - Convert an environment value to to an ip address + * + * @var: Environment variable to convert. The value of this variable must be + * in the format format a.b.c.d, where each value is a decimal number from + * 0 to 255 + * @return IP address, or 0 if invalid + */ +static inline struct in_addr env_get_ip(char *var) +{ + return string_to_ip(env_get(var)); +} + #endif /* __NET_H__ */ diff --git a/include/rand.h b/include/rand.h new file mode 100644 index 00000000000..c9d15f50a13 --- /dev/null +++ b/include/rand.h @@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * (C) Copyright 2000-2009 + * Wolfgang Denk, DENX Software Engineering, wd@denx.de. + */ + +#ifndef __RAND_H +#define __RAND_H + +#define RAND_MAX -1U + +/** + * srand() - Set the random-number seed value + * + * This can be used to restart the pseudo-random-number sequence from a known + * point. This affects future calls to rand() to start from that point + * + * @seed: New seed + */ +void srand(unsigned int seed); + +/** + * rand() - Get a 32-bit pseudo-random number + * + * @returns next random number in the sequence + */ +unsigned int rand(void); + +/** + * rand_r() - Get a 32-bit pseudo-random number + * + * This version of the function allows multiple sequences to be used at the + * same time, since it requires the caller to store the seed value. + * + * @seed value to use, updated on exit + * @returns next random number in the sequence + */ +unsigned int rand_r(unsigned int *seedp); + +#endif diff --git a/include/serial.h b/include/serial.h index c1368c68b64..104f34ff914 100644 --- a/include/serial.h +++ b/include/serial.h @@ -50,18 +50,20 @@ extern void serial_reinit_all(void); /* For usbtty */ #ifdef CONFIG_USB_TTY -extern int usbtty_getc(void); -extern void usbtty_putc(const char c); -extern void usbtty_puts(const char *str); -extern int usbtty_tstc(void); +struct stdio_dev; + +int usbtty_getc(struct stdio_dev *dev); +void usbtty_putc(struct stdio_dev *dev, const char c); +void usbtty_puts(struct stdio_dev *dev, const char *str); +int usbtty_tstc(struct stdio_dev *dev); #else /* stubs */ -#define usbtty_getc() 0 -#define usbtty_putc(a) -#define usbtty_puts(a) -#define usbtty_tstc() 0 +#define usbtty_getc(dev) 0 +#define usbtty_putc(dev, a) +#define usbtty_puts(dev, a) +#define usbtty_tstc(dev) 0 #endif /* CONFIG_USB_TTY */ @@ -322,4 +324,23 @@ void pl01x_serial_initialize(void); void pxa_serial_initialize(void); void sh_serial_initialize(void); +/** + * serial_printf() - Write a formatted string to the serial console + * + * The total size of the output must be less than CONFIG_SYS_PBSIZE. + * + * @fmt: Printf format string, followed by format arguments + * @return number of characters written + */ +int serial_printf(const char *fmt, ...) + __attribute__ ((format (__printf__, 1, 2))); + +int serial_init(void); +void serial_setbrg(void); +void serial_putc(const char ch); +void serial_putc_raw(const char ch); +void serial_puts(const char *str); +int serial_getc(void); +int serial_tstc(void); + #endif diff --git a/include/sort.h b/include/sort.h new file mode 100644 index 00000000000..0c6b588fcb0 --- /dev/null +++ b/include/sort.h @@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright 2019 Google LLC + */ + +#ifndef __SORT_H +#define __SORT_H + +/** + * qsort() - Use the quicksort algorithm to sort some values + * + * @base: Base address of array to sort + * @nmemb: Number of members to sort + * @size: Size of each member in bytes + * @compar: Comparison function which should return: + * < 0 if element at s1 < element at s2, + * 0 if element at s1 == element at s2, + * > 0 if element at s1 > element at s2, + */ +void qsort(void *base, size_t nmemb, size_t size, + int (*compar)(const void *s1, const void *s2)); + +/** + * strcmp_compar() - compar function for string arrays + * + * This can be passed to qsort when a string array is being sorted + * + * @s1: First string to compare + * @s2: Second string to compare + * @return comparison value (less than, equal to, or greater than 0) + */ +int strcmp_compar(const void *s1, const void *s2); + +#endif diff --git a/include/status_led.h b/include/status_led.h index 5b3570166db..6707ab1d29d 100644 --- a/include/status_led.h +++ b/include/status_led.h @@ -36,8 +36,8 @@ #endif /* CONFIG_LED_STATUS5 */ void status_led_init(void); -void status_led_tick (unsigned long timestamp); -void status_led_set (int led, int state); +void status_led_tick(unsigned long timestamp); +void status_led_set(int led, int state); /***** MVS v1 **********************************************************/ #if (defined(CONFIG_MVS) && CONFIG_MVS < 2) diff --git a/include/time.h b/include/time.h index a1149522edf..71446c31714 100644 --- a/include/time.h +++ b/include/time.h @@ -70,4 +70,47 @@ uint64_t usec_to_tick(unsigned long usec); (time_after_eq(a,b) && \ time_before(a,c)) +/** + * usec2ticks() - Convert microseconds to internal ticks + * + * @usec: Value of microseconds to convert + * @return Corresponding internal ticks value, calculated using get_tbclk() + */ +ulong usec2ticks(unsigned long usec); + +/** + * ticks2usec() - Convert internal ticks to microseconds + * + * @ticks: Value of ticks to convert + * @return Corresponding microseconds value, calculated using get_tbclk() + */ +ulong ticks2usec(unsigned long ticks); + +/** + * wait_ticks() - waits a given number of ticks + * + * This is an internal function typically used to implement udelay() and + * similar. Normally you should use udelay() or mdelay() instead. + * + * @ticks: Number of ticks to wait + */ +void wait_ticks(unsigned long ticks); + +/** + * timer_get_us() - Get monotonic microsecond timer + * + * @return value of monotonic microsecond timer + */ +unsigned long timer_get_us(void); + +/** + * get_ticks() - Get the current tick value + * + * This is an internal value used by the timer on the system. Ticks increase + * monotonically at the rate given by get_tbclk(). + * + * @return current tick value + */ +uint64_t get_ticks(void); + #endif /* _TIME_H */ diff --git a/include/u-boot/crc.h b/include/u-boot/crc.h index 788ef29a17b..1086d2168ce 100644 --- a/include/u-boot/crc.h +++ b/include/u-boot/crc.h @@ -8,7 +8,19 @@ #ifndef _UBOOT_CRC_H #define _UBOOT_CRC_H -/* lib/crc8.c */ +/** + * crc8() - Calculate and return CRC-8 of the data + * + * This uses an x^8 + x^2 + x + 1 polynomial. A table-based algorithm would + * be faster, but for only a few bytes it isn't worth the code size + * + * lib/crc8.c + * + * @crc_start: CRC8 start value + * @vptr: Buffer to checksum + * @len: Length of buffer in bytes + * @return CRC8 checksum + */ unsigned int crc8(unsigned int crc_start, const unsigned char *vptr, int len); /* lib/crc16.c - 16 bit CRC with polynomial x^16+x^12+x^5+1 (CRC-CCITT) */ @@ -26,9 +38,47 @@ void crc16_ccitt_wd_buf(const uint8_t *in, uint len, uint8_t *out, uint chunk_sz); /* lib/crc32.c */ -uint32_t crc32 (uint32_t, const unsigned char *, uint); -uint32_t crc32_wd (uint32_t, const unsigned char *, uint, uint); -uint32_t crc32_no_comp (uint32_t, const unsigned char *, uint); + +/** + * crc32 - Calculate the CRC32 for a block of data + * + * @crc: Input crc to chain from a previous calculution (use 0 to start a new + * calculation) + * @buf: Bytes to checksum + * @len: Number of bytes to checksum + * @return checksum value + */ +uint32_t crc32(uint32_t crc, const unsigned char *buf, uint len); + +/** + * crc32_wd - Calculate the CRC32 for a block of data (watchdog version) + * + * This checksums the data @chunk_sz bytes at a time, calling WATCHDOG_RESET() + * after each chunk, to prevent the watchdog from firing. + * + * @crc: Input crc to chain from a previous calculution (use 0 to start a new + * calculation) + * @buf: Bytes to checksum + * @len: Number of bytes to checksum + * @chunk_sz: Chunk size to use between watchdog resets + * @return checksum + */ +uint32_t crc32_wd(uint32_t crc, const unsigned char *buf, uint len, + uint chunk_sz); + +/** + * crc32_no_comp - Calculate the CRC32 for a block of data (no one's compliment) + * + * This version uses a different algorithm which doesn't use one's compliment. + * JFFS2 (and other things?) use this. + * + * @crc: Input crc to chain from a previous calculution (use 0 to start a new + * calculation) + * @buf: Bytes to checksum + * @len: Number of bytes to checksum + * @return checksum value + */ +uint32_t crc32_no_comp(uint32_t crc, const unsigned char *buf, uint len); /** * crc32_wd_buf - Perform CRC32 on a buffer and return result in buffer @@ -38,11 +88,34 @@ uint32_t crc32_no_comp (uint32_t, const unsigned char *, uint); * @output: Place to put checksum result (4 bytes) * @chunk_sz: Trigger watchdog after processing this many bytes */ -void crc32_wd_buf(const unsigned char *input, uint ilen, - unsigned char *output, uint chunk_sz); +void crc32_wd_buf(const uint8_t *input, uint ilen, uint8_t *output, + uint chunk_sz); /* lib/crc32c.c */ -void crc32c_init(uint32_t *, uint32_t); -uint32_t crc32c_cal(uint32_t, const char *, int, uint32_t *); + +/** + * crc32c_init() - Set up a the CRC32 table + * + * This sets up 256-item table to aid in CRC32 calculation + * + * @crc32c_table: Place to put table + * @pol: polynomial to use + */ +void crc32c_init(uint32_t *crc32c_table, uint32_t pol); + +/** + * crc32c_cal() - Perform CRC32 on a buffer given a table + * + * This algorithm uses the table (set up by crc32c_init() to speed up + * processing. + * + * @crc: Previous crc (use 0 at start) + * @data: Data bytes to checksum + * @length: Number of bytes to process + * @crc32c_table:: CRC table + * @return checksum value + */ +uint32_t crc32c_cal(uint32_t crc, const char *data, int length, + uint32_t *crc32c_table); #endif /* _UBOOT_CRC_H */ diff --git a/include/vsprintf.h b/include/vsprintf.h index d1740a378e0..56844dd2de8 100644 --- a/include/vsprintf.h +++ b/include/vsprintf.h @@ -212,4 +212,14 @@ void print_grouped_ull(unsigned long long int_val, int digits); bool str2off(const char *p, loff_t *num); bool str2long(const char *p, ulong *num); + +/** + * strmhz() - Convert a value to a Hz string + * + * This creates a string indicating the number of MHz of a value. For example, + * 2700000 produces "2.7". + * @buf: Buffer to hold output string, which must be large enough + * @hz: Value to convert + */ +char *strmhz(char *buf, unsigned long hz); #endif |