Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:53

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup mpc83xx
0007  *
0008  * @brief Source for BSP startup code.
0009  */
0010 
0011 /*
0012  * Copyright (C) 2008, 2014 embedded brains GmbH & Co. KG
0013  *
0014  * Redistribution and use in source and binary forms, with or without
0015  * modification, are permitted provided that the following conditions
0016  * are met:
0017  * 1. Redistributions of source code must retain the above copyright
0018  *    notice, this list of conditions and the following disclaimer.
0019  * 2. Redistributions in binary form must reproduce the above copyright
0020  *    notice, this list of conditions and the following disclaimer in the
0021  *    documentation and/or other materials provided with the distribution.
0022  *
0023  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0024  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0025  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0026  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0027  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0028  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0029  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0030  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0031  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0032  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0033  * POSSIBILITY OF SUCH DAMAGE.
0034  */
0035 
0036 #include <rtems/counter.h>
0037 
0038 #include <libchip/ns16550.h>
0039 
0040 #include <libcpu/powerpc-utility.h>
0041 
0042 #include <bsp.h>
0043 #include <bsp/vectors.h>
0044 #include <bsp/bootcard.h>
0045 #include <bsp/irq-generic.h>
0046 #include <bsp/linker-symbols.h>
0047 #include <bsp/u-boot.h>
0048 #include <bsp/console-termios.h>
0049 
0050 /* Configuration parameters for console driver, ... */
0051 unsigned int BSP_bus_frequency;
0052 
0053 /* Configuration parameter for clock driver */
0054 uint32_t bsp_time_base_frequency;
0055 
0056 /* Legacy */
0057 uint32_t bsp_clicks_per_usec;
0058 
0059 /* Default decrementer exception handler */
0060 static int mpc83xx_decrementer_exception_handler( BSP_Exception_frame *frame, unsigned number)
0061 {
0062   ppc_set_decrementer_register(UINT32_MAX);
0063 
0064   return 0;
0065 }
0066 
0067 uint32_t _CPU_Counter_frequency(void)
0068 {
0069   return bsp_time_base_frequency;
0070 }
0071 
0072 void bsp_start( void)
0073 {
0074   rtems_status_code sc = RTEMS_SUCCESSFUL;
0075   unsigned long i = 0;
0076 
0077   /*
0078    * Get CPU identification dynamically. Note that the get_ppc_cpu_type() function
0079    * store the result in global variables so that it can be used latter...
0080    */
0081   get_ppc_cpu_type();
0082   get_ppc_cpu_revision();
0083 
0084   /* Basic CPU initialization */
0085   cpu_init();
0086 
0087   /*
0088    * Enable instruction and data caches. Do not force writethrough mode.
0089    */
0090 
0091 #ifdef BSP_INSTRUCTION_CACHE_ENABLED
0092   rtems_cache_enable_instruction();
0093 #endif
0094 
0095 #ifdef BSP_DATA_CACHE_ENABLED
0096   rtems_cache_enable_data();
0097 #endif
0098 
0099   /*
0100    * This is evaluated during runtime, so it should be ok to set it
0101    * before we initialize the drivers.
0102    */
0103 
0104   /* Initialize some device driver parameters */
0105 
0106 #ifdef HAS_UBOOT
0107   BSP_bus_frequency = bsp_uboot_board_info.bi_busfreq;
0108 #else /* HAS_UBOOT */
0109   BSP_bus_frequency = BSP_CLKIN_FRQ * BSP_SYSPLL_MF / BSP_SYSPLL_CKID;
0110 #endif /* HAS_UBOOT */
0111   bsp_time_base_frequency = BSP_bus_frequency / 4;
0112   bsp_clicks_per_usec = bsp_time_base_frequency / 1000000;
0113 
0114   /* Initialize some console parameters */
0115   for (i = 0; i < console_device_count; ++i) {
0116     ns16550_context *ctx = (ns16550_context *) console_device_table[i].context;
0117 
0118     ctx->clock = BSP_bus_frequency;
0119 
0120     #ifdef HAS_UBOOT
0121       ctx->initial_baud = bsp_uboot_board_info.bi_baudrate;
0122     #endif
0123   }
0124 
0125   /* Initialize exception handler */
0126 #ifndef BSP_DATA_CACHE_ENABLED
0127   ppc_exc_cache_wb_check = 0;
0128 #endif
0129   ppc_exc_initialize();
0130 
0131   /* Install default handler for the decrementer exception */
0132   sc = ppc_exc_set_handler( ASM_DEC_VECTOR, mpc83xx_decrementer_exception_handler);
0133   if (sc != RTEMS_SUCCESSFUL) {
0134     rtems_panic("cannot install decrementer exception handler");
0135   }
0136 
0137   /* Initalize interrupt support */
0138   bsp_interrupt_initialize();
0139 
0140 #ifdef SHOW_MORE_INIT_SETTINGS
0141   printk("Exit from bspstart\n");
0142 #endif
0143 }