rrc-open-firmware/src/entrypoint.asm
DataHoarder c99d942f3e
All checks were successful
continuous-integration/drone/push Build is passing
Add further config values, set spi values for rrcc to use
2021-01-04 08:21:58 +01:00

131 lines
6.4 KiB
NASM

; Copyright (c) 2021, rrc-open-firmware FM10K-Documentation Contributors
;
; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that the following conditions are met:
;
; * Redistributions of source code must retain the above copyright notice,
; this list of conditions and the following disclaimer.
; * 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.
; * Neither the name of the copyright holder nor the names of its contributors
; may be used to endorse or promote products derived from this software
; without specific prior written permission.
;
; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT OWNER OR CONTRIBUTORS 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.
.constant rrcc_SPI_TRANSFER_MODE, bootCfg_spiTransferMode
.constant rrcc_SPI_TRANSFER_SPEED, bootCfg_spiTransferSpeed
.constant rrcc_IMAGE_VERSION, platform_firmware_versionNumber
entrypoint:
CALL @init_startClocks
FASTCALL @init_setClockSource, bootCfg_systimeClockSource
FASTCALL @init_setPcieSplitMode, bootCfg_pep0_mode, bootCfg_pep2_mode, bootCfg_pep4_mode, bootCfg_pep6_mode
SET DEVICE_CFG, 0xff80, 0xff80 ; Set PCIeEnable[0-8] to enabled
CALL @init_markClockStable
CALL @init_markSbusBooted
FASTCALL @init_memoryRepairConfig, bootCfg_skipMemRepair
CALL @init_bistStateCheck
MOV R0, bootCfg_skipPcieInitialization
BEQ R0, 1, 1, @.skipPcieInit
SET SOFT_RESET, 0, 0x6 ; Enable areas, EPLReset = 0, SwitchReset = 0
WAIT 10 ; Wait 100ns, minimum
FASTCALL @init_setPciePEPEnabled, bootCfg_pep0_enable, bootCfg_pep1_enable, bootCfg_pep2_enable, bootCfg_pep3_enable, bootCfg_pep4_enable, bootCfg_pep5_enable, bootCfg_pep6_enable, bootCfg_pep7_enable, bootCfg_pep8_enable
FASTCALL @init_PCIE_setClockOutDiv, 10
CALL @lock_PCIE_SBUS_take ; Try to take lock for ourselves
BNE RRET, 1, 0x1, @.skipPcieInit ; We failed to take the lock
CALL @init_PCIE_MASTER_SPICO
BNE RRET, 1, 0x1, @.skipPcieInit ; Failed to init properly
CALL @init_ALL_PCIE_SERDES_SPICO
BNE RRET, 1, 0x1, @.skipPcieInit ; Failed to init properly
; Restart PEPs
MOV api_BSM_STATUS, 0x00000010
FASTCALL @init_setPciePEPEnabled, bootCfg_pep0_enable, bootCfg_pep1_enable, bootCfg_pep2_enable, bootCfg_pep3_enable, bootCfg_pep4_enable, bootCfg_pep5_enable, bootCfg_pep6_enable, bootCfg_pep7_enable, bootCfg_pep8_enable
WAIT 5
MOV api_BSM_STATUS, 0x00010010
MOV api_PCIE_DE_WARM_RESET_STATUS, api_BSM_STATUS
FASTCALL @init_PCIE_setClockOutDiv, 6
CALL @init_PCIE_EACH_SERDES_SPICO
BNE RRET, 1, 0x1, @.skipPcieInit ; Failed to init properly
; TODO complete this
.skipPcieInit:
BEQ platform_PCIE_SBUS_LOCK_HOLD, 1, 0x1, @.noReleaseLock
CALL @lock_PCIE_SBUS_release
.noReleaseLock:
CALL @config_load_bootCfg_customMac
MOV api_EEPROM_IMAGE_VERSION, platform_firmware_versionNumber ; Sets the version on memory where a switch manager can read it
RET
init_markSbusBooted:
MOV api_BSM_STATUS, 0x0000b
MOV SBUS_EPL_CFG, 0 ; Set SBUS_ControllerReset = 0 (Not in reset)
MOV SBUS_PCIE_CFG, 0 ; Set SBUS_ControllerReset = 0 (Not in reset)
MOV api_BSM_STATUS, 0x1000b
MOV api_SBUS_RESET_STATUS, api_BSM_STATUS
RET
; FASTCALL void(bool skipMemRepair)
init_memoryRepairConfig:
MOV api_BSM_STATUS, 0x00000c ; apparently api_MEMORY_REPAIR_STATUS is not set here
BEQ P0, 0, 0x1, @.noSkipRepair
MOV api_BSM_STATUS, 0x41000c
MOV api_MEMORY_REPAIR_STATUS, api_BSM_STATUS
RET
.noSkipRepair:
MOV REI_CTRL, 0x9; Set RAM EFUSE interface, Reset = 1, Mode = 0, Run = 0, AutoLoadEnable = 1
MOV REI_CTRL, 0x8; Take it out of reset. Set RAM EFUSE interface, Reset = 0, Mode = 0, Run = 0, AutoLoadEnable = 1
MOV api_BSM_STATUS, 0x01000c ; apparently api_MEMORY_REPAIR_STATUS is not set here
MOV R0, 0x3 ; Number of total tries
.checkMemTest:
SUB R0, R0, 1 ; Decrease total tries
PNE REI_STAT, 1, 0x3, 16000, 10, @.failMemCheck ; Check if ReiDonePass = 1, and ReiDoneFail = 0
MOV api_BSM_STATUS, 0x11000c ; Success!
MOV api_MEMORY_REPAIR_STATUS, api_BSM_STATUS
WAIT 10
RET
.failMemCheck:
BEQ REI_STAT, 0x2, 0x2, @.failMem ; Check if ReiDoneFail = 1, and ReiDonePass = 0
MOV api_BSM_STATUS, 0x31000c ; Retry
MOV api_MEMORY_REPAIR_STATUS, api_BSM_STATUS
BNE R0, 0, 0x3, @.checkMemTest ; Jump if total tries != 0
.failMem: ; Failed or took too many tries
MOV api_BSM_STATUS, 0x21000c
MOV api_MEMORY_REPAIR_STATUS, api_BSM_STATUS
END ; Program Execution finishes after memory check failed
init_bistStateCheck:
MOV api_BSM_STATUS, 0x000000d
WRITE BIST_CTRL_0, 0x00000000, 0x0000ffff ; 64-bit write, regular BIST, BistRun_PCIE[0-8] = 1, BistRun_EPL = 1, BistRun_FABRIC = 1, BistRun_TUNNEL = 1, BistRun_BSM = 1, BistRun_CRM = 1, BistRun_FIBM = 1, BistRun_SBM = 1
WRITE BIST_CTRL_0, 0x0000ffff, 0x0000ffff ; 64-bit write, BIST memory init, BistRun_PCIE[0-8] = 1, BistRun_EPL = 1, BistRun_FABRIC = 1, BistRun_TUNNEL = 1, BistRun_BSM = 1, BistRun_CRM = 1, BistRun_FIBM = 1, BistRun_SBM = 1
WAIT 80000
WRITE BIST_CTRL_0, 0x00000000, 0x0000ffff ; 64-bit write, regular BIST, BistRun_PCIE[0-8] = 1, BistRun_EPL = 1, BistRun_FABRIC = 1, BistRun_TUNNEL = 1, BistRun_BSM = 1, BistRun_CRM = 1, BistRun_FIBM = 1, BistRun_SBM = 1
WRITE BIST_CTRL_0, 0x00000000, 0x00000000 ; 64-bit write, regular BIST, set all BistRun_* = 0
MOV api_BSM_STATUS, 0x110000d
MOV api_MEMORY_INIT_STATUS, api_BSM_STATUS
RET