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

4.104.115
Last change on this file since 05adba6 was 6771a9e7, checked in by Ralf Corsepius <ralf.corsepius@…>, on 08/20/08 at 09:00:11

Add missing prototypes.

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