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

4.104.115
Last change on this file since 8da29747 was 8da29747, checked in by Joel Sherrill <joel.sherrill@…>, on 09/10/08 at 21:35:19

2008-09-10 Joel Sherrill <joel.sherrill@…>

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