source: rtems/bsps/powerpc/mvme5500/start/bspstart.c @ 762fa62

5
Last change on this file since 762fa62 was 65f868c, checked in by Sebastian Huber <sebastian.huber@…>, on 05/23/18 at 12:17:25

Add _CPU_Counter_frequency()

Add rtems_counter_frequency() API function. Use it to initialize the
counter value converter via the new system initialization step
(RTEMS_SYSINIT_CPU_COUNTER). This decouples the counter implementation
and the counter converter. It avoids an unnecessary pull in of the
64-bit integer division from libgcc.

Update #3456.

  • Property mode set to 100644
File size: 9.2 KB
Line 
1/*
2 *  This routine does the bulk of the system initialization.
3 */
4
5/*
6 *  COPYRIGHT (c) 1989-2007.
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 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 board.
20 *  Also, the settings of L1, L2, and L3 caches is not necessary here.
21 *  (C) by Brookhaven National Lab., S. Kate Feng <feng1@bnl.gov>, 2003-2009
22 */
23
24#include <string.h>
25#include <stdlib.h>
26#include <ctype.h>
27
28#include <rtems/sysinit.h>
29#include <rtems/system.h>
30#include <rtems/powerpc/powerpc.h>
31
32#include <libcpu/spr.h>   /* registers.h is included here */
33#include <bsp.h>
34#include <bsp/bootcard.h>
35#include <bsp/uart.h>
36#include <bsp/pci.h>
37#include <libcpu/bat.h>
38#include <libcpu/pte121.h>
39#include <libcpu/cpuIdent.h>
40#include <bsp/vectors.h>
41#include <bsp/VME.h>
42#include <bsp/bspException.h>
43
44#include <rtems/bspIo.h>
45#include <rtems/counter.h>
46
47/*
48#define SHOW_MORE_INIT_SETTINGS
49#define SHOW_LCR1_REGISTER
50#define SHOW_LCR2_REGISTER
51#define SHOW_LCR3_REGISTER
52#define CONF_VPD
53*/
54
55extern uint32_t probeMemoryEnd(void); /* from shared/startup/probeMemoryEnd.c */
56
57BSP_output_char_function_type     BSP_output_char = BSP_output_char_via_serial;
58BSP_polling_getchar_function_type BSP_poll_char = NULL;
59
60extern void _return_to_ppcbug(void);
61extern unsigned long __rtems_end[];
62extern unsigned get_L1CR(void), get_L2CR(void), get_L3CR(void);
63extern Triv121PgTbl BSP_pgtbl_setup(unsigned int *);
64extern void BSP_pgtbl_activate(Triv121PgTbl);
65extern int I2Cread_eeprom(unsigned char I2cBusAddr, uint32_t devA2A1A0, uint32_t AddrBytes, unsigned char *pBuff, uint32_t numBytes);
66extern void BSP_vme_config(void);
67
68extern unsigned char ReadConfVPD_buff(int offset);
69
70uint32_t bsp_clicks_per_usec;
71
72typedef struct CmdLineRec_ {
73    unsigned long  size;
74    char           buf[0];
75} CmdLineRec, *CmdLine;
76
77
78#define mtspr(reg, val)  \
79  __asm __volatile("mtspr %0,%1" : : "K"(reg), "r"(val))
80
81
82#define mfspr(reg) \
83  ( { unsigned val; \
84    __asm __volatile("mfspr %0,%1" : "=r"(val) : "K"(reg)); \
85    val; } )
86
87/*
88 * Copy Additional boot param passed by boot loader
89 */
90#define MAX_LOADER_ADD_PARM 80
91char loaderParam[MAX_LOADER_ADD_PARM];
92
93/*
94 * Total memory using RESIDUAL DATA
95 */
96unsigned int BSP_mem_size;
97/*
98 * PCI Bus Frequency
99 */
100unsigned int BSP_bus_frequency;
101/*
102 * processor clock frequency
103 */
104unsigned int BSP_processor_frequency;
105/*
106 * Time base divisior (how many tick for 1 second).
107 */
108unsigned int BSP_time_base_divisor;
109static unsigned char ConfVPD_buff[200];
110
111#define CMDLINE_BUF_SIZE  2048
112
113static char cmdline_buf[CMDLINE_BUF_SIZE];
114char *BSP_commandline_string = cmdline_buf;
115
116/* NOTE: we cannot simply malloc the commandline string;
117 * save_boot_params() is called during a very early stage when
118 * libc/malloc etc. are not yet initialized!
119 *
120 * Here's what we do:
121 *
122 * initial layout setup by the loader (preload.S):
123 *
124 * 0..RTEMS...__rtems_end | cmdline ....... TOP
125 *
126 * After the save_boot_params() routine returns, the stack area will be
127 * set up (start.S):
128 *
129 * 0..RTEMS..__rtems_end | INIT_STACK | IRQ_STACK | ..... TOP
130 *
131 * initialize_executive_early() [called from boot_card()]
132 * will initialize the workspace:
133 *
134 * 0..RTEMS..__rtems_end | INIT_STACK | IRQ_STACK | ...... | workspace | TOP
135 *
136 * and later calls our bsp_predriver_hook() which ends up initializing
137 * libc which in turn initializes the heap
138 *
139 * 0..RTEMS..__rtems_end | INIT_STACK | IRQ_STACK | heap | workspace | TOP
140 *
141 * The idea here is to first move the commandline to the future 'heap' area
142 * from where it will be picked up by our bsp_predriver_hook().
143 * bsp_predriver_hook() then moves it either to INIT_STACK or the workspace
144 * area using proper allocation, initializes libc and finally moves
145 * the data to the environment / malloced areas...
146 */
147
148/* this routine is called early at shared/start/start.S
149 * and must be safe with a not properly aligned stack
150 */
151char *
152save_boot_params(
153  void *r3,
154  void *r4,
155  void* r5,
156  char *cmdline_start,
157  char *cmdline_end
158)
159{
160  int i=cmdline_end-cmdline_start;
161
162  if ( i >= CMDLINE_BUF_SIZE )
163    i = CMDLINE_BUF_SIZE-1;
164  else if ( i < 0 )
165    i = 0;
166
167  memmove(cmdline_buf, cmdline_start, i);
168  cmdline_buf[i]=0;
169  return cmdline_buf;
170}
171
172uint32_t _CPU_Counter_frequency(void)
173{
174  return BSP_bus_frequency / (BSP_time_base_divisor / 1000);
175}
176
177void bsp_start( void )
178{
179#ifdef CONF_VPD
180  int i;
181#endif
182#ifdef SHOW_LCR1_REGISTER
183  unsigned l1cr;
184#endif
185#ifdef SHOW_LCR2_REGISTER
186  unsigned l2cr;
187#endif
188#ifdef SHOW_LCR3_REGISTER
189  unsigned l3cr;
190#endif
191  uintptr_t intrStackStart;
192  uintptr_t intrStackSize;
193  Triv121PgTbl  pt=0;
194
195  /* Till Straumann: 4/2005
196   * Need to map the system registers early, so we can printk...
197   * (otherwise we silently die)
198   */
199  /*
200   * Kate Feng : PCI 0 domain memory space, want to leave room for the VME window
201   */
202  setdbat(2, PCI0_MEM_BASE, PCI0_MEM_BASE, 0x10000000, IO_PAGE);
203
204  /* Till Straumann: 2004
205   * map the PCI 0, 1 Domain I/O space, GT64260B registers
206   * and the reserved area so that the size is the power of 2.
207   * 2009 : map the entire 256 M space
208   *
209   */
210  setdbat(3,PCI0_IO_BASE, PCI0_IO_BASE, 0x10000000, IO_PAGE);
211
212
213  /*
214   * Get CPU identification dynamically. Note that the get_ppc_cpu_type()
215   * function store the result in global variables so that it can be used later.
216   */
217  get_ppc_cpu_type();
218  get_ppc_cpu_revision();
219
220#ifdef SHOW_LCR1_REGISTER
221  l1cr = get_L1CR();
222  printk("Initial L1CR value = %x\n", l1cr);
223#endif
224
225  /*
226   * Initialize the interrupt related settings.
227   */
228  intrStackStart = (uintptr_t) __rtems_end;
229  intrStackSize = rtems_configuration_get_interrupt_stack_size();
230
231  /*
232   * Initialize default raw exception handlers.
233   */
234  ppc_exc_initialize(intrStackStart, intrStackSize);
235
236  /*
237   * Init MMU block address translation to enable hardware
238   * access
239   * More PCI1 memory mapping to be done after BSP_pgtbl_activate.
240   */
241  printk("-----------------------------------------\n");
242  printk("Welcome to %s on MVME5500-0163\n", _RTEMS_version );
243  printk("-----------------------------------------\n");
244
245  BSP_mem_size         =  probeMemoryEnd();
246
247  /* TODO: calculate the BSP_bus_frequency using the REF_CLK bit
248   *       of System Status  register
249   */
250  /* rtems_bsp_delay_in_bus_cycles are defined in registers.h */
251  BSP_bus_frequency      = 133333333;
252  BSP_processor_frequency    = 1000000000;
253  /* P94 : 7455 clocks the TB/DECR at 1/4 of the system bus clock frequency */
254  BSP_time_base_divisor      = 4000;
255
256  /* Maybe not setup yet becuase of the warning message */
257  /* Allocate and set up the page table mappings
258   * This is only available on >604 CPUs.
259   *
260   * NOTE: This setup routine may modify the available memory
261   *       size. It is essential to call it before
262   *       calculating the workspace etc.
263   */
264  pt = BSP_pgtbl_setup(&BSP_mem_size);
265  if (!pt)
266     printk("WARNING: unable to setup page tables.\n");
267
268  printk("Now BSP_mem_size = 0x%x\n",BSP_mem_size);
269
270  /* P94 : 7455 TB/DECR is clocked by the system bus clock frequency */
271
272  bsp_clicks_per_usec    = BSP_bus_frequency/(BSP_time_base_divisor * 1000);
273
274  /*
275   * Initalize RTEMS IRQ system
276   */
277   BSP_rtems_irq_mng_init(0);
278
279#ifdef SHOW_LCR2_REGISTER
280  l2cr = get_L2CR();
281  printk("Initial L2CR value = %x\n", l2cr);
282#endif
283
284#ifdef SHOW_LCR3_REGISTER
285  /* L3CR needs DEC int. handler installed for bsp_delay()*/
286  l3cr = get_L3CR();
287  printk("Initial L3CR value = %x\n", l3cr);
288#endif
289
290
291  /* Activate the page table mappings only after
292   * initializing interrupts because the irq_mng_init()
293   * routine needs to modify the text
294   */
295  if (pt) {
296#ifdef SHOW_MORE_INIT_SETTINGS
297    printk("Page table setup finished; will activate it NOW...\n");
298#endif
299    BSP_pgtbl_activate(pt);
300  }
301  /* Read Configuration Vital Product Data (VPD) */
302  if ( I2Cread_eeprom(0xa8, 4,2, &ConfVPD_buff[0], 150))
303     printk("I2Cread_eeprom() error \n");
304  else {
305#ifdef CONF_VPD
306    printk("\n");
307    for (i=0; i<150; i++) {
308      printk("%2x ", ConfVPD_buff[i]);
309      if ((i % 20)==0 ) printk("\n");
310    }
311    printk("\n");
312#endif
313  }
314
315  /*
316   * PCI 1 domain memory space
317   */
318  setdbat(1, PCI1_MEM_BASE, PCI1_MEM_BASE, 0x10000000, IO_PAGE);
319
320
321#ifdef SHOW_MORE_INIT_SETTINGS
322  printk("Going to start PCI buses scanning and initialization\n");
323#endif
324  pci_initialize();
325#ifdef SHOW_MORE_INIT_SETTINGS
326  printk("Number of PCI buses found is : %d\n", pci_bus_count());
327#endif
328
329  /* Install our own exception handler (needs PCI) */
330  globalExceptHdl = BSP_exceptionHandler;
331
332  /* clear hostbridge errors. MCP signal is not used on the MVME5500
333   * PCI config space scanning code will trip otherwise :-(
334   */
335  _BSP_clear_hostbridge_errors(0, 1 /*quiet*/);
336
337#ifdef SHOW_MORE_INIT_SETTINGS
338  printk("MSR %x \n", _read_MSR());
339  printk("Exit from bspstart\n");
340#endif
341
342}
343
344unsigned char ReadConfVPD_buff(int offset)
345{
346  return(ConfVPD_buff[offset]);
347}
348
349RTEMS_SYSINIT_ITEM(
350  BSP_vme_config,
351  RTEMS_SYSINIT_BSP_PRE_DRIVERS,
352  RTEMS_SYSINIT_ORDER_MIDDLE
353);
Note: See TracBrowser for help on using the repository browser.