📄 platform.s
字号:
##
#=============================================================================
## platform.S
##
## MIPS Atlas platform code
##
##=============================================================================
#####ECOSGPLCOPYRIGHTBEGIN####
## -------------------------------------------
## This file is part of eCos, the Embedded Configurable Operating System.
## Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
##
## eCos is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free
## Software Foundation; either version 2 or (at your option) any later version.
##
## eCos is distributed in the hope that it will be useful, but WITHOUT ANY
## WARRANTY; without even the implied warranty of MERCHANTABILITY or
## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
## for more details.
##
## You should have received a copy of the GNU General Public License along
## with eCos; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
##
## As a special exception, if other files instantiate templates or use macros
## or inline functions from this file, or you compile this file and link it
## with other works to produce a work based on this file, this file does not
## by itself cause the resulting work to be covered by the GNU General Public
## License. However the source code for this file must still be made available
## in accordance with section (3) of the GNU General Public License.
##
## This exception does not invalidate any other reasons why a work based on
## this file might be covered by the GNU General Public License.
##
## Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
## at http://sources.redhat.com/ecos/ecos-license/
## -------------------------------------------
#####ECOSGPLCOPYRIGHTEND####
##=============================================================================
#######DESCRIPTIONBEGIN####
##
## Author(s): dmoseley
## Contributors: dmoseley
## Date: 2000-06-06
## Purpose: MIPS Atlas platform code
## Description: Platform specific code for Atlas board.
##
##
##
##
######DESCRIPTIONEND####
##
##=============================================================================
#include <pkgconf/system.h>
#include <pkgconf/hal.h>
#ifdef CYGPKG_KERNEL
# include <pkgconf/kernel.h>
#endif
#include <cyg/hal/arch.inc>
#include <cyg/hal/plf_io.h>
#include <cyg/hal/hal_arch.h>
##-----------------------------------------------------------------------------
##-----------------------------------------------------------------------------
# Platform Initialization.
# This code performs platform specific initialization.
##-----------------------------------------------------------------------------
## MEMC initialization.
##
#if defined(CYG_HAL_STARTUP_ROM) || defined(CYG_HAL_STARTUP_ROMRAM)
.text
.set noreorder
.macro MASK_WRITE_PCI_REG regnum, devnum, mask
.set noreorder
# First, read the appropriate register
li t0, HAL_GALILEO_PCI0_CONFIG_ADDR_ConfigEn | \regnum | \devnum
sw t0, HAL_GALILEO_PCI0_CONFIG_ADDR_OFFSET(s7)
lw t1, HAL_GALILEO_PCI0_CONFIG_DATA_OFFSET(s7)
# Now, mask in the appropriate bits
li t2, \mask
or t1, t2
# Write the updated value
li t0, HAL_GALILEO_PCI0_CONFIG_ADDR_ConfigEn | \regnum | \devnum
sw t0, HAL_GALILEO_PCI0_CONFIG_ADDR_OFFSET(s7)
sw t1, HAL_GALILEO_PCI0_CONFIG_DATA_OFFSET(s7)
.endm
.macro WRITE_PCI_REG regnum, devnum, base
.set noreorder
li t0, HAL_GALILEO_PCI0_CONFIG_ADDR_ConfigEn | \regnum | \devnum
li t1, \base
sw t0, HAL_GALILEO_PCI0_CONFIG_ADDR_OFFSET(s7)
sw t1, HAL_GALILEO_PCI0_CONFIG_DATA_OFFSET(s7)
.endm
#define NO_MASK 0
#define NO_ERROR_CHECK 0
#define ERROR_CHECK 1
.macro READ_SPD_VALUE func, mask, ret_reg, err_check
.set noreorder
jal read_spd_value
li a0, \func # delay slot
.if \err_check
beq v0, zero, error
nop
.endif
move \ret_reg, v0
.if \mask
and \ret_reg, \mask
.endif
.endm
##-----------------------------------------------------------------------------
##
## Initialize the RAM.
##
## To do that, we need to first initialize the Galileo PCI stuff to gain access
## to the SAA9730.
## From there, use the I2C bus of the SAA9730 to read the SPD SDRAM
## config data. We then setup the Galileo SDRAM configuration
##
## Returns
## v0 = Error Code
## v1 = SDRAM size
##
FUNC_START(hal_atlas_init_sdram)
.set noreorder
# Save the return address
move s8, ra
# Setup the base address registers
li s7, CYGARC_UNCACHED_ADDRESS(HAL_GALILEO_REGISTER_BASE)
# Setup the Galileo controller Endian configuration
li t0, (HAL_GALILEO_BYTE_SWAP)
sw t0, HAL_GALILEO_PCI_INTERNAL_COMMAND_OFFSET(s7)
# Setup the PCI_0 Timeout and retry configuration
li t0, HAL_GALILEO_PCI0_TIMEOUT_RETRY_VALUE
sw t0, HAL_GALILEO_PCI0_TIMEOUT_RETRY_OFFSET(s7)
# Setup Galileo as PCI Master
MASK_WRITE_PCI_REG HAL_GALILEO_PCI0_STATUS_COMMAND_REGNUM, HAL_ATLAS_NULL_DEVNUM, \
(HAL_GALILEO_PCI0_CONFIG_MEMEn | HAL_GALILEO_PCI0_CONFIG_MasEn | HAL_GALILEO_PCI0_CONFIG_SErrEn)
# Setup Galileo PCI latency timer
MASK_WRITE_PCI_REG HAL_GALILEO_PCI0_BIST_REGNUM, HAL_ATLAS_NULL_DEVNUM, \
HAL_GALILEO_PCI0_LAT_TIMER_VAL
# Setup base address for SAA9730
WRITE_PCI_REG HAL_GALILEO_PCI0_SCS32_BASE_REGNUM, HAL_ATLAS_SAA9730_DEVNUM, \
CYGARC_PHYSICAL_ADDRESS(HAL_GALILEO_PCI0_MEM0_BASE)
# Setup SAA9730 command and status register
MASK_WRITE_PCI_REG HAL_GALILEO_PCI0_STATUS_COMMAND_REGNUM, HAL_ATLAS_SAA9730_DEVNUM, \
(HAL_GALILEO_PCI0_CONFIG_MEMEn | HAL_GALILEO_PCI0_CONFIG_SErrEn)
# Init the I2C controller
li t0, HAL_SAA9730_I2CSC_I2CCC_6400
li t1, CYGARC_UNCACHED_ADDRESS(HAL_GALILEO_PCI0_MEM0_BASE)
sw t0, HAL_SAA9730_I2CSC_OFFSET(t1)
##=====================================================================================
##
## Read the SPD device parameters and determine memory size
##
READ_SPD_VALUE HAL_SPD_GET_NUM_ROW_BITS, 0xf, s0, ERROR_CHECK
READ_SPD_VALUE HAL_SPD_GET_NUM_COL_BITS, 0xf, s1, ERROR_CHECK
READ_SPD_VALUE HAL_SPD_GET_NUM_DEVICE_BANKS, NO_MASK, s2, ERROR_CHECK
READ_SPD_VALUE HAL_SPD_GET_SDRAM_WIDTH, 0x7f, s3, ERROR_CHECK
READ_SPD_VALUE HAL_SPD_GET_NUM_MODULE_BANKS, NO_MASK, s4, ERROR_CHECK
READ_SPD_VALUE HAL_SPD_GET_ROW_DENSITY, NO_MASK, s5, ERROR_CHECK
#
# Determine Size
# SIZE = SDRAM_WIDTH * NUM_DEVICE_BANKS * 2 ^ (NUM_ROW_BITS + NUM_COL_BITS)
#
addu t0, s0, s1 # t0 = (NUM_ROW_BITS + NUM_COL_BITS)
li t1, 1 # t1 = 2 ^ 0
sll t1, t0 # t1 = 2 ^ (NUM_ROW_BITS + NUM_COL_BITS)
multu s2, t1
mflo s6 # s6 = NUM_DEVICE_BANKS * 2 ^ (NUM_ROW_BITS + NUM_COL_BITS)
nop
nop
nop
multu s6, s3
mflo s6 # s6 = SDRAM_WIDTH * NUM_DEVICE_BANKS * 2 ^ (NUM_ROW_BITS + NUM_COL_BITS)
nop
nop
nop
#
# Determine size of Bank 0
#
li s0, HAL_ATLAS_MAX_BANKSIZE
0:
and t1, s5, BIT7
bnez t1, 8f
sll s5, 1
b 0b
srl s0, 1
8:
#
# Determine if Bank 1 exists
#
li t0, 1
beq s4, t0, 8f
move s1, zero
#
# Determine if Bank 1 is different than Bank 0
#
and t1, s5, 0xFF
beq t1, zero, 8f
move s1, s0
#
# Determine size of Bank 1
#
li s1, HAL_ATLAS_MAX_BANKSIZE
0:
and t1, s5, BIT7
bnez t1, 8f
sll s5, 1
b 0b
srl s1, 1
8:
#
# FIXME: We should probably do some validation on the various
# memory parameters here at some point.
#
#
# Set the base SDRAM bank configuration value.
# All other fields are zero, and the proper value is masked
# in when they are known
#
li s5, HAL_GALILEO_SDRAM_SRAS_TO_SCAS_DELAY_3C | \
HAL_GALILEO_SDRAM_WIDTH_64BIT | \
HAL_GALILEO_SDRAM_SRAS_PRECHARGE_3C
#
# Setup the CASLAT value.
# Support only CASLAT = 2
#
READ_SPD_VALUE HAL_SPD_GET_CAS_LAT, NO_MASK, v0, NO_ERROR_CHECK
and t0, v0, 2
beqz t0, error
nop
ori s5, HAL_GALILEO_SDRAM_BANK0_CASLAT_2
#
# Setup SDRAM device size
#
li t0, SZ_16M
beq s6, t0, 8f
nop
ori s5, HAL_GALILEO_SDRAM_BANK0_SZ_64M
8:
#
# Setup burst length: Support only 8
#
READ_SPD_VALUE HAL_SPD_GET_BURST_LENGTH, NO_MASK, v0, NO_ERROR_CHECK
and t0, v0, 8
beqz t0, error
nop
#
# Setup Parity.
# Only support Parity/Noparity. Don't support ECC.
#
READ_SPD_VALUE HAL_SPD_GET_CONFIG_TYPE, NO_MASK, v0, NO_ERROR_CHECK
li t0, HAL_SPD_CONFIG_TYPE_PARITY
beq t0, v0, 0f
nop
li t0, HAL_SPD_CONFIG_TYPE_ECC
beq t0, v0, error
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -