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

4.104.114.95
Last change on this file since 7347b0d was 7347b0d, checked in by Till Straumann <strauman@…>, on 03/21/08 at 06:38:04

2007-03-20 Till Straumann <strauman@…>

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