2020-03-12 01:18:37 +03:00
|
|
|
/*
|
|
|
|
* Allwinner H3 System on Chip emulation
|
|
|
|
*
|
|
|
|
* Copyright (C) 2019 Niek Linnenbank <nieklinnenbank@gmail.com>
|
|
|
|
*
|
|
|
|
* This program 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 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2021-05-27 12:51:52 +03:00
|
|
|
* The Allwinner H3 is a System on Chip containing four ARM Cortex-A7
|
2020-03-12 01:18:37 +03:00
|
|
|
* processor cores. Features and specifications include DDR2/DDR3 memory,
|
|
|
|
* SD/MMC storage cards, 10/100/1000Mbit Ethernet, USB 2.0, HDMI and
|
|
|
|
* various I/O modules.
|
|
|
|
*
|
|
|
|
* This implementation is based on the following datasheet:
|
|
|
|
*
|
|
|
|
* https://linux-sunxi.org/File:Allwinner_H3_Datasheet_V1.2.pdf
|
|
|
|
*
|
|
|
|
* The latest datasheet and more info can be found on the Linux Sunxi wiki:
|
|
|
|
*
|
|
|
|
* https://linux-sunxi.org/H3
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef HW_ARM_ALLWINNER_H3_H
|
|
|
|
#define HW_ARM_ALLWINNER_H3_H
|
|
|
|
|
|
|
|
#include "qom/object.h"
|
|
|
|
#include "hw/arm/boot.h"
|
|
|
|
#include "hw/timer/allwinner-a10-pit.h"
|
|
|
|
#include "hw/intc/arm_gic.h"
|
2020-03-12 01:18:39 +03:00
|
|
|
#include "hw/misc/allwinner-h3-ccu.h"
|
2020-03-12 01:18:42 +03:00
|
|
|
#include "hw/misc/allwinner-cpucfg.h"
|
2020-03-12 01:18:47 +03:00
|
|
|
#include "hw/misc/allwinner-h3-dramc.h"
|
2020-03-12 01:18:41 +03:00
|
|
|
#include "hw/misc/allwinner-h3-sysctrl.h"
|
2020-03-12 01:18:43 +03:00
|
|
|
#include "hw/misc/allwinner-sid.h"
|
2020-03-12 01:18:44 +03:00
|
|
|
#include "hw/sd/allwinner-sdhost.h"
|
2020-03-12 01:18:45 +03:00
|
|
|
#include "hw/net/allwinner-sun8i-emac.h"
|
2020-03-12 01:18:48 +03:00
|
|
|
#include "hw/rtc/allwinner-rtc.h"
|
2020-03-12 01:18:37 +03:00
|
|
|
#include "target/arm/cpu.h"
|
2020-03-12 01:18:46 +03:00
|
|
|
#include "sysemu/block-backend.h"
|
2020-03-12 01:18:37 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Allwinner H3 device list
|
|
|
|
*
|
|
|
|
* This enumeration is can be used refer to a particular device in the
|
|
|
|
* Allwinner H3 SoC. For example, the physical memory base address for
|
|
|
|
* each device can be found in the AwH3State object in the memmap member
|
|
|
|
* using the device enum value as index.
|
|
|
|
*
|
|
|
|
* @see AwH3State
|
|
|
|
*/
|
|
|
|
enum {
|
2020-08-25 22:20:01 +03:00
|
|
|
AW_H3_DEV_SRAM_A1,
|
|
|
|
AW_H3_DEV_SRAM_A2,
|
|
|
|
AW_H3_DEV_SRAM_C,
|
|
|
|
AW_H3_DEV_SYSCTRL,
|
|
|
|
AW_H3_DEV_MMC0,
|
|
|
|
AW_H3_DEV_SID,
|
|
|
|
AW_H3_DEV_EHCI0,
|
|
|
|
AW_H3_DEV_OHCI0,
|
|
|
|
AW_H3_DEV_EHCI1,
|
|
|
|
AW_H3_DEV_OHCI1,
|
|
|
|
AW_H3_DEV_EHCI2,
|
|
|
|
AW_H3_DEV_OHCI2,
|
|
|
|
AW_H3_DEV_EHCI3,
|
|
|
|
AW_H3_DEV_OHCI3,
|
|
|
|
AW_H3_DEV_CCU,
|
|
|
|
AW_H3_DEV_PIT,
|
|
|
|
AW_H3_DEV_UART0,
|
|
|
|
AW_H3_DEV_UART1,
|
|
|
|
AW_H3_DEV_UART2,
|
|
|
|
AW_H3_DEV_UART3,
|
|
|
|
AW_H3_DEV_EMAC,
|
|
|
|
AW_H3_DEV_DRAMCOM,
|
|
|
|
AW_H3_DEV_DRAMCTL,
|
|
|
|
AW_H3_DEV_DRAMPHY,
|
|
|
|
AW_H3_DEV_GIC_DIST,
|
|
|
|
AW_H3_DEV_GIC_CPU,
|
|
|
|
AW_H3_DEV_GIC_HYP,
|
|
|
|
AW_H3_DEV_GIC_VCPU,
|
|
|
|
AW_H3_DEV_RTC,
|
|
|
|
AW_H3_DEV_CPUCFG,
|
|
|
|
AW_H3_DEV_SDRAM
|
2020-03-12 01:18:37 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Total number of CPU cores in the H3 SoC */
|
|
|
|
#define AW_H3_NUM_CPUS (4)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allwinner H3 object model
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** Object type for the Allwinner H3 SoC */
|
|
|
|
#define TYPE_AW_H3 "allwinner-h3"
|
|
|
|
|
|
|
|
/** Convert input object to Allwinner H3 state object */
|
2020-09-16 21:25:19 +03:00
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(AwH3State, AW_H3)
|
2020-03-12 01:18:37 +03:00
|
|
|
|
|
|
|
/** @} */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allwinner H3 object
|
|
|
|
*
|
|
|
|
* This struct contains the state of all the devices
|
|
|
|
* which are currently emulated by the H3 SoC code.
|
|
|
|
*/
|
2020-09-03 23:43:22 +03:00
|
|
|
struct AwH3State {
|
2020-03-12 01:18:37 +03:00
|
|
|
/*< private >*/
|
|
|
|
DeviceState parent_obj;
|
|
|
|
/*< public >*/
|
|
|
|
|
|
|
|
ARMCPU cpus[AW_H3_NUM_CPUS];
|
|
|
|
const hwaddr *memmap;
|
|
|
|
AwA10PITState timer;
|
2020-03-12 01:18:39 +03:00
|
|
|
AwH3ClockCtlState ccu;
|
2020-03-12 01:18:42 +03:00
|
|
|
AwCpuCfgState cpucfg;
|
2020-03-12 01:18:47 +03:00
|
|
|
AwH3DramCtlState dramc;
|
2020-03-12 01:18:41 +03:00
|
|
|
AwH3SysCtrlState sysctrl;
|
2020-03-12 01:18:43 +03:00
|
|
|
AwSidState sid;
|
2020-03-12 01:18:44 +03:00
|
|
|
AwSdHostState mmc0;
|
2020-03-12 01:18:45 +03:00
|
|
|
AwSun8iEmacState emac;
|
2020-03-12 01:18:48 +03:00
|
|
|
AwRtcState rtc;
|
2020-03-12 01:18:37 +03:00
|
|
|
GICState gic;
|
|
|
|
MemoryRegion sram_a1;
|
|
|
|
MemoryRegion sram_a2;
|
|
|
|
MemoryRegion sram_c;
|
2020-09-03 23:43:22 +03:00
|
|
|
};
|
2020-03-12 01:18:37 +03:00
|
|
|
|
2020-03-12 01:18:46 +03:00
|
|
|
/**
|
|
|
|
* Emulate Boot ROM firmware setup functionality.
|
|
|
|
*
|
|
|
|
* A real Allwinner H3 SoC contains a Boot ROM
|
|
|
|
* which is the first code that runs right after
|
|
|
|
* the SoC is powered on. The Boot ROM is responsible
|
|
|
|
* for loading user code (e.g. a bootloader) from any
|
|
|
|
* of the supported external devices and writing the
|
|
|
|
* downloaded code to internal SRAM. After loading the SoC
|
|
|
|
* begins executing the code written to SRAM.
|
|
|
|
*
|
|
|
|
* This function emulates the Boot ROM by copying 32 KiB
|
|
|
|
* of data from the given block device and writes it to
|
|
|
|
* the start of the first internal SRAM memory.
|
|
|
|
*
|
|
|
|
* @s: Allwinner H3 state object pointer
|
|
|
|
* @blk: Block backend device object pointer
|
|
|
|
*/
|
|
|
|
void allwinner_h3_bootrom_setup(AwH3State *s, BlockBackend *blk);
|
|
|
|
|
2020-03-12 01:18:37 +03:00
|
|
|
#endif /* HW_ARM_ALLWINNER_H3_H */
|