1 /* $Id: start.S,v 1.1.1.1 2006/09/14 01:59:08 root Exp $ */
4 * Copyright (c) 2001 Opsycon AB (www.opsycon.se)
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Opsycon AB, Sweden.
17 * 4. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
21 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
24 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
44 #include "pmon/dev/ns16550.h"
45 #include "target/i82371eb.h"
46 #include "target/prid.h"
47 #include "target/sbd.h"
48 #include "target/bonito.h"
49 #include "target/i8254.h"
50 #include "target/pc97307.h"
51 #include "target/isapnpreg.h"
56 .rdata;98: .asciz x; .text; la a0, 98b; bal stringserial; nop
61 .rdata;98: .asciz x; .text; la a0, 98b; bal stringserial; nop
63 #define CONFIG_CACHE_64K_4WAY 1
72 #define CFG_IB 0x00000020
73 #define CFG_DB 0x00000010
75 #define CFG_BE 0x00008000
76 #define CFG_EPMASK 0x0f000000
77 #define CFG_EPD 0x00000000
78 #define CFG_EM_R4K 0x00000000
79 #define CFG_EMMASK 0x00c00000
80 #define CFG_AD 0x00800000
82 #define CP0_CONFIG $16
86 #define DDR100 0x04041091
87 #define DDR266 0x0410435e
88 #define DDR300 0x041453df
91 #define DEBUG_WR(num) \
102 * s0 link versus load offset, used to relocate absolute adresses.
106 * s4 Bonito base address.
121 stack = start - 0x4000 /* Place PMON stack below PMON start in RAM */
123 /* NOTE!! Not more that 16 instructions here!!! Right now it's FULL! */
124 mtc0 zero, COP_0_STATUS_REG
125 mtc0 zero, COP_0_CAUSE_REG
126 li t0, SR_BOOT_EXC_VEC /* Exception to Boostrap Location */
127 mtc0 t0, COP_0_STATUS_REG
131 bal uncached /* Switch to uncached address space */
134 bal locate /* Get current execute address */
138 or ra, UNCACHED_MEMORY_ADDR
143 * Reboot vector usable from outside pmon.
163 * Exception vectors here for rom, before we are up and running. Catch
164 * whatever comes up before we have a fully fledged exception handler.
166 .align 9 /* bfc00200 */
172 .align 7 /* bfc00280 */
179 .align 8 /* bfc00300 */
180 PRINTSTR("\r\nPANIC! Unexpected Cache Error exception! ")
181 mfc0 a0, COP_0_CACHE_ERR
186 /* General exception */
187 .align 7 /* bfc00380 */
193 .align 8 /* bfc00400 */
201 PRINTSTR("\r\nCAUSE=")
202 mfc0 a0, COP_0_CAUSE_REG
205 PRINTSTR("\r\nSTATUS=")
206 mfc0 a0, COP_0_STATUS_REG
209 PRINTSTR("\r\nERRORPC=")
210 mfc0 a0, COP_0_ERROR_PC
214 mfc0 a0, COP_0_EXC_PC
217 PRINTSTR("\r\nDERR0=")
218 cfc0 a0, COP_0_DERR_0
221 PRINTSTR("\r\nDERR1=")
222 cfc0 a0, COP_0_DERR_1
226 // b ext_map_and_reboot
249 * We get here from executing a bal to get the PC value of the current execute
250 * location into ra. Check to see if we run from ROM or if this is ramloaded.
257 li t0,SR_BOOT_EXC_VEC
258 mtc0 t0,COP_0_STATUS_REG
259 mtc0 zero,COP_0_CAUSE_REG
262 li bonito,PHYS_TO_UNCACHED(BONITO_REG_BASE)
265 #define MOD_MASK 0x00000003
266 #define MOD_B 0x00000000 /* byte "modifier" */
267 #define MOD_H 0x00000001 /* halfword "modifier" */
268 #define MOD_W 0x00000002 /* word "modifier" */
270 # define MOD_D 0x00000003 /* doubleword "modifier" */
273 #define OP_MASK 0x000000fc
274 #define OP_EXIT 0x00000000 /* exit (status) */
275 #define OP_DELAY 0x00000008 /* delay (cycles) */
276 #define OP_RD 0x00000010 /* read (addr) */
277 #define OP_WR 0x00000014 /* write (addr, val) */
278 #define OP_RMW 0x00000018 /* read-modify-write (addr, and, or) */
279 #define OP_WAIT 0x00000020 /* wait (addr, mask, value) */
281 #define WR_INIT(mod,addr,val) \
282 .word OP_WR|mod,PHYS_TO_UNCACHED(addr);\
285 #define RD_INIT(mod,addr) \
286 .word OP_RD|mod,PHYS_TO_UNCACHED(addr);\
289 #define RMW_INIT(mod,addr,and,or) \
290 .word OP_RMW|mod,PHYS_TO_UNCACHED(addr);\
293 #define WAIT_INIT(mod,addr,and,or) \
294 .word OP_WAIT|mod,PHYS_TO_UNCACHED(addr);\
297 #define DELAY_INIT(cycles) \
298 .word OP_DELAY,(cycles);\
301 #define EXIT_INIT(status) \
302 .word OP_EXIT,(status);\
305 #define BONITO_INIT(r,v) WR_INIT(MOD_W,BONITO_BASE+/**/r,v)
306 #define BONITO_BIS(r,b) RMW_INIT(MOD_W,BONITO_BASE+(r),~0,b)
307 #define BONITO_BIC(r,b) RMW_INIT(MOD_W,BONITO_BASE+(r),~(b),0)
308 #define BONITO_RMW(r,c,s) RMW_INIT(MOD_W,BONITO_BASE+(r),~(c),s)
310 #define CFGADDR(idsel,function,reg) ((1<<(11+(idsel)))+((function)<<8)+(reg))
311 #define _ISABWR_INIT(mod,function,isabreg,val) \
312 WR_INIT(MOD_W,BONITO_BASE+BONITO_PCIMAP_CFG,CFGADDR(PCI_IDSEL_I82371,function,isabreg)>>16) ; \
313 RD_INIT(MOD_W,BONITO_BASE+BONITO_PCIMAP_CFG) ; \
314 WR_INIT(mod,PCI_CFG_SPACE+(CFGADDR(PCI_IDSEL_I82371,function,isabreg)&0xffff),val)
316 #define _ISABRD_INIT(mod,function,isabreg) \
317 WR_INIT(MOD_W,BONITO_BASE+BONITO_PCIMAP_CFG,CFGADDR(PCI_IDSEL_I82371,function,isabreg)>>16) ; \
318 RD_INIT(MOD_W,BONITO_BASE+BONITO_PCIMAP_CFG) ; \
319 RD_INIT(mod,PCI_CFG_SPACE+(CFGADDR(PCI_IDSEL_I82371,function,isabreg)&0xffff))
322 #define _ISAWR_INIT(isareg,val) \
323 WR_INIT(MOD_B,PCI_IO_SPACE+(isareg),val)
325 #define _ISARD_INIT(isareg) \
326 RD_INIT(MOD_B,PCI_IO_SPACE+(isareg))
329 #define ISABBWR_INIT(function,isabreg,val) \
330 _ISABWR_INIT(MOD_B,function,(isabreg),val)
331 #define ISABHWR_INIT(function,isabreg,val) \
332 _ISABWR_INIT(MOD_H,function,(isabreg),val)
333 #define ISABWWR_INIT(function,isabreg,val) \
334 _ISABWR_INIT(MOD_W,function,isabreg,val)
335 #define ISAWR_INIT(isareg,val) \
336 _ISAWR_INIT(isareg,val)
337 #define ISARD_INIT(isareg) \
343 /* bonito endianess */
344 BONITO_BIC(BONITO_BONPONCFG,BONITO_BONPONCFG_CPUBIGEND)
345 BONITO_BIC(BONITO_BONGENCFG,BONITO_BONGENCFG_BYTESWAP|BONITO_BONGENCFG_MSTRBYTESWAP)
346 BONITO_BIS(BONITO_BONPONCFG, BONITO_BONPONCFG_IS_ARBITER)
349 * In certain situations it is possible for the Bonito ASIC
350 * to come up with the PCI registers uninitialised, so do them here
352 #define PCI_CLASS_BRIDGE 0x06
353 #define PCI_CLASS_SHIFT 24
354 #define PCI_SUBCLASS_BRIDGE_HOST 0x00
355 #define PCI_SUBCLASS_SHIFT 16
356 #define PCI_COMMAND_IO_ENABLE 0x00000001
357 #define PCI_COMMAND_MEM_ENABLE 0x00000002
358 #define PCI_COMMAND_MASTER_ENABLE 0x00000004
359 #define PCI_COMMAND_STATUS_REG 0x04
360 #define PCI_MAP_IO 0X00000001
361 #define PCI_DEV_I82371 17
362 #define PCI_CFG_SPACE BONITO_PCICFG_BASE
364 BONITO_INIT(BONITO_PCICLASS,(PCI_CLASS_BRIDGE << PCI_CLASS_SHIFT) | (PCI_SUBCLASS_BRIDGE_HOST << PCI_SUBCLASS_SHIFT))
365 BONITO_INIT(BONITO_PCICMD, BONITO_PCICMD_PERR_CLR|BONITO_PCICMD_SERR_CLR|BONITO_PCICMD_MABORT_CLR|BONITO_PCICMD_MTABORT_CLR|BONITO_PCICMD_TABORT_CLR|BONITO_PCICMD_MPERR_CLR)
366 BONITO_INIT(BONITO_PCILTIMER, 0)
367 BONITO_INIT(BONITO_PCIBASE0, 0)
368 BONITO_INIT(BONITO_PCIBASE1, 0)
369 BONITO_INIT(BONITO_PCIBASE2, 0)
370 BONITO_INIT(BONITO_PCIEXPRBASE, 0)
371 BONITO_INIT(BONITO_PCIINT, 0)
373 BONITO_BIS(BONITO_PCICMD, BONITO_PCICMD_PERRRESPEN)
375 BONITO_BIS(BONITO_PCICMD, PCI_COMMAND_IO_ENABLE|PCI_COMMAND_MEM_ENABLE|PCI_COMMAND_MASTER_ENABLE)
377 /* enable i/o buffer cache and other go faster bits */
378 BONITO_BIS(BONITO_BONGENCFG, \
379 BONITO_BONGENCFG_BUSERREN| \
380 BONITO_BONGENCFG_PREFETCHEN| \
381 BONITO_BONGENCFG_WBEHINDEN| \
382 BONITO_BONGENCFG_PCIQUEUE| \
383 BONITO_BONGENCFG_SNOOPEN)
385 BONITO_BIC(BONITO_BONGENCFG, 0x80) #½ûÖ¹iobc
387 # BONITO_BIS(BONITO_BONGENCFG, BONITO_BONGENCFG_BUSERREN)
390 BONITO_BIS(BONITO_BONGENCFG, BONITO_BONGENCFG_DEBUGMODE)
392 /******** added to void init southbridge*/
396 ISABWWR_INIT(2, 0x20, 0x8040|PCI_MAP_IO)
397 ISABWWR_INIT(2, PCI_COMMAND_STATUS_REG, 5)
400 /* zhb init floppy-disk */
401 ISABWWR_INIT(3, I82371_PCI3_DEVRESD, 0x1800)
402 ISABWWR_INIT(3, I82371_PCI3_DEVRESB, 0x20000000)
405 /* Turn most special purpose pins into GPIO; set ISA mode */
406 ISABWWR_INIT(0, I82371_GENCFG, I82371_GENCFG_CFG)
408 /* Set the SMB base address */
409 ISABWWR_INIT(3, I82371_PCI3_SMBBA, SMB_PORT|PCI_MAP_IO)
410 /* enable the host controller */
411 ISABBWR_INIT(3, I82371_PCI3_SMBHSTCFG, I82371_PCI3_SMB_HST_EN)
412 /* enable the SMB IO ports */
413 ISABBWR_INIT(3, PCI_COMMAND_STATUS_REG, PCI_COMMAND_IO_ENABLE)
415 ISABWWR_INIT(3, I82371_PCI3_PMBA, PM_PORT|PCI_MAP_IO) /*notice*/
417 ISABBWR_INIT(3, I82371_PCI3_PMREGMISC, 0x01)
420 /* disable RTC & KBD chip selects */
421 ISABHWR_INIT(0, I82371_XBCS, 0)
423 /* Enable PCI 2.1 timing support */
424 ISABBWR_INIT(0, I82371_DLC, I82371_DLC_DT /* | I82371_DLC_PR */ | I82371_DLC_USBPR | I82371_DLC_DTTE)
426 /* Set top of memory to 16MB, so all ISA bus master & DMA
427 accesses are forwarded to PCI mem space
429 ISABBWR_INIT(0, I82371_TOM, I82371_TOM_TOM(16) | I82371_TOM_FWD_LBIOS | I82371_TOM_FWD_AB | I82371_TOM_FWD_89)
432 /* 15us ISA bus refresh clock */
433 #define ISAREFRESH (PT_CRYSTAL/(1000000/15))
434 ISARD_INIT(CTC_PORT+PT_CONTROL)
436 /* program i8254 ISA refresh counter */
437 ISAWR_INIT(CTC_PORT+PT_CONTROL,PTCW_SC(PT_REFRESH)|PTCW_16B|PTCW_MODE(MODE_RG))
438 ISAWR_INIT(CTC_PORT+PT_REFRESH, ISAREFRESH & 0xff)
439 ISAWR_INIT(CTC_PORT+PT_REFRESH, ISAREFRESH >> 8)
441 /* program ISA ICU */
442 ISAWR_INIT(ICU1_PORT, 0x11) /* ICW1 */
443 ISAWR_INIT(ICU1_PORT+1,0x00) /* ICW2: vector */
444 ISAWR_INIT(ICU1_PORT+1,0x04) /* ICW3: cascade on IRQ2 */
445 ISAWR_INIT(ICU1_PORT+1,0x01) /* ICW4: 8086 mode */
446 ISAWR_INIT(ICU1_PORT+1,0xff) /* OCW1: mask all */
448 ISAWR_INIT(ICU2_PORT, 0x11) /* ICW1 */
449 ISAWR_INIT(ICU2_PORT+1,0x08) /* ICW2: vector */
450 ISAWR_INIT(ICU2_PORT+1,0x02) /* ICW3: */
451 ISAWR_INIT(ICU2_PORT+1,0x01) /* ICW4: 8086 mode */
452 ISAWR_INIT(ICU2_PORT+1,0xff) /* OCW1: mask all */
454 ISAWR_INIT(ICU1_PORT+1,~(1<<2)) /* enable IRQ2 */
455 /* set up ISA devices */
457 /* select logical device 1 (mouse) */
458 ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_LOGICAL_DEV_NUM)
459 ISAWR_INIT(ISAPNP_MBDATA,1)
460 ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_ACTIVATE)
461 ISAWR_INIT(ISAPNP_MBDATA,1)
463 /* select logical device 4 (parallel) */
464 ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_LOGICAL_DEV_NUM)
465 ISAWR_INIT(ISAPNP_MBDATA,4)
466 ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_IO_DESC0+ISAPNP_IO_BASE_15_8)
467 ISAWR_INIT(ISAPNP_MBDATA,(ECP_PORT>>8) & 0xff)
468 ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_IO_DESC0+ISAPNP_IO_BASE_7_0)
469 ISAWR_INIT(ISAPNP_MBDATA,ECP_PORT & 0xff)
470 ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_IRQ_DESC0+ISAPNP_IRQ_CONTROL)
471 ISAWR_INIT(ISAPNP_MBDATA,ISAPNP_IRQ_HIGH)
472 ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_ACTIVATE)
473 ISAWR_INIT(ISAPNP_MBDATA,1)
475 /* select logical device 5 (COM2) */
476 ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_LOGICAL_DEV_NUM)
477 ISAWR_INIT(ISAPNP_MBDATA,5)
478 ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_ACTIVATE)
479 ISAWR_INIT(ISAPNP_MBDATA,1)
481 /* select logical device 6 (COM1) */
482 ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_LOGICAL_DEV_NUM)
483 ISAWR_INIT(ISAPNP_MBDATA,6)
484 ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_ACTIVATE)
485 ISAWR_INIT(ISAPNP_MBDATA,1)
499 reginit: /* local name */
517 8: bne t4, OP_DELAY, 8f
643 * WAIT(ADDR,MASK,VAL)
689 .next: addu a0,Init_Size
699 /* Initialise other low-level I/O devices */
722 PRINTSTR("\r\nPMON2000 MIPS Initializing. Standby...\r\n")
726 mfc0 a0, COP_0_ERROR_PC
731 mfc0 a0, COP_0_CONFIG
742 PRINTSTR("Raw word read of SMB base address: ");
743 li a0,CFGADDR(PCI_DEV_I82371,3,I82371_PCI3_SMBBA)
744 li a1,PHYS_TO_UNCACHED(PCI_CFG_SPACE)
748 li a2,BONITO_BASE+BONITO_PCIMAP_CFG
749 sw a0,BONITO_PCIMAP_CFG(bonito)
750 lw zero,BONITO_PCIMAP_CFG(bonito)
759 /***(qiaochong) memeory initialization use macro,not smbbus ***/
760 /*bit 31: DDRÅäÖýáÊø±êÖ¾£¬1±íʾ½áÊø£¬Ö»¶Á*/
761 #define DDR_DQS_SELECT (0<<30) /*bit 30 Ñ¡ÔñÊý¾ÝÀ´Ô´£¬0: Ë«ÑزÉÑù£»1£ºDQS²ÉÑù*/
762 #define DDR_DIMM_DIC (1<<29) /*bit 29 ±êʶDIMM_slot0ÊÇ·ñ²åÓÐÄÚ´æÌõ¡£
764 #define DDR_DIMM_MODULE_NUM (3<<27) /*bit 28:27 DIMM0/DIMM1ÉÏMOUDLEµÄÊýÄ¿£º
765 2¡¯b00£ºDIMM1: 1; DIMM0: 1
766 2¡¯b01£ºDIMM1: 1; DIMM0: 2
767 2¡¯b10£ºDIMM1: 2; DIMM0: 1
768 2¡¯b11£ºDIMM1: 2; DIMM0: 2
770 #define DDR_IS_SEQ (1<<26) /*bit 26 ÒåÍ»·¢Ê½¶ÁдʱµÄ¿éÄÚ˳Ðò£¬
771 1¡¯b0£ºË³Ðò£»1¡¯b1£º½»Ì棬ÏÖÔÚÖ»Ö§³Ö½»Ì淽ʽ*/
772 #define DDR_TYPE (5<<22) /*bit 25:22 ±í2£ºDDR ¿ØÖÆÆ÷ËùÖ§³ÖµÄDDR SDRAM ¼ÆоƬÀàÐÍ
773 BITS Density Org. Row Addr. Col Addr.
774 0000 64Mb 16Mb X 4 DA[11:0] DA[9:0]
776 0001 64Mb 8Mb X 8 DA[11:0] DA[8:0]
778 0010 64Mb 4Mb X 16 DA[11:0] DA[7:0]
779 0011 128Mb 32Mb X 4 DA[11:0] DA[11],DA[9:0]
780 0100 256Mb 64Mb X 4 DA[12:0] DA[11],DA[9:0]
782 0101 256Mb 32Mb X 8 DA[12:0] DA[9:0]
784 0110 256Mb 16Mb X 16 DA[12:0] DA[8:0]
785 0111 512Mb 128Mb X 4 DA[12:0] DA[12:11],DA[9:0]
786 1000 1Gb 256Mb X 4 DA[13:0] DA[12:11],DA[9:0]
787 1001 1Gb 128Mb X 8 DA[13:0] DA[11],DA[9:0]
788 1010 1Gb 64Mb X 16 DA[13:0] DA[9:0]
790 #define DDR_tREF (100<<10) /*bit 21:10 SDRAMˢвÙ×÷Ö®¼ä¼ÆÊý£¨Ö÷Ƶ100MHz£©£º
793 SDRAMˢвÙ×÷Ö®¼ä¼ÆÊý£¨Ö÷Ƶ133MHz£©£º
796 SDRAMˢвÙ×÷Ö®¼ä¼ÆÊý£¨Ö÷Ƶ166MHz£©£º
800 #define DDR_TRCD (0<<9) /*bit 9 ÐеØÖ·ÓÐЧµ½ÁеØÖ·ÓÐЧ֮¼äÐè¾¹ýµÄ¼ÆÊý
801 1¡¯b0 2 cycles£¨DDR100£©
802 1¡¯b1 3 cycles£¨DDR266¡¢DDR333£©*/
803 #define DDR_TRPC (1<<7) /*bit 8:7 AUTO_REFRESHµ½ACTIVEÖ®¼äÐè¾¹ýµÄ¼ÆÊý
805 2¡¯b01 8 cylces £¨DDR100£©
806 2¡¯b10 10 cycles£¨DDR266£©
807 2¡¯b11 12 cycles£¨DDR333£©
809 #define DDR_TRAS (0<<6) /*bit 6 ACTIVEµ½PRECHARGEÖ®¼äÐè¾¹ýµÄ¼ÆÊý
810 1¡¯b0 5 cycles£¨DDR100£©
811 1¡¯b1 7 cycles£¨DDR266¡¢DDR333£©
813 #define DDR_TCAS (1<<4) /*bit 5:4 ´Ó¶ÁÃüÁîµ½µÚÒ»¸öÊý¾Ýµ½À´Ðè¾¹ýµÄ¼ÆÊý
819 #define DDR_TWR (0<<3) /*bit 3 д²Ù×÷×îºóÒ»¸öÊý¾Ýµ½PRECHARGEÖ®¼äÐè¾¹ýµÄ¼ÆÊý
820 1¡¯b0 2 cycles£¨DDR100£©
821 1¡¯b1 3 cycles£¨DDR266¡¢DDR333£©
823 #define DDR_TRP (0<<2) /*bit 2 PRECHARGEÃüÁîÖ´ÐÐʱ¼ä¼ÆÊý
824 1¡¯b0 2 cycles£¨DDR100£©
825 1¡¯b1 3 cycles£¨DDR266¡¢DDR333£©
827 #define DDR_TRC (1<<0) /*bit 1:0 ACTIVEÓëACTIVE/AUTO_REFRESHÃüÁîÖ®¼ä¼ÆÊý
829 2¡¯b01 7 cycles£¨DDR100£©
830 2¡¯b10 9 cycles£¨DDR266£©
831 2¡¯b11 10cycles£¨DDR333£©
832 ×¢£¨ÓÉÓÚprechargeºÍras casµÄÑÓʱ¼ÓÆðÀ´ÕýºÃÂú×ãÕâ¸öÑÓʱ£¬ËùÒÔÔÚDDR¿ØÖÆÆ÷ÀïûÓоßÌ忼ÂÇÕâ¸ö²ÎÊý£©
834 #define sdcfg_DATA DDR_DQS_SELECT|DDR_DIMM_DIC|DDR_DIMM_MODULE_NUM|DDR_IS_SEQ|DDR_TYPE|DDR_tREF|DDR_TRCD|DDR_TRPC|DDR_TRAS|DDR_TCAS|DDR_TWR|DDR_TRP|DDR_TRC
837 # li sdCfg,0x05441091
838 sw sdCfg,BONITO_SDCFG(bonito)
847 sw a0,BONITO_MEMSIZE(bonito)
852 li t1,0 # accumulate pcimembasecfg settings
854 /* set bar0 mask and translation to point to SDRAM */
857 srl t0,BONITO_PCIMEMBASECFG_ASHIFT-BONITO_PCIMEMBASECFG_MEMBASE0_MASK_SHIFT
858 and t0,BONITO_PCIMEMBASECFG_MEMBASE0_MASK
862 srl t0,BONITO_PCIMEMBASECFG_ASHIFT-BONITO_PCIMEMBASECFG_MEMBASE0_TRANS_SHIFT
863 and t0,BONITO_PCIMEMBASECFG_MEMBASE0_TRANS
865 or t1,BONITO_PCIMEMBASECFG_MEMBASE0_CACHED
867 /* set bar1 to minimum size to conserve PCI space */
869 srl t0,BONITO_PCIMEMBASECFG_ASHIFT-BONITO_PCIMEMBASECFG_MEMBASE1_MASK_SHIFT
870 and t0,BONITO_PCIMEMBASECFG_MEMBASE1_MASK
874 srl t0,BONITO_PCIMEMBASECFG_ASHIFT-BONITO_PCIMEMBASECFG_MEMBASE1_TRANS_SHIFT
875 and t0,BONITO_PCIMEMBASECFG_MEMBASE1_TRANS
877 or t1,BONITO_PCIMEMBASECFG_MEMBASE1_CACHED
879 sw t1,BONITO_PCIMEMBASECFG(bonito)
881 /* enable configuration cycles now */
882 lw t0,BONITO_BONPONCFG(bonito)
883 and t0,~BONITO_BONPONCFG_CONFIG_DIS
884 sw t0,BONITO_BONPONCFG(bonito)
886 PRINTSTR("Init SDRAM Done!\r\n");
889 * Reset and initialize caches to a known state.
891 #define IndexStoreTagI 0x08
892 #define IndexStoreTagD 0x09
893 #define IndexStoreTagS 0x0b
894 #define IndexStoreTagT 0x0a
898 * RM7000 config register bits.
900 #define CF_7_SE (1 << 3) /* Secondary cache enable */
901 #define CF_7_SC (1 << 31) /* Secondary cache not present */
902 #define CF_7_TE (1 << 12) /* Tertiary cache enable */
903 #define CF_7_TC (1 << 17) /* Tertiary cache not present */
904 #define CF_7_TS (3 << 20) /* Tertiary cache size */
905 #define CF_7_TS_AL 20 /* Shift to align */
906 #define NOP8 nop;nop;nop;nop;nop;nop;nop;nop
908 TTYDBG("Sizing caches...\r\n");
913 bne a0, a1, cache_done
915 TTYDBG("godson2 caches found\r\n")
916 bal godson2_cache_init
921 TTYDBG("Init caches done, cfg = ")
922 mfc0 a0, COP_0_CONFIG
927 #include "machine/newtest/mydebug.S"
930 TTYDBG("Copy PMON to execute location...\r\n")
931 #include "copypmon.S"
932 TTYDBG("Copy PMON to execute location done.\r\n")
933 #include "test_after_copy1.S"
937 sw a0, CpuTertiaryCacheSize /* Set L3 cache size */
946 TTYDBG("Dumping GT64240 setup.\r\n")
947 TTYDBG("offset----data------------------------.\r\n")
978 * Clear the TLB. Normally called from start.S.
986 li a3, 0 # First TLB index.
989 MTC0 a2, COP_0_TLB_PG_MASK # Whatever...
992 MTC0 zero, COP_0_TLB_HI # Clear entry high.
993 MTC0 zero, COP_0_TLB_LO0 # Clear entry low0.
994 MTC0 zero, COP_0_TLB_LO1 # Clear entry low1.
996 mtc0 a3, COP_0_TLB_INDEX # Set the index.
1001 tlbwi # Write the TLB
1011 * Set up the TLB. Normally called from start.S.
1014 li a3, 0 # First TLB index.
1017 MTC0 a2, COP_0_TLB_PG_MASK # All pages are 16Mb.
1021 MTC0 a2, COP_0_TLB_HI # Set up entry high.
1024 srl a2, a0, PG_SHIFT
1025 and a2, a2, PG_FRAME
1027 MTC0 a2, COP_0_TLB_LO0 # Set up entry low0.
1028 addu a2, (0x01000000 >> PG_SHIFT)
1029 MTC0 a2, COP_0_TLB_LO1 # Set up entry low1.
1031 mtc0 a3, COP_0_TLB_INDEX # Set the index.
1036 tlbwi # Write the TLB
1039 addu a0, a2 # Step address 32Mb.
1048 MTC0 a2, COP_0_TLB_HI # Set up entry high.
1051 MTC0 a2, COP_0_TLB_HI # Set up entry high.
1053 srl a2, a1, PG_SHIFT
1054 and a2, a1, PG_FRAME
1056 MTC0 a2, COP_0_TLB_LO0 # Set up entry low0.
1057 addu a2, (0x01000000 >> PG_SHIFT)
1058 MTC0 a2, COP_0_TLB_LO1 # Set up entry low1.
1059 MFC0 a3,COP_0_TLB_INDEX
1062 tlbwi # Write the TLB
1074 * Simple character printing routine used before full initialization
1134 #ifdef HAVE_NB_SERIAL
1135 la v0, COM3_BASE_ADDR
1142 la v0, COM1_BASE_ADDR
1148 la v0, COM2_BASE_ADDR
1155 lbu v1, NSREG(NS16550_LSR)(v0)
1160 sb a0, NSREG(NS16550_DATA)(v0)
1166 /* baud rate definitions, matching include/termios.h */
1181 #define B19200 19200
1182 #define B38400 38400
1183 #define B57600 57600
1184 #define B115200 115200
1189 #ifdef HAVE_NB_SERIAL
1190 la v0, COM3_BASE_ADDR
1191 li a0, NS16550HZ/(16*CONS_BAUD)
1195 li a0, NS16550HZ/2/(16*CONS_BAUD)
1199 la v0, COM1_BASE_ADDR
1206 la v0, COM2_BASE_ADDR
1213 li v1, FIFO_ENABLE|FIFO_RCV_RST|FIFO_XMT_RST|FIFO_TRIGGER_4
1214 sb v1, NSREG(NS16550_FIFO)(v0)
1216 sb v1, NSREG(NS16550_CFCR)(v0)
1217 //li v1, NS16550HZ/(16*CONS_BAUD)
1219 sb v1, NSREG(NS16550_DATA)(v0)
1221 sb v1, NSREG(NS16550_IER)(v0)
1223 sb v1, NSREG(NS16550_CFCR)(v0)
1224 li v1, MCR_DTR|MCR_RTS
1225 sb v1, NSREG(NS16550_MCR)(v0)
1227 sb v1, NSREG(NS16550_IER)(v0)
1234 #define get1counts \
1245 #ifdef NVRAM_IN_FLASH
1246 li a1,(0xbfc00000+NVRAM_OFFS+3)
1257 li a1,RTC_NVRAM_BASE+3
1262 sb a1,(PHYS_TO_UNCACHED(PCI_IO_SPACE+RTC_INDEX_REG))
1263 lbu v0,(PHYS_TO_UNCACHED(PCI_IO_SPACE+RTC_DATA_REG))
1281 and a0,a2,UART1_232|UART1_422|UART1_485
1286 and a0,a2,UART2_232|UART2_422|UART2_485
1292 sw a2,(PHYS_TO_UNCACHED(PCI_IO_SPACE+GPO_REG))
1298 li a0,(UART1_232|UART2_232|LAN1_EN|LAN2A_EN|LAN2B_EN|GPIO_SETS)
1299 sw a0,(PHYS_TO_UNCACHED(PCI_IO_SPACE+GPO_REG))
1305 /* enable configuration cycles now */
1306 lw t0,BONITO_BONPONCFG(bonito)
1308 sw t1,BONITO_BONPONCFG(bonito)
1313 sw t0,BONITO_BONPONCFG(bonito)
1318 #define I82371_RST_REG 0xcf9
1321 sb v0,(PHYS_TO_UNCACHED(PCI_IO_SPACE+I82371_RST_REG))
1323 sb v0,(PHYS_TO_UNCACHED(PCI_IO_SPACE+I82371_RST_REG))
1332 #define SMBOFFS(reg) I82371_SMB_SMB##reg
1337 li a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1338 lbu a0,SMBOFFS(HSTSTS)(a0)
1344 li a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1345 lbu a0,SMBOFFS(SLVSTS)(a0)
1351 li a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1352 lbu a0,SMBOFFS(HSTCNT)(a0)
1358 li a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1359 lbu a0,SMBOFFS(HSTCMD)(a0)
1365 li a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1366 lbu a0,SMBOFFS(HSTADD)(a0)
1372 li a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1373 lbu a0,SMBOFFS(HSTDAT0)(a0)
1379 li a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1380 lbu a0,SMBOFFS(HSTDAT1)(a0)
1386 li a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1387 lbu a0,SMBOFFS(BLKDAT)(a0)
1393 li a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1394 lbu a0,SMBOFFS(SLVCNT)(a0)
1400 li a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1401 lbu a0,SMBOFFS(SHDWCMD)(a0)
1407 li a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1408 lbu a0,SMBOFFS(SLVEVT)(a0)
1414 li a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1415 lbu a0,SMBOFFS(SLVDAT)(a0)
1428 li t0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1430 lbu t1,SMBOFFS(HSTSTS)(t0)
1431 and t1,~(I82371_SMB_FAILED|I82371_SMB_BUS_ERR|I82371_SMB_DEV_ERR|I82371_SMB_INTER)
1432 sb t1,SMBOFFS(HSTSTS)(t0)
1435 or t1,0xa1 # DIMM base address and read bit
1436 sb t1,SMBOFFS(HSTADD)(t0)
1437 sb a1,SMBOFFS(HSTCMD)(t0)
1440 li t1,I82371_SMB_START|I82371_SMB_BDRW
1441 sb t1,SMBOFFS(HSTCNT)(t0)
1444 1: lbu t1,SMBOFFS(HSTSTS)(t0)
1445 and t2,t1,I82371_SMB_FAILED|I82371_SMB_BUS_ERR|I82371_SMB_DEV_ERR|I82371_SMB_INTER
1454 # clear pending errors/interrupts
1455 sb t1,SMBOFFS(HSTSTS)(t0)
1457 and t2,t1,I82371_SMB_FAILED|I82371_SMB_BUS_ERR|I82371_SMB_DEV_ERR
1460 lbu v0,SMBOFFS(HSTDAT0)(t0)
1476 .asciz "\r\nInvalid transmit pattern. Must be DDDD or DDxDDx\r\n"
1478 .asciz "\r\nPANIC! Unexpected TLB refill exception!\r\n"
1480 .asciz "\r\nPANIC! Unexpected XTLB refill exception!\r\n"
1482 .asciz "\r\nPANIC! Unexpected General exception!\r\n"
1484 .asciz "\r\nPANIC! Unexpected Interrupt exception!\r\n"
1486 .ascii "0123456789abcdef"
1491 * I2C Functions used in early startup code to get SPD info from
1492 * SDRAM modules. This code must be entirely PIC and RAM independent.
1496 #define DELAY(count) \
1503 #define I2C_INT_ENABLE 0x80
1504 #define I2C_ENABLE 0x40
1505 #define I2C_ACK 0x04
1506 #define I2C_INT_FLAG 0x08
1507 #define I2C_STOP_BIT 0x10
1508 #define I2C_START_BIT 0x20
1510 #define I2C_AMOD_RD 0x01
1512 #define BUS_ERROR 0x00
1513 #define START_CONDITION_TRA 0x08
1514 #define RSTART_CONDITION_TRA 0x10
1515 #define ADDR_AND_WRITE_BIT_TRA_ACK_REC 0x18
1516 #define ADDR_AND_READ_BIT_TRA_ACK_REC 0x40
1517 #define SLAVE_REC_WRITE_DATA_ACK_TRA 0x28
1518 #define MAS_REC_READ_DATA_ACK_NOT_TRA 0x58
1520 #define Index_Store_Tag_D 0x05
1521 #define Index_Invalidate_I 0x00
1522 #define Index_Writeback_Inv_D 0x01
1529 LEAF(godson2_cache_init)
1531 cache_detect_size_way:
1545 srlv t6, t6, t7 /* 4way */
1553 #a0=0x80000000, a1=icache_size, a2=dcache_size
1554 #a3, v0 and v1 used as local registers
1562 cache Index_Store_Tag_D, 0x0(v0)
1563 cache Index_Store_Tag_D, 0x1(v0)
1567 cache Index_Store_Tag_D, 0x2(v0)
1568 cache Index_Store_Tag_D, 0x3(v0)
1579 cache Index_Invalidate_I, 0x0(v0)
1589 cache Index_Writeback_Inv_D, 0x0(v0)
1590 cache Index_Writeback_Inv_D, 0x1(v0)
1594 cache Index_Writeback_Inv_D, 0x2(v0)
1595 cache Index_Writeback_Inv_D, 0x3(v0)
1606 TTYDBG("cache init panic\r\n");
1609 .end godson2_cache_init
1611 #define WATCHDOG_REG BONITO(0x0160)
1615 sw a0,WATCHDOG_REG(bonito)
1617 sw a0,WATCHDOG_REG(bonito)