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

4.104.114.95
Last change on this file since 27d4569 was 27d4569, checked in by Joel Sherrill <joel.sherrill@…>, on 01/29/08 at 22:01:18

2008-01-29 Eric Norum <norume@…>

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