source: rtems/c/src/lib/libbsp/powerpc/mvme3100/startup/bspstart.c @ b1e8a58

4.115
Last change on this file since b1e8a58 was b1e8a58, checked in by Sebastian Huber <sebastian.huber@…>, on 11/14/12 at 08:57:55

bsps/powerpc: Exception initialization error is fatal

  • Property mode set to 100644
File size: 11.3 KB
Line 
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 *
7 *  COPYRIGHT (c) 1989-1998.
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
12 *  http://www.rtems.com/license/LICENSE.
13 *
14 *  Modified to support the MCP750.
15 *  Modifications Copyright (C) 1999 Eric Valette. valette@crf.canon.fr
16 *
17 *  Modified for mvme3100 by T. Straumann
18 */
19
20#include <string.h>
21#include <stdlib.h>
22
23#include <rtems.h>
24#include <bsp.h>
25#include <rtems/bspIo.h>
26#include <libcpu/spr.h>
27#include <libcpu/io.h>
28#include <libcpu/e500_mmu.h>
29#include <bsp/uart.h>
30#include <bsp/irq.h>
31#include <bsp/pci.h>
32#include <bsp/vpd.h>
33#include <libcpu/cpuIdent.h>
34#include <bsp/vectors.h>
35#include <rtems/powerpc/powerpc.h>
36
37#define SHOW_MORE_INIT_SETTINGS
38#undef  DEBUG
39
40#define NumberOf(arr) (sizeof(arr)/sizeof(arr[0]))
41
42#ifdef  DEBUG
43#define STATIC
44#else
45#define STATIC static
46#endif
47
48extern unsigned long __rtems_end[];
49extern void              BSP_vme_config(void);
50extern void          BSP_pciConfigDump_early( void );
51extern unsigned      ppc_exc_lock_std, ppc_exc_gpr3_std;
52
53/*
54 * Copy Additional boot param passed by boot loader
55 */
56#define CMDLINE_BUF_SIZE        2048
57
58static char cmdline_buf[CMDLINE_BUF_SIZE] = {0};
59char *BSP_commandline_string         = cmdline_buf;
60
61/*
62 * Vital Board data Start using DATA RESIDUAL
63 */
64uint32_t bsp_clicks_per_usec         = 0;
65/*
66 * Total memory using RESIDUAL DATA
67 */
68unsigned int BSP_mem_size            = 0;
69/*
70 * PCI Bus Frequency
71 */
72unsigned int BSP_pci_bus_frequency   = 0xdeadbeef;
73/*
74 * PPC Bus Frequency
75 */
76unsigned int BSP_bus_frequency       = 0;
77/*
78 * processor clock frequency
79 */
80unsigned int BSP_processor_frequency = 0;
81/*
82 * Time base divisior (how many tick for 1 second).
83 */
84unsigned int BSP_time_base_divisor   = 8000; /* if external RTC clock unused (HID0) */
85
86/* Board identification string */
87char BSP_productIdent[20]            = {0};
88char BSP_serialNumber[20]            = {0};
89
90/* VPD appends an extra char -- what for ? */
91char BSP_enetAddr0[7]                = {0};
92char BSP_enetAddr1[7]                = {0};
93char BSP_enetAddr2[7]                = {0};
94
95static void
96prether(char *b, int idx)
97{
98int i;
99        printk("Ethernet %i                  %02X", idx, *b++);
100        for ( i=0; i<5; i++ )
101                printk(":%02X",*b++);
102        printk("\n");
103}
104
105
106BSP_output_char_function_type     BSP_output_char = BSP_output_char_via_serial;
107BSP_polling_getchar_function_type BSP_poll_char = NULL;
108
109void BSP_panic(char *s)
110{
111  printk("\n%s PANIC %s\n",_RTEMS_version, s);
112  __asm__ __volatile ("sc");
113}
114
115void _BSP_Fatal_error(unsigned int v)
116{
117  printk("\n%s PANIC ERROR %x\n",_RTEMS_version, v);
118  __asm__ __volatile ("sc");
119}
120
121char *rtems_progname;
122
123/*
124 *  Use the shared implementations of the following routines
125 */
126
127char * save_boot_params(void* r3, void *r4, void* r5, char *additional_boot_options)
128{
129
130  strncpy(cmdline_buf, additional_boot_options, CMDLINE_BUF_SIZE);
131  cmdline_buf[CMDLINE_BUF_SIZE - 1] ='\0';
132  return cmdline_buf;
133}
134
135#define CS_CONFIG_CS_EN (1<<31)
136#define CS_BNDS_SA(x)   ((((uint32_t)(x))>>(31-15)) & 0xff)
137#define CS_BNDS_EA(x)   ((((uint32_t)(x))>>(31-31)) & 0xff)
138
139static inline uint32_t
140_ccsr_rd32(uint32_t off)
141{
142        return in_be32( (volatile unsigned *)(BSP_8540_CCSR_BASE + off) );
143}
144
145static inline void
146_ccsr_wr32(uint32_t off, uint32_t val)
147{
148        out_be32( (volatile unsigned *)(BSP_8540_CCSR_BASE + off), val );
149}
150
151
152STATIC uint32_t
153BSP_get_mem_size( void )
154{
155int i;
156uint32_t        cs_bnds, cs_config;
157uint32_t        memsz=0;
158uint32_t        v;
159
160        for ( cs_bnds = 0x2000, cs_config=0x2080, i=0; i<4; i++, cs_bnds+=8, cs_config+=4 ) {
161                if ( CS_CONFIG_CS_EN & _ccsr_rd32( cs_config ) ) {
162                        v = _ccsr_rd32( cs_bnds );
163
164                        memsz += CS_BNDS_EA(v) - CS_BNDS_SA(v) + 1;
165                }
166        }
167        return memsz << 24;
168}
169
170STATIC void
171BSP_calc_freqs( void )
172{
173uint32_t        porpllsr   = _ccsr_rd32( 0xe0000 );
174unsigned        plat_ratio = (porpllsr >> (31-30)) & 0x1f;
175unsigned    e500_ratio = (porpllsr >> (31-15)) & 0x3f;
176
177        switch ( plat_ratio ) {
178                case  2: case  3: case  4: case  5: case  6:
179                case  8: case  9: case 10: case 12: case 16:
180                /* supported ratios */
181                        BSP_bus_frequency = BSP_pci_bus_frequency * plat_ratio;
182                break;
183
184                default:
185                        BSP_panic("Unknown PLL sys-clock ratio; something's wrong here");
186        }
187
188        switch ( e500_ratio ) {
189                case 4: case 5: case 6: case 7:
190                        BSP_processor_frequency = (BSP_pci_bus_frequency * e500_ratio) >> 1;
191                break;
192
193                default:
194                        BSP_panic("Unknown PLL e500-clock ratio; something's wrong here");
195        }
196
197        printk("Core Complex Bus (CCB) Clock Freq: %10u Hz\n", BSP_bus_frequency);
198        printk("CPU Clock Freq:                    %10u Hz\n", BSP_processor_frequency);
199}
200
201void
202bsp_predriver_hook(void)
203{
204        /* Some drivers (RTC) may need i2c */
205        BSP_i2c_initialize();
206}
207
208/*
209 *  bsp_start
210 *
211 *  This routine does the bulk of the system initialization.
212 */
213
214#include <libcpu/spr.h>
215
216SPR_RW(HID1)
217
218void bsp_start( void )
219{
220unsigned char       *stack;
221uintptr_t           intrStackStart;
222uintptr_t           intrStackSize;
223char                *chpt;
224ppc_cpu_id_t        myCpu;
225ppc_cpu_revision_t  myCpuRevision;
226int                 i;
227E500_tlb_va_cache_t *tlb;
228
229VpdBufRec          vpdData [] = {
230        { key: ProductIdent, instance: 0, buf: BSP_productIdent, buflen: sizeof(BSP_productIdent) - 1 },
231        { key: SerialNumber, instance: 0, buf: BSP_serialNumber, buflen: sizeof(BSP_serialNumber) - 1 },
232        { key: BusClockHz,   instance: 0, buf: &BSP_pci_bus_frequency, buflen: sizeof(BSP_pci_bus_frequency)  },
233        { key: EthernetAddr, instance: 0, buf: BSP_enetAddr0, buflen: sizeof(BSP_enetAddr0) },
234        { key: EthernetAddr, instance: 1, buf: BSP_enetAddr1, buflen: sizeof(BSP_enetAddr1) },
235        { key: EthernetAddr, instance: 2, buf: BSP_enetAddr2, buflen: sizeof(BSP_enetAddr2) },
236        VPD_END
237};
238
239        /* Intersperse messages with actions to help locate problems */
240        printk("-----------------------------------------\n");
241
242        /*
243         * Get CPU identification dynamically. Note that the get_ppc_cpu_type()
244         * function store the result in global variables so that it can be used
245         * later...
246         */
247        myCpu         = get_ppc_cpu_type();
248        myCpuRevision = get_ppc_cpu_revision();
249
250        printk("Welcome to %s\n", _RTEMS_version);
251        printk("BSP: %s, CVS Release ($Name$)\n", "mvme3100");
252
253        /*
254         * the initial stack  has aready been set to this value in start.S
255         * so there is no need to set it in r1 again... It is just for info
256         * so that It can be printed without accessing R1.
257         */
258        asm volatile("mr %0, 1":"=r"(stack));
259
260        /* tag the bottom */
261        *((uint32_t*)stack) = 0;
262
263        /*
264         * Initialize the interrupt related settings.
265         */
266        intrStackStart = (uintptr_t) __rtems_end;
267        intrStackSize = rtems_configuration_get_interrupt_stack_size();
268
269        /*
270         * Initialize default raw exception handlers.
271         */
272        ppc_exc_initialize(
273                PPC_INTERRUPT_DISABLE_MASK_DEFAULT,
274                intrStackStart,
275                intrStackSize
276        );
277
278        printk("CPU 0x%x - rev 0x%x\n", myCpu, myCpuRevision);
279
280#ifdef SHOW_MORE_INIT_SETTINGS
281        printk("Additionnal boot options are %s\n", BSP_commandline_string);
282        printk("Initial system stack at %x\n",      stack);
283        printk("Software IRQ stack starts at %x with size %u\n", intrStackStart, intrStackSize);
284#endif
285
286#ifdef SHOW_MORE_INIT_SETTINGS
287        printk("Going to start PCI buses scanning and initialization\n");
288#endif
289
290        BSP_mem_size            = BSP_get_mem_size();
291
292        {
293                /* memory-select errors were disabled in 'start.S';
294                 * motload has all TLBs mapping a possible larger area as
295                 * memory (not-guarded, caching-enabled) than actual physical
296                 * memory is available.
297                 * In case of speculative loads this may cause 'memory-select' errors
298                 * which seem to raise 'core_fault_in' (found no description in
299                 * the manual but I experienced this problem).
300                 * Such errors (if HID1[RFXE] is clear) may *stall* execution
301                 * leading to mysterious 'hangs'.
302                 *
303                 * Here we remove all mappings, re-enable memory-select
304                 * errors and make sure we enable HID1[RFXE] to avoid
305                 * stalls (since we don't implement handling individual
306                 * error-handling interrupts).
307                 */
308
309                /* enable machine check for bad bus errors */
310                _write_HID1( _read_HID1() | 0x20000 );
311
312                rtems_e500_initlb();
313
314                for ( i=0, tlb=rtems_e500_tlb_va_cache; i<NumberOf(rtems_e500_tlb_va_cache); i++, tlb++ ) {
315                        /* disable TLBs for caching-enabled, non-guarded areas
316                         * beyond physical memory
317                         */
318                        if (    tlb->att.v
319                            &&  0xa != (tlb->att.wimge & 0xa)
320                                &&  (tlb->va.va_epn<<12) >= BSP_mem_size ) {
321                                rtems_e500_clrtlb( E500_SELTLB_1 | i );
322                        }
323                }
324
325                /* clear all pending memory errors */
326                _ccsr_wr32(0x2e40, 0xffffffff);
327                /* enable checking for memory-select errors */
328                _ccsr_wr32(0x2e44, _ccsr_rd32(0x2e44) & ~1 );
329        }
330
331        BSP_vpdRetrieveFields( vpdData );
332
333        printk("Board Type: %s (S/N %s)\n",
334                        BSP_productIdent[0] ? BSP_productIdent : "n/a",
335                        BSP_serialNumber[0] ? BSP_serialNumber : "n/a");
336
337        printk("External (=PCI Bus) Clock Freq   ");
338        if ( 0xdeadbeef == BSP_pci_bus_frequency ) {
339                BSP_pci_bus_frequency   = 66666666;
340                printk(" NOT FOUND in VPD; using %10u Hz\n",
341                                BSP_pci_bus_frequency);
342        } else {
343                printk(": %10u Hz\n",
344                                BSP_pci_bus_frequency);
345        }
346
347        /* Calculate CPU and CCB bus freqs */
348        BSP_calc_freqs();
349
350        pci_initialize();
351
352        prether(BSP_enetAddr0, 0);
353        prether(BSP_enetAddr1, 1);
354        prether(BSP_enetAddr2, 2);
355
356        /* need to tweak the motload setup */
357        BSP_motload_pci_fixup();
358
359#ifdef SHOW_MORE_INIT_SETTINGS
360        printk("Number of PCI buses found is : %d\n", pci_bus_count());
361        {
362                BSP_pciConfigDump_early();
363        }
364#endif
365
366        if ( (chpt = strstr(BSP_commandline_string,"MEMSZ=")) ) {
367                char            *endp;
368                uint32_t        sz;
369                chpt+=6 /* strlen("MEMSZ=") */;
370                sz = strtoul(chpt, &endp, 0);
371                if ( endp != chpt )
372                        BSP_mem_size = sz;
373        }
374
375        printk("Memory:                            %10u bytes\n", BSP_mem_size);
376
377        BSP_bus_frequency       = 333333333;
378        BSP_processor_frequency = 833333333;
379        BSP_time_base_divisor   = 8000; /* if external RTC clock unused (HID0) */
380
381        /* clear hostbridge errors but leave MCP disabled -
382         * PCI config space scanning code will trip otherwise :-(
383         */
384        _BSP_clear_hostbridge_errors(0 /* enableMCP */, 0/*quiet*/);
385
386        bsp_clicks_per_usec = BSP_bus_frequency/(BSP_time_base_divisor * 1000);
387
388        /*
389         * Initalize RTEMS IRQ system
390         */
391        BSP_rtems_irq_mng_init(0);
392
393        if (1) {
394                int i;
395                unsigned msr,tcr;
396                asm volatile("mfmsr %0":"=r"(msr));
397                asm volatile("mftcr %0":"=r"(tcr));
398                printk("MSR is 0x%08x, TCR 0x%08x\n",msr,tcr);
399                asm volatile("mttcr %0"::"r"(0));
400                if (0) {
401                        asm volatile("mtmsr %0"::"r"(msr|0x8000));
402                        for (i=0; i<12; i++)
403                                BSP_enable_irq_at_pic(i);
404                        printk("IRQS enabled\n");
405                }
406        }
407
408        if (0) {
409                unsigned x;
410                asm volatile("mfivpr %0":"=r"(x));
411                printk("IVPR: 0x%08x\n",x);
412                asm volatile("mfivor8 %0":"=r"(x));
413                printk("IVOR8: 0x%08x\n",x);
414                printk("0x%08x\n",*(unsigned *)0xc00);
415                printk("0x%08x\n",*(unsigned *)0xc04);
416                printk("0x%08x\n",*(unsigned *)0xc08);
417                printk("0x%08x\n\n\n",*(unsigned *)0xc0c);
418                if (0) {
419                        *(unsigned *)0xc08 = 0x4c000064;
420                        asm volatile("dcbf 0, %0; icbi 0, %0; sync; isync"::"r"(0xc00));
421                }
422
423                printk("0x%08x\n", ppc_exc_lock_std);
424                printk("0x%08x\n", ppc_exc_gpr3_std);
425
426                asm volatile("sc");
427
428                printk("0x%08x\n", ppc_exc_lock_std);
429                printk("0x%08x\n", ppc_exc_gpr3_std);
430        }
431
432        printk("-----------------------------------------\n");
433
434#ifdef SHOW_MORE_INIT_SETTINGS
435        printk("Exit from bspstart\n");
436#endif
437
438}
Note: See TracBrowser for help on using the repository browser.