source: rtems/bsps/powerpc/mvme3100/start/bspstart.c @ 8f8ccee

5
Last change on this file since 8f8ccee was 9964895, checked in by Sebastian Huber <sebastian.huber@…>, on 04/20/18 at 08:35:35

bsps: Move startup files to bsps

Adjust build support files to new directory layout.

This patch is a part of the BSP source reorganization.

Update #3285.

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