]> git.ipfire.org Git - people/ms/u-boot.git/blobdiff - include/common.h
board_f: Drop return value from initdram()
[people/ms/u-boot.git] / include / common.h
index 4566bd11111c97061856a4386e883fa53f784bab..dd8b25f421e8d410e19b636c99856f3e8923e29d 100644 (file)
@@ -15,9 +15,15 @@ typedef volatile unsigned long       vu_long;
 typedef volatile unsigned short vu_short;
 typedef volatile unsigned char vu_char;
 
+/* Allow sharing constants with type modifiers between C and assembly. */
+#define _AC(X, Y)       (X##Y)
+
 #include <config.h>
+#include <errno.h>
+#include <time.h>
 #include <asm-offsets.h>
 #include <linux/bitops.h>
+#include <linux/delay.h>
 #include <linux/types.h>
 #include <linux/string.h>
 #include <linux/stringify.h>
@@ -70,12 +76,15 @@ typedef volatile unsigned char      vu_char;
 #ifdef CONFIG_4xx
 #include <asm/ppc4xx.h>
 #endif
-#ifdef CONFIG_BLACKFIN
-#include <asm/blackfin.h>
-#endif
 #ifdef CONFIG_SOC_DA8XX
 #include <asm/arch/hardware.h>
 #endif
+#ifdef CONFIG_FSL_LSCH3
+#include <asm/arch/immap_lsch3.h>
+#endif
+#ifdef CONFIG_FSL_LSCH2
+#include <asm/arch/immap_lsch2.h>
+#endif
 
 #include <part.h>
 #include <flash.h>
@@ -94,6 +103,13 @@ typedef volatile unsigned char      vu_char;
 #define _DEBUG 0
 #endif
 
+#ifdef CONFIG_SPL_BUILD
+#define _SPL_BUILD     1
+#else
+#define _SPL_BUILD     0
+#endif
+
+/* Define this at the top of a file to add a prefix to debug messages */
 #ifndef pr_fmt
 #define pr_fmt(fmt) fmt
 #endif
@@ -109,9 +125,14 @@ typedef volatile unsigned char     vu_char;
                        printf(pr_fmt(fmt), ##args);    \
        } while (0)
 
+/* Show a message if DEBUG is defined in a file */
 #define debug(fmt, args...)                    \
        debug_cond(_DEBUG, fmt, ##args)
 
+/* Show a message if not in SPL */
+#define warn_non_spl(fmt, args...)                     \
+       debug_cond(!_SPL_BUILD, fmt, ##args)
+
 /*
  * An assertion is run-time check done in debug mode only. If DEBUG is not
  * defined then it is skipped. If DEBUG is defined and the assertion fails,
@@ -140,9 +161,6 @@ void __assert_fail(const char *assertion, const char *file, unsigned line,
 #define BUG_ON(condition) do { if (unlikely((condition)!=0)) BUG(); } while(0)
 #endif /* BUG */
 
-/* Force a compilation error if condition is true */
-#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
-
 typedef void (interrupt_handler_t)(void *);
 
 #include <asm/u-boot.h> /* boot information for Linux kernel */
@@ -191,7 +209,7 @@ int timer_init(void);
 int    cpu_init(void);
 
 /* */
-phys_size_t initdram (int);
+int initdram(void);
 
 #include <display_options.h>
 
@@ -212,11 +230,47 @@ int run_command_repeatable(const char *cmd, int flag);
  * @return 0 on success, or != 0 on error.
  */
 int run_command_list(const char *cmd, int len, int flag);
-extern char console_buffer[];
 
 /* arch/$(ARCH)/lib/board.c */
 void board_init_f(ulong);
 void board_init_r(gd_t *, ulong) __attribute__ ((noreturn));
+
+/**
+ * ulong board_init_f_alloc_reserve - allocate reserved area
+ *
+ * This function is called by each architecture very early in the start-up
+ * code to allow the C runtime to reserve space on the stack for writable
+ * 'globals' such as GD and the malloc arena.
+ *
+ * @top:       top of the reserve area, growing down.
+ * @return:    bottom of reserved area
+ */
+ulong board_init_f_alloc_reserve(ulong top);
+
+/**
+ * board_init_f_init_reserve - initialize the reserved area(s)
+ *
+ * This function is called once the C runtime has allocated the reserved
+ * area on the stack. It must initialize the GD at the base of that area.
+ *
+ * @base:      top from which reservation was done
+ */
+void board_init_f_init_reserve(ulong base);
+
+/**
+ * arch_setup_gd() - Set up the global_data pointer
+ *
+ * This pointer is special in some architectures and cannot easily be assigned
+ * to. For example on x86 it is implemented by adding a specific record to its
+ * Global Descriptor Table! So we we provide a function to carry out this task.
+ * For most architectures this can simply be:
+ *
+ *    gd = gd_ptr;
+ *
+ * @gd_ptr:    Pointer to global data
+ */
+void arch_setup_gd(gd_t *gd_ptr);
+
 int checkboard(void);
 int show_board_info(void);
 int checkflash(void);
@@ -227,17 +281,19 @@ int mac_read_from_eeprom(void);
 extern u8 __dtb_dt_begin[];    /* embedded device tree blob */
 int set_cpu_clk_info(void);
 int mdm_init(void);
-#if defined(CONFIG_DISPLAY_CPUINFO)
 int print_cpuinfo(void);
-#else
-static inline int print_cpuinfo(void)
-{
-       return 0;
-}
-#endif
 int update_flash_size(int flash_size);
 int arch_early_init_r(void);
 
+/**
+ * arch_fsp_init() - perform firmware support package init
+ *
+ * Where U-Boot relies on binary blobs to handle part of the system init, this
+ * function can be used to set up the blobs. This is used on some Intel
+ * platforms.
+ */
+int arch_fsp_init(void);
+
 /**
  * arch_cpu_init_dm() - init CPU after driver model is available
  *
@@ -296,9 +352,6 @@ extern ulong load_addr;             /* Default Load Address */
 extern ulong save_addr;                /* Default Save Address */
 extern ulong save_size;                /* Default Save Size */
 
-/* common/cmd_doc.c */
-void   doc_probe(unsigned long physadr);
-
 /* common/cmd_net.c */
 int do_tftpb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
 
@@ -384,7 +437,6 @@ int get_env_id (void);
 
 void   pci_init      (void);
 void   pci_init_board(void);
-void   pciinfo       (int, int);
 
 #if defined(CONFIG_PCI) && defined(CONFIG_4xx)
     int           pci_pre_init        (struct pci_controller *);
@@ -426,10 +478,7 @@ void       reset_phy     (void);
 void   fdc_hw_init   (void);
 
 /* $(BOARD)/eeprom.c */
-void eeprom_init  (void);
-#ifndef CONFIG_SPI
-int  eeprom_probe (unsigned dev_addr, unsigned offset);
-#endif
+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);
 
@@ -454,6 +503,7 @@ extern ssize_t spi_write (uchar *, int, uchar *, int);
 
 /* $(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);
@@ -528,12 +578,6 @@ void ddr_enable_ecc(unsigned int dram_size);
 #endif
 #endif
 
-/*
- * Return the current value of a monotonically increasing microsecond timer.
- * Granularity may be larger than 1us if hardware does not support this.
- */
-ulong timer_get_us(void);
-
 /* $(CPU)/cpu.c */
 static inline int cpumask_next(int cpu, unsigned int mask)
 {
@@ -553,7 +597,17 @@ int        cpu_num_dspcores(void);
 u32    cpu_mask      (void);
 u32    cpu_dsp_mask(void);
 int    is_core_valid (unsigned int);
-int    probecpu      (void);
+
+/**
+ * arch_cpu_init() - basic cpu-dependent setup for an architecture
+ *
+ * This is called after early malloc is available. It should handle any
+ * CPU- or SoC- specific init needed to continue the init sequence. See
+ * board_f.c for where it is called. If this is not provided, a default
+ * version (which does nothing) will be used.
+ */
+int arch_cpu_init(void);
+
 int    checkcpu      (void);
 int    checkicache   (void);
 int    checkdcache   (void);
@@ -561,12 +615,8 @@ void       upmconfig     (unsigned int, unsigned int *, unsigned int);
 ulong  get_tbclk     (void);
 void   reset_misc    (void);
 void   reset_cpu     (ulong addr);
-#if defined (CONFIG_OF_LIBFDT) && defined (CONFIG_OF_BOARD_SETUP)
 void ft_cpu_setup(void *blob, bd_t *bd);
-#ifdef CONFIG_PCI
 void ft_pci_setup(void *blob, bd_t *bd);
-#endif
-#endif
 
 void smp_set_core_boot_addr(unsigned long addr, int corenr);
 void smp_kick_all_cpus(void);
@@ -587,12 +637,7 @@ int serial_stub_tstc(struct stdio_dev *sdev);
 
 /* $(CPU)/speed.c */
 int    get_clocks (void);
-int    get_clocks_866 (void);
-int    sdram_adjust_866 (void);
-int    adjust_sdram_tbs_8xx (void);
-#if defined(CONFIG_MPC8260)
-int    prt_8260_clks (void);
-#elif defined(CONFIG_MPC5xxx)
+#if defined(CONFIG_MPC5xxx)
 int    prt_mpc5xxx_clks (void);
 #endif
 #ifdef CONFIG_4xx
@@ -625,10 +670,8 @@ int get_serial_clock(void);
 #if defined(CONFIG_MPC85xx)
 typedef MPC85xx_SYS_INFO sys_info_t;
 void   get_sys_info  ( sys_info_t * );
-#  if defined(CONFIG_OF_LIBFDT)
-       void ft_fixup_cpu(void *, u64);
-       void ft_fixup_num_cores(void *);
-#  endif
+void ft_fixup_cpu(void *, u64);
+void ft_fixup_num_cores(void *);
 #endif
 #if defined(CONFIG_MPC86xx)
 typedef MPC86xx_SYS_INFO sys_info_t;
@@ -665,11 +708,6 @@ ulong cpu_init_f(void);
 #endif
 
 int    cpu_init_r    (void);
-#if defined(CONFIG_MPC8260)
-int    prt_8260_rsr  (void);
-#elif defined(CONFIG_MPC83xx)
-int    prt_83xx_rsr  (void);
-#endif
 
 /* $(CPU)/interrupts.c */
 int    interrupt_init     (void);
@@ -678,7 +716,6 @@ void        external_interrupt (struct pt_regs *);
 void   irq_install_handler(int, interrupt_handler_t *, void *);
 void   irq_free_handler   (int);
 void   reset_timer        (void);
-ulong  get_timer          (ulong base);
 
 /* Return value of monotonic microsecond timer */
 unsigned long timer_get_us(void);
@@ -734,10 +771,8 @@ uint64_t get_ticks(void);
 void   wait_ticks    (unsigned long);
 
 /* arch/$(ARCH)/lib/time.c */
-void   __udelay      (unsigned long);
 ulong  usec2ticks    (unsigned long usec);
 ulong  ticks2usec    (unsigned long ticks);
-int    init_timebase (void);
 
 /* lib/gunzip.c */
 int gunzip(void *, int, unsigned char *, unsigned long *);
@@ -778,20 +813,19 @@ void gzwrite_progress_finish(int retcode,
  *                             for files under 4GiB
  */
 int gzwrite(unsigned char *src, int len,
-           struct block_dev_desc *dev,
+           struct blk_desc *dev,
            unsigned long szwritebuf,
            u64 startoffs,
            u64 szexpected);
 
+/* 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/time.c */
-void   udelay        (unsigned long);
-void mdelay(unsigned long);
-
 /* lib/uuid.c */
 #include <uuid.h>
 
@@ -810,15 +844,6 @@ void srand(unsigned int seed);
 unsigned int rand(void);
 unsigned int rand_r(unsigned int *seedp);
 
-/* common/console.c */
-int    console_init_f(void);   /* Before relocation; uses the serial  stuff    */
-int    console_init_r(void);   /* After  relocation; uses the console stuff    */
-int    console_assign(int file, const char *devname);  /* Assign the console   */
-int    ctrlc (void);
-int    had_ctrlc (void);       /* have we had a Control-C since last clear? */
-void   clear_ctrlc (void);     /* clear the Control-C condition */
-int    disable_ctrlc (int);    /* 1 to disable, 0 to enable Control-C detect */
-int confirm_yesno(void);        /*  1 if input is "y", "Y", "yes" or "YES" */
 /*
  * STDIO based functions (can always be used)
  */
@@ -830,11 +855,21 @@ int       getc(void);
 int    tstc(void);
 
 /* stdout */
+#if !defined(CONFIG_SPL_BUILD) || \
+       (defined(CONFIG_TPL_BUILD) && defined(CONFIG_TPL_SERIAL_SUPPORT)) || \
+       (defined(CONFIG_SPL_BUILD) && !defined(CONFIG_TPL_BUILD) && \
+               defined(CONFIG_SPL_SERIAL_SUPPORT))
 void   putc(const char c);
 void   puts(const char *s);
 int    printf(const char *fmt, ...)
                __attribute__ ((format (__printf__, 1, 2)));
 int    vprintf(const char *fmt, va_list args);
+#else
+#define        putc(...) do { } while (0)
+#define puts(...) do { } while (0)
+#define printf(...) do { } while (0)
+#define vprintf(...) do { } while (0)
+#endif
 
 /* stderr */
 #define eputc(c)               fputc(stderr, c)
@@ -870,16 +905,9 @@ static inline struct in_addr getenv_ip(char *var)
        return string_to_ip(getenv(var));
 }
 
-/*
- * CONSOLE multiplexing.
- */
-#ifdef CONFIG_CONSOLE_MUX
-#include <iomux.h>
-#endif
-
 int    pcmcia_init (void);
 
-#ifdef CONFIG_STATUS_LED
+#ifdef CONFIG_LED_STATUS
 # include <status_led.h>
 #endif
 
@@ -897,7 +925,12 @@ int cpu_disable(int nr);
 int cpu_release(int nr, int argc, char * const argv[]);
 #endif
 
-#endif /* __ASSEMBLY__ */
+#else  /* __ASSEMBLY__ */
+
+/* Drop a C type modifier (like in 3UL) for constants used in assembly. */
+#define _AC(X, Y)       X
+
+#endif /* __ASSEMBLY__ */
 
 #ifdef CONFIG_PPC
 /*
@@ -909,6 +942,9 @@ int cpu_release(int nr, int argc, char * const argv[]);
 
 /* Put only stuff here that the assembler can digest */
 
+/* Declare an unsigned long constant digestable both by C and an assembler. */
+#define UL(x)           _AC(x, UL)
+
 #ifdef CONFIG_POST
 #define CONFIG_HAS_POST
 #ifndef CONFIG_POST_ALT_LIST
@@ -923,93 +959,6 @@ int cpu_release(int nr, int argc, char * const argv[]);
 
 #define ROUND(a,b)             (((a) + (b) - 1) & ~((b) - 1))
 
-/*
- * ARCH_DMA_MINALIGN is defined in asm/cache.h for each architecture.  It
- * is used to align DMA buffers.
- */
-#ifndef __ASSEMBLY__
-#include <asm/cache.h>
-#endif
-
-/*
- * The ALLOC_CACHE_ALIGN_BUFFER macro is used to allocate a buffer on the
- * stack that meets the minimum architecture alignment requirements for DMA.
- * Such a buffer is useful for DMA operations where flushing and invalidating
- * the cache before and after a read and/or write operation is required for
- * correct operations.
- *
- * When called the macro creates an array on the stack that is sized such
- * that:
- *
- * 1) The beginning of the array can be advanced enough to be aligned.
- *
- * 2) The size of the aligned portion of the array is a multiple of the minimum
- *    architecture alignment required for DMA.
- *
- * 3) The aligned portion contains enough space for the original number of
- *    elements requested.
- *
- * The macro then creates a pointer to the aligned portion of this array and
- * assigns to the pointer the address of the first element in the aligned
- * portion of the array.
- *
- * Calling the macro as:
- *
- *     ALLOC_CACHE_ALIGN_BUFFER(uint32_t, buffer, 1024);
- *
- * Will result in something similar to saying:
- *
- *     uint32_t    buffer[1024];
- *
- * The following differences exist:
- *
- * 1) The resulting buffer is guaranteed to be aligned to the value of
- *    ARCH_DMA_MINALIGN.
- *
- * 2) The buffer variable created by the macro is a pointer to the specified
- *    type, and NOT an array of the specified type.  This can be very important
- *    if you want the address of the buffer, which you probably do, to pass it
- *    to the DMA hardware.  The value of &buffer is different in the two cases.
- *    In the macro case it will be the address of the pointer, not the address
- *    of the space reserved for the buffer.  However, in the second case it
- *    would be the address of the buffer.  So if you are replacing hard coded
- *    stack buffers with this macro you need to make sure you remove the & from
- *    the locations where you are taking the address of the buffer.
- *
- * Note that the size parameter is the number of array elements to allocate,
- * not the number of bytes.
- *
- * This macro can not be used outside of function scope, or for the creation
- * of a function scoped static buffer.  It can not be used to create a cache
- * line aligned global buffer.
- */
-#define PAD_COUNT(s, pad) (((s) - 1) / (pad) + 1)
-#define PAD_SIZE(s, pad) (PAD_COUNT(s, pad) * pad)
-#define ALLOC_ALIGN_BUFFER_PAD(type, name, size, align, pad)           \
-       char __##name[ROUND(PAD_SIZE((size) * sizeof(type), pad), align)  \
-                     + (align - 1)];                                   \
-                                                                       \
-       type *name = (type *) ALIGN((uintptr_t)__##name, align)
-#define ALLOC_ALIGN_BUFFER(type, name, size, align)            \
-       ALLOC_ALIGN_BUFFER_PAD(type, name, size, align, 1)
-#define ALLOC_CACHE_ALIGN_BUFFER_PAD(type, name, size, pad)            \
-       ALLOC_ALIGN_BUFFER_PAD(type, name, size, ARCH_DMA_MINALIGN, pad)
-#define ALLOC_CACHE_ALIGN_BUFFER(type, name, size)                     \
-       ALLOC_ALIGN_BUFFER(type, name, size, ARCH_DMA_MINALIGN)
-
-/*
- * DEFINE_CACHE_ALIGN_BUFFER() is similar to ALLOC_CACHE_ALIGN_BUFFER, but it's
- * purpose is to allow allocating aligned buffers outside of function scope.
- * Usage of this macro shall be avoided or used with extreme care!
- */
-#define DEFINE_ALIGN_BUFFER(type, name, size, align)                   \
-       static char __##name[ALIGN(size * sizeof(type), align)] \
-                       __aligned(align);                               \
-                                                                       \
-       static type *name = (type *)__##name
-#define DEFINE_CACHE_ALIGN_BUFFER(type, name, size)                    \
-       DEFINE_ALIGN_BUFFER(type, name, size, ARCH_DMA_MINALIGN)
-
 /*
  * check_member() - Check the offset of a structure member
  *
@@ -1021,6 +970,13 @@ int cpu_release(int nr, int argc, char * const argv[]);
        offsetof(struct structure, member) == offset, \
        "`struct " #structure "` offset for `" #member "` is not " #offset)
 
+/* Avoid using CONFIG_EFI_STUB directly as we may boot from other loaders */
+#ifdef CONFIG_EFI_STUB
+#define ll_boot_init() false
+#else
+#define ll_boot_init() true
+#endif
+
 /* Pull in stuff for the build system */
 #ifdef DO_DEPS_ONLY
 # include <environment.h>