Commit c821b5f120bedf73867513466412587c6912a8f8

Authored by Grant Erickson
Committed by Stefan Roese
1 parent a439680019

ppc4xx: Enable Primordial Stack for 40x and Unify ECC Handling

This patch (Part 1 of 2):

* Rolls up a suite of changes to enable correct primordial stack and
  global data handling when the data cache is used for such a purpose
  for PPC40x-variants (i.e. CFG_INIT_DCACHE_CS).

* Related to the first, unifies DDR2 SDRAM and ECC initialization by
  eliminating redundant ECC initialization implementations and moving
  redundant SDRAM initialization out of board code into shared 4xx
  code.

* Enables MCSR visibility on the 405EX(r).

* Enables the use of the data cache for initial RAM on
  both AMCC's Kilauea and Makalu and removes a redundant
  CFG_POST_MEMORY flag from each board's CONFIG_POST value.

  - Removed, per Stefan Roese's request, defunct memory.c file for
    Makalu and rolled sdram_init from it into makalu.c.

With respect to the 4xx DDR initialization and ECC unification, there
is certainly more work that can and should be done (file renaming,
etc.). However, that can be handled at a later date on a second or
third pass. As it stands, this patch moves things forward in an
incremental yet positive way for those platforms that utilize this
code and the features associated with it.

Signed-off-by: Grant Erickson <gerickson@nuovations.com>
Signed-off-by: Stefan Roese <sr@denx.de>

Showing 12 changed files with 723 additions and 274 deletions Side-by-side Diff

cpu/ppc4xx/44x_spd_ddr.c
... ... @@ -53,6 +53,8 @@
53 53 #include <ppc4xx.h>
54 54 #include <asm/mmu.h>
55 55  
  56 +#include "ecc.h"
  57 +
56 58 #if defined(CONFIG_SPD_EEPROM) && \
57 59 (defined(CONFIG_440GP) || defined(CONFIG_440GX) || \
58 60 defined(CONFIG_440EP) || defined(CONFIG_440GR))
... ... @@ -296,10 +298,6 @@
296 298 unsigned long num_dimm_banks);
297 299 static void program_tr1(void);
298 300  
299   -#ifdef CONFIG_DDR_ECC
300   -static void program_ecc(unsigned long num_bytes);
301   -#endif
302   -
303 301 static unsigned long program_bxcr(unsigned long *dimm_populated,
304 302 unsigned char *iic0_dimm_addr,
305 303 unsigned long num_dimm_banks);
... ... @@ -418,7 +416,7 @@
418 416 /*
419 417 * If ecc is enabled, initialize the parity bits.
420 418 */
421   - program_ecc(total_size);
  419 + ecc_init(CFG_SDRAM_BASE, total_size);
422 420 #endif
423 421  
424 422 return total_size;
... ... @@ -1402,46 +1400,5 @@
1402 1400  
1403 1401 return(bank_base_addr);
1404 1402 }
1405   -
1406   -#ifdef CONFIG_DDR_ECC
1407   -static void program_ecc(unsigned long num_bytes)
1408   -{
1409   - unsigned long bank_base_addr;
1410   - unsigned long current_address;
1411   - unsigned long end_address;
1412   - unsigned long address_increment;
1413   - unsigned long cfg0;
1414   -
1415   - /*
1416   - * get Memory Controller Options 0 data
1417   - */
1418   - mfsdram(mem_cfg0, cfg0);
1419   -
1420   - /*
1421   - * reset the bank_base address
1422   - */
1423   - bank_base_addr = CFG_SDRAM_BASE;
1424   -
1425   - if ((cfg0 & SDRAM_CFG0_MCHK_MASK) != SDRAM_CFG0_MCHK_NON) {
1426   - mtsdram(mem_cfg0, (cfg0 & ~SDRAM_CFG0_MCHK_MASK) | SDRAM_CFG0_MCHK_GEN);
1427   -
1428   - if ((cfg0 & SDRAM_CFG0_DMWD_MASK) == SDRAM_CFG0_DMWD_32)
1429   - address_increment = 4;
1430   - else
1431   - address_increment = 8;
1432   -
1433   - current_address = (unsigned long)(bank_base_addr);
1434   - end_address = (unsigned long)(bank_base_addr) + num_bytes;
1435   -
1436   - while (current_address < end_address) {
1437   - *((unsigned long*)current_address) = 0x00000000;
1438   - current_address += address_increment;
1439   - }
1440   -
1441   - mtsdram(mem_cfg0, (cfg0 & ~SDRAM_CFG0_MCHK_MASK) |
1442   - SDRAM_CFG0_MCHK_CHK);
1443   - }
1444   -}
1445   -#endif /* CONFIG_DDR_ECC */
1446 1403 #endif /* CONFIG_SPD_EEPROM */
cpu/ppc4xx/44x_spd_ddr2.c
... ... @@ -3,9 +3,12 @@
3 3 * This SPD SDRAM detection code supports AMCC PPC44x cpu's with a
4 4 * DDR2 controller (non Denali Core). Those currently are:
5 5 *
6   - * 405: 405EX
  6 + * 405: 405EX(r)
7 7 * 440/460: 440SP/440SPe/460EX/460GT
8 8 *
  9 + * Copyright (c) 2008 Nuovation System Designs, LLC
  10 + * Grant Erickson <gerickson@nuovations.com>
  11 +
9 12 * (C) Copyright 2007-2008
10 13 * Stefan Roese, DENX Software Engineering, sr@denx.de.
11 14 *
... ... @@ -45,6 +48,8 @@
45 48 #include <asm/mmu.h>
46 49 #include <asm/cache.h>
47 50  
  51 +#include "ecc.h"
  52 +
48 53 #if defined(CONFIG_SPD_EEPROM) && \
49 54 (defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
50 55 defined(CONFIG_460EX) || defined(CONFIG_460GT))
51 56  
... ... @@ -3064,10 +3069,117 @@
3064 3069 dcr_data = mfdcr(SDRAM_R3BAS);
3065 3070 printf(" MQ3_B0BAS = 0x%08X\n", dcr_data);
3066 3071 }
3067   -#else
  3072 +#else /* !defined(DEBUG) */
3068 3073 static void ppc440sp_sdram_register_dump(void)
3069 3074 {
3070 3075 }
3071   -#endif
3072   -#endif /* CONFIG_SPD_EEPROM */
  3076 +#endif /* defined(DEBUG) */
  3077 +#elif defined(CONFIG_405EX)
  3078 +/*-----------------------------------------------------------------------------
  3079 + * Function: initdram
  3080 + * Description: Configures the PPC405EX(r) DDR1/DDR2 SDRAM memory
  3081 + * banks. The configuration is performed using static, compile-
  3082 + * time parameters.
  3083 + *---------------------------------------------------------------------------*/
  3084 +long initdram(int board_type)
  3085 +{
  3086 + unsigned long val;
  3087 +
  3088 + /* Set Memory Bank Configuration Registers */
  3089 +
  3090 + mtsdram(SDRAM_MB0CF, CFG_SDRAM0_MB0CF);
  3091 + mtsdram(SDRAM_MB1CF, CFG_SDRAM0_MB1CF);
  3092 + mtsdram(SDRAM_MB2CF, CFG_SDRAM0_MB2CF);
  3093 + mtsdram(SDRAM_MB3CF, CFG_SDRAM0_MB3CF);
  3094 +
  3095 + /* Set Memory Clock Timing Register */
  3096 +
  3097 + mtsdram(SDRAM_CLKTR, CFG_SDRAM0_CLKTR);
  3098 +
  3099 + /* Set Refresh Time Register */
  3100 +
  3101 + mtsdram(SDRAM_RTR, CFG_SDRAM0_RTR);
  3102 +
  3103 + /* Set SDRAM Timing Registers */
  3104 +
  3105 + mtsdram(SDRAM_SDTR1, CFG_SDRAM0_SDTR1);
  3106 + mtsdram(SDRAM_SDTR2, CFG_SDRAM0_SDTR2);
  3107 + mtsdram(SDRAM_SDTR3, CFG_SDRAM0_SDTR3);
  3108 +
  3109 + /* Set Mode and Extended Mode Registers */
  3110 +
  3111 + mtsdram(SDRAM_MMODE, CFG_SDRAM0_MMODE);
  3112 + mtsdram(SDRAM_MEMODE, CFG_SDRAM0_MEMODE);
  3113 +
  3114 + /* Set Memory Controller Options 1 Register */
  3115 +
  3116 + mtsdram(SDRAM_MCOPT1, CFG_SDRAM0_MCOPT1);
  3117 +
  3118 + /* Set Manual Initialization Control Registers */
  3119 +
  3120 + mtsdram(SDRAM_INITPLR0, CFG_SDRAM0_INITPLR0);
  3121 + mtsdram(SDRAM_INITPLR1, CFG_SDRAM0_INITPLR1);
  3122 + mtsdram(SDRAM_INITPLR2, CFG_SDRAM0_INITPLR2);
  3123 + mtsdram(SDRAM_INITPLR3, CFG_SDRAM0_INITPLR3);
  3124 + mtsdram(SDRAM_INITPLR4, CFG_SDRAM0_INITPLR4);
  3125 + mtsdram(SDRAM_INITPLR5, CFG_SDRAM0_INITPLR5);
  3126 + mtsdram(SDRAM_INITPLR6, CFG_SDRAM0_INITPLR6);
  3127 + mtsdram(SDRAM_INITPLR7, CFG_SDRAM0_INITPLR7);
  3128 + mtsdram(SDRAM_INITPLR8, CFG_SDRAM0_INITPLR8);
  3129 + mtsdram(SDRAM_INITPLR9, CFG_SDRAM0_INITPLR9);
  3130 + mtsdram(SDRAM_INITPLR10, CFG_SDRAM0_INITPLR10);
  3131 + mtsdram(SDRAM_INITPLR11, CFG_SDRAM0_INITPLR11);
  3132 + mtsdram(SDRAM_INITPLR12, CFG_SDRAM0_INITPLR12);
  3133 + mtsdram(SDRAM_INITPLR13, CFG_SDRAM0_INITPLR13);
  3134 + mtsdram(SDRAM_INITPLR14, CFG_SDRAM0_INITPLR14);
  3135 + mtsdram(SDRAM_INITPLR15, CFG_SDRAM0_INITPLR15);
  3136 +
  3137 + /* Set On-Die Termination Registers */
  3138 +
  3139 + mtsdram(SDRAM_CODT, CFG_SDRAM0_CODT);
  3140 + mtsdram(SDRAM_MODT0, CFG_SDRAM0_MODT0);
  3141 + mtsdram(SDRAM_MODT1, CFG_SDRAM0_MODT1);
  3142 +
  3143 + /* Set Write Timing Register */
  3144 +
  3145 + mtsdram(SDRAM_WRDTR, CFG_SDRAM0_WRDTR);
  3146 +
  3147 + /*
  3148 + * Start Initialization by SDRAM0_MCOPT2[SREN] = 0 and
  3149 + * SDRAM0_MCOPT2[IPTR] = 1
  3150 + */
  3151 +
  3152 + mtsdram(SDRAM_MCOPT2, (SDRAM_MCOPT2_SREN_EXIT |
  3153 + SDRAM_MCOPT2_IPTR_EXECUTE));
  3154 +
  3155 + /*
  3156 + * Poll SDRAM0_MCSTAT[MIC] for assertion to indicate the
  3157 + * completion of initialization.
  3158 + */
  3159 +
  3160 + do {
  3161 + mfsdram(SDRAM_MCSTAT, val);
  3162 + } while ((val & SDRAM_MCSTAT_MIC_MASK) != SDRAM_MCSTAT_MIC_COMP);
  3163 +
  3164 + /* Set Delay Control Registers */
  3165 +
  3166 + mtsdram(SDRAM_DLCR, CFG_SDRAM0_DLCR);
  3167 + mtsdram(SDRAM_RDCC, CFG_SDRAM0_RDCC);
  3168 + mtsdram(SDRAM_RQDC, CFG_SDRAM0_RQDC);
  3169 + mtsdram(SDRAM_RFDC, CFG_SDRAM0_RFDC);
  3170 +
  3171 + /*
  3172 + * Enable Controller by SDRAM0_MCOPT2[DCEN] = 1:
  3173 + */
  3174 +
  3175 + mfsdram(SDRAM_MCOPT2, val);
  3176 + mtsdram(SDRAM_MCOPT2, val | SDRAM_MCOPT2_DCEN_ENABLE);
  3177 +
  3178 +#if defined(CONFIG_DDR_ECC)
  3179 + ecc_init(CFG_SDRAM_BASE, CFG_MBYTES_SDRAM << 20);
  3180 +#endif /* defined(CONFIG_DDR_ECC) */
  3181 +
  3182 + return (CFG_MBYTES_SDRAM << 20);
  3183 +}
  3184 +#endif /* defined(CONFIG_SPD_EEPROM) && defined(CONFIG_440SP) || ... */
... ... @@ -45,6 +45,7 @@
45 45 COBJS += cpu_init.o
46 46 COBJS += denali_data_eye.o
47 47 COBJS += denali_spd_ddr2.o
  48 +COBJS += ecc.o
48 49 COBJS += fdt.o
49 50 COBJS += gpio.o
50 51 COBJS += i2c.o
cpu/ppc4xx/cpu_init.c
... ... @@ -32,73 +32,6 @@
32 32 DECLARE_GLOBAL_DATA_PTR;
33 33 #endif
34 34  
35   -#ifdef CFG_INIT_DCACHE_CS
36   -# if (CFG_INIT_DCACHE_CS == 0)
37   -# define PBxAP pb0ap
38   -# define PBxCR pb0cr
39   -# if (defined(CFG_EBC_PB0AP) && defined(CFG_EBC_PB0CR))
40   -# define PBxAP_VAL CFG_EBC_PB0AP
41   -# define PBxCR_VAL CFG_EBC_PB0CR
42   -# endif
43   -# endif
44   -# if (CFG_INIT_DCACHE_CS == 1)
45   -# define PBxAP pb1ap
46   -# define PBxCR pb1cr
47   -# if (defined(CFG_EBC_PB1AP) && defined(CFG_EBC_PB1CR))
48   -# define PBxAP_VAL CFG_EBC_PB1AP
49   -# define PBxCR_VAL CFG_EBC_PB1CR
50   -# endif
51   -# endif
52   -# if (CFG_INIT_DCACHE_CS == 2)
53   -# define PBxAP pb2ap
54   -# define PBxCR pb2cr
55   -# if (defined(CFG_EBC_PB2AP) && defined(CFG_EBC_PB2CR))
56   -# define PBxAP_VAL CFG_EBC_PB2AP
57   -# define PBxCR_VAL CFG_EBC_PB2CR
58   -# endif
59   -# endif
60   -# if (CFG_INIT_DCACHE_CS == 3)
61   -# define PBxAP pb3ap
62   -# define PBxCR pb3cr
63   -# if (defined(CFG_EBC_PB3AP) && defined(CFG_EBC_PB3CR))
64   -# define PBxAP_VAL CFG_EBC_PB3AP
65   -# define PBxCR_VAL CFG_EBC_PB3CR
66   -# endif
67   -# endif
68   -# if (CFG_INIT_DCACHE_CS == 4)
69   -# define PBxAP pb4ap
70   -# define PBxCR pb4cr
71   -# if (defined(CFG_EBC_PB4AP) && defined(CFG_EBC_PB4CR))
72   -# define PBxAP_VAL CFG_EBC_PB4AP
73   -# define PBxCR_VAL CFG_EBC_PB4CR
74   -# endif
75   -# endif
76   -# if (CFG_INIT_DCACHE_CS == 5)
77   -# define PBxAP pb5ap
78   -# define PBxCR pb5cr
79   -# if (defined(CFG_EBC_PB5AP) && defined(CFG_EBC_PB5CR))
80   -# define PBxAP_VAL CFG_EBC_PB5AP
81   -# define PBxCR_VAL CFG_EBC_PB5CR
82   -# endif
83   -# endif
84   -# if (CFG_INIT_DCACHE_CS == 6)
85   -# define PBxAP pb6ap
86   -# define PBxCR pb6cr
87   -# if (defined(CFG_EBC_PB6AP) && defined(CFG_EBC_PB6CR))
88   -# define PBxAP_VAL CFG_EBC_PB6AP
89   -# define PBxCR_VAL CFG_EBC_PB6CR
90   -# endif
91   -# endif
92   -# if (CFG_INIT_DCACHE_CS == 7)
93   -# define PBxAP pb7ap
94   -# define PBxCR pb7cr
95   -# if (defined(CFG_EBC_PB7AP) && defined(CFG_EBC_PB7CR))
96   -# define PBxAP_VAL CFG_EBC_PB7AP
97   -# define PBxCR_VAL CFG_EBC_PB7CR
98   -# endif
99   -# endif
100   -#endif /* CFG_INIT_DCACHE_CS */
101   -
102 35 #ifndef CFG_PLL_RECONFIG
103 36 #define CFG_PLL_RECONFIG 0
104 37 #endif
... ... @@ -352,24 +285,6 @@
352 285 #if defined(CONFIG_405GP)
353 286 uint pvr = get_pvr();
354 287 #endif
355   -
356   -#ifdef CFG_INIT_DCACHE_CS
357   - /*
358   - * Flush and invalidate dcache, then disable CS for temporary stack.
359   - * Afterwards, this CS can be used for other purposes
360   - */
361   - dcache_disable(); /* flush and invalidate dcache */
362   - mtebc(PBxAP, 0);
363   - mtebc(PBxCR, 0); /* disable CS for temporary stack */
364   -
365   -#if (defined(PBxAP_VAL) && defined(PBxCR_VAL))
366   - /*
367   - * Write new value into CS register
368   - */
369   - mtebc(PBxAP, PBxAP_VAL);
370   - mtebc(PBxCR, PBxCR_VAL);
371   -#endif
372   -#endif /* CFG_INIT_DCACHE_CS */
373 288  
374 289 /*
375 290 * Write Ethernetaddress into on-chip register
  1 +/*
  2 + * Copyright (c) 2008 Nuovation System Designs, LLC
  3 + * Grant Erickson <gerickson@nuovations.com>
  4 + *
  5 + * (C) Copyright 2005-2007
  6 + * Stefan Roese, DENX Software Engineering, sr@denx.de.
  7 + *
  8 + * (C) Copyright 2002
  9 + * Jun Gu, Artesyn Technology, jung@artesyncp.com
  10 + *
  11 + * (C) Copyright 2001
  12 + * Bill Hunter, Wave 7 Optics, williamhunter@attbi.com
  13 + *
  14 + * See file CREDITS for list of people who contributed to this
  15 + * project.
  16 + *
  17 + * This program is free software; you can redistribute it and/or
  18 + * modify it under the terms of the GNU General Public License as
  19 + * published by the Free Software Foundation; either version 2 of
  20 + * the License, or (at your option) any later version.
  21 + *
  22 + * This program is distributed in the hope that it will abe useful,
  23 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25 + * GNU General Public License for more details.
  26 + *
  27 + * You should have received a copy of the GNU General Public License
  28 + * along with this program; if not, write to the Free Software
  29 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  30 + * MA 02111-1307 USA
  31 + *
  32 + * Description:
  33 + * This file implements generic DRAM ECC initialization for
  34 + * PowerPC processors using a SDRAM DDR/DDR2 controller,
  35 + * including the 405EX(r), 440GP/GX/EP/GR, 440SP(E), and
  36 + * 460EX/GT.
  37 + */
  38 +
  39 +#include <common.h>
  40 +#include <ppc4xx.h>
  41 +#include <ppc_asm.tmpl>
  42 +#include <ppc_defs.h>
  43 +#include <asm/processor.h>
  44 +#include <asm/io.h>
  45 +
  46 +#include "ecc.h"
  47 +
  48 +#if !defined(CONFIG_440EPX) && !defined(CONFIG_440GRX)
  49 +#if defined(CONFIG_DDR_ECC) || defined(CONFIG_SDRAM_ECC)
  50 +/*
  51 + * void ecc_init()
  52 + *
  53 + * Description:
  54 + * This routine initializes a range of DRAM ECC memory with known
  55 + * data and enables ECC checking.
  56 + *
  57 + * TO DO:
  58 + * - Improve performance by utilizing cache.
  59 + * - Further generalize to make usable by other 4xx variants (e.g.
  60 + * 440EPx, et al).
  61 + *
  62 + * Input(s):
  63 + * start - A pointer to the start of memory covered by ECC requiring
  64 + * initialization.
  65 + * size - The size, in bytes, of the memory covered by ECC requiring
  66 + * initialization.
  67 + *
  68 + * Output(s):
  69 + * start - A pointer to the start of memory covered by ECC with
  70 + * CFG_ECC_PATTERN written to all locations and ECC data
  71 + * primed.
  72 + *
  73 + * Returns:
  74 + * N/A
  75 + */
  76 +void ecc_init(unsigned long * const start, unsigned long size)
  77 +{
  78 + const unsigned long pattern = CFG_ECC_PATTERN;
  79 + unsigned * const end = (unsigned long * const)((long)start + size);
  80 + unsigned long * current = start;
  81 + unsigned long mcopt1;
  82 + long increment;
  83 +
  84 + if (start >= end)
  85 + return;
  86 +
  87 + mfsdram(SDRAM_MCOPT1, mcopt1);
  88 +
  89 + /* Enable ECC generation without checking or reporting */
  90 +
  91 + mtsdram(SDRAM_MCOPT1, ((mcopt1 & ~SDRAM_MCOPT1_MCHK_MASK) |
  92 + SDRAM_MCOPT1_MCHK_GEN));
  93 +
  94 + increment = sizeof(u32);
  95 +
  96 +#if defined(CONFIG_440)
  97 + /*
  98 + * Look at the geometry of SDRAM (data width) to determine whether we
  99 + * can skip words when writing.
  100 + */
  101 +
  102 + if ((mcopt1 & SDRAM_MCOPT1_DMWD_MASK) != SDRAM_MCOPT1_DMWD_32)
  103 + increment = sizeof(u64);
  104 +#endif /* defined(CONFIG_440) */
  105 +
  106 + while (current < end) {
  107 + *current = pattern;
  108 + current = (unsigned long *)((long)current + increment);
  109 + }
  110 +
  111 + /* Wait until the writes are finished. */
  112 +
  113 + sync();
  114 +
  115 + /* Enable ECC generation with checking and no reporting */
  116 +
  117 + mtsdram(SDRAM_MCOPT1, ((mcopt1 & ~SDRAM_MCOPT1_MCHK_MASK) |
  118 + SDRAM_MCOPT1_MCHK_CHK));
  119 +}
  120 +#endif /* defined(CONFIG_DDR_ECC) || defined(CONFIG_SDRAM_ECC) */
  121 +#endif /* !defined(CONFIG_440EPX) && !defined(CONFIG_440GRX) */
  1 +/*
  2 + * Copyright (c) 2008 Nuovation System Designs, LLC
  3 + * Grant Erickson <gerickson@nuovations.com>
  4 + *
  5 + * Copyright (c) 2007 DENX Software Engineering, GmbH
  6 + * Stefan Roese <sr@denx.de>
  7 + *
  8 + * See file CREDITS for list of people who contributed to this
  9 + * project.
  10 + *
  11 + * This program is free software; you can redistribute it and/or
  12 + * modify it under the terms of the GNU General Public License as
  13 + * published by the Free Software Foundation; either version 2 of
  14 + * the License, or (at your option) any later version.
  15 + *
  16 + * This program is distributed in the hope that it will abe useful,
  17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19 + * GNU General Public License for more details.
  20 + *
  21 + * You should have received a copy of the GNU General Public License
  22 + * along with this program; if not, write to the Free Software
  23 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24 + * MA 02111-1307 USA
  25 + *
  26 + * Description:
  27 + * This file implements ECC initialization for PowerPC processors
  28 + * using the SDRAM DDR2 controller, including the 405EX(r),
  29 + * 440SP(E), 460EX and 460GT.
  30 + *
  31 + */
  32 +
  33 +#ifndef _ECC_H_
  34 +#define _ECC_H_
  35 +
  36 +#if !defined(CFG_ECC_PATTERN)
  37 +#define CFG_ECC_PATTERN 0x00000000
  38 +#endif /* !defined(CFG_ECC_PATTERN) */
  39 +
  40 +extern void ecc_init(unsigned long * const start, unsigned long size);
  41 +
  42 +#endif /* _ECC_H_ */
... ... @@ -31,6 +31,7 @@
31 31 #include <ppc4xx.h>
32 32 #include <asm/processor.h>
33 33 #include "sdram.h"
  34 +#include "ecc.h"
34 35  
35 36 #ifdef CONFIG_SDRAM_BANK0
36 37  
... ... @@ -331,49 +332,6 @@
331 332 /* return the current value for TR1 */
332 333 *tr1_value = (first_good + last_bad) / 2;
333 334 }
334   -
335   -#ifdef CONFIG_SDRAM_ECC
336   -static void ecc_init(ulong start, ulong size)
337   -{
338   - ulong current_addr; /* current byte address */
339   - ulong end_addr; /* end of memory region */
340   - ulong addr_inc; /* address skip between writes */
341   - ulong cfg0_reg; /* for restoring ECC state */
342   -
343   - /*
344   - * TODO: Enable dcache before running this test (speedup)
345   - */
346   -
347   - mfsdram(mem_cfg0, cfg0_reg);
348   - mtsdram(mem_cfg0, (cfg0_reg & ~SDRAM_CFG0_MEMCHK) | SDRAM_CFG0_MEMCHK_GEN);
349   -
350   - /*
351   - * look at geometry of SDRAM (data width) to determine whether we
352   - * can skip words when writing
353   - */
354   - if ((cfg0_reg & SDRAM_CFG0_DRAMWDTH) == SDRAM_CFG0_DRAMWDTH_32)
355   - addr_inc = 4;
356   - else
357   - addr_inc = 8;
358   -
359   - current_addr = start;
360   - end_addr = start + size;
361   -
362   - while (current_addr < end_addr) {
363   - *((ulong *)current_addr) = 0x00000000;
364   - current_addr += addr_inc;
365   - }
366   -
367   - /*
368   - * TODO: Flush dcache and disable it again
369   - */
370   -
371   - /*
372   - * Enable ecc checking and parity errors
373   - */
374   - mtsdram(mem_cfg0, (cfg0_reg & ~SDRAM_CFG0_MEMCHK) | SDRAM_CFG0_MEMCHK_CHK);
375   -}
376   -#endif
377 335  
378 336 /*
379 337 * Autodetect onboard DDR SDRAM on 440 platforms
... ... @@ -3,6 +3,8 @@
3 3 * Copyright (C) 1999 Magnus Damm <kieraypc01.p.y.kie.era.ericsson.se>
4 4 * Copyright (C) 2000,2001,2002 Wolfgang Denk <wd@denx.de>
5 5 * Copyright (C) 2007 Stefan Roese <sr@denx.de>, DENX Software Engineering
  6 + * Copyright (c) 2008 Nuovation System Designs, LLC
  7 + * Grant Erickson <gerickson@nuovations.com>
6 8 *
7 9 * See file CREDITS for list of people who contributed to this
8 10 * project.
9 11  
10 12  
11 13  
12 14  
13 15  
14 16  
15 17  
16 18  
17 19  
... ... @@ -79,41 +81,124 @@
79 81 # if (CFG_INIT_DCACHE_CS == 0)
80 82 # define PBxAP pb0ap
81 83 # define PBxCR pb0cr
  84 +# if (defined(CFG_EBC_PB0AP) && defined(CFG_EBC_PB0CR))
  85 +# define PBxAP_VAL CFG_EBC_PB0AP
  86 +# define PBxCR_VAL CFG_EBC_PB0CR
  87 +# endif
82 88 # endif
83 89 # if (CFG_INIT_DCACHE_CS == 1)
84 90 # define PBxAP pb1ap
85 91 # define PBxCR pb1cr
  92 +# if (defined(CFG_EBC_PB1AP) && defined(CFG_EBC_PB1CR))
  93 +# define PBxAP_VAL CFG_EBC_PB1AP
  94 +# define PBxCR_VAL CFG_EBC_PB1CR
  95 +# endif
86 96 # endif
87 97 # if (CFG_INIT_DCACHE_CS == 2)
88 98 # define PBxAP pb2ap
89 99 # define PBxCR pb2cr
  100 +# if (defined(CFG_EBC_PB2AP) && defined(CFG_EBC_PB2CR))
  101 +# define PBxAP_VAL CFG_EBC_PB2AP
  102 +# define PBxCR_VAL CFG_EBC_PB2CR
  103 +# endif
90 104 # endif
91 105 # if (CFG_INIT_DCACHE_CS == 3)
92 106 # define PBxAP pb3ap
93 107 # define PBxCR pb3cr
  108 +# if (defined(CFG_EBC_PB3AP) && defined(CFG_EBC_PB3CR))
  109 +# define PBxAP_VAL CFG_EBC_PB3AP
  110 +# define PBxCR_VAL CFG_EBC_PB3CR
  111 +# endif
94 112 # endif
95 113 # if (CFG_INIT_DCACHE_CS == 4)
96 114 # define PBxAP pb4ap
97 115 # define PBxCR pb4cr
  116 +# if (defined(CFG_EBC_PB4AP) && defined(CFG_EBC_PB4CR))
  117 +# define PBxAP_VAL CFG_EBC_PB4AP
  118 +# define PBxCR_VAL CFG_EBC_PB4CR
  119 +# endif
98 120 # endif
99 121 # if (CFG_INIT_DCACHE_CS == 5)
100 122 # define PBxAP pb5ap
101 123 # define PBxCR pb5cr
  124 +# if (defined(CFG_EBC_PB5AP) && defined(CFG_EBC_PB5CR))
  125 +# define PBxAP_VAL CFG_EBC_PB5AP
  126 +# define PBxCR_VAL CFG_EBC_PB5CR
  127 +# endif
102 128 # endif
103 129 # if (CFG_INIT_DCACHE_CS == 6)
104 130 # define PBxAP pb6ap
105 131 # define PBxCR pb6cr
  132 +# if (defined(CFG_EBC_PB6AP) && defined(CFG_EBC_PB6CR))
  133 +# define PBxAP_VAL CFG_EBC_PB6AP
  134 +# define PBxCR_VAL CFG_EBC_PB6CR
  135 +# endif
106 136 # endif
107 137 # if (CFG_INIT_DCACHE_CS == 7)
108 138 # define PBxAP pb7ap
109 139 # define PBxCR pb7cr
  140 +# if (defined(CFG_EBC_PB7AP) && defined(CFG_EBC_PB7CR))
  141 +# define PBxAP_VAL CFG_EBC_PB7AP
  142 +# define PBxCR_VAL CFG_EBC_PB7CR
  143 +# endif
110 144 # endif
  145 +# ifndef PBxAP_VAL
  146 +# define PBxAP_VAL 0
  147 +# endif
  148 +# ifndef PBxCR_VAL
  149 +# define PBxCR_VAL 0
  150 +# endif
  151 +/*
  152 + * Memory Bank x (nothingness) initialization CFG_INIT_RAM_ADDR + 64 MiB
  153 + * used as temporary stack pointer for the primordial stack
  154 + */
  155 +# ifndef CFG_INIT_DCACHE_PBxAR
  156 +# define CFG_INIT_DCACHE_PBxAR (EBC_BXAP_BME_DISABLED | \
  157 + EBC_BXAP_TWT_ENCODE(7) | \
  158 + EBC_BXAP_BCE_DISABLE | \
  159 + EBC_BXAP_BCT_2TRANS | \
  160 + EBC_BXAP_CSN_ENCODE(0) | \
  161 + EBC_BXAP_OEN_ENCODE(0) | \
  162 + EBC_BXAP_WBN_ENCODE(0) | \
  163 + EBC_BXAP_WBF_ENCODE(0) | \
  164 + EBC_BXAP_TH_ENCODE(2) | \
  165 + EBC_BXAP_RE_DISABLED | \
  166 + EBC_BXAP_SOR_NONDELAYED | \
  167 + EBC_BXAP_BEM_WRITEONLY | \
  168 + EBC_BXAP_PEN_DISABLED)
  169 +# endif /* CFG_INIT_DCACHE_PBxAR */
  170 +# ifndef CFG_INIT_DCACHE_PBxCR
  171 +# define CFG_INIT_DCACHE_PBxCR (EBC_BXCR_BAS_ENCODE(CFG_INIT_RAM_ADDR) | \
  172 + EBC_BXCR_BS_64MB | \
  173 + EBC_BXCR_BU_RW | \
  174 + EBC_BXCR_BW_16BIT)
  175 +# endif /* CFG_INIT_DCACHE_PBxCR */
  176 +# ifndef CFG_INIT_RAM_PATTERN
  177 +# define CFG_INIT_RAM_PATTERN 0xDEADDEAD
  178 +# endif
111 179 #endif /* CFG_INIT_DCACHE_CS */
112 180  
113 181 #if (defined(CFG_INIT_RAM_DCACHE) && (CFG_INIT_RAM_END > (4 << 10)))
114 182 #error Only 4k of init-ram is supported - please adjust CFG_INIT_RAM_END!
115 183 #endif
116 184  
  185 +/*
  186 + * Unless otherwise overriden, enable two 128MB cachable instruction regions
  187 + * at CFG_SDRAM_BASE and another 128MB cacheable instruction region covering
  188 + * NOR flash at CFG_FLASH_BASE. Disable all cacheable data regions.
  189 + */
  190 +#if !defined(CFG_ICACHE_SACR_VALUE)
  191 +# define CFG_ICACHE_SACR_VALUE \
  192 + (PPC_128MB_SACR_VALUE(CFG_SDRAM_BASE + ( 0 << 20)) | \
  193 + PPC_128MB_SACR_VALUE(CFG_SDRAM_BASE + (128 << 20)) | \
  194 + PPC_128MB_SACR_VALUE(CFG_FLASH_BASE))
  195 +#endif /* !defined(CFG_ICACHE_SACR_VALUE) */
  196 +
  197 +#if !defined(CFG_DCACHE_SACR_VALUE)
  198 +# define CFG_DCACHE_SACR_VALUE \
  199 + (0x00000000)
  200 +#endif /* !defined(CFG_DCACHE_SACR_VALUE) */
  201 +
117 202 #define function_prolog(func_name) .text; \
118 203 .align 2; \
119 204 .globl func_name; \
120 205  
... ... @@ -840,16 +925,16 @@
840 925 /* make sure above stores all comlete before going on */
841 926 sync
842 927  
843   - /*----------------------------------------------------------------------- */
844   - /* Enable two 128MB cachable regions. */
845   - /*----------------------------------------------------------------------- */
846   - addis r1,r0,0xc000
847   - addi r1,r1,0x0001
848   - mticcr r1 /* instruction cache */
  928 + /* Set-up icache cacheability. */
  929 + lis r1, CFG_ICACHE_SACR_VALUE@h
  930 + ori r1, r1, CFG_ICACHE_SACR_VALUE@l
  931 + mticcr r1
  932 + isync
849 933  
850   - addis r1,r0,0x0000
851   - addi r1,r1,0x0000
852   - mtdccr r1 /* data cache */
  934 + /* Set-up dcache cacheability. */
  935 + lis r1, CFG_DCACHE_SACR_VALUE@h
  936 + ori r1, r1, CFG_DCACHE_SACR_VALUE@l
  937 + mtdccr r1
853 938  
854 939 addis r1,r0,CFG_INIT_RAM_ADDR@h
855 940 ori r1,r1,CFG_INIT_SP_OFFSET /* set up the stack to SDRAM */
856 941  
857 942  
... ... @@ -892,27 +977,20 @@
892 977 /* dbsr is cleared by setting bits to 1) */
893 978 mtdbsr r4 /* clear/reset the dbsr */
894 979  
895   - /*----------------------------------------------------------------------- */
896   - /* Invalidate I and D caches. Enable I cache for defined memory regions */
897   - /* to speed things up. Leave the D cache disabled for now. It will be */
898   - /* enabled/left disabled later based on user selected menu options. */
899   - /* Be aware that the I cache may be disabled later based on the menu */
900   - /* options as well. See miscLib/main.c. */
901   - /*----------------------------------------------------------------------- */
  980 + /* Invalidate the i- and d-caches. */
902 981 bl invalidate_icache
903 982 bl invalidate_dcache
904 983  
905   - /*----------------------------------------------------------------------- */
906   - /* Enable two 128MB cachable regions. */
907   - /*----------------------------------------------------------------------- */
908   - lis r4,0xc000
909   - ori r4,r4,0x0001
910   - mticcr r4 /* instruction cache */
  984 + /* Set-up icache cacheability. */
  985 + lis r4, CFG_ICACHE_SACR_VALUE@h
  986 + ori r4, r4, CFG_ICACHE_SACR_VALUE@l
  987 + mticcr r4
911 988 isync
912 989  
913   - lis r4,0x0000
914   - ori r4,r4,0x0000
915   - mtdccr r4 /* data cache */
  990 + /* Set-up dcache cacheability. */
  991 + lis r4, CFG_DCACHE_SACR_VALUE@h
  992 + ori r4, r4, CFG_DCACHE_SACR_VALUE@l
  993 + mtdccr r4
916 994  
917 995 #if !(defined(CFG_EBC_PB0AP) && defined(CFG_EBC_PB0CR)) || defined(CONFIG_405EX)
918 996 /*----------------------------------------------------------------------- */
... ... @@ -922,9 +1000,9 @@
922 1000 #endif
923 1001 #if !(defined(CFG_INIT_DCACHE_CS) || defined(CFG_TEMP_STACK_OCM))
924 1002 /*
925   - * Boards like the Kilauea (405EX) don't have OCM and can't use
926   - * DCache for init-ram. So setup stack here directly after the
927   - * SDRAM is initialized.
  1003 + * For boards that don't have OCM and can't use the data cache
  1004 + * for their primordial stack, setup stack here directly after the
  1005 + * SDRAM is initialized in ext_bus_cntlr_init.
928 1006 */
929 1007 lis r1, CFG_INIT_RAM_ADDR@h
930 1008 ori r1,r1,CFG_INIT_SP_OFFSET /* set up the stack in SDRAM */
931 1009  
932 1010  
933 1011  
934 1012  
935 1013  
936 1014  
937 1015  
938 1016  
939 1017  
940 1018  
... ... @@ -1043,48 +1121,87 @@
1043 1121 /* Setup temporary stack in DCACHE or OCM if needed for SDRAM SPD. */
1044 1122 /*----------------------------------------------------------------------- */
1045 1123 #ifdef CFG_INIT_DCACHE_CS
1046   - /*----------------------------------------------------------------------- */
1047   - /* Memory Bank x (nothingness) initialization 1GB+64MEG */
1048   - /* used as temporary stack pointer for stage0 */
1049   - /*----------------------------------------------------------------------- */
1050   - li r4,PBxAP
1051   - mtdcr ebccfga,r4
1052   - lis r4,0x0380
1053   - ori r4,r4,0x0480
1054   - mtdcr ebccfgd,r4
  1124 + li r4, PBxAP
  1125 + mtdcr ebccfga, r4
  1126 + lis r4, CFG_INIT_DCACHE_PBxAR@h
  1127 + ori r4, r4, CFG_INIT_DCACHE_PBxAR@l
  1128 + mtdcr ebccfgd, r4
1055 1129  
1056   - addi r4,0,PBxCR
1057   - mtdcr ebccfga,r4
1058   - lis r4,0x400D
1059   - ori r4,r4,0xa000
1060   - mtdcr ebccfgd,r4
  1130 + addi r4, 0, PBxCR
  1131 + mtdcr ebccfga, r4
  1132 + lis r4, CFG_INIT_DCACHE_PBxCR@h
  1133 + ori r4, r4, CFG_INIT_DCACHE_PBxCR@l
  1134 + mtdcr ebccfgd, r4
1061 1135  
1062   - /* turn on data cache for this region */
1063   - lis r4,0x0080
  1136 + /*
  1137 + * Enable the data cache for the 128MB storage access control region
  1138 + * at CFG_INIT_RAM_ADDR.
  1139 + */
  1140 + mfdccr r4
  1141 + oris r4, r4, PPC_128MB_SACR_VALUE(CFG_INIT_RAM_ADDR)@h
  1142 + ori r4, r4, PPC_128MB_SACR_VALUE(CFG_INIT_RAM_ADDR)@l
1064 1143 mtdccr r4
1065 1144  
1066   - /* set stack pointer and clear stack to known value */
  1145 + /*
  1146 + * Preallocate data cache lines to be used to avoid a subsequent
  1147 + * cache miss and an ensuing machine check exception when exceptions
  1148 + * are enabled.
  1149 + */
  1150 + li r0, 0
1067 1151  
1068   - lis r1,CFG_INIT_RAM_ADDR@h
1069   - ori r1,r1,CFG_INIT_SP_OFFSET@l
  1152 + lis r3, CFG_INIT_RAM_ADDR@h
  1153 + ori r3, r3, CFG_INIT_RAM_ADDR@l
1070 1154  
1071   - li r4,2048 /* we store 2048 words to stack */
  1155 + lis r4, CFG_INIT_RAM_END@h
  1156 + ori r4, r4, CFG_INIT_RAM_END@l
  1157 +
  1158 + /*
  1159 + * Convert the size, in bytes, to the number of cache lines/blocks
  1160 + * to preallocate.
  1161 + */
  1162 + clrlwi. r5, r4, (32 - L1_CACHE_SHIFT)
  1163 + srwi r5, r4, L1_CACHE_SHIFT
  1164 + beq ..load_counter
  1165 + addi r5, r5, 0x0001
  1166 +..load_counter:
  1167 + mtctr r5
  1168 +
  1169 + /* Preallocate the computed number of cache blocks. */
  1170 +..alloc_dcache_block:
  1171 + dcba r0, r3
  1172 + addi r3, r3, L1_CACHE_BYTES
  1173 + bdnz ..alloc_dcache_block
  1174 + sync
  1175 +
  1176 + /*
  1177 + * Load the initial stack pointer and data area and convert the size,
  1178 + * in bytes, to the number of words to initialize to a known value.
  1179 + */
  1180 + lis r1, CFG_INIT_RAM_ADDR@h
  1181 + ori r1, r1, CFG_INIT_SP_OFFSET@l
  1182 +
  1183 + lis r4, (CFG_INIT_RAM_END >> 2)@h
  1184 + ori r4, r4, (CFG_INIT_RAM_END >> 2)@l
1072 1185 mtctr r4
1073 1186  
1074   - lis r2,CFG_INIT_RAM_ADDR@h /* we also clear data area */
1075   - ori r2,r2,CFG_INIT_RAM_END@l /* so cant copy value from r1 */
  1187 + lis r2, CFG_INIT_RAM_ADDR@h
  1188 + ori r2, r2, CFG_INIT_RAM_END@l
1076 1189  
1077   - lis r4,0xdead /* we store 0xdeaddead in the stack */
1078   - ori r4,r4,0xdead
  1190 + lis r4, CFG_INIT_RAM_PATTERN@h
  1191 + ori r4, r4, CFG_INIT_RAM_PATTERN@l
1079 1192  
1080 1193 ..stackloop:
1081   - stwu r4,-4(r2)
  1194 + stwu r4, -4(r2)
1082 1195 bdnz ..stackloop
1083 1196  
1084   - li r0, 0 /* Make room for stack frame header and */
1085   - stwu r0, -4(r1) /* clear final stack frame so that */
1086   - stwu r0, -4(r1) /* stack backtraces terminate cleanly */
1087 1197 /*
  1198 + * Make room for stack frame header and clear final stack frame so
  1199 + * that stack backtraces terminate cleanly.
  1200 + */
  1201 + stwu r0, -4(r1)
  1202 + stwu r0, -4(r1)
  1203 +
  1204 + /*
1088 1205 * Set up a dummy frame to store reset vector as return address.
1089 1206 * this causes stack underflow to reset board.
1090 1207 */
1091 1208  
1092 1209  
1093 1210  
1094 1211  
1095 1212  
1096 1213  
... ... @@ -1328,34 +1445,73 @@
1328 1445 * This "function" does not return, instead it continues in RAM
1329 1446 * after relocating the monitor code.
1330 1447 *
1331   - * r3 = dest
1332   - * r4 = src
1333   - * r5 = length in bytes
1334   - * r6 = cachelinesize
  1448 + * r3 = Relocated stack pointer
  1449 + * r4 = Relocated global data pointer
  1450 + * r5 = Relocated text pointer
1335 1451 */
1336 1452 .globl relocate_code
1337 1453 relocate_code:
1338   -#ifdef CONFIG_4xx_DCACHE
  1454 +#if defined(CONFIG_4xx_DCACHE) || defined(CFG_INIT_DCACHE_CS)
1339 1455 /*
1340   - * We need to flush the Init Data before the dcache will be
1341   - * invalidated
  1456 + * We need to flush the initial global data (gd_t) before the dcache
  1457 + * will be invalidated.
1342 1458 */
1343 1459  
1344   - /* save regs */
1345   - mr r9,r3
1346   - mr r10,r4
1347   - mr r11,r5
  1460 + /* Save registers */
  1461 + mr r9, r3
  1462 + mr r10, r4
  1463 + mr r11, r5
1348 1464  
1349   - mr r3,r4
1350   - addi r4,r4,0x200 /* should be enough for init data */
  1465 + /* Flush initial global data range */
  1466 + mr r3, r4
  1467 + addi r4, r4, CFG_GBL_DATA_SIZE@l
1351 1468 bl flush_dcache_range
1352 1469  
1353   - /* restore regs */
1354   - mr r3,r9
1355   - mr r4,r10
1356   - mr r5,r11
1357   -#endif
  1470 +#if defined(CFG_INIT_DCACHE_CS)
  1471 + /*
  1472 + * Undo the earlier data cache set-up for the primordial stack and
  1473 + * data area. First, invalidate the data cache and then disable data
  1474 + * cacheability for that area. Finally, restore the EBC values, if
  1475 + * any.
  1476 + */
1358 1477  
  1478 + /* Invalidate the primordial stack and data area in cache */
  1479 + lis r3, CFG_INIT_RAM_ADDR@h
  1480 + ori r3, r3, CFG_INIT_RAM_ADDR@l
  1481 +
  1482 + lis r4, CFG_INIT_RAM_END@h
  1483 + ori r4, r4, CFG_INIT_RAM_END@l
  1484 + add r4, r4, r3
  1485 +
  1486 + bl invalidate_dcache_range
  1487 +
  1488 + /* Disable cacheability for the region */
  1489 + mfdccr r3
  1490 + lis r4, ~PPC_128MB_SACR_VALUE(CFG_INIT_RAM_ADDR)@h
  1491 + ori r4, r4, ~PPC_128MB_SACR_VALUE(CFG_INIT_RAM_ADDR)@l
  1492 + and r3, r3, r4
  1493 + mtdccr r3
  1494 +
  1495 + /* Restore the EBC parameters */
  1496 + li r3, PBxAP
  1497 + mtdcr ebccfga, r3
  1498 + lis r3, PBxAP_VAL@h
  1499 + ori r3, r3, PBxAP_VAL@l
  1500 + mtdcr ebccfgd, r3
  1501 +
  1502 + li r3, PBxCR
  1503 + mtdcr ebccfga, r3
  1504 + lis r3, PBxCR_VAL@h
  1505 + ori r3, r3, PBxCR_VAL@l
  1506 + mtdcr ebccfgd, r3
  1507 +#endif /* defined(CFG_INIT_DCACHE_CS) */
  1508 +
  1509 + /* Restore registers */
  1510 + mr r3, r9
  1511 + mr r4, r10
  1512 + mr r5, r11
  1513 +#endif /* defined(CONFIG_4xx_DCACHE) || defined(CFG_INIT_DCACHE_CS) */
  1514 +
1359 1515 #ifdef CFG_INIT_RAM_DCACHE
1360 1516 /*
1361 1517 * Unlock the previously locked d-cache
1362 1518  
... ... @@ -1396,13 +1552,13 @@
1396 1552 addi r1,r0,CFG_TLB_FOR_BOOT_FLASH /* Use defined TLB */
1397 1553 #else
1398 1554 addi r1,r0,0x0000 /* Default TLB entry is #0 */
1399   -#endif
  1555 +#endif /* CFG_TLB_FOR_BOOT_FLASH */
1400 1556 tlbre r0,r1,0x0002 /* Read contents */
1401 1557 ori r0,r0,0x0c00 /* Or in the inhibit, write through bit */
1402 1558 tlbwe r0,r1,0x0002 /* Save it out */
1403 1559 sync
1404 1560 isync
1405   -#endif
  1561 +#endif /* defined(CONFIG_440EP) || ... || defined(CONFIG_460GT) */
1406 1562 mr r1, r3 /* Set new stack pointer */
1407 1563 mr r9, r4 /* Save copy of Init Data pointer */
1408 1564 mr r10, r5 /* Save copy of Destination Address */
... ... @@ -1425,7 +1581,7 @@
1425 1581  
1426 1582 /* First our own GOT */
1427 1583 add r14, r14, r15
1428   - /* the the one used by the C code */
  1584 + /* then the one used by the C code */
1429 1585 add r30, r30, r15
1430 1586  
1431 1587 /*
... ... @@ -170,7 +170,7 @@
170 170  
171 171 val = get_esr();
172 172  
173   -#if !defined(CONFIG_440)
  173 +#if !defined(CONFIG_440) && !defined(CONFIG_405EX)
174 174 if (val& ESR_IMCP) {
175 175 printf("Instruction");
176 176 mtspr(ESR, val & ~ESR_IMCP);
... ... @@ -179,7 +179,7 @@
179 179 }
180 180 printf(" machine check.\n");
181 181  
182   -#elif defined(CONFIG_440)
  182 +#elif defined(CONFIG_440) || defined(CONFIG_405EX)
183 183 if (val& ESR_IMCP){
184 184 printf("Instruction Synchronous Machine Check exception\n");
185 185 mtspr(SPRN_ESR, val & ~ESR_IMCP);
186 186  
... ... @@ -187,10 +187,15 @@
187 187 val = mfspr(MCSR);
188 188 if (val & MCSR_IB)
189 189 printf("Instruction Read PLB Error\n");
  190 +#if defined(CONFIG_440)
190 191 if (val & MCSR_DRB)
191 192 printf("Data Read PLB Error\n");
192 193 if (val & MCSR_DWB)
193 194 printf("Data Write PLB Error\n");
  195 +#else
  196 + if (val & MCSR_DB)
  197 + printf("Data PLB Error\n");
  198 +#endif
194 199 if (val & MCSR_TLBP)
195 200 printf("TLB Parity Error\n");
196 201 if (val & MCSR_ICP){
include/asm-ppc/processor.h
... ... @@ -460,17 +460,19 @@
460 460 #define SPRN_PID2 0x27a /* Process ID Register 2 */
461 461 #define SPRN_MCSR 0x23c /* Machine Check Syndrome register */
462 462 #define SPRN_MCAR 0x23d /* Machine Check Address register */
463   -#ifdef CONFIG_440
464 463 #define MCSR_MCS 0x80000000 /* Machine Check Summary */
465 464 #define MCSR_IB 0x40000000 /* Instruction PLB Error */
  465 +#if defined(CONFIG_440)
466 466 #define MCSR_DRB 0x20000000 /* Data Read PLB Error */
467 467 #define MCSR_DWB 0x10000000 /* Data Write PLB Error */
  468 +#else
  469 +#define MCSR_DB 0x20000000 /* Data PLB Error */
  470 +#endif /* defined(CONFIG_440) */
468 471 #define MCSR_TLBP 0x08000000 /* TLB Parity Error */
469 472 #define MCSR_ICP 0x04000000 /* I-Cache Parity Error */
470 473 #define MCSR_DCSP 0x02000000 /* D-Cache Search Parity Error */
471 474 #define MCSR_DCFP 0x01000000 /* D-Cache Flush Parity Error */
472 475 #define MCSR_IMPE 0x00800000 /* Imprecise Machine Check Exception */
473   -#endif
474 476 #define ESR_ST 0x00800000 /* Store Operation */
475 477  
476 478 #if defined(CONFIG_MPC86xx)
... ... @@ -22,6 +22,10 @@
22 22 #ifndef __PPC405_H__
23 23 #define __PPC405_H__
24 24  
  25 +/* Define bits and masks for real-mode storage attribute control registers */
  26 +#define PPC_128MB_SACR_BIT(addr) ((addr) >> 27)
  27 +#define PPC_128MB_SACR_VALUE(addr) PPC_REG_VAL(PPC_128MB_SACR_BIT(addr),1)
  28 +
25 29 #ifndef CONFIG_IOP480
26 30 #define CFG_DCACHE_SIZE (16 << 10) /* For AMCC 405 CPUs */
27 31 #else
... ... @@ -363,6 +367,120 @@
363 367 #endif /* defined(CONFIG_405EZ) */
364 368  
365 369 /******************************************************************************
  370 + * External Bus Controller (EBC)
  371 + *****************************************************************************/
  372 +
  373 +/* Bank Configuration Register */
  374 +#define EBC_BXCR_BAS_MASK PPC_REG_VAL(11, 0xFFF)
  375 +#define EBC_BXCR_BAS_ENCODE(n) (((static_cast(unsigned long, n)) & \
  376 + EBC_BXCR_BAS_MASK) << 0)
  377 +#define EBC_BXCR_BS_MASK PPC_REG_VAL(14, 0x7)
  378 +#define EBC_BXCR_BS_1MB PPC_REG_VAL(14, 0x0)
  379 +#define EBC_BXCR_BS_2MB PPC_REG_VAL(14, 0x1)
  380 +#define EBC_BXCR_BS_4MB PPC_REG_VAL(14, 0x2)
  381 +#define EBC_BXCR_BS_8MB PPC_REG_VAL(14, 0x3)
  382 +#define EBC_BXCR_BS_16MB PPC_REG_VAL(14, 0x4)
  383 +#define EBC_BXCR_BS_32MB PPC_REG_VAL(14, 0x5)
  384 +#define EBC_BXCR_BS_64MB PPC_REG_VAL(14, 0x6)
  385 +#define EBC_BXCR_BS_128MB PPC_REG_VAL(14, 0x7)
  386 +#define EBC_BXCR_BU_MASK PPC_REG_VAL(16, 0x3)
  387 +#define EBC_BXCR_BU_NONE PPC_REG_VAL(16, 0x0)
  388 +#define EBC_BXCR_BU_R PPC_REG_VAL(16, 0x1)
  389 +#define EBC_BXCR_BU_W PPC_REG_VAL(16, 0x2)
  390 +#define EBC_BXCR_BU_RW PPC_REG_VAL(16, 0x3)
  391 +#define EBC_BXCR_BW_MASK PPC_REG_VAL(18, 0x3)
  392 +#define EBC_BXCR_BW_8BIT PPC_REG_VAL(18, 0x0)
  393 +#define EBC_BXCR_BW_16BIT PPC_REG_VAL(18, 0x1)
  394 +#define EBC_BXCR_BW_32BIT PPC_REG_VAL(18, 0x3)
  395 +
  396 +/* Bank Access Parameter Register */
  397 +#define EBC_BXAP_BME_ENABLED PPC_REG_VAL(0, 0x1)
  398 +#define EBC_BXAP_BME_DISABLED PPC_REG_VAL(0, 0x0)
  399 +#define EBC_BXAP_TWT_ENCODE(n) PPC_REG_VAL(8, \
  400 + (static_cast(unsigned long, n)) \
  401 + & 0xFF)
  402 +#define EBC_BXAP_FWT_ENCODE(n) PPC_REG_VAL(5, \
  403 + (static_cast(unsigned long, n)) \
  404 + & 0x1F)
  405 +#define EBC_BXAP_BWT_ENCODE(n) PPC_REG_VAL(8, \
  406 + (static_cast(unsigned long, n)) \
  407 + & 0x7)
  408 +#define EBC_BXAP_BCE_DISABLE PPC_REG_VAL(9, 0x0)
  409 +#define EBC_BXAP_BCE_ENABLE PPC_REG_VAL(9, 0x1)
  410 +#define EBC_BXAP_BCT_MASK PPC_REG_VAL(11, 0x3)
  411 +#define EBC_BXAP_BCT_2TRANS PPC_REG_VAL(11, 0x0)
  412 +#define EBC_BXAP_BCT_4TRANS PPC_REG_VAL(11, 0x1)
  413 +#define EBC_BXAP_BCT_8TRANS PPC_REG_VAL(11, 0x2)
  414 +#define EBC_BXAP_BCT_16TRANS PPC_REG_VAL(11, 0x3)
  415 +#define EBC_BXAP_CSN_ENCODE(n) PPC_REG_VAL(13, \
  416 + (static_cast(unsigned long, n)) \
  417 + & 0x3)
  418 +#define EBC_BXAP_OEN_ENCODE(n) PPC_REG_VAL(15, \
  419 + (static_cast(unsigned long, n)) \
  420 + & 0x3)
  421 +#define EBC_BXAP_WBN_ENCODE(n) PPC_REG_VAL(17, \
  422 + (static_cast(unsigned long, n)) \
  423 + & 0x3)
  424 +#define EBC_BXAP_WBF_ENCODE(n) PPC_REG_VAL(19, \
  425 + (static_cast(unsigned long, n)) \
  426 + & 0x3)
  427 +#define EBC_BXAP_TH_ENCODE(n) PPC_REG_VAL(22, \
  428 + (static_cast(unsigned long, n)) \
  429 + & 0x7)
  430 +#define EBC_BXAP_RE_ENABLED PPC_REG_VAL(23, 0x1)
  431 +#define EBC_BXAP_RE_DISABLED PPC_REG_VAL(23, 0x0)
  432 +#define EBC_BXAP_SOR_DELAYED PPC_REG_VAL(24, 0x0)
  433 +#define EBC_BXAP_SOR_NONDELAYED PPC_REG_VAL(24, 0x1)
  434 +#define EBC_BXAP_BEM_WRITEONLY PPC_REG_VAL(25, 0x0)
  435 +#define EBC_BXAP_BEM_RW PPC_REG_VAL(25, 0x1)
  436 +#define EBC_BXAP_PEN_DISABLED PPC_REG_VAL(26, 0x0)
  437 +#define EBC_BXAP_PEN_ENABLED PPC_REG_VAL(26, 0x1)
  438 +
  439 +/* Configuration Register */
  440 +#define EBC_CFG_LE_MASK PPC_REG_VAL(0, 0x1)
  441 +#define EBC_CFG_LE_UNLOCK PPC_REG_VAL(0, 0x0)
  442 +#define EBC_CFG_LE_LOCK PPC_REG_VAL(0, 0x1)
  443 +#define EBC_CFG_PTD_MASK PPC_REG_VAL(1, 0x1)
  444 +#define EBC_CFG_PTD_ENABLE PPC_REG_VAL(1, 0x0)
  445 +#define EBC_CFG_PTD_DISABLE PPC_REG_VAL(1, 0x1)
  446 +#define EBC_CFG_RTC_MASK PPC_REG_VAL(4, 0x7)
  447 +#define EBC_CFG_RTC_16PERCLK PPC_REG_VAL(4, 0x0)
  448 +#define EBC_CFG_RTC_32PERCLK PPC_REG_VAL(4, 0x1)
  449 +#define EBC_CFG_RTC_64PERCLK PPC_REG_VAL(4, 0x2)
  450 +#define EBC_CFG_RTC_128PERCLK PPC_REG_VAL(4, 0x3)
  451 +#define EBC_CFG_RTC_256PERCLK PPC_REG_VAL(4, 0x4)
  452 +#define EBC_CFG_RTC_512PERCLK PPC_REG_VAL(4, 0x5)
  453 +#define EBC_CFG_RTC_1024PERCLK PPC_REG_VAL(4, 0x6)
  454 +#define EBC_CFG_RTC_2048PERCLK PPC_REG_VAL(4, 0x7)
  455 +#define EBC_CFG_ATC_MASK PPC_REG_VAL(5, 0x1)
  456 +#define EBC_CFG_ATC_HI PPC_REG_VAL(5, 0x0)
  457 +#define EBC_CFG_ATC_PREVIOUS PPC_REG_VAL(5, 0x1)
  458 +#define EBC_CFG_DTC_MASK PPC_REG_VAL(6, 0x1)
  459 +#define EBC_CFG_DTC_HI PPC_REG_VAL(6, 0x0)
  460 +#define EBC_CFG_DTC_PREVIOUS PPC_REG_VAL(6, 0x1)
  461 +#define EBC_CFG_CTC_MASK PPC_REG_VAL(7, 0x1)
  462 +#define EBC_CFG_CTC_HI PPC_REG_VAL(7, 0x0)
  463 +#define EBC_CFG_CTC_PREVIOUS PPC_REG_VAL(7, 0x1)
  464 +#define EBC_CFG_OEO_MASK PPC_REG_VAL(8, 0x1)
  465 +#define EBC_CFG_OEO_DISABLE PPC_REG_VAL(8, 0x0)
  466 +#define EBC_CFG_OEO_ENABLE PPC_REG_VAL(8, 0x1)
  467 +#define EBC_CFG_EMC_MASK PPC_REG_VAL(9, 0x1)
  468 +#define EBC_CFG_EMC_NONDEFAULT PPC_REG_VAL(9, 0x0)
  469 +#define EBC_CFG_EMC_DEFAULT PPC_REG_VAL(9, 0x1)
  470 +#define EBC_CFG_PME_MASK PPC_REG_VAL(14, 0x1)
  471 +#define EBC_CFG_PME_DISABLE PPC_REG_VAL(14, 0x0)
  472 +#define EBC_CFG_PME_ENABLE PPC_REG_VAL(14, 0x1)
  473 +#define EBC_CFG_PMT_MASK PPC_REG_VAL(19, 0x1F)
  474 +#define EBC_CFG_PMT_ENCODE(n) PPC_REG_VAL(19, \
  475 + (static_cast(unsigned long, n)) \
  476 + & 0x1F)
  477 +#define EBC_CFG_PR_MASK PPC_REG_VAL(21, 0x3)
  478 +#define EBC_CFG_PR_16 PPC_REG_VAL(21, 0x0)
  479 +#define EBC_CFG_PR_32 PPC_REG_VAL(21, 0x1)
  480 +#define EBC_CFG_PR_64 PPC_REG_VAL(21, 0x2)
  481 +#define EBC_CFG_PR_128 PPC_REG_VAL(21, 0x3)
  482 +
  483 +/******************************************************************************
366 484 * SDRAM Controller
367 485 ******************************************************************************/
368 486 /* values for memcfga register - indirect addressing of these regs */
... ... @@ -1218,19 +1336,43 @@
1218 1336  
1219 1337 /*-----------------------------------------------------------------------------+
1220 1338 | Memory Bank 0-7 configuration
1221   -+-----------------------------------------------------------------------------*/
1222   -#define SDRAM_RXBAS_SDSZ_4 0x00000000 /* 4M */
1223   -#define SDRAM_RXBAS_SDSZ_8 0x00001000 /* 8M */
1224   -#define SDRAM_RXBAS_SDSZ_16 0x00002000 /* 16M */
1225   -#define SDRAM_RXBAS_SDSZ_32 0x00003000 /* 32M */
1226   -#define SDRAM_RXBAS_SDSZ_64 0x00004000 /* 64M */
1227   -#define SDRAM_RXBAS_SDSZ_128 0x00005000 /* 128M */
1228   -#define SDRAM_RXBAS_SDSZ_256 0x00006000 /* 256M */
1229   -#define SDRAM_RXBAS_SDSZ_512 0x00007000 /* 512M */
1230   -#define SDRAM_RXBAS_SDSZ_1024 0x00008000 /* 1024M */
1231   -#define SDRAM_RXBAS_SDSZ_2048 0x00009000 /* 2048M */
1232   -#define SDRAM_RXBAS_SDSZ_4096 0x0000a000 /* 4096M */
1233   -#define SDRAM_RXBAS_SDSZ_8192 0x0000b000 /* 8192M */
  1339 ++----------------------------------------------------------------------------*/
  1340 +#define SDRAM_RXBAS_SDSZ_MASK PPC_REG_VAL(19, 0xF)
  1341 +#define SDRAM_RXBAS_SDSZ_4MB PPC_REG_VAL(19, 0x0)
  1342 +#define SDRAM_RXBAS_SDSZ_8MB PPC_REG_VAL(19, 0x1)
  1343 +#define SDRAM_RXBAS_SDSZ_16MB PPC_REG_VAL(19, 0x2)
  1344 +#define SDRAM_RXBAS_SDSZ_32MB PPC_REG_VAL(19, 0x3)
  1345 +#define SDRAM_RXBAS_SDSZ_64MB PPC_REG_VAL(19, 0x4)
  1346 +#define SDRAM_RXBAS_SDSZ_128MB PPC_REG_VAL(19, 0x5)
  1347 +#define SDRAM_RXBAS_SDSZ_256MB PPC_REG_VAL(19, 0x6)
  1348 +#define SDRAM_RXBAS_SDSZ_512MB PPC_REG_VAL(19, 0x7)
  1349 +#define SDRAM_RXBAS_SDSZ_1024MB PPC_REG_VAL(19, 0x8)
  1350 +#define SDRAM_RXBAS_SDSZ_2048MB PPC_REG_VAL(19, 0x9)
  1351 +#define SDRAM_RXBAS_SDSZ_4096MB PPC_REG_VAL(19, 0xA)
  1352 +#define SDRAM_RXBAS_SDSZ_8192MB PPC_REG_VAL(19, 0xB)
  1353 +#define SDRAM_RXBAS_SDSZ_8 SDRAM_RXBAS_SDSZ_8MB
  1354 +#define SDRAM_RXBAS_SDSZ_16 SDRAM_RXBAS_SDSZ_16MB
  1355 +#define SDRAM_RXBAS_SDSZ_32 SDRAM_RXBAS_SDSZ_32MB
  1356 +#define SDRAM_RXBAS_SDSZ_64 SDRAM_RXBAS_SDSZ_64MB
  1357 +#define SDRAM_RXBAS_SDSZ_128 SDRAM_RXBAS_SDSZ_128MB
  1358 +#define SDRAM_RXBAS_SDSZ_256 SDRAM_RXBAS_SDSZ_256MB
  1359 +#define SDRAM_RXBAS_SDSZ_512 SDRAM_RXBAS_SDSZ_512MB
  1360 +#define SDRAM_RXBAS_SDSZ_1024 SDRAM_RXBAS_SDSZ_1024MB
  1361 +#define SDRAM_RXBAS_SDSZ_2048 SDRAM_RXBAS_SDSZ_2048MB
  1362 +#define SDRAM_RXBAS_SDSZ_4096 SDRAM_RXBAS_SDSZ_4096MB
  1363 +#define SDRAM_RXBAS_SDSZ_8192 SDRAM_RXBAS_SDSZ_8192MB
  1364 +#define SDRAM_RXBAS_SDAM_MODE0 PPC_REG_VAL(23, 0x0)
  1365 +#define SDRAM_RXBAS_SDAM_MODE1 PPC_REG_VAL(23, 0x1)
  1366 +#define SDRAM_RXBAS_SDAM_MODE2 PPC_REG_VAL(23, 0x2)
  1367 +#define SDRAM_RXBAS_SDAM_MODE3 PPC_REG_VAL(23, 0x3)
  1368 +#define SDRAM_RXBAS_SDAM_MODE4 PPC_REG_VAL(23, 0x4)
  1369 +#define SDRAM_RXBAS_SDAM_MODE5 PPC_REG_VAL(23, 0x5)
  1370 +#define SDRAM_RXBAS_SDAM_MODE6 PPC_REG_VAL(23, 0x6)
  1371 +#define SDRAM_RXBAS_SDAM_MODE7 PPC_REG_VAL(23, 0x7)
  1372 +#define SDRAM_RXBAS_SDAM_MODE8 PPC_REG_VAL(23, 0x8)
  1373 +#define SDRAM_RXBAS_SDAM_MODE9 PPC_REG_VAL(23, 0x9)
  1374 +#define SDRAM_RXBAS_SDBE_DISABLE PPC_REG_VAL(31, 0x0)
  1375 +#define SDRAM_RXBAS_SDBE_ENABLE PPC_REG_VAL(31, 0x1)
1234 1376  
1235 1377 /*-----------------------------------------------------------------------------+
1236 1378 | Memory Controller Status
... ... @@ -1611,6 +1753,29 @@
1611 1753 #define SDR0_PFC1_USBBIGEN 0x00000010
1612 1754 #define SDR0_PFC1_GPT_FREQ 0x0000000f
1613 1755 #endif
  1756 +
  1757 +/* General Purpose Timer (GPT) Register Offsets */
  1758 +#define GPT0_TBC 0x00000000
  1759 +#define GPT0_IM 0x00000018
  1760 +#define GPT0_ISS 0x0000001C
  1761 +#define GPT0_ISC 0x00000020
  1762 +#define GPT0_IE 0x00000024
  1763 +#define GPT0_COMP0 0x00000080
  1764 +#define GPT0_COMP1 0x00000084
  1765 +#define GPT0_COMP2 0x00000088
  1766 +#define GPT0_COMP3 0x0000008C
  1767 +#define GPT0_COMP4 0x00000090
  1768 +#define GPT0_COMP5 0x00000094
  1769 +#define GPT0_COMP6 0x00000098
  1770 +#define GPT0_MASK0 0x000000C0
  1771 +#define GPT0_MASK1 0x000000C4
  1772 +#define GPT0_MASK2 0x000000C8
  1773 +#define GPT0_MASK3 0x000000CC
  1774 +#define GPT0_MASK4 0x000000D0
  1775 +#define GPT0_MASK5 0x000000D4
  1776 +#define GPT0_MASK6 0x000000D8
  1777 +#define GPT0_DCT0 0x00000110
  1778 +#define GPT0_DCIS 0x0000011C
1614 1779  
1615 1780 #endif /* __PPC405_H__ */
... ... @@ -29,6 +29,21 @@
29 29 #endif
30 30  
31 31 /*
  32 + * Macro for generating register field mnemonics
  33 + */
  34 +#define PPC_REG_BITS 32
  35 +#define PPC_REG_VAL(bit, value) ((value) << ((PPC_REG_BITS - 1) - (bit)))
  36 +
  37 +/*
  38 + * Elide casts when assembling register mnemonics
  39 + */
  40 +#ifndef __ASSEMBLY__
  41 +#define static_cast(type, val) (type)(val)
  42 +#else
  43 +#define static_cast(type, val) (val)
  44 +#endif
  45 +
  46 +/*
32 47 * Common stuff for 4xx (405 and 440)
33 48 */
34 49