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

4.115
Last change on this file since 24bf11e was 24bf11e, checked in by Sebastian Huber <sebastian.huber@…>, on 02/12/14 at 09:31:38

score: Add CPU counter support

Add a CPU counter interface to allow access to a free-running counter.
It is useful to measure short time intervals. This can be used for
example to enable profiling of critical low-level functions.

Add two busy wait functions rtems_counter_delay_ticks() and
rtems_counter_delay_nanoseconds() implemented via the CPU counter.

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