setup.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:8k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * setup.c
  3.  *
  4.  * BRIEF MODULE DESCRIPTION
  5.  * Momentum Computer Ocelot-G (CP7000G) - board dependent boot routines
  6.  *
  7.  * Copyright (C) 1996, 1997, 2001  Ralf Baechle
  8.  * Copyright (C) 2000 RidgeRun, Inc.
  9.  * Copyright (C) 2001 Red Hat, Inc.
  10.  * Copyright (C) 2002 Momentum Computer
  11.  *
  12.  * Author: Matthew Dharm, Momentum Computer
  13.  *   mdharm@momenco.com
  14.  *
  15.  * Author: RidgeRun, Inc.
  16.  *   glonnon@ridgerun.com, skranz@ridgerun.com, stevej@ridgerun.com
  17.  *
  18.  * Copyright 2001 MontaVista Software Inc.
  19.  * Author: jsun@mvista.com or jsun@junsun.net
  20.  *
  21.  *  This program is free software; you can redistribute  it and/or modify it
  22.  *  under  the terms of  the GNU General  Public License as published by the
  23.  *  Free Software Foundation;  either version 2 of the  License, or (at your
  24.  *  option) any later version.
  25.  *
  26.  *  THIS  SOFTWARE  IS PROVIDED   ``AS  IS'' AND   ANY  EXPRESS OR IMPLIED
  27.  *  WARRANTIES,   INCLUDING, BUT NOT  LIMITED  TO, THE IMPLIED WARRANTIES OF
  28.  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
  29.  *  NO  EVENT  SHALL   THE AUTHOR  BE    LIABLE FOR ANY   DIRECT, INDIRECT,
  30.  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  31.  *  NOT LIMITED   TO, PROCUREMENT OF  SUBSTITUTE GOODS  OR SERVICES; LOSS OF
  32.  *  USE, DATA,  OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  33.  *  ANY THEORY OF LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT
  34.  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  35.  *  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  36.  *
  37.  *  You should have received a copy of the  GNU General Public License along
  38.  *  with this program; if not, write  to the Free Software Foundation, Inc.,
  39.  *  675 Mass Ave, Cambridge, MA 02139, USA.
  40.  *
  41.  */
  42. #include <linux/init.h>
  43. #include <linux/kernel.h>
  44. #include <linux/types.h>
  45. #include <linux/mc146818rtc.h>
  46. #include <linux/mm.h>
  47. #include <linux/swap.h>
  48. #include <linux/ioport.h>
  49. #include <linux/sched.h>
  50. #include <linux/interrupt.h>
  51. #include <linux/pci.h>
  52. #include <linux/timex.h>
  53. #include <linux/vmalloc.h>
  54. #include <asm/time.h>
  55. #include <asm/bootinfo.h>
  56. #include <asm/page.h>
  57. #include <asm/bootinfo.h>
  58. #include <asm/io.h>
  59. #include <asm/irq.h>
  60. #include <asm/pci.h>
  61. #include <asm/processor.h>
  62. #include <asm/ptrace.h>
  63. #include <asm/reboot.h>
  64. #include <asm/mc146818rtc.h>
  65. #include <linux/version.h>
  66. #include <linux/bootmem.h>
  67. #include <linux/blk.h>
  68. #include "gt64240.h"
  69. #include "ocelot_pld.h"
  70. extern struct rtc_ops no_rtc_ops;
  71. unsigned long gt64240_base;
  72. /* These functions are used for rebooting or halting the machine*/
  73. extern void momenco_ocelot_restart(char *command);
  74. extern void momenco_ocelot_halt(void);
  75. extern void momenco_ocelot_power_off(void);
  76. extern void gt64240_time_init(void);
  77. extern void momenco_ocelot_irq_setup(void);
  78. static char reset_reason;
  79. #define ENTRYLO(x) ((pte_val(mk_pte_phys((x), PAGE_KERNEL_UNCACHED)) >> 6)|1)
  80. static void __init setup_l3cache(unsigned long size);
  81. void __init bus_error_init(void) { /* nothing */ }
  82. /* setup code for a handoff from a version 2 PMON 2000 PROM */
  83. void PMON_v2_setup(void)
  84. {
  85. /* A wired TLB entry for the GT64240 and the serial port. The
  86.    GT64240 is going to be hit on every IRQ anyway - there's
  87.    absolutely no point in letting it be a random TLB entry, as
  88.    it'll just cause needless churning of the TLB. And we use
  89.    the other half for the serial port, which is just a PITA
  90.    otherwise :)
  91. Device Physical Virtual
  92. GT64240 Internal Regs 0xf4000000 0xe0000000
  93. UARTs (CS2) 0xfd000000 0xe0001000
  94. */
  95. add_wired_entry(ENTRYLO(0xf4000000), ENTRYLO(0xf4010000), 0xf4000000, PM_64K);
  96. add_wired_entry(ENTRYLO(0xfd000000), ENTRYLO(0xfd001000), 0xfd000000, PM_4K);
  97. /* Also a temporary entry to let us talk to the Ocelot PLD and NVRAM
  98.    in the CS[012] region. We can't use ioremap() yet. The NVRAM
  99.    is a ST M48T37Y, which includes NVRAM, RTC, and Watchdog functions.
  100. Ocelot PLD (CS0) 0xfc000000 0xe0020000
  101. NVRAM (CS1) 0xfc800000 0xe0030000
  102. */
  103. add_temporary_entry(ENTRYLO(0xfc000000), ENTRYLO(0xfc010000), 0xfc000000, PM_64K);
  104. add_temporary_entry(ENTRYLO(0xfc800000), ENTRYLO(0xfc810000), 0xfc800000, PM_64K);
  105. gt64240_base = 0xf4000000;
  106. }
  107. void __init momenco_ocelot_g_setup(void)
  108. {
  109. void (*l3func)(unsigned long)=KSEG1ADDR(&setup_l3cache);
  110. unsigned int tmpword;
  111. board_time_init = gt64240_time_init;
  112. _machine_restart = momenco_ocelot_restart;
  113. _machine_halt = momenco_ocelot_halt;
  114. _machine_power_off = momenco_ocelot_power_off;
  115. /*
  116.  * initrd_start = (ulong)ocelot_initrd_start;
  117.  * initrd_end = (ulong)ocelot_initrd_start + (ulong)ocelot_initrd_size;
  118.  * initrd_below_start_ok = 1;
  119.  */
  120. rtc_ops = &no_rtc_ops;
  121. /* do handoff reconfiguration */
  122. PMON_v2_setup();
  123. /* Turn off the Bit-Error LED */
  124. OCELOT_PLD_WRITE(0x80, INTCLR);
  125. tmpword = OCELOT_PLD_READ(BOARDREV);
  126. if (tmpword < 26)
  127. printk("Momenco Ocelot-G: Board Assembly Rev. %cn", 'A'+tmpword);
  128. else
  129. printk("Momenco Ocelot-G: Board Assembly Revision #0x%xn", tmpword);
  130. tmpword = OCELOT_PLD_READ(PLD1_ID);
  131. printk("PLD 1 ID: %d.%dn", tmpword>>4, tmpword&15);
  132. tmpword = OCELOT_PLD_READ(PLD2_ID);
  133. printk("PLD 2 ID: %d.%dn", tmpword>>4, tmpword&15);
  134. tmpword = OCELOT_PLD_READ(RESET_STATUS);
  135. printk("Reset reason: 0x%xn", tmpword);
  136. reset_reason = tmpword;
  137. OCELOT_PLD_WRITE(0xff, RESET_STATUS);
  138. tmpword = OCELOT_PLD_READ(BOARD_STATUS);
  139. printk("Board Status register: 0x%02xn", tmpword);
  140. printk("  - User jumper: %sn", (tmpword & 0x80)?"installed":"absent");
  141. printk("  - Boot flash write jumper: %sn", (tmpword&0x40)?"installed":"absent");
  142. printk("  - Tulip PHY %s connectedn", (tmpword&0x10)?"is":"not");
  143. printk("  - L3 Cache size: %d MiBn", (1<<((tmpword&12) >> 2))&~1);
  144. printk("  - SDRAM size: %d MiBn", 1<<(6+(tmpword&3)));
  145. if (tmpword&12)
  146. l3func((1<<(((tmpword&12) >> 2)+20)));
  147. switch(tmpword &3) {
  148. case 3:
  149. /* 512MiB -- two banks of 256MiB */
  150. add_memory_region(  0x0<<20, 0x100<<20, BOOT_MEM_RAM);
  151. /*
  152. add_memory_region(0x100<<20, 0x100<<20, BOOT_MEM_RAM);
  153. */
  154. break;
  155. case 2:
  156. /* 256MiB -- two banks of 128MiB */
  157. add_memory_region( 0x0<<20, 0x80<<20, BOOT_MEM_RAM);
  158. add_memory_region(0x80<<20, 0x80<<20, BOOT_MEM_RAM);
  159. break;
  160. case 1:
  161. /* 128MiB -- 64MiB per bank */
  162. add_memory_region( 0x0<<20, 0x40<<20, BOOT_MEM_RAM);
  163. add_memory_region(0x40<<20, 0x40<<20, BOOT_MEM_RAM);
  164. break;
  165. case 0:
  166. /* 64MiB */
  167. add_memory_region( 0x0<<20, 0x40<<20, BOOT_MEM_RAM);
  168. break;
  169. }
  170. /* FIXME: Fix up the DiskOnChip mapping */
  171. GT_WRITE(0x468, 0xfef73);
  172. }
  173. extern int rm7k_tcache_enabled;
  174. /*
  175.  * This runs in KSEG1. See the verbiage in rm7k.c::probe_scache()
  176.  */
  177. #define Page_Invalidate_T 0x16
  178. static void __init setup_l3cache(unsigned long size)
  179. {
  180. int register i;
  181. unsigned long tmp;
  182. printk("Enabling L3 cache...");
  183. /* Enable the L3 cache in the GT64120A's CPU Configuration register */
  184. GT_READ(0, &tmp);
  185. GT_WRITE(0, tmp | (1<<14));
  186. /* Enable the L3 cache in the CPU */
  187. set_cp0_config(1<<12 /* CONF_TE */);
  188. /* Clear the cache */
  189. set_taglo(0);
  190. set_taghi(0);
  191. for (i=0; i < size; i+= 4096) {
  192. __asm__ __volatile__ (
  193. ".set noreordernt"
  194. ".set mips3nt"
  195. "cache %1, (%0)nt"
  196. ".set mips0nt"
  197. ".set reorder"
  198. :
  199. : "r" (KSEG0ADDR(i)),
  200.   "i" (Page_Invalidate_T));
  201. }
  202. /* Let the RM7000 MM code know that the tertiary cache is enabled */
  203. rm7k_tcache_enabled = 1;
  204. printk("Donen");
  205. }
  206. /* This needs to be one of the first initcalls, because no I/O port access
  207.    can work before this */
  208. static int io_base_ioremap(void)
  209. {
  210. /* we're mapping PCI accesses from 0xc0000000 to 0xf0000000 */
  211. void *io_remap_range = ioremap(0xc0000000, 0x30000000);
  212. if (!io_remap_range) {
  213. panic("Could not ioremap I/O port range");
  214. }
  215. printk("io_remap_range set at 0x%08xn", (uint32_t)io_remap_range);
  216. set_io_port_base(io_remap_range - 0xc0000000);
  217. return 0;
  218. }
  219. module_init(io_base_ioremap);