Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup tqm8xx
0007  *
0008  * @brief Source for BSP startup code.
0009  */
0010 
0011 /*
0012  * Copyright (c) 2008 embedded brains GmbH & Co. KG
0013  * Redistribution and use in source and binary forms, with or without
0014  * modification, are permitted provided that the following conditions
0015  * are met:
0016  * 1. Redistributions of source code must retain the above copyright
0017  *    notice, this list of conditions and the following disclaimer.
0018  * 2. Redistributions in binary form must reproduce the above copyright
0019  *    notice, this list of conditions and the following disclaimer in the
0020  *    documentation and/or other materials provided with the distribution.
0021  *
0022  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0023  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0024  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0025  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0026  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0027  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0028  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0029  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0030  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0031  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0032  * POSSIBILITY OF SUCH DAMAGE.
0033  */
0034 
0035 #include <stdlib.h>
0036 
0037 #include <rtems.h>
0038 #include <rtems/counter.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 
0047 #ifdef BSP_HAS_TQMMON
0048 /*
0049  * FIXME: TQ Monitor structure
0050  */
0051 #endif /* BSP_HAS_TQMMON */
0052 
0053 /* Configuration parameters for console driver, ... */
0054 uint32_t BSP_bus_frequency;
0055 
0056 /* Configuration parameter for clock driver */
0057 uint32_t bsp_time_base_frequency;
0058 
0059 /* Legacy */
0060 uint32_t bsp_clicks_per_usec; /* for PIT driver: OSCCLK */
0061 
0062 static const char *bsp_tqm_get_cib_string( const char *cib_id)
0063 {
0064   char srch_pattern[10] = "";
0065   char *fnd_str;
0066   /*
0067    * create search pattern
0068    */
0069   strcat(srch_pattern,"-");
0070   strncat(srch_pattern,
0071       cib_id,
0072       sizeof(srch_pattern)-1-strlen(srch_pattern));
0073   strncat(srch_pattern,
0074       " ",
0075       sizeof(srch_pattern)-1-strlen(srch_pattern));
0076   /*
0077    * search for pattern in info block (CIB)
0078    */
0079   fnd_str = strstr((const char *)TQM_CONF_INFO_BLOCK_ADDR,srch_pattern);
0080 
0081   if (fnd_str == NULL) {
0082     return NULL;
0083   }
0084   else {
0085     /*
0086      * found? then advance behind search pattern
0087      */
0088     return fnd_str + strlen(srch_pattern);
0089   }
0090 }
0091 
0092 static uint32_t str_to_u32(const char *s)
0093 {
0094   uint32_t v = 0;
0095 
0096   while (true) {
0097     unsigned char digit = (unsigned char)*s - '0';
0098 
0099     if (digit > 9) {
0100       break;
0101     }
0102 
0103     v = (v * 10) + digit;
0104     ++s;
0105   }
0106 
0107   return v;
0108 }
0109 
0110 static rtems_status_code  bsp_tqm_get_cib_uint32( const char *cib_id,
0111                        uint32_t   *result)
0112 {
0113   const char *item_ptr;
0114   item_ptr = bsp_tqm_get_cib_string(cib_id);
0115   if (item_ptr == NULL) {
0116     return RTEMS_INVALID_ID;
0117   }
0118   /*
0119    * convert string to uint32
0120    */
0121   *result = str_to_u32(item_ptr);
0122   return RTEMS_SUCCESSFUL;
0123 }
0124 
0125 uint32_t _CPU_Counter_frequency(void)
0126 {
0127   return bsp_time_base_frequency;
0128 }
0129 
0130 void bsp_start( void)
0131 {
0132   /*
0133    * Get CPU identification dynamically. Note that the get_ppc_cpu_type()
0134    * function stores the result in global variables so that it can be used
0135    * later...
0136    */
0137   get_ppc_cpu_type();
0138   get_ppc_cpu_revision();
0139 
0140   /* Basic CPU initialization */
0141   cpu_init();
0142 
0143   /*
0144    * Enable instruction and data caches. Do not force writethrough mode.
0145    */
0146 
0147 #if BSP_INSTRUCTION_CACHE_ENABLED
0148   rtems_cache_enable_instruction();
0149 #endif
0150 
0151 #if BSP_DATA_CACHE_ENABLED
0152   rtems_cache_enable_data();
0153 #endif
0154 
0155   /*
0156    * This is evaluated during runtime, so it should be ok to set it
0157    * before we initialize the drivers.
0158    */
0159 
0160   /* Initialize some device driver parameters */
0161   /*
0162    * get the (internal) bus frequency
0163    * NOTE: the external bus may be clocked at a lower speed
0164    * but this does not concern the internal units like PIT,
0165    * DEC, baudrate generator etc)
0166    */
0167   if (RTEMS_SUCCESSFUL !=
0168       bsp_tqm_get_cib_uint32("cu",
0169                  &BSP_bus_frequency)) {
0170     rtems_panic("Cannot determine BUS frequency\n");
0171   }
0172 
0173   bsp_time_base_frequency = BSP_bus_frequency / 16;
0174   bsp_clicks_per_usec = bsp_time_base_frequency / 1000000;
0175 
0176   ppc_exc_initialize();
0177   bsp_interrupt_initialize();
0178 
0179 #ifdef SHOW_MORE_INIT_SETTINGS
0180   printk("Exit from bspstart\n");
0181 #endif
0182 }