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

4.9
Last change on this file since 83e392b4 was 83e392b4, checked in by Eric Norum <WENorum@…>, on 10/23/08 at 13:45:55

Reset card on RTEMS shutdown.

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