1 /* $Id: start.S,v 1.3 2004/05/17 10:39:22 wlin 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
71 #define CFG_IB 0x00000020
72 #define CFG_DB 0x00000010
74 #define CFG_BE 0x00008000
75 #define CFG_EPMASK 0x0f000000
76 #define CFG_EPD 0x00000000
77 #define CFG_EM_R4K 0x00000000
78 #define CFG_EMMASK 0x00c00000
79 #define CFG_AD 0x00800000
84 * s0 link versus load offset, used to relocate absolute adresses.
88 * s4 Bonito base address.
103 stack = start - 0x4000 /* Place PMON stack below PMON start in RAM */
105 /* NOTE!! Not more that 16 instructions here!!! Right now it's FULL! */
106 mtc0 zero, COP_0_STATUS_REG
107 mtc0 zero, COP_0_CAUSE_REG
108 li t0, SR_BOOT_EXC_VEC /* Exception to Boostrap Location */
109 mtc0 t0, COP_0_STATUS_REG
113 bal uncached /* Switch to uncached address space */
116 bal locate /* Get current execute address */
120 or ra, UNCACHED_MEMORY_ADDR
125 * Reboot vector usable from outside pmon.
145 * Exception vectors here for rom, before we are up and running. Catch
146 * whatever comes up before we have a fully fledged exception handler.
148 .align 9 /* bfc00200 */
154 .align 7 /* bfc00280 */
161 .align 8 /* bfc00300 */
162 PRINTSTR("\r\nPANIC! Unexpected Cache Error exception! ")
163 mfc0 a0, COP_0_CACHE_ERR
168 /* General exception */
169 .align 7 /* bfc00380 */
175 .align 8 /* bfc00400 */
183 PRINTSTR("\r\nERRORPC=")
184 mfc0 a0, COP_0_ERROR_PC
188 mfc0 a0, COP_0_EXC_PC
191 PRINTSTR("\r\nDERR0=")
192 cfc0 a0, COP_0_DERR_0
195 PRINTSTR("\r\nDERR1=")
196 cfc0 a0, COP_0_DERR_1
199 // b ext_map_and_reboot
222 * We get here from executing a bal to get the PC value of the current execute
223 * location into ra. Check to see if we run from ROM or if this is ramloaded.
230 li t0,SR_BOOT_EXC_VEC
231 mtc0 t0,COP_0_STATUS_REG
232 mtc0 zero,COP_0_CAUSE_REG
235 li bonito,PHYS_TO_UNCACHED(BONITO_REG_BASE)
238 la s0, start /* RA set from BAL above! */
239 subu s0, ra, s0 /* s0 is now load vs. link offset */
240 and s0, 0xffff0000 /* Mask off lower bits */
242 mfc0 v0,COP_0_STATUS_REG
243 mtc0 zero,COP_0_WATCH_LO
244 mtc0 zero,COP_0_WATCH_HI
245 and v0,SR_SOFT_RESET # preserve Soft Reset
246 or v0,SR_BOOT_EXC_VEC # set Boot Exceptions
247 beq t0,0x0a11,1f # R4200 rev 1.1: disable cache errors
249 beq t0,0x5413,1f # R5432 rev 1.3: disable cache errors
257 * Clean out and initialize the TLB
268 * Turn off all high decoders to avoid address conflicts.
270 mtc0 v0,COP_0_STATUS_REG
271 mtc0 zero,COP_0_CAUSE_REG
273 mfc0 t2,COP_0_PRID # get PrID
274 mtc0 zero,$18 # C0_IWATCH/C0_WATCHLO
275 mtc0 zero,$19 # C0_DWATCH/C0_WATCHHI
277 li bonito,PHYS_TO_UNCACHED(BONITO_REG_BASE)
284 mtc0 zero,$0 # C0_IBASE
285 mtc0 zero,$1 # C0_IBOUND
286 mtc0 zero,$2 # C0_DBASE
287 mtc0 zero,$3 # C0_DBOUND
292 and t1,~0x3f # set bits 5..0 only
293 or t1,CFG_IB | CFG_DB | CFG_C_WBACK
304 2: mtc0 t1,COP_0_CONFIG
305 3: mfc0 t1,COP_0_STATUS_REG # get Status
306 mtc0 zero,COP_0_CAUSE_REG
307 and t1,SR_SOFT_RESET # leave the SoftReset bit
308 or t1,SR_BOOT_EXC_VEC # force Boot Exception Vec
309 mtc0 t1,COP_0_STATUS_REG
312 #define MOD_MASK 0x00000003
313 #define MOD_B 0x00000000 /* byte "modifier" */
314 #define MOD_H 0x00000001 /* halfword "modifier" */
315 #define MOD_W 0x00000002 /* word "modifier" */
317 # define MOD_D 0x00000003 /* doubleword "modifier" */
320 #define OP_MASK 0x000000fc
321 #define OP_EXIT 0x00000000 /* exit (status) */
322 #define OP_DELAY 0x00000008 /* delay (cycles) */
323 #define OP_RD 0x00000010 /* read (addr) */
324 #define OP_WR 0x00000014 /* write (addr, val) */
325 #define OP_RMW 0x00000018 /* read-modify-write (addr, and, or) */
326 #define OP_WAIT 0x00000020 /* wait (addr, mask, value) */
328 #define WR_INIT(mod,addr,val) \
329 .word OP_WR|mod,PHYS_TO_UNCACHED(addr);\
332 #define RD_INIT(mod,addr) \
333 .word OP_RD|mod,PHYS_TO_UNCACHED(addr);\
336 #define RMW_INIT(mod,addr,and,or) \
337 .word OP_RMW|mod,PHYS_TO_UNCACHED(addr);\
340 #define WAIT_INIT(mod,addr,and,or) \
341 .word OP_WAIT|mod,PHYS_TO_UNCACHED(addr);\
344 #define DELAY_INIT(cycles) \
345 .word OP_DELAY,(cycles);\
348 #define EXIT_INIT(status) \
349 .word OP_EXIT,(status);\
352 #define BONITO_INIT(r,v) WR_INIT(MOD_W,BONITO_BASE+/**/r,v)
353 #define BONITO_BIS(r,b) RMW_INIT(MOD_W,BONITO_BASE+(r),~0,b)
354 #define BONITO_BIC(r,b) RMW_INIT(MOD_W,BONITO_BASE+(r),~(b),0)
355 #define BONITO_RMW(r,c,s) RMW_INIT(MOD_W,BONITO_BASE+(r),~(c),s)
357 #define CFGADDR(idsel,function,reg) ((1<<(11+(idsel)))+((function)<<8)+(reg))
358 #define _ISABWR_INIT(mod,function,isabreg,val) \
359 WR_INIT(MOD_W,BONITO_BASE+BONITO_PCIMAP_CFG,CFGADDR(PCI_IDSEL_I82371,function,isabreg)>>16) ; \
360 RD_INIT(MOD_W,BONITO_BASE+BONITO_PCIMAP_CFG) ; \
361 WR_INIT(mod,PCI_CFG_SPACE+(CFGADDR(PCI_IDSEL_I82371,function,isabreg)&0xffff),val)
363 #define _ISABRD_INIT(mod,function,isabreg) \
364 WR_INIT(MOD_W,BONITO_BASE+BONITO_PCIMAP_CFG,CFGADDR(PCI_IDSEL_I82371,function,isabreg)>>16) ; \
365 RD_INIT(MOD_W,BONITO_BASE+BONITO_PCIMAP_CFG) ; \
366 RD_INIT(mod,PCI_CFG_SPACE+(CFGADDR(PCI_IDSEL_I82371,function,isabreg)&0xffff))
369 #define _ISAWR_INIT(isareg,val) \
370 WR_INIT(MOD_B,PCI_IO_SPACE+(isareg),val)
372 #define _ISARD_INIT(isareg) \
373 RD_INIT(MOD_B,PCI_IO_SPACE+(isareg))
376 #define ISABBWR_INIT(function,isabreg,val) \
377 _ISABWR_INIT(MOD_B,function,(isabreg),val)
378 #define ISABHWR_INIT(function,isabreg,val) \
379 _ISABWR_INIT(MOD_H,function,(isabreg),val)
380 #define ISABWWR_INIT(function,isabreg,val) \
381 _ISABWR_INIT(MOD_W,function,isabreg,val)
382 #define ISAWR_INIT(isareg,val) \
383 _ISAWR_INIT(isareg,val)
384 #define ISARD_INIT(isareg) \
390 /* bonito endianess */
391 BONITO_BIC(BONITO_BONPONCFG,BONITO_BONPONCFG_CPUBIGEND)
392 BONITO_BIC(BONITO_BONGENCFG,BONITO_BONGENCFG_BYTESWAP|BONITO_BONGENCFG_MSTRBYTESWAP)
393 BONITO_BIS(BONITO_BONPONCFG, BONITO_BONPONCFG_IS_ARBITER)
396 * In certain situations it is possible for the Bonito ASIC
397 * to come up with the PCI registers uninitialised, so do them here
399 #define PCI_CLASS_BRIDGE 0x06
400 #define PCI_CLASS_SHIFT 24
401 #define PCI_SUBCLASS_BRIDGE_HOST 0x00
402 #define PCI_SUBCLASS_SHIFT 16
403 #define PCI_COMMAND_IO_ENABLE 0x00000001
404 #define PCI_COMMAND_MEM_ENABLE 0x00000002
405 #define PCI_COMMAND_MASTER_ENABLE 0x00000004
406 #define PCI_COMMAND_STATUS_REG 0x04
407 #define PCI_MAP_IO 0X00000001
408 #define PCI_DEV_I82371 17
409 #define PCI_CFG_SPACE BONITO_PCICFG_BASE
411 BONITO_INIT(BONITO_PCICLASS,(PCI_CLASS_BRIDGE << PCI_CLASS_SHIFT) | (PCI_SUBCLASS_BRIDGE_HOST << PCI_SUBCLASS_SHIFT))
412 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)
413 BONITO_INIT(BONITO_PCILTIMER, 0)
414 BONITO_INIT(BONITO_PCIBASE0, 0)
415 BONITO_INIT(BONITO_PCIBASE1, 0)
416 BONITO_INIT(BONITO_PCIBASE2, 0)
417 BONITO_INIT(BONITO_PCIEXPRBASE, 0)
418 BONITO_INIT(BONITO_PCIINT, 0)
420 BONITO_BIS(BONITO_PCICMD, BONITO_PCICMD_PERRRESPEN)
422 BONITO_BIS(BONITO_PCICMD, PCI_COMMAND_IO_ENABLE|PCI_COMMAND_MEM_ENABLE|PCI_COMMAND_MASTER_ENABLE)
424 /* enable i/o buffer cache and other go faster bits */
425 BONITO_BIS(BONITO_BONGENCFG, \
426 BONITO_BONGENCFG_BUSERREN| \
427 BONITO_BONGENCFG_PREFETCHEN| \
428 BONITO_BONGENCFG_WBEHINDEN| \
429 BONITO_BONGENCFG_PCIQUEUE| \
430 BONITO_BONGENCFG_SNOOPEN)
432 BONITO_BIC(BONITO_BONGENCFG, 0x80) #½ûÖ¹iobc
434 # BONITO_BIS(BONITO_BONGENCFG, BONITO_BONGENCFG_BUSERREN)
437 BONITO_BIS(BONITO_BONGENCFG, BONITO_BONGENCFG_DEBUGMODE)
439 /******** added to void init southbridge*/
442 /* Turn most special purpose pins into GPIO; set ISA mode */
443 ISABWWR_INIT(0, I82371_GENCFG, I82371_GENCFG_CFG)
445 /* disable RTC & KBD chip selects */
446 ISABHWR_INIT(0, I82371_XBCS, 0)
448 /* Enable PCI 2.1 timing support */
449 ISABBWR_INIT(0, I82371_DLC, I82371_DLC_DT /* | I82371_DLC_PR */ | I82371_DLC_USBPR | I82371_DLC_DTTE)
451 /* Set top of memory to 16MB, so all ISA bus master & DMA
452 accesses are forwarded to PCI mem space
454 ISABBWR_INIT(0, I82371_TOM, I82371_TOM_TOM(16) | I82371_TOM_FWD_LBIOS | I82371_TOM_FWD_AB | I82371_TOM_FWD_89)
456 /* Set the SMB base address */
457 ISABWWR_INIT(3, I82371_PCI3_SMBBA, SMB_PORT|PCI_MAP_IO)
458 /* enable the host controller */
459 ISABBWR_INIT(3, I82371_PCI3_SMBHSTCFG, I82371_PCI3_SMB_HST_EN)
460 /* enable the SMB IO ports */
461 ISABBWR_INIT(3, PCI_COMMAND_STATUS_REG, PCI_COMMAND_IO_ENABLE)
463 ISABWWR_INIT(3, I82371_PCI3_PMBA, 0x8000|PCI_MAP_IO)
464 ISABBWR_INIT(3, I82371_PCI3_PMREGMISC, 0x01)
466 /* 15us ISA bus refresh clock */
467 #define ISAREFRESH (PT_CRYSTAL/(1000000/15))
468 ISARD_INIT(CTC_PORT+PT_CONTROL)
470 /* program i8254 ISA refresh counter */
471 ISAWR_INIT(CTC_PORT+PT_CONTROL,PTCW_SC(PT_REFRESH)|PTCW_16B|PTCW_MODE(MODE_RG))
472 ISAWR_INIT(CTC_PORT+PT_REFRESH, ISAREFRESH & 0xff)
473 ISAWR_INIT(CTC_PORT+PT_REFRESH, ISAREFRESH >> 8)
475 /* program ISA ICU */
476 ISAWR_INIT(ICU1_PORT, 0x11) /* ICW1 */
477 ISAWR_INIT(ICU1_PORT+1,0x00) /* ICW2: vector */
478 ISAWR_INIT(ICU1_PORT+1,0x04) /* ICW3: cascade on IRQ2 */
479 ISAWR_INIT(ICU1_PORT+1,0x01) /* ICW4: 8086 mode */
480 ISAWR_INIT(ICU1_PORT+1,0xff) /* OCW1: mask all */
482 ISAWR_INIT(ICU2_PORT, 0x11) /* ICW1 */
483 ISAWR_INIT(ICU2_PORT+1,0x08) /* ICW2: vector */
484 ISAWR_INIT(ICU2_PORT+1,0x02) /* ICW3: */
485 ISAWR_INIT(ICU2_PORT+1,0x01) /* ICW4: 8086 mode */
486 ISAWR_INIT(ICU2_PORT+1,0xff) /* OCW1: mask all */
488 ISAWR_INIT(ICU1_PORT+1,~(1<<2)) /* enable IRQ2 */
489 /* set up ISA devices */
491 /* select logical device 1 (mouse) */
492 ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_LOGICAL_DEV_NUM)
493 ISAWR_INIT(ISAPNP_MBDATA,1)
494 ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_ACTIVATE)
495 ISAWR_INIT(ISAPNP_MBDATA,1)
497 /* select logical device 4 (parallel) */
498 ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_LOGICAL_DEV_NUM)
499 ISAWR_INIT(ISAPNP_MBDATA,4)
500 ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_IO_DESC0+ISAPNP_IO_BASE_15_8)
501 ISAWR_INIT(ISAPNP_MBDATA,(ECP_PORT>>8) & 0xff)
502 ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_IO_DESC0+ISAPNP_IO_BASE_7_0)
503 ISAWR_INIT(ISAPNP_MBDATA,ECP_PORT & 0xff)
504 ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_IRQ_DESC0+ISAPNP_IRQ_CONTROL)
505 ISAWR_INIT(ISAPNP_MBDATA,ISAPNP_IRQ_HIGH)
506 ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_ACTIVATE)
507 ISAWR_INIT(ISAPNP_MBDATA,1)
509 /* select logical device 5 (COM2) */
510 ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_LOGICAL_DEV_NUM)
511 ISAWR_INIT(ISAPNP_MBDATA,5)
512 ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_ACTIVATE)
513 ISAWR_INIT(ISAPNP_MBDATA,1)
515 /* select logical device 6 (COM1) */
516 ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_LOGICAL_DEV_NUM)
517 ISAWR_INIT(ISAPNP_MBDATA,6)
518 ISAWR_INIT(ISAPNP_MBADDR,ISAPNP_ACTIVATE)
519 ISAWR_INIT(ISAPNP_MBDATA,1)
532 reginit: /* local name */
550 8: bne t4, OP_DELAY, 8f
676 * WAIT(ADDR,MASK,VAL)
722 .next: addu a0,Init_Size
732 /* Initialise other low-level I/O devices */
738 PRINTSTR("\r\nPMON2000 MIPS Initializing. Standby...\r\n")
741 mfc0 a0, COP_0_ERROR_PC
746 mfc0 a0, COP_0_CONFIG
757 PRINTSTR("Raw word read of SMB base address: ");
758 li a0,CFGADDR(PCI_DEV_I82371,3,I82371_PCI3_SMBBA)
759 li a1,PHYS_TO_UNCACHED(PCI_CFG_SPACE)
763 li a2,BONITO_BASE+BONITO_PCIMAP_CFG
764 sw a0,BONITO_PCIMAP_CFG(bonito)
765 lw zero,BONITO_PCIMAP_CFG(bonito)
774 PRINTSTR("Raw word read of SMB HSTCFG: ");
775 li a0,CFGADDR(PCI_DEV_I82371,3,I82371_PCI3_SMBHSTCFG) # byte???
776 li a1,PHYS_TO_UNCACHED(PCI_CFG_SPACE)
780 li a2,BONITO_BASE+BONITO_PCIMAP_CFG
781 sw a0,BONITO_PCIMAP_CFG(bonito)
782 lw zero,BONITO_PCIMAP_CFG(bonito)
790 PRINTSTR("Raw word read of SMB IO ENABLE: ");
791 li a0,CFGADDR(PCI_DEV_I82371,3,PCI_COMMAND_STATUS_REG)
792 li a1,PHYS_TO_UNCACHED(PCI_CFG_SPACE)
796 li a2,BONITO_BASE+BONITO_PCIMAP_CFG
797 sw a0,BONITO_PCIMAP_CFG(bonito)
798 lw zero,BONITO_PCIMAP_CFG(bonito)
813 PRINTSTR("DIMM read\n")
814 #ifdef DEBUG_DIMM_SPD
834 * Now determine DRAM configuration and size by
835 * reading the I2C EEROM on the DIMMS
840 /* start with SODIMM #0 */
847 /* read DIMM memory type (must be SDRAM) */
853 PRINTSTR("read memory type\r\n")
854 /* read DIMM memory size per side */
860 sll tmpsize,v0,22 # multiply by 4M
862 PRINTSTR("read memory size per side\r\n")
863 /* read DIMM number of rows */
868 bgtu v0,14-11,.nodimm
870 sll v0,BONITO_SDCFG_AROWBITS_SHIFT
871 and v0,BONITO_SDCFG_AROWBITS
874 PRINTSTR("read number of rows\r\n")
875 2: /* read DIMM number of cols */
882 sll v0,BONITO_SDCFG_ACOLBITS_SHIFT
883 and v0,BONITO_SDCFG_ACOLBITS
886 PRINTSTR("read number of col\r\n")
887 2: /* read DIMM number of blocks-per-dram */
895 or sdShape,BONITO_SDCFG_ABANKBIT
897 PRINTSTR("read blocks per dram\r\n")
898 2: /* read DIMM number of sides (banks) */
906 or sdShape,BONITO_SDCFG_ASIDES
907 sll tmpsize,1 # msize *= 2
909 PRINTSTR("read number of sides\r\n")
910 2: /* read DIMM width */
918 or sdShape,BONITO_SDCFG_AWIDTH64
920 PRINTSTR("read width\r\n")
921 2: addu msize,tmpsize
927 PRINTSTR ("\r\niNo DIMM in slot ")
934 or sdShape,BONITO_SDCFG_AABSENT
937 sll sdShape,BONITO_SDCFG_BROWBITS_SHIFT
941 PRINTSTR("DIMM0 in slot")
947 PRINTSTR("DIMM1...\n")
953 PRINTSTR("DIMM SIZE=")
958 /* If we are running in SDRAM, chop 4MB off the memory size,
959 and don't modify sdCfg register (assume someone in
960 PCI-world has already set it up). */
961 lw t0,BONITO_BONPONCFG(bonito)
962 and t0,BONITO_BONPONCFG_ROMBOOT
963 bne t0,BONITO_BONPONCFG_ROMBOOT_SDRAM,1f
965 beqz msize,2f # already zero!
970 1: sw sdCfg,BONITO_SDCFG(bonito)
977 sw sdCfg,BONITO_SDCFG(bonito)
988 li t1,0 # accumulate pcimembasecfg settings
990 /* set bar0 mask and translation to point to SDRAM */
993 srl t0,BONITO_PCIMEMBASECFG_ASHIFT-BONITO_PCIMEMBASECFG_MEMBASE0_MASK_SHIFT
994 and t0,BONITO_PCIMEMBASECFG_MEMBASE0_MASK
998 srl t0,BONITO_PCIMEMBASECFG_ASHIFT-BONITO_PCIMEMBASECFG_MEMBASE0_TRANS_SHIFT
999 and t0,BONITO_PCIMEMBASECFG_MEMBASE0_TRANS
1001 or t1,BONITO_PCIMEMBASECFG_MEMBASE0_CACHED
1003 /* set bar1 to minimum size to conserve PCI space */
1005 srl t0,BONITO_PCIMEMBASECFG_ASHIFT-BONITO_PCIMEMBASECFG_MEMBASE1_MASK_SHIFT
1006 and t0,BONITO_PCIMEMBASECFG_MEMBASE1_MASK
1010 srl t0,BONITO_PCIMEMBASECFG_ASHIFT-BONITO_PCIMEMBASECFG_MEMBASE1_TRANS_SHIFT
1011 and t0,BONITO_PCIMEMBASECFG_MEMBASE1_TRANS
1013 or t1,BONITO_PCIMEMBASECFG_MEMBASE1_CACHED
1015 sw t1,BONITO_PCIMEMBASECFG(bonito)
1017 /* enable configuration cycles now */
1018 lw t0,BONITO_BONPONCFG(bonito)
1019 and t0,~BONITO_BONPONCFG_CONFIG_DIS
1020 sw t0,BONITO_BONPONCFG(bonito)
1022 PRINTSTR("Init SDRAM Done!\r\n");
1025 * Reset and initialize caches to a known state.
1027 #define IndexStoreTagI 0x08
1028 #define IndexStoreTagD 0x09
1029 #define IndexStoreTagS 0x0b
1030 #define IndexStoreTagT 0x0a
1034 * RM7000 config register bits.
1036 #define CF_7_SE (1 << 3) /* Secondary cache enable */
1037 #define CF_7_SC (1 << 31) /* Secondary cache not present */
1038 #define CF_7_TE (1 << 12) /* Tertiary cache enable */
1039 #define CF_7_TC (1 << 17) /* Tertiary cache not present */
1040 #define CF_7_TS (3 << 20) /* Tertiary cache size */
1041 #define CF_7_TS_AL 20 /* Shift to align */
1042 #define NOP8 nop;nop;nop;nop;nop;nop;nop;nop
1044 TTYDBG("Sizing caches...\r\n");
1046 mfc0 t3, COP_0_CONFIG /* t3 = original config */
1047 and t3, 0xffffeff0 /* Make sure coherency is OK */
1049 and t3, ~(CF_7_TE|CF_7_SE|CF_7_TC|CF_7_SC) /* disable L2/L3 cache */
1050 mtc0 t3, COP_0_CONFIG
1057 sllv s3, t2, t1 /* s3 = I cache size */
1061 addu s4, t1, 16 /* s4 = I cache line size */
1065 sllv s5, t2, t1 /* s5 = D cache size */
1068 addu s6, t1, 16 /* s6 = D cache line size */
1070 TTYDBG("Init caches...\r\n")
1072 li s7, 0 /* no L2 cache */
1073 li s8, 0 /* no L3 cache */
1076 # TTYDBG("godson2 caches found\r\n")
1077 bal godson1_cache_init
1081 TTYDBG("Init caches done, cfg = ")
1082 mfc0 a0, COP_0_CONFIG
1088 TTYDBG("Copy PMON to execute location...\r\n")
1090 TTYDBG(" start = 0x")
1094 TTYDBG("\r\n copytoram = 0x")
1099 TTYDBG("\r\n s0 = 0x")
1117 /* copy text section */
1119 1: and t3,t0,0x0000ffff
1136 PRINTSTR("\ncopy text section done.\r\n")
1146 TTYDBG("Copy PMON to execute location done.\r\n")
1148 /*sw 0, CpuTertiaryCacheSize*/ /* Set L3 cache size */
1157 TTYDBG("Dumping GT64240 setup.\r\n")
1158 TTYDBG("offset----data------------------------.\r\n")
1189 * Clear the TLB. Normally called from start.S.
1197 li a3, 0 # First TLB index.
1200 MTC0 a2, COP_0_TLB_PG_MASK # Whatever...
1203 MTC0 zero, COP_0_TLB_HI # Clear entry high.
1204 MTC0 zero, COP_0_TLB_LO0 # Clear entry low0.
1205 MTC0 zero, COP_0_TLB_LO1 # Clear entry low1.
1207 mtc0 a3, COP_0_TLB_INDEX # Set the index.
1212 tlbwi # Write the TLB
1222 * Set up the TLB. Normally called from start.S.
1225 li a3, 0 # First TLB index.
1228 MTC0 a2, COP_0_TLB_PG_MASK # All pages are 16Mb.
1232 MTC0 a2, COP_0_TLB_HI # Set up entry high.
1235 srl a2, a0, PG_SHIFT
1236 and a2, a2, PG_FRAME
1238 MTC0 a2, COP_0_TLB_LO0 # Set up entry low0.
1239 addu a2, (0x01000000 >> PG_SHIFT)
1240 MTC0 a2, COP_0_TLB_LO1 # Set up entry low1.
1242 mtc0 a3, COP_0_TLB_INDEX # Set the index.
1247 tlbwi # Write the TLB
1250 addu a0, a2 # Step address 32Mb.
1257 * Simple character printing routine used before full initialization
1260 #define TXWAIT 0x100000
1262 /* blocking transmit, with timeout */
1263 li t0,TXWAIT # timeout
1264 1: lbu t1,PHYS_TO_UNCACHED(0x1fd002fd) # get LSR
1265 and t1,0x20 # tx ready?
1266 bnez t1,1f # yup - go and write
1268 subu t0,1 # continue until timeout
1271 1: sb a0,PHYS_TO_UNCACHED(0x1fd002f8) # write data
1272 li t0,TXWAIT # timeout
1273 1: lbu t1,PHYS_TO_UNCACHED(0x1fd003fd) # get LSR
1274 and t1,0x20 # tx ready?
1275 bnez t1,1f # yup - go and write
1277 subu t0,1 # continue until timeout
1280 1: sb a0,PHYS_TO_UNCACHED(0x1fd003f8) # write data
1339 # la v0, COM1_BASE_ADDR
1340 la v0, COM3_BASE_ADDR
1342 lbu v1, NSREG(NS16550_LSR)(v0)
1347 sb a0, NSREG(NS16550_DATA)(v0)
1352 /* baud rate definitions, matching include/termios.h */
1367 #define B19200 19200
1368 #define B38400 38400
1369 #define B57600 57600
1370 #define B115200 115200
1373 # la v0, COM1_BASE_ADDR
1374 la v0, COM3_BASE_ADDR
1376 li v1, FIFO_ENABLE|FIFO_RCV_RST|FIFO_XMT_RST|FIFO_TRIGGER_4
1377 sb v1, NSREG(NS16550_FIFO)(v0)
1379 sb v1, NSREG(NS16550_CFCR)(v0)
1380 li v1, NS16550HZ/(16*CONS_BAUD)
1381 sb v1, NSREG(NS16550_DATA)(v0)
1383 sb v1, NSREG(NS16550_IER)(v0)
1385 sb v1, NSREG(NS16550_CFCR)(v0)
1386 li v1, MCR_DTR|MCR_RTS
1387 sb v1, NSREG(NS16550_MCR)(v0)
1389 sb v1, NSREG(NS16550_IER)(v0)
1392 # la v0, COM2_BASE_ADDR
1400 #define SMBOFFS(reg) I82371_SMB_SMB##reg
1405 li a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1406 lbu a0,SMBOFFS(HSTSTS)(a0)
1412 li a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1413 lbu a0,SMBOFFS(SLVSTS)(a0)
1419 li a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1420 lbu a0,SMBOFFS(HSTCNT)(a0)
1426 li a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1427 lbu a0,SMBOFFS(HSTCMD)(a0)
1433 li a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1434 lbu a0,SMBOFFS(HSTADD)(a0)
1440 li a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1441 lbu a0,SMBOFFS(HSTDAT0)(a0)
1447 li a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1448 lbu a0,SMBOFFS(HSTDAT1)(a0)
1454 li a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1455 lbu a0,SMBOFFS(BLKDAT)(a0)
1461 li a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1462 lbu a0,SMBOFFS(SLVCNT)(a0)
1468 li a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1469 lbu a0,SMBOFFS(SHDWCMD)(a0)
1475 li a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1476 lbu a0,SMBOFFS(SLVEVT)(a0)
1482 li a0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1483 lbu a0,SMBOFFS(SLVDAT)(a0)
1496 li t0,PHYS_TO_UNCACHED(ISAPORT_BASE(SMB_PORT))
1498 lbu t1,SMBOFFS(HSTSTS)(t0)
1499 and t1,~(I82371_SMB_FAILED|I82371_SMB_BUS_ERR|I82371_SMB_DEV_ERR|I82371_SMB_INTER)
1500 sb t1,SMBOFFS(HSTSTS)(t0)
1503 or t1,0xa1 # DIMM base address and read bit
1504 sb t1,SMBOFFS(HSTADD)(t0)
1505 sb a1,SMBOFFS(HSTCMD)(t0)
1508 li t1,I82371_SMB_START|I82371_SMB_BDRW
1509 sb t1,SMBOFFS(HSTCNT)(t0)
1512 1: lbu t1,SMBOFFS(HSTSTS)(t0)
1513 and t2,t1,I82371_SMB_FAILED|I82371_SMB_BUS_ERR|I82371_SMB_DEV_ERR|I82371_SMB_INTER
1522 # clear pending errors/interrupts
1523 sb t1,SMBOFFS(HSTSTS)(t0)
1525 and t2,t1,I82371_SMB_FAILED|I82371_SMB_BUS_ERR|I82371_SMB_DEV_ERR
1528 lbu v0,SMBOFFS(HSTDAT0)(t0)
1544 .asciz "\r\nInvalid transmit pattern. Must be DDDD or DDxDDx\r\n"
1546 .asciz "\r\nPANIC! Unexpected TLB refill exception!\r\n"
1548 .asciz "\r\nPANIC! Unexpected XTLB refill exception!\r\n"
1550 .asciz "\r\nPANIC! Unexpected General exception!\r\n"
1552 .asciz "\r\nPANIC! Unexpected Interrupt exception!\r\n"
1554 .ascii "0123456789abcdef"
1559 * I2C Functions used in early startup code to get SPD info from
1560 * SDRAM modules. This code must be entirely PIC and RAM independent.
1564 #define DELAY(count) \
1571 #define I2C_INT_ENABLE 0x80
1572 #define I2C_ENABLE 0x40
1573 #define I2C_ACK 0x04
1574 #define I2C_INT_FLAG 0x08
1575 #define I2C_STOP_BIT 0x10
1576 #define I2C_START_BIT 0x20
1578 #define I2C_AMOD_RD 0x01
1580 #define BUS_ERROR 0x00
1581 #define START_CONDITION_TRA 0x08
1582 #define RSTART_CONDITION_TRA 0x10
1583 #define ADDR_AND_WRITE_BIT_TRA_ACK_REC 0x18
1584 #define ADDR_AND_READ_BIT_TRA_ACK_REC 0x40
1585 #define SLAVE_REC_WRITE_DATA_ACK_TRA 0x28
1586 #define MAS_REC_READ_DATA_ACK_NOT_TRA 0x58
1588 #define Index_Store_Tag_D 0x05
1589 #define Index_Invalidate_I 0x00
1590 #define Index_Writeback_Inv_D 0x01
1592 LEAF(godson1_cache_init)
1596 mfc0 t4, COP_0_CONFIG
1612 #a0=0x80000000, a1=icache_size, a2=dcache_size
1613 #a3, v0 and v1 used as local registers
1614 mtc0 $0, COP_0_TAG_HI
1620 mtc0 $0, COP_0_TAG_LO
1621 cache Index_Store_Tag_D, 0x0(v0)
1622 mtc0 $0, COP_0_TAG_LO
1623 cache Index_Store_Tag_D, 0x1(v0)
1633 cache Index_Invalidate_I, 0x0(v0)
1634 # cache Index_Invalidate_I, 0x1(v0)
1644 cache Index_Writeback_Inv_D, 0x0(v0)
1645 cache Index_Writeback_Inv_D, 0x1(v0)
1655 TTYDBG("cache init panic\r\n");
1659 END(godson1_cache_init)