source: rtems/bsps/powerpc/beatnik/start/bspstart.c

Last change on this file was 4b9b6dd, checked in by Sebastian Huber <sebastian.huber@…>, on May 5, 2020 at 12:34:32 PM

Use rtems_get_version_string()

Update #3970.

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