[7be6ad9] | 1 | /* |
---|
| 2 | * This routine starts the application. It includes application, |
---|
| 3 | * board, and monitor specific initialization and configuration. |
---|
| 4 | * The generic CPU dependent initialization has been performed |
---|
| 5 | * before this routine is invoked. |
---|
| 6 | * |
---|
[07e9642c] | 7 | * COPYRIGHT (c) 1989-2007. |
---|
[7be6ad9] | 8 | * On-Line Applications Research Corporation (OAR). |
---|
| 9 | * |
---|
| 10 | * The license and distribution terms for this file may be |
---|
| 11 | * found in the file LICENSE in this distribution or at |
---|
[f8e0327] | 12 | * http://www.rtems.com/license/LICENSE. |
---|
[7be6ad9] | 13 | * |
---|
| 14 | * Modified to support the MCP750. |
---|
| 15 | * Modifications Copyright (C) 1999 Eric Valette. valette@crf.canon.fr |
---|
| 16 | * |
---|
[ee732739] | 17 | * Modified to support the Synergy VGM & Motorola PowerPC boards |
---|
| 18 | * (C) by Till Straumann, <strauman@slac.stanford.edu>, 2002, 2004, 2005 |
---|
[7be6ad9] | 19 | * |
---|
[ee732739] | 20 | * Modified to support the MVME5500 board. |
---|
| 21 | * Also, the settings of L1, L2, and L3 caches is not necessary here. |
---|
[72510eb2] | 22 | * (C) by Brookhaven National Lab., S. Kate Feng <feng1@bnl.gov>, 2003-2009 |
---|
[ac7af4a] | 23 | * |
---|
[f8e0327] | 24 | * $Id$ |
---|
[7be6ad9] | 25 | */ |
---|
[f8e0327] | 26 | |
---|
[7be6ad9] | 27 | #include <string.h> |
---|
| 28 | #include <stdlib.h> |
---|
| 29 | #include <ctype.h> |
---|
| 30 | |
---|
| 31 | #include <rtems/system.h> |
---|
[1899fe4] | 32 | #include <rtems/powerpc/powerpc.h> |
---|
| 33 | |
---|
[7be6ad9] | 34 | #include <libcpu/spr.h> /* registers.h is included here */ |
---|
| 35 | #include <bsp.h> |
---|
| 36 | #include <bsp/uart.h> |
---|
| 37 | #include <bsp/pci.h> |
---|
| 38 | #include <libcpu/bat.h> |
---|
| 39 | #include <libcpu/pte121.h> |
---|
| 40 | #include <libcpu/cpuIdent.h> |
---|
| 41 | #include <bsp/vectors.h> |
---|
| 42 | #include <bsp/bspException.h> |
---|
| 43 | |
---|
[ef9e015] | 44 | #include <rtems/bspIo.h> |
---|
[7be6ad9] | 45 | #include <rtems/sptables.h> |
---|
| 46 | |
---|
| 47 | /* |
---|
| 48 | #define SHOW_MORE_INIT_SETTINGS |
---|
| 49 | #define SHOW_LCR1_REGISTER |
---|
| 50 | #define SHOW_LCR2_REGISTER |
---|
| 51 | #define SHOW_LCR3_REGISTER |
---|
| 52 | #define CONF_VPD |
---|
| 53 | */ |
---|
| 54 | |
---|
| 55 | /* there is no public Workspace_Free() variant :-( */ |
---|
| 56 | #include <rtems/score/wkspace.h> |
---|
| 57 | |
---|
[2e9d27c0] | 58 | extern uint32_t probeMemoryEnd(void); /* from shared/startup/probeMemoryEnd.c */ |
---|
| 59 | |
---|
| 60 | |
---|
[7be6ad9] | 61 | BSP_output_char_function_type BSP_output_char = BSP_output_char_via_serial; |
---|
| 62 | |
---|
[6771a9e7] | 63 | extern void _return_to_ppcbug(void); |
---|
[7be6ad9] | 64 | extern unsigned long __rtems_end[]; |
---|
[6771a9e7] | 65 | extern unsigned get_L1CR(void), get_L2CR(void), get_L3CR(void); |
---|
[06d14130] | 66 | extern Triv121PgTbl BSP_pgtbl_setup(unsigned int *); |
---|
[6771a9e7] | 67 | extern void BSP_pgtbl_activate(Triv121PgTbl); |
---|
| 68 | extern int I2Cread_eeprom(unsigned char I2cBusAddr, uint32_t devA2A1A0, uint32_t AddrBytes, unsigned char *pBuff, uint32_t numBytes); |
---|
[7be6ad9] | 69 | extern void BSP_vme_config(void); |
---|
| 70 | |
---|
[2e9d27c0] | 71 | extern unsigned char ReadConfVPD_buff(int offset); |
---|
| 72 | |
---|
[fda16849] | 73 | extern unsigned long __bss_start[], __SBSS_START__[], __SBSS_END__[]; |
---|
| 74 | extern unsigned long __SBSS2_START__[], __SBSS2_END__[]; |
---|
| 75 | |
---|
[07e9642c] | 76 | uint32_t bsp_clicks_per_usec; |
---|
| 77 | |
---|
[7be6ad9] | 78 | SPR_RW(SPRG1) |
---|
| 79 | |
---|
| 80 | typedef struct CmdLineRec_ { |
---|
[b5e7018] | 81 | unsigned long size; |
---|
| 82 | char buf[0]; |
---|
[7be6ad9] | 83 | } CmdLineRec, *CmdLine; |
---|
| 84 | |
---|
| 85 | |
---|
[b5e7018] | 86 | #define mtspr(reg, val) \ |
---|
| 87 | __asm __volatile("mtspr %0,%1" : : "K"(reg), "r"(val)) |
---|
[7be6ad9] | 88 | |
---|
| 89 | |
---|
[b5e7018] | 90 | #define mfspr(reg) \ |
---|
| 91 | ( { unsigned val; \ |
---|
| 92 | __asm __volatile("mfspr %0,%1" : "=r"(val) : "K"(reg)); \ |
---|
| 93 | val; } ) |
---|
[7be6ad9] | 94 | |
---|
| 95 | /* |
---|
| 96 | * Copy Additional boot param passed by boot loader |
---|
| 97 | */ |
---|
| 98 | #define MAX_LOADER_ADD_PARM 80 |
---|
| 99 | char loaderParam[MAX_LOADER_ADD_PARM]; |
---|
| 100 | |
---|
| 101 | /* |
---|
| 102 | * Total memory using RESIDUAL DATA |
---|
| 103 | */ |
---|
| 104 | unsigned int BSP_mem_size; |
---|
| 105 | /* |
---|
| 106 | * PCI Bus Frequency |
---|
| 107 | */ |
---|
| 108 | unsigned int BSP_bus_frequency; |
---|
| 109 | /* |
---|
| 110 | * processor clock frequency |
---|
| 111 | */ |
---|
| 112 | unsigned int BSP_processor_frequency; |
---|
| 113 | /* |
---|
| 114 | * Time base divisior (how many tick for 1 second). |
---|
| 115 | */ |
---|
| 116 | unsigned int BSP_time_base_divisor; |
---|
[72510eb2] | 117 | static unsigned char ConfVPD_buff[200]; |
---|
[7be6ad9] | 118 | |
---|
[b5e7018] | 119 | #define CMDLINE_BUF_SIZE 2048 |
---|
[ee732739] | 120 | |
---|
| 121 | static char cmdline_buf[CMDLINE_BUF_SIZE]; |
---|
| 122 | char *BSP_commandline_string = cmdline_buf; |
---|
| 123 | |
---|
[7be6ad9] | 124 | void BSP_panic(char *s) |
---|
| 125 | { |
---|
| 126 | printk("%s PANIC %s\n",_RTEMS_version, s); |
---|
[ac7af4a] | 127 | __asm__ __volatile ("sc"); |
---|
[7be6ad9] | 128 | } |
---|
| 129 | |
---|
| 130 | void _BSP_Fatal_error(unsigned int v) |
---|
| 131 | { |
---|
| 132 | printk("%s PANIC ERROR %x\n",_RTEMS_version, v); |
---|
[ac7af4a] | 133 | __asm__ __volatile ("sc"); |
---|
[7be6ad9] | 134 | } |
---|
[ac7af4a] | 135 | |
---|
[2e9d27c0] | 136 | void zero_bss(void) |
---|
[7be6ad9] | 137 | { |
---|
[b5e7018] | 138 | memset( |
---|
| 139 | __SBSS_START__, |
---|
| 140 | 0, |
---|
| 141 | ((unsigned) __SBSS_END__) - ((unsigned)__SBSS_START__) |
---|
| 142 | ); |
---|
| 143 | memset( |
---|
| 144 | __SBSS2_START__, |
---|
| 145 | 0, |
---|
| 146 | ((unsigned) __SBSS2_END__) - ((unsigned)__SBSS2_START__) |
---|
| 147 | ); |
---|
| 148 | memset( |
---|
| 149 | __bss_start, |
---|
| 150 | 0, |
---|
| 151 | ((unsigned) __rtems_end) - ((unsigned)__bss_start) |
---|
| 152 | ); |
---|
[7be6ad9] | 153 | } |
---|
| 154 | |
---|
| 155 | /* NOTE: we cannot simply malloc the commandline string; |
---|
| 156 | * save_boot_params() is called during a very early stage when |
---|
| 157 | * libc/malloc etc. are not yet initialized! |
---|
| 158 | * |
---|
| 159 | * Here's what we do: |
---|
| 160 | * |
---|
| 161 | * initial layout setup by the loader (preload.S): |
---|
| 162 | * |
---|
| 163 | * 0..RTEMS...__rtems_end | cmdline ....... TOP |
---|
| 164 | * |
---|
| 165 | * After the save_boot_params() routine returns, the stack area will be |
---|
| 166 | * set up (start.S): |
---|
| 167 | * |
---|
| 168 | * 0..RTEMS..__rtems_end | INIT_STACK | IRQ_STACK | ..... TOP |
---|
| 169 | * |
---|
| 170 | * initialize_executive_early() [called from boot_card()] |
---|
| 171 | * will initialize the workspace: |
---|
| 172 | * |
---|
| 173 | * 0..RTEMS..__rtems_end | INIT_STACK | IRQ_STACK | ...... | workspace | TOP |
---|
| 174 | * |
---|
| 175 | * and later calls our pretasking_hook() which ends up initializing |
---|
| 176 | * libc which in turn initializes the heap |
---|
| 177 | * |
---|
| 178 | * 0..RTEMS..__rtems_end | INIT_STACK | IRQ_STACK | heap | workspace | TOP |
---|
| 179 | * |
---|
| 180 | * The idea here is to first move the commandline to the future 'heap' area |
---|
| 181 | * from where it will be picked up by our pretasking_hook(). |
---|
| 182 | * pretasking_hook() then moves it either to INIT_STACK or the workspace |
---|
| 183 | * area using proper allocation, initializes libc and finally moves |
---|
| 184 | * the data to the environment / malloced areas... |
---|
| 185 | */ |
---|
| 186 | |
---|
[ac7af4a] | 187 | /* this routine is called early at shared/start/start.S |
---|
[7be6ad9] | 188 | * and must be safe with a not properly aligned stack |
---|
| 189 | */ |
---|
[5eccbac] | 190 | char * |
---|
[b5e7018] | 191 | save_boot_params( |
---|
| 192 | void *r3, |
---|
| 193 | void *r4, |
---|
| 194 | void* r5, |
---|
| 195 | char *cmdline_start, |
---|
| 196 | char *cmdline_end |
---|
| 197 | ) |
---|
[7be6ad9] | 198 | { |
---|
[b5e7018] | 199 | int i=cmdline_end-cmdline_start; |
---|
| 200 | |
---|
| 201 | if ( i >= CMDLINE_BUF_SIZE ) |
---|
| 202 | i = CMDLINE_BUF_SIZE-1; |
---|
| 203 | else if ( i < 0 ) |
---|
| 204 | i = 0; |
---|
| 205 | |
---|
| 206 | memmove(cmdline_buf, cmdline_start, i); |
---|
| 207 | cmdline_buf[i]=0; |
---|
[5eccbac] | 208 | return cmdline_buf; |
---|
[7be6ad9] | 209 | } |
---|
| 210 | |
---|
| 211 | /* |
---|
| 212 | * bsp_start |
---|
| 213 | * |
---|
| 214 | * This routine does the bulk of the system initialization. |
---|
| 215 | */ |
---|
| 216 | |
---|
| 217 | void bsp_start( void ) |
---|
| 218 | { |
---|
[2d2de4eb] | 219 | rtems_status_code sc = RTEMS_SUCCESSFUL; |
---|
[05682dc] | 220 | #ifdef CONF_VPD |
---|
[7be6ad9] | 221 | int i; |
---|
[05682dc] | 222 | #endif |
---|
| 223 | #ifdef SHOW_LCR1_REGISTER |
---|
| 224 | unsigned l1cr; |
---|
| 225 | #endif |
---|
| 226 | #ifdef SHOW_LCR2_REGISTER |
---|
| 227 | unsigned l2cr; |
---|
| 228 | #endif |
---|
| 229 | #ifdef SHOW_LCR3_REGISTER |
---|
| 230 | unsigned l3cr; |
---|
| 231 | #endif |
---|
[2d2de4eb] | 232 | uintptr_t intrStackStart; |
---|
| 233 | uintptr_t intrStackSize; |
---|
[7be6ad9] | 234 | ppc_cpu_id_t myCpu; |
---|
| 235 | ppc_cpu_revision_t myCpuRevision; |
---|
[b5e7018] | 236 | Triv121PgTbl pt=0; |
---|
[ee732739] | 237 | |
---|
| 238 | /* Till Straumann: 4/2005 |
---|
| 239 | * Need to map the system registers early, so we can printk... |
---|
| 240 | * (otherwise we silently die) |
---|
| 241 | */ |
---|
| 242 | /* |
---|
[ac7af4a] | 243 | * Kate Feng : PCI 0 domain memory space, want to leave room for the VME window |
---|
[ee732739] | 244 | */ |
---|
| 245 | setdbat(2, PCI0_MEM_BASE, PCI0_MEM_BASE, 0x10000000, IO_PAGE); |
---|
| 246 | |
---|
| 247 | /* Till Straumann: 2004 |
---|
| 248 | * map the PCI 0, 1 Domain I/O space, GT64260B registers |
---|
| 249 | * and the reserved area so that the size is the power of 2. |
---|
[72510eb2] | 250 | * 2009 : map the entire 256 M space |
---|
[ac7af4a] | 251 | * |
---|
[ee732739] | 252 | */ |
---|
[72510eb2] | 253 | setdbat(3,PCI0_IO_BASE, PCI0_IO_BASE, 0x10000000, IO_PAGE); |
---|
[ee732739] | 254 | |
---|
| 255 | |
---|
[7be6ad9] | 256 | /* |
---|
| 257 | * Get CPU identification dynamically. Note that the get_ppc_cpu_type() function |
---|
| 258 | * store the result in global variables so that it can be used latter... |
---|
| 259 | */ |
---|
[b5e7018] | 260 | myCpu = get_ppc_cpu_type(); |
---|
[7be6ad9] | 261 | myCpuRevision = get_ppc_cpu_revision(); |
---|
| 262 | |
---|
| 263 | #ifdef SHOW_LCR1_REGISTER |
---|
| 264 | l1cr = get_L1CR(); |
---|
[ac7af4a] | 265 | printk("Initial L1CR value = %x\n", l1cr); |
---|
[7be6ad9] | 266 | #endif |
---|
| 267 | |
---|
| 268 | /* |
---|
[a86f3aac] | 269 | * Initialize the interrupt related settings. |
---|
[7be6ad9] | 270 | */ |
---|
[2d2de4eb] | 271 | intrStackStart = (uintptr_t) __rtems_end; |
---|
[a86f3aac] | 272 | intrStackSize = rtems_configuration_get_interrupt_stack_size(); |
---|
[7be6ad9] | 273 | |
---|
| 274 | /* |
---|
[a86f3aac] | 275 | * Initialize default raw exception handlers. |
---|
[7be6ad9] | 276 | */ |
---|
[2d2de4eb] | 277 | sc = ppc_exc_initialize( |
---|
[a86f3aac] | 278 | PPC_INTERRUPT_DISABLE_MASK_DEFAULT, |
---|
| 279 | intrStackStart, |
---|
| 280 | intrStackSize |
---|
| 281 | ); |
---|
[2d2de4eb] | 282 | if (sc != RTEMS_SUCCESSFUL) { |
---|
| 283 | BSP_panic("cannot initialize exceptions"); |
---|
| 284 | } |
---|
[b5e7018] | 285 | |
---|
[7be6ad9] | 286 | /* |
---|
| 287 | * Init MMU block address translation to enable hardware |
---|
| 288 | * access |
---|
| 289 | * More PCI1 memory mapping to be done after BSP_pgtbl_activate. |
---|
| 290 | */ |
---|
| 291 | printk("-----------------------------------------\n"); |
---|
| 292 | printk("Welcome to %s on MVME5500-0163\n", _RTEMS_version ); |
---|
| 293 | printk("-----------------------------------------\n"); |
---|
| 294 | |
---|
[72510eb2] | 295 | BSP_mem_size = probeMemoryEnd(); |
---|
[b5e7018] | 296 | /* TODO: calculate the BSP_bus_frequency using the REF_CLK bit |
---|
| 297 | * of System Status register |
---|
| 298 | */ |
---|
[7be6ad9] | 299 | /* rtems_bsp_delay_in_bus_cycles are defined in registers.h */ |
---|
[b5e7018] | 300 | BSP_bus_frequency = 133333333; |
---|
| 301 | BSP_processor_frequency = 1000000000; |
---|
| 302 | /* P94 : 7455 clocks the TB/DECR at 1/4 of the system bus clock frequency */ |
---|
| 303 | BSP_time_base_divisor = 4000; |
---|
[7be6ad9] | 304 | |
---|
| 305 | |
---|
| 306 | /* Maybe not setup yet becuase of the warning message */ |
---|
| 307 | /* Allocate and set up the page table mappings |
---|
| 308 | * This is only available on >604 CPUs. |
---|
| 309 | * |
---|
| 310 | * NOTE: This setup routine may modify the available memory |
---|
| 311 | * size. It is essential to call it before |
---|
| 312 | * calculating the workspace etc. |
---|
| 313 | */ |
---|
| 314 | pt = BSP_pgtbl_setup(&BSP_mem_size); |
---|
| 315 | if (!pt) |
---|
| 316 | printk("WARNING: unable to setup page tables.\n"); |
---|
| 317 | |
---|
[ac7af4a] | 318 | printk("Now BSP_mem_size = 0x%x\n",BSP_mem_size); |
---|
[7be6ad9] | 319 | |
---|
| 320 | /* P94 : 7455 TB/DECR is clocked by the system bus clock frequency */ |
---|
| 321 | |
---|
[b5e7018] | 322 | bsp_clicks_per_usec = BSP_bus_frequency/(BSP_time_base_divisor * 1000); |
---|
| 323 | |
---|
[7be6ad9] | 324 | /* |
---|
| 325 | * Initalize RTEMS IRQ system |
---|
| 326 | */ |
---|
| 327 | BSP_rtems_irq_mng_init(0); |
---|
| 328 | |
---|
| 329 | #ifdef SHOW_LCR2_REGISTER |
---|
| 330 | l2cr = get_L2CR(); |
---|
| 331 | printk("Initial L2CR value = %x\n", l2cr); |
---|
[ac7af4a] | 332 | #endif |
---|
[7be6ad9] | 333 | |
---|
| 334 | #ifdef SHOW_LCR3_REGISTER |
---|
| 335 | /* L3CR needs DEC int. handler installed for bsp_delay()*/ |
---|
| 336 | l3cr = get_L3CR(); |
---|
| 337 | printk("Initial L3CR value = %x\n", l3cr); |
---|
[ac7af4a] | 338 | #endif |
---|
[7be6ad9] | 339 | |
---|
| 340 | |
---|
| 341 | /* Activate the page table mappings only after |
---|
| 342 | * initializing interrupts because the irq_mng_init() |
---|
| 343 | * routine needs to modify the text |
---|
[ac7af4a] | 344 | */ |
---|
[7be6ad9] | 345 | if (pt) { |
---|
| 346 | #ifdef SHOW_MORE_INIT_SETTINGS |
---|
| 347 | printk("Page table setup finished; will activate it NOW...\n"); |
---|
| 348 | #endif |
---|
| 349 | BSP_pgtbl_activate(pt); |
---|
| 350 | } |
---|
[72510eb2] | 351 | /* Read Configuration Vital Product Data (VPD) */ |
---|
| 352 | if ( I2Cread_eeprom(0xa8, 4,2, &ConfVPD_buff[0], 150)) |
---|
| 353 | printk("I2Cread_eeprom() error \n"); |
---|
| 354 | else { |
---|
| 355 | #ifdef CONF_VPD |
---|
| 356 | printk("\n"); |
---|
| 357 | for (i=0; i<150; i++) { |
---|
[ac7af4a] | 358 | printk("%2x ", ConfVPD_buff[i]); |
---|
[72510eb2] | 359 | if ((i % 20)==0 ) printk("\n"); |
---|
| 360 | } |
---|
| 361 | printk("\n"); |
---|
| 362 | #endif |
---|
| 363 | } |
---|
[7be6ad9] | 364 | |
---|
| 365 | /* |
---|
| 366 | * PCI 1 domain memory space |
---|
| 367 | */ |
---|
| 368 | setdbat(1, PCI1_MEM_BASE, PCI1_MEM_BASE, 0x10000000, IO_PAGE); |
---|
[ac7af4a] | 369 | |
---|
[7be6ad9] | 370 | |
---|
| 371 | #ifdef SHOW_MORE_INIT_SETTINGS |
---|
| 372 | printk("Going to start PCI buses scanning and initialization\n"); |
---|
[ac7af4a] | 373 | #endif |
---|
[037864f5] | 374 | pci_initialize(); |
---|
[7be6ad9] | 375 | #ifdef SHOW_MORE_INIT_SETTINGS |
---|
[4cbb57da] | 376 | printk("Number of PCI buses found is : %d\n", pci_bus_count()); |
---|
[7be6ad9] | 377 | #endif |
---|
| 378 | |
---|
| 379 | /* Install our own exception handler (needs PCI) */ |
---|
| 380 | globalExceptHdl = BSP_exceptionHandler; |
---|
| 381 | |
---|
| 382 | /* clear hostbridge errors. MCP signal is not used on the MVME5500 |
---|
| 383 | * PCI config space scanning code will trip otherwise :-( |
---|
| 384 | */ |
---|
| 385 | _BSP_clear_hostbridge_errors(0, 1 /*quiet*/); |
---|
| 386 | |
---|
| 387 | #ifdef SHOW_MORE_INIT_SETTINGS |
---|
| 388 | printk("MSR %x \n", _read_MSR()); |
---|
| 389 | printk("Exit from bspstart\n"); |
---|
| 390 | #endif |
---|
| 391 | |
---|
| 392 | } |
---|
[72510eb2] | 393 | |
---|
| 394 | unsigned char ReadConfVPD_buff(int offset) |
---|
| 395 | { |
---|
| 396 | return(ConfVPD_buff[offset]); |
---|
| 397 | } |
---|