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

4.104.114.9
Last change on this file since b599faa was b599faa, checked in by Till Straumann <strauman@…>, on Dec 14, 2007 at 6:30:15 AM
  • imported MVME3100 BSP (from SLAC repository)
  • Property mode set to 100644
File size: 12.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 <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
231void bsp_start( void )
232{
233unsigned char      *stack;
234register uint32_t  intrStack;
235register uint32_t  *intrStackPtr;
236unsigned char      *work_space_start;
237char               *chpt;
238ppc_cpu_id_t       myCpu;
239ppc_cpu_revision_t myCpuRevision;
240
241VpdBufRec          vpdData [] = {
242        { key: ProductIdent, instance: 0, buf: BSP_productIdent, buflen: sizeof(BSP_productIdent) - 1 },
243        { key: SerialNumber, instance: 0, buf: BSP_serialNumber, buflen: sizeof(BSP_serialNumber) - 1 },
244        { key: BusClockHz,   instance: 0, buf: &BSP_pci_bus_frequency, buflen: sizeof(BSP_pci_bus_frequency)  },
245        { key: EthernetAddr, instance: 0, buf: BSP_enetAddr0, buflen: sizeof(BSP_enetAddr0) },
246        { key: EthernetAddr, instance: 1, buf: BSP_enetAddr1, buflen: sizeof(BSP_enetAddr1) },
247        { key: EthernetAddr, instance: 2, buf: BSP_enetAddr2, buflen: sizeof(BSP_enetAddr2) },
248        VPD_END
249};
250
251        /* Intersperse messages with actions to help locate problems */
252        printk("-----------------------------------------\n");
253
254        /*
255         * Get CPU identification dynamically. Note that the get_ppc_cpu_type()
256         * function store the result in global variables so that it can be used
257         * later...
258         */
259        myCpu         = get_ppc_cpu_type();
260        myCpuRevision = get_ppc_cpu_revision();
261
262        printk("Welcome to %s\n", _RTEMS_version);
263        printk("BSP: %s, CVS Release ($Name$)\n", "mvme3100");
264
265        /*
266         * the initial stack  has aready been set to this value in start.S
267         * so there is no need to set it in r1 again... It is just for info
268         * so that It can be printed without accessing R1.
269         */
270        asm volatile("mr %0, 1":"=r"(stack));
271#if 0
272        stack = ((unsigned char*) __rtems_end) +
273                INIT_STACK_SIZE - PPC_MINIMUM_STACK_FRAME_SIZE;
274#endif
275
276        /* tag the bottom */
277        *((uint32_t*)stack) = 0;
278
279        /*
280         * Initialize the interrupt related settings
281         * SPRG1 = software managed IRQ stack
282         *
283         * This could be done later (e.g in IRQ_INIT) but it helps to understand
284         * some settings below...
285         */
286        BSP_heap_start = ((uint32_t) __rtems_end) + INIT_STACK_SIZE + INTR_STACK_SIZE;
287
288        /* reserve space for the marker/tag frame */
289        intrStack      = BSP_heap_start - PPC_MINIMUM_STACK_FRAME_SIZE;
290
291        /* make sure it's properly aligned */
292        intrStack     &= ~(CPU_STACK_ALIGNMENT-1);
293
294        /* tag the bottom (T. Straumann 6/36/2001 <strauman@slac.stanford.edu>) */
295        intrStackPtr   = (uint32_t*) intrStack;
296        *intrStackPtr  = 0;
297
298        _write_SPRG1(intrStack);
299
300        /* signal them that we have fixed PR288 - eventually, this should go away */
301        _write_SPRG0(PPC_BSP_HAS_FIXED_PR288);
302
303        /*
304         * Initialize default raw exception handlers. See vectors/vectors_init.c
305         */
306        initialize_exceptions();
307
308        printk("CPU 0x%x - rev 0x%x\n", myCpu, myCpuRevision);
309
310#ifdef SHOW_MORE_INIT_SETTINGS
311        printk("Additionnal boot options are %s\n", BSP_commandline_string);
312        printk("Initial system stack at %x\n",      stack);
313        printk("Software IRQ stack at %x\n",        intrStack);
314#endif
315
316#ifdef SHOW_MORE_INIT_SETTINGS
317        printk("Going to start PCI buses scanning and initialization\n");
318#endif
319
320        printk("Build Date: %s\n",BSP_build_date);
321
322        BSP_vpdRetrieveFields( vpdData );
323
324        printk("Board Type: %s (S/N %s)\n",
325                        BSP_productIdent[0] ? BSP_productIdent : "n/a",
326                        BSP_serialNumber[0] ? BSP_serialNumber : "n/a");
327
328        printk("External (=PCI Bus) Clock Freq   ");
329        if ( 0xdeadbeef == BSP_pci_bus_frequency ) {
330                BSP_pci_bus_frequency   = 66666666;
331                printk(" NOT FOUND in VPD; using %10u Hz\n",
332                                BSP_pci_bus_frequency);
333        } else {
334                printk(": %10u Hz\n",
335                                BSP_pci_bus_frequency);
336        }
337
338        /* Calculate CPU and CCB bus freqs */
339        BSP_calc_freqs();
340
341        pci_initialize();
342
343        prether(BSP_enetAddr0, 0);
344        prether(BSP_enetAddr1, 1);
345        prether(BSP_enetAddr2, 2);
346
347        /* need to tweak the motload setup */
348        BSP_motload_pci_fixup();
349
350#ifdef SHOW_MORE_INIT_SETTINGS
351        printk("Number of PCI buses found is : %d\n", pci_bus_count());
352        {
353                void BSP_pciConfigDump_early();
354                BSP_pciConfigDump_early();
355        }
356#endif
357
358#ifdef TEST_RAW_EXCEPTION_CODE
359        printk("Testing exception handling Part 1\n");
360        /*
361         * Cause a software exception
362         */
363        __asm__ __volatile ("sc");
364        /*
365         * Check we can still catch exceptions and return coorectly.
366         */
367        printk("Testing exception handling Part 2\n");
368        __asm__ __volatile ("sc");
369
370        /*
371         *  Somehow doing the above seems to clobber SPRG0 on the mvme2100.  It
372         *  is probably a not so subtle hint that you do not want to use PPCBug
373         *  once RTEMS is up and running.  Anyway, we still needs to indicate
374         *  that we have fixed PR288.  Eventually, this should go away.
375         */
376        _write_SPRG0(PPC_BSP_HAS_FIXED_PR288);
377#endif
378
379        BSP_mem_size            = BSP_get_mem_size();
380
381        if ( (chpt = strstr(BSP_commandline_string,"MEMSZ=")) ) {
382                char            *endp;
383                uint32_t        sz;
384                chpt+=6 /* strlen("MEMSZ=") */;
385                sz = strtoul(chpt, &endp, 0);
386                if ( endp != chpt )
387                        BSP_mem_size = sz;
388        }
389
390        printk("Memory:                            %10u bytes\n", BSP_mem_size);
391
392        BSP_bus_frequency       = 333333333;
393        BSP_processor_frequency = 833333333;
394        BSP_time_base_divisor   = 8000; /* if external RTC clock unused (HID0) */
395
396        /* clear hostbridge errors but leave MCP disabled -
397         * PCI config space scanning code will trip otherwise :-(
398         */
399        _BSP_clear_hostbridge_errors(0 /* enableMCP */, 0/*quiet*/);
400
401        /*
402         * Set up our hooks
403         * Make sure libc_init is done before drivers initialized so that
404         * they can use atexit()
405         */
406
407#if 0
408        Cpu_table.interrupt_stack_size = CONFIGURE_INTERRUPT_STACK_MEMORY;
409/* FIXME */
410#endif
411        bsp_clicks_per_usec            = BSP_bus_frequency/(BSP_time_base_divisor * 1000);
412
413#ifdef SHOW_MORE_INIT_SETTINGS
414        printk("Configuration.work_space_size = %x\n",
415                        Configuration.work_space_size);
416#endif
417
418        work_space_start =
419                (unsigned char *)BSP_mem_size - Configuration.work_space_size;
420
421        if ( work_space_start <=
422                        ((unsigned char *)__rtems_end) + INIT_STACK_SIZE + INTR_STACK_SIZE) {
423                printk( "bspstart: Not enough RAM!!!\n" );
424                bsp_cleanup();
425        }
426
427        Configuration.work_space_start = work_space_start;
428
429        /*
430         * Initalize RTEMS IRQ system
431         */
432        BSP_rtems_irq_mng_init(0);
433
434        if (1) {
435                int i;
436                unsigned msr,tcr;
437                asm volatile("mfmsr %0":"=r"(msr));
438                asm volatile("mftcr %0":"=r"(tcr));
439                printk("MSR is 0x%08x, TCR 0x%08x\n",msr,tcr);
440                asm volatile("mttcr %0"::"r"(0));
441                if (0) {
442                        asm volatile("mtmsr %0"::"r"(msr|0x8000));
443                        for (i=0; i<12; i++)
444                                BSP_enable_irq_at_pic(i); 
445                        printk("IRQS enabled\n");
446                }
447        }
448
449        if (0) {
450                extern unsigned ppc_exc_lock_std, ppc_exc_gpr3_std;
451                unsigned x;
452                asm volatile("mfivpr %0":"=r"(x));
453                printk("IVPR: 0x%08x\n",x);
454                asm volatile("mfivor8 %0":"=r"(x));
455                printk("IVOR8: 0x%08x\n",x);
456                printk("0x%08x\n",*(unsigned *)0xc00);
457                printk("0x%08x\n",*(unsigned *)0xc04);
458                printk("0x%08x\n",*(unsigned *)0xc08);
459                printk("0x%08x\n\n\n",*(unsigned *)0xc0c);
460                if (0) {
461                        *(unsigned *)0xc08 = 0x4c000064;
462                        asm volatile("dcbf 0, %0; icbi 0, %0; sync; isync"::"r"(0xc00));
463                }
464
465                printk("0x%08x\n", ppc_exc_lock_std);
466                printk("0x%08x\n", ppc_exc_gpr3_std);
467
468                asm volatile("sc");
469
470                printk("0x%08x\n", ppc_exc_lock_std);
471                printk("0x%08x\n", ppc_exc_gpr3_std);
472        }
473
474        printk("-----------------------------------------\n");
475
476#ifdef SHOW_MORE_INIT_SETTINGS
477        printk("Exit from bspstart\n");
478#endif
479
480}
Note: See TracBrowser for help on using the repository browser.