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

4.104.115
Last change on this file since c7880448 was c7880448, checked in by Till Straumann <strauman@…>, on 10/20/09 at 18:07:22

2009-10-20 Till Straumann <strauman@…>

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