source: rtems/bsps/powerpc/motorola_powerpc/start/bspstart.c @ a884df3

5
Last change on this file since a884df3 was a884df3, checked in by Sebastian Huber <sebastian.huber@…>, on 04/17/18 at 07:49:49

bsp/motorola_powerpc: Move bspstart.c to bsps

This shared powerpc file was only used by this BSP.

This patch is a part of the BSP source reorganization.

Update #3285.

  • Property mode set to 100644
File size: 9.7 KB
RevLine 
[acc25ee]1/*
[ad38073]2 *  This routine does the bulk of the system initialization.
3 */
4
5/*
[28f398e7]6 *  COPYRIGHT (c) 1989-2007.
[acc25ee]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
[c499856]11 *  http://www.rtems.org/license/LICENSE.
[acc25ee]12 *
13 *  Modified to support the MCP750.
14 *  Modifications Copyright (C) 1999 Eric Valette. valette@crf.canon.fr
15 */
16
17#include <string.h>
[eba2e4f]18
[e79a1947]19#include <bsp.h>
[ad38073]20#include <bsp/bootcard.h>
[d1999c8b]21#include <rtems/bspIo.h>
[24bf11e]22#include <rtems/counter.h>
[acc25ee]23#include <bsp/consoleIo.h>
24#include <libcpu/spr.h>
25#include <bsp/residual.h>
26#include <bsp/pci.h>
27#include <bsp/openpic.h>
28#include <bsp/irq.h>
29#include <libcpu/bat.h>
[4f3e4f33]30#include <libcpu/pte121.h>
[70f1268d]31#include <libcpu/cpuIdent.h>
[acc25ee]32#include <bsp/vectors.h>
33#include <bsp/motorola.h>
[1899fe4]34#include <rtems/powerpc/powerpc.h>
[acc25ee]35
[cc981e1]36extern void _return_to_ppcbug(void);
[64f8ae4]37extern unsigned long __rtems_end[];
[cc981e1]38extern void L1_caches_enables(void);
39extern unsigned get_L2CR(void);
[acc25ee]40extern void set_L2CR(unsigned);
[86939c94]41extern Triv121PgTbl BSP_pgtbl_setup(unsigned int *);
[cc981e1]42extern void                     BSP_pgtbl_activate(Triv121PgTbl);
[4f3e4f33]43
[ec821af]44SPR_RW(SPRG1)
[4f3e4f33]45
[e79a1947]46#if defined(DEBUG_BATS)
[cc981e1]47extern void ShowBATS(void);
[e79a1947]48#endif
49
[28f398e7]50/*
51 *  Driver configuration parameters
52 */
53uint32_t   bsp_clicks_per_usec;
54
[acc25ee]55/*
56 * Copy of residuals passed by firmware
57 */
[6128a4a]58RESIDUAL residualCopy;
[acc25ee]59/*
60 * Copy Additional boot param passed by boot loader
61 */
62#define MAX_LOADER_ADD_PARM 80
63char loaderParam[MAX_LOADER_ADD_PARM];
[1051054]64
65char *BSP_commandline_string = loaderParam;
[acc25ee]66/*
67 * Vital Board data Start using DATA RESIDUAL
68 */
69/*
70 * Total memory using RESIDUAL DATA
71 */
72unsigned int BSP_mem_size;
[db77b92]73
[acc25ee]74/*
75 * PCI Bus Frequency
76 */
77unsigned int BSP_bus_frequency;
78/*
79 * processor clock frequency
80 */
81unsigned int BSP_processor_frequency;
82/*
83 * Time base divisior (how many tick for 1 second).
84 */
85unsigned int BSP_time_base_divisor;
86
87/*
88 *  Use the shared implementations of the following routines
89 */
[6128a4a]90
[9ffca502]91char *save_boot_params(
92  void *r3,
93  void *r4,
94  void *r5,
95  char *cmdline_start,
96  char *cmdline_end
[db77b92]97)
[acc25ee]98{
[6128a4a]99
[9ffca502]100  residualCopy = *(RESIDUAL *)r3;
101  strncpy(loaderParam, cmdline_start, MAX_LOADER_ADD_PARM);
[acc25ee]102  loaderParam[MAX_LOADER_ADD_PARM - 1] ='\0';
[ec625ec]103  return loaderParam;
[acc25ee]104}
105
[416ec41]106#if defined(mvme2100)
[e79a1947]107unsigned int EUMBBAR;
108
[ac7af4a]109/*
[e79a1947]110 * Return the current value of the Embedded Utilities Memory Block Base Address
111 * Register (EUMBBAR) as read from the processor configuration register using
112 * Processor Address Map B (CHRP).
[ac7af4a]113 */
[7294054b]114static unsigned int get_eumbbar(void) {
[2d5c486]115  out_le32( (volatile uint32_t *)0xfec00000, 0x80000078 );
116  return in_le32( (volatile uint32_t *)0xfee00000 );
[e79a1947]117}
118#endif
119
[acc25ee]120/*
121 *  bsp_start
122 *
123 *  This routine does the bulk of the system initialization.
124 */
125
126void bsp_start( void )
127{
[416ec41]128#if !defined(mvme2100)
[acc25ee]129  unsigned l2cr;
[e79a1947]130#endif
[2d2de4eb]131  uintptr_t intrStackStart;
132  uintptr_t intrStackSize;
[acc25ee]133  prep_t boardManufacturer;
134  motorolaBoard myBoard;
[4f3e4f33]135  Triv121PgTbl  pt=0;
[e79a1947]136
[acc25ee]137  /*
[e79a1947]138   * Get CPU identification dynamically. Note that the get_ppc_cpu_type()
[ac7af4a]139   * function store the result in global variables so that it can be used
[e79a1947]140   * later...
[acc25ee]141   */
[c506cc98]142  get_ppc_cpu_type();
143  get_ppc_cpu_revision();
[e79a1947]144
[ab20575]145  /*
146   * Init MMU block address translation to enable hardware access
147   */
148
149#if !defined(mvme2100)
150  /*
151   * PC legacy IO space used for inb/outb and all PC compatible hardware
152   */
153  setdbat(1, _IO_BASE, _IO_BASE, 0x10000000, IO_PAGE);
154#endif
155
156  /*
157   * PCI devices memory area. Needed to access OpenPIC features
158   * provided by the Raven
159   *
160   * T. Straumann: give more PCI address space
161   */
162  setdbat(2, PCI_MEM_BASE+PCI_MEM_WIN0, PCI_MEM_BASE+PCI_MEM_WIN0, 0x10000000, IO_PAGE);
163
164  /*
165   * Must have acces to open pic PCI ACK registers provided by the RAVEN
166   */
[58127230]167#ifndef qemu
[ab20575]168  setdbat(3, 0xf0000000, 0xf0000000, 0x10000000, IO_PAGE);
[58127230]169#else
170  setdbat(3, 0xb0000000, 0xb0000000, 0x10000000, IO_PAGE);
171#endif
[ab20575]172
[e79a1947]173#if defined(mvme2100)
[ab20575]174  /* Need 0xfec00000 mapped for this */
[ac7af4a]175  EUMBBAR = get_eumbbar();
[e79a1947]176#endif
177
[acc25ee]178  /*
179   * enables L1 Cache. Note that the L1_caches_enables() codes checks for
180   * relevant CPU type so that the reason why there is no use of myCpu...
181   */
182  L1_caches_enables();
[e79a1947]183
[4b6692f]184  select_console(CONSOLE_LOG);
185
186  /*
187   * We check that the keyboard is present and immediately
188   * select the serial console if not.
189   */
190#if defined(BSP_KBD_IOBASE)
191  { int err;
192    err = kbdreset();
193    if (err) select_console(CONSOLE_SERIAL);
194  }
195#else
196  select_console(CONSOLE_SERIAL);
197#endif
198
199
[416ec41]200#if !defined(mvme2100)
[acc25ee]201  /*
202   * Enable L2 Cache. Note that the set_L2CR(L2CR) codes checks for
203   * relevant CPU type (mpc750)...
204   */
205  l2cr = get_L2CR();
206#ifdef SHOW_LCR2_REGISTER
207  printk("Initial L2CR value = %x\n", l2cr);
[6128a4a]208#endif
[acc25ee]209  if ( (! (l2cr & 0x80000000)) && ((int) l2cr == -1))
210    set_L2CR(0xb9A14000);
[e79a1947]211#endif
212
[acc25ee]213  /*
[a86f3aac]214   * Initialize the interrupt related settings.
[acc25ee]215   */
[2d2de4eb]216  intrStackStart = (uintptr_t) __rtems_end;
[a86f3aac]217  intrStackSize = rtems_configuration_get_interrupt_stack_size();
[ec821af]218
[acc25ee]219  /*
[a86f3aac]220   * Initialize default raw exception handlers.
[acc25ee]221   */
[801b5d8]222  ppc_exc_initialize(intrStackStart, intrStackSize);
[e79a1947]223
[acc25ee]224  boardManufacturer   =  checkPrepBoardType(&residualCopy);
225  if (boardManufacturer != PREP_Motorola) {
226    printk("Unsupported hardware vendor\n");
227    while (1);
228  }
229  myBoard = getMotorolaBoard();
[6128a4a]230
[acc25ee]231  printk("-----------------------------------------\n");
[e79a1947]232  printk("Welcome to %s on %s\n", _RTEMS_version,
233                                    motorolaBoardToString(myBoard));
[acc25ee]234  printk("-----------------------------------------\n");
[6128a4a]235#ifdef SHOW_MORE_INIT_SETTINGS
[acc25ee]236  printk("Residuals are located at %x\n", (unsigned) &residualCopy);
237  printk("Additionnal boot options are %s\n", loaderParam);
[a86f3aac]238  printk("Software IRQ stack starts at %x with size %u\n", intrStackStart, intrStackSize);
[acc25ee]239  printk("-----------------------------------------\n");
240#endif
241
[6128a4a]242#ifdef TEST_RETURN_TO_PPCBUG
[acc25ee]243  printk("Hit <Enter> to return to PPCBUG monitor\n");
244  printk("When Finished hit GO. It should print <Back from monitor>\n");
245  debug_getc();
246  _return_to_ppcbug();
247  printk("Back from monitor\n");
248  _return_to_ppcbug();
249#endif /* TEST_RETURN_TO_PPCBUG  */
250
251#ifdef SHOW_MORE_INIT_SETTINGS
252  printk("Going to start PCI buses scanning and initialization\n");
[6128a4a]253#endif
[3a3e0b0e]254
[4820d95]255  pci_initialize();
[e79a1947]256  {
257    const struct _int_map *bspmap  = motorolaIntMap(currentBoard);
258    if( bspmap ) {
259       printk("pci : Configuring interrupt routing for '%s'\n",
260          motorolaBoardToString(currentBoard));
261       FixupPCI(bspmap, motorolaIntSwizzle(currentBoard));
[3a3e0b0e]262    }
263    else
264       printk("pci : Interrupt routing not available for this bsp\n");
265 }
266
[acc25ee]267#ifdef SHOW_MORE_INIT_SETTINGS
[548ed3f]268  printk("Number of PCI buses found is : %d\n", pci_bus_count());
[acc25ee]269#endif
[6128a4a]270#ifdef TEST_RAW_EXCEPTION_CODE
[acc25ee]271  printk("Testing exception handling Part 1\n");
272  /*
273   * Cause a software exception
274   */
275  __asm__ __volatile ("sc");
276  /*
[e79a1947]277   * Check we can still catch exceptions and return coorectly.
[acc25ee]278   */
279  printk("Testing exception handling Part 2\n");
280  __asm__ __volatile ("sc");
[e79a1947]281
282  /*
[a86f3aac]283   * Somehow doing the above seems to clobber SPRG0 on the mvme2100.  The
284   * interrupt disable mask is stored in SPRG0. Is this a problem?
[e79a1947]285   */
[a86f3aac]286  ppc_interrupt_set_disable_mask( PPC_INTERRUPT_DISABLE_MASK_DEFAULT);
287
[6128a4a]288#endif
[acc25ee]289
[a86f3aac]290/* See above */
291
[e79a1947]292  BSP_mem_size            = residualCopy.TotalMemory;
293  BSP_bus_frequency       = residualCopy.VitalProductData.ProcessorBusHz;
294  BSP_processor_frequency = residualCopy.VitalProductData.ProcessorHz;
295  BSP_time_base_divisor   = (residualCopy.VitalProductData.TimeBaseDivisor?
296                    residualCopy.VitalProductData.TimeBaseDivisor : 4000);
[4f3e4f33]297
[674b9497]298  /* clear hostbridge errors but leave MCP disabled -
299   * PCI config space scanning code will trip otherwise :-(
300   */
301  _BSP_clear_hostbridge_errors(0 /* enableMCP */, 0/*quiet*/);
[14ec2d4]302
[5cf0656]303  if (BSP_mem_size > 0x10000000)
304  {
305    /* Support cases of system memory size larger than 256Mb.
306     *
307     * We use BAT3 in order to obtain access to the top section of the RAM.
308     * We also need to do this just before setting up the page table because
309     * this is where the page table will be located.
310     */
311    const unsigned int mem256Count = (BSP_mem_size / 0x10000000);
312    const unsigned int BAT3Addr    = ((BSP_mem_size % 0x10000000)  ?
313                                       (mem256Count     * 0x10000000) :
314                                      ((mem256Count-1) * 0x10000000));
315    setdbat(3, BAT3Addr, BAT3Addr, 0x10000000, IO_PAGE);
316#ifdef SHOW_MORE_INIT_SETTINGS
317    printk("Setting up BAT3 for large memory support. (BAT3 --> 0x%x)\n", BAT3Addr);
318#endif
319  }
320
[4f3e4f33]321  /* Allocate and set up the page table mappings
322   * This is only available on >604 CPUs.
323   *
324   * NOTE: This setup routine may modify the available memory
325   *       size. It is essential to call it before
326   *       calculating the workspace etc.
327   */
328  pt = BSP_pgtbl_setup(&BSP_mem_size);
329
[e79a1947]330  if (!pt || TRIV121_MAP_SUCCESS != triv121PgTblMap(
[58127230]331            pt, TRIV121_121_VSID,
332#ifndef qemu
333            0xfeff0000,
334#else
335            0xbffff000,
336#endif
337            1,
[e79a1947]338            TRIV121_ATTR_IO_PAGE, TRIV121_PP_RW_PAGE)) {
339        printk("WARNING: unable to setup page tables VME "
340               "bridge must share PCI space\n");
[4f3e4f33]341  }
[6128a4a]342
[acc25ee]343  /*
[7321ff0]344   *  initialize the device driver parameters
[acc25ee]345   */
[28f398e7]346  bsp_clicks_per_usec    = BSP_bus_frequency/(BSP_time_base_divisor * 1000);
[24bf11e]347  rtems_counter_initialize_converter(
348    BSP_bus_frequency / (BSP_time_base_divisor / 1000)
349  );
[acc25ee]350
351  /*
352   * Initalize RTEMS IRQ system
353   */
354  BSP_rtems_irq_mng_init(0);
[4f3e4f33]355
356  /* Activate the page table mappings only after
357   * initializing interrupts because the irq_mng_init()
358   * routine needs to modify the text
[6128a4a]359   */
[4f3e4f33]360  if (pt) {
361#ifdef  SHOW_MORE_INIT_SETTINGS
362    printk("Page table setup finished; will activate it NOW...\n");
363#endif
364    BSP_pgtbl_activate(pt);
[e79a1947]365    /* finally, switch off DBAT3 */
[ac7af4a]366    setdbat(3, 0, 0, 0, 0);
[4f3e4f33]367  }
368
[e79a1947]369#if defined(DEBUG_BATS)
370  ShowBATS();
371#endif
372
[acc25ee]373#ifdef SHOW_MORE_INIT_SETTINGS
374  printk("Exit from bspstart\n");
[6128a4a]375#endif
[acc25ee]376}
Note: See TracBrowser for help on using the repository browser.