1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup mpc83xx |
---|
5 | * |
---|
6 | * @brief Source for BSP startup code. |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * Copyright (c) 2008 |
---|
11 | * Embedded Brains GmbH |
---|
12 | * Obere Lagerstr. 30 |
---|
13 | * D-82178 Puchheim |
---|
14 | * Germany |
---|
15 | * rtems@embedded-brains.de |
---|
16 | * |
---|
17 | * The license and distribution terms for this file may be |
---|
18 | * found in the file LICENSE in this distribution or at |
---|
19 | * http://www.rtems.com/license/LICENSE. |
---|
20 | * |
---|
21 | * $Id$ |
---|
22 | */ |
---|
23 | |
---|
24 | #include <libchip/serial.h> |
---|
25 | |
---|
26 | #include <libcpu/powerpc-utility.h> |
---|
27 | |
---|
28 | #include <bsp.h> |
---|
29 | #include <bsp/vectors.h> |
---|
30 | #include <bsp/bootcard.h> |
---|
31 | #include <bsp/irq-generic.h> |
---|
32 | #include <bsp/u-boot.h> |
---|
33 | |
---|
34 | /* Configuration parameters for console driver, ... */ |
---|
35 | unsigned int BSP_bus_frequency; |
---|
36 | |
---|
37 | /* Configuration parameters for clock driver, ... */ |
---|
38 | uint32_t bsp_clicks_per_usec; |
---|
39 | |
---|
40 | /* Default decrementer exception handler */ |
---|
41 | static int mpc83xx_decrementer_exception_handler( BSP_Exception_frame *frame, unsigned number) |
---|
42 | { |
---|
43 | ppc_set_decrementer_register(UINT32_MAX); |
---|
44 | |
---|
45 | return 0; |
---|
46 | } |
---|
47 | |
---|
48 | void BSP_panic(char *s) |
---|
49 | { |
---|
50 | rtems_interrupt_level level; |
---|
51 | |
---|
52 | rtems_interrupt_disable(level); |
---|
53 | |
---|
54 | printk("%s PANIC %s\n", rtems_get_version_string(), s); |
---|
55 | |
---|
56 | while (1) { |
---|
57 | /* Do nothing */ |
---|
58 | } |
---|
59 | } |
---|
60 | |
---|
61 | void _BSP_Fatal_error(unsigned n) |
---|
62 | { |
---|
63 | rtems_interrupt_level level; |
---|
64 | |
---|
65 | rtems_interrupt_disable( level); |
---|
66 | |
---|
67 | printk( "%s PANIC ERROR %u\n", rtems_get_version_string(), n); |
---|
68 | |
---|
69 | while (1) { |
---|
70 | /* Do nothing */ |
---|
71 | } |
---|
72 | } |
---|
73 | |
---|
74 | void bsp_start( void) |
---|
75 | { |
---|
76 | rtems_status_code sc = RTEMS_SUCCESSFUL; |
---|
77 | unsigned long i = 0; |
---|
78 | |
---|
79 | ppc_cpu_id_t myCpu; |
---|
80 | ppc_cpu_revision_t myCpuRevision; |
---|
81 | |
---|
82 | uintptr_t interrupt_stack_start = (uintptr_t) bsp_interrupt_stack_start; |
---|
83 | uintptr_t interrupt_stack_size = (uintptr_t) bsp_interrupt_stack_size; |
---|
84 | |
---|
85 | /* |
---|
86 | * Get CPU identification dynamically. Note that the get_ppc_cpu_type() function |
---|
87 | * store the result in global variables so that it can be used latter... |
---|
88 | */ |
---|
89 | myCpu = get_ppc_cpu_type(); |
---|
90 | myCpuRevision = get_ppc_cpu_revision(); |
---|
91 | |
---|
92 | /* Basic CPU initialization */ |
---|
93 | cpu_init(); |
---|
94 | |
---|
95 | /* |
---|
96 | * Enable instruction and data caches. Do not force writethrough mode. |
---|
97 | */ |
---|
98 | |
---|
99 | #ifdef BSP_INSTRUCTION_CACHE_ENABLED |
---|
100 | rtems_cache_enable_instruction(); |
---|
101 | #endif |
---|
102 | |
---|
103 | #ifdef BSP_DATA_CACHE_ENABLED |
---|
104 | rtems_cache_enable_data(); |
---|
105 | #endif |
---|
106 | |
---|
107 | /* |
---|
108 | * This is evaluated during runtime, so it should be ok to set it |
---|
109 | * before we initialize the drivers. |
---|
110 | */ |
---|
111 | |
---|
112 | /* Initialize some device driver parameters */ |
---|
113 | |
---|
114 | #ifdef HAS_UBOOT |
---|
115 | BSP_bus_frequency = bsp_uboot_board_info.bi_busfreq; |
---|
116 | bsp_clicks_per_usec = bsp_uboot_board_info.bi_busfreq / 4000000; |
---|
117 | #else /* HAS_UBOOT */ |
---|
118 | BSP_bus_frequency = BSP_CLKIN_FRQ * BSP_SYSPLL_MF / BSP_SYSPLL_CKID; |
---|
119 | bsp_clicks_per_usec = BSP_bus_frequency / 4000000; |
---|
120 | #endif /* HAS_UBOOT */ |
---|
121 | |
---|
122 | /* Initialize some console parameters */ |
---|
123 | for (i = 0; i < Console_Port_Count; ++i) { |
---|
124 | Console_Configuration_Ports [i].ulClock = BSP_bus_frequency; |
---|
125 | |
---|
126 | #ifdef HAS_UBOOT |
---|
127 | Console_Configuration_Ports [i].pDeviceParams = |
---|
128 | (void *) bsp_uboot_board_info.bi_baudrate; |
---|
129 | #endif |
---|
130 | } |
---|
131 | |
---|
132 | /* Initialize exception handler */ |
---|
133 | #ifndef BSP_DATA_CACHE_ENABLED |
---|
134 | ppc_exc_cache_wb_check = 0; |
---|
135 | #endif |
---|
136 | sc = ppc_exc_initialize( |
---|
137 | PPC_INTERRUPT_DISABLE_MASK_DEFAULT, |
---|
138 | interrupt_stack_start, |
---|
139 | interrupt_stack_size |
---|
140 | ); |
---|
141 | if (sc != RTEMS_SUCCESSFUL) { |
---|
142 | BSP_panic("cannot initialize exceptions"); |
---|
143 | } |
---|
144 | |
---|
145 | /* Install default handler for the decrementer exception */ |
---|
146 | sc = ppc_exc_set_handler( ASM_DEC_VECTOR, mpc83xx_decrementer_exception_handler); |
---|
147 | if (sc != RTEMS_SUCCESSFUL) { |
---|
148 | BSP_panic("cannot install decrementer exception handler"); |
---|
149 | } |
---|
150 | |
---|
151 | /* Initalize interrupt support */ |
---|
152 | sc = bsp_interrupt_initialize(); |
---|
153 | if (sc != RTEMS_SUCCESSFUL) { |
---|
154 | BSP_panic("cannot intitialize interrupts\n"); |
---|
155 | } |
---|
156 | |
---|
157 | #ifdef SHOW_MORE_INIT_SETTINGS |
---|
158 | printk("Exit from bspstart\n"); |
---|
159 | #endif |
---|
160 | } |
---|