source: rtems/c/src/lib/libbsp/powerpc/beatnik/startup/bspstart.c @ 443c61ec

5
Last change on this file since 443c61ec was 443c61ec, checked in by Sebastian Huber <sebastian.huber@…>, on 11/25/15 at 08:01:57

Delete empty libc_init()

  • Property mode set to 100644
File size: 10.8 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.OARcorp.com/rtems/license.html.
12 *
13 *  Modified to support the MCP750.
14 *  Modifications Copyright (C) 1999 Eric Valette. valette@crf.canon.fr
15 *
16 *  Modified to support the Synergy VGM & Motorola PowerPC boards.
17 *  (C) by Till Straumann, <strauman@slac.stanford.edu>, 2002, 2004, 2005
18 *
19 *  Modified to support the mvme5500 BSP
20 *  (C) by Kate Feng <feng1@bnl.gov>, 2003, 2004
21 *      under the contract DE-AC02-98CH10886 with the Deaprtment of Energy
22 *
23 *  T. Straumann: 2005-2007; stolen again for 'beatnik'...
24 */
25#include <string.h>
26#include <stdlib.h>
27#include <ctype.h>
28
29#include <rtems/system.h>
30#include <rtems/libio.h>
31#include <rtems/libcsupport.h>
32#include <rtems/bspIo.h>
33#include <rtems/counter.h>
34#include <rtems/powerpc/powerpc.h>
35/*#include <bsp/consoleIo.h>*/
36#include <libcpu/spr.h>   /* registers.h is included here */
37#include <bsp.h>
38#include <bsp/bootcard.h>
39#include <bsp/uart.h>
40#include <bsp/pci.h>
41#include <bsp/gtreg.h>
42#include <bsp/gt_timer.h>
43#include <libcpu/bat.h>
44#include <libcpu/pte121.h>
45#include <libcpu/cpuIdent.h>
46#include <bsp/vectors.h>
47#include <bsp/vpd.h>
48
49/* for RTEMS_VERSION :-( I dont like the preassembled string */
50#include <rtems/sptables.h>
51
52#define SHOW_MORE_INIT_SETTINGS
53
54BSP_output_char_function_type     BSP_output_char = BSP_output_char_via_serial;
55BSP_polling_getchar_function_type BSP_poll_char = NULL;
56
57extern Triv121PgTbl BSP_pgtbl_setup(unsigned int *);
58extern void BSP_pgtbl_activate(Triv121PgTbl);
59extern void BSP_motload_pci_fixup(void);
60
61extern unsigned long __rtems_end[];
62
63/* We really shouldn't use these since MMUoff also sets IP;
64 * nevertheless, during early init I don't care for now
65 */
66extern void MMUoff(void);
67extern void MMUon(void);
68
69extern uint32_t probeMemoryEnd(void);
70
71SPR_RW(SPRG0)
72SPR_RW(SPRG1)
73SPR_RO(HID1)
74
75/* Table of PLL multipliers for 7455/7457:
7601000   2     00010   7.5       00000   11.5      00001   17
7710000   3     11000   8         10111   12        00101   18
7810100   4     01100   8.5       11111   12.5      00111   20
7910110   5     01111   9         01011   13        01001   21
8010010   5.5   01110   9.5       11100   13.5      01101   24
8111010   6     10101   10        11001   14        11101   28
8201010   6.5   10001   10.5      00011   15        00110   bypass
8300100   7     10011   11        11011   16        11110   off
84*/
85
86/* Sorted according to CFG bits and multiplied by 2 it looks
87 * like this (note that this is in sequential order, not
88 * tabulated as above)
89 */
90signed char mpc7450PllMultByTwo[32] = {
9123,       34,           15,           30,
9214,       36,           2/*bypass*/,  40,
934,        42,           13,           26,
9417,       48,           19,           18,
956,        21,           11,           22,
968,        20,           10,           24,
9716,       28,           12,           32,
9827,       56,           0/*off*/,     25,
99};
100
101uint32_t bsp_clicks_per_usec         = 0;
102
103/*
104 * Total memory using probing.
105 */
106unsigned int BSP_mem_size;
107
108/*
109 * PCI Bus Frequency
110 */
111unsigned int BSP_bus_frequency       = 0xdeadbeef;
112/*
113 * processor clock frequency
114 */
115unsigned int BSP_processor_frequency = 0xdeadbeef;
116
117/*
118 * Time base divisior (bus freq / TB clock)
119 */
120unsigned int BSP_time_base_divisor   = 4000; /* most 604+ CPUs seem to use this */
121
122/* Board identification string */
123char BSP_productIdent[20] = {0};
124char BSP_serialNumber[20] = {0};
125
126/* VPD appends an extra char -- what for ? */
127char BSP_enetAddr0[7] = {0};
128char BSP_enetAddr1[7] = {0};
129
130char *rtems_progname;
131
132/*
133 *  Use the shared implementations of the following routines
134 */
135 
136extern void bsp_pretasking_hook(void);
137
138#define CMDLINE_BUF_SIZE        2048
139
140static char cmdline_buf[CMDLINE_BUF_SIZE];
141char *BSP_commandline_string = cmdline_buf;
142
143/* this routine is called early and must be safe with a not properly
144 * aligned stack
145 */
146char *save_boot_params(
147  void *r3,
148  void *r4,
149  void *r5,
150  char *cmdline_start,
151  char *cmdline_end
152)
153{
154int             i=cmdline_end-cmdline_start;
155        if ( i >= CMDLINE_BUF_SIZE )
156                i = CMDLINE_BUF_SIZE-1;
157        else if ( i < 0 )
158                i = 0;
159        memmove(cmdline_buf, cmdline_start, i);
160        cmdline_buf[i]=0;
161    return cmdline_buf;
162}
163
164static BSP_BoardType    board_type = Unknown;
165
166BSP_BoardType
167BSP_getBoardType( void )
168{
169        return board_type;
170}
171
172/*
173 *  bsp_start
174 *
175 *  This routine does the bulk of the system initialization.
176 */
177
178void bsp_start( void )
179{
180  unsigned char  *stack;
181  char           *chpt;
182  uint32_t       intrStackStart;
183  uint32_t       intrStackSize;
184
185  Triv121PgTbl  pt=0;
186
187  VpdBufRec vpdData [] = {
188        { key: ProductIdent, instance: 0, buf: BSP_productIdent, buflen: sizeof(BSP_productIdent) - 1 },
189        { key: SerialNumber, instance: 0, buf: BSP_serialNumber, buflen: sizeof(BSP_serialNumber) - 1 },
190        { key: CpuClockHz,   instance: 0, buf: &BSP_processor_frequency, buflen: sizeof(BSP_processor_frequency)  },
191        { key: BusClockHz,   instance: 0, buf: &BSP_bus_frequency, buflen: sizeof(BSP_bus_frequency)  },
192        { key: EthernetAddr, instance: 0, buf: BSP_enetAddr0, buflen: sizeof(BSP_enetAddr0) },
193        { key: EthernetAddr, instance: 1, buf: BSP_enetAddr1, buflen: sizeof(BSP_enetAddr1) },
194        VPD_END
195  };
196
197  /* T. Straumann: 4/2005
198   *
199   * Need to map the system registers early, so we can printk...
200   * (otherwise we silently die)
201   */
202  /* map the PCI 0, 1 Domain I/O space, GT64260B registers
203   * and the reserved area so that the size is the power of 2.
204   */
205  setdbat(7, BSP_DEV_AND_PCI_IO_BASE, BSP_DEV_AND_PCI_IO_BASE, BSP_DEV_AND_PCI_IO_SIZE, IO_PAGE);
206
207  /* Intersperse messages with actions to help locate problems */
208  printk("-----------------------------------------\n");
209
210  /*
211   * Get CPU identification dynamically. Note that the get_ppc_cpu_type() & friends functions
212   * store the result in global variables so that it can be used latter...
213   * This also verifies that we run on a known CPU.
214   */
215  get_ppc_cpu_type();
216  get_ppc_cpu_revision();
217
218  /* Make sure we detect a known host bridge */
219  BSP_getDiscoveryVersion(/* assert detection */ 1);
220
221  printk("Welcome to RTEMS %s\n", _RTEMS_version );
222
223  /* Leave all caches as MotLoad left them. Seems to be fine */
224
225  /*
226   * the initial stack  has aready been set to this value in start.S
227   * so there is no need to set it in r1 again... It is just for info
228   * so that it can be printed without accessing R1.
229   */
230  __asm__ volatile("mr %0, 1":"=r"(stack));
231
232  /* tag the bottom (T. Straumann 6/36/2001 <strauman@slac.stanford.edu>) */
233
234  *((uint32_t *)stack) = 0;
235
236  /*
237   * Initialize the interrupt related settings
238   * SPRG0 = interrupt nesting level count
239   * SPRG1 = software managed IRQ stack
240   *
241   * This could be done latter (e.g in IRQ_INIT) but it helps to understand
242   * some settings below...
243   */
244  intrStackStart = (uint32_t)__rtems_end;
245  intrStackSize  = rtems_configuration_get_interrupt_stack_size();
246
247  /*
248   * Initialize default raw exception handlers. See vectors/vectors_init.c
249   */
250  ppc_exc_initialize(intrStackStart, intrStackSize);
251
252  printk("CPU: %s\n", get_ppc_cpu_type_name(current_ppc_cpu));
253
254  /*
255   * Initialize RTEMS IRQ system
256   */
257   BSP_rtems_irq_mng_init(0);
258
259  BSP_vpdRetrieveFields(vpdData);
260
261  if ( !strncmp(BSP_productIdent,"MVME5500",8) )
262        board_type = MVME5500;
263  else if ( !strncmp(BSP_productIdent,"MVME6100",8) )
264        board_type = MVME6100;
265
266  printk("Board Type: %s (S/N %s)\n",
267                BSP_productIdent[0] ? BSP_productIdent : "n/a",
268                BSP_serialNumber[0] ? BSP_serialNumber : "n/a");
269
270  if ( 0xdeadbeef == BSP_bus_frequency ) {
271        BSP_bus_frequency       = 133333333;
272        printk("Bus Clock Freq NOT FOUND in VPD; using %10u Hz\n",
273                BSP_bus_frequency);
274  } else {
275        printk("Bus Clock Freq:  %10u Hz\n",
276                BSP_bus_frequency);
277  }
278
279  if ( 0xdeadbeef == BSP_processor_frequency ) {
280        BSP_processor_frequency  = BSP_bus_frequency/2;
281        BSP_processor_frequency *= mpc7450PllMultByTwo[ (_read_HID1() >> (31-19)) & 31 ];
282  }
283  printk("CPU Clock Freq:  %10u Hz\n", BSP_processor_frequency);
284       
285  /* probe real memory size; if it's more than 256M we can't currently access it
286   * since at this point only BAT-0 maps 0..256M
287   */
288  BSP_mem_size                          =  probeMemoryEnd();
289
290  if ( (chpt = strstr(BSP_commandline_string,"MEMSZ=")) ) {
291                char            *endp;
292                uint32_t        sz;
293                chpt+=6 /* strlen("MEMSZ=") */;
294                sz = strtoul(chpt, &endp, 0);
295                if ( endp != chpt )
296                        BSP_mem_size = sz;
297  }
298
299  printk("Memory:          %10u bytes\n", BSP_mem_size);
300
301  if ( BSP_mem_size > 0x10000000 ) {
302        uint32_t s;
303        if ( BSP_mem_size > 0x80000000 ) {
304                BSP_mem_size = 0x80000000;
305                printk("Memory clipped to 0x%08x for now, sorry\n", BSP_mem_size);
306        }
307        for ( s = 0x20000000; s < BSP_mem_size ; s<<=1)
308                ;
309        MMUoff();
310        /* since it's currently in use we must first surrender it */
311        setdbat(0, 0, 0, 0, 0);
312        setdbat(0, 0, 0, s, _PAGE_RW);
313        MMUon();
314  }
315
316  printk("-----------------------------------------\n");
317
318  /* Maybe not setup yet because of the warning message */
319
320  /* Allocate and set up the page table mappings
321   * This is only available on >604 CPUs.
322   *
323   * NOTE: This setup routine may modify the available memory
324   *       size. It is essential to call it before
325   *       calculating the workspace etc.
326   */
327  pt = BSP_pgtbl_setup(&BSP_mem_size);
328  if (!pt)
329     printk("WARNING: unable to setup page tables.\n");
330
331#ifdef SHOW_MORE_INIT_SETTINGS
332  printk("Now BSP_mem_size = 0x%x\n",BSP_mem_size);
333#endif
334
335  /*
336   * Set up our hooks
337   */
338
339  bsp_clicks_per_usec = BSP_bus_frequency/(BSP_time_base_divisor * 1000);
340  rtems_counter_initialize_converter(
341    BSP_bus_frequency / (BSP_time_base_divisor / 1000)
342  );
343
344#ifdef SHOW_MORE_INIT_SETTINGS
345  printk(
346    "Configuration.work_space_size = %x\n",
347    rtems_configuration_get_work_space_size()
348  );
349#endif
350
351  /* Activate the page table mappings only after
352   * initializing interrupts because the irq_mng_init()
353   * routine needs to modify the text
354   */           
355  if ( pt ) {
356#ifdef SHOW_MORE_INIT_SETTINGS
357    printk("Page table setup finished; will activate it NOW...\n");
358#endif
359    BSP_pgtbl_activate(pt);
360  }
361
362#ifdef SHOW_MORE_INIT_SETTINGS
363  printk("Going to start PCI buses scanning and initialization\n");
364#endif
365  BSP_pci_initialize();
366
367  /* need to tweak the motload setup */
368  BSP_motload_pci_fixup();
369
370  /* map 512M, 256 for PCI 256 for VME */
371  setdbat(5,BSP_PCI_HOSE0_MEM_BASE, BSP_PCI_HOSE0_MEM_BASE, BSP_PCI_HOSE0_MEM_SIZE, IO_PAGE);
372  setdbat(6,BSP_PCI_HOSE1_MEM_BASE, BSP_PCI_HOSE1_MEM_BASE, 0x10000000, IO_PAGE);
373
374#ifdef SHOW_MORE_INIT_SETTINGS
375  printk("Number of PCI buses found is : %d\n", pci_bus_count());
376#endif
377
378  /*
379   * Initialize hardware timer facility (not used by BSP itself)
380   * Needs PCI to identify discovery version...
381   */
382  BSP_timers_initialize();
383
384#ifdef SHOW_MORE_INIT_SETTINGS
385  printk("MSR %x \n", _read_MSR());
386  printk("Exit from bspstart\n");
387#endif
388}
Note: See TracBrowser for help on using the repository browser.