]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - arch/mips/txx9/generic/setup.c
MIPS: TXx9: Cache fixup
[linux-2.6-omap-h63xx.git] / arch / mips / txx9 / generic / setup.c
index 0afe94c48fb65e82ee283f5fbd2fbce6362dcdb9..fa88aefea9ef247832f2278be176ec896ea7175a 100644 (file)
@@ -25,6 +25,7 @@
 #include <asm/bootinfo.h>
 #include <asm/time.h>
 #include <asm/reboot.h>
+#include <asm/r4kcache.h>
 #include <asm/txx9/generic.h>
 #include <asm/txx9/pci.h>
 #ifdef CONFIG_CPU_TX49XX
@@ -53,6 +54,7 @@ txx9_reg_res_init(unsigned int pcode, unsigned long base, unsigned long size)
                txx9_ce_res[i].name = txx9_ce_res_name[i];
        }
 
+       txx9_pcode = pcode;
        sprintf(txx9_pcode_str, "TX%x", pcode);
        if (base) {
                txx9_reg_res.start = base & 0xfffffffffULL;
@@ -118,39 +120,226 @@ int irq_to_gpio(unsigned irq)
 EXPORT_SYMBOL(irq_to_gpio);
 #endif
 
-extern struct txx9_board_vec jmr3927_vec;
-extern struct txx9_board_vec rbtx4927_vec;
-extern struct txx9_board_vec rbtx4937_vec;
-extern struct txx9_board_vec rbtx4938_vec;
+#define BOARD_VEC(board)       extern struct txx9_board_vec board;
+#include <asm/txx9/boards.h>
+#undef BOARD_VEC
 
 struct txx9_board_vec *txx9_board_vec __initdata;
 static char txx9_system_type[32];
 
-void __init prom_init_cmdline(void)
+static struct txx9_board_vec *board_vecs[] __initdata = {
+#define BOARD_VEC(board)       &board,
+#include <asm/txx9/boards.h>
+#undef BOARD_VEC
+};
+
+static struct txx9_board_vec *__init find_board_byname(const char *name)
+{
+       int i;
+
+       /* search board_vecs table */
+       for (i = 0; i < ARRAY_SIZE(board_vecs); i++) {
+               if (strstr(board_vecs[i]->system, name))
+                       return board_vecs[i];
+       }
+       return NULL;
+}
+
+static void __init prom_init_cmdline(void)
 {
        int argc = (int)fw_arg0;
-       char **argv = (char **)fw_arg1;
+       int *argv32 = (int *)fw_arg1;
        int i;                  /* Always ignore the "-c" at argv[0] */
-#ifdef CONFIG_64BIT
-       char *fixed_argv[32];
-       for (i = 0; i < argc; i++)
-               fixed_argv[i] = (char *)(long)(*((__s32 *)argv + i));
-       argv = fixed_argv;
-#endif
+       char builtin[CL_SIZE];
 
        /* ignore all built-in args if any f/w args given */
-       if (argc > 1)
-               *arcs_cmdline = '\0';
+       /*
+        * But if built-in strings was started with '+', append them
+        * to command line args.  If built-in was started with '-',
+        * ignore all f/w args.
+        */
+       builtin[0] = '\0';
+       if (arcs_cmdline[0] == '+')
+               strcpy(builtin, arcs_cmdline + 1);
+       else if (arcs_cmdline[0] == '-') {
+               strcpy(builtin, arcs_cmdline + 1);
+               argc = 0;
+       } else if (argc <= 1)
+               strcpy(builtin, arcs_cmdline);
+       arcs_cmdline[0] = '\0';
 
        for (i = 1; i < argc; i++) {
+               char *str = (char *)(long)argv32[i];
                if (i != 1)
                        strcat(arcs_cmdline, " ");
-               strcat(arcs_cmdline, argv[i]);
+               if (strchr(str, ' ')) {
+                       strcat(arcs_cmdline, "\"");
+                       strcat(arcs_cmdline, str);
+                       strcat(arcs_cmdline, "\"");
+               } else
+                       strcat(arcs_cmdline, str);
+       }
+       /* append saved builtin args */
+       if (builtin[0]) {
+               if (arcs_cmdline[0])
+                       strcat(arcs_cmdline, " ");
+               strcat(arcs_cmdline, builtin);
        }
 }
 
-void __init prom_init(void)
+static int txx9_ic_disable __initdata;
+static int txx9_dc_disable __initdata;
+
+#if defined(CONFIG_CPU_TX49XX)
+/* flush all cache on very early stage (before 4k_cache_init) */
+static void __init early_flush_dcache(void)
+{
+       unsigned int conf = read_c0_config();
+       unsigned int dc_size = 1 << (12 + ((conf & CONF_DC) >> 6));
+       unsigned int linesz = 32;
+       unsigned long addr, end;
+
+       end = INDEX_BASE + dc_size / 4;
+       /* 4way, waybit=0 */
+       for (addr = INDEX_BASE; addr < end; addr += linesz) {
+               cache_op(Index_Writeback_Inv_D, addr | 0);
+               cache_op(Index_Writeback_Inv_D, addr | 1);
+               cache_op(Index_Writeback_Inv_D, addr | 2);
+               cache_op(Index_Writeback_Inv_D, addr | 3);
+       }
+}
+
+static void __init txx9_cache_fixup(void)
+{
+       unsigned int conf;
+
+       conf = read_c0_config();
+       /* flush and disable */
+       if (txx9_ic_disable) {
+               conf |= TX49_CONF_IC;
+               write_c0_config(conf);
+       }
+       if (txx9_dc_disable) {
+               early_flush_dcache();
+               conf |= TX49_CONF_DC;
+               write_c0_config(conf);
+       }
+
+       /* enable cache */
+       conf = read_c0_config();
+       if (!txx9_ic_disable)
+               conf &= ~TX49_CONF_IC;
+       if (!txx9_dc_disable)
+               conf &= ~TX49_CONF_DC;
+       write_c0_config(conf);
+
+       if (conf & TX49_CONF_IC)
+               pr_info("TX49XX I-Cache disabled.\n");
+       if (conf & TX49_CONF_DC)
+               pr_info("TX49XX D-Cache disabled.\n");
+}
+#elif defined(CONFIG_CPU_TX39XX)
+/* flush all cache on very early stage (before tx39_cache_init) */
+static void __init early_flush_dcache(void)
+{
+       unsigned int conf = read_c0_config();
+       unsigned int dc_size = 1 << (10 + ((conf & TX39_CONF_DCS_MASK) >>
+                                          TX39_CONF_DCS_SHIFT));
+       unsigned int linesz = 16;
+       unsigned long addr, end;
+
+       end = INDEX_BASE + dc_size / 2;
+       /* 2way, waybit=0 */
+       for (addr = INDEX_BASE; addr < end; addr += linesz) {
+               cache_op(Index_Writeback_Inv_D, addr | 0);
+               cache_op(Index_Writeback_Inv_D, addr | 1);
+       }
+}
+
+static void __init txx9_cache_fixup(void)
 {
+       unsigned int conf;
+
+       conf = read_c0_config();
+       /* flush and disable */
+       if (txx9_ic_disable) {
+               conf &= ~TX39_CONF_ICE;
+               write_c0_config(conf);
+       }
+       if (txx9_dc_disable) {
+               early_flush_dcache();
+               conf &= ~TX39_CONF_DCE;
+               write_c0_config(conf);
+       }
+
+       /* enable cache */
+       conf = read_c0_config();
+       if (!txx9_ic_disable)
+               conf |= TX39_CONF_ICE;
+       if (!txx9_dc_disable)
+               conf |= TX39_CONF_DCE;
+       write_c0_config(conf);
+
+       if (!(conf & TX39_CONF_ICE))
+               pr_info("TX39XX I-Cache disabled.\n");
+       if (!(conf & TX39_CONF_DCE))
+               pr_info("TX39XX D-Cache disabled.\n");
+}
+#else
+static inline void txx9_cache_fixup(void)
+{
+}
+#endif
+
+static void __init preprocess_cmdline(void)
+{
+       char cmdline[CL_SIZE];
+       char *s;
+
+       strcpy(cmdline, arcs_cmdline);
+       s = cmdline;
+       arcs_cmdline[0] = '\0';
+       while (s && *s) {
+               char *str = strsep(&s, " ");
+               if (strncmp(str, "board=", 6) == 0) {
+                       txx9_board_vec = find_board_byname(str + 6);
+                       continue;
+               } else if (strncmp(str, "masterclk=", 10) == 0) {
+                       unsigned long val;
+                       if (strict_strtoul(str + 10, 10, &val) == 0)
+                               txx9_master_clock = val;
+                       continue;
+               } else if (strcmp(str, "icdisable") == 0) {
+                       txx9_ic_disable = 1;
+                       continue;
+               } else if (strcmp(str, "dcdisable") == 0) {
+                       txx9_dc_disable = 1;
+                       continue;
+               }
+               if (arcs_cmdline[0])
+                       strcat(arcs_cmdline, " ");
+               strcat(arcs_cmdline, str);
+       }
+
+       txx9_cache_fixup();
+}
+
+static void __init select_board(void)
+{
+       const char *envstr;
+
+       /* first, determine by "board=" argument in preprocess_cmdline() */
+       if (txx9_board_vec)
+               return;
+       /* next, determine by "board" envvar */
+       envstr = prom_getenv("board");
+       if (envstr) {
+               txx9_board_vec = find_board_byname(envstr);
+               if (txx9_board_vec)
+                       return;
+       }
+
+       /* select "default" board */
 #ifdef CONFIG_CPU_TX39XX
        txx9_board_vec = &jmr3927_vec;
 #endif
@@ -171,6 +360,13 @@ void __init prom_init(void)
 #endif
        }
 #endif
+}
+
+void __init prom_init(void)
+{
+       prom_init_cmdline();
+       preprocess_cmdline();
+       select_board();
 
        strcpy(txx9_system_type, txx9_board_vec->system);
 
@@ -191,6 +387,21 @@ char * __init prom_getcmdline(void)
        return &(arcs_cmdline[0]);
 }
 
+const char *__init prom_getenv(const char *name)
+{
+       const s32 *str = (const s32 *)fw_arg2;
+
+       if (!str)
+               return NULL;
+       /* YAMON style ("name", "value" pairs) */
+       while (str[0] && str[1]) {
+               if (!strcmp((const char *)(unsigned long)str[0], name))
+                       return (const char *)(unsigned long)str[1];
+               str += 2;
+       }
+       return NULL;
+}
+
 static void __noreturn txx9_machine_halt(void)
 {
        local_irq_disable();