📄 tgt_machdep.c
字号:
/* $Id: tgt_machdep.c,v 1.17 2003/08/10 10:52:35 pefo Exp $ *//* * Copyright (c) 2001 Opsycon AB (www.opsycon.se) * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Opsycon AB, Sweden. * 4. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * */#if 1#include <sys/param.h>#include <sys/syslog.h>#include <machine/endian.h>#include <sys/device.h>#include <machine/cpu.h>#include <machine/pio.h>#include <machine/intr.h>#include <dev/pci/pcivar.h>#endif#include <sys/types.h>#include <termio.h>#include <string.h>#include <time.h>#include <stdlib.h>#include <autoconf.h>#include <machine/cpu.h>#include <machine/pio.h>#include "pflash.h"#include "dev/pflash_tgt.h"#include "include/ocelot_g.h"#include <pmon/dev/gt64240reg.h>#include <pmon/dev/ns16550.h>#include "include/m48t37.h"#include <pmon.h>#include "flash.h"#if (NMOD_FLASH_AMD + NMOD_FLASH_INTEL) == 0#ifdef HAVE_FLASH#undef HAVE_FLASH#endif#else#define HAVE_FLASH#endif#define TOD_REG(x) (clkbase + x)extern char _end[];extern struct trapframe DBGREG;extern void *memset __P((void *, int, size_t));extern unsigned char hwethadr[6];static int md_pipefreq = 0;static int md_cpufreq = 0;static int clk_invalid = 0;static int nvram_invalid = 0;static int cksum __P((void *p, size_t s, int set));static void _probe_frequencies __P((void));ConfigEntry ConfigTable[] ={ { (char *)COM1_BASE_ADDR, 0, ns16550, 256, CONS_BAUD, NS16550HZ }, { (char *)COM2_BASE_ADDR, 0, ns16550, 256, CONS_BAUD, NS16550HZ }, { 0 }};unsigned long _filebase;extern char MipsException[], MipsExceptionEnd[];void initmips __P((u_int32_t));voidinitmips(msize) u_int32_t msize;{ u_int32_t totalSize; totalSize = msize;SBD_DISPLAY ("MSIZ", CHKPNT_AUTO); totalmemsize = totalSize; /* * Set up memory address decoders to map entire memory. * But first move away bootrom map to high memory. */ GT_WRITE(BOOTCS_LOW_DECODE_ADDRESS, BOOT_BASE >> 20); GT_WRITE(BOOTCS_HIGH_DECODE_ADDRESS, (BOOT_BASE + BOOT_SIZE - 1) >> 20); if(msize == 0x20000000) { /* 512 Mb */ GT_WRITE(SCS_2_LOW_DECODE_ADDRESS, 0x100); GT_WRITE(SCS_2_HIGH_DECODE_ADDRESS, 0x1ff); GT_WRITE(SCS_0_HIGH_DECODE_ADDRESS, 0x0ff); } else { /* 1Gb */ GT_WRITE(SCS_2_LOW_DECODE_ADDRESS, 0x200); GT_WRITE(SCS_2_HIGH_DECODE_ADDRESS, 0x3ff); GT_WRITE(SCS_0_HIGH_DECODE_ADDRESS, 0x1ff); } /* * Probe clock frequencys so delays will work properly. */ tgt_cpufreq(); /* * Init PMON and debug */ cpuinfotab[0] = &DBGREG; dbginit(NULL); /* * Set up exception vectors. */ bcopy(MipsException, (char *)TLB_MISS_EXC_VEC, MipsExceptionEnd - MipsException); bcopy(MipsException, (char *)GEN_EXC_VEC, MipsExceptionEnd - MipsException); CPU_FlushCache(); CPU_SetSR(0, SR_BOOT_EXC_VEC); /* * Register initial memory map. */ register_mem((void *)0, (void *)totalmemsize-1, MEM_RAM, "SDRAM"); register_mem((void *)CACHED_TO_PHYS(memtop), kmemtop-1, MEM_DATA, "Kernel data"); register_mem((void *)0, (void *)CACHED_TO_PHYS(_end)-1, MEM_CODE, "PMON2000"); register_mem((void *)CACHED_TO_PHYS(_end), (void *)CACHED_TO_PHYS(heaptop)-1, MEM_DATA, "PMON2000 heap"); register_mem((void *)FPGA_BASE, (void *)BOOT_BASE+BOOT_SIZE-1, MEM_IO, "decoded space"); register_mem((void *)FPGA_BASE, (void *)FPGA_BASE+FPGA_SIZE-1, MEM_IO, "fpga control"); register_mem((void *)RTC_BASE, (void *)RTC_BASE+RTC_SIZE-1, MEM_IO, "RTC and NVRAM"); register_mem((void *)UART_BASE, (void *)UART_BASE+UART_SIZE-1, MEM_IO, "NS16552"); register_mem((void *)FLASH_BASE, (void *)FLASH_BASE+FLASH_SIZE-1, MEM_FLASH, "DiskOnChip"); register_mem((void *)GT_BASE_ADDR, (void *)GT_BASE_ADDR+65535, MEM_IO, "internal registers"); register_mem((void *)0xffc00000, (void *)0xffc7ffff, MEM_FLASH, "boot flash"); /* * Launch! */ pmon_main();}/* * Put all machine dependent initialization here. This call * is done after console has been initialized so it's safe * to output configuration and debug information with printf. */voidtgt_devconfig(){ _pci_devinit(1); /* PCI device initialization */ /* Set the PHY addresses for the GT ethernet */ GT_WRITE(ETH_PHY_ADDR_REG, 0x2828); GT_WRITE(MAIN_ROUTING_REGISTER, 0x007ffe38); GT_WRITE(SERIAL_PORT_MULTIPLEX, 0x00000102); config_init(); configure();}voidtgt_devinit(){ /* * Gather info about and configure caches. */ if(getenv("ocache_off")) { CpuOnboardCacheOn = 0; } else { CpuOnboardCacheOn = 1; } if(getenv("ecache_off")) { CpuExternalCacheOn = 0; } else { CpuExternalCacheOn = 1; } CPU_ConfigCache(); /* Register Discovery area where PCI lives */ register_mem((void *)0xc0000000, (void *)0xffffffff, MEM_IO, "MV64240 I/O"); _pci_businit(1); /* PCI bus initialization */}voidtgt_reboot(){ void (*longreach) __P((void)); int i; /* Reset reset cause */ out8(PLD_RSTAT, in8(PLD_RSTAT)); /* Enable watchdog one tick at 1/16th second */ out8(M48T37_BASE+7, 0x84); /* Then wait... */ for(i = 0; i < 200000000; i++); /* Unreliable but try this if watchdog fails... */ printf("Watchdog reboot failed!\n"); longreach = (void *)0xbfc00000; (*longreach)(); while(1);}/* * This function makes inital HW setup for debugger and * returns the apropriate setting for the status register. */register_ttgt_enable(int machtype){ /* XXX Do any HW specific setup */ return(SR_COP_1_BIT|SR_FR_32|SR_EXL);}/* * Target dependent version printout. * Printout available target version information. */voidtgt_cmd_vers(){ printf("Board revision level: %c.\n", in8(PLD_BAR) + 'A'); printf("PLD revision levels: %d.%d and %d.%d.\n", in8(PLD_ID1) >> 4, in8(PLD_ID1) & 15, in8(PLD_ID2) >> 4, in8(PLD_ID2) & 15);}/* * Display any target specific logo. */#if defined(HAVE_LOGO)voidtgt_logo(){}#endifstatic void_probe_frequencies(){#ifdef HAVE_TOD int i, timeout, cur, sec, cnt; int clkbase = M48T37_BASE;#endifextern void tgt_setpar100mhz __P((void)); SBD_DISPLAY ("FREQ", CHKPNT_FREQ); md_pipefreq = 300000000; /* Defaults */ md_cpufreq = 100000000; clk_invalid = 1;#ifdef HAVE_TOD /* * Check if clock is stopped and start it if it is. */ if(inb(TOD_REG(TOD_SECOND)) & TOD_SECOND_ST) { outb(TOD_REG(TOD_SECOND), inb(TOD_REG(TOD_SECOND)) & ~TOD_SECOND_ST); } else { clk_invalid = 0; } /* * Do the next twice for two reasons. First make sure we run from * cache. Second make sure synched on second update. (Pun intended!) */ for(i = 2; i != 0; i--) { cnt = CPU_GetCOUNT(); timeout = 100000000; outb(TOD_REG(TOD_CTRL), inb(TOD_REG(TOD_CTRL)) | TOD_CTRL_R); /* stop update */ sec = inb(TOD_REG(TOD_SECOND)) & 0x0f; outb(TOD_REG(TOD_CTRL), inb(TOD_REG(TOD_CTRL)) & ~TOD_CTRL_R); /* start update */ do { timeout--; outb(TOD_REG(TOD_CTRL), inb(TOD_REG(TOD_CTRL)) | TOD_CTRL_R); cur = inb(TOD_REG(TOD_SECOND)) & 0x0f; outb(TOD_REG(TOD_CTRL), inb(TOD_REG(TOD_CTRL)) & ~TOD_CTRL_R); } while(timeout != 0 && cur == sec); cnt = CPU_GetCOUNT() - cnt; if(timeout == 0) { clk_invalid = 1; return; /* Get out if clock is not running */ } } /* * Calculate the external bus clock frequency. */ md_pipefreq = (cnt + 5999)/ 10000; md_pipefreq *= 20000; /* * Calculate the external frequency. */ i = 2 - ((CPU_GetCONFIG() >> 16) & 1); /* Halfclock bit */ md_cpufreq = md_pipefreq * 2; md_cpufreq /= (((CPU_GetCONFIG() >> 28) & 7) + 2) * i; /* * Hack to change timing of GT64240 if not 125Mhz FSB. */ if(md_cpufreq < 110000000) { tgt_setpar100mhz(); }#endif /* HAVE_TOD */}/* * Returns the CPU pipelie clock frequency */inttgt_pipefreq(){ if(md_pipefreq == 0) { _probe_frequencies(); } return(md_pipefreq);}/* * Returns the external clock frequency, usually the bus clock */inttgt_cpufreq(){ if(md_cpufreq == 0) { _probe_frequencies(); } return(md_cpufreq);}#ifdef HAVE_TOD/* * Returns the current time if a TOD clock is present or 0 * This code is defunct after 2088... (out of bits) */#define FROMBCD(x) (((x) >> 4) * 10 + ((x) & 0xf))#define TOBCD(x) (((x) / 10 * 16) + ((x) % 10)) #define YEARDAYS(year) ((((year) % 4) == 0 && \ ((year % 100) != 0 || (year % 400) == 0)) ? 366 : 365)#define SECMIN (60) /* seconds per minute */#define SECHOUR (60*SECMIN) /* seconds per hour */#define SECDAY (24*SECHOUR) /* seconds per day */#define SECYR (365*SECDAY) /* seconds per common year */static const short dayyr[12] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };time_ttgt_gettime(){ struct tm tm; int clkbase = M48T37_BASE; int century; time_t t; if(clk_invalid) { tm.tm_sec = 0; tm.tm_min = 0; tm.tm_hour = 0; tm.tm_wday = 0; tm.tm_mday = 1; tm.tm_mon = 1; tm.tm_year = 0; } else { outb(TOD_REG(TOD_CTRL), inb(TOD_REG(TOD_CTRL)) | TOD_CTRL_R); tm.tm_sec = FROMBCD(inb(TOD_REG(TOD_SECOND))); tm.tm_min = FROMBCD(inb(TOD_REG(TOD_MINUTE))); tm.tm_hour = FROMBCD(inb(TOD_REG(TOD_HOUR))); tm.tm_wday = FROMBCD(inb(TOD_REG(TOD_DAY))); tm.tm_mday = FROMBCD(inb(TOD_REG(TOD_DATE))); tm.tm_mon = FROMBCD(inb(TOD_REG(TOD_MONTH))) - 1; tm.tm_year = FROMBCD(inb(TOD_REG(TOD_YEAR))); century = FROMBCD(inb(TOD_REG(TOD_CENTURY))); outb(TOD_REG(TOD_CTRL), inb(TOD_REG(TOD_CTRL)) & ~TOD_CTRL_R); } /* Since tm_year is defined to be years since 1900 we compute */ /* the correct value here */ tm.tm_year = century*100 + tm.tm_year - 1900; tm.tm_isdst = tm.tm_gmtoff = 0; t = gmmktime(&tm); if(clk_invalid) { tgt_settime(t); } return(t);}/* * Set the current time if a TOD clock is present */voidtgt_settime(time_t t){ struct tm *tm; int clkbase = M48T37_BASE; int century; tm = gmtime(&t); /* Enable register writing */ outb(TOD_REG(TOD_CTRL), inb(TOD_REG(TOD_CTRL)) | TOD_CTRL_W); century = (tm->tm_year + 1900)/100; outb(TOD_REG(TOD_CENTURY), TOBCD(century)); outb(TOD_REG(TOD_YEAR), TOBCD((tm->tm_year + 1900) % 100)); outb(TOD_REG(TOD_MONTH), TOBCD(tm->tm_mon + 1));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -