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